WIP: restrictions
[wireshark-wip.git] / echld / common.c
blob2032d6cab38c4ed6ec02280c4d6485405d9f1028
1 /* echld_common.h
2 * common functions of ECHLD
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * Copyright (c) 2013 by Luis Ontanon <luis@ontanon.org>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "echld-int.h"
29 #ifdef DEBUG_BASE
31 static int dbg_level = DEBUG_BASE;
32 static FILE* dbg_fp;
33 static const char* dbg_prefix;
35 static void common_dbg(int level, const char* fmt, ...) {
36 va_list ap;
37 char str[1024];
39 if (level > dbg_level) return;
41 va_start(ap,fmt);
42 g_vsnprintf(str,1024,fmt,ap);
43 va_end(ap);
45 if (dbg_fp) {
46 fprintf(dbg_fp,"%s: level=%d msg='%s'\n",dbg_prefix,level,str);
47 fflush(dbg_fp);
51 extern void echld_common_set_dbg(int level, FILE* fp, const char* prefix) {
52 dbg_prefix = prefix;
53 dbg_level = level;
54 dbg_fp = fp;
56 #define DBG(attrs) ( common_dbg attrs )
57 #else
58 #define DBG(attrs)
59 #endif
62 struct _st_map
64 child_state_t id;
65 const char* str;
68 static struct _st_map st_map[] = {
69 { FREE, "FREE"},
70 { CREATING, "CREATING"},
71 { IDLE, "IDLE"},
72 { READY, "READY"},
73 { READING, "READING"},
74 { CAPTURING, "CAPTURING"},
75 { DONE, "DONE"},
76 { CLOSING, "CLOSING"},
77 { CLOSED, "CLOSED"},
78 { ERRORED, "ERRORED"},
79 {0,NULL}
82 const char* echld_state_str(child_state_t id) {
83 int i = 0;
85 for (;st_map[i].str;i++) {
86 if (id == st_map[i].id) return st_map[i].str;
89 return "UNKNOWN";
93 struct _t_map
95 echld_msg_type_t type;
96 const char* str;
99 static struct _t_map t_map[] = {
100 {ECHLD_ERROR,"ERROR"},
101 {ECHLD_TIMED_OUT,"TIMED_OUT"},
102 {ECHLD_NEW_CHILD,"NEW_CHILD"},
103 {ECHLD_HELLO,"HELLO"},
104 {ECHLD_CHILD_DEAD,"CHILD_DEAD"},
105 {ECHLD_CLOSE_CHILD,"CLOSE_CHILD"},
106 {ECHLD_CLOSING,"CLOSING"},
107 {ECHLD_SET_PARAM,"SET_PARAM"},
108 {ECHLD_GET_PARAM,"GET_PARAM"},
109 {ECHLD_PARAM,"PARAM"},
110 {ECHLD_PING,"PING"},
111 {ECHLD_PONG,"PONG"},
112 {ECHLD_OPEN_FILE,"OPEN_FILE"},
113 {ECHLD_FILE_OPENED,"FILE_OPENED"},
114 {ECHLD_OPEN_INTERFACE,"OPEN_INTERFACE"},
115 {ECHLD_INTERFACE_OPENED,"INTERFACE_OPENED"},
116 {ECHLD_START_CAPTURE,"START_CAPTURE"},
117 {ECHLD_CAPTURE_STARTED,"CAPTURE_STARTED"},
118 {ECHLD_NOTIFY,"NOTIFY"},
119 {ECHLD_GET_SUM,"GET_SUM"},
120 {ECHLD_PACKET_SUM,"PACKET_SUM"},
121 {ECHLD_GET_TREE,"GET_TREE"},
122 {ECHLD_TREE,"TREE"},
123 {ECHLD_GET_BUFFER,"GET_BUFFER"},
124 {ECHLD_BUFFER,"BUFFER"},
125 {ECHLD_EOF,"EOF"},
126 {ECHLD_STOP_CAPTURE,"STOP_CAPTURE"},
127 {ECHLD_CAPTURE_STOPPED,"CAPTURE_STOPPED"},
128 {ECHLD_ADD_NOTE,"ADD_NOTE"},
129 {ECHLD_NOTE_ADDED,"NOTE_ADDED"},
130 {ECHLD_APPLY_FILTER,"APPLY_FILTER"},
131 {ECHLD_PACKET_LIST,"PACKET_LIST"},
132 {ECHLD_SAVE_FILE,"SAVE_FILE"},
133 {ECHLD_FILE_SAVED,"FILE_SAVED"},
134 {ECHLD_NULL,NULL}
137 const char* echld_msg_type_str(echld_msg_type_t id) {
138 int i = 0;
140 for (;t_map[i].str;i++) {
141 if (id == t_map[i].type) return t_map[i].str;
144 return "UNKNOWN";
149 the "epan pipe" protocol
152 typedef void (*reader_realloc_t)(echld_reader_t*, size_t);
154 static void child_realloc_buff(echld_reader_t* r, size_t needed) {
155 size_t a = r->actual_len;
156 size_t s = r->len;
157 long rp_off = r->rp - r->data;
159 DBG((2,"REALLOC BUFF needed=%d",needed));
161 if ( a < (s + needed) ) {
162 guint8* data = r->data;
164 do {
165 a *= 2;
166 } while( a < (s + needed) );
168 data = (guint8*)g_realloc(data,a);
170 r->actual_len = a;
171 r->len = s;
172 r->data = data;
173 r->wp = data + s;
174 r->rp = data + rp_off;
178 static reader_realloc_t reader_realloc_buff = child_realloc_buff;
180 #ifdef PARENT_THREADS
181 static void parent_realloc_buff(echld_reader_t* b, size_t needed) {
182 // parent thread: obtain malloc mutex
183 child_realloc_buff(b,needed);
184 // parent thread: release malloc mutex
186 #endif
190 void echld_reset_reader(echld_reader_t* r, int fd, size_t initial) {
191 r->fd = fd;
192 fcntl(fd, F_SETFL, O_NONBLOCK);
194 if (r->data == NULL) {
195 r->actual_len = initial;
196 r->data =(guint8*) g_malloc0(initial);
197 r->wp = r->data;
198 r->rp = r->data;
199 r->len = 0;
200 } else {
201 r->wp = r->data;
202 r->rp = r->data;
203 r->len = 0;
207 void echld_init_reader(echld_reader_t* r, int fd, size_t initial) {
208 echld_reset_reader(r,fd,initial);
213 void free_reader(echld_reader_t* r) {
214 free(r->data);
217 static long reader_readv(echld_reader_t* r, size_t len) {
218 struct iovec iov;
219 long nread;
221 DBG((2,"READV needed=%d",len));
223 if ( (r->actual_len - r->len) < len )
224 reader_realloc_buff(r, len);
226 iov.iov_base = r->wp;
227 iov.iov_len = len;
229 nread = readv(r->fd, &iov, 1);
231 DBG((2,"READV nread=%d msg='%s'",nread, (nread<0) ? strerror(errno) : "-" ));
233 if (nread >= 0) {
234 r->wp += nread;
235 r->len += nread;
238 if (errno == EAGAIN) return 0;
240 return nread;
244 long echld_read_frame(echld_reader_t* r, read_cb_t cb, void* cb_data) {
245 DBG((4,"READ = echld_read_frame fd=%d",r->fd));
247 // it will use shared memory instead of inband communication
248 do {
249 hdr_t* h = (hdr_t*)r->rp;
250 long nread;
251 size_t fr_len = 0;
252 size_t missing;
254 DBG((5,"READ reader_len=%d",r->len));
256 if ( r->len < ECHLD_HDR_LEN) {
257 /* read the header */
258 goto incomplete_header;
259 } else if ( ! reader_has_frame(r) ) {
260 /* read the (rest of) the frame */
261 goto incomplete_frame;
264 DBG((5,"READ we've got a frame! fr_len=%d ch=%d t='%c' rh=%d",fr_len, h->h.chld_id, HDR_TYPE(h), h->h.reqh_id));
267 cb( &(r->rp[sizeof(hdr_t)]), HDR_LEN(h), h->h.chld_id, HDR_TYPE(h), h->h.reqh_id, cb_data);
269 r->len = 0;
270 r->wp = r->data;
271 r->rp = r->data;
273 DBG((5,"READ consumed frame!"));
275 goto again;
277 incomplete_header:
278 missing = ECHLD_HDR_LEN - (r->len);
279 DBG((5,"READ incomplete_header missing=%d",missing));
281 nread = reader_readv(r,missing);
284 if (nread < 0 && errno != EAGAIN) {
285 goto kaput; /*XXX*/
286 } else if (nread < (long)missing) {
287 goto again;
288 } else {
289 goto incomplete_frame;
292 incomplete_frame:
293 fr_len = HDR_LEN(h) + ECHLD_HDR_LEN;
294 missing = fr_len - r->len;
296 DBG((5,"READ incomplete_frame fr_len=%d missing=%d",fr_len ,missing));
298 if (missing) {
299 nread = reader_readv(r,missing);
301 if (nread < 0 && errno != EAGAIN) {
302 goto kaput; /*XXX*/
303 } else if (nread < (long)missing) {
304 goto again;
308 } while(1);
310 DBG((1,"READ incomplete_frame Cannot happen"));
312 return 0;
313 again: return 1;
314 kaput: return -1;
317 long echld_write_frame(int fd, GByteArray* ba, guint16 chld_id, echld_msg_type_t type, guint16 reqh_id, void* data _U_) {
318 hdr_t h;
319 struct iovec iov[2];
320 int iov_cnt = 1;
323 h.h.type_len = (type<<24) | ((ba?ba->len:0) & 0x00ffffff) ;
324 h.h.chld_id = chld_id;
325 h.h.reqh_id = reqh_id;
327 iov[0].iov_base = &h;
328 iov[0].iov_len = 8;
330 if ( ba && ba->len > 0 ) {
331 iov[1].iov_base = ba->data;
332 iov[1].iov_len = ba->len;
333 iov_cnt++;
336 return (long) writev(fd, iov, iov_cnt);
339 /* paramset management */
341 param_t* paramset_find (param_t* paramsets, char* name, char** err) {
342 int i;
343 for (i = 0; paramsets[i].name != NULL;i++) {
344 if (strcmp(name,paramsets[i].name) == 0 ) return &(paramsets[i]);
347 *err = g_strdup_printf("Could not find param='%s'",name);
348 return NULL;
351 echld_bool_t paramset_apply_set (param_t* paramsets, char* name, char* val, char** err) {
352 param_t* p = paramset_find(paramsets,name,err);
354 if ( !p ) return FALSE;
355 if ( ! p->set ) {
356 *err = g_strdup_printf("Cannot set RO param='%s'",name);
357 return FALSE;
360 return p->set(val,err);
363 char* paramset_apply_get (param_t* paramsets, char* name, char** err) {
364 param_t* p = paramset_find(paramsets,name,err);
366 if ( !p ) return NULL;
368 if ( ! p->get ) {
369 *err = g_strdup_printf("Cannot get WO param='%s'",name);
370 return NULL;
373 return p->get(err);
376 echld_bool_t paramset_apply_em(param_t* paramset, enc_msg_t* em, char** err) {
377 GByteArray* ba = (GByteArray*)em;
378 char* p = (char*) ba->data;
379 int tot_len = ba->len;
380 long rem = tot_len;
381 p[rem-1] = '\0'; /* make sure last char is null */
383 while(rem > 2) {
384 char* param = p;
385 long param_len = strlen(param)+1;
386 char* value = p + param_len;
387 long value_len;
389 rem -= param_len;
391 if (rem < 0) {
392 *err = g_strdup_printf("Malformed msg param len invalid");
393 return FALSE;
396 value_len = strlen(value)+1;
398 rem -= value_len;
399 p = value + value_len;
401 if (rem < 0) {
402 *err = g_strdup_printf("Malformed msg value len invalid");
403 return FALSE;
406 if (! paramset_apply_set(paramset,param,value,err))
407 return FALSE;
410 return TRUE;
413 char* paramset_get_params_list(param_t* paramsets,const char* fmt) {
414 param_t* p = paramsets;
415 GString* str = g_string_new("");
416 char* s;
418 for (;p->name;p++) {
419 g_string_append_printf(str,fmt,
420 p->name,
421 ((p->get && p->set)?"rw":(p->get?"ro":"wo")),
422 p->desc);
425 s = str->str;
426 g_string_free(str,FALSE);
427 return s;
433 /* encoders and decoders */
439 /* binary encoders and decoders used for parent->child communication */
441 static enc_msg_t* str_enc(const char* s) {
442 GByteArray* ba = g_byte_array_new();
443 g_byte_array_append(ba,s,(guint)(strlen(s)+1));
444 return (enc_msg_t*)ba;
447 static gboolean str_dec(guint8* b, size_t bs, char** text) {
448 guint8* end = b+bs;
449 b[bs-1] = '\0'; /* null terminate the buffer to avoid strlen running */
450 *text = (char*)b;
451 if (b+(strlen(b)+1) > end) return FALSE;
452 return TRUE;
455 static gboolean str_deca(enc_msg_t* ba, char** text) {
456 return str_dec(ba->data,ba->len,text);
459 static enc_msg_t* int_str_enc(int i, const char* s) {
460 GByteArray* ba = g_byte_array_new();
461 g_byte_array_append(ba,(guint8*)&i,sizeof(int));
462 g_byte_array_append(ba,s,(guint)(strlen(s)+1));
463 return (enc_msg_t*)ba;
466 static gboolean int_str_dec(guint8* b, size_t bs, int* ip, char** text) {
467 guint8* end = b+bs;
468 b[bs-1] = '\0'; /* null terminate the buffer to avoid strlen running */
470 if ((sizeof(int)) > bs) return FALSE;
471 *ip = *((int*)b);
472 b += (sizeof(int));
473 *text = (char*)b;
474 if ((b += (strlen(b)+1)) > end) return FALSE;
476 return TRUE;
479 static gboolean int_str_deca(enc_msg_t* ba, int* ip, char** text) {
480 return int_str_dec(ba->data,ba->len,ip,text);
483 static enc_msg_t* int_enc(int i) {
484 GByteArray* ba = g_byte_array_new();
485 g_byte_array_append(ba,(guint8*)&i,sizeof(int));
486 return (enc_msg_t*)ba;
489 static gboolean int_dec(guint8* b, size_t bs, int* ip) {
490 if ((sizeof(int)) > bs) return FALSE;
491 *ip = *((int*)b);
492 return TRUE;
495 static gboolean int_deca(enc_msg_t* ba, int* ip) {
496 return int_dec(ba->data,ba->len,ip);
499 static enc_msg_t* x2str_enc(const char* s1, const char* s2) {
500 GByteArray* ba = g_byte_array_new();
501 g_byte_array_append(ba,s1,(guint)(strlen(s1)+1));
502 g_byte_array_append(ba,s2,(guint)(strlen(s2)+1));
503 return (enc_msg_t*)ba;
506 static gboolean x2str_dec(guint8* b, size_t blen, char** str1, char** str2) {
507 guint8* end = b+blen;
508 b[blen-1] = '\0'; /* null terminate the buffer to avoid strlen running */
510 *str1 = (char*)b;
511 if ((b += (strlen(b)+1)) > end) return FALSE;
512 *str2 = (char*)(b);
513 if ((b += (strlen(b)+1)) > end) return FALSE;
514 return TRUE;
517 static gboolean x2str_deca(enc_msg_t* ba, char** str1, char** str2) {
518 return x2str_dec(ba->data,ba->len,str1,str2);
521 static gboolean int_3str_dec (guint8* b, size_t len, int* i, char** s1, char** s2, char** s3) {
522 guint8* end = b+len;
523 b[len-1] = '\0';
525 if ((sizeof(int)) > len) return FALSE;
526 *i = *((int*)b);
527 b += sizeof(int);
529 *s1 = (char*)b;
530 if ((b += (strlen(b)+1)) > end) return FALSE;
531 *s2 = (char*)(b);
532 if ((b += (strlen(b)+1)) > end) return FALSE;
533 *s3 = (char*)b;
534 if ((b += (strlen(b)+1)) > end) return FALSE;
535 return TRUE;
538 static enc_msg_t* int_3str_enc(int i, const char* s1, const char* s2, const char* s3) {
539 GByteArray* ba = g_byte_array_new();
540 g_byte_array_append(ba,(guint8*)&i,sizeof(int));
541 g_byte_array_append(ba,s1,(guint)(strlen(s1)+1));
542 g_byte_array_append(ba,s2,(guint)(strlen(s2)+1));
543 g_byte_array_append(ba,s3,(guint)(strlen(s3)+1));
544 return (enc_msg_t*)ba;
547 static gboolean int_3str_deca (enc_msg_t* e, int* i, char** s1, char** s2, char** s3) {
548 return int_3str_dec(e->data,e->len,i,s1,s2,s3);
551 static gboolean x3str_dec (guint8* b, size_t len, char** s1, char** s2, char** s3) {
552 guint8* end = b+len;
553 b[len-1] = '\0';
556 *s1 = (char*)b;
557 if ((b += (strlen(b)+1)) > end) return FALSE;
558 *s2 = (char*)(b);
559 if ((b += (strlen(b)+1)) > end) return FALSE;
560 *s3 = (char*)b;
561 if ((b += (strlen(b)+1)) > end) return FALSE;
562 return TRUE;
565 static gboolean x3str_deca (enc_msg_t* e, char** s1, char** s2, char** s3) {
566 return x3str_dec(e->data,e->len,s1,s2,s3);
570 static enc_msg_t* x3str_enc(const char* s1, const char* s2, const char* s3) {
571 GByteArray* ba = g_byte_array_new();
572 g_byte_array_append(ba,s1,(guint)(strlen(s1)+1));
573 g_byte_array_append(ba,s2,(guint)(strlen(s2)+1));
574 g_byte_array_append(ba,s3,(guint)(strlen(s3)+1));
575 return (enc_msg_t*)ba;
578 static echld_parent_encoder_t parent_encoder = {
579 int_str_enc,
580 str_enc,
581 x2str_enc,
582 int_enc,
583 str_enc,
584 x2str_enc,
585 str_enc,
586 str_enc,
587 str_enc,
588 int_str_enc,
589 str_enc,
590 x2str_enc
593 echld_parent_encoder_t* echld_get_encoder(void) {
594 return &parent_encoder;
597 static child_decoder_t child_decoder = {
598 int_str_dec,
599 x2str_dec,
600 str_dec,
601 int_dec,
602 str_dec,
603 x2str_dec,
604 str_dec,
605 str_dec,
606 str_dec,
607 int_str_dec,
608 str_dec,
609 x2str_dec
612 static child_encoder_t child_encoder = {
613 int_str_enc,
614 str_enc,
615 x2str_enc,
616 str_enc,
617 int_str_enc,
618 int_str_enc,
619 int_3str_enc,
620 x3str_enc
623 static parent_decoder_t parent_decoder = {
624 int_str_deca,
625 str_deca,
626 x2str_deca,
627 str_deca,
628 int_str_deca,
629 int_str_deca,
630 int_3str_deca,
631 x3str_deca
634 void echld_get_all_codecs( child_encoder_t **e, child_decoder_t **d, echld_parent_encoder_t **pe, parent_decoder_t** pd) {
635 e && (*e = &child_encoder);
636 d && (*d = &child_decoder);
637 pe && (*pe = &parent_encoder);
638 pd && (*pd = &parent_decoder);
643 /* output encoders, used in the switch */
646 static char* packet_summary_json(GByteArray* ba _U_) {
647 /* dummy */
648 return g_strdup("{type='packet_summary', packet_summary={}");
651 static char* tree_json(GByteArray* ba _U_) {
652 /* dummy */
653 return g_strdup("{type='tree', tree={}");
656 char* tvb_json(GByteArray* ba _U_, tvb_t* tvb _U_, const char* name) {
657 /* dummy */
658 return g_strdup_printf("{type='buffer', buffer={name='%s', range='0-2', data=[0x12,0xff] }",name);
661 static char* error_json(GByteArray* ba) {
662 char* s = (char*)(ba->data + sizeof(int));
663 int i = *((int*)s);
665 s = g_strdup_printf("{type='error', error={errnum=%d, message='%s'}}",i,s);
667 return s;
670 static char* child_dead_json(GByteArray* ba) {
671 char* s = (char*)(ba->data + sizeof(int));
672 int i = *((int*)s);
674 s = g_strdup_printf("{type='child_dead', child_dead={childnum=%d, message='%s'}}",i,s);
676 return s;
679 static char* closing_json(GByteArray* ba) {
680 char* s = (char*)(ba->data);
681 s = g_strdup_printf("{type='closing', closing={reason='%s'}}",s);
683 return s;
688 static char* note_added_json(GByteArray* ba) {
689 char* s = (char*)(ba->data);
690 s = g_strdup_printf("{ type='note_added', note_added={msg='%s'}}",s);
692 return s;
695 static char* packet_list_json(GByteArray* ba _U_) {
696 return g_strdup("{}");
699 static char* file_saved_json(GByteArray* ba) {
700 char* s = (char*)(ba->data);
702 s = g_strdup_printf("{ type='file_saved', file_saved={msg='%s'}}",s);
704 return s;
709 static char* param_set_json(GByteArray* ba) {
710 char* s1 = (char*)(ba->data);
711 char* s2 = ((char*)(ba->data)) + strlen(s1);
713 s1 = g_strdup_printf("{type='param_set', param_set={param='%s' value='%s'}}",s1,s2);
716 return s1;
719 static char* set_param_json(GByteArray* ba) {
720 char* s1 = (char*)(ba->data);
721 char* s2 = ((char*)(ba->data)) + strlen(s1);
723 s1 = g_strdup_printf("{type='set_param', set_param={param='%s' value='%s'}}",s1,s2);
726 return s1;
729 static char* get_param_json(GByteArray* ba) {
730 char* s1 = (char*)(ba->data);
732 s1 = g_strdup_printf("{type='get_param', get_param={param='%s'}}",s1);
735 return s1;
738 static char* file_opened_json(GByteArray* ba _U_) {
739 return g_strdup("");
742 static char* open_file_json(GByteArray* ba _U_) {
743 return g_strdup("");
746 static char* open_interface_json(GByteArray* ba _U_) {
747 return g_strdup("");
751 static char* interface_opened_json(GByteArray* ba _U_) {
752 return g_strdup("");
755 static char* notify_json(GByteArray* ba _U_) {
756 return g_strdup("");
759 static char* get_tree_json(GByteArray* ba _U_) {
760 return g_strdup("");
763 static char* get_sum_json(GByteArray* ba _U_) {
764 return g_strdup("");
767 static char* get_buffer_json(GByteArray* ba _U_) {
768 return g_strdup("");
771 static char* buffer_json(GByteArray* ba _U_) {
772 return g_strdup("");
775 static char* add_note_json(GByteArray* ba _U_) {
776 return g_strdup("");
779 static char* apply_filter_json(GByteArray* ba _U_) {
780 return g_strdup("");
783 static char* save_file_json(GByteArray* ba _U_) {
784 return g_strdup("");
788 /* this to be used only at the parent */
789 static char* decode_json(echld_msg_type_t type, enc_msg_t* m) {
790 GByteArray* ba = (GByteArray*)m;
792 switch(type) {
793 case ECHLD_ERROR: return error_json(ba);
794 case ECHLD_TIMED_OUT: return g_strdup("{type='timed_out'}");
795 case ECHLD_NEW_CHILD: return g_strdup("{type='new_child'}");
796 case ECHLD_HELLO: return g_strdup("{type='helo'}");
797 case ECHLD_CHILD_DEAD: return child_dead_json(ba);
798 case ECHLD_CLOSE_CHILD: return g_strdup("{type='close_child'}");
799 case ECHLD_CLOSING: return closing_json(ba);
800 case ECHLD_SET_PARAM: return set_param_json(ba);
801 case ECHLD_GET_PARAM: return get_param_json(ba);
802 case ECHLD_PARAM: return param_set_json(ba);
803 case ECHLD_PING: return g_strdup("{type='ping'}");
804 case ECHLD_PONG: return g_strdup("{type='pong'}");
805 case ECHLD_OPEN_FILE: return open_file_json(ba);
806 case ECHLD_FILE_OPENED: return file_opened_json(ba);
807 case ECHLD_OPEN_INTERFACE: return open_interface_json(ba);
808 case ECHLD_INTERFACE_OPENED: return interface_opened_json(ba);
809 case ECHLD_START_CAPTURE: return g_strdup("{type='start_capture'}");
810 case ECHLD_CAPTURE_STARTED: return g_strdup("{type='capture_started'}");
811 case ECHLD_NOTIFY: return notify_json(ba);
812 case ECHLD_GET_SUM: return get_sum_json(ba);
813 case ECHLD_PACKET_SUM: return packet_summary_json(ba);
814 case ECHLD_GET_TREE: return get_tree_json(ba);
815 case ECHLD_TREE: return tree_json(ba);
816 case ECHLD_GET_BUFFER: return get_buffer_json(ba);
817 case ECHLD_BUFFER: return buffer_json(ba);
818 case ECHLD_EOF: return g_strdup("{type='eof'}");
819 case ECHLD_STOP_CAPTURE: return g_strdup("{type='stop_capture'}");
820 case ECHLD_CAPTURE_STOPPED: return g_strdup("{type='capture_stopped'}");
821 case ECHLD_ADD_NOTE: return add_note_json(ba);
822 case ECHLD_NOTE_ADDED: return note_added_json(ba);
823 case ECHLD_APPLY_FILTER: return apply_filter_json(ba);
824 case ECHLD_PACKET_LIST: return packet_list_json(ba);
825 case ECHLD_SAVE_FILE: return save_file_json(ba);
826 case ECHLD_FILE_SAVED: return file_saved_json(ba);
827 case EC_ACTUAL_ERROR: return g_strdup("{type='actual_error'}");
828 default: break;
831 return NULL;
833 char* echld_decode(echld_msg_type_t t, enc_msg_t* m ) {
834 return decode_json(t,m);
839 extern void dummy_switch(echld_msg_type_t type) {
840 switch(type) {
841 case ECHLD_ERROR: break; //
842 case ECHLD_TIMED_OUT: break;
843 case ECHLD_NEW_CHILD: break;
844 case ECHLD_HELLO: break;
845 case ECHLD_CHILD_DEAD: break; //S msg
846 case ECHLD_CLOSE_CHILD: break;
847 case ECHLD_CLOSING: break; //
848 case ECHLD_SET_PARAM: break;
849 case ECHLD_GET_PARAM: break;
850 case ECHLD_PARAM: break; //SS param,val
851 case ECHLD_PING: break;
852 case ECHLD_PONG: break; //
853 case ECHLD_OPEN_FILE: break;
854 case ECHLD_FILE_OPENED: break; //
855 case ECHLD_OPEN_INTERFACE: break;
856 case ECHLD_INTERFACE_OPENED: break; //
857 case ECHLD_START_CAPTURE: break;
858 case ECHLD_CAPTURE_STARTED: break; //
859 case ECHLD_NOTIFY: break; //S notification (pre-encoded)
860 case ECHLD_GET_SUM: break;
861 case ECHLD_PACKET_SUM: break; //S (pre-encoded)
862 case ECHLD_GET_TREE: break;
863 case ECHLD_TREE: break; //IS framenum,tree (pre-encoded)
864 case ECHLD_GET_BUFFER: break;
865 case ECHLD_BUFFER: break; //SSIS name,range,totlen,data
866 case ECHLD_EOF: break; //
867 case ECHLD_STOP_CAPTURE: break;
868 case ECHLD_CAPTURE_STOPPED: break; //
869 case ECHLD_ADD_NOTE: break;
870 case ECHLD_NOTE_ADDED: break; //IS
871 case ECHLD_APPLY_FILTER: break;
872 case ECHLD_PACKET_LIST: break; //SS name,range
873 case ECHLD_SAVE_FILE: break;
874 case ECHLD_FILE_SAVED: break;
875 case EC_ACTUAL_ERROR: break;
878 switch(type) {
879 case ECHLD_NEW_CHILD: break;
880 case ECHLD_CLOSE_CHILD: break;
881 case ECHLD_SET_PARAM: break; // set_param(p,v)
882 case ECHLD_GET_PARAM: break; // get_param(p)
883 case ECHLD_PING: break;
884 case ECHLD_OPEN_FILE: break; // open_file(f,mode)
885 case ECHLD_OPEN_INTERFACE: break; // open_interface(if,param)
886 case ECHLD_START_CAPTURE: break;
887 case ECHLD_GET_SUM: break; // get_sum(rng)
888 case ECHLD_GET_TREE: break; // get_tree(rng)
889 case ECHLD_GET_BUFFER: break; // get_buffer(rng)
890 case ECHLD_STOP_CAPTURE: break;
891 case ECHLD_ADD_NOTE: break; // add_note(framenum,note)
892 case ECHLD_APPLY_FILTER: break; // apply_filter(df)
893 case ECHLD_SAVE_FILE: break; // save_file(f,mode)
896 case ECHLD_ERROR: break; // error(err,reason)
897 case ECHLD_TIMED_OUT: break;
898 case ECHLD_HELLO: break;
899 case ECHLD_CHILD_DEAD: break; // child_dead(msg)
900 case ECHLD_CLOSING: break;
901 case ECHLD_PARAM: break;
902 case ECHLD_PONG: break;
903 case ECHLD_FILE_OPENED: break;
904 case ECHLD_INTERFACE_OPENED: break;
905 case ECHLD_CAPTURE_STARTED: break;
906 case ECHLD_NOTIFY: break; // notify(pre-encoded)
907 case ECHLD_PACKET_SUM: break; // packet_sum(pre-encoded)
908 case ECHLD_TREE: break; //tree(framenum, tree(pre-encoded) )
909 case ECHLD_BUFFER: break; // buffer (name,range,totlen,data)
910 case ECHLD_EOF: break;
911 case ECHLD_CAPTURE_STOPPED: break;
912 case ECHLD_NOTE_ADDED: break;
913 case ECHLD_PACKET_LIST: break; // packet_list(name,filter,range);
914 case ECHLD_FILE_SAVED: break;
916 case EC_ACTUAL_ERROR: break;
920 static void* unused = int_deca;
922 extern void unused_things(void) {
923 unused = NULL;