dect
/
libdect
Archived
13
0
Fork 0

example: add dummy ops for unimplemented functions

Avoid segfaults when unimplemented callbacks are invoked by providing
dummy functions.

Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
Patrick McHardy 2009-12-28 17:58:15 +01:00
parent 548fc15cb5
commit ad905dd6d0
7 changed files with 343 additions and 8 deletions

View File

@ -3,17 +3,21 @@ PROGRAMS += cc mm-fp discover hijack
cc-destdir := usr/bin
cc-obj += event_ops.o
cc-obj += dummy_ops.o
cc-obj += audio.o
cc-obj += cc.o
mm-fp-destdir := usr/bin
mm-fp-obj += event_ops.o
mm-fp-obj += dummy_ops.o
mm-fp-obj += mm-fp.o
discover-destdir:= usr/bin
discover-obj += event_ops.o
discover-obj += dummy_ops.o
discover-obj += discover.o
hijack-destdir := usr/bin
hijack-obj += event_ops.o
hijack-obj += dummy_ops.o
hijack-obj += hijack.o

View File

@ -244,7 +244,7 @@ static void dect_dl_u_data_ind(struct dect_handle *dh, struct dect_call *call,
dect_audio_queue(priv->audio, mb);
}
static const struct dect_cc_ops cc_ops = {
static struct dect_cc_ops cc_ops = {
.priv_size = sizeof(struct call),
.mncc_connect_ind = dect_mncc_connect_ind,
.mncc_setup_ind = dect_mncc_setup_ind,
@ -256,18 +256,14 @@ static const struct dect_cc_ops cc_ops = {
.dl_u_data_ind = dect_dl_u_data_ind,
};
static const struct dect_mm_ops mm_ops = {
.mm_access_rights_ind = 0,
.mm_access_rights_cfm = 0,
};
static struct dect_ops ops = {
.cc_ops = &cc_ops,
.mm_ops = &mm_ops,
};
int main(int argc, char **argv)
{
dummy_ops_init(&ops);
if (dect_event_ops_init(&ops) < 0)
exit(1);

View File

@ -10,6 +10,8 @@ extern int dect_event_ops_init(struct dect_ops *ops);
extern void dect_event_loop(void);
extern void dect_event_ops_cleanup(void);
extern void dummy_ops_init(struct dect_ops *ops);
#include "../src/ccitt-adpcm/g72x.h"
struct dect_audio_handle {

View File

@ -9,6 +9,8 @@ static struct dect_ops ops;
int main(int argc, char **argv)
{
dummy_ops_init(&ops);
if (dect_event_ops_init(&ops) < 0)
exit(1);

327
example/dummy_ops.c Normal file
View File

@ -0,0 +1,327 @@
#include <libdect.h>
#include "common.h"
/*
* CC Ops
*/
static void mncc_setup_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_setup_param *param)
{
}
static void mncc_setup_ack_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_setup_ack_param *param)
{
}
static void mncc_reject_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_release_param *param)
{
}
static void mncc_call_proc_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_call_proc_param *param)
{
}
static void mncc_alert_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_alert_param *param)
{
}
static void mncc_connect_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_connect_param *param)
{
}
static void mncc_connect_cfm(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_connect_param *param)
{
}
static void mncc_release_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_release_param *param)
{
}
static void mncc_release_cfm(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_release_param *param)
{
}
static void mncc_facility_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_facility_param *param)
{
}
static void mncc_info_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_info_param *param)
{
}
static void mncc_modify_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_modify_param *param)
{
}
static void mncc_modify_cfm(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_modify_param *param)
{
}
static void mncc_hold_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_hold_param *param)
{
}
static void mncc_hold_cfm(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_hold_param *param)
{
}
static void mncc_retrieve_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_hold_param *param)
{
}
static void mncc_retrieve_cfm(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_hold_param *param)
{
}
static void mncc_iwu_info_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_mncc_iwu_info_param *param)
{
}
static void dl_u_data_ind(struct dect_handle *dh, struct dect_call *call,
struct dect_msg_buf *mb)
{
}
static struct dect_cc_ops dummy_cc_ops;
/*
* MM Ops
*/
static void mm_access_rights_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_access_rights_param *param)
{
}
static void mm_access_rights_cfm(struct dect_handle *dh,
struct dect_mm_endpoint *mme, bool accept,
struct dect_mm_access_rights_param *param)
{
}
static void mm_access_rights_terminate_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_access_rights_terminate_param *param)
{
}
static void mm_access_rights_terminate_cfm(struct dect_handle *dh,
struct dect_mm_endpoint *mme, bool accept,
struct dect_mm_access_rights_terminate_param *param)
{
}
static void mm_key_allocate_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_key_allocate_param *param)
{
}
static void mm_authenticate_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_authenticate_param *param)
{
}
static void mm_authenticate_cfm(struct dect_handle *dh,
struct dect_mm_endpoint *mme, bool accept,
struct dect_mm_authenticate_param *param)
{
}
static void mm_cipher_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_cipher_param *param)
{
}
static void mm_cipher_cfm(struct dect_handle *dh,
struct dect_mm_endpoint *mme, bool accept,
struct dect_mm_cipher_param *param)
{
}
static void mm_locate_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_locate_param *param)
{
}
static void mm_locate_res(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_locate_param *param)
{
}
static void mm_detach_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_detach_param *param)
{
}
static void mm_identity_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_identity_param *param)
{
}
static void mm_identity_cfm(struct dect_handle *dh,
struct dect_mm_endpoint *mme, bool accept,
struct dect_mm_identity_param *param)
{
}
static void mm_identity_assign_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_identity_assign_param *param)
{
}
static void mm_identity_assign_cfm(struct dect_handle *dh,
struct dect_mm_endpoint *mme, bool accept,
struct dect_mm_identity_assign_param *param)
{
}
static void mm_info_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_info_param *param)
{
}
static void mm_info_cfm(struct dect_handle *dh,
struct dect_mm_endpoint *mme, bool accept,
struct dect_mm_info_param *param)
{
}
static void mm_iwu_ind(struct dect_handle *dh,
struct dect_mm_endpoint *mme,
struct dect_mm_iwu_param *param)
{
}
static struct dect_mm_ops dummy_mm_ops;
void dummy_ops_init(struct dect_ops *ops)
{
struct dect_cc_ops *cc_ops;
struct dect_mm_ops *mm_ops;
if (!ops->cc_ops)
ops->cc_ops = &dummy_cc_ops;
cc_ops = (void *)ops->cc_ops;
if (!cc_ops->mncc_setup_ind)
cc_ops->mncc_setup_ind = mncc_setup_ind;
if (!cc_ops->mncc_setup_ack_ind)
cc_ops->mncc_setup_ack_ind = mncc_setup_ack_ind;
if (!cc_ops->mncc_reject_ind)
cc_ops->mncc_reject_ind = mncc_reject_ind;
if (!cc_ops->mncc_call_proc_ind)
cc_ops->mncc_call_proc_ind = mncc_call_proc_ind;
if (!cc_ops->mncc_alert_ind)
cc_ops->mncc_alert_ind = mncc_alert_ind;
if (!cc_ops->mncc_connect_ind)
cc_ops->mncc_connect_ind = mncc_connect_ind;
if (!cc_ops->mncc_connect_cfm)
cc_ops->mncc_connect_cfm = mncc_connect_cfm;
if (!cc_ops->mncc_release_ind)
cc_ops->mncc_release_ind = mncc_release_ind;
if (!cc_ops->mncc_release_cfm)
cc_ops->mncc_release_cfm = mncc_release_cfm;
if (!cc_ops->mncc_facility_ind)
cc_ops->mncc_facility_ind = mncc_facility_ind;
if (!cc_ops->mncc_info_ind)
cc_ops->mncc_info_ind = mncc_info_ind;
if (!cc_ops->mncc_modify_ind)
cc_ops->mncc_modify_ind = mncc_modify_ind;
if (!cc_ops->mncc_modify_cfm)
cc_ops->mncc_modify_cfm = mncc_modify_cfm;
if (!cc_ops->mncc_hold_ind)
cc_ops->mncc_hold_ind = mncc_hold_ind;
if (!cc_ops->mncc_hold_cfm)
cc_ops->mncc_hold_cfm = mncc_hold_cfm;
if (!cc_ops->mncc_retrieve_ind)
cc_ops->mncc_retrieve_ind = mncc_retrieve_ind;
if (!cc_ops->mncc_retrieve_cfm)
cc_ops->mncc_retrieve_cfm = mncc_retrieve_cfm;
if (!cc_ops->mncc_iwu_info_ind)
cc_ops->mncc_iwu_info_ind = mncc_iwu_info_ind;
if (!cc_ops->dl_u_data_ind)
cc_ops->dl_u_data_ind = dl_u_data_ind;
if (!ops->mm_ops)
ops->mm_ops = &dummy_mm_ops;
mm_ops = (void *)ops->mm_ops;
if (!mm_ops->mm_access_rights_ind)
mm_ops->mm_access_rights_ind = mm_access_rights_ind;
if (!mm_ops->mm_access_rights_cfm)
mm_ops->mm_access_rights_cfm = mm_access_rights_cfm;
if (!mm_ops->mm_access_rights_terminate_ind)
mm_ops->mm_access_rights_terminate_ind = mm_access_rights_terminate_ind;
if (!mm_ops->mm_access_rights_terminate_cfm)
mm_ops->mm_access_rights_terminate_cfm = mm_access_rights_terminate_cfm;
if (!mm_ops->mm_key_allocate_ind)
mm_ops->mm_key_allocate_ind = mm_key_allocate_ind;
if (!mm_ops->mm_authenticate_ind)
mm_ops->mm_authenticate_ind = mm_authenticate_ind;
if (!mm_ops->mm_authenticate_cfm)
mm_ops->mm_authenticate_cfm = mm_authenticate_cfm;
if (!mm_ops->mm_cipher_ind)
mm_ops->mm_cipher_ind = mm_cipher_ind;
if (!mm_ops->mm_cipher_cfm)
mm_ops->mm_cipher_cfm = mm_cipher_cfm;
if (!mm_ops->mm_locate_ind)
mm_ops->mm_locate_ind = mm_locate_ind;
if (!mm_ops->mm_locate_res)
mm_ops->mm_locate_res = mm_locate_res;
if (!mm_ops->mm_authenticate_ind)
mm_ops->mm_authenticate_ind = mm_authenticate_ind;
if (!mm_ops->mm_authenticate_cfm)
mm_ops->mm_authenticate_cfm = mm_authenticate_cfm;
if (!mm_ops->mm_cipher_ind)
mm_ops->mm_cipher_ind = mm_cipher_ind;
if (!mm_ops->mm_cipher_cfm)
mm_ops->mm_cipher_cfm = mm_cipher_cfm;
if (!mm_ops->mm_locate_ind)
mm_ops->mm_locate_ind = mm_locate_ind;
if (!mm_ops->mm_locate_res)
mm_ops->mm_locate_res = mm_locate_res;
if (!mm_ops->mm_detach_ind)
mm_ops->mm_detach_ind = mm_detach_ind;
if (!mm_ops->mm_identity_ind)
mm_ops->mm_identity_ind = mm_identity_ind;
if (!mm_ops->mm_identity_cfm)
mm_ops->mm_identity_cfm = mm_identity_cfm;
if (!mm_ops->mm_identity_assign_ind)
mm_ops->mm_identity_assign_ind = mm_identity_assign_ind;
if (!mm_ops->mm_identity_assign_cfm)
mm_ops->mm_identity_assign_cfm = mm_identity_assign_cfm;
if (!mm_ops->mm_info_ind)
mm_ops->mm_info_ind = mm_info_ind;
if (!mm_ops->mm_info_cfm)
mm_ops->mm_info_cfm = mm_info_cfm;
if (!mm_ops->mm_iwu_ind)
mm_ops->mm_iwu_ind = mm_iwu_ind;
}

View File

@ -76,6 +76,8 @@ int main(int argc, char **argv)
slot = atoi(argv[1]);
dect_build_msg(&msg, atoi(argv[2]), atoi(argv[3]));
dummy_ops_init(&ops);
if (dect_event_ops_init(&ops) < 0)
pexit("dect_event_ops_init");

View File

@ -169,7 +169,7 @@ static void mm_access_rights_ind(struct dect_handle *dh,
dect_mm_access_rights_res(dh, mme, true, param);
}
static const struct dect_mm_ops mm_ops = {
static struct dect_mm_ops mm_ops = {
.priv_size = sizeof(struct mm_priv),
.mm_authenticate_ind = mm_authenticate_ind,
.mm_authenticate_cfm = mm_authenticate_cfm,
@ -189,6 +189,8 @@ int main(int argc, char **argv)
if (rand_fd < 0)
exit(1);
dummy_ops_init(&ops);
if (dect_event_ops_init(&ops) < 0)
exit(1);