Browse code

- sip_router/ and sip_router/modules/usrloc added to the path where include files are looked up - changed includes like "../../xxx" to <xxx> - fixed append_branch condition (now checks for a zombie state) - function rewriting Request-URI implemented more efficiently - use_domain parameter removed (will be always used now)

Jan Janak authored on 05/11/2003 11:49:25
Showing 13 changed files
... ...
@@ -10,4 +10,6 @@ auto_gen=
10 10
 NAME=registrar.so
11 11
 LIBS=
12 12
 
13
+DEFS+=-I../.. -I../usrloc
14
+
13 15
 include ../../Makefile.modules
... ...
@@ -34,13 +34,13 @@
34 34
 */
35 35
 
36 36
 #include <string.h> 
37
-#include <ctype.h>
38
-#include "../../dprint.h"
39
-#include "../../ut.h"      /* q_memchr */
40
-#include "../../parser/parse_uri.h"
41
-#include "common.h"
37
+#include <dprint.h>
38
+#include <ut.h>      /* q_memchr */
39
+#include <parser/parse_uri.h>
42 40
 #include "rerrno.h"
43 41
 #include "reg_mod.h"
42
+#include "common.h"
43
+
44 44
 
45 45
 #define MAX_AOR_LEN 256
46 46
 
... ...
@@ -56,13 +56,13 @@ int extract_aor(str* _uri, str* _a)
56 56
 
57 57
 	if (parse_uri(_uri->s, _uri->len, &puri) < 0) {
58 58
 		rerrno = R_AOR_PARSE;
59
-		LOG(L_ERR, "extract_aor(): Error while parsing AOR, sending 400\n");
59
+		LOG(L_ERR, "extract_aor(): Error while parsing Address of Record\n");
60 60
 		return -1;
61 61
 	}
62 62
 	
63 63
 	if ((puri.user.len + puri.host.len + 1) > MAX_AOR_LEN) {
64 64
 		rerrno = R_AOR_LEN;
65
-		LOG(L_ERR, "extract_aor(): Address Of Record too long, sending 500\n");
65
+		LOG(L_ERR, "extract_aor(): Address Of Record too long\n");
66 66
 		return -2;
67 67
 	}
68 68
 
... ...
@@ -77,11 +77,9 @@ int extract_aor(str* _uri, str* _a)
77 77
 
78 78
 	user_len = _a->len;
79 79
 
80
-	if (use_domain) {
81
-		aor_buf[_a->len] = '@';
82
-		memcpy(aor_buf + _a->len + 1, puri.host.s, puri.host.len);
83
-		_a->len += 1 + puri.host.len;
84
-	}
80
+	aor_buf[_a->len] = '@';
81
+	memcpy(aor_buf + _a->len + 1, puri.host.s, puri.host.len);
82
+	_a->len += 1 + puri.host.len;
85 83
 
86 84
 	if (case_sensitive) {
87 85
 		tmp.s = _a->s + user_len + 1;
... ...
@@ -31,8 +31,7 @@
31 31
 #ifndef COMMON_H
32 32
 #define COMMON_H
33 33
 
34
-#include "../../str.h"
35
-#include "../../parser/msg_parser.h"
34
+#include <str.h>
36 35
 
37 36
 
38 37
 /*
... ...
@@ -32,45 +32,44 @@
32 32
  */
33 33
 
34 34
 
35
-#include "lookup.h"
36 35
 #include <string.h>
37
-#include "../../ut.h"
38
-#include "../../dset.h"
39
-#include "../../str.h"
40
-#include "../../config.h"
41
-#include "../../action.h"
42
-#include "../usrloc/usrloc.h"
36
+#include <ut.h>
37
+#include <dset.h>
38
+#include <str.h>
39
+#include <config.h>
40
+#include <action.h>
41
+#include <usrloc.h>
43 42
 #include "common.h"
44 43
 #include "regtime.h"
45 44
 #include "reg_mod.h"
45
+#include "lookup.h"
46 46
 
47 47
 
48 48
 /*
49 49
  * Rewrite Request-URI
50 50
  */
51
-static inline int rwrite(struct sip_msg* _m, str* _s)
51
+static inline int rewrite(struct sip_msg* _m, str* _s)
52 52
 {
53
-	char buffer[MAX_URI_SIZE];
54
-	struct action act;
55
-	
56
-	if (_s->len > MAX_URI_SIZE - 1) {
57
-		LOG(L_ERR, "rwrite(): URI too long\n");
53
+	char* buf;
54
+
55
+	buf = (char*)pkg_malloc(_s->len + 1);
56
+	if (!buf) {
57
+		LOG(L_ERR, "rewrite(): No memory left\n");
58 58
 		return -1;
59 59
 	}
60
-	
61
-	memcpy(buffer, _s->s, _s->len);
62
-	buffer[_s->len] = '\0';
63
-	
64
-	DBG("rwrite(): Rewriting Request-URI with '%s'\n", buffer);
65
-	act.type = SET_URI_T;
66
-	act.p1_type = STRING_ST;
67
-	act.p1.string = buffer;
68
-	act.next = 0;
69
-	
70
-	if (do_action(&act, _m) < 0) {
71
-		LOG(L_ERR, "rwrite(): Error in do_action\n");
72
-		return -1;
60
+
61
+	memcpy(buf, _s->s, _s->len);
62
+	_s->s[_s->len] = '\0';
63
+
64
+	_m->parsed_uri_ok = 0;
65
+	if (_m->new_uri.s) {
66
+		pkg_free(_m->new_uri.s);
73 67
 	}
68
+
69
+	_m->new_uri.s = buf;
70
+	_m->new_uri.len = _s->len;
71
+
72
+	DBG("rewrite(): Rewriting Request-URI with '%.*s'\n", _s->len, buf);
74 73
 	return 0;
75 74
 }
76 75
 
... ...
@@ -118,7 +117,7 @@ int lookup(struct sip_msg* _m, char* _t, char* _s)
118 118
 		ptr = ptr->next;
119 119
 	
120 120
 	if (ptr) {
121
-		if (rwrite(_m, &ptr->c) < 0) {
121
+		if (rewrite(_m, &ptr->c) < 0) {
122 122
 			LOG(L_ERR, "lookup(): Unable to rewrite Request-URI\n");
123 123
 			ul.unlock_udomain((udomain_t*)_t);
124 124
 			return -4;
... ...
@@ -135,20 +134,22 @@ int lookup(struct sip_msg* _m, char* _t, char* _s)
135 135
 	if (!append_branches) goto skip;
136 136
 
137 137
 	while(ptr) {
138
-		if (ptr->expires > act_time) {
138
+		if (ptr->expires > act_time && (ptr->state < CS_ZOMBIE_N)) {
139 139
 			if (append_branch(_m, ptr->c.s, ptr->c.len) == -1) {
140 140
 				LOG(L_ERR, "lookup(): Error while appending a branch\n");
141
-				ul.unlock_udomain((udomain_t*)_t);
142
-				return 1; /* Return OK here so the function succeeds */
143
-			}
144
-			nat |= ptr->flags & FL_NAT;
141
+				     /* Return 1 here so the function succeeds even if appending of
142
+				      * a branch failed
143
+				      */
144
+				goto skip; 
145
+			} 
146
+			
147
+			nat |= ptr->flags & FL_NAT; 
145 148
 		} 
146
-		ptr = ptr->next;
149
+		ptr = ptr->next; 
147 150
 	}
148 151
 	
149 152
  skip:
150 153
 	ul.unlock_udomain((udomain_t*)_t);
151
-
152 154
 	if (nat) setflag(_m, nat_flag);
153 155
 	return 1;
154 156
 }
... ...
@@ -31,7 +31,7 @@
31 31
 #ifndef LOOKUP_H
32 32
 #define LOOKUP_H
33 33
 
34
-#include "../../parser/msg_parser.h"
34
+#include <parser/msg_parser.h>
35 35
 
36 36
 
37 37
 /*
... ...
@@ -34,16 +34,15 @@
34 34
  *  2003-03-21  save_noreply added, provided by Maxim Sobolev <sobomax@portaone.com> (janakj)
35 35
  */
36 36
 
37
-
38
-#include "reg_mod.h"
39 37
 #include <stdio.h>
40
-#include "../../sr_module.h"
41
-#include "../../timer.h"
42
-#include "../../dprint.h"
43
-#include "../../error.h"
44
-
38
+#include <sr_module.h>
39
+#include <timer.h>
40
+#include <dprint.h>
41
+#include <error.h>
45 42
 #include "save.h"
46 43
 #include "lookup.h"
44
+#include "reg_mod.h"
45
+
47 46
 
48 47
 MODULE_VERSION
49 48
 
... ...
@@ -56,13 +55,13 @@ usrloc_api_t ul;            /* Structure containing pointers to usrloc functions
56 56
 int default_expires = 3600; /* Default expires value in seconds */
57 57
 int default_q       = 0;    /* Default q value multiplied by 1000 */
58 58
 int append_branches = 1;    /* If set to 1, lookup will put all contacts found in msg structure */
59
-int use_domain      = 0;    /* If set to 1, domain will username@domain will be used as AOR */
60 59
 int case_sensitive  = 0;    /* If set to 1, username in aor will be case sensitive */
61 60
 int desc_time_order = 0;    /* By default do not order according to the descending modification time */
62 61
 int nat_flag        = 4;    /* SER flag marking contacts behind NAT */
63 62
 
64 63
 float def_q;                /* default_q converted to float in mod_init */
65 64
 
65
+
66 66
 /*
67 67
  * sl_send_reply function pointer
68 68
  */
... ...
@@ -76,7 +75,7 @@ static cmd_export_t cmds[] = {
76 76
 	{"save",         save,         1, domain_fixup, REQUEST_ROUTE                },
77 77
 	{"save_noreply", save_noreply, 1, domain_fixup, REQUEST_ROUTE                },
78 78
 	{"lookup",       lookup,       1, domain_fixup, REQUEST_ROUTE | FAILURE_ROUTE},
79
-	{0,0,0,0,0}
79
+	{0, 0, 0, 0, 0}
80 80
 };
81 81
 
82 82
 
... ...
@@ -87,11 +86,10 @@ static param_export_t params[] = {
87 87
 	{"default_expires", INT_PARAM, &default_expires},
88 88
 	{"default_q",       INT_PARAM, &default_q      },
89 89
 	{"append_branches", INT_PARAM, &append_branches},
90
-	{"use_domain",      INT_PARAM, &use_domain     },
91 90
 	{"case_sensitive",  INT_PARAM, &case_sensitive },
92 91
 	{"desc_time_order", INT_PARAM, &desc_time_order},
93 92
 	{"nat_flag",        INT_PARAM, &nat_flag       },
94
-	{0,0,0}
93
+	{0, 0, 0}
95 94
 };
96 95
 
97 96
 
... ...
@@ -31,13 +31,12 @@
31 31
 #ifndef REG_MOD_H
32 32
 #define REG_MOD_H
33 33
 
34
-#include "../../parser/msg_parser.h"
35
-#include "../usrloc/usrloc.h"
34
+#include <parser/msg_parser.h>
35
+#include <usrloc.h>
36 36
 
37 37
 extern int default_expires;
38 38
 extern int default_q;
39 39
 extern int append_branches;
40
-extern int use_domain;
41 40
 extern int case_sensitive;
42 41
 extern int desc_time_order;
43 42
 extern int nat_flag;
... ...
@@ -34,19 +34,22 @@
34 34
  */
35 35
 
36 36
 #include <stdio.h>
37
-#include "../../ut.h"
38
-#include "../../parser/msg_parser.h"
39
-#include "../../data_lump_rpl.h"
37
+#include <ut.h>
38
+#include <parser/msg_parser.h>
39
+#include <data_lump_rpl.h>
40
+#include <usrloc.h>
40 41
 #include "rerrno.h"
41 42
 #include "reg_mod.h"
42 43
 #include "regtime.h"
43 44
 #include "reply.h"
44 45
 
46
+
45 47
 #define MAX_CONTACT_BUFFER 1024
46 48
 
47 49
 #define E_INFO "P-Registrar-Error: "
48 50
 #define E_INFO_LEN (sizeof(E_INFO) - 1)
49 51
 
52
+
50 53
 static char b[MAX_CONTACT_BUFFER];
51 54
 static int l;
52 55
 
... ...
@@ -204,7 +207,6 @@ int codes[] = {
204 204
 };
205 205
 
206 206
 
207
-
208 207
 /*
209 208
  * Send a reply
210 209
  */
... ...
@@ -31,8 +31,7 @@
31 31
 #ifndef REPLY_H
32 32
 #define REPLY_H
33 33
 
34
-#include "../../parser/msg_parser.h"
35
-#include "../usrloc/usrloc.h"
34
+#include <parser/msg_parser.h>
36 35
 
37 36
 
38 37
 /*
... ...
@@ -34,20 +34,20 @@
34 34
  */
35 35
 
36 36
 
37
-#include "../../comp_defs.h"
38
-#include "save.h"
39
-#include "../../str.h"
40
-#include "../../parser/parse_to.h"
41
-#include "../../dprint.h"
42
-#include "../../trim.h"
43
-#include "../../ut.h"
44
-#include "../usrloc/usrloc.h"
37
+#include <comp_defs.h>
38
+#include <str.h>
39
+#include <parser/parse_to.h>
40
+#include <dprint.h>
41
+#include <trim.h>
42
+#include <ut.h>
43
+#include <usrloc.h>
45 44
 #include "common.h"
46 45
 #include "sip_msg.h"
47 46
 #include "rerrno.h"
48 47
 #include "reply.h"
49 48
 #include "reg_mod.h"
50 49
 #include "regtime.h"
50
+#include "save.h"
51 51
 
52 52
 
53 53
 void remove_cont(urecord_t* _r, ucontact_t* _c)
... ...
@@ -37,7 +37,7 @@
37 37
 #define SAVE_H
38 38
 
39 39
 
40
-#include "../../parser/msg_parser.h"
40
+#include <parser/msg_parser.h>
41 41
 
42 42
 
43 43
 /*
... ...
@@ -45,6 +45,7 @@
45 45
  */
46 46
 int save(struct sip_msg* _m, char* _t, char* _s);
47 47
 
48
+
48 49
 /*
49 50
  * Process REGISTER request and save it's contacts, do not send any replies
50 51
  */
... ...
@@ -29,14 +29,14 @@
29 29
 
30 30
 
31 31
 
32
-#include "sip_msg.h"
33
-#include "../../parser/hf.h"
34
-#include "../../dprint.h"
35
-#include "../../parser/parse_expires.h"  
36
-#include "../../ut.h"
32
+#include <parser/hf.h>
33
+#include <dprint.h>
34
+#include <parser/parse_expires.h>  
35
+#include <ut.h>
37 36
 #include "reg_mod.h"                     /* Module parameters */
38 37
 #include "regtime.h"                     /* act_time */
39 38
 #include "rerrno.h"
39
+#include "sip_msg.h"
40 40
 
41 41
 
42 42
 static struct hdr_field* act_contact;
... ...
@@ -226,11 +226,6 @@ int calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e)
226 226
 	} else {
227 227
 		if (str2int(&_ep->body, (unsigned int*)_e) < 0) {
228 228
 			*_e = 3600;
229
-			     /*
230
-			       rerrno = R_INV_EXP;
231
-			       LOG(L_ERR, "calc_contact_expires(): Invalid expires parameter\n");
232
-			       return -1;
233
-			     */
234 229
 		}
235 230
 		     /* Convert to absolute value */
236 231
 		if (*_e != 0) *_e += act_time;
... ...
@@ -32,8 +32,8 @@
32 32
 #define SIP_MSG_H
33 33
 
34 34
 
35
-#include "../../parser/msg_parser.h"
36
-#include "../../parser/contact/parse_contact.h"
35
+#include <parser/msg_parser.h>
36
+#include <parser/contact/parse_contact.h>
37 37
 
38 38
 
39 39
 /*