Hi,
attached patch converts the utils module to use the sr msg_send functionality. Please review if the API is used correct.
In kamailio we use this "while( get_next_su( proxy, to, 0) == 0 );" construct to loop over all destinations (e.g. for failover), how this is handled in sr?
Thanks,
Henning
On Mar 18, 2009 at 16:57, Henning Westerholt henning.westerholt@1und1.de wrote:
Look ok.
In kamailio we use this "while( get_next_su( proxy, to, 0) == 0 );" construct to loop over all destinations (e.g. for failover), how this is handled in sr?
int err; struct dns_srv_handle dns_srv_h;
dns_srv_handle_init(&dns_srv_h); err=dns_sip_resolve2su(&dns_srv_h, &send_info->to, dst, port, &proto, dns_flags); if (err!=0){ /* ERROR */ }
do{ /* ... get_send_socket a.s.o */ if (msg_send(send_info, buf, len)<0) continue; }while( dns_srv_handle_next(&dns_srv_h, err) && ((err=dns_sip_resolve2su(&dns_srv_h, &send_info->to, dst, port, &proto, dns_flags)) == 0) ); dns_srv_handle_put(&dns_srv_h); /* very important, don't forget or the the corresp. dns cache entry won't ever be freed */
(lots of stuff omitted, like error checks, blacklist check/add, dns failover on/off checks, #ifdefs for USE_DNS_FAILOVER a.s.o.)
Basically dns_srv_handle_next() selects the next ip and also tells if there are no more ips availale. It needs a struct dns_srv_handle which was used before in a call to dns_sip_resolve*() and the return value (err) of the last dns_sip_resolve*() call. You could use 0 instead of err, if you check dns_sip_resolve*() return in some other place and stop the loop on error.
For a more complete example, see forward_request() in forward.c.
You might be able to use forward_request() directly and get rid of all the send and failover code (I haven't checked if it's possible or utils_forward() needs something more special). forward_request() will also use the blacklist (if configured).
Andrei