packet-smb2: fix lease epoch fields
[metze/wireshark/wip.git] / ui / follow.c
1 /* follow.c
2  *
3  * $Id$
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 #include <string.h>
27
28 #include <glib.h>
29
30 #include <wsutil/filesystem.h>
31 #include <epan/dfilter/dfilter.h>
32
33 #include "ui/follow.h"
34
35 #ifdef HAVE_LIBZ
36 static char *
37 sgetline(char *str, int *next)
38 {
39     char *end;
40
41     end = strstr(str, "\r\n");
42     if (!end) {
43         *next = (int)strlen(str);
44         return NULL;
45     }
46     *end = '\0';
47     *next = (int)(end-str+2);
48     return str;
49 }
50
51 gboolean
52 parse_http_header(char *data, size_t len, size_t *content_start)
53 {
54     char *tmp, *copy, *line;
55     size_t pos = 0;
56     int next_line;
57     gboolean is_gzipped;
58
59     /* XXX handle case where only partial header is passed in here.
60      * we should pass something back to indicate whether header is complete.
61      * (if not, is_gzipped is may still be unknown)
62      */
63
64     /*
65      * In order to parse header, we duplicate data and tokenize lines.
66      * We aren't interested in actual data, so use g_strndup instead of memcpy
67      * to (possibly) copy fewer bytes (e.g., if a nul byte exists in data)
68      * This also ensures that we have a terminated string for further
69      * processing.
70      */
71     tmp = copy = g_strndup(data, len);
72     if (!tmp) {
73         *content_start = 0;
74         return FALSE;
75     }
76
77     /* skip HTTP... line*/
78     /*line = */sgetline(tmp, &next_line);
79
80     tmp += next_line;
81     pos += next_line;
82
83     is_gzipped = FALSE;
84
85     *content_start = -1;
86     while ((line = sgetline(tmp, &next_line))) {
87         char *key, *val, *c;
88
89         tmp += next_line;
90         pos += next_line;
91
92         if (strlen(line) == 0) {
93             /* end of header*/
94             break;
95         }
96
97         c = strchr(line, ':');
98         if (!c) break;
99
100         key = line;
101         *c = '\0';
102         val = c+2;
103
104         if (!strcmp(key, "Content-Encoding") && strstr(val, "gzip")) {
105             is_gzipped = TRUE;
106         }
107     }
108     *content_start = pos;
109     g_free(copy);
110     return is_gzipped;
111 }
112 #endif
113
114
115 /*
116  * Editor modelines
117  *
118  * Local Variables:
119  * c-basic-offset: 4
120  * tab-width: 8
121  * indent-tabs-mode: nil
122  * End:
123  *
124  * ex: set shiftwidth=4 tabstop=8 expandtab:
125  * :indentSize=4:tabSize=8:noTabs=true:
126  */