浏览代码

maxfwd(k): added inter-module API structure

Daniel-Constantin Mierla 15 年之前
父节点
当前提交
5d3b2f3631
共有 2 个文件被更改,包括 95 次插入3 次删除
  1. 62 0
      modules_k/maxfwd/api.h
  2. 33 3
      modules_k/maxfwd/maxfwd.c

+ 62 - 0
modules_k/maxfwd/api.h

@@ -0,0 +1,62 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ *
+ * 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 _MAXFWD_API_H_
+#define _MAXFWD_API_H_
+
+#include "../../sr_module.h"
+#include "../../parser/msg_parser.h"
+
+typedef int (*process_maxfwd_f)(struct sip_msg *msg, int limit);
+
+/**
+ * @brief MAXFWD API structure
+ */
+typedef struct maxfwd_api {
+	process_maxfwd_f process_maxfwd;
+} maxfwd_api_t;
+
+typedef int (*bind_maxfwd_f)(maxfwd_api_t* api);
+
+/**
+ * @brief Load the MAXFWD API
+ */
+static inline int maxfwd_load_api(maxfwd_api_t *api)
+{
+	bind_maxfwd_f bindmaxfwd;
+
+	bindmaxfwd = (bind_maxfwd_f)find_export("bind_maxfwd", 0, 0);
+	if(bindmaxfwd == 0) {
+		LM_ERR("cannot find bind_maxfwd\n");
+		return -1;
+	}
+	if (bindmaxfwd(api)==-1)
+	{
+		LM_ERR("cannot bind maxfwd api\n");
+		return -1;
+	}
+	return 0;
+}
+
+#endif
+

+ 33 - 3
modules_k/maxfwd/maxfwd.c

@@ -45,6 +45,7 @@
 #include "../../ut.h"
 #include "../../ut.h"
 #include "../../mem/mem.h"
 #include "../../mem/mem.h"
 #include "mf_funcs.h"
 #include "mf_funcs.h"
+#include "api.h"
 
 
 MODULE_VERSION
 MODULE_VERSION
 
 
@@ -57,11 +58,15 @@ static int w_process_maxfwd_header(struct sip_msg* msg,char* str,char* str2);
 static int is_maxfwd_lt(struct sip_msg *msg, char *slimit, char *foo);
 static int is_maxfwd_lt(struct sip_msg *msg, char *slimit, char *foo);
 static int mod_init(void);
 static int mod_init(void);
 
 
+int bind_maxfwd(maxfwd_api_t *api);
+
 static cmd_export_t cmds[]={
 static cmd_export_t cmds[]={
 	{"mf_process_maxfwd_header", (cmd_function)w_process_maxfwd_header, 1,
 	{"mf_process_maxfwd_header", (cmd_function)w_process_maxfwd_header, 1,
 		fixup_maxfwd_header, 0, REQUEST_ROUTE},
 		fixup_maxfwd_header, 0, REQUEST_ROUTE},
 	{"is_maxfwd_lt", (cmd_function)is_maxfwd_lt, 1,
 	{"is_maxfwd_lt", (cmd_function)is_maxfwd_lt, 1,
 		fixup_maxfwd_header, 0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
 		fixup_maxfwd_header, 0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
+	{"bind_maxfwd",  (cmd_function)bind_maxfwd,  0,
+		0, 0, 0},
 	{0,0,0,0,0,0}
 	{0,0,0,0,0,0}
 };
 };
 
 
@@ -131,8 +136,10 @@ static int fixup_maxfwd_header(void** param, int param_no)
 }
 }
 
 
 
 
-
-static int w_process_maxfwd_header(struct sip_msg* msg, char* str1,char* str2)
+/**
+ * process max forward header
+ */
+int process_maxfwd_header(struct sip_msg *msg, int limit)
 {
 {
 	int val;
 	int val;
 	str mf_value;
 	str mf_value;
@@ -141,7 +148,7 @@ static int w_process_maxfwd_header(struct sip_msg* msg, char* str1,char* str2)
 	switch (val) {
 	switch (val) {
 		/* header not found */
 		/* header not found */
 		case -1:
 		case -1:
-			if (add_maxfwd_header( msg, (unsigned int)(unsigned long)str1)!=0)
+			if (add_maxfwd_header(msg, (unsigned int)limit)!=0)
 				goto error;
 				goto error;
 			return 2;
 			return 2;
 		/* error */
 		/* error */
@@ -166,8 +173,18 @@ error:
 	return -2;
 	return -2;
 }
 }
 
 
+/**
+ *
+ */
+static int w_process_maxfwd_header(struct sip_msg* msg, char* str1, char* str2)
+{
+	return process_maxfwd_header(msg, (int)(unsigned long)str1);
+}
 
 
 
 
+/**
+ *
+ */
 static int is_maxfwd_lt(struct sip_msg *msg, char *slimit, char *foo)
 static int is_maxfwd_lt(struct sip_msg *msg, char *slimit, char *foo)
 {
 {
 	str mf_value;
 	str mf_value;
@@ -189,3 +206,16 @@ static int is_maxfwd_lt(struct sip_msg *msg, char *slimit, char *foo)
 	return 1;
 	return 1;
 }
 }
 
 
+/**
+ * @brief bind functions to MAXFWD API structure
+ */
+int bind_maxfwd(maxfwd_api_t *api)
+{
+	if (!api) {
+		ERR("Invalid parameter value\n");
+		return -1;
+	}
+	api->process_maxfwd = process_maxfwd_header;
+
+	return 0;
+}