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
deleted file mode 100644
... ...
@@ -1,547 +0,0 @@
1
-/* 
2
- * regexp and regexp substitutions implementations
3
- * 
4
- * Copyright (C) 2001-2003 FhG Fokus
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
- *
22
- */
23
-
24
-/*!
25
- * \file
26
- * \brief Kamailio core ::  regexp and regexp substitutions implementations
27
- * \ingroup core
28
- * Module: \ref core
29
- */
30
-
31
-
32
-#include "dprint.h"
33
-#include "mem/mem.h"
34
-#include "re.h"
35
-
36
-#include <string.h>
37
-
38
-#define MAX_REPLACE_WITH 100
39
-#define REPLACE_BUFFER_SIZE 1024
40
-
41
-void subst_expr_free(struct subst_expr* se)
42
-{
43
-	if (se->replacement.s) pkg_free(se->replacement.s);
44
-	if (se->re) { regfree(se->re); pkg_free(se->re); };
45
-	pkg_free(se);
46
-}
47
-
48
-
49
-
50
-/* frees the entire list, head (l) too */
51
-void replace_lst_free(struct replace_lst* l)
52
-{
53
-	struct replace_lst* t;
54
-	
55
-	while (l){
56
-		t=l;
57
-		l=l->next;
58
-		if (t->rpl.s) pkg_free(t->rpl.s);
59
-		pkg_free(t);
60
-	}
61
-}
62
-
63
-int parse_repl(struct replace_with * rw, char ** begin, 
64
-				char * end, int *max_token_nb, int with_sep)
65
-{
66
-
67
-	char* p0;
68
-	char * repl;
69
-	str s;
70
-	int token_nb;
71
-	int escape;
72
-	int max_pmatch;
73
-	char *p, c;
74
-
75
-	/* parse replacement */
76
-	p = *begin;
77
-	c = *p;
78
-	if(with_sep)
79
-		p++;
80
-	repl= p;
81
-	token_nb=0;
82
-	max_pmatch=0;
83
-	escape=0;
84
-	for(;p<end; p++){
85
-		if (escape){
86
-			escape=0;
87
-			switch (*p){
88
-				/* special char escapes */
89
-				case '\\':
90
-					rw[token_nb].size=2;
91
-					rw[token_nb].offset=(p-1)-repl;
92
-					rw[token_nb].type=REPLACE_CHAR;
93
-					rw[token_nb].u.c='\\';
94
-					break;
95
-				case 'n':
96
-					rw[token_nb].size=2;
97
-					rw[token_nb].offset=(p-1)-repl;
98
-					rw[token_nb].type=REPLACE_CHAR;
99
-					rw[token_nb].u.c='\n';
100
-					break;
101
-				case 'r':
102
-					rw[token_nb].size=2;
103
-					rw[token_nb].offset=(p-1)-repl;
104
-					rw[token_nb].type=REPLACE_CHAR;
105
-					rw[token_nb].u.c='\r';
106
-					break;
107
-				case 't':
108
-					rw[token_nb].size=2;
109
-					rw[token_nb].offset=(p-1)-repl;
110
-					rw[token_nb].type=REPLACE_CHAR;
111
-					rw[token_nb].u.c='\t';
112
-					break;
113
-				case PV_MARKER:
114
-					rw[token_nb].size=2;
115
-					rw[token_nb].offset=(p-1)-repl;
116
-					rw[token_nb].type=REPLACE_CHAR;
117
-					rw[token_nb].u.c=PV_MARKER;
118
-					break;
119
-				/* special sip msg parts escapes */
120
-				case 'u':
121
-					rw[token_nb].size=2;
122
-					rw[token_nb].offset=(p-1)-repl;
123
-					rw[token_nb].type=REPLACE_URI;
124
-					break;
125
-				/* re matches */
126
-				case '0': /* allow 0, too, reference to the whole match */
127
-				case '1':
128
-				case '2':
129
-				case '3':
130
-				case '4':
131
-				case '5':
132
-				case '6':
133
-				case '7':
134
-				case '8':
135
-				case '9':
136
-					rw[token_nb].size=2;
137
-					rw[token_nb].offset=(p-1)-repl;
138
-					rw[token_nb].type=REPLACE_NMATCH;
139
-					rw[token_nb].u.nmatch=(*p)-'0';
140
-								/* 0 is the whole matched str*/
141
-					if (max_pmatch<rw[token_nb].u.nmatch) 
142
-						max_pmatch=rw[token_nb].u.nmatch;
143
-					break;
144
-				default: /* just print current char */
145
-					if (*p!=c){
146
-						WARN("subst_parser:\\%c unknown escape in %s\n", *p, *begin);
147
-					}
148
-					rw[token_nb].size=2;
149
-					rw[token_nb].offset=(p-1)-repl;
150
-					rw[token_nb].type=REPLACE_CHAR;
151
-					rw[token_nb].u.c=*p;
152
-					break;
153
-			}
154
-
155
-			token_nb++;
156
-
157
-			if (token_nb>=MAX_REPLACE_WITH){
158
-				ERR("subst_parser: too many escapes in the replace part %s\n", *begin);
159
-				goto error;
160
-			}
161
-		}else if (*p=='\\') {
162
-			escape=1;
163
-		}else if (*p==PV_MARKER) {
164
-			s.s = p;
165
-			s.len = end - s.s;
166
-			p0 = pv_parse_spec(&s, &rw[token_nb].u.spec);
167
-			if(p0==NULL)
168
-			{
169
-				ERR("subst_parser: bad specifier in replace part %s\n", *begin);
170
-				goto error;
171
-			}
172
-			rw[token_nb].size=p0-p;
173
-			rw[token_nb].offset=p-repl;
174
-			rw[token_nb].type=REPLACE_SPEC;
175
-			token_nb++;
176
-			p=p0-1;
177
-		}else  if (*p==c && with_sep){
178
-				goto found_repl;
179
-		}
180
-	}
181
-	if(with_sep){
182
-		ERR("subst_parser: missing separator: %s\n", *begin);
183
-		goto error;
184
-	}
185
-
186
-found_repl:
187
-
188
-	*max_token_nb = max_pmatch;
189
-	*begin = p;
190
-	return token_nb;
191
-
192
-error:
193
-	return -1;
194
-}
195
-
196
-
197
-/* parse a /regular expression/replacement/flags into a subst_expr structure */
198
-struct subst_expr* subst_parser(str* subst)
199
-{
200
-	char c;
201
-	char* end;
202
-	char* p;
203
-	char* re;
204
-	char* re_end;
205
-	char* repl;
206
-	char* repl_end;
207
-	struct replace_with rw[MAX_REPLACE_WITH];
208
-	int rw_no;
209
-	int cflags; /* regcomp flags */
210
-	int replace_all;
211
-	struct subst_expr* se;
212
-	regex_t* regex;
213
-	int max_pmatch;
214
-	int r;
215
-	
216
-	/* init */
217
-	se=0;
218
-	regex=0;
219
-	cflags=REG_EXTENDED  | REG_NEWLINE; /* don't match newline */
220
-	replace_all=0;
221
-	if (subst->len<3){
222
-		LM_ERR("expression is too short: %.*s\n", subst->len, subst->s);
223
-		goto error;
224
-	}
225
-	
226
-	p=subst->s;
227
-	c=*p;
228
-	if (c=='\\'){
229
-		LM_ERR("invalid separator char <%c> in %.*s\n", c, subst->len, subst->s);
230
-		goto error;
231
-	}
232
-	p++;
233
-	end=subst->s+subst->len;
234
-	/* find re */
235
-	re=p;
236
-	for (;p<end;p++){
237
-		/* if unescaped sep. char */
238
-		if ((*p==c) && (*(p-1)!='\\')) goto found_re;
239
-	}
240
-	LM_ERR("no separator found: %.*s\n", subst->len, subst->s);
241
-	goto error;
242
-found_re:
243
-	re_end=p;
244
-	if (end < (p + 2)) {
245
-		LM_ERR("String too short\n");
246
-		goto error;
247
-	}
248
-	repl=p+1;
249
-	if ((rw_no = parse_repl(rw, &p, end, &max_pmatch, WITH_SEP)) < 0)
250
-		goto error;
251
-	repl_end = p;
252
-	p++;
253
-	
254
-	/* parse flags */
255
-	for(;p<end; p++){
256
-		switch(*p){
257
-			case 'i':
258
-				cflags|=REG_ICASE;
259
-				break;
260
-			case 's':
261
-				cflags&=(~REG_NEWLINE);
262
-				break;
263
-			case 'g':
264
-				replace_all=1;
265
-				break;
266
-			default:
267
-				LM_ERR("unknown flag %c in %.*s\n", *p, subst->len, subst->s);
268
-				goto error;
269
-		}
270
-	}
271
-
272
-	/* compile the re */
273
-	if ((regex=pkg_malloc(sizeof(regex_t)))==0){
274
-		LM_ERR("out of memory\n");
275
-		goto error;
276
-	}
277
-	c=*re_end; /* regcomp expects null terminated strings -- save */
278
-	*re_end=0;
279
-	if (regcomp(regex, re, cflags)!=0){
280
-		pkg_free(regex);
281
-		regex=0;
282
-		*re_end=c; /* restore */
283
-		LM_ERR("bad regular expression %.*s in %.*s\n",
284
-				(int)(re_end-re), re, subst->len, subst->s);
285
-		goto error;
286
-	}
287
-	*re_end=c; /* restore */
288
-	/* construct the subst_expr structure */
289
-	se=pkg_malloc(sizeof(struct subst_expr)+
290
-					((rw_no)?(rw_no-1)*sizeof(struct replace_with):0));
291
-		/* 1 replace_with structure is  already included in subst_expr */
292
-	if (se==0){
293
-		LM_ERR("out of memory\n");
294
-		goto error;
295
-	}
296
-	memset((void*)se, 0, sizeof(struct subst_expr));
297
-	se->re=regex;
298
-	se->replacement.len=repl_end-repl;
299
-	if (se->replacement.len > 0) {
300
-		if ((se->replacement.s=pkg_malloc(se->replacement.len))==0){
301
-			LM_ERR("out of memory\n");
302
-			goto error;
303
-		}
304
-		/* start copying */
305
-		memcpy(se->replacement.s, repl, se->replacement.len);
306
-	} else {
307
-		se->replacement.s = NULL;
308
-	}
309
-	se->replace_all=replace_all;
310
-	se->n_escapes=rw_no;
311
-	se->max_pmatch=max_pmatch;
312
-	for (r=0; r<rw_no; r++) se->replace[r]=rw[r];
313
-	LM_DBG("ok, se is %p\n", se);
314
-	return se;
315
-	
316
-error:
317
-	if (se) { subst_expr_free(se); regex=0; }
318
-	if (regex) { regfree (regex); pkg_free(regex); }
319
-	return 0;
320
-}
321
-
322
-/* rpl.s will be alloc'ed with the proper size & rpl.len set
323
- * returns 0 on success, <0 on error*/
324
-static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
325
-					struct subst_expr* se, struct sip_msg* msg, str* rpl)
326
-{
327
-	int r;
328
-	str* uri;
329
-	pv_value_t sv;
330
-	char* p;
331
-	char* dest;
332
-	char* end;
333
-	int size;
334
-	static char rbuf[REPLACE_BUFFER_SIZE];
335
-
336
-#define RBUF_APPEND(dst, src, size) \
337
-	if ((dst) - rbuf + (size) >= REPLACE_BUFFER_SIZE - 1) {	\
338
-		LM_ERR("Buffer too small\n");			\
339
-		goto error;											\
340
-	}														\
341
-	memcpy((dst), (src), (size));							\
342
-	(dst) += (size);
343
-
344
-	p=se->replacement.s;
345
-	end=p+se->replacement.len;
346
-	dest=rbuf;
347
-	
348
-	for (r=0; r<se->n_escapes; r++){
349
-		/* copy the unescaped parts */
350
-		size=se->replacement.s+se->replace[r].offset-p;
351
-		RBUF_APPEND(dest, p, size);
352
-		p+=size+se->replace[r].size;
353
-		switch(se->replace[r].type){
354
-			case REPLACE_NMATCH:
355
-				if ((se->replace[r].u.nmatch<nmatch)&&(
356
-						pmatch[se->replace[r].u.nmatch].rm_so!=-1)){
357
-						/* do the replace */
358
-						size=pmatch[se->replace[r].u.nmatch].rm_eo-
359
-								pmatch[se->replace[r].u.nmatch].rm_so;
360
-						RBUF_APPEND(dest, 
361
-									match+pmatch[se->replace[r].u.nmatch].rm_so,
362
-									size);
363
-				};
364
-				break;
365
-			case REPLACE_CHAR:
366
-				RBUF_APPEND(dest, &se->replace[r].u.c, 1);
367
-				break;
368
-			case REPLACE_URI:
369
-				if (msg->first_line.type!=SIP_REQUEST){
370
-					LM_CRIT("uri substitution on a reply\n");
371
-					break; /* ignore, we can continue */
372
-				}
373
-				uri= (msg->new_uri.s)?(&msg->new_uri):
374
-					(&msg->first_line.u.request.uri);
375
-				RBUF_APPEND(dest, uri->s, uri->len);
376
-				break;
377
-			case REPLACE_SPEC:
378
-				if(pv_get_spec_value(msg, &se->replace[r].u.spec, &sv)!=0) {
379
-					LM_ERR("item substitution returned error\n");
380
-					break; /* ignore, we can continue */
381
-				}
382
-				RBUF_APPEND(dest, sv.rs.s, sv.rs.len);
383
-				break;
384
-			default:
385
-				LM_CRIT("unknown type %d\n", se->replace[r].type);
386
-				/* ignore it */
387
-		}
388
-	}
389
-	RBUF_APPEND(dest, p, end-p);
390
-	rpl->len = dest - rbuf;
391
-	if ((rpl->s = pkg_malloc(rpl->len)) == NULL) {
392
-		LM_ERR("Out of pkg memory\n");
393
-		goto error;
394
-	}
395
-	memcpy(rpl->s, rbuf, rpl->len);
396
-	return 0;
397
-error:
398
-	return -1;
399
-}
400
-
401
-
402
-
403
-/* WARNING: input must be 0 terminated! */
404
-/* returns: 0 if no match or error, or subst result; if count!=0
405
- *           it will be set to 0 (no match), the number of matches
406
- *           or -1 (error).
407
- */
408
-struct replace_lst* subst_run(struct subst_expr* se, const char* input,
409
-								struct sip_msg* msg, int* count)
410
-{
411
-	struct replace_lst *head;
412
-	struct replace_lst **crt;
413
-	const char *p;
414
-	int r;
415
-	regmatch_t* pmatch;
416
-	int nmatch;
417
-	int eflags;
418
-	int cnt;
419
-	
420
-	
421
-	/* init */
422
-	head=0;
423
-	cnt=0;
424
-	crt=&head;
425
-	p=input;
426
-	nmatch=se->max_pmatch+1;
427
-	/* no of () referenced + 1 for the whole string: pmatch[0] */
428
-	pmatch=pkg_malloc(nmatch*sizeof(regmatch_t));
429
-	if (pmatch==0){
430
-		LM_ERR("out of mem\n");
431
-		goto error;
432
-	}
433
-	eflags=0;
434
-	do{
435
-		r=regexec(se->re, p, nmatch, pmatch, eflags);
436
-		LM_DBG("running. r=%d\n", r);
437
-		/* subst */
438
-		if (r==0){ /* != REG_NOMATCH */
439
-			if (pmatch[0].rm_so==-1) {
440
-				LM_ERR("Unknown offset?\n");
441
-				goto error;
442
-			}
443
-			if (pmatch[0].rm_so==pmatch[0].rm_eo) {
444
-				LM_ERR("Matched string is empty, invalid regexp?\n");
445
-				goto error;
446
-			}
447
-			*crt=pkg_malloc(sizeof(struct replace_lst));
448
-			if (*crt==0){
449
-				LM_ERR("out of mem\n");
450
-				goto error;
451
-			}
452
-			memset(*crt, 0, sizeof(struct replace_lst));
453
-			(*crt)->offset=pmatch[0].rm_so+(int)(p-input);
454
-			(*crt)->size=pmatch[0].rm_eo-pmatch[0].rm_so;
455
-			LM_DBG("matched (%d, %d): [%.*s]\n",
456
-					(*crt)->offset, (*crt)->size, 
457
-					(*crt)->size, input+(*crt)->offset);
458
-			/* create subst. string */
459
-			/* construct the string from replace[] */
460
-			if (replace_build(p, nmatch, pmatch, se, msg, &((*crt)->rpl))<0){
461
-				goto error;
462
-			}
463
-			crt=&((*crt)->next);
464
-			p+=pmatch[0].rm_eo;
465
-			if (*(p-1) == '\n' || *(p-1) == '\r') eflags&=~REG_NOTBOL;
466
-			else eflags|=REG_NOTBOL;
467
-			cnt++;
468
-		}
469
-	}while((r==0) && se->replace_all);
470
-	pkg_free(pmatch);
471
-	if (count)*count=cnt;
472
-	return head;
473
-error:
474
-	if (head) replace_lst_free(head);
475
-	if (pmatch) pkg_free(pmatch);
476
-	if (count) *count=-1;
477
-	return 0;
478
-}
479
-
480
-
481
-
482
-/* returns the substitution result in a str, input must be 0 term
483
- *  0 on no match or malloc error
484
- *  if count is non zero it will be set to the number of matches, or -1
485
- *   if error 
486
- */ 
487
-str* subst_str(const char *input, struct sip_msg* msg, struct subst_expr* se,
488
-				int* count)
489
-{
490
-	str* res;
491
-	struct replace_lst *lst;
492
-	struct replace_lst* l;
493
-	int len;
494
-	int size;
495
-	const char* p;
496
-	char* dest;
497
-	const char* end;
498
-	
499
-	
500
-	/* compute the len */
501
-	len=strlen(input);
502
-	end=input+len;
503
-	lst=subst_run(se, input, msg, count);
504
-	if (lst==0){
505
-		LM_DBG("no match\n");
506
-		return 0;
507
-	}
508
-	for (l=lst; l; l=l->next)
509
-		len+=(int)(l->rpl.len)-l->size;
510
-	res=pkg_malloc(sizeof(str));
511
-	if (res==0){
512
-		LM_ERR("mem. allocation error\n");
513
-		goto error;
514
-	}
515
-	res->s=pkg_malloc(len+1); /* space for null termination */
516
-	if (res->s==0){
517
-		LM_ERR("mem. allocation error (res->s)\n");
518
-		goto error;
519
-	}
520
-	res->s[len]=0;
521
-	res->len=len;
522
-	
523
-	/* replace */
524
-	dest=res->s;
525
-	p=input;
526
-	for(l=lst; l; l=l->next){
527
-		size=l->offset+input-p;
528
-		memcpy(dest, p, size); /* copy till offset */
529
-		p+=size + l->size; /* skip l->size bytes */
530
-		dest+=size;
531
-		if (l->rpl.len){
532
-			memcpy(dest, l->rpl.s, l->rpl.len);
533
-			dest+=l->rpl.len;
534
-		}
535
-	}
536
-	memcpy(dest, p, end-p);
537
-	if(lst) replace_lst_free(lst);
538
-	return res;
539
-error:
540
-	if (lst) replace_lst_free(lst);
541
-	if (res){
542
-		if (res->s) pkg_free(res->s);
543
-		pkg_free(res);
544
-	}
545
-	if (count) *count=-1;
546
-	return 0;
547
-}
Browse code

re.c: logging: DBG->LM_DBG

Ovidiu Sas authored on 13/01/2015 15:38:49
Showing 1 changed files
... ...
@@ -310,7 +310,7 @@ found_re:
310 310
 	se->n_escapes=rw_no;
311 311
 	se->max_pmatch=max_pmatch;
312 312
 	for (r=0; r<rw_no; r++) se->replace[r]=rw[r];
313
-	DBG("subst_parser: ok, se is %p\n", se);
313
+	LM_DBG("ok, se is %p\n", se);
314 314
 	return se;
315 315
 	
316 316
 error:
... ...
@@ -433,7 +433,7 @@ struct replace_lst* subst_run(struct subst_expr* se, const char* input,
433 433
 	eflags=0;
434 434
 	do{
435 435
 		r=regexec(se->re, p, nmatch, pmatch, eflags);
436
-		DBG("subst_run: running. r=%d\n", r);
436
+		LM_DBG("running. r=%d\n", r);
437 437
 		/* subst */
438 438
 		if (r==0){ /* != REG_NOMATCH */
439 439
 			if (pmatch[0].rm_so==-1) {
... ...
@@ -452,7 +452,7 @@ struct replace_lst* subst_run(struct subst_expr* se, const char* input,
452 452
 			memset(*crt, 0, sizeof(struct replace_lst));
453 453
 			(*crt)->offset=pmatch[0].rm_so+(int)(p-input);
454 454
 			(*crt)->size=pmatch[0].rm_eo-pmatch[0].rm_so;
455
-			DBG("subst_run: matched (%d, %d): [%.*s]\n",
455
+			LM_DBG("matched (%d, %d): [%.*s]\n",
456 456
 					(*crt)->offset, (*crt)->size, 
457 457
 					(*crt)->size, input+(*crt)->offset);
458 458
 			/* create subst. string */
... ...
@@ -502,7 +502,7 @@ str* subst_str(const char *input, struct sip_msg* msg, struct subst_expr* se,
502 502
 	end=input+len;
503 503
 	lst=subst_run(se, input, msg, count);
504 504
 	if (lst==0){
505
-		DBG("subst_str: no match\n");
505
+		LM_DBG("no match\n");
506 506
 		return 0;
507 507
 	}
508 508
 	for (l=lst; l; l=l->next)
Browse code

core Update headers, change "SIP-router" to "Kamailio", update doxygen file headers

Olle E. Johansson authored on 03/01/2015 14:15:58
Showing 1 changed files
... ...
@@ -10,11 +10,6 @@
10 10
  * the Free Software Foundation; either version 2 of the License, or
11 11
  * (at your option) any later version
12 12
  *
13
- * For a license to use the ser software under conditions
14
- * other than those described here, or to purchase support for this
15
- * software, please contact iptel.org by e-mail at the following addresses:
16
- *    info@iptel.org
17
- *
18 13
  * Kamailio is distributed in the hope that it will be useful,
19 14
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -1,13 +1,11 @@
1 1
 /* 
2
- * $Id$
3
- *
4 2
  * regexp and regexp substitutions implementations
5 3
  * 
6 4
  * Copyright (C) 2001-2003 FhG Fokus
7 5
  *
8
- * This file is part of ser, a free SIP server.
6
+ * This file is part of Kamailio, a free SIP server.
9 7
  *
10
- * ser is free software; you can redistribute it and/or modify
8
+ * Kamailio is free software; you can redistribute it and/or modify
11 9
  * it under the terms of the GNU General Public License as published by
12 10
  * the Free Software Foundation; either version 2 of the License, or
13 11
  * (at your option) any later version
... ...
@@ -17,7 +15,7 @@
17 15
  * software, please contact iptel.org by e-mail at the following addresses:
18 16
  *    info@iptel.org
19 17
  *
20
- * ser is distributed in the hope that it will be useful,
18
+ * Kamailio is distributed in the hope that it will be useful,
21 19
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 20
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 21
  * GNU General Public License for more details.
... ...
@@ -26,16 +24,11 @@
26 24
  * along with this program; if not, write to the Free Software 
27 25
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
28 26
  *
29
- *
30
- * History:
31
- * --------
32
- *   2003-08-04  created by andrei
33
- *   2004-11-12  minor api extension, added *count (andrei)
34 27
  */
35 28
 
36 29
 /*!
37 30
  * \file
38
- * \brief SIP-router core ::  regexp and regexp substitutions implementations
31
+ * \brief Kamailio core ::  regexp and regexp substitutions implementations
39 32
  * \ingroup core
40 33
  * Module: \ref core
41 34
  */
Browse code

re.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 04/10/2014 00:56:28
Showing 1 changed files
... ...
@@ -231,16 +231,14 @@ struct subst_expr* subst_parser(str* subst)
231 231
 	cflags=REG_EXTENDED  | REG_NEWLINE; /* don't match newline */
232 232
 	replace_all=0;
233 233
 	if (subst->len<3){
234
-		LOG(L_ERR, "ERROR: subst_parser: expression is too short: %.*s\n",
235
-				subst->len, subst->s);
234
+		LM_ERR("expression is too short: %.*s\n", subst->len, subst->s);
236 235
 		goto error;
237 236
 	}
238 237
 	
239 238
 	p=subst->s;
240 239
 	c=*p;
241 240
 	if (c=='\\'){
242
-		LOG(L_ERR, "ERROR: subst_parser: invalid separator char <%c>"
243
-				" in %.*s\n", c, subst->len, subst->s);
241
+		LM_ERR("invalid separator char <%c> in %.*s\n", c, subst->len, subst->s);
244 242
 		goto error;
245 243
 	}
246 244
 	p++;
... ...
@@ -251,13 +249,12 @@ struct subst_expr* subst_parser(str* subst)
251 249
 		/* if unescaped sep. char */
252 250
 		if ((*p==c) && (*(p-1)!='\\')) goto found_re;
253 251
 	}
254
-	LOG(L_ERR, "ERROR: subst_parser: no separator found: %.*s\n", subst->len, 
255
-			subst->s);
252
+	LM_ERR("no separator found: %.*s\n", subst->len, subst->s);
256 253
 	goto error;
257 254
 found_re:
258 255
 	re_end=p;
259 256
 	if (end < (p + 2)) {
260
-		ERR("subst_parser: String too short\n");
257
+		LM_ERR("String too short\n");
261 258
 		goto error;
262 259
 	}
263 260
 	repl=p+1;
... ...
@@ -279,15 +276,14 @@ found_re:
279 276
 				replace_all=1;
280 277
 				break;
281 278
 			default:
282
-				LOG(L_ERR, "ERROR: subst_parser: unknown flag %c in %.*s\n",
283
-						*p, subst->len, subst->s);
279
+				LM_ERR("unknown flag %c in %.*s\n", *p, subst->len, subst->s);
284 280
 				goto error;
285 281
 		}
286 282
 	}
287 283
 
288 284
 	/* compile the re */
289 285
 	if ((regex=pkg_malloc(sizeof(regex_t)))==0){
290
-		LOG(L_ERR, "ERROR: subst_parser: out of memory (re)\n");
286
+		LM_ERR("out of memory\n");
291 287
 		goto error;
292 288
 	}
293 289
 	c=*re_end; /* regcomp expects null terminated strings -- save */
... ...
@@ -296,8 +292,8 @@ found_re:
296 292
 		pkg_free(regex);
297 293
 		regex=0;
298 294
 		*re_end=c; /* restore */
299
-		LOG(L_ERR, "ERROR: subst_parser: bad regular expression %.*s in "
300
-				"%.*s\n", (int)(re_end-re), re, subst->len, subst->s);
295
+		LM_ERR("bad regular expression %.*s in %.*s\n",
296
+				(int)(re_end-re), re, subst->len, subst->s);
301 297
 		goto error;
302 298
 	}
303 299
 	*re_end=c; /* restore */
... ...
@@ -306,7 +302,7 @@ found_re:
306 302
 					((rw_no)?(rw_no-1)*sizeof(struct replace_with):0));
307 303
 		/* 1 replace_with structure is  already included in subst_expr */
308 304
 	if (se==0){
309
-		LOG(L_ERR, "ERROR: subst_parser: out of memory (subst_expr)\n");
305
+		LM_ERR("out of memory\n");
310 306
 		goto error;
311 307
 	}
312 308
 	memset((void*)se, 0, sizeof(struct subst_expr));
... ...
@@ -314,7 +310,7 @@ found_re:
314 310
 	se->replacement.len=repl_end-repl;
315 311
 	if (se->replacement.len > 0) {
316 312
 		if ((se->replacement.s=pkg_malloc(se->replacement.len))==0){
317
-			LOG(L_ERR, "ERROR: subst_parser: out of memory (replacement)\n");
313
+			LM_ERR("out of memory\n");
318 314
 			goto error;
319 315
 		}
320 316
 		/* start copying */
... ...
@@ -351,7 +347,7 @@ static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
351 347
 
352 348
 #define RBUF_APPEND(dst, src, size) \
353 349
 	if ((dst) - rbuf + (size) >= REPLACE_BUFFER_SIZE - 1) {	\
354
-		ERR("replace_build: Buffer too small\n");			\
350
+		LM_ERR("Buffer too small\n");			\
355 351
 		goto error;											\
356 352
 	}														\
357 353
 	memcpy((dst), (src), (size));							\
... ...
@@ -383,8 +379,7 @@ static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
383 379
 				break;
384 380
 			case REPLACE_URI:
385 381
 				if (msg->first_line.type!=SIP_REQUEST){
386
-					LOG(L_CRIT, "BUG: replace_build: uri substitution on"
387
-								" a reply\n");
382
+					LM_CRIT("uri substitution on a reply\n");
388 383
 					break; /* ignore, we can continue */
389 384
 				}
390 385
 				uri= (msg->new_uri.s)?(&msg->new_uri):
... ...
@@ -393,21 +388,20 @@ static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
393 388
 				break;
394 389
 			case REPLACE_SPEC:
395 390
 				if(pv_get_spec_value(msg, &se->replace[r].u.spec, &sv)!=0) {
396
-					ERR("replace_build: item substitution returned error\n");
391
+					LM_ERR("item substitution returned error\n");
397 392
 					break; /* ignore, we can continue */
398 393
 				}
399 394
 				RBUF_APPEND(dest, sv.rs.s, sv.rs.len);
400 395
 				break;
401 396
 			default:
402
-				LOG(L_CRIT, "BUG: replace_build: unknown type %d\n", 
403
-						se->replace[r].type);
397
+				LM_CRIT("unknown type %d\n", se->replace[r].type);
404 398
 				/* ignore it */
405 399
 		}
406 400
 	}
407 401
 	RBUF_APPEND(dest, p, end-p);
408 402
 	rpl->len = dest - rbuf;
409 403
 	if ((rpl->s = pkg_malloc(rpl->len)) == NULL) {
410
-		ERR("replace_build: Out of pkg memory\n");
404
+		LM_ERR("Out of pkg memory\n");
411 405
 		goto error;
412 406
 	}
413 407
 	memcpy(rpl->s, rbuf, rpl->len);
... ...
@@ -445,7 +439,7 @@ struct replace_lst* subst_run(struct subst_expr* se, const char* input,
445 439
 	/* no of () referenced + 1 for the whole string: pmatch[0] */
446 440
 	pmatch=pkg_malloc(nmatch*sizeof(regmatch_t));
447 441
 	if (pmatch==0){
448
-		LOG(L_ERR, "ERROR: subst_run_ out of mem. (pmatch)\n");
442
+		LM_ERR("out of mem\n");
449 443
 		goto error;
450 444
 	}
451 445
 	eflags=0;
... ...
@@ -455,16 +449,16 @@ struct replace_lst* subst_run(struct subst_expr* se, const char* input,
455 449
 		/* subst */
456 450
 		if (r==0){ /* != REG_NOMATCH */
457 451
 			if (pmatch[0].rm_so==-1) {
458
-				ERR("subst_run: Unknown offset?\n");
452
+				LM_ERR("Unknown offset?\n");
459 453
 				goto error;
460 454
 			}
461 455
 			if (pmatch[0].rm_so==pmatch[0].rm_eo) {
462
-				ERR("subst_run: Matched string is empty, invalid regexp?\n");
456
+				LM_ERR("Matched string is empty, invalid regexp?\n");
463 457
 				goto error;
464 458
 			}
465 459
 			*crt=pkg_malloc(sizeof(struct replace_lst));
466 460
 			if (*crt==0){
467
-				LOG(L_ERR, "ERROR: subst_run: out of mem (crt)\n");
461
+				LM_ERR("out of mem\n");
468 462
 				goto error;
469 463
 			}
470 464
 			memset(*crt, 0, sizeof(struct replace_lst));
... ...
@@ -527,12 +521,12 @@ str* subst_str(const char *input, struct sip_msg* msg, struct subst_expr* se,
527 521
 		len+=(int)(l->rpl.len)-l->size;
528 522
 	res=pkg_malloc(sizeof(str));
529 523
 	if (res==0){
530
-		LOG(L_ERR, "ERROR: subst_str: mem. allocation error\n");
524
+		LM_ERR("mem. allocation error\n");
531 525
 		goto error;
532 526
 	}
533 527
 	res->s=pkg_malloc(len+1); /* space for null termination */
534 528
 	if (res->s==0){
535
-		LOG(L_ERR, "ERROR: subst_str: mem. allocation error (res->s)\n");
529
+		LM_ERR("mem. allocation error (res->s)\n");
536 530
 		goto error;
537 531
 	}
538 532
 	res->s[len]=0;
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -24,7 +24,7 @@
24 24
  *
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
28 28
  *
29 29
  *
30 30
  * History:
Browse code

core: link regex before replacement field allocation can fail

- regex will be freed properly if there was an error for replacement

Daniel-Constantin Mierla authored on 21/04/2014 15:56:01
Showing 1 changed files
... ...
@@ -310,6 +310,7 @@ found_re:
310 310
 		goto error;
311 311
 	}
312 312
 	memset((void*)se, 0, sizeof(struct subst_expr));
313
+	se->re=regex;
313 314
 	se->replacement.len=repl_end-repl;
314 315
 	if (se->replacement.len > 0) {
315 316
 		if ((se->replacement.s=pkg_malloc(se->replacement.len))==0){
... ...
@@ -321,7 +322,6 @@ found_re:
321 322
 	} else {
322 323
 		se->replacement.s = NULL;
323 324
 	}
324
-	se->re=regex;
325 325
 	se->replace_all=replace_all;
326 326
 	se->n_escapes=rw_no;
327 327
 	se->max_pmatch=max_pmatch;
Browse code

Adding doxygen template to all core .c files

Please fill in after the :: to explain the function of this file.

oej authored on 10/10/2009 13:54:13
Showing 1 changed files
... ...
@@ -33,6 +33,13 @@
33 33
  *   2004-11-12  minor api extension, added *count (andrei)
34 34
  */
35 35
 
36
+/*!
37
+ * \file
38
+ * \brief SIP-router core ::  regexp and regexp substitutions implementations
39
+ * \ingroup core
40
+ * Module: \ref core
41
+ */
42
+
36 43
 
37 44
 #include "dprint.h"
38 45
 #include "mem/mem.h"
Browse code

Remove function replace_len which is no longer needed.

This function was originally used to calculate the size of the memory
buffer in replace_build for the resulting string. Since we now print
the result into a static buffer, this function is no longer needed.

Jan Janak authored on 08/03/2009 03:42:10
Showing 1 changed files
... ...
@@ -328,52 +328,6 @@ error:
328 328
 	return 0;
329 329
 }
330 330
 
331
-
332
-
333
-static int replace_len(const char* match, int nmatch, regmatch_t* pmatch,
334
-					struct subst_expr* se, struct sip_msg* msg)
335
-{
336
-	int r;
337
-	int len;
338
-	str* uri;
339
-	
340
-	len=se->replacement.len;
341
-	for (r=0; r<se->n_escapes; r++){
342
-		switch(se->replace[r].type){
343
-			case REPLACE_NMATCH:
344
-				len-=se->replace[r].size;
345
-				if ((se->replace[r].u.nmatch<nmatch)&&(
346
-						pmatch[se->replace[r].u.nmatch].rm_so!=-1)){
347
-						/* do the replace */
348
-						len+=pmatch[se->replace[r].u.nmatch].rm_eo-
349
-								pmatch[se->replace[r].u.nmatch].rm_so;
350
-				};
351
-				break;
352
-			case REPLACE_CHAR:
353
-				len-=(se->replace[r].size-1);
354
-				break;
355
-			case REPLACE_URI:
356
-				len-=se->replace[r].size;
357
-				if (msg->first_line.type!=SIP_REQUEST){
358
-					LOG(L_CRIT, "BUG: replace_len: uri substitution on"
359
-								" a reply\n");
360
-					break; /* ignore, we can continue */
361
-				}
362
-				uri= (msg->new_uri.s)?(&msg->new_uri):
363
-					(&msg->first_line.u.request.uri);
364
-				len+=uri->len;
365
-				break;
366
-			default:
367
-				LOG(L_CRIT, "BUG: replace_len: unknown type %d\n", 
368
-						se->replace[r].type);
369
-				/* ignore it */
370
-		}
371
-	}
372
-	return len;
373
-}
374
-
375
-
376
-
377 331
 /* rpl.s will be alloc'ed with the proper size & rpl.len set
378 332
  * returns 0 on success, <0 on error*/
379 333
 static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
Browse code

Kamailio compatibility changes: replace_build

List of changes:
* Add support for pseudo variables
* Create a static buffer allocated on the stack that will be used to
print the resulting string, we no longer can determine the final
size of the result in advance because of pseudo-variable support and
thus we print to a fixed-size buffer and copy the result into a
dynamically allocated buffer when done.
* Define macro RBUF_APPEND which is used to add text to the static
buffer, the macro checks if there is enough space in the buffer
before each write
* Remove the call to replace_len at the beginning of the function
* Replace all occurrences of memcpy(...) and dest+=... with
RBUF_APPEND
* At the end create a dynamically allocated buffer for the result and
copy the string from the static buffer into the dynamic buffer.

Jan Janak authored on 08/03/2009 03:40:13
Showing 1 changed files
... ...
@@ -381,30 +381,30 @@ static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
381 381
 {