Hi,
I'm trying to add a header to SIP messages (for a research project). However, it seems as ser (version 0.8.11pre26) doesn't like my code. Below is the function which is part of a module. It seems as depending on the length of the variable test, ser either crashes or just doesn't send on the full message (truncated after the new header). It sounds a bit like a memory problem. I tried to make sure that memory is properly allocated (thats why the pkg_malloc) and the string is terminated.
I'd be grateful for any pointers!
Thanks, Mario
--
static int exec_pol(struct sip_msg* msg, char* string, char* string2) {
struct lump* anchor; char* nheader; char test[] = "ConType: ABC";
LOG(L_ERR, "PSCON: New Attempt to Add a Header");
if (parse_headers(msg, HDR_EOH, 0) == -1) { LOG(L_ERR, "Error parsing headers"); return 1; }
if(msg->first_line.type == SIP_REQUEST) { anchor = anchor_lump(&msg->add_rm, msg->eoh - msg->buf, 0, 0); if (anchor == 0) { LOG(L_ERR, "Problem with getting anchor"); return 1; }
nheader = pkg_malloc(strlen(test)+1); strcpy(nheader, test); nheader[strlen(test)]=0;
if (insert_new_lump_after(anchor, nheader, strlen(nheader)+1, 0)==0) { LOG(L_ERR, "ERROR: inserting new header"); } }
LOG(L_ERR, "pscon: all fine, returning now ...\n"); return 1; }