decrypt drsuapi attributes
[wireshark-sm.git] / epan / export_object.c
blobf65603f2a546005614217bfd0cebd1a125ce8dbd
1 /* export_object.c
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 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <string.h>
15 #include "proto.h"
16 #include "packet_info.h"
17 #include "export_object.h"
19 struct register_eo {
20 int proto_id; /* protocol id (0-indexed) */
21 const char* tap_listen_str; /* string used in register_tap_listener (NULL to use protocol name) */
22 tap_packet_cb eo_func; /* function to be called for new incoming packets for SRT */
23 export_object_gui_reset_cb reset_cb; /* function to parse parameters of optional arguments of tap string */
26 static wmem_tree_t *registered_eo_tables;
28 int
29 register_export_object(const int proto_id, tap_packet_cb export_packet_func, export_object_gui_reset_cb reset_cb)
31 register_eo_t *table;
32 DISSECTOR_ASSERT(export_packet_func);
34 table = wmem_new(wmem_epan_scope(), register_eo_t);
36 table->proto_id = proto_id;
37 table->tap_listen_str = wmem_strdup_printf(wmem_epan_scope(), "%s_eo", proto_get_protocol_filter_name(proto_id));
38 table->eo_func = export_packet_func;
39 table->reset_cb = reset_cb;
41 if (registered_eo_tables == NULL)
42 registered_eo_tables = wmem_tree_new(wmem_epan_scope());
44 wmem_tree_insert_string(registered_eo_tables, proto_get_protocol_filter_name(proto_id), table, 0);
45 return register_tap(table->tap_listen_str);
48 int get_eo_proto_id(register_eo_t* eo)
50 if (!eo) {
51 return -1;
53 return eo->proto_id;
56 const char* get_eo_tap_listener_name(register_eo_t* eo)
58 return eo->tap_listen_str;
61 tap_packet_cb get_eo_packet_func(register_eo_t* eo)
63 return eo->eo_func;
66 export_object_gui_reset_cb get_eo_reset_func(register_eo_t* eo)
68 return eo->reset_cb;
71 register_eo_t* get_eo_by_name(const char* name)
73 return (register_eo_t*)wmem_tree_lookup_string(registered_eo_tables, name, 0);
76 void eo_iterate_tables(wmem_foreach_func func, void *user_data)
78 wmem_tree_foreach(registered_eo_tables, func, user_data);
81 static GString *eo_rename(GString *gstr, size_t maxlen, int dupn)
83 GString *gstr_tmp;
84 char *tmp_ptr;
85 GString *ext_str = NULL;
87 gstr_tmp = g_string_new("");
88 if (dupn != 0) {
89 g_string_append_printf (gstr_tmp, "(%d)", dupn);
91 if ( (tmp_ptr = strrchr(gstr->str, '.')) != NULL && ((ext_str = g_string_new(tmp_ptr))->len + strlen(gstr_tmp->str) < maxlen) ) {
92 /* Retain the extension */
93 gstr = g_string_truncate(gstr, gstr->len - ext_str->len);
94 if ( gstr->len >= (maxlen - (strlen(gstr_tmp->str) + ext_str->len)) )
95 gstr = g_string_truncate(gstr, maxlen - (strlen(gstr_tmp->str) + ext_str->len));
96 gstr = g_string_append(gstr, gstr_tmp->str);
97 gstr = g_string_append(gstr, ext_str->str);
99 else {
100 if ( gstr->len >= (maxlen - strlen(gstr_tmp->str)) )
101 gstr = g_string_truncate(gstr, maxlen - strlen(gstr_tmp->str));
102 gstr = g_string_append(gstr, gstr_tmp->str);
105 if (ext_str) {
106 g_string_free(ext_str, TRUE);
109 g_string_free(gstr_tmp, TRUE);
110 return gstr;
113 GString *
114 eo_massage_str(const char *in_str, size_t maxlen, int dupn)
116 char *tmp_ptr;
117 /* The characters in "reject" come from:
118 * https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions.
119 * Add to the list as necessary for other OS's.
121 const char *reject = "<>:\"/\\|?*"
122 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
123 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
124 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
125 GString *out_str;
127 out_str = g_string_new("");
129 /* Find all disallowed characters/bytes and replace them with %xx */
130 while ( (tmp_ptr = strpbrk(in_str, reject)) != NULL ) {
131 out_str = g_string_append_len(out_str, in_str, tmp_ptr - in_str);
132 g_string_append_printf(out_str, "%%%02x", *tmp_ptr);
133 in_str = tmp_ptr + 1;
135 out_str = g_string_append(out_str, in_str);
136 if ( dupn != 0 || out_str->len > maxlen )
137 out_str = eo_rename(out_str, maxlen, dupn);
138 return out_str;
141 const char *
142 eo_ct2ext(const char *content_type)
144 /* TODO: Map the content type string to an extension string. If no match,
145 * return NULL. */
146 return content_type;
149 void eo_free_entry(export_object_entry_t *entry)
151 g_free(entry->hostname);
152 g_free(entry->content_type);
153 g_free(entry->filename);
154 g_free(entry->payload_data);
156 g_free(entry);
160 * Editor modelines
162 * Local Variables:
163 * c-basic-offset: 4
164 * tab-width: 8
165 * indent-tabs-mode: nil
166 * End:
168 * ex: set shiftwidth=4 tabstop=8 expandtab:
169 * :indentSize=4:tabSize=8:noTabs=true: