summaryrefslogtreecommitdiff
path: root/bsp
diff options
context:
space:
mode:
authorbernard.xiong <[email protected]>2009-10-09 16:02:20 +0000
committerbernard.xiong <[email protected]>2009-10-09 16:02:20 +0000
commitdf1d469cd05809209b7795472adfb2eb4f9824ca (patch)
treeae69053b028fe62baa98bbbe115436202ba38c23 /bsp
parente30e7152cb390542f14cb9922a03f68be2b3bc03 (diff)
fix http client code for host address parse
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@83 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'bsp')
-rw-r--r--bsp/stm32_radio/http.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/bsp/stm32_radio/http.c b/bsp/stm32_radio/http.c
index e430ddf5da..1ccef9a751 100644
--- a/bsp/stm32_radio/http.c
+++ b/bsp/stm32_radio/http.c
@@ -121,7 +121,7 @@ const char *http_resolve_address( struct sockaddr_in *server, const char * url,
{
char *ptr;
char port[6] = "80"; /* default port of 80(HTTP) */
- int i = 0, rv;
+ int i = 0, rv, is_domain;
/* strip http: */
ptr = strchr(url, ':');
@@ -133,14 +133,11 @@ const char *http_resolve_address( struct sockaddr_in *server, const char * url,
/* URL must start with double forward slashes. */
if((url[0] != '/') || (url[1] != '/' )) return(NULL);
- url += 2;
+ url += 2; is_domain = 0;
for(i = 0; ((url[i] != '\0') && (url[i] != '/')) && (i < 30); i++)
{
if((((host_addr[i] = url[i]) < '0') || (url[i] > '9')) && (url[i] != '.'))
{
- /* get host addr ok. */
- host_addr[i] = '\0';
-
if(url[i] == ':')
{
unsigned char w;
@@ -149,29 +146,31 @@ const char *http_resolve_address( struct sockaddr_in *server, const char * url,
port[w] = url[w + i + 1];
port[w] = '\0';
- inet_aton(host_addr, (struct in_addr*)&(server->sin_addr));
- /* set the port */
- server->sin_port = htons((int) strtol(port, NULL, 10));
-
rt_kprintf("HTTP: using port %s for connection\n", port);
break;
}
- else
- {
- /* set the port */
- server->sin_port = htons((int) strtol(port, NULL, 10));
-
- /* resolve the host name. */
- rv = dns_gethostbyname(host_addr, &server->sin_addr, RT_NULL, RT_NULL);
- if(rv != 0)
- {
- rt_kprintf("HTTP: failed to resolve domain '%s'\n", host_addr);
- return RT_NULL;
- }
- }
+ else is_domain = 1;
}
}
+ /* get host addr ok. */
+ host_addr[i] = '\0';
+ inet_aton(host_addr, (struct in_addr*)&(server->sin_addr));
+ if (!is_domain)
+ {
+ /* set the port */
+ server->sin_port = htons((int) strtol(port, NULL, 10));
+ }
+ else
+ {
+ /* resolve the host name. */
+ rv = dns_gethostbyname(host_addr, &server->sin_addr, RT_NULL, RT_NULL);
+ if(rv != 0)
+ {
+ rt_kprintf("HTTP: failed to resolve domain '%s'\n", host_addr);
+ return RT_NULL;
+ }
+ }
server->sin_family = AF_INET;
while (*url != '/') url ++;
@@ -265,7 +264,7 @@ struct http_session* http_session_open(char* url)
char host_addr[32];
struct http_session* session;
- session = (struct http_session*) rt_malloc(sizeof(struct http_session*));
+ session = (struct http_session*) rt_malloc(sizeof(struct http_session));
if(session == RT_NULL) return RT_NULL;
session->size = 0;