Browse Source

pike: exporte pike_check_req() to kemi

- coherent indentation
Daniel-Constantin Mierla 9 years ago
parent
commit
169e1d5952

+ 15 - 15
modules/pike/ip_tree.c

@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2001-2003 FhG Fokus
  *
  * This file is part of Kamailio, a free SIP server.
@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -141,7 +141,7 @@ error:
 	return -1;
 }
 
-unsigned int get_max_hits() { return root != 0 ? root->max_hits : -1; } 
+unsigned int get_max_hits() { return root != 0 ? root->max_hits : -1; }
 
 /* destroy an ip_node and all nodes under it; the nodes must be first removed
  * from any other lists/timers */
@@ -234,15 +234,15 @@ struct ip_node *split_node(struct ip_node* dad, unsigned char byte)
 
 #define is_hot_non_leaf(_node) \
 	( (_node)->hits[PREV_POS]>=root->max_hits>>2 ||\
-	  (_node)->hits[CURR_POS]>=root->max_hits>>2 ||\
-	  (((_node)->hits[PREV_POS]+(_node)->hits[CURR_POS])>>1)>=\
-		 root->max_hits>>2 )
+		(_node)->hits[CURR_POS]>=root->max_hits>>2 ||\
+		(((_node)->hits[PREV_POS]+(_node)->hits[CURR_POS])>>1)>=\
+			root->max_hits>>2 )
 
 #define is_hot_leaf(_node) \
 	( (_node)->leaf_hits[PREV_POS]>=root->max_hits ||\
-	  (_node)->leaf_hits[CURR_POS]>=root->max_hits ||\
-	  (((_node)->leaf_hits[PREV_POS]+(_node)->leaf_hits[CURR_POS])>>1)>=\
-		 root->max_hits )
+		(_node)->leaf_hits[CURR_POS]>=root->max_hits ||\
+		(((_node)->leaf_hits[PREV_POS]+(_node)->leaf_hits[CURR_POS])>>1)>=\
+			root->max_hits )
 
 #define is_warm_leaf(_node) \
 	( (_node)->hits[CURR_POS]>=root->max_hits>>2 )
@@ -260,13 +260,13 @@ int is_node_hot_leaf(struct ip_node *node)
 char *node_status_array[] = {"", "WARM", "HOT", "ALL"};
 node_status_t node_status(struct ip_node *node)
 {
-        if ( is_hot_leaf(node) )
-                return NODE_STATUS_HOT;
+	if ( is_hot_leaf(node) )
+		return NODE_STATUS_HOT;
 
-        if ( is_warm_leaf(node) )
-                return NODE_STATUS_WARM;
+	if ( is_warm_leaf(node) )
+		return NODE_STATUS_WARM;
 
-        return NODE_STATUS_OK;
+	return NODE_STATUS_OK;
 }
 
 

+ 7 - 7
modules/pike/ip_tree.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2001-2003 FhG Fokus
  *
  * This file is part of Kamailio, a free SIP server.
@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -87,10 +87,10 @@ void unlock_tree_branch(unsigned char b);
 struct ip_node* get_tree_branch(unsigned char b);
 
 typedef enum {
-        NODE_STATUS_OK    = 0,
-        NODE_STATUS_WARM  = 1,
-        NODE_STATUS_HOT   = 2,
-        NODE_STATUS_ALL   = 3   /** used for status matching */
+	NODE_STATUS_OK    = 0,
+	NODE_STATUS_WARM  = 1,
+	NODE_STATUS_HOT   = 2,
+	NODE_STATUS_ALL   = 3   /** used for status matching */
 } node_status_t;
 node_status_t node_status(struct ip_node *node);
 extern char *node_status_array[];

+ 24 - 3
modules/pike/pike.c

@@ -15,8 +15,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -35,6 +35,7 @@
 #include "../../mem/shm_mem.h"
 #include "../../timer.h"
 #include "../../locking.h"
+#include "../../kemi.h"
 #include "ip_tree.h"
 #include "timer.h"
 #include "pike_mi.h"
@@ -63,7 +64,7 @@ struct list_link*       timer = 0;
 
 
 static cmd_export_t cmds[]={
-	{"pike_check_req", (cmd_function)pike_check_req,  0,  0, 0, REQUEST_ROUTE},
+	{"pike_check_req", (cmd_function)w_pike_check_req,  0,  0, 0, REQUEST_ROUTE},
 	{0,0,0,0,0,0}
 };
 
@@ -180,4 +181,24 @@ static int pike_exit(void)
 	return 0;
 }
 
+/**
+ *
+ */
+static sr_kemi_t sr_kemi_pike_exports[] = {
+	{ str_init("pike"), str_init("pike_check_req"),
+		SR_KEMIP_INT, pike_check_req,
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
 
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+	sr_kemi_modules_add(sr_kemi_pike_exports);
+	return 0;
+}

+ 12 - 8
modules/pike/pike_funcs.c

@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2001-2003 FhG Fokus
  *
  * This file is part of Kamailio, a free SIP server.
@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -53,7 +53,7 @@ void pike_counter_init()
 
 
 
-int pike_check_req(struct sip_msg *msg, char *foo, char *bar)
+int pike_check_req(sip_msg_t *msg)
 {
 	struct ip_node *node;
 	struct ip_node *father;
@@ -96,7 +96,7 @@ int pike_check_req(struct sip_msg *msg, char *foo, char *bar)
 	lock_get(timer_lock);
 	if ( flags&NEW_NODE ) {
 		/* put this node into the timer list and remove its
-		   father only if this has one kid and is not a LEAF_NODE*/
+		 * father only if this has one kid and is not a LEAF_NODE*/
 		node->expires =  get_ticks() + timeout;
 		append_to_timer( timer, &(node->timer_ll) );
 		node->flags |= NODE_INTIMER_FLAG;
@@ -124,7 +124,7 @@ int pike_check_req(struct sip_msg *msg, char *foo, char *bar)
 			/* tree leafs which are not potential red nodes are not update in
 			 * order to make them to expire */
 			/* debug */
-			assert( has_timer_set(&(node->timer_ll)) 
+			assert( has_timer_set(&(node->timer_ll))
 				&& (node->flags&(NODE_EXPIRED_FLAG|NODE_INTIMER_FLAG)) );
 			/* if node exprired, ignore the current hit and let is
 			 * expire in timer process */
@@ -134,7 +134,7 @@ int pike_check_req(struct sip_msg *msg, char *foo, char *bar)
 			}
 		} else {
 			/* debug */
-			assert( !has_timer_set(&(node->timer_ll)) 
+			assert( !has_timer_set(&(node->timer_ll))
 				&& !(node->flags&(NODE_INTIMER_FLAG|NODE_EXPIRED_FLAG)) );
 			/* debug */
 			assert( !(node->flags&NODE_IPLEAF_FLAG) && node->kids );
@@ -159,6 +159,10 @@ int pike_check_req(struct sip_msg *msg, char *foo, char *bar)
 }
 
 
+int w_pike_check_req(struct sip_msg *msg, char *foo, char *bar)
+{
+	return pike_check_req(msg);
+}
 
 void clean_routine(unsigned int ticks , void *param)
 {
@@ -216,7 +220,7 @@ void clean_routine(unsigned int ticks , void *param)
 				continue;
 
 			/* process the node */
-			LM_DBG("clean node %p (kids=%p; hits=[%d,%d];leaf=[%d,%d])\n", 
+			LM_DBG("clean node %p (kids=%p; hits=[%d,%d];leaf=[%d,%d])\n",
 				node,node->kids,
 				node->hits[PREV_POS],node->hits[CURR_POS],
 				node->leaf_hits[PREV_POS],node->leaf_hits[CURR_POS]);

+ 5 - 4
modules/pike/pike_funcs.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2001-2003 FhG Fokus
  *
  * This file is part of Kamailio, a free SIP server.
@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -27,7 +27,8 @@
 
 
 void pike_counter_init(void);
-int  pike_check_req(struct sip_msg *msg, char *foo, char *bar);
+int  pike_check_req(sip_msg_t *msg);
+int  w_pike_check_req(struct sip_msg *msg, char *foo, char *bar);
 void clean_routine(unsigned int, void*);
 void swap_routine(unsigned int, void*);
 

+ 4 - 4
modules/pike/pike_mi.c

@@ -15,8 +15,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -86,8 +86,8 @@ static void print_red_ips( struct ip_node *ip, int level, struct mi_node *node)
 
 
 /*
-  Syntax of "pike_list" :
-    no nodes
+ * Syntax of "pike_list" :
+ * no nodes
 */
 struct mi_root* mi_pike_list(struct mi_root* cmd_tree, void* param)
 {

+ 2 - 2
modules/pike/pike_mi.h

@@ -15,8 +15,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */

+ 19 - 19
modules/pike/pike_rpc.c

@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -23,7 +23,7 @@
 #include "../../rpc_lookup.h"
 /*??? #include "rpc.h" */
 /*??? #include "top.h" */
-#include "../../timer.h"	/* ticks_t */	
+#include "../../timer.h"	/* ticks_t */
 
 #include "../../dprint.h"
 #include "pike_top.h"
@@ -44,11 +44,11 @@ static void traverse_subtree( struct ip_node *node, int depth, int options )
 	static unsigned char ip_addr[MAX_DEPTH];
 
 	struct ip_node *foo;
-	
+
 	DBG("pike:rpc traverse_subtree, depth: %d, byte: %d", depth, node->byte);
 
 	assert( depth < MAX_DEPTH );
-	
+
 	ip_addr[depth] = node->byte;
 
 	if ( node->flags & NODE_IPLEAF_FLAG ) {
@@ -73,7 +73,7 @@ static void traverse_subtree( struct ip_node *node, int depth, int options )
 		DBG("pike:rpc traverse_subtree, not IP leaf, depth: %d, ip: %d.%d.%d.%d   hits[%d,%d], expires: %d",
 			depth, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], node->hits[0], node->hits[1], node->expires - get_ticks());
 	}
-	
+
 	foo = node->kids;
 	while (foo) {
 		traverse_subtree( foo, depth + 1, options );
@@ -88,7 +88,7 @@ static void collect_data(int options)
 	g_max_hits = get_max_hits();
 
 	DBG("pike: collect_data");
-	
+
 	// maybe try_lock first and than do the rest?
 	for(i=0;i<MAX_IP_BRANCHES;i++) {
 		if (get_tree_branch(i)==0)
@@ -98,7 +98,7 @@ static void collect_data(int options)
 		if (get_tree_branch(i))
 			traverse_subtree( get_tree_branch(i), 0, options );
 		unlock_tree_branch(i);
-    }
+	}
 }
 
 /* do not use static buffer with this function */
@@ -107,7 +107,7 @@ static char *concat(char *buff, size_t buffsize, const char *first, int second)
 {
 	int rv;
 	size_t size;
-	
+
 	while ( (rv = snprintf(buff, buffsize, "%s%d", first, second)) >= buffsize ) {
 		size = rv > 128 ? rv : 128;
 		buff = (char *)realloc(buff, size);
@@ -141,13 +141,13 @@ static void pike_top(rpc_t *rpc, void *c)
 	int   options = 0;
 
 	DBG("pike: top");
-	
+
 	/* obtain params */
 	if (rpc->scan(c, "s", &stropts) <= 0)
 		stropts = "HOT";
 
 	DBG("pike:top: string options: '%s'", stropts);
-	if ( strstr(stropts, "ALL") ) { 
+	if ( strstr(stropts, "ALL") ) {
 		options = NODE_STATUS_ALL;
 	} else if ( strstr(stropts, "HOT") ) {
 		options |= NODE_STATUS_HOT;
@@ -161,14 +161,14 @@ static void pike_top(rpc_t *rpc, void *c)
 		rpc->fault(c, 500, "Bad argument. Select: ALL, HOT or WARM");
 		return;
 	}
-	
-	
+
+
 	print_tree( 0 );
-	
+
 	collect_data(options);
 	top_list_root = pike_top_get_root();
 	DBG("pike_top: top_list_root = %p", top_list_root);
-	
+
 	rpc->add(c, "{", &handle);
 	rpc->struct_add(handle, "d", "max_hits", get_max_hits());
 	i = 0; // it is passed as number of rows
@@ -180,7 +180,7 @@ static void pike_top(rpc_t *rpc, void *c)
 			pike_top_print_addr(ti->ip_addr, ti->addr_len, addr_buff, sizeof(addr_buff));
 			DBG("pike:top: result[%d]: %s leaf_hits[%d,%d] hits[%d,%d] expires: %d status: 0x%02x",
 					i, addr_buff, ti->leaf_hits[0], ti->leaf_hits[1],
-					ti->hits[0], ti->hits[1], ti->expires, ti->status); 
+					ti->hits[0], ti->hits[1], ti->expires, ti->status);
 			rpc->struct_add(handle, "sddds",
 							concat(ip_addr, ip_addr_size, "ip_addr", i), addr_buff,
 							concat(leaf_hits_prev, leaf_hits_prev_size, "leaf_hits_prev", i), ti->leaf_hits[0],
@@ -197,7 +197,7 @@ static void pike_top(rpc_t *rpc, void *c)
 	free(expires);
 	free(status);
 	pike_top_list_clear();
-	
+
 	rpc->send(c);
 }
 
@@ -209,8 +209,8 @@ static const char* pike_top_doc[] = {
 	0                 /* Method signature(s) */
 };
 
-/* 
- * RPC Methods exported by this module 
+/*
+ * RPC Methods exported by this module
  */
 
 rpc_export_t pike_rpc_methods[] = {

+ 2 - 2
modules/pike/pike_rpc.h

@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */

+ 13 - 13
modules/pike/pike_top.c

@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -42,9 +42,9 @@ char *pike_top_print_addr( unsigned char *ip, int iplen, char *buff, int buffsiz
 {
 	unsigned short *ipv6_ptr = (unsigned short *)ip;
 	memset(buff, 0, PIKE_BUFF_SIZE*sizeof(char));
-	
+
 	DBG("pike:top:print_addr(iplen: %d, buffsize: %d)", iplen, buffsize);
-	
+
 	if ( iplen == 4 ) {
 		inet_ntop(AF_INET, ip, buff, buffsize);
 	}
@@ -53,10 +53,10 @@ char *pike_top_print_addr( unsigned char *ip, int iplen, char *buff, int buffsiz
 	}
 	else {
 		sprintf( buff, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
-				 htons(ipv6_ptr[0]), htons(ipv6_ptr[1]), htons(ipv6_ptr[2]), htons(ipv6_ptr[3]),
-				 htons(ipv6_ptr[4]), htons(ipv6_ptr[5]), htons(ipv6_ptr[6]), htons(ipv6_ptr[7]) );
+				htons(ipv6_ptr[0]), htons(ipv6_ptr[1]), htons(ipv6_ptr[2]), htons(ipv6_ptr[3]),
+				htons(ipv6_ptr[4]), htons(ipv6_ptr[5]), htons(ipv6_ptr[6]), htons(ipv6_ptr[7]));
 	}
-	
+
 	return buff;
 }
 
@@ -69,25 +69,25 @@ static char *print_addr(unsigned char *ip, int iplen)
 int pike_top_add_entry( unsigned char *ip_addr, int addr_len, unsigned short leaf_hits[2], unsigned short hits[2], unsigned int expires, node_status_t status )
 {
 	struct TopListItem_t *new_item = (struct TopListItem_t *)malloc(sizeof(struct TopListItem_t));
-	
+
 	print_addr(ip_addr, addr_len);
 	DBG("pike_top_add_enrty(ip: %s, leaf_hits[%d,%d], hits[%d,%d],"
 			" expires: %d, status: %d)",
 			buff, leaf_hits[0], leaf_hits[1], hits[0], hits[1],
 			expires, status);
 	assert(new_item != 0);
-	
+
 	memset( (void *)new_item, 0, sizeof(struct TopListItem_t) );
-	
+
 	new_item->status  = status;
 	new_item->expires = expires;
 	new_item->hits[0] = hits[0];
 	new_item->hits[1] = hits[1];
 	new_item->leaf_hits[0] = leaf_hits[0];
 	new_item->leaf_hits[1] = leaf_hits[1];
-	
+
 	assert( addr_len <= 16 );
-	
+
 	new_item->addr_len = addr_len;
 	memcpy(new_item->ip_addr, ip_addr, addr_len);
 
@@ -100,7 +100,7 @@ int pike_top_add_entry( unsigned char *ip_addr, int addr_len, unsigned short lea
 void pike_top_list_clear()
 {
 	struct TopListItem_t *ptr;
-	
+
 	top_list_iter = top_list_root;
 	while (top_list_iter) {
 		ptr = top_list_iter->next;

+ 2 - 2
modules/pike/pike_top.h

@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */

+ 3 - 3
modules/pike/timer.c

@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2001-2003 FhG Fokus
  *
  * This file is part of Kamailio, a free SIP server.
@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */

+ 3 - 3
modules/pike/timer.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2001-2003 FhG Fokus
  *
  * This file is part of Kamailio, a free SIP server.
@@ -13,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  *