2006-02-07 22:08:12 +00:00
|
|
|
/*
|
|
|
|
* ex-opt.c
|
2014-02-25 20:42:35 +00:00
|
|
|
*
|
2006-02-07 22:08:12 +00:00
|
|
|
* Extension command line options
|
|
|
|
*
|
2008-08-05 21:03:46 +00:00
|
|
|
* (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
|
2006-02-07 22:08:12 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2006-02-07 22:08:12 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2006-02-07 22:08:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include "ex-opt.h"
|
|
|
|
|
|
|
|
static GHashTable* ex_opts = NULL;
|
|
|
|
|
|
|
|
gboolean ex_opt_add(const gchar* optarg) {
|
|
|
|
gchar** splitted;
|
2014-02-25 20:42:35 +00:00
|
|
|
|
|
|
|
if (!ex_opts)
|
2006-02-07 22:08:12 +00:00
|
|
|
ex_opts = g_hash_table_new(g_str_hash,g_str_equal);
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
splitted = g_strsplit(optarg,":",2);
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
if (splitted[0] && splitted[1]) {
|
2013-03-19 04:54:30 +00:00
|
|
|
GPtrArray* this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,splitted[0]);
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
if (this_opts) {
|
|
|
|
g_ptr_array_add(this_opts,splitted[1]);
|
|
|
|
g_free(splitted[0]);
|
|
|
|
} else {
|
|
|
|
this_opts = g_ptr_array_new();
|
|
|
|
g_ptr_array_add(this_opts,splitted[1]);
|
|
|
|
g_hash_table_insert(ex_opts,splitted[0],this_opts);
|
|
|
|
}
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
g_free(splitted);
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
g_strfreev(splitted);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gint ex_opt_count(const gchar* key) {
|
|
|
|
GPtrArray* this_opts;
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
if (! ex_opts)
|
|
|
|
return 0;
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2013-03-19 04:54:30 +00:00
|
|
|
this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,key);
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
if (this_opts) {
|
|
|
|
return this_opts->len;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 15:40:40 +00:00
|
|
|
const gchar* ex_opt_get_nth(const gchar* key, guint key_index) {
|
2006-02-07 22:08:12 +00:00
|
|
|
GPtrArray* this_opts;
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
if (! ex_opts)
|
|
|
|
return 0;
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2013-03-19 04:54:30 +00:00
|
|
|
this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,key);
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
if (this_opts) {
|
2016-06-23 15:40:40 +00:00
|
|
|
if (this_opts->len > key_index) {
|
|
|
|
return (const gchar *)g_ptr_array_index(this_opts,key_index);
|
2006-02-07 22:08:12 +00:00
|
|
|
} else {
|
|
|
|
/* XXX: assert? */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern const gchar* ex_opt_get_next(const gchar* key) {
|
|
|
|
GPtrArray* this_opts;
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
if (! ex_opts)
|
|
|
|
return 0;
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2013-03-19 04:54:30 +00:00
|
|
|
this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,key);
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2006-02-07 22:08:12 +00:00
|
|
|
if (this_opts) {
|
|
|
|
if (this_opts->len)
|
2013-03-19 04:54:30 +00:00
|
|
|
return (const gchar *)g_ptr_array_remove_index(this_opts,0);
|
2014-02-25 20:42:35 +00:00
|
|
|
else
|
2006-02-07 22:08:12 +00:00
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-10 14:41:10 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2014-10-10 14:41:10 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|