Skip to content

Instantly share code, notes, and snippets.

@IvanRibakov
Created May 7, 2019 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IvanRibakov/3302cb286b1f4b786d109b406f2435a2 to your computer and use it in GitHub Desktop.
Save IvanRibakov/3302cb286b1f4b786d109b406f2435a2 to your computer and use it in GitHub Desktop.
Kamailio in-dialog request from C code
static int requestWithinDialog(char *callId, char *cseqNum, char *fromTag, char *toTag,
char *method, char *ruri, char *from, char *to, char *headers,
txCallback *callbackHandler, void *callbackParam) {
LM_DBG("Call > requestWithinDialog\n");
LM_DBG("Creating new %s request: fromTag: %s, toTag: %s, cseqNum: %s, callID: %s\n",
method, fromTag, toTag, cseqNum, callId);
uac_req_t uac_r;
str methodStr = {method, strlen(method)};
str headersStr = STR_NULL;
if (headers != NULL) {
headersStr.s = headers;
headersStr.len = strlen(headers);
}
str bodyStr = STR_NULL;
set_uac_req(&uac_r,
&methodStr, // method
&headersStr, // headers
&bodyStr, // body
NULL, // dialog
TMCB_LOCAL_COMPLETED, // cb_flags
callbackHandler, // transaction_cb
callbackParam // cb parameter
);
str callIdStr = {strdup(callId), strlen(callId)};
str ruriStr = {strdup(ruri), strlen(ruri)};
str toStr = {to, strlen(to)};
str fromStr = {from, strlen(from)};
str fromTagStr = {fromTag, strlen(fromTag)};
///////////////////////////////////////////////////////
// [Copy-paste START] TM module, uac.c -> req_outisde()
///////////////////////////////////////////////////////
// generate_callid(&callid);
// generate_fromtag(&fromtag, &callIdStr);
int cseq = atoi(cseqNum);
cseq = cseq + 1;
if (tmb.new_dlg_uac(&callIdStr, &fromTagStr, cseq, &fromStr, &toStr, &uac_r.dialog) < 0) {
LM_ERR("Error while initialising dialog with existing dialog parameters\n");
return -1;
}
// Set dialog toTag
uac_r.dialog->id.rem_tag.s = shm_malloc(sizeof(char) * (strlen(toTag) + 1));
strcpy(uac_r.dialog->id.rem_tag.s, toTag);
uac_r.dialog->id.rem_tag.len = strlen(toTag);
if (ruriStr.len > 0) {
uac_r.dialog->rem_target.s = ruriStr.s;
uac_r.dialog->rem_target.len = ruriStr.len;
/* hooks will be set from w_calculate_hooks */
}
//if (next_hop) uac_r->dialog->dst_uri = *next_hop;
tmb.calculate_hooks(uac_r.dialog);
///////////////////////////////////////////////////////
// [Copy-paste END]
///////////////////////////////////////////////////////
int ret = tmb.t_request_within(&uac_r);
ret = (ret >= 0) ? 1 : -1; // Returning 1 if success, -1 otherwise
LM_DBG("requestWithinDialog completed with exit code: %i\n", ret);
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment