From 95c14b735e08d5350a43722b4b02889c4f0c6c2a Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Wed, 20 Jun 2007 02:24:13 +0200 Subject: [PATCH] Should parse URLs correctly. --- common/http.c | 34 ++++++++++++++++++++++++++++++++++ include/http.h | 7 ++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/common/http.c b/common/http.c index 0924367..3342a60 100644 --- a/common/http.c +++ b/common/http.c @@ -20,9 +20,43 @@ #include #include #include +#include #include #ifdef HAVE_CONFIG_H #include #endif +#include +#include +struct hturlinfo *parseurl(char *url) +{ + char *p, *p2, *p3; + struct hturlinfo *ui; + + if(strncmp(url, "http://", 7)) + return(NULL); + ui = memset(smalloc(sizeof(*ui)), 0, sizeof(*ui)); + p = url + 7; + if((p2 = strchr(p, '/')) != NULL) + *(p2++) = 0; + if((p3 = strrchr(p, ':')) != NULL) { + *(p3++) = 0; + ui->port = atoi(p3); + } + ui->host = sstrdup(p); + if(p2 == NULL) { + ui->path = sstrdup("/"); + } else { + p = p2; + if((p2 = strchr(p, '?')) != NULL) + *(p2++) = 0; + ui->path = sstrdup(p); + } + if(p2 == NULL) { + ui->query = sstrdup(""); + } else { + ui->query = sstrdup(p2); + } + return(ui); +} diff --git a/include/http.h b/include/http.h index 0873659..0456d5a 100644 --- a/include/http.h +++ b/include/http.h @@ -17,18 +17,19 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifdef _HTTP_H +#ifndef _HTTP_H #define _HTTP_H struct hturlinfo { char *host; int port; - char *rest; + char *path; + char *query; }; struct htconn { int fd; - struct char *outbuf, *inbuf; + char *outbuf, *inbuf; size_t outbufsize, outbufdata; size_t inbufsize, inbufdata; struct hturlinfo *url; -- 2.11.0