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 155
 		case SET_USERPASS_T:
156 156
 		case SET_PORT_T:
157 157
 		case SET_URI_T:
158
+				user=0;
158 159
 				if (a->p1_type!=STRING_ST){
159 160
 					LOG(L_CRIT, "BUG: do_action: bad set*() type %d\n",
160 161
 							a->p1_type);
... ...
@@ -166,7 +168,8 @@ int do_action(struct action* a, struct sip_msg* msg)
166 166
 					len=strlen(a->p1.string);
167 167
 					msg->new_uri=malloc(len+1);
168 168
 					if (msg->new_uri==0){
169
-						LOG(L_ERR, "ERROR: do_action: memory allocation failure\n");
169
+						LOG(L_ERR, "ERROR: do_action: memory allocation"
170
+								" failure\n");
170 171
 						ret=E_OUT_OF_MEM;
171 172
 						break;
172 173
 					}
... ...
@@ -179,14 +182,16 @@ int do_action(struct action* a, struct sip_msg* msg)
179 179
 				if (msg->new_uri) tmp=msg->new_uri;
180 180
 				else tmp=msg->first_line.u.request.uri;
181 181
 				if (parse_uri(tmp, strlen(tmp), &uri)<0){
182
-					LOG(L_ERR, "ERROR: do_action: bad uri <%s>, dropping packet\n", tmp);
182
+					LOG(L_ERR, "ERROR: do_action: bad uri <%s>, dropping"
183
+								" packet\n", tmp);
183 184
 					ret=E_UNSPEC;
184 185
 					break;
185 186
 				}
186 187
 				
187 188
 				new_uri=malloc(MAX_URI_SIZE);
188 189
 				if (new_uri==0){
189
-					LOG(L_ERR, "ERROR: do_action: memory allocation failure\n");
190
+					LOG(L_ERR, "ERROR: do_action: memory allocation "
191
+								" failure\n");
190 192
 					ret=E_OUT_OF_MEM;
191 193
 					break;
192 194
 				}
... ...
@@ -196,11 +201,14 @@ int do_action(struct action* a, struct sip_msg* msg)
196 196
 				len=strlen("sip:"); if(crt+len>end) goto error_uri;
197 197
 				memcpy(crt,"sip:",len);crt+=len;
198 198
 				/* user */
199
-				if ((a->type==SET_USER_T)||(a->type==SET_USERPASS_T)) tmp=a->p1.string;
200
-				else tmp=uri.user;
199
+				if ((a->type==SET_USER_T)||(a->type==SET_USERPASS_T))
200
+					tmp=a->p1.string;
201
+				else 
202
+					tmp=uri.user;
201 203
 				if (tmp){
202 204
 					len=strlen(tmp); if(crt+len>end) goto error_uri;
203 205
 					memcpy(crt,tmp,len);crt+=len;
206
+					user=1; /* we have an user field so mark it */
204 207
 				}
205 208
 				if (a->type==SET_USERPASS_T) tmp=0;
206 209
 				else tmp=uri.passwd;
... ...
@@ -212,10 +220,14 @@ int do_action(struct action* a, struct sip_msg* msg)
212 212
 					memcpy(crt,tmp,len);crt+=len;
213 213
 				}
214 214
 				/* 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;
215
+				if (user || tmp){ /* add @ */
216
+					len=strlen("@"); if(crt+len>end) goto error_uri;
217
+					memcpy(crt,"@",len);crt+=len;
218
+				}
219
+				if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T))
220
+					tmp=a->p1.string;
221
+				else
222
+					tmp=uri.host;
219 223
 				if (tmp){
220 224
 					len=strlen(tmp); if(crt+len>end) goto error_uri;
221 225
 					memcpy(crt,tmp,len);crt+=len;