[sr-dev] git:master: xhttp: exported xhttp reply via inter-module api

Daniel-Constantin Mierla miconda at gmail.com
Sun Jan 16 22:45:51 CET 2011


Module: sip-router
Branch: master
Commit: efc3f1f5050ea2302952158098d61b457a7c8df1
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=efc3f1f5050ea2302952158098d61b457a7c8df1

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sat Jan 15 16:29:02 2011 +0100

xhttp: exported xhttp reply via inter-module api

---

 modules/xhttp/api.h       |   58 +++++++++++++++++++++++++++++++++++++++++++++
 modules/xhttp/xhttp_mod.c |   17 +++++++++++++
 2 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/modules/xhttp/api.h b/modules/xhttp/api.h
new file mode 100644
index 0000000..0fc7ee5
--- /dev/null
+++ b/modules/xhttp/api.h
@@ -0,0 +1,58 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2010 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of kamailio, a free SIP server.
+ *
+ * kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+		       
+#ifndef _XHTTP_API_H_
+#define _XHTTP_API_H_
+
+#include "../../sr_module.h"
+
+typedef int (*xhttp_reply_f)(sip_msg_t *msg, int code, str *reason,
+		str *ctype, str *body);
+
+typedef struct xhttp_api {
+	xhttp_reply_f reply;
+} xhttp_api_t;
+
+typedef int (*bind_xhttp_f)(xhttp_api_t* api);
+int bind_xhttp(xhttp_api_t* api);
+
+/**
+ * @brief Load the XHTTP API
+ */
+static inline int xhttp_load_api(xhttp_api_t *api)
+{
+	bind_xhttp_f bindxhttp;
+
+	bindxhttp = (bind_xhttp_f)find_export("bind_xhttp", 0, 0);
+	if(bindxhttp == 0) {
+		LM_ERR("cannot find bind_xhttp\n");
+		return -1;
+	}
+	if(bindxhttp(api)<0)
+	{
+		LM_ERR("cannot bind xhttp api\n");
+		return -1;
+	}
+	return 0;
+}
+
+#endif
diff --git a/modules/xhttp/xhttp_mod.c b/modules/xhttp/xhttp_mod.c
index 1c5ff7e..23ac3c4 100644
--- a/modules/xhttp/xhttp_mod.c
+++ b/modules/xhttp/xhttp_mod.c
@@ -44,6 +44,8 @@
 #include "../../mod_fix.h"
 #include "../../pvar.h"
 
+#include "api.h"
+
 MODULE_VERSION
 
 static int xhttp_handler(sip_msg_t* msg);
@@ -69,6 +71,8 @@ sl_api_t slb;
 static cmd_export_t cmds[] = {
 	{"xhttp_reply",    (cmd_function)w_xhttp_send_reply,
 		4, fixup_xhttp_reply,  0, REQUEST_ROUTE},
+	{"bind_xhttp",     (cmd_function)bind_xhttp,
+		0, 0, 0, ANY_ROUTE},
 	{0, 0, 0, 0, 0}
 };
 
@@ -486,4 +490,17 @@ static int fixup_xhttp_reply(void** param, int param_no)
 	return 0;
 }
 
+/**
+ *
+ */
+int bind_xhttp(xhttp_api_t* api)
+{
+	if (!api) {
+		ERR("Invalid parameter value\n");
+		return -1;
+	}
+	api->reply = xhttp_send_reply;
+	return 0;
+}
+
 /** @} */




More information about the sr-dev mailing list