4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * Copyright (c) 2013 by Luis Ontanon <luis@ontanon.org>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "echld-int.h"
28 #include "echld-util.h"
38 static long timevaldiff(struct timeval *starttime, struct timeval *finishtime) {
40 msec=(finishtime->tv_sec-starttime->tv_sec)*1000;
41 msec+=(finishtime->tv_usec-starttime->tv_usec)/1000;
45 static gboolean pong(echld_msg_type_t type, GByteArray* ba _U_, void* data) {
46 struct _ping* p = (struct _ping*)data;
49 gettimeofday(&t,NULL);
54 ret = timevaldiff(&(p->tv),&t);
61 if (p->cb) p->cb(ret, p->cb_data);
69 extern echld_state_t echld_ping(int chld_id, echld_ping_cb_t pcb, void* cb_data) {
70 struct _ping* p = g_new0(struct _ping,1);
74 gettimeofday(&(p->tv),NULL);
76 return echld_reqh(chld_id, ECHLD_PING, 0, NULL, pong, p);
84 echld_bool_t (*dec)(enc_msg_t*, char**, char**);
85 echld_bool_t (*dec_err)(enc_msg_t*, int* , char**);
89 #define CHNULL ((char*)NULL)
91 static gboolean got_param(echld_msg_type_t type, GByteArray* ba _U_, void* data) {
92 struct _get_param* g = (struct _get_param*)data;
100 g->dec(ba,¶m,&value);
101 g->cb(param,value,NULL,g->cb_data);
107 g->dec_err(ba,&errnum,&err_msg);
108 g->cb(NULL,NULL,err_msg,g->cb_data);
112 err_msg = g_strdup_printf("other type='%s'",TY(type));
113 g->cb(NULL,NULL,err_msg,g->cb_data);
122 extern echld_state_t echld_get_param(int chld_id, const char* param, echld_param_cb_t acb, void* cb_data) {
123 struct _get_param* g = g_new0(struct _get_param,1);
124 echld_parent_encoder_t* enc;
125 parent_decoder_t* dec;
128 echld_get_all_codecs(NULL, NULL, &enc, &dec);
130 em = enc->get_param(param);
134 g->cb_data = cb_data;
136 g->dec_err = dec->error;
138 return echld_reqh(chld_id, ECHLD_GET_PARAM, 0, em, got_param, g);
141 extern echld_state_t echld_set_param(int chld_id, const char* param, const char* value, echld_param_cb_t acb, void* cb_data) {
142 struct _get_param* g = g_new0(struct _get_param,1);
143 echld_parent_encoder_t* enc;
144 parent_decoder_t* dec;
147 echld_get_all_codecs(NULL, NULL, &enc, &dec);
149 em = enc->set_param(param,value);
153 g->cb_data = cb_data;
155 g->dec_err = dec->error;
157 return echld_reqh(chld_id, ECHLD_SET_PARAM, 0, em, got_param, g);
160 typedef struct _close {
165 static gboolean closed(echld_msg_type_t type, GByteArray* ba, void* data) {
166 close_t* c = (close_t*)data;
167 parent_decoder_t* dec;
170 echld_get_all_codecs(NULL, NULL, NULL, &dec);
173 case ECHLD_CLOSING: {
175 c->cb(NULL,c->cb_data);
182 if ( dec->error(ba, &errnum ,&err_msg) ) {
183 c->cb(err_msg,c->cb_data);
186 c->cb("Canot decode error message",c->cb_data);
191 err_msg = g_strdup_printf("other type='%s'",TY(type));
192 c->cb(err_msg,c->cb_data);
202 echld_state_t echld_close(int child_id, echld_close_cb_t pcb, void* cb_data) {
203 close_t* c = g_new0(close_t,1);
205 c->cb_data = cb_data;
207 return echld_reqh(child_id,ECHLD_CLOSE_CHILD, 0, NULL, closed, c);