diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-08-21 23:33:23 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-08-22 06:34:06 +0000 |
commit | 5825f59ddccb8af2b4a06356f61195dd26c977d7 (patch) | |
tree | 5250e297808ccc0dd7dd36c688dbba8d53368c75 /epan/media_params.c | |
parent | efdcb25360621e5ac14f276b37964f27f4ce0ba4 (diff) | |
download | wireshark-5825f59ddccb8af2b4a06356f61195dd26c977d7.tar.gz |
Pass an HTTP message type to all HTTP subdissectors.
This gets complicated, because those subdissectors might be called by
other dissectors as well. We need a better way of passing that sort of
out-of-bound information.
Pull some routines used for processing Content-Type parameters into
common code; we can't guarantee that the media parameters passed in
would be writable (passing it as *the* data hid that; passing a
structure with that *and* the HTTP message type revealed it), so don't
convert it to lower-case in place.
Use that information, if available, to determine whether an IPP message
is a requet or a response.
Change-Id: I4bccc9f05cd0b14ad445be7ab37b3d884d841325
Reviewed-on: https://code.wireshark.org/review/17216
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/media_params.c')
-rw-r--r-- | epan/media_params.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/epan/media_params.c b/epan/media_params.c new file mode 100644 index 0000000000..863025b437 --- /dev/null +++ b/epan/media_params.c @@ -0,0 +1,133 @@ +/* media_params.c + * Routines for parsing media type parameters + * Copyright 2004, Anders Broman. + * Copyright 2004, Olivier Biot. + * + * Refer to the AUTHORS file or the AUTHORS section in the man page + * for contacting the author(s) of this file. + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include <string.h> + +#include <glib.h> + +#include <epan/media_params.h> + +/* Return the index of a given char in the given string, + * or -1 if not found. + */ +gint +index_of_char(const char *str, const char c) +{ + gint len = 0; + const char *p = str; + + while (*p && *p != c) { + p++; + len++; + } + + if (*p) + return len; + return -1; +} + +char * +find_parameter(const char *parameters, const char *key, int *retlen) +{ + const char *start, *p; + int keylen = 0; + int len = 0; + + if(!parameters || !*parameters || !key || strlen(key) == 0) + /* we won't be able to find anything */ + return NULL; + + keylen = (int) strlen(key); + p = parameters; + + while (*p) { + + while ((*p) && g_ascii_isspace(*p)) + p++; /* Skip white space */ + + if (g_ascii_strncasecmp(p, key, keylen) == 0) + break; + /* Skip to next parameter */ + p = strchr(p, ';'); + if (p == NULL) + { + return NULL; + } + p++; /* Skip semicolon */ + + } + if (*p == 0x0) + return NULL; /* key wasn't found */ + + start = p + keylen; + if (start[0] == 0) { + return NULL; + } + + /* + * Process the parameter value + */ + if (start[0] == '"') { + /* + * Parameter value is a quoted-string + */ + start++; /* Skip the quote */ + len = index_of_char(start, '"'); + if (len < 0) { + /* + * No closing quote + */ + return NULL; + } + } else { + /* + * Look for end of boundary + */ + p = start; + while (*p) { + if (*p == ';' || g_ascii_isspace(*p)) + break; + p++; + len++; + } + } + + if(retlen) + (*retlen) = len; + + /* + * This is one of those ugly routines like strchr() where you can + * pass in a constant or non-constant string, and the result + * points into that string and inherits the constness of the + * input argument, but C doesn't support that, so the input + * parameter is const char * and the result is char *. + */ + return (char *)start; +} + |