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
12 #include "wtap_opttypes.h"
24 #include <wsutil/wsjson.h>
25 #include <wsutil/json_dumper.h>
26 #include <wsutil/ws_assert.h>
27 #include <wsutil/wsgcrypt.h>
30 #include <epan/epan_dissect.h>
31 #include <epan/exceptions.h>
32 #include <epan/color_filters.h>
33 #include <epan/prefs.h>
34 #include <epan/prefs-int.h>
35 #include <epan/uat-int.h>
36 #include <wiretap/wtap.h>
38 #include <epan/column.h>
39 #include <epan/column-info.h>
41 #include <ui/ssl_key_export.h>
43 #include <ui/io_graph_item.h>
44 #include <epan/stats_tree_priv.h>
45 #include <epan/stat_tap_ui.h>
46 #include <epan/conversation_table.h>
47 #include <epan/sequence_analysis.h>
48 #include <epan/expert.h>
49 #include <epan/export_object.h>
50 #include <epan/follow.h>
51 #include <epan/rtd_table.h>
52 #include <epan/srt_table.h>
53 #include <epan/to_str.h>
55 #include <epan/dissectors/packet-h225.h>
56 #include <epan/rtp_pt.h>
57 #include <ui/voip_calls.h>
58 #include <ui/rtp_stream.h>
59 #include <ui/tap-rtp-common.h>
60 #include <ui/tap-rtp-analysis.h>
61 #include <ui/cli/tap-protohierstat.h>
62 #include <ui/cli/tap-voip.h>
63 #include <wsutil/version_info.h>
64 #include <epan/to_str.h>
66 #include <epan/addr_resolv.h>
67 #include <epan/dissectors/packet-rtp.h>
68 #include <ui/rtp_media.h>
69 #include <ui/mcast_stream.h>
70 #include <speex/speex_resampler.h>
72 #include <epan/maxmind_db.h>
74 #include <wsutil/pint.h>
75 #include <wsutil/strnatcmp.h>
76 #include <wsutil/strtoi.h>
82 struct sharkd_filter_item
84 guint8
*filtered
; /* can be NULL if all frames are matching for given filter. */
87 static GHashTable
*filter_table
;
92 static json_dumper dumper
;
96 json_find_attr(const char *buf
, const jsmntok_t
*tokens
, int count
, const char *attr
)
100 for (i
= 0; i
< count
; i
+= 2)
102 const char *tok_attr
= &buf
[tokens
[i
+ 0].start
];
103 const char *tok_value
= &buf
[tokens
[i
+ 1].start
];
105 if (!strcmp(tok_attr
, attr
))
113 json_print_base64(const guint8
*data
, size_t len
)
115 json_dumper_begin_base64(&dumper
);
116 json_dumper_write_base64(&dumper
, data
, len
);
117 json_dumper_end_base64(&dumper
);
120 static void G_GNUC_PRINTF(2, 3)
121 sharkd_json_value_anyf(const char *key
, const char *format
, ...)
124 json_dumper_set_member_name(&dumper
, key
);
127 va_start(ap
, format
);
128 json_dumper_value_va_list(&dumper
, format
, ap
);
133 sharkd_json_value_string(const char *key
, const char *str
)
136 json_dumper_set_member_name(&dumper
, key
);
137 json_dumper_value_string(&dumper
, str
);
141 sharkd_json_value_base64(const char *key
, const guint8
*data
, size_t len
)
144 json_dumper_set_member_name(&dumper
, key
);
145 json_print_base64(data
, len
);
148 static void G_GNUC_PRINTF(2, 3)
149 sharkd_json_value_stringf(const char *key
, const char *format
, ...)
152 json_dumper_set_member_name(&dumper
, key
);
155 va_start(ap
, format
);
156 char* sformat
= ws_strdup_printf("\"%s\"", format
);
157 json_dumper_value_va_list(&dumper
, sformat
, ap
);
163 sharkd_json_array_open(const char *key
)
166 json_dumper_set_member_name(&dumper
, key
);
167 json_dumper_begin_array(&dumper
);
171 sharkd_json_array_close(void)
173 json_dumper_end_array(&dumper
);
177 sharkd_json_object_open(const char *key
)
180 json_dumper_set_member_name(&dumper
, key
);
181 json_dumper_begin_object(&dumper
);
185 sharkd_json_object_close(void)
187 json_dumper_end_object(&dumper
);
191 sharkd_json_response_open(guint32 id
)
193 json_dumper_begin_object(&dumper
); // start the message
194 sharkd_json_value_string("jsonrpc", "2.0");
195 sharkd_json_value_anyf("id", "%d", id
);
199 sharkd_json_response_close(void)
201 json_dumper_end_object(&dumper
); // end the message
203 json_dumper_finish(&dumper
);
206 * We do an explicit fflush after every line, because
207 * we want output to be written to the socket as soon
208 * as the line is complete.
210 * The stream is fully-buffered by default, so it's
211 * only flushed when the buffer fills or the FILE *
212 * is closed. On UN*X, we could set it to be line
213 * buffered, but the MSVC standard I/O routines don't
214 * support line buffering - they only support *byte*
215 * buffering, doing a write for every byte written,
216 * which is too inefficient, and full buffering,
217 * which is what you get if you request line buffering.
223 sharkd_json_result_prologue(guint32 id
)
225 sharkd_json_response_open(id
);
226 sharkd_json_object_open("result"); // start the result object
230 sharkd_json_result_epilogue(void)
232 json_dumper_end_object(&dumper
); // end the result object
233 sharkd_json_response_close();
237 sharkd_json_result_array_prologue(guint32 id
)
239 sharkd_json_response_open(id
);
240 sharkd_json_array_open("result"); // start the result array
244 sharkd_json_result_array_epilogue(void)
246 sharkd_json_array_close(); // end of result array
247 sharkd_json_response_close();
251 sharkd_json_simple_ok(guint32 id
)
253 sharkd_json_result_prologue(id
);
254 sharkd_json_value_string("status", "OK");
255 sharkd_json_result_epilogue();
259 sharkd_json_warning(guint32 id
, char *warning
)
261 sharkd_json_result_prologue(id
);
262 sharkd_json_value_string("status", "Warning");
263 sharkd_json_value_string("warning", warning
);
264 sharkd_json_result_epilogue();
267 static void G_GNUC_PRINTF(4, 5)
268 sharkd_json_error(guint32 id
, int code
, char* data
, char* format
, ...)
270 sharkd_json_response_open(id
);
271 sharkd_json_object_open("error");
272 sharkd_json_value_anyf("code", "%d", code
);
276 // format the text message
279 va_start(args
, format
);
280 char *error_msg
= ws_strdup_vprintf(format
, args
);
283 sharkd_json_value_string("message", error_msg
);
288 sharkd_json_object_close();
291 sharkd_json_value_string("data", data
);
293 sharkd_json_response_close();
297 is_param_match(const char *param_in
, const char *valid_param
)
301 if ((ptr
= g_strrstr(valid_param
, "*")))
303 size_t prefix_len
= ptr
- valid_param
;
304 return !strncmp(param_in
, valid_param
, prefix_len
);
307 return !strcmp(param_in
, valid_param
);
311 * json_prep does four things:
313 * 1. check the syntax of the root and parameter members
314 * 2. tokenize the names and values by zero terminating them
315 * 3. unescape the names and values
316 * 4. extracts and saves the rpcid
317 * - we have to do it here as it's needed for the error messages
319 * The objective is to minimise the validation work in the functions
320 * that process each called method.
322 * This gets a little messy as the JSON parser creates a flat list
323 * of all members rather than create a tree.
326 json_prep(char* buf
, const jsmntok_t
* tokens
, int count
)
329 const char* method
= NULL
;
330 char* attr_name
= NULL
;
331 char* attr_value
= NULL
;
333 #define SHARKD_JSON_ANY 0
334 #define SHARKD_JSON_STRING 1
335 #define SHARKD_JSON_INTEGER 2
336 #define SHARKD_JSON_UINTEGER 3
337 #define SHARKD_JSON_FLOAT 4
338 #define SHARKD_JSON_OBJECT 5
339 #define SHARKD_JSON_ARRAY 6
340 #define SHARKD_JSON_BOOLEAN 7
341 #define SHARKD_ARRAY_END 99
343 struct member_attribute
{
344 const char* parent_ctx
;
349 gboolean is_mandatory
;
352 #define SHARKD_MANDATORY TRUE
353 #define SHARKD_OPTIONAL FALSE
356 * The member attribute structure is key to the syntax checking. The
357 * array contains all of the root level (1) member names, the data
358 * types permissible for the value and a boolean that indicates whether
359 * or not the member is mandatory.
361 * Once we get into the next layer (2) of the json tree, we need to check
362 * params member names and data types dependent in the context of the method
366 struct member_attribute name_array
[] = {
368 {NULL
, "jsonrpc", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
369 {NULL
, "userid", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
370 {NULL
, "id", 1, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_MANDATORY
},
371 {NULL
, "method", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
372 {NULL
, "params", 1, JSMN_OBJECT
, SHARKD_JSON_OBJECT
, SHARKD_OPTIONAL
},
375 {"method", "analyse", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
376 {"method", "bye", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
377 {"method", "check", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
378 {"method", "complete", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
379 {"method", "download", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
380 {"method", "dumpconf", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
381 {"method", "follow", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
382 {"method", "frame", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
383 {"method", "frames", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
384 {"method", "info", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
385 {"method", "intervals", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
386 {"method", "iograph", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
387 {"method", "load", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
388 {"method", "setcomment", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
389 {"method", "setconf", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
390 {"method", "status", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
391 {"method", "tap", 1, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
393 // Parameters and their method context
394 {"check", "field", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
395 {"check", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
396 {"complete", "field", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
397 {"complete", "pref", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
398 {"download", "token", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
399 {"dumpconf", "pref", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
400 {"follow", "follow", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
401 {"follow", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
402 {"follow", "sub_stream", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
403 {"frame", "frame", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_MANDATORY
},
404 {"frame", "proto", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
405 {"frame", "ref_frame", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
406 {"frame", "prev_frame", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
407 {"frame", "columns", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
408 {"frame", "color", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
409 {"frame", "bytes", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
410 {"frame", "hidden", 2, JSMN_PRIMITIVE
, SHARKD_JSON_BOOLEAN
, SHARKD_OPTIONAL
},
411 {"frames", "column*", 2, JSMN_UNDEFINED
, SHARKD_JSON_ANY
, SHARKD_OPTIONAL
},
412 {"frames", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
413 {"frames", "skip", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
414 {"frames", "limit", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
415 {"frames", "refs", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
416 {"intervals", "interval", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
417 {"intervals", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
418 {"iograph", "interval", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_OPTIONAL
},
419 {"iograph", "interval_units", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
420 {"iograph", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
421 {"iograph", "graph0", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
422 {"iograph", "graph1", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
423 {"iograph", "graph2", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
424 {"iograph", "graph3", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
425 {"iograph", "graph4", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
426 {"iograph", "graph5", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
427 {"iograph", "graph6", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
428 {"iograph", "graph7", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
429 {"iograph", "graph8", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
430 {"iograph", "graph9", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
431 {"iograph", "filter0", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
432 {"iograph", "filter1", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
433 {"iograph", "filter2", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
434 {"iograph", "filter3", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
435 {"iograph", "filter4", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
436 {"iograph", "filter5", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
437 {"iograph", "filter6", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
438 {"iograph", "filter7", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
439 {"iograph", "filter8", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
440 {"iograph", "filter9", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
441 {"load", "file", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
442 {"setcomment", "frame", 2, JSMN_PRIMITIVE
, SHARKD_JSON_UINTEGER
, SHARKD_MANDATORY
},
443 {"setcomment", "comment", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
444 {"setconf", "name", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
445 {"setconf", "value", 2, JSMN_UNDEFINED
, SHARKD_JSON_ANY
, SHARKD_MANDATORY
},
446 {"tap", "tap0", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_MANDATORY
},
447 {"tap", "tap1", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
448 {"tap", "tap2", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
449 {"tap", "tap3", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
450 {"tap", "tap4", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
451 {"tap", "tap5", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
452 {"tap", "tap6", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
453 {"tap", "tap7", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
454 {"tap", "tap8", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
455 {"tap", "tap9", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
456 {"tap", "tap10", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
457 {"tap", "tap11", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
458 {"tap", "tap12", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
459 {"tap", "tap13", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
460 {"tap", "tap14", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
461 {"tap", "tap15", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
462 {"tap", "filter", 2, JSMN_STRING
, SHARKD_JSON_STRING
, SHARKD_OPTIONAL
},
464 // End of the name_array
465 {NULL
, NULL
, 0, JSMN_STRING
, SHARKD_ARRAY_END
, SHARKD_OPTIONAL
},
470 /* sanity check, and split strings */
471 if (count
< 1 || tokens
[0].type
!= JSMN_OBJECT
)
475 "The request must an object"
480 /* don't need [0] token */
488 "The request must contain name/value pairs"
493 for (i
= 0; i
< count
; i
+= 2)
495 buf
[tokens
[i
+ 0].end
] = '\0';
496 buf
[tokens
[i
+ 1].end
] = '\0';
499 // we must get the id as soon as possible so that it's available in all future error messages
500 attr_value
= (char*)json_find_attr(buf
, tokens
, count
, "id");
503 if (!ws_strtou32(attr_value
, NULL
, &rpcid
))
507 "The id value must be a positive integer"
513 method
= json_find_attr(buf
, tokens
, count
, "method");
517 gboolean is_supported
= FALSE
;
518 i
= 0; // name array index
520 // check that the request method is good
521 while (name_array
[i
].value_type
!= SHARKD_ARRAY_END
)
523 if (name_array
[i
].parent_ctx
)
525 if (!strcmp(method
, name_array
[i
].name
) && !strcmp(name_array
[i
].parent_ctx
, "method"))
526 is_supported
= TRUE
; // the method is valid
536 "The method %s is not supported", method
542 for (i
= 0; i
< count
; i
+= 2)
544 if (tokens
[i
].type
!= JSMN_STRING
)
548 "Member names must be a string - member %d is not string", (i
/ 2) + 1
553 attr_name
= &buf
[tokens
[i
+ 0].start
];
554 attr_value
= &buf
[tokens
[i
+ 1].start
];
556 if (!strcmp(attr_name
, "jsonrpc"))
558 if (strcmp(&buf
[tokens
[i
+ 1].start
], "2.0"))
562 "Only JSON %s is supported", "2.0"
568 /* unescape only value, as keys are simple strings */
569 if (tokens
[i
+ 1].type
== JSMN_STRING
&& !json_decode_string_inplace(attr_value
))
573 "Cannot unescape the value string of member %d", (i
/ 2) + 1
578 /* Confirm that the member is valid */
579 gboolean match
= FALSE
;
581 // We need to check root members (level 1) and parameters (level 2), hence the for loop.
583 for (int level
= 1; level
< 3; level
++)
587 while (name_array
[j
].value_type
!= SHARKD_ARRAY_END
) // iterate through the array until we hit the end
589 if (is_param_match(attr_name
, name_array
[j
].name
) && name_array
[j
].level
== level
)
591 // We need to be sure the match is in the correct context
592 // i.e. is this a match for a root member (level 1) or for a parameter (level 2).
596 // need to guard against a parameter name matching a method name
599 if (name_array
[j
].parent_ctx
)
605 if (!strcmp(method
, &buf
[tokens
[i
+ 0].start
]))
616 if (level
== 2 && !strcmp(name_array
[j
].parent_ctx
, method
))
630 // The match looks good, let's now check the data types
632 if (tokens
[i
+ 1].type
!= name_array
[j
].type
&& name_array
[j
].type
!= SHARKD_JSON_ANY
)
636 "The data type for member %s is not valid", attr_name
640 else if (name_array
[j
].type
== JSMN_PRIMITIVE
&& name_array
[j
].value_type
== SHARKD_JSON_UINTEGER
)
643 if (!ws_strtou32(attr_value
, NULL
, &temp
) || temp
<= 0)
647 "The value for %s must be a positive integer", name_array
[j
].name
652 else if (name_array
[j
].type
== JSMN_PRIMITIVE
&& name_array
[j
].value_type
== SHARKD_JSON_BOOLEAN
)
654 if (strcmp(attr_value
, "true") && strcmp(attr_value
, "false"))
658 "The value for %s must be a boolean (true or false)", name_array
[j
].name
664 break; // looks like a valid match
674 "%s is not a valid member name", attr_name
680 /* check for mandatory members */
683 while (name_array
[j
].value_type
!= SHARKD_ARRAY_END
)
685 if (name_array
[j
].is_mandatory
&& name_array
[j
].level
== 1)
687 if (!json_find_attr(buf
, tokens
, count
, name_array
[j
].name
))
691 "Mandatory member %s is missing", name_array
[j
].name
699 // check that the current request contains the mandatory parameters
702 while (name_array
[j
].value_type
!= SHARKD_ARRAY_END
)
704 if (name_array
[j
].is_mandatory
&& name_array
[j
].level
== 2 && !strcmp(method
, name_array
[j
].parent_ctx
))
706 if (!json_find_attr(buf
, tokens
, count
, name_array
[j
].name
))
710 "Mandatory parameter %s is missing", name_array
[j
].name
719 // check that the parameters for the current request are valid for the method and that the data type for the value is valid
725 sharkd_session_filter_free(gpointer data
)
727 struct sharkd_filter_item
*l
= (struct sharkd_filter_item
*) data
;
733 static const struct sharkd_filter_item
*
734 sharkd_session_filter_data(const char *filter
)
736 struct sharkd_filter_item
*l
;
738 l
= (struct sharkd_filter_item
*) g_hash_table_lookup(filter_table
, filter
);
741 guint8
*filtered
= NULL
;
743 int ret
= sharkd_filter(filter
, &filtered
);
748 l
= g_new(struct sharkd_filter_item
, 1);
749 l
->filtered
= filtered
;
751 g_hash_table_insert(filter_table
, g_strdup(filter
), l
);
758 sharkd_rtp_match_init(rtpstream_id_t
*id
, const char *init_str
)
760 gboolean ret
= FALSE
;
762 guint32 tmp_addr_src
, tmp_addr_dst
;
763 address tmp_src_addr
, tmp_dst_addr
;
765 memset(id
, 0, sizeof(*id
));
767 arr
= g_strsplit(init_str
, "_", 7); /* pass larger value, so we'll catch incorrect input :) */
768 if (g_strv_length(arr
) != 5)
771 /* TODO, for now only IPv4 */
772 if (!get_host_ipaddr(arr
[0], &tmp_addr_src
))
775 if (!ws_strtou16(arr
[1], NULL
, &id
->src_port
))
778 if (!get_host_ipaddr(arr
[2], &tmp_addr_dst
))
781 if (!ws_strtou16(arr
[3], NULL
, &id
->dst_port
))
784 if (!ws_hexstrtou32(arr
[4], NULL
, &id
->ssrc
))
787 set_address(&tmp_src_addr
, AT_IPv4
, 4, &tmp_addr_src
);
788 copy_address(&id
->src_addr
, &tmp_src_addr
);
789 set_address(&tmp_dst_addr
, AT_IPv4
, 4, &tmp_addr_dst
);
790 copy_address(&id
->dst_addr
, &tmp_dst_addr
);
800 sharkd_session_process_info_nstat_cb(const void *key
, void *value
, void *userdata _U_
)
802 stat_tap_table_ui
*stat_tap
= (stat_tap_table_ui
*) value
;
804 json_dumper_begin_object(&dumper
);
805 sharkd_json_value_string("name", stat_tap
->title
);
806 sharkd_json_value_stringf("tap", "nstat:%s", (const char *) key
);
807 json_dumper_end_object(&dumper
);
813 sharkd_session_process_info_conv_cb(const void* key
, void* value
, void* userdata _U_
)
815 struct register_ct
*table
= (struct register_ct
*) value
;
817 const char *label
= (const char *) key
;
819 if (get_conversation_packet_func(table
))
821 json_dumper_begin_object(&dumper
);
822 sharkd_json_value_stringf("name", "Conversation List/%s", label
);
823 sharkd_json_value_stringf("tap", "conv:%s", label
);
824 json_dumper_end_object(&dumper
);
827 if (get_endpoint_packet_func(table
))
829 json_dumper_begin_object(&dumper
);
830 sharkd_json_value_stringf("name", "Endpoint/%s", label
);
831 sharkd_json_value_stringf("tap", "endpt:%s", label
);
832 json_dumper_end_object(&dumper
);
838 sharkd_session_seq_analysis_cb(const void *key
, void *value
, void *userdata _U_
)
840 register_analysis_t
*analysis
= (register_analysis_t
*) value
;
842 json_dumper_begin_object(&dumper
);
843 sharkd_json_value_string("name", sequence_analysis_get_ui_name(analysis
));
844 sharkd_json_value_stringf("tap", "seqa:%s", (const char *) key
);
845 json_dumper_end_object(&dumper
);
851 sharkd_export_object_visit_cb(const void *key _U_
, void *value
, void *user_data _U_
)
853 register_eo_t
*eo
= (register_eo_t
*) value
;
855 const int proto_id
= get_eo_proto_id(eo
);
856 const char *filter
= proto_get_protocol_filter_name(proto_id
);
857 const char *label
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
859 json_dumper_begin_object(&dumper
);
860 sharkd_json_value_stringf("name", "Export Object/%s", label
);
861 sharkd_json_value_stringf("tap", "eo:%s", filter
);
862 json_dumper_end_object(&dumper
);
868 sharkd_srt_visit_cb(const void *key _U_
, void *value
, void *user_data _U_
)
870 register_srt_t
*srt
= (register_srt_t
*) value
;
872 const int proto_id
= get_srt_proto_id(srt
);
873 const char *filter
= proto_get_protocol_filter_name(proto_id
);
874 const char *label
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
876 json_dumper_begin_object(&dumper
);
877 sharkd_json_value_stringf("name", "Service Response Time/%s", label
);
878 sharkd_json_value_stringf("tap", "srt:%s", filter
);
879 json_dumper_end_object(&dumper
);
885 sharkd_rtd_visit_cb(const void *key _U_
, void *value
, void *user_data _U_
)
887 register_rtd_t
*rtd
= (register_rtd_t
*) value
;
889 const int proto_id
= get_rtd_proto_id(rtd
);
890 const char *filter
= proto_get_protocol_filter_name(proto_id
);
891 const char *label
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
893 json_dumper_begin_object(&dumper
);
894 sharkd_json_value_stringf("name", "Response Time Delay/%s", label
);
895 sharkd_json_value_stringf("tap", "rtd:%s", filter
);
896 json_dumper_end_object(&dumper
);
902 sharkd_follower_visit_cb(const void *key _U_
, void *value
, void *user_data _U_
)
904 register_follow_t
*follower
= (register_follow_t
*) value
;
906 const int proto_id
= get_follow_proto_id(follower
);
907 const char *label
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
908 const char *filter
= label
; /* correct: get_follow_by_name() is registered by short name */
910 json_dumper_begin_object(&dumper
);
911 sharkd_json_value_stringf("name", "Follow/%s", label
);
912 sharkd_json_value_stringf("tap", "follow:%s", filter
);
913 json_dumper_end_object(&dumper
);
919 sharkd_session_print_capture_types(void)
922 GArray
*writable_type_subtypes
;
923 writable_type_subtypes
= wtap_get_writable_file_types_subtypes(FT_SORT_BY_NAME
);
924 for (i
= 0; i
< writable_type_subtypes
->len
; i
++) {
925 int ft
= g_array_index(writable_type_subtypes
, int, i
);
926 sharkd_json_object_open(NULL
);
927 sharkd_json_value_string("name", wtap_file_type_subtype_name(ft
));
928 sharkd_json_value_string("description", wtap_file_type_subtype_description(ft
));
929 sharkd_json_object_close();
931 g_array_free(writable_type_subtypes
, TRUE
);
934 struct encap_type_info
937 const char *description
;
941 encap_type_info_nat_compare(gconstpointer a
, gconstpointer b
)
943 return ws_ascii_strnatcmp(((const struct encap_type_info
*)a
)->name
,
944 ((const struct encap_type_info
*)b
)->name
);
948 encap_type_info_visit(gpointer data
, gpointer user_data _U_
)
950 sharkd_json_object_open(NULL
);
951 sharkd_json_value_string("name", ((struct encap_type_info
*)data
)->name
);
952 sharkd_json_value_string("description", ((struct encap_type_info
*)data
)->description
);
953 sharkd_json_object_close();
957 sharkd_session_print_encap_types(void)
960 struct encap_type_info
*encaps
;
962 encaps
= g_new(struct encap_type_info
, WTAP_NUM_ENCAP_TYPES
);
963 for (i
= 0; i
< WTAP_NUM_ENCAP_TYPES
; i
++) {
964 encaps
[i
].name
= wtap_encap_name(i
);
965 if (encaps
[i
].name
!= NULL
) {
966 encaps
[i
].description
= wtap_encap_description(i
);
967 list
= g_slist_insert_sorted(list
, &encaps
[i
], encap_type_info_nat_compare
);
970 g_slist_foreach(list
, encap_type_info_visit
, NULL
);
976 * sharkd_session_process_info()
978 * Process info request
980 * Output object with attributes:
981 * (m) version - version number
983 * (m) columns - available column formats, array of object with attributes:
984 * 'name' - column name
985 * 'format' - column format-name
987 * (m) stats - available statistics, array of object with attributes:
988 * 'name' - statistic name
989 * 'tap' - sharkd tap-name for statistic
991 * (m) convs - available conversation list, array of object with attributes:
992 * 'name' - conversation name
993 * 'tap' - sharkd tap-name for conversation
995 * (m) eo - available export object list, array of object with attributes:
996 * 'name' - export object name
997 * 'tap' - sharkd tap-name for eo
999 * (m) srt - available service response time list, array of object with attributes:
1000 * 'name' - service response time name
1001 * 'tap' - sharkd tap-name for srt
1003 * (m) rtd - available response time delay list, array of object with attributes:
1004 * 'name' - response time delay name
1005 * 'tap' - sharkd tap-name for rtd
1007 * (m) seqa - available sequence analysis (flow) list, array of object with attributes:
1008 * 'name' - sequence analysis name
1009 * 'tap' - sharkd tap-name
1011 * (m) taps - available taps, array of object with attributes:
1013 * 'tap' - sharkd tap-name
1015 * (m) follow - available followers, array of object with attributes:
1017 * 'tap' - sharkd tap-name
1019 * (m) ftypes - conversation table for FT_ number to string, array of FT_xxx strings.
1021 * (m) nstat - available table-based taps, array of object with attributes:
1023 * 'tap' - sharkd tap-name
1025 * (m) capture_types - available capture types, array of object with attributes:
1026 * 'name' - capture type name
1027 * 'description' - capture type description
1029 * (m) encap_types - available encapsulation types, array of object with attributes:
1030 * 'name' - encapsulation type name
1031 * 'description' - encapsulation type description
1034 sharkd_session_process_info(void)
1038 sharkd_json_result_prologue(rpcid
);
1040 sharkd_json_array_open("columns");
1041 for (i
= 0; i
< NUM_COL_FMTS
; i
++)
1043 const char *col_format
= col_format_to_string(i
);
1044 const char *col_descr
= col_format_desc(i
);
1046 json_dumper_begin_object(&dumper
);
1047 sharkd_json_value_string("name", col_descr
);
1048 sharkd_json_value_string("format", col_format
);
1049 json_dumper_end_object(&dumper
);
1051 sharkd_json_array_close();
1053 sharkd_json_array_open("stats");
1055 GList
*cfg_list
= stats_tree_get_cfg_list();
1058 for (l
= cfg_list
; l
; l
= l
->next
)
1060 stats_tree_cfg
*cfg
= (stats_tree_cfg
*) l
->data
;
1062 json_dumper_begin_object(&dumper
);
1063 sharkd_json_value_string("name", cfg
->title
);
1064 sharkd_json_value_stringf("tap", "stat:%s", cfg
->abbr
);
1065 json_dumper_end_object(&dumper
);
1068 g_list_free(cfg_list
);
1070 sharkd_json_array_close();
1072 sharkd_json_array_open("ftypes");
1073 for (i
= 0; i
< FT_NUM_TYPES
; i
++)
1074 sharkd_json_value_string(NULL
, ftype_name((ftenum_t
) i
));
1075 sharkd_json_array_close();
1077 sharkd_json_array_open("capture_types");
1078 sharkd_session_print_capture_types();
1079 sharkd_json_array_close();
1081 sharkd_json_array_open("encap_types");
1082 sharkd_session_print_encap_types();
1083 sharkd_json_array_close();
1085 sharkd_json_value_string("version", get_ws_vcs_version_info_short());
1087 sharkd_json_array_open("nstat");
1089 stat_tap_iterate_tables(sharkd_session_process_info_nstat_cb
, &i
);
1090 sharkd_json_array_close();
1092 sharkd_json_array_open("convs");
1094 conversation_table_iterate_tables(sharkd_session_process_info_conv_cb
, &i
);
1095 sharkd_json_array_close();
1097 sharkd_json_array_open("seqa");
1099 sequence_analysis_table_iterate_tables(sharkd_session_seq_analysis_cb
, &i
);
1100 sharkd_json_array_close();
1102 sharkd_json_array_open("taps");
1104 json_dumper_begin_object(&dumper
);
1105 sharkd_json_value_string("name", "UDP Multicast Streams");
1106 sharkd_json_value_string("tap", "multicast");
1107 json_dumper_end_object(&dumper
);
1109 json_dumper_begin_object(&dumper
);
1110 sharkd_json_value_string("name", "RTP streams");
1111 sharkd_json_value_string("tap", "rtp-streams");
1112 json_dumper_end_object(&dumper
);
1114 json_dumper_begin_object(&dumper
);
1115 sharkd_json_value_string("name", "Protocol Hierarchy Statistics");
1116 sharkd_json_value_string("tap", "phs");
1117 json_dumper_end_object(&dumper
);
1119 json_dumper_begin_object(&dumper
);
1120 sharkd_json_value_string("name", "VoIP Calls");
1121 sharkd_json_value_string("tap", "voip-calls");
1122 json_dumper_end_object(&dumper
);
1124 json_dumper_begin_object(&dumper
);
1125 sharkd_json_value_string("name", "VoIP Conversations");
1126 sharkd_json_value_string("tap", "voip-convs");
1127 json_dumper_end_object(&dumper
);
1129 json_dumper_begin_object(&dumper
);
1130 sharkd_json_value_string("name", "Expert Information");
1131 sharkd_json_value_string("tap", "expert");
1132 json_dumper_end_object(&dumper
);
1134 sharkd_json_array_close();
1136 sharkd_json_array_open("eo");
1138 eo_iterate_tables(sharkd_export_object_visit_cb
, &i
);
1139 sharkd_json_array_close();
1141 sharkd_json_array_open("srt");
1143 srt_table_iterate_tables(sharkd_srt_visit_cb
, &i
);
1144 sharkd_json_array_close();
1146 sharkd_json_array_open("rtd");
1148 rtd_table_iterate_tables(sharkd_rtd_visit_cb
, &i
);
1149 sharkd_json_array_close();
1151 sharkd_json_array_open("follow");
1153 follow_iterate_followers(sharkd_follower_visit_cb
, &i
);
1154 sharkd_json_array_close();
1156 sharkd_json_result_epilogue();
1160 * sharkd_session_process_load()
1162 * Process load request
1165 * (m) file - file to be loaded
1167 * Output object with attributes:
1168 * (m) err - error code
1171 sharkd_session_process_load(const char *buf
, const jsmntok_t
*tokens
, int count
)
1173 const char *tok_file
= json_find_attr(buf
, tokens
, count
, "file");
1179 fprintf(stderr
, "load: filename=%s\n", tok_file
);
1181 if (sharkd_cf_open(tok_file
, WTAP_TYPE_AUTO
, FALSE
, &err
) != CF_OK
)
1185 "Unable to open the file"
1192 err
= sharkd_load_cap_file();
1194 CATCH(OutOfMemoryError
)
1197 rpcid
, -32603, NULL
,
1198 "Load failed, out of memory"
1200 fprintf(stderr
, "load: OutOfMemoryError\n");
1207 sharkd_json_simple_ok(rpcid
);
1211 sharkd_json_result_prologue(rpcid
);
1212 sharkd_json_value_string("status", wtap_strerror(err
));
1213 sharkd_json_value_anyf("err", "%d", err
);
1214 sharkd_json_result_epilogue();
1220 * sharkd_session_process_status()
1222 * Process status request
1224 * Output object with attributes:
1225 * (m) frames - count of currently loaded frames
1226 * (m) duration - time difference between time of first frame, and last loaded frame
1227 * (o) filename - capture filename
1228 * (o) filesize - capture filesize
1229 * (o) columns - array of column titles
1230 * (o) column_info - array of column infos, array of object with attributes:
1231 * 'title' - column title
1232 * 'format' - column format (%x or %Cus:<expr>:<occurrence> if COL_CUSTOM)
1233 * 'visible' - true if column is visible
1234 * 'resolved' - true if column is resolved
1237 sharkd_session_process_status(void)
1239 sharkd_json_result_prologue(rpcid
);
1241 sharkd_json_value_anyf("frames", "%u", cfile
.count
);
1242 sharkd_json_value_anyf("duration", "%.9f", nstime_to_sec(&cfile
.elapsed_time
));
1246 char *name
= g_path_get_basename(cfile
.filename
);
1248 sharkd_json_value_string("filename", name
);
1252 if (cfile
.provider
.wth
)
1254 gint64 file_size
= wtap_file_size(cfile
.provider
.wth
, NULL
);
1257 sharkd_json_value_anyf("filesize", "%" PRId64
, file_size
);
1260 if (cfile
.cinfo
.num_cols
> 0)
1262 sharkd_json_array_open("columns");
1263 for (int i
= 0; i
< cfile
.cinfo
.num_cols
; ++i
)
1265 sharkd_json_value_string(NULL
, get_column_title(i
));
1267 sharkd_json_array_close();
1269 sharkd_json_array_open("column_info");
1270 for (int i
= 0; i
< cfile
.cinfo
.num_cols
; ++i
)
1272 int fmt
= get_column_format(i
);
1273 sharkd_json_object_open(NULL
);
1274 sharkd_json_value_string("title", get_column_title(i
));
1275 if (fmt
!= COL_CUSTOM
)
1277 sharkd_json_value_string("format", col_format_to_string(fmt
));
1279 sharkd_json_value_stringf("format", "%s:%s:%d", col_format_to_string(fmt
), get_column_custom_fields(i
), get_column_custom_occurrence(i
));
1281 sharkd_json_value_anyf("visible", get_column_visible(i
) ? "true" : "false");
1282 sharkd_json_value_anyf("resolved", get_column_resolved(i
) ? "true" : "false");
1283 sharkd_json_object_close();
1285 sharkd_json_array_close();
1288 sharkd_json_result_epilogue();
1291 struct sharkd_analyse_data
1293 GHashTable
*protocols_set
;
1294 nstime_t
*first_time
;
1295 nstime_t
*last_time
;
1299 sharkd_session_process_analyse_cb(epan_dissect_t
*edt
, proto_tree
*tree _U_
,
1300 struct epan_column_info
*cinfo _U_
, const GSList
*data_src _U_
, void *data
)
1302 struct sharkd_analyse_data
*analyser
= (struct sharkd_analyse_data
*) data
;
1303 packet_info
*pi
= &edt
->pi
;
1304 frame_data
*fdata
= pi
->fd
;
1306 if (analyser
->first_time
== NULL
|| nstime_cmp(&fdata
->abs_ts
, analyser
->first_time
) < 0)
1307 analyser
->first_time
= &fdata
->abs_ts
;
1309 if (analyser
->last_time
== NULL
|| nstime_cmp(&fdata
->abs_ts
, analyser
->last_time
) > 0)
1310 analyser
->last_time
= &fdata
->abs_ts
;
1314 wmem_list_frame_t
*frame
;
1316 for (frame
= wmem_list_head(pi
->layers
); frame
; frame
= wmem_list_frame_next(frame
))
1318 int proto_id
= GPOINTER_TO_UINT(wmem_list_frame_data(frame
));
1320 if (!g_hash_table_lookup_extended(analyser
->protocols_set
, GUINT_TO_POINTER(proto_id
), NULL
, NULL
))
1322 g_hash_table_insert(analyser
->protocols_set
, GUINT_TO_POINTER(proto_id
), GUINT_TO_POINTER(proto_id
));
1323 sharkd_json_value_string(NULL
, proto_get_protocol_filter_name(proto_id
));
1331 * sharkd_session_process_status()
1333 * Process analyse request
1335 * Output object with attributes:
1336 * (m) frames - count of currently loaded frames
1337 * (m) protocols - protocol list
1338 * (m) first - earliest frame time
1339 * (m) last - latest frame time
1342 sharkd_session_process_analyse(void)
1344 struct sharkd_analyse_data analyser
;
1345 wtap_rec rec
; /* Record metadata */
1346 Buffer rec_buf
; /* Record data */
1348 analyser
.first_time
= NULL
;
1349 analyser
.last_time
= NULL
;
1350 analyser
.protocols_set
= g_hash_table_new(NULL
/* g_direct_hash() */, NULL
/* g_direct_equal */);
1352 sharkd_json_result_prologue(rpcid
);
1354 sharkd_json_value_anyf("frames", "%u", cfile
.count
);
1356 sharkd_json_array_open("protocols");
1358 wtap_rec_init(&rec
);
1359 ws_buffer_init(&rec_buf
, 1514);
1361 for (guint32 framenum
= 1; framenum
<= cfile
.count
; framenum
++)
1363 enum dissect_request_status status
;
1367 status
= sharkd_dissect_request(framenum
,
1368 (framenum
!= 1) ? 1 : 0, framenum
- 1,
1369 &rec
, &rec_buf
, NULL
, SHARKD_DISSECT_FLAG_NULL
,
1370 &sharkd_session_process_analyse_cb
, &analyser
,
1374 case DISSECT_REQUEST_SUCCESS
:
1377 case DISSECT_REQUEST_NO_SUCH_FRAME
:
1378 /* XXX - report the error. */
1381 case DISSECT_REQUEST_READ_ERROR
:
1383 * Free up the error string.
1384 * XXX - report the error.
1391 sharkd_json_array_close();
1393 if (analyser
.first_time
)
1394 sharkd_json_value_anyf("first", "%.9f", nstime_to_sec(analyser
.first_time
));
1396 if (analyser
.last_time
)
1397 sharkd_json_value_anyf("last", "%.9f", nstime_to_sec(analyser
.last_time
));
1399 sharkd_json_result_epilogue();
1401 wtap_rec_cleanup(&rec
);
1402 ws_buffer_free(&rec_buf
);
1404 g_hash_table_destroy(analyser
.protocols_set
);
1407 static column_info
*
1408 sharkd_session_create_columns(column_info
*cinfo
, const char *buf
, const jsmntok_t
*tokens
, int count
)
1410 const char *columns_custom
[32];
1411 guint16 columns_fmt
[32];
1412 gint16 columns_occur
[32];
1416 for (i
= 0; i
< 32; i
++)
1418 const char *tok_column
;
1419 char tok_column_name
[64];
1422 snprintf(tok_column_name
, sizeof(tok_column_name
), "column%d", i
);
1423 tok_column
= json_find_attr(buf
, tokens
, count
, tok_column_name
);
1424 if (tok_column
== NULL
)
1427 columns_custom
[i
] = NULL
;
1428 columns_occur
[i
] = 0;
1430 if ((custom_sepa
= strchr(tok_column
, ':')))
1432 *custom_sepa
= '\0'; /* XXX, C abuse: discarding-const */
1434 columns_fmt
[i
] = COL_CUSTOM
;
1435 columns_custom
[i
] = tok_column
;
1437 if (!ws_strtoi16(custom_sepa
+ 1, NULL
, &columns_occur
[i
]))
1442 if (!ws_strtou16(tok_column
, NULL
, &columns_fmt
[i
]))
1445 if (columns_fmt
[i
] >= NUM_COL_FMTS
)
1448 /* if custom, that it shouldn't be just custom number -> error */
1449 if (columns_fmt
[i
] == COL_CUSTOM
)
1456 col_setup(cinfo
, cols
);
1458 for (i
= 0; i
< cols
; i
++)
1460 col_item_t
*col_item
= &cinfo
->columns
[i
];
1462 col_item
->col_fmt
= columns_fmt
[i
];
1463 col_item
->col_title
= NULL
; /* no need for title */
1465 if (col_item
->col_fmt
== COL_CUSTOM
)
1467 col_item
->col_custom_fields
= g_strdup(columns_custom
[i
]);
1468 col_item
->col_custom_occurrence
= columns_occur
[i
];
1471 col_item
->col_fence
= 0;
1474 col_finalize(cinfo
);
1480 sharkd_session_process_frames_cb(epan_dissect_t
*edt
, proto_tree
*tree _U_
,
1481 struct epan_column_info
*cinfo
, const GSList
*data_src _U_
, void *data _U_
)
1483 packet_info
*pi
= &edt
->pi
;
1484 frame_data
*fdata
= pi
->fd
;
1485 wtap_block_t pkt_block
= NULL
;
1487 char *comment
= NULL
;
1489 json_dumper_begin_object(&dumper
);
1491 sharkd_json_array_open("c");
1492 for (int col
= 0; col
< cinfo
->num_cols
; ++col
)
1494 sharkd_json_value_string(NULL
, get_column_text(cinfo
, col
));
1496 sharkd_json_array_close();
1498 sharkd_json_value_anyf("num", "%u", pi
->num
);
1501 * Get the block for this record, if it has one.
1503 pkt_block
= sharkd_get_packet_block(fdata
);
1506 * Does this record have any comments?
1508 if (pkt_block
!= NULL
&&
1509 WTAP_OPTTYPE_SUCCESS
== wtap_block_get_nth_string_option_value(pkt_block
, OPT_COMMENT
, 0, &comment
))
1511 sharkd_json_value_anyf("ct", "true");
1513 sharkd_json_array_open("comments");
1514 for (i
= 0; wtap_block_get_nth_string_option_value(pkt_block
, OPT_COMMENT
, i
, &comment
) == WTAP_OPTTYPE_SUCCESS
; i
++) {
1515 sharkd_json_value_string(NULL
, comment
);
1517 sharkd_json_array_close();
1521 sharkd_json_value_anyf("i", "true");
1524 sharkd_json_value_anyf("m", "true");
1526 if (fdata
->color_filter
)
1528 sharkd_json_value_stringf("bg", "%06x", color_t_to_rgb(&fdata
->color_filter
->bg_color
));
1529 sharkd_json_value_stringf("fg", "%06x", color_t_to_rgb(&fdata
->color_filter
->fg_color
));
1532 wtap_block_unref(pkt_block
);
1533 json_dumper_end_object(&dumper
);
1537 * sharkd_session_process_frames()
1539 * Process frames request
1542 * (o) column0...columnXX - requested columns either number in range [0..NUM_COL_FMTS), or custom (syntax <dfilter>:<occurrence>).
1543 * If column0 is not specified default column set will be used.
1544 * (o) filter - filter to be used
1545 * (o) skip=N - skip N frames
1546 * (o) limit=N - show only N frames
1547 * (o) refs - list (comma separated) with sorted time reference frame numbers.
1549 * Output array of frames with attributes:
1550 * (m) c - array of column data
1551 * (m) num - frame number
1552 * (o) i - if frame is ignored
1553 * (o) m - if frame is marked
1554 * (o) ct - if frame is commented
1555 * (o) comments - array of comment strings
1556 * (o) bg - color filter - background color in hex
1557 * (o) fg - color filter - foreground color in hex
1560 sharkd_session_process_frames(const char *buf
, const jsmntok_t
*tokens
, int count
)
1562 const char *tok_filter
= json_find_attr(buf
, tokens
, count
, "filter");
1563 const char *tok_column
= json_find_attr(buf
, tokens
, count
, "column0");
1564 const char *tok_skip
= json_find_attr(buf
, tokens
, count
, "skip");
1565 const char *tok_limit
= json_find_attr(buf
, tokens
, count
, "limit");
1566 const char *tok_refs
= json_find_attr(buf
, tokens
, count
, "refs");
1568 const guint8
*filter_data
= NULL
;
1570 guint32 prev_dis_num
= 0;
1571 guint32 current_ref_frame
= 0, next_ref_frame
= G_MAXUINT32
;
1575 wtap_rec rec
; /* Record metadata */
1576 Buffer rec_buf
; /* Record data */
1577 column_info
*cinfo
= &cfile
.cinfo
;
1578 column_info user_cinfo
;
1582 memset(&user_cinfo
, 0, sizeof(user_cinfo
));
1583 cinfo
= sharkd_session_create_columns(&user_cinfo
, buf
, tokens
, count
);
1587 rpcid
, -13001, NULL
,
1588 "Column definition invalid - note column 6 requires a custom definition"
1596 const struct sharkd_filter_item
*filter_item
;
1598 filter_item
= sharkd_session_filter_data(tok_filter
);
1602 rpcid
, -13002, NULL
,
1603 "Filter expression invalid"
1608 filter_data
= filter_item
->filtered
;
1614 if (!ws_strtou32(tok_skip
, NULL
, &skip
))
1621 if (!ws_strtou32(tok_limit
, NULL
, &limit
))
1627 if (!ws_strtou32(tok_refs
, &tok_refs
, &next_ref_frame
))
1631 sharkd_json_result_array_prologue(rpcid
);
1633 wtap_rec_init(&rec
);
1634 ws_buffer_init(&rec_buf
, 1514);
1636 for (guint32 framenum
= 1; framenum
<= cfile
.count
; framenum
++)
1639 guint32 ref_frame
= (framenum
!= 1) ? 1 : 0;
1640 enum dissect_request_status status
;
1644 if (filter_data
&& !(filter_data
[framenum
/ 8] & (1 << (framenum
% 8))))
1650 prev_dis_num
= framenum
;
1656 if (framenum
>= next_ref_frame
)
1658 current_ref_frame
= next_ref_frame
;
1660 if (*tok_refs
!= ',')
1661 next_ref_frame
= G_MAXUINT32
;
1663 while (*tok_refs
== ',' && framenum
>= next_ref_frame
)
1665 current_ref_frame
= next_ref_frame
;
1667 if (!ws_strtou32(tok_refs
+ 1, &tok_refs
, &next_ref_frame
))
1669 fprintf(stderr
, "sharkd_session_process_frames() wrong format for refs: %s\n", tok_refs
);
1674 if (*tok_refs
== '\0' && framenum
>= next_ref_frame
)
1676 current_ref_frame
= next_ref_frame
;
1677 next_ref_frame
= G_MAXUINT32
;
1681 if (current_ref_frame
)
1682 ref_frame
= current_ref_frame
;
1685 fdata
= sharkd_get_frame(framenum
);
1686 status
= sharkd_dissect_request(framenum
,
1687 ref_frame
, prev_dis_num
,
1688 &rec
, &rec_buf
, cinfo
,
1689 (fdata
->color_filter
== NULL
) ? SHARKD_DISSECT_FLAG_COLOR
: SHARKD_DISSECT_FLAG_NULL
,
1690 &sharkd_session_process_frames_cb
, NULL
,
1694 case DISSECT_REQUEST_SUCCESS
:
1697 case DISSECT_REQUEST_NO_SUCH_FRAME
:
1698 /* XXX - report the error. */
1701 case DISSECT_REQUEST_READ_ERROR
:
1703 * Free up the error string.
1704 * XXX - report the error.
1710 prev_dis_num
= framenum
;
1712 if (limit
&& --limit
== 0)
1715 sharkd_json_result_array_epilogue();
1717 if (cinfo
!= &cfile
.cinfo
)
1720 wtap_rec_cleanup(&rec
);
1721 ws_buffer_free(&rec_buf
);
1725 sharkd_session_process_tap_stats_node_cb(const char *key
, const stat_node
*n
)
1729 sharkd_json_array_open(key
);
1730 for (node
= n
->children
; node
; node
= node
->next
)
1732 json_dumper_begin_object(&dumper
);
1734 /* code based on stats_tree_get_values_from_node() */
1735 sharkd_json_value_string("name", node
->name
);
1736 sharkd_json_value_anyf("count", "%d", node
->counter
);
1737 if (node
->counter
&& ((node
->st_flags
& ST_FLG_AVERAGE
) || node
->rng
))
1739 switch(node
->datatype
)
1742 sharkd_json_value_anyf("avg", "%.2f", ((float)node
->total
.int_total
) / node
->counter
);
1743 sharkd_json_value_anyf("min", "%d", node
->minvalue
.int_min
);
1744 sharkd_json_value_anyf("max", "%d", node
->maxvalue
.int_max
);
1747 sharkd_json_value_anyf("avg", "%.2f", node
->total
.float_total
/ node
->counter
);
1748 sharkd_json_value_anyf("min", "%f", node
->minvalue
.float_min
);
1749 sharkd_json_value_anyf("max", "%f", node
->maxvalue
.float_max
);
1754 if (node
->st
->elapsed
)
1755 sharkd_json_value_anyf("rate", "%.4f", ((float)node
->counter
) / node
->st
->elapsed
);
1757 if (node
->parent
&& node
->parent
->counter
)
1758 sharkd_json_value_anyf("perc", "%.2f", (node
->counter
* 100.0) / node
->parent
->counter
);
1759 else if (node
->parent
== &(node
->st
->root
))
1760 sharkd_json_value_anyf("perc", "100");
1762 if (prefs
.st_enable_burstinfo
&& node
->max_burst
)
1764 if (prefs
.st_burst_showcount
)
1765 sharkd_json_value_anyf("burstcount", "%d", node
->max_burst
);
1767 sharkd_json_value_anyf("burstrate", "%.4f", ((double)node
->max_burst
) / prefs
.st_burst_windowlen
);
1769 sharkd_json_value_anyf("bursttime", "%.3f", (node
->burst_time
/ 1000.0));
1774 sharkd_session_process_tap_stats_node_cb("sub", node
);
1776 json_dumper_end_object(&dumper
);
1778 sharkd_json_array_close();
1782 * sharkd_session_process_tap_stats_cb()
1786 * (m) tap - tap name
1787 * (m) type:stats - tap output type
1788 * (m) name - stat name
1789 * (m) stats - array of object with attributes:
1790 * (m) name - stat item name
1791 * (m) count - stat item counter
1792 * (o) avg - stat item averange value
1793 * (o) min - stat item min value
1794 * (o) max - stat item max value
1795 * (o) rate - stat item rate value (ms)
1796 * (o) perc - stat item percentage
1797 * (o) burstrate - stat item burst rate
1798 * (o) burstcount - stat item burst count
1799 * (o) burstttme - stat item burst start
1800 * (o) sub - array of object with attributes like in stats node.
1803 sharkd_session_process_tap_stats_cb(void *psp
)
1805 stats_tree
*st
= (stats_tree
*) psp
;
1807 json_dumper_begin_object(&dumper
);
1809 sharkd_json_value_stringf("tap", "stats:%s", st
->cfg
->abbr
);
1810 sharkd_json_value_string("type", "stats");
1811 sharkd_json_value_string("name", st
->cfg
->path
);
1813 sharkd_session_process_tap_stats_node_cb("stats", &st
->root
);
1815 json_dumper_end_object(&dumper
);
1819 sharkd_session_free_tap_stats_cb(void *psp
)
1821 stats_tree
*st
= (stats_tree
*) psp
;
1823 stats_tree_free(st
);
1826 struct sharkd_expert_tap
1833 * sharkd_session_process_tap_expert_cb()
1835 * Output expert tap:
1837 * (m) tap - tap name
1838 * (m) type:expert - tap output type
1839 * (m) details - array of object with attributes:
1840 * (m) f - frame number, which generated expert information
1843 * (m) m - expert message
1847 sharkd_session_process_tap_expert_cb(void *tapdata
)
1849 struct sharkd_expert_tap
*etd
= (struct sharkd_expert_tap
*) tapdata
;
1852 json_dumper_begin_object(&dumper
);
1854 sharkd_json_value_string("tap", "expert");
1855 sharkd_json_value_string("type", "expert");
1857 sharkd_json_array_open("details");
1858 for (list
= etd
->details
; list
; list
= list
->next
)
1860 expert_info_t
*ei
= (expert_info_t
*) list
->data
;
1863 json_dumper_begin_object(&dumper
);
1865 sharkd_json_value_anyf("f", "%u", ei
->packet_num
);
1867 tmp
= try_val_to_str(ei
->severity
, expert_severity_vals
);
1869 sharkd_json_value_string("s", tmp
);
1871 tmp
= try_val_to_str(ei
->group
, expert_group_vals
);
1873 sharkd_json_value_string("g", tmp
);
1875 sharkd_json_value_string("m", ei
->summary
);
1878 sharkd_json_value_string("p", ei
->protocol
);
1880 json_dumper_end_object(&dumper
);
1882 sharkd_json_array_close();
1884 json_dumper_end_object(&dumper
);
1887 static tap_packet_status
1888 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_
)
1890 struct sharkd_expert_tap
*etd
= (struct sharkd_expert_tap
*) tapdata
;
1891 const expert_info_t
*ei
= (const expert_info_t
*) pointer
;
1892 expert_info_t
*ei_copy
;
1895 return TAP_PACKET_DONT_REDRAW
;
1897 ei_copy
= g_new(expert_info_t
, 1);
1898 /* Note: this is a shallow copy */
1901 /* ei->protocol, ei->summary might be allocated in packet scope, make a copy. */
1902 ei_copy
->protocol
= g_string_chunk_insert_const(etd
->text
, ei_copy
->protocol
);
1903 ei_copy
->summary
= g_string_chunk_insert_const(etd
->text
, ei_copy
->summary
);
1905 etd
->details
= g_slist_prepend(etd
->details
, ei_copy
);
1907 return TAP_PACKET_REDRAW
;
1911 sharkd_session_free_tap_expert_cb(void *tapdata
)
1913 struct sharkd_expert_tap
*etd
= (struct sharkd_expert_tap
*) tapdata
;
1915 g_slist_free_full(etd
->details
, g_free
);
1916 g_string_chunk_free(etd
->text
);
1921 * sharkd_session_process_tap_flow_cb()
1924 * (m) tap - tap name
1925 * (m) type:flow - tap output type
1926 * (m) nodes - array of strings with node address
1927 * (m) flows - array of object with attributes:
1928 * (m) t - frame time string
1929 * (m) n - array of two numbers with source node index and destination node index
1930 * (m) pn - array of two numbers with source and destination port
1934 sharkd_session_process_tap_flow_cb(void *tapdata
)
1936 seq_analysis_info_t
*graph_analysis
= (seq_analysis_info_t
*) tapdata
;
1940 sequence_analysis_get_nodes(graph_analysis
);
1942 json_dumper_begin_object(&dumper
);
1943 sharkd_json_value_stringf("tap", "seqa:%s", graph_analysis
->name
);
1944 sharkd_json_value_string("type", "flow");
1946 sharkd_json_array_open("nodes");
1947 for (i
= 0; i
< graph_analysis
->num_nodes
; i
++)
1951 addr_str
= address_to_display(NULL
, &(graph_analysis
->nodes
[i
]));
1952 sharkd_json_value_string(NULL
, addr_str
);
1953 wmem_free(NULL
, addr_str
);
1955 sharkd_json_array_close();
1957 sharkd_json_array_open("flows");
1958 flow_list
= g_queue_peek_nth_link(graph_analysis
->items
, 0);
1961 seq_analysis_item_t
*sai
= (seq_analysis_item_t
*) flow_list
->data
;
1963 flow_list
= g_list_next(flow_list
);
1968 json_dumper_begin_object(&dumper
);
1970 sharkd_json_value_string("t", sai
->time_str
);
1971 sharkd_json_value_anyf("n", "[%u,%u]", sai
->src_node
, sai
->dst_node
);
1972 sharkd_json_value_anyf("pn", "[%u,%u]", sai
->port_src
, sai
->port_dst
);
1975 sharkd_json_value_string("c", sai
->comment
);
1977 json_dumper_end_object(&dumper
);
1979 sharkd_json_array_close();
1981 json_dumper_end_object(&dumper
);
1985 sharkd_session_free_tap_flow_cb(void *tapdata
)
1987 seq_analysis_info_t
*graph_analysis
= (seq_analysis_info_t
*) tapdata
;
1989 sequence_analysis_info_free(graph_analysis
);
1992 struct sharkd_conv_tap_data
1996 gboolean resolve_name
;
1997 gboolean resolve_port
;
2001 sharkd_session_geoip_addr(address
*addr
, const char *suffix
)
2003 const mmdb_lookup_t
*lookup
= NULL
;
2004 gboolean with_geoip
= FALSE
;
2007 if (addr
->type
== AT_IPv4
)
2009 const ws_in4_addr
*ip4
= (const ws_in4_addr
*) addr
->data
;
2011 lookup
= maxmind_db_lookup_ipv4(ip4
);
2013 else if (addr
->type
== AT_IPv6
)
2015 const ws_in6_addr
*ip6
= (const ws_in6_addr
*) addr
->data
;
2017 lookup
= maxmind_db_lookup_ipv6(ip6
);
2020 if (!lookup
|| !lookup
->found
)
2023 if (lookup
->country
)
2025 snprintf(json_key
, sizeof(json_key
), "geoip_country%s", suffix
);
2026 sharkd_json_value_string(json_key
, lookup
->country
);
2030 if (lookup
->country_iso
)
2032 snprintf(json_key
, sizeof(json_key
), "geoip_country_iso%s", suffix
);
2033 sharkd_json_value_string(json_key
, lookup
->country_iso
);
2039 snprintf(json_key
, sizeof(json_key
), "geoip_city%s", suffix
);
2040 sharkd_json_value_string(json_key
, lookup
->city
);
2046 snprintf(json_key
, sizeof(json_key
), "geoip_as_org%s", suffix
);
2047 sharkd_json_value_string(json_key
, lookup
->as_org
);
2051 if (lookup
->as_number
> 0)
2053 snprintf(json_key
, sizeof(json_key
), "geoip_as%s", suffix
);
2054 sharkd_json_value_anyf(json_key
, "%u", lookup
->as_number
);
2058 if (lookup
->latitude
>= -90.0 && lookup
->latitude
<= 90.0)
2060 snprintf(json_key
, sizeof(json_key
), "geoip_lat%s", suffix
);
2061 sharkd_json_value_anyf(json_key
, "%f", lookup
->latitude
);
2065 if (lookup
->longitude
>= -180.0 && lookup
->longitude
<= 180.0)
2067 snprintf(json_key
, sizeof(json_key
), "geoip_lon%s", suffix
);
2068 sharkd_json_value_anyf(json_key
, "%f", lookup
->longitude
);
2075 struct sharkd_analyse_rtp_items
2078 guint32 sequence_num
;
2086 double arrive_offset
;
2088 /* from tap_rtp_stat_t */
2093 struct sharkd_analyse_rtp
2095 const char *tap_name
;
2100 tap_rtp_stat_t statinfo
;
2104 sharkd_session_process_tap_rtp_free_cb(void *tapdata
)
2106 struct sharkd_analyse_rtp
*rtp_req
= (struct sharkd_analyse_rtp
*) tapdata
;
2108 g_slist_free_full(rtp_req
->packets
, g_free
);
2112 static tap_packet_status
2113 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_
)
2115 struct sharkd_analyse_rtp
*rtp_req
= (struct sharkd_analyse_rtp
*) tapdata
;
2116 const struct _rtp_info
*rtp_info
= (const struct _rtp_info
*) pointer
;
2118 if (rtpstream_id_equal_pinfo_rtp_info(&rtp_req
->id
, pinfo
, rtp_info
))
2120 tap_rtp_stat_t
*statinfo
= &(rtp_req
->statinfo
);
2121 struct sharkd_analyse_rtp_items
*item
;
2123 rtppacket_analyse(statinfo
, pinfo
, rtp_info
);
2125 item
= g_new(struct sharkd_analyse_rtp_items
, 1);
2127 if (!rtp_req
->packets
)
2128 rtp_req
->start_time
= nstime_to_sec(&pinfo
->abs_ts
);
2130 item
->frame_num
= pinfo
->num
;
2131 item
->sequence_num
= rtp_info
->info_seq_num
;
2132 item
->delta
= (statinfo
->flags
& STAT_FLAG_FIRST
) ? 0.0 : statinfo
->delta
;
2133 item
->jitter
= (statinfo
->flags
& STAT_FLAG_FIRST
) ? 0.0 : statinfo
->jitter
;
2134 item
->skew
= (statinfo
->flags
& STAT_FLAG_FIRST
) ? 0.0 : statinfo
->skew
;
2135 item
->bandwidth
= statinfo
->bandwidth
;
2136 item
->marker
= rtp_info
->info_marker_set
? TRUE
: FALSE
;
2137 item
->arrive_offset
= nstime_to_sec(&pinfo
->abs_ts
) - rtp_req
->start_time
;
2139 item
->flags
= statinfo
->flags
;
2140 item
->pt
= statinfo
->pt
;
2142 /* XXX, O(n) optimize */
2143 rtp_req
->packets
= g_slist_append(rtp_req
->packets
, item
);
2146 return TAP_PACKET_REDRAW
;
2150 * sharkd_session_process_tap_rtp_analyse_cb()
2152 * Output rtp analyse tap:
2153 * (m) tap - tap name
2154 * (m) type - tap output type
2155 * (m) ssrc - RTP SSRC
2156 * (m) max_delta - Max delta (ms)
2157 * (m) max_delta_nr - Max delta packet #
2158 * (m) max_jitter - Max jitter (ms)
2159 * (m) mean_jitter - Mean jitter (ms)
2160 * (m) max_skew - Max skew (ms)
2161 * (m) total_nr - Total number of RTP packets
2162 * (m) seq_err - Number of sequence errors
2163 * (m) duration - Duration (ms)
2164 * (m) items - array of object with attributes:
2165 * (m) f - frame number
2166 * (m) o - arrive offset
2167 * (m) sn - sequence number
2171 * (m) bw - bandwidth
2172 * (o) s - status string
2173 * (o) t - status type
2174 * (o) mark - rtp mark
2177 sharkd_session_process_tap_rtp_analyse_cb(void *tapdata
)
2179 const int RTP_TYPE_CN
= 1;
2180 const int RTP_TYPE_ERROR
= 2;
2181 const int RTP_TYPE_WARN
= 3;
2182 const int RTP_TYPE_PT_EVENT
= 4;
2184 const struct sharkd_analyse_rtp
*rtp_req
= (struct sharkd_analyse_rtp
*) tapdata
;
2185 const tap_rtp_stat_t
*statinfo
= &rtp_req
->statinfo
;
2189 json_dumper_begin_object(&dumper
);
2191 sharkd_json_value_string("tap", rtp_req
->tap_name
);
2192 sharkd_json_value_string("type", "rtp-analyse");
2193 sharkd_json_value_stringf("ssrc", "0x%x", rtp_req
->id
.ssrc
);
2195 sharkd_json_value_anyf("max_delta", "%f", statinfo
->max_delta
);
2196 sharkd_json_value_anyf("max_delta_nr", "%u", statinfo
->max_nr
);
2197 sharkd_json_value_anyf("max_jitter", "%f", statinfo
->max_jitter
);
2198 sharkd_json_value_anyf("mean_jitter", "%f", statinfo
->mean_jitter
);
2199 sharkd_json_value_anyf("max_skew", "%f", statinfo
->max_skew
);
2200 sharkd_json_value_anyf("total_nr", "%u", statinfo
->total_nr
);
2201 sharkd_json_value_anyf("seq_err", "%u", statinfo
->sequence
);
2202 sharkd_json_value_anyf("duration", "%f", statinfo
->time
- statinfo
->start_time
);
2204 sharkd_json_array_open("items");
2205 for (l
= rtp_req
->packets
; l
; l
= l
->next
)
2207 struct sharkd_analyse_rtp_items
*item
= (struct sharkd_analyse_rtp_items
*) l
->data
;
2209 json_dumper_begin_object(&dumper
);
2211 sharkd_json_value_anyf("f", "%u", item
->frame_num
);
2212 sharkd_json_value_anyf("o", "%.9f", item
->arrive_offset
);
2213 sharkd_json_value_anyf("sn", "%u", item
->sequence_num
);
2214 sharkd_json_value_anyf("d", "%.2f", item
->delta
);
2215 sharkd_json_value_anyf("j", "%.2f", item
->jitter
);
2216 sharkd_json_value_anyf("sk", "%.2f", item
->skew
);
2217 sharkd_json_value_anyf("bw", "%.2f", item
->bandwidth
);
2219 if (item
->pt
== PT_CN
)
2221 sharkd_json_value_string("s", "Comfort noise (PT=13, RFC 3389)");
2222 sharkd_json_value_anyf("t", "%d", RTP_TYPE_CN
);
2224 else if (item
->pt
== PT_CN_OLD
)
2226 sharkd_json_value_string("s", "Comfort noise (PT=19, reserved)");
2227 sharkd_json_value_anyf("t", "%d", RTP_TYPE_CN
);
2229 else if (item
->flags
& STAT_FLAG_WRONG_SEQ
)
2231 sharkd_json_value_string("s", "Wrong sequence number");
2232 sharkd_json_value_anyf("t", "%d", RTP_TYPE_ERROR
);
2234 else if (item
->flags
& STAT_FLAG_DUP_PKT
)
2236 sharkd_json_value_string("s", "Suspected duplicate (MAC address) only delta time calculated");
2237 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2239 else if (item
->flags
& STAT_FLAG_REG_PT_CHANGE
)
2241 sharkd_json_value_stringf("s", "Payload changed to PT=%u%s",
2243 (item
->flags
& STAT_FLAG_PT_T_EVENT
) ? " telephone/event" : "");
2244 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2246 else if (item
->flags
& STAT_FLAG_WRONG_TIMESTAMP
)
2248 sharkd_json_value_string("s", "Incorrect timestamp");
2249 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2251 else if ((item
->flags
& STAT_FLAG_PT_CHANGE
)
2252 && !(item
->flags
& STAT_FLAG_FIRST
)
2253 && !(item
->flags
& STAT_FLAG_PT_CN
)
2254 && (item
->flags
& STAT_FLAG_FOLLOW_PT_CN
)
2255 && !(item
->flags
& STAT_FLAG_MARKER
))
2257 sharkd_json_value_string("s", "Marker missing?");
2258 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2260 else if (item
->flags
& STAT_FLAG_PT_T_EVENT
)
2262 sharkd_json_value_stringf("s", "PT=%u telephone/event", item
->pt
);
2263 sharkd_json_value_anyf("t", "%d", RTP_TYPE_PT_EVENT
);
2265 else if (item
->flags
& STAT_FLAG_MARKER
)
2267 sharkd_json_value_anyf("t", "%d", RTP_TYPE_WARN
);
2271 sharkd_json_value_anyf("mark", "1");
2273 json_dumper_end_object(&dumper
);
2275 sharkd_json_array_close();
2277 json_dumper_end_object(&dumper
);
2281 * sharkd_session_process_tap_conv_cb()
2284 * (m) tap - tap name
2285 * (m) type - tap output type
2286 * (m) proto - protocol short name
2287 * (o) filter - filter string
2288 * (o) geoip - whether GeoIP information is available, boolean
2290 * (o) convs - array of object with attributes:
2291 * (m) saddr - source address
2292 * (m) daddr - destination address
2293 * (o) sport - source port
2294 * (o) dport - destination port
2295 * (m) txf - TX frame count
2296 * (m) txb - TX bytes
2297 * (m) rxf - RX frame count
2298 * (m) rxb - RX bytes
2299 * (m) start - (relative) first packet time
2300 * (m) stop - (relative) last packet time
2301 * (o) filter - conversation filter
2303 * (o) hosts - array of object with attributes:
2304 * (m) host - host address
2305 * (o) port - host port
2306 * (m) txf - TX frame count
2307 * (m) txb - TX bytes
2308 * (m) rxf - RX frame count
2309 * (m) rxb - RX bytes
2312 sharkd_session_process_tap_conv_cb(void *arg
)
2314 conv_hash_t
*hash
= (conv_hash_t
*) arg
;
2315 const struct sharkd_conv_tap_data
*iu
= (struct sharkd_conv_tap_data
*) hash
->user_data
;
2317 int proto_with_port
;
2322 json_dumper_begin_object(&dumper
);
2323 sharkd_json_value_string("tap", iu
->type
);
2325 if (!strncmp(iu
->type
, "conv:", 5))
2327 sharkd_json_value_string("type", "conv");
2328 sharkd_json_array_open("convs");
2329 proto
= iu
->type
+ 5;
2331 else if (!strncmp(iu
->type
, "endpt:", 6))
2333 sharkd_json_value_string("type", "host");
2334 sharkd_json_array_open("hosts");
2335 proto
= iu
->type
+ 6;
2339 sharkd_json_value_string("type", "err");
2343 proto_with_port
= (!strcmp(proto
, "TCP") || !strcmp(proto
, "UDP") || !strcmp(proto
, "SCTP"));
2345 if (iu
->hash
.conv_array
!= NULL
&& !strncmp(iu
->type
, "conv:", 5))
2347 for (i
= 0; i
< iu
->hash
.conv_array
->len
; i
++)
2349 conv_item_t
*iui
= &g_array_index(iu
->hash
.conv_array
, conv_item_t
, i
);
2350 char *src_addr
, *dst_addr
;
2351 char *src_port
, *dst_port
;
2354 json_dumper_begin_object(&dumper
);
2356 sharkd_json_value_string("saddr", (src_addr
= get_conversation_address(NULL
, &iui
->src_address
, iu
->resolve_name
)));
2357 sharkd_json_value_string("daddr", (dst_addr
= get_conversation_address(NULL
, &iui
->dst_address
, iu
->resolve_name
)));
2359 if (proto_with_port
)
2361 sharkd_json_value_string("sport", (src_port
= get_conversation_port(NULL
, iui
->src_port
, iui
->ctype
, iu
->resolve_port
)));
2362 sharkd_json_value_string("dport", (dst_port
= get_conversation_port(NULL
, iui
->dst_port
, iui
->ctype
, iu
->resolve_port
)));
2364 wmem_free(NULL
, src_port
);
2365 wmem_free(NULL
, dst_port
);
2368 sharkd_json_value_anyf("rxf", "%" PRIu64
, iui
->rx_frames
);
2369 sharkd_json_value_anyf("rxb", "%" PRIu64
, iui
->rx_bytes
);
2371 sharkd_json_value_anyf("txf", "%" PRIu64
, iui
->tx_frames
);
2372 sharkd_json_value_anyf("txb", "%" PRIu64
, iui
->tx_bytes
);
2374 sharkd_json_value_anyf("start", "%.9f", nstime_to_sec(&iui
->start_time
));
2375 sharkd_json_value_anyf("stop", "%.9f", nstime_to_sec(&iui
->stop_time
));
2377 filter_str
= get_conversation_filter(iui
, CONV_DIR_A_TO_FROM_B
);
2380 sharkd_json_value_string("filter", filter_str
);
2384 wmem_free(NULL
, src_addr
);
2385 wmem_free(NULL
, dst_addr
);
2387 if (sharkd_session_geoip_addr(&(iui
->src_address
), "1"))
2389 if (sharkd_session_geoip_addr(&(iui
->dst_address
), "2"))
2392 json_dumper_end_object(&dumper
);
2395 else if (iu
->hash
.conv_array
!= NULL
&& !strncmp(iu
->type
, "endpt:", 6))
2397 for (i
= 0; i
< iu
->hash
.conv_array
->len
; i
++)
2399 endpoint_item_t
*endpoint
= &g_array_index(iu
->hash
.conv_array
, endpoint_item_t
, i
);
2400 char *host_str
, *port_str
;
2403 json_dumper_begin_object(&dumper
);
2405 sharkd_json_value_string("host", (host_str
= get_conversation_address(NULL
, &endpoint
->myaddress
, iu
->resolve_name
)));
2407 if (proto_with_port
)
2409 sharkd_json_value_string("port", (port_str
= get_endpoint_port(NULL
, endpoint
, iu
->resolve_port
)));
2411 wmem_free(NULL
, port_str
);
2414 sharkd_json_value_anyf("rxf", "%" PRIu64
, endpoint
->rx_frames
);
2415 sharkd_json_value_anyf("rxb", "%" PRIu64
, endpoint
->rx_bytes
);
2417 sharkd_json_value_anyf("txf", "%" PRIu64
, endpoint
->tx_frames
);
2418 sharkd_json_value_anyf("txb", "%" PRIu64
, endpoint
->tx_bytes
);
2420 filter_str
= get_endpoint_filter(endpoint
);
2423 sharkd_json_value_string("filter", filter_str
);
2427 wmem_free(NULL
, host_str
);
2429 if (sharkd_session_geoip_addr(&(endpoint
->myaddress
), ""))
2431 json_dumper_end_object(&dumper
);
2434 sharkd_json_array_close();
2436 sharkd_json_value_string("proto", proto
);
2437 sharkd_json_value_anyf("geoip", with_geoip
? "true" : "false");
2439 json_dumper_end_object(&dumper
);
2443 sharkd_session_free_tap_conv_cb(void *arg
)
2445 conv_hash_t
*hash
= (conv_hash_t
*) arg
;
2446 struct sharkd_conv_tap_data
*iu
= (struct sharkd_conv_tap_data
*) hash
->user_data
;
2448 if (!strncmp(iu
->type
, "conv:", 5))
2450 reset_conversation_table_data(hash
);
2452 else if (!strncmp(iu
->type
, "endpt:", 6))
2454 reset_endpoint_table_data(hash
);
2461 * sharkd_session_process_tap_nstat_cb()
2464 * (m) tap - tap name
2465 * (m) type - tap output type
2466 * (m) fields: array of objects with attributes:
2469 * (m) tables: array of object with attributes:
2470 * (m) t - table title
2471 * (m) i - array of items
2474 sharkd_session_process_tap_nstat_cb(void *arg
)
2476 stat_data_t
*stat_data
= (stat_data_t
*) arg
;
2479 json_dumper_begin_object(&dumper
);
2480 sharkd_json_value_stringf("tap", "nstat:%s", stat_data
->stat_tap_data
->cli_string
);
2481 sharkd_json_value_string("type", "nstat");
2483 sharkd_json_array_open("fields");
2484 for (i
= 0; i
< stat_data
->stat_tap_data
->nfields
; i
++)
2486 stat_tap_table_item
*field
= &(stat_data
->stat_tap_data
->fields
[i
]);
2488 json_dumper_begin_object(&dumper
);
2489 sharkd_json_value_string("c", field
->column_name
);
2490 json_dumper_end_object(&dumper
);
2492 sharkd_json_array_close();
2494 sharkd_json_array_open("tables");
2495 for (i
= 0; i
< stat_data
->stat_tap_data
->tables
->len
; i
++)
2497 stat_tap_table
*table
= g_array_index(stat_data
->stat_tap_data
->tables
, stat_tap_table
*, i
);
2499 json_dumper_begin_object(&dumper
);
2501 sharkd_json_value_string("t", table
->title
);
2503 sharkd_json_array_open("i");
2504 for (j
= 0; j
< table
->num_elements
; j
++)
2506 stat_tap_table_item_type
*field_data
;
2508 field_data
= stat_tap_get_field_data(table
, j
, 0);
2509 if (field_data
== NULL
|| field_data
->type
== TABLE_ITEM_NONE
) /* Nothing for us here */
2512 sharkd_json_array_open(NULL
);
2513 for (k
= 0; k
< table
->num_fields
; k
++)
2515 field_data
= stat_tap_get_field_data(table
, j
, k
);
2517 switch (field_data
->type
)
2519 case TABLE_ITEM_UINT
:
2520 sharkd_json_value_anyf(NULL
, "%u", field_data
->value
.uint_value
);
2523 case TABLE_ITEM_INT
:
2524 sharkd_json_value_anyf(NULL
, "%d", field_data
->value
.int_value
);
2527 case TABLE_ITEM_STRING
:
2528 sharkd_json_value_string(NULL
, field_data
->value
.string_value
);
2531 case TABLE_ITEM_FLOAT
:
2532 sharkd_json_value_anyf(NULL
, "%f", field_data
->value
.float_value
);
2535 case TABLE_ITEM_ENUM
:
2536 sharkd_json_value_anyf(NULL
, "%d", field_data
->value
.enum_value
);
2539 case TABLE_ITEM_NONE
:
2540 sharkd_json_value_anyf(NULL
, "null");
2545 sharkd_json_array_close();
2547 sharkd_json_array_close();
2548 json_dumper_end_object(&dumper
);
2550 sharkd_json_array_close();
2552 json_dumper_end_object(&dumper
);
2556 sharkd_session_free_tap_nstat_cb(void *arg
)
2558 stat_data_t
*stat_data
= (stat_data_t
*) arg
;
2560 free_stat_tables(stat_data
->stat_tap_data
);
2564 * sharkd_session_process_tap_rtd_cb()
2567 * (m) tap - tap name
2568 * (m) type - tap output type
2569 * (m) stats - statistics rows - array object with attributes:
2570 * (m) type - statistic name
2571 * (m) num - number of messages
2572 * (m) min - minimum SRT time
2573 * (m) max - maximum SRT time
2574 * (m) tot - total SRT time
2575 * (m) min_frame - minimal SRT
2576 * (m) max_frame - maximum SRT
2577 * (o) open_req - Open Requests
2578 * (o) disc_rsp - Discarded Responses
2579 * (o) req_dup - Duplicated Requests
2580 * (o) rsp_dup - Duplicated Responses
2581 * (o) open_req - Open Requests
2582 * (o) disc_rsp - Discarded Responses
2583 * (o) req_dup - Duplicated Requests
2584 * (o) rsp_dup - Duplicated Responses
2587 sharkd_session_process_tap_rtd_cb(void *arg
)
2589 rtd_data_t
*rtd_data
= (rtd_data_t
*) arg
;
2590 register_rtd_t
*rtd
= (register_rtd_t
*) rtd_data
->user_data
;
2594 const char *filter
= proto_get_protocol_filter_name(get_rtd_proto_id(rtd
));
2596 /* XXX, some dissectors are having single table and multiple timestats (mgcp, megaco),
2597 * some multiple table and single timestat (radius, h225)
2598 * and it seems that value_string is used one for timestamp-ID, other one for table-ID
2599 * I wonder how it will gonna work with multiple timestats and multiple tables...
2600 * (for usage grep for: register_rtd_table)
2602 const value_string
*vs
= get_rtd_value_string(rtd
);
2604 json_dumper_begin_object(&dumper
);
2605 sharkd_json_value_stringf("tap", "rtd:%s", filter
);
2606 sharkd_json_value_string("type", "rtd");
2608 if (rtd_data
->stat_table
.num_rtds
== 1)
2610 const rtd_timestat
*ms
= &rtd_data
->stat_table
.time_stats
[0];
2612 sharkd_json_value_anyf("open_req", "%u", ms
->open_req_num
);
2613 sharkd_json_value_anyf("disc_rsp", "%u", ms
->disc_rsp_num
);
2614 sharkd_json_value_anyf("req_dup", "%u", ms
->req_dup_num
);
2615 sharkd_json_value_anyf("rsp_dup", "%u", ms
->rsp_dup_num
);
2618 sharkd_json_array_open("stats");
2619 for (i
= 0; i
< rtd_data
->stat_table
.num_rtds
; i
++)
2621 const rtd_timestat
*ms
= &rtd_data
->stat_table
.time_stats
[i
];
2623 for (j
= 0; j
< ms
->num_timestat
; j
++)
2625 const char *type_str
;
2627 if (ms
->rtd
[j
].num
== 0)
2630 json_dumper_begin_object(&dumper
);
2632 if (rtd_data
->stat_table
.num_rtds
== 1)
2633 type_str
= val_to_str_const(j
, vs
, "Other"); /* 1 table - description per row */
2635 type_str
= val_to_str_const(i
, vs
, "Other"); /* multiple table - description per table */
2636 sharkd_json_value_string("type", type_str
);
2638 sharkd_json_value_anyf("num", "%u", ms
->rtd
[j
].num
);
2639 sharkd_json_value_anyf("min", "%.9f", nstime_to_sec(&(ms
->rtd
[j
].min
)));
2640 sharkd_json_value_anyf("max", "%.9f", nstime_to_sec(&(ms
->rtd
[j
].max
)));
2641 sharkd_json_value_anyf("tot", "%.9f", nstime_to_sec(&(ms
->rtd
[j
].tot
)));
2642 sharkd_json_value_anyf("min_frame", "%u", ms
->rtd
[j
].min_num
);
2643 sharkd_json_value_anyf("max_frame", "%u", ms
->rtd
[j
].max_num
);
2645 if (rtd_data
->stat_table
.num_rtds
!= 1)
2647 /* like in tshark, display it on every row */
2648 sharkd_json_value_anyf("open_req", "%u", ms
->open_req_num
);
2649 sharkd_json_value_anyf("disc_rsp", "%u", ms
->disc_rsp_num
);
2650 sharkd_json_value_anyf("req_dup", "%u", ms
->req_dup_num
);
2651 sharkd_json_value_anyf("rsp_dup", "%u", ms
->rsp_dup_num
);
2654 json_dumper_end_object(&dumper
);
2657 sharkd_json_array_close();
2659 json_dumper_end_object(&dumper
);
2663 sharkd_session_free_tap_rtd_cb(void *arg
)
2665 rtd_data_t
*rtd_data
= (rtd_data_t
*) arg
;
2667 free_rtd_table(&rtd_data
->stat_table
);
2672 * sharkd_session_process_tap_srt_cb()
2675 * (m) tap - tap name
2676 * (m) type - tap output type
2678 * (m) tables - array of object with attributes:
2679 * (m) n - table name
2680 * (m) f - table filter
2681 * (o) c - table column name
2682 * (m) r - table rows - array object with attributes:
2684 * (m) idx - procedure index
2685 * (m) num - number of events
2686 * (m) min - minimum SRT time
2687 * (m) max - maximum SRT time
2688 * (m) tot - total SRT time
2691 sharkd_session_process_tap_srt_cb(void *arg
)
2693 srt_data_t
*srt_data
= (srt_data_t
*) arg
;
2694 register_srt_t
*srt
= (register_srt_t
*) srt_data
->user_data
;
2696 const char *filter
= proto_get_protocol_filter_name(get_srt_proto_id(srt
));
2700 json_dumper_begin_object(&dumper
);
2701 sharkd_json_value_stringf("tap", "srt:%s", filter
);
2702 sharkd_json_value_string("type", "srt");
2704 sharkd_json_array_open("tables");
2705 for (i
= 0; i
< srt_data
->srt_array
->len
; i
++)
2708 srt_stat_table
*rst
= g_array_index(srt_data
->srt_array
, srt_stat_table
*, i
);
2712 json_dumper_begin_object(&dumper
);
2715 sharkd_json_value_string("n", rst
->name
);
2716 else if (rst
->short_name
)
2717 sharkd_json_value_string("n", rst
->short_name
);
2719 sharkd_json_value_stringf("n", "table%u", i
);
2721 if (rst
->filter_string
)
2722 sharkd_json_value_string("f", rst
->filter_string
);
2724 if (rst
->proc_column_name
)
2725 sharkd_json_value_string("c", rst
->proc_column_name
);
2727 sharkd_json_array_open("r");
2728 for (j
= 0; j
< rst
->num_procs
; j
++)
2731 srt_procedure_t
*proc
= &rst
->procedures
[j
];
2733 if (proc
->stats
.num
== 0)
2736 json_dumper_begin_object(&dumper
);
2738 sharkd_json_value_string("n", proc
->procedure
);
2740 if (rst
->filter_string
)
2741 sharkd_json_value_anyf("idx", "%d", proc
->proc_index
);
2743 sharkd_json_value_anyf("num", "%u", proc
->stats
.num
);
2745 sharkd_json_value_anyf("min", "%.9f", nstime_to_sec(&proc
->stats
.min
));
2746 sharkd_json_value_anyf("max", "%.9f", nstime_to_sec(&proc
->stats
.max
));
2747 sharkd_json_value_anyf("tot", "%.9f", nstime_to_sec(&proc
->stats
.tot
));
2749 json_dumper_end_object(&dumper
);
2751 sharkd_json_array_close();
2753 json_dumper_end_object(&dumper
);
2755 sharkd_json_array_close();
2757 json_dumper_end_object(&dumper
);
2761 sharkd_session_free_tap_srt_cb(void *arg
)
2763 srt_data_t
*srt_data
= (srt_data_t
*) arg
;
2764 register_srt_t
*srt
= (register_srt_t
*) srt_data
->user_data
;
2766 free_srt_table(srt
, srt_data
->srt_array
);
2767 g_array_free(srt_data
->srt_array
, TRUE
);
2772 sharkd_session_process_tap_phs_cb_aux(phs_t
*rs
)
2774 for (; rs
; rs
= rs
->sibling
) {
2775 if (rs
->protocol
== -1) {
2778 sharkd_json_object_open(NULL
);
2779 sharkd_json_value_string("proto", rs
->proto_name
);
2780 sharkd_json_value_anyf("frames", "%"PRIu32
, rs
->frames
);
2781 sharkd_json_value_anyf("bytes", "%"PRIu64
, rs
->bytes
);
2782 if (rs
->child
!= NULL
&& rs
->child
->protocol
!= -1) {
2783 sharkd_json_array_open("protos");
2784 sharkd_session_process_tap_phs_cb_aux(rs
->child
);
2785 sharkd_json_array_close();
2787 sharkd_json_object_close();
2792 * sharkd_session_process_tap_phs_cb()
2795 * (m) tap - tap name
2796 * (m) type - tap output type
2797 * (m) filter - tap filter argument
2798 * (m) protos - array of proto objects
2801 * (m) proto - protocol name
2802 * (m) frames - frame count
2803 * (m) bytes - bytes count
2804 * (o) protos - array of proto objects
2807 sharkd_session_process_tap_phs_cb(void *arg
)
2809 phs_t
*rs
= (phs_t
*)arg
;
2810 sharkd_json_object_open(NULL
);
2811 sharkd_json_value_string("tap", "phs");
2812 sharkd_json_value_string("type", "phs");
2813 sharkd_json_value_string("filter", rs
->filter
? rs
->filter
: "");
2814 sharkd_json_array_open("protos");
2815 sharkd_session_process_tap_phs_cb_aux(rs
);
2816 sharkd_json_array_close();
2817 sharkd_json_object_close();
2821 sharkd_session_free_tap_phs_cb(void *arg
)
2823 phs_t
*rs
= (phs_t
*)arg
;
2827 struct sharkd_export_object_list
2829 struct sharkd_export_object_list
*next
;
2836 static struct sharkd_export_object_list
*sharkd_eo_list
;
2839 * sharkd_session_process_tap_eo_cb()
2842 * (m) tap - tap name
2843 * (m) type - tap output type
2844 * (m) proto - protocol short name
2845 * (m) objects - array of object with attributes:
2846 * (m) pkt - packet number
2847 * (o) hostname - hostname
2848 * (o) type - content type
2849 * (o) filename - filename
2850 * (m) len - object length
2851 * (m) sha1 - object's sha1 sum
2854 sharkd_session_process_tap_eo_cb(void *tapdata
)
2856 export_object_list_t
*tap_object
= (export_object_list_t
*) tapdata
;
2857 struct sharkd_export_object_list
*object_list
= (struct sharkd_export_object_list
*) tap_object
->gui_data
;
2860 char sha1sum_bytes
[HASH_SHA1_LENGTH
], *sha1sum_str
;
2862 json_dumper_begin_object(&dumper
);
2863 sharkd_json_value_string("tap", object_list
->type
);
2864 sharkd_json_value_string("type", "eo");
2866 sharkd_json_value_string("proto", object_list
->proto
);
2868 sharkd_json_array_open("objects");
2869 for (slist
= object_list
->entries
; slist
; slist
= slist
->next
)
2871 const export_object_entry_t
*eo_entry
= (export_object_entry_t
*) slist
->data
;
2873 json_dumper_begin_object(&dumper
);
2875 sharkd_json_value_anyf("pkt", "%u", eo_entry
->pkt_num
);
2877 if (eo_entry
->hostname
)
2878 sharkd_json_value_string("hostname", eo_entry
->hostname
);
2880 if (eo_entry
->content_type
)
2881 sharkd_json_value_string("type", eo_entry
->content_type
);
2883 if (eo_entry
->filename
)
2884 sharkd_json_value_string("filename", eo_entry
->filename
);
2886 sharkd_json_value_stringf("_download", "%s_%d", object_list
->type
, i
);
2888 sharkd_json_value_anyf("len", "%zu", eo_entry
->payload_len
);
2890 gcry_md_hash_buffer(GCRY_MD_SHA1
, sha1sum_bytes
, eo_entry
->payload_data
, eo_entry
->payload_len
);
2891 sha1sum_str
= bytes_to_str(NULL
, sha1sum_bytes
, HASH_SHA1_LENGTH
);
2892 sharkd_json_value_string("sha1", sha1sum_str
);
2893 g_free(sha1sum_str
);
2895 json_dumper_end_object(&dumper
);
2899 sharkd_json_array_close();
2901 json_dumper_end_object(&dumper
);
2905 sharkd_eo_object_list_add_entry(void *gui_data
, export_object_entry_t
*entry
)
2907 struct sharkd_export_object_list
*object_list
= (struct sharkd_export_object_list
*) gui_data
;
2909 object_list
->entries
= g_slist_append(object_list
->entries
, entry
);
2912 static export_object_entry_t
*
2913 sharkd_eo_object_list_get_entry(void *gui_data
, int row
)
2915 struct sharkd_export_object_list
*object_list
= (struct sharkd_export_object_list
*) gui_data
;
2917 return (export_object_entry_t
*) g_slist_nth_data(object_list
->entries
, row
);
2920 static struct sharkd_export_object_list
*
2921 sharkd_eo_object_list_get_entry_by_type(void *gui_data
, const char *tap_type
)
2923 struct sharkd_export_object_list
*object_list
= (struct sharkd_export_object_list
*) gui_data
;
2924 for (; object_list
; object_list
= object_list
->next
)
2926 if (!strcmp(object_list
->type
, tap_type
))
2934 * sharkd_session_process_tap_rtp_cb()
2936 * Output RTP streams tap:
2937 * (m) tap - tap name
2938 * (m) type - tap output type
2939 * (m) streams - array of object with attributes:
2940 * (m) ssrc - RTP synchronization source identifier
2941 * (m) payload - stream payload
2942 * (m) saddr - source address
2943 * (m) sport - source port
2944 * (m) daddr - destination address
2945 * (m) dport - destination port
2946 * (m) pkts - packets count
2947 * (m) max_delta - max delta (ms)
2948 * (m) max_jitter - max jitter (ms)
2949 * (m) mean_jitter - mean jitter (ms)
2952 * (m) problem - if analyser found the problem
2953 * (m) ipver - address IP version (4 or 6)
2956 sharkd_session_process_tap_rtp_cb(void *arg
)
2958 rtpstream_tapinfo_t
*rtp_tapinfo
= (rtpstream_tapinfo_t
*) arg
;
2962 json_dumper_begin_object(&dumper
);
2963 sharkd_json_value_string("tap", "rtp-streams");
2964 sharkd_json_value_string("type", "rtp-streams");
2966 sharkd_json_array_open("streams");
2967 for (listx
= g_list_first(rtp_tapinfo
->strinfo_list
); listx
; listx
= listx
->next
)
2969 rtpstream_info_t
*streaminfo
= (rtpstream_info_t
*) listx
->data
;
2970 rtpstream_info_calc_t calc
;
2972 rtpstream_info_calculate(streaminfo
, &calc
);
2974 json_dumper_begin_object(&dumper
);
2976 sharkd_json_value_stringf("ssrc", "0x%x", calc
.ssrc
);
2977 sharkd_json_value_string("payload", calc
.all_payload_type_names
);
2979 sharkd_json_value_string("saddr", calc
.src_addr_str
);
2980 sharkd_json_value_anyf("sport", "%u", calc
.src_port
);
2981 sharkd_json_value_string("daddr", calc
.dst_addr_str
);
2982 sharkd_json_value_anyf("dport", "%u", calc
.dst_port
);
2984 sharkd_json_value_anyf("start_time", "%f", calc
.start_time_ms
);
2985 sharkd_json_value_anyf("duration", "%f", calc
.duration_ms
);
2987 sharkd_json_value_anyf("pkts", "%u", calc
.packet_count
);
2988 sharkd_json_value_anyf("lost", "%u", calc
.lost_num
);
2989 sharkd_json_value_anyf("lost_percent", "%f", calc
.lost_perc
);
2991 sharkd_json_value_anyf("max_delta", "%f",calc
.max_delta
);
2992 sharkd_json_value_anyf("min_delta", "%f",calc
.min_delta
);
2993 sharkd_json_value_anyf("mean_delta", "%f",calc
.mean_delta
);
2994 sharkd_json_value_anyf("min_jitter", "%f", calc
.min_jitter
);
2995 sharkd_json_value_anyf("max_jitter", "%f", calc
.max_jitter
);
2996 sharkd_json_value_anyf("mean_jitter", "%f", calc
.mean_jitter
);
2998 sharkd_json_value_anyf("expectednr", "%u", calc
.packet_expected
);
2999 sharkd_json_value_anyf("totalnr", "%u", calc
.total_nr
);
3001 sharkd_json_value_anyf("problem", calc
.problem
? "true" : "false");
3004 sharkd_json_value_anyf("ipver", "%d", (streaminfo
->id
.src_addr
.type
== AT_IPv6
) ? 6 : 4);
3006 rtpstream_info_calc_free(&calc
);
3008 json_dumper_end_object(&dumper
);
3010 sharkd_json_array_close();
3012 json_dumper_end_object(&dumper
);
3016 * sharkd_session_process_tap_multicast_cb()
3018 * Output UDP Multicast streams tap:
3019 * (m) tap - tap name
3020 * (m) type - tap output type
3021 * (m) bufferThresholdBytes - byte count for a stream where a buffer alarm should be reported
3022 * (m) burstIntervalMs - analysis interval in milliseconds
3023 * (m) burstThresholdPackets - count of packets in an interval that should trigger an alarm
3024 * (m) streams - array of streams with metrics:
3025 * (m) saddr - source address
3026 * (m) sport - source port
3027 * (m) daddr - destination address
3028 * (m) dport - destination port
3029 * (m) packets - object group for packet metrics with attributes:
3030 * (m) number - count of packets in the stream
3031 * (m) perSecond - average number of packets per seconds in the stream
3032 * (m) bandwidth - object group for bandwidth metrics with attributes:
3033 * (m) average - average measured bitrate in the stream
3034 * (m) max - max measured bitrate in the stream
3035 * (m) buffer - object group for buffer metrics with attributes:
3036 * (m) alarms - number of times the stream exceeded the buffer threshold
3037 * (m) max - highest stream buffer utilization
3038 * (m) burst - object group for burst metrics with attributes:
3039 * (m) alarms - number of times the stream exceeded the burst threshold
3040 * (m) max - most stream packets measured in a burst interval
3043 sharkd_session_process_tap_multicast_cb(void *arg
)
3045 mcaststream_tapinfo_t
*tapinfo
= (mcaststream_tapinfo_t
*)arg
;
3049 json_dumper_begin_object(&dumper
);
3051 sharkd_json_value_string("tap", "multicast");
3052 sharkd_json_value_string("type", "multicast");
3054 sharkd_json_value_anyf("bufferThresholdBytes", "%u", mcast_stream_bufferalarm
);
3055 sharkd_json_value_anyf("burstIntervalMs", "%u", mcast_stream_burstint
);
3056 sharkd_json_value_anyf("burstThresholdPackets", "%u", mcast_stream_trigger
);
3058 sharkd_json_array_open("streams");
3059 for (list_item
= g_list_first(tapinfo
->strinfo_list
); list_item
; list_item
= list_item
->next
) {
3060 mcast_stream_info_t
*stream_info
= (mcast_stream_info_t
*) list_item
->data
;
3061 sharkd_json_object_open(NULL
);
3063 addr_str
= address_to_display(NULL
, &stream_info
->src_addr
);
3064 sharkd_json_value_string("saddr", addr_str
);
3065 wmem_free(NULL
, addr_str
);
3066 sharkd_json_value_anyf("sport", "%u", stream_info
->src_port
);
3067 addr_str
= address_to_display(NULL
, &stream_info
->dest_addr
);
3068 sharkd_json_value_string("daddr", addr_str
);
3069 wmem_free(NULL
, addr_str
);
3070 sharkd_json_value_anyf("dport", "%u", stream_info
->dest_port
);
3071 sharkd_json_object_open("packets");
3073 sharkd_json_value_anyf("number", "%u", stream_info
->npackets
);
3074 sharkd_json_value_anyf("perSecond", "%f", stream_info
->apackets
);
3076 sharkd_json_object_close();
3077 sharkd_json_object_open("bandwidth");
3079 sharkd_json_value_anyf("average", "%f", stream_info
->average_bw
);
3080 sharkd_json_value_anyf("max", "%f", stream_info
->element
.maxbw
);
3082 sharkd_json_object_close();
3083 sharkd_json_object_open("buffer");
3085 sharkd_json_value_anyf("alarms", "%u", stream_info
->element
.numbuffalarms
);
3086 sharkd_json_value_anyf("max", "%u", stream_info
->element
.topbuffusage
);
3088 sharkd_json_object_close();
3089 sharkd_json_object_open("burst");
3091 sharkd_json_value_anyf("alarms", "%u", stream_info
->element
.numbursts
);
3092 sharkd_json_value_anyf("max", "%u", stream_info
->element
.topburstsize
);
3094 sharkd_json_object_close();
3096 sharkd_json_object_close();
3098 sharkd_json_array_close();
3100 json_dumper_end_object(&dumper
);
3104 sharkd_session_process_free_tap_multicast_cb(void *tapdata
)
3106 mcaststream_tapinfo_t
*tapinfo
= (mcaststream_tapinfo_t
*)tapdata
;
3108 mcaststream_reset(tapinfo
);
3114 * sharkd_session_process_tap_voip_calls_cb()
3116 * Output VoIP Calls tap:
3117 * (m) tap - tap name
3118 * (m) type - tap output type
3119 * (m) calls - array of objects with attributes:
3120 * (m) call - call number
3121 * (m) start_time - start timestamp
3122 * (m) stop_time - stop timestamp
3123 * (m) initial_speaker - address of initial speaker
3124 * (m) from - from address
3125 * (m) to - to address
3126 * (m) protocol - protocol name
3127 * (m) packets - packet count
3128 * (m) state - state string
3129 * (m) comment - comment string
3132 sharkd_session_process_tap_voip_calls_cb(void *arg
)
3134 voip_calls_tapinfo_t
*tapinfo
= (voip_calls_tapinfo_t
*)arg
;
3136 GList
*cur_call
= g_queue_peek_nth_link(tapinfo
->callsinfos
, 0);
3137 sharkd_json_object_open(NULL
);
3138 sharkd_json_value_string("tap", "voip-calls");
3139 sharkd_json_value_string("type", "voip-calls");
3140 sharkd_json_array_open("calls");
3141 while (cur_call
&& cur_call
->data
) {
3142 voip_calls_info_t
*call_info_
= (voip_calls_info_t
*) cur_call
->data
;
3143 sharkd_json_object_open(NULL
);
3144 sharkd_json_value_anyf("call", "%hu", call_info_
->call_num
);
3145 sharkd_json_value_anyf("start_time", "%.6f", nstime_to_sec(&(call_info_
->start_rel_ts
)));
3146 sharkd_json_value_anyf("stop_time", "%.6f", nstime_to_sec(&(call_info_
->stop_rel_ts
)));
3147 addr_str
= address_to_display(NULL
, &(call_info_
->initial_speaker
));
3148 sharkd_json_value_string("initial_speaker", addr_str
);
3149 wmem_free(NULL
, addr_str
);
3150 sharkd_json_value_string("from", call_info_
->from_identity
);
3151 sharkd_json_value_string("to", call_info_
->to_identity
);
3152 sharkd_json_value_string("protocol", ((call_info_
->protocol
== VOIP_COMMON
) && call_info_
->protocol_name
) ?
3153 call_info_
->protocol_name
: voip_protocol_name
[call_info_
->protocol
]);
3154 sharkd_json_value_anyf("packets", "%u", call_info_
->npackets
);
3155 sharkd_json_value_string("state", voip_call_state_name
[call_info_
->call_state
]);
3156 sharkd_json_value_string("comment", call_info_
->call_comment
);
3157 sharkd_json_object_close();
3158 cur_call
= g_list_next(cur_call
);
3160 sharkd_json_array_close();
3161 sharkd_json_object_close();
3165 sharkd_session_free_tap_voip_calls_cb(void *tapdata
)
3167 voip_calls_tapinfo_t
*tapinfo
= (voip_calls_tapinfo_t
*)tapdata
;
3168 voip_calls_remove_all_tap_listeners(tapinfo
);
3169 if (tapinfo
->callsinfos
!= NULL
) {
3170 g_queue_free(tapinfo
->callsinfos
);
3172 if (tapinfo
->graph_analysis
!= NULL
) {
3173 sequence_analysis_info_free(tapinfo
->graph_analysis
);
3175 memset(tapinfo
, 0, sizeof(*tapinfo
));
3179 struct sharkd_voip_convs_req
{
3180 voip_calls_tapinfo_t
*tapinfo
;
3181 const char *tap_name
;
3185 * sharkd_session_process_tap_voip_convs_cb()
3187 * Output VoIP Conversations tap:
3188 * (m) tap - tap name
3189 * (m) type - tap output type
3190 * (m) convs - array of objects with attributes:
3191 * (m) frame - frame number
3192 * (m) call - call number
3193 * (m) time - timestamp
3194 * (m) dst_addr - destination address
3195 * (m) dst_port - destination port
3196 * (m) src_addr - source address
3197 * (m) src_port - source port
3198 * (m) label - label string
3199 * (m) comment - comment string
3202 sharkd_session_process_tap_voip_convs_cb(void *arg
)
3204 struct sharkd_voip_convs_req
*voip_convs_req
= (struct sharkd_voip_convs_req
*)arg
;
3205 voip_calls_tapinfo_t
*tapinfo
= voip_convs_req
->tapinfo
;
3206 seq_analysis_info_t
*sainfo
= tapinfo
->graph_analysis
;
3208 sequence_analysis_list_sort(sainfo
);
3209 sharkd_json_object_open(NULL
);
3210 sharkd_json_value_string("tap", voip_convs_req
->tap_name
);
3211 sharkd_json_value_string("type", "voip-convs");
3212 sharkd_json_array_open("convs");
3213 for (GList
*cur
= g_queue_peek_nth_link(sainfo
->items
, 0); cur
; cur
= g_list_next(cur
)) {
3214 seq_analysis_item_t
*sai
= (seq_analysis_item_t
*) cur
->data
;
3215 if ((voip_conv_sel
[sai
->conv_num
/ VOIP_CONV_BITS
] & (1 << (sai
->conv_num
% VOIP_CONV_BITS
))) == 0)
3217 sharkd_json_object_open(NULL
);
3218 sharkd_json_value_anyf("frame", "%d", sai
->frame_number
);
3219 sharkd_json_value_anyf("call", "%d", sai
->conv_num
);
3220 sharkd_json_value_string("time", sai
->time_str
);
3221 addr_str
= address_to_display(NULL
, &(sai
->dst_addr
));
3222 sharkd_json_value_string("dst_addr", addr_str
);
3223 wmem_free(NULL
, addr_str
);
3224 sharkd_json_value_anyf("dst_port", "%d", sai
->port_dst
);
3225 addr_str
= address_to_display(NULL
, &(sai
->src_addr
));
3226 sharkd_json_value_string("src_addr", addr_str
);
3227 wmem_free(NULL
, addr_str
);
3228 sharkd_json_value_anyf("src_port", "%d", sai
->port_src
);
3229 sharkd_json_value_string("label", sai
->frame_label
);
3230 sharkd_json_value_string("comment", sai
->comment
);
3231 sharkd_json_object_close();
3233 sharkd_json_array_close();
3234 sharkd_json_object_close();
3238 sharkd_session_free_tap_voip_convs_cb(void *tapdata
)
3240 struct sharkd_voip_convs_req
*voip_convs_req
= (struct sharkd_voip_convs_req
*)tapdata
;
3241 voip_calls_tapinfo_t
*tapinfo
= voip_convs_req
->tapinfo
;
3242 voip_calls_remove_all_tap_listeners(tapinfo
);
3243 if (tapinfo
->callsinfos
!= NULL
) {
3244 g_queue_free(tapinfo
->callsinfos
);
3246 if (tapinfo
->graph_analysis
!= NULL
) {
3247 sequence_analysis_info_free(tapinfo
->graph_analysis
);
3249 memset(tapinfo
, 0, sizeof(*tapinfo
));
3250 g_free(voip_convs_req
);
3253 struct sharkd_hosts_req
{
3254 const char *tap_name
;
3260 sharkd_session_tap_ipv4_host_compare(gconstpointer a
, gconstpointer b
)
3262 return ws_ascii_strnatcmp(((const hashipv4_t
*)a
)->name
,
3263 ((const hashipv4_t
*)b
)->name
);
3267 sharkd_session_tap_ipv6_host_compare(gconstpointer a
, gconstpointer b
)
3269 return ws_ascii_strnatcmp(((const hashipv6_t
*)a
)->name
,
3270 ((const hashipv6_t
*)b
)->name
);
3274 sharkd_session_tap_ipv4_host_print(gpointer data
, gpointer user_data _U_
)
3276 hashipv4_t
*ipv4_hash_table_entry
= (hashipv4_t
*)data
;
3277 sharkd_json_object_open(NULL
);
3278 sharkd_json_value_string("name", ipv4_hash_table_entry
->name
);
3279 sharkd_json_value_string("addr", ipv4_hash_table_entry
->ip
);
3280 sharkd_json_object_close();
3284 sharkd_session_tap_ipv6_host_print(gpointer data
, gpointer user_data _U_
)
3286 hashipv6_t
*ipv6_hash_table_entry
= (hashipv6_t
*)data
;
3287 sharkd_json_object_open(NULL
);
3288 sharkd_json_value_string("name", ipv6_hash_table_entry
->name
);
3289 sharkd_json_value_string("addr", ipv6_hash_table_entry
->ip6
);
3290 sharkd_json_object_close();
3294 sharkd_session_tap_ipv4_host_insert_sorted(gpointer key _U_
, gpointer value
, gpointer user_data
)
3296 hashipv4_t
*ipv4_hash_table_entry
= (hashipv4_t
*)value
;
3297 GSList
**list
= (GSList
**)user_data
;
3298 if ((ipv4_hash_table_entry
->flags
& NAME_RESOLVED
)) {
3299 *list
= g_slist_insert_sorted(*list
, ipv4_hash_table_entry
, sharkd_session_tap_ipv4_host_compare
);
3304 sharkd_session_tap_ipv6_host_insert_sorted(gpointer key _U_
, gpointer value
, gpointer user_data
)
3306 hashipv6_t
*ipv6_hash_table_entry
= (hashipv6_t
*)value
;
3307 GSList
**list
= (GSList
**) user_data
;
3308 if ((ipv6_hash_table_entry
->flags
& NAME_RESOLVED
)) {
3309 *list
= g_slist_insert_sorted(*list
, ipv6_hash_table_entry
, sharkd_session_tap_ipv6_host_compare
);
3314 sharkd_session_tap_ipv4_hosts_print(void)
3316 wmem_map_t
*ipv4_hash_table
= get_ipv4_hash_table();
3317 if (!ipv4_hash_table
)
3319 GSList
*list
= NULL
;
3320 wmem_map_foreach(ipv4_hash_table
, sharkd_session_tap_ipv4_host_insert_sorted
, &list
);
3321 g_slist_foreach(list
, sharkd_session_tap_ipv4_host_print
, NULL
);
3326 sharkd_session_tap_ipv6_hosts_print(void)
3328 wmem_map_t
*ipv6_hash_table
= get_ipv6_hash_table();
3329 if (!ipv6_hash_table
)
3331 GSList
*list
= NULL
;
3332 wmem_map_foreach(ipv6_hash_table
, sharkd_session_tap_ipv6_host_insert_sorted
, &list
);
3333 g_slist_foreach(list
, sharkd_session_tap_ipv6_host_print
, NULL
);
3338 * sharkd_session_process_tap_hosts_cb()
3341 * (m) tap - tap name
3342 * (m) type - tap output type
3343 * (o) ipv4_hosts - array of objects with attributes:
3344 * (m) addr - ipv4 address
3345 * (m) name - resolved name of address
3346 * (o) ipv6_hosts - array of objects with attributes:
3347 * (m) addr - ipv6 address
3348 * (m) name - resolved name of address
3351 sharkd_session_process_tap_hosts_cb(void *arg
)
3353 struct sharkd_hosts_req
*hosts_req
= (struct sharkd_hosts_req
*)arg
;
3354 sharkd_json_object_open(NULL
);
3355 sharkd_json_value_string("tap", hosts_req
->tap_name
);
3356 sharkd_json_value_string("type", "hosts");
3357 if (hosts_req
->dump_v4
) {
3358 sharkd_json_array_open("ipv4_hosts");
3359 sharkd_session_tap_ipv4_hosts_print();
3360 sharkd_json_array_close();
3362 if (hosts_req
->dump_v6
) {
3363 sharkd_json_array_open("ipv6_hosts");
3364 sharkd_session_tap_ipv6_hosts_print();
3365 sharkd_json_array_close();
3367 sharkd_json_object_close();
3371 sharkd_session_free_tap_hosts_cb(void *tapdata
)
3373 struct sharkd_hosts_req
*hosts_req
= (struct sharkd_hosts_req
*)tapdata
;
3378 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
)
3380 export_object_list_t
*eo_object
;
3381 struct sharkd_export_object_list
*object_list
;
3383 object_list
= sharkd_eo_object_list_get_entry_by_type(sharkd_eo_list
, tap_type
);
3386 g_slist_free_full(object_list
->entries
, (GDestroyNotify
) eo_free_entry
);
3387 object_list
->entries
= NULL
;
3391 object_list
= g_new(struct sharkd_export_object_list
, 1);
3392 object_list
->type
= g_strdup(tap_type
);
3393 object_list
->proto
= proto_get_protocol_short_name(find_protocol_by_id(get_eo_proto_id(eo
)));
3394 object_list
->entries
= NULL
;
3395 object_list
->next
= sharkd_eo_list
;
3396 sharkd_eo_list
= object_list
;
3399 eo_object
= g_new0(export_object_list_t
, 1);
3400 eo_object
->add_entry
= sharkd_eo_object_list_add_entry
;
3401 eo_object
->get_entry
= sharkd_eo_object_list_get_entry
;
3402 eo_object
->gui_data
= (void *) object_list
;
3404 *ptap_data
= eo_object
;
3405 *ptap_free
= g_free
; /* need to free only eo_object, object_list need to be kept for potential download */
3407 return register_tap_listener(get_eo_tap_listener_name(eo
), eo_object
, tap_filter
, 0, NULL
, get_eo_packet_func(eo
), tap_draw
, NULL
);
3411 * sharkd_session_process_tap()
3413 * Process tap request
3416 * (m) tap0 - First tap request
3417 * (o) tap1...tap15 - Other tap requests
3419 * Output object with attributes:
3420 * (m) taps - array of object with attributes:
3421 * (m) tap - tap name
3422 * (m) type - tap output type
3424 * for type:stats see sharkd_session_process_tap_stats_cb()
3425 * for type:nstat see sharkd_session_process_tap_nstat_cb()
3426 * for type:conv see sharkd_session_process_tap_conv_cb()
3427 * for type:host see sharkd_session_process_tap_conv_cb()
3428 * for type:rtp-streams see sharkd_session_process_tap_rtp_cb()
3429 * for type:rtp-analyse see sharkd_session_process_tap_rtp_analyse_cb()
3430 * for type:eo see sharkd_session_process_tap_eo_cb()
3431 * for type:expert see sharkd_session_process_tap_expert_cb()
3432 * for type:rtd see sharkd_session_process_tap_rtd_cb()
3433 * for type:srt see sharkd_session_process_tap_srt_cb()
3434 * for type:flow see sharkd_session_process_tap_flow_cb()
3436 * (m) err - error code
3439 sharkd_session_process_tap(char *buf
, const jsmntok_t
*tokens
, int count
)
3441 void *taps_data
[16];
3442 GFreeFunc taps_free
[16];
3445 const char *tap_filter
= json_find_attr(buf
, tokens
, count
, "filter");
3447 rtpstream_tapinfo_t rtp_tapinfo
=
3448 { NULL
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, 0, TAP_ANALYSE
, NULL
, NULL
, NULL
, FALSE
, FALSE
};
3450 for (i
= 0; i
< 16; i
++)
3453 const char *tok_tap
;
3455 void *tap_data
= NULL
;
3456 GFreeFunc tap_free
= NULL
;
3457 GString
*tap_error
= NULL
;
3459 snprintf(tapbuf
, sizeof(tapbuf
), "tap%d", i
);
3460 tok_tap
= json_find_attr(buf
, tokens
, count
, tapbuf
);
3464 if (!strncmp(tok_tap
, "stat:", 5))
3466 stats_tree_cfg
*cfg
= stats_tree_get_cfg_by_abbr(tok_tap
+ 5);
3472 rpcid
, -11001, NULL
,
3473 "sharkd_session_process_tap() stat %s not found", tok_tap
+ 5
3478 st
= stats_tree_new(cfg
, NULL
, tap_filter
);
3480 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
);
3482 if (!tap_error
&& cfg
->init
)
3486 tap_free
= sharkd_session_free_tap_stats_cb
;
3488 else if (!strcmp(tok_tap
, "expert"))
3490 struct sharkd_expert_tap
*expert_tap
;
3492 expert_tap
= g_new0(struct sharkd_expert_tap
, 1);
3493 expert_tap
->text
= g_string_chunk_new(100);
3495 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
);
3497 tap_data
= expert_tap
;
3498 tap_free
= sharkd_session_free_tap_expert_cb
;
3500 else if (!strncmp(tok_tap
, "seqa:", 5))
3502 seq_analysis_info_t
*graph_analysis
;
3503 register_analysis_t
*analysis
;
3504 const char *tap_name
;
3505 tap_packet_cb tap_func
;
3508 analysis
= sequence_analysis_find_by_name(tok_tap
+ 5);
3512 rpcid
, -11002, NULL
,
3513 "sharkd_session_process_tap() seq analysis %s not found", tok_tap
+ 5
3518 graph_analysis
= sequence_analysis_info_new();
3519 graph_analysis
->name
= tok_tap
+ 5;
3520 /* TODO, make configurable */
3521 graph_analysis
->any_addr
= FALSE
;
3523 tap_name
= sequence_analysis_get_tap_listener_name(analysis
);
3524 tap_flags
= sequence_analysis_get_tap_flags(analysis
);
3525 tap_func
= sequence_analysis_get_packet_func(analysis
);
3527 tap_error
= register_tap_listener(tap_name
, graph_analysis
, tap_filter
, tap_flags
, NULL
, tap_func
, sharkd_session_process_tap_flow_cb
, NULL
);
3529 tap_data
= graph_analysis
;
3530 tap_free
= sharkd_session_free_tap_flow_cb
;
3532 else if (!strncmp(tok_tap
, "conv:", 5) || !strncmp(tok_tap
, "endpt:", 6))
3534 struct register_ct
*ct
= NULL
;
3535 const char *ct_tapname
;
3536 struct sharkd_conv_tap_data
*ct_data
;
3537 tap_packet_cb tap_func
= NULL
;
3539 if (!strncmp(tok_tap
, "conv:", 5))
3541 ct
= get_conversation_by_proto_id(proto_get_id_by_short_name(tok_tap
+ 5));
3543 if (!ct
|| !(tap_func
= get_conversation_packet_func(ct
)))
3546 rpcid
, -11003, NULL
,
3547 "sharkd_session_process_tap() conv %s not found", tok_tap
+ 5
3552 else if (!strncmp(tok_tap
, "endpt:", 6))
3554 ct
= get_conversation_by_proto_id(proto_get_id_by_short_name(tok_tap
+ 6));
3556 if (!ct
|| !(tap_func
= get_endpoint_packet_func(ct
)))
3559 rpcid
, -11004, NULL
,
3560 "sharkd_session_process_tap() endpt %s not found", tok_tap
+ 6
3568 rpcid
, -11005, NULL
,
3569 "sharkd_session_process_tap() conv/endpt(?): %s not found", tok_tap
3574 ct_tapname
= proto_get_protocol_filter_name(get_conversation_proto_id(ct
));
3576 ct_data
= g_new0(struct sharkd_conv_tap_data
, 1);
3577 ct_data
->type
= tok_tap
;
3578 ct_data
->hash
.user_data
= ct_data
;
3580 /* XXX: make configurable */
3581 ct_data
->resolve_name
= TRUE
;
3582 ct_data
->resolve_port
= TRUE
;
3584 tap_error
= register_tap_listener(ct_tapname
, &ct_data
->hash
, tap_filter
, 0, NULL
, tap_func
, sharkd_session_process_tap_conv_cb
, NULL
);
3586 tap_data
= &ct_data
->hash
;
3587 tap_free
= sharkd_session_free_tap_conv_cb
;
3589 else if (!strncmp(tok_tap
, "nstat:", 6))
3591 stat_tap_table_ui
*stat_tap
= stat_tap_by_name(tok_tap
+ 6);
3592 stat_data_t
*stat_data
;
3597 rpcid
, -11006, NULL
,
3598 "sharkd_session_process_tap() nstat=%s not found", tok_tap
+ 6
3603 stat_tap
->stat_tap_init_cb(stat_tap
);
3605 stat_data
= g_new0(stat_data_t
, 1);
3606 stat_data
->stat_tap_data
= stat_tap
;
3607 stat_data
->user_data
= NULL
;
3609 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
);
3611 tap_data
= stat_data
;
3612 tap_free
= sharkd_session_free_tap_nstat_cb
;
3614 else if (!strncmp(tok_tap
, "rtd:", 4))
3616 register_rtd_t
*rtd
= get_rtd_table_by_name(tok_tap
+ 4);
3617 rtd_data_t
*rtd_data
;
3623 rpcid
, -11007, NULL
,
3624 "sharkd_session_process_tap() rtd=%s not found", tok_tap
+ 4
3629 rtd_table_get_filter(rtd
, "", &tap_filter
, &err
);
3633 rpcid
, -11008, NULL
,
3634 "sharkd_session_process_tap() rtd=%s err=%s", tok_tap
+ 4, err
3640 rtd_data
= g_new0(rtd_data_t
, 1);
3641 rtd_data
->user_data
= rtd
;
3642 rtd_table_dissector_init(rtd
, &rtd_data
->stat_table
, NULL
, NULL
);
3644 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
);
3646 tap_data
= rtd_data
;
3647 tap_free
= sharkd_session_free_tap_rtd_cb
;
3649 else if (!strncmp(tok_tap
, "srt:", 4))
3651 register_srt_t
*srt
= get_srt_table_by_name(tok_tap
+ 4);
3652 srt_data_t
*srt_data
;
3658 rpcid
, -11009, NULL
,
3659 "sharkd_session_process_tap() srt=%s not found", tok_tap
+ 4
3664 srt_table_get_filter(srt
, "", &tap_filter
, &err
);
3668 rpcid
, -11010, NULL
,
3669 "sharkd_session_process_tap() srt=%s err=%s", tok_tap
+ 4, err
3675 srt_data
= g_new0(srt_data_t
, 1);
3676 srt_data
->srt_array
= g_array_new(FALSE
, TRUE
, sizeof(srt_stat_table
*));
3677 srt_data
->user_data
= srt
;
3678 srt_table_dissector_init(srt
, srt_data
->srt_array
);
3680 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
);
3682 tap_data
= srt_data
;
3683 tap_free
= sharkd_session_free_tap_srt_cb
;
3685 else if (!strncmp(tok_tap
, "eo:", 3))
3687 register_eo_t
*eo
= get_eo_by_name(tok_tap
+ 3);
3692 rpcid
, -11011, NULL
,
3693 "sharkd_session_process_tap() eo=%s not found", tok_tap
+ 3
3698 tap_error
= sharkd_session_eo_register_tap_listener(eo
, tok_tap
, tap_filter
, sharkd_session_process_tap_eo_cb
, &tap_data
, &tap_free
);
3700 /* tap_data & tap_free assigned by sharkd_session_eo_register_tap_listener */
3702 else if (!strcmp(tok_tap
, "rtp-streams"))
3704 tap_error
= register_tap_listener("rtp", &rtp_tapinfo
, tap_filter
, 0, rtpstream_reset_cb
, rtpstream_packet_cb
, sharkd_session_process_tap_rtp_cb
, NULL
);
3706 tap_data
= &rtp_tapinfo
;
3707 tap_free
= rtpstream_reset_cb
;
3709 else if (!strncmp(tok_tap
, "rtp-analyse:", 12))
3711 struct sharkd_analyse_rtp
*rtp_req
;
3713 rtp_req
= (struct sharkd_analyse_rtp
*) g_malloc0(sizeof(*rtp_req
));
3714 if (!sharkd_rtp_match_init(&rtp_req
->id
, tok_tap
+ 12))
3716 rtpstream_id_free(&rtp_req
->id
);
3721 rtp_req
->tap_name
= tok_tap
;
3722 rtp_req
->statinfo
.first_packet
= TRUE
;
3723 rtp_req
->statinfo
.reg_pt
= PT_UNDEFINED
;
3725 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
);
3728 tap_free
= sharkd_session_process_tap_rtp_free_cb
;
3730 else if (!strcmp(tok_tap
, "multicast"))
3732 mcaststream_tapinfo_t
*mcaststream_tapinfo
;
3733 mcaststream_tapinfo
= (mcaststream_tapinfo_t
*) g_malloc0(sizeof(*mcaststream_tapinfo
));
3735 tap_error
= register_tap_listener("udp", mcaststream_tapinfo
, tap_filter
, 0, NULL
, mcaststream_packet
, sharkd_session_process_tap_multicast_cb
, NULL
);
3736 tap_data
= mcaststream_tapinfo
;
3737 tap_free
= sharkd_session_process_free_tap_multicast_cb
;
3739 else if (!strcmp(tok_tap
, "phs"))
3743 pc_proto_id
= proto_registrar_get_id_byname("pkt_comment");
3745 rs
= new_phs_t(NULL
, tap_filter
);
3747 tap_error
= register_tap_listener("frame", rs
, tap_filter
, TL_REQUIRES_PROTO_TREE
, NULL
,
3748 protohierstat_packet
,
3749 sharkd_session_process_tap_phs_cb
, NULL
);
3752 tap_free
= sharkd_session_free_tap_phs_cb
;
3754 else if (!strcmp(tok_tap
, "voip-calls"))
3756 voip_stat_init_tapinfo();
3758 tap_error
= register_tap_listener("frame", &tapinfo_
, tap_filter
, 0, NULL
, NULL
, sharkd_session_process_tap_voip_calls_cb
, NULL
);
3760 tapinfo_
.session
= cfile
.epan
;
3761 voip_calls_init_all_taps(&tapinfo_
);
3763 tap_data
= &tapinfo_
;
3764 tap_free
= sharkd_session_free_tap_voip_calls_cb
;
3766 else if (!strncmp(tok_tap
, "voip-convs:", 11))
3769 unsigned int min
, max
;
3770 struct sharkd_voip_convs_req
*voip_convs_req
;
3771 const char *conv_arg
= tok_tap
+ 11;
3773 // parse tok_tap to get which call we are asking for
3774 if (*conv_arg
== 0) {
3775 // set all bits of voip_conv_sel (-1 in binary is all 1's)
3776 memset(voip_conv_sel
, -1, sizeof(voip_conv_sel
));
3778 memset(voip_conv_sel
, 0, sizeof(voip_conv_sel
));
3780 while (*conv_arg
!= 0) {
3781 if (*conv_arg
== ',') {
3784 if (sscanf(conv_arg
, "%u-%u%n", &min
, &max
, &len
) == 2) {
3786 } else if (sscanf(conv_arg
, "%u%n", &min
, &len
) == 1) {
3791 rpcid
, -11014, NULL
,
3792 "sharkd_session_process_tap() voip-convs=%s invalid 'convs' parameter", tok_tap
3796 if (min
> max
|| min
>= VOIP_CONV_MAX
|| max
>= VOIP_CONV_MAX
) {
3798 rpcid
, -11012, NULL
,
3799 "sharkd_session_process_tap() voip-convs=%s invalid 'convs' number range", tok_tap
3803 for(; min
<= max
; min
++) {
3804 voip_conv_sel
[min
/ VOIP_CONV_BITS
] |= 1 << (min
% VOIP_CONV_BITS
);
3809 voip_stat_init_tapinfo();
3811 voip_convs_req
= (struct sharkd_voip_convs_req
*) g_malloc0(sizeof(*voip_convs_req
));
3812 voip_convs_req
->tapinfo
= &tapinfo_
;
3813 voip_convs_req
->tap_name
= tok_tap
;
3815 tap_error
= register_tap_listener("frame", voip_convs_req
, tap_filter
, 0, NULL
, NULL
, sharkd_session_process_tap_voip_convs_cb
, NULL
);
3817 tapinfo_
.session
= cfile
.epan
;
3818 voip_calls_init_all_taps(&tapinfo_
);
3820 tap_data
= voip_convs_req
;
3821 tap_free
= sharkd_session_free_tap_voip_convs_cb
;
3823 else if (!strncmp(tok_tap
, "hosts:", 6))
3827 struct sharkd_hosts_req
*hosts_req
;
3828 const char *proto_arg
;
3829 gchar
**proto_tokens
;
3832 proto_arg
= tok_tap
+ 6;
3834 if (strlen(proto_arg
) == 0) {
3841 proto_tokens
= g_strsplit(proto_arg
, ",", 0);
3843 while (proto_tokens
[proto_count
]) {
3844 if (!strcmp("ip", proto_tokens
[proto_count
]) ||
3845 !strcmp("ipv4", proto_tokens
[proto_count
])) {
3847 } else if (!strcmp("ipv6", proto_tokens
[proto_count
])) {
3850 g_strfreev(proto_tokens
);
3852 rpcid
, -11015, NULL
,
3853 "sharkd_session_process_tap() hosts=%s invalid 'protos' parameter", tok_tap
3859 g_strfreev(proto_tokens
);
3862 hosts_req
= (struct sharkd_hosts_req
*)g_malloc0(sizeof(*hosts_req
));
3863 hosts_req
->dump_v4
= dump_v4
;
3864 hosts_req
->dump_v6
= dump_v6
;
3865 hosts_req
->tap_name
= tok_tap
;
3867 tap_error
= register_tap_listener("frame", hosts_req
, tap_filter
, TL_REQUIRES_PROTO_TREE
, NULL
, NULL
, sharkd_session_process_tap_hosts_cb
, NULL
);
3869 tap_data
= hosts_req
;
3870 tap_free
= sharkd_session_free_tap_hosts_cb
;
3875 rpcid
, -11012, NULL
,
3876 "sharkd_session_process_tap() %s not recognized", tok_tap
3884 rpcid
, -11013, NULL
,
3885 "sharkd_session_process_tap() name=%s error=%s", tok_tap
, tap_error
->str
3887 g_string_free(tap_error
, TRUE
);
3893 taps_data
[taps_count
] = tap_data
;
3894 taps_free
[taps_count
] = tap_free
;
3898 fprintf(stderr
, "sharkd_session_process_tap() count=%d\n", taps_count
);
3899 if (taps_count
== 0)
3901 sharkd_json_result_prologue(rpcid
);
3902 sharkd_json_array_open("taps");
3903 sharkd_json_array_close();
3904 sharkd_json_result_epilogue();
3908 sharkd_json_result_prologue(rpcid
);
3909 sharkd_json_array_open("taps");
3911 sharkd_json_array_close();
3912 sharkd_json_result_epilogue();
3914 for (i
= 0; i
< taps_count
; i
++)
3917 remove_tap_listener(taps_data
[i
]);
3920 taps_free
[i
](taps_data
[i
]);
3925 * sharkd_session_process_follow()
3927 * Process follow request
3930 * (m) follow - follow protocol request (e.g. HTTP)
3931 * (m) filter - filter request (e.g. tcp.stream == 1)
3932 * (m) stream - stream index number
3933 * (o) sub_stream - follow sub-stream index number (e.g. for HTTP/2 and QUIC streams)
3935 * Output object with attributes:
3937 * (m) err - error code
3938 * (m) shost - server host
3939 * (m) sport - server port
3940 * (m) sbytes - server send bytes count
3941 * (m) chost - client host
3942 * (m) cport - client port
3943 * (m) cbytes - client send bytes count
3944 * (o) payloads - array of object with attributes:
3945 * (o) s - set if server sent, else client
3946 * (m) n - packet number
3947 * (m) d - data base64 encoded
3950 sharkd_session_process_follow(char *buf
, const jsmntok_t
*tokens
, int count
)
3952 const char *tok_follow
= json_find_attr(buf
, tokens
, count
, "follow");
3953 const char *tok_filter
= json_find_attr(buf
, tokens
, count
, "filter");
3954 const char *tok_sub_stream
= json_find_attr(buf
, tokens
, count
, "sub_stream");
3956 register_follow_t
*follower
;
3959 follow_info_t
*follow_info
;
3963 follower
= get_follow_by_name(tok_follow
);
3967 rpcid
, -12001, NULL
,
3968 "sharkd_session_process_follow() follower=%s not found", tok_follow
3973 guint64 substream_id
= SUBSTREAM_UNUSED
;
3976 ws_strtou64(tok_sub_stream
, NULL
, &substream_id
);
3979 /* follow_reset_stream ? */
3980 follow_info
= g_new0(follow_info_t
, 1);
3981 follow_info
->substream_id
= substream_id
;
3982 /* gui_data, filter_out_filter not set, but not used by dissector */
3984 tap_error
= register_tap_listener(get_follow_tap_string(follower
), follow_info
, tok_filter
, 0, NULL
, get_follow_tap_handler(follower
), NULL
, NULL
);
3988 rpcid
, -12002, NULL
,
3989 "sharkd_session_process_follow() name=%s error=%s", tok_follow
, tap_error
->str
3991 g_string_free(tap_error
, TRUE
);
3992 g_free(follow_info
);
3998 sharkd_json_result_prologue(rpcid
);
4000 /* Server information: hostname, port, bytes sent */
4001 host
= address_to_name(&follow_info
->server_ip
);
4002 sharkd_json_value_string("shost", host
);
4004 port
= get_follow_port_to_display(follower
)(NULL
, follow_info
->server_port
);
4005 sharkd_json_value_string("sport", port
);
4006 wmem_free(NULL
, port
);
4008 sharkd_json_value_anyf("sbytes", "%u", follow_info
->bytes_written
[0]);
4010 /* Client information: hostname, port, bytes sent */
4011 host
= address_to_name(&follow_info
->client_ip
);
4012 sharkd_json_value_string("chost", host
);
4014 port
= get_follow_port_to_display(follower
)(NULL
, follow_info
->client_port
);
4015 sharkd_json_value_string("cport", port
);
4016 wmem_free(NULL
, port
);
4018 sharkd_json_value_anyf("cbytes", "%u", follow_info
->bytes_written
[1]);
4020 if (follow_info
->payload
)
4022 follow_record_t
*follow_record
;
4025 sharkd_json_array_open("payloads");
4026 for (cur
= g_list_last(follow_info
->payload
); cur
; cur
= g_list_previous(cur
))
4028 follow_record
= (follow_record_t
*) cur
->data
;
4030 json_dumper_begin_object(&dumper
);
4032 sharkd_json_value_anyf("n", "%u", follow_record
->packet_num
);
4033 sharkd_json_value_base64("d", follow_record
->data
->data
, follow_record
->data
->len
);
4035 if (follow_record
->is_server
)
4036 sharkd_json_value_anyf("s", "%d", 1);
4038 json_dumper_end_object(&dumper
);
4040 sharkd_json_array_close();
4043 sharkd_json_result_epilogue();
4045 remove_tap_listener(follow_info
);
4046 follow_info_free(follow_info
);
4050 sharkd_session_process_frame_cb_tree(const char *key
, epan_dissect_t
*edt
, proto_tree
*tree
, tvbuff_t
**tvbs
, gboolean display_hidden
)
4054 sharkd_json_array_open(key
);
4055 for (node
= tree
->first_child
; node
; node
= node
->next
)
4057 field_info
*finfo
= PNODE_FINFO(node
);
4062 if (!display_hidden
&& FI_GET_FLAG(finfo
, FI_HIDDEN
))
4065 json_dumper_begin_object(&dumper
);
4069 char label_str
[ITEM_LABEL_LENGTH
];
4071 label_str
[0] = '\0';
4072 proto_item_fill_label(finfo
, label_str
);
4073 sharkd_json_value_string("l", label_str
);
4077 sharkd_json_value_string("l", finfo
->rep
->representation
);
4080 if (finfo
->ds_tvb
&& tvbs
&& tvbs
[0] != finfo
->ds_tvb
)
4084 for (idx
= 1; tvbs
[idx
]; idx
++)
4086 if (tvbs
[idx
] == finfo
->ds_tvb
)
4088 sharkd_json_value_anyf("ds", "%d", idx
);
4094 if (finfo
->start
>= 0 && finfo
->length
> 0)
4095 sharkd_json_value_anyf("h", "[%d,%d]", finfo
->start
, finfo
->length
);
4097 if (finfo
->appendix_start
>= 0 && finfo
->appendix_length
> 0)
4098 sharkd_json_value_anyf("i", "[%d,%d]", finfo
->appendix_start
, finfo
->appendix_length
);
4105 if (finfo
->hfinfo
->type
== FT_PROTOCOL
)
4107 sharkd_json_value_string("t", "proto");
4109 else if (finfo
->hfinfo
->type
== FT_FRAMENUM
)
4111 sharkd_json_value_string("t", "framenum");
4112 sharkd_json_value_anyf("fnum", "%u", fvalue_get_uinteger(finfo
->value
));
4114 else if (FI_GET_FLAG(finfo
, FI_URL
) && FT_IS_STRING(finfo
->hfinfo
->type
))
4116 char *url
= fvalue_to_string_repr(NULL
, finfo
->value
, FTREPR_DISPLAY
, finfo
->hfinfo
->display
);
4118 sharkd_json_value_string("t", "url");
4119 sharkd_json_value_string("url", url
);
4120 wmem_free(NULL
, url
);
4123 filter
= proto_construct_match_selected_string(finfo
, edt
);
4126 sharkd_json_value_string("f", filter
);
4127 wmem_free(NULL
, filter
);
4130 if (finfo
->hfinfo
->abbrev
)
4131 sharkd_json_value_string("fn", finfo
->hfinfo
->abbrev
);
4134 if (FI_GET_FLAG(finfo
, FI_GENERATED
))
4135 sharkd_json_value_anyf("g", "true");
4137 if (FI_GET_FLAG(finfo
, FI_HIDDEN
))
4138 sharkd_json_value_anyf("v", "true");
4140 if (FI_GET_FLAG(finfo
, PI_SEVERITY_MASK
))
4142 const char *severity
= try_val_to_str(FI_GET_FLAG(finfo
, PI_SEVERITY_MASK
), expert_severity_vals
);
4144 ws_assert(severity
!= NULL
);
4146 sharkd_json_value_string("s", severity
);
4149 if (((proto_tree
*) node
)->first_child
)
4151 if (finfo
->tree_type
!= -1)
4152 sharkd_json_value_anyf("e", "%d", finfo
->tree_type
);
4154 sharkd_session_process_frame_cb_tree("n", edt
, (proto_tree
*) node
, tvbs
, display_hidden
);
4157 json_dumper_end_object(&dumper
);
4159 sharkd_json_array_close();
4163 sharkd_follower_visit_layers_cb(const void *key _U_
, void *value
, void *user_data
)
4165 register_follow_t
*follower
= (register_follow_t
*) value
;
4166 epan_dissect_t
*edt
= (epan_dissect_t
*) user_data
;
4167 packet_info
*pi
= &edt
->pi
;
4169 const int proto_id
= get_follow_proto_id(follower
);
4171 guint32 ignore_stream
;
4172 guint32 ignore_sub_stream
;
4174 if (proto_is_frame_protocol(pi
->layers
, proto_get_protocol_filter_name(proto_id
)))
4176 const char *layer_proto
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
4177 char *follow_filter
;
4179 follow_filter
= get_follow_conv_func(follower
)(edt
, pi
, &ignore_stream
, &ignore_sub_stream
);
4181 json_dumper_begin_array(&dumper
);
4182 json_dumper_value_string(&dumper
, layer_proto
);
4183 json_dumper_value_string(&dumper
, follow_filter
);
4184 json_dumper_end_array(&dumper
);
4186 g_free(follow_filter
);
4193 sharkd_followers_visit_layers_cb(const void *key _U_
, void *value
, void *user_data
)
4195 register_follow_t
*follower
= (register_follow_t
*) value
;
4196 epan_dissect_t
*edt
= (epan_dissect_t
*) user_data
;
4197 packet_info
*pi
= &edt
->pi
;
4199 const int proto_id
= get_follow_proto_id(follower
);
4204 if (proto_is_frame_protocol(pi
->layers
, proto_get_protocol_filter_name(proto_id
)))
4206 const char *layer_proto
= proto_get_protocol_short_name(find_protocol_by_id(proto_id
));
4207 char *follow_filter
;
4209 follow_filter
= get_follow_conv_func(follower
)(edt
, pi
, &stream
, &sub_stream
);
4211 sharkd_json_object_open(NULL
);
4212 sharkd_json_value_string("protocol", layer_proto
);
4213 sharkd_json_value_string("filter", follow_filter
);
4214 if (get_follow_stream_count_func(follower
) != NULL
)
4216 sharkd_json_value_anyf("stream", "%u", stream
);
4218 if (get_follow_sub_stream_id_func(follower
) != NULL
)
4220 sharkd_json_value_anyf("sub_stream", "%u", sub_stream
);
4222 sharkd_json_object_close();
4224 g_free(follow_filter
);
4230 struct sharkd_frame_request_data
4232 gboolean display_hidden
;
4236 sharkd_session_process_frame_cb(epan_dissect_t
*edt
, proto_tree
*tree
, struct epan_column_info
*cinfo
, const GSList
*data_src
, void *data
)
4238 packet_info
*pi
= &edt
->pi
;
4239 frame_data
*fdata
= pi
->fd
;
4240 wtap_block_t pkt_block
= NULL
;
4242 const struct sharkd_frame_request_data
* const req_data
= (const struct sharkd_frame_request_data
* const) data
;
4243 const gboolean display_hidden
= (req_data
) ? req_data
->display_hidden
: FALSE
;
4245 sharkd_json_result_prologue(rpcid
);
4247 if (fdata
->has_modified_block
)
4248 pkt_block
= sharkd_get_modified_block(fdata
);
4250 pkt_block
= pi
->rec
->block
;
4258 n
= wtap_block_count_option(pkt_block
, OPT_COMMENT
);
4260 sharkd_json_array_open("comment");
4261 for (i
= 0; i
< n
; i
++) {
4262 if (WTAP_OPTTYPE_SUCCESS
== wtap_block_get_nth_string_option_value(pkt_block
, OPT_COMMENT
, i
, &comment
)) {
4263 sharkd_json_value_string(NULL
, comment
);
4266 sharkd_json_array_close();
4271 tvbuff_t
**tvbs
= NULL
;
4273 /* arrayize data src, to speedup searching for ds_tvb index */
4274 if (data_src
&& data_src
->next
/* only needed if there are more than one data source */)
4276 guint count
= g_slist_length((GSList
*) data_src
);
4279 tvbs
= (tvbuff_t
**) g_malloc0((count
+ 1) * sizeof(*tvbs
));
4281 for (i
= 0; i
< count
; i
++)
4283 const struct data_source
*src
= (const struct data_source
*) g_slist_nth_data((GSList
*) data_src
, i
);
4285 tvbs
[i
] = get_data_source_tvb(src
);
4291 sharkd_session_process_frame_cb_tree("tree", edt
, tree
, tvbs
, display_hidden
);
4300 sharkd_json_array_open("col");
4301 for (col
= 0; col
< cinfo
->num_cols
; ++col
)
4303 sharkd_json_value_string(NULL
, get_column_text(cinfo
, col
));
4305 sharkd_json_array_close();
4309 sharkd_json_value_anyf("i", "true");
4312 sharkd_json_value_anyf("m", "true");
4314 if (fdata
->color_filter
)
4316 sharkd_json_value_stringf("bg", "%06x", color_t_to_rgb(&fdata
->color_filter
->bg_color
));
4317 sharkd_json_value_stringf("fg", "%06x", color_t_to_rgb(&fdata
->color_filter
->fg_color
));
4322 struct data_source
*src
= (struct data_source
*) data_src
->data
;
4323 gboolean ds_open
= FALSE
;
4328 tvb
= get_data_source_tvb(src
);
4329 length
= tvb_captured_length(tvb
);
4333 const guchar
*cp
= tvb_get_ptr(tvb
, 0, length
);
4335 /* XXX pi.fd->encoding */
4336 sharkd_json_value_base64("bytes", cp
, length
);
4340 sharkd_json_value_base64("bytes", "", 0);
4343 data_src
= data_src
->next
;
4346 sharkd_json_array_open("ds");
4352 src
= (struct data_source
*) data_src
->data
;
4354 json_dumper_begin_object(&dumper
);
4357 char *src_name
= get_data_source_name(src
);
4359 sharkd_json_value_string("name", src_name
);
4360 wmem_free(NULL
, src_name
);
4363 tvb
= get_data_source_tvb(src
);
4364 length
= tvb_captured_length(tvb
);
4368 const guchar
*cp
= tvb_get_ptr(tvb
, 0, length
);
4370 /* XXX pi.fd->encoding */
4371 sharkd_json_value_base64("bytes", cp
, length
);
4375 sharkd_json_value_base64("bytes", "", 0);
4378 json_dumper_end_object(&dumper
);
4380 data_src
= data_src
->next
;
4383 /* close ds, only if was opened */
4385 sharkd_json_array_close();
4388 sharkd_json_array_open("fol");
4389 follow_iterate_followers(sharkd_follower_visit_layers_cb
, edt
);
4390 sharkd_json_array_close();
4392 sharkd_json_array_open("followers");
4393 follow_iterate_followers(sharkd_followers_visit_layers_cb
, edt
);
4394 sharkd_json_array_close();
4396 sharkd_json_result_epilogue();
4399 #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 */
4401 struct sharkd_iograph
4405 io_graph_item_unit_t calc_type
;
4411 io_graph_item_t
*items
;
4415 static tap_packet_status
4416 sharkd_iograph_packet(void *g
, packet_info
*pinfo
, epan_dissect_t
*edt
, const void *dummy _U_
, tap_flags_t flags _U_
)
4418 struct sharkd_iograph
*graph
= (struct sharkd_iograph
*) g
;
4420 gboolean update_succeeded
;
4422 int64_t tmp_idx
= get_io_graph_index(pinfo
, graph
->interval
);
4423 if (tmp_idx
< 0 || tmp_idx
>= SHARKD_IOGRAPH_MAX_ITEMS
)
4424 return TAP_PACKET_DONT_REDRAW
;
4428 if (idx
+ 1 > graph
->num_items
)
4430 if (idx
+ 1 > graph
->space_items
)
4432 int new_size
= idx
+ 1024;
4434 graph
->items
= (io_graph_item_t
*) g_realloc(graph
->items
, sizeof(io_graph_item_t
) * new_size
);
4435 reset_io_graph_items(&graph
->items
[graph
->space_items
], new_size
- graph
->space_items
, graph
->hf_index
);
4437 graph
->space_items
= new_size
;
4439 else if (graph
->items
== NULL
)
4441 graph
->items
= g_new(io_graph_item_t
, graph
->space_items
);
4442 reset_io_graph_items(graph
->items
, graph
->space_items
, graph
->hf_index
);
4445 graph
->num_items
= idx
+ 1;
4448 update_succeeded
= update_io_graph_item(graph
->items
, idx
, pinfo
, edt
, graph
->hf_index
, graph
->calc_type
, graph
->interval
);
4449 /* XXX - TAP_PACKET_FAILED if the item couldn't be updated, with an error message? */
4450 return update_succeeded
? TAP_PACKET_REDRAW
: TAP_PACKET_DONT_REDRAW
;
4454 * sharkd_session_process_iograph()
4456 * Process iograph request
4459 * (o) interval - interval time, if not specified: 1000
4460 * (o) interval_units - units for interval time, must be 's', 'ms' or 'us', if not specified: ms
4461 * (m) graph0 - First graph request
4462 * (o) graph1...graph9 - Other graph requests
4463 * (o) filter0 - First graph filter
4464 * (o) filter1...filter9 - Other graph filters
4466 * Graph requests can be one of: "packets", "bytes", "bits", "sum:<field>", "frames:<field>", "max:<field>", "min:<field>", "avg:<field>", "load:<field>",
4467 * if you use variant with <field>, you need to pass field name in filter request.
4469 * Output object with attributes:
4470 * (m) iograph - array of graph results with attributes:
4471 * errmsg - graph cannot be constructed
4472 * items - graph values, zeros are skipped, if value is not a number it's next index encoded as hex string
4475 sharkd_session_process_iograph(char *buf
, const jsmntok_t
*tokens
, int count
)
4477 const char *tok_interval
= json_find_attr(buf
, tokens
, count
, "interval");
4478 const char *tok_interval_units
= json_find_attr(buf
, tokens
, count
, "interval_units");
4479 struct sharkd_iograph graphs
[10];
4480 gboolean is_any_ok
= FALSE
;
4485 /* default: 1000ms = one per second */
4486 guint32 interval
= 1000;
4487 const char *interval_units
= "ms";
4490 ws_strtou32(tok_interval
, NULL
, &interval
);
4492 if (tok_interval_units
)
4494 if (strcmp(tok_interval_units
, "us") != 0 &&
4495 strcmp(tok_interval_units
, "ms") != 0 &&
4496 strcmp(tok_interval_units
, "s") != 0)
4500 "Invalid interval_units parameter: '%s', must be 's', 'ms' or 'us'", tok_interval_units
4504 interval_units
= tok_interval_units
;
4507 guint32 interval_us
= 0;
4508 if (strcmp(interval_units
, "us") == 0)
4510 interval_us
= interval
;
4512 else if (strcmp(interval_units
, "ms") == 0)
4514 interval_us
= 1000 * interval
;
4516 else if (strcmp(interval_units
, "s") == 0)
4518 interval_us
= 1000000 * interval
;
4521 for (i
= graph_count
= 0; i
< (int) G_N_ELEMENTS(graphs
); i
++)
4523 struct sharkd_iograph
*graph
= &graphs
[graph_count
];
4525 const char *tok_graph
;
4526 const char *tok_filter
;
4527 char tok_format_buf
[32];
4528 const char *field_name
;
4530 snprintf(tok_format_buf
, sizeof(tok_format_buf
), "graph%d", i
);
4531 tok_graph
= json_find_attr(buf
, tokens
, count
, tok_format_buf
);
4535 snprintf(tok_format_buf
, sizeof(tok_format_buf
), "filter%d", i
);
4536 tok_filter
= json_find_attr(buf
, tokens
, count
, tok_format_buf
);
4538 if (!strcmp(tok_graph
, "packets"))
4539 graph
->calc_type
= IOG_ITEM_UNIT_PACKETS
;
4540 else if (!strcmp(tok_graph
, "bytes"))
4541 graph
->calc_type
= IOG_ITEM_UNIT_BYTES
;
4542 else if (!strcmp(tok_graph
, "bits"))
4543 graph
->calc_type
= IOG_ITEM_UNIT_BITS
;
4544 else if (g_str_has_prefix(tok_graph
, "sum:"))
4545 graph
->calc_type
= IOG_ITEM_UNIT_CALC_SUM
;
4546 else if (g_str_has_prefix(tok_graph
, "frames:"))
4547 graph
->calc_type
= IOG_ITEM_UNIT_CALC_FRAMES
;
4548 else if (g_str_has_prefix(tok_graph
, "fields:"))
4549 graph
->calc_type
= IOG_ITEM_UNIT_CALC_FIELDS
;
4550 else if (g_str_has_prefix(tok_graph
, "max:"))
4551 graph
->calc_type
= IOG_ITEM_UNIT_CALC_MAX
;
4552 else if (g_str_has_prefix(tok_graph
, "min:"))
4553 graph
->calc_type
= IOG_ITEM_UNIT_CALC_MIN
;
4554 else if (g_str_has_prefix(tok_graph
, "avg:"))
4555 graph
->calc_type
= IOG_ITEM_UNIT_CALC_AVERAGE
;
4556 else if (g_str_has_prefix(tok_graph
, "load:"))
4557 graph
->calc_type
= IOG_ITEM_UNIT_CALC_LOAD
;
4561 field_name
= strchr(tok_graph
, ':');
4563 field_name
= field_name
+ 1;
4565 /* io_graph_item now supports microseconds (and this parameter
4566 * is expected to be in microseconds.) */
4567 graph
->interval
= interval_us
;
4569 graph
->hf_index
= -1;
4570 graph
->error
= check_field_unit(field_name
, &graph
->hf_index
, graph
->calc_type
);
4572 graph
->space_items
= 0; /* TODO, can avoid realloc()s in sharkd_iograph_packet() by calculating: capture_time / interval */
4573 graph
->num_items
= 0;
4574 graph
->items
= NULL
;
4577 graph
->error
= register_tap_listener("frame", graph
, tok_filter
, TL_REQUIRES_PROTO_TREE
, NULL
, sharkd_iograph_packet
, NULL
, NULL
);
4585 "%s", graph
->error
->str
4587 g_string_free(graph
->error
, TRUE
);
4591 if (graph
->error
== NULL
)
4595 /* retap only if we have at least one ok */
4599 sharkd_json_result_prologue(rpcid
);
4601 sharkd_json_array_open("iograph");
4602 for (i
= 0; i
< graph_count
; i
++)
4604 struct sharkd_iograph
*graph
= &graphs
[i
];
4606 json_dumper_begin_object(&dumper
);
4610 fprintf(stderr
, "SNAP 6002 - we should never get to here.\n");
4611 g_string_free(graph
->error
, TRUE
);
4619 sharkd_json_array_open("items");
4620 for (idx
= 0; idx
< graph
->num_items
; idx
++)
4624 val
= get_io_graph_item(graph
->items
, graph
->calc_type
, idx
, graph
->hf_index
, &cfile
, graph
->interval
, graph
->num_items
);
4626 /* if it's zero, don't display */
4630 /* cause zeros are not printed, need to output index */
4631 if (next_idx
!= idx
)
4632 sharkd_json_value_stringf(NULL
, "%x", idx
);
4634 sharkd_json_value_anyf(NULL
, "%f", val
);
4637 sharkd_json_array_close();
4639 json_dumper_end_object(&dumper
);
4641 remove_tap_listener(graph
);
4642 g_free(graph
->items
);
4644 sharkd_json_array_close();
4646 sharkd_json_result_epilogue();
4650 * sharkd_session_process_intervals()
4652 * Process intervals request - generate basic capture file statistics per requested interval.
4655 * (o) interval - interval time in ms, if not specified: 1000ms
4656 * (o) filter - filter for generating interval request
4658 * Output object with attributes:
4659 * (m) intervals - array of intervals, with indexes:
4660 * [0] - index of interval,
4661 * [1] - number of frames during interval,
4662 * [2] - number of bytes during interval.
4664 * (m) last - last interval number.
4665 * (m) frames - total number of frames
4666 * (m) bytes - total number of bytes
4668 * NOTE: If frames are not in order, there might be items with same interval index, or even negative one.
4671 sharkd_session_process_intervals(char *buf
, const jsmntok_t
*tokens
, int count
)
4673 const char *tok_interval
= json_find_attr(buf
, tokens
, count
, "interval");
4674 const char *tok_filter
= json_find_attr(buf
, tokens
, count
, "filter");
4676 const guint8
*filter_data
= NULL
;
4680 unsigned int frames
;
4686 guint32 interval_ms
= 1000; /* default: one per second */
4692 ws_strtou32(tok_interval
, NULL
, &interval_ms
); // already validated
4696 const struct sharkd_filter_item
*filter_item
;
4698 filter_item
= sharkd_session_filter_data(tok_filter
);
4703 "Invalid filter parameter: %s", tok_filter
4707 filter_data
= filter_item
->filtered
;
4710 st_total
.frames
= 0;
4718 sharkd_json_result_prologue(rpcid
);
4719 sharkd_json_array_open("intervals");
4721 start_ts
= (cfile
.count
>= 1) ? &(sharkd_get_frame(1)->abs_ts
) : NULL
;
4723 for (guint32 framenum
= 1; framenum
<= cfile
.count
; framenum
++)
4729 if (filter_data
&& !(filter_data
[framenum
/ 8] & (1 << (framenum
% 8))))
4732 fdata
= sharkd_get_frame(framenum
);
4734 msec_rel
= (fdata
->abs_ts
.secs
- start_ts
->secs
) * (gint64
) 1000 + (fdata
->abs_ts
.nsecs
- start_ts
->nsecs
) / 1000000;
4735 new_idx
= msec_rel
/ interval_ms
;
4741 sharkd_json_value_anyf(NULL
, "[%" PRId64
",%u,%" PRIu64
"]", idx
, st
.frames
, st
.bytes
);
4753 st
.bytes
+= fdata
->pkt_len
;
4755 st_total
.frames
+= 1;
4756 st_total
.bytes
+= fdata
->pkt_len
;
4761 sharkd_json_value_anyf(NULL
, "[%" PRId64
",%u,%" PRIu64
"]", idx
, st
.frames
, st
.bytes
);
4763 sharkd_json_array_close();
4765 sharkd_json_value_anyf("last", "%" PRId64
, max_idx
);
4766 sharkd_json_value_anyf("frames", "%u", st_total
.frames
);
4767 sharkd_json_value_anyf("bytes", "%" PRIu64
, st_total
.bytes
);
4769 sharkd_json_result_epilogue();
4773 * sharkd_session_process_frame()
4775 * Process frame request
4778 * (m) frame - requested frame number
4779 * (o) ref_frame - time reference frame number
4780 * (o) prev_frame - previously displayed frame number
4781 * (o) proto - set if output frame tree
4782 * (o) columns - set if output frame columns
4783 * (o) color - set if output color-filter bg/fg
4784 * (o) bytes - set if output frame bytes
4785 * (o) hidden - set if output hidden tree fields
4787 * Output object with attributes:
4788 * (m) err - 0 if succeed
4789 * (o) tree - array of frame nodes with attributes:
4791 * t: 'proto', 'framenum', 'url' - type of node
4795 * e - subtree ett index
4796 * n - array of subtree nodes
4797 * h - two item array: (item start, item length)
4798 * i - two item array: (appendix start, appendix length)
4799 * p - [RESERVED] two item array: (protocol start, protocol length)
4800 * ds- data src index
4801 * url - only for t:'url', url
4802 * fnum - only for t:'framenum', frame number
4803 * g - if field is generated by Wireshark
4804 * v - if field is hidden
4806 * (o) col - array of column data
4807 * (o) bytes - base64 of frame bytes
4808 * (o) ds - array of other data srcs
4809 * (o) comment - frame comment
4810 * (o) fol - array of follow filters:
4812 * [1] - filter string
4813 * (o) followers - array of followers with attributes:
4814 * protocol - protocol string
4815 * filter - filter string
4816 * stream - stream index number
4817 * sub_stream - sub-stream index number (optional, e.g. for HTTP/2 and QUIC streams)
4818 * (o) i - if frame is ignored
4819 * (o) m - if frame is marked
4820 * (o) bg - color filter - background color in hex
4821 * (o) fg - color filter - foreground color in hex
4824 sharkd_session_process_frame(char *buf
, const jsmntok_t
*tokens
, int count
)
4826 const char *tok_frame
= json_find_attr(buf
, tokens
, count
, "frame");
4827 const char *tok_ref_frame
= json_find_attr(buf
, tokens
, count
, "ref_frame");
4828 const char *tok_prev_frame
= json_find_attr(buf
, tokens
, count
, "prev_frame");
4829 column_info
*cinfo
= NULL
;
4831 guint32 framenum
, ref_frame_num
, prev_dis_num
;
4832 guint32 dissect_flags
= SHARKD_DISSECT_FLAG_NULL
;
4833 struct sharkd_frame_request_data req_data
;
4834 wtap_rec rec
; /* Record metadata */
4835 Buffer rec_buf
; /* Record data */
4836 enum dissect_request_status status
;
4840 ws_strtou32(tok_frame
, NULL
, &framenum
); // we have already validated this
4842 ref_frame_num
= (framenum
!= 1) ? 1 : 0;
4845 ws_strtou32(tok_ref_frame
, NULL
, &ref_frame_num
);
4846 if (ref_frame_num
> framenum
)
4850 "Invalid ref_frame - The ref_frame occurs after the frame specified"
4856 prev_dis_num
= framenum
- 1;
4859 ws_strtou32(tok_prev_frame
, NULL
, &prev_dis_num
);
4860 if (prev_dis_num
>= framenum
)
4864 "Invalid prev_frame - The prev_frame occurs on or after the frame specified"
4870 if (json_find_attr(buf
, tokens
, count
, "proto") != NULL
)
4871 dissect_flags
|= SHARKD_DISSECT_FLAG_PROTO_TREE
;
4872 if (json_find_attr(buf
, tokens
, count
, "bytes") != NULL
)
4873 dissect_flags
|= SHARKD_DISSECT_FLAG_BYTES
;
4874 if (json_find_attr(buf
, tokens
, count
, "columns") != NULL
) {
4875 dissect_flags
|= SHARKD_DISSECT_FLAG_COLUMNS
;
4876 cinfo
= &cfile
.cinfo
;
4878 if (json_find_attr(buf
, tokens
, count
, "color") != NULL
)
4879 dissect_flags
|= SHARKD_DISSECT_FLAG_COLOR
;
4881 req_data
.display_hidden
= (json_find_attr(buf
, tokens
, count
, "v") != NULL
);
4883 wtap_rec_init(&rec
);
4884 ws_buffer_init(&rec_buf
, 1514);
4886 status
= sharkd_dissect_request(framenum
, ref_frame_num
, prev_dis_num
,
4887 &rec
, &rec_buf
, cinfo
, dissect_flags
,
4888 &sharkd_session_process_frame_cb
, &req_data
, &err
, &err_info
);
4891 case DISSECT_REQUEST_SUCCESS
:
4895 case DISSECT_REQUEST_NO_SUCH_FRAME
:
4898 "Invalid frame - The frame number requested is out of range"
4902 case DISSECT_REQUEST_READ_ERROR
:
4905 /* XXX - show the error details */
4906 "Read error - The frame could not be read from the file"
4912 wtap_rec_cleanup(&rec
);
4913 ws_buffer_free(&rec_buf
);
4917 * sharkd_session_process_check()
4919 * Process check request.
4922 * (o) filter - filter to be checked
4923 * (o) field - field to be checked
4925 * Output object with attributes:
4926 * (m) err - always 0
4927 * (o) filter - 'ok', 'warn' or error message
4928 * (o) field - 'ok', or 'notfound'
4931 sharkd_session_process_check(char *buf
, const jsmntok_t
*tokens
, int count
)
4933 const char *tok_filter
= json_find_attr(buf
, tokens
, count
, "filter");
4934 const char *tok_field
= json_find_attr(buf
, tokens
, count
, "field");
4936 if (tok_filter
!= NULL
)
4939 df_error_t
*df_err
= NULL
;
4941 if (dfilter_compile(tok_filter
, &dfp
, &df_err
))
4943 if (dfp
&& dfilter_deprecated_tokens(dfp
))
4944 sharkd_json_warning(rpcid
, "Filter contains deprecated tokens");
4946 sharkd_json_simple_ok(rpcid
);
4949 df_error_free(&df_err
);
4956 "Filter invalid - %s", df_err
->msg
4958 df_error_free(&df_err
);
4963 if (tok_field
!= NULL
)
4965 header_field_info
*hfi
= proto_registrar_get_byname(tok_field
);
4971 "Field %s not found", tok_field
4977 sharkd_json_simple_ok(rpcid
);
4982 sharkd_json_simple_ok(rpcid
);
4986 struct sharkd_session_process_complete_pref_data
4993 sharkd_session_process_complete_pref_cb(module_t
*module
, gpointer d
)
4995 struct sharkd_session_process_complete_pref_data
*data
= (struct sharkd_session_process_complete_pref_data
*) d
;
4997 if (strncmp(data
->pref
, module
->name
, strlen(data
->pref
)) != 0)
5000 json_dumper_begin_object(&dumper
);
5001 sharkd_json_value_string("f", module
->name
);
5002 sharkd_json_value_string("d", module
->title
);
5003 json_dumper_end_object(&dumper
);
5009 sharkd_session_process_complete_pref_option_cb(pref_t
*pref
, gpointer d
)
5011 struct sharkd_session_process_complete_pref_data
*data
= (struct sharkd_session_process_complete_pref_data
*) d
;
5012 const char *pref_name
= prefs_get_name(pref
);
5013 const char *pref_title
= prefs_get_title(pref
);
5015 if (strncmp(data
->pref
, pref_name
, strlen(data
->pref
)) != 0)
5018 json_dumper_begin_object(&dumper
);
5019 sharkd_json_value_stringf("f", "%s.%s", data
->module
, pref_name
);
5020 sharkd_json_value_string("d", pref_title
);
5021 json_dumper_end_object(&dumper
);
5023 return 0; /* continue */
5027 * sharkd_session_process_complete()
5029 * Process complete request
5032 * (o) field - field to be completed
5033 * (o) pref - preference to be completed
5035 * Output object with attributes:
5036 * (m) err - always 0
5037 * (o) field - array of object with attributes:
5038 * (m) f - field text
5039 * (o) t - field type (FT_ number)
5040 * (o) n - field name
5041 * (o) pref - array of object with attributes:
5043 * (o) d - pref description
5046 sharkd_session_process_complete(char *buf
, const jsmntok_t
*tokens
, int count
)
5048 const char *tok_field
= json_find_attr(buf
, tokens
, count
, "field");
5049 const char *tok_pref
= json_find_attr(buf
, tokens
, count
, "pref");
5051 sharkd_json_result_prologue(rpcid
);
5053 if (tok_field
!= NULL
&& tok_field
[0])
5055 const size_t filter_length
= strlen(tok_field
);
5056 const int filter_with_dot
= !!strchr(tok_field
, '.');
5062 sharkd_json_array_open("field");
5064 for (proto_id
= proto_get_first_protocol(&proto_cookie
); proto_id
!= -1; proto_id
= proto_get_next_protocol(&proto_cookie
))
5066 protocol_t
*protocol
= find_protocol_by_id(proto_id
);
5067 const char *protocol_filter
;
5068 const char *protocol_name
;
5069 header_field_info
*hfinfo
;
5071 if (!proto_is_protocol_enabled(protocol
))
5074 protocol_name
= proto_get_protocol_long_name(protocol
);
5075 protocol_filter
= proto_get_protocol_filter_name(proto_id
);
5077 if (strlen(protocol_filter
) >= filter_length
&& !g_ascii_strncasecmp(tok_field
, protocol_filter
, filter_length
))
5079 json_dumper_begin_object(&dumper
);
5081 sharkd_json_value_string("f", protocol_filter
);
5082 sharkd_json_value_anyf("t", "%d", FT_PROTOCOL
);
5083 sharkd_json_value_string("n", protocol_name
);
5085 json_dumper_end_object(&dumper
);
5088 if (!filter_with_dot
)
5091 for (hfinfo
= proto_get_first_protocol_field(proto_id
, &field_cookie
); hfinfo
!= NULL
; hfinfo
= proto_get_next_protocol_field(proto_id
, &field_cookie
))
5093 if (hfinfo
->same_name_prev_id
!= -1) /* ignore duplicate names */
5096 if (strlen(hfinfo
->abbrev
) >= filter_length
&& !g_ascii_strncasecmp(tok_field
, hfinfo
->abbrev
, filter_length
))
5098 json_dumper_begin_object(&dumper
);
5100 sharkd_json_value_string("f", hfinfo
->abbrev
);
5102 /* XXX, skip displaying name, if there are multiple (to not confuse user) */
5103 if (hfinfo
->same_name_next
== NULL
)
5105 sharkd_json_value_anyf("t", "%d", hfinfo
->type
);
5106 sharkd_json_value_string("n", hfinfo
->name
);
5109 json_dumper_end_object(&dumper
);
5114 sharkd_json_array_close();
5117 if (tok_pref
!= NULL
&& tok_pref
[0])
5119 struct sharkd_session_process_complete_pref_data data
;
5122 data
.module
= tok_pref
;
5123 data
.pref
= tok_pref
;
5125 sharkd_json_array_open("pref");
5126 if ((dot_sepa
= strchr(tok_pref
, '.')))
5130 *dot_sepa
= '\0'; /* XXX, C abuse: discarding-const */
5131 data
.pref
= dot_sepa
+ 1;
5133 pref_mod
= prefs_find_module(data
.module
);
5135 prefs_pref_foreach(pref_mod
, sharkd_session_process_complete_pref_option_cb
, &data
);
5141 prefs_modules_foreach(sharkd_session_process_complete_pref_cb
, &data
);
5143 sharkd_json_array_close();
5146 sharkd_json_result_epilogue();
5152 * sharkd_session_process_setcomment()
5154 * Process setcomment request
5157 * (m) frame - frame number
5158 * (o) comment - user comment
5160 * Output object with attributes:
5161 * (m) err - error code: 0 succeed
5164 * For now, adds comments, doesn't remove or replace them.
5167 sharkd_session_process_setcomment(char *buf
, const jsmntok_t
*tokens
, int count
)
5169 const char *tok_frame
= json_find_attr(buf
, tokens
, count
, "frame");
5170 const char *tok_comment
= json_find_attr(buf
, tokens
, count
, "comment");
5174 wtap_opttype_return_val ret
;
5175 wtap_block_t pkt_block
= NULL
;
5177 if (!tok_frame
|| !ws_strtou32(tok_frame
, NULL
, &framenum
) || framenum
== 0)
5181 "Frame number must be a positive integer"
5186 fdata
= sharkd_get_frame(framenum
); // BUG HERE - If no file loaded you get a crash
5191 "Frame number is out of range"
5196 pkt_block
= sharkd_get_packet_block(fdata
);
5198 ret
= wtap_block_add_string_option(pkt_block
, OPT_COMMENT
, tok_comment
, strlen(tok_comment
));
5200 if (ret
!= WTAP_OPTTYPE_SUCCESS
)
5204 "Unable to set the comment"
5209 sharkd_set_modified_block(fdata
, pkt_block
);
5210 sharkd_json_simple_ok(rpcid
);
5215 * sharkd_session_process_setconf()
5217 * Process setconf request
5220 * (m) name - preference name
5221 * (m) value - preference value
5223 * Output object with attributes:
5224 * (m) err - error code: 0 succeed
5227 sharkd_session_process_setconf(char *buf
, const jsmntok_t
*tokens
, int count
)
5229 const char *tok_name
= json_find_attr(buf
, tokens
, count
, "name");
5230 const char *tok_value
= json_find_attr(buf
, tokens
, count
, "value");
5232 char *errmsg
= NULL
;
5234 prefs_set_pref_e ret
;
5236 if (!tok_name
|| tok_name
[0] == '\0')
5240 "Preference name missing"
5249 "Preference value missing"
5254 snprintf(pref
, sizeof(pref
), "%s:%s", tok_name
, tok_value
);
5256 ret
= prefs_set_pref(pref
, &errmsg
);
5261 sharkd_json_simple_ok(rpcid
);
5264 case PREFS_SET_OBSOLETE
:
5267 "The preference specified is obsolete"
5271 case PREFS_SET_NO_SUCH_PREF
:
5274 "No such preference exists"
5281 "Unable to set the preference"
5288 struct sharkd_session_process_dumpconf_data
5294 sharkd_session_process_dumpconf_cb(pref_t
*pref
, gpointer d
)
5296 struct sharkd_session_process_dumpconf_data
*data
= (struct sharkd_session_process_dumpconf_data
*) d
;
5297 const char *pref_name
= prefs_get_name(pref
);
5299 char json_pref_key
[512];
5301 snprintf(json_pref_key
, sizeof(json_pref_key
), "%s.%s", data
->module
->name
, pref_name
);
5302 sharkd_json_object_open(json_pref_key
);
5304 switch (prefs_get_type(pref
))
5307 sharkd_json_value_anyf("u", "%u", prefs_get_uint_value_real(pref
, pref_current
));
5308 if (prefs_get_uint_base(pref
) != 10)
5309 sharkd_json_value_anyf("ub", "%u", prefs_get_uint_base(pref
));
5313 sharkd_json_value_anyf("b", prefs_get_bool_value(pref
, pref_current
) ? "1" : "0");
5317 case PREF_SAVE_FILENAME
:
5318 case PREF_OPEN_FILENAME
:
5321 case PREF_DISSECTOR
:
5322 sharkd_json_value_string("s", prefs_get_string_value(pref
, pref_current
));
5327 const enum_val_t
*enums
;
5329 sharkd_json_array_open("e");
5330 for (enums
= prefs_get_enumvals(pref
); enums
->name
; enums
++)
5332 json_dumper_begin_object(&dumper
);
5334 sharkd_json_value_anyf("v", "%d", enums
->value
);
5336 if (enums
->value
== prefs_get_enum_value(pref
, pref_current
))
5337 sharkd_json_value_anyf("s", "1");
5339 sharkd_json_value_string("d", enums
->description
);
5341 json_dumper_end_object(&dumper
);
5343 sharkd_json_array_close();
5348 case PREF_DECODE_AS_RANGE
:
5350 char *range_str
= range_convert_range(NULL
, prefs_get_range_value_real(pref
, pref_current
));
5351 sharkd_json_value_string("r", range_str
);
5352 wmem_free(NULL
, range_str
);
5358 uat_t
*uat
= prefs_get_uat_value(pref
);
5361 sharkd_json_array_open("t");
5362 for (idx
= 0; idx
< uat
->raw_data
->len
; idx
++)
5364 void *rec
= UAT_INDEX_PTR(uat
, idx
);
5367 sharkd_json_array_open(NULL
);
5368 for (colnum
= 0; colnum
< uat
->ncols
; colnum
++)
5370 char *str
= uat_fld_tostr(rec
, &(uat
->fields
[colnum
]));
5372 sharkd_json_value_string(NULL
, str
);
5376 sharkd_json_array_close();
5379 sharkd_json_array_close();
5385 case PREF_STATIC_TEXT
:
5392 sharkd_json_value_string("t", prefs_get_title(pref
));
5395 sharkd_json_object_close();
5397 return 0; /* continue */
5401 sharkd_session_process_dumpconf_mod_cb(module_t
*module
, gpointer d
)
5403 struct sharkd_session_process_dumpconf_data
*data
= (struct sharkd_session_process_dumpconf_data
*) d
;
5405 data
->module
= module
;
5406 prefs_pref_foreach(module
, sharkd_session_process_dumpconf_cb
, data
);
5412 * sharkd_session_process_dumpconf()
5414 * Process dumpconf request
5417 * (o) pref - module, or preference, NULL for all
5419 * Output object with attributes:
5420 * (o) prefs - object with module preferences
5421 * (m) [KEY] - preference name
5422 * (o) u - preference value (for PREF_UINT)
5423 * (o) ub - preference value suggested base for display (for PREF_UINT) and if different than 10
5424 * (o) b - preference value (only for PREF_BOOL) (1 true, 0 false)
5425 * (o) s - preference value (for PREF_STRING, PREF_SAVE_FILENAME, PREF_OPEN_FILENAME, PREF_DIRNAME, PREF_PASSWORD, PREF_DISSECTOR)
5426 * (o) e - preference possible values (only for PREF_ENUM)
5427 * (o) r - preference value (for PREF_RANGE, PREF_DECODE_AS_RANGE)
5428 * (o) t - preference value (only for PREF_UAT)
5431 sharkd_session_process_dumpconf(char *buf
, const jsmntok_t
*tokens
, int count
)
5433 const char *tok_pref
= json_find_attr(buf
, tokens
, count
, "pref");
5439 struct sharkd_session_process_dumpconf_data data
;
5443 sharkd_json_result_prologue(rpcid
);
5445 sharkd_json_object_open("prefs");
5446 prefs_modules_foreach(sharkd_session_process_dumpconf_mod_cb
, &data
);
5447 sharkd_json_object_close();
5449 sharkd_json_result_epilogue();
5453 if ((dot_sepa
= strchr(tok_pref
, '.')))
5455 pref_t
*pref
= NULL
;
5457 *dot_sepa
= '\0'; /* XXX, C abuse: discarding-const */
5458 pref_mod
= prefs_find_module(tok_pref
);
5460 pref
= prefs_find_preference(pref_mod
, dot_sepa
+ 1);
5465 struct sharkd_session_process_dumpconf_data data
;
5467 data
.module
= pref_mod
;
5469 sharkd_json_result_prologue(rpcid
);
5471 sharkd_json_object_open("prefs");
5472 sharkd_session_process_dumpconf_cb(pref
, &data
);
5473 sharkd_json_object_close();
5475 sharkd_json_result_epilogue();
5482 "Invalid pref %s.", tok_pref
5489 pref_mod
= prefs_find_module(tok_pref
);
5492 struct sharkd_session_process_dumpconf_data data
;
5494 data
.module
= pref_mod
;
5496 sharkd_json_result_prologue(rpcid
);
5498 sharkd_json_object_open("prefs");
5499 prefs_pref_foreach(pref_mod
, sharkd_session_process_dumpconf_cb
, &data
);
5500 sharkd_json_object_close();
5502 sharkd_json_result_epilogue();
5508 "Invalid pref %s.", tok_pref
5513 struct sharkd_download_rtp
5521 sharkd_rtp_download_free_items(void *ptr
)
5523 rtp_packet_t
*rtp_packet
= (rtp_packet_t
*) ptr
;
5525 g_free(rtp_packet
->info
);
5526 g_free(rtp_packet
->payload_data
);
5531 sharkd_rtp_download_decode(struct sharkd_download_rtp
*req
)
5533 /* based on RtpAudioStream::decode() 6e29d874f8b5e6ebc59f661a0bb0dab8e56f122a */
5534 /* TODO, for now only without silence (timing_mode_ = Uninterrupted) */
5536 static const int sample_bytes_
= sizeof(SAMPLE
) / sizeof(char);
5538 guint32 audio_out_rate_
= 0;
5539 struct _GHashTable
*decoders_hash_
= rtp_decoder_hash_table_new();
5540 struct SpeexResamplerState_
*audio_resampler_
= NULL
;
5542 gsize resample_buff_len
= 0x1000;
5543 SAMPLE
*resample_buff
= (SAMPLE
*) g_malloc(resample_buff_len
);
5544 spx_uint32_t cur_in_rate
= 0;
5545 char *write_buff
= NULL
;
5546 size_t write_bytes
= 0;
5547 unsigned channels
= 0;
5548 unsigned sample_rate
= 0;
5552 for (l
= req
->packets
; l
; l
= l
->next
)
5554 rtp_packet_t
*rtp_packet
= (rtp_packet_t
*) l
->data
;
5556 SAMPLE
*decode_buff
= NULL
;
5557 size_t decoded_bytes
;
5559 decoded_bytes
= decode_rtp_packet(rtp_packet
, &decode_buff
, decoders_hash_
, &channels
, &sample_rate
);
5560 if (decoded_bytes
== 0 || sample_rate
== 0)
5562 /* We didn't decode anything. Clean up and prep for the next packet. */
5563 g_free(decode_buff
);
5567 if (audio_out_rate_
== 0)
5573 /* First non-zero wins */
5574 audio_out_rate_
= sample_rate
;
5576 RTP_STREAM_DEBUG("Audio sample rate is %u", audio_out_rate_
);
5578 /* write WAVE header */
5579 memset(&wav_hdr
, 0, sizeof(wav_hdr
));
5580 memcpy(&wav_hdr
[0], "RIFF", 4);
5581 memcpy(&wav_hdr
[4], "\xFF\xFF\xFF\xFF", 4); /* XXX, unknown */
5582 memcpy(&wav_hdr
[8], "WAVE", 4);
5584 memcpy(&wav_hdr
[12], "fmt ", 4);
5585 memcpy(&wav_hdr
[16], "\x10\x00\x00\x00", 4); /* PCM */
5586 memcpy(&wav_hdr
[20], "\x01\x00", 2); /* PCM */
5589 memcpy(&wav_hdr
[22], &tmp16
, 2);
5591 tmp32
= sample_rate
;
5592 memcpy(&wav_hdr
[24], &tmp32
, 4);
5594 tmp32
= sample_rate
* channels
* sample_bytes_
;
5595 memcpy(&wav_hdr
[28], &tmp32
, 4);
5597 tmp16
= channels
* sample_bytes_
;
5598 memcpy(&wav_hdr
[32], &tmp16
, 2);
5599 /* bits per sample */
5600 tmp16
= 8 * sample_bytes_
;
5601 memcpy(&wav_hdr
[34], &tmp16
, 2);
5603 memcpy(&wav_hdr
[36], "data", 4);
5604 memcpy(&wav_hdr
[40], "\xFF\xFF\xFF\xFF", 4); /* XXX, unknown */
5606 json_dumper_write_base64(&dumper
, wav_hdr
, sizeof(wav_hdr
));
5609 // Write samples to our file.
5610 write_buff
= (char *) decode_buff
;
5611 write_bytes
= decoded_bytes
;
5613 if (audio_out_rate_
!= sample_rate
)
5615 spx_uint32_t in_len
, out_len
;
5617 /* Resample the audio to match our previous output rate. */
5618 if (!audio_resampler_
)
5620 audio_resampler_
= speex_resampler_init(1, sample_rate
, audio_out_rate_
, 10, NULL
);
5621 speex_resampler_skip_zeros(audio_resampler_
);
5622 RTP_STREAM_DEBUG("Started resampling from %u to (out) %u Hz.", sample_rate
, audio_out_rate_
);
5626 spx_uint32_t audio_out_rate
;
5627 speex_resampler_get_rate(audio_resampler_
, &cur_in_rate
, &audio_out_rate
);
5629 if (sample_rate
!= cur_in_rate
)
5631 speex_resampler_set_rate(audio_resampler_
, sample_rate
, audio_out_rate
);
5632 RTP_STREAM_DEBUG("Changed input rate from %u to %u Hz. Out is %u.", cur_in_rate
, sample_rate
, audio_out_rate_
);
5635 in_len
= (spx_uint32_t
)rtp_packet
->info
->info_payload_len
;
5636 out_len
= (audio_out_rate_
* (spx_uint32_t
)rtp_packet
->info
->info_payload_len
/ sample_rate
) + (audio_out_rate_
% sample_rate
!= 0);
5637 if (out_len
* sample_bytes_
> resample_buff_len
)
5639 while ((out_len
* sample_bytes_
> resample_buff_len
))
5640 resample_buff_len
*= 2;
5641 resample_buff
= (SAMPLE
*) g_realloc(resample_buff
, resample_buff_len
);
5644 speex_resampler_process_int(audio_resampler_
, 0, decode_buff
, &in_len
, resample_buff
, &out_len
);
5645 write_buff
= (char *) resample_buff
;
5646 write_bytes
= out_len
* sample_bytes_
;
5649 /* Write the decoded, possibly-resampled audio */
5650 json_dumper_write_base64(&dumper
, write_buff
, write_bytes
);
5652 g_free(decode_buff
);
5655 g_free(resample_buff
);
5656 g_hash_table_destroy(decoders_hash_
);
5659 static tap_packet_status
5660 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_
)
5662 const struct _rtp_info
*rtp_info
= (const struct _rtp_info
*) data
;
5663 struct sharkd_download_rtp
*req_rtp
= (struct sharkd_download_rtp
*) tapdata
;
5665 /* do not consider RTP packets without a setup frame */
5666 if (rtp_info
->info_setup_frame_num
== 0)
5667 return TAP_PACKET_DONT_REDRAW
;
5669 if (rtpstream_id_equal_pinfo_rtp_info(&req_rtp
->id
, pinfo
, rtp_info
))
5671 rtp_packet_t
*rtp_packet
;
5673 rtp_packet
= g_new0(rtp_packet_t
, 1);
5674 rtp_packet
->info
= (struct _rtp_info
*) g_memdup2(rtp_info
, sizeof(struct _rtp_info
));
5676 if (rtp_info
->info_all_data_present
&& rtp_info
->info_payload_len
!= 0)
5677 rtp_packet
->payload_data
= (guint8
*) g_memdup2(&(rtp_info
->info_data
[rtp_info
->info_payload_offset
]), rtp_info
->info_payload_len
);
5679 if (!req_rtp
->packets
)
5680 req_rtp
->start_time
= nstime_to_sec(&pinfo
->abs_ts
);
5682 rtp_packet
->frame_num
= pinfo
->num
;
5683 rtp_packet
->arrive_offset
= nstime_to_sec(&pinfo
->abs_ts
) - req_rtp
->start_time
;
5685 /* XXX, O(n) optimize */
5686 req_rtp
->packets
= g_slist_append(req_rtp
->packets
, rtp_packet
);
5689 return TAP_PACKET_DONT_REDRAW
;
5693 sharkd_session_eo_retap_listener(const char *tap_type
) {
5695 register_eo_t
*eo
= NULL
;
5696 GString
*tap_error
= NULL
;
5697 void *tap_data
= NULL
;
5698 GFreeFunc tap_free
= NULL
;
5700 // get <name> from eo:<name>, get_eo_by_name only needs the name (http etc.)
5701 eo
= get_eo_by_name(tap_type
+ 3);
5706 rpcid
, -11011, NULL
,
5707 "sharkd_session_eo_retap_listener() eo=%s not found", tap_type
+ 3
5713 tap_error
= sharkd_session_eo_register_tap_listener(eo
, tap_type
, NULL
, NULL
, &tap_data
, &tap_free
);
5718 rpcid
, -10002, NULL
,
5719 "sharkd_session_eo_retap_listener() sharkd_session_eo_register_tap_listener error %s",
5721 g_string_free(tap_error
, TRUE
);
5729 remove_tap_listener(tap_data
);
5738 * sharkd_session_process_download()
5740 * Process download request
5743 * (m) token - token to download
5745 * Output object with attributes:
5746 * (o) file - suggested name of file
5747 * (o) mime - suggested content type
5748 * (o) data - payload base64 encoded
5751 sharkd_session_process_download(char *buf
, const jsmntok_t
*tokens
, int count
)
5753 const char *tok_token
= json_find_attr(buf
, tokens
, count
, "token");
5758 rpcid
, -10005, NULL
,
5764 if (!strncmp(tok_token
, "eo:", 3))
5766 // get eo:<name> from eo:<name>_<row>
5767 char *tap_type
= g_strdup(tok_token
);
5768 char *tmp
= strrchr(tap_type
, '_');
5772 // if eo:<name> not in sharkd_eo_list, retap
5773 if (!sharkd_eo_object_list_get_entry_by_type(sharkd_eo_list
, tap_type
) &&
5774 !sharkd_session_eo_retap_listener(tap_type
))
5777 // sharkd_json_error called in sharkd_session_eo_retap_listener
5783 struct sharkd_export_object_list
*object_list
;
5784 const export_object_entry_t
*eo_entry
= NULL
;
5786 for (object_list
= sharkd_eo_list
; object_list
; object_list
= object_list
->next
)
5788 size_t eo_type_len
= strlen(object_list
->type
);
5790 if (!strncmp(tok_token
, object_list
->type
, eo_type_len
) && tok_token
[eo_type_len
] == '_')
5794 if (sscanf(&tok_token
[eo_type_len
+ 1], "%d", &row
) != 1)
5797 eo_entry
= (export_object_entry_t
*) g_slist_nth_data(object_list
->entries
, row
);
5804 const char *mime
= (eo_entry
->content_type
) ? eo_entry
->content_type
: "application/octet-stream";
5805 const char *filename
= (eo_entry
->filename
) ? eo_entry
->filename
: tok_token
;
5807 sharkd_json_result_prologue(rpcid
);
5808 sharkd_json_value_string("file", filename
);
5809 sharkd_json_value_string("mime", mime
);
5810 sharkd_json_value_base64("data", eo_entry
->payload_data
, eo_entry
->payload_len
);
5811 sharkd_json_result_epilogue();
5815 sharkd_json_result_prologue(rpcid
);
5816 sharkd_json_result_epilogue();
5819 else if (!strcmp(tok_token
, "ssl-secrets"))
5822 char *str
= ssl_export_sessions(&str_len
);
5826 const char *mime
= "text/plain";
5827 const char *filename
= "keylog.txt";
5829 sharkd_json_result_prologue(rpcid
);
5830 sharkd_json_value_string("file", filename
);
5831 sharkd_json_value_string("mime", mime
);
5832 sharkd_json_value_base64("data", str
, str_len
);
5833 sharkd_json_result_epilogue();
5837 else if (!strncmp(tok_token
, "rtp:", 4))
5839 struct sharkd_download_rtp rtp_req
;
5842 memset(&rtp_req
, 0, sizeof(rtp_req
));
5843 if (!sharkd_rtp_match_init(&rtp_req
.id
, tok_token
+ 4))
5846 rpcid
, -10001, NULL
,
5847 "sharkd_session_process_download() rtp tokenizing error %s", tok_token
5852 tap_error
= register_tap_listener("rtp", &rtp_req
, NULL
, 0, NULL
, sharkd_session_packet_download_tap_rtp_cb
, NULL
, NULL
);
5856 rpcid
, -10002, NULL
,
5857 "sharkd_session_process_download() rtp error %s", tap_error
->str
5859 g_string_free(tap_error
, TRUE
);
5864 remove_tap_listener(&rtp_req
);
5866 if (rtp_req
.packets
)
5868 const char *mime
= "audio/x-wav";
5869 const char *filename
= tok_token
;
5871 sharkd_json_result_prologue(rpcid
);
5872 sharkd_json_value_string("file", filename
);
5873 sharkd_json_value_string("mime", mime
);
5875 json_dumper_set_member_name(&dumper
, "data");
5876 json_dumper_begin_base64(&dumper
);
5877 sharkd_rtp_download_decode(&rtp_req
);
5878 json_dumper_end_base64(&dumper
);
5880 sharkd_json_result_epilogue();
5882 g_slist_free_full(rtp_req
.packets
, sharkd_rtp_download_free_items
);
5887 rpcid
, -10003, NULL
,
5888 "no rtp data available"
5895 rpcid
, -10004, NULL
,
5896 "unrecognized token"
5902 sharkd_session_process(char *buf
, const jsmntok_t
*tokens
, int count
)
5904 if (json_prep(buf
, tokens
, count
))
5906 /* don't need [0] token */
5910 const char* tok_method
= json_find_attr(buf
, tokens
, count
, "method");
5914 rpcid
, -32601, NULL
,
5918 if (!strcmp(tok_method
, "load"))
5919 sharkd_session_process_load(buf
, tokens
, count
);
5920 else if (!strcmp(tok_method
, "status"))
5921 sharkd_session_process_status();
5922 else if (!strcmp(tok_method
, "analyse"))
5923 sharkd_session_process_analyse();
5924 else if (!strcmp(tok_method
, "info"))
5925 sharkd_session_process_info();
5926 else if (!strcmp(tok_method
, "check"))
5927 sharkd_session_process_check(buf
, tokens
, count
);
5928 else if (!strcmp(tok_method
, "complete"))
5929 sharkd_session_process_complete(buf
, tokens
, count
);
5930 else if (!strcmp(tok_method
, "frames"))
5931 sharkd_session_process_frames(buf
, tokens
, count
);
5932 else if (!strcmp(tok_method
, "tap"))
5933 sharkd_session_process_tap(buf
, tokens
, count
);
5934 else if (!strcmp(tok_method
, "follow"))
5935 sharkd_session_process_follow(buf
, tokens
, count
);
5936 else if (!strcmp(tok_method
, "iograph"))
5937 sharkd_session_process_iograph(buf
, tokens
, count
);
5938 else if (!strcmp(tok_method
, "intervals"))
5939 sharkd_session_process_intervals(buf
, tokens
, count
);
5940 else if (!strcmp(tok_method
, "frame"))
5941 sharkd_session_process_frame(buf
, tokens
, count
);
5942 else if (!strcmp(tok_method
, "setcomment"))
5943 sharkd_session_process_setcomment(buf
, tokens
, count
);
5944 else if (!strcmp(tok_method
, "setconf"))
5945 sharkd_session_process_setconf(buf
, tokens
, count
);
5946 else if (!strcmp(tok_method
, "dumpconf"))
5947 sharkd_session_process_dumpconf(buf
, tokens
, count
);
5948 else if (!strcmp(tok_method
, "download"))
5949 sharkd_session_process_download(buf
, tokens
, count
);
5950 else if (!strcmp(tok_method
, "bye"))
5952 sharkd_json_simple_ok(rpcid
);
5958 rpcid
, -32601, NULL
,
5959 "The method \"%s\" is unknown", tok_method
5966 sharkd_session_main(int mode_setting
)
5969 jsmntok_t
*tokens
= NULL
;
5970 int tokens_max
= -1;
5972 mode
= mode_setting
;
5974 fprintf(stderr
, "Hello in child.\n");
5976 dumper
.output_file
= stdout
;
5978 filter_table
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, sharkd_session_filter_free
);
5980 #ifdef HAVE_MAXMINDDB
5981 /* mmdbresolve was stopped before fork(), force starting it */
5982 uat_get_table_by_name("MaxMind Database Paths")->post_update_cb();
5985 set_resolution_synchrony(TRUE
);
5987 while (fgets(buf
, sizeof(buf
), stdin
))
5989 /* every command is line separated JSON */
5992 ret
= json_parse(buf
, NULL
, 0);
5996 rpcid
, -32600, NULL
,
6002 /* fprintf(stderr, "JSON: %d tokens\n", ret); */
6005 if (tokens
== NULL
|| tokens_max
< ret
)
6008 tokens
= (jsmntok_t
*) g_realloc(tokens
, sizeof(jsmntok_t
) * tokens_max
);
6011 memset(tokens
, 0, ret
* sizeof(jsmntok_t
));
6013 ret
= json_parse(buf
, tokens
, ret
);
6017 rpcid
, -32600, NULL
,
6023 host_name_lookup_process();
6025 sharkd_session_process(buf
, tokens
, ret
);
6028 g_hash_table_destroy(filter_table
);