3 * Copyright (C) 2016 Jakub Zawadzki
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <wsutil/wsjsmn.h>
34 #include <wsutil/ws_printf.h>
37 #include <epan/exceptions.h>
38 #include <epan/color_filters.h>
39 #include <epan/prefs.h>
40 #include <epan/prefs-int.h>
41 #include <epan/uat-int.h>
42 #include <wiretap/wtap.h>
44 #include <epan/column.h>
46 #include <ui/ssl_key_export.h>
48 #include <epan/stats_tree_priv.h>
49 #include <epan/stat_tap_ui.h>
50 #include <epan/conversation_table.h>
51 #include <epan/expert.h>
52 #include <epan/export_object.h>
53 #include <epan/follow.h>
54 #include <epan/rtd_table.h>
55 #include <epan/srt_table.h>
57 #include <epan/dissectors/packet-h225.h>
58 #include <epan/rtp_pt.h>
59 #include <ui/voip_calls.h>
60 #include <ui/rtp_stream.h>
61 #include <ui/tap-rtp-common.h>
62 #include <epan/to_str.h>
64 #include <epan/addr_resolv.h>
65 #include <epan/dissectors/packet-rtp.h>
66 #include <ui/rtp_media.h>
67 #include <codecs/speex/speex_resampler.h>
71 # include <epan/geoip_db.h>
72 # include <wsutil/pint.h>
75 #include <wsutil/glib-compat.h>
76 #include <wsutil/strtoi.h>
81 json_unescape_str(char *input)
91 /* TODO, add more escaping rules */
103 json_find_attr(const char *buf, const jsmntok_t *tokens, int count, const char *attr)
107 for (i = 0; i < count; i += 2)
109 const char *tok_attr = &buf[tokens[i + 0].start];
110 const char *tok_value = &buf[tokens[i + 1].start];
112 if (!strcmp(tok_attr, attr))
120 json_puts_string(const char *str)
128 for (i = 0; str[i]; i++)
153 json_print_base64_step(const guint8 *data, int *state1, int *state2)
155 gchar buf[(1 / 3 + 1) * 4 + 4 + 1];
159 wrote = g_base64_encode_step(data, 1, FALSE, buf, state1, state2);
161 wrote = g_base64_encode_close(FALSE, buf, state1, state2);
171 json_print_base64(const guint8 *data, size_t len)
174 int base64_state1 = 0;
175 int base64_state2 = 0;
179 for (i = 0; i < len; i++)
180 json_print_base64_step(&data[i], &base64_state1, &base64_state2);
182 json_print_base64_step(NULL, &base64_state1, &base64_state2);
189 struct filter_item *next;
195 static struct filter_item *filter_list = NULL;
197 static const guint8 *
198 sharkd_session_filter_data(const char *filter)
200 struct filter_item *l;
202 for (l = filter_list; l; l = l->next)
204 if (!strcmp(l->filter, filter))
209 guint8 *filtered = NULL;
211 int ret = sharkd_filter(filter, &filtered);
216 l = (struct filter_item *) g_malloc(sizeof(struct filter_item));
217 l->filter = g_strdup(filter);
218 l->filtered = filtered;
220 l->next = filter_list;
227 struct sharkd_rtp_match
229 guint32 addr_src, addr_dst;
238 sharkd_rtp_match_init(struct sharkd_rtp_match *req, const char *init_str)
240 gboolean ret = FALSE;
243 arr = g_strsplit(init_str, "_", 7); /* pass larger value, so we'll catch incorrect input :) */
244 if (g_strv_length(arr) != 5)
247 /* TODO, for now only IPv4 */
248 if (!get_host_ipaddr(arr[0], &req->addr_src))
251 if (!ws_strtou16(arr[1], NULL, &req->src_port))
254 if (!get_host_ipaddr(arr[2], &req->addr_dst))
257 if (!ws_strtou16(arr[3], NULL, &req->dst_port))
260 if (!ws_hexstrtou32(arr[4], NULL, &req->ssrc))
263 set_address(&req->src_addr, AT_IPv4, 4, &req->addr_src);
264 set_address(&req->dst_addr, AT_IPv4, 4, &req->addr_dst);
273 sharkd_rtp_match_check(const struct sharkd_rtp_match *req, const packet_info *pinfo, const struct _rtp_info *rtp_info)
275 if (rtp_info->info_sync_src == req->ssrc &&
276 pinfo->srcport == req->src_port &&
277 pinfo->destport == req->dst_port &&
278 addresses_equal(&pinfo->src, &req->src_addr) &&
279 addresses_equal(&pinfo->dst, &req->dst_addr))
288 sharkd_session_process_info_nstat_cb(const void *key, void *value, void *userdata)
290 stat_tap_table_ui *new_stat_tap = (stat_tap_table_ui *) value;
291 int *pi = (int *) userdata;
293 printf("%s{", (*pi) ? "," : "");
294 printf("\"name\":\"%s\"", new_stat_tap->title);
295 printf(",\"tap\":\"nstat:%s\"", (const char *) key);
303 sharkd_session_process_info_conv_cb(const void* key, void* value, void* userdata)
305 struct register_ct *table = (struct register_ct *) value;
306 int *pi = (int *) userdata;
308 const char *label = (const char*)key;
310 if (get_conversation_packet_func(table))
312 printf("%s{", (*pi) ? "," : "");
313 printf("\"name\":\"Conversation List/%s\"", label);
314 printf(",\"tap\":\"conv:%s\"", label);
320 if (get_hostlist_packet_func(table))
322 printf("%s{", (*pi) ? "," : "");
323 printf("\"name\":\"Endpoint/%s\"", label);
324 printf(",\"tap\":\"endpt:%s\"", label);
333 sharkd_export_object_visit_cb(const void *key _U_, void *value, void *user_data)
335 register_eo_t *eo = (register_eo_t*)value;
336 int *pi = (int *) user_data;
338 const int proto_id = get_eo_proto_id(eo);
339 const char *filter = proto_get_protocol_filter_name(proto_id);
340 const char *label = proto_get_protocol_short_name(find_protocol_by_id(proto_id));
342 printf("%s{", (*pi) ? "," : "");
343 printf("\"name\":\"Export Object/%s\"", label);
344 printf(",\"tap\":\"eo:%s\"", filter);
352 sharkd_srt_visit_cb(const void *key _U_, void *value, void *user_data)
354 register_srt_t *srt = (register_srt_t *) value;
355 int *pi = (int *) user_data;
357 const int proto_id = get_srt_proto_id(srt);
358 const char *filter = proto_get_protocol_filter_name(proto_id);
359 const char *label = proto_get_protocol_short_name(find_protocol_by_id(proto_id));
361 printf("%s{", (*pi) ? "," : "");
362 printf("\"name\":\"Service Response Time/%s\"", label);
363 printf(",\"tap\":\"srt:%s\"", filter);
371 sharkd_rtd_visit_cb(const void *key _U_, void *value, void *user_data)
373 register_rtd_t *rtd = (register_rtd_t *) value;
374 int *pi = (int *) user_data;
376 const int proto_id = get_rtd_proto_id(rtd);
377 const char *filter = proto_get_protocol_filter_name(proto_id);
378 const char *label = proto_get_protocol_short_name(find_protocol_by_id(proto_id));
380 printf("%s{", (*pi) ? "," : "");
381 printf("\"name\":\"Response Time Delay/%s\"", label);
382 printf(",\"tap\":\"rtd:%s\"", filter);
390 sharkd_follower_visit_cb(const void *key _U_, void *value, void *user_data)
392 register_follow_t *follower = (register_follow_t*) value;
393 int *pi = (int *) user_data;
395 const int proto_id = get_follow_proto_id(follower);
396 const char *label = proto_get_protocol_short_name(find_protocol_by_id(proto_id));
397 const char *filter = label; /* correct: get_follow_by_name() is registered by short name */
399 printf("%s{", (*pi) ? "," : "");
400 printf("\"name\":\"Follow/%s\"", label);
401 printf(",\"tap\":\"follow:%s\"", filter);
409 * sharkd_session_process_info()
411 * Process info request
413 * Output object with attributes:
414 * (m) columns - available column formats, array of object with attributes:
415 * 'name' - column name
416 * 'format' - column format-name
418 * (m) stats - available statistics, array of object with attributes:
419 * 'name' - statistic name
420 * 'tap' - sharkd tap-name for statistic
422 * (m) convs - available conversation list, array of object with attributes:
423 * 'name' - conversation name
424 * 'tap' - sharkd tap-name for conversation
426 * (m) eo - available export object list, array of object with attributes:
427 * 'name' - export object name
428 * 'tap' - sharkd tap-name for eo
430 * (m) srt - available service response time list, array of object with attributes:
431 * 'name' - service response time name
432 * 'tap' - sharkd tap-name for srt
434 * (m) rtd - available response time delay list, array of object with attributes:
435 * 'name' - response time delay name
436 * 'tap' - sharkd tap-name for rtd
438 * (m) taps - available taps, array of object with attributes:
440 * 'tap' - sharkd tap-name
442 * (m) follow - available followers, array of object with attributes:
444 * 'tap' - sharkd tap-name
446 * (m) ftypes - conversation table for FT_ number to string
449 sharkd_session_process_info(void)
453 printf("{\"columns\":[");
454 for (i = 0; i < NUM_COL_FMTS; i++)
456 const char *col_format = col_format_to_string(i);
457 const char *col_descr = col_format_desc(i);
459 printf("%s{", (i) ? "," : "");
460 printf("\"name\":\"%s\"", col_descr);
461 printf(",\"format\":\"%s\"", col_format);
466 printf(",\"stats\":[");
468 GList *cfg_list = stats_tree_get_cfg_list();
470 const char *sepa = "";
472 for (l = cfg_list; l; l = l->next)
474 stats_tree_cfg *cfg = (stats_tree_cfg *) l->data;
477 printf("\"name\":\"%s\"", cfg->name);
478 printf(",\"tap\":\"stat:%s\"", cfg->abbr);
483 g_list_free(cfg_list);
487 printf(",\"ftypes\":[");
488 for (i = 0; i < FT_NUM_TYPES; i++)
492 json_puts_string(ftype_name((ftenum_t) i));
496 printf(",\"version\":");
497 json_puts_string(sharkd_version());
499 printf(",\"nstat\":[");
501 new_stat_tap_iterate_tables(sharkd_session_process_info_nstat_cb, &i);
504 printf(",\"convs\":[");
506 conversation_table_iterate_tables(sharkd_session_process_info_conv_cb, &i);
509 printf(",\"taps\":[");
511 printf("{\"name\":\"%s\",\"tap\":\"%s\"}", "RTP streams", "rtp-streams");
512 printf(",{\"name\":\"%s\",\"tap\":\"%s\"}", "Expert Information", "expert");
518 eo_iterate_tables(sharkd_export_object_visit_cb, &i);
521 printf(",\"srt\":[");
523 srt_table_iterate_tables(sharkd_srt_visit_cb, &i);
526 printf(",\"rtd\":[");
528 rtd_table_iterate_tables(sharkd_rtd_visit_cb, &i);
531 printf(",\"follow\":[");
533 follow_iterate_followers(sharkd_follower_visit_cb, &i);
540 * sharkd_session_process_load()
542 * Process load request
545 * (m) file - file to be loaded
547 * Output object with attributes:
548 * (m) err - error code
551 sharkd_session_process_load(const char *buf, const jsmntok_t *tokens, int count)
553 const char *tok_file = json_find_attr(buf, tokens, count, "file");
556 fprintf(stderr, "load: filename=%s\n", tok_file);
561 if (sharkd_cf_open(tok_file, WTAP_TYPE_AUTO, FALSE, &err) != CF_OK)
563 printf("{\"err\":%d}\n", err);
569 err = sharkd_load_cap_file();
571 CATCH(OutOfMemoryError)
573 fprintf(stderr, "load: OutOfMemoryError\n");
578 printf("{\"err\":%d}\n", err);
582 * sharkd_session_process_status()
584 * Process status request
586 * Output object with attributes:
587 * (m) frames - count of currently loaded frames
588 * (m) duration - time difference between time of first frame, and last loaded frame
589 * (o) filename - capture filename
590 * (o) filesize - capture filesize
593 sharkd_session_process_status(void)
595 printf("{\"frames\":%u", cfile.count);
597 printf(",\"duration\":%.9f", nstime_to_sec(&cfile.elapsed_time));
601 char *name = g_path_get_basename(cfile.filename);
603 printf(",\"filename\":");
604 json_puts_string(name);
610 gint64 file_size = wtap_file_size(cfile.wth, NULL);
613 printf(",\"filesize\":%" G_GINT64_FORMAT, file_size);
619 struct sharkd_analyse_data
621 GHashTable *protocols_set;
622 nstime_t *first_time;
627 sharkd_session_process_analyse_cb(packet_info *pi, proto_tree *tree, struct epan_column_info *cinfo, const GSList *data_src, void *data)
629 struct sharkd_analyse_data *analyser = (struct sharkd_analyse_data *) data;
630 frame_data *fdata = pi->fd;
636 if (analyser->first_time == NULL || nstime_cmp(&fdata->abs_ts, analyser->first_time) < 0)
637 analyser->first_time = &fdata->abs_ts;
639 if (analyser->last_time == NULL || nstime_cmp(&fdata->abs_ts, analyser->last_time) > 0)
640 analyser->last_time = &fdata->abs_ts;
644 wmem_list_frame_t *frame;
646 for (frame = wmem_list_head(pi->layers); frame; frame = wmem_list_frame_next(frame))
648 int proto_id = GPOINTER_TO_UINT(wmem_list_frame_data(frame));
650 if (!g_hash_table_lookup_extended(analyser->protocols_set, GUINT_TO_POINTER(proto_id), NULL, NULL))
652 g_hash_table_insert(analyser->protocols_set, GUINT_TO_POINTER(proto_id), GUINT_TO_POINTER(proto_id));
654 if (g_hash_table_size(analyser->protocols_set) != 1)
656 json_puts_string(proto_get_protocol_filter_name(proto_id));
664 * sharkd_session_process_status()
666 * Process analyse request
668 * Output object with attributes:
669 * (m) frames - count of currently loaded frames
670 * (m) protocols - protocol list
671 * (m) first - earliest frame time
672 * (m) last - latest frame time
675 sharkd_session_process_analyse(void)
677 unsigned int framenum;
678 struct sharkd_analyse_data analyser;
680 analyser.first_time = NULL;
681 analyser.last_time = NULL;
682 analyser.protocols_set = g_hash_table_new(NULL /* g_direct_hash() */, NULL /* g_direct_equal */);
684 printf("{\"frames\":%u", cfile.count);
686 printf(",\"protocols\":[");
687 for (framenum = 1; framenum <= cfile.count; framenum++)
688 sharkd_dissect_request(framenum, &sharkd_session_process_analyse_cb, 0, 0, 0, &analyser);
691 if (analyser.first_time)
692 printf(",\"first\":%.9f", nstime_to_sec(analyser.first_time));
694 if (analyser.last_time)
695 printf(",\"last\":%.9f", nstime_to_sec(analyser.last_time));
699 g_hash_table_destroy(analyser.protocols_set);
703 * sharkd_session_process_frames()
705 * Process frames request
708 * (o) filter - filter to be used
709 * (o) skip=N - skip N frames
710 * (o) limit=N - show only N frames
712 * Output array of frames with attributes:
713 * (m) c - array of column data
714 * (m) num - frame number
715 * (m) i - if frame is ignored
716 * (m) m - if frame is marked
717 * (m) bg - color filter - background color in hex
718 * (m) fg - color filter - foreground color in hex
721 sharkd_session_process_frames(const char *buf, const jsmntok_t *tokens, int count)
723 const char *tok_filter = json_find_attr(buf, tokens, count, "filter");
724 const char *tok_skip = json_find_attr(buf, tokens, count, "skip");
725 const char *tok_limit = json_find_attr(buf, tokens, count, "limit");
727 const guint8 *filter_data = NULL;
729 const char *frame_sepa = "";
736 column_info *cinfo = &cfile.cinfo;
740 filter_data = sharkd_session_filter_data(tok_filter);
748 if (!ws_strtou32(tok_skip, NULL, &skip))
755 if (!ws_strtou32(tok_limit, NULL, &limit))
760 for (framenum = 1; framenum <= cfile.count; framenum++)
762 frame_data *fdata = frame_data_sequence_find(cfile.frames, framenum);
764 if (filter_data && !(filter_data[framenum / 8] & (1 << (framenum % 8))))
773 sharkd_dissect_columns(framenum, cinfo, (fdata->color_filter == NULL));
775 printf("%s{\"c\":[", frame_sepa);
776 for (col = 0; col < cinfo->num_cols; ++col)
778 const col_item_t *col_item = &cinfo->columns[col];
783 json_puts_string(col_item->col_data);
785 printf("],\"num\":%u", framenum);
787 if (fdata->flags.ignored)
788 printf(",\"i\":true");
790 if (fdata->flags.marked)
791 printf(",\"m\":true");
793 if (fdata->color_filter)
795 printf(",\"bg\":\"%x\"", color_t_to_rgb(&fdata->color_filter->bg_color));
796 printf(",\"fg\":\"%x\"", color_t_to_rgb(&fdata->color_filter->fg_color));
802 if (limit && --limit == 0)
807 if (cinfo != &cfile.cinfo)
812 sharkd_session_process_tap_stats_node_cb(const stat_node *n)
815 const char *sepa = "";
818 for (node = n->children; node; node = node->next)
820 /* code based on stats_tree_get_values_from_node() */
821 printf("%s{\"name\":\"%s\"", sepa, node->name);
822 printf(",\"count\":%d", node->counter);
823 if (node->counter && ((node->st_flags & ST_FLG_AVERAGE) || node->rng))
825 printf(",\"avg\":%.2f", ((float)node->total) / node->counter);
826 printf(",\"min\":%d", node->minvalue);
827 printf(",\"max\":%d", node->maxvalue);
830 if (node->st->elapsed)
831 printf(",\"rate\":%.4f",((float)node->counter) / node->st->elapsed);
833 if (node->parent && node->parent->counter)
834 printf(",\"perc\":%.2f", (node->counter * 100.0) / node->parent->counter);
835 else if (node->parent == &(node->st->root))
836 printf(",\"perc\":100");
838 if (prefs.st_enable_burstinfo && node->max_burst)
840 if (prefs.st_burst_showcount)
841 printf(",\"burstcount\":%d", node->max_burst);
843 printf(",\"burstrate\":%.4f", ((double)node->max_burst) / prefs.st_burst_windowlen);
845 printf(",\"bursttime\":%.3f", ((double)node->burst_time / 1000.0));
851 sharkd_session_process_tap_stats_node_cb(node);
860 * sharkd_session_process_tap_stats_cb()
865 * (m) type:stats - tap output type
866 * (m) name - stat name
867 * (m) stats - array of object with attributes:
868 * (m) name - stat item name
869 * (m) count - stat item counter
870 * (o) avg - stat item averange value
871 * (o) min - stat item min value
872 * (o) max - stat item max value
873 * (o) rate - stat item rate value (ms)
874 * (o) perc - stat item percentage
875 * (o) burstrate - stat item burst rate
876 * (o) burstcount - stat item burst count
877 * (o) burstttme - stat item burst start
878 * (o) sub - array of object with attributes like in stats node.
881 sharkd_session_process_tap_stats_cb(void *psp)
883 stats_tree *st = (stats_tree *) psp;
885 printf("{\"tap\":\"stats:%s\",\"type\":\"stats\"", st->cfg->abbr);
887 printf(",\"name\":\"%s\",\"stats\":", st->cfg->name);
888 sharkd_session_process_tap_stats_node_cb(&st->root);
893 sharkd_session_free_tap_stats_cb(void *psp)
895 stats_tree *st = (stats_tree *) psp;
900 struct sharkd_expert_tap
907 * sharkd_session_process_tap_expert_cb()
912 * (m) type:expert - tap output type
913 * (m) details - array of object with attributes:
914 * (m) f - frame number, which generated expert information
917 * (m) m - expert message
921 sharkd_session_process_tap_expert_cb(void *tapdata)
923 struct sharkd_expert_tap *etd = (struct sharkd_expert_tap *) tapdata;
925 const char *sepa = "";
927 printf("{\"tap\":\"%s\",\"type\":\"%s\"", "expert", "expert");
929 printf(",\"details\":[");
930 for (list = etd->details; list; list = list->next)
932 expert_info_t *ei = (expert_info_t *) list->data;
937 printf("\"f\":%u,", ei->packet_num);
939 tmp = try_val_to_str(ei->severity, expert_severity_vals);
941 printf("\"s\":\"%s\",", tmp);
943 tmp = try_val_to_str(ei->group, expert_group_vals);
945 printf("\"g\":\"%s\",", tmp);
948 json_puts_string(ei->summary);
954 json_puts_string(ei->protocol);
966 sharkd_session_packet_tap_expert_cb(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pointer)
968 struct sharkd_expert_tap *etd = (struct sharkd_expert_tap *) tapdata;
969 expert_info_t *ei = (expert_info_t *) pointer;
971 ei = (expert_info_t *) g_memdup(ei, sizeof(*ei));
972 ei->protocol = g_string_chunk_insert_const(etd->text, ei->protocol);
973 ei->summary = g_string_chunk_insert_const(etd->text, ei->summary);
975 etd->details = g_slist_prepend(etd->details, ei);
981 sharkd_session_free_tap_expert_cb(void *tapdata)
983 struct sharkd_expert_tap *etd = (struct sharkd_expert_tap *) tapdata;
985 g_slist_free_full(etd->details, g_free);
986 g_string_chunk_free(etd->text);
990 struct sharkd_conv_tap_data
994 gboolean resolve_name;
995 gboolean resolve_port;
999 sharkd_session_geoip_addr(address *addr, const char *suffix)
1007 if (addr->type == AT_IPv4)
1009 guint32 ip = pntoh32(addr->data);
1011 guint num_dbs = geoip_db_num_dbs();
1014 for (dbnum = 0; dbnum < num_dbs; dbnum++)
1016 const char *geoip_key = NULL;
1019 int db_type = geoip_db_type(dbnum);
1023 case GEOIP_COUNTRY_EDITION:
1024 geoip_key = "geoip_country";
1027 case GEOIP_CITY_EDITION_REV0:
1028 case GEOIP_CITY_EDITION_REV1:
1029 geoip_key = "geoip_city";
1032 case GEOIP_ORG_EDITION:
1033 geoip_key = "geoip_org";
1036 case GEOIP_ISP_EDITION:
1037 geoip_key = "geoip_isp";
1040 case GEOIP_ASNUM_EDITION:
1041 geoip_key = "geoip_as";
1044 case WS_LAT_FAKE_EDITION:
1045 geoip_key = "geoip_lat";
1048 case WS_LON_FAKE_EDITION:
1049 geoip_key = "geoip_lon";
1053 if (geoip_key && (geoip_val = geoip_db_lookup_ipv4(dbnum, ip, NULL)))
1055 printf(",\"%s%s\":", geoip_key, suffix);
1056 json_puts_string(geoip_val);
1061 #ifdef HAVE_GEOIP_V6
1062 if (addr->type == AT_IPv6)
1064 const struct e_in6_addr *ip6 = (const struct e_in6_addr *) addr->data;
1066 guint num_dbs = geoip_db_num_dbs();
1069 for (dbnum = 0; dbnum < num_dbs; dbnum++)
1071 const char *geoip_key = NULL;
1074 int db_type = geoip_db_type(dbnum);
1078 case GEOIP_COUNTRY_EDITION_V6:
1079 geoip_key = "geoip_country";
1081 #if NUM_DB_TYPES > 31
1082 case GEOIP_CITY_EDITION_REV0_V6:
1083 case GEOIP_CITY_EDITION_REV1_V6:
1084 geoip_key = "geoip_city";
1087 case GEOIP_ORG_EDITION_V6:
1088 geoip_key = "geoip_org";
1091 case GEOIP_ISP_EDITION_V6:
1092 geoip_key = "geoip_isp";
1095 case GEOIP_ASNUM_EDITION_V6:
1096 geoip_key = "geoip_as";
1098 #endif /* DB_NUM_TYPES */
1099 case WS_LAT_FAKE_EDITION:
1100 geoip_key = "geoip_lat";
1103 case WS_LON_FAKE_EDITION:
1104 geoip_key = "geoip_lon";
1108 if (geoip_key && (geoip_val = geoip_db_lookup_ipv6(dbnum, *ip6, NULL)))
1110 printf(",\"%s%s\":", geoip_key, suffix);
1111 json_puts_string(geoip_val);
1116 #endif /* HAVE_GEOIP_V6 */
1117 #endif /* HAVE_GEOIP */
1122 struct sharkd_analyse_rtp_items
1125 guint32 sequence_num;
1133 double arrive_offset;
1135 /* from tap_rtp_stat_t */
1140 struct sharkd_analyse_rtp
1142 const char *tap_name;
1143 struct sharkd_rtp_match rtp;
1147 tap_rtp_stat_t statinfo;
1151 sharkd_session_process_tap_rtp_free_cb(void *tapdata)
1153 struct sharkd_analyse_rtp *rtp_req = (struct sharkd_analyse_rtp *) tapdata;
1155 g_slist_free_full(rtp_req->packets, g_free);
1160 sharkd_session_packet_tap_rtp_analyse_cb(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pointer)
1162 struct sharkd_analyse_rtp *rtp_req = (struct sharkd_analyse_rtp *) tapdata;
1163 const struct _rtp_info *rtpinfo = (const struct _rtp_info *) pointer;
1165 if (sharkd_rtp_match_check(&rtp_req->rtp, pinfo, rtpinfo))
1167 tap_rtp_stat_t *statinfo = &(rtp_req->statinfo);
1168 struct sharkd_analyse_rtp_items *item;
1170 rtp_packet_analyse(statinfo, pinfo, rtpinfo);
1172 item = (struct sharkd_analyse_rtp_items *) g_malloc(sizeof(struct sharkd_analyse_rtp_items));
1174 if (!rtp_req->packets)
1175 rtp_req->start_time = nstime_to_sec(&pinfo->abs_ts);
1177 item->frame_num = pinfo->num;
1178 item->sequence_num = rtpinfo->info_seq_num;
1179 item->delta = (statinfo->flags & STAT_FLAG_FIRST) ? 0.0 : statinfo->delta;
1180 item->jitter = (statinfo->flags & STAT_FLAG_FIRST) ? 0.0 : statinfo->jitter;
1181 item->skew = (statinfo->flags & STAT_FLAG_FIRST) ? 0.0 : statinfo->skew;
1182 item->bandwidth = statinfo->bandwidth;
1183 item->marker = rtpinfo->info_marker_set ? TRUE : FALSE;
1184 item->arrive_offset= nstime_to_sec(&pinfo->abs_ts) - rtp_req->start_time;
1186 item->flags = statinfo->flags;
1187 item->pt = statinfo->pt;
1189 /* XXX, O(n) optimize */
1190 rtp_req->packets = g_slist_append(rtp_req->packets, item);
1197 * sharkd_session_process_tap_rtp_analyse_cb()
1199 * Output rtp analyse tap:
1200 * (m) tap - tap name
1201 * (m) type - tap output type
1202 * (m) ssrc - RTP SSRC
1203 * (m) max_delta - Max delta (ms)
1204 * (m) max_delta_nr - Max delta packet #
1205 * (m) max_jitter - Max jitter (ms)
1206 * (m) mean_jitter - Mean jitter (ms)
1207 * (m) max_skew - Max skew (ms)
1208 * (m) total_nr - Total number of RTP packets
1209 * (m) seq_err - Number of sequence errors
1210 * (m) duration - Duration (ms)
1211 * (m) items - array of object with attributes:
1212 * (m) f - frame number
1213 * (m) o - arrive offset
1214 * (m) sn - sequence number
1218 * (m) bw - bandwidth
1219 * (o) s - status string
1220 * (o) t - status type
1221 * (o) mark - rtp mark
1224 sharkd_session_process_tap_rtp_analyse_cb(void *tapdata)
1226 const int RTP_TYPE_CN = 1;
1227 const int RTP_TYPE_ERROR = 2;
1228 const int RTP_TYPE_WARN = 3;
1229 const int RTP_TYPE_PT_EVENT = 4;
1231 const struct sharkd_analyse_rtp *rtp_req = (struct sharkd_analyse_rtp *) tapdata;
1232 const tap_rtp_stat_t *statinfo = &rtp_req->statinfo;
1234 const char *sepa = "";
1237 printf("{\"tap\":\"%s\",\"type\":\"rtp-analyse\"", rtp_req->tap_name);
1239 printf(",\"ssrc\":%u", rtp_req->rtp.ssrc);
1241 printf(",\"max_delta\":%f", statinfo->max_delta);
1242 printf(",\"max_delta_nr\":%u", statinfo->max_nr);
1243 printf(",\"max_jitter\":%f", statinfo->max_jitter);
1244 printf(",\"mean_jitter\":%f", statinfo->mean_jitter);
1245 printf(",\"max_skew\":%f", statinfo->max_skew);
1246 printf(",\"total_nr\":%u", statinfo->total_nr);
1247 printf(",\"seq_err\":%u", statinfo->sequence);
1248 printf(",\"duration\":%f", statinfo->time - statinfo->start_time);
1250 printf(",\"items\":[");
1251 for (l = rtp_req->packets; l; l = l->next)
1253 struct sharkd_analyse_rtp_items *item = (struct sharkd_analyse_rtp_items *) l->data;
1255 printf("%s{", sepa);
1257 printf("\"f\":%u", item->frame_num);
1258 printf(",\"o\":%.9f", item->arrive_offset);
1259 printf(",\"sn\":%u", item->sequence_num);
1260 printf(",\"d\":%.2f", item->delta);
1261 printf(",\"j\":%.2f", item->jitter);
1262 printf(",\"sk\":%.2f", item->skew);
1263 printf(",\"bw\":%.2f", item->bandwidth);
1265 if (item->pt == PT_CN)
1266 printf(",\"s\":\"%s\",\"t\":%d", "Comfort noise (PT=13, RFC 3389)", RTP_TYPE_CN);
1267 else if (item->pt == PT_CN_OLD)
1268 printf(",\"s\":\"%s\",\"t\":%d", "Comfort noise (PT=19, reserved)", RTP_TYPE_CN);
1269 else if (item->flags & STAT_FLAG_WRONG_SEQ)
1270 printf(",\"s\":\"%s\",\"t\":%d", "Wrong sequence number", RTP_TYPE_ERROR);
1271 else if (item->flags & STAT_FLAG_DUP_PKT)
1272 printf(",\"s\":\"%s\",\"t\":%d", "Suspected duplicate (MAC address) only delta time calculated", RTP_TYPE_WARN);
1273 else if (item->flags & STAT_FLAG_REG_PT_CHANGE)
1274 printf(",\"s\":\"Payload changed to PT=%u%s\",\"t\":%d",
1276 (item->flags & STAT_FLAG_PT_T_EVENT) ? " telephone/event" : "",
1278 else if (item->flags & STAT_FLAG_WRONG_TIMESTAMP)
1279 printf(",\"s\":\"%s\",\"t\":%d", "Incorrect timestamp", RTP_TYPE_WARN);
1280 else if ((item->flags & STAT_FLAG_PT_CHANGE)
1281 && !(item->flags & STAT_FLAG_FIRST)
1282 && !(item->flags & STAT_FLAG_PT_CN)
1283 && (item->flags & STAT_FLAG_FOLLOW_PT_CN)
1284 && !(item->flags & STAT_FLAG_MARKER))
1286 printf(",\"s\":\"%s\",\"t\":%d", "Marker missing?", RTP_TYPE_WARN);
1288 else if (item->flags & STAT_FLAG_PT_T_EVENT)
1289 printf(",\"s\":\"PT=%u telephone/event\",\"t\":%d", item->pt, RTP_TYPE_PT_EVENT);
1290 else if (item->flags & STAT_FLAG_MARKER)
1291 printf(",\"t\":%d", RTP_TYPE_WARN);
1294 printf(",\"mark\":1");
1305 * sharkd_session_process_tap_conv_cb()
1308 * (m) tap - tap name
1309 * (m) type - tap output type
1310 * (m) proto - protocol short name
1311 * (o) filter - filter string
1313 * (o) convs - array of object with attributes:
1314 * (m) saddr - source address
1315 * (m) daddr - destination address
1316 * (o) sport - source port
1317 * (o) dport - destination port
1318 * (m) txf - TX frame count
1319 * (m) txb - TX bytes
1320 * (m) rxf - RX frame count
1321 * (m) rxb - RX bytes
1322 * (m) start - (relative) first packet time
1323 * (m) stop - (relative) last packet time
1325 * (o) hosts - array of object with attributes:
1326 * (m) host - host address
1327 * (o) port - host port
1328 * (m) txf - TX frame count
1329 * (m) txb - TX bytes
1330 * (m) rxf - RX frame count
1331 * (m) rxb - RX bytes
1334 sharkd_session_process_tap_conv_cb(void *arg)
1336 conv_hash_t *hash = (conv_hash_t *) arg;
1337 const struct sharkd_conv_tap_data *iu = (struct sharkd_conv_tap_data *) hash->user_data;
1339 int proto_with_port;
1344 if (!strncmp(iu->type, "conv:", 5))
1346 printf("{\"tap\":\"%s\",\"type\":\"conv\"", iu->type);
1347 printf(",\"convs\":[");
1348 proto = iu->type + 5;
1350 else if (!strncmp(iu->type, "endpt:", 6))
1352 printf("{\"tap\":\"%s\",\"type\":\"host\"", iu->type);
1353 printf(",\"hosts\":[");
1354 proto = iu->type + 6;
1358 printf("{\"tap\":\"%s\",\"type\":\"err\"", iu->type);
1362 proto_with_port = (!strcmp(proto, "TCP") || !strcmp(proto, "UDP") || !strcmp(proto, "SCTP"));
1364 if (iu->hash.conv_array != NULL && !strncmp(iu->type, "conv:", 5))
1366 for (i = 0; i < iu->hash.conv_array->len; i++)
1368 conv_item_t *iui = &g_array_index(iu->hash.conv_array, conv_item_t, i);
1369 char *src_addr, *dst_addr;
1370 char *src_port, *dst_port;
1373 printf("%s{", i ? "," : "");
1375 printf("\"saddr\":\"%s\"", (src_addr = get_conversation_address(NULL, &iui->src_address, iu->resolve_name)));
1376 printf(",\"daddr\":\"%s\"", (dst_addr = get_conversation_address(NULL, &iui->dst_address, iu->resolve_name)));
1378 if (proto_with_port)
1380 printf(",\"sport\":\"%s\"", (src_port = get_conversation_port(NULL, iui->src_port, iui->ptype, iu->resolve_port)));
1381 printf(",\"dport\":\"%s\"", (dst_port = get_conversation_port(NULL, iui->dst_port, iui->ptype, iu->resolve_port)));
1383 wmem_free(NULL, src_port);
1384 wmem_free(NULL, dst_port);
1387 printf(",\"rxf\":%" G_GUINT64_FORMAT, iui->rx_frames);
1388 printf(",\"rxb\":%" G_GUINT64_FORMAT, iui->rx_bytes);
1390 printf(",\"txf\":%" G_GUINT64_FORMAT, iui->tx_frames);
1391 printf(",\"txb\":%" G_GUINT64_FORMAT, iui->tx_bytes);
1393 printf(",\"start\":%.9f", nstime_to_sec(&iui->start_time));
1394 printf(",\"stop\":%.9f", nstime_to_sec(&iui->stop_time));
1396 filter_str = get_conversation_filter(iui, CONV_DIR_A_TO_FROM_B);
1399 printf(",\"filter\":\"%s\"", filter_str);
1403 wmem_free(NULL, src_addr);
1404 wmem_free(NULL, dst_addr);
1406 if (sharkd_session_geoip_addr(&(iui->src_address), "1"))
1408 if (sharkd_session_geoip_addr(&(iui->dst_address), "2"))
1414 else if (iu->hash.conv_array != NULL && !strncmp(iu->type, "endpt:", 6))
1416 for (i = 0; i < iu->hash.conv_array->len; i++)
1418 hostlist_talker_t *host = &g_array_index(iu->hash.conv_array, hostlist_talker_t, i);
1419 char *host_str, *port_str;
1422 printf("%s{", i ? "," : "");
1424 printf("\"host\":\"%s\"", (host_str = get_conversation_address(NULL, &host->myaddress, iu->resolve_name)));
1426 if (proto_with_port)
1428 printf(",\"port\":\"%s\"", (port_str = get_conversation_port(NULL, host->port, host->ptype, iu->resolve_port)));
1430 wmem_free(NULL, port_str);
1433 printf(",\"rxf\":%" G_GUINT64_FORMAT, host->rx_frames);
1434 printf(",\"rxb\":%" G_GUINT64_FORMAT, host->rx_bytes);
1436 printf(",\"txf\":%" G_GUINT64_FORMAT, host->tx_frames);
1437 printf(",\"txb\":%" G_GUINT64_FORMAT, host->tx_bytes);
1439 filter_str = get_hostlist_filter(host);
1442 printf(",\"filter\":\"%s\"", filter_str);
1446 wmem_free(NULL, host_str);
1448 if (sharkd_session_geoip_addr(&(host->myaddress), ""))
1454 printf("],\"proto\":\"%s\",\"geoip\":%s},", proto, with_geoip ? "true" : "false");
1458 sharkd_session_free_tap_conv_cb(void *arg)
1460 conv_hash_t *hash = (conv_hash_t *) arg;
1461 struct sharkd_conv_tap_data *iu = (struct sharkd_conv_tap_data *) hash->user_data;
1463 if (!strncmp(iu->type, "conv:", 5))
1465 reset_conversation_table_data(hash);
1467 else if (!strncmp(iu->type, "endpt:", 6))
1469 reset_hostlist_table_data(hash);
1476 * sharkd_session_process_tap_nstat_cb()
1479 * (m) tap - tap name
1480 * (m) type - tap output type
1481 * (m) fields: array of objects with attributes:
1484 * (m) tables: array of object with attributes:
1485 * (m) t - table title
1486 * (m) i - array of items
1489 sharkd_session_process_tap_nstat_cb(void *arg)
1491 new_stat_data_t *stat_data = (new_stat_data_t *) arg;
1494 printf("{\"tap\":\"nstat:%s\",\"type\":\"nstat\"", stat_data->stat_tap_data->cli_string);
1496 printf(",\"fields\":[");
1497 for (i = 0; i < stat_data->stat_tap_data->nfields; i++)
1499 stat_tap_table_item *field = &(stat_data->stat_tap_data->fields[i]);
1507 json_puts_string(field->column_name);
1513 printf(",\"tables\":[");
1514 for (i = 0; i < stat_data->stat_tap_data->tables->len; i++)
1516 stat_tap_table *table = g_array_index(stat_data->stat_tap_data->tables, stat_tap_table *, i);
1517 const char *sepa = "";
1525 printf("\"%s\"", table->title);
1528 for (j = 0; j < table->num_elements; j++)
1530 stat_tap_table_item_type *field_data;
1532 field_data = new_stat_tap_get_field_data(table, j, 0);
1533 if (field_data == NULL || field_data->type == TABLE_ITEM_NONE) /* Nothing for us here */
1536 printf("%s[", sepa);
1537 for (k = 0; k < table->num_fields; k++)
1539 field_data = new_stat_tap_get_field_data(table, j, k);
1544 switch (field_data->type)
1546 case TABLE_ITEM_UINT:
1547 printf("%u", field_data->value.uint_value);
1550 case TABLE_ITEM_INT:
1551 printf("%d", field_data->value.uint_value);
1554 case TABLE_ITEM_STRING:
1555 json_puts_string(field_data->value.string_value);
1558 case TABLE_ITEM_FLOAT:
1559 printf("%f", field_data->value.float_value);
1562 case TABLE_ITEM_ENUM:
1563 printf("%d", field_data->value.enum_value);
1566 case TABLE_ITEM_NONE:
1583 sharkd_session_free_tap_nstat_cb(void *arg)
1585 new_stat_data_t *stat_data = (new_stat_data_t *) arg;
1587 free_stat_tables(stat_data->stat_tap_data, NULL, NULL);
1591 * sharkd_session_process_tap_rtd_cb()
1594 * (m) tap - tap name
1595 * (m) type - tap output type
1596 * (m) stats - statistics rows - array object with attributes:
1597 * (m) type - statistic name
1598 * (m) num - number of messages
1599 * (m) min - minimum SRT time
1600 * (m) max - maximum SRT time
1601 * (m) tot - total SRT time
1602 * (m) min_frame - minimal SRT
1603 * (m) max_frame - maximum SRT
1604 * (o) open_req - Open Requests
1605 * (o) disc_rsp - Discarded Responses
1606 * (o) req_dup - Duplicated Requests
1607 * (o) rsp_dup - Duplicated Responses
1608 * (o) open_req - Open Requests
1609 * (o) disc_rsp - Discarded Responses
1610 * (o) req_dup - Duplicated Requests
1611 * (o) rsp_dup - Duplicated Responses
1614 sharkd_session_process_tap_rtd_cb(void *arg)
1616 rtd_data_t *rtd_data = (rtd_data_t *) arg;
1617 register_rtd_t *rtd = (register_rtd_t *) rtd_data->user_data;
1621 const char *filter = proto_get_protocol_filter_name(get_rtd_proto_id(rtd));
1623 /* XXX, some dissectors are having single table and multiple timestats (mgcp, megaco),
1624 * some multiple table and single timestat (radius, h225)
1625 * and it seems that value_string is used one for timestamp-ID, other one for table-ID
1626 * I wonder how it will gonna work with multiple timestats and multiple timestat...
1627 * (for usage grep for: register_rtd_table)
1629 const value_string *vs = get_rtd_value_string(rtd);
1630 const char *sepa = "";
1632 printf("{\"tap\":\"rtd:%s\",\"type\":\"rtd\"", filter);
1634 if (rtd_data->stat_table.num_rtds == 1)
1636 const rtd_timestat *ms = &rtd_data->stat_table.time_stats[0];
1638 printf(",\"open_req\":%u", ms->open_req_num);
1639 printf(",\"disc_rsp\":%u", ms->disc_rsp_num);
1640 printf(",\"req_dup\":%u", ms->req_dup_num);
1641 printf(",\"rsp_dup\":%u", ms->rsp_dup_num);
1644 printf(",\"stats\":[");
1645 for (i = 0; i < rtd_data->stat_table.num_rtds; i++)
1647 const rtd_timestat *ms = &rtd_data->stat_table.time_stats[i];
1649 for (j = 0; j < ms->num_timestat; j++)
1651 const char *type_str;
1653 if (ms->rtd[j].num == 0)
1656 printf("%s{", sepa);
1658 if (rtd_data->stat_table.num_rtds == 1)
1659 type_str = val_to_str_const(j, vs, "Other"); /* 1 table - description per row */
1661 type_str = val_to_str_const(i, vs, "Other"); /* multiple table - description per table */
1662 printf("\"type\":");
1663 json_puts_string(type_str);
1665 printf(",\"num\":%u", ms->rtd[j].num);
1666 printf(",\"min\":%.9f", nstime_to_sec(&(ms->rtd[j].min)));
1667 printf(",\"max\":%.9f", nstime_to_sec(&(ms->rtd[j].max)));
1668 printf(",\"tot\":%.9f", nstime_to_sec(&(ms->rtd[j].tot)));
1669 printf(",\"min_frame\":%u", ms->rtd[j].min_num);
1670 printf(",\"max_frame\":%u", ms->rtd[j].max_num);
1672 if (rtd_data->stat_table.num_rtds != 1)
1674 /* like in tshark, display it on every row */
1675 printf(",\"open_req\":%u", ms->open_req_num);
1676 printf(",\"disc_rsp\":%u", ms->disc_rsp_num);
1677 printf(",\"req_dup\":%u", ms->req_dup_num);
1678 printf(",\"rsp_dup\":%u", ms->rsp_dup_num);
1689 sharkd_session_free_tap_rtd_cb(void *arg)
1691 rtd_data_t *rtd_data = (rtd_data_t *) arg;
1693 free_rtd_table(&rtd_data->stat_table, NULL, NULL);
1698 * sharkd_session_process_tap_srt_cb()
1701 * (m) tap - tap name
1702 * (m) type - tap output type
1704 * (m) tables - array of object with attributes:
1705 * (m) n - table name
1706 * (m) f - table filter
1707 * (o) c - table column name
1708 * (m) r - table rows - array object with attributes:
1710 * (m) idx - procedure index
1711 * (m) num - number of events
1712 * (m) min - minimum SRT time
1713 * (m) max - maximum SRT time
1714 * (m) tot - total SRT time
1717 sharkd_session_process_tap_srt_cb(void *arg)
1719 srt_data_t *srt_data = (srt_data_t *) arg;
1720 register_srt_t *srt = (register_srt_t *) srt_data->user_data;
1722 const char *filter = proto_get_protocol_filter_name(get_srt_proto_id(srt));
1726 printf("{\"tap\":\"srt:%s\",\"type\":\"srt\"", filter);
1728 printf(",\"tables\":[");
1729 for (i = 0; i < srt_data->srt_array->len; i++)
1732 srt_stat_table *rst = g_array_index(srt_data->srt_array, srt_stat_table *, i);
1733 const char *sepa = "";
1743 json_puts_string(rst->name);
1744 else if (rst->short_name)
1745 json_puts_string(rst->short_name);
1747 printf("\"table%u\"", i);
1749 if (rst->filter_string)
1752 json_puts_string(rst->filter_string);
1755 if (rst->proc_column_name)
1758 json_puts_string(rst->proc_column_name);
1762 for (j = 0; j < rst->num_procs; j++)
1765 srt_procedure_t *proc = &rst->procedures[j];
1767 if (proc->stats.num == 0)
1770 printf("%s{", sepa);
1773 json_puts_string(proc->procedure);
1775 if (rst->filter_string)
1776 printf(",\"idx\":%d", proc->proc_index);
1778 printf(",\"num\":%u", proc->stats.num);
1780 printf(",\"min\":%.9f", nstime_to_sec(&proc->stats.min));
1781 printf(",\"max\":%.9f", nstime_to_sec(&proc->stats.max));
1782 printf(",\"tot\":%.9f", nstime_to_sec(&proc->stats.tot));
1794 sharkd_session_free_tap_srt_cb(void *arg)
1796 srt_data_t *srt_data = (srt_data_t *) arg;
1797 register_srt_t *srt = (register_srt_t *) srt_data->user_data;
1799 free_srt_table(srt, srt_data->srt_array, NULL, NULL);
1800 g_array_free(srt_data->srt_array, TRUE);
1804 struct sharkd_export_object_list
1806 struct sharkd_export_object_list *next;
1813 static struct sharkd_export_object_list *sharkd_eo_list;
1816 * sharkd_session_process_tap_eo_cb()
1819 * (m) tap - tap name
1820 * (m) type - tap output type
1821 * (m) proto - protocol short name
1822 * (m) objects - array of object with attributes:
1823 * (m) pkt - packet number
1824 * (o) hostname - hostname
1825 * (o) type - content type
1826 * (o) filename - filename
1827 * (m) len - object length
1830 sharkd_session_process_tap_eo_cb(void *tapdata)
1832 export_object_list_t *tap_object = (export_object_list_t *) tapdata;
1833 struct sharkd_export_object_list *object_list = (struct sharkd_export_object_list*) tap_object->gui_data;
1837 printf("{\"tap\":\"%s\",\"type\":\"eo\"", object_list->type);
1838 printf(",\"proto\":\"%s\"", object_list->proto);
1839 printf(",\"objects\":[");
1841 for (slist = object_list->entries; slist; slist = slist->next)
1843 const export_object_entry_t *eo_entry = (export_object_entry_t *) slist->data;
1845 printf("%s{", i ? "," : "");
1847 printf("\"pkt\":%u", eo_entry->pkt_num);
1849 if (eo_entry->hostname)
1851 printf(",\"hostname\":");
1852 json_puts_string(eo_entry->hostname);
1855 if (eo_entry->content_type)
1857 printf(",\"type\":");
1858 json_puts_string(eo_entry->content_type);
1861 if (eo_entry->filename)
1863 printf(",\"filename\":");
1864 json_puts_string(eo_entry->filename);
1867 printf(",\"_download\":\"%s_%d\"", object_list->type, i);
1869 printf(",\"len\":%" G_GINT64_FORMAT, eo_entry->payload_len);
1880 sharkd_eo_object_list_add_entry(void *gui_data, export_object_entry_t *entry)
1882 struct sharkd_export_object_list *object_list = (struct sharkd_export_object_list *) gui_data;
1884 object_list->entries = g_slist_append(object_list->entries, entry);
1887 static export_object_entry_t *
1888 sharkd_eo_object_list_get_entry(void *gui_data, int row)
1890 struct sharkd_export_object_list *object_list = (struct sharkd_export_object_list *) gui_data;
1892 return (export_object_entry_t *) g_slist_nth_data(object_list->entries, row);
1896 * sharkd_session_process_tap_rtp_cb()
1898 * Output RTP streams tap:
1899 * (m) tap - tap name
1900 * (m) type - tap output type
1901 * (m) streams - array of object with attributes:
1902 * (m) ssrc - RTP synchronization source identifier
1903 * (m) payload - stream payload
1904 * (m) saddr - source address
1905 * (m) sport - source port
1906 * (m) daddr - destination address
1907 * (m) dport - destination port
1908 * (m) pkts - packets count
1909 * (m) max_delta - max delta (ms)
1910 * (m) max_jitter - max jitter (ms)
1911 * (m) mean_jitter - mean jitter (ms)
1914 * (m) problem - if analyser found the problem
1915 * (m) ipver - address IP version (4 or 6)
1918 sharkd_session_process_tap_rtp_cb(void *arg)
1920 rtpstream_tapinfo_t *rtp_tapinfo = (rtpstream_tapinfo_t *) arg;
1923 const char *sepa = "";
1925 printf("{\"tap\":\"%s\",\"type\":\"%s\"", "rtp-streams", "rtp-streams");
1927 printf(",\"streams\":[");
1928 for (listx = g_list_first(rtp_tapinfo->strinfo_list); listx; listx = listx->next)
1930 rtp_stream_info_t *streaminfo = (rtp_stream_info_t *) listx->data;
1932 char *src_addr, *dst_addr;
1936 src_addr = address_to_display(NULL, &(streaminfo->src_addr));
1937 dst_addr = address_to_display(NULL, &(streaminfo->dest_addr));
1939 if (streaminfo->payload_type_name != NULL)
1940 payload = wmem_strdup(NULL, streaminfo->payload_type_name);
1942 payload = val_to_str_ext_wmem(NULL, streaminfo->payload_type, &rtp_payload_type_short_vals_ext, "Unknown (%u)");
1944 printf("%s{\"ssrc\":%u", sepa, streaminfo->ssrc);
1945 printf(",\"payload\":\"%s\"", payload);
1947 printf(",\"saddr\":\"%s\"", src_addr);
1948 printf(",\"sport\":%u", streaminfo->src_port);
1950 printf(",\"daddr\":\"%s\"", dst_addr);
1951 printf(",\"dport\":%u", streaminfo->dest_port);
1953 printf(",\"pkts\":%u", streaminfo->packet_count);
1955 printf(",\"max_delta\":%f", streaminfo->rtp_stats.max_delta);
1956 printf(",\"max_jitter\":%f", streaminfo->rtp_stats.max_jitter);
1957 printf(",\"mean_jitter\":%f", streaminfo->rtp_stats.mean_jitter);
1959 expected = (streaminfo->rtp_stats.stop_seq_nr + streaminfo->rtp_stats.cycles * 65536) - streaminfo->rtp_stats.start_seq_nr + 1;
1960 printf(",\"expectednr\":%u", expected);
1961 printf(",\"totalnr\":%u", streaminfo->rtp_stats.total_nr);
1963 printf(",\"problem\":%s", streaminfo->problem ? "true" : "false");
1966 printf(",\"ipver\":%d", (streaminfo->src_addr.type == AT_IPv6) ? 6 : 4);
1968 wmem_free(NULL, src_addr);
1969 wmem_free(NULL, dst_addr);
1970 wmem_free(NULL, payload);
1979 * sharkd_session_process_tap()
1981 * Process tap request
1984 * (m) tap0 - First tap request
1985 * (o) tap1...tap15 - Other tap requests
1987 * Output object with attributes:
1988 * (m) taps - array of object with attributes:
1989 * (m) tap - tap name
1990 * (m) type - tap output type
1992 * for type:stats see sharkd_session_process_tap_stats_cb()
1993 * for type:nstat see sharkd_session_process_tap_nstat_cb()
1994 * for type:conv see sharkd_session_process_tap_conv_cb()
1995 * for type:host see sharkd_session_process_tap_conv_cb()
1996 * for type:rtp-streams see sharkd_session_process_tap_rtp_cb()
1997 * for type:rtp-analyse see sharkd_session_process_tap_rtp_analyse_cb()
1998 * for type:eo see sharkd_session_process_tap_eo_cb()
1999 * for type:expert see sharkd_session_process_tap_expert_cb()
2000 * for type:rtd see sharkd_session_process_tap_rtd_cb()
2001 * for type:srt see sharkd_session_process_tap_srt_cb()
2003 * (m) err - error code
2006 sharkd_session_process_tap(char *buf, const jsmntok_t *tokens, int count)
2008 void *taps_data[16];
2009 GFreeFunc taps_free[16];
2013 rtpstream_tapinfo_t rtp_tapinfo =
2014 {NULL, NULL, NULL, NULL, 0, NULL, 0, TAP_ANALYSE, NULL, NULL, NULL, FALSE};
2016 for (i = 0; i < 16; i++)
2019 const char *tok_tap;
2021 void *tap_data = NULL;
2022 GFreeFunc tap_free = NULL;
2023 const char *tap_filter = "";
2024 GString *tap_error = NULL;
2026 ws_snprintf(tapbuf, sizeof(tapbuf), "tap%d", i);
2027 tok_tap = json_find_attr(buf, tokens, count, tapbuf);
2031 if (!strncmp(tok_tap, "stat:", 5))
2033 stats_tree_cfg *cfg = stats_tree_get_cfg_by_abbr(tok_tap + 5);
2038 fprintf(stderr, "sharkd_session_process_tap() stat %s not found\n", tok_tap + 5);
2042 st = stats_tree_new(cfg, NULL, tap_filter);
2044 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);
2046 if (!tap_error && cfg->init)
2050 tap_free = sharkd_session_free_tap_stats_cb;
2052 else if (!strcmp(tok_tap, "expert"))
2054 struct sharkd_expert_tap *expert_tap;
2056 expert_tap = g_new0(struct sharkd_expert_tap, 1);
2057 expert_tap->text = g_string_chunk_new(100);
2059 tap_error = register_tap_listener("expert", expert_tap, NULL, 0, NULL, sharkd_session_packet_tap_expert_cb, sharkd_session_process_tap_expert_cb);
2061 tap_data = expert_tap;
2062 tap_free = sharkd_session_free_tap_expert_cb;
2064 else if (!strncmp(tok_tap, "conv:", 5) || !strncmp(tok_tap, "endpt:", 6))
2066 struct register_ct *ct = NULL;
2067 const char *ct_tapname;
2068 struct sharkd_conv_tap_data *ct_data;
2069 tap_packet_cb tap_func = NULL;
2071 if (!strncmp(tok_tap, "conv:", 5))
2073 ct = get_conversation_by_proto_id(proto_get_id_by_short_name(tok_tap + 5));
2075 if (!ct || !(tap_func = get_conversation_packet_func(ct)))
2077 fprintf(stderr, "sharkd_session_process_tap() conv %s not found\n", tok_tap + 5);
2081 else if (!strncmp(tok_tap, "endpt:", 6))
2083 ct = get_conversation_by_proto_id(proto_get_id_by_short_name(tok_tap + 6));
2085 if (!ct || !(tap_func = get_hostlist_packet_func(ct)))
2087 fprintf(stderr, "sharkd_session_process_tap() endpt %s not found\n", tok_tap + 6);
2093 fprintf(stderr, "sharkd_session_process_tap() conv/endpt(?): %s not found\n", tok_tap);
2097 ct_tapname = proto_get_protocol_filter_name(get_conversation_proto_id(ct));
2099 ct_data = (struct sharkd_conv_tap_data *) g_malloc0(sizeof(struct sharkd_conv_tap_data));
2100 ct_data->type = tok_tap;
2101 ct_data->hash.user_data = ct_data;
2103 /* XXX: make configurable */
2104 ct_data->resolve_name = TRUE;
2105 ct_data->resolve_port = TRUE;
2107 tap_error = register_tap_listener(ct_tapname, &ct_data->hash, tap_filter, 0, NULL, tap_func, sharkd_session_process_tap_conv_cb);
2109 tap_data = &ct_data->hash;
2110 tap_free = sharkd_session_free_tap_conv_cb;
2112 else if (!strncmp(tok_tap, "nstat:", 6))
2114 stat_tap_table_ui *stat = new_stat_tap_by_name(tok_tap + 6);
2115 new_stat_data_t *stat_data;
2119 fprintf(stderr, "sharkd_session_process_tap() nstat=%s not found\n", tok_tap + 6);
2123 stat->stat_tap_init_cb(stat, NULL, NULL);
2125 stat_data = g_new0(new_stat_data_t, 1);
2126 stat_data->stat_tap_data = stat;
2127 stat_data->user_data = NULL;
2129 tap_error = register_tap_listener(stat->tap_name, stat_data, tap_filter, 0, NULL, stat->packet_func, sharkd_session_process_tap_nstat_cb);
2131 tap_data = stat_data;
2132 tap_free = sharkd_session_free_tap_nstat_cb;
2134 else if (!strncmp(tok_tap, "rtd:", 4))
2136 register_rtd_t *rtd = get_rtd_table_by_name(tok_tap + 4);
2137 rtd_data_t *rtd_data;
2142 fprintf(stderr, "sharkd_session_process_tap() rtd=%s not found\n", tok_tap + 4);
2146 rtd_table_get_filter(rtd, "", &tap_filter, &err);
2149 fprintf(stderr, "sharkd_session_process_tap() rtd=%s err=%s\n", tok_tap + 4, err);
2154 rtd_data = g_new0(rtd_data_t, 1);
2155 rtd_data->user_data = rtd;
2156 rtd_table_dissector_init(rtd, &rtd_data->stat_table, NULL, NULL);
2158 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);
2160 tap_data = rtd_data;
2161 tap_free = sharkd_session_free_tap_rtd_cb;
2163 else if (!strncmp(tok_tap, "srt:", 4))
2165 register_srt_t *srt = get_srt_table_by_name(tok_tap + 4);
2166 srt_data_t *srt_data;
2171 fprintf(stderr, "sharkd_session_process_tap() srt=%s not found\n", tok_tap + 4);
2175 srt_table_get_filter(srt, "", &tap_filter, &err);
2178 fprintf(stderr, "sharkd_session_process_tap() srt=%s err=%s\n", tok_tap + 4, err);
2183 srt_data = g_new0(srt_data_t, 1);
2184 srt_data->srt_array = g_array_new(FALSE, TRUE, sizeof(srt_stat_table *));
2185 srt_data->user_data = srt;
2186 srt_table_dissector_init(srt, srt_data->srt_array, NULL, NULL);
2188 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);
2190 tap_data = srt_data;
2191 tap_free = sharkd_session_free_tap_srt_cb;
2193 else if (!strncmp(tok_tap, "eo:", 3))
2195 register_eo_t *eo = get_eo_by_name(tok_tap + 3);
2196 export_object_list_t *eo_object;
2197 struct sharkd_export_object_list *object_list;
2201 fprintf(stderr, "sharkd_session_process_tap() eo=%s not found\n", tok_tap + 3);
2205 for (object_list = sharkd_eo_list; object_list; object_list = object_list->next)
2207 if (!strcmp(object_list->type, tok_tap))
2209 g_slist_free_full(object_list->entries, (GDestroyNotify) eo_free_entry);
2210 object_list->entries = NULL;
2217 object_list = g_new(struct sharkd_export_object_list, 1);
2218 object_list->type = g_strdup(tok_tap);
2219 object_list->proto = proto_get_protocol_short_name(find_protocol_by_id(get_eo_proto_id(eo)));
2220 object_list->entries = NULL;
2221 object_list->next = sharkd_eo_list;
2222 sharkd_eo_list = object_list;
2225 eo_object = g_new0(export_object_list_t, 1);
2226 eo_object->add_entry = sharkd_eo_object_list_add_entry;
2227 eo_object->get_entry = sharkd_eo_object_list_get_entry;
2228 eo_object->gui_data = (void *) object_list;
2230 tap_error = register_tap_listener(get_eo_tap_listener_name(eo), eo_object, NULL, 0, NULL, get_eo_packet_func(eo), sharkd_session_process_tap_eo_cb);
2232 tap_data = eo_object;
2233 tap_free = g_free; /* need to free only eo_object, object_list need to be kept for potential download */
2235 else if (!strcmp(tok_tap, "rtp-streams"))
2237 tap_error = register_tap_listener("rtp", &rtp_tapinfo, tap_filter, 0, rtpstream_reset_cb, rtpstream_packet, sharkd_session_process_tap_rtp_cb);
2239 tap_data = &rtp_tapinfo;
2240 tap_free = rtpstream_reset_cb;
2242 else if (!strncmp(tok_tap, "rtp-analyse:", 12))
2244 struct sharkd_analyse_rtp *rtp_req;
2246 rtp_req = (struct sharkd_analyse_rtp *) g_malloc0(sizeof(*rtp_req));
2247 if (!sharkd_rtp_match_init(&rtp_req->rtp, tok_tap + 12))
2253 rtp_req->tap_name = tok_tap;
2254 rtp_req->statinfo.first_packet = TRUE;
2255 rtp_req->statinfo.reg_pt = PT_UNDEFINED;
2257 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);
2260 tap_free = sharkd_session_process_tap_rtp_free_cb;
2264 fprintf(stderr, "sharkd_session_process_tap() %s not recognized\n", tok_tap);
2270 fprintf(stderr, "sharkd_session_process_tap() name=%s error=%s", tok_tap, tap_error->str);
2271 g_string_free(tap_error, TRUE);
2277 taps_data[taps_count] = tap_data;
2278 taps_free[taps_count] = tap_free;
2282 fprintf(stderr, "sharkd_session_process_tap() count=%d\n", taps_count);
2283 if (taps_count == 0)
2286 printf("{\"taps\":[");
2288 printf("null],\"err\":0}\n");
2290 for (i = 0; i < taps_count; i++)
2293 remove_tap_listener(taps_data[i]);
2296 taps_free[i](taps_data[i]);
2301 * sharkd_session_process_follow()
2303 * Process follow request
2306 * (m) follow - follow protocol request (e.g. HTTP)
2307 * (m) filter - filter request (e.g. tcp.stream == 1)
2309 * Output object with attributes:
2311 * (m) err - error code
2312 * (m) shost - server host
2313 * (m) sport - server port
2314 * (m) sbytes - server send bytes count
2315 * (m) chost - client host
2316 * (m) cport - client port
2317 * (m) cbytes - client send bytes count
2318 * (o) payloads - array of object with attributes:
2319 * (o) s - set if server sent, else client
2320 * (m) n - packet number
2321 * (m) d - data base64 encoded
2324 sharkd_session_process_follow(char *buf, const jsmntok_t *tokens, int count)
2326 const char *tok_follow = json_find_attr(buf, tokens, count, "follow");
2327 const char *tok_filter = json_find_attr(buf, tokens, count, "filter");
2329 register_follow_t *follower;
2332 follow_info_t *follow_info;
2336 if (!tok_follow || !tok_filter)
2339 follower = get_follow_by_name(tok_follow);
2342 fprintf(stderr, "sharkd_session_process_follow() follower=%s not found\n", tok_follow);
2346 /* follow_reset_stream ? */
2347 follow_info = g_new0(follow_info_t, 1);
2348 /* gui_data, filter_out_filter not set, but not used by dissector */
2350 tap_error = register_tap_listener(get_follow_tap_string(follower), follow_info, tok_filter, 0, NULL, get_follow_tap_handler(follower), NULL);
2353 fprintf(stderr, "sharkd_session_process_follow() name=%s error=%s", tok_follow, tap_error->str);
2354 g_string_free(tap_error, TRUE);
2355 g_free(follow_info);
2363 printf("\"err\":0");
2365 /* Server information: hostname, port, bytes sent */
2366 host = address_to_name(&follow_info->server_ip);
2367 printf(",\"shost\":");
2368 json_puts_string(host);
2370 port = get_follow_port_to_display(follower)(NULL, follow_info->server_port);
2371 printf(",\"sport\":");
2372 json_puts_string(port);
2373 wmem_free(NULL, port);
2375 printf(",\"sbytes\":%u", follow_info->bytes_written[0]);
2377 /* Client information: hostname, port, bytes sent */
2378 host = address_to_name(&follow_info->client_ip);
2379 printf(",\"chost\":");
2380 json_puts_string(host);
2382 port = get_follow_port_to_display(follower)(NULL, follow_info->client_port);
2383 printf(",\"cport\":");
2384 json_puts_string(port);
2385 wmem_free(NULL, port);
2387 printf(",\"cbytes\":%u", follow_info->bytes_written[1]);
2389 if (follow_info->payload)
2391 follow_record_t *follow_record;
2393 const char *sepa = "";
2395 printf(",\"payloads\":[");
2397 for (cur = follow_info->payload; cur; cur = g_list_next(cur))
2399 follow_record = (follow_record_t *) cur->data;
2401 printf("%s{", sepa);
2403 printf("\"n\":%u", follow_record->packet_num);
2406 json_print_base64(follow_record->data->data, follow_record->data->len);
2408 if (follow_record->is_server)
2409 printf(",\"s\":%d", 1);
2420 remove_tap_listener(follow_info);
2421 follow_info_free(follow_info);
2425 sharkd_session_process_frame_cb_tree(proto_tree *tree, tvbuff_t **tvbs)
2428 const char *sepa = "";
2431 for (node = tree->first_child; node; node = node->next)
2433 field_info *finfo = PNODE_FINFO(node);
2438 /* XXX, for now always skip hidden */
2439 if (FI_GET_FLAG(finfo, FI_HIDDEN))
2442 printf("%s{", sepa);
2447 char label_str[ITEM_LABEL_LENGTH];
2449 label_str[0] = '\0';
2450 proto_item_fill_label(finfo, label_str);
2451 json_puts_string(label_str);
2455 json_puts_string(finfo->rep->representation);
2458 if (finfo->ds_tvb && tvbs && tvbs[0] != finfo->ds_tvb)
2462 for (idx = 1; tvbs[idx]; idx++)
2464 if (tvbs[idx] == finfo->ds_tvb)
2466 printf(",\"ds\":%d", idx);
2472 if (finfo->start >= 0 && finfo->length > 0)
2473 printf(",\"h\":[%d,%d]", finfo->start, finfo->length);
2475 if (finfo->appendix_start >= 0 && finfo->appendix_length > 0)
2476 printf(",\"i\":[%d,%d]", finfo->appendix_start, finfo->appendix_length);
2481 if (finfo->hfinfo->type == FT_PROTOCOL)
2483 printf(",\"t\":\"proto\"");
2485 else if (finfo->hfinfo->type == FT_FRAMENUM)
2487 printf(",\"t\":\"framenum\",\"fnum\":%u", finfo->value.value.uinteger);
2489 else if (FI_GET_FLAG(finfo, FI_URL) && IS_FT_STRING(finfo->hfinfo->type))
2491 char *url = fvalue_to_string_repr(NULL, &finfo->value, FTREPR_DISPLAY, finfo->hfinfo->display);
2493 printf(",\"t\":\"url\",\"url\":");
2494 json_puts_string(url);
2495 wmem_free(NULL, url);
2499 if (FI_GET_FLAG(finfo, PI_SEVERITY_MASK))
2501 const char *severity = try_val_to_str(FI_GET_FLAG(finfo, PI_SEVERITY_MASK), expert_severity_vals);
2503 g_assert(severity != NULL);
2505 printf(",\"s\":\"%s\"", severity);
2508 if (((proto_tree *) node)->first_child) {
2509 if (finfo->tree_type != -1)
2510 printf(",\"e\":%d", finfo->tree_type);
2512 sharkd_session_process_frame_cb_tree((proto_tree *) node, tvbs);
2522 sharkd_follower_visit_layers_cb(const void *key _U_, void *value, void *user_data)
2524 register_follow_t *follower = (register_follow_t *) value;
2525 packet_info *pi = (packet_info *) user_data;
2527 const int proto_id = get_follow_proto_id(follower);
2529 guint32 ignore_stream;
2531 if (proto_is_frame_protocol(pi->layers, proto_get_protocol_filter_name(proto_id)))
2533 const char *layer_proto = proto_get_protocol_short_name(find_protocol_by_id(proto_id));
2534 char *follow_filter;
2536 follow_filter = get_follow_conv_func(follower)(pi, &ignore_stream);
2538 printf(",[\"%s\",", layer_proto);
2539 json_puts_string(follow_filter);
2542 g_free(follow_filter);
2549 sharkd_session_process_frame_cb(packet_info *pi, proto_tree *tree, struct epan_column_info *cinfo, const GSList *data_src, void *data)
2556 printf("\"err\":0");
2560 tvbuff_t **tvbs = NULL;
2562 printf(",\"tree\":");
2564 /* arrayize data src, to speedup searching for ds_tvb index */
2565 if (data_src && data_src->next /* only needed if there are more than one data source */)
2567 guint count = g_slist_length((GSList *) data_src);
2570 tvbs = (tvbuff_t **) g_malloc((count + 1) * sizeof(*tvbs));
2572 for (i = 0; i < count; i++)
2574 struct data_source *src = (struct data_source *) g_slist_nth_data((GSList *) data_src, i);
2576 tvbs[i] = get_data_source_tvb(src);
2582 sharkd_session_process_frame_cb_tree(tree, tvbs);
2591 printf(",\"col\":[");
2592 for (col = 0; col < cinfo->num_cols; ++col)
2594 const col_item_t *col_item = &cinfo->columns[col];
2596 printf("%s\"%s\"", (col) ? "," : "", col_item->col_data);
2603 struct data_source *src = (struct data_source *)data_src->data;
2604 const char *ds_sepa = NULL;
2609 tvb = get_data_source_tvb(src);
2610 length = tvb_captured_length(tvb);
2612 printf(",\"bytes\":");
2615 const guchar *cp = tvb_get_ptr(tvb, 0, length);
2617 /* XXX pi.fd->flags.encoding */
2618 json_print_base64(cp, length);
2622 json_print_base64("", 0);
2625 data_src = data_src->next;
2628 printf(",\"ds\":[");
2634 src = (struct data_source *)data_src->data;
2637 char *src_name = get_data_source_name(src);
2639 printf("%s{\"name\":", ds_sepa);
2640 json_puts_string(src_name);
2641 wmem_free(NULL, src_name);
2644 tvb = get_data_source_tvb(src);
2645 length = tvb_captured_length(tvb);
2647 printf(",\"bytes\":");
2650 const guchar *cp = tvb_get_ptr(tvb, 0, length);
2652 /* XXX pi.fd->flags.encoding */
2653 json_print_base64(cp, length);
2657 json_print_base64("", 0);
2663 data_src = data_src->next;
2666 /* close ds, only if was opened */
2667 if (ds_sepa != NULL)
2671 printf(",\"fol\":[0");
2672 follow_iterate_followers(sharkd_follower_visit_layers_cb, pi);
2679 * sharkd_session_process_intervals()
2681 * Process intervals request - generate basic capture file statistics per requested interval.
2684 * (o) interval - interval time in ms, if not specified: 1000ms
2685 * (o) filter - filter for generating interval request
2687 * Output object with attributes:
2688 * (m) intervals - array of intervals, with indexes:
2689 * [0] - index of interval,
2690 * [1] - number of frames during interval,
2691 * [2] - number of bytes during interval.
2693 * (m) last - last interval number.
2694 * (m) frames - total number of frames
2695 * (m) bytes - total number of bytes
2697 * NOTE: If frames are not in order, there might be items with same interval index, or even negative one.
2700 sharkd_session_process_intervals(char *buf, const jsmntok_t *tokens, int count)
2702 const char *tok_interval = json_find_attr(buf, tokens, count, "interval");
2703 const char *tok_filter = json_find_attr(buf, tokens, count, "filter");
2705 const guint8 *filter_data = NULL;
2709 unsigned int frames;
2713 nstime_t *start_ts = NULL;
2715 guint32 interval_ms = 1000; /* default: one per second */
2717 const char *sepa = "";
2718 unsigned int framenum;
2723 if (!ws_strtou32(tok_interval, NULL, &interval_ms) || interval_ms == 0) {
2724 fprintf(stderr, "Invalid interval parameter: %s.\n", tok_interval);
2731 filter_data = sharkd_session_filter_data(tok_filter);
2736 st_total.frames = 0;
2744 printf("{\"intervals\":[");
2746 for (framenum = 1; framenum <= cfile.count; framenum++)
2748 frame_data *fdata = frame_data_sequence_find(cfile.frames, framenum);
2752 if (start_ts == NULL)
2753 start_ts = &fdata->abs_ts;
2755 if (filter_data && !(filter_data[framenum / 8] & (1 << (framenum % 8))))
2758 msec_rel = (fdata->abs_ts.secs - start_ts->secs) * (gint64) 1000 + (fdata->abs_ts.nsecs - start_ts->nsecs) / 1000000;
2759 new_idx = msec_rel / interval_ms;
2765 printf("%s[%" G_GINT64_FORMAT ",%u,%" G_GUINT64_FORMAT "]", sepa, idx, st.frames, st.bytes);
2778 st.bytes += fdata->pkt_len;
2780 st_total.frames += 1;
2781 st_total.bytes += fdata->pkt_len;
2786 printf("%s[%" G_GINT64_FORMAT ",%u,%" G_GUINT64_FORMAT "]", sepa, idx, st.frames, st.bytes);
2790 printf("],\"last\":%" G_GINT64_FORMAT ",\"frames\":%u,\"bytes\":%" G_GUINT64_FORMAT "}\n", max_idx, st_total.frames, st_total.bytes);
2794 * sharkd_session_process_frame()
2796 * Process frame request
2799 * (m) frame - requested frame number
2800 * (o) proto - set if output frame tree
2801 * (o) columns - set if output frame columns
2802 * (o) bytes - set if output frame bytes
2804 * Output object with attributes:
2805 * (m) err - 0 if succeed
2806 * (o) tree - array of frame nodes with attributes:
2808 * t: 'proto', 'framenum', 'url' - type of node
2810 * e - subtree ett index
2811 * n - array of subtree nodes
2812 * h - two item array: (item start, item length)
2813 * i - two item array: (appendix start, appendix length)
2814 * p - [RESERVED] two item array: (protocol start, protocol length)
2815 * ds- data src index
2816 * url - only for t:'url', url
2817 * fnum - only for t:'framenum', frame number
2819 * (o) col - array of column data
2820 * (o) bytes - base64 of frame bytes
2821 * (o) ds - array of other data srcs
2822 * (o) fol - array of follow filters:
2824 * [1] - filter string
2827 sharkd_session_process_frame(char *buf, const jsmntok_t *tokens, int count)
2829 const char *tok_frame = json_find_attr(buf, tokens, count, "frame");
2830 int tok_proto = (json_find_attr(buf, tokens, count, "proto") != NULL);
2831 int tok_bytes = (json_find_attr(buf, tokens, count, "bytes") != NULL);
2832 int tok_columns = (json_find_attr(buf, tokens, count, "columns") != NULL);
2836 if (!tok_frame || !ws_strtou32(tok_frame, NULL, &framenum) || framenum == 0)
2839 sharkd_dissect_request(framenum, &sharkd_session_process_frame_cb, tok_bytes, tok_columns, tok_proto, NULL);
2843 * sharkd_session_process_check()
2845 * Process check request.
2848 * (o) filter - filter to be checked
2850 * Output object with attributes:
2851 * (m) err - always 0
2852 * (o) filter - 'ok', 'warn' or error message
2855 sharkd_session_process_check(char *buf, const jsmntok_t *tokens, int count)
2857 const char *tok_filter = json_find_attr(buf, tokens, count, "filter");
2859 printf("{\"err\":0");
2860 if (tok_filter != NULL)
2862 char *err_msg = NULL;
2865 if (dfilter_compile(tok_filter, &dfp, &err_msg))
2867 const char *s = "ok";
2869 if (dfilter_deprecated_tokens(dfp))
2872 printf(",\"filter\":\"%s\"", s);
2877 printf(",\"filter\":");
2878 json_puts_string(err_msg);
2887 struct sharkd_session_process_complete_pref_data
2895 sharkd_session_process_complete_pref_cb(module_t *module, gpointer d)
2897 struct sharkd_session_process_complete_pref_data *data = (struct sharkd_session_process_complete_pref_data *) d;
2899 if (strncmp(data->pref, module->name, strlen(data->pref)) != 0)
2902 printf("%s{\"f\":\"%s\",\"d\":\"%s\"}", data->sepa, module->name, module->title);
2909 sharkd_session_process_complete_pref_option_cb(pref_t *pref, gpointer d)
2911 struct sharkd_session_process_complete_pref_data *data = (struct sharkd_session_process_complete_pref_data *) d;
2912 const char *pref_name = prefs_get_name(pref);
2913 const char *pref_title = prefs_get_title(pref);
2915 if (strncmp(data->pref, pref_name, strlen(data->pref)) != 0)
2918 printf("%s{\"f\":\"%s.%s\",\"d\":\"%s\"}", data->sepa, data->module, pref_name, pref_title);
2921 return 0; /* continue */
2925 * sharkd_session_process_complete()
2927 * Process complete request
2930 * (o) field - field to be completed
2931 * (o) pref - preference to be completed
2933 * Output object with attributes:
2934 * (m) err - always 0
2935 * (o) field - array of object with attributes:
2936 * (m) f - field text
2937 * (o) t - field type (FT_ number)
2938 * (o) n - field name
2939 * (o) pref - array of object with attributes:
2941 * (o) d - pref description
2944 sharkd_session_process_complete(char *buf, const jsmntok_t *tokens, int count)
2946 const char *tok_field = json_find_attr(buf, tokens, count, "field");
2947 const char *tok_pref = json_find_attr(buf, tokens, count, "pref");
2949 printf("{\"err\":0");
2950 if (tok_field != NULL && tok_field[0])
2952 const size_t filter_length = strlen(tok_field);
2953 const int filter_with_dot = !!strchr(tok_field, '.');
2958 const char *sepa = "";
2960 printf(",\"field\":[");
2962 for (proto_id = proto_get_first_protocol(&proto_cookie); proto_id != -1; proto_id = proto_get_next_protocol(&proto_cookie))
2964 protocol_t *protocol = find_protocol_by_id(proto_id);
2965 const char *protocol_filter;
2966 const char *protocol_name;
2967 header_field_info *hfinfo;
2969 if (!proto_is_protocol_enabled(protocol))
2972 protocol_name = proto_get_protocol_long_name(protocol);
2973 protocol_filter = proto_get_protocol_filter_name(proto_id);
2975 if (strlen(protocol_filter) >= filter_length && !g_ascii_strncasecmp(tok_field, protocol_filter, filter_length))
2977 printf("%s{", sepa);
2980 json_puts_string(protocol_filter);
2981 printf(",\"t\":%d", FT_PROTOCOL);
2983 json_puts_string(protocol_name);
2989 if (!filter_with_dot)
2992 for (hfinfo = proto_get_first_protocol_field(proto_id, &field_cookie); hfinfo != NULL; hfinfo = proto_get_next_protocol_field(proto_id, &field_cookie))
2994 if (hfinfo->same_name_prev_id != -1) /* ignore duplicate names */
2997 if (strlen(hfinfo->abbrev) >= filter_length && !g_ascii_strncasecmp(tok_field, hfinfo->abbrev, filter_length))
2999 printf("%s{", sepa);
3002 json_puts_string(hfinfo->abbrev);
3004 /* XXX, skip displaying name, if there are multiple (to not confuse user) */
3005 if (hfinfo->same_name_next == NULL)
3007 printf(",\"t\":%d", hfinfo->type);
3009 json_puts_string(hfinfo->name);
3021 if (tok_pref != NULL && tok_pref[0])
3023 struct sharkd_session_process_complete_pref_data data;
3026 data.module = tok_pref;
3027 data.pref = tok_pref;
3030 printf(",\"pref\":[");
3032 if ((dot_sepa = strchr(tok_pref, '.')))
3036 *dot_sepa = '\0'; /* XXX, C abuse: discarding-const */
3037 data.pref = dot_sepa + 1;
3039 pref_mod = prefs_find_module(data.module);
3041 prefs_pref_foreach(pref_mod, sharkd_session_process_complete_pref_option_cb, &data);
3047 prefs_modules_foreach(sharkd_session_process_complete_pref_cb, &data);
3059 * sharkd_session_process_setconf()
3061 * Process setconf request
3064 * (m) name - preference name
3065 * (m) value - preference value
3067 * Output object with attributes:
3068 * (m) err - error code: 0 succeed
3071 sharkd_session_process_setconf(char *buf, const jsmntok_t *tokens, int count)
3073 const char *tok_name = json_find_attr(buf, tokens, count, "name");
3074 const char *tok_value = json_find_attr(buf, tokens, count, "value");
3077 prefs_set_pref_e ret;
3079 if (!tok_name || tok_name[0] == '\0' || !tok_value)
3082 ws_snprintf(pref, sizeof(pref), "%s:%s", tok_name, tok_value);
3084 ret = prefs_set_pref(pref);
3085 printf("{\"err\":%d}\n", ret);
3088 struct sharkd_session_process_dumpconf_data
3095 sharkd_session_process_dumpconf_cb(pref_t *pref, gpointer d)
3097 struct sharkd_session_process_dumpconf_data *data = (struct sharkd_session_process_dumpconf_data *) d;
3098 const char *pref_name = prefs_get_name(pref);
3100 printf("%s\"%s.%s\":{", data->sepa, data->module->name, pref_name);
3102 switch (prefs_get_type(pref))
3105 case PREF_DECODE_AS_UINT:
3106 printf("\"u\":%u", prefs_get_uint_value_real(pref, pref_current));
3107 if (prefs_get_uint_base(pref) != 10)
3108 printf(",\"ub\":%u", prefs_get_uint_base(pref));
3112 printf("\"b\":%s", prefs_get_bool_value(pref, pref_current) ? "1" : "0");
3117 json_puts_string(prefs_get_string_value(pref, pref_current));
3122 const enum_val_t *enums;
3123 const char *enum_sepa = "";
3126 for (enums = prefs_get_enumvals(pref); enums->name; enums++)
3128 printf("%s{\"v\":%d", enum_sepa, enums->value);
3130 if (enums->value == prefs_get_enum_value(pref, pref_current))
3134 json_puts_string(enums->description);
3144 case PREF_DECODE_AS_RANGE:
3146 char *range_str = range_convert_range(NULL, prefs_get_range_value_real(pref, pref_current));
3147 printf("\"r\":\"%s\"", range_str);
3148 wmem_free(NULL, range_str);
3154 uat_t *uat = prefs_get_uat_value(pref);
3158 for (idx = 0; idx < uat->raw_data->len; idx++)
3160 void *rec = UAT_INDEX_PTR(uat, idx);
3167 for (colnum = 0; colnum < uat->ncols; colnum++)
3169 char *str = uat_fld_tostr(rec, &(uat->fields[colnum]));
3174 json_puts_string(str);
3187 case PREF_STATIC_TEXT:
3195 json_puts_string(prefs_get_title(pref));
3201 return 0; /* continue */
3205 sharkd_session_process_dumpconf_mod_cb(module_t *module, gpointer d)
3207 struct sharkd_session_process_dumpconf_data *data = (struct sharkd_session_process_dumpconf_data *) d;
3209 data->module = module;
3210 prefs_pref_foreach(module, sharkd_session_process_dumpconf_cb, data);
3216 * sharkd_session_process_dumpconf()
3218 * Process dumpconf request
3221 * (o) pref - module, or preference, NULL for all
3223 * Output object with attributes:
3224 * (o) prefs - object with module preferences
3225 * (m) [KEY] - preference name
3226 * (o) u - preference value (only for PREF_UINT)
3227 * (o) ub - preference value suggested base for display (only for PREF_UINT) and if different than 10
3228 * (o) b - preference value (only for PREF_BOOL) (1 true, 0 false)
3229 * (o) s - preference value (only for PREF_STRING)
3230 * (o) e - preference possible values (only for PREF_ENUM)
3231 * (o) r - preference value (only for PREF_RANGE)
3232 * (o) t - preference value (only for PREF_UAT)
3235 sharkd_session_process_dumpconf(char *buf, const jsmntok_t *tokens, int count)
3237 const char *tok_pref = json_find_attr(buf, tokens, count, "pref");
3243 struct sharkd_session_process_dumpconf_data data;
3248 printf("{\"prefs\":{");
3249 prefs_modules_foreach(sharkd_session_process_dumpconf_mod_cb, &data);
3254 if ((dot_sepa = strchr(tok_pref, '.')))
3256 pref_t *pref = NULL;
3258 *dot_sepa = '\0'; /* XXX, C abuse: discarding-const */
3259 pref_mod = prefs_find_module(tok_pref);
3261 pref = prefs_find_preference(pref_mod, dot_sepa + 1);
3266 struct sharkd_session_process_dumpconf_data data;
3268 data.module = pref_mod;
3271 printf("{\"prefs\":{");
3272 sharkd_session_process_dumpconf_cb(pref, &data);
3279 pref_mod = prefs_find_module(tok_pref);
3282 struct sharkd_session_process_dumpconf_data data;
3284 data.module = pref_mod;
3287 printf("{\"prefs\":{");
3288 prefs_pref_foreach(pref_mod, sharkd_session_process_dumpconf_cb, &data);
3293 struct sharkd_download_rtp
3295 struct sharkd_rtp_match rtp;
3301 sharkd_rtp_download_free_items(void *ptr)
3303 rtp_packet_t *rtp_packet = (rtp_packet_t *) ptr;
3305 g_free(rtp_packet->info);
3306 g_free(rtp_packet->payload_data);
3311 sharkd_rtp_download_decode(struct sharkd_download_rtp *req)
3313 /* based on RtpAudioStream::decode() 6e29d874f8b5e6ebc59f661a0bb0dab8e56f122a */
3314 /* TODO, for now only without silence (timing_mode_ = Uninterrupted) */
3316 static const int sample_bytes_ = sizeof(SAMPLE) / sizeof(char);
3318 guint32 audio_out_rate_ = 0;
3319 struct _GHashTable *decoders_hash_ = rtp_decoder_hash_table_new();
3320 struct SpeexResamplerState_ *audio_resampler_ = NULL;
3322 gsize resample_buff_len = 0x1000;
3323 SAMPLE *resample_buff = (SAMPLE *) g_malloc(resample_buff_len);
3324 spx_uint32_t cur_in_rate = 0;
3325 char *write_buff = NULL;
3326 gint64 write_bytes = 0;
3327 unsigned channels = 0;
3328 unsigned sample_rate = 0;
3331 int base64_state1 = 0;
3332 int base64_state2 = 0;
3336 for (l = req->packets; l; l = l->next)
3338 rtp_packet_t *rtp_packet = (rtp_packet_t *) l->data;
3340 SAMPLE *decode_buff = NULL;
3341 size_t decoded_bytes;
3343 decoded_bytes = decode_rtp_packet(rtp_packet, &decode_buff, decoders_hash_, &channels, &sample_rate);
3344 if (decoded_bytes == 0 || sample_rate == 0)
3346 /* We didn't decode anything. Clean up and prep for the next packet. */
3347 g_free(decode_buff);
3351 if (audio_out_rate_ == 0)
3357 /* First non-zero wins */
3358 audio_out_rate_ = sample_rate;
3360 RTP_STREAM_DEBUG("Audio sample rate is %u", audio_out_rate_);
3362 /* write WAVE header */
3363 memset(&wav_hdr, 0, sizeof(wav_hdr));
3364 memcpy(&wav_hdr[0], "RIFF", 4);
3365 memcpy(&wav_hdr[4], "\xFF\xFF\xFF\xFF", 4); /* XXX, unknown */
3366 memcpy(&wav_hdr[8], "WAVE", 4);
3368 memcpy(&wav_hdr[12], "fmt ", 4);
3369 memcpy(&wav_hdr[16], "\x10\x00\x00\x00", 4); /* PCM */
3370 memcpy(&wav_hdr[20], "\x01\x00", 2); /* PCM */
3373 memcpy(&wav_hdr[22], &tmp16, 2);
3375 tmp32 = sample_rate;
3376 memcpy(&wav_hdr[24], &tmp32, 4);
3378 tmp32 = sample_rate * channels * sample_bytes_;
3379 memcpy(&wav_hdr[28], &tmp32, 4);
3381 tmp16 = channels * sample_bytes_;
3382 memcpy(&wav_hdr[32], &tmp16, 2);
3383 /* bits per sample */
3384 tmp16 = 8 * sample_bytes_;
3385 memcpy(&wav_hdr[34], &tmp16, 2);
3387 memcpy(&wav_hdr[36], "data", 4);
3388 memcpy(&wav_hdr[40], "\xFF\xFF\xFF\xFF", 4); /* XXX, unknown */
3390 for (i = 0; i < (int) sizeof(wav_hdr); i++)
3391 json_print_base64_step(&wav_hdr[i], &base64_state1, &base64_state2);
3394 // Write samples to our file.
3395 write_buff = (char *) decode_buff;
3396 write_bytes = decoded_bytes;
3398 if (audio_out_rate_ != sample_rate)
3400 spx_uint32_t in_len, out_len;
3402 /* Resample the audio to match our previous output rate. */
3403 if (!audio_resampler_)
3405 audio_resampler_ = speex_resampler_init(1, sample_rate, audio_out_rate_, 10, NULL);
3406 speex_resampler_skip_zeros(audio_resampler_);
3407 RTP_STREAM_DEBUG("Started resampling from %u to (out) %u Hz.", sample_rate, audio_out_rate_);
3411 spx_uint32_t audio_out_rate;
3412 speex_resampler_get_rate(audio_resampler_, &cur_in_rate, &audio_out_rate);
3414 if (sample_rate != cur_in_rate)
3416 speex_resampler_set_rate(audio_resampler_, sample_rate, audio_out_rate);
3417 RTP_STREAM_DEBUG("Changed input rate from %u to %u Hz. Out is %u.", cur_in_rate, sample_rate, audio_out_rate_);
3420 in_len = (spx_uint32_t)rtp_packet->info->info_payload_len;
3421 out_len = (audio_out_rate_ * (spx_uint32_t)rtp_packet->info->info_payload_len / sample_rate) + (audio_out_rate_ % sample_rate != 0);
3422 if (out_len * sample_bytes_ > resample_buff_len)
3424 while ((out_len * sample_bytes_ > resample_buff_len))
3425 resample_buff_len *= 2;
3426 resample_buff = (SAMPLE *) g_realloc(resample_buff, resample_buff_len);
3429 speex_resampler_process_int(audio_resampler_, 0, decode_buff, &in_len, resample_buff, &out_len);
3430 write_buff = (char *) resample_buff;
3431 write_bytes = out_len * sample_bytes_;
3434 /* Write the decoded, possibly-resampled audio */
3435 for (i = 0; i < write_bytes; i++)
3436 json_print_base64_step(&write_buff[i], &base64_state1, &base64_state2);
3438 g_free(decode_buff);
3441 json_print_base64_step(NULL, &base64_state1, &base64_state2);
3443 g_free(resample_buff);
3444 g_hash_table_destroy(decoders_hash_);
3448 sharkd_session_packet_download_tap_rtp_cb(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, const void *data)
3450 const struct _rtp_info *rtp_info = (const struct _rtp_info *) data;
3451 struct sharkd_download_rtp *req_rtp = (struct sharkd_download_rtp *) tapdata;
3453 /* do not consider RTP packets without a setup frame */
3454 if (rtp_info->info_setup_frame_num == 0)
3457 if (sharkd_rtp_match_check(&req_rtp->rtp, pinfo, rtp_info))
3459 rtp_packet_t *rtp_packet;
3461 rtp_packet = g_new0(rtp_packet_t, 1);
3462 rtp_packet->info = (struct _rtp_info *) g_memdup(rtp_info, sizeof(struct _rtp_info));
3464 if (rtp_info->info_all_data_present && rtp_info->info_payload_len != 0)
3465 rtp_packet->payload_data = (guint8 *) g_memdup(&(rtp_info->info_data[rtp_info->info_payload_offset]), rtp_info->info_payload_len);
3467 if (!req_rtp->packets)
3468 req_rtp->start_time = nstime_to_sec(&pinfo->abs_ts);
3470 rtp_packet->frame_num = pinfo->num;
3471 rtp_packet->arrive_offset = nstime_to_sec(&pinfo->abs_ts) - req_rtp->start_time;
3473 /* XXX, O(n) optimize */
3474 req_rtp->packets = g_slist_append(req_rtp->packets, rtp_packet);
3481 * sharkd_session_process_download()
3483 * Process download request
3486 * (m) token - token to download
3488 * Output object with attributes:
3489 * (o) file - suggested name of file
3490 * (o) mime - suggested content type
3491 * (o) data - payload base64 encoded
3494 sharkd_session_process_download(char *buf, const jsmntok_t *tokens, int count)
3496 const char *tok_token = json_find_attr(buf, tokens, count, "token");
3501 if (!strncmp(tok_token, "eo:", 3))
3503 struct sharkd_export_object_list *object_list;
3504 const export_object_entry_t *eo_entry = NULL;
3506 for (object_list = sharkd_eo_list; object_list; object_list = object_list->next)
3508 size_t eo_type_len = strlen(object_list->type);
3510 if (!strncmp(tok_token, object_list->type, eo_type_len) && tok_token[eo_type_len] == '_')
3514 if (sscanf(&tok_token[eo_type_len + 1], "%d", &row) != 1)
3517 eo_entry = (export_object_entry_t *) g_slist_nth_data(object_list->entries, row);
3524 const char *mime = (eo_entry->content_type) ? eo_entry->content_type : "application/octet-stream";
3525 const char *filename = (eo_entry->filename) ? eo_entry->filename : tok_token;
3527 printf("{\"file\":");
3528 json_puts_string(filename);
3529 printf(",\"mime\":");
3530 json_puts_string(mime);
3531 printf(",\"data\":");
3532 json_print_base64(eo_entry->payload_data, (int) eo_entry->payload_len); /* XXX, export object will be truncated if >= 2^31 */
3536 else if (!strcmp(tok_token, "ssl-secrets"))
3538 char *str = ssl_export_sessions();
3542 const char *mime = "text/plain";
3543 const char *filename = "keylog.txt";
3545 printf("{\"file\":");
3546 json_puts_string(filename);
3547 printf(",\"mime\":");
3548 json_puts_string(mime);
3549 printf(",\"data\":");
3550 json_print_base64(str, strlen(str));
3555 else if (!strncmp(tok_token, "rtp:", 4))
3557 struct sharkd_download_rtp rtp_req;
3560 memset(&rtp_req, 0, sizeof(rtp_req));
3561 if (!sharkd_rtp_match_init(&rtp_req.rtp, tok_token + 4))
3563 fprintf(stderr, "sharkd_session_process_download() rtp tokenizing error %s\n", tok_token);
3567 tap_error = register_tap_listener("rtp", &rtp_req, NULL, 0, NULL, sharkd_session_packet_download_tap_rtp_cb, NULL);
3570 fprintf(stderr, "sharkd_session_process_download() rtp error=%s", tap_error->str);
3571 g_string_free(tap_error, TRUE);
3576 remove_tap_listener(&rtp_req);
3578 if (rtp_req.packets)
3580 const char *mime = "audio/x-wav";
3581 const char *filename = tok_token;
3583 printf("{\"file\":");
3584 json_puts_string(filename);
3585 printf(",\"mime\":");
3586 json_puts_string(mime);
3588 printf(",\"data\":");
3590 sharkd_rtp_download_decode(&rtp_req);
3595 g_slist_free_full(rtp_req.packets, sharkd_rtp_download_free_items);
3601 sharkd_session_process(char *buf, const jsmntok_t *tokens, int count)
3605 /* sanity check, and split strings */
3606 if (count < 1 || tokens[0].type != JSMN_OBJECT)
3608 fprintf(stderr, "sanity check(1): [0] not object\n");
3612 /* don't need [0] token */
3618 fprintf(stderr, "sanity check(2): %d not even\n", count);
3622 for (i = 0; i < count; i += 2)
3624 if (tokens[i].type != JSMN_STRING)
3626 fprintf(stderr, "sanity check(3): [%d] not string\n", i);
3630 buf[tokens[i + 0].end] = '\0';
3631 buf[tokens[i + 1].end] = '\0';
3633 json_unescape_str(&buf[tokens[i + 0].start]);
3634 json_unescape_str(&buf[tokens[i + 1].start]);
3638 const char *tok_req = json_find_attr(buf, tokens, count, "req");
3642 fprintf(stderr, "sanity check(4): no \"req\".\n");
3646 if (!strcmp(tok_req, "load"))
3647 sharkd_session_process_load(buf, tokens, count);
3648 else if (!strcmp(tok_req, "status"))
3649 sharkd_session_process_status();
3650 else if (!strcmp(tok_req, "analyse"))
3651 sharkd_session_process_analyse();
3652 else if (!strcmp(tok_req, "info"))
3653 sharkd_session_process_info();
3654 else if (!strcmp(tok_req, "check"))
3655 sharkd_session_process_check(buf, tokens, count);
3656 else if (!strcmp(tok_req, "complete"))
3657 sharkd_session_process_complete(buf, tokens, count);
3658 else if (!strcmp(tok_req, "frames"))
3659 sharkd_session_process_frames(buf, tokens, count);
3660 else if (!strcmp(tok_req, "tap"))
3661 sharkd_session_process_tap(buf, tokens, count);
3662 else if (!strcmp(tok_req, "follow"))
3663 sharkd_session_process_follow(buf, tokens, count);
3664 else if (!strcmp(tok_req, "intervals"))
3665 sharkd_session_process_intervals(buf, tokens, count);
3666 else if (!strcmp(tok_req, "frame"))
3667 sharkd_session_process_frame(buf, tokens, count);
3668 else if (!strcmp(tok_req, "setconf"))
3669 sharkd_session_process_setconf(buf, tokens, count);
3670 else if (!strcmp(tok_req, "dumpconf"))
3671 sharkd_session_process_dumpconf(buf, tokens, count);
3672 else if (!strcmp(tok_req, "download"))
3673 sharkd_session_process_download(buf, tokens, count);
3674 else if (!strcmp(tok_req, "bye"))
3677 fprintf(stderr, "::: req = %s\n", tok_req);
3679 /* reply for every command are 0+ lines of JSON reply (outputed above), finished by empty new line */
3683 * We do an explicit fflush after every line, because
3684 * we want output to be written to the socket as soon
3685 * as the line is complete.
3687 * The stream is fully-buffered by default, so it's
3688 * only flushed when the buffer fills or the FILE *
3689 * is closed. On UN*X, we could set it to be line
3690 * buffered, but the MSVC standard I/O routines don't
3691 * support line buffering - they only support *byte*
3692 * buffering, doing a write for every byte written,
3693 * which is too inefficient, and full buffering,
3694 * which is what you get if you request line buffering.
3701 sharkd_session_main(void)
3704 jsmntok_t *tokens = NULL;
3705 int tokens_max = -1;
3707 fprintf(stderr, "Hello in child.\n");
3709 while (fgets(buf, sizeof(buf), stdin))
3711 /* every command is line seperated JSON */
3714 ret = wsjsmn_parse(buf, NULL, 0);
3717 fprintf(stderr, "invalid JSON -> closing\n");
3721 /* fprintf(stderr, "JSON: %d tokens\n", ret); */
3724 if (tokens == NULL || tokens_max < ret)
3727 tokens = (jsmntok_t *) g_realloc(tokens, sizeof(jsmntok_t) * tokens_max);
3730 memset(tokens, 0, ret * sizeof(jsmntok_t));
3732 ret = wsjsmn_parse(buf, tokens, ret);
3735 fprintf(stderr, "invalid JSON(2) -> closing\n");
3739 sharkd_session_process(buf, tokens, ret);
3748 * Editor modelines - http://www.wireshark.org/tools/modelines.html
3753 * indent-tabs-mode: t
3756 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
3757 * :indentSize=8:tabSize=8:noTabs=false: