Revision: 14527 Author: adrian.chadd Date: Thu Apr 1 23:26:01 2010 Log: Preparatory legwork for tidying up method_t and writing some testing code for it.
* Migrate the method related routines out from src/ and into libhttp/. * Add a routine - urlMethodAssign() - which is intended to handle assigning method_t's from one pointer to another - and will be used initially to debug memory leaks! This shouldn't result in any functional changes in the codebase! http://code.google.com/p/lusca-cache/source/detail?r=14527 Added: /branches/LUSCA_HEAD/libhttp/HttpMethod.c /branches/LUSCA_HEAD/libhttp/HttpMethod.h Modified: /branches/LUSCA_HEAD/libhttp/Makefile.am /branches/LUSCA_HEAD/src/enums.h /branches/LUSCA_HEAD/src/protos.h /branches/LUSCA_HEAD/src/squid.h /branches/LUSCA_HEAD/src/structs.h /branches/LUSCA_HEAD/src/typedefs.h /branches/LUSCA_HEAD/src/url.c ======================================= --- /dev/null +++ /branches/LUSCA_HEAD/libhttp/HttpMethod.c Thu Apr 1 23:26:01 2010 @@ -0,0 +1,267 @@ + +/* + * $Id: url.c 14346 2009-10-28 12:23:15Z adrian.chadd $ + * + * DEBUG: section 23 URL Parsing + * AUTHOR: Duane Wessels + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#include "../include/config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "../include/util.h" + +#include "../libcore/varargs.h" +#include "../libcore/debug.h" + +#include "HttpMethod.h" + +struct rms { + method_t method; + int string_len; +}; + +/* + * It is currently VERY, VERY IMPORTANT that these be in order of their + * definition in the method_code_t enum. + */ +static struct rms request_methods[] = +{ + { + {METHOD_NONE, "NONE", + {0, 0}}, 4}, + { + {METHOD_GET, "GET", + {1, 0}}, 3}, + { + {METHOD_POST, "POST", + {0, 1}}, 4}, + { + {METHOD_PUT, "PUT", + {0, 1}}, 3}, + { + {METHOD_HEAD, "HEAD", + {1, 0}}, 4}, + { + {METHOD_CONNECT, "CONNECT", + {0, 0}}, 7}, + { + {METHOD_TRACE, "TRACE", + {0, 0}}, 5}, + { + {METHOD_PURGE, "PURGE", + {0, 1}}, 5}, + { + {METHOD_OPTIONS, "OPTIONS", + {0, 0}}, 7}, + { + {METHOD_DELETE, "DELETE", + {0, 1}}, 6}, + { + {METHOD_PROPFIND, "PROPFIND", + {0, 0}}, 8}, + { + {METHOD_PROPPATCH, "PROPPATCH", + {0, 1}}, 9}, + { + {METHOD_MKCOL, "MKCOL", + {0, 1}}, 5}, + { + {METHOD_COPY, "COPY", + {0, 0}}, 4}, + { + {METHOD_MOVE, "MOVE", + {0, 1}}, 4}, + { + {METHOD_LOCK, "LOCK", + {0, 0}}, 4}, + { + {METHOD_UNLOCK, "UNLOCK", + {0, 0}}, 6}, + { + {METHOD_BMOVE, "BMOVE", + {0, 1}}, 5}, + { + {METHOD_BDELETE, "BDELETE", + {0, 1}}, 7}, + { + {METHOD_BPROPFIND, "BPROPFIND", + {0, 0}}, 9}, + { + {METHOD_BPROPPATCH, "BPROPPATCH", + {0, 0}}, 10}, + { + {METHOD_BCOPY, "BCOPY", + {0, 0}}, 5}, + { + {METHOD_SEARCH, "SEARCH", + {0, 0}}, 6}, + { + {METHOD_SUBSCRIBE, "SUBSCRIBE", + {0, 0}}, 9}, + { + {METHOD_UNSUBSCRIBE, "UNSUBSCRIBE", + {0, 0}}, 11}, + { + {METHOD_POLL, "POLL", + {0, 0}}, 4}, + { + {METHOD_REPORT, "REPORT", + {0, 0}}, 6}, + { + {METHOD_MKACTIVITY, "MKACTIVITY", + {0, 0}}, 10}, + { + {METHOD_CHECKOUT, "CHECKOUT", + {0, 0}}, 8}, + { + {METHOD_MERGE, "MERGE", + {0, 0}}, 5}, + { + {METHOD_OTHER, NULL, + {0, 0}}, 0}, +}; + +/* + * Assign "src" to "dst". + * + * This will just copy the pointers for now and log a message + * whenever a destination pointer is being overwritten that + * is METHOD_OTHER. + * + * It'll eventually be a "copy" function which will free the + * original pointer and then dup the origin if it's METHOD_OTHER. + */ +void +urlMethodAssign(method_t **dst, method_t *src) +{ + if (*dst && (*dst)->code == METHOD_OTHER) { + debug(23, 1) ("urlMethodAssign: overwriting an existing method: '%s'\n", + urlMethodGetConstStr((*dst))); + } + + *dst = src; +} + +method_t * +urlMethodGetKnown(const char *s, int len) +{ + struct rms *rms; + + for (rms = request_methods; rms->string_len != 0; rms++) { + if (len != rms->string_len) { + continue; + } + if (strncasecmp(s, rms->method.string, len) == 0) { + return (&rms->method); + } + } + + return (NULL); +} + +method_t * +urlMethodGet(const char *s, int len) +{ + method_t *method; + + method = urlMethodGetKnown(s, len); + if (method != NULL) { + return (method); + } + method = xmalloc(sizeof(method_t)); + method->code = METHOD_OTHER; + method->string = xstrndup(s, len + 1); + method->flags.cachable = 0; + method->flags.purges_all = 1; + + return (method); +} + +method_t * +urlMethodGetKnownByCode(method_code_t code) +{ + if (code < 0 || code >= METHOD_OTHER) { + return (NULL); + } + return (&request_methods[code].method); +} + +method_t * +urlMethodDup(method_t * orig) +{ + method_t *method; + + if (orig == NULL) { + return (NULL); + } + if (orig->code != METHOD_OTHER) { + return (orig); + } + method = xmalloc(sizeof(method_t)); + method->code = orig->code; + method->string = xstrdup(orig->string); + method->flags.cachable = orig->flags.cachable; + method->flags.purges_all = orig->flags.purges_all; + + return (method); +} + +/* + * return the string for the method name + */ +const char * +urlMethodGetConstStr(method_t *method) +{ + /* XXX this should log a NULL method! */ + if (! method) + return "NULL"; + if (! method->string) + return "NULL"; + return method->string; +} + +void +urlMethodFree(method_t * method) +{ + + if (method == NULL) { + return; + } + if (method->code != METHOD_OTHER) { + return; + } + xfree((char *) method->string); + xfree(method); +} + ======================================= --- /dev/null +++ /branches/LUSCA_HEAD/libhttp/HttpMethod.h Thu Apr 1 23:26:01 2010 @@ -0,0 +1,90 @@ + +/* + * $Id: enums.h 14466 2010-03-20 09:58:36Z adrian.chadd $ + * + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#ifndef __LIBHTTP_HTTP_METHOD_H__ +#define __LIBHTTP_HTTP_METHOD_H__ + +typedef enum { + METHOD_NONE, /* 000 */ + METHOD_GET, /* 001 */ + METHOD_POST, /* 010 */ + METHOD_PUT, /* 011 */ + METHOD_HEAD, /* 100 */ + METHOD_CONNECT, /* 101 */ + METHOD_TRACE, /* 110 */ + METHOD_PURGE, /* 111 */ + METHOD_OPTIONS, + METHOD_DELETE, /* RFC2616 section 9.7 */ + METHOD_PROPFIND, + METHOD_PROPPATCH, + METHOD_MKCOL, + METHOD_COPY, + METHOD_MOVE, + METHOD_LOCK, + METHOD_UNLOCK, + METHOD_BMOVE, + METHOD_BDELETE, + METHOD_BPROPFIND, + METHOD_BPROPPATCH, + METHOD_BCOPY, + METHOD_SEARCH, + METHOD_SUBSCRIBE, + METHOD_UNSUBSCRIBE, + METHOD_POLL, + METHOD_REPORT, + METHOD_MKACTIVITY, + METHOD_CHECKOUT, + METHOD_MERGE, + METHOD_OTHER, +} method_code_t; + +struct _method_t { + method_code_t code; + const char *string; + struct { + unsigned int cachable:1; + unsigned int purges_all:1; + } flags; +}; +typedef struct _method_t method_t; + +extern void urlMethodAssign(method_t **dst, method_t *src); +extern method_t * urlMethodGetKnown(const char *s, int len); +extern method_t * urlMethodGet(const char *s, int len); +extern method_t * urlMethodDup(method_t * orig); +extern method_t * urlMethodGetKnownByCode(method_code_t code); +extern const char * urlMethodGetConstStr(method_t *method); +extern void urlMethodFree(method_t * method); + + +#endif ======================================= --- /branches/LUSCA_HEAD/libhttp/Makefile.am Fri Dec 26 19:27:42 2008 +++ /branches/LUSCA_HEAD/libhttp/Makefile.am Thu Apr 1 23:26:01 2010 @@ -20,7 +20,8 @@ HttpMsg.c \ HttpHdrRange.c \ HttpHdrContRange.c \ - HttpBody.c + HttpBody.c \ + HttpMethod.c noinst_LIBRARIES = \ libhttp.a ======================================= --- /branches/LUSCA_HEAD/src/enums.h Sat Mar 20 02:58:36 2010 +++ /branches/LUSCA_HEAD/src/enums.h Thu Apr 1 23:26:01 2010 @@ -261,40 +261,6 @@ STORE_DISK_CLIENT } store_client_t; -typedef enum { - METHOD_NONE, /* 000 */ - METHOD_GET, /* 001 */ - METHOD_POST, /* 010 */ - METHOD_PUT, /* 011 */ - METHOD_HEAD, /* 100 */ - METHOD_CONNECT, /* 101 */ - METHOD_TRACE, /* 110 */ - METHOD_PURGE, /* 111 */ - METHOD_OPTIONS, - METHOD_DELETE, /* RFC2616 section 9.7 */ - METHOD_PROPFIND, - METHOD_PROPPATCH, - METHOD_MKCOL, - METHOD_COPY, - METHOD_MOVE, - METHOD_LOCK, - METHOD_UNLOCK, - METHOD_BMOVE, - METHOD_BDELETE, - METHOD_BPROPFIND, - METHOD_BPROPPATCH, - METHOD_BCOPY, - METHOD_SEARCH, - METHOD_SUBSCRIBE, - METHOD_UNSUBSCRIBE, - METHOD_POLL, - METHOD_REPORT, - METHOD_MKACTIVITY, - METHOD_CHECKOUT, - METHOD_MERGE, - METHOD_OTHER, -} method_code_t; - typedef enum { PROTO_NONE, PROTO_HTTP, ======================================= --- /branches/LUSCA_HEAD/src/protos.h Sun Mar 28 00:33:28 2010 +++ /branches/LUSCA_HEAD/src/protos.h Thu Apr 1 23:26:01 2010 @@ -805,12 +805,6 @@ extern char *url_convert_hex(char *org_url, int allocate); extern char *url_escape(const char *url); extern protocol_t urlParseProtocol(const char *); -extern method_t *urlMethodGet(const char *, int len); -extern method_t *urlMethodGetKnown(const char *, int len); -extern method_t *urlMethodGetKnownByCode(method_code_t); -extern method_t *urlMethodDup(method_t *); -extern const char * urlMethodGetConstStr(method_t *method); -extern void urlMethodFree(method_t *); extern void urlInitialize(void); extern request_t *urlParse(method_t *, char *); extern const char *urlCanonical(request_t *); ======================================= --- /branches/LUSCA_HEAD/src/squid.h Thu Oct 15 16:08:35 2009 +++ /branches/LUSCA_HEAD/src/squid.h Thu Apr 1 23:26:01 2010 @@ -405,6 +405,7 @@ #include "../libhttp/HttpHdrContRange.h" #include "../libhttp/HttpBody.h" #include "../libhttp/HttpReply.h" +#include "../libhttp/HttpMethod.h" #include "../libiapp/event.h" #include "../libiapp/iapp_ssl.h" ======================================= --- /branches/LUSCA_HEAD/src/structs.h Sat Mar 20 01:31:20 2010 +++ /branches/LUSCA_HEAD/src/structs.h Thu Apr 1 23:26:01 2010 @@ -935,15 +935,6 @@ struct timeval store_complete_stop; }; -struct _method_t { - method_code_t code; - const char *string; - struct { - unsigned int cachable:1; - unsigned int purges_all:1; - } flags; -}; - struct _AccessLogEntry { const char *url; struct { ======================================= --- /branches/LUSCA_HEAD/src/typedefs.h Tue Aug 4 08:00:11 2009 +++ /branches/LUSCA_HEAD/src/typedefs.h Thu Apr 1 23:26:01 2010 @@ -108,7 +108,6 @@ typedef struct _header_mangler header_mangler; typedef struct _body_size body_size; typedef struct _delay_body_size delay_body_size; -typedef struct _method_t method_t; typedef struct _request_t request_t; typedef struct _AccessLogEntry AccessLogEntry; typedef struct _cachemgr_passwd cachemgr_passwd; ======================================= --- /branches/LUSCA_HEAD/src/url.c Wed Oct 28 05:23:15 2009 +++ /branches/LUSCA_HEAD/src/url.c Thu Apr 1 23:26:01 2010 @@ -35,112 +35,6 @@ #include "squid.h" -struct rms { - method_t method; - int string_len; -}; - -/* - * It is currently VERY, VERY IMPORTANT that these be in order of their - * definition in the method_code_t enum. - */ -static struct rms request_methods[] = -{ - { - {METHOD_NONE, "NONE", - {0, 0}}, 4}, - { - {METHOD_GET, "GET", - {1, 0}}, 3}, - { - {METHOD_POST, "POST", - {0, 1}}, 4}, - { - {METHOD_PUT, "PUT", - {0, 1}}, 3}, - { - {METHOD_HEAD, "HEAD", - {1, 0}}, 4}, - { - {METHOD_CONNECT, "CONNECT", - {0, 0}}, 7}, - { - {METHOD_TRACE, "TRACE", - {0, 0}}, 5}, - { - {METHOD_PURGE, "PURGE", - {0, 1}}, 5}, - { - {METHOD_OPTIONS, "OPTIONS", - {0, 0}}, 7}, - { - {METHOD_DELETE, "DELETE", - {0, 1}}, 6}, - { - {METHOD_PROPFIND, "PROPFIND", - {0, 0}}, 8}, - { - {METHOD_PROPPATCH, "PROPPATCH", - {0, 1}}, 9}, - { - {METHOD_MKCOL, "MKCOL", - {0, 1}}, 5}, - { - {METHOD_COPY, "COPY", - {0, 0}}, 4}, - { - {METHOD_MOVE, "MOVE", - {0, 1}}, 4}, - { - {METHOD_LOCK, "LOCK", - {0, 0}}, 4}, - { - {METHOD_UNLOCK, "UNLOCK", - {0, 0}}, 6}, - { - {METHOD_BMOVE, "BMOVE", - {0, 1}}, 5}, - { - {METHOD_BDELETE, "BDELETE", - {0, 1}}, 7}, - { - {METHOD_BPROPFIND, "BPROPFIND", - {0, 0}}, 9}, - { - {METHOD_BPROPPATCH, "BPROPPATCH", - {0, 0}}, 10}, - { - {METHOD_BCOPY, "BCOPY", - {0, 0}}, 5}, - { - {METHOD_SEARCH, "SEARCH", - {0, 0}}, 6}, - { - {METHOD_SUBSCRIBE, "SUBSCRIBE", - {0, 0}}, 9}, - { - {METHOD_UNSUBSCRIBE, "UNSUBSCRIBE", - {0, 0}}, 11}, - { - {METHOD_POLL, "POLL", - {0, 0}}, 4}, - { - {METHOD_REPORT, "REPORT", - {0, 0}}, 6}, - { - {METHOD_MKACTIVITY, "MKACTIVITY", - {0, 0}}, 10}, - { - {METHOD_CHECKOUT, "CHECKOUT", - {0, 0}}, 8}, - { - {METHOD_MERGE, "MERGE", - {0, 0}}, 5}, - { - {METHOD_OTHER, NULL, - {0, 0}}, 0}, -}; - const char *ProtocolStr[] = { "NONE", @@ -227,98 +121,6 @@ assert(0 < matchDomainName("x-foo.com", ".foo.com")); /* more cases? */ } - -method_t * -urlMethodGetKnown(const char *s, int len) -{ - struct rms *rms; - - for (rms = request_methods; rms->string_len != 0; rms++) { - if (len != rms->string_len) { - continue; - } - if (strncasecmp(s, rms->method.string, len) == 0) { - return (&rms->method); - } - } - - return (NULL); -} - -method_t * -urlMethodGet(const char *s, int len) -{ - method_t *method; - - method = urlMethodGetKnown(s, len); - if (method != NULL) { - return (method); - } - method = xmalloc(sizeof(method_t)); - method->code = METHOD_OTHER; - method->string = xstrndup(s, len + 1); - method->flags.cachable = 0; - method->flags.purges_all = 1; - - return (method); -} - -method_t * -urlMethodGetKnownByCode(method_code_t code) -{ - if (code < 0 || code >= METHOD_OTHER) { - return (NULL); - } - return (&request_methods[code].method); -} - -method_t * -urlMethodDup(method_t * orig) -{ - method_t *method; - - if (orig == NULL) { - return (NULL); - } - if (orig->code != METHOD_OTHER) { - return (orig); - } - method = xmalloc(sizeof(method_t)); - method->code = orig->code; - method->string = xstrdup(orig->string); - method->flags.cachable = orig->flags.cachable; - method->flags.purges_all = orig->flags.purges_all; - - return (method); -} - -/* - * return the string for the method name - */ -const char * -urlMethodGetConstStr(method_t *method) -{ - /* XXX this should log a NULL method! */ - if (! method) - return "NULL"; - if (! method->string) - return "NULL"; - return method->string; -} - -void -urlMethodFree(method_t * method) -{ - - if (method == NULL) { - return; - } - if (method->code != METHOD_OTHER) { - return; - } - xfree((char *) method->string); - xfree(method); -} protocol_t urlParseProtocol(const char *s) -- 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.
