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> |
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 |
} |
} |
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)) |
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)) |
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; |
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 |
|
|
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) |
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) |