summaryrefslogtreecommitdiffstats
path: root/ui/cli/tap-funnel.c
blob: 9adfc2961969ce34522492cb0322ae9b42747361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 *  tap-funnel.c
 *
 * EPAN's GUI mini-API
 *
 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"


#include <epan/funnel.h>
#include <stdio.h>

#include "ws_attributes.h"

#include <wsutil/wslog.h>

void register_tap_listener_funnel(void);

struct _funnel_text_window_t {
    gchar *title;
    GString *text;
};

static GPtrArray *text_windows = NULL;

static funnel_text_window_t *new_text_window(funnel_ops_id_t *ops_id _U_, const gchar *title) {
    funnel_text_window_t *tw = g_new(funnel_text_window_t, 1);
    tw->title = g_strdup(title);
    tw->text = g_string_new("");

    if (!text_windows)
        text_windows = g_ptr_array_new();

    g_ptr_array_add(text_windows, tw);

    return tw;
}

static void text_window_clear(funnel_text_window_t *tw) {
    g_string_free(tw->text, TRUE);
    tw->text = g_string_new("");
}

static void text_window_append(funnel_text_window_t *tw, const char *text ) {
    g_string_append(tw->text, text);
}

static void text_window_set_text(funnel_text_window_t *tw, const char *text) {
    g_string_free(tw->text, TRUE);
    tw->text = g_string_new(text);
}

static void text_window_prepend(funnel_text_window_t *tw, const char *text) {
    g_string_prepend(tw->text, text);
}

static const gchar *text_window_get_text(funnel_text_window_t *tw) {
    return tw->text->str;
}


static const funnel_ops_t funnel_ops = {
    NULL,
    new_text_window,
    text_window_set_text,
    text_window_append,
    text_window_prepend,
    text_window_clear,
    text_window_get_text,
    NULL,
    NULL,
    NULL,
    NULL,
    /*...,*/
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
};


void initialize_funnel_ops(void) {
    funnel_set_funnel_ops(&funnel_ops);
}


void funnel_dump_all_text_windows(void) {
    guint i;

    if (!text_windows) return;

    for ( i = 0 ; i < text_windows->len; i++) {
        funnel_text_window_t *tw = (funnel_text_window_t *)g_ptr_array_index(text_windows, i);
        printf("\n========================== %s "
               "==========================\n%s\n", tw->title, tw->text->str);

        g_ptr_array_remove_index(text_windows, i);
        g_free(tw->title);
        g_string_free(tw->text, TRUE);
        g_free(tw);
    }
}

#if 0

GHashTable *menus = NULL;
typedef struct _menu_cb_t {
    void (*callback)(gpointer);
    void *callback_data;
} menu_cb_t;


static void  init_funnel_cmd(const char *opt_arg, void *data ) {
    gchar **args = g_strsplit(opt_arg, ",", 0);
    gchar **arg;
    menu_cb_t *mcb = data;

    for (arg = args; *arg ; arg++) {
        g_strstrip(*arg);
    }

    if (mcb->callback) {
        mcb->callback(mcb->callback_data);
    }

}

static void register_menu_cb(const char *name,
                             register_stat_group_t group _U_,
                             void (*callback)(gpointer),
                             gpointer callback_data,
                             gboolean retap _U_) {
    menu_cb_t* mcb = g_new(menu_cb_t, 1);
    stat_tap_ui ui_info;

    mcb->callback = callback;
    mcb->callback_data = callback_data;

    if (!menus)
        menus = g_hash_table_new(g_str_hash, g_str_equal);

    g_hash_table_insert(menus, g_strdup(name), mcb);

    ui_info.group = REGISTER_STAT_GROUP_GENERIC;
    ui_info.title = NULL;
    ui_info.cli_string = name;
    ui_info.tap_init_cb = init_funnel_cmd;
    ui_info.nparams = 0;
    ui_info.params = NULL;
    register_stat_tap_ui(&ui_info, mcb);
}

void initialize_funnel_ops(void) {
    funnel_set_funnel_ops(&funnel_ops);
}

#endif
void
register_tap_listener_funnel(void)
{
#if 0
    /* #if 0 at least since Revision Rev 17396 */
    funnel_register_all_menus(register_menu_cb);
#endif
}