1 |
/* wptHTTP.cpp - Generic HTTP support |
/* wptHTTP.cpp - Generic HTTP support |
2 |
* Copyright (C) 2004, 2005, 2006 Timo Schulz |
* Copyright (C) 2004, 2005, 2006, 2007 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
54 |
wHTTP::wHTTP (const char *_url) |
wHTTP::wHTTP (const char *_url) |
55 |
{ |
{ |
56 |
reset (); |
reset (); |
57 |
|
open (_url); |
58 |
|
} |
59 |
|
|
|
if (extractHostInfo (_url, &this->host, &this->url)) |
|
|
return; |
|
60 |
|
|
61 |
/* FIXME: we should throw an exception in case of an error. */ |
/* Open a connection to the given URL. */ |
62 |
|
int |
63 |
|
wHTTP::open (const char *_url) |
64 |
|
{ |
65 |
|
releaseMem (); |
66 |
|
|
67 |
|
if (extractHostInfo (_url, &this->host, &this->url)) |
68 |
|
return -1; |
69 |
|
|
70 |
if (!sendRequest (this->host, this->port, this->url)) |
if (!sendRequest (this->host, this->port, this->url)) |
71 |
parseResponse (&statcode); |
return parseResponse (&statcode); |
72 |
|
|
73 |
|
return 0; |
74 |
} |
} |
75 |
|
|
76 |
|
|
559 |
} |
} |
560 |
|
|
561 |
|
|
562 |
/* Destroy HTTP object. */ |
/* Release all used structures. */ |
563 |
wHTTP::~wHTTP (void) |
void |
564 |
|
wHTTP::releaseMem (void) |
565 |
{ |
{ |
566 |
http_head_t h; |
http_head_t h; |
567 |
|
|
570 |
free (resp_headers); |
free (resp_headers); |
571 |
resp_headers = h; |
resp_headers = h; |
572 |
} |
} |
573 |
|
resp_headers = NULL; |
574 |
while (req_headers) { |
while (req_headers) { |
575 |
h = req_headers->next; |
h = req_headers->next; |
576 |
free (req_headers); |
free (req_headers); |
577 |
req_headers = h; |
req_headers = h; |
578 |
} |
} |
579 |
|
req_headers = NULL; |
580 |
safe_free (url); |
safe_free (url); |
581 |
safe_free (host); |
safe_free (host); |
582 |
|
} |
583 |
|
|
584 |
|
|
585 |
|
/* Destroy HTTP object. */ |
586 |
|
wHTTP::~wHTTP (void) |
587 |
|
{ |
588 |
|
releaseMem (); |
589 |
if (fd != 0) { |
if (fd != 0) { |
590 |
closesocket (fd); |
closesocket (fd); |
591 |
fd = 0; |
fd = 0; |