Back to index

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

Go to the source code of this file.

Classes

struct  proxyinfo
struct  proxybuf

Functions

int connect_proxy (struct proxyinfo *)
void proxyloop (int)
int proxy_readline (int fd, struct proxybuf *pb, char *linebuf, size_t linebuflen, int imapmode)
int proxy_write (int fd, const char *hostname, const char *buf, size_t buf_len)

Class Documentation

struct proxybuf

Definition at line 21 of file proxy.h.

Class Members
char buffer
size_t bufleft
char * bufptr

Function Documentation

int connect_proxy ( struct proxyinfo )

Definition at line 71 of file proxy.c.

{
       char *h=strdup(pi->host);
       char *p, *q;
       int fd;

       if (!h)
       {
              courier_authdebug_printf("%s", strerror(errno));
              return -1;
       }

       for (p=h; *p;)
       {
              if (*p == ',')
              {
                     ++p;
                     continue;
              }

              for (q=p; *q; q++)
                     if (*q == ',')
                            break;
              if (*q)
                     *q++=0;

              fd=connect_host(pi, p);
              if (fd >= 0)
              {
                     free(h);
                     return fd;
              }
              p=q;
       }
       free(h);
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int proxy_readline ( int  fd,
struct proxybuf pb,
char *  linebuf,
size_t  linebuflen,
int  imapmode 
)

Definition at line 435 of file proxy.c.

{
       size_t i;
       int ch;
       int prevch;

       i=0;

       ch=0;

       do
       {
              prevch=ch;

              ch=proxy_getch(fd, pb);

              if (ch < 0)
                     return -1;

              if (i < linebuflen)
                     linebuf[i++]=(char)ch;
       } while (ch != '\n' || (imapmode && prevch != '\r'));

       if (i)
              linebuf[--i]=0;

       if (i && linebuf[i-1] == '\r')
              linebuf[--i]=0;

       DPRINTF("Received: %s", linebuf);

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int proxy_write ( int  fd,
const char *  hostname,
const char *  buf,
size_t  buf_len 
)

Definition at line 472 of file proxy.c.

{
       DPRINTF("Sending: %s", buf);

       while (buf_len)
       {
              int n;

              if (proxy_waitfd(fd, 1, hostname))
                     return -1;

              n=write(fd, buf, buf_len);

              if (n < 0)
              {
                     courier_authdebug_printf
                            ("Error sending to %s: %s",
                             hostname, strerror(errno));
                     return -1;
              }

              if (n == 0)
              {
                     courier_authdebug_printf
                            ("Connection close by %s", hostname);
                     return -1;
              }

              buf_len -= n;
              buf += n;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void proxyloop ( int  )

Definition at line 621 of file proxy.c.

{
       char stdin_buf[BUFSIZ];
       char stdout_buf[BUFSIZ];

       char *stdin_ptr=NULL;
       char *stdout_ptr=NULL;
       size_t stdin_left=0;
       size_t stdout_left=0;
       int n;

       fd_set fdr, fdw;

       if (fcntl(0, F_SETFL, O_NONBLOCK) ||
           fcntl(1, F_SETFL, O_NONBLOCK))
       {
              courier_authdebug_printf("fcntl: %s",
                                    strerror(errno));
              return;
       }

       do
       {
              FD_ZERO(&fdr);
              FD_ZERO(&fdw);

              if (stdin_left == 0)
                     FD_SET(0, &fdr);
              else
                     FD_SET(fd, &fdw);

              if (stdout_left == 0)
                     FD_SET(fd, &fdr);
              else
                     FD_SET(1, &fdw);

              n=1;

              if (select(fd+1, &fdr, &fdw, NULL, NULL) < 0)
              {
                     courier_authdebug_printf("select: %s",
                                           strerror(errno));
                     continue;
              }

              if (stdin_left == 0)
              {
                     if (FD_ISSET(0, &fdr))
                     {
                            n=read(0, stdin_buf, sizeof(stdin_buf));

                            if (n > 0)
                            {
                                   stdin_ptr=stdin_buf;
                                   stdin_left=(size_t)n;
                            }
                     }
              }
              else if (FD_ISSET(fd, &fdw))
              {
                     n=write(fd, stdin_ptr, stdin_left);

                     if (n > 0)
                     {
                            stdin_ptr += n;
                            stdin_left -= n;
                     }
              }

              if (n > 0)
              {
                     if (stdout_left == 0)
                     {
                            if (FD_ISSET(fd, &fdr))
                            {
                                   n=read(fd, stdout_buf,
                                          sizeof(stdout_buf));
                            
                                   if (n > 0)
                                   {
                                          stdout_ptr=stdout_buf;
                                          stdout_left=(size_t)n;
                                   }
                            }
                     } else if (FD_ISSET(1, &fdw))
                     {
                            n=write(1, stdout_ptr, stdout_left);

                            if (n > 0)
                            {
                                   stdout_ptr += n;
                                   stdout_left -= n;
                            }
                     }
              }
       } while (n > 0);

       if (n < 0)
              courier_authdebug_printf("%s", strerror(errno));
}

Here is the caller graph for this function: