-
Notifications
You must be signed in to change notification settings - Fork 5
/
print_stream_mem.c
56 lines (47 loc) · 1.37 KB
/
print_stream_mem.c
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
#include "ws_dissect.h"
#include <glib.h>
#include <epan/print_stream.h>
struct output_mem {
print_stream_t stream;
char *buf;
GString *gstr;
};
static gboolean destroy_mem(print_stream_t *self)
{
struct output_mem *output = (struct output_mem *)self;
(void)output;
g_free(self);
return TRUE;
}
static gboolean print_line_mem(print_stream_t *self, int indent, const char *line) {
struct output_mem *output = (struct output_mem*)self;
GString *gstr = output->gstr;
while (indent --> 0)
gstr = g_string_append_c(gstr, '\t');
gstr = g_string_append(gstr, line);
gstr = g_string_append_c(gstr, '\n');
return TRUE;
}
static gboolean new_page_mem(print_stream_t *self) {
struct output_mem *output = (struct output_mem*)self;
GString *gstr = output->gstr;
gstr = g_string_append(gstr, "\n\n");
return TRUE;
}
static const print_stream_ops_t print_mem_ops = {
NULL, /* preamble */
print_line_mem,
NULL, /* bookmark */
new_page_mem,
NULL, /* finale */
destroy_mem
};
print_stream_t *ws_dissect_print_stream_gstring_new(GString *gstr) {
struct output_mem *output;
print_stream_t *stream;
stream = (print_stream_t *)g_malloc0(sizeof*output);
stream->ops = &print_mem_ops;
output = stream->data = stream;
output->gstr = gstr;
return stream;
}