On 06/09/2014 06:03 PM, Roberto Fichera wrote: Hi,
> On 06/09/2014 05:49 PM, Daniel-Constantin Mierla wrote: >> Hello, > > Hi, > >> On 09/06/14 17:41, Roberto Fichera wrote: >>> [...] >>> >>>> your patch seems a bit to complex -- I didn't figure out why you store the >>>> message in pkg memory. >>> >>> Ok! So I will need to shm_malloc() the memory in such case, right? >> I don't get why you need to do that at all. If you need to access from, to, >> etc..., you can get them from the SIP >> response. You go in dangerous zone as you do that cloning. > > The idea was to set a sip_msg just to have all the pseudo-variable available > within the event route and nothing else. > >> Because you want to execute the event route on 200ok, the best is to run the >> event route with the SIP response structure. > > At the beginning this was my choice, but I'd always got ps->req = NULL in the > callback tmcb_params > hence the event route wasn't executed. But I'll re-try it just to be sure. I can confirm, I'm always getting ps->req = NULL un 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: <core> [parser/msg_parser.c:170]: get_hdr_field(): get_hdr_field: cseq <CSeq>: <10> <MESSAGE> Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: tm [t_lookup.c:949]: t_reply_matching(): DEBUG: t_reply_matching: hash 39390 label 0 branch 0 Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: tm [t_lookup.c:1004]: t_reply_matching(): DEBUG: t_reply_matching: reply matched (T=0xb2f7ebfc)! Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: tm [t_lookup.c:1141]: t_check_msg(): DEBUG: t_check_msg: msg id=1 global id=1 T end=0xb2f7ebfc Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: tm [t_reply.c:2206]: reply_received(): DEBUG: reply_received: org. status uas=0, uac[0]=0 local=2 is_invite=0) Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: tm [t_reply.c:1304]: t_should_relay_response(): ->>>>>>>>> T_code=0, new_code=200 Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: tm [t_reply.c:2086]: local_reply(): DEBUG: local_reply: branch=0, save=0, winner=0 Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: tm [t_reply.c:2123]: local_reply(): DEBUG: local transaction completed Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: tm [t_hooks.c:288]: run_trans_callbacks_internal(): DBG: trans=0xb2f7ebfc, callback type 1024, id 0 entered Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: msilo [msilo.c:1378]: m_tm_callback_on_delivered_event(): >>>>>>> msilo_notification_event 0xb301669c Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: msilo [msilo.c:1380]: m_tm_callback_on_delivered_event(): completed with status 200 [mid: 147] Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: msilo [msilo.c:1393]: m_tm_callback_on_delivered_event(): message <147> was sent successfully Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: msilo [ms_msg_list.c:236]: msg_list_set_flag(): mid:147 fl:4 Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: msilo [msilo.c:1403]: m_tm_callback_on_delivered_event(): executing event_route[msilo:on-delivered] (1) --->>>>> Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: msilo [msilo.c:1410]: m_tm_callback_on_delivered_event(): event_route[msilo:on-delivered] ps->req=(nil)) Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: tm [t_reply.c:1663]: cleanup_uac_timers(): DEBUG: cleanup_uac_timers: RETR/FR timers reset Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: <core> [usr_avp.c:644]: destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil) Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: <core> [usr_avp.c:644]: destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil) Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: <core> [usr_avp.c:644]: destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil) Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: <core> [usr_avp.c:644]: destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil) Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: <core> [usr_avp.c:644]: destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil) Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: <core> [usr_avp.c:644]: destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil) Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: <core> [xavp.c:448]: xavp_destroy_list(): destroying xavp list (nil) Jun 09 17:06:38 ip-10-227-0-26.localdomain /usr/sbin/kamailio[25089]: DEBUG: <core> [receive.c:296]: receive_msg(): receive_msg: cleaning up > > BTW! using shm_malloc() I was finally able to execute the event route in the > script with all the > pseudo-variable correctly set! Attached you will find the patch I'm actually using. Cheers, Roberto Fichera. > > Cheers, > Roberto Fichera. > >> >> Cheers, >> Daniel >> -- >> Daniel-Constantin Mierla - http://www.asipto.com >> http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda >> >> >> _______________________________________________ >> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list >> sr-users@lists.sip-router.org >> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users > > > > _______________________________________________ > SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list > sr-users@lists.sip-router.org > http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
diff --git a/modules/msilo/msilo.c b/modules/msilo/msilo.c index 903b3cf..476c0de 100644 --- a/modules/msilo/msilo.c +++ b/modules/msilo/msilo.c @@ -62,9 +62,13 @@ #include "../../parser/contact/parse_contact.h" #include "../../parser/parse_allow.h" #include "../../parser/parse_methods.h" +#include "../../parser/msg_parser.h" #include "../../resolve.h" #include "../../usr_avp.h" #include "../../mod_fix.h" +#include "../../dprint.h" +#include "../../globals.h" +#include "../../dset.h" #include "../../modules/tm/tm_load.h" @@ -185,6 +189,7 @@ int check_message_support(struct sip_msg* msg); /** TM callback function */ static void m_tm_callback( struct cell *t, int type, struct tmcb_params *ps); +static void m_tm_callback_on_delivered_event( struct cell *t, int type, struct tmcb_params *ps); static cmd_export_t cmds[]={ {"m_store", (cmd_function)m_store_2, 0, 0, 0, REQUEST_ROUTE | FAILURE_ROUTE}, @@ -281,6 +286,17 @@ static int bind_msilo(msilo_api_t* api) return 0; } +/* where to go for the local request route ("msilo:on-delivered") */ +static int msilo_event_on_delivered=-1; /* default disabled */ + +typedef struct msilo_notification_event +{ + struct sip_msg *req; + int mid; +} msilo_notification_event_t; + +static msilo_notification_event_t *msilo_make_request(str *ruri, str *to, str *from, str *hdr, int mid); + /** * init module function */ @@ -480,6 +496,11 @@ static int mod_init(void) if(ms_outbound_proxy.s!=NULL) ms_outbound_proxy.len = strlen(ms_outbound_proxy.s); + /* check if the on-delivered route event exists or not */ + msilo_event_on_delivered=route_lookup(&event_rt, "msilo:on-delivered"); + if (msilo_event_on_delivered>=0 && event_rt.rlist[msilo_event_on_delivered]==0) + msilo_event_on_delivered=-1; /* disable */ + return 0; } @@ -839,7 +860,7 @@ static int m_store(struct sip_msg* msg, str *owner_s) db_vals[nr_keys].val.blob_val.len = extra_hdrs.len; nr_keys++; - + if(msilo_dbf.insert(db_con, db_keys, db_vals, nr_keys) < 0) { LM_ERR("failed to store message\n"); @@ -971,7 +992,7 @@ static int m_dump(struct sip_msg* msg, str* owner_s) uac_req_t uac_r; str str_vals[5], hdr_str, body_str, extra_hdrs_str, tmp_extra_hdrs; time_t rtime; - + /* init */ ob_key = &sc_mid; @@ -1096,8 +1117,7 @@ static int m_dump(struct sip_msg* msg, str* owner_s) SET_STR_VAL(str_vals[2], db_res, i, 3); /* body */ SET_STR_VAL(str_vals[3], db_res, i, 4); /* ctype */ SET_STR_VAL(str_vals[4], db_res, i, 6); /* stored hdrs */ - rtime = - (time_t)RES_ROWS(db_res)[i].values[5/*inc time*/].val.int_val; + rtime = (time_t)RES_ROWS(db_res)[i].values[5/*inc time*/].val.int_val; if (ms_extra_hdrs != NULL) { if (fixup_get_svalue(msg, (gparam_p)*ms_extra_hdrs_sp, @@ -1145,7 +1165,7 @@ static int m_dump(struct sip_msg* msg, str* owner_s) if(tmp_extra_hdrs.len>0) pkg_free(tmp_extra_hdrs.s); - LM_DBG("msg [%d-%d] for: %.*s\n", i+1, mid, pto->uri.len, pto->uri.s); + LM_DBG("msg [%d-%d] for: %.*s\n", i+1, mid, pto->uri.len, pto->uri.s); /** sending using TM function: t_uac */ body_str.len = 1024; @@ -1166,14 +1186,19 @@ static int m_dump(struct sip_msg* msg, str* owner_s) uac_r.headers = &hdr_str; uac_r.body = (n<0)?&str_vals[2]:&body_str; uac_r.cb_flags = TMCB_LOCAL_COMPLETED; - uac_r.cb = m_tm_callback; - uac_r.cbp = (void*)(long)mid; - - tmb.t_request(&uac_r, /* UAC Req */ - &str_vals[1], /* Request-URI */ - &str_vals[1], /* To */ - &str_vals[0], /* From */ - (ms_outbound_proxy.s)?&ms_outbound_proxy:0 /* ob uri */ + uac_r.cbp = (void*)msilo_make_request(&str_vals[1] /* ruri */, + &str_vals[1] /* to */, + &str_vals[0] /* from */, + &hdr_str, + mid); + + uac_r.cb = m_tm_callback_on_delivered_event; + + tmb.t_request(&uac_r, /* UAC Req */ + &str_vals[1], /* Request-URI */ + &str_vals[1], /* To */ + &str_vals[0], /* From */ + (ms_outbound_proxy.s)?&ms_outbound_proxy:0 /* ob uri */ ); } @@ -1334,6 +1359,69 @@ done: return; } +/** + * TM callback function - delete message from database if was sent OK and execute + * the msilo:on-delivered event route + */ +void m_tm_callback_on_delivered_event(struct cell *t, int type, struct tmcb_params *ps) +{ + msilo_notification_event_t *event; + + if(ps->param==NULL || *ps->param == NULL) + { + LM_DBG("message id not received\n"); + goto done; + } + + event = (msilo_notification_event_t*)*ps->param; + + LM_DBG(">>>>>>> msilo_notification_event %p\n", event); + + LM_DBG("completed with status %d [mid: %d]\n", ps->code, event->mid); + if(!db_con) + { + LM_ERR("db_con is NULL\n"); + goto done; + } + if(ps->code >= 300) + { + LM_DBG("message <%d> was not sent successfully\n", event->mid); + msg_list_set_flag(ml, event->mid, MS_MSG_ERRO); + goto done; + } + + LM_DBG("message <%d> was sent successfully\n", event->mid); + msg_list_set_flag(ml, event->mid, MS_MSG_DONE); + + /* execute the msilo:on-delivered event route */ + if(unlikely(msilo_event_on_delivered>=0)) + { + int sflag_bk; + int backup_route_type; + struct run_act_ctx ctx; + + LM_DBG("executing event_route[msilo:on-delivered] (%d)\n", msilo_event_on_delivered); + + sflag_bk = getsflags(); + backup_route_type = get_route_type(); + + set_route_type(EVENT_ROUTE); + init_run_actions_ctx(&ctx); + LM_DBG("event_route[msilo:on-delivered] event->req=%p)\n", event->req); + run_top_route(event_rt.rlist[msilo_event_on_delivered], event->req, &ctx); + + set_route_type(backup_route_type); + setsflagsval(sflag_bk); + + shm_free(event->req->buf); + shm_free(event->req); + shm_free(event); + } + +done: + return; +} + void m_send_ontimer(unsigned int ticks, void *param) { db_key_t db_keys[2]; @@ -1620,3 +1708,94 @@ int check_message_support(struct sip_msg* msg) return -1; } +#define FAKED_SIP_MSG "MESSAGE %.*s SIP/2.0\r\nVia: SIP/2.0/UDP 127.0.0.1\r\nFrom: <%.*s>;tag=123\r\nTo: <%.*s>\r\nCall-ID: 123\r\n%.*s\r\nCSeq: 1 MESSAGE\r\nContent-Length: 0\r\n\r\n" +#define FAKED_SIP_MSG_LEN (sizeof(FAKED_SIP_MSG)-1) +static unsigned int _faked_msg_no = 1; + +static msilo_notification_event_t *msilo_make_request(str *ruri, str *to, str *from, str *hdr, int mid) +{ + msilo_notification_event_t *ret = NULL; + struct sip_msg *msg = NULL; + char *buff = NULL; + int buff_len = 0; + + if ((ret = shm_malloc(sizeof(msilo_notification_event_t))) == NULL) + { + LM_ERR("Out of pkg memory"); + goto out; + } + + memset(ret, 0, sizeof(msilo_notification_event_t)); + + if ((msg = shm_malloc(sizeof(struct sip_msg))) == NULL) + { + LM_ERR("Out of pkg memory"); + shm_free(ret); + ret = NULL; + goto out; + } + + LM_DBG(">>>>>>> msilo_sip_msg at %p\n", msg); + + memset(msg, 0, sizeof(struct sip_msg)); + + buff_len = FAKED_SIP_MSG_LEN + ruri->len + to->len + from->len + hdr->len + 1; + + if ((buff = shm_malloc(buff_len)) == NULL) + { + LM_ERR("Out of pkg memory"); + shm_free(msg); + shm_free(ret); + ret = NULL; + goto out; + } + + memset(buff, 0, buff_len); + + msg->id = 1 + _faked_msg_no++; + msg->pid = my_pid(); + memset(&msg->tval, 0, sizeof(struct timeval)); + clear_branches(); + + msg->buf = buff; + msg->len = buff_len-1; + + snprintf( msg->buf, buff_len-1, FAKED_SIP_MSG, ruri->len, ruri->s, + from->len, from->s, + to->len, to->s, + hdr->len, hdr->s ); + msg->buf[buff_len-1] = '\0'; + + LM_DBG(">>>>>>> msilo_event_msg[%d]: %s <<<<<<<<", msg->len, msg->buf); + + msg->set_global_address = default_global_address; + msg->set_global_port = default_global_port; + + if (parse_msg(msg->buf, msg->len, msg) != 0) + { + LM_ERR("parse_msg failed\n"); + shm_free(buff); + shm_free(msg); + shm_free(ret); + ret = NULL; + goto out; + } + + msg->rcv.proto = PROTO_UDP; + msg->rcv.src_port = 5060; + msg->rcv.src_ip.u.addr32[0] = 0x7f000001; + msg->rcv.src_ip.af = AF_INET; + msg->rcv.src_ip.len = 4; + msg->rcv.dst_port = 5060; + msg->rcv.dst_ip.u.addr32[0] = 0x7f000001; + msg->rcv.dst_ip.af = AF_INET; + msg->rcv.dst_ip.len = 4; + + ret->req = msg; + ret->mid = mid; + +out: + LM_DBG(">>>>>>> msilo_notification_event %p\n", ret); + return ret; +} +
_______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users