Hello,<br><br>I'm an undergrad working on a research project.<br><br>This project involved the modification of several header fields depending on various factors. At this point, I've been able to remove the supplied display name and replace it with "unverified". But, I'm stuck on how to add a display name to the from header when the UAC does not supply one.<br>
<br>My code closely follows the work done in the uac module already in opensips. It works perfectly when a display name is present but when it is not present it adds garbage to the display field.<br><br>For instance, wireshark shows my from field to be<br>
<br>From: "unverified" <.. .....1..........*d..........*d........1.0.....1.......<br>......f........f....................1...........25f<br>@........................Q..............|..............1..1....1...sip:john@mydomain>;tag=f04dda0088604f4892aed058306835e5<br>
<br>I'm fairly certain that I may not be setting my anchor point correctly since I'm not quite sure how the offset is calculated.<br><br>1. When a field is to be modified <i>[for instance the display field in the from header in the get_display_anchor function below]</i>, Why is the anchor set at an (address - msg->buf)? In the case of get_display_anchor, it uses the pointer to the first char (<) in
the uri minus the msg->buf. Also, please note that QjSimple does not send the usually <i><sip:john@mydomain></i> but sends <i>john@mydomain</i>. <br><br>When I looked in msg_parser.c, it says that the msg->buf variable is a scratch variable. So the only thing I can assume is that the pointer to first char is not pointing at the real header field in memory but is pointing a scratch address within the msg->buf so if you substract the size of msg->buf it will point to the real variable address.<br>
<br>2. When using the lump_struct to add, remove or insert headers, when is that operation executed?<br><br>Thank you for all your help.<br><br>John <br><br><br>Please see the function get_display_anchor from uac_replace.c below:<br>
<br>static struct lump* get_display_anchor(struct sip_msg *msg,<br> struct hdr_field *hdr, struct to_body *body, str *dsp)<br>{<br> LM_INFO("Entering.....");<br><br> LM_INFO("Header Field=%.*s\n", hdr->body.len, hdr->body.s);<br>
LM_INFO("Body=%.*s\n", body->display.len, body->display.s);<br> LM_INFO("DSP=%.*s\n", dsp->len, dsp->s);<br> <br> struct lump* l;<br> char *p1;<br> char *p2;<br><br> /* is URI quoted or not? */<br>
p1 = hdr->name.s + hdr->name.len;<br><br> for( p2=body->uri.s-1 ; p2>=p1 && *p2!='<' ; p2--);<br><br><br> if (*p2=='<') {<br> LM_INFO("Is quoted ");<br>
l = anchor_lump( msg,<b> p2 - msg->buf</b>, 0, 0); // why p2 - msg->buff ??<br> if (l==0) {<br> LM_ERR("unable to build lump anchor\n");<br> return 0;<br> }<br>
dsp->s[dsp->len++] = ' ';<br> return l;<br> }<br><br> /* not quoted - more complicated....must place the closing bracket */<br> l = anchor_lump( msg, (body->uri.s+body->uri.len) - msg->buf, 0, 0);<br>
if (l==0) {<br> LM_ERR("unable to build lump anchor\n");<br> return 0;<br> }<br> p1 = (char*)pkg_malloc(1);<br> if (p1==0) {<br> LM_ERR("no more pkg mem \n");<br> return 0;<br>
}<br> *p1 = '>';<br><br><br><br> if (insert_new_lump_after( l, p1, 1, 0)==0) {<br> LM_ERR("insert lump failed\n");<br> pkg_free(p1);<br> return 0;<br> }<br> /* build anchor for display */<br>
l = anchor_lump( msg, body->uri.s - msg->buf, 0, 0);<br> if (l==0) {<br> LM_ERR("unable to build lump anchor\n");<br> return 0;<br> }<br> dsp->s[dsp->len++] = ' ';<br>
dsp->s[dsp->len++] = '<';<br> <br> LM_INFO("Header Field=%.*s\n", hdr->body.len, hdr->body.s);<br> LM_INFO("Body=%.*s\n", body->display.len, body->display.s);<br>
LM_INFO("DSP=%.*s\n", dsp->len, dsp->s);<br><br> return l;<br>}<br><br><br>Please see my code below:<br><br>static int new_func(struct sip_msg* _msg, char* notUsed1, char* notUsed2)<br>{<br> LM_INFO("Entering...");<br>
<br> struct to_body *body; // [defined: parse_to.h]<br> struct lump *l; // [defined: lump_struct.h]<br> struct hdr_field *hdr; // [defined: hf.h]<br> str d;<br> str *display = &d; // new display name 'unverified'<br>
str buf;<br><br> str_copy(display,"\"unverified\"", strlen("\"unverified\""));<br><br> if(parse_from_header(_msg) && parse_headers(_msg, HDR_EOH_T, 0)) // Make sure the from field has been parsed<br>
{<br> LM_ERR("Error Parsing Headers");<br> return -1;<br> }<br><br> hdr = _msg->from; // Assign the address of the parsed header field to hdr<br><br> body = (struct to_body*)hdr->parsed; // Get the parsed data from the header field <br>
// and cast it into a struct to_body<br><br> l=0;<br><br> if(body->display.len) // Check if there is a display name<br> {<br> <br> LM_INFO("Removing display [%.*s]\n", body->display.len, body->display.s);<br>
<br> l = del_lump(_msg, body->display.s-_msg->buf, body->display.len,0); // [defined: data_lump.c]<br> <br> buf.s = pkg_malloc(display->len + 2); <br><br> memcpy(buf.s, display->s, display->len);<br>
<br> buf.len = display->len;<br><br> LM_INFO("-------- Anchor Start -------");<br> <br> l = get_display_anchor(_msg, hdr, body, &buf);<br><br> LM_INFO("-------- Insert Start ----------");<br>
<br> l = insert_new_lump_after(l, buf.s, buf.len, 0); <br><br> if(l == 0)<br> {<br> LM_INFO("insert new display lump failed\n");<br> pkg_free(buf.s);<br> return -1;<br>
}<br><br><br> }<br> else // If there isn't a display name<br> {<br><br> buf.s = pkg_malloc(display->len + 2);<br> <br> memcpy(buf.s, display->s, display->len);<br><br> buf.len = display->len;<br>
<br> l = get_display_anchor(_msg, hdr, body, &buf);<br><br> l = insert_new_lump_after(l, buf.s, l->u.value, 0);<br><br> }<br><br><br> LM_INFO("------- END -------");<br><br> return 1;<br>
} <br>