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 219
  *                 null. If null or use_dns_failover==0 normal dns lookup will
219 220
  *                 be performed (no failover).
220 221
  *         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()) 
222
+ *         force_send_sock - if 0 dst->send_sock will be set to the default 
223
+ *                 (see get_send_socket2()) 
224 224
  *         uri   - uri in str form
225 225
  *         proto - if != PROTO_NONE, this protocol will be forced over the
226 226
  *                 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 314
 		ERR("failed to resolve \"%.*s\"\n", host->len, ZSW(host->s));
314 315
 		return 0;
315 316
 	}
316
-	dst->send_sock = get_send_socket(msg, &dst->to, dst->proto);
317
+	dst->send_sock = get_send_socket2(force_send_socket, &dst->to,
318
+										dst->proto, 0);
317 319
 	if (dst->send_sock==0) {
318 320
 		ERR("no corresponding socket for af %d\n", dst->to.s.sa_family);
319 321
 		/* ser_error = E_NO_SOCKET;*/
... ...
@@ -323,6 +325,45 @@ inline static struct dest_info *uri2dst(struct dest_info* dst,
323 325
 }
324 326
 
325 327
 
328
+
329
+/*
330
+ * Convert a URI into a dest_info structure
331
+ * If the uri host resolves to multiple ips and dns_h!=0 the first ip for 
332
+ *  which a send socket is found will be used. If no send_socket are found,
333
+ *  the first ip is selected.
334
+ *
335
+ * params: dns_h - pointer to a valid dns_srv_handle structure (intialized!) or
336
+ *                 null. If null or use_dns_failover==0 normal dns lookup will
337
+ *                 be performed (no failover).
338
+ *         dst   - will be filled
339
+ *         msg   -  sip message used to set dst->send_sock, if 0 dst->send_sock
340
+ *                 will be set to the default w/o using msg->force_send_socket 
341
+ *                 (see get_send_socket()) 
342
+ *         uri   - uri in str form
343
+ *         proto - if != PROTO_NONE, this protocol will be forced over the
344
+ *                 uri_proto, otherwise the uri proto will be used if set or
345
+ *                 the proto obtained from the dns lookup
346
+ * returns 0 on error, dst on success
347
+ */
348
+#ifdef USE_DNS_FAILOVER
349
+inline static struct dest_info *uri2dst(struct dns_srv_handle* dns_h,
350
+										struct dest_info* dst,
351
+										struct sip_msg *msg, str *uri, 
352
+											int proto )
353
+{
354
+	return uri2dst2(dns_h, dst, msg?msg->force_send_socket:0, uri, proto);
355
+}
356
+#else
357
+inline static struct dest_info *uri2dst(struct dest_info* dst,
358
+										struct sip_msg *msg, str *uri, 
359
+											int proto )
360
+{
361
+	return uri2dst2(dst, msg?msg->force_send_socket:0, uri, proto);
362
+}
363
+#endif /* USE_DNS_FAILOVER */
364
+
365
+
366
+
326 367
 #if 0
327 368
 /*
328 369
  * Convert a URI into the corresponding sockaddr_union (address to send to) and