Module: sip-router Branch: master Commit: 513a71df7b6fa8b5ae3ec124f02e02c3855c5803 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=513a71df...
Author: Peter Dunkley peter.dunkley@crocodile-rcs.com Committer: Peter Dunkley peter.dunkley@crocodile-rcs.com Date: Thu Mar 1 17:53:16 2012 +0000
modules/mqueue: Added C API to enable other modules to bind to mqueue
- Exported mq_add using this API so it can be added to app_lua
---
modules/mqueue/api.h | 28 ++++++++++++++++++++++++++++ modules/mqueue/mqueue_mod.c | 12 +++++++++++- 2 files changed, 39 insertions(+), 1 deletions(-)
diff --git a/modules/mqueue/api.h b/modules/mqueue/api.h new file mode 100644 index 0000000..3c67f2f --- /dev/null +++ b/modules/mqueue/api.h @@ -0,0 +1,28 @@ +#ifndef _MQUEUE_EXT_API_H_ +#define _MQUEUE_EXT_API_H_ + +typedef int (*mq_add_f)(str*, str*, str*); +typedef struct mq_api { + mq_add_f add; +} mq_api_t; + +typedef int (*bind_mq_f)(mq_api_t* api); + +static inline int load_mq_api(mq_api_t *api) +{ + bind_mq_f bindmq; + + bindmq = (bind_mq_f)find_export("bind_mq", 1, 0); + if(bindmq == 0) { + LM_ERR("cannot find bind_mq\n"); + return -1; + } + if(bindmq(api)<0) + { + LM_ERR("cannot bind mq api\n"); + return -1; + } + return 0; +} + +#endif diff --git a/modules/mqueue/mqueue_mod.c b/modules/mqueue/mqueue_mod.c index 5a74f58..a99a361 100644 --- a/modules/mqueue/mqueue_mod.c +++ b/modules/mqueue/mqueue_mod.c @@ -36,6 +36,7 @@ #include "../../shm_init.h"
#include "mqueue_api.h" +#include "api.h"
MODULE_VERSION
@@ -47,6 +48,7 @@ static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val); static int w_mq_pv_free(struct sip_msg* msg, char* mq, char* str2); int mq_param(modparam_t type, void *val); static int fixup_mq_add(void** param, int param_no); +static int bind_mq(mq_api_t* api);
static pv_export_t mod_pvs[] = { { {"mqk", sizeof("mqk")-1}, PVT_OTHER, pv_get_mqk, 0, @@ -64,6 +66,8 @@ static cmd_export_t cmds[]={ 0, ANY_ROUTE}, {"mq_pv_free", (cmd_function)w_mq_pv_free, 1, fixup_str_null, 0, ANY_ROUTE}, + {"bind_mq", (cmd_function)bind_mq, 1, 0, + 0, ANY_ROUTE}, {0, 0, 0, 0, 0, 0} };
@@ -208,4 +212,10 @@ static int fixup_mq_add(void** param, int param_no) return fixup_str_null(param, 1); }
- +static int bind_mq(mq_api_t* api) +{ + if (!api) + return -1; + api->add = mq_item_add; + return 0; +}