Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Nedeľa, 25. október 2026

Rozdiely pre dead/mail2sms/http.c medzi verziami 1.10 a 1.11

verzia 1.10, 2001/10/30 18:18:12 verzia 1.11, 2001/11/12 16:08:00
Riadok 1 
Riadok 1 
 /*  /*
  * Author: Lubomir Host 'rajo' <host8@kepler.fmph.uniba.sk>   * Author: Lubomir Host 'rajo' <host8@kepler.fmph.uniba.sk>
  * $Log$   * $Log$
    * Revision 1.11  2001/11/12 16:08:00  host8
    * Big improvements in http. connect() doesn't work correctly yet.
    *
  * Revision 1.10  2001/10/30 18:18:12  jombik9   * Revision 1.10  2001/10/30 18:18:12  jombik9
  * Improvements.   * Improvements.
  *   *
Riadok 31 
Riadok 34 
 #include <netinet/in.h>  #include <netinet/in.h>
 #include <arpa/inet.h>  #include <arpa/inet.h>
 #include <netdb.h>  #include <netdb.h>
   #include <errno.h>
   
 #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
 #  include "config.h"  #  include "config.h"
 #endif  #endif
 #include "mail2sms.h"  #include "mail2sms.h"
 #include "strings.h"  #include "strings.h"
   #include "strdyn.h"
 #include "http.h"  #include "http.h"
   
 static void http_set_cookie(HTTP_REQUEST *r, char *str);  static void free_cookie(COOKIE *c);
   static COOKIE *new_cookie(void);
   static COOKIE *duplicate_cookie(COOKIE *c);
   static COOKIE **add_to_cookies(COOKIE **coo, COOKIE *c);
   static char * get_cookie(HTTP_REQUEST *r);
   static int get_size_cookies(COOKIE **coo);
   static void http_set_cookie(char *str);
 static void free_request(HTTP_REQUEST *r);  static void free_request(HTTP_REQUEST *r);
 static void free_requests(HTTP_REQUEST **req);  
 static int get_size_requests(HTTP_REQUEST **req);  static int get_size_requests(HTTP_REQUEST **req);
 static HTTP_REQUEST **create_requests(void);  static HTTP_REQUEST **create_requests(void);
 static HTTP_REQUEST *new_request(void);  static HTTP_REQUEST *new_request(void);
 static HTTP_REQUEST *duplicate_request(const HTTP_REQUEST *r);  static HTTP_REQUEST *duplicate_request(HTTP_REQUEST *r);
 static HTTP_REQUEST **add_to_requests(HTTP_REQUEST **req, const HTTP_REQUEST *r);  static HTTP_REQUEST **add_to_requests(HTTP_REQUEST **req, HTTP_REQUEST *r);
 static char *get_http_referer(HTTP_REQUEST **req);  static char *get_http_referer(HTTP_REQUEST **req);
 static char *get_cookie(HTTP_REQUEST *r);  
   
 HTTP_REQUEST **requests;  HTTP_REQUEST **requests;
   COOKIE **cookies;
   
 // GetAddrInfo(const char *str, int port) {{{  /*
   // static struct addrinfo *GetAddrInfo(const char *str, int port) {{{
 static struct addrinfo *GetAddrInfo(const char *host, int port)  static struct addrinfo *GetAddrInfo(const char *host, int port)
 {  {
         struct addrinfo hints, *res;  struct addrinfo hints, *res;
         int error;  int error;
   
         memset(&hints, 0, sizeof(hints));  memset(&hints, 0, sizeof(hints));
         hints.ai_family = PF_UNSPEC;  hints.ai_family = PF_UNSPEC;
         hints.ai_socktype = SOCK_STREAM;  hints.ai_socktype = SOCK_STREAM;
         error = getaddrinfo(host, "80", &hints, &res);  error = getaddrinfo(host, "80", &hints, &res);
         if (error || !res) {  if (error || !res) {
                 fprintf(stderr, "GetAddrInfo: getaddrinfo(%s, %d): %s\n", host, port,  fprintf(stderr, "GetAddrInfo: getaddrinfo(%s, %d): %s\n", host, port,
                                                                 strerror(error));  strerror(error));
                 res = NULL;  res = NULL;
         }  }
   
   return res;
   } // }}}
    */
   // static void free_cookie(COOKIE *c) {{{
   static void free_cookie(COOKIE *c)
   {
           free(c->domain);
           free(c->text);
           free(c);
   }
   // }}}
   // static COOKIE **create_cookies(void) {{{
   static COOKIE **create_cookies(void)
   {
           register COOKIE **coo;
   
         return res;          if ((coo = (COOKIE **) malloc(1 * sizeof(COOKIE *))) == NULL)
                   return NULL;
   
           coo[0] = NULL;
   
           return (coo);
 } // }}}  } // }}}
 // http_set_cookie(HTTP_REQUEST *r, char *str) {{{  // static COOKIE *new_cookie(void) {{{
 static void http_set_cookie(HTTP_REQUEST *r, char *str)  static COOKIE *new_cookie(void)
 {  {
           COOKIE *new;
   
           new = (COOKIE *) malloc(1*sizeof(COOKIE));
           new->domain = NULL;
           new->text = NULL;
   
           return (new);
   } // }}}
   // static COOKIE *duplicate_cookie(COOKIE *c) {{{
   static COOKIE *duplicate_cookie(COOKIE *c)
   {
           COOKIE *new;
   
           if (c == NULL)
                   return (NULL);
           if ((new = new_cookie()) == NULL)
                   return (NULL);
   
           if (c->domain != NULL)
                   new->domain = strdup(c->domain);
           if (c->text != NULL)
                   new->text = strdup(c->text);
   
           return (new);
   } // }}}
   // static COOKIE **add_to_cookies(COOKIE **coo, COOKIE *r) {{{
   static COOKIE **add_to_cookies(COOKIE **coo, COOKIE *c)
   {
           register int count;
   
           if (coo == NULL)
                   if ((coo = create_cookies()) == NULL)
                           return NULL;
           if (c == NULL)
                   return (coo);
   
           count = get_size_cookies(coo);
   
           coo = (COOKIE **) realloc(coo, (count + 2) * sizeof(COOKIE *));
           if (coo == NULL)
                   return NULL;
   
           coo[count] = c;
           coo[count + 1] = NULL;
   
           return coo;
   } // }}}
   // static COOKIE *parse_cookie(char *str) {{{
   static COOKIE *parse_cookie(char *str)
   {
           COOKIE *c;
           char **array;
           int i;
         /* Cookies {{{          /* Cookies {{{
            read(4, "HTTP/1.1 302 Object moved\r\nServer: Microsoft-IIS/5.0\r\nDate: Mon, 22 Oct 2001 16:43:36 GMT\r\nLocation: http://www4.mtnsms.com/members/contacts/contacts.asp\r\nConnection: Keep-Alive\r\nContent-Length: 173\r\nContent-Type: text/html\r\nExpires: Mon, 22 Oct 2001 16:43:36 GMT\r\nSet-Cookie: mtnsms%2Ep%2E2=color=0&cn=rajo%40host%2Esk&akey=; expires=Sat, 22-Oct-2011 16:43:36 GMT; domain=.mtnsms.com; path=/\r\nSet-Cookie: mtnsms%2Et%2E2=skey=178A2593%2D5FA7%2D406B%2D8DE9%2D5EA0B8A4BB15; domain=.mtnsms.com; path=/\r\nCache-control: private\r\n\r\n<head><title>Object moved</title></head>\n<body><h1>Object Moved</h1>This object may be found <a HREF=\"http://www4.mtnsms.com/members/contacts/contacts.asp\">here</a>.</body>\n", 1535) = 699             read(4, "HTTP/1.1 302 Object moved\r\n
            Accept-Language: en\r\nUser-Agent: Lynx/2.8.4dev.7 libwww-FM/2.14\r\nReferer: http://www.mtnsms.com/\r\nCookie2: $Version=\"1\"\r\nCookie: mtnsms%2Ep%2E2=color=0&cn=rajo%40host%2Esk&akey=; mtnsms%2Et%2E2=skey=178A2593%2D5FA7%2D406B%2D8DE9%2D5EA0B8A4BB15\r\n\r\n", 747) = 747  Server: Microsoft-IIS/5.0\r\n
         *  }}} Cookies */  Date: Mon, 22 Oct 2001 16:43:36 GMT\r\n
   Location: http://www4.mtnsms.com/members/contacts/contacts.asp\r\n
   Connection: Keep-Alive\r\n
   Content-Length: 173\r\n
   Content-Type: text/html\r\n
   Expires: Mon, 22 Oct 2001 16:43:36 GMT\r\n
   Set-Cookie: mtnsms%2Ep%2E2=color=0&cn=rajo%40host%2Esk&akey=; expires=Sat, 22-Oct-2011 16:43:36 GMT; domain=.mtnsms.com; path=/\r\n
   Set-Cookie: mtnsms%2Et%2E2=skey=178A2593%2D5FA7%2D406B%2D8DE9%2D5EA0B8A4BB15; domain=.mtnsms.com; path=/\r\n
   Cache-control: private\r\n\r\n
   
   Accept-Language: en\r\nUser-Agent: Lynx/2.8.4dev.7 libwww-FM/2.14\r\n
   Referer: http://www.mtnsms.com/\r\n
   Cookie2: $Version=\"1\"\r\n
   Cookie: mtnsms%2Ep%2E2=color=0&cn=rajo%40host%2Esk&akey=; mtnsms%2Et%2E2=skey=178A2593%2D5FA7%2D406B%2D8DE9%2D5EA0B8A4BB15\r\n\r\n", 747) = 747
            *  }}} Cookies */
   
           c = new_cookie();
           array = strdyn_explode_chr(str, ';');
   
           for (i=0; array[i] != NULL; i++) {
                   char *tmp;
   
   #ifdef DEBUG
                   if (debug > 7)
                           fprintf(stderr, "parsed_cookie[%d] = '%s'\n", i, array[i]);
   #endif
   
                   tmp = array[i];
                   if (tmp == strstr(tmp, " domain=")) {
                           c->domain = strdup(tmp+8);
                   }
                   else if (tmp == strstr(tmp, " expires=")) {
                           /* ignored */
                   }
                   else if (tmp == strstr(tmp, " path=")) {
                           /* ignored */
                   }
                   else {
   #ifdef DEBUG
                           if (debug >7)
                                   fprintf(stderr, "cookies->text-old = '%s'", c->text);
   #endif
                           if (c->text == NULL)
                                   c->text = strdup(tmp);
                           else {
                                   char *ar[2];
   
                                   ar[0] = c->text, ar[1] = tmp;
                                   c->text = strdyn_implode_str(ar, "");
                           }
   #ifdef DEBUG
                           if (debug >7)
                                   fprintf(stderr, " new = '%s'\n", c->text);
   #endif
                   }
           }
   
           return (c);
   } // }}}
   // static char * get_cookie(HTTP_REQUEST *r) {{{
   static char *get_cookie(HTTP_REQUEST *r)
   {
           int i;
           int count;
           char *str = NULL;
   
           count = get_size_cookies(cookies);
   #ifdef DEBUG
           fprintf(stderr, "count = %d in get_cookie()\n", count);
   #endif
           for (i=(count-1); i >= 0; i--) {
                   if (cookies[i] != NULL &&
                                                                   cookies[i]->domain != NULL &&
                                                                   strstr(r->host, cookies[i]->domain)
                                                                   != NULL) {
                           str = cookies[i]->text;
                           break;
                   }
           }
   
           return (str);
   }
   // }}}
   // static int get_size_cookies(COOKIE **coo) {{{
   static int get_size_cookies(COOKIE **coo)
   {
           register int i;
   
           for (i = 0; coo[i] != NULL; i++)
                   ;
   
           return i;
   } // }}}
   // static void http_set_cookie(char *str) {{{
   static void http_set_cookie(char *str)
   {
         if (str != NULL) {          if (str != NULL) {
                 if (str == strstr("Set-Cookie: ", str)) {                  if (str == strstr("Set-Cookie: ", str)) {
                         r->cookies = strdup(str + 13);                          cookies = add_to_cookies(cookies, parse_cookie(str + 12));
                 }                  }
         }          }
 } // }}}  } // }}}
   // static void free_request(HTTP_REQUEST *r) {{{
   static void free_request(HTTP_REQUEST *r)
   {
           free(r->ret_val);
           free(r->host);
           free(r->file);
           free(r);
   }
   // }}}
   // static int get_size_requests(HTTP_REQUEST **req) {{{
   static int get_size_requests(HTTP_REQUEST **req)
   {
           register int i;
   
           for (i = 0; req[i] != NULL; i++)
                   ;
   
           return i;
   } // }}}
   // static HTTP_REQUEST **create_requests(void) {{{
   static HTTP_REQUEST **create_requests(void)
   {
           register HTTP_REQUEST **req;
   
           if ((req = (HTTP_REQUEST **) malloc(1 * sizeof(HTTP_REQUEST *))) == NULL)
                   return NULL;
   
           req[0] = NULL;
   
           return (req);
   } // }}}
   // static HTTP_REQUEST *new_request(void) {{{
   static HTTP_REQUEST *new_request(void)
   {
           HTTP_REQUEST *new;
   
           new = (HTTP_REQUEST *) malloc(1*sizeof(HTTP_REQUEST));
   
           return (new);
   } // }}}
   // static HTTP_REQUEST *duplicate_request(HTTP_REQUEST *r) {{{
   static HTTP_REQUEST *duplicate_request(HTTP_REQUEST *r)
   {
           HTTP_REQUEST *new;
   
           if (r == NULL)
                   return (NULL);
           if ((new = new_request()) == NULL)
                   return (NULL);
   
           new->frw = r->frw;
           new->method = r->method;
           new->port = r->port;
           fprintf(stderr, "%d - OK\n", __LINE__);
           if (r->ret_val != NULL)
                   new->ret_val = strdup(r->ret_val);
           else
                   new->ret_val = NULL;
           fprintf(stderr, "%d - OK\n", __LINE__);
           if (r->host != NULL)
                   new->host = strdup(r->host);
           else
                   new->host = NULL;
           fprintf(stderr, "%d - OK\n", __LINE__);
           if (r->file != NULL)
                   new->file = strdup(r->file);
           else
                   new->file = NULL;
           fprintf(stderr, "%d - OK\n", __LINE__);
   
           return (new);
   } // }}}
   // static HTTP_REQUEST **add_to_requests(HTTP_REQUEST **req, HTTP_REQUEST *r) {{{
   static HTTP_REQUEST **add_to_requests(HTTP_REQUEST **req, HTTP_REQUEST *r)
   {
           register int count;
   
           if (req == NULL)
                   if ((req = create_requests()) == NULL)
                           return NULL;
   
           count = get_size_requests(req);
   
           req = (HTTP_REQUEST **) realloc(req, (count + 2) * sizeof(HTTP_REQUEST *));
           if (req == NULL)
                   return NULL;
   
           // req[count] = duplicate_request(r);
           req[count] = r;
           req[count + 1] = NULL;
   
           return req;
   } // }}}
   // static char * get_http_referer(HTTP_REQUEST **req) {{{
   static char *get_http_referer(HTTP_REQUEST **req)
   {
           int count;
   
           count = get_size_requests(req);
   
           if (count > 0) {
                   return (req[count -1]->host);
           }
   
           return (NULL);
   }
   // }}}
 // static http_connect(HTTP_REQUEST *r) {{{  // static http_connect(HTTP_REQUEST *r) {{{
 static FILE *http_connect(HTTP_REQUEST *r)  static FILE *http_connect(HTTP_REQUEST *r)
 {  {
         int s = 0;          int s = 0;
         int i, idx = -1;          int i, idx = -1;
         struct sockaddr_in serv_addr;          struct sockaddr_in serv_addr;
         struct addrinfo *res0;          //      struct addrinfo *res0;
   
         memset((char *) &serv_addr, 0, sizeof(serv_addr));  
         serv_addr.sin_family = AF_INET;  
         serv_addr.sin_port = htons((unsigned short int) r->port);  
   
         res0 = GetAddrInfo(r->host, r->port);          if (r == NULL || r->host == NULL)
         if (res0 == NULL) {  
                 fprintf(stderr, "Unable to locate remote host %s.", r->host);  
                 return (NULL);                  return (NULL);
         }  
   
         for (i=0; servers[i].desc != NULL; i++) {          for (i=0; servers[i].desc != NULL; i++) {
                 if (servers[i].id == id) {                  if (servers[i].id == id) {
Riadok 111  static FILE *http_connect(HTTP_REQUEST *
Riadok 391  static FILE *http_connect(HTTP_REQUEST *
                 fprintf(stderr, "Id %d not found in servers[] !\n", id);                  fprintf(stderr, "Id %d not found in servers[] !\n", id);
                 exit(1);                  exit(1);
         }          }
         if (r->host == NULL)  
                 serv_addr.sin_addr.s_addr = inet_addr(servers[idx].ip);          memset((char *) &serv_addr, 0, sizeof(serv_addr));
         else          serv_addr.sin_family = AF_INET;
                 serv_addr.sin_addr.s_addr = inet_addr(r->host);          serv_addr.sin_addr.s_addr = inet_addr(r->host);
         if (serv_addr.sin_addr.s_addr == INADDR_NONE) {          if (serv_addr.sin_addr.s_addr == INADDR_NONE) {
                 struct hostent *pent = gethostbyname(r->host);                  struct hostent *pent = gethostbyname(r->host);
                 if (pent != NULL)                  if (pent != NULL)
                         serv_addr.sin_addr.s_addr = *((u_long *) (pent->h_addr));                          serv_addr.sin_addr.s_addr = *((u_long *) (pent->h_addr));
         }          }
         if (serv_addr.sin_addr.s_addr == INADDR_NONE)          if (serv_addr.sin_addr.s_addr == INADDR_NONE) {
                 return NULL;                  fprintf(stderr, "Can't connect to %s[%s] - %s\n", servers[idx].desc,
                                                                   servers[idx].ip, strerror(errno));
                   return (NULL);
           }
   
           if (r->port != 0) {
                   serv_addr.sin_port = htons((u_short) r->port);
                   if (serv_addr.sin_port == 0) {
                           struct servent *pent;
                           char str_port[10];
   
                           if (snprintf(str_port, 9, "%d", r->port) == -1) {
                                   fprintf(stderr, "Can't connect to %s[%s] - %s\n",
                                                                                   servers[idx].desc,
                                                                                   servers[idx].ip, strerror(errno));
                                   return (NULL);
                           }
                           pent = getservbyname(str_port, "tcp");
                           if (pent != NULL)
                                   serv_addr.sin_port = pent->s_port;
                   }
                   if (serv_addr.sin_port == 0) {
                           fprintf(stderr, "Can't connect to %s[%s] - %s\n", servers[idx].desc,
                                                                           servers[idx].ip, strerror(errno));
                           return (NULL);
                   }
           }
           else {
                   // No port specified ... use telnet port. //
                   struct servent *pent = getservbyname ("www", "tcp");
                   if (pent == NULL)
                           serv_addr.sin_port = htons(23);
                   else
                           serv_addr.sin_port = pent->s_port;
           }
   
         s = socket(PF_INET, SOCK_STREAM, 0);          s = socket(PF_INET, SOCK_STREAM, 0);
   
         if (s != -1) {          if (s != -1) {
                 for (i=0; i<MAX_CONNECTS; i++) {                  for (i=0; i<MAX_CONNECTS; i++) {
                         if (connect(s, (struct sockaddr *)&serv_addr,                          if (connect(s, (struct sockaddr *)&serv_addr,
                                                                                 sizeof(serv_addr)) != -1)                                                                                  sizeof(serv_addr)) != -1) {
                                 break;                                  if ((r->frw = fdopen(s, "w+b")) != NULL)
                                           return (r->frw);
                           }
                 }                  }
                 if ((r->frw = fdopen(s, "w+b")) != NULL)  
                         return (r->frw);  
         }          }
         fprintf(stderr, "Can't connect to %s[%s]\n", servers[idx].desc,          else {
                                                         servers[idx].ip);                  fprintf(stderr, "Can't connect to %s[%s] - %s\n", servers[idx].desc,
                                                                   servers[idx].ip, strerror(errno));
                   return (NULL);
           }
   
           fprintf(stderr, "Can't connect to %s[%s] - %s\n", servers[idx].desc,
                                                           servers[idx].ip, strerror(errno));
           return (NULL);
   
   
         return(NULL);          /* povodny bordel {{{
              res0 = GetAddrInfo(r->host, r->port);
              if (res0 == NULL) {
              fprintf(stderr, "Unable to locate remote host %s.", r->host);
              return (NULL);
              }
   
              for (i=0; servers[i].desc != NULL; i++) {
              if (servers[i].id == id) {
              idx = i;
              break;
              }
              }
              if (idx == -1) {
              fprintf(stderr, "Id %d not found in servers[] !\n", id);
              exit(1);
              }
              if (r->host == NULL)
              serv_addr.sin_addr.s_addr = inet_addr(servers[idx].ip);
              else
              serv_addr.sin_addr.s_addr = inet_addr(r->host);
              if (serv_addr.sin_addr.s_addr == INADDR_NONE) {
              struct hostent *pent = gethostbyname(r->host);
              if (pent != NULL)
              serv_addr.sin_addr.s_addr = *((u_long *) (pent->h_addr));
              }
              if (serv_addr.sin_addr.s_addr == INADDR_NONE)
              return NULL;
              }}} */
           /****i* lib5250/telnet_stream_connect {{{
            * NAME
            *    telnet_stream_connect
            * SYNOPSIS
            *    ret = telnet_stream_connect (This, to);
            * INPUTS
            *    Tn5250Stream *       This       -
            *    const char *         to         -
            * DESCRIPTION
            *    Connects to server.  The `to' parameter is in the form
            *    host[:port].
            *****
            static int telnet_stream_connect(Tn5250Stream * This, const char *to)
            {
            struct sockaddr_in serv_addr;
            u_long ioctlarg = 1;
            char *address;
            int r;
   
            memset((char *) &serv_addr, 0, sizeof(serv_addr));
            serv_addr.sin_family = AF_INET;
   
           // Figure out the internet address. //
           address = (char *)malloc (strlen (to)+1);
           strcpy (address, to);
           if (strchr (address, ':'))
            *strchr (address, ':') = '\0';
   
            serv_addr.sin_addr.s_addr = inet_addr(address);
            if (serv_addr.sin_addr.s_addr == INADDR_NONE) {
            struct hostent *pent = TN_GETHOSTBYNAME(address);
            if (pent != NULL)
           serv_addr.sin_addr.s_addr = *((u_long *) (pent->h_addr));
   }
   g_free (address);
   if (serv_addr.sin_addr.s_addr == INADDR_NONE)
           return LAST_ERROR;
   
           // Figure out the port name. //
           if (strchr (to, ':') != NULL) {
                   const char *port = strchr (to, ':') + 1;
                   serv_addr.sin_port = htons((u_short) atoi(port));
                   if (serv_addr.sin_port == 0) {
                           struct servent *pent = getservbyname(port, "tcp");
                           if (pent != NULL)
                                   serv_addr.sin_port = pent->s_port;
                   }
                   if (serv_addr.sin_port == 0)
                           return LAST_ERROR;
           } else {
                   // No port specified ... use telnet port. //
                   struct servent *pent = getservbyname ("telnet", "tcp");
                   if (pent == NULL)
                           serv_addr.sin_port = htons(23);
                   else
                           serv_addr.sin_port = pent->s_port;
           }
   
   This->sockfd = socket(PF_INET, SOCK_STREAM, 0);
   if (WAS_INVAL_SOCK(This->sockfd)) {
           return LAST_ERROR;
   }
   r = TN_CONNECT(This->sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
   if (WAS_ERROR_RET(r)) {
           return LAST_ERROR;
   }
   // Set socket to non-blocking mode. //
   #ifdef FIONBIO
   TN5250_LOG(("Non-Blocking\n"));
   TN_IOCTL(This->sockfd, FIONBIO, &ioctlarg);
   #endif
   
   This->state = TN5250_STREAM_STATE_DATA;
   return 0;
   } // }}}
   */
 } // }}}  } // }}}
 // static void http_read_source(HTTP_REQUEST *r) {{{  // static void http_read_source(HTTP_REQUEST *r) {{{
 static void http_read_source(HTTP_REQUEST *r)  static void http_read_source(HTTP_REQUEST *r)
Riadok 217  static void http_read_source(HTTP_REQUES
Riadok 643  static void http_read_source(HTTP_REQUES
                 }                  }
 #endif  #endif
                 if (buf == strstr(buf, "Set-Cookie: "))                  if (buf == strstr(buf, "Set-Cookie: "))
                         http_set_cookie(r, buf);                          http_set_cookie(buf);
         }          }
 #ifdef DEBUG  #ifdef DEBUG
         if (search_for_link == 1) {          if (search_for_link == 1) {
Riadok 247  int http_request(int method, char *file,
Riadok 673  int http_request(int method, char *file,
         r->file = strdup(file);          r->file = strdup(file);
         requests = add_to_requests(requests, r);          requests = add_to_requests(requests, r);
   
         if ((r->frw = http_connect(r)) == NULL)          if ((r->frw = http_connect(r)) == NULL) {
                 return(-1);                  exit(errno);
           }
 #ifdef DEBUG  #ifdef DEBUG
         if (debug) { // Debug code STAHUJEM/POSIELAM {{{          if (debug) { // Debug code STAHUJEM/POSIELAM {{{
                 if (method == HTTP_GET) {                  if (method == HTTP_GET) {
Riadok 306  int http_request(int method, char *file,
Riadok 733  int http_request(int method, char *file,
         }          }
         fprintf(r->frw, "\r\n");          fprintf(r->frw, "\r\n");
         http_read_source(r);          http_read_source(r);
         /*  
         if (g.goto_object_moved != NULL) {  
                 char *tmp_host;  
                 char *tmp_file;  
   
                 if ((tmp_file = strstr((g.goto_object_moved+17), "/")) != NULL) {  
                 tmp_host = (char *)  
                 malloc ((tmp_file-g.goto_object_moved-16)*sizeof(char));  
                 strncpy(tmp_host, (g.goto_object_moved+17),  
                 (tmp_file-g.goto_object_moved-17));  
                 my_free(g.goto_object_moved);  
                 http_request(HTTP_GET, tmp_file, tmp_host, NULL);  
                 my_free(tmp_host);  
                 } else {  
 #ifdef DEBUG  
 fprintf(stderr, "Invalid link '%s'!\n", g.goto_object_moved);  
 #endif  
 }  
 my_free(g.goto_object_moved);  
 }  
 */  
 #ifdef DEBUG  #ifdef DEBUG
         if (debug) {          if (debug) {
                 fprintf(stderr, "HTTP request sent, reply OK...\n");                  fprintf(stderr, "HTTP request sent, reply OK...\n");
         }          }
 #endif  #endif
 return 0;          return 0;
 } // }}}  } // }}}
 // static void free_request(HTTP_REQUEST *r) {{{  // void http_init(void) {{{
 static void free_request(HTTP_REQUEST *r)  void http_init(void)
 {  {
         free(r->ret_val);          if ((requests = create_requests()) == NULL) {
         free(r->host);                  fprintf(stderr, "Failed creation of internal structures!\n");
         free(r->file);                  exit(1);
         free(r->cookies);          }
         free(r);          if ((cookies = create_cookies()) == NULL) {
                   fprintf(stderr, "Failed creation of internal structures!\n");
                   exit(1);
           }
   
           return;
 }  }
 // }}}  // }}}
 // static void free_requests(HTTP_REQUEST **req) {{{  // void free_requests(HTTP_REQUEST **req) {{{
 static void free_requests(HTTP_REQUEST **req)  void free_requests(HTTP_REQUEST **req)
 {  {
         register int i;          register int i;
   
Riadok 355  static void free_requests(HTTP_REQUEST *
Riadok 766  static void free_requests(HTTP_REQUEST *
         free(req);          free(req);
 }  }
 // }}}  // }}}
 // static int get_size_requests(HTTP_REQUEST **req) {{{  
 static int get_size_requests(HTTP_REQUEST **req)  
 {  
         register int i;  
   
         for (i = 0; req[i] != NULL; i++)  
                 ;  
   
         return i;  
 } // }}}  
 // static HTTP_REQUEST **create_requests(void) {{{  
 static HTTP_REQUEST **create_requests(void)  
 {  
         register HTTP_REQUEST **req;  
   
         if ((req = (HTTP_REQUEST **) malloc(1 * sizeof(HTTP_REQUEST *))) == NULL)  
                 return NULL;  
   
         req[0] = NULL;  
   
         return req;  
 } // }}}  
 // static HTTP_REQUEST *new_request(void) {{{  
 static HTTP_REQUEST *new_request(void)  
 {  
         HTTP_REQUEST *new;  
   
         new = (HTTP_REQUEST *) malloc(1*sizeof(HTTP_REQUEST));  
   
         return (new);  
 } // }}}  
 // static HTTP_REQUEST *duplicate_request(HTTP_REQUEST *r) {{{  
 static HTTP_REQUEST *duplicate_request(const HTTP_REQUEST *r)  
 {  
         HTTP_REQUEST *new;  
   
         if( r == NULL)  
                 return (NULL);  
         if ((new = (HTTP_REQUEST *) malloc(1*sizeof(HTTP_REQUEST))) == NULL)  
                 return (NULL);  
   
         new->frw = r->frw;  
         new->method = r->method;  
         new->port = r->port;  
         if (r->ret_val != NULL)  
                 new->ret_val = strdup(r->ret_val);  
         else  
                 new->ret_val = NULL;  
         if (r->host != NULL)  
                 new->host = strdup(r->host);  
         else  
                 new->host = NULL;  
         if (r->file != NULL)  
                 new->file = strdup(r->file);  
         else  
                 new->file = NULL;  
         if (r->cookies != NULL)  
                 new->cookies = strdup(r->cookies);  
         else  
                 new->cookies = NULL;  
   
         return (new);  
 } // }}}  
 // static HTTP_REQUEST **add_to_requests(HTTP_REQUEST **req, const HTTP_REQUEST *r) {{{  
 static HTTP_REQUEST **add_to_requests(HTTP_REQUEST **req, const HTTP_REQUEST *r)  
 {  
         register int count;  
   
         if (req == NULL)  
                 if ((req = create_requests()) == NULL)  
                         return NULL;  
   
         count = get_size_requests(req);  
   
         req = (HTTP_REQUEST **) realloc(req, (count + 2) * sizeof(HTTP_REQUEST *));  
         if (req == NULL)  
                 return NULL;  
   
         req[count] = duplicate_request(r);  
         req[count + 1] = NULL;  
   
         return req;  
 } // }}}  
 // static char * get_http_referer(HTTP_REQUEST **req) {{{  
 static char *get_http_referer(HTTP_REQUEST **req)  
 {  
         int count;  
   
         count = get_size_requests(req);  
   
         if (count > 0) {  
                 return (req[count -1]->host);  
         }  
   
         return (NULL);  
 }  
 // }}}  
 // static char * get_cookie(HTTP_REQUEST *r) {{{  
 static char *get_cookie(HTTP_REQUEST *r)  
 {  
         int i;  
         int count;  
   
         count = get_size_requests(requests);  
 #ifdef DEBUG  
         fprintf(stderr, "count = %d in get_cookie()\n", count);  
 #endif  
         for (i=(count-1); i >= 0; i--) {  
                 if (strcmp(requests[i]->host, r->host) == 0 &&  
                                                                 r->cookies != NULL) {  
                         r->cookies = requests[i]->cookies;  
                         break;  
                 }  
         }  
   
         return (r->cookies);  
 }  
 // }}}  
 // void http_init(void) {{{  
 void http_init(void)  
 {  
         if ((requests = create_requests()) == NULL) {  
                 fprintf(stderr, "Failed creation of internal structures!\n");  
                 exit(1);  
         }  
   
         return;  
 }  
 // }}}  
 /* Modeline for ViM {{{1  /* Modeline for ViM {{{1
  * vim:set ts=4:   * vim:set ts=4:
  * vim600:fdm=marker fdl=0 fdc=3:   * vim600:fdm=marker fdl=0 fdc=3:

Legend:
Odstranené z verzie1.10  
zmenené riadky
  Pridané vo verzii1.11

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok