Browse code

modules_k/*: moved k modules in directory modules/

Daniel-Constantin Mierla authored on 20/01/2013 11:57:52
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,832 +0,0 @@
1
-/*
2
- * Hash functions for cached trusted and address tables
3
- *
4
- * Copyright (C) 2003-2012 Juha Heinanen
5
- *
6
- * This file is part of Kamailio, a free SIP server.
7
- *
8
- * Kamailio is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version
12
- *
13
- * Kamailio is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License 
19
- * along with this program; if not, write to the Free Software 
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
- */
22
-
23
-#include <sys/types.h>
24
-#include <regex.h>
25
-#include "../../mem/shm_mem.h"
26
-#include "../../parser/parse_from.h"
27
-#include "../../ut.h"
28
-#include "../../hashes.h"
29
-#include "../../usr_avp.h"
30
-#include "../../ip_addr.h"
31
-#include "../../pvar.h"
32
-#include "hash.h"
33
-#include "trusted.h"
34
-#include "address.h"
35
-
36
-#define perm_hash(_s)  core_hash( &(_s), 0, PERM_HASH_SIZE)
37
-
38
-
39
-/* tag AVP specs */
40
-static int     tag_avp_type;
41
-static int_str tag_avp;
42
-
43
-extern int peer_tag_mode;
44
-
45
-
46
-
47
-/*
48
- * Parse and set tag AVP specs
49
- */
50
-int init_tag_avp(str *tag_avp_param)
51
-{
52
-	pv_spec_t avp_spec;
53
-	unsigned short avp_flags;
54
-
55
-	if (tag_avp_param->s && tag_avp_param->len > 0) {
56
-		if (pv_parse_spec(tag_avp_param, &avp_spec)==0
57
-				|| avp_spec.type != PVT_AVP) {
58
-			LM_ERR("malformed or non "
59
-					"AVP %.*s peer_tag_avp definition\n", tag_avp_param->len, tag_avp_param->s);
60
-			return -1;
61
-		}
62
-		if(pv_get_avp_name(0, &avp_spec.pvp, &tag_avp, &avp_flags)!=0) {
63
-			LM_ERR("[%.*s]- invalid "
64
-					"peer_tag_avp AVP definition\n", tag_avp_param->len, tag_avp_param->s);
65
-			return -1;
66
-		}
67
-		tag_avp_type = avp_flags;
68
-	} else {
69
-		tag_avp.n = 0;
70
-	}
71
-	return 0;
72
-}
73
-
74
-
75
-/*
76
- * Gets tag avp specs
77
- */
78
-void get_tag_avp(int_str *tag_avp_p, int *tag_avp_type_p)
79
-{
80
-	*tag_avp_p = tag_avp;
81
-	*tag_avp_type_p = tag_avp_type;
82
-}
83
-
84
-
85
-/*
86
- * Create and initialize a hash table
87
- */
88
-struct trusted_list** new_hash_table(void)
89
-{
90
-	struct trusted_list** ptr;
91
-
92
-	/* Initializing hash tables and hash table variable */
93
-	ptr = (struct trusted_list **)shm_malloc
94
-		(sizeof(struct trusted_list*) * PERM_HASH_SIZE);
95
-	if (!ptr) {
96
-		LM_ERR("no shm memory for hash table\n");
97
-		return 0;
98
-	}
99
-
100
-	memset(ptr, 0, sizeof(struct trusted_list*) * PERM_HASH_SIZE);
101
-	return ptr;
102
-}
103
-
104
-
105
-/*
106
- * Release all memory allocated for a hash table
107
- */
108
-void free_hash_table(struct trusted_list** table)
109
-{
110
-	if (!table)
111
-		return;
112
-
113
-	empty_hash_table(table);
114
-	shm_free(table);
115
-}
116
-
117
-
118
-/* 
119
- * Add <src_ip, proto, pattern, tag> into hash table, where proto is integer
120
- * representation of string argument proto.
121
- */
122
-int hash_table_insert(struct trusted_list** table, char* src_ip, 
123
-		char* proto, char* pattern, char* tag)
124
-{
125
-	struct trusted_list *np;
126
-	unsigned int hash_val;
127
-
128
-	np = (struct trusted_list *) shm_malloc(sizeof(*np));
129
-	if (np == NULL) {
130
-		LM_ERR("cannot allocate shm memory for table entry\n");
131
-		return -1;
132
-	}
133
-
134
-	if (strcasecmp(proto, "any") == 0) {
135
-		np->proto = PROTO_NONE;
136
-	} else if (strcasecmp(proto, "udp") == 0) {
137
-		np->proto = PROTO_UDP;
138
-	} else if (strcasecmp(proto, "tcp") == 0) {
139
-		np->proto = PROTO_TCP;
140
-	} else if (strcasecmp(proto, "tls") == 0) {
141
-		np->proto = PROTO_TLS;
142
-	} else if (strcasecmp(proto, "sctp") == 0) {
143
-		np->proto = PROTO_SCTP;
144
-	} else if (strcasecmp(proto, "ws") == 0) {
145
-		np->proto = PROTO_WS;
146
-	} else if (strcasecmp(proto, "wss") == 0) {
147
-		np->proto = PROTO_WSS;
148
-	} else if (strcasecmp(proto, "none") == 0) {
149
-		shm_free(np);
150
-		return 1;
151
-	} else {
152
-		LM_CRIT("unknown protocol\n");
153
-		shm_free(np);
154
-		return -1;
155
-	}
156
-
157
-	np->src_ip.len = strlen(src_ip);
158
-	np->src_ip.s = (char *) shm_malloc(np->src_ip.len);
159
-
160
-	if (np->src_ip.s == NULL) {
161
-		LM_CRIT("cannot allocate shm memory for src_ip string\n");
162
-		shm_free(np);
163
-		return -1;
164
-	}
165
-
166
-	(void) strncpy(np->src_ip.s, src_ip, np->src_ip.len);
167
-
168
-	if (pattern) {
169
-		np->pattern = (char *) shm_malloc(strlen(pattern)+1);
170
-		if (np->pattern == NULL) {
171
-			LM_CRIT("cannot allocate shm memory for pattern string\n");
172
-			shm_free(np->src_ip.s);
173
-			shm_free(np);
174
-			return -1;
175
-		}
176
-		(void) strcpy(np->pattern, pattern);
177
-	} else {
178
-		np->pattern = 0;
179
-	}
180
-
181
-	if (tag) {
182
-		np->tag.len = strlen(tag);
183
-		np->tag.s = (char *) shm_malloc((np->tag.len) + 1);
184
-		if (np->tag.s == NULL) {
185
-			LM_CRIT("cannot allocate shm memory for pattern string\n");
186
-			shm_free(np->src_ip.s);
187
-			shm_free(np->pattern);
188
-			shm_free(np);
189
-			return -1;
190
-		}
191
-		(void) strcpy(np->tag.s, tag);
192
-	} else {
193
-		np->tag.len = 0;
194
-		np->tag.s = 0;
195
-	}
196
-
197
-	hash_val = perm_hash(np->src_ip);
198
-	np->next = table[hash_val];
199
-	table[hash_val] = np;
200
-
201
-	return 1;
202
-}
203
-
204
-
205
-/* 
206
- * Check if an entry exists in hash table that has given src_ip and protocol
207
- * value and pattern that matches to From URI.  If an entry exists and tag_avp
208
- * has been defined, tag of the entry is added as a value to tag_avp.
209
- * Returns number of matches or -1 if none matched.
210
- */
211
-int match_hash_table(struct trusted_list** table, struct sip_msg* msg,
212
-		char *src_ip_c_str, int proto)
213
-{
214
-	str uri;
215
-	char uri_string[MAX_URI_SIZE + 1];
216
-	regex_t preg;
217
-	struct trusted_list *np;
218
-	str src_ip;
219
-	int_str val;
220
-	int count = 0;
221
-
222
-	src_ip.s = src_ip_c_str;
223
-	src_ip.len = strlen(src_ip.s);
224
-
225
-	if (IS_SIP(msg))
226
-	{
227
-		if (parse_from_header(msg) < 0) return -1;
228
-		uri = get_from(msg)->uri;
229
-		if (uri.len > MAX_URI_SIZE) {
230
-			LM_ERR("from URI too large\n");
231
-			return -1;
232
-		}
233
-		memcpy(uri_string, uri.s, uri.len);
234
-		uri_string[uri.len] = (char)0;
235
-	}
236
-
237
-	for (np = table[perm_hash(src_ip)]; np != NULL; np = np->next) {
238
-	    if ((np->src_ip.len == src_ip.len) && 
239
-		(strncmp(np->src_ip.s, src_ip.s, src_ip.len) == 0) &&
240
-		((np->proto == PROTO_NONE) || (proto == PROTO_NONE) ||
241
-		 (np->proto == proto))) {
242
-		if (np->pattern && IS_SIP(msg)) {
243
-		    if (regcomp(&preg, np->pattern, REG_NOSUB)) {
244
-			LM_ERR("invalid regular expression\n");
245
-			continue;
246
-		    }
247
-		    if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) {
248
-			regfree(&preg);
249
-			continue;
250
-		    }
251
-		    regfree(&preg);
252
-		}
253
-		/* Found a match */
254
-		if (tag_avp.n && np->tag.s) {
255
-		    val.s = np->tag;
256
-		    if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, val) != 0) {
257
-			LM_ERR("setting of tag_avp failed\n");
258
-			return -1;
259
-		    }
260
-		}
261
-		if (!peer_tag_mode)
262
-		    return 1;
263
-		count++;
264
-	    }
265
-	}
266
-	if (!count)
267
-	    return -1;
268
-	else 
269
-	    return count;
270
-}
271
-
272
-
273
-/*! \brief
274
- * MI Interface :: Print trusted entries stored in hash table 
275
- */
276
-int hash_table_mi_print(struct trusted_list** table, struct mi_node* rpl)
277
-{
278
-	int i;
279
-	struct trusted_list *np;
280
-
281
-	for (i = 0; i < PERM_HASH_SIZE; i++) {
282
-		np = table[i];
283
-		while (np) {
284
-			if (addf_mi_node_child(rpl, 0, 0, 0,
285
-						"%4d <%.*s, %d, %s, %s>",
286
-						i,
287
-						np->src_ip.len, ZSW(np->src_ip.s),
288
-						np->proto,
289
-						np->pattern?np->pattern:"NULL",
290
-						np->tag.len?np->tag.s:"NULL") == 0) {
291
-				return -1;
292
-			}
293
-			np = np->next;
294
-		}
295
-	}
296
-	return 0;
297
-}
298
-
299
-/*! \brief
300
- * RPC interface :: Print trusted entries stored in hash table 
301
- */
302
-int hash_table_rpc_print(struct trusted_list** hash_table, rpc_t* rpc, void* c)
303
-{
304
-	int i;
305
-	struct trusted_list *np;
306
-	void* th;
307
-	void* ih;
308
-
309
-	if (rpc->add(c, "{", &th) < 0)
310
-	{
311
-		rpc->fault(c, 500, "Internal error creating rpc");
312
-		return -1;
313
-	}
314
-
315
-	for (i = 0; i < PERM_HASH_SIZE; i++) {
316
-		np = hash_table[i];
317
-		while (np) {
318
-			if(rpc->struct_add(th, "d{", 
319
-					"table", i,
320
-					"item", &ih) < 0)
321
-                        {
322
-                                rpc->fault(c, 500, "Internal error creating rpc ih");
323
-                                return -1;
324
-                        }
325
-
326
-			if(rpc->struct_add(ih, "s", "ip", np->src_ip.s) < 0)
327
-			{
328
-				rpc->fault(c, 500, "Internal error creating rpc data (ip)");
329
-				return -1;
330
-			}
331
-			if(rpc->struct_add(ih, "dss", "proto",  np->proto,
332
-						"pattern",  np->pattern ? np->pattern : "NULL",
333
-						"tag",  np->tag.len ? np->tag.s : "NULL") < 0)
334
-			{
335
-				rpc->fault(c, 500, "Internal error creating rpc data");
336
-				return -1;
337
-			}
338
-			np = np->next;
339
-		}
340
-	}
341
-	return 0;
342
-}
343
-
344
-/* 
345
- * Free contents of hash table, it doesn't destroy the
346
- * hash table itself
347
- */
348
-void empty_hash_table(struct trusted_list **table)
349
-{
350
-	int i;
351
-	struct trusted_list *np, *next;
352
-
353
-	for (i = 0; i < PERM_HASH_SIZE; i++) {
354
-		np = table[i];
355
-		while (np) {
356
-			if (np->src_ip.s) shm_free(np->src_ip.s);
357
-			if (np->pattern) shm_free(np->pattern);
358
-			if (np->tag.s) shm_free(np->tag.s);
359
-			next = np->next;
360
-			shm_free(np);
361
-			np = next;
362
-		}
363
-		table[i] = 0;
364
-	}
365
-}
366
-
367
-
368
-/*
369
- * Create and initialize an address hash table
370
- */
371
-struct addr_list** new_addr_hash_table(void)
372
-{
373
-	struct addr_list** ptr;
374
-
375
-	/* Initializing hash tables and hash table variable */
376
-	ptr = (struct addr_list **)shm_malloc
377
-		(sizeof(struct addr_list*) * PERM_HASH_SIZE);
378
-	if (!ptr) {
379
-		LM_ERR("no shm memory for hash table\n");
380
-		return 0;
381
-	}
382
-
383
-	memset(ptr, 0, sizeof(struct addr_list*) * PERM_HASH_SIZE);
384
-	return ptr;
385
-}
386
-
387
-
388
-/*
389
- * Release all memory allocated for a hash table
390
- */
391
-void free_addr_hash_table(struct addr_list** table)
392
-{
393
-	if (!table)
394
-		return;
395
-
396
-	empty_addr_hash_table(table);
397
-	shm_free(table);
398
-}
399
-
400
-
401
-/* 
402
- * Add <grp, ip_addr, port> into hash table
403
- */
404
-int addr_hash_table_insert(struct addr_list** table, unsigned int grp,
405
-		ip_addr_t *addr, unsigned int port, char *tagv)
406
-{
407
-	struct addr_list *np;
408
-	unsigned int hash_val;
409
-	str addr_str;
410
-	int len;
411
-
412
-	len = sizeof(struct addr_list);
413
-	if(tagv!=NULL)
414
-		len += strlen(tagv) + 1;
415
-
416
-	np = (struct addr_list *) shm_malloc(len);
417
-	if (np == NULL) {
418
-		LM_ERR("no shm memory for table entry\n");
419
-		return -1;
420
-	}
421
-
422
-	memset(np, 0, len);
423
-
424
-	np->grp = grp;
425
-	memcpy(&np->addr, addr, sizeof(ip_addr_t));
426
-	np->port = port;
427
-	if(tagv!=NULL)
428
-	{
429
-		np->tag.s = (char*)np + sizeof(struct addr_list);
430
-		np->tag.len = strlen(tagv);
431
-		strcpy(np->tag.s, tagv);
432
-	}
433
-
434
-	addr_str.s = (char*)addr->u.addr;
435
-	addr_str.len = 4;
436
-	hash_val = perm_hash(addr_str);
437
-	np->next = table[hash_val];
438
-	table[hash_val] = np;
439
-
440
-	return 1;
441
-}
442
-
443
-
444
-/* 
445
- * Check if an entry exists in hash table that has given group, ip_addr, and
446
- * port.  Port 0 in hash table matches any port.
447
- */
448
-int match_addr_hash_table(struct addr_list** table, unsigned int group,
449
-		ip_addr_t *addr, unsigned int port)
450
-{
451
-	struct addr_list *np;
452
-	str addr_str;
453
-	avp_value_t val;
454
-
455
-	addr_str.s = (char*)addr->u.addr;
456
-	addr_str.len = 4;
457
-
458
-	for (np = table[perm_hash(addr_str)]; np != NULL; np = np->next) {
459
-		if ( (np->grp == group)
460
-				&& ((np->port == 0) || (np->port == port))
461
-				&& ip_addr_cmp(&np->addr, addr)) {
462
-
463
-			if (tag_avp.n && np->tag.s) {
464
-				val.s = np->tag;
465
-				if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, val) != 0) {
466
-					LM_ERR("setting of tag_avp failed\n");
467
-					return -1;
468
-				}
469
-			}
470
-
471
-			return 1;
472
-		}
473
-	}
474
-
475
-	return -1;
476
-}
477
-
478
-
479
-/* 
480
- * Check if an ip_addr/port entry exists in hash table in any group.
481
- * Returns first group in which ip_addr/port is found.
482
- * Port 0 in hash table matches any port. 
483
- */
484
-int find_group_in_addr_hash_table(struct addr_list** table,
485
-		ip_addr_t *addr, unsigned int port)
486
-{
487
-	struct addr_list *np;
488
-	str addr_str;
489
-
490
-	addr_str.s = (char*)addr->u.addr;
491
-	addr_str.len = 4;
492
-
493
-	for (np = table[perm_hash(addr_str)]; np != NULL; np = np->next) {
494
-		if (((np->port == 0) || (np->port == port))
495
-				&& ip_addr_cmp(&np->addr, addr)) {
496
-			return np->grp;
497
-		}
498
-	}
499
-
500
-	return -1;
501
-}
502
-
503
-/*! \brief
504
- * MI: Print addresses stored in hash table 
505
- */
506
-int addr_hash_table_mi_print(struct addr_list** table, struct mi_node* rpl)
507
-{
508
-	int i;
509
-	struct addr_list *np;
510
-
511
-	for (i = 0; i < PERM_HASH_SIZE; i++) {
512
-		np = table[i];
513
-		while (np) {
514
-			if (addf_mi_node_child(rpl, 0, 0, 0,
515
-						"%4d <%u, %s, %u> [%s]",
516
-						i, np->grp, ip_addr2a(&np->addr),
517
-						np->port, (np->tag.s==NULL)?"":np->tag.s) == 0)
518
-				return -1;
519
-			np = np->next;
520
-		}
521
-	}
522
-	return 0;
523
-}
524
-
525
-/*! \brief
526
- * RPC: Print addresses stored in hash table 
527
- */
528
-int addr_hash_table_rpc_print(struct addr_list** table, rpc_t* rpc, void* c)
529
-{
530
-	int i;
531
-	void* th;
532
-	void* ih;
533
-	struct addr_list *np;
534
-
535
-
536
-	if (rpc->add(c, "{", &th) < 0)
537
-	{
538
-		rpc->fault(c, 500, "Internal error creating rpc");
539
-		return -1;
540
-	}
541
-
542
-	for (i = 0; i < PERM_HASH_SIZE; i++) {
543
-		np = table[i];
544
-		while (np) {
545
-			if(rpc->struct_add(th, "dd{", 
546
-					"table", i,
547
-					"group", np->grp,
548
-					"item", &ih) < 0)
549
-                        {
550
-                                rpc->fault(c, 500, "Internal error creating rpc ih");
551
-                                return -1;
552
-                        }
553
-
554
-			if(rpc->struct_add(ih, "s", "ip", ip_addr2a(&np->addr)) < 0)
555
-			{
556
-				rpc->fault(c, 500, "Internal error creating rpc data (ip)");
557
-				return -1;
558
-			}
559
-			if(rpc->struct_add(ih, "ds", "port",  np->port,
560
-						"tag",  np->tag.len ? np->tag.s : "NULL") < 0)
561
-			{
562
-				rpc->fault(c, 500, "Internal error creating rpc data");
563
-				return -1;
564
-			}
565
-			np = np->next;
566
-		}
567
-	}
568
-	return 0;
569
-}
570
-
571
-
572
-/* 
573
- * Free contents of hash table, it doesn't destroy the
574
- * hash table itself
575
- */
576
-void empty_addr_hash_table(struct addr_list **table)
577
-{
578
-	int i;
579
-	struct addr_list *np, *next;
580
-
581
-	for (i = 0; i < PERM_HASH_SIZE; i++) {
582
-		np = table[i];
583
-		while (np) {
584
-			next = np->next;
585
-			shm_free(np);
586
-			np = next;
587
-		}
588
-		table[i] = 0;
589
-	}
590
-}
591
-
592
-
593
-/*
594
- * Create and initialize a subnet table
595
- */
596
-struct subnet* new_subnet_table(void)
597
-{
598
-	struct subnet* ptr;
599
-
600
-	/* subnet record [PERM_MAX_SUBNETS] contains in its grp field 
601
-	   the number of subnet records in the subnet table */
602
-	ptr = (struct subnet *)shm_malloc
603
-		(sizeof(struct subnet) * (PERM_MAX_SUBNETS + 1));
604
-	if (!ptr) {
605
-		LM_ERR("no shm memory for subnet table\n");
606
-		return 0;
607
-	}
608
-	memset(ptr, 0, sizeof(struct subnet) * (PERM_MAX_SUBNETS + 1));
609
-	return ptr;
610
-}
611
-
612
-
613
-/* 
614
- * Add <grp, subnet, mask, port, tag> into subnet table so that table is
615
- * kept in increasing ordered according to grp.
616
- */
617
-int subnet_table_insert(struct subnet* table, unsigned int grp,
618
-		ip_addr_t *subnet, unsigned int mask,
619
-		unsigned int port, char *tagv)
620
-{
621
-	int i;
622
-	unsigned int count;
623
-	str tags;
624
-
625
-	count = table[PERM_MAX_SUBNETS].grp;
626
-
627
-	if (count == PERM_MAX_SUBNETS) {
628
-		LM_CRIT("subnet table is full\n");
629
-		return 0;
630
-	}
631
-
632
-	if(tagv==NULL)
633
-	{
634
-		tags.s = NULL;
635
-		tags.len = 0;
636
-	} else {
637
-		tags.len = strlen(tagv);
638
-		tags.s = (char*)shm_malloc(tags.len+1);
639
-		if(tags.s==NULL)
640
-		{
641
-			LM_ERR("No more shared memory\n");
642
-			return 0;
643
-		}
644
-		strcpy(tags.s, tagv);
645
-	}
646
-
647
-	i = count - 1;
648
-
649
-	while ((i >= 0) && (table[i].grp > grp)) {
650
-		table[i + 1] = table[i];
651
-		i--;
652
-	}
653
-
654
-	table[i + 1].grp = grp;
655
-	memcpy(&table[i + 1].subnet, subnet, sizeof(ip_addr_t));
656
-	table[i + 1].port = port;
657
-	table[i + 1].mask = mask;
658
-	table[i + 1].tag = tags;
659
-
660
-	table[PERM_MAX_SUBNETS].grp = count + 1;
661
-
662
-	return 1;
663
-}
664
-
665
-
666
-/* 
667
- * Check if an entry exists in subnet table that matches given group, ip_addr,
668
- * and port.  Port 0 in subnet table matches any port.
669
- */
670
-int match_subnet_table(struct subnet* table, unsigned int grp,
671
-		ip_addr_t *addr, unsigned int port)
672
-{
673
-	unsigned int count, i;
674
-	avp_value_t val;
675
-
676
-	count = table[PERM_MAX_SUBNETS].grp;
677
-
678
-	i = 0;
679
-	while ((i < count) && (table[i].grp < grp))
680
-		i++;
681
-
682
-	if (i == count) return -1;
683
-
684
-	while ((i < count) && (table[i].grp == grp)) {
685
-		if (((table[i].port == port) || (table[i].port == 0))
686
-			&& (ip_addr_match_net(addr, &table[i].subnet, table[i].mask)==0))
687
-		{
688
-			if (tag_avp.n && table[i].tag.s) {
689
-				val.s = table[i].tag;
690
-				if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, val) != 0) {
691
-					LM_ERR("setting of tag_avp failed\n");
692
-					return -1;
693
-				}
694
-			}
695
-			return 1;
696
-		}
697
-		i++;
698
-	}
699
-
700
-	return -1;
701
-}
702
-
703
-
704
-/* 
705
- * Check if an entry exists in subnet table that matches given ip_addr,
706
- * and port.  Port 0 in subnet table matches any port.  Return group of
707
- * first match or -1 if no match is found.
708
- */
709
-int find_group_in_subnet_table(struct subnet* table,
710
-		ip_addr_t *addr, unsigned int port)
711
-{
712
-	unsigned int count, i;
713
-
714
-	count = table[PERM_MAX_SUBNETS].grp;
715
-
716
-	i = 0;
717
-	while (i < count) {
718
-		if ( ((table[i].port == port) || (table[i].port == 0))
719
-			&& (ip_addr_match_net(addr, &table[i].subnet, table[i].mask)==0))
720
-			return table[i].grp;
721
-		i++;
722
-	}
723
-
724
-	return -1;
725
-}
726
-
727
-
728
-/* 
729
- * Print subnets stored in subnet table 
730
- */
731
-int subnet_table_mi_print(struct subnet* table, struct mi_node* rpl)
732
-{
733
-	unsigned int count, i;
734
-
735
-	count = table[PERM_MAX_SUBNETS].grp;
736
-
737
-	for (i = 0; i < count; i++) {
738
-		if (addf_mi_node_child(rpl, 0, 0, 0,
739
-					"%4d <%u, %s, %u, %u> [%s]",
740
-					i, table[i].grp, ip_addr2a(&table[i].subnet),
741
-					table[i].mask, table[i].port,
742
-					(table[i].tag.s==NULL)?"":table[i].tag.s) == 0) {
743
-			return -1;
744
-		}
745
-	}
746
-	return 0;
747
-}
748
-
749
-/*! \brief
750
- * RPC interface :: Print subnet entries stored in hash table 
751
- */
752
-int subnet_table_rpc_print(struct subnet* table, rpc_t* rpc, void* c)
753
-{
754
-	int i;
755
-	int count;
756
-	void* th;
757
-	void* ih;
758
-
759
-	count = table[PERM_MAX_SUBNETS].grp;
760
-
761
-	if (rpc->add(c, "{", &th) < 0)
762
-	{
763
-		rpc->fault(c, 500, "Internal error creating rpc");
764
-		return -1;
765
-	}
766
-
767
-	for (i = 0; i < count; i++) {
768
-		if(rpc->struct_add(th, "dd{", 
769
-				"id", i,
770
-				"group", table[i].grp,
771
-				"item", &ih) < 0)
772
-                {
773
-                        rpc->fault(c, 500, "Internal error creating rpc ih");
774
-                        return -1;
775
-                }
776
-
777
-		if(rpc->struct_add(ih, "s", "ip", ip_addr2a(&table[i].subnet)) < 0)
778
-		{
779
-			rpc->fault(c, 500, "Internal error creating rpc data (subnet)");
780
-			return -1;
781
-		}
782
-		if(rpc->struct_add(ih, "dds", "mask", table[i].mask,
783
-					"port", table[i].port,
784
-					"tag",  (table[i].tag.s==NULL)?"":table[i].tag.s) < 0)
785
-		{
786
-			rpc->fault(c, 500, "Internal error creating rpc data");
787
-			return -1;
788
-		}
789
-	}
790
-	return 0;
791
-}
792
-
793
-
794
-/* 
795
- * Empty contents of subnet table
796
- */
797
-void empty_subnet_table(struct subnet *table)
798
-{
799
-	int i;
800
-	table[PERM_MAX_SUBNETS].grp = 0;
801
-	for(i=0; i<PERM_MAX_SUBNETS; i++)
802
-	{
803
-		if(table[i].tag.s!=NULL)
804
-		{
805
-			shm_free(table[i].tag.s);
806
-			table[i].tag.s = NULL;
807
-			table[i].tag.len =0;
808
-		}
809
-	}
810
-}
811
-
812
-
813
-/*
814
- * Release memory allocated for a subnet table
815
- */
816
-void free_subnet_table(struct subnet* table)
817
-{
818
-	int i;
819
-	if (!table)
820
-		return;
821
-	for(i=0; i<PERM_MAX_SUBNETS; i++)
822
-	{
823
-		if(table[i].tag.s!=NULL)
824
-		{
825
-			shm_free(table[i].tag.s);
826
-			table[i].tag.s = NULL;
827
-			table[i].tag.len =0;
828
-		}
829
-	}
830
-
831
-	shm_free(table);
832
-}
Browse code

permissions: remove unused variable `count'

Ovidiu Sas authored on 11/01/2013 20:13:16
Showing 1 changed files
... ...
@@ -528,7 +528,6 @@ int addr_hash_table_mi_print(struct addr_list** table, struct mi_node* rpl)
528 528
 int addr_hash_table_rpc_print(struct addr_list** table, rpc_t* rpc, void* c)
529 529
 {
530 530
 	int i;
531
-	int count;
532 531
 	void* th;
533 532
 	void* ih;
534 533
 	struct addr_list *np;
Browse code

permissions(k) Add RPC function calls that match functionality in old modules_s module

Olle E. Johansson authored on 08/01/2013 11:52:44
Showing 1 changed files
... ...
@@ -270,8 +270,8 @@ int match_hash_table(struct trusted_list** table, struct sip_msg* msg,
270 270
 }
271 271
 
272 272
 
273
-/* 
274
- * Print trusted entries stored in hash table 
273
+/*! \brief
274
+ * MI Interface :: Print trusted entries stored in hash table 
275 275
  */
276 276
 int hash_table_mi_print(struct trusted_list** table, struct mi_node* rpl)
277 277
 {
... ...
@@ -296,6 +296,50 @@ int hash_table_mi_print(struct trusted_list** table, struct mi_node* rpl)
296 296
 	return 0;
297 297
 }
298 298
 
299
+/*! \brief
300
+ * RPC interface :: Print trusted entries stored in hash table 
301
+ */
302
+int hash_table_rpc_print(struct trusted_list** hash_table, rpc_t* rpc, void* c)
303
+{
304
+	int i;
305
+	struct trusted_list *np;
306
+	void* th;
307
+	void* ih;
308
+
309
+	if (rpc->add(c, "{", &th) < 0)
310
+	{
311
+		rpc->fault(c, 500, "Internal error creating rpc");
312
+		return -1;
313
+	}
314
+
315
+	for (i = 0; i < PERM_HASH_SIZE; i++) {
316
+		np = hash_table[i];
317
+		while (np) {
318
+			if(rpc->struct_add(th, "d{", 
319
+					"table", i,
320
+					"item", &ih) < 0)
321
+                        {
322
+                                rpc->fault(c, 500, "Internal error creating rpc ih");
323
+                                return -1;
324
+                        }
325
+
326
+			if(rpc->struct_add(ih, "s", "ip", np->src_ip.s) < 0)
327
+			{
328
+				rpc->fault(c, 500, "Internal error creating rpc data (ip)");
329
+				return -1;
330
+			}
331
+			if(rpc->struct_add(ih, "dss", "proto",  np->proto,
332
+						"pattern",  np->pattern ? np->pattern : "NULL",
333
+						"tag",  np->tag.len ? np->tag.s : "NULL") < 0)
334
+			{
335
+				rpc->fault(c, 500, "Internal error creating rpc data");
336
+				return -1;
337
+			}
338
+			np = np->next;
339
+		}
340
+	}
341
+	return 0;
342
+}
299 343
 
300 344
 /* 
301 345
  * Free contents of hash table, it doesn't destroy the
... ...
@@ -456,9 +500,8 @@ int find_group_in_addr_hash_table(struct addr_list** table,
456 500
 	return -1;
457 501
 }
458 502