Browse code

tm: new uri2dst() version

- new uri2dst2() function which can have the send_socket passed
directly to it.
- uri2dst() is now a wrapper over uri2dst2().

Andrei Pelinescu-Onciul authored on 20/07/2009 23:15:02
Showing 1 changed files
... ...
@@ -209,7 +209,8 @@ inline static int get_uri_send_info(str* uri, str* host, unsigned short* port,
209 209
 
210 210
 
211 211
 /*
212
- * Convert a URI into a dest_info structure
212
+ * Convert a URI into a dest_info structure.
213
+ * Same as uri2dst, but uses directly force_send_socket instead of msg.
213 214
  * If the uri host resolves to multiple ips and dns_h!=0 the first ip for 
214 215
  *  which a send socket is found will be used. If no send_socket are found,
215 216
  *  the first ip is selected.
... ...
@@ -218,9 +219,8 @@ inline static int get_uri_send_info(str* uri, str* host, unsigned short* port,
218 218
  *                 null. If null or use_dns_failover==0 normal dns lookup will
219 219
  *                 be performed (no failover).
220 220
  *         dst   - will be filled
221
- *         msg   -  sip message used to set dst->send_sock, if 0 dst->send_sock
222
- *                 will be set to the default w/o using msg->force_send_socket 
223
- *                 (see get_send_socket()) 
221
+ *         force_send_sock - if 0 dst->send_sock will be set to the default 
222
+ *                 (see get_send_socket2()) 
224 223
  *         uri   - uri in str form
225 224
  *         proto - if != PROTO_NONE, this protocol will be forced over the
226 225
  *                 uri_proto, otherwise the uri proto will be used if set or
... ...
@@ -228,14 +228,14 @@ inline static int get_uri_send_info(str* uri, str* host, unsigned short* port,
228 228
  * returns 0 on error, dst on success
229 229
  */
230 230
 #ifdef USE_DNS_FAILOVER
231
-inline static struct dest_info *uri2dst(struct dns_srv_handle* dns_h,
231
+inline static struct dest_info *uri2dst2(struct dns_srv_handle* dns_h,
232 232
 										struct dest_info* dst,
233
-										struct sip_msg *msg, str *uri, 
234
-											int proto )
233
+										struct socket_info *force_send_socket,
234
+										str *uri, int proto )
235 235
 #else
236
-inline static struct dest_info *uri2dst(struct dest_info* dst,
237
-										struct sip_msg *msg, str *uri, 
238
-											int proto )
236
+inline static struct dest_info *uri2dst2(struct dest_info* dst,
237
+										struct socket_info *force_send_socket,
238
+										str *uri, int proto )
239 239
 #endif
240 240
 {
241 241
 	struct sip_uri parsed_uri;
... ...
@@ -297,7 +297,8 @@ inline static struct dest_info *uri2dst(struct dest_info* dst,
297 297
 				dst->to=to;
298 298
 				ip_found=1;
299 299
 			}
300
-			dst->send_sock = get_send_socket(msg, &to, dst->proto);
300
+			dst->send_sock = get_send_socket2(force_send_socket, &to,
301
+												dst->proto, 0);
301 302
 			if (dst->send_sock){
302 303
 				dst->to=to;
303 304
 				return dst; /* found a good one */
... ...
@@ -313,7 +314,8 @@ inline static struct dest_info *uri2dst(struct dest_info* dst,
313 313
 		ERR("failed to resolve \"%.*s\"\n", host->len, ZSW(host->s));
314 314
 		return 0;
315 315
 	}
316
-	dst->send_sock = get_send_socket(msg, &dst->to, dst->proto);
316
+	dst->send_sock = get_send_socket2(force_send_socket, &dst->to,
317
+										dst->proto, 0);
317 318
 	if (dst->send_sock==0) {
318 319
 		ERR("no corresponding socket for af %d\n", dst->to.s.sa_family);
319 320
 		/* ser_error = E_NO_SOCKET;*/
... ...
@@ -323,6 +325,45 @@ inline static struct dest_info *uri2dst(struct dest_info* dst,
323 323
 }
324 324
 
325 325
 
326
+
327
+/*
328
+ * Convert a URI into a dest_info structure
329
+ * If the uri host resolves to multiple ips and dns_h!=0 the first ip for 
330
+ *  which a send socket is found will be used. If no send_socket are found,
331
+ *  the first ip is selected.
332
+ *
333
+ * params: dns_h - pointer to a valid dns_srv_handle structure (intialized!) or
334
+ *                 null. If null or use_dns_failover==0 normal dns lookup will
335
+ *                 be performed (no failover).
336
+ *         dst   - will be filled
337
+ *         msg   -  sip message used to set dst->send_sock, if 0 dst->send_sock
338
+ *                 will be set to the default w/o using msg->force_send_socket 
339
+ *                 (see get_send_socket()) 
340
+ *         uri   - uri in str form
341
+ *         proto - if != PROTO_NONE, this protocol will be forced over the
342
+ *                 uri_proto, otherwise the uri proto will be used if set or
343
+ *                 the proto obtained from the dns lookup
344
+ * returns 0 on error, dst on success
345
+ */
346
+#ifdef USE_DNS_FAILOVER
347
+inline static struct dest_info *uri2dst(struct dns_srv_handle* dns_h,
348
+										struct dest_info* dst,
349
+										struct sip_msg *msg, str *uri, 
350
+											int proto )
351
+{
352
+	return uri2dst2(dns_h, dst, msg?msg->force_send_socket:0, uri, proto);
353
+}
354
+#else
355
+inline static struct dest_info *uri2dst(struct dest_info* dst,
356
+										struct sip_msg *msg, str *uri, 
357
+											int proto )
358
+{
359
+	return uri2dst2(dst, msg?msg->force_send_socket:0, uri, proto);
360
+}
361
+#endif /* USE_DNS_FAILOVER */
362
+
363
+
364
+
326 365
 #if 0
327 366
 /*
328 367
  * Convert a URI into the corresponding sockaddr_union (address to send to) and