ssl,dtls: use ProtocolVersion from Server Hello
[metze/wireshark/wip.git] / epan / ex-opt.c
1 /*
2  *  ex-opt.c
3  *
4  * Extension command line options
5  *
6  * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 #include "config.h"
28
29 #include <glib.h>
30 #include "ex-opt.h"
31
32 static GHashTable* ex_opts = NULL;
33
34 gboolean ex_opt_add(const gchar* optarg) {
35     gchar** splitted;
36
37     if (!ex_opts)
38         ex_opts = g_hash_table_new(g_str_hash,g_str_equal);
39
40     splitted = g_strsplit(optarg,":",2);
41
42     if (splitted[0] && splitted[1]) {
43         GPtrArray* this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,splitted[0]);
44
45         if (this_opts) {
46             g_ptr_array_add(this_opts,splitted[1]);
47             g_free(splitted[0]);
48         } else {
49             this_opts = g_ptr_array_new();
50             g_ptr_array_add(this_opts,splitted[1]);
51             g_hash_table_insert(ex_opts,splitted[0],this_opts);
52         }
53
54         g_free(splitted);
55
56         return TRUE;
57     } else {
58         g_strfreev(splitted);
59         return FALSE;
60     }
61 }
62
63 gint ex_opt_count(const gchar* key) {
64     GPtrArray* this_opts;
65
66     if (! ex_opts)
67         return 0;
68
69     this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,key);
70
71     if (this_opts) {
72         return this_opts->len;
73     } else {
74         return 0;
75     }
76 }
77
78 const gchar* ex_opt_get_nth(const gchar* key, guint index) {
79     GPtrArray* this_opts;
80
81     if (! ex_opts)
82         return 0;
83
84     this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,key);
85
86     if (this_opts) {
87         if (this_opts->len > index) {
88             return (const gchar *)g_ptr_array_index(this_opts,index);
89         } else {
90             /* XXX: assert? */
91             return NULL;
92         }
93     } else {
94         return NULL;
95     }
96
97 }
98
99 extern const gchar* ex_opt_get_next(const gchar* key) {
100     GPtrArray* this_opts;
101
102     if (! ex_opts)
103         return 0;
104
105     this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,key);
106
107     if (this_opts) {
108         if (this_opts->len)
109             return (const gchar *)g_ptr_array_remove_index(this_opts,0);
110         else
111             return NULL;
112     } else {
113         return NULL;
114     }
115 }
116
117 /*
118  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
119  *
120  * Local variables:
121  * c-basic-offset: 4
122  * tab-width: 8
123  * indent-tabs-mode: nil
124  * End:
125  *
126  * vi: set shiftwidth=4 tabstop=8 expandtab:
127  * :indentSize=4:tabSize=8:noTabs=true:
128  */