Module: sip-router Branch: tmp/build_request Commit: 8bae6347fdc3957110ae562e443f63dd8fd598a5 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8bae6347...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Wed Jul 8 13:08:30 2009 +0200
tm: execute event_route[tm:local-request] if defined
- call event_route[tm:local-request] if defined and local requests are sent by tm (similar to K local_route)
---
modules/tm/uac.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 96 insertions(+), 2 deletions(-)
diff --git a/modules/tm/uac.c b/modules/tm/uac.c index 6dfd0fc..e5aab83 100644 --- a/modules/tm/uac.c +++ b/modules/tm/uac.c @@ -82,7 +82,11 @@ #include "../../dns_cache.h" #include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */ #endif - +#ifdef WITH_EVENT_LOCAL_REQUEST +#include "../../receive.h" +#include "../../route.h" +#include "../../action.h" +#endif
#define FROM_TAG_LEN (MD5_LEN + 1 /* - */ + CRC16_LEN) /* length of FROM tags */
@@ -187,7 +191,7 @@ static inline int t_uac_prepare(uac_req_t *uac_r, struct cell *new_cell; struct retr_buf *request; char* buf; - int buf_len, ret; + int buf_len, ret; unsigned int hi; int is_ack; ticks_t lifetime; @@ -195,6 +199,17 @@ static inline int t_uac_prepare(uac_req_t *uac_r, struct dns_srv_handle dns_h; #endif long nhtype; +#ifdef WITH_EVENT_LOCAL_REQUEST + int rt; + static struct sip_msg lreq; + char *buf1; + int buf_len1; + int sflag_bk; + int backup_route_type; + avp_list_t* backup_user_from, *backup_user_to; + avp_list_t* backup_domain_from, *backup_domain_to; + avp_list_t* backup_uri_from, *backup_uri_to; +#endif
ret=-1; hi=0; /* make gcc happy */ @@ -309,6 +324,85 @@ static inline int t_uac_prepare(uac_req_t *uac_r, goto error1; }
+#ifdef WITH_EVENT_LOCAL_REQUEST + /* todo: cache this at startup */ + rt = route_lookup(&event_rt, "tm:local-request"); + if (rt>=0 && event_rt.rlist[rt]!=NULL) { + LM_DBG("executing event_route[tm:local-request]\n"); + if(build_sip_msg_from_buf(&lreq, buf, buf_len, inc_msg_no())==0) { + /* fill some field in sip_msg */ + if (set_dst_uri(&lreq, uac_r->dialog->hooks.next_hop)) { + LM_ERR("failed to set dst_uri"); + free_sip_msg(&lreq); + } else { + lreq.force_send_socket = uac_r->dialog->send_sock; + lreq.rcv.proto = uac_r->dialog->send_sock->proto; + lreq.rcv.src_ip = uac_r->dialog->send_sock->address; + lreq.rcv.src_port = uac_r->dialog->send_sock->port_no; + /* backup environment (e.g., AVP lists, ...) */ + backup_uri_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, + &new_cell->uri_avps_from); + backup_uri_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, + &new_cell->uri_avps_to); + backup_user_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_USER, + &new_cell->user_avps_from); + backup_user_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, + &new_cell->user_avps_to); + backup_domain_from = set_avp_list( + AVP_TRACK_FROM | AVP_CLASS_DOMAIN, + &new_cell->domain_avps_from); + backup_domain_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, + &new_cell->domain_avps_to); + sflag_bk = getsflags(); + + /* run the route */ + backup_route_type = get_route_type(); + set_route_type(LOCAL_ROUTE); + run_top_route(event_rt.rlist[rt], &lreq); + set_route_type( backup_route_type ); + + /* restore original environment */ + set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, backup_uri_from); + set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, backup_uri_to); + set_avp_list(AVP_TRACK_FROM | AVP_CLASS_USER, backup_user_from); + set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, backup_user_to); + set_avp_list(AVP_TRACK_FROM | AVP_CLASS_DOMAIN, + backup_domain_from); + set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, backup_domain_to); + setsflagsval(sflag_bk); + + if (lreq.new_uri.s) + { + pkg_free(lreq.new_uri.s); + lreq.new_uri.s=0; + lreq.new_uri.len=0; + } + if (lreq.dst_uri.s) + { + pkg_free(lreq.dst_uri.s); + lreq.dst_uri.s=0; + lreq.dst_uri.len=0; + } + + if (lreq.add_rm || lreq.body_lumps) { + LM_DBG("apply new updates to sip msg\n"); + buf1 = build_req_buf_from_sip_req(&lreq, + (unsigned int*)&buf_len1, + &dst, BUILD_NO_LOCAL_VIA|BUILD_NO_VIA1_UPDATE| + BUILD_IN_SHM); + if (!buf1) { + free_sip_msg(&lreq); + } else { + shm_free(buf); + buf = buf1; + buf_len = buf_len1; + } + } + } + } + } +#endif + new_cell->method.s = buf; new_cell->method.len = uac_r->method->len;