inline int add_contact(struct sip_msg* msg , str* user) { struct lump_rpl *lump; char *buf, *p; int len; len = 9 /*"Contact: "*/ + user->len/*user*/ + 1 /*"@"*/ + domain.len/*host*/ + 6/*"<sip:>"*/ + CRLF_LEN; buf = pkg_malloc( len ); if(!buf) { LM_ERR("out of memory! \n"); return -1; } p = buf; append_str( p, "Contact: " , 9); append_str( p, "<sip:" , 5); append_str( p, user->s, user->len); *(p++) = '@'; append_str( p, domain.s, domain.len); *(p++) = '>'; append_str( p, CRLF, CRLF_LEN); lump = build_lump_rpl( buf , len , LUMP_RPL_HDR); if(!lump) { LM_ERR("unable to build lump_rpl! \n"); pkg_free( buf ); return -1; } add_lump_rpl( msg , lump ); pkg_free(buf); return 1; }
static int cpl_update_contact(struct sip_msg* msg, char* str1, char* str2) { TRedirectMessage *redirect; struct lump_rpl *lump; char *buf, *p; int len; int i; if (resp_code!=REDIRECT_CALL || !resp_buf || !resp_len) return -1; redirect = parseRedirectResponse( resp_buf , resp_len ); printRedirectMessage( redirect ); len = 9 /*"Contact: "*/; /* locations*/ for( i=0 ; i<redirect->numberOfLocations; i++) len += 2/*"<>"*/ + redirect->locations[i].urlLength; len += redirect->numberOfLocations -1 /*","*/; len += CRLF_LEN; buf = pkg_malloc( len ); if(!buf) { LOG(L_ERR,"ERROR:cpl_update_contact: out of memory! \n"); return -1; } p = buf; memcpy( p , "Contact: " , 9); p += 9; for( i=0 ; i<redirect->numberOfLocations; i++) { if (i) *(p++)=','; *(p++) = '<'; memcpy(p,redirect->locations[i].URL,redirect->locations[i].urlLength); p += redirect->locations[i].urlLength; *(p++) = '>'; } memcpy(p,CRLF,CRLF_LEN); lump = build_lump_rpl( buf , len , LUMP_RPL_HDR); if(!buf) { LOG(L_ERR,"ERROR:cpl_update_contact: unable to build lump_rpl! \n"); pkg_free( buf ); return -1; } add_lump_rpl( msg , lump ); freeRedirectMessage( redirect ); pkg_free(buf); return 1; }