Hello,<br><br>I&#39;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&#39;ve been able to remove the supplied display name and replace it with &quot;unverified&quot;. But, I&#39;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: &quot;unverified&quot; &lt;.. .....1..........*d..........*d........1.0.....1.......<br>......f........f....................1...........25f<br>@........................Q..............|..............1..1....1...sip:john@mydomain&gt;;tag=f04dda0088604f4892aed058306835e5<br>
<br>I&#39;m fairly certain that I may not be setting my anchor point correctly since I&#39;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-&gt;buf)? In the case of get_display_anchor, it uses the pointer to the first char (&lt;) in 
the uri minus the msg-&gt;buf. Also, please note that QjSimple does not send the usually <i>&lt;sip:john@mydomain&gt;</i> but sends <i>john@mydomain</i>. <br><br>When I looked in msg_parser.c, it says that the msg-&gt;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-&gt;buf so if you substract the size of msg-&gt;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(&quot;Entering.....&quot;);<br><br>    LM_INFO(&quot;Header Field=%.*s\n&quot;, hdr-&gt;body.len, hdr-&gt;body.s);<br>
    LM_INFO(&quot;Body=%.*s\n&quot;, body-&gt;display.len, body-&gt;display.s);<br>    LM_INFO(&quot;DSP=%.*s\n&quot;, dsp-&gt;len, dsp-&gt;s);<br>    <br>    struct lump* l;<br>    char *p1;<br>    char *p2;<br><br>    /* is URI quoted or not? */<br>
    p1 = hdr-&gt;name.s + hdr-&gt;name.len;<br><br>    for( p2=body-&gt;uri.s-1 ; p2&gt;=p1 &amp;&amp; *p2!=&#39;&lt;&#39; ; p2--);<br><br><br>    if (*p2==&#39;&lt;&#39;) {<br>        LM_INFO(&quot;Is quoted &quot;);<br>
        l = anchor_lump( msg,<b> p2 - msg-&gt;buf</b>, 0, 0);  // why p2 - msg-&gt;buff ??<br>        if (l==0) {<br>            LM_ERR(&quot;unable to build lump anchor\n&quot;);<br>            return 0;<br>        }<br>
        dsp-&gt;s[dsp-&gt;len++] = &#39; &#39;;<br>        return l;<br>    }<br><br>    /* not quoted - more complicated....must place the closing bracket */<br>    l = anchor_lump( msg, (body-&gt;uri.s+body-&gt;uri.len) - msg-&gt;buf, 0, 0);<br>
    if (l==0) {<br>        LM_ERR(&quot;unable to build lump anchor\n&quot;);<br>        return 0;<br>    }<br>    p1 = (char*)pkg_malloc(1);<br>    if (p1==0) {<br>        LM_ERR(&quot;no more pkg mem \n&quot;);<br>        return 0;<br>
    }<br>    *p1 = &#39;&gt;&#39;;<br><br><br><br>    if (insert_new_lump_after( l, p1, 1, 0)==0) {<br>        LM_ERR(&quot;insert lump failed\n&quot;);<br>        pkg_free(p1);<br>        return 0;<br>    }<br>    /* build anchor for display */<br>
    l = anchor_lump( msg, body-&gt;uri.s - msg-&gt;buf, 0, 0);<br>    if (l==0) {<br>        LM_ERR(&quot;unable to build lump anchor\n&quot;);<br>        return 0;<br>    }<br>    dsp-&gt;s[dsp-&gt;len++] = &#39; &#39;;<br>
    dsp-&gt;s[dsp-&gt;len++] = &#39;&lt;&#39;;<br>    <br>    LM_INFO(&quot;Header Field=%.*s\n&quot;, hdr-&gt;body.len, hdr-&gt;body.s);<br>    LM_INFO(&quot;Body=%.*s\n&quot;, body-&gt;display.len, body-&gt;display.s);<br>
    LM_INFO(&quot;DSP=%.*s\n&quot;, dsp-&gt;len, dsp-&gt;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(&quot;Entering...&quot;);<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 = &amp;d;    // new display name &#39;unverified&#39;<br>
    str buf;<br><br>    str_copy(display,&quot;\&quot;unverified\&quot;&quot;, strlen(&quot;\&quot;unverified\&quot;&quot;));<br><br>    if(parse_from_header(_msg) &amp;&amp; parse_headers(_msg, HDR_EOH_T, 0)) // Make sure the from field has been parsed<br>
    {<br>        LM_ERR(&quot;Error Parsing Headers&quot;);<br>        return -1;<br>    }<br><br>    hdr = _msg-&gt;from;    // Assign the address of the parsed header field to hdr<br><br>    body = (struct to_body*)hdr-&gt;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-&gt;display.len)    // Check if there is a display name<br>    {<br>        <br>        LM_INFO(&quot;Removing display [%.*s]\n&quot;, body-&gt;display.len, body-&gt;display.s);<br>
<br>        l = del_lump(_msg, body-&gt;display.s-_msg-&gt;buf, body-&gt;display.len,0); // [defined: data_lump.c]<br>    <br>        buf.s = pkg_malloc(display-&gt;len + 2);    <br><br>        memcpy(buf.s, display-&gt;s, display-&gt;len);<br>
<br>        buf.len = display-&gt;len;<br><br>        LM_INFO(&quot;-------- Anchor Start -------&quot;);<br>    <br>        l = get_display_anchor(_msg, hdr, body, &amp;buf);<br><br>        LM_INFO(&quot;-------- Insert Start ----------&quot;);<br>
    <br>        l = insert_new_lump_after(l, buf.s, buf.len, 0);        <br><br>        if(l == 0)<br>        {<br>            LM_INFO(&quot;insert new display lump failed\n&quot;);<br>            pkg_free(buf.s);<br>            return -1;<br>
        }<br><br><br>    }<br>    else  // If there isn&#39;t a display name<br>    {<br><br>        buf.s = pkg_malloc(display-&gt;len + 2);<br>        <br>        memcpy(buf.s, display-&gt;s, display-&gt;len);<br><br>        buf.len = display-&gt;len;<br>
<br>        l = get_display_anchor(_msg, hdr, body, &amp;buf);<br><br>        l = insert_new_lump_after(l, buf.s, l-&gt;u.value, 0);<br><br>    }<br><br><br>    LM_INFO(&quot;------- END -------&quot;);<br><br>    return 1;<br>
} <br>