/** internal print uri into rpc reply function. * Prints the uris into rpc reply. It's used internally by * rpc_uac_callback(). * @param rpc * @param c - rpc context * @param reply - sip reply */ static void rpc_print_uris(rpc_t* rpc, void* c, struct sip_msg* reply) { dlg_t* dlg; dlg=shm_malloc(sizeof(dlg_t)); if (dlg==0){ ERR("out of memory (shm)\n"); return; } memset(dlg, 0, sizeof(dlg_t)); if (dlg_response_uac(dlg, reply, TARGET_REFRESH_UNKNOWN) < 0) { LM_ERR("failure while filling dialog structure\n"); free_dlg(dlg); return; } if (dlg->state != DLG_CONFIRMED) { free_dlg(dlg); return; } if (dlg->hooks.request_uri->s){ rpc->add(c, "S", dlg->hooks.request_uri); }else{ rpc->add(c, "s", ""); } if (dlg->hooks.next_hop->s) { rpc->add(c, "S", dlg->hooks.next_hop); } else { rpc->add(c, "s", ""); } rpc_print_routes(rpc, c, dlg); free_dlg(dlg); return; }
/* * Establishing a new dialog, UAS side */ int new_dlg_uas(struct sip_msg* _req, int _code, /*str* _tag,*/ dlg_t** _d) { dlg_t* res; str tag; if (!_req || /*!_tag ||*/ !_d) { LOG(L_ERR, "new_dlg_uas(): Invalid parameter value\n"); return -1; } if (_code > 299) { DBG("new_dlg_uas(): Status code >= 300, no dialog created\n"); } res = (dlg_t*)shm_malloc(sizeof(dlg_t)); if (res == 0) { LOG(L_ERR, "new_dlg_uac(): No memory left\n"); return -3; } /* Clear everything */ memset(res, 0, sizeof(dlg_t)); if (request2dlg(_req, res) < 0) { LOG(L_ERR, "new_dlg_uas(): Error while converting request to dialog\n"); free_dlg(res); return -4; } if (_code > 100) { tag.s = tm_tags; tag.len = TOTAG_VALUE_LEN; calc_crc_suffix(_req, tm_tag_suffix); if (str_duplicate(&res->id.loc_tag, &tag) < 0) { free_dlg(res); return -5; } } *_d = res; if (_code < 100) (*_d)->state = DLG_NEW; else if (_code < 200) (*_d)->state = DLG_EARLY; else (*_d)->state = DLG_CONFIRMED; if (calculate_hooks(*_d) < 0) { LOG(L_ERR, "new_dlg_uas(): Error while calculating hooks\n"); free_dlg(res); return -6; } #ifdef DIALOG_CALLBACKS run_new_dlg_callbacks(DLG_CB_UAS, res, _req); #endif return 0; }
/* * Send a transactional request, no dialogs involved */ int request(str* m, str* ruri, str* to, str* from, str* h, str* b, transaction_cb c, void* cp) { str callid, fromtag; dlg_t* dialog; int res; if (check_params(m, to, from, &dialog) < 0) goto err; generate_callid(&callid); generate_fromtag(&fromtag, &callid); if (new_dlg_uac(&callid, &fromtag, DEFAULT_CSEQ, from, to, &dialog) < 0) { LOG(L_ERR, "req_outside(): Error while creating temorary dialog\n"); goto err; } if (ruri) { dialog->rem_target.s = ruri->s; dialog->rem_target.len = ruri->len; dialog->hooks.request_uri = &dialog->rem_target; } res = t_uac(m, h, b, dialog, c, cp); dialog->rem_target.s = 0; free_dlg(dialog); return res; err: if (cp) shm_free(cp); return -1; }
/* * Send a transactional request, no dialogs involved */ int request(str* m, str* ruri, str* to, str* from, str* h, str* b, str *oburi, transaction_cb cb, void* cbp,release_tmcb_param release_func) { str callid, fromtag; dlg_t* dialog; int res; if (check_params(m, to, from, &dialog) < 0) goto err; generate_callid(&callid); generate_fromtag(&fromtag, &callid); if (new_dlg_uac(&callid, &fromtag, DEFAULT_CSEQ, from, to, &dialog) < 0) { LM_ERR("failed to create temporary dialog\n"); goto err; } if (ruri) { dialog->rem_target.s = ruri->s; dialog->rem_target.len = ruri->len; dialog->hooks.request_uri = &dialog->rem_target; } if (oburi && oburi->s) dialog->hooks.next_hop = oburi; w_calculate_hooks(dialog); res = t_uac(m, h, b, dialog, cb, cbp, release_func); dialog->rem_target.s = 0; free_dlg(dialog); return res; err: return -1; }
/* * Send a transactional request, no dialogs involved * WARNING: writes uac_r->dialog */ int request(uac_req_t *uac_r, str* ruri, str* to, str* from, str *next_hop) { str callid, fromtag; dlg_t* dialog; int res; if (check_params(uac_r, to, from) < 0) goto err; if (uac_r->callid == NULL || uac_r->callid->len <= 0) generate_callid(&callid); else callid = *uac_r->callid; generate_fromtag(&fromtag, &callid); if (new_dlg_uac(&callid, &fromtag, DEFAULT_CSEQ, from, to, &dialog) < 0) { LOG(L_ERR, "request(): Error while creating temporary dialog\n"); goto err; } if (ruri) { dialog->rem_target.s = ruri->s; dialog->rem_target.len = ruri->len; /* hooks will be set from w_calculate_hooks */ } if (next_hop) dialog->dst_uri = *next_hop; w_calculate_hooks(dialog); /* WARNING: * to be clean it should be called * set_dlg_target(dialog, ruri, next_hop); * which sets both uris if given [but it duplicates them in shm!] * * but in this case the _ruri parameter in set_dlg_target * must be optional (it is needed now) and following hacks * dialog->rem_target.s = 0; * dialog->dst_uri.s = 0; * before freeing dialog here must be removed */ uac_r->dialog = dialog; if(uac_r->ssock!=NULL && uac_r->ssock->len>0 && uac_r->dialog->send_sock==NULL) { /* set local send socket */ uac_r->dialog->send_sock = lookup_local_socket(uac_r->ssock); } res = t_uac(uac_r); dialog->rem_target.s = 0; dialog->dst_uri.s = 0; free_dlg(dialog); uac_r->dialog = 0; return res; err: /* callback parameter must be freed outside of tm module if (cp) shm_free(cp); */ return -1; }
/* * Send a transactional request, no dialogs involved */ int request(str* m, str* ruri, str* to, str* from, str* h, str* b, str *next_hop, transaction_cb c, void* cp) { str callid, fromtag; dlg_t* dialog; int res; if (check_params(m, to, from, &dialog) < 0) goto err; generate_callid(&callid); generate_fromtag(&fromtag, &callid); if (new_dlg_uac(&callid, &fromtag, DEFAULT_CSEQ, from, to, &dialog) < 0) { LOG(L_ERR, "request(): Error while creating temporary dialog\n"); goto err; } if (ruri) { dialog->rem_target.s = ruri->s; dialog->rem_target.len = ruri->len; /* hooks will be set from w_calculate_hooks */ } if (next_hop) dialog->dst_uri = *next_hop; w_calculate_hooks(dialog); /* WARNING: * to be clean it should be called * set_dlg_target(dialog, ruri, next_hop); * which sets both uris if given [but it duplicates them in shm!] * * but in this case the _ruri parameter in set_dlg_target * must be optional (it is needed now) and following hacks * dialog->rem_target.s = 0; * dialog->dst_uri.s = 0; * before freeing dialog here must be removed */ res = t_uac(m, h, b, dialog, c, cp); dialog->rem_target.s = 0; dialog->dst_uri.s = 0; free_dlg(dialog); return res; err: if (cp) shm_free(cp); return -1; }