MT#10583 support b2bua callback to sip proxy address

pull/69/head
Richard Fuchs 11 years ago
parent 6e32379cab
commit 02d27d5e02

@ -60,8 +60,7 @@ struct iterator_helper {
struct xmlrpc_helper { struct xmlrpc_helper {
enum xmlrpc_format fmt; enum xmlrpc_format fmt;
GStringChunk *c; GStringChunk *c;
char *url; GSList *tags_urls;
GSList *tags;
}; };
struct streamhandler_io { struct streamhandler_io {
@ -1130,18 +1129,22 @@ void xmlrpc_kill_calls(void *p) {
int i = 0; int i = 0;
int status; int status;
str *tag; str *tag;
const char *url;
while (xh->tags) { while (xh->tags_urls && xh->tags_urls->next) {
tag = xh->tags->data; tag = xh->tags_urls->data;
url = xh->tags_urls->next->data;
ilog(LOG_INFO, "Forking child to close call with tag "STR_FORMAT" via XMLRPC", STR_FMT(tag)); ilog(LOG_INFO, "Forking child to close call with tag "STR_FORMAT" via XMLRPC call to %s",
STR_FMT(tag), url);
pid = fork(); pid = fork();
if (pid) { if (pid) {
retry: retry:
pid = waitpid(pid, &status, 0); pid = waitpid(pid, &status, 0);
if ((pid > 0 && WIFEXITED(status) && WEXITSTATUS(status) == 0) || i >= 3) { if ((pid > 0 && WIFEXITED(status) && WEXITSTATUS(status) == 0) || i >= 3) {
xh->tags = g_slist_delete_link(xh->tags, xh->tags); xh->tags_urls = g_slist_delete_link(xh->tags_urls, xh->tags_urls);
xh->tags_urls = g_slist_delete_link(xh->tags_urls, xh->tags_urls);
i = 0; i = 0;
} }
else { else {
@ -1181,11 +1184,11 @@ retry:
r = NULL; r = NULL;
switch (xh->fmt) { switch (xh->fmt) {
case XF_SEMS: case XF_SEMS:
xmlrpc_client_call2f(&e, c, xh->url, "di", &r, "(ssss)", xmlrpc_client_call2f(&e, c, url, "di", &r, "(ssss)",
"sbc", "postControlCmd", tag->s, "teardown"); "sbc", "postControlCmd", tag->s, "teardown");
break; break;
case XF_CALLID: case XF_CALLID:
xmlrpc_client_call2f(&e, c, xh->url, "teardown", &r, "(s)", tag->s); xmlrpc_client_call2f(&e, c, url, "teardown", &r, "(s)", tag->s);
break; break;
} }
@ -1195,7 +1198,8 @@ retry:
goto fault; goto fault;
xmlrpc_client_destroy(c); xmlrpc_client_destroy(c);
xh->tags = g_slist_delete_link(xh->tags, xh->tags); xh->tags_urls = g_slist_delete_link(xh->tags_urls, xh->tags_urls);
xh->tags_urls = g_slist_delete_link(xh->tags_urls, xh->tags_urls);
xmlrpc_env_clean(&e); xmlrpc_env_clean(&e);
_exit(0); _exit(0);
@ -1213,8 +1217,9 @@ void kill_calls_timer(GSList *list, struct callmaster *m) {
struct call *ca; struct call *ca;
GSList *csl; GSList *csl;
struct call_monologue *cm; struct call_monologue *cm;
const char *url; const char *url, *url_prefix, *url_suffix;
struct xmlrpc_helper *xh = NULL; struct xmlrpc_helper *xh = NULL;
char addr[64], url_buf[128];
if (!list) if (!list)
return; return;
@ -1224,8 +1229,15 @@ void kill_calls_timer(GSList *list, struct callmaster *m) {
if (url) { if (url) {
xh = g_slice_alloc(sizeof(*xh)); xh = g_slice_alloc(sizeof(*xh));
xh->c = g_string_chunk_new(64); xh->c = g_string_chunk_new(64);
xh->url = g_string_chunk_insert(xh->c, url); url_prefix = NULL;
xh->tags = NULL; url_suffix = strstr(url, "%%");
if (url_suffix) {
url_prefix = g_string_chunk_insert_len(xh->c, url, url_suffix - url);
url_suffix = g_string_chunk_insert(xh->c, url_suffix + 2);
}
else
url_suffix = g_string_chunk_insert(xh->c, url);
xh->tags_urls = NULL;
xh->fmt = m->conf.fmt; xh->fmt = m->conf.fmt;
} }
@ -1237,17 +1249,27 @@ void kill_calls_timer(GSList *list, struct callmaster *m) {
rwlock_lock_r(&ca->master_lock); rwlock_lock_r(&ca->master_lock);
if (url_prefix) {
smart_ntop_p(addr, &ca->created_from_addr.sin6_addr, sizeof(addr));
snprintf(url_buf, sizeof(url_buf), "%s%s%s",
url_prefix, addr, url_suffix);
}
else
snprintf(url_buf, sizeof(url_buf), "%s", url_suffix);
switch (m->conf.fmt) { switch (m->conf.fmt) {
case XF_SEMS: case XF_SEMS:
for (csl = ca->monologues; csl; csl = csl->next) { for (csl = ca->monologues; csl; csl = csl->next) {
cm = csl->data; cm = csl->data;
if (cm->tag.s && cm->tag.len) { if (cm->tag.s && cm->tag.len) {
xh->tags = g_slist_prepend(xh->tags, str_chunk_insert(xh->c, &cm->tag)); xh->tags_urls = g_slist_prepend(xh->tags_urls, g_string_chunk_insert(xh->c, url_buf));
xh->tags_urls = g_slist_prepend(xh->tags_urls, str_chunk_insert(xh->c, &cm->tag));
} }
} }
break; break;
case XF_CALLID: case XF_CALLID:
xh->tags = g_slist_prepend(xh->tags, str_chunk_insert(xh->c, &ca->callid)); xh->tags_urls = g_slist_prepend(xh->tags_urls, g_string_chunk_insert(xh->c, url_buf));
xh->tags_urls = g_slist_prepend(xh->tags_urls, str_chunk_insert(xh->c, &ca->callid));
break; break;
} }

Loading…
Cancel
Save