From 0b4754a432708fec0328414fe4adff19c70c3855 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 12 May 2008 14:50:00 +0000 Subject: [PATCH] Moved parse_url() into libcitadel; I will need it for something outside of rssclient soon. --- citadel/citadel.h | 2 +- citadel/modules/rssclient/serv_rssclient.c | 55 --------------------- libcitadel/lib/libcitadel.h | 16 +----- libcitadel/lib/tools.c | 57 ++++++++++++++++++++++ webcit/webcit.h | 2 +- 5 files changed, 61 insertions(+), 71 deletions(-) diff --git a/citadel/citadel.h b/citadel/citadel.h index c68393b17..044392379 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -41,7 +41,7 @@ extern "C" { #define REV_LEVEL 735 /* This version */ #define REV_MIN 591 /* Oldest compatible database */ #define EXPORT_REV_MIN 733 /* Oldest compatible export files */ -#define LIBCITADEL_MIN 109 /* Minimum required version of libcitadel */ +#define LIBCITADEL_MIN 113 /* Minimum required version of libcitadel */ #define SERVER_TYPE 0 /* zero for stock Citadel; other developers please obtain SERVER_TYPE codes for your implementations */ diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c index e97a59dcb..2aaa140ef 100644 --- a/citadel/modules/rssclient/serv_rssclient.c +++ b/citadel/modules/rssclient/serv_rssclient.c @@ -331,61 +331,6 @@ void rss_xml_chardata(void *data, const XML_Char *s, int len) { -/* - * Parse a URL into host, port number, and resource identifier. - */ -int parse_url(char *url, char *hostname, int *port, char *identifier) -{ - char protocol[1024]; - char scratch[1024]; - char *ptr = NULL; - char *nptr = NULL; - - strcpy(scratch, url); - ptr = (char *)strchr(scratch, ':'); - if (!ptr) { - return(1); /* no protocol specified */ - } - - strcpy(ptr, ""); - strcpy(protocol, scratch); - if (strcmp(protocol, "http")) { - return(2); /* not HTTP */ - } - - strcpy(scratch, url); - ptr = (char *) strstr(scratch, "//"); - if (!ptr) { - return(3); /* no server specified */ - } - ptr += 2; - - strcpy(hostname, ptr); - nptr = (char *)strchr(ptr, ':'); - if (!nptr) { - *port = 80; /* default */ - nptr = (char *)strchr(hostname, '/'); - } - else { - sscanf(nptr, ":%d", port); - nptr = (char *)strchr(hostname, ':'); - } - - if (nptr) { - *nptr = '\0'; - } - - nptr = (char *)strchr(ptr, '/'); - - if (!nptr) { - return(4); /* no url specified */ - } - - strcpy(identifier, nptr); - return(0); -} - - /* * Begin a feed parse */ diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 7da1178f7..4bfea6f6f 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -9,7 +9,7 @@ */ #include #include -#define LIBCITADEL_VERSION_NUMBER 112 +#define LIBCITADEL_VERSION_NUMBER 113 /* * Here's a bunch of stupid magic to make the MIME parser portable. @@ -274,35 +274,23 @@ typedef void (*TransitionFunc) (void *Item1, void *Item2, int Odd); typedef void (*PrintHashDataFunc) (const char *Key, void *Item, int Odd); HashList *NewHash(int Uniq, HashFunc F); - void DeleteHash(HashList **Hash); - int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data); - void Put(HashList *Hash, const char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt); - int GetKey(HashList *Hash, char *HKey, long HKLen, void **Data); - int GetHashKeys(HashList *Hash, char ***List); - int dbg_PrintHash(HashList *Hash, PrintHashContent first, PrintHashContent Second); - - int PrintHash(HashList *Hash, TransitionFunc Trans, PrintHashDataFunc PrintEntry); - HashPos *GetNewHashPos(void); - void DeleteHashPos(HashPos **DelMe); - int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, char **HashKey, void **Data); - void SortByHashKey(HashList *Hash, int Order); void SortByHashKeyStr(HashList *Hash); int GetCount(HashList *Hash); const void *GetSearchPayload(const void *HashVoid); void SortByPayload(HashList *Hash, CompareFunc SortBy); - void convert_spaces_to_underscores(char *str); +int parse_url(char *url, char *hostname, int *port, char *identifier); /* * Convert 4 bytes char into an Integer. diff --git a/libcitadel/lib/tools.c b/libcitadel/lib/tools.c index 2077a514b..60168fe91 100644 --- a/libcitadel/lib/tools.c +++ b/libcitadel/lib/tools.c @@ -1031,3 +1031,60 @@ void convert_spaces_to_underscores(char *str) } } + +/* + * Parse a URL into host, port number, and resource identifier. + * (This is used by various functions which might need to fetch web pages.) + */ +int parse_url(char *url, char *hostname, int *port, char *identifier) +{ + char protocol[1024]; + char scratch[1024]; + char *ptr = NULL; + char *nptr = NULL; + + strcpy(scratch, url); + ptr = (char *)strchr(scratch, ':'); + if (!ptr) { + return(1); /* no protocol specified */ + } + + strcpy(ptr, ""); + strcpy(protocol, scratch); + if (strcmp(protocol, "http")) { + return(2); /* not HTTP */ + } + + strcpy(scratch, url); + ptr = (char *) strstr(scratch, "//"); + if (!ptr) { + return(3); /* no server specified */ + } + ptr += 2; + + strcpy(hostname, ptr); + nptr = (char *)strchr(ptr, ':'); + if (!nptr) { + *port = 80; /* default */ + nptr = (char *)strchr(hostname, '/'); + } + else { + sscanf(nptr, ":%d", port); + nptr = (char *)strchr(hostname, ':'); + } + + if (nptr) { + *nptr = '\0'; + } + + nptr = (char *)strchr(ptr, '/'); + + if (!nptr) { + return(4); /* no url specified */ + } + + strcpy(identifier, nptr); + return(0); +} + + diff --git a/webcit/webcit.h b/webcit/webcit.h index a321aba9a..6f123d5a6 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -126,7 +126,7 @@ extern locale_t wc_locales[]; #define CLIENT_ID 4 #define CLIENT_VERSION 735 /* This version of WebCit */ #define MINIMUM_CIT_VERSION 730 /* min required Citadel ver */ -#define LIBCITADEL_MIN 112 /* min required libcitadel ver */ +#define LIBCITADEL_MIN 113 /* min required libcitadel ver */ #define DEFAULT_HOST "localhost" /* Default Citadel server */ #define DEFAULT_PORT "504" #define LB (1) /* Internal escape chars */ -- 2.30.2