| 2090 | |
| 2091 | |
| 2092 | static int pv_get_branch_fields(struct sip_msg *msg, pv_param_t *param, |
| 2093 | pv_value_t *res) |
| 2094 | { |
| 2095 | int size; |
| 2096 | int idx; |
| 2097 | int idxf; |
| 2098 | char *p; |
| 2099 | |
| 2100 | if(msg==NULL || res==NULL) |
| 2101 | return -1; |
| 2102 | |
| 2103 | if ( (size=get_dset_size()) == 0) |
| 2104 | return pv_get_null(msg, param, res); |
| 2105 | |
| 2106 | /* get the index */ |
| 2107 | if(pv_get_spec_index(msg, param, &idx, &idxf)!=0) { |
| 2108 | LM_ERR("invalid index\n"); |
| 2109 | return -1; |
| 2110 | } |
| 2111 | |
| 2112 | if (idxf!=PV_IDX_ALL && idx==0) { |
| 2113 | /* no index specified -> return the first branch */ |
| 2114 | return get_branch_field( 0, param->pvn.u.isname.name.n, res); |
| 2115 | } |
| 2116 | |
| 2117 | if(idxf==PV_IDX_ALL) { |
| 2118 | /* return all branches */ |
| 2119 | p = pv_local_buf; |
| 2120 | idx = 0; |
| 2121 | |
| 2122 | while ( idx<size ) { |
| 2123 | |
| 2124 | get_branch_field( idx, param->pvn.u.isname.name.n, res); |
| 2125 | |
| 2126 | if ( pv_local_buf + PV_LOCAL_BUF_SIZE <= |
| 2127 | p + res->rs.len + PV_FIELD_DELIM_LEN ) { |
| 2128 | LM_ERR("local buffer length exceeded\n"); |
| 2129 | return pv_get_null(msg, param, res); |
| 2130 | } |
| 2131 | |
| 2132 | if (idx) { |
| 2133 | memcpy(p, PV_FIELD_DELIM, PV_FIELD_DELIM_LEN); |
| 2134 | p += PV_FIELD_DELIM_LEN; |
| 2135 | } |
| 2136 | |
| 2137 | memcpy(p, res->rs.s, res->rs.len); |
| 2138 | p += res->rs.len; |
| 2139 | idx++; |
| 2140 | } |
| 2141 | |
| 2142 | res->rs.s = pv_local_buf; |
| 2143 | res->rs.len = p - pv_local_buf; |
| 2144 | res->flags = PV_VAL_STR; |
| 2145 | return 0; |
| 2146 | } |
| 2147 | |
| 2148 | /* numerical index */ |
| 2149 | if (idx<0) { |
nothing calls this directly
no test coverage detected