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.
29 #include "echld-int.h"
30 #include "echld-util.h"
40 static long timevaldiff(struct timeval
*starttime
, struct timeval
*finishtime
) {
42 msec
=(finishtime
->tv_sec
-starttime
->tv_sec
)*1000;
43 msec
+=(finishtime
->tv_usec
-starttime
->tv_usec
)/1000;
47 static gboolean
pong(echld_msg_type_t type
, GByteArray
* ba _U_
, void* data
) {
48 struct _ping
* p
= (struct _ping
*)data
;
51 gettimeofday(&t
,NULL
);
56 ret
= timevaldiff(&(p
->tv
),&t
);
63 if (p
->cb
) p
->cb(ret
, p
->cb_data
);
71 extern echld_state_t
echld_ping(int chld_id
, echld_ping_cb_t pcb
, void* cb_data
) {
72 struct _ping
* p
= g_new0(struct _ping
,1);
76 gettimeofday(&(p
->tv
),NULL
);
78 return echld_reqh(chld_id
, ECHLD_PING
, 0, NULL
, pong
, p
);
86 echld_bool_t (*dec
)(enc_msg_t
*, char**, char**);
87 echld_bool_t (*dec_err
)(enc_msg_t
*, int* , char**);
91 #define CHNULL ((char*)NULL)
93 static gboolean
got_param(echld_msg_type_t type
, GByteArray
* ba _U_
, void* data
) {
94 struct _get_param
* g
= (struct _get_param
*)data
;
102 g
->dec(ba
,¶m
,&value
);
103 g
->cb(param
,value
,NULL
,g
->cb_data
);
109 g
->dec_err(ba
,&errnum
,&err_msg
);
110 g
->cb(NULL
,NULL
,err_msg
,g
->cb_data
);
114 err_msg
= g_strdup_printf("other type='%s'",TY(type
));
115 g
->cb(NULL
,NULL
,err_msg
,g
->cb_data
);
124 extern echld_state_t
echld_get_param(int chld_id
, const char* param
, echld_param_cb_t acb
, void* cb_data
) {
125 struct _get_param
* g
= g_new0(struct _get_param
,1);
126 echld_parent_encoder_t
* enc
;
127 parent_decoder_t
* dec
;
130 echld_get_all_codecs(NULL
, NULL
, &enc
, &dec
);
132 em
= enc
->get_param(param
);
136 g
->cb_data
= cb_data
;
138 g
->dec_err
= dec
->error
;
140 return echld_reqh(chld_id
, ECHLD_GET_PARAM
, 0, em
, got_param
, g
);
143 extern echld_state_t
echld_set_param(int chld_id
, const char* param
, const char* value
, echld_param_cb_t acb
, void* cb_data
) {
144 struct _get_param
* g
= g_new0(struct _get_param
,1);
145 echld_parent_encoder_t
* enc
;
146 parent_decoder_t
* dec
;
149 echld_get_all_codecs(NULL
, NULL
, &enc
, &dec
);
151 em
= enc
->set_param(param
,value
);
155 g
->cb_data
= cb_data
;
157 g
->dec_err
= dec
->error
;
159 return echld_reqh(chld_id
, ECHLD_SET_PARAM
, 0, em
, got_param
, g
);
162 typedef struct _close
{
167 static gboolean
closed(echld_msg_type_t type
, GByteArray
* ba
, void* data
) {
168 close_t
* c
= (close_t
*)data
;
169 parent_decoder_t
* dec
;
172 echld_get_all_codecs(NULL
, NULL
, NULL
, &dec
);
175 case ECHLD_CLOSING
: {
177 c
->cb(NULL
,c
->cb_data
);
184 if ( dec
->error(ba
, &errnum
,&err_msg
) ) {
185 c
->cb(err_msg
,c
->cb_data
);
188 c
->cb("Canot decode error message",c
->cb_data
);
193 err_msg
= g_strdup_printf("other type='%s'",TY(type
));
194 c
->cb(err_msg
,c
->cb_data
);
204 echld_state_t
echld_close(int child_id
, echld_close_cb_t pcb
, void* cb_data
) {
205 close_t
* c
= g_new0(close_t
,1);
207 c
->cb_data
= cb_data
;
209 return echld_reqh(child_id
,ECHLD_CLOSE_CHILD
, 0, NULL
, closed
, c
);