From 0a2e9eef732efa8b48e5188b361f523dfe8bb0cc Mon Sep 17 00:00:00 2001 From: bertrand Date: Sat, 24 Apr 1999 11:11:07 +0000 Subject: URL rewritten completely. Error handling not implemented in public 1999-04-24 bertrand * camel/url-util.c (new_g_url): URL rewritten completely. Error handling not implemented in public functions. But URL scan works pretty well :))) svn path=/trunk/; revision=874 --- ChangeLog | 9 +- camel/url-util.c | 284 +++++++++++++++++++++++++++++++++++++++++++++---------- camel/url-util.h | 10 ++ 3 files changed, 250 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index e08a74d7fa..8fd676df44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +1999-04-24 bertrand + + * camel/url-util.c (new_g_url): URL + rewritten completely. Error handling not + implemented in public functions. + But URL scan works pretty well :))) + 1999-04-24 bertrand * camel/url-util.[ch]: I needed the url @@ -21,7 +28,7 @@ * camel/camel-store.h: * camel/camel-folder.h: - correct declarations of structss + correct declarations of structs 1999-04-22 bertrand diff --git a/camel/url-util.c b/camel/url-util.c index d1ea09c6c9..45b5c0691d 100644 --- a/camel/url-util.c +++ b/camel/url-util.c @@ -31,20 +31,96 @@ Uniform Ressource Locators Bertrand. */ +/* + XXX TODO: recover the words between #'s or ?'s after the path */ -#include /* for isalpha */ -#include /* for atoi */ - #include "url-util.h" +typedef gboolean find_item_func(GString *url, GString **item, guint *position, gboolean *error); + +typedef struct { + char *item_name; + GString **item_value; + find_item_func *find_func; +} FindStepStruct; + +static gboolean find_protocol(GString *url, GString **item, guint *position, gboolean *error); +static gboolean find_user(GString *url, GString **item, guint *position, gboolean *error); +static gboolean find_passwd(GString *url, GString **item, guint *position, gboolean *error); +static gboolean find_host(GString *url, GString **item, guint *position, gboolean *error); +static gboolean find_port(GString *url, GString **item, guint *position, gboolean *error); +static gboolean find_path(GString *url, GString **item, guint *position, gboolean *error); + + + +/** + * new_g_url: create an Gurl object from a string + * @url_string: The string containing the URL to scan + * + * This routine takes a GString and parses it as an + * URL of the form: + * protocol://user:password@host:port/path + * there is no test on the values. For example, + * "port" can be a string, not only a number ! + * The Gurl structure fields ar filled with + * the scan results. When a member of the + * general URL can not be found, the corresponding + * Gurl member is NULL + * + * Return value: a Gurl structure containng the URL items. + **/ +Gurl *new_g_url(GString* url_string) +{ + Gurl *g_url; + + GString *protocol; + GString *user; + GString *passwd; + GString *host; + GString *port; + GString *path; + + guint position=0; + gboolean error; + gboolean found; + guint i; + + g_url = g_new(Gurl,1); + +#define NB_STEP_URL 6 + { + FindStepStruct step[NB_STEP_URL] = { + { "protocol", &(g_url->protocol), find_protocol}, + { "user", &(g_url->user), find_user}, + { "password", &(g_url->passwd), find_passwd}, + { "host", &(g_url->host), find_host}, + { "port", &(g_url->port), find_port}, + { "path", &(g_url->path), find_path} + }; + + for (i=0; istr; len_url = url->len; - *protocol = NULL; + *item = NULL; *error = FALSE; i=*position; @@ -71,7 +147,7 @@ find_protocol(GString *url, GString **protocol, guint *position, gboolean *error { str_protocol = g_strndup(str_url, i-3); - *protocol = g_string_new(str_protocol); + *item = g_string_new(str_protocol); *position=i; return TRUE; } @@ -83,7 +159,7 @@ find_protocol(GString *url, GString **protocol, guint *position, gboolean *error static gboolean -find_user(GString *url, GString **user, guint *position, gboolean *error) +find_user(GString *url, GString **item, guint *position, gboolean *error) { guint i; guint at_pos; @@ -95,7 +171,7 @@ find_user(GString *url, GString **user, guint *position, gboolean *error) str_url = url->str; len_url = url->len; - *user = NULL; + *item = NULL; i=*position; @@ -110,21 +186,21 @@ find_user(GString *url, GString **user, guint *position, gboolean *error) while ( (istr; len_url = url->len; - *passwd = NULL; + *item = NULL; i=*position; @@ -150,24 +226,132 @@ find_passwd(GString *url, GString **passwd, guint *position, gboolean *error) } str_passwd = g_strndup(str_url+ *position, i - *position); - *passwd = g_string_new(str_passwd); + *item = g_string_new(str_passwd); *position=i+1; /* skip it the '@' */ return TRUE; +} + + + +static gboolean +find_host(GString *url, GString **item, guint *position, gboolean *error) +{ + guint i; + guint slash_pos; + + gchar *str_url; + gint len_url; + gchar *str_host; + + str_url = url->str; + len_url = url->len; + + *item = NULL; + i=*position; + + + /* find a '/' */ + while ((istr; + len_url = url->len; + + *item = NULL; + i=*position; + + /* find a '/' */ + while ((istr; + len_url = url->len; + + *item = NULL; + i=*position; + + + /* find a '#' */ + while ((istr); - - /* Try to find the protocol */ - found = find_protocol(url, &protocol, &position, &error); - if (found) { - printf("protocol found : %s\n", protocol->str); - } else printf("protocol not found in URL\n\n"); - printf("posistion of the next item:\n"); - printf("%s\n", url->str); - for(i=0; istr); + } else printf("** %s not found in URL\n", test_step[i].item_name); + printf("next item position:\n"); + printf("%s\n", url->str); + for(i_pos=0; i_posstr); - } else printf("user name not found in URL\n"); - printf("posistion of the next item:\n"); - printf("%s\n", url->str); - for(i=0; istr); - printf("\n"); - } else printf("passwd not found in URL\n"); - printf("posistion of the next item:\n"); - printf("%s\n", url->str); - for(i=0; i