Browse code

pike: use core search functions

Daniel-Constantin Mierla authored on 03/09/2020 11:08:38
Showing 1 changed files
... ...
@@ -26,6 +26,7 @@
26 26
 #include "../../core/timer.h"	/* ticks_t */
27 27
 
28 28
 #include "../../core/dprint.h"
29
+#include "../../core/ut.h"
29 30
 #include "pike_top.h"
30 31
 
31 32
 #include <stdlib.h>
... ...
@@ -128,11 +129,11 @@ static void pike_top(rpc_t *rpc, void *c)
128 129
 		stropts = "HOT";
129 130
 
130 131
 	DBG("pike:top: string options: '%s'", stropts);
131
-	if ( strcasestr(stropts, "ALL") ) {
132
+	if ( strz_casesearch_strz(stropts, "ALL") ) {
132 133
 		options = NODE_STATUS_ALL;
133
-	} else if ( strcasestr(stropts, "HOT") ) {
134
+	} else if ( strz_casesearch_strz(stropts, "HOT") ) {
134 135
 		options |= NODE_STATUS_HOT;
135
-	} else if ( strcasestr(stropts, "WARM") ) {
136
+	} else if ( strz_casesearch_strz(stropts, "WARM") ) {
136 137
 		options |= NODE_STATUS_WARM;
137 138
 	}
138 139
 	DBG("pike:top: options: 0x%02x\n", options);
Browse code

pike: rpc pike.top - support for case insensitive match of parameter

Daniel-Constantin Mierla authored on 11/08/2020 09:22:35
Showing 1 changed files
... ...
@@ -128,11 +128,11 @@ static void pike_top(rpc_t *rpc, void *c)
128 128
 		stropts = "HOT";
129 129
 
130 130
 	DBG("pike:top: string options: '%s'", stropts);
131
-	if ( strstr(stropts, "ALL") ) {
131
+	if ( strcasestr(stropts, "ALL") ) {
132 132
 		options = NODE_STATUS_ALL;
133
-	} else if ( strstr(stropts, "HOT") ) {
133
+	} else if ( strcasestr(stropts, "HOT") ) {
134 134
 		options |= NODE_STATUS_HOT;
135
-	} else if ( strstr(stropts, "WARM") ) {
135
+	} else if ( strcasestr(stropts, "WARM") ) {
136 136
 		options |= NODE_STATUS_WARM;
137 137
 	}
138 138
 	DBG("pike:top: options: 0x%02x\n", options);
Browse code

pike: renamed common name structs and globals to have module prefix

Daniel-Constantin Mierla authored on 24/03/2020 15:39:54
Showing 1 changed files
... ...
@@ -39,11 +39,11 @@
39 39
 
40 40
 static unsigned int g_max_hits = 0;
41 41
 
42
-static void traverse_subtree( struct ip_node *node, int depth, int options )
42
+static void traverse_subtree( pike_ip_node_t *node, int depth, int options )
43 43
 {
44 44
 	static unsigned char ip_addr[MAX_DEPTH];
45 45
 
46
-	struct ip_node *foo;
46
+	pike_ip_node_t *foo;
47 47
 
48 48
 	DBG("pike:rpc traverse_subtree, depth: %d, byte: %d", depth, node->byte);
49 49
 
Browse code

pike: removed mi command

- use rpc command pike.top (aliased as pike.list)

Daniel-Constantin Mierla authored on 02/01/2017 08:34:35
Showing 1 changed files
... ...
@@ -191,5 +191,6 @@ static const char* pike_top_doc[] = {
191 191
 
192 192
 rpc_export_t pike_rpc_methods[] = {
193 193
 	{"pike.top",   pike_top,     pike_top_doc, 0},
194
+	{"pike.list",  pike_top,     pike_top_doc, 0},
194 195
 	{0, 0, 0, 0}
195 196
 };
Browse code

core, lib, modules: updated include paths for header files

Daniel-Constantin Mierla authored on 07/12/2016 11:07:22
Showing 1 changed files
... ...
@@ -20,12 +20,12 @@
20 20
  */
21 21
 
22 22
 #include "ip_tree.h"
23
-#include "../../rpc_lookup.h"
23
+#include "../../core/rpc_lookup.h"
24 24
 /*??? #include "rpc.h" */
25 25
 /*??? #include "top.h" */
26
-#include "../../timer.h"	/* ticks_t */
26
+#include "../../core/timer.h"	/* ticks_t */
27 27
 
28
-#include "../../dprint.h"
28
+#include "../../core/dprint.h"
29 29
 #include "pike_top.h"
30 30
 
31 31
 #include <stdlib.h>
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,195 @@
1
+/*
2
+ * PIKE module
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Kamailio is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * Kamailio is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
+ *
20
+ */
21
+
22
+#include "ip_tree.h"
23
+#include "../../rpc_lookup.h"
24
+/*??? #include "rpc.h" */
25
+/*??? #include "top.h" */
26
+#include "../../timer.h"	/* ticks_t */
27
+
28
+#include "../../dprint.h"
29
+#include "pike_top.h"
30
+
31
+#include <stdlib.h>
32
+#include <unistd.h>
33
+#include <assert.h>
34
+// TODO FIXME LCH remove arpa/inet.h after testing
35
+#include <arpa/inet.h>
36
+
37
+// IPv6 address is a 16 bytes long
38
+#define MAX_DEPTH 16
39
+
40
+static unsigned int g_max_hits = 0;
41
+
42
+static void traverse_subtree( struct ip_node *node, int depth, int options )
43
+{
44
+	static unsigned char ip_addr[MAX_DEPTH];
45
+
46
+	struct ip_node *foo;
47
+
48
+	DBG("pike:rpc traverse_subtree, depth: %d, byte: %d", depth, node->byte);
49
+
50
+	assert( depth < MAX_DEPTH );
51
+
52
+	ip_addr[depth] = node->byte;
53
+
54
+	if ( node->flags & NODE_IPLEAF_FLAG ) {
55
+		int ns = node_status(node);
56
+		DBG("pike:traverse_subtree: options: 0x%02x, node status: 0x%02x",
57
+				options, ns);
58
+		/* add to the result list if it has requested status */
59
+		switch (options) {
60
+			case NODE_STATUS_HOT:
61
+						if ( ns & NODE_STATUS_HOT )
62
+							pike_top_add_entry(ip_addr, depth+1,
63
+									node->leaf_hits, node->hits,
64
+									node->expires - get_ticks(), ns);
65
+						break;
66
+			case NODE_STATUS_ALL:
67
+						pike_top_add_entry(ip_addr, depth+1, node->leaf_hits,
68
+								node->hits, node->expires - get_ticks(), ns);
69
+						break;
70
+		}
71
+	}
72
+	else if (! node->kids) {
73
+		/* TODO non IP leaf of ip_tree - it is possible to report WARM nodes here */
74
+/*		if ( options == ns )
75
+			pike_top_add_entry(ip_addr, depth+1, node->leaf_hits, node->hits,
76
+					node->expires - get_ticks(), ns);
77
+*/	}
78
+	else {	/* not a any kind of leaf - inner node */
79
+		DBG("pike:rpc traverse_subtree, not IP leaf, depth: %d, ip: %d.%d.%d.%d"
80
+				"   hits[%d,%d], expires: %d",
81
+			depth, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3],
82
+			node->hits[0], node->hits[1], node->expires - get_ticks());
83
+	}
84
+
85
+	foo = node->kids;
86
+	while (foo) {
87
+		traverse_subtree( foo, depth + 1, options );
88
+		foo = foo->next;
89
+	}
90
+}
91
+
92
+static void collect_data(int options)
93
+{
94
+	int i;
95
+
96
+	g_max_hits = get_max_hits();
97
+
98
+	DBG("pike: collect_data");
99
+
100
+	// maybe try_lock first and than do the rest?
101
+	for(i=0;i<MAX_IP_BRANCHES;i++) {
102
+		if (get_tree_branch(i)==0)
103
+			continue;
104
+		DBG("pike: collect_data: branch %d", i);
105
+		lock_tree_branch(i);
106
+		if (get_tree_branch(i))
107
+			traverse_subtree( get_tree_branch(i), 0, options );
108
+		unlock_tree_branch(i);
109
+	}
110
+}
111
+
112
+static void pike_top(rpc_t *rpc, void *c)
113
+{
114
+	int i;
115
+	void *handle;
116
+	void *list;
117
+	void *item;
118
+	struct TopListItem_t *top_list_root;
119
+	struct TopListItem_t *ti = 0;
120
+	char addr_buff[PIKE_BUFF_SIZE*sizeof(char)];
121
+	char *stropts;
122
+	int   options = 0;
123
+
124
+	DBG("pike: top");
125
+
126
+	/* obtain params */
127
+	if (rpc->scan(c, "s", &stropts) <= 0)
128
+		stropts = "HOT";
129
+
130
+	DBG("pike:top: string options: '%s'", stropts);
131
+	if ( strstr(stropts, "ALL") ) {
132
+		options = NODE_STATUS_ALL;
133
+	} else if ( strstr(stropts, "HOT") ) {
134
+		options |= NODE_STATUS_HOT;
135
+	} else if ( strstr(stropts, "WARM") ) {
136
+		options |= NODE_STATUS_WARM;
137
+	}
138
+	DBG("pike:top: options: 0x%02x\n", options);
139
+
140
+
141
+	if (options == 0) {
142
+		rpc->fault(c, 500, "Bad argument. Select: ALL, HOT or WARM");
143
+		return;
144
+	}
145
+
146
+
147
+	print_tree( 0 );
148
+
149
+	collect_data(options);
150
+	top_list_root = pike_top_get_root();
151
+	DBG("pike_top: top_list_root = %p", top_list_root);
152
+
153
+	rpc->add(c, "{", &handle);
154
+	rpc->struct_add(handle, "d[", "max_hits", get_max_hits(), "list", &list);
155
+	i = 0; // it is passed as number of rows
156
+	if ( top_list_root == 0 ) {
157
+		DBG("pike_top: no data");
158
+	}
159
+	else {
160
+		for( ti = top_list_root, i = 0; ti != 0; ti = ti->next, ++i ) {
161
+			pike_top_print_addr(ti->ip_addr, ti->addr_len, addr_buff,
162
+					sizeof(addr_buff));
163
+			DBG("pike:top: result[%d]: %s leaf_hits[%d,%d] hits[%d,%d]"
164
+					" expires: %d status: 0x%02x",
165
+					i, addr_buff, ti->leaf_hits[0], ti->leaf_hits[1],
166
+					ti->hits[0], ti->hits[1], ti->expires, ti->status);
167
+			rpc->array_add(list, "{", &item);
168
+			rpc->struct_add(item, "sddds",
169
+							"ip_addr", addr_buff,
170
+							"leaf_hits_prev", ti->leaf_hits[0],
171
+							"leaf_hits_curr", ti->leaf_hits[1],
172
+							"expires", ti->expires,
173
+							"status", node_status_array[ti->status]);
174
+		}
175
+	}
176
+	rpc->struct_add(handle, "d", "number_of_rows", i);
177
+	pike_top_list_clear();
178
+}
179
+
180
+/* ----- exported data structure with methods ----- */
181
+
182
+// TODO check documentation
183
+static const char* pike_top_doc[] = {
184
+	"pike.top Dump parts of the pike table",  /* Documentation string */
185
+	0                 /* Method signature(s) */
186
+};
187
+
188
+/*
189
+ * RPC Methods exported by this module
190
+ */
191
+
192
+rpc_export_t pike_rpc_methods[] = {
193
+	{"pike.top",   pike_top,     pike_top_doc, 0},
194
+	{0, 0, 0, 0}
195
+};