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,152 +0,0 @@
1
-/*
2
- * $Id$
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
- * 
22
- * History:
23
- * ----------
24
- * 2003-02-28 scratchpad compatibility abandoned (jiri)
25
- * 2002-01-28 scratchpad removed (jiri)
26
- * 2004-08-15 max value of max-fwd header is configurable (bogdan)
27
- * 2005-11-03 MF value saved in msg->maxforwards->parsed (bogdan)
28
- */
29
-
30
-
31
-#include <stdlib.h>
32
-#include <string.h>
33
-
34
-#include "mf_funcs.h"
35
-#include "../../mem/mem.h"
36
-#include "../../ut.h"
37
-#include "../../data_lump.h"
38
-
39
-
40
-#define MF_HDR "Max-Forwards: "
41
-#define MF_HDR_LEN (sizeof(MF_HDR) - 1)
42
-
43
-/* do a tricky thing and keep the parsed value of MAXFWD hdr incremented 
44
- * by one in order to make difference between 0 (not set)
45
- * and 0 (zero value) - bogdan */
46
-#define IS_MAXWD_STORED(_msg_) \
47
-	((_msg_)->maxforwards->parsed)
48
-#define STORE_MAXWD_VAL(_msg_,_val_) \
49
-	(_msg_)->maxforwards->parsed = ((void*)(long)((_val_)+1))
50
-#define FETCH_MAXWD_VAL(_msg_) \
51
-	(((int)(long)(_msg_)->maxforwards->parsed)-1)
52
-
53
-/* looks for the MAX FORWARDS header
54
-   returns its value, -1 if is not present or -2 for error */
55
-int is_maxfwd_present( struct sip_msg* msg , str *foo)
56
-{
57
-	int x, err;
58
-
59
-	/* lookup into the message for MAX FORWARDS header*/
60
-	if ( !msg->maxforwards ) {
61
-		if  ( parse_headers( msg , HDR_MAXFORWARDS_F, 0 )==-1 ){
62
-			LM_ERR("parsing MAX_FORWARD header failed!\n");
63
-			return -2;
64
-		}
65
-		if (!msg->maxforwards) {
66
-			LM_DBG("max_forwards header not found!\n");
67
-			return -1;
68
-		}
69
-	} else if (IS_MAXWD_STORED(msg)) {
70
-		trim_len( foo->len , foo->s , msg->maxforwards->body );
71
-		return FETCH_MAXWD_VAL(msg);
72
-	}
73
-
74
-	/* if header is present, trim to get only the string containing numbers */
75
-	trim_len( foo->len , foo->s , msg->maxforwards->body );
76
-
77
-	/* convert from string to number */
78
-	x = str2s( foo->s,foo->len,&err);
79
-	if (err){
80
-		LM_ERR("unable to parse the max forwards number\n");
81
-		return -2;
82
-	}
83
-	/* store the parsed values */
84
-	STORE_MAXWD_VAL(msg, x);
85
-	LM_DBG("value = %d \n",x);
86
-	return x;
87
-}
88
-
89
-
90
-
91
-int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
92
-{
93
-	int i;
94
-
95
-	/* decrement the value */
96
-	x--;
97
-
98
-	/* update the stored value */
99
-	STORE_MAXWD_VAL(msg, x);
100
-
101
-	/*rewriting the max-fwd value in the message (buf and orig)*/
102
-	for(i = s->len - 1; i >= 0; i--) {
103
-		s->s[i] = (x % 10) + '0';
104
-		x /= 10;
105
-		if (x==0) {
106
-			i = i - 1;
107
-			break;
108
-		}
109
-	}
110
-	while(i >= 0) s->s[i--] = ' ';
111
-
112
-	return 0;
113
-}
114
-
115
-int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
116
-{
117
-	unsigned int  len;
118
-	char          *buf;
119
-	struct lump*  anchor;
120
-
121
-	/* constructing the header */
122
-	len = MF_HDR_LEN /*"MAX-FORWARDS: "*/+ CRLF_LEN + 3/*val max on 3 digits*/;
123
-
124
-	buf = (char*)pkg_malloc( len );
125
-	if (!buf) {
126
-		LM_ERR("add_maxfwd_header: no more pkg memory\n");
127
-		goto error;
128
-	}
129
-	memcpy( buf , MF_HDR, MF_HDR_LEN );
130
-	len = MF_HDR_LEN ;
131
-	len += btostr( buf+len , val );
132
-	memcpy( buf+len , CRLF , CRLF_LEN );
133
-	len +=CRLF_LEN;
134
-
135
-	/*inserts the header at the beginning of the message*/
136
-	anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0 , 0);
137
-	if (anchor == 0) {
138
-		LM_ERR("add_maxfwd_header: failed to get anchor\n");
139
-		goto error1;
140
-	}
141
-
142
-	if (insert_new_lump_before(anchor, buf, len, 0) == 0) {
143
-		LM_ERR("add_maxfwd_header: failed to insert MAX-FORWARDS lump\n");
144
-		goto error1;
145
-	}
146
-
147
-	return 0;
148
-error1:
149
-	pkg_free( buf );
150
-error:
151
-	return -1;
152
-}
Browse code

maxfwd(k): max_limit module param can be changed at runtime

- changed to use cfg param reload framework
- added aliases to existing functions to make them compatible with ser
flavour
- config functions can take variables as parameters

Daniel-Constantin Mierla authored on 21/12/2012 21:43:54
Showing 1 changed files
... ...
@@ -51,7 +51,7 @@
51 51
 	(((int)(long)(_msg_)->maxforwards->parsed)-1)
52 52
 
53 53
 /* looks for the MAX FORWARDS header
54
-   returns the its value, -1 if is not present or -2 for error */
54
+   returns its value, -1 if is not present or -2 for error */
55 55
 int is_maxfwd_present( struct sip_msg* msg , str *foo)
56 56
 {
57 57
 	int x, err;
Browse code

Delete btostr function which is already defined in ut.h

Jan Janak authored on 03/03/2009 16:25:44
Showing 1 changed files
... ...
@@ -112,19 +112,6 @@ int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
112 112
 	return 0;
113 113
 }
114 114
 
115
-static inline int btostr( char *p,  unsigned char val)
116
-{
117
-	unsigned int a,b,i =0;
118
-
119
-	if ( (a=val/100)!=0 )
120
-		*(p+(i++)) = a+'0';         /*first digit*/
121
-	if ( (b=val%100/10)!=0 || a)
122
-		*(p+(i++)) = b+'0';        /*second digit*/
123
-	*(p+(i++)) = '0'+val%10;              /*third digit*/
124
-
125
-	return i;
126
-}
127
-
128 115
 int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
129 116
 {
130 117
 	unsigned int  len;
Browse code

- port from opensips (#4939), credits to Bogdan - fixed bug in decrementing the max_forward value: The issue occurs when calling 'mf_process_maxfwd_header' or 'is_maxfwd_lt' script functions more than once within a single script execution. The second occurrence always returns as if the max forward header value has reached zero due to an issue with the temporary value (max forwards count) stored by the module being overwritten with zero during an int to string conversion - fixed internal link corruption when 'mf_process_maxfwd_header' is used more than once in the script.

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5252 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 24/11/2008 17:50:16
Showing 1 changed files
... ...
@@ -67,6 +67,7 @@ int is_maxfwd_present( struct sip_msg* msg , str *foo)
67 67
 			return -1;
68 68
 		}
69 69
 	} else if (IS_MAXWD_STORED(msg)) {
70
+		trim_len( foo->len , foo->s , msg->maxforwards->body );
70 71
 		return FETCH_MAXWD_VAL(msg);
71 72
 	}
72 73
 
... ...
@@ -91,8 +92,13 @@ int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
91 92
 {
92 93
 	int i;
93 94
 
94
-	/*rewriting the max-fwd value in the message (buf and orig)*/
95
+	/* decrement the value */
95 96
 	x--;
97
+
98
+	/* update the stored value */
99
+	STORE_MAXWD_VAL(msg, x);
100
+
101
+	/*rewriting the max-fwd value in the message (buf and orig)*/
96 102
 	for(i = s->len - 1; i >= 0; i--) {
97 103
 		s->s[i] = (x % 10) + '0';
98 104
 		x /= 10;
... ...
@@ -103,9 +109,6 @@ int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
103 109
 	}
104 110
 	while(i >= 0) s->s[i--] = ' ';
105 111
 
106
-	/* update the stored value */
107
-	STORE_MAXWD_VAL(msg, x);
108
-
109 112
 	return 0;
110 113
 }
111 114
 
Browse code

- remove one (commented out) NOTICE log from seed_child - move btostr function into maxfwd module, this is only used here, no need to copy this into every file that include ut.h

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4891 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 11/09/2008 17:09:28
Showing 1 changed files
... ...
@@ -109,7 +109,18 @@ int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
109 109
 	return 0;
110 110
 }
111 111
 
112
+static inline int btostr( char *p,  unsigned char val)
113
+{
114
+	unsigned int a,b,i =0;
115
+
116
+	if ( (a=val/100)!=0 )
117
+		*(p+(i++)) = a+'0';         /*first digit*/
118
+	if ( (b=val%100/10)!=0 || a)
119
+		*(p+(i++)) = b+'0';        /*second digit*/
120
+	*(p+(i++)) = '0'+val%10;              /*third digit*/
112 121
 
122
+	return i;
123
+}
113 124
 
114 125
 int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
115 126
 {
Browse code

- change name in copyright headers

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4518 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 28/07/2008 15:39:28
Showing 1 changed files
... ...
@@ -3,14 +3,14 @@
3 3
  *
4 4
  * Copyright (C) 2001-2003 FhG Fokus
5 5
  *
6
- * This file is part of openser, a free SIP server.
6
+ * This file is part of Kamailio, a free SIP server.
7 7
  *
8
- * openser is free software; you can redistribute it and/or modify
8
+ * Kamailio is free software; you can redistribute it and/or modify
9 9
  * it under the terms of the GNU General Public License as published by
10 10
  * the Free Software Foundation; either version 2 of the License, or
11 11
  * (at your option) any later version
12 12
  *
13
- * openser is distributed in the hope that it will be useful,
13
+ * Kamailio is distributed in the hope that it will be useful,
14 14
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
Browse code

- removed the function name from the log message (it will by automatically added by the new logging system)

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2483 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 19/07/2007 13:01:03
Showing 1 changed files
... ...
@@ -59,11 +59,11 @@ int is_maxfwd_present( struct sip_msg* msg , str *foo)
59 59
 	/* lookup into the message for MAX FORWARDS header*/
60 60
 	if ( !msg->maxforwards ) {
61 61
 		if  ( parse_headers( msg , HDR_MAXFORWARDS_F, 0 )==-1 ){
62
-			LM_ERR("is_maxfwd_present: parsing MAX_FORWARD header failed!\n");
62
+			LM_ERR("parsing MAX_FORWARD header failed!\n");
63 63
 			return -2;
64 64
 		}
65 65
 		if (!msg->maxforwards) {
66
-			LM_DBG("is_maxfwd_present: max_forwards header not found!\n");
66
+			LM_DBG("max_forwards header not found!\n");
67 67
 			return -1;
68 68
 		}
69 69
 	} else if (IS_MAXWD_STORED(msg)) {
... ...
@@ -76,12 +76,12 @@ int is_maxfwd_present( struct sip_msg* msg , str *foo)
76 76
 	/* convert from string to number */
77 77
 	x = str2s( foo->s,foo->len,&err);
78 78
 	if (err){
79
-		LM_ERR("is_maxfwd_present: unable to parse the max forwards number\n");
79
+		LM_ERR("unable to parse the max forwards number\n");
80 80
 		return -2;
81 81
 	}
82 82
 	/* store the parsed values */
83 83
 	STORE_MAXWD_VAL(msg, x);
84
-	LM_DBG("is_maxfwd_present: value = %d \n",x);
84
+	LM_DBG("value = %d \n",x);
85 85
 	return x;
86 86
 }
87 87
 
Browse code

- all log messages ported to the new set of macros

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2461 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 16/07/2007 20:06:19
Showing 1 changed files
... ...
@@ -59,12 +59,11 @@ int is_maxfwd_present( struct sip_msg* msg , str *foo)
59 59
 	/* lookup into the message for MAX FORWARDS header*/
60 60
 	if ( !msg->maxforwards ) {
61 61
 		if  ( parse_headers( msg , HDR_MAXFORWARDS_F, 0 )==-1 ){
62
-			LOG( L_ERR , "ERROR:maxfwd:is_maxfwd_present :"
63
-				" parsing MAX_FORWARD header failed!\n");
62
+			LM_ERR("is_maxfwd_present: parsing MAX_FORWARD header failed!\n");
64 63
 			return -2;
65 64
 		}
66 65
 		if (!msg->maxforwards) {
67
-			DBG("DEBUG: is_maxfwd_present: max_forwards header not found!\n");
66
+			LM_DBG("is_maxfwd_present: max_forwards header not found!\n");
68 67
 			return -1;
69 68
 		}
70 69
 	} else if (IS_MAXWD_STORED(msg)) {
... ...
@@ -77,13 +76,12 @@ int is_maxfwd_present( struct sip_msg* msg , str *foo)
77 76
 	/* convert from string to number */
78 77
 	x = str2s( foo->s,foo->len,&err);
79 78
 	if (err){
80
-		LOG(L_ERR, "ERROR:maxfwd:is_maxfwd_present:"
81
-			" unable to parse the max forwards number !\n");
79
+		LM_ERR("is_maxfwd_present: unable to parse the max forwards number\n");
82 80
 		return -2;
83 81
 	}
84 82
 	/* store the parsed values */
85 83
 	STORE_MAXWD_VAL(msg, x);
86
-	DBG("DEBUG:maxfwd:is_maxfwd_present: value = %d \n",x);
84
+	LM_DBG("is_maxfwd_present: value = %d \n",x);
87 85
 	return x;
88 86
 }
89 87
 
... ...
@@ -124,7 +122,7 @@ int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
124 122
 
125 123
 	buf = (char*)pkg_malloc( len );
126 124
 	if (!buf) {
127
-		LOG(L_ERR, "ERROR:maxfwd:add_maxfwd_header: no more pkg memory\n");
125
+		LM_ERR("add_maxfwd_header: no more pkg memory\n");
128 126
 		goto error;
129 127
 	}
130 128
 	memcpy( buf , MF_HDR, MF_HDR_LEN );
... ...
@@ -136,13 +134,12 @@ int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
136 134
 	/*inserts the header at the beginning of the message*/
137 135
 	anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0 , 0);
138 136
 	if (anchor == 0) {
139
-		LOG(L_ERR, "ERROR:maxfwd:add_maxfwd_header: failed to get anchor\n");
137
+		LM_ERR("add_maxfwd_header: failed to get anchor\n");
140 138
 		goto error1;
141 139
 	}
142 140
 
143 141
 	if (insert_new_lump_before(anchor, buf, len, 0) == 0) {
144
-		LOG(L_ERR, "ERROR:maxfwd:add_maxfwd_header: failed to insert "
145
-			"MAX-FORWARDS lump\n");
142
+		LM_ERR("add_maxfwd_header: failed to insert MAX-FORWARDS lump\n");
146 143
 		goto error1;
147 144
 	}
148 145
 
Browse code

- bogus brakets fixed

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1393 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 13/12/2006 18:11:07
Showing 1 changed files
... ...
@@ -46,7 +46,7 @@
46 46
 #define IS_MAXWD_STORED(_msg_) \
47 47
 	((_msg_)->maxforwards->parsed)
48 48
 #define STORE_MAXWD_VAL(_msg_,_val_) \
49
-	(_msg_)->maxforwards->parsed = ((void*)(long)(_val_)+1)
49
+	(_msg_)->maxforwards->parsed = ((void*)(long)((_val_)+1))
50 50
 #define FETCH_MAXWD_VAL(_msg_) \
51 51
 	(((int)(long)(_msg_)->maxforwards->parsed)-1)
52 52
 
Browse code

- better error reporting for mf_process_maxfwd_header() - improvement: store MF value in parsed structure for later usage - new function is_maxfwd_lt() added

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@362 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 03/11/2005 16:27:21
Showing 1 changed files
... ...
@@ -24,6 +24,7 @@
24 24
  * 2003-02-28 scratchpad compatibility abandoned (jiri)
25 25
  * 2002-01-28 scratchpad removed (jiri)
26 26
  * 2004-08-15 max value of max-fwd header is configurable (bogdan)
27
+ * 2005-11-03 MF value saved in msg->maxforwards->parsed (bogdan)
27 28
  */
28 29
 
29 30
 
... ...
@@ -39,6 +40,15 @@
39 40
 #define MF_HDR "Max-Forwards: "
40 41
 #define MF_HDR_LEN (sizeof(MF_HDR) - 1)
41 42
 
43
+/* do a tricky thing and keep the parsed value of MAXFWD hdr incremented 
44
+ * by one in order to make difference between 0 (not set)
45
+ * and 0 (zero value) - bogdan */
46
+#define IS_MAXWD_STORED(_msg_) \
47
+	((_msg_)->maxforwards->parsed)
48
+#define STORE_MAXWD_VAL(_msg_,_val_) \
49
+	(_msg_)->maxforwards->parsed = ((void*)(long)(_val_)+1)
50
+#define FETCH_MAXWD_VAL(_msg_) \
51
+	(((int)(long)(_msg_)->maxforwards->parsed)-1)
42 52
 
43 53
 /* looks for the MAX FORWARDS header
44 54
    returns the its value, -1 if is not present or -2 for error */
... ...
@@ -57,6 +67,8 @@ int is_maxfwd_present( struct sip_msg* msg , str *foo)
57 67
 			DBG("DEBUG: is_maxfwd_present: max_forwards header not found!\n");
58 68
 			return -1;
59 69
 		}
70
+	} else if (IS_MAXWD_STORED(msg)) {
71
+		return FETCH_MAXWD_VAL(msg);
60 72
 	}
61 73
 
62 74
 	/* if header is present, trim to get only the string containing numbers */
... ...
@@ -69,6 +81,8 @@ int is_maxfwd_present( struct sip_msg* msg , str *foo)
69 81
 			" unable to parse the max forwards number !\n");
70 82
 		return -2;
71 83
 	}
84
+	/* store the parsed values */
85
+	STORE_MAXWD_VAL(msg, x);
72 86
 	DBG("DEBUG:maxfwd:is_maxfwd_present: value = %d \n",x);
73 87
 	return x;
74 88
 }
... ...
@@ -91,7 +105,10 @@ int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
91 105
 	}
92 106
 	while(i >= 0) s->s[i--] = ' ';
93 107
 
94
-	return 1;
108
+	/* update the stored value */
109
+	STORE_MAXWD_VAL(msg, x);
110
+
111
+	return 0;
95 112
 }
96 113
 
97 114
 
... ...
@@ -129,8 +146,7 @@ int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
129 146
 		goto error1;
130 147
 	}
131 148
 
132
-	return 1;
133
-
149
+	return 0;
134 150
 error1:
135 151
 	pkg_free( buf );
136 152
 error:
Browse code

fixups and cleanup: - max_limit of MAX-FORWARDS cannot exceed 256 (as per RFC) - proper checks (as range) for the module and function params - useless checks removed

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@268 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 15/09/2005 10:32:49
Showing 1 changed files
... ...
@@ -75,18 +75,10 @@ int is_maxfwd_present( struct sip_msg* msg , str *foo)
75 75
 
76 76
 
77 77
 
78
-
79 78
 int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
80 79
 {
81 80
 	int i;
82 81
 
83
-	/* double check */
84
-	if ( !msg->maxforwards ) {
85
-		LOG( L_ERR , "ERROR: decrement_maxfwd :"
86
-			" MAX_FORWARDS header not found !\n");
87
-		goto error;
88
-	}
89
-
90 82
 	/*rewriting the max-fwd value in the message (buf and orig)*/
91 83
 	x--;
92 84
 	for(i = s->len - 1; i >= 0; i--) {
... ...
@@ -100,33 +92,23 @@ int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
100 92
 	while(i >= 0) s->s[i--] = ' ';
101 93
 
102 94
 	return 1;
103
-error:
104
-	return -1;
105 95
 }
106 96
 
107 97
 
108 98
 
109
-
110 99
 int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
111 100
 {
112 101
 	unsigned int  len;
113 102
 	char          *buf;
114 103
 	struct lump*  anchor;
115 104
 
116
-	/* double check just to be sure */
117
-	if ( msg->maxforwards ) {
118
-		LOG( L_ERR , "ERROR: add_maxfwd_header :"
119
-			" MAX_FORWARDS header already exists (%p) !\n",msg->maxforwards);
120
-		goto error;
121
-	}
122
-
123 105
 	/* constructing the header */
124 106
 	len = MF_HDR_LEN /*"MAX-FORWARDS: "*/+ CRLF_LEN + 3/*val max on 3 digits*/;
125 107
 
126 108
 	buf = (char*)pkg_malloc( len );
127 109
 	if (!buf) {
128
-		LOG(L_ERR, "ERROR : add_maxfwd_header : No memory left\n");
129
-		return -1;
110
+		LOG(L_ERR, "ERROR:maxfwd:add_maxfwd_header: no more pkg memory\n");
111
+		goto error;
130 112
 	}
131 113
 	memcpy( buf , MF_HDR, MF_HDR_LEN );
132 114
 	len = MF_HDR_LEN ;
... ...
@@ -137,14 +119,13 @@ int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
137 119
 	/*inserts the header at the beginning of the message*/
138 120
 	anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0 , 0);
139 121
 	if (anchor == 0) {
140
-		LOG(L_ERR, "ERROR: add_maxfwd_header :"
141
-		   " Error, can't get anchor\n");
122
+		LOG(L_ERR, "ERROR:maxfwd:add_maxfwd_header: failed to get anchor\n");
142 123
 		goto error1;
143 124
 	}
144 125
 
145 126
 	if (insert_new_lump_before(anchor, buf, len, 0) == 0) {
146
-		LOG(L_ERR, "ERROR: add_maxfwd_header : "
147
-		    "Error, can't insert MAX-FORWARDS\n");
127
+		LOG(L_ERR, "ERROR:maxfwd:add_maxfwd_header: failed to insert "
128
+			"MAX-FORWARDS lump\n");
148 129
 		goto error1;
149 130
 	}
150 131
 
Browse code

-merging OpenSER 0.9.4 with SER unstable

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@30 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 16/06/2005 12:42:16
Showing 1 changed files
... ...
@@ -48,7 +48,7 @@ int is_maxfwd_present( struct sip_msg* msg , str *foo)
48 48
 
49 49
 	/* lookup into the message for MAX FORWARDS header*/
50 50
 	if ( !msg->maxforwards ) {
51
-		if  ( parse_headers( msg , HDR_MAXFORWARDS, 0 )==-1 ){
51
+		if  ( parse_headers( msg , HDR_MAXFORWARDS_F, 0 )==-1 ){
52 52
 			LOG( L_ERR , "ERROR:maxfwd:is_maxfwd_present :"
53 53
 				" parsing MAX_FORWARD header failed!\n");
54 54
 			return -2;
... ...
@@ -89,7 +89,7 @@ int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
89 89
 
90 90
 	/*rewriting the max-fwd value in the message (buf and orig)*/
91 91
 	x--;
92
-	for(i = s->len - 1; x && i >= 0; i--) {
92
+	for(i = s->len - 1; i >= 0; i--) {
93 93
 		s->s[i] = (x % 10) + '0';
94 94
 		x /= 10;
95 95
 		if (x==0) {
Browse code

Initial revision

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 13/06/2005 16:47:24
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,157 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2001-2003 FhG Fokus
5
+ *
6
+ * This file is part of openser, a free SIP server.
7
+ *
8
+ * openser 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
+ * openser 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
+ * History:
23
+ * ----------
24
+ * 2003-02-28 scratchpad compatibility abandoned (jiri)
25
+ * 2002-01-28 scratchpad removed (jiri)
26
+ * 2004-08-15 max value of max-fwd header is configurable (bogdan)
27
+ */
28
+
29
+
30
+#include <stdlib.h>
31
+#include <string.h>
32
+
33
+#include "mf_funcs.h"
34
+#include "../../mem/mem.h"
35
+#include "../../ut.h"
36
+#include "../../data_lump.h"
37
+
38
+
39
+#define MF_HDR "Max-Forwards: "
40
+#define MF_HDR_LEN (sizeof(MF_HDR) - 1)
41
+
42
+
43
+/* looks for the MAX FORWARDS header
44
+   returns the its value, -1 if is not present or -2 for error */
45
+int is_maxfwd_present( struct sip_msg* msg , str *foo)
46
+{
47
+	int x, err;
48
+
49
+	/* lookup into the message for MAX FORWARDS header*/
50
+	if ( !msg->maxforwards ) {
51
+		if  ( parse_headers( msg , HDR_MAXFORWARDS, 0 )==-1 ){
52
+			LOG( L_ERR , "ERROR:maxfwd:is_maxfwd_present :"
53
+				" parsing MAX_FORWARD header failed!\n");
54
+			return -2;
55
+		}
56
+		if (!msg->maxforwards) {
57
+			DBG("DEBUG: is_maxfwd_present: max_forwards header not found!\n");
58
+			return -1;
59
+		}
60
+	}
61
+
62
+	/* if header is present, trim to get only the string containing numbers */
63
+	trim_len( foo->len , foo->s , msg->maxforwards->body );
64
+
65
+	/* convert from string to number */
66
+	x = str2s( foo->s,foo->len,&err);
67
+	if (err){
68
+		LOG(L_ERR, "ERROR:maxfwd:is_maxfwd_present:"
69
+			" unable to parse the max forwards number !\n");
70
+		return -2;
71
+	}
72
+	DBG("DEBUG:maxfwd:is_maxfwd_present: value = %d \n",x);
73
+	return x;
74
+}
75
+
76
+
77
+
78
+
79
+int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
80
+{
81
+	int i;
82
+
83
+	/* double check */
84
+	if ( !msg->maxforwards ) {
85
+		LOG( L_ERR , "ERROR: decrement_maxfwd :"
86
+			" MAX_FORWARDS header not found !\n");
87
+		goto error;
88
+	}
89
+
90
+	/*rewriting the max-fwd value in the message (buf and orig)*/
91
+	x--;
92
+	for(i = s->len - 1; x && i >= 0; i--) {
93
+		s->s[i] = (x % 10) + '0';
94
+		x /= 10;
95
+		if (x==0) {
96
+			i = i - 1;
97
+			break;
98
+		}
99
+	}
100
+	while(i >= 0) s->s[i--] = ' ';
101
+
102
+	return 1;
103
+error:
104
+	return -1;
105
+}
106
+
107
+
108
+
109
+
110
+int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
111
+{
112
+	unsigned int  len;
113
+	char          *buf;
114
+	struct lump*  anchor;
115
+
116
+	/* double check just to be sure */
117
+	if ( msg->maxforwards ) {
118
+		LOG( L_ERR , "ERROR: add_maxfwd_header :"
119
+			" MAX_FORWARDS header already exists (%p) !\n",msg->maxforwards);
120
+		goto error;
121
+	}
122
+
123
+	/* constructing the header */
124
+	len = MF_HDR_LEN /*"MAX-FORWARDS: "*/+ CRLF_LEN + 3/*val max on 3 digits*/;
125
+
126
+	buf = (char*)pkg_malloc( len );
127
+	if (!buf) {
128
+		LOG(L_ERR, "ERROR : add_maxfwd_header : No memory left\n");
129
+		return -1;
130
+	}
131
+	memcpy( buf , MF_HDR, MF_HDR_LEN );
132
+	len = MF_HDR_LEN ;
133
+	len += btostr( buf+len , val );
134
+	memcpy( buf+len , CRLF , CRLF_LEN );
135
+	len +=CRLF_LEN;
136
+
137
+	/*inserts the header at the beginning of the message*/
138
+	anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0 , 0);
139
+	if (anchor == 0) {
140
+		LOG(L_ERR, "ERROR: add_maxfwd_header :"
141
+		   " Error, can't get anchor\n");
142
+		goto error1;
143
+	}
144
+
145
+	if (insert_new_lump_before(anchor, buf, len, 0) == 0) {
146
+		LOG(L_ERR, "ERROR: add_maxfwd_header : "
147
+		    "Error, can't insert MAX-FORWARDS\n");
148
+		goto error1;
149
+	}
150
+
151
+	return 1;
152
+
153
+error1:
154
+	pkg_free( buf );
155
+error:
156
+	return -1;
157
+}