! \brief * Add a new branch to current transaction */
| 264 | * Add a new branch to current transaction |
| 265 | */ |
| 266 | int append_msg_branch(struct msg_branch *branch) |
| 267 | { |
| 268 | int idx; |
| 269 | struct msg_branch_wrap *new_br; |
| 270 | struct dset_ctx *dsct = get_dset_ctx(); |
| 271 | |
| 272 | if (dsct && !dsct->enabled) |
| 273 | return -1; |
| 274 | |
| 275 | if (dsct==NULL && _dst_malloc(&dsct)<0 ) |
| 276 | return -1; |
| 277 | |
| 278 | idx = dsct->nr_branches; |
| 279 | |
| 280 | /* if we have already set up the maximum number |
| 281 | * of branches, don't try new ones |
| 282 | */ |
| 283 | if (idx == MAX_BRANCHES - 1) { |
| 284 | LM_ERR("max nr of branches exceeded\n"); |
| 285 | ser_error = E_TOO_MANY_BRANCHES; |
| 286 | return -1; |
| 287 | } |
| 288 | |
| 289 | if (idx % DSET_INCREMENT == 0) { |
| 290 | new_br = pkg_realloc(dsct->branches, |
| 291 | (idx + DSET_INCREMENT) * sizeof *dsct->branches); |
| 292 | if (!new_br) { |
| 293 | LM_ERR("oom 2\n"); |
| 294 | return E_OUT_OF_MEM; |
| 295 | } |
| 296 | memset((char *)new_br + idx * sizeof *new_br, 0, |
| 297 | DSET_INCREMENT * sizeof *new_br); |
| 298 | |
| 299 | dsct->branches = new_br; |
| 300 | } |
| 301 | |
| 302 | if (_set_msg_branch( dsct->branches + idx, branch)<0) |
| 303 | return -1; |
| 304 | |
| 305 | dsct->nr_branches++; |
| 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | |
| 310 | /* ! \brief |