@grumvalski done, I've merged similar functionality in ts_append.c implementation. tsilo.c implementation has been updated accordingly. Can you please check out and see if it can be merged like that? I have tested usage of kamailio's script functions ts_append() and ts_append_by_contact() with a new code, and it worked fine.
P.S.: Previously I had an intention to keep as much back-compatibility as possible to let the new code be not overlapping with previously existing.
---
@henningw TM's part had been updated previously as requested. Could you please have a look? Thank you. (Please remember, it looks like t_append_branches() function is only used by TSILO now).