<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.14.3">
</HEAD>
<BODY>
Olle--<BR>
<BR>
I thought to double check with you... the price of missing something is pretty high.<BR>
<BR>
Put on your thinking cap, pull out some paper and a pencil, turn off the cell phone... this is going to require<BR>
some thought!<BR>
<BR>
<BR>
For reference, here's the search loop in find_call:<BR>
<BR>
<BR>
dialoglist_lock();<BR>
for (p = dialoglist; p; p = p->next) {<BR>
/* In pedantic, we do not want packets with bad syntax to be connected to a PVT */<BR>
int found = FALSE;<BR>
if (ast_strlen_zero(p->callid))<BR>
continue;<BR>
if (req->method == SIP_REGISTER)<BR>
found = (!strcmp(p->callid, callid));<BR>
else<BR>
found = (!strcmp(p->callid, callid) &&<BR>
(!pedanticsipchecking <FONT COLOR="#ff0000">|| !tag ||</FONT> ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))) ;<BR>
<BR>
ast_debug(5, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", <BR>
found ? "Found" : "No match", p->callid, p->theirtag, p->tag);<BR>
<BR>
/* If we get a new request within an existing to-tag - check the to tag as well */<BR>
if (pedanticsipchecking && found && req->method != SIP_RESPONSE) { /* SIP Request */<BR>
if (p->tag[0] == '\0' && totag[0]) {<BR>
/* We have no to tag, but they have. Wrong dialog */<BR>
found = FALSE;<BR>
} else if (totag[0]) { /* Both have tags, compare them */<BR>
if (strcmp(totag, p->tag)) {<BR>
found = FALSE; /* This is not our packet */<BR>
}<BR>
}<BR>
if (!found)<BR>
ast_debug(5, "= Being pedantic: This ... request: Call ID: %s Ourtag <null> Totag %s Method %s\n", <BR>
p->callid, totag, sip_methods[req->method].text);<BR>
}<BR>
<BR>
<BR>
if (found) {<BR>
/* Found the call */<BR>
sip_pvt_lock(p);<BR>
dialoglist_unlock();<BR>
return p;<BR>
}<BR>
}<BR>
dialoglist_unlock();<BR>
<BR>
The object: remove the loop, and replace it with astobj2 hash table lookups.<BR>
<BR>
I checked Luigi's astobj2 branch, where he put dialogs in a table, but he implements the above as a linear traversal, which is not my goal. I want to improve performance, not just convert the code to be astobj2 based...<BR>
<BR>
There seem to be two main modes: with pedanticsipchecking ON, and pedanticsipchecking OFF.<BR>
<HR NOSHADE>
<BR>
<BR>
<BR>
Things are simple in OFF mode:<BR>
<BR>
fundamentally, whether req->method is SIP_REGISTER or not, found is true when a dialog's callid matches.<BR>
No code after setting found could disqualify this choice.<BR>
<BR>
<HR NOSHADE>
<BR>
<BR>
<BR>
Things get more complex in pedanticsipchecking ON mode:<BR>
<BR>
It seems split into whether req->method is SIP_REGISTER/SIP_RESPONSE or not:<BR>
<BR>
If req->method is SIP_REGISTER:<BR>
<BR>
if match(p->callid,callid) AND (!totag[0] || (p->tag[0] && match(p->tag,totag)) <BR>
<BR>
else <BR>
<BR>
If req->method is SIP_RESPONSE:<BR>
<BR>
If callid matches AND ( empty(p->theirtag) || match(p->theirtag,tag)) <BR>
<BR>
else<BR>
<BR>
If callid matches AND (!totag[0] || (p->tag[0] && match(p->tag,totag)) <BR>
AND ( empty(p->theirtag) || match(p->theirtag,tag)) <BR>
<BR>
(I notice in the code that there is : ... <FONT COLOR="#ff0000">|| !tag ||</FONT> ... which will never be true, and can be dropped)<BR>
<BR>
<HR NOSHADE>
<BR>
<BR>
I'm finding that coding the above via hashtable lookups to be mind-bending. I've got ideas as how to handle it, and I'm "hashing" it out, (pardon the really, really bad pun there).<BR>
<BR>
What I'd like to do, is verify that my refactoring of the logic above is indeed correct, and some explanation as to how dialogs can be created without unique callid's and when such are created, how the other fields are affected, namely, the from/to tag/headers as they are recorded in the dialog structures... Can you help me? I'm hoping there may be a simplifying assumption or two that will make things easier.<BR>
<BR>
Many thanks,<BR>
<BR>
murf<BR>
<BR>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>
--
Steve Murphy
Software Developer
Digium
</PRE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>