re-tested it again, it does check only first dialog in a body
your code with my custom logging
```
int ps_match_dialog_state_from_body(str body, int *is_dialog, char *vstate)
{
xmlDocPtr doc;
xmlNodePtr node;
xmlNodePtr childNode;
char *tmp_state;
int rmatch = 0;
*is_dialog = 0;
LM_ERR("****** body to parse %s\n", body);
doc = xmlParseMemory(body.s, body.len);
if(doc == NULL || doc->children == NULL)
{
LM_ERR("failed to parse xml document\n");
return -1;
}
node = xmlNodeGetChildByName(doc->children, "dialog");
while(node != NULL)
{
*is_dialog = 1;
childNode = xmlNodeGetChildByName(node, "state");
tmp_state = (char *)xmlNodeGetContent(childNode);
if (tmp_state != NULL)
{
LM_ERR("vstate is %s, tmp_state is %s\n", vstate, tmp_state);
if(strcmp(tmp_state, vstate)!=0) {
LM_ERR("states are different! goto done \n");
xmlFree(tmp_state);
rmatch = 0;
goto done;
}
rmatch = 1;
xmlFree(tmp_state);
}
/* search for next dialog node */
do {
LM_ERR("do entered \n");
if(node->next != NULL && node->next->name != NULL
&& xmlStrcmp(node->name, node->next->name) == 0) {
node = node->next;
LM_ERR("break it \n");
break;
}
node = node->next;
LM_ERR("node->next \n");
} while(node != NULL);
}
done:
xmlFreeDoc(doc);
LM_ERR("going to return rmatch %d\n", rmatch);
return rmatch;
}
```
body of PUBLISH, that being processed:
```
<?xml version="1.0"?>
<dialog-info xmlns="urn:ietf:params:xml:ns:dialog-info"
version="109" state="full" entity="252">
<dialog id="3282208261(a)10.100.1.24"
call-id="3282208261(a)10.100.1.24" local-tag="as0cf4d423"
remote-tag="3673383467" remote-uri="sip:252@10.100.1.24:33035"
local-uri="sip:254@10.100.1.85:6050" direction="initiator">
<note>On the phone</note>
<remote>
<identity display="user252">sip:252@10.100.1.85</identity>
<target uri="sip:252@10.100.1.85">
</target>
</remote>
<local>
<identity display="user254">sip:254@10.100.1.85</identity>
<target uri="sip:254@10.100.1.85"/>
</local>
<state>confirmed</state>
</dialog>
</dialog-info>
```
logs printed by kamailio:
```
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:321]: ps_match_dialog_state_from_body(): ****** body to parse <?xml
version="1.0"?>
<dialog-info xmlns="urn:ietf:params:xml:ns:dialog-info"
version="108" state="full" entity="252">
<dialog id="0b386c6122b2dabc0fa49b1d4972ca3c@127.0.0.1:6050"
call-id="0b386c6122b2dabc0fa49b1d4972ca3c@127.0.0.1:6050"
local-tag="as29381132" remote-tag="3958334712"
remote-uri="sip:252@10.100.1.24:33035"
local-uri="sip:251@127.0.0.1:6050" direction="recipient">
<note>Ready</note>
<remote>
<identity>252</identity>
<target uri="252">
</target>
</remote>
<local>
<identity>251</identity>
<target uri="251"/>
</local>
<state>terminated</state>
</dialog>
<dialog id="3282208261(a)10.100.1.24"
call-id="3282208261(a)10.100.1.24" local-tag="as0cf4d423"
remote-tag="3673383467" remote-uri="sip:252@10.100.1.24:33035"
local-uri="sip:254@10.100.1.85:6050" direction="initiator">
<note>On the phone</note>
<remote>
<identity display="user252">sip:252@10.100.1.85</identity>
<target uri="sip:252@10.100.1.85">
</target>
</remote>
<local>
<identity display="user254">sip:254@10.100.1.85</identity>
<target uri="sip:254@10.100.1.85"/>
</local>
<state>confirmed</state>
</dialog>
</dialog-info>
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:341]: ps_match_dialog_state_from_body(): vstate is terminated, tmp_state is
terminated
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:355]: ps_match_dialog_state_from_body(): do entered
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:363]: ps_match_dialog_state_from_body(): node->next
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:355]: ps_match_dialog_state_from_body(): do entered
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:363]: ps_match_dialog_state_from_body(): node->next
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:355]: ps_match_dialog_state_from_body(): do entered
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:363]: ps_match_dialog_state_from_body(): node->next
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:355]: ps_match_dialog_state_from_body(): do entered
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:363]: ps_match_dialog_state_from_body(): node->next
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:369]: ps_match_dialog_state_from_body(): going to return rmatch 1
Feb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence
[presentity.c:559]: ps_match_dialog_state(): rmatch is 1
```
so for some reason in `do { ... } while ()` it did not break.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/1427#issuecomment-365531427