/[winpt]/trunk/Src/wptHTTP.cpp
ViewVC logotype

Diff of /trunk/Src/wptHTTP.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 260 by twoaday, Wed Aug 16 10:01:30 2006 UTC revision 262 by twoaday, Sat Sep 30 10:24:34 2006 UTC
# Line 12  Line 12 
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   * General Public License for more details.   * General Public License for more details.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
15   */   */
16  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
17  #include <config.h>  #include <config.h>
# Line 58  wHTTP::wHTTP (const char *_host, int _po Line 54  wHTTP::wHTTP (const char *_host, int _po
54  wHTTP::wHTTP (const char *_url)  wHTTP::wHTTP (const char *_url)
55  {  {
56      reset ();      reset ();
57      extractHostInfo (_url, &this->host, &this->url);  
58      /* XXX: if the connection fails, return the error code to the user. */      if (extractHostInfo (_url, &this->host, &this->url))
59            return;    
60    
61        /* FIXME: we should throw an exception in case of an error. */
62      if (!sendRequest (this->host, this->port, this->url))      if (!sendRequest (this->host, this->port, this->url))
63          parseResponse (&statcode);          parseResponse (&statcode);
64  }  }
# Line 84  wHTTP::reset (void) Line 83  wHTTP::reset (void)
83  int  int
84  wHTTP::head (const char *_url)  wHTTP::head (const char *_url)
85  {  {
86        int err;
87    
88      safe_free (host);      safe_free (host);
89      safe_free (url);      safe_free (url);
90    
91      extractHostInfo (_url, &this->host, &this->url);      err = extractHostInfo (_url, &this->host, &this->url);
92        if (err)
93            return err;
94      method = HTTP_HEAD;      method = HTTP_HEAD;
95    
96      if (!sendRequest (host, port, url))      if (!sendRequest (host, port, url))
# Line 101  wHTTP::head (const char *_url) Line 104  wHTTP::head (const char *_url)
104  int  int
105  wHTTP::get (const char *_url)  wHTTP::get (const char *_url)
106  {  {
107        int err;
108    
109      safe_free (host);      safe_free (host);
110      safe_free (url);      safe_free (url);
111    
112      extractHostInfo (_url, &this->host, &this->url);      err = extractHostInfo (_url, &this->host, &this->url);
113        if (err)
114            return err;
115    
116      method = HTTP_GET;      method = HTTP_GET;
117      if (!sendRequest (this->host, this->port, this->url))      if (!sendRequest (this->host, this->port, this->url))
# Line 310  wHTTP::readLine (char *buf, unsigned int Line 317  wHTTP::readLine (char *buf, unsigned int
317     @host and also return the resource part of the url in @new_url. */     @host and also return the resource part of the url in @new_url. */
318  int  int
319  wHTTP::extractHostInfo (const char *_url, char **_host, char **new_url)  wHTTP::extractHostInfo (const char *_url, char **_host, char **new_url)
320  {  {  
321        char tmpbuf[2*MAX_PATH+1];
322      char *p;      char *p;
     char tmpbuf[512];  
323    
324      *_host = NULL;      *_host = NULL;
325      *new_url = NULL;      *new_url = NULL;
# Line 328  wHTTP::extractHostInfo (const char *_url Line 335  wHTTP::extractHostInfo (const char *_url
335      p = strtok (tmpbuf+7, "/");      p = strtok (tmpbuf+7, "/");
336      if (!p)      if (!p)
337          return WPTERR_GENERAL;          return WPTERR_GENERAL;
338      *_host = strdup (p);      *_host = strdup (p);  
339      p = strchr (_url, '/');      p = strchr (_url, '/');
340      if (!p) {      if (!p) /* document were given so we assume the root '/'. */
341          safe_free (*_host);          *new_url = strdup ("/");
342          return WPTERR_GENERAL;      else
343      }          *new_url = strdup (p);
     *new_url = strdup (p);  
344      return 0;      return 0;
345  }  }
346    
# Line 434  wHTTP::parseHeaders (http_head_t *r_head Line 440  wHTTP::parseHeaders (http_head_t *r_head
440          return WPTERR_GENERAL;          return WPTERR_GENERAL;
441    
442      do  {      do  {
443          rc = readLine (buf, 299, 1, &nn, NULL);          rc = readLine (buf, DIM (buf)-1, 1, &nn, NULL);
444          if (rc)          if (rc)
445              return rc;              return rc;
446          if (nn == 2)          if (nn == 2)
# Line 483  wHTTP::readData (FILE *out) Line 489  wHTTP::readData (FILE *out)
489      }      }
490    
491      do {      do {
492          rc = readLine (buf, sizeof (buf)-1, 1, &n, &eof);          rc = readLine (buf, DIM (buf)-1, 1, &n, &eof);
493          if (rc)          if (rc)
494              return rc;              return rc;
495          if (n > 0)          if (n > 0)

Legend:
Removed from v.260  
changed lines
  Added in v.262

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26