diff --git a/src/modules/tsilo/ts_append.c b/src/modules/tsilo/ts_append.c index e4967f8167a..2781deffc42 100644 --- a/src/modules/tsilo/ts_append.c +++ b/src/modules/tsilo/ts_append.c @@ -36,26 +36,37 @@ #include "ts_hash.h" #include "ts_append.h" -int ts_append(struct sip_msg* msg, str *ruri, char *table) { +int ts_append(struct sip_msg* msg, str *ruri, str *contact, char *table) { ts_urecord_t* _r; ts_transaction_t* ptr; struct sip_uri p_uri; + struct sip_uri c_uri; str *t_uri; int res; int appended; - + + /* parse R-URI */ if (use_domain) { t_uri = ruri; } else { - if(parse_uri(ruri->s, ruri->len, &p_uri)<0) { + if(parse_uri(ruri->s, ruri->len, &p_uri) < 0) { LM_ERR("failed to parse uri %.*s\n", ruri->len, ruri->s); return -1; } t_uri = &p_uri.user; } + /* parse contact if given */ + if(contact->s != NULL && contact->len != 0) { + if (parse_uri(contact->s, contact->len, &c_uri) < 0) { + LM_ERR("failed to parse contact %.*s\n", ruri->len, ruri->s); + return -1; + } + } + + /* find urecord in TSILO cache */ lock_entry_by_ruri(t_uri); res = get_ts_urecord(t_uri, &_r); @@ -66,12 +77,13 @@ int ts_append(struct sip_msg* msg, str *ruri, char *table) { return -1; } + /* cycle through existing transactions */ ptr = _r->transactions; while(ptr) { LM_DBG("transaction %u:%u found for %.*s, going to append branches\n",ptr->tindex, ptr->tlabel, t_uri->len, t_uri->s); - appended = ts_append_to(msg, ptr->tindex, ptr->tlabel, table, ruri); + appended = ts_append_to(msg, ptr->tindex, ptr->tlabel, table, ruri, contact); if (appended > 0) update_stat(added_branches, appended); ptr = ptr->next; @@ -82,27 +94,28 @@ int ts_append(struct sip_msg* msg, str *ruri, char *table) { return 1; } -int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *uri) { +int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *uri, str *contact) { struct cell *t=0; - struct cell *orig_t; + struct cell *orig_t; /* a pointer to an existing transaction or 0 if lookup fails */ struct sip_msg *orig_msg; int ret; str stable; - str contact; /* needed for usage of TM's API, t_append_branches() */ - contact.s = NULL; /* must be emptied */ - contact.len = 0; + if(contact->s!=NULL && contact->len > 0) { + LM_DBG("trying to append based on specific contact <%.*s>\n", contact->len, contact->s); + } + /* lookup a transaction based on its identifier (hash_index:label) */ orig_t = _tmb.t_gett(); if(_tmb.t_lookup_ident(&t, tindex, tlabel) < 0) { - LM_ERR("transaction [%u:%u] not found\n", - tindex, tlabel); + LM_ERR("transaction [%u:%u] not found\n", tindex, tlabel); ret = -1; goto done; } + /* check if the dialog is still in the early stage */ if (t->flags & T_CANCELED) { LM_DBG("trasaction [%u:%u] was cancelled\n", tindex, tlabel); @@ -117,119 +130,6 @@ int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str * goto done; } - orig_msg = t->uas.request; - - stable.s = table; - stable.len = strlen(stable.s); - if(uri==NULL || uri->s==NULL || uri->len<=0) { - ret = _regapi.lookup_to_dset(orig_msg, &stable, NULL); - } else { - ret = _regapi.lookup_to_dset(orig_msg, &stable, uri); - } - - if(ret != 1) { - LM_DBG("transaction %u:%u: error updating dset (%d)\n", tindex, tlabel, ret); - ret = -4; - goto done; - } - - ret = _tmb.t_append_branches(&contact); - -done: - /* unref the transaction which had been referred by t_lookup_ident() call. - * Restore the original transaction (if any) */ - if(t) _tmb.unref_cell(t); - _tmb.t_sett(orig_t, T_BR_UNDEFINED); - - return ret; -} - -int ts_append_by_contact(struct sip_msg* msg, str *ruri, str *contact, char *table) { - ts_urecord_t* _r; - ts_transaction_t* ptr; - - struct sip_uri p_uri; - struct sip_uri c_uri; - str *t_uri; - - int res; - int appended; - - /* parse R-URI */ - if (use_domain) { - t_uri = ruri; - } else { - if (parse_uri(ruri->s, ruri->len, &p_uri) < 0) { - LM_ERR("tsilo: failed to parse uri %.*s\n", ruri->len, ruri->s); - return -1; - } - t_uri = &p_uri.user; - } - - /* parse contact */ - if (parse_uri(contact->s, contact->len, &c_uri) < 0) { - LM_ERR("tsilo: failed to parse contact %.*s\n", ruri->len, ruri->s); - return -1; - } - - /* find urecord in TSILO cache */ - lock_entry_by_ruri(t_uri); - res = get_ts_urecord(t_uri, &_r); - - if (res != 0) { - LM_ERR("tsilo: failed to retrieve record for %.*s\n", t_uri->len, t_uri->s); - unlock_entry_by_ruri(t_uri); - return -1; - } - - /* cycle through existing transactions */ - ptr = _r->transactions; - while(ptr) { - LM_DBG("tsilo: transaction %u:%u found for %.*s, going to append branches\n", - ptr->tindex, ptr->tlabel, t_uri->len, t_uri->s); - /* append only if the desired contact has been found in locations */ - appended = ts_append_by_contact_to(msg, ptr->tindex, ptr->tlabel, table, ruri, contact); - if (appended > 0) - update_stat(added_branches, appended); - ptr = ptr->next; - } - - unlock_entry_by_ruri(t_uri); - - return 1; -} - -int ts_append_by_contact_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *uri, str *contact) { - struct cell *t=0; - struct cell *orig_t; /* a pointer to an existing transaction or 0 if lookup fails*/ - struct sip_msg *orig_msg; - int ret; - str stable; - - LM_DBG("tsilo: trying to append based on contact <%.*s>\n", contact->len, contact->s); - - /* lookup a transaction based on its identifier (hash_index:label) */ - orig_t = _tmb.t_gett(); - if(_tmb.t_lookup_ident(&t, tindex, tlabel) < 0) - { - LM_ERR("tsilo: transaction [%u:%u] not found\n", tindex, tlabel); - ret = -1; - goto done; - } - - /* check if the dialog is still in the early stage */ - if (t->flags & T_CANCELED) { - LM_DBG("tsilo: trasaction [%u:%u] was cancelled\n", tindex, tlabel); - ret = -2; - goto done; - } - if (t->uas.status >= 200) { - LM_DBG("tsilo: trasaction [%u:%u] sent out a final response already - %d\n", - tindex, tlabel, t->uas.status); - ret = -3; - goto done; - } - /* get original (very first) request of the transaction */ orig_msg = t->uas.request; stable.s = table; @@ -242,13 +142,13 @@ int ts_append_by_contact_to(struct sip_msg* msg, int tindex, int tlabel, char *t } if(ret != 1) { - LM_ERR("tsilo: transaction %u:%u: error updating dset (%d)\n", tindex, tlabel, ret); + LM_ERR("transaction %u:%u: error updating dset (%d)\n", tindex, tlabel, ret); ret = -4; goto done; } - /* start the transaction only for the desired contact - contact must be of syntax: sip:@: with no parameters list*/ + /* if the contact has been given previously + then do a new append only for the desired location */ ret = _tmb.t_append_branches(contact); done: diff --git a/src/modules/tsilo/ts_append.h b/src/modules/tsilo/ts_append.h index 461f8881f3e..02f3244b273 100644 --- a/src/modules/tsilo/ts_append.h +++ b/src/modules/tsilo/ts_append.h @@ -22,9 +22,7 @@ #ifndef _TS_APPEND_H #define _TS_APPEND_H -int ts_append(struct sip_msg* msg, str *ruri, char *table); -int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *uri); -int ts_append_by_contact(struct sip_msg* msg, str *ruri, str *contact, char *table); -int ts_append_by_contact_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *uri, str *contact); +int ts_append(struct sip_msg* msg, str *ruri, str *contact, char *table); +int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *uri, str *contact); #endif diff --git a/src/modules/tsilo/tsilo.c b/src/modules/tsilo/tsilo.c index 2eefb2fe2d0..9769a3c7d81 100644 --- a/src/modules/tsilo/tsilo.c +++ b/src/modules/tsilo/tsilo.c @@ -275,6 +275,9 @@ static int w_ts_append(struct sip_msg* _msg, char *_table, char *_ruri) str ruri = STR_NULL; int rc; + /* we do not want to do append by particular location */ + str contact = STR_NULL; + if(_ruri==NULL || (fixup_get_svalue(_msg, (gparam_p)_ruri, &tmp)!=0 || tmp.len<=0)) { LM_ERR("invalid ruri parameter\n"); return -1; @@ -285,7 +288,7 @@ static int w_ts_append(struct sip_msg* _msg, char *_table, char *_ruri) if (pkg_str_dup(&ruri, &tmp) < 0) return -1; - rc = ts_append(_msg, &ruri, _table); + rc = ts_append(_msg, &ruri, &contact, _table); pkg_free(ruri.s); @@ -300,13 +303,16 @@ static int ki_ts_append(sip_msg_t* _msg, str *_table, str *_ruri) str ruri = STR_NULL; int rc; + /* we do not want to do append by particular location */ + str contact = STR_NULL; + if(ts_check_uri(_ruri)<0) return -1; if (pkg_str_dup(&ruri, _ruri) < 0) return -1; - rc = ts_append(_msg, &ruri, _table->s); + rc = ts_append(_msg, &ruri, &contact, _table->s); pkg_free(ruri.s); @@ -321,6 +327,9 @@ static int w_ts_append_to(struct sip_msg* msg, char *idx, char *lbl, char *table unsigned int tindex; unsigned int tlabel; + /* we do not want to do append by particular location */ + str contact = STR_NULL; + if(fixup_get_ivalue(msg, (gparam_p)idx, (int*)&tindex)<0) { LM_ERR("cannot get transaction index\n"); return -1; @@ -331,7 +340,8 @@ static int w_ts_append_to(struct sip_msg* msg, char *idx, char *lbl, char *table return -1; } - return ts_append_to(msg, tindex, tlabel, table, 0); + /* we do not want to do append by particular location here */ + return ts_append_to(msg, tindex, tlabel, table, 0, &contact); } /** @@ -339,8 +349,12 @@ static int w_ts_append_to(struct sip_msg* msg, char *idx, char *lbl, char *table */ static int ki_ts_append_to(sip_msg_t* _msg, int tindex, int tlabel, str *_table) { + /* we do not want to do append by particular location */ + str contact = STR_NULL; + + /* we do not want to do append by particular location here */ return ts_append_to(_msg, (unsigned int)tindex, (unsigned int)tlabel, - _table->s, 0); + _table->s, 0, &contact); } /** @@ -352,6 +366,9 @@ static int w_ts_append_to2(struct sip_msg* msg, char *idx, char *lbl, char *tabl unsigned int tlabel; str suri; + /* we do not want to do append by particular location */ + str contact = STR_NULL; + if(fixup_get_ivalue(msg, (gparam_p)idx, (int*)&tindex)<0) { LM_ERR("cannot get transaction index\n"); return -1; @@ -369,7 +386,8 @@ static int w_ts_append_to2(struct sip_msg* msg, char *idx, char *lbl, char *tabl if(ts_check_uri(&suri)<0) return -1; - return ts_append_to(msg, tindex, tlabel, table, &suri); + /* we do not want to do append by particular location here */ + return ts_append_to(msg, tindex, tlabel, table, &suri, &contact); } /** @@ -378,8 +396,12 @@ static int w_ts_append_to2(struct sip_msg* msg, char *idx, char *lbl, char *tabl static int ki_ts_append_to_uri(sip_msg_t* _msg, int tindex, int tlabel, str *_table, str *_uri) { + /* we do not want to do append by particular location */ + str contact = STR_NULL; + + /* we do not want to do append by particular location here */ return ts_append_to(_msg, (unsigned int)tindex, (unsigned int)tlabel, - _table->s, _uri); + _table->s, _uri, &contact); } /** @@ -455,7 +477,7 @@ static int w_ts_append_by_contact2(struct sip_msg* _msg, char *_table, char *_ru } /* contact must be of syntax: sip:@: with no parameters list */ - rc = ts_append_by_contact(_msg, &ruri, &contact, _table); + rc = ts_append(_msg, &ruri, &contact, _table); /* free previously used memory */ pkg_free(ruri.s); @@ -512,7 +534,7 @@ static int ki_ts_append_by_contact(sip_msg_t* _msg, str *_table, str *_ruri) { } /* contact must be of syntax: sip:@: with no parameters list */ - rc = ts_append_by_contact(_msg, &ruri, &contact, _table->s); + rc = ts_append(_msg, &ruri, &contact, _table->s); pkg_free(ruri.s); pkg_free(contact.s); @@ -576,7 +598,7 @@ static int w_ts_append_by_contact3(struct sip_msg* _msg, char *_table, char *_ru } /* contact must be of syntax: sip:@: with no parameters list */ - rc = ts_append_by_contact(_msg, &ruri, &contact, _table); + rc = ts_append(_msg, &ruri, &contact, _table); pkg_free(ruri.s); pkg_free(contact.s); @@ -606,7 +628,7 @@ static int ki_ts_append_by_contact_uri(sip_msg_t* _msg, str *_table, str *_ruri, return -1; /* contact must be of syntax: sip:@: with no parameters list */ - rc = ts_append_by_contact(_msg, &ruri, &contact, _table->s); + rc = ts_append(_msg, &ruri, &contact, _table->s); pkg_free(ruri.s); pkg_free(contact.s);