Переглянути джерело

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
Peter Dunkley 13 роки тому
батько
коміт
513a71df7b
2 змінених файлів з 39 додано та 1 видалено
  1. 28 0
      modules/mqueue/api.h
  2. 11 1
      modules/mqueue/mqueue_mod.c

+ 28 - 0
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

+ 11 - 1
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;
+}