<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I believe you can do this a lot easier in ser.cfg 2.x using selects to
pick the Contact.<br>
g-)<br>
<br>
Fernando Schmitt wrote:
<blockquote cite="mid:20070815062507.2830EB01C1@larry.ufrgs.br"
type="cite">
<meta http-equiv="Content-Type" content="text/html; ">
<meta name="Generator" content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
pre
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle18
        {mso-style-type:personal-compose;
        font-family:Verdana;
        color:windowtext;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
<div class="Section1">
<p class="MsoNormal"><font face="Verdana" size="2"><span
style="font-size: 10pt; font-family: Verdana;">Juha,<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Verdana" size="2"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font face="Verdana" size="2"><span
style="font-size: 10pt; font-family: Verdana;">I’m new into C
programming… Could you kindly
let me know where this code should be inserted?<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Verdana" size="2"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">yes, i implemented a function called move that turned 302 to invite, but<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">that code relied on a patch to tm module that gave me access to contact<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">header of reply in reply route.<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">i found the function and it is below. someone who needs this<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">functionality has to check if same kind of access to the contact header<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">of the reply is still possible or if the access method is now different<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">and modify the code accordingly.<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">also, all contacts would need to be taken from 302, not just the first.<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">contact_re was compiled during module initialization:<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> regcomp(&contact_re, "^Contact:(.*)$", REG_EXTENDED|REG_NEWLINE);<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">needless to say, i'm not proud of this code, but it gives an idea on how<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">it can be done.<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">-- juha<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">/*<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> * Appends a new branch to request using the first Contact URI of the (302)<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> * reply (if any) as the Request URI. Returns 1 if appending succeeded and -1<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> * if it failed.<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> */<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">int move(struct sip_msg* _m, char* _s1, char* _s2)<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">{<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> struct sip_msg* reply;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> regmatch_t pmatch[2];<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> struct hdr_field hf;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> contact_t* first;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> reply = _m->final_reply;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> if (!reply) {<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> LOG(L_ERR, "move(): No reply found\n");<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> return -1;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> }<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> LOG(L_ERR, "move(): unparsed part of reply: %s\n", reply->unparsed);<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> if ((regexec(&contact_re, reply->unparsed, 2, &(pmatch[0]), 0) != 0) ||<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> (pmatch[1].rm_so == -1)) {<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> LOG(L_ERR, "move(): No Contact header found\n");<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> return -1;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> }<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> hf.type = HDR_CONTACT;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> hf.name.len = 0;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> hf.body.len = pmatch[1].rm_eo - pmatch[1].rm_so - 1;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> hf.body.s = &(reply->unparsed[pmatch[1].rm_so]);<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> hf.len = hf.body.len + 2;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> hf.parsed = NULL;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> hf.next = NULL;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> <o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> LOG(L_ERR, "hf.body: '%.*s'\n", hf.body.len, hf.body.s);<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> <o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> if (parse_contact(&hf) < 0) {<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> LOG(L_ERR, "move(): Error while parsing Contact\n");<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> goto failure;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> }<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> <o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> if (((contact_body_t*)hf.parsed)->star == 1) {<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> LOG(L_ERR, "move(): Contact is *\n");<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> goto failure;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> }<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> first = ((contact_body_t*)hf.parsed)->contacts;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> if (first) {<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> if (append_branch(_m, first->uri.s, first->uri.len) == 1) {<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> goto success;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> } else {<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> LOG(L_ERR, "move(): Appending branch failed\n");<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> }<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> } else {<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> LOG(L_ERR, "move(): No contacts in Contact header\n");<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> }<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">failure:<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> if (hf.parsed) {<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> free_contact((contact_body_t**)(&(hf.parsed)));<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> }<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> return -1;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">success:<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> free_contact((contact_body_t**)(&(hf.parsed)));<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;"> return 1;<o:p></o:p></span></font></pre>
<pre><font face="Courier New" size="2"><span style="font-size: 10pt;">}<o:p></o:p></span></font></pre>
<p class="MsoNormal"><font face="Verdana" size="2"><span
style="font-size: 10pt; font-family: Verdana;"><o:p> </o:p></span></font></p>
<p class="MsoNormal"><font face="Verdana" size="2"><span
style="font-size: 10pt; font-family: Verdana;">Fernando Schmitt</span></font><o:p></o:p></p>
</div>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Serusers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Serusers@lists.iptel.org">Serusers@lists.iptel.org</a>
<a class="moz-txt-link-freetext" href="http://lists.iptel.org/mailman/listinfo/serusers">http://lists.iptel.org/mailman/listinfo/serusers</a>
</pre>
</blockquote>
</body>
</html>