int add_maxfwd_header( struct sip_msg* msg , unsigned int val ) { unsigned int len; char *buf; struct lump* anchor; /* double check just to be sure */ if ( msg->maxforwards ) { LOG( L_ERR , "ERROR: add_maxfwd_header :" " MAX_FORWARDS header already exists (%p) !\n",msg->maxforwards); goto error; } /* constructing the header */ len = 14 /*"MAX-FORWARDS: "*/+ CRLF_LEN + 3/*val max on 3 digits*/; buf = (char*)pkg_malloc( len ); if (!buf) { LOG(L_ERR, "ERROR : add_maxfwd_header : " "No memory left\n"); return -1; } memcpy( buf , "Max-Forwards: ", 14 ); len = 14 ; len += btostr( buf+len , val ); memcpy( buf+len , CRLF , CRLF_LEN ); len +=CRLF_LEN; /*inserts the header at the begining of the message*/ anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0 , 0); if (anchor == 0) { LOG(L_ERR, "ERROR: add_maxfwd_header :" " Error, can't get anchor\n"); goto error1; } if (insert_new_lump_before(anchor, buf, len, 0) == 0) { LOG(L_ERR, "ERROR: add_maxfwd_header : " "Error, can't insert MAX-FORWARDS\n"); goto error1; } return 1; error1: pkg_free( buf ); error: return -1; }
int decrement_maxfwd( struct sip_msg* msg , int x, str *mf_val) { int n; /* double check */ if ( !msg->maxforwards ) { LOG( L_ERR , "ERROR: decrement_maxfwd :" " MAX_FORWARDS header not found !\n"); goto error; } /*rewritting the max-fwd value in the message (buf and orig)*/ n = btostr(mf_val->s,x-1); if ( n<mf_val->len ) mf_val->s[n] = ' '; return 1; error: return -1; }
int add_maxfwd_header( struct sip_msg* msg , unsigned int val ) { unsigned int len; char *buf; struct lump* anchor; /* constructing the header */ len = MF_HDR_LEN /*"MAX-FORWARDS: "*/+ CRLF_LEN + 3/*val max on 3 digits*/; buf = (char*)pkg_malloc( len ); if (!buf) { LOG(L_ERR, "ERROR:maxfwd:add_maxfwd_header: no more pkg memory\n"); goto error; } memcpy( buf , MF_HDR, MF_HDR_LEN ); len = MF_HDR_LEN ; len += btostr( buf+len , val ); memcpy( buf+len , CRLF , CRLF_LEN ); len +=CRLF_LEN; /*inserts the header at the beginning of the message*/ anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0 , 0); if (anchor == 0) { LOG(L_ERR, "ERROR:maxfwd:add_maxfwd_header: failed to get anchor\n"); goto error1; } if (insert_new_lump_before(anchor, buf, len, 0) == 0) { LOG(L_ERR, "ERROR:maxfwd:add_maxfwd_header: failed to insert " "MAX-FORWARDS lump\n"); goto error1; } return 1; error1: pkg_free( buf ); error: return -1; }