Browse code

- fixed extra '@' added when rewritting the host part of uris w/o an username.

Andrei Pelinescu-Onciul authored on 05/10/2001 23:58:55
Showing 3 changed files
... ...
@@ -2,8 +2,15 @@ $Id$
2 2
 
3 3
 [ under construction :) ]
4 4
 
5
-read INSTALL
6
-compile & sip_router -h
5
+Sources:
6
+
7
+ - set your tab stop to 4 (in vi: set ts=4).
8
+
9
+
10
+Compile & Install:
11
+
12
+- read INSTALL
13
+- compile & sip_router -h
7 14
 
8 15
 
9 16
 Configuration files:
... ...
@@ -14,10 +14,13 @@ High priority:
14 14
 - add User-Agent (for the replies)
15 15
 
16 16
 Low priority:
17
+- config file version (a la sendmail)
17 18
 - loop detection
18 19
 - cfg. file reload
19 20
 - flags for using names or ip adresses in Via ?
20 21
 
22
+- handle SIGCHLD, SIGHUP
23
+
21 24
 - make install
22 25
 - init.d scripts (and rc.local? for *BSD or Slackware)
23 26
 - man page
... ...
@@ -38,6 +38,7 @@ int do_action(struct action* a, struct sip_msg* msg)
38 38
 	char* tmp;
39 39
 	char *new_uri, *end, *crt;
40 40
 	int len;
41
+	int user;
41 42
 	struct sip_uri uri;
42 43
 
43 44
 	ret=E_BUG;
... ...
@@ -155,6 +156,7 @@ int do_action(struct action* a, struct sip_msg* msg)
155 156
 		case SET_USERPASS_T:
156 157
 		case SET_PORT_T:
157 158
 		case SET_URI_T:
159
+				user=0;
158 160
 				if (a->p1_type!=STRING_ST){
159 161
 					LOG(L_CRIT, "BUG: do_action: bad set*() type %d\n",
160 162
 							a->p1_type);
... ...
@@ -166,7 +168,8 @@ int do_action(struct action* a, struct sip_msg* msg)
166 168
 					len=strlen(a->p1.string);
167 169
 					msg->new_uri=malloc(len+1);
168 170
 					if (msg->new_uri==0){
169
-						LOG(L_ERR, "ERROR: do_action: memory allocation failure\n");
171
+						LOG(L_ERR, "ERROR: do_action: memory allocation"
172
+								" failure\n");
170 173
 						ret=E_OUT_OF_MEM;
171 174
 						break;
172 175
 					}
... ...
@@ -179,14 +182,16 @@ int do_action(struct action* a, struct sip_msg* msg)
179 182
 				if (msg->new_uri) tmp=msg->new_uri;
180 183
 				else tmp=msg->first_line.u.request.uri;
181 184
 				if (parse_uri(tmp, strlen(tmp), &uri)<0){
182
-					LOG(L_ERR, "ERROR: do_action: bad uri <%s>, dropping packet\n", tmp);
185
+					LOG(L_ERR, "ERROR: do_action: bad uri <%s>, dropping"
186
+								" packet\n", tmp);
183 187
 					ret=E_UNSPEC;
184 188
 					break;
185 189
 				}
186 190
 				
187 191
 				new_uri=malloc(MAX_URI_SIZE);
188 192
 				if (new_uri==0){
189
-					LOG(L_ERR, "ERROR: do_action: memory allocation failure\n");
193
+					LOG(L_ERR, "ERROR: do_action: memory allocation "
194
+								" failure\n");
190 195
 					ret=E_OUT_OF_MEM;
191 196
 					break;
192 197
 				}
... ...
@@ -196,11 +201,14 @@ int do_action(struct action* a, struct sip_msg* msg)
196 201
 				len=strlen("sip:"); if(crt+len>end) goto error_uri;
197 202
 				memcpy(crt,"sip:",len);crt+=len;
198 203
 				/* user */
199
-				if ((a->type==SET_USER_T)||(a->type==SET_USERPASS_T)) tmp=a->p1.string;
200
-				else tmp=uri.user;
204
+				if ((a->type==SET_USER_T)||(a->type==SET_USERPASS_T))
205
+					tmp=a->p1.string;
206
+				else 
207
+					tmp=uri.user;
201 208
 				if (tmp){
202 209
 					len=strlen(tmp); if(crt+len>end) goto error_uri;
203 210
 					memcpy(crt,tmp,len);crt+=len;
211
+					user=1; /* we have an user field so mark it */
204 212
 				}
205 213
 				if (a->type==SET_USERPASS_T) tmp=0;
206 214
 				else tmp=uri.passwd;
... ...
@@ -212,10 +220,14 @@ int do_action(struct action* a, struct sip_msg* msg)
212 220
 					memcpy(crt,tmp,len);crt+=len;
213 221
 				}
214 222
 				/* host */
215
-				len=strlen("@"); if(crt+len>end) goto error_uri;
216
-				memcpy(crt,"@",len);crt+=len;
217
-				if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T)) tmp=a->p1.string;
218
-				else tmp=uri.host;
223
+				if (user || tmp){ /* add @ */
224
+					len=strlen("@"); if(crt+len>end) goto error_uri;
225
+					memcpy(crt,"@",len);crt+=len;
226
+				}
227
+				if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T))
228
+					tmp=a->p1.string;
229
+				else
230
+					tmp=uri.host;
219 231
 				if (tmp){
220 232
 					len=strlen(tmp); if(crt+len>end) goto error_uri;
221 233
 					memcpy(crt,tmp,len);crt+=len;