2 * GUI independent helper routines common to all export object taps.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "packet_info.h"
29 #include "export_object.h"
32 int proto_id; /* protocol id (0-indexed) */
33 const char* tap_listen_str; /* string used in register_tap_listener (NULL to use protocol name) */
34 tap_packet_cb eo_func; /* function to be called for new incoming packets for SRT */
35 export_object_gui_reset_cb reset_cb; /* function to parse parameters of optional arguments of tap string */
38 static GSList *registered_eo_tables = NULL;
41 insert_sorted_by_table_name(gconstpointer aparam, gconstpointer bparam)
43 const register_eo_t *a = (const register_eo_t *)aparam;
44 const register_eo_t *b = (const register_eo_t *)bparam;
46 return g_ascii_strcasecmp(proto_get_protocol_filter_name(a->proto_id), proto_get_protocol_filter_name(b->proto_id));
50 register_export_object(const int proto_id, tap_packet_cb export_packet_func, export_object_gui_reset_cb reset_cb)
53 DISSECTOR_ASSERT(export_packet_func);
55 table = g_new(register_eo_t,1);
57 table->proto_id = proto_id;
58 table->tap_listen_str = g_strdup_printf("%s_eo", proto_get_protocol_filter_name(proto_id));
59 table->eo_func = export_packet_func;
60 table->reset_cb = reset_cb;
62 registered_eo_tables = g_slist_insert_sorted(registered_eo_tables, table, insert_sorted_by_table_name);
63 return register_tap(table->tap_listen_str);
66 int get_eo_proto_id(register_eo_t* eo)
74 const char* get_eo_tap_listener_name(register_eo_t* eo)
76 return eo->tap_listen_str;
79 tap_packet_cb get_eo_packet_func(register_eo_t* eo)
84 export_object_gui_reset_cb get_eo_reset_func(register_eo_t* eo)
90 find_matching_eo(gconstpointer arg1, gconstpointer arg2)
92 register_eo_t *eo = (register_eo_t*)arg1;
93 const gchar *name = (const gchar *)arg2;
95 return strcmp(proto_get_protocol_filter_name(eo->proto_id), name);
98 register_eo_t* get_eo_by_name(const char* name)
102 found_eo = g_slist_find_custom(registered_eo_tables,
103 (gpointer)name, find_matching_eo);
106 return (register_eo_t*)found_eo->data;
111 void eo_iterate_tables(GFunc func, gpointer user_data)
113 g_slist_foreach(registered_eo_tables, func, user_data);
116 static GString *eo_rename(GString *gstr, int dupn)
122 gstr_tmp = g_string_new("(");
123 g_string_append_printf (gstr_tmp, "%d)", dupn);
124 if ( (tmp_ptr = strrchr(gstr->str, '.')) != NULL ) {
125 /* Retain the extension */
126 ext_str = g_string_new(tmp_ptr);
127 gstr = g_string_truncate(gstr, gstr->len - ext_str->len);
128 if ( gstr->len >= (EXPORT_OBJECT_MAXFILELEN - (strlen(gstr_tmp->str) + ext_str->len)) )
129 gstr = g_string_truncate(gstr, EXPORT_OBJECT_MAXFILELEN - (strlen(gstr_tmp->str) + ext_str->len));
130 gstr = g_string_append(gstr, gstr_tmp->str);
131 gstr = g_string_append(gstr, ext_str->str);
132 g_string_free(ext_str, TRUE);
135 if ( gstr->len >= (EXPORT_OBJECT_MAXFILELEN - strlen(gstr_tmp->str)) )
136 gstr = g_string_truncate(gstr, EXPORT_OBJECT_MAXFILELEN - strlen(gstr_tmp->str));
137 gstr = g_string_append(gstr, gstr_tmp->str);
139 g_string_free(gstr_tmp, TRUE);
144 eo_massage_str(const gchar *in_str, gsize maxlen, int dupn)
147 /* The characters in "reject" come from:
148 * http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx.
149 * Add to the list as necessary for other OS's.
151 const gchar *reject = "<>:\"/\\|?*"
152 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
153 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
154 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
158 out_str = g_string_new("");
160 /* Find all disallowed characters/bytes and replace them with %xx */
161 while ( (tmp_ptr = strpbrk(in_str, reject)) != NULL ) {
162 out_str = g_string_append_len(out_str, in_str, tmp_ptr - in_str);
163 g_string_append_printf(out_str, "%%%02x", *tmp_ptr);
164 in_str = tmp_ptr + 1;
166 out_str = g_string_append(out_str, in_str);
167 if ( out_str->len > maxlen ) {
168 if ( (tmp_ptr = strrchr(out_str->str, '.')) != NULL ) {
169 /* Retain the extension */
170 ext_str = g_string_new(tmp_ptr);
171 out_str = g_string_truncate(out_str, maxlen - ext_str->len);
172 out_str = g_string_append(out_str, ext_str->str);
173 g_string_free(ext_str, TRUE);
176 out_str = g_string_truncate(out_str, maxlen);
179 out_str = eo_rename(out_str, dupn);
184 eo_ct2ext(const char *content_type)
186 /* TODO: Map the content type string to an extension string. If no match,
191 void eo_free_entry(export_object_entry_t *entry)
193 g_free(entry->hostname);
194 g_free(entry->content_type);
195 g_free(entry->filename);
196 g_free(entry->payload_data);
202 free_eo_table(gpointer p, gpointer user_data _U_)
204 register_eo_t *table = (register_eo_t*)p;
205 g_free((gpointer)table->tap_listen_str);
209 void export_object_cleanup(void)
211 g_slist_foreach(registered_eo_tables, free_eo_table, NULL);
212 g_slist_free(registered_eo_tables);
221 * indent-tabs-mode: nil
224 * ex: set shiftwidth=4 tabstop=8 expandtab:
225 * :indentSize=4:tabSize=8:noTabs=true: