MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / t_get_branch_idx_by_attr

Function t_get_branch_idx_by_attr

modules/tm/tm.c:1826–1911  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1824
1825
1826static int t_get_branch_idx_by_attr(struct sip_msg* msg,
1827 str* attr, str* val_s, int *val_i, pv_spec_t *result, int *offset)
1828{
1829 struct cell *t;
1830 int attr_id;
1831 int branch;
1832 struct usr_avp *avp;
1833 int_str avp_val;
1834 pv_value_t ret_val, in_val;
1835
1836 t=get_t();
1837
1838 if (t==NULL || t==T_UNDEFINED) {
1839 /* no transaction */
1840 return -2;
1841 }
1842
1843 if ( (attr_id=get_avp_id(attr))<0 ) {
1844 LM_ERR("failed to get ID for the <%.*s> attribute\n",
1845 attr->len,attr->s);
1846 return -2;
1847 }
1848 memset(&in_val, 0, sizeof in_val);
1849
1850 if (val_s) {
1851 in_val.flags = PV_VAL_STR;
1852 in_val.rs = *val_s;
1853 } else if (val_i) {
1854 in_val.flags = PV_VAL_INT;
1855 in_val.ri = *val_i;
1856 } else {
1857 in_val.flags = PV_VAL_NULL;
1858 }
1859
1860 for ( branch=offset?*offset:0 ; branch<t->nr_of_outgoings ; branch++) {
1861 /* iterate the attrs for matching the name */
1862 for ( avp=TM_BRANCH(t,branch).battrs ; avp ; avp=avp->next) {
1863 if (attr_id == avp->id) {
1864 /* attr name matching */
1865 if (val_s==NULL && val_i==NULL) {
1866 /* no value searched , so we have a finding here */
1867 get_avp_val( avp, &avp_val );
1868 break;
1869 } else {
1870 get_avp_val( avp, &avp_val );
1871 /* do some complex matching between the pv_value and AVP */
1872 if ( (avp->flags&AVP_VAL_NULL && in_val.flags&PV_VAL_NULL)
1873 || /* ^^^^ both values are null */
1874 (!(avp->flags&AVP_VAL_STR) && in_val.flags&PV_VAL_INT &&
1875 avp_val.n==in_val.ri )
1876 || /* ^^^^ both values are int */
1877 (avp->flags&AVP_VAL_STR && in_val.flags&PV_VAL_STR &&
1878 str_match(&avp_val.s,&in_val.rs)==1)
1879 ) { /* ^^^^ both values are str */
1880 /* we have a matching */
1881 break;
1882 }
1883 }

Callers

nothing calls this directly

Calls 5

get_tFunction · 0.85
get_avp_idFunction · 0.85
get_avp_valFunction · 0.85
str_matchFunction · 0.85
pv_set_valueFunction · 0.85

Tested by

no test coverage detected