Revision: 14690 Author: adrian.chadd Date: Sun May 23 04:11:01 2010 Log: Migrate a couple of url protocol parsing routines into libsqurl.
http://code.google.com/p/lusca-cache/source/detail?r=14690 Modified: /branches/LUSCA_HEAD/libsqurl/proto.c /branches/LUSCA_HEAD/libsqurl/proto.h /branches/LUSCA_HEAD/src/protos.h /branches/LUSCA_HEAD/src/url.c ======================================= --- /branches/LUSCA_HEAD/libsqurl/proto.c Sun May 23 00:40:23 2010 +++ /branches/LUSCA_HEAD/libsqurl/proto.c Sun May 23 04:11:01 2010 @@ -1,6 +1,11 @@ #include "../include/config.h" #include <stdio.h> +#if HAVE_STRING_H +#include <string.h> +#endif + +#include "proto.h" const char *ProtocolStr[] = { @@ -19,3 +24,54 @@ "TOTAL" }; +protocol_t +urlParseProtocol(const char *s) +{ + /* test common stuff first */ + if (strcasecmp(s, "http") == 0) + return PROTO_HTTP; + if (strcasecmp(s, "ftp") == 0) + return PROTO_FTP; + if (strcasecmp(s, "https") == 0) + return PROTO_HTTPS; + if (strcasecmp(s, "file") == 0) + return PROTO_FTP; + if (strcasecmp(s, "gopher") == 0) + return PROTO_GOPHER; + if (strcasecmp(s, "wais") == 0) + return PROTO_WAIS; + if (strcasecmp(s, "cache_object") == 0) + return PROTO_CACHEOBJ; + if (strcasecmp(s, "urn") == 0) + return PROTO_URN; + if (strcasecmp(s, "whois") == 0) + return PROTO_WHOIS; + if (strcasecmp(s, "internal") == 0) + return PROTO_INTERNAL; + return PROTO_NONE; +} + +int +urlDefaultPort(protocol_t p) +{ + switch (p) { + case PROTO_HTTP: + return 80; + case PROTO_HTTPS: + return 443; + case PROTO_FTP: + return 21; + case PROTO_GOPHER: + return 70; + case PROTO_WAIS: + return 210; + case PROTO_CACHEOBJ: + case PROTO_INTERNAL: + return CACHE_HTTP_PORT; + case PROTO_WHOIS: + return 43; + default: + return 0; + } +} + ======================================= --- /branches/LUSCA_HEAD/libsqurl/proto.h Sun May 23 00:40:23 2010 +++ /branches/LUSCA_HEAD/libsqurl/proto.h Sun May 23 04:11:01 2010 @@ -19,4 +19,7 @@ extern const char *ProtocolStr[]; +extern protocol_t urlParseProtocol(const char *s); +extern int urlDefaultPort(protocol_t p); + #endif ======================================= --- /branches/LUSCA_HEAD/src/protos.h Sun May 23 00:35:08 2010 +++ /branches/LUSCA_HEAD/src/protos.h Sun May 23 04:11:01 2010 @@ -783,7 +783,6 @@ /* url.c */ extern char *url_escape(const char *url); -extern protocol_t urlParseProtocol(const char *); extern void urlInitialize(void); extern request_t *urlParse(method_t *, char *); extern const char *urlCanonical(request_t *); @@ -793,7 +792,6 @@ extern char *urlInternal(const char *dir, const char *name); extern int matchDomainName(const char *host, const char *domain); extern int urlCheckRequest(const request_t *); -extern int urlDefaultPort(protocol_t p); extern char *urlCanonicalClean(const request_t *); extern char *urlHostname(const char *url); ======================================= --- /branches/LUSCA_HEAD/src/url.c Sun May 23 03:46:54 2010 +++ /branches/LUSCA_HEAD/src/url.c Sun May 23 04:11:01 2010 @@ -79,58 +79,6 @@ assert(0 < matchDomainName("x-foo.com", ".foo.com")); /* more cases? */ } - -protocol_t -urlParseProtocol(const char *s) -{ - /* test common stuff first */ - if (strcasecmp(s, "http") == 0) - return PROTO_HTTP; - if (strcasecmp(s, "ftp") == 0) - return PROTO_FTP; - if (strcasecmp(s, "https") == 0) - return PROTO_HTTPS; - if (strcasecmp(s, "file") == 0) - return PROTO_FTP; - if (strcasecmp(s, "gopher") == 0) - return PROTO_GOPHER; - if (strcasecmp(s, "wais") == 0) - return PROTO_WAIS; - if (strcasecmp(s, "cache_object") == 0) - return PROTO_CACHEOBJ; - if (strcasecmp(s, "urn") == 0) - return PROTO_URN; - if (strcasecmp(s, "whois") == 0) - return PROTO_WHOIS; - if (strcasecmp(s, "internal") == 0) - return PROTO_INTERNAL; - return PROTO_NONE; -} - - -int -urlDefaultPort(protocol_t p) -{ - switch (p) { - case PROTO_HTTP: - return 80; - case PROTO_HTTPS: - return 443; - case PROTO_FTP: - return 21; - case PROTO_GOPHER: - return 70; - case PROTO_WAIS: - return 210; - case PROTO_CACHEOBJ: - case PROTO_INTERNAL: - return CACHE_HTTP_PORT; - case PROTO_WHOIS: - return 43; - default: - return 0; - } -} /* * This routine parses a URL. Its assumed that the URL is complete - -- You received this message because you are subscribed to the Google Groups "lusca-commit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/lusca-commit?hl=en.
