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
... ...
@@ -76,7 +76,7 @@ static char *print_addr(unsigned char *ip, int iplen)
76 76
 
77 77
 int pike_top_add_entry( unsigned char *ip_addr, int addr_len,
78 78
 		unsigned short leaf_hits[2], unsigned short hits[2],
79
-		unsigned int expires, node_status_t status )
79
+		unsigned int expires, pike_node_status_t status )
80 80
 {
81 81
 	struct TopListItem_t *new_item
82 82
 				= (struct TopListItem_t *)malloc(sizeof(struct TopListItem_t));
Browse code

pike: use snprintf() instead of sprintf()

Daniel-Constantin Mierla authored on 25/11/2019 10:29:16
Showing 1 changed files
... ...
@@ -41,22 +41,28 @@ char *pike_top_print_addr( unsigned char *ip, int iplen, char *buff,
41 41
 		int buffsize )
42 42
 {
43 43
 	unsigned short *ipv6_ptr = (unsigned short *)ip;
44
-	memset(buff, 0, PIKE_BUFF_SIZE*sizeof(char));
44
+	int bsize;
45
+	int blen;
46
+
47
+	bsize = PIKE_BUFF_SIZE*sizeof(char);
48
+	memset(buff, 0, bsize);
45 49
 
46 50
 	DBG("pike:top:print_addr(iplen: %d, buffsize: %d)", iplen, buffsize);
47 51
 
48 52
 	if ( iplen == 4 ) {
49 53
 		inet_ntop(AF_INET, ip, buff, buffsize);
50
-	}
51
-	else if ( iplen == 16 ) {
54
+	} else if ( iplen == 16 ) {
52 55
 		inet_ntop(AF_INET6, ip, buff, buffsize);
53
-	}
54
-	else {
55
-		sprintf( buff, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
56
+	} else {
57
+		blen = snprintf(buff, bsize, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
56 58
 				htons(ipv6_ptr[0]), htons(ipv6_ptr[1]), htons(ipv6_ptr[2]),
57 59
 				htons(ipv6_ptr[3]),
58 60
 				htons(ipv6_ptr[4]), htons(ipv6_ptr[5]), htons(ipv6_ptr[6]),
59 61
 				htons(ipv6_ptr[7]));
62
+		if(blen < 0 || blen >= bsize) {
63
+			LM_ERR("failed to print the address - reset it\n");
64
+			memset(buff, 0, bsize);
65
+		}
60 66
 	}
61 67
 
62 68
 	return buff;
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,7 +20,7 @@
20 20
  */
21 21
 #include "pike_top.h"
22 22
 
23
-#include "../../dprint.h"
23
+#include "../../core/dprint.h"
24 24
 
25 25
 #include <stdio.h>
26 26
 #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,117 @@
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
+#include "pike_top.h"
22
+
23
+#include "../../dprint.h"
24
+
25
+#include <stdio.h>
26
+#include <stdlib.h>
27
+#include <string.h>
28
+#include <assert.h>
29
+#include <arpa/inet.h>
30
+#include "ip_tree.h"
31
+
32
+
33
+static struct TopListItem_t *top_list_root = 0;
34
+static struct TopListItem_t *top_list_iter = 0;
35
+
36
+static char buff[PIKE_BUFF_SIZE];
37
+
38
+struct TopListItem_t *pike_top_get_root() { return top_list_root; }
39
+
40
+char *pike_top_print_addr( unsigned char *ip, int iplen, char *buff,
41
+		int buffsize )
42
+{
43
+	unsigned short *ipv6_ptr = (unsigned short *)ip;
44
+	memset(buff, 0, PIKE_BUFF_SIZE*sizeof(char));
45
+
46
+	DBG("pike:top:print_addr(iplen: %d, buffsize: %d)", iplen, buffsize);
47
+
48
+	if ( iplen == 4 ) {
49
+		inet_ntop(AF_INET, ip, buff, buffsize);
50
+	}
51
+	else if ( iplen == 16 ) {
52
+		inet_ntop(AF_INET6, ip, buff, buffsize);
53
+	}
54
+	else {
55
+		sprintf( buff, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
56
+				htons(ipv6_ptr[0]), htons(ipv6_ptr[1]), htons(ipv6_ptr[2]),
57
+				htons(ipv6_ptr[3]),
58
+				htons(ipv6_ptr[4]), htons(ipv6_ptr[5]), htons(ipv6_ptr[6]),
59
+				htons(ipv6_ptr[7]));
60
+	}
61
+
62
+	return buff;
63
+}
64
+
65
+/* if you do not need global buffer, you can use this simpler call */
66
+static char *print_addr(unsigned char *ip, int iplen)
67
+{
68
+	return pike_top_print_addr(ip, iplen, buff, sizeof(buff));
69
+}
70
+
71
+int pike_top_add_entry( unsigned char *ip_addr, int addr_len,
72
+		unsigned short leaf_hits[2], unsigned short hits[2],
73
+		unsigned int expires, node_status_t status )
74
+{
75
+	struct TopListItem_t *new_item
76
+				= (struct TopListItem_t *)malloc(sizeof(struct TopListItem_t));
77
+
78
+	print_addr(ip_addr, addr_len);
79
+	DBG("pike_top_add_enrty(ip: %s, leaf_hits[%d,%d], hits[%d,%d],"
80
+			" expires: %d, status: %d)",
81
+			buff, leaf_hits[0], leaf_hits[1], hits[0], hits[1],
82
+			expires, status);
83
+	assert(new_item != 0);
84
+
85
+	memset( (void *)new_item, 0, sizeof(struct TopListItem_t) );
86
+
87
+	new_item->status  = status;
88
+	new_item->expires = expires;
89
+	new_item->hits[0] = hits[0];
90
+	new_item->hits[1] = hits[1];
91
+	new_item->leaf_hits[0] = leaf_hits[0];
92
+	new_item->leaf_hits[1] = leaf_hits[1];
93
+
94
+	assert( addr_len <= 16 );
95
+
96
+	new_item->addr_len = addr_len;
97
+	memcpy(new_item->ip_addr, ip_addr, addr_len);
98
+
99
+	new_item->next = top_list_root;
100
+	top_list_root  = new_item;
101
+
102
+	return 1;
103
+}
104
+
105
+void pike_top_list_clear()
106
+{
107
+	struct TopListItem_t *ptr;
108
+
109
+	top_list_iter = top_list_root;
110
+	while (top_list_iter) {
111
+		ptr = top_list_iter->next;
112
+		free(top_list_iter);
113
+		top_list_iter = ptr;
114
+	}
115
+	top_list_root = 0;
116
+	memset(buff, 0, sizeof(buff));
117
+}