Back to index

courier  0.68.2
Functions
imapwrite.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void writeflush ()
void writemem (const char *, size_t)
void writes (const char *)
void writeqs (const char *)
void writen (unsigned long n)
void write_error_exit (const char *)

Function Documentation

void write_error_exit ( const char *  )

Definition at line 190 of file imapwrite.c.

{
       outbuf_cnt=0;
       writes("* BYE [ALERT] Fatal error: ");
       if (funcname && *funcname)
       {
              writes(funcname);
              writes(": ");
       }

       if (errno)
       {
#if    HAVE_STRERROR
       const  char *p;

              p=strerror(errno);
#else
       char   p[40];

              sprintf(p, "Error %d", (int)errno);
#endif


              writes(p);
       }
       writes("\r\n");
       writeflush();

       if (funcname && *funcname)
       {
              fprintf(stderr, "ERR: %s: %s\n", getenv("AUTHENTICATED"),
                     funcname);
              fflush(stderr);
       }
       _exit(1);
}

Here is the call graph for this function:

void writeflush ( )

Definition at line 40 of file imapwrite.c.

{
const char *p=outbuf;
unsigned s=outbuf_cnt;
time_t t, tend;
fd_set fds;
struct timeval       tv;
int    n;

       if (s == 0)   return;
       time(&t);
       tend=t+SOCKET_TIMEOUT;
       if (debugfile)
       {
              fprintf(debugfile, "WRITE: ");
              if (fwrite(p, 1, s, debugfile) == 1)
                     fprintf(debugfile, "\n");
              fflush(debugfile);
       }
       while (t < tend)
       {
              FD_ZERO(&fds);
              FD_SET(1, &fds);
              tv.tv_sec=tend-t;
              tv.tv_usec=0;
              /* BUG: if client closes connection BEFORE we flush it, select "stucks"
               * until timeout. To workaround this, we should "write" first, and then
               * if we get EPIPE connection is already closed. Othervise, try select
               */
              if ((n=write(1, p, s)) <= 0)
              {
                     if (errno == EPIPE ||
                            select(2, 0, &fds, 0, &tv) <= 0 ||
                            !FD_ISSET(1, &fds) ||
                            (n=write(1, p, s)) <= 0)
                     {
                            disconnected();
                            return;
                     }
              }
              bytes_sent_count += n;
              p += n;
              s -= n;
              if (s == 0)   break;
              time(&t);
       }
       if (s) disconnected();
       outbuf_cnt=0;
}

Here is the call graph for this function:

void writemem ( const char *  ,
size_t   
)

Definition at line 90 of file imapwrite.c.

{
size_t n;

       while (l)
       {
              n=sizeof(outbuf) - outbuf_cnt;

              if (n >= l)
              {
                     memcpy(outbuf+outbuf_cnt, s, l);
                     outbuf_cnt += l;
                     break;
              }
              if (n == 0)
              {
                     writeflush();
                     continue;
              }
              if (n > l)    n=l;
              memcpy(outbuf+outbuf_cnt, s, n);
              outbuf_cnt += n;
              l -= n;
              s += n;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void writen ( unsigned long  n)

Definition at line 122 of file imapwrite.c.

{
char   buf[40];

       sprintf(buf, "%lu", n);
       writemem(buf, strlen(buf));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void writeqs ( const char *  )

Definition at line 130 of file imapwrite.c.

{
size_t i=strlen(s), j;

       while (i)
       {
              for (j=0; j<i; j++)
              {
                     if ( s[j] == '"' || s[j] == '\\')
                     {
                            writemem(s, j);
                            writemem("\\", 1);
                            writemem(s+j, 1);
                            ++j;
                            s += j;
                            i -= j;
                            j=0;
                            break;
                     }
#if 0
                     if (s[j] == '&')
                     {
                            writemem(s, j);
                            writemem("&-", 2);
                            ++j;
                            s += j;
                            i -= j;
                            j=0;
                            break;
                     }

                     if (s[j] < ' ' || s[j] >= 0x7F)
                     {
                     char   *q;

                            writemem(s, j);
                            ++j;
                            s += j;
                            i -= j;
                            for (j=0; j<i; j++)
                                   if (s[j] >= ' ' && s[j] < 0x7F)
                                          break;
                            q=imap_utf7_encode(s, j);
                            if (!q)       write_error_exit(0);
                            writemem("&", 1);
                            writes(q);
                            writemem("-", 1);
                            s += j;
                            i -= j;
                            j=0;
                            break;
                     }
#endif
              }
              writemem(s, j);
              s += j;
              i -= j;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void writes ( const char *  )

Definition at line 117 of file imapwrite.c.

{
       writemem(s, strlen(s));
}

Here is the call graph for this function: