3 * Copyright (C) 2016 Jakub Zawadzki
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
23 #include <wsutil/wsjson.h>
24 #include <wsutil/json_dumper.h>
25 #include <wsutil/ws_assert.h>
26 #include <wsutil/wsgcrypt.h>
29 #include <epan/epan_dissect.h>
30 #include <epan/exceptions.h>
31 #include <epan/color_filters.h>
32 #include <epan/prefs.h>
33 #include <epan/prefs-int.h>
34 #include <epan/uat-int.h>
35 #include <wiretap/wtap.h>
37 #include <epan/column.h>
38 #include <epan/column-info.h>
40 #include <ui/ssl_key_export.h>
42 #include <ui/io_graph_item.h>
43 #include <epan/stats_tree_priv.h>
44 #include <epan/stat_tap_ui.h>
45 #include <epan/conversation_table.h>
46 #include <epan/sequence_analysis.h>
47 #include <epan/expert.h>
48 #include <epan/export_object.h>
49 #include <epan/follow.h>
50 #include <epan/rtd_table.h>
51 #include <epan/srt_table.h>
52 #include <epan/to_str.h>
54 #include <epan/dissectors/packet-h225.h>
55 #include <epan/rtp_pt.h>
56 #include <ui/voip_calls.h>
57 #include <ui/rtp_stream.h>
58 #include <ui/tap-rtp-common.h>
59 #include <ui/tap-rtp-analysis.h>
60 #include <ui/cli/tap-protohierstat.h>
61 #include <ui/cli/tap-voip.h>
62 #include <wsutil/version_info.h>
63 #include <epan/to_str.h>
65 #include <epan/addr_resolv.h>
66 #include <epan/dissectors/packet-rtp.h>
67 #include <ui/rtp_media.h>
68 #include <ui/mcast_stream.h>
69 #include <speex/speex_resampler.h>
71 #include <epan/maxmind_db.h>
73 #include <wsutil/pint.h>
74 #include <wsutil/strnatcmp.h>
75 #include <wsutil/strtoi.h>
81 struct sharkd_filter_item
83 uint8_t *filtered
; /* can be NULL if all frames are matching for given filter. */
86 static GHashTable
*filter_table
;
89 static uint32_t rpcid
;
91 static json_dumper dumper
;
95 json_find_attr(const char *buf
, const jsmntok_t
*tokens
, int count
, const char *attr
)
99 for (i
= 0; i
< count
; i
+= 2)
101 const char *tok_attr
= &buf
[tokens
[i
+ 0].start
];
102 const char *tok_value
= &buf
[tokens
[i
+ 1].start
];
104 if (!strcmp(tok_attr
, attr
))
112 json_print_base64(const uint8_t *data
, size_t len
)
114 json_dumper_begin_base64(&dumper
);
115 json_dumper_write_base64(&dumper
, data
, len
);
116 json_dumper_end_base64(&dumper
);
119 static void G_GNUC_PRINTF(2, 3)
120 sharkd_json_value_anyf(const char *key
, const char *format
, ...)
123 json_dumper_set_member_name(&dumper
, key
);
126 va_start(ap
, format
);
127 json_dumper_value_va_list(&dumper
, format
, ap
);
132 sharkd_json_value_string(const char *key
, const char *str
)
135 json_dumper_set_member_name(&dumper
, key
);
136 json_dumper_value_string(&dumper
, str
);
140 sharkd_json_value_base64(const char *key
, const uint8_t *data
, size_t len
)
143 json_dumper_set_member_name(&dumper
, key
);
144 json_print_base64(data
, len
);
147 static void G_GNUC_PRINTF(2, 3)
148 sharkd_json_value_stringf(const char *key
, const char *format
, ...)
151 json_dumper_set_member_name(&dumper
, key
);
154 va_start(ap
, format
);
155 char* sformat
= ws_strdup_printf("\"%s\"", format
);
156 json_dumper_value_va_list(&dumper
, sformat
, ap
);
162 sharkd_json_array_open(const char *key
)
165 json_dumper_set_member_name(&dumper
, key
);
166 json_dumper_begin_array(&dumper
);
170 sharkd_json_array_close(void)
172 json_dumper_end_array(&dumper
);
176 sharkd_json_object_open(const char *key
)
179 json_dumper_set_member_name(&dumper
, key
);
180 json_dumper_begin_object(&dumper
);
184 sharkd_json_object_close(void)
186 json_dumper_end_object(&dumper
);
190 sharkd_json_response_open(uint32_t id
)
192 json_dumper_begin_object(&dumper
); // start the message
193 sharkd_json_value_string("jsonrpc", "2.0");
194 sharkd_json_value_anyf("id", "%d", id
);
198 sharkd_json_response_close(void)
200 json_dumper_end_object(&dumper
); // end the message
202 json_dumper_finish(&dumper
);
205 * We do an explicit fflush after every line, because
206 * we want output to be written to the socket as soon
207 * as the line is complete.
209 * The stream is fully-buffered by default, so it's
210 * only flushed when the buffer fills or the FILE *
211 * is closed. On UN*X, we could set it to be line
212 * buffered, but the MSVC standard I/O routines don't
213 * support line buffering - they only support *byte*
214 * buffering, doing a write for every byte written,
215 * which is too inefficient, and full buffering,
216 * which is what you get if you request line buffering.
222 sharkd_json_result_prologue(uint32_t id
)
224 sharkd_json_response_open(id
);
225 sharkd_json_object_open("result"); // start the result object
229 sharkd_json_result_epilogue(void)
231 json_dumper_end_object(&dumper
); // end the result object
232 sharkd_json_response_close();
236 sharkd_json_result_array_prologue(uint32_t id
)
238 sharkd_json_response_open(id
);
239 sharkd_json_array_open("result"); // start the result array
243 sharkd_json_result_array_epilogue(void)
245 sharkd_json_array_close(); // end of result array
246 sharkd_json_response_close();
250 sharkd_json_simple_ok(uint32_t id
)
252 sharkd_json_result_prologue(id
);
253 sharkd_json_value_string("status", "OK");
254 sharkd_json_result_epilogue();
258 sharkd_json_warning(uint32_t id
, char *warning
)
260 sharkd_json_result_prologue(id
);
261 sharkd_json_value_string("status", "Warning");
262 sharkd_json_value_string("warning", warning
);
263 sharkd_json_result_epilogue();
266 static void G_GNUC_PRINTF(4, 5)
267 sharkd_json_error(uint32_t id
, int code
, char* data
, char* format
, ...)
269 sharkd_json_response_open(id
);
270 sharkd_json_object_open("error");
271 sharkd_json_value_anyf("code", "%d", code
);
275 // format the text message
278 va_start(args
, format
);
279 char *error_msg
= ws_strdup_vprintf(format
, args
);
282 sharkd_json_value_string("message", error_msg
);
287 sharkd_json_object_close();
290 sharkd_json_value_string("data", data
);
292 sharkd_json_response_close();
296 is_param_match(const char *param_in
, const char *valid_param
)
300 if ((ptr
= g_strrstr(valid_param
, "*")))
302 size_t prefix_len
= ptr
- valid_param
;
303 return !strncmp(param_in
, valid_param
, prefix_len
);
306 return !strcmp(param_in
, valid_param
);
310 * json_prep does four things:
312 * 1. check the syntax of the root and parameter members
313 * 2. tokenize the names and values by zero terminating them
314 * 3. unescape the names and values
315 * 4. extracts and saves the rpcid
316 * - we have to do it here as it's needed for the error messages
318 * The objective is to minimise the validation work in the functions
319 * that process each called method.
321 * This gets a little messy as the JSON parser creates a flat list
322 * of all members rather than create a tree.
325 json_prep(char* buf
, const jsmntok_t
* tokens
, int count
)
328 const char* method
= NULL
;
329 char* attr_name
= NULL
;
330 char* attr_value
= NULL
;
332 #define SHARKD_JSON_ANY 0
333 #define SHARKD_JSON_STRING 1
334 #define SHARKD_JSON_INTEGER 2
335 #define SHARKD_JSON_UINTEGER 3
336 #define SHARKD_JSON_FLOAT 4
337 #define SHARKD_JSON_OBJECT 5
338 #define SHARKD_JSON_ARRAY 6
339 #define SHARKD_JSON_BOOLEAN 7
340 #define SHARKD_ARRAY_END 99
342 struct member_attribute
{
343 const char* parent_ctx
;
351 #define SHARKD_MANDATORY true
352 #define SHARKD_OPTIONAL false
355 * The member attribute structure is key to the syntax checking. The
356 * array contains all of the root level (1) member names, the data
357 * types permissible for the value and a boolean that indicates whether
358 * or not the member is mandatory.
360 * Once we get into the next layer (2) of the json tree, we need to check
361 * params member names and data types dependent in the context of the method
365 struct member_attribute name_array
[] = {
367 {NULL
, "jsonrpc", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
368 {NULL
, "userid", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
369 {NULL
, "id", 1, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_MANDATORY
},
370 {NULL
, "method", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
371 {NULL
, "params", 1, JSMN_OBJECT
, SHARKD_JSON_OBJECT
, SHARKD_OPTIONAL
},
374 {"method", "analyse", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
375 {"method", "bye", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
376 {"method", "check", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
377 {"method", "complete", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
378 {"method", "download", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
379 {"method", "dumpconf", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
380 {"method", "follow", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
381 {"method", "frame", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
382 {"method", "frames", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
383 {"method", "info", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
384 {"method", "intervals", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
385 {"method", "iograph", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
386 {"method", "load", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
387 {"method", "setcomment", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
388 {"method", "setconf", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
389 {"method", "status", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
390 {"method", "tap", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
392 // Parameters and their method context
393 {"check", "field", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
394 {"check", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
395 {"complete", "field", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
396 {"complete", "pref", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
397 {"download", "token", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
398 {"dumpconf", "pref", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
399 {"follow", "follow", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
400 {"follow", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
401 {"follow", "sub_stream", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
402 {"frame", "frame", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_MANDATORY
},
403 {"frame", "proto", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
404 {"frame", "ref_frame", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
405 {"frame", "prev_frame", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
406 {"frame", "columns", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
407 {"frame", "color", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
408 {"frame", "bytes", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
409 {"frame", "hidden", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
410 {"frames", "column*", 2, JSMN_UNDEFINED
, SHARKD_JSON_ANY
, SHARKD_OPTIONAL
},
411 {"frames", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
412 {"frames", "skip", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
413 {"frames", "limit", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
414 {"frames", "refs", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
415 {"intervals", "interval", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
416 {"intervals", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
417 {"iograph", "interval", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
418 {"iograph", "interval_units", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
419 {"iograph", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
420 {"iograph", "graph0", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
421 {"iograph", "graph1", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
422 {"iograph", "graph2", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
423 {"iograph", "graph3", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
424 {"iograph", "graph4", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
425 {"iograph", "graph5", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
426 {"iograph", "graph6", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
427 {"iograph", "graph7", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
428 {"iograph", "graph8", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
429 {"iograph", "graph9", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
430 {"iograph", "filter0", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
431 {"iograph", "filter1", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
432 {"iograph", "filter2", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
433 {"iograph", "filter3", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
434 {"iograph", "filter4", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
435 {"iograph", "filter5", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
436 {"iograph", "filter6", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
437 {"iograph", "filter7", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
438 {"iograph", "filter8", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
439 {"iograph", "filter9", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
440 {"iograph", "aot0", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
441 {"iograph", "aot1", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
442 {"iograph", "aot2", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
443 {"iograph", "aot3", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
444 {"iograph", "aot4", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
445 {"iograph", "aot5", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
446 {"iograph", "aot6", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
447 {"iograph", "aot7", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
448 {"iograph", "aot8", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
449 {"iograph", "aot9", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
450 {"load", "file", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
451 {"setcomment", "frame", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_MANDATORY
},
452 {"setcomment", "comment", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
453 {"setconf", "name", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
454 {"setconf", "value", 2, JSMN_UNDEFINED
, SHARKD_JSON_ANY
, SHARKD_MANDATORY
},
455 {"tap", "tap0", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
456 {"tap", "tap1", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
457 {"tap", "tap2", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
458 {"tap", "tap3", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
459 {"tap", "tap4", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
460 {"tap", "tap5", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
461 {"tap", "tap6", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
462 {"tap", "tap7", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
463 {"tap", "tap8", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
464 {"tap", "tap9", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
465 {"tap", "tap10", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
466 {"tap", "tap11", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
467 {"tap", "tap12", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
468 {"tap", "tap13", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
469 {"tap", "tap14", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
470 {"tap", "tap15", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
471 {"tap", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
473 // End of the name_array
474 {NULL
, NULL
, 0, JSMN_STRING
, SHARKD_ARRAY_END
, SHARKD_OPTIONAL
},
479 /* sanity check, and split strings */
480 if (count
< 1 || tokens
[0].type
!= JSMN_OBJECT
)
484 "The request must an object"
489 /* don't need [0] token */
497 "The request must contain name/value pairs"
502 for (i
= 0; i
< count
; i
+= 2)
504 buf
[tokens
[i
+ 0].end
] = '\0';
505 buf
[tokens
[i
+ 1].end
] = '\0';
508 // we must get the id as soon as possible so that it's available in all future error messages
509 attr_value
= (char*)json_find_attr(buf
, tokens
, count
, "id");
512 if (!ws_strtou32(attr_value
, NULL
, &rpcid
))
516 "The id value must be a positive integer"
522 method
= json_find_attr(buf
, tokens
, count
, "method");
526 bool is_supported
= false;
527 i
= 0; // name array index
529 // check that the request method is good
530 while (name_array
[i
].value_type
!= SHARKD_ARRAY_END
)
532 if (name_array
[i
].parent_ctx
)
534 if (!strcmp(method
, name_array
[i
].name
) && !strcmp(name_array
[i
].parent_ctx
, "method"))
535 is_supported
= true; // the method is valid
545 "The method %s is not supported", method
551 for (i
= 0; i
< count
; i
+= 2)
553 if (tokens
[i
].type
!= JSMN_STRING
)
557 "Member names must be a string - member %d is not string", (i
/ 2) + 1
562 attr_name
= &buf
[tokens
[i
+ 0].start
];
563 attr_value
= &buf
[tokens
[i
+ 1].start
];
565 if (!strcmp(attr_name
, "jsonrpc"))
567 if (strcmp(&buf
[tokens
[i
+ 1].start
], "2.0"))
571 "Only JSON %s is supported", "2.0"
577 /* unescape only value, as keys are simple strings */
578 if (tokens
[i
+ 1].type
== JSMN_STRING
&& !json_decode_string_inplace(attr_value
))
582 "Cannot unescape the value string of member %d", (i
/ 2) + 1
587 /* Confirm that the member is valid */
590 // We need to check root members (level 1) and parameters (level 2), hence the for loop.
592 for (int level
= 1; level
< 3; level
++)
596 while (name_array
[j
].value_type
!= SHARKD_ARRAY_END
) // iterate through the array until we hit the end
598 if (is_param_match(attr_name
, name_array
[j
].name
) && name_array
[j
].level
== level
)
600 // We need to be sure the match is in the correct context
601 // i.e. is this a match for a root member (level 1) or for a parameter (level 2).
605 // need to guard against a parameter name matching a method name
608 if (name_array
[j
].parent_ctx
)
614 if (!strcmp(method
, &buf
[tokens
[i
+ 0].start
]))
625 if (level
== 2 && !strcmp(name_array
[j
].parent_ctx
, method
))
639 // The match looks good, let's now check the data types
641 if (tokens
[i
+ 1].type
!= name_array
[j
].type
&& name_array
[j
].type
!= SHARKD_JSON_ANY
)
645 "The data type for member %s is not valid", attr_name
649 else if (name_array
[j
].type
== JSMN_PRIMITIVE
&& name_array
[j
].value_type
== SHARKD_JSON_UINTEGER
)
652 if (!ws_strtou32(attr_value
, NULL
, &temp
) || temp
<= 0)
656 "The value for %s must be a positive integer", name_array
[j
].name
661 else if (name_array
[j
].type
== JSMN_PRIMITIVE
&& name_array
[j
].value_type
== SHARKD_JSON_BOOLEAN
)
663 if (strcmp(attr_value
, "true") && strcmp(attr_value
, "false"))
667 "The value for %s must be a boolean (true or false)", name_array
[j
].name
673 break; // looks like a valid match
683 "%s is not a valid member name", attr_name
689 /* check for mandatory members */
692 while (name_array
[j
].value_type
!= SHARKD_ARRAY_END
)
694 if (name_array
[j
].is_mandatory
&& name_array
[j
].level
== 1)
696 if (!json_find_attr(buf
, tokens
, count
, name_array
[j
].name
))
700 "Mandatory member %s is missing", name_array
[j
].name
708 // check that the current request contains the mandatory parameters
711 while (name_array
[j
].value_type
!= SHARKD_ARRAY_END
)
713 if (name_array
[j
].is_mandatory
&& name_array
[j
].level
== 2 && !strcmp(method
, name_array
[j
].parent_ctx
))
715 if (!json_find_attr(buf
, tokens
, count
, name_array
[j
].name
))
719 "Mandatory parameter %s is missing", name_array
[j
].name
728 // check that the parameters for the current request are valid for the method and that the data type for the value is valid
734 sharkd_session_filter_free(void *data
)
736 struct sharkd_filter_item
*l
= (struct sharkd_filter_item
*) data
;
742 static const struct sharkd_filter_item
*
743 sharkd_session_filter_data(const char *filter
)
745 struct sharkd_filter_item
*l
;
747 l
= (struct sharkd_filter_item
*) g_hash_table_lookup(filter_table
, filter
);
750 uint8_t *filtered
= NULL
;
752 int ret
= sharkd_filter(filter
, &filtered
);
757 l
= g_new(struct sharkd_filter_item
, 1);
758 l
->filtered
= filtered
;
760 g_hash_table_insert(filter_table
, g_strdup(filter
), l
);
767 sharkd_rtp_match_init(rtpstream_id_t
*id
, const char *init_str
)
771 uint32_t tmp_addr_src
, tmp_addr_dst
;
772 address tmp_src_addr
, tmp_dst_addr
;
774 memset(id
, 0, sizeof(*id
));
776 arr
= g_strsplit(init_str
, "_", 7); /* pass larger value, so we'll catch incorrect input :) */
777 if (g_strv_length(arr
) != 5)
780 /* TODO, for now only IPv4 */
781 if (!get_host_ipaddr(arr
[0], &tmp_addr_src
))
784 if (!ws_strtou16(arr
[1], NULL
, &id
->src_port
))
787 if (!get_host_ipaddr(arr
[2], &tmp_addr_dst
))
790 if (!ws_strtou16(arr
[3], NULL
, &id
->dst_port
))
793 if (!ws_hexstrtou32(arr
[4], NULL
, &id
->ssrc
))
796 set_address(&tmp_src_addr
, AT_IPv4
, 4, &tmp_addr_src
);
797 copy_address(&id
->src_addr
, &tmp_src_addr
);
798 set_address(&tmp_dst_addr
, AT_IPv4
, 4, &tmp_addr_dst
);
799 copy_address(&id
->dst_addr
, &tmp_dst_addr
);
809 sharkd_session_process_info_nstat_cb(const void *key
, void *value
, void *userdata _U_
)
811 stat_tap_table_ui
*stat_tap
= (stat_tap_table_ui
*) value
;
813 json_dumper_begin_object(&dumper
);
814 sharkd_json_value_string("name", stat_tap
->title
);
815 sharkd_json_value_stringf("tap", "nstat:%s", (const char *) key
);
816 json_dumper_end_object(&dumper
);
822 sharkd_session_process_info_conv_cb(const void* key
, void* value
, void* userdata _U_
)
824 struct register_ct
*table
= (struct register_ct
*) value
;
826 const char *label
= (const char *) key
;
828 if (get_conversation_packet_func(table
))
830 json_dumper_begin_object(&dumper
);
831 sharkd_json_value_stringf("name", "Conversation List/%s", label
);
832 sharkd_json_value_stringf("tap", "conv:%s", label
);
833 json_dumper_end_object(&dumper
);
836 if (get_endpoint_packet_func(table
))
838 json_dumper_begin_object(&dumper
);
839 sharkd_json_value_stringf("name", "Endpoint/%s", label
);
840 sharkd_json_value_stringf("tap", "endpt:%s", label
);
841 json_dumper_end_object(&dumper
);
847 sharkd_session_seq_analysis_cb(const void *key
, void *value
, void *userdata _U_
)
849 register_analysis_t
*analysis
= (register_analysis_t
*) value
;
851 json_dumper_begin_object(&dumper
);
852 sharkd_json_value_string("name", sequence_analysis_get_ui_name(analysis
));
853 sharkd_json_value_stringf("tap", "seqa:%s", (const char *) key
);
854 json_dumper_end_object(&dumper
);
860 sharkd_export_object_visit_cb(const void *key _U_
, void *value
, void *user_data _U_
)
862 register_eo_t
*eo
= (register_eo_t
*) value
;
864 const int proto_id
= get_eo_proto_id(eo
);
865 const char *filter
= proto_get_protocol_filter_name(proto_id
);
866 const char *label
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
868 json_dumper_begin_object(&dumper
);
869 sharkd_json_value_stringf("name", "Export Object/%s", label
);
870 sharkd_json_value_stringf("tap", "eo:%s", filter
);
871 json_dumper_end_object(&dumper
);
877 sharkd_srt_visit_cb(const void *key _U_
, void *value
, void *user_data _U_
)
879 register_srt_t
*srt
= (register_srt_t
*) value
;
881 const int proto_id
= get_srt_proto_id(srt
);
882 const char *filter
= proto_get_protocol_filter_name(proto_id
);
883 const char *label
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
885 json_dumper_begin_object(&dumper
);
886 sharkd_json_value_stringf("name", "Service Response Time/%s", label
);
887 sharkd_json_value_stringf("tap", "srt:%s", filter
);
888 json_dumper_end_object(&dumper
);
894 sharkd_rtd_visit_cb(const void *key _U_
, void *value
, void *user_data _U_
)
896 register_rtd_t
*rtd
= (register_rtd_t
*) value
;
898 const int proto_id
= get_rtd_proto_id(rtd
);
899 const char *filter
= proto_get_protocol_filter_name(proto_id
);
900 const char *label
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
902 json_dumper_begin_object(&dumper
);
903 sharkd_json_value_stringf("name", "Response Time Delay/%s", label
);
904 sharkd_json_value_stringf("tap", "rtd:%s", filter
);
905 json_dumper_end_object(&dumper
);
911 sharkd_follower_visit_cb(const void *key _U_
, void *value
, void *user_data _U_
)
913 register_follow_t
*follower
= (register_follow_t
*) value
;
915 const int proto_id
= get_follow_proto_id(follower
);
916 const char *label
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
917 const char *filter
= label
; /* correct: get_follow_by_name() is registered by short name */
919 json_dumper_begin_object(&dumper
);
920 sharkd_json_value_stringf("name", "Follow/%s", label
);
921 sharkd_json_value_stringf("tap", "follow:%s", filter
);
922 json_dumper_end_object(&dumper
);
928 sharkd_session_print_capture_types(void)
931 GArray
*writable_type_subtypes
;
932 writable_type_subtypes
= wtap_get_writable_file_types_subtypes(FT_SORT_BY_NAME
);
933 for (i
= 0; i
< writable_type_subtypes
->len
; i
++) {
934 int ft
= g_array_index(writable_type_subtypes
, int, i
);
935 sharkd_json_object_open(NULL
);
936 sharkd_json_value_string("name", wtap_file_type_subtype_name(ft
));
937 sharkd_json_value_string("description", wtap_file_type_subtype_description(ft
));
938 sharkd_json_object_close();
940 g_array_free(writable_type_subtypes
, TRUE
);
943 struct encap_type_info
946 const char *description
;
950 encap_type_info_nat_compare(const void *a
, const void *b
)
952 return ws_ascii_strnatcmp(((const struct encap_type_info
*)a
)->name
,
953 ((const struct encap_type_info
*)b
)->name
);
957 encap_type_info_visit(void *data
, void *user_data _U_
)
959 sharkd_json_object_open(NULL
);
960 sharkd_json_value_string("name", ((struct encap_type_info
*)data
)->name
);
961 sharkd_json_value_string("description", ((struct encap_type_info
*)data
)->description
);
962 sharkd_json_object_close();
966 sharkd_session_print_encap_types(void)
969 struct encap_type_info
*encaps
;
971 encaps
= g_new(struct encap_type_info
, WTAP_NUM_ENCAP_TYPES
);
972 for (i
= 0; i
< WTAP_NUM_ENCAP_TYPES
; i
++) {
973 encaps
[i
].name
= wtap_encap_name(i
);
974 if (encaps
[i
].name
!= NULL
) {
975 encaps
[i
].description
= wtap_encap_description(i
);
976 list
= g_slist_insert_sorted(list
, &encaps
[i
], encap_type_info_nat_compare
);
979 g_slist_foreach(list
, encap_type_info_visit
, NULL
);
985 * sharkd_session_process_info()
987 * Process info request
989 * Output object with attributes:
990 * (m) version - version number
992 * (m) columns - available column formats, array of object with attributes:
993 * 'name' - column name
994 * 'format' - column format-name
996 * (m) stats - available statistics, array of object with attributes:
997 * 'name' - statistic name
998 * 'tap' - sharkd tap-name for statistic
1000 * (m) convs - available conversation list, array of object with attributes:
1001 * 'name' - conversation name
1002 * 'tap' - sharkd tap-name for conversation
1004 * (m) eo - available export object list, array of object with attributes:
1005 * 'name' - export object name
1006 * 'tap' - sharkd tap-name for eo
1008 * (m) srt - available service response time list, array of object with attributes:
1009 * 'name' - service response time name
1010 * 'tap' - sharkd tap-name for srt
1012 * (m) rtd - available response time delay list, array of object with attributes:
1013 * 'name' - response time delay name
1014 * 'tap' - sharkd tap-name for rtd
1016 * (m) seqa - available sequence analysis (flow) list, array of object with attributes:
1017 * 'name' - sequence analysis name
1018 * 'tap' - sharkd tap-name
1020 * (m) taps - available taps, array of object with attributes:
1022 * 'tap' - sharkd tap-name
1024 * (m) follow - available followers, array of object with attributes:
1026 * 'tap' - sharkd tap-name
1028 * (m) ftypes - conversation table for FT_ number to string, array of FT_xxx strings.
1030 * (m) nstat - available table-based taps, array of object with attributes:
1032 * 'tap' - sharkd tap-name
1034 * (m) capture_types - available capture types, array of object with attributes:
1035 * 'name' - capture type name
1036 * 'description' - capture type description
1038 * (m) encap_types - available encapsulation types, array of object with attributes:
1039 * 'name' - encapsulation type name
1040 * 'description' - encapsulation type description
1043 sharkd_session_process_info(void)
1047 sharkd_json_result_prologue(rpcid
);
1049 sharkd_json_array_open("columns");
1050 for (i
= 0; i
< NUM_COL_FMTS
; i
++)
1052 const char *col_format
= col_format_to_string(i
);
1053 const char *col_descr
= col_format_desc(i
);
1055 json_dumper_begin_object(&dumper
);
1056 sharkd_json_value_string("name", col_descr
);
1057 sharkd_json_value_string("format", col_format
);
1058 json_dumper_end_object(&dumper
);
1060 sharkd_json_array_close();
1062 sharkd_json_array_open("stats");
1064 GList
*cfg_list
= stats_tree_get_cfg_list();
1067 for (l
= cfg_list
; l
; l
= l
->next
)
1069 stats_tree_cfg
*cfg
= (stats_tree_cfg
*) l
->data
;
1071 json_dumper_begin_object(&dumper
);
1072 sharkd_json_value_string("name", cfg
->title
);
1073 sharkd_json_value_stringf("tap", "stat:%s", cfg
->abbr
);
1074 json_dumper_end_object(&dumper
);
1077 g_list_free(cfg_list
);
1079 sharkd_json_array_close();
1081 sharkd_json_array_open("ftypes");
1082 for (i
= 0; i
< FT_NUM_TYPES
; i
++)
1083 sharkd_json_value_string(NULL
, ftype_name((ftenum_t
) i
));
1084 sharkd_json_array_close();
1086 sharkd_json_array_open("capture_types");
1087 sharkd_session_print_capture_types();
1088 sharkd_json_array_close();
1090 sharkd_json_array_open("encap_types");
1091 sharkd_session_print_encap_types();
1092 sharkd_json_array_close();
1094 sharkd_json_value_string("version", get_ws_vcs_version_info_short());
1096 sharkd_json_array_open("nstat");
1098 stat_tap_iterate_tables(sharkd_session_process_info_nstat_cb
, &i
);
1099 sharkd_json_array_close();
1101 sharkd_json_array_open("convs");
1103 conversation_table_iterate_tables(sharkd_session_process_info_conv_cb
, &i
);
1104 sharkd_json_array_close();
1106 sharkd_json_array_open("seqa");
1108 sequence_analysis_table_iterate_tables(sharkd_session_seq_analysis_cb
, &i
);
1109 sharkd_json_array_close();
1111 sharkd_json_array_open("taps");
1113 json_dumper_begin_object(&dumper
);
1114 sharkd_json_value_string("name", "UDP Multicast Streams");
1115 sharkd_json_value_string("tap", "multicast");
1116 json_dumper_end_object(&dumper
);
1118 json_dumper_begin_object(&dumper
);
1119 sharkd_json_value_string("name", "RTP streams");
1120 sharkd_json_value_string("tap", "rtp-streams");
1121 json_dumper_end_object(&dumper
);
1123 json_dumper_begin_object(&dumper
);
1124 sharkd_json_value_string("name", "Protocol Hierarchy Statistics");
1125 sharkd_json_value_string("tap", "phs");
1126 json_dumper_end_object(&dumper
);
1128 json_dumper_begin_object(&dumper
);
1129 sharkd_json_value_string("name", "VoIP Calls");
1130 sharkd_json_value_string("tap", "voip-calls");
1131 json_dumper_end_object(&dumper
);
1133 json_dumper_begin_object(&dumper
);
1134 sharkd_json_value_string("name", "VoIP Conversations");
1135 sharkd_json_value_string("tap", "voip-convs");
1136 json_dumper_end_object(&dumper
);
1138 json_dumper_begin_object(&dumper
);
1139 sharkd_json_value_string("name", "Expert Information");
1140 sharkd_json_value_string("tap", "expert");
1141 json_dumper_end_object(&dumper
);
1143 sharkd_json_array_close();
1145 sharkd_json_array_open("eo");
1147 eo_iterate_tables(sharkd_export_object_visit_cb
, &i
);
1148 sharkd_json_array_close();
1150 sharkd_json_array_open("srt");
1152 srt_table_iterate_tables(sharkd_srt_visit_cb
, &i
);
1153 sharkd_json_array_close();
1155 sharkd_json_array_open("rtd");
1157 rtd_table_iterate_tables(sharkd_rtd_visit_cb
, &i
);
1158 sharkd_json_array_close();
1160 sharkd_json_array_open("follow");
1162 follow_iterate_followers(sharkd_follower_visit_cb
, &i
);
1163 sharkd_json_array_close();
1165 sharkd_json_result_epilogue();
1169 * sharkd_session_process_load()
1171 * Process load request
1174 * (m) file - file to be loaded
1176 * Output object with attributes:
1177 * (m) err - error code
1180 sharkd_session_process_load(const char *buf
, const jsmntok_t
*tokens
, int count
)
1182 const char *tok_file
= json_find_attr(buf
, tokens
, count
, "file");
1188 fprintf(stderr
, "load: filename=%s\n", tok_file
);
1190 if (sharkd_cf_open(tok_file
, WTAP_TYPE_AUTO
, false, &err
) != CF_OK
)
1194 "Unable to open the file"
1201 err
= sharkd_load_cap_file();
1203 CATCH(OutOfMemoryError
)
1206 rpcid
, -32603, NULL
,
1207 "Load failed, out of memory"
1209 fprintf(stderr
, "load: OutOfMemoryError\n");
1216 sharkd_json_simple_ok(rpcid
);
1220 sharkd_json_result_prologue(rpcid
);
1221 sharkd_json_value_string("status", wtap_strerror(err
));
1222 sharkd_json_value_anyf("err", "%d", err
);
1223 sharkd_json_result_epilogue();
1229 * sharkd_session_process_status()
1231 * Process status request
1233 * Output object with attributes:
1234 * (m) frames - count of currently loaded frames
1235 * (m) duration - time difference between time of first frame, and last loaded frame
1236 * (o) filename - capture filename
1237 * (o) filesize - capture filesize
1238 * (o) columns - array of column titles
1239 * (o) column_info - array of column infos, array of object with attributes:
1240 * 'title' - column title
1241 * 'format' - column format (%x or %Cus:<expr>:<occurrence> if COL_CUSTOM)
1242 * 'visible' - true if column is visible
1243 * 'display' - column display format; 'U', 'R' or 'D'
1246 sharkd_session_process_status(void)
1248 sharkd_json_result_prologue(rpcid
);
1250 sharkd_json_value_anyf("frames", "%u", cfile
.count
);
1251 sharkd_json_value_anyf("duration", "%.9f", nstime_to_sec(&cfile
.elapsed_time
));
1255 char *name
= g_path_get_basename(cfile
.filename
);
1257 sharkd_json_value_string("filename", name
);
1261 if (cfile
.provider
.wth
)
1263 int64_t file_size
= wtap_file_size(cfile
.provider
.wth
, NULL
);
1266 sharkd_json_value_anyf("filesize", "%" PRId64
, file_size
);
1269 if (cfile
.cinfo
.num_cols
> 0)
1271 sharkd_json_array_open("columns");
1272 for (int i
= 0; i
< cfile
.cinfo
.num_cols
; ++i
)
1274 sharkd_json_value_string(NULL
, get_column_title(i
));
1276 sharkd_json_array_close();
1278 sharkd_json_array_open("column_info");
1279 for (int i
= 0; i
< cfile
.cinfo
.num_cols
; ++i
)
1281 int fmt
= get_column_format(i
);
1282 sharkd_json_object_open(NULL
);
1283 sharkd_json_value_string("title", get_column_title(i
));
1284 if (fmt
!= COL_CUSTOM
)
1286 sharkd_json_value_string("format", col_format_to_string(fmt
));
1288 sharkd_json_value_stringf("format", "%s:%s:%d", col_format_to_string(fmt
), get_column_custom_fields(i
), get_column_custom_occurrence(i
));
1290 sharkd_json_value_anyf("visible", get_column_visible(i
) ? "true" : "false");
1291 sharkd_json_value_stringf("display", "%c", get_column_display_format(i
));
1292 sharkd_json_object_close();
1294 sharkd_json_array_close();
1297 sharkd_json_result_epilogue();
1300 struct sharkd_analyse_data
1302 GHashTable
*protocols_set
;
1303 nstime_t
*first_time
;
1304 nstime_t
*last_time
;
1308 sharkd_session_process_analyse_cb(epan_dissect_t
*edt
, proto_tree
*tree _U_
,
1309 struct epan_column_info
*cinfo _U_
, const GSList
*data_src _U_
, void *data
)
1311 struct sharkd_analyse_data
*analyser
= (struct sharkd_analyse_data
*) data
;
1312 packet_info
*pi
= &edt
->pi
;
1313 frame_data
*fdata
= pi
->fd
;
1315 if (analyser
->first_time
== NULL
|| nstime_cmp(&fdata
->abs_ts
, analyser
->first_time
) < 0)
1316 analyser
->first_time
= &fdata
->abs_ts
;
1318 if (analyser
->last_time
== NULL
|| nstime_cmp(&fdata
->abs_ts
, analyser
->last_time
) > 0)
1319 analyser
->last_time
= &fdata
->abs_ts
;
1323 wmem_list_frame_t
*frame
;
1325 for (frame
= wmem_list_head(pi
->layers
); frame
; frame
= wmem_list_frame_next(frame
))
1327 int proto_id
= GPOINTER_TO_UINT(wmem_list_frame_data(frame
));
1329 if (!g_hash_table_lookup_extended(analyser
->protocols_set
, GUINT_TO_POINTER(proto_id
), NULL
, NULL
))
1331 g_hash_table_insert(analyser
->protocols_set
, GUINT_TO_POINTER(proto_id
), GUINT_TO_POINTER(proto_id
));
1332 sharkd_json_value_string(NULL
, proto_get_protocol_filter_name(proto_id
));
1340 * sharkd_session_process_status()
1342 * Process analyse request
1344 * Output object with attributes:
1345 * (m) frames - count of currently loaded frames
1346 * (m) protocols - protocol list
1347 * (m) first - earliest frame time
1348 * (m) last - latest frame time
1351 sharkd_session_process_analyse(void)
1353 struct sharkd_analyse_data analyser
;
1354 wtap_rec rec
; /* Record information */
1356 analyser
.first_time
= NULL
;
1357 analyser
.last_time
= NULL
;
1358 analyser
.protocols_set
= g_hash_table_new(NULL
/* g_direct_hash() */, NULL
/* g_direct_equal */);
1360 sharkd_json_result_prologue(rpcid
);
1362 sharkd_json_value_anyf("frames", "%u", cfile
.count
);
1364 sharkd_json_array_open("protocols");
1366 wtap_rec_init(&rec
, 1514);
1368 for (uint32_t framenum
= 1; framenum
<= cfile
.count
; framenum
++)
1370 enum dissect_request_status status
;
1374 status
= sharkd_dissect_request(framenum
,
1375 (framenum
!= 1) ? 1 : 0, framenum
- 1,
1376 &rec
, NULL
, SHARKD_DISSECT_FLAG_NULL
,
1377 &sharkd_session_process_analyse_cb
, &analyser
,
1381 case DISSECT_REQUEST_SUCCESS
:
1384 case DISSECT_REQUEST_NO_SUCH_FRAME
:
1385 /* XXX - report the error. */
1388 case DISSECT_REQUEST_READ_ERROR
:
1390 * Free up the error string.
1391 * XXX - report the error.
1398 sharkd_json_array_close();
1400 if (analyser
.first_time
)
1401 sharkd_json_value_anyf("first", "%.9f", nstime_to_sec(analyser
.first_time
));
1403 if (analyser
.last_time
)
1404 sharkd_json_value_anyf("last", "%.9f", nstime_to_sec(analyser
.last_time
));
1406 sharkd_json_result_epilogue();
1408 wtap_rec_cleanup(&rec
);
1410 g_hash_table_destroy(analyser
.protocols_set
);
1413 static column_info
*
1414 sharkd_session_create_columns(column_info
*cinfo
, const char *buf
, const jsmntok_t
*tokens
, int count
)
1416 const char *columns_custom
[32];
1417 uint16_t columns_fmt
[32];
1418 int16_t columns_occur
[32];
1422 for (i
= 0; i
< 32; i
++)
1424 const char *tok_column
;
1425 char tok_column_name
[64];
1428 snprintf(tok_column_name
, sizeof(tok_column_name
), "column%d", i
);
1429 tok_column
= json_find_attr(buf
, tokens
, count
, tok_column_name
);
1430 if (tok_column
== NULL
)
1433 columns_custom
[i
] = NULL
;
1434 columns_occur
[i
] = 0;
1436 if ((custom_sepa
= strchr(tok_column
, ':')))
1438 *custom_sepa
= '\0'; /* XXX, C abuse: discarding-const */
1440 columns_fmt
[i
] = COL_CUSTOM
;
1441 columns_custom
[i
] = tok_column
;
1443 if (!ws_strtoi16(custom_sepa
+ 1, NULL
, &columns_occur
[i
]))
1448 if (!ws_strtou16(tok_column
, NULL
, &columns_fmt
[i
]))
1451 if (columns_fmt
[i
] >= NUM_COL_FMTS
)
1454 /* if custom, that it shouldn't be just custom number -> error */
1455 if (columns_fmt
[i
] == COL_CUSTOM
)
1462 col_setup(cinfo
, cols
);
1464 for (i
= 0; i
< cols
; i
++)
1466 col_item_t
*col_item
= &cinfo
->columns
[i
];
1468 col_item
->col_fmt
= columns_fmt
[i
];
1469 col_item
->col_title
= NULL
; /* no need for title */
1471 if (col_item
->col_fmt
== COL_CUSTOM
)
1473 col_item
->col_custom_fields
= g_strdup(columns_custom
[i
]);
1474 col_item
->col_custom_occurrence
= columns_occur
[i
];
1477 col_item
->col_fence
= 0;
1480 col_finalize(cinfo
);
1486 sharkd_session_process_frames_cb(epan_dissect_t
*edt
, proto_tree
*tree _U_
,
1487 struct epan_column_info
*cinfo
, const GSList
*data_src _U_
, void *data _U_
)
1489 packet_info
*pi
= &edt
->pi
;
1490 frame_data
*fdata
= pi
->fd
;
1491 wtap_block_t pkt_block
= NULL
;
1493 char *comment
= NULL
;
1495 json_dumper_begin_object(&dumper
);
1497 sharkd_json_array_open("c");
1498 for (int col
= 0; col
< cinfo
->num_cols
; ++col
)
1500 sharkd_json_value_string(NULL
, get_column_text(cinfo
, col
));
1502 sharkd_json_array_close();
1504 sharkd_json_value_anyf("num", "%u", pi
->num
);
1507 * Get the block for this record, if it has one.
1509 pkt_block
= sharkd_get_packet_block(fdata
);
1512 * Does this record have any comments?
1514 if (pkt_block
!= NULL
&&
1515 WTAP_OPTTYPE_SUCCESS
== wtap_block_get_nth_string_option_value(pkt_block
, OPT_COMMENT
, 0, &comment
))
1517 sharkd_json_value_anyf("ct", "true");
1519 sharkd_json_array_open("comments");
1520 for (i
= 0; wtap_block_get_nth_string_option_value(pkt_block
, OPT_COMMENT
, i
, &comment
) == WTAP_OPTTYPE_SUCCESS
; i
++) {
1521 sharkd_json_value_string(NULL
, comment
);
1523 sharkd_json_array_close();
1527 sharkd_json_value_anyf("i", "true");
1530 sharkd_json_value_anyf("m", "true");
1532 if (fdata
->color_filter
)
1534 sharkd_json_value_stringf("bg", "%06x", color_t_to_rgb(&fdata
->color_filter
->bg_color
));
1535 sharkd_json_value_stringf("fg", "%06x", color_t_to_rgb(&fdata
->color_filter
->fg_color
));
1538 wtap_block_unref(pkt_block
);
1539 json_dumper_end_object(&dumper
);
1543 * sharkd_session_process_frames()
1545 * Process frames request
1548 * (o) column0...columnXX - requested columns either number in range [0..NUM_COL_FMTS), or custom (syntax <dfilter>:<occurrence>).
1549 * If column0 is not specified default column set will be used.
1550 * (o) filter - filter to be used
1551 * (o) skip=N - skip N frames
1552 * (o) limit=N - show only N frames
1553 * (o) refs - list (comma separated) with sorted time reference frame numbers.
1555 * Output array of frames with attributes:
1556 * (m) c - array of column data
1557 * (m) num - frame number
1558 * (o) i - if frame is ignored
1559 * (o) m - if frame is marked
1560 * (o) ct - if frame is commented
1561 * (o) comments - array of comment strings
1562 * (o) bg - color filter - background color in hex
1563 * (o) fg - color filter - foreground color in hex
1566 sharkd_session_process_frames(const char *buf
, const jsmntok_t
*tokens
, int count
)
1568 const char *tok_filter
= json_find_attr(buf
, tokens
, count
, "filter");
1569 const char *tok_column
= json_find_attr(buf
, tokens
, count
, "column0");
1570 const char *tok_skip
= json_find_attr(buf
, tokens
, count
, "skip");
1571 const char *tok_limit
= json_find_attr(buf
, tokens
, count
, "limit");
1572 const char *tok_refs
= json_find_attr(buf
, tokens
, count
, "refs");
1574 const uint8_t *filter_data
= NULL
;
1576 uint32_t prev_dis_num
= 0;
1577 uint32_t current_ref_frame
= 0, next_ref_frame
= UINT32_MAX
;
1581 wtap_rec rec
; /* Record information */
1582 column_info
*cinfo
= &cfile
.cinfo
;
1583 column_info user_cinfo
;
1587 memset(&user_cinfo
, 0, sizeof(user_cinfo
));
1588 cinfo
= sharkd_session_create_columns(&user_cinfo
, buf
, tokens
, count
);
1592 rpcid
, -13001, NULL
,
1593 "Column definition invalid - note column 6 requires a custom definition"
1601 const struct sharkd_filter_item
*filter_item
;
1603 filter_item
= sharkd_session_filter_data(tok_filter
);
1607 rpcid
, -13002, NULL
,
1608 "Filter expression invalid"
1613 filter_data
= filter_item
->filtered
;
1619 if (!ws_strtou32(tok_skip
, NULL
, &skip
))
1626 if (!ws_strtou32(tok_limit
, NULL
, &limit
))
1632 if (!ws_strtou32(tok_refs
, &tok_refs
, &next_ref_frame
))
1636 sharkd_json_result_array_prologue(rpcid
);
1638 wtap_rec_init(&rec
, 1514);
1640 for (uint32_t framenum
= 1; framenum
<= cfile
.count
; framenum
++)
1643 uint32_t ref_frame
= (framenum
!= 1) ? 1 : 0;
1644 enum dissect_request_status status
;
1648 if (filter_data
&& !(filter_data
[framenum
/ 8] & (1 << (framenum
% 8))))
1654 prev_dis_num
= framenum
;
1660 if (framenum
>= next_ref_frame
)
1662 current_ref_frame
= next_ref_frame
;
1664 if (*tok_refs
!= ',')
1665 next_ref_frame
= UINT32_MAX
;
1667 while (*tok_refs
== ',' && framenum
>= next_ref_frame
)
1669 current_ref_frame
= next_ref_frame
;
1671 if (!ws_strtou32(tok_refs
+ 1, &tok_refs
, &next_ref_frame
))
1673 fprintf(stderr
, "sharkd_session_process_frames() wrong format for refs: %s\n", tok_refs
);
1678 if (*tok_refs
== '\0' && framenum
>= next_ref_frame
)
1680 current_ref_frame
= next_ref_frame
;
1681 next_ref_frame
= UINT32_MAX
;
1685 if (current_ref_frame
)
1686 ref_frame
= current_ref_frame
;
1689 fdata
= sharkd_get_frame(framenum
);
1690 status
= sharkd_dissect_request(framenum
,
1691 ref_frame
, prev_dis_num
,
1693 (fdata
->color_filter
== NULL
) ? SHARKD_DISSECT_FLAG_COLOR
: SHARKD_DISSECT_FLAG_NULL
,
1694 &sharkd_session_process_frames_cb
, NULL
,
1698 case DISSECT_REQUEST_SUCCESS
:
1701 case DISSECT_REQUEST_NO_SUCH_FRAME
:
1702 /* XXX - report the error. */
1705 case DISSECT_REQUEST_READ_ERROR
:
1707 * Free up the error string.
1708 * XXX - report the error.
1714 prev_dis_num
= framenum
;
1716 if (limit
&& --limit
== 0)
1719 sharkd_json_result_array_epilogue();
1721 if (cinfo
!= &cfile
.cinfo
)
1724 wtap_rec_cleanup(&rec
);
1728 sharkd_session_process_tap_stats_node_cb(const char *key
, const stat_node
*n
)
1732 sharkd_json_array_open(key
);
1733 for (node
= n
->children
; node
; node
= node
->next
)
1735 json_dumper_begin_object(&dumper
);
1737 /* code based on stats_tree_get_values_from_node() */
1738 sharkd_json_value_string("name", node
->name
);
1739 sharkd_json_value_anyf("count", "%d", node
->counter
);
1740 if (node
->counter
&& ((node
->st_flags
& ST_FLG_AVERAGE
) || node
->rng
))
1742 switch(node
->datatype
)
1745 sharkd_json_value_anyf("avg", "%.2f", ((float)node
->total
.int_total
) / node
->counter
);
1746 sharkd_json_value_anyf("min", "%d", node
->minvalue
.int_min
);
1747 sharkd_json_value_anyf("max", "%d", node
->maxvalue
.int_max
);
1750 sharkd_json_value_anyf("avg", "%.2f", node
->total
.float_total
/ node
->counter
);
1751 sharkd_json_value_anyf("min", "%f", node
->minvalue
.float_min
);
1752 sharkd_json_value_anyf("max", "%f", node
->maxvalue
.float_max
);
1757 if (node
->st
->elapsed
)
1758 sharkd_json_value_anyf("rate", "%.4f", ((float)node
->counter
) / node
->st
->elapsed
);
1760 if (node
->parent
&& node
->parent
->counter
)
1761 sharkd_json_value_anyf("perc", "%.2f", (node
->counter
* 100.0) / node
->parent
->counter
);
1762 else if (node
->parent
== &(node
->st
->root
))
1763 sharkd_json_value_anyf("perc", "100");
1765 if (prefs
.st_enable_burstinfo
&& node
->max_burst
)
1767 if (prefs
.st_burst_showcount
)
1768 sharkd_json_value_anyf("burstcount", "%d", node
->max_burst
);
1770 sharkd_json_value_anyf("burstrate", "%.4f", ((double)node
->max_burst
) / prefs
.st_burst_windowlen
);
1772 sharkd_json_value_anyf("bursttime", "%.3f", (node
->burst_time
/ 1000.0));
1777 sharkd_session_process_tap_stats_node_cb("sub", node
);
1779 json_dumper_end_object(&dumper
);
1781 sharkd_json_array_close();
1785 * sharkd_session_process_tap_stats_cb()
1789 * (m) tap - tap name
1790 * (m) type:stats - tap output type
1791 * (m) name - stat name
1792 * (m) stats - array of object with attributes:
1793 * (m) name - stat item name
1794 * (m) count - stat item counter
1795 * (o) avg - stat item averange value
1796 * (o) min - stat item min value
1797 * (o) max - stat item max value
1798 * (o) rate - stat item rate value (ms)
1799 * (o) perc - stat item percentage
1800 * (o) burstrate - stat item burst rate
1801 * (o) burstcount - stat item burst count
1802 * (o) burstttme - stat item burst start
1803 * (o) sub - array of object with attributes like in stats node.
1806 sharkd_session_process_tap_stats_cb(void *psp
)
1808 stats_tree
*st
= (stats_tree
*) psp
;
1810 json_dumper_begin_object(&dumper
);
1812 sharkd_json_value_stringf("tap", "stats:%s", st
->cfg
->abbr
);
1813 sharkd_json_value_string("type", "stats");
1814 sharkd_json_value_string("name", st
->cfg
->path
);
1816 sharkd_session_process_tap_stats_node_cb("stats", &st
->root
);
1818 json_dumper_end_object(&dumper
);
1822 sharkd_session_free_tap_stats_cb(void *psp
)
1824 stats_tree
*st
= (stats_tree
*) psp
;
1826 stats_tree_free(st
);
1829 struct sharkd_expert_tap
1836 * sharkd_session_process_tap_expert_cb()
1838 * Output expert tap:
1840 * (m) tap - tap name
1841 * (m) type:expert - tap output type
1842 * (m) details - array of object with attributes:
1843 * (m) f - frame number, which generated expert information
1846 * (m) m - expert message
1850 sharkd_session_process_tap_expert_cb(void *tapdata
)
1852 struct sharkd_expert_tap
*etd
= (struct sharkd_expert_tap
*) tapdata
;
1855 json_dumper_begin_object(&dumper
);
1857 sharkd_json_value_string("tap", "expert");
1858 sharkd_json_value_string("type", "expert");
1860 sharkd_json_array_open("details");
1861 for (list
= etd
->details
; list
; list
= list
->next
)
1863 expert_info_t
*ei
= (expert_info_t
*) list
->data
;
1866 json_dumper_begin_object(&dumper
);
1868 sharkd_json_value_anyf("f", "%u", ei
->packet_num
);
1870 tmp
= try_val_to_str(ei
->severity
, expert_severity_vals
);
1872 sharkd_json_value_string("s", tmp
);
1874 tmp
= try_val_to_str(ei
->group
, expert_group_vals
);
1876 sharkd_json_value_string("g", tmp
);
1878 sharkd_json_value_string("m", ei
->summary
);
1881 sharkd_json_value_string("p", ei
->protocol
);
1883 json_dumper_end_object(&dumper
);
1885 sharkd_json_array_close();
1887 json_dumper_end_object(&dumper
);
1890 static tap_packet_status
1891 sharkd_session_packet_tap_expert_cb(void *tapdata
, packet_info
*pinfo _U_
, epan_dissect_t
*edt _U_
, const void *pointer
, tap_flags_t flags _U_
)
1893 struct sharkd_expert_tap
*etd
= (struct sharkd_expert_tap
*) tapdata
;
1894 const expert_info_t
*ei
= (const expert_info_t
*) pointer
;
1895 expert_info_t
*ei_copy
;
1898 return TAP_PACKET_DONT_REDRAW
;
1900 ei_copy
= g_new(expert_info_t
, 1);
1901 /* Note: this is a shallow copy */
1904 /* ei->protocol, ei->summary might be allocated in packet scope, make a copy. */
1905 ei_copy
->protocol
= g_string_chunk_insert_const(etd
->text
, ei_copy
->protocol
);
1906 ei_copy
->summary
= g_string_chunk_insert_const(etd
->text
, ei_copy
->summary
);
1908 etd
->details
= g_slist_prepend(etd
->details
, ei_copy
);
1910 return TAP_PACKET_REDRAW
;
1914 sharkd_session_free_tap_expert_cb(void *tapdata
)
1916 struct sharkd_expert_tap
*etd
= (struct sharkd_expert_tap
*) tapdata
;
1918 g_slist_free_full(etd
->details
, g_free
);
1919 g_string_chunk_free(etd
->text
);
1924 * sharkd_session_process_tap_flow_cb()
1927 * (m) tap - tap name
1928 * (m) type:flow - tap output type
1929 * (m) nodes - array of strings with node address
1930 * (m) flows - array of object with attributes:
1931 * (m) t - frame time string
1932 * (m) n - array of two numbers with source node index and destination node index
1933 * (m) pn - array of two numbers with source and destination port
1937 sharkd_session_process_tap_flow_cb(void *tapdata
)
1939 seq_analysis_info_t
*graph_analysis
= (seq_analysis_info_t
*) tapdata
;
1943 sequence_analysis_get_nodes(graph_analysis
);
1945 json_dumper_begin_object(&dumper
);
1946 sharkd_json_value_stringf("tap", "seqa:%s", graph_analysis
->name
);
1947 sharkd_json_value_string("type", "flow");
1949 sharkd_json_array_open("nodes");
1950 for (i
= 0; i
< graph_analysis
->num_nodes
; i
++)
1954 addr_str
= address_to_display(NULL
, &(graph_analysis
->nodes
[i
]));
1955 sharkd_json_value_string(NULL
, addr_str
);
1956 wmem_free(NULL
, addr_str
);
1958 sharkd_json_array_close();
1960 sharkd_json_array_open("flows");
1961 flow_list
= g_queue_peek_nth_link(graph_analysis
->items
, 0);
1964 seq_analysis_item_t
*sai
= (seq_analysis_item_t
*) flow_list
->data
;
1966 flow_list
= g_list_next(flow_list
);
1971 json_dumper_begin_object(&dumper
);
1973 sharkd_json_value_string("t", sai
->time_str
);
1974 sharkd_json_value_anyf("n", "[%u,%u]", sai
->src_node
, sai
->dst_node
);
1975 sharkd_json_value_anyf("pn", "[%u,%u]", sai
->port_src
, sai
->port_dst
);
1978 sharkd_json_value_string("c", sai
->comment
);
1980 json_dumper_end_object(&dumper
);
1982 sharkd_json_array_close();
1984 json_dumper_end_object(&dumper
);
1988 sharkd_session_free_tap_flow_cb(void *tapdata
)
1990 seq_analysis_info_t
*graph_analysis
= (seq_analysis_info_t
*) tapdata
;
1992 sequence_analysis_info_free(graph_analysis
);
1995 struct sharkd_conv_tap_data
2004 sharkd_session_geoip_addr(address
*addr
, const char *suffix
)
2006 const mmdb_lookup_t
*lookup
= NULL
;
2007 bool with_geoip
= false;
2010 if (addr
->type
== AT_IPv4
)
2012 const ws_in4_addr
*ip4
= (const ws_in4_addr
*) addr
->data
;
2014 lookup
= maxmind_db_lookup_ipv4(ip4
);
2016 else if (addr
->type
== AT_IPv6
)
2018 const ws_in6_addr
*ip6
= (const ws_in6_addr
*) addr
->data
;
2020 lookup
= maxmind_db_lookup_ipv6(ip6
);
2023 if (!lookup
|| !lookup
->found
)
2026 if (lookup
->country
)
2028 snprintf(json_key
, sizeof(json_key
), "geoip_country%s", suffix
);
2029 sharkd_json_value_string(json_key
, lookup
->country
);
2033 if (lookup
->country_iso
)
2035 snprintf(json_key
, sizeof(json_key
), "geoip_country_iso%s", suffix
);
2036 sharkd_json_value_string(json_key
, lookup
->country_iso
);
2042 snprintf(json_key
, sizeof(json_key
), "geoip_city%s", suffix
);
2043 sharkd_json_value_string(json_key
, lookup
->city
);
2049 snprintf(json_key
, sizeof(json_key
), "geoip_as_org%s", suffix
);
2050 sharkd_json_value_string(json_key
, lookup
->as_org
);
2054 if (lookup
->as_number
> 0)
2056 snprintf(json_key
, sizeof(json_key
), "geoip_as%s", suffix
);
2057 sharkd_json_value_anyf(json_key
, "%u", lookup
->as_number
);
2061 if (lookup
->latitude
>= -90.0 && lookup
->latitude
<= 90.0)
2063 snprintf(json_key
, sizeof(json_key
), "geoip_lat%s", suffix
);
2064 sharkd_json_value_anyf(json_key
, "%f", lookup
->latitude
);
2068 if (lookup
->longitude
>= -180.0 && lookup
->longitude
<= 180.0)
2070 snprintf(json_key
, sizeof(json_key
), "geoip_lon%s", suffix
);
2071 sharkd_json_value_anyf(json_key
, "%f", lookup
->longitude
);
2078 struct sharkd_analyse_rtp_items
2081 uint32_t sequence_num
;
2089 double arrive_offset
;
2091 /* from tap_rtp_stat_t */
2096 struct sharkd_analyse_rtp
2098 const char *tap_name
;
2103 tap_rtp_stat_t statinfo
;
2107 sharkd_session_process_tap_rtp_free_cb(void *tapdata
)
2109 struct sharkd_analyse_rtp
*rtp_req
= (struct sharkd_analyse_rtp
*) tapdata
;
2111 g_slist_free_full(rtp_req
->packets
, g_free
);
2115 static tap_packet_status
2116 sharkd_session_packet_tap_rtp_analyse_cb(void *tapdata
, packet_info
*pinfo
, epan_dissect_t
*edt _U_
, const void *pointer
, tap_flags_t flags _U_
)
2118 struct sharkd_analyse_rtp
*rtp_req
= (struct sharkd_analyse_rtp
*) tapdata
;
2119 const struct _rtp_info
*rtp_info
= (const struct _rtp_info
*) pointer
;
2121 if (rtpstream_id_equal_pinfo_rtp_info(&rtp_req
->id
, pinfo
, rtp_info
))
2123 tap_rtp_stat_t
*statinfo
= &(rtp_req
->statinfo
);
2124 struct sharkd_analyse_rtp_items
*item
;
2126 rtppacket_analyse(statinfo
, pinfo
, rtp_info
);
2128 item
= g_new(struct sharkd_analyse_rtp_items
, 1);
2130 if (!rtp_req
->packets
)
2131 rtp_req
->start_time
= nstime_to_sec(&pinfo
->abs_ts
);
2133 item
->frame_num
= pinfo
->num
;
2134 item
->sequence_num
= rtp_info
->info_seq_num
;
2135 item
->delta
= (statinfo
->flags
& STAT_FLAG_FIRST
) ? 0.0 : statinfo
->delta
;
2136 item
->jitter
= (statinfo
->flags
& STAT_FLAG_FIRST
) ? 0.0 : statinfo
->jitter
;
2137 item
->skew
= (statinfo
->flags
& STAT_FLAG_FIRST
) ? 0.0 : statinfo
->skew
;
2138 item
->bandwidth
= statinfo
->bandwidth
;
2139 item
->marker
= rtp_info
->info_marker_set
? true : false;
2140 item
->arrive_offset
= nstime_to_sec(&pinfo
->abs_ts
) - rtp_req
->start_time
;
2142 item
->flags
= statinfo
->flags
;
2143 item
->pt
= statinfo
->pt
;
2145 /* XXX, O(n) optimize */
2146 rtp_req
->packets
= g_slist_append(rtp_req
->packets
, item
);
2149 return TAP_PACKET_REDRAW
;
2153 * sharkd_session_process_tap_rtp_analyse_cb()
2155 * Output rtp analyse tap:
2156 * (m) tap - tap name
2157 * (m) type - tap output type
2158 * (m) ssrc - RTP SSRC
2159 * (m) max_delta - Max delta (ms)
2160 * (m) max_delta_nr - Max delta packet #
2161 * (m) max_jitter - Max jitter (ms)
2162 * (m) mean_jitter - Mean jitter (ms)
2163 * (m) max_skew - Max skew (ms)
2164 * (m) total_nr - Total number of RTP packets
2165 * (m) seq_err - Number of sequence errors
2166 * (m) duration - Duration (ms)
2167 * (m) items - array of object with attributes:
2168 * (m) f - frame number
2169 * (m) o - arrive offset
2170 * (m) sn - sequence number
2174 * (m) bw - bandwidth
2175 * (o) s - status string
2176 * (o) t - status type
2177 * (o) mark - rtp mark
2180 sharkd_session_process_tap_rtp_analyse_cb(void *tapdata
)
2182 const int RTP_TYPE_CN
= 1;
2183 const int RTP_TYPE_ERROR
= 2;
2184 const int RTP_TYPE_WARN
= 3;
2185 const int RTP_TYPE_PT_EVENT
= 4;
2187 const struct sharkd_analyse_rtp
*rtp_req
= (struct sharkd_analyse_rtp
*) tapdata
;
2188 const tap_rtp_stat_t
*statinfo
= &rtp_req
->statinfo
;
2192 json_dumper_begin_object(&dumper
);
2194 sharkd_json_value_string("tap", rtp_req
->tap_name
);
2195 sharkd_json_value_string("type", "rtp-analyse");
2196 sharkd_json_value_stringf("ssrc", "0x%x", rtp_req
->id
.ssrc
);
2198 sharkd_json_value_anyf("max_delta", "%f", statinfo
->max_delta
);
2199 sharkd_json_value_anyf("max_delta_nr", "%u", statinfo
->max_nr
);
2200 sharkd_json_value_anyf("max_jitter", "%f", statinfo
->max_jitter
);
2201 sharkd_json_value_anyf("mean_jitter", "%f", statinfo
->mean_jitter
);
2202 sharkd_json_value_anyf("max_skew", "%f", statinfo
->max_skew
);
2203 sharkd_json_value_anyf("total_nr", "%u", statinfo
->total_nr
);
2204 sharkd_json_value_anyf("seq_err", "%u", statinfo
->sequence
);
2205 sharkd_json_value_anyf("duration", "%f", statinfo
->time
- statinfo
->start_time
);
2207 sharkd_json_array_open("items");
2208 for (l
= rtp_req
->packets
; l
; l
= l
->next
)
2210 struct sharkd_analyse_rtp_items
*item
= (struct sharkd_analyse_rtp_items
*) l
->data
;
2212 json_dumper_begin_object(&dumper
);
2214 sharkd_json_value_anyf("f", "%u", item
->frame_num
);
2215 sharkd_json_value_anyf("o", "%.9f", item
->arrive_offset
);
2216 sharkd_json_value_anyf("sn", "%u", item
->sequence_num
);
2217 sharkd_json_value_anyf("d", "%.2f", item
->delta
);
2218 sharkd_json_value_anyf("j", "%.2f", item
->jitter
);
2219 sharkd_json_value_anyf("sk", "%.2f", item
->skew
);
2220 sharkd_json_value_anyf("bw", "%.2f", item
->bandwidth
);
2222 if (item
->pt
== PT_CN
)
2224 sharkd_json_value_string("s", "Comfort noise (PT=13, RFC 3389)");
2225 sharkd_json_value_anyf("t", "%d", RTP_TYPE_CN
);
2227 else if (item
->pt
== PT_CN_OLD
)
2229 sharkd_json_value_string("s", "Comfort noise (PT=19, reserved)");
2230 sharkd_json_value_anyf("t", "%d", RTP_TYPE_CN
);
2232 else if (item
->flags
& STAT_FLAG_WRONG_SEQ
)
2234 sharkd_json_value_string("s", "Wrong sequence number");
2235 sharkd_json_value_anyf("t", "%d", RTP_TYPE_ERROR
);
2237 else if (item
->flags
& STAT_FLAG_DUP_PKT
)
2239 sharkd_json_value_string("s", "Suspected duplicate (MAC address) only delta time calculated");
2240 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2242 else if (item
->flags
& STAT_FLAG_REG_PT_CHANGE
)
2244 sharkd_json_value_stringf("s", "Payload changed to PT=%u%s",
2246 (item
->flags
& STAT_FLAG_PT_T_EVENT
) ? " telephone/event" : "");
2247 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2249 else if (item
->flags
& STAT_FLAG_WRONG_TIMESTAMP
)
2251 sharkd_json_value_string("s", "Incorrect timestamp");
2252 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2254 else if ((item
->flags
& STAT_FLAG_PT_CHANGE
)
2255 && !(item
->flags
& STAT_FLAG_FIRST
)
2256 && !(item
->flags
& STAT_FLAG_PT_CN
)
2257 && (item
->flags
& STAT_FLAG_FOLLOW_PT_CN
)
2258 && !(item
->flags
& STAT_FLAG_MARKER
))
2260 sharkd_json_value_string("s", "Marker missing?");
2261 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2263 else if (item
->flags
& STAT_FLAG_PT_T_EVENT
)
2265 sharkd_json_value_stringf("s", "PT=%u telephone/event", item
->pt
);
2266 sharkd_json_value_anyf("t", "%d", RTP_TYPE_PT_EVENT
);
2268 else if (item
->flags
& STAT_FLAG_MARKER
)
2270 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2274 sharkd_json_value_anyf("mark", "1");
2276 json_dumper_end_object(&dumper
);
2278 sharkd_json_array_close();
2280 json_dumper_end_object(&dumper
);
2284 * sharkd_session_process_tap_conv_cb()
2287 * (m) tap - tap name
2288 * (m) type - tap output type
2289 * (m) proto - protocol short name
2290 * (o) filter - filter string
2291 * (o) geoip - whether GeoIP information is available, boolean
2293 * (o) convs - array of object with attributes:
2294 * (m) saddr - source address
2295 * (m) daddr - destination address
2296 * (o) sport - source port
2297 * (o) dport - destination port
2298 * (m) txf - TX frame count
2299 * (m) txb - TX bytes
2300 * (m) rxf - RX frame count
2301 * (m) rxb - RX bytes
2302 * (m) start - (relative) first packet time
2303 * (m) stop - (relative) last packet time
2304 * (o) filter - conversation filter
2306 * (o) hosts - array of object with attributes:
2307 * (m) host - host address
2308 * (o) port - host port
2309 * (m) txf - TX frame count
2310 * (m) txb - TX bytes
2311 * (m) rxf - RX frame count
2312 * (m) rxb - RX bytes
2315 sharkd_session_process_tap_conv_cb(void *arg
)
2317 conv_hash_t
*hash
= (conv_hash_t
*) arg
;
2318 const struct sharkd_conv_tap_data
*iu
= (struct sharkd_conv_tap_data
*) hash
->user_data
;
2320 int proto_with_port
;
2325 json_dumper_begin_object(&dumper
);
2326 sharkd_json_value_string("tap", iu
->type
);
2328 if (!strncmp(iu
->type
, "conv:", 5))
2330 sharkd_json_value_string("type", "conv");
2331 sharkd_json_array_open("convs");
2332 proto
= iu
->type
+ 5;
2334 else if (!strncmp(iu
->type
, "endpt:", 6))
2336 sharkd_json_value_string("type", "host");
2337 sharkd_json_array_open("hosts");
2338 proto
= iu
->type
+ 6;
2342 sharkd_json_value_string("type", "err");
2346 proto_with_port
= (!strcmp(proto
, "TCP") || !strcmp(proto
, "UDP") || !strcmp(proto
, "SCTP"));
2348 if (iu
->hash
.conv_array
!= NULL
&& !strncmp(iu
->type
, "conv:", 5))
2350 for (i
= 0; i
< iu
->hash
.conv_array
->len
; i
++)
2352 conv_item_t
*iui
= &g_array_index(iu
->hash
.conv_array
, conv_item_t
, i
);
2353 char *src_addr
, *dst_addr
;
2354 char *src_port
, *dst_port
;
2357 json_dumper_begin_object(&dumper
);
2359 sharkd_json_value_string("saddr", (src_addr
= get_conversation_address(NULL
, &iui
->src_address
, iu
->resolve_name
)));
2360 sharkd_json_value_string("daddr", (dst_addr
= get_conversation_address(NULL
, &iui
->dst_address
, iu
->resolve_name
)));
2362 if (proto_with_port
)
2364 sharkd_json_value_string("sport", (src_port
= get_conversation_port(NULL
, iui
->src_port
, iui
->ctype
, iu
->resolve_port
)));
2365 sharkd_json_value_string("dport", (dst_port
= get_conversation_port(NULL
, iui
->dst_port
, iui
->ctype
, iu
->resolve_port
)));
2367 wmem_free(NULL
, src_port
);
2368 wmem_free(NULL
, dst_port
);
2371 sharkd_json_value_anyf("rxf", "%" PRIu64
, iui
->rx_frames
);
2372 sharkd_json_value_anyf("rxb", "%" PRIu64
, iui
->rx_bytes
);
2374 sharkd_json_value_anyf("txf", "%" PRIu64
, iui
->tx_frames
);
2375 sharkd_json_value_anyf("txb", "%" PRIu64
, iui
->tx_bytes
);
2377 sharkd_json_value_anyf("start", "%.9f", nstime_to_sec(&iui
->start_time
));
2378 sharkd_json_value_anyf("stop", "%.9f", nstime_to_sec(&iui
->stop_time
));
2380 filter_str
= get_conversation_filter(iui
, CONV_DIR_A_TO_FROM_B
);
2383 sharkd_json_value_string("filter", filter_str
);
2387 wmem_free(NULL
, src_addr
);
2388 wmem_free(NULL
, dst_addr
);
2390 if (sharkd_session_geoip_addr(&(iui
->src_address
), "1"))
2392 if (sharkd_session_geoip_addr(&(iui
->dst_address
), "2"))
2395 json_dumper_end_object(&dumper
);
2398 else if (iu
->hash
.conv_array
!= NULL
&& !strncmp(iu
->type
, "endpt:", 6))
2400 for (i
= 0; i
< iu
->hash
.conv_array
->len
; i
++)
2402 endpoint_item_t
*endpoint
= &g_array_index(iu
->hash
.conv_array
, endpoint_item_t
, i
);
2403 char *host_str
, *port_str
;
2406 json_dumper_begin_object(&dumper
);
2408 sharkd_json_value_string("host", (host_str
= get_conversation_address(NULL
, &endpoint
->myaddress
, iu
->resolve_name
)));
2410 if (proto_with_port
)
2412 sharkd_json_value_string("port", (port_str
= get_endpoint_port(NULL
, endpoint
, iu
->resolve_port
)));
2414 wmem_free(NULL
, port_str
);
2417 sharkd_json_value_anyf("rxf", "%" PRIu64
, endpoint
->rx_frames
);
2418 sharkd_json_value_anyf("rxb", "%" PRIu64
, endpoint
->rx_bytes
);
2420 sharkd_json_value_anyf("txf", "%" PRIu64
, endpoint
->tx_frames
);
2421 sharkd_json_value_anyf("txb", "%" PRIu64
, endpoint
->tx_bytes
);
2423 filter_str
= get_endpoint_filter(endpoint
);
2426 sharkd_json_value_string("filter", filter_str
);
2430 wmem_free(NULL
, host_str
);
2432 if (sharkd_session_geoip_addr(&(endpoint
->myaddress
), ""))
2434 json_dumper_end_object(&dumper
);
2437 sharkd_json_array_close();
2439 sharkd_json_value_string("proto", proto
);
2440 sharkd_json_value_anyf("geoip", with_geoip
? "true" : "false");
2442 json_dumper_end_object(&dumper
);
2446 sharkd_session_free_tap_conv_cb(void *arg
)
2448 conv_hash_t
*hash
= (conv_hash_t
*) arg
;
2449 struct sharkd_conv_tap_data
*iu
= (struct sharkd_conv_tap_data
*) hash
->user_data
;
2451 if (!strncmp(iu
->type
, "conv:", 5))
2453 reset_conversation_table_data(hash
);
2455 else if (!strncmp(iu
->type
, "endpt:", 6))
2457 reset_endpoint_table_data(hash
);
2464 * sharkd_session_process_tap_nstat_cb()
2467 * (m) tap - tap name
2468 * (m) type - tap output type
2469 * (m) fields: array of objects with attributes:
2472 * (m) tables: array of object with attributes:
2473 * (m) t - table title
2474 * (m) i - array of items
2477 sharkd_session_process_tap_nstat_cb(void *arg
)
2479 stat_data_t
*stat_data
= (stat_data_t
*) arg
;
2482 json_dumper_begin_object(&dumper
);
2483 sharkd_json_value_stringf("tap", "nstat:%s", stat_data
->stat_tap_data
->cli_string
);
2484 sharkd_json_value_string("type", "nstat");
2486 sharkd_json_array_open("fields");
2487 for (i
= 0; i
< stat_data
->stat_tap_data
->nfields
; i
++)
2489 stat_tap_table_item
*field
= &(stat_data
->stat_tap_data
->fields
[i
]);
2491 json_dumper_begin_object(&dumper
);
2492 sharkd_json_value_string("c", field
->column_name
);
2493 json_dumper_end_object(&dumper
);
2495 sharkd_json_array_close();
2497 sharkd_json_array_open("tables");
2498 for (i
= 0; i
< stat_data
->stat_tap_data
->tables
->len
; i
++)
2500 stat_tap_table
*table
= g_array_index(stat_data
->stat_tap_data
->tables
, stat_tap_table
*, i
);
2502 json_dumper_begin_object(&dumper
);
2504 sharkd_json_value_string("t", table
->title
);
2506 sharkd_json_array_open("i");
2507 for (j
= 0; j
< table
->num_elements
; j
++)
2509 stat_tap_table_item_type
*field_data
;
2511 field_data
= stat_tap_get_field_data(table
, j
, 0);
2512 if (field_data
== NULL
|| field_data
->type
== TABLE_ITEM_NONE
) /* Nothing for us here */
2515 sharkd_json_array_open(NULL
);
2516 for (k
= 0; k
< table
->num_fields
; k
++)
2518 field_data
= stat_tap_get_field_data(table
, j
, k
);
2520 switch (field_data
->type
)
2522 case TABLE_ITEM_UINT
:
2523 sharkd_json_value_anyf(NULL
, "%u", field_data
->value
.uint_value
);
2526 case TABLE_ITEM_INT
:
2527 sharkd_json_value_anyf(NULL
, "%d", field_data
->value
.int_value
);
2530 case TABLE_ITEM_STRING
:
2531 sharkd_json_value_string(NULL
, field_data
->value
.string_value
);
2534 case TABLE_ITEM_FLOAT
:
2535 sharkd_json_value_anyf(NULL
, "%f", field_data
->value
.float_value
);
2538 case TABLE_ITEM_ENUM
:
2539 sharkd_json_value_anyf(NULL
, "%d", field_data
->value
.enum_value
);
2542 case TABLE_ITEM_NONE
:
2543 sharkd_json_value_anyf(NULL
, "null");
2548 sharkd_json_array_close();
2550 sharkd_json_array_close();
2551 json_dumper_end_object(&dumper
);
2553 sharkd_json_array_close();
2555 json_dumper_end_object(&dumper
);
2559 sharkd_session_free_tap_nstat_cb(void *arg
)
2561 stat_data_t
*stat_data
= (stat_data_t
*) arg
;
2563 free_stat_tables(stat_data
->stat_tap_data
);
2567 * sharkd_session_process_tap_rtd_cb()
2570 * (m) tap - tap name
2571 * (m) type - tap output type
2572 * (m) stats - statistics rows - array object with attributes:
2573 * (m) type - statistic name
2574 * (m) num - number of messages
2575 * (m) min - minimum SRT time
2576 * (m) max - maximum SRT time
2577 * (m) tot - total SRT time
2578 * (m) min_frame - minimal SRT
2579 * (m) max_frame - maximum SRT
2580 * (o) open_req - Open Requests
2581 * (o) disc_rsp - Discarded Responses
2582 * (o) req_dup - Duplicated Requests
2583 * (o) rsp_dup - Duplicated Responses
2584 * (o) open_req - Open Requests
2585 * (o) disc_rsp - Discarded Responses
2586 * (o) req_dup - Duplicated Requests
2587 * (o) rsp_dup - Duplicated Responses
2590 sharkd_session_process_tap_rtd_cb(void *arg
)
2592 rtd_data_t
*rtd_data
= (rtd_data_t
*) arg
;
2593 register_rtd_t
*rtd
= (register_rtd_t
*) rtd_data
->user_data
;
2597 const char *filter
= proto_get_protocol_filter_name(get_rtd_proto_id(rtd
));
2599 /* XXX, some dissectors are having single table and multiple timestats (mgcp, megaco),
2600 * some multiple table and single timestat (radius, h225)
2601 * and it seems that value_string is used one for timestamp-ID, other one for table-ID
2602 * I wonder how it will gonna work with multiple timestats and multiple tables...
2603 * (for usage grep for: register_rtd_table)
2605 const value_string
*vs
= get_rtd_value_string(rtd
);
2607 json_dumper_begin_object(&dumper
);
2608 sharkd_json_value_stringf("tap", "rtd:%s", filter
);
2609 sharkd_json_value_string("type", "rtd");
2611 if (rtd_data
->stat_table
.num_rtds
== 1)
2613 const rtd_timestat
*ms
= &rtd_data
->stat_table
.time_stats
[0];
2615 sharkd_json_value_anyf("open_req", "%u", ms
->open_req_num
);
2616 sharkd_json_value_anyf("disc_rsp", "%u", ms
->disc_rsp_num
);
2617 sharkd_json_value_anyf("req_dup", "%u", ms
->req_dup_num
);
2618 sharkd_json_value_anyf("rsp_dup", "%u", ms
->rsp_dup_num
);
2621 sharkd_json_array_open("stats");
2622 for (i
= 0; i
< rtd_data
->stat_table
.num_rtds
; i
++)
2624 const rtd_timestat
*ms
= &rtd_data
->stat_table
.time_stats
[i
];
2626 for (j
= 0; j
< ms
->num_timestat
; j
++)
2628 const char *type_str
;
2630 if (ms
->rtd
[j
].num
== 0)
2633 json_dumper_begin_object(&dumper
);
2635 if (rtd_data
->stat_table
.num_rtds
== 1)
2636 type_str
= val_to_str_const(j
, vs
, "Other"); /* 1 table - description per row */
2638 type_str
= val_to_str_const(i
, vs
, "Other"); /* multiple table - description per table */
2639 sharkd_json_value_string("type", type_str
);
2641 sharkd_json_value_anyf("num", "%u", ms
->rtd
[j
].num
);
2642 sharkd_json_value_anyf("min", "%.9f", nstime_to_sec(&(ms
->rtd
[j
].min
)));
2643 sharkd_json_value_anyf("max", "%.9f", nstime_to_sec(&(ms
->rtd
[j
].max
)));
2644 sharkd_json_value_anyf("tot", "%.9f", nstime_to_sec(&(ms
->rtd
[j
].tot
)));
2645 sharkd_json_value_anyf("min_frame", "%u", ms
->rtd
[j
].min_num
);
2646 sharkd_json_value_anyf("max_frame", "%u", ms
->rtd
[j
].max_num
);
2648 if (rtd_data
->stat_table
.num_rtds
!= 1)
2650 /* like in tshark, display it on every row */
2651 sharkd_json_value_anyf("open_req", "%u", ms
->open_req_num
);
2652 sharkd_json_value_anyf("disc_rsp", "%u", ms
->disc_rsp_num
);
2653 sharkd_json_value_anyf("req_dup", "%u", ms
->req_dup_num
);
2654 sharkd_json_value_anyf("rsp_dup", "%u", ms
->rsp_dup_num
);
2657 json_dumper_end_object(&dumper
);
2660 sharkd_json_array_close();
2662 json_dumper_end_object(&dumper
);
2666 sharkd_session_free_tap_rtd_cb(void *arg
)
2668 rtd_data_t
*rtd_data
= (rtd_data_t
*) arg
;
2670 free_rtd_table(&rtd_data
->stat_table
);
2675 * sharkd_session_process_tap_srt_cb()
2678 * (m) tap - tap name
2679 * (m) type - tap output type
2681 * (m) tables - array of object with attributes:
2682 * (m) n - table name
2683 * (m) f - table filter
2684 * (o) c - table column name
2685 * (m) r - table rows - array object with attributes:
2687 * (m) idx - procedure index
2688 * (m) num - number of events
2689 * (m) min - minimum SRT time
2690 * (m) max - maximum SRT time
2691 * (m) tot - total SRT time
2694 sharkd_session_process_tap_srt_cb(void *arg
)
2696 srt_data_t
*srt_data
= (srt_data_t
*) arg
;
2697 register_srt_t
*srt
= (register_srt_t
*) srt_data
->user_data
;
2699 const char *filter
= proto_get_protocol_filter_name(get_srt_proto_id(srt
));
2703 json_dumper_begin_object(&dumper
);
2704 sharkd_json_value_stringf("tap", "srt:%s", filter
);
2705 sharkd_json_value_string("type", "srt");
2707 sharkd_json_array_open("tables");
2708 for (i
= 0; i
< srt_data
->srt_array
->len
; i
++)
2711 srt_stat_table
*rst
= g_array_index(srt_data
->srt_array
, srt_stat_table
*, i
);
2715 json_dumper_begin_object(&dumper
);
2718 sharkd_json_value_string("n", rst
->name
);
2719 else if (rst
->short_name
)
2720 sharkd_json_value_string("n", rst
->short_name
);
2722 sharkd_json_value_stringf("n", "table%u", i
);
2724 if (rst
->filter_string
)
2725 sharkd_json_value_string("f", rst
->filter_string
);
2727 if (rst
->proc_column_name
)
2728 sharkd_json_value_string("c", rst
->proc_column_name
);
2730 sharkd_json_array_open("r");
2731 for (j
= 0; j
< rst
->num_procs
; j
++)
2734 srt_procedure_t
*proc
= &rst
->procedures
[j
];
2736 if (proc
->stats
.num
== 0)
2739 json_dumper_begin_object(&dumper
);
2741 sharkd_json_value_string("n", proc
->procedure
);
2743 if (rst
->filter_string
)
2744 sharkd_json_value_anyf("idx", "%d", proc
->proc_index
);
2746 sharkd_json_value_anyf("num", "%u", proc
->stats
.num
);
2748 sharkd_json_value_anyf("min", "%.9f", nstime_to_sec(&proc
->stats
.min
));
2749 sharkd_json_value_anyf("max", "%.9f", nstime_to_sec(&proc
->stats
.max
));
2750 sharkd_json_value_anyf("tot", "%.9f", nstime_to_sec(&proc
->stats
.tot
));
2752 json_dumper_end_object(&dumper
);
2754 sharkd_json_array_close();
2756 json_dumper_end_object(&dumper
);
2758 sharkd_json_array_close();
2760 json_dumper_end_object(&dumper
);
2764 sharkd_session_free_tap_srt_cb(void *arg
)
2766 srt_data_t
*srt_data
= (srt_data_t
*) arg
;
2767 register_srt_t
*srt
= (register_srt_t
*) srt_data
->user_data
;
2769 free_srt_table(srt
, srt_data
->srt_array
);
2770 g_array_free(srt_data
->srt_array
, TRUE
);
2775 sharkd_session_process_tap_phs_cb_aux(phs_t
*rs
)
2777 for (; rs
; rs
= rs
->sibling
) {
2778 if (rs
->protocol
== -1) {
2781 sharkd_json_object_open(NULL
);
2782 sharkd_json_value_string("proto", rs
->proto_name
);
2783 sharkd_json_value_anyf("frames", "%"PRIu32
, rs
->frames
);
2784 sharkd_json_value_anyf("bytes", "%"PRIu64
, rs
->bytes
);
2785 if (rs
->child
!= NULL
&& rs
->child
->protocol
!= -1) {
2786 sharkd_json_array_open("protos");
2787 sharkd_session_process_tap_phs_cb_aux(rs
->child
);
2788 sharkd_json_array_close();
2790 sharkd_json_object_close();
2795 * sharkd_session_process_tap_phs_cb()
2798 * (m) tap - tap name
2799 * (m) type - tap output type
2800 * (m) filter - tap filter argument
2801 * (m) protos - array of proto objects
2804 * (m) proto - protocol name
2805 * (m) frames - frame count
2806 * (m) bytes - bytes count
2807 * (o) protos - array of proto objects
2810 sharkd_session_process_tap_phs_cb(void *arg
)
2812 phs_t
*rs
= (phs_t
*)arg
;
2813 sharkd_json_object_open(NULL
);
2814 sharkd_json_value_string("tap", "phs");
2815 sharkd_json_value_string("type", "phs");
2816 sharkd_json_value_string("filter", rs
->filter
? rs
->filter
: "");
2817 sharkd_json_array_open("protos");
2818 sharkd_session_process_tap_phs_cb_aux(rs
);
2819 sharkd_json_array_close();
2820 sharkd_json_object_close();
2824 sharkd_session_free_tap_phs_cb(void *arg
)
2826 phs_t
*rs
= (phs_t
*)arg
;
2830 struct sharkd_export_object_list
2832 struct sharkd_export_object_list
*next
;
2839 static struct sharkd_export_object_list
*sharkd_eo_list
;
2842 * sharkd_session_process_tap_eo_cb()
2845 * (m) tap - tap name
2846 * (m) type - tap output type
2847 * (m) proto - protocol short name
2848 * (m) objects - array of object with attributes:
2849 * (m) pkt - packet number
2850 * (o) hostname - hostname
2851 * (o) type - content type
2852 * (o) filename - filename
2853 * (m) len - object length
2854 * (m) sha1 - object's sha1 sum
2857 sharkd_session_process_tap_eo_cb(void *tapdata
)
2859 export_object_list_t
*tap_object
= (export_object_list_t
*) tapdata
;
2860 struct sharkd_export_object_list
*object_list
= (struct sharkd_export_object_list
*) tap_object
->gui_data
;
2863 char sha1sum_bytes
[HASH_SHA1_LENGTH
], *sha1sum_str
;
2865 json_dumper_begin_object(&dumper
);
2866 sharkd_json_value_string("tap", object_list
->type
);
2867 sharkd_json_value_string("type", "eo");
2869 sharkd_json_value_string("proto", object_list
->proto
);
2871 sharkd_json_array_open("objects");
2872 for (slist
= object_list
->entries
; slist
; slist
= slist
->next
)
2874 const export_object_entry_t
*eo_entry
= (export_object_entry_t
*) slist
->data
;
2876 json_dumper_begin_object(&dumper
);
2878 sharkd_json_value_anyf("pkt", "%u", eo_entry
->pkt_num
);
2880 if (eo_entry
->hostname
)
2881 sharkd_json_value_string("hostname", eo_entry
->hostname
);
2883 if (eo_entry
->content_type
)
2884 sharkd_json_value_string("type", eo_entry
->content_type
);
2886 if (eo_entry
->filename
)
2887 sharkd_json_value_string("filename", eo_entry
->filename
);
2889 sharkd_json_value_stringf("_download", "%s_%d", object_list
->type
, i
);
2891 sharkd_json_value_anyf("len", "%zu", eo_entry
->payload_len
);
2893 gcry_md_hash_buffer(GCRY_MD_SHA1
, sha1sum_bytes
, eo_entry
->payload_data
, eo_entry
->payload_len
);
2894 sha1sum_str
= bytes_to_str(NULL
, sha1sum_bytes
, HASH_SHA1_LENGTH
);
2895 sharkd_json_value_string("sha1", sha1sum_str
);
2896 g_free(sha1sum_str
);
2898 json_dumper_end_object(&dumper
);
2902 sharkd_json_array_close();
2904 json_dumper_end_object(&dumper
);
2908 sharkd_eo_object_list_add_entry(void *gui_data
, export_object_entry_t
*entry
)
2910 struct sharkd_export_object_list
*object_list
= (struct sharkd_export_object_list
*) gui_data
;
2912 object_list
->entries
= g_slist_append(object_list
->entries
, entry
);
2915 static export_object_entry_t
*
2916 sharkd_eo_object_list_get_entry(void *gui_data
, int row
)
2918 struct sharkd_export_object_list
*object_list
= (struct sharkd_export_object_list
*) gui_data
;
2920 return (export_object_entry_t
*) g_slist_nth_data(object_list
->entries
, row
);
2923 static struct sharkd_export_object_list
*
2924 sharkd_eo_object_list_get_entry_by_type(void *gui_data
, const char *tap_type
)
2926 struct sharkd_export_object_list
*object_list
= (struct sharkd_export_object_list
*) gui_data
;
2927 for (; object_list
; object_list
= object_list
->next
)
2929 if (!strcmp(object_list
->type
, tap_type
))
2937 * sharkd_session_process_tap_rtp_cb()
2939 * Output RTP streams tap:
2940 * (m) tap - tap name
2941 * (m) type - tap output type
2942 * (m) streams - array of object with attributes:
2943 * (m) ssrc - RTP synchronization source identifier
2944 * (m) payload - stream payload
2945 * (m) saddr - source address
2946 * (m) sport - source port
2947 * (m) daddr - destination address
2948 * (m) dport - destination port
2949 * (m) pkts - packets count
2950 * (m) max_delta - max delta (ms)
2951 * (m) max_jitter - max jitter (ms)
2952 * (m) mean_jitter - mean jitter (ms)
2955 * (m) problem - if analyser found the problem
2956 * (m) ipver - address IP version (4 or 6)
2959 sharkd_session_process_tap_rtp_cb(void *arg
)
2961 rtpstream_tapinfo_t
*rtp_tapinfo
= (rtpstream_tapinfo_t
*) arg
;
2965 json_dumper_begin_object(&dumper
);
2966 sharkd_json_value_string("tap", "rtp-streams");
2967 sharkd_json_value_string("type", "rtp-streams");
2969 sharkd_json_array_open("streams");
2970 for (listx
= g_list_first(rtp_tapinfo
->strinfo_list
); listx
; listx
= listx
->next
)
2972 rtpstream_info_t
*streaminfo
= (rtpstream_info_t
*) listx
->data
;
2973 rtpstream_info_calc_t calc
;
2975 rtpstream_info_calculate(streaminfo
, &calc
);
2977 json_dumper_begin_object(&dumper
);
2979 sharkd_json_value_stringf("ssrc", "0x%x", calc
.ssrc
);
2980 sharkd_json_value_string("payload", calc
.all_payload_type_names
);
2982 sharkd_json_value_string("saddr", calc
.src_addr_str
);
2983 sharkd_json_value_anyf("sport", "%u", calc
.src_port
);
2984 sharkd_json_value_string("daddr", calc
.dst_addr_str
);
2985 sharkd_json_value_anyf("dport", "%u", calc
.dst_port
);
2987 sharkd_json_value_anyf("start_time", "%f", calc
.start_time_ms
);
2988 sharkd_json_value_anyf("duration", "%f", calc
.duration_ms
);
2990 sharkd_json_value_anyf("pkts", "%u", calc
.packet_count
);
2991 sharkd_json_value_anyf("lost", "%u", calc
.lost_num
);
2992 sharkd_json_value_anyf("lost_percent", "%f", calc
.lost_perc
);
2994 sharkd_json_value_anyf("max_delta", "%f",calc
.max_delta
);
2995 sharkd_json_value_anyf("min_delta", "%f",calc
.min_delta
);
2996 sharkd_json_value_anyf("mean_delta", "%f",calc
.mean_delta
);
2997 sharkd_json_value_anyf("min_jitter", "%f", calc
.min_jitter
);
2998 sharkd_json_value_anyf("max_jitter", "%f", calc
.max_jitter
);
2999 sharkd_json_value_anyf("mean_jitter", "%f", calc
.mean_jitter
);
3001 sharkd_json_value_anyf("expectednr", "%u", calc
.packet_expected
);
3002 sharkd_json_value_anyf("totalnr", "%u", calc
.total_nr
);
3004 sharkd_json_value_anyf("problem", calc
.problem
? "true" : "false");
3007 sharkd_json_value_anyf("ipver", "%d", (streaminfo
->id
.src_addr
.type
== AT_IPv6
) ? 6 : 4);
3009 rtpstream_info_calc_free(&calc
);
3011 json_dumper_end_object(&dumper
);
3013 sharkd_json_array_close();
3015 json_dumper_end_object(&dumper
);
3019 * sharkd_session_process_tap_multicast_cb()
3021 * Output UDP Multicast streams tap:
3022 * (m) tap - tap name
3023 * (m) type - tap output type
3024 * (m) bufferThresholdBytes - byte count for a stream where a buffer alarm should be reported
3025 * (m) burstIntervalMs - analysis interval in milliseconds
3026 * (m) burstThresholdPackets - count of packets in an interval that should trigger an alarm
3027 * (m) streams - array of streams with metrics:
3028 * (m) saddr - source address
3029 * (m) sport - source port
3030 * (m) daddr - destination address
3031 * (m) dport - destination port
3032 * (m) packets - object group for packet metrics with attributes:
3033 * (m) number - count of packets in the stream
3034 * (m) perSecond - average number of packets per seconds in the stream
3035 * (m) bandwidth - object group for bandwidth metrics with attributes:
3036 * (m) average - average measured bitrate in the stream
3037 * (m) max - max measured bitrate in the stream
3038 * (m) buffer - object group for buffer metrics with attributes:
3039 * (m) alarms - number of times the stream exceeded the buffer threshold
3040 * (m) max - highest stream buffer utilization
3041 * (m) burst - object group for burst metrics with attributes:
3042 * (m) alarms - number of times the stream exceeded the burst threshold
3043 * (m) max - most stream packets measured in a burst interval
3046 sharkd_session_process_tap_multicast_cb(void *arg
)
3048 mcaststream_tapinfo_t
*tapinfo
= (mcaststream_tapinfo_t
*)arg
;
3052 json_dumper_begin_object(&dumper
);
3054 sharkd_json_value_string("tap", "multicast");
3055 sharkd_json_value_string("type", "multicast");
3057 sharkd_json_value_anyf("bufferThresholdBytes", "%u", mcast_stream_bufferalarm
);
3058 sharkd_json_value_anyf("burstIntervalMs", "%u", mcast_stream_burstint
);
3059 sharkd_json_value_anyf("burstThresholdPackets", "%u", mcast_stream_trigger
);
3061 sharkd_json_array_open("streams");
3062 for (list_item
= g_list_first(tapinfo
->strinfo_list
); list_item
; list_item
= list_item
->next
) {
3063 mcast_stream_info_t
*stream_info
= (mcast_stream_info_t
*) list_item
->data
;
3064 sharkd_json_object_open(NULL
);
3066 addr_str
= address_to_display(NULL
, &stream_info
->src_addr
);
3067 sharkd_json_value_string("saddr", addr_str
);
3068 wmem_free(NULL
, addr_str
);
3069 sharkd_json_value_anyf("sport", "%u", stream_info
->src_port
);
3070 addr_str
= address_to_display(NULL
, &stream_info
->dest_addr
);
3071 sharkd_json_value_string("daddr", addr_str
);
3072 wmem_free(NULL
, addr_str
);
3073 sharkd_json_value_anyf("dport", "%u", stream_info
->dest_port
);
3074 sharkd_json_object_open("packets");
3076 sharkd_json_value_anyf("number", "%u", stream_info
->npackets
);
3077 sharkd_json_value_anyf("perSecond", "%f", stream_info
->apackets
);
3079 sharkd_json_object_close();
3080 sharkd_json_object_open("bandwidth");
3082 sharkd_json_value_anyf("average", "%f", stream_info
->average_bw
);
3083 sharkd_json_value_anyf("max", "%f", stream_info
->element
.maxbw
);
3085 sharkd_json_object_close();
3086 sharkd_json_object_open("buffer");
3088 sharkd_json_value_anyf("alarms", "%u", stream_info
->element
.numbuffalarms
);
3089 sharkd_json_value_anyf("max", "%u", stream_info
->element
.topbuffusage
);
3091 sharkd_json_object_close();
3092 sharkd_json_object_open("burst");
3094 sharkd_json_value_anyf("alarms", "%u", stream_info
->element
.numbursts
);
3095 sharkd_json_value_anyf("max", "%u", stream_info
->element
.topburstsize
);
3097 sharkd_json_object_close();
3099 sharkd_json_object_close();
3101 sharkd_json_array_close();
3103 json_dumper_end_object(&dumper
);
3107 sharkd_session_process_free_tap_multicast_cb(void *tapdata
)
3109 mcaststream_tapinfo_t
*tapinfo
= (mcaststream_tapinfo_t
*)tapdata
;
3111 mcaststream_reset(tapinfo
);
3117 * sharkd_session_process_tap_voip_calls_cb()
3119 * Output VoIP Calls tap:
3120 * (m) tap - tap name
3121 * (m) type - tap output type
3122 * (m) calls - array of objects with attributes:
3123 * (m) call - call number
3124 * (m) start_time - start timestamp
3125 * (m) stop_time - stop timestamp
3126 * (m) initial_speaker - address of initial speaker
3127 * (m) from - from address
3128 * (m) to - to address
3129 * (m) protocol - protocol name
3130 * (m) packets - packet count
3131 * (m) state - state string
3132 * (m) comment - comment string
3135 sharkd_session_process_tap_voip_calls_cb(void *arg
)
3137 voip_calls_tapinfo_t
*tapinfo
= (voip_calls_tapinfo_t
*)arg
;
3139 GList
*cur_call
= g_queue_peek_nth_link(tapinfo
->callsinfos
, 0);
3140 sharkd_json_object_open(NULL
);
3141 sharkd_json_value_string("tap", "voip-calls");
3142 sharkd_json_value_string("type", "voip-calls");
3143 sharkd_json_array_open("calls");
3144 while (cur_call
&& cur_call
->data
) {
3145 voip_calls_info_t
*call_info_
= (voip_calls_info_t
*) cur_call
->data
;
3146 sharkd_json_object_open(NULL
);
3147 sharkd_json_value_anyf("call", "%hu", call_info_
->call_num
);
3148 sharkd_json_value_anyf("start_time", "%.6f", nstime_to_sec(&(call_info_
->start_rel_ts
)));
3149 sharkd_json_value_anyf("stop_time", "%.6f", nstime_to_sec(&(call_info_
->stop_rel_ts
)));
3150 addr_str
= address_to_display(NULL
, &(call_info_
->initial_speaker
));
3151 sharkd_json_value_string("initial_speaker", addr_str
);
3152 wmem_free(NULL
, addr_str
);
3153 sharkd_json_value_string("from", call_info_
->from_identity
);
3154 sharkd_json_value_string("to", call_info_
->to_identity
);
3155 sharkd_json_value_string("protocol", ((call_info_
->protocol
== VOIP_COMMON
) && call_info_
->protocol_name
) ?
3156 call_info_
->protocol_name
: voip_protocol_name
[call_info_
->protocol
]);
3157 sharkd_json_value_anyf("packets", "%u", call_info_
->npackets
);
3158 sharkd_json_value_string("state", voip_call_state_name
[call_info_
->call_state
]);
3159 sharkd_json_value_string("comment", call_info_
->call_comment
);
3160 sharkd_json_object_close();
3161 cur_call
= g_list_next(cur_call
);
3163 sharkd_json_array_close();
3164 sharkd_json_object_close();
3168 sharkd_session_free_tap_voip_calls_cb(void *tapdata
)
3170 voip_calls_tapinfo_t
*tapinfo
= (voip_calls_tapinfo_t
*)tapdata
;
3171 voip_calls_remove_all_tap_listeners(tapinfo
);
3172 if (tapinfo
->callsinfos
!= NULL
) {
3173 g_queue_free(tapinfo
->callsinfos
);
3175 if (tapinfo
->graph_analysis
!= NULL
) {
3176 sequence_analysis_info_free(tapinfo
->graph_analysis
);
3178 memset(tapinfo
, 0, sizeof(*tapinfo
));
3182 struct sharkd_voip_convs_req
{
3183 voip_calls_tapinfo_t
*tapinfo
;
3184 const char *tap_name
;
3188 * sharkd_session_process_tap_voip_convs_cb()
3190 * Output VoIP Conversations tap:
3191 * (m) tap - tap name
3192 * (m) type - tap output type
3193 * (m) convs - array of objects with attributes:
3194 * (m) frame - frame number
3195 * (m) call - call number
3196 * (m) time - timestamp
3197 * (m) dst_addr - destination address
3198 * (m) dst_port - destination port
3199 * (m) src_addr - source address
3200 * (m) src_port - source port
3201 * (m) label - label string
3202 * (m) comment - comment string
3205 sharkd_session_process_tap_voip_convs_cb(void *arg
)
3207 struct sharkd_voip_convs_req
*voip_convs_req
= (struct sharkd_voip_convs_req
*)arg
;
3208 voip_calls_tapinfo_t
*tapinfo
= voip_convs_req
->tapinfo
;
3209 seq_analysis_info_t
*sainfo
= tapinfo
->graph_analysis
;
3211 sequence_analysis_list_sort(sainfo
);
3212 sharkd_json_object_open(NULL
);
3213 sharkd_json_value_string("tap", voip_convs_req
->tap_name
);
3214 sharkd_json_value_string("type", "voip-convs");
3215 sharkd_json_array_open("convs");
3216 for (GList
*cur
= g_queue_peek_nth_link(sainfo
->items
, 0); cur
; cur
= g_list_next(cur
)) {
3217 seq_analysis_item_t
*sai
= (seq_analysis_item_t
*) cur
->data
;
3218 if ((voip_conv_sel
[sai
->conv_num
/ VOIP_CONV_BITS
] & (1 << (sai
->conv_num
% VOIP_CONV_BITS
))) == 0)
3220 sharkd_json_object_open(NULL
);
3221 sharkd_json_value_anyf("frame", "%d", sai
->frame_number
);
3222 sharkd_json_value_anyf("call", "%d", sai
->conv_num
);
3223 sharkd_json_value_string("time", sai
->time_str
);
3224 addr_str
= address_to_display(NULL
, &(sai
->dst_addr
));
3225 sharkd_json_value_string("dst_addr", addr_str
);
3226 wmem_free(NULL
, addr_str
);
3227 sharkd_json_value_anyf("dst_port", "%d", sai
->port_dst
);
3228 addr_str
= address_to_display(NULL
, &(sai
->src_addr
));
3229 sharkd_json_value_string("src_addr", addr_str
);
3230 wmem_free(NULL
, addr_str
);
3231 sharkd_json_value_anyf("src_port", "%d", sai
->port_src
);
3232 sharkd_json_value_string("label", sai
->frame_label
);
3233 sharkd_json_value_string("comment", sai
->comment
);
3234 sharkd_json_object_close();
3236 sharkd_json_array_close();
3237 sharkd_json_object_close();
3241 sharkd_session_free_tap_voip_convs_cb(void *tapdata
)
3243 struct sharkd_voip_convs_req
*voip_convs_req
= (struct sharkd_voip_convs_req
*)tapdata
;
3244 voip_calls_tapinfo_t
*tapinfo
= voip_convs_req
->tapinfo
;
3245 voip_calls_remove_all_tap_listeners(tapinfo
);
3246 if (tapinfo
->callsinfos
!= NULL
) {
3247 g_queue_free(tapinfo
->callsinfos
);
3249 if (tapinfo
->graph_analysis
!= NULL
) {
3250 sequence_analysis_info_free(tapinfo
->graph_analysis
);
3252 memset(tapinfo
, 0, sizeof(*tapinfo
));
3253 g_free(voip_convs_req
);
3256 struct sharkd_hosts_req
{
3257 const char *tap_name
;
3263 sharkd_session_tap_ipv4_host_compare(const void *a
, const void *b
)
3265 return ws_ascii_strnatcmp(((const hashipv4_t
*)a
)->name
,
3266 ((const hashipv4_t
*)b
)->name
);
3270 sharkd_session_tap_ipv6_host_compare(const void *a
, const void *b
)
3272 return ws_ascii_strnatcmp(((const hashipv6_t
*)a
)->name
,
3273 ((const hashipv6_t
*)b
)->name
);
3277 sharkd_session_tap_ipv4_host_print(void *data
, void *user_data _U_
)
3279 hashipv4_t
*ipv4_hash_table_entry
= (hashipv4_t
*)data
;
3280 sharkd_json_object_open(NULL
);
3281 sharkd_json_value_string("name", ipv4_hash_table_entry
->name
);
3282 sharkd_json_value_string("addr", ipv4_hash_table_entry
->ip
);
3283 sharkd_json_object_close();
3287 sharkd_session_tap_ipv6_host_print(void *data
, void *user_data _U_
)
3289 hashipv6_t
*ipv6_hash_table_entry
= (hashipv6_t
*)data
;
3290 sharkd_json_object_open(NULL
);
3291 sharkd_json_value_string("name", ipv6_hash_table_entry
->name
);
3292 sharkd_json_value_string("addr", ipv6_hash_table_entry
->ip6
);
3293 sharkd_json_object_close();
3297 sharkd_session_tap_ipv4_host_insert_sorted(void *key _U_
, void *value
, void *user_data
)
3299 hashipv4_t
*ipv4_hash_table_entry
= (hashipv4_t
*)value
;
3300 GSList
**list
= (GSList
**)user_data
;
3301 if ((ipv4_hash_table_entry
->flags
& NAME_RESOLVED
)) {
3302 *list
= g_slist_insert_sorted(*list
, ipv4_hash_table_entry
, sharkd_session_tap_ipv4_host_compare
);
3307 sharkd_session_tap_ipv6_host_insert_sorted(void *key _U_
, void *value
, void *user_data
)
3309 hashipv6_t
*ipv6_hash_table_entry
= (hashipv6_t
*)value
;
3310 GSList
**list
= (GSList
**) user_data
;
3311 if ((ipv6_hash_table_entry
->flags
& NAME_RESOLVED
)) {
3312 *list
= g_slist_insert_sorted(*list
, ipv6_hash_table_entry
, sharkd_session_tap_ipv6_host_compare
);
3317 sharkd_session_tap_ipv4_hosts_print(void)
3319 wmem_map_t
*ipv4_hash_table
= get_ipv4_hash_table();
3320 if (!ipv4_hash_table
)
3322 GSList
*list
= NULL
;
3323 wmem_map_foreach(ipv4_hash_table
, sharkd_session_tap_ipv4_host_insert_sorted
, &list
);
3324 g_slist_foreach(list
, sharkd_session_tap_ipv4_host_print
, NULL
);
3329 sharkd_session_tap_ipv6_hosts_print(void)
3331 wmem_map_t
*ipv6_hash_table
= get_ipv6_hash_table();
3332 if (!ipv6_hash_table
)
3334 GSList
*list
= NULL
;
3335 wmem_map_foreach(ipv6_hash_table
, sharkd_session_tap_ipv6_host_insert_sorted
, &list
);
3336 g_slist_foreach(list
, sharkd_session_tap_ipv6_host_print
, NULL
);
3341 * sharkd_session_process_tap_hosts_cb()
3344 * (m) tap - tap name
3345 * (m) type - tap output type
3346 * (o) ipv4_hosts - array of objects with attributes:
3347 * (m) addr - ipv4 address
3348 * (m) name - resolved name of address
3349 * (o) ipv6_hosts - array of objects with attributes:
3350 * (m) addr - ipv6 address
3351 * (m) name - resolved name of address
3354 sharkd_session_process_tap_hosts_cb(void *arg
)
3356 struct sharkd_hosts_req
*hosts_req
= (struct sharkd_hosts_req
*)arg
;
3357 sharkd_json_object_open(NULL
);
3358 sharkd_json_value_string("tap", hosts_req
->tap_name
);
3359 sharkd_json_value_string("type", "hosts");
3360 if (hosts_req
->dump_v4
) {
3361 sharkd_json_array_open("ipv4_hosts");
3362 sharkd_session_tap_ipv4_hosts_print();
3363 sharkd_json_array_close();
3365 if (hosts_req
->dump_v6
) {
3366 sharkd_json_array_open("ipv6_hosts");
3367 sharkd_session_tap_ipv6_hosts_print();
3368 sharkd_json_array_close();
3370 sharkd_json_object_close();
3374 sharkd_session_free_tap_hosts_cb(void *tapdata
)
3376 struct sharkd_hosts_req
*hosts_req
= (struct sharkd_hosts_req
*)tapdata
;
3381 sharkd_session_eo_register_tap_listener(register_eo_t
*eo
, const char *tap_type
, const char *tap_filter
, tap_draw_cb tap_draw
, void **ptap_data
, GFreeFunc
* ptap_free
)
3383 export_object_list_t
*eo_object
;
3384 struct sharkd_export_object_list
*object_list
;
3386 object_list
= sharkd_eo_object_list_get_entry_by_type(sharkd_eo_list
, tap_type
);
3389 g_slist_free_full(object_list
->entries
, (GDestroyNotify
) eo_free_entry
);
3390 object_list
->entries
= NULL
;
3394 object_list
= g_new(struct sharkd_export_object_list
, 1);
3395 object_list
->type
= g_strdup(tap_type
);
3396 object_list
->proto
= proto_get_protocol_short_name(find_protocol_by_id(get_eo_proto_id(eo
)));
3397 object_list
->entries
= NULL
;
3398 object_list
->next
= sharkd_eo_list
;
3399 sharkd_eo_list
= object_list
;
3402 eo_object
= g_new0(export_object_list_t
, 1);
3403 eo_object
->add_entry
= sharkd_eo_object_list_add_entry
;
3404 eo_object
->get_entry
= sharkd_eo_object_list_get_entry
;
3405 eo_object
->gui_data
= (void *) object_list
;
3407 *ptap_data
= eo_object
;
3408 *ptap_free
= g_free
; /* need to free only eo_object, object_list need to be kept for potential download */
3410 return register_tap_listener(get_eo_tap_listener_name(eo
), eo_object
, tap_filter
, 0, NULL
, get_eo_packet_func(eo
), tap_draw
, NULL
);
3414 * sharkd_session_process_tap()
3416 * Process tap request
3419 * (m) tap0 - First tap request
3420 * (o) tap1...tap15 - Other tap requests
3422 * Output object with attributes:
3423 * (m) taps - array of object with attributes:
3424 * (m) tap - tap name
3425 * (m) type - tap output type
3427 * for type:stats see sharkd_session_process_tap_stats_cb()
3428 * for type:nstat see sharkd_session_process_tap_nstat_cb()
3429 * for type:conv see sharkd_session_process_tap_conv_cb()
3430 * for type:host see sharkd_session_process_tap_conv_cb()
3431 * for type:rtp-streams see sharkd_session_process_tap_rtp_cb()
3432 * for type:rtp-analyse see sharkd_session_process_tap_rtp_analyse_cb()
3433 * for type:eo see sharkd_session_process_tap_eo_cb()
3434 * for type:expert see sharkd_session_process_tap_expert_cb()
3435 * for type:rtd see sharkd_session_process_tap_rtd_cb()
3436 * for type:srt see sharkd_session_process_tap_srt_cb()
3437 * for type:flow see sharkd_session_process_tap_flow_cb()
3439 * (m) err - error code
3442 sharkd_session_process_tap(char *buf
, const jsmntok_t
*tokens
, int count
)
3444 void *taps_data
[16];
3445 GFreeFunc taps_free
[16];
3448 const char *tap_filter
= json_find_attr(buf
, tokens
, count
, "filter");
3450 rtpstream_tapinfo_t rtp_tapinfo
=
3451 { NULL
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, 0, TAP_ANALYSE
, NULL
, NULL
, NULL
, false, false};
3453 for (i
= 0; i
< 16; i
++)
3456 const char *tok_tap
;
3458 void *tap_data
= NULL
;
3459 GFreeFunc tap_free
= NULL
;
3460 GString
*tap_error
= NULL
;
3462 snprintf(tapbuf
, sizeof(tapbuf
), "tap%d", i
);
3463 tok_tap
= json_find_attr(buf
, tokens
, count
, tapbuf
);
3467 if (!strncmp(tok_tap
, "stat:", 5))
3469 stats_tree_cfg
*cfg
= stats_tree_get_cfg_by_abbr(tok_tap
+ 5);
3475 rpcid
, -11001, NULL
,
3476 "sharkd_session_process_tap() stat %s not found", tok_tap
+ 5
3481 st
= stats_tree_new(cfg
, NULL
, tap_filter
);
3483 tap_error
= register_tap_listener(st
->cfg
->tapname
, st
, st
->filter
, st
->cfg
->flags
, stats_tree_reset
, stats_tree_packet
, sharkd_session_process_tap_stats_cb
, NULL
);
3485 if (!tap_error
&& cfg
->init
)
3489 tap_free
= sharkd_session_free_tap_stats_cb
;
3491 else if (!strcmp(tok_tap
, "expert"))
3493 struct sharkd_expert_tap
*expert_tap
;
3495 expert_tap
= g_new0(struct sharkd_expert_tap
, 1);
3496 expert_tap
->text
= g_string_chunk_new(100);
3498 tap_error
= register_tap_listener("expert", expert_tap
, tap_filter
, 0, NULL
, sharkd_session_packet_tap_expert_cb
, sharkd_session_process_tap_expert_cb
, NULL
);
3500 tap_data
= expert_tap
;
3501 tap_free
= sharkd_session_free_tap_expert_cb
;
3503 else if (!strncmp(tok_tap
, "seqa:", 5))
3505 seq_analysis_info_t
*graph_analysis
;
3506 register_analysis_t
*analysis
;
3507 const char *tap_name
;
3508 tap_packet_cb tap_func
;
3511 analysis
= sequence_analysis_find_by_name(tok_tap
+ 5);
3515 rpcid
, -11002, NULL
,
3516 "sharkd_session_process_tap() seq analysis %s not found", tok_tap
+ 5
3521 graph_analysis
= sequence_analysis_info_new();
3522 graph_analysis
->name
= tok_tap
+ 5;
3523 /* TODO, make configurable */
3524 graph_analysis
->any_addr
= false;
3526 tap_name
= sequence_analysis_get_tap_listener_name(analysis
);
3527 tap_flags
= sequence_analysis_get_tap_flags(analysis
);
3528 tap_func
= sequence_analysis_get_packet_func(analysis
);
3530 tap_error
= register_tap_listener(tap_name
, graph_analysis
, tap_filter
, tap_flags
, NULL
, tap_func
, sharkd_session_process_tap_flow_cb
, NULL
);
3532 tap_data
= graph_analysis
;
3533 tap_free
= sharkd_session_free_tap_flow_cb
;
3535 else if (!strncmp(tok_tap
, "conv:", 5) || !strncmp(tok_tap
, "endpt:", 6))
3537 struct register_ct
*ct
= NULL
;
3538 const char *ct_tapname
;
3539 struct sharkd_conv_tap_data
*ct_data
;
3540 tap_packet_cb tap_func
= NULL
;
3542 if (!strncmp(tok_tap
, "conv:", 5))
3544 ct
= get_conversation_by_proto_id(proto_get_id_by_short_name(tok_tap
+ 5));
3546 if (!ct
|| !(tap_func
= get_conversation_packet_func(ct
)))
3549 rpcid
, -11003, NULL
,
3550 "sharkd_session_process_tap() conv %s not found", tok_tap
+ 5
3555 else if (!strncmp(tok_tap
, "endpt:", 6))
3557 ct
= get_conversation_by_proto_id(proto_get_id_by_short_name(tok_tap
+ 6));
3559 if (!ct
|| !(tap_func
= get_endpoint_packet_func(ct
)))
3562 rpcid
, -11004, NULL
,
3563 "sharkd_session_process_tap() endpt %s not found", tok_tap
+ 6
3571 rpcid
, -11005, NULL
,
3572 "sharkd_session_process_tap() conv/endpt(?): %s not found", tok_tap
3577 ct_tapname
= proto_get_protocol_filter_name(get_conversation_proto_id(ct
));
3579 ct_data
= g_new0(struct sharkd_conv_tap_data
, 1);
3580 ct_data
->type
= tok_tap
;
3581 ct_data
->hash
.user_data
= ct_data
;
3583 /* XXX: make configurable */
3584 ct_data
->resolve_name
= true;
3585 ct_data
->resolve_port
= true;
3587 tap_error
= register_tap_listener(ct_tapname
, &ct_data
->hash
, tap_filter
, 0, NULL
, tap_func
, sharkd_session_process_tap_conv_cb
, NULL
);
3589 tap_data
= &ct_data
->hash
;
3590 tap_free
= sharkd_session_free_tap_conv_cb
;
3592 else if (!strncmp(tok_tap
, "nstat:", 6))
3594 stat_tap_table_ui
*stat_tap
= stat_tap_by_name(tok_tap
+ 6);
3595 stat_data_t
*stat_data
;
3600 rpcid
, -11006, NULL
,
3601 "sharkd_session_process_tap() nstat=%s not found", tok_tap
+ 6
3606 stat_tap
->stat_tap_init_cb(stat_tap
);
3608 stat_data
= g_new0(stat_data_t
, 1);
3609 stat_data
->stat_tap_data
= stat_tap
;
3610 stat_data
->user_data
= NULL
;
3612 tap_error
= register_tap_listener(stat_tap
->tap_name
, stat_data
, tap_filter
, 0, NULL
, stat_tap
->packet_func
, sharkd_session_process_tap_nstat_cb
, NULL
);
3614 tap_data
= stat_data
;
3615 tap_free
= sharkd_session_free_tap_nstat_cb
;
3617 else if (!strncmp(tok_tap
, "rtd:", 4))
3619 register_rtd_t
*rtd
= get_rtd_table_by_name(tok_tap
+ 4);
3620 rtd_data_t
*rtd_data
;
3626 rpcid
, -11007, NULL
,
3627 "sharkd_session_process_tap() rtd=%s not found", tok_tap
+ 4
3632 rtd_table_get_filter(rtd
, "", &tap_filter
, &err
);
3636 rpcid
, -11008, NULL
,
3637 "sharkd_session_process_tap() rtd=%s err=%s", tok_tap
+ 4, err
3643 rtd_data
= g_new0(rtd_data_t
, 1);
3644 rtd_data
->user_data
= rtd
;
3645 rtd_table_dissector_init(rtd
, &rtd_data
->stat_table
, NULL
, NULL
);
3647 tap_error
= register_tap_listener(get_rtd_tap_listener_name(rtd
), rtd_data
, tap_filter
, 0, NULL
, get_rtd_packet_func(rtd
), sharkd_session_process_tap_rtd_cb
, NULL
);
3649 tap_data
= rtd_data
;
3650 tap_free
= sharkd_session_free_tap_rtd_cb
;
3652 else if (!strncmp(tok_tap
, "srt:", 4))
3654 register_srt_t
*srt
= get_srt_table_by_name(tok_tap
+ 4);
3655 srt_data_t
*srt_data
;
3661 rpcid
, -11009, NULL
,
3662 "sharkd_session_process_tap() srt=%s not found", tok_tap
+ 4
3667 srt_table_get_filter(srt
, "", &tap_filter
, &err
);
3671 rpcid
, -11010, NULL
,
3672 "sharkd_session_process_tap() srt=%s err=%s", tok_tap
+ 4, err
3678 srt_data
= g_new0(srt_data_t
, 1);
3679 srt_data
->srt_array
= g_array_new(FALSE
, TRUE
, sizeof(srt_stat_table
*));
3680 srt_data
->user_data
= srt
;
3681 srt_table_dissector_init(srt
, srt_data
->srt_array
);
3683 tap_error
= register_tap_listener(get_srt_tap_listener_name(srt
), srt_data
, tap_filter
, 0, NULL
, get_srt_packet_func(srt
), sharkd_session_process_tap_srt_cb
, NULL
);
3685 tap_data
= srt_data
;
3686 tap_free
= sharkd_session_free_tap_srt_cb
;
3688 else if (!strncmp(tok_tap
, "eo:", 3))
3690 register_eo_t
*eo
= get_eo_by_name(tok_tap
+ 3);
3695 rpcid
, -11011, NULL
,
3696 "sharkd_session_process_tap() eo=%s not found", tok_tap
+ 3
3701 tap_error
= sharkd_session_eo_register_tap_listener(eo
, tok_tap
, tap_filter
, sharkd_session_process_tap_eo_cb
, &tap_data
, &tap_free
);
3703 /* tap_data & tap_free assigned by sharkd_session_eo_register_tap_listener */
3705 else if (!strcmp(tok_tap
, "rtp-streams"))
3707 tap_error
= register_tap_listener("rtp", &rtp_tapinfo
, tap_filter
, 0, rtpstream_reset_cb
, rtpstream_packet_cb
, sharkd_session_process_tap_rtp_cb
, NULL
);
3709 tap_data
= &rtp_tapinfo
;
3710 tap_free
= rtpstream_reset_cb
;
3712 else if (!strncmp(tok_tap
, "rtp-analyse:", 12))
3714 struct sharkd_analyse_rtp
*rtp_req
;
3716 rtp_req
= (struct sharkd_analyse_rtp
*) g_malloc0(sizeof(*rtp_req
));
3717 if (!sharkd_rtp_match_init(&rtp_req
->id
, tok_tap
+ 12))
3719 rtpstream_id_free(&rtp_req
->id
);
3724 rtp_req
->tap_name
= tok_tap
;
3725 rtp_req
->statinfo
.first_packet
= true;
3726 rtp_req
->statinfo
.reg_pt
= PT_UNDEFINED
;
3728 tap_error
= register_tap_listener("rtp", rtp_req
, tap_filter
, 0, NULL
, sharkd_session_packet_tap_rtp_analyse_cb
, sharkd_session_process_tap_rtp_analyse_cb
, NULL
);
3731 tap_free
= sharkd_session_process_tap_rtp_free_cb
;
3733 else if (!strcmp(tok_tap
, "multicast"))
3735 mcaststream_tapinfo_t
*mcaststream_tapinfo
;
3736 mcaststream_tapinfo
= (mcaststream_tapinfo_t
*) g_malloc0(sizeof(*mcaststream_tapinfo
));
3738 tap_error
= register_tap_listener("udp", mcaststream_tapinfo
, tap_filter
, 0, NULL
, mcaststream_packet
, sharkd_session_process_tap_multicast_cb
, NULL
);
3739 tap_data
= mcaststream_tapinfo
;
3740 tap_free
= sharkd_session_process_free_tap_multicast_cb
;
3742 else if (!strcmp(tok_tap
, "phs"))
3746 pc_proto_id
= proto_registrar_get_id_byname("pkt_comment");
3748 rs
= new_phs_t(NULL
, tap_filter
);
3750 tap_error
= register_tap_listener("frame", rs
, tap_filter
,
3751 TL_REQUIRES_PROTO_TREE
|TL_REQUIRES_PROTOCOLS
,
3752 NULL
, protohierstat_packet
,
3753 sharkd_session_process_tap_phs_cb
, NULL
);
3756 tap_free
= sharkd_session_free_tap_phs_cb
;
3758 else if (!strcmp(tok_tap
, "voip-calls"))
3760 voip_stat_init_tapinfo();
3762 tap_error
= register_tap_listener("frame", &tapinfo_
, tap_filter
, 0, NULL
, NULL
, sharkd_session_process_tap_voip_calls_cb
, NULL
);
3764 tapinfo_
.session
= cfile
.epan
;
3765 voip_calls_init_all_taps(&tapinfo_
);
3767 tap_data
= &tapinfo_
;
3768 tap_free
= sharkd_session_free_tap_voip_calls_cb
;
3770 else if (!strncmp(tok_tap
, "voip-convs:", 11))
3773 unsigned int min
, max
;
3774 struct sharkd_voip_convs_req
*voip_convs_req
;
3775 const char *conv_arg
= tok_tap
+ 11;
3777 // parse tok_tap to get which call we are asking for
3778 if (*conv_arg
== 0) {
3779 // set all bits of voip_conv_sel (-1 in binary is all 1's)
3780 memset(voip_conv_sel
, -1, sizeof(voip_conv_sel
));
3782 memset(voip_conv_sel
, 0, sizeof(voip_conv_sel
));
3784 while (*conv_arg
!= 0) {
3785 if (*conv_arg
== ',') {
3788 if (sscanf(conv_arg
, "%u-%u%n", &min
, &max
, &len
) == 2) {
3790 } else if (sscanf(conv_arg
, "%u%n", &min
, &len
) == 1) {
3795 rpcid
, -11014, NULL
,
3796 "sharkd_session_process_tap() voip-convs=%s invalid 'convs' parameter", tok_tap
3800 if (min
> max
|| min
>= VOIP_CONV_MAX
|| max
>= VOIP_CONV_MAX
) {
3802 rpcid
, -11012, NULL
,
3803 "sharkd_session_process_tap() voip-convs=%s invalid 'convs' number range", tok_tap
3807 for(; min
<= max
; min
++) {
3808 voip_conv_sel
[min
/ VOIP_CONV_BITS
] |= 1 << (min
% VOIP_CONV_BITS
);
3813 voip_stat_init_tapinfo();
3815 voip_convs_req
= (struct sharkd_voip_convs_req
*) g_malloc0(sizeof(*voip_convs_req
));
3816 voip_convs_req
->tapinfo
= &tapinfo_
;
3817 voip_convs_req
->tap_name
= tok_tap
;
3819 tap_error
= register_tap_listener("frame", voip_convs_req
, tap_filter
, 0, NULL
, NULL
, sharkd_session_process_tap_voip_convs_cb
, NULL
);
3821 tapinfo_
.session
= cfile
.epan
;
3822 voip_calls_init_all_taps(&tapinfo_
);
3824 tap_data
= voip_convs_req
;
3825 tap_free
= sharkd_session_free_tap_voip_convs_cb
;
3827 else if (!strncmp(tok_tap
, "hosts:", 6))
3831 struct sharkd_hosts_req
*hosts_req
;
3832 const char *proto_arg
;
3833 char **proto_tokens
;
3836 proto_arg
= tok_tap
+ 6;
3838 if (strlen(proto_arg
) == 0) {
3845 proto_tokens
= g_strsplit(proto_arg
, ",", 0);
3847 while (proto_tokens
[proto_count
]) {
3848 if (!strcmp("ip", proto_tokens
[proto_count
]) ||
3849 !strcmp("ipv4", proto_tokens
[proto_count
])) {
3851 } else if (!strcmp("ipv6", proto_tokens
[proto_count
])) {
3854 g_strfreev(proto_tokens
);
3856 rpcid
, -11015, NULL
,
3857 "sharkd_session_process_tap() hosts=%s invalid 'protos' parameter", tok_tap
3863 g_strfreev(proto_tokens
);
3866 hosts_req
= (struct sharkd_hosts_req
*)g_malloc0(sizeof(*hosts_req
));
3867 hosts_req
->dump_v4
= dump_v4
;
3868 hosts_req
->dump_v6
= dump_v6
;
3869 hosts_req
->tap_name
= tok_tap
;
3871 tap_error
= register_tap_listener("frame", hosts_req
, tap_filter
, TL_REQUIRES_PROTO_TREE
, NULL
, NULL
, sharkd_session_process_tap_hosts_cb
, NULL
);
3873 tap_data
= hosts_req
;
3874 tap_free
= sharkd_session_free_tap_hosts_cb
;
3879 rpcid
, -11012, NULL
,
3880 "sharkd_session_process_tap() %s not recognized", tok_tap
3888 rpcid
, -11013, NULL
,
3889 "sharkd_session_process_tap() name=%s error=%s", tok_tap
, tap_error
->str
3891 g_string_free(tap_error
, TRUE
);
3897 taps_data
[taps_count
] = tap_data
;
3898 taps_free
[taps_count
] = tap_free
;
3902 fprintf(stderr
, "sharkd_session_process_tap() count=%d\n", taps_count
);
3903 if (taps_count
== 0)
3905 sharkd_json_result_prologue(rpcid
);
3906 sharkd_json_array_open("taps");
3907 sharkd_json_array_close();
3908 sharkd_json_result_epilogue();
3912 sharkd_json_result_prologue(rpcid
);
3913 sharkd_json_array_open("taps");
3915 sharkd_json_array_close();
3916 sharkd_json_result_epilogue();
3918 for (i
= 0; i
< taps_count
; i
++)
3921 remove_tap_listener(taps_data
[i
]);
3924 taps_free
[i
](taps_data
[i
]);
3929 * sharkd_session_process_follow()
3931 * Process follow request
3934 * (m) follow - follow protocol request (e.g. HTTP)
3935 * (m) filter - filter request (e.g. tcp.stream == 1)
3936 * (m) stream - stream index number
3937 * (o) sub_stream - follow sub-stream index number (e.g. for HTTP/2 and QUIC streams)
3939 * Output object with attributes:
3941 * (m) err - error code
3942 * (m) shost - server host
3943 * (m) sport - server port
3944 * (m) sbytes - server send bytes count
3945 * (m) chost - client host
3946 * (m) cport - client port
3947 * (m) cbytes - client send bytes count
3948 * (o) payloads - array of object with attributes:
3949 * (o) s - set if server sent, else client
3950 * (m) n - packet number
3951 * (m) d - data base64 encoded
3954 sharkd_session_process_follow(char *buf
, const jsmntok_t
*tokens
, int count
)
3956 const char *tok_follow
= json_find_attr(buf
, tokens
, count
, "follow");
3957 const char *tok_filter
= json_find_attr(buf
, tokens
, count
, "filter");
3958 const char *tok_sub_stream
= json_find_attr(buf
, tokens
, count
, "sub_stream");
3960 register_follow_t
*follower
;
3963 follow_info_t
*follow_info
;
3967 follower
= get_follow_by_name(tok_follow
);
3971 rpcid
, -12001, NULL
,
3972 "sharkd_session_process_follow() follower=%s not found", tok_follow
3977 uint64_t substream_id
= SUBSTREAM_UNUSED
;
3980 ws_strtou64(tok_sub_stream
, NULL
, &substream_id
);
3983 /* follow_reset_stream ? */
3984 follow_info
= g_new0(follow_info_t
, 1);
3985 follow_info
->substream_id
= substream_id
;
3986 /* gui_data, filter_out_filter not set, but not used by dissector */
3988 tap_error
= register_tap_listener(get_follow_tap_string(follower
), follow_info
, tok_filter
, 0, NULL
, get_follow_tap_handler(follower
), NULL
, NULL
);
3992 rpcid
, -12002, NULL
,
3993 "sharkd_session_process_follow() name=%s error=%s", tok_follow
, tap_error
->str
3995 g_string_free(tap_error
, TRUE
);
3996 g_free(follow_info
);
4002 sharkd_json_result_prologue(rpcid
);
4004 /* Server information: hostname, port, bytes sent */
4005 host
= address_to_name(&follow_info
->server_ip
);
4006 sharkd_json_value_string("shost", host
);
4008 port
= get_follow_port_to_display(follower
)(NULL
, follow_info
->server_port
);
4009 sharkd_json_value_string("sport", port
);
4010 wmem_free(NULL
, port
);
4012 sharkd_json_value_anyf("sbytes", "%u", follow_info
->bytes_written
[0]);
4014 /* Client information: hostname, port, bytes sent */
4015 host
= address_to_name(&follow_info
->client_ip
);
4016 sharkd_json_value_string("chost", host
);
4018 port
= get_follow_port_to_display(follower
)(NULL
, follow_info
->client_port
);
4019 sharkd_json_value_string("cport", port
);
4020 wmem_free(NULL
, port
);
4022 sharkd_json_value_anyf("cbytes", "%u", follow_info
->bytes_written
[1]);
4024 if (follow_info
->payload
)
4026 follow_record_t
*follow_record
;
4029 sharkd_json_array_open("payloads");
4030 for (cur
= g_list_last(follow_info
->payload
); cur
; cur
= g_list_previous(cur
))
4032 follow_record
= (follow_record_t
*) cur
->data
;
4034 json_dumper_begin_object(&dumper
);
4036 sharkd_json_value_anyf("n", "%u", follow_record
->packet_num
);
4037 sharkd_json_value_base64("d", follow_record
->data
->data
, follow_record
->data
->len
);
4039 if (follow_record
->is_server
)
4040 sharkd_json_value_anyf("s", "%d", 1);
4042 json_dumper_end_object(&dumper
);
4044 sharkd_json_array_close();
4047 sharkd_json_result_epilogue();
4049 remove_tap_listener(follow_info
);
4050 follow_info_free(follow_info
);
4054 sharkd_session_process_frame_cb_tree(const char *key
, epan_dissect_t
*edt
, proto_tree
*tree
, tvbuff_t
**tvbs
, bool display_hidden
)
4058 sharkd_json_array_open(key
);
4059 for (node
= tree
->first_child
; node
; node
= node
->next
)
4061 field_info
*finfo
= PNODE_FINFO(node
);
4066 if (!display_hidden
&& FI_GET_FLAG(finfo
, FI_HIDDEN
))
4069 json_dumper_begin_object(&dumper
);
4073 char label_str
[ITEM_LABEL_LENGTH
];
4075 label_str
[0] = '\0';
4076 proto_item_fill_label(finfo
, label_str
, NULL
);
4077 sharkd_json_value_string("l", label_str
);
4081 sharkd_json_value_string("l", finfo
->rep
->representation
);
4084 if (finfo
->ds_tvb
&& tvbs
&& tvbs
[0] != finfo
->ds_tvb
)
4088 for (idx
= 1; tvbs
[idx
]; idx
++)
4090 if (tvbs
[idx
] == finfo
->ds_tvb
)
4092 sharkd_json_value_anyf("ds", "%d", idx
);
4098 if (finfo
->start
>= 0 && finfo
->length
> 0)
4099 sharkd_json_value_anyf("h", "[%d,%d]", finfo
->start
, finfo
->length
);
4101 if (finfo
->appendix_start
>= 0 && finfo
->appendix_length
> 0)
4102 sharkd_json_value_anyf("i", "[%d,%d]", finfo
->appendix_start
, finfo
->appendix_length
);
4109 if (finfo
->hfinfo
->type
== FT_PROTOCOL
)
4111 sharkd_json_value_string("t", "proto");
4113 else if (finfo
->hfinfo
->type
== FT_FRAMENUM
)
4115 sharkd_json_value_string("t", "framenum");
4116 sharkd_json_value_anyf("fnum", "%u", fvalue_get_uinteger(finfo
->value
));
4118 else if (FI_GET_FLAG(finfo
, FI_URL
) && FT_IS_STRING(finfo
->hfinfo
->type
))
4120 char *url
= fvalue_to_string_repr(NULL
, finfo
->value
, FTREPR_DISPLAY
, finfo
->hfinfo
->display
);
4122 sharkd_json_value_string("t", "url");
4123 sharkd_json_value_string("url", url
);
4124 wmem_free(NULL
, url
);
4127 filter
= proto_construct_match_selected_string(finfo
, edt
);
4130 sharkd_json_value_string("f", filter
);
4131 wmem_free(NULL
, filter
);
4134 if (finfo
->hfinfo
->abbrev
)
4135 sharkd_json_value_string("fn", finfo
->hfinfo
->abbrev
);
4138 if (FI_GET_FLAG(finfo
, FI_GENERATED
))
4139 sharkd_json_value_anyf("g", "true");
4141 if (FI_GET_FLAG(finfo
, FI_HIDDEN
))
4142 sharkd_json_value_anyf("v", "true");
4144 if (FI_GET_FLAG(finfo
, PI_SEVERITY_MASK
))
4146 const char *severity
= try_val_to_str(FI_GET_FLAG(finfo
, PI_SEVERITY_MASK
), expert_severity_vals
);
4148 ws_assert(severity
!= NULL
);
4150 sharkd_json_value_string("s", severity
);
4153 if (((proto_tree
*) node
)->first_child
)
4155 if (finfo
->tree_type
!= -1)
4156 sharkd_json_value_anyf("e", "%d", finfo
->tree_type
);
4158 sharkd_session_process_frame_cb_tree("n", edt
, (proto_tree
*) node
, tvbs
, display_hidden
);
4161 json_dumper_end_object(&dumper
);
4163 sharkd_json_array_close();
4167 sharkd_follower_visit_layers_cb(const void *key _U_
, void *value
, void *user_data
)
4169 register_follow_t
*follower
= (register_follow_t
*) value
;
4170 epan_dissect_t
*edt
= (epan_dissect_t
*) user_data
;
4171 packet_info
*pi
= &edt
->pi
;
4173 const int proto_id
= get_follow_proto_id(follower
);
4175 uint32_t ignore_stream
;
4176 uint32_t ignore_sub_stream
;
4178 if (proto_is_frame_protocol(pi
->layers
, proto_get_protocol_filter_name(proto_id
)))
4180 const char *layer_proto
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
4181 char *follow_filter
;
4183 follow_filter
= get_follow_conv_func(follower
)(edt
, pi
, &ignore_stream
, &ignore_sub_stream
);
4185 json_dumper_begin_array(&dumper
);
4186 json_dumper_value_string(&dumper
, layer_proto
);
4187 json_dumper_value_string(&dumper
, follow_filter
);
4188 json_dumper_end_array(&dumper
);
4190 g_free(follow_filter
);
4197 sharkd_followers_visit_layers_cb(const void *key _U_
, void *value
, void *user_data
)
4199 register_follow_t
*follower
= (register_follow_t
*) value
;
4200 epan_dissect_t
*edt
= (epan_dissect_t
*) user_data
;
4201 packet_info
*pi
= &edt
->pi
;
4203 const int proto_id
= get_follow_proto_id(follower
);
4206 unsigned sub_stream
;
4208 if (proto_is_frame_protocol(pi
->layers
, proto_get_protocol_filter_name(proto_id
)))
4210 const char *layer_proto
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
4211 char *follow_filter
;
4213 follow_filter
= get_follow_conv_func(follower
)(edt
, pi
, &stream
, &sub_stream
);
4215 sharkd_json_object_open(NULL
);
4216 sharkd_json_value_string("protocol", layer_proto
);
4217 sharkd_json_value_string("filter", follow_filter
);
4218 if (get_follow_stream_count_func(follower
) != NULL
)
4220 sharkd_json_value_anyf("stream", "%u", stream
);
4222 if (get_follow_sub_stream_id_func(follower
) != NULL
)
4224 sharkd_json_value_anyf("sub_stream", "%u", sub_stream
);
4226 sharkd_json_object_close();
4228 g_free(follow_filter
);
4234 struct sharkd_frame_request_data
4236 bool display_hidden
;
4240 sharkd_session_process_frame_cb(epan_dissect_t
*edt
, proto_tree
*tree
, struct epan_column_info
*cinfo
, const GSList
*data_src
, void *data
)
4242 packet_info
*pi
= &edt
->pi
;
4243 frame_data
*fdata
= pi
->fd
;
4244 wtap_block_t pkt_block
= NULL
;
4246 const struct sharkd_frame_request_data
* const req_data
= (const struct sharkd_frame_request_data
* const) data
;
4247 const bool display_hidden
= (req_data
) ? req_data
->display_hidden
: false;
4249 sharkd_json_result_prologue(rpcid
);
4251 if (fdata
->has_modified_block
)
4252 pkt_block
= sharkd_get_modified_block(fdata
);
4254 pkt_block
= pi
->rec
->block
;
4262 n
= wtap_block_count_option(pkt_block
, OPT_COMMENT
);
4264 sharkd_json_array_open("comment");
4265 for (i
= 0; i
< n
; i
++) {
4266 if (WTAP_OPTTYPE_SUCCESS
== wtap_block_get_nth_string_option_value(pkt_block
, OPT_COMMENT
, i
, &comment
)) {
4267 sharkd_json_value_string(NULL
, comment
);
4270 sharkd_json_array_close();
4275 tvbuff_t
**tvbs
= NULL
;
4277 /* arrayize data src, to speedup searching for ds_tvb index */
4278 if (data_src
&& data_src
->next
/* only needed if there are more than one data source */)
4280 unsigned count
= g_slist_length((GSList
*) data_src
);
4283 tvbs
= (tvbuff_t
**) g_malloc0((count
+ 1) * sizeof(*tvbs
));
4285 for (i
= 0; i
< count
; i
++)
4287 const struct data_source
*src
= (const struct data_source
*) g_slist_nth_data((GSList
*) data_src
, i
);
4289 tvbs
[i
] = get_data_source_tvb(src
);
4295 sharkd_session_process_frame_cb_tree("tree", edt
, tree
, tvbs
, display_hidden
);
4304 sharkd_json_array_open("col");
4305 for (col
= 0; col
< cinfo
->num_cols
; ++col
)
4307 sharkd_json_value_string(NULL
, get_column_text(cinfo
, col
));
4309 sharkd_json_array_close();
4313 sharkd_json_value_anyf("i", "true");
4316 sharkd_json_value_anyf("m", "true");
4318 if (fdata
->color_filter
)
4320 sharkd_json_value_stringf("bg", "%06x", color_t_to_rgb(&fdata
->color_filter
->bg_color
));
4321 sharkd_json_value_stringf("fg", "%06x", color_t_to_rgb(&fdata
->color_filter
->fg_color
));
4326 struct data_source
*src
= (struct data_source
*) data_src
->data
;
4327 bool ds_open
= false;
4332 tvb
= get_data_source_tvb(src
);
4333 length
= tvb_captured_length(tvb
);
4337 const unsigned char *cp
= tvb_get_ptr(tvb
, 0, length
);
4339 /* XXX pi.fd->encoding */
4340 sharkd_json_value_base64("bytes", cp
, length
);
4344 sharkd_json_value_base64("bytes", "", 0);
4347 data_src
= data_src
->next
;
4350 sharkd_json_array_open("ds");
4356 src
= (struct data_source
*) data_src
->data
;
4358 json_dumper_begin_object(&dumper
);
4361 char *src_name
= get_data_source_name(src
);
4363 sharkd_json_value_string("name", src_name
);
4364 wmem_free(NULL
, src_name
);
4367 tvb
= get_data_source_tvb(src
);
4368 length
= tvb_captured_length(tvb
);
4372 const unsigned char *cp
= tvb_get_ptr(tvb
, 0, length
);
4374 /* XXX pi.fd->encoding */
4375 sharkd_json_value_base64("bytes", cp
, length
);
4379 sharkd_json_value_base64("bytes", "", 0);
4382 json_dumper_end_object(&dumper
);
4384 data_src
= data_src
->next
;
4387 /* close ds, only if was opened */
4389 sharkd_json_array_close();
4392 sharkd_json_array_open("fol");
4393 follow_iterate_followers(sharkd_follower_visit_layers_cb
, edt
);
4394 sharkd_json_array_close();
4396 sharkd_json_array_open("followers");
4397 follow_iterate_followers(sharkd_followers_visit_layers_cb
, edt
);
4398 sharkd_json_array_close();
4400 sharkd_json_result_epilogue();
4403 #define SHARKD_IOGRAPH_MAX_ITEMS 1 << 25 /* 33,554,432 limit of items, same as max_io_items_ in ui/qt/io_graph_dialog.h */
4405 struct sharkd_iograph
4409 io_graph_item_unit_t calc_type
;
4416 io_graph_item_t
*items
;
4420 static tap_packet_status
4421 sharkd_iograph_packet(void *g
, packet_info
*pinfo
, epan_dissect_t
*edt
, const void *dummy _U_
, tap_flags_t flags _U_
)
4423 struct sharkd_iograph
*graph
= (struct sharkd_iograph
*) g
;
4425 bool update_succeeded
;
4427 int64_t tmp_idx
= get_io_graph_index(pinfo
, graph
->interval
);
4428 if (tmp_idx
< 0 || tmp_idx
>= SHARKD_IOGRAPH_MAX_ITEMS
)
4429 return TAP_PACKET_DONT_REDRAW
;
4433 if (idx
+ 1 > graph
->num_items
)
4435 if (idx
+ 1 > graph
->space_items
)
4437 int new_size
= idx
+ 1024;
4439 graph
->items
= (io_graph_item_t
*) g_realloc(graph
->items
, sizeof(io_graph_item_t
) * new_size
);
4440 reset_io_graph_items(&graph
->items
[graph
->space_items
], new_size
- graph
->space_items
, graph
->hf_index
);
4442 graph
->space_items
= new_size
;
4444 else if (graph
->items
== NULL
)
4446 graph
->items
= g_new(io_graph_item_t
, graph
->space_items
);
4447 reset_io_graph_items(graph
->items
, graph
->space_items
, graph
->hf_index
);
4450 graph
->num_items
= idx
+ 1;
4453 update_succeeded
= update_io_graph_item(graph
->items
, idx
, pinfo
, edt
, graph
->hf_index
, graph
->calc_type
, graph
->interval
);
4454 /* XXX - TAP_PACKET_FAILED if the item couldn't be updated, with an error message? */
4455 return update_succeeded
? TAP_PACKET_REDRAW
: TAP_PACKET_DONT_REDRAW
;
4459 * sharkd_session_process_iograph()
4461 * Process iograph request
4464 * (o) interval - interval time, if not specified: 1000
4465 * (o) interval_units - units for interval time, must be 's', 'ms' or 'us', if not specified: ms
4466 * (m) graph0 - First graph request
4467 * (o) graph1...graph9 - Other graph requests
4468 * (o) filter0 - First graph filter
4469 * (o) filter1...filter9 - Other graph filters
4471 * Graph requests can be one of: "packets", "bytes", "bits", "sum:<field>", "frames:<field>", "max:<field>", "min:<field>", "avg:<field>", "load:<field>",
4472 * if you use variant with <field>, you need to pass field name in filter request.
4474 * Output object with attributes:
4475 * (m) iograph - array of graph results with attributes:
4476 * errmsg - graph cannot be constructed
4477 * items - graph values, zeros are skipped, if value is not a number it's next index encoded as hex string
4480 sharkd_session_process_iograph(char *buf
, const jsmntok_t
*tokens
, int count
)
4482 const char *tok_interval
= json_find_attr(buf
, tokens
, count
, "interval");
4483 const char *tok_interval_units
= json_find_attr(buf
, tokens
, count
, "interval_units");
4484 struct sharkd_iograph graphs
[10];
4485 bool is_any_ok
= false;
4490 /* default: 1000ms = one per second */
4491 uint32_t interval
= 1000;
4492 const char *interval_units
= "ms";
4495 ws_strtou32(tok_interval
, NULL
, &interval
);
4497 if (tok_interval_units
)
4499 if (strcmp(tok_interval_units
, "us") != 0 &&
4500 strcmp(tok_interval_units
, "ms") != 0 &&
4501 strcmp(tok_interval_units
, "s") != 0)
4505 "Invalid interval_units parameter: '%s', must be 's', 'ms' or 'us'", tok_interval_units
4509 interval_units
= tok_interval_units
;
4512 uint32_t interval_us
= 0;
4513 if (strcmp(interval_units
, "us") == 0)
4515 interval_us
= interval
;
4517 else if (strcmp(interval_units
, "ms") == 0)
4519 interval_us
= 1000 * interval
;
4521 else if (strcmp(interval_units
, "s") == 0)
4523 interval_us
= 1000000 * interval
;
4526 for (i
= graph_count
= 0; i
< (int) G_N_ELEMENTS(graphs
); i
++)
4528 struct sharkd_iograph
*graph
= &graphs
[graph_count
];
4530 const char *tok_graph
;
4531 const char *tok_filter
;
4532 char tok_format_buf
[32];
4533 const char *field_name
;
4534 const char *tok_aot
;
4536 snprintf(tok_format_buf
, sizeof(tok_format_buf
), "graph%d", i
);
4537 tok_graph
= json_find_attr(buf
, tokens
, count
, tok_format_buf
);
4541 snprintf(tok_format_buf
, sizeof(tok_format_buf
), "filter%d", i
);
4542 tok_filter
= json_find_attr(buf
, tokens
, count
, tok_format_buf
);
4544 if (!strcmp(tok_graph
, "packets"))
4545 graph
->calc_type
= IOG_ITEM_UNIT_PACKETS
;
4546 else if (!strcmp(tok_graph
, "bytes"))
4547 graph
->calc_type
= IOG_ITEM_UNIT_BYTES
;
4548 else if (!strcmp(tok_graph
, "bits"))
4549 graph
->calc_type
= IOG_ITEM_UNIT_BITS
;
4550 else if (g_str_has_prefix(tok_graph
, "sum:"))
4551 graph
->calc_type
= IOG_ITEM_UNIT_CALC_SUM
;
4552 else if (g_str_has_prefix(tok_graph
, "frames:"))
4553 graph
->calc_type
= IOG_ITEM_UNIT_CALC_FRAMES
;
4554 else if (g_str_has_prefix(tok_graph
, "fields:"))
4555 graph
->calc_type
= IOG_ITEM_UNIT_CALC_FIELDS
;
4556 else if (g_str_has_prefix(tok_graph
, "max:"))
4557 graph
->calc_type
= IOG_ITEM_UNIT_CALC_MAX
;
4558 else if (g_str_has_prefix(tok_graph
, "min:"))
4559 graph
->calc_type
= IOG_ITEM_UNIT_CALC_MIN
;
4560 else if (g_str_has_prefix(tok_graph
, "avg:"))
4561 graph
->calc_type
= IOG_ITEM_UNIT_CALC_AVERAGE
;
4562 else if (g_str_has_prefix(tok_graph
, "load:"))
4563 graph
->calc_type
= IOG_ITEM_UNIT_CALC_LOAD
;
4564 else if (g_str_has_prefix(tok_graph
, "throughput:"))
4565 graph
->calc_type
= IOG_ITEM_UNIT_CALC_THROUGHPUT
;
4569 field_name
= strchr(tok_graph
, ':');
4571 field_name
= field_name
+ 1;
4573 /* io_graph_item now supports microseconds (and this parameter
4574 * is expected to be in microseconds.) */
4575 graph
->interval
= interval_us
;
4577 graph
->hf_index
= -1;
4578 graph
->error
= check_field_unit(field_name
, &graph
->hf_index
, graph
->calc_type
);
4580 graph
->space_items
= 0; /* TODO, can avoid realloc()s in sharkd_iograph_packet() by calculating: capture_time / interval */
4581 graph
->num_items
= 0;
4582 graph
->items
= NULL
;
4584 snprintf(tok_format_buf
, sizeof(tok_format_buf
), "aot%d", i
);
4585 tok_aot
= json_find_attr(buf
, tokens
, count
, tok_format_buf
);
4586 if (tok_aot
!=NULL
) {
4587 graph
->aot
= (!strcmp(tok_aot
, "true")) ? true : false;
4594 graph
->error
= register_tap_listener("frame", graph
, tok_filter
, TL_REQUIRES_PROTO_TREE
, NULL
, sharkd_iograph_packet
, NULL
, NULL
);
4602 "%s", graph
->error
->str
4604 g_string_free(graph
->error
, TRUE
);
4608 if (graph
->error
== NULL
)
4612 /* retap only if we have at least one ok */
4616 sharkd_json_result_prologue(rpcid
);
4618 sharkd_json_array_open("iograph");
4619 for (i
= 0; i
< graph_count
; i
++)
4621 struct sharkd_iograph
*graph
= &graphs
[i
];
4623 json_dumper_begin_object(&dumper
);
4627 fprintf(stderr
, "SNAP 6002 - we should never get to here.\n");
4628 g_string_free(graph
->error
, TRUE
);
4636 sharkd_json_array_open("items");
4637 for (idx
= 0; idx
< graph
->num_items
; idx
++)
4641 val
= get_io_graph_item(graph
->items
, graph
->calc_type
, idx
, graph
->hf_index
, &cfile
, graph
->interval
, graph
->num_items
, graph
->aot
);
4643 /* if it's zero, don't display */
4647 /* cause zeros are not printed, need to output index */
4648 if (next_idx
!= idx
)
4649 sharkd_json_value_stringf(NULL
, "%x", idx
);
4651 sharkd_json_value_anyf(NULL
, "%f", val
);
4654 sharkd_json_array_close();
4656 json_dumper_end_object(&dumper
);
4658 remove_tap_listener(graph
);
4659 g_free(graph
->items
);
4661 sharkd_json_array_close();
4663 sharkd_json_result_epilogue();
4667 * sharkd_session_process_intervals()
4669 * Process intervals request - generate basic capture file statistics per requested interval.
4672 * (o) interval - interval time in ms, if not specified: 1000ms
4673 * (o) filter - filter for generating interval request
4675 * Output object with attributes:
4676 * (m) intervals - array of intervals, with indexes:
4677 * [0] - index of interval,
4678 * [1] - number of frames during interval,
4679 * [2] - number of bytes during interval.
4681 * (m) last - last interval number.
4682 * (m) frames - total number of frames
4683 * (m) bytes - total number of bytes
4685 * NOTE: If frames are not in order, there might be items with same interval index, or even negative one.
4688 sharkd_session_process_intervals(char *buf
, const jsmntok_t
*tokens
, int count
)
4690 const char *tok_interval
= json_find_attr(buf
, tokens
, count
, "interval");
4691 const char *tok_filter
= json_find_attr(buf
, tokens
, count
, "filter");
4693 const uint8_t *filter_data
= NULL
;
4697 unsigned int frames
;
4703 uint32_t interval_ms
= 1000; /* default: one per second */
4706 int64_t max_idx
= 0;
4709 ws_strtou32(tok_interval
, NULL
, &interval_ms
); // already validated
4713 const struct sharkd_filter_item
*filter_item
;
4715 filter_item
= sharkd_session_filter_data(tok_filter
);
4720 "Invalid filter parameter: %s", tok_filter
4724 filter_data
= filter_item
->filtered
;
4727 st_total
.frames
= 0;
4735 sharkd_json_result_prologue(rpcid
);
4736 sharkd_json_array_open("intervals");
4738 start_ts
= (cfile
.count
>= 1) ? &(sharkd_get_frame(1)->abs_ts
) : NULL
;
4740 for (uint32_t framenum
= 1; framenum
<= cfile
.count
; framenum
++)
4746 if (filter_data
&& !(filter_data
[framenum
/ 8] & (1 << (framenum
% 8))))
4749 fdata
= sharkd_get_frame(framenum
);
4751 msec_rel
= (fdata
->abs_ts
.secs
- start_ts
->secs
) * (int64_t) 1000 + (fdata
->abs_ts
.nsecs
- start_ts
->nsecs
) / 1000000;
4752 new_idx
= msec_rel
/ interval_ms
;
4758 sharkd_json_value_anyf(NULL
, "[%" PRId64
",%u,%" PRIu64
"]", idx
, st
.frames
, st
.bytes
);
4770 st
.bytes
+= fdata
->pkt_len
;
4772 st_total
.frames
+= 1;
4773 st_total
.bytes
+= fdata
->pkt_len
;
4778 sharkd_json_value_anyf(NULL
, "[%" PRId64
",%u,%" PRIu64
"]", idx
, st
.frames
, st
.bytes
);
4780 sharkd_json_array_close();
4782 sharkd_json_value_anyf("last", "%" PRId64
, max_idx
);
4783 sharkd_json_value_anyf("frames", "%u", st_total
.frames
);
4784 sharkd_json_value_anyf("bytes", "%" PRIu64
, st_total
.bytes
);
4786 sharkd_json_result_epilogue();
4790 * sharkd_session_process_frame()
4792 * Process frame request
4795 * (m) frame - requested frame number
4796 * (o) ref_frame - time reference frame number
4797 * (o) prev_frame - previously displayed frame number
4798 * (o) proto - set if output frame tree
4799 * (o) columns - set if output frame columns
4800 * (o) color - set if output color-filter bg/fg
4801 * (o) bytes - set if output frame bytes
4802 * (o) hidden - set if output hidden tree fields
4804 * Output object with attributes:
4805 * (m) err - 0 if succeed
4806 * (o) tree - array of frame nodes with attributes:
4808 * t: 'proto', 'framenum', 'url' - type of node
4812 * e - subtree ett index
4813 * n - array of subtree nodes
4814 * h - two item array: (item start, item length)
4815 * i - two item array: (appendix start, appendix length)
4816 * p - [RESERVED] two item array: (protocol start, protocol length)
4817 * ds- data src index
4818 * url - only for t:'url', url
4819 * fnum - only for t:'framenum', frame number
4820 * g - if field is generated by Wireshark
4821 * v - if field is hidden
4823 * (o) col - array of column data
4824 * (o) bytes - base64 of frame bytes
4825 * (o) ds - array of other data srcs
4826 * (o) comment - frame comment
4827 * (o) fol - array of follow filters:
4829 * [1] - filter string
4830 * (o) followers - array of followers with attributes:
4831 * protocol - protocol string
4832 * filter - filter string
4833 * stream - stream index number
4834 * sub_stream - sub-stream index number (optional, e.g. for HTTP/2 and QUIC streams)
4835 * (o) i - if frame is ignored
4836 * (o) m - if frame is marked
4837 * (o) bg - color filter - background color in hex
4838 * (o) fg - color filter - foreground color in hex
4841 sharkd_session_process_frame(char *buf
, const jsmntok_t
*tokens
, int count
)
4843 const char *tok_frame
= json_find_attr(buf
, tokens
, count
, "frame");
4844 const char *tok_ref_frame
= json_find_attr(buf
, tokens
, count
, "ref_frame");
4845 const char *tok_prev_frame
= json_find_attr(buf
, tokens
, count
, "prev_frame");
4846 column_info
*cinfo
= NULL
;
4848 uint32_t framenum
, ref_frame_num
, prev_dis_num
;
4849 uint32_t dissect_flags
= SHARKD_DISSECT_FLAG_NULL
;
4850 struct sharkd_frame_request_data req_data
;
4851 wtap_rec rec
; /* Record information */
4852 enum dissect_request_status status
;
4856 ws_strtou32(tok_frame
, NULL
, &framenum
); // we have already validated this
4858 ref_frame_num
= (framenum
!= 1) ? 1 : 0;
4861 ws_strtou32(tok_ref_frame
, NULL
, &ref_frame_num
);
4862 if (ref_frame_num
> framenum
)
4866 "Invalid ref_frame - The ref_frame occurs after the frame specified"
4872 prev_dis_num
= framenum
- 1;
4875 ws_strtou32(tok_prev_frame
, NULL
, &prev_dis_num
);
4876 if (prev_dis_num
>= framenum
)
4880 "Invalid prev_frame - The prev_frame occurs on or after the frame specified"
4886 if (json_find_attr(buf
, tokens
, count
, "proto") != NULL
)
4887 dissect_flags
|= SHARKD_DISSECT_FLAG_PROTO_TREE
;
4888 if (json_find_attr(buf
, tokens
, count
, "bytes") != NULL
)
4889 dissect_flags
|= SHARKD_DISSECT_FLAG_BYTES
;
4890 if (json_find_attr(buf
, tokens
, count
, "columns") != NULL
) {
4891 dissect_flags
|= SHARKD_DISSECT_FLAG_COLUMNS
;
4892 cinfo
= &cfile
.cinfo
;
4894 if (json_find_attr(buf
, tokens
, count
, "color") != NULL
)
4895 dissect_flags
|= SHARKD_DISSECT_FLAG_COLOR
;
4897 req_data
.display_hidden
= (json_find_attr(buf
, tokens
, count
, "v") != NULL
);
4899 wtap_rec_init(&rec
, 1514);
4901 status
= sharkd_dissect_request(framenum
, ref_frame_num
, prev_dis_num
,
4902 &rec
, cinfo
, dissect_flags
,
4903 &sharkd_session_process_frame_cb
, &req_data
, &err
, &err_info
);
4906 case DISSECT_REQUEST_SUCCESS
:
4910 case DISSECT_REQUEST_NO_SUCH_FRAME
:
4913 "Invalid frame - The frame number requested is out of range"
4917 case DISSECT_REQUEST_READ_ERROR
:
4920 /* XXX - show the error details */
4921 "Read error - The frame could not be read from the file"
4927 wtap_rec_cleanup(&rec
);
4931 * sharkd_session_process_check()
4933 * Process check request.
4936 * (o) filter - filter to be checked
4937 * (o) field - field to be checked
4939 * Output object with attributes:
4940 * (m) err - always 0
4941 * (o) filter - 'ok', 'warn' or error message
4942 * (o) field - 'ok', or 'notfound'
4945 sharkd_session_process_check(char *buf
, const jsmntok_t
*tokens
, int count
)
4947 const char *tok_filter
= json_find_attr(buf
, tokens
, count
, "filter");
4948 const char *tok_field
= json_find_attr(buf
, tokens
, count
, "field");
4950 if (tok_filter
!= NULL
)
4953 df_error_t
*df_err
= NULL
;
4955 if (dfilter_compile(tok_filter
, &dfp
, &df_err
))
4957 if (dfp
&& dfilter_deprecated_tokens(dfp
))
4958 sharkd_json_warning(rpcid
, "Filter contains deprecated tokens");
4960 sharkd_json_simple_ok(rpcid
);
4963 df_error_free(&df_err
);
4970 "Filter invalid - %s", df_err
->msg
4972 df_error_free(&df_err
);
4977 if (tok_field
!= NULL
)
4979 header_field_info
*hfi
= proto_registrar_get_byname(tok_field
);
4985 "Field %s not found", tok_field
4991 sharkd_json_simple_ok(rpcid
);
4996 sharkd_json_simple_ok(rpcid
);
5000 struct sharkd_session_process_complete_pref_data
5007 sharkd_session_process_complete_pref_cb(module_t
*module
, void *d
)
5009 struct sharkd_session_process_complete_pref_data
*data
= (struct sharkd_session_process_complete_pref_data
*) d
;
5011 if (strncmp(data
->pref
, module
->name
, strlen(data
->pref
)) != 0)
5014 json_dumper_begin_object(&dumper
);
5015 sharkd_json_value_string("f", module
->name
);
5016 sharkd_json_value_string("d", module
->title
);
5017 json_dumper_end_object(&dumper
);
5023 sharkd_session_process_complete_pref_option_cb(pref_t
*pref
, void *d
)
5025 struct sharkd_session_process_complete_pref_data
*data
= (struct sharkd_session_process_complete_pref_data
*) d
;
5026 const char *pref_name
= prefs_get_name(pref
);
5027 const char *pref_title
= prefs_get_title(pref
);
5029 if (strncmp(data
->pref
, pref_name
, strlen(data
->pref
)) != 0)
5032 json_dumper_begin_object(&dumper
);
5033 sharkd_json_value_stringf("f", "%s.%s", data
->module
, pref_name
);
5034 sharkd_json_value_string("d", pref_title
);
5035 json_dumper_end_object(&dumper
);
5037 return 0; /* continue */
5041 * sharkd_session_process_complete()
5043 * Process complete request
5046 * (o) field - field to be completed
5047 * (o) pref - preference to be completed
5049 * Output object with attributes:
5050 * (m) err - always 0
5051 * (o) field - array of object with attributes:
5052 * (m) f - field text
5053 * (o) t - field type (FT_ number)
5054 * (o) n - field name
5055 * (o) pref - array of object with attributes:
5057 * (o) d - pref description
5060 sharkd_session_process_complete(char *buf
, const jsmntok_t
*tokens
, int count
)
5062 const char *tok_field
= json_find_attr(buf
, tokens
, count
, "field");
5063 const char *tok_pref
= json_find_attr(buf
, tokens
, count
, "pref");
5065 sharkd_json_result_prologue(rpcid
);
5067 if (tok_field
!= NULL
&& tok_field
[0])
5069 const size_t filter_length
= strlen(tok_field
);
5070 const int filter_with_dot
= !!strchr(tok_field
, '.');
5076 sharkd_json_array_open("field");
5078 for (proto_id
= proto_get_first_protocol(&proto_cookie
); proto_id
!= -1; proto_id
= proto_get_next_protocol(&proto_cookie
))
5080 protocol_t
*protocol
= find_protocol_by_id(proto_id
);
5081 const char *protocol_filter
;
5082 const char *protocol_name
;
5083 header_field_info
*hfinfo
;
5085 if (!proto_is_protocol_enabled(protocol
))
5088 protocol_name
= proto_get_protocol_long_name(protocol
);
5089 protocol_filter
= proto_get_protocol_filter_name(proto_id
);
5091 if (strlen(protocol_filter
) >= filter_length
&& !g_ascii_strncasecmp(tok_field
, protocol_filter
, filter_length
))
5093 json_dumper_begin_object(&dumper
);
5095 sharkd_json_value_string("f", protocol_filter
);
5096 sharkd_json_value_anyf("t", "%d", FT_PROTOCOL
);
5097 sharkd_json_value_string("n", protocol_name
);
5099 json_dumper_end_object(&dumper
);
5102 if (!filter_with_dot
)
5105 for (hfinfo
= proto_get_first_protocol_field(proto_id
, &field_cookie
); hfinfo
!= NULL
; hfinfo
= proto_get_next_protocol_field(proto_id
, &field_cookie
))
5107 if (hfinfo
->same_name_prev_id
!= -1) /* ignore duplicate names */
5110 if (strlen(hfinfo
->abbrev
) >= filter_length
&& !g_ascii_strncasecmp(tok_field
, hfinfo
->abbrev
, filter_length
))
5112 json_dumper_begin_object(&dumper
);
5114 sharkd_json_value_string("f", hfinfo
->abbrev
);
5116 /* XXX, skip displaying name, if there are multiple (to not confuse user) */
5117 if (hfinfo
->same_name_next
== NULL
)
5119 sharkd_json_value_anyf("t", "%d", hfinfo
->type
);
5120 sharkd_json_value_string("n", hfinfo
->name
);
5123 json_dumper_end_object(&dumper
);
5128 sharkd_json_array_close();
5131 if (tok_pref
!= NULL
&& tok_pref
[0])
5133 struct sharkd_session_process_complete_pref_data data
;
5136 data
.module
= tok_pref
;
5137 data
.pref
= tok_pref
;
5139 sharkd_json_array_open("pref");
5140 if ((dot_sepa
= strchr(tok_pref
, '.')))
5144 *dot_sepa
= '\0'; /* XXX, C abuse: discarding-const */
5145 data
.pref
= dot_sepa
+ 1;
5147 pref_mod
= prefs_find_module(data
.module
);
5149 prefs_pref_foreach(pref_mod
, sharkd_session_process_complete_pref_option_cb
, &data
);
5155 prefs_modules_foreach(sharkd_session_process_complete_pref_cb
, &data
);
5157 sharkd_json_array_close();
5160 sharkd_json_result_epilogue();
5166 * sharkd_session_process_setcomment()
5168 * Process setcomment request
5171 * (m) frame - frame number
5172 * (o) comment - user comment
5174 * Output object with attributes:
5175 * (m) err - error code: 0 succeed
5178 * For now, adds comments, doesn't remove or replace them.
5181 sharkd_session_process_setcomment(char *buf
, const jsmntok_t
*tokens
, int count
)
5183 const char *tok_frame
= json_find_attr(buf
, tokens
, count
, "frame");
5184 const char *tok_comment
= json_find_attr(buf
, tokens
, count
, "comment");
5188 wtap_opttype_return_val ret
;
5189 wtap_block_t pkt_block
= NULL
;
5191 if (!tok_frame
|| !ws_strtou32(tok_frame
, NULL
, &framenum
) || framenum
== 0)
5195 "Frame number must be a positive integer"
5200 fdata
= sharkd_get_frame(framenum
); // BUG HERE - If no file loaded you get a crash
5205 "Frame number is out of range"
5210 pkt_block
= sharkd_get_packet_block(fdata
);
5212 ret
= wtap_block_add_string_option(pkt_block
, OPT_COMMENT
, tok_comment
, strlen(tok_comment
));
5214 if (ret
!= WTAP_OPTTYPE_SUCCESS
)
5218 "Unable to set the comment"
5223 sharkd_set_modified_block(fdata
, pkt_block
);
5224 sharkd_json_simple_ok(rpcid
);
5229 * sharkd_session_process_setconf()
5231 * Process setconf request
5234 * (m) name - preference name
5235 * (m) value - preference value
5237 * Output object with attributes:
5238 * (m) err - error code: 0 succeed
5241 sharkd_session_process_setconf(char *buf
, const jsmntok_t
*tokens
, int count
)
5243 const char *tok_name
= json_find_attr(buf
, tokens
, count
, "name");
5244 const char *tok_value
= json_find_attr(buf
, tokens
, count
, "value");
5246 char *errmsg
= NULL
;
5248 prefs_set_pref_e ret
;
5250 if (!tok_name
|| tok_name
[0] == '\0')
5254 "Preference name missing"
5263 "Preference value missing"
5268 snprintf(pref
, sizeof(pref
), "%s:%s", tok_name
, tok_value
);
5270 ret
= prefs_set_pref(pref
, &errmsg
);
5275 sharkd_json_simple_ok(rpcid
);
5278 case PREFS_SET_OBSOLETE
:
5281 "The preference specified is obsolete"
5285 case PREFS_SET_NO_SUCH_PREF
:
5288 "No such preference exists"
5295 "Unable to set the preference%s%s",
5296 errmsg
? ": " : "", errmsg
? errmsg
: ""
5303 struct sharkd_session_process_dumpconf_data
5309 sharkd_session_process_dumpconf_cb(pref_t
*pref
, void *d
)
5311 struct sharkd_session_process_dumpconf_data
*data
= (struct sharkd_session_process_dumpconf_data
*) d
;
5312 const char *pref_name
= prefs_get_name(pref
);
5314 char json_pref_key
[512];
5316 snprintf(json_pref_key
, sizeof(json_pref_key
), "%s.%s", data
->module
->name
, pref_name
);
5317 sharkd_json_object_open(json_pref_key
);
5319 switch (prefs_get_type(pref
))
5322 sharkd_json_value_anyf("u", "%u", prefs_get_uint_value(pref
, pref_current
));
5323 if (prefs_get_uint_base(pref
) != 10)
5324 sharkd_json_value_anyf("ub", "%u", prefs_get_uint_base(pref
));
5328 sharkd_json_value_anyf("b", prefs_get_bool_value(pref
, pref_current
) ? "1" : "0");
5332 case PREF_SAVE_FILENAME
:
5333 case PREF_OPEN_FILENAME
:
5336 case PREF_DISSECTOR
:
5337 sharkd_json_value_string("s", prefs_get_string_value(pref
, pref_current
));
5342 const enum_val_t
*enums
;
5344 sharkd_json_array_open("e");
5345 for (enums
= prefs_get_enumvals(pref
); enums
->name
; enums
++)
5347 json_dumper_begin_object(&dumper
);
5349 sharkd_json_value_anyf("v", "%d", enums
->value
);
5351 if (enums
->value
== prefs_get_enum_value(pref
, pref_current
))
5352 sharkd_json_value_anyf("s", "1");
5354 sharkd_json_value_string("d", enums
->description
);
5356 json_dumper_end_object(&dumper
);
5358 sharkd_json_array_close();
5363 case PREF_DECODE_AS_RANGE
:
5365 char *range_str
= range_convert_range(NULL
, prefs_get_range_value_real(pref
, pref_current
));
5366 sharkd_json_value_string("r", range_str
);
5367 wmem_free(NULL
, range_str
);
5373 uat_t
*uat
= prefs_get_uat_value(pref
);
5376 sharkd_json_array_open("t");
5377 for (idx
= 0; idx
< uat
->raw_data
->len
; idx
++)
5379 void *rec
= UAT_INDEX_PTR(uat
, idx
);
5382 sharkd_json_array_open(NULL
);
5383 for (colnum
= 0; colnum
< uat
->ncols
; colnum
++)
5385 char *str
= uat_fld_tostr(rec
, &(uat
->fields
[colnum
]));
5387 sharkd_json_value_string(NULL
, str
);
5391 sharkd_json_array_close();
5394 sharkd_json_array_close();
5400 case PREF_STATIC_TEXT
:
5407 sharkd_json_value_string("t", prefs_get_title(pref
));
5410 sharkd_json_object_close();
5412 return 0; /* continue */
5416 sharkd_session_process_dumpconf_mod_cb(module_t
*module
, void *d
)
5418 struct sharkd_session_process_dumpconf_data
*data
= (struct sharkd_session_process_dumpconf_data
*) d
;
5420 data
->module
= module
;
5421 prefs_pref_foreach(module
, sharkd_session_process_dumpconf_cb
, data
);
5427 * sharkd_session_process_dumpconf()
5429 * Process dumpconf request
5432 * (o) pref - module, or preference, NULL for all
5434 * Output object with attributes:
5435 * (o) prefs - object with module preferences
5436 * (m) [KEY] - preference name
5437 * (o) u - preference value (for PREF_UINT)
5438 * (o) ub - preference value suggested base for display (for PREF_UINT) and if different than 10
5439 * (o) b - preference value (only for PREF_BOOL) (1 true, 0 false)
5440 * (o) s - preference value (for PREF_STRING, PREF_SAVE_FILENAME, PREF_OPEN_FILENAME, PREF_DIRNAME, PREF_PASSWORD, PREF_DISSECTOR)
5441 * (o) e - preference possible values (only for PREF_ENUM)
5442 * (o) r - preference value (for PREF_RANGE, PREF_DECODE_AS_RANGE)
5443 * (o) t - preference value (only for PREF_UAT)
5446 sharkd_session_process_dumpconf(char *buf
, const jsmntok_t
*tokens
, int count
)
5448 const char *tok_pref
= json_find_attr(buf
, tokens
, count
, "pref");
5454 struct sharkd_session_process_dumpconf_data data
;
5458 sharkd_json_result_prologue(rpcid
);
5460 sharkd_json_object_open("prefs");
5461 prefs_modules_foreach(sharkd_session_process_dumpconf_mod_cb
, &data
);
5462 sharkd_json_object_close();
5464 sharkd_json_result_epilogue();
5468 if ((dot_sepa
= strchr(tok_pref
, '.')))
5470 pref_t
*pref
= NULL
;
5472 *dot_sepa
= '\0'; /* XXX, C abuse: discarding-const */
5473 pref_mod
= prefs_find_module(tok_pref
);
5475 pref
= prefs_find_preference(pref_mod
, dot_sepa
+ 1);
5480 struct sharkd_session_process_dumpconf_data data
;
5482 data
.module
= pref_mod
;
5484 sharkd_json_result_prologue(rpcid
);
5486 sharkd_json_object_open("prefs");
5487 sharkd_session_process_dumpconf_cb(pref
, &data
);
5488 sharkd_json_object_close();
5490 sharkd_json_result_epilogue();
5497 "Invalid pref %s.", tok_pref
5504 pref_mod
= prefs_find_module(tok_pref
);
5507 struct sharkd_session_process_dumpconf_data data
;
5509 data
.module
= pref_mod
;
5511 sharkd_json_result_prologue(rpcid
);
5513 sharkd_json_object_open("prefs");
5514 prefs_pref_foreach(pref_mod
, sharkd_session_process_dumpconf_cb
, &data
);
5515 sharkd_json_object_close();
5517 sharkd_json_result_epilogue();
5523 "Invalid pref %s.", tok_pref
5528 struct sharkd_download_rtp
5536 sharkd_rtp_download_free_items(void *ptr
)
5538 rtp_packet_t
*rtp_packet
= (rtp_packet_t
*) ptr
;
5540 g_free(rtp_packet
->info
);
5541 g_free(rtp_packet
->payload_data
);
5546 sharkd_rtp_download_decode(struct sharkd_download_rtp
*req
)
5548 /* based on RtpAudioStream::decode() 6e29d874f8b5e6ebc59f661a0bb0dab8e56f122a */
5549 /* TODO, for now only without silence (timing_mode_ = Uninterrupted) */
5551 static const int sample_bytes_
= sizeof(SAMPLE
) / sizeof(char);
5553 uint32_t audio_out_rate_
= 0;
5554 struct _GHashTable
*decoders_hash_
= rtp_decoder_hash_table_new();
5555 struct SpeexResamplerState_
*audio_resampler_
= NULL
;
5557 size_t resample_buff_len
= 0x1000;
5558 SAMPLE
*resample_buff
= (SAMPLE
*) g_malloc(resample_buff_len
);
5559 spx_uint32_t cur_in_rate
= 0;
5560 char *write_buff
= NULL
;
5561 size_t write_bytes
= 0;
5562 unsigned channels
= 0;
5563 unsigned sample_rate
= 0;
5567 for (l
= req
->packets
; l
; l
= l
->next
)
5569 rtp_packet_t
*rtp_packet
= (rtp_packet_t
*) l
->data
;
5571 SAMPLE
*decode_buff
= NULL
;
5572 size_t decoded_bytes
;
5574 decoded_bytes
= decode_rtp_packet(rtp_packet
, &decode_buff
, decoders_hash_
, &channels
, &sample_rate
);
5575 if (decoded_bytes
== 0 || sample_rate
== 0)
5577 /* We didn't decode anything. Clean up and prep for the next packet. */
5578 g_free(decode_buff
);
5582 if (audio_out_rate_
== 0)
5588 /* First non-zero wins */
5589 audio_out_rate_
= sample_rate
;
5591 RTP_STREAM_DEBUG("Audio sample rate is %u", audio_out_rate_
);
5593 /* write WAVE header */
5594 memset(&wav_hdr
, 0, sizeof(wav_hdr
));
5595 memcpy(&wav_hdr
[0], "RIFF", 4);
5596 memcpy(&wav_hdr
[4], "\xFF\xFF\xFF\xFF", 4); /* XXX, unknown */
5597 memcpy(&wav_hdr
[8], "WAVE", 4);
5599 memcpy(&wav_hdr
[12], "fmt ", 4);
5600 memcpy(&wav_hdr
[16], "\x10\x00\x00\x00", 4); /* PCM */
5601 memcpy(&wav_hdr
[20], "\x01\x00", 2); /* PCM */
5604 memcpy(&wav_hdr
[22], &tmp16
, 2);
5606 tmp32
= sample_rate
;
5607 memcpy(&wav_hdr
[24], &tmp32
, 4);
5609 tmp32
= sample_rate
* channels
* sample_bytes_
;
5610 memcpy(&wav_hdr
[28], &tmp32
, 4);
5612 tmp16
= channels
* sample_bytes_
;
5613 memcpy(&wav_hdr
[32], &tmp16
, 2);
5614 /* bits per sample */
5615 tmp16
= 8 * sample_bytes_
;
5616 memcpy(&wav_hdr
[34], &tmp16
, 2);
5618 memcpy(&wav_hdr
[36], "data", 4);
5619 memcpy(&wav_hdr
[40], "\xFF\xFF\xFF\xFF", 4); /* XXX, unknown */
5621 json_dumper_write_base64(&dumper
, wav_hdr
, sizeof(wav_hdr
));
5624 // Write samples to our file.
5625 write_buff
= (char *) decode_buff
;
5626 write_bytes
= decoded_bytes
;
5628 if (audio_out_rate_
!= sample_rate
)
5630 spx_uint32_t in_len
, out_len
;
5632 /* Resample the audio to match our previous output rate. */
5633 if (!audio_resampler_
)
5635 audio_resampler_
= speex_resampler_init(1, sample_rate
, audio_out_rate_
, 10, NULL
);
5636 speex_resampler_skip_zeros(audio_resampler_
);
5637 RTP_STREAM_DEBUG("Started resampling from %u to (out) %u Hz.", sample_rate
, audio_out_rate_
);
5641 spx_uint32_t audio_out_rate
;
5642 speex_resampler_get_rate(audio_resampler_
, &cur_in_rate
, &audio_out_rate
);
5644 if (sample_rate
!= cur_in_rate
)
5646 speex_resampler_set_rate(audio_resampler_
, sample_rate
, audio_out_rate
);
5647 RTP_STREAM_DEBUG("Changed input rate from %u to %u Hz. Out is %u.", cur_in_rate
, sample_rate
, audio_out_rate_
);
5650 in_len
= (spx_uint32_t
)rtp_packet
->info
->info_payload_len
;
5651 out_len
= (audio_out_rate_
* (spx_uint32_t
)rtp_packet
->info
->info_payload_len
/ sample_rate
) + (audio_out_rate_
% sample_rate
!= 0);
5652 if (out_len
* sample_bytes_
> resample_buff_len
)
5654 while ((out_len
* sample_bytes_
> resample_buff_len
))
5655 resample_buff_len
*= 2;
5656 resample_buff
= (SAMPLE
*) g_realloc(resample_buff
, resample_buff_len
);
5659 speex_resampler_process_int(audio_resampler_
, 0, decode_buff
, &in_len
, resample_buff
, &out_len
);
5660 write_buff
= (char *) resample_buff
;
5661 write_bytes
= out_len
* sample_bytes_
;
5664 /* Write the decoded, possibly-resampled audio */
5665 json_dumper_write_base64(&dumper
, write_buff
, write_bytes
);
5667 g_free(decode_buff
);
5670 g_free(resample_buff
);
5671 g_hash_table_destroy(decoders_hash_
);
5674 static tap_packet_status
5675 sharkd_session_packet_download_tap_rtp_cb(void *tapdata
, packet_info
*pinfo
, epan_dissect_t
*edt _U_
, const void *data
, tap_flags_t flags _U_
)
5677 const struct _rtp_info
*rtp_info
= (const struct _rtp_info
*) data
;
5678 struct sharkd_download_rtp
*req_rtp
= (struct sharkd_download_rtp
*) tapdata
;
5680 /* do not consider RTP packets without a setup frame */
5681 if (rtp_info
->info_setup_frame_num
== 0)
5682 return TAP_PACKET_DONT_REDRAW
;
5684 if (rtpstream_id_equal_pinfo_rtp_info(&req_rtp
->id
, pinfo
, rtp_info
))
5686 rtp_packet_t
*rtp_packet
;
5688 rtp_packet
= g_new0(rtp_packet_t
, 1);
5689 rtp_packet
->info
= (struct _rtp_info
*) g_memdup2(rtp_info
, sizeof(struct _rtp_info
));
5691 if (rtp_info
->info_all_data_present
&& rtp_info
->info_payload_len
!= 0)
5692 rtp_packet
->payload_data
= (uint8_t *) g_memdup2(&(rtp_info
->info_data
[rtp_info
->info_payload_offset
]), rtp_info
->info_payload_len
);
5694 if (!req_rtp
->packets
)
5695 req_rtp
->start_time
= nstime_to_sec(&pinfo
->abs_ts
);
5697 rtp_packet
->frame_num
= pinfo
->num
;
5698 rtp_packet
->arrive_offset
= nstime_to_sec(&pinfo
->abs_ts
) - req_rtp
->start_time
;
5700 /* XXX, O(n) optimize */
5701 req_rtp
->packets
= g_slist_append(req_rtp
->packets
, rtp_packet
);
5704 return TAP_PACKET_DONT_REDRAW
;
5708 sharkd_session_eo_retap_listener(const char *tap_type
) {
5710 register_eo_t
*eo
= NULL
;
5711 GString
*tap_error
= NULL
;
5712 void *tap_data
= NULL
;
5713 GFreeFunc tap_free
= NULL
;
5715 // get <name> from eo:<name>, get_eo_by_name only needs the name (http etc.)
5716 eo
= get_eo_by_name(tap_type
+ 3);
5721 rpcid
, -11011, NULL
,
5722 "sharkd_session_eo_retap_listener() eo=%s not found", tap_type
+ 3
5728 tap_error
= sharkd_session_eo_register_tap_listener(eo
, tap_type
, NULL
, NULL
, &tap_data
, &tap_free
);
5733 rpcid
, -10002, NULL
,
5734 "sharkd_session_eo_retap_listener() sharkd_session_eo_register_tap_listener error %s",
5736 g_string_free(tap_error
, TRUE
);
5744 remove_tap_listener(tap_data
);
5753 * sharkd_session_process_download()
5755 * Process download request
5758 * (m) token - token to download
5760 * Output object with attributes:
5761 * (o) file - suggested name of file
5762 * (o) mime - suggested content type
5763 * (o) data - payload base64 encoded
5766 sharkd_session_process_download(char *buf
, const jsmntok_t
*tokens
, int count
)
5768 const char *tok_token
= json_find_attr(buf
, tokens
, count
, "token");
5773 rpcid
, -10005, NULL
,
5779 if (!strncmp(tok_token
, "eo:", 3))
5781 // get eo:<name> from eo:<name>_<row>
5782 char *tap_type
= g_strdup(tok_token
);
5783 char *tmp
= strrchr(tap_type
, '_');
5787 // if eo:<name> not in sharkd_eo_list, retap
5788 if (!sharkd_eo_object_list_get_entry_by_type(sharkd_eo_list
, tap_type
) &&
5789 !sharkd_session_eo_retap_listener(tap_type
))
5792 // sharkd_json_error called in sharkd_session_eo_retap_listener
5798 struct sharkd_export_object_list
*object_list
;
5799 const export_object_entry_t
*eo_entry
= NULL
;
5801 for (object_list
= sharkd_eo_list
; object_list
; object_list
= object_list
->next
)
5803 size_t eo_type_len
= strlen(object_list
->type
);
5805 if (!strncmp(tok_token
, object_list
->type
, eo_type_len
) && tok_token
[eo_type_len
] == '_')
5809 if (sscanf(&tok_token
[eo_type_len
+ 1], "%d", &row
) != 1)
5812 eo_entry
= (export_object_entry_t
*) g_slist_nth_data(object_list
->entries
, row
);
5819 const char *mime
= (eo_entry
->content_type
) ? eo_entry
->content_type
: "application/octet-stream";
5820 const char *filename
= (eo_entry
->filename
) ? eo_entry
->filename
: tok_token
;
5822 sharkd_json_result_prologue(rpcid
);
5823 sharkd_json_value_string("file", filename
);
5824 sharkd_json_value_string("mime", mime
);
5825 sharkd_json_value_base64("data", eo_entry
->payload_data
, eo_entry
->payload_len
);
5826 sharkd_json_result_epilogue();
5830 sharkd_json_result_prologue(rpcid
);
5831 sharkd_json_result_epilogue();
5834 else if (!strcmp(tok_token
, "ssl-secrets"))
5837 char *str
= ssl_export_sessions(&str_len
);
5841 const char *mime
= "text/plain";
5842 const char *filename
= "keylog.txt";
5844 sharkd_json_result_prologue(rpcid
);
5845 sharkd_json_value_string("file", filename
);
5846 sharkd_json_value_string("mime", mime
);
5847 sharkd_json_value_base64("data", str
, str_len
);
5848 sharkd_json_result_epilogue();
5852 else if (!strncmp(tok_token
, "rtp:", 4))
5854 struct sharkd_download_rtp rtp_req
;
5857 memset(&rtp_req
, 0, sizeof(rtp_req
));
5858 if (!sharkd_rtp_match_init(&rtp_req
.id
, tok_token
+ 4))
5861 rpcid
, -10001, NULL
,
5862 "sharkd_session_process_download() rtp tokenizing error %s", tok_token
5867 tap_error
= register_tap_listener("rtp", &rtp_req
, NULL
, 0, NULL
, sharkd_session_packet_download_tap_rtp_cb
, NULL
, NULL
);
5871 rpcid
, -10002, NULL
,
5872 "sharkd_session_process_download() rtp error %s", tap_error
->str
5874 g_string_free(tap_error
, TRUE
);
5879 remove_tap_listener(&rtp_req
);
5881 if (rtp_req
.packets
)
5883 const char *mime
= "audio/x-wav";
5884 const char *filename
= tok_token
;
5886 sharkd_json_result_prologue(rpcid
);
5887 sharkd_json_value_string("file", filename
);
5888 sharkd_json_value_string("mime", mime
);
5890 json_dumper_set_member_name(&dumper
, "data");
5891 json_dumper_begin_base64(&dumper
);
5892 sharkd_rtp_download_decode(&rtp_req
);
5893 json_dumper_end_base64(&dumper
);
5895 sharkd_json_result_epilogue();
5897 g_slist_free_full(rtp_req
.packets
, sharkd_rtp_download_free_items
);
5902 rpcid
, -10003, NULL
,
5903 "no rtp data available"
5910 rpcid
, -10004, NULL
,
5911 "unrecognized token"
5917 sharkd_session_process(char *buf
, const jsmntok_t
*tokens
, int count
)
5919 if (json_prep(buf
, tokens
, count
))
5921 /* don't need [0] token */
5925 const char* tok_method
= json_find_attr(buf
, tokens
, count
, "method");
5929 rpcid
, -32601, NULL
,
5933 if (!strcmp(tok_method
, "load"))
5934 sharkd_session_process_load(buf
, tokens
, count
);
5935 else if (!strcmp(tok_method
, "status"))
5936 sharkd_session_process_status();
5937 else if (!strcmp(tok_method
, "analyse"))
5938 sharkd_session_process_analyse();
5939 else if (!strcmp(tok_method
, "info"))
5940 sharkd_session_process_info();
5941 else if (!strcmp(tok_method
, "check"))
5942 sharkd_session_process_check(buf
, tokens
, count
);
5943 else if (!strcmp(tok_method
, "complete"))
5944 sharkd_session_process_complete(buf
, tokens
, count
);
5945 else if (!strcmp(tok_method
, "frames"))
5946 sharkd_session_process_frames(buf
, tokens
, count
);
5947 else if (!strcmp(tok_method
, "tap"))
5948 sharkd_session_process_tap(buf
, tokens
, count
);
5949 else if (!strcmp(tok_method
, "follow"))
5950 sharkd_session_process_follow(buf
, tokens
, count
);
5951 else if (!strcmp(tok_method
, "iograph"))
5952 sharkd_session_process_iograph(buf
, tokens
, count
);
5953 else if (!strcmp(tok_method
, "intervals"))
5954 sharkd_session_process_intervals(buf
, tokens
, count
);
5955 else if (!strcmp(tok_method
, "frame"))
5956 sharkd_session_process_frame(buf
, tokens
, count
);
5957 else if (!strcmp(tok_method
, "setcomment"))
5958 sharkd_session_process_setcomment(buf
, tokens
, count
);
5959 else if (!strcmp(tok_method
, "setconf"))
5960 sharkd_session_process_setconf(buf
, tokens
, count
);
5961 else if (!strcmp(tok_method
, "dumpconf"))
5962 sharkd_session_process_dumpconf(buf
, tokens
, count
);
5963 else if (!strcmp(tok_method
, "download"))
5964 sharkd_session_process_download(buf
, tokens
, count
);
5965 else if (!strcmp(tok_method
, "bye"))
5967 sharkd_json_simple_ok(rpcid
);
5973 rpcid
, -32601, NULL
,
5974 "The method \"%s\" is unknown", tok_method
5981 sharkd_session_main(int mode_setting
)
5984 jsmntok_t
*tokens
= NULL
;
5985 int tokens_max
= -1;
5987 mode
= mode_setting
;
5989 fprintf(stderr
, "Hello in child.\n");
5991 dumper
.output_file
= stdout
;
5993 filter_table
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, sharkd_session_filter_free
);
5995 #ifdef HAVE_MAXMINDDB
5996 /* mmdbresolve was stopped before fork(), force starting it */
5997 uat_get_table_by_name("MaxMind Database Paths")->post_update_cb();
6000 set_resolution_synchrony(true);
6002 while (fgets(buf
, sizeof(buf
), stdin
))
6004 /* every command is line separated JSON */
6007 ret
= json_parse(buf
, NULL
, 0);
6011 rpcid
, -32600, NULL
,
6017 /* fprintf(stderr, "JSON: %d tokens\n", ret); */
6020 if (tokens
== NULL
|| tokens_max
< ret
)
6023 tokens
= (jsmntok_t
*) g_realloc(tokens
, sizeof(jsmntok_t
) * tokens_max
);
6026 memset(tokens
, 0, ret
* sizeof(jsmntok_t
));
6028 ret
= json_parse(buf
, tokens
, ret
);
6032 rpcid
, -32600, NULL
,
6038 host_name_lookup_process();
6040 sharkd_session_process(buf
, tokens
, ret
);
6043 g_hash_table_destroy(filter_table
);