<p>re-tested it again, it does check only first dialog in a body</p>
<p>your code with my custom logging</p>
<pre><code>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;
}
</code></pre>
<p>body of PUBLISH, that being processed:</p>
<pre><code><?xml version="1.0"?>
<dialog-info xmlns="urn:ietf:params:xml:ns:dialog-info" version="109" state="full" entity="252">
<dialog id="3282208261@10.100.1.24" call-id="3282208261@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>
</code></pre>
<p>logs printed by kamailio:</p>
<pre><code>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@10.100.1.24" call-id="3282208261@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
</code></pre>
<p>so for some reason in <code>do { ... } while ()</code> it did not break.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1427#issuecomment-365531427">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZTzO8MaR-I7nTBjga8xcWm1V7ryWks5tUpoTgaJpZM4R5QB3">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZeK2KTLCQxqcEa6wnW8R6uVAdpJjks5tUpoTgaJpZM4R5QB3.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/issues/1427#issuecomment-365531427"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"PERSON","message":"@vance-od in #1427: re-tested it again, it does check only first dialog in a body\r\n\r\nyour code with my custom logging\r\n```\r\nint ps_match_dialog_state_from_body(str body, int *is_dialog, char *vstate)\r\n{\r\n\txmlDocPtr doc;\r\n\txmlNodePtr node;\r\n\txmlNodePtr childNode;\r\n\tchar *tmp_state;\r\n\tint rmatch = 0;\r\n\r\n\t*is_dialog = 0;\r\n\r\n\tLM_ERR(\"****** body to parse %s\\n\", body);\r\n\r\n\tdoc = xmlParseMemory(body.s, body.len);\r\n\tif(doc == NULL || doc-\u003echildren == NULL)\r\n\t{\r\n\t\tLM_ERR(\"failed to parse xml document\\n\");\r\n\t\treturn -1;\r\n\t}\r\n\r\n\tnode = xmlNodeGetChildByName(doc-\u003echildren, \"dialog\");\r\n\r\n\twhile(node != NULL)\r\n\t{\r\n\t\t*is_dialog = 1;\r\n\r\n\t\tchildNode = xmlNodeGetChildByName(node, \"state\");\r\n\t\ttmp_state = (char *)xmlNodeGetContent(childNode);\r\n\r\n\t\tif (tmp_state != NULL)\r\n\t\t{\r\n\t\t\tLM_ERR(\"vstate is %s, tmp_state is %s\\n\", vstate, tmp_state);\r\n\r\n\t\t\tif(strcmp(tmp_state, vstate)!=0) {\r\n\t\t\t\tLM_ERR(\"states are different! goto done \\n\");\r\n\r\n\t\t\t\txmlFree(tmp_state);\r\n\t\t\t\trmatch = 0;\r\n\t\t\t\tgoto done;\r\n\t\t\t}\r\n\t\t\trmatch = 1;\r\n\t\t\txmlFree(tmp_state);\r\n\t\t}\r\n\t\t/* search for next dialog node */\r\n\t\tdo {\r\n\t\t\tLM_ERR(\"do entered \\n\");\r\n\t\t\tif(node-\u003enext != NULL \u0026\u0026 node-\u003enext-\u003ename != NULL\r\n\t\t\t\t\t\u0026\u0026 xmlStrcmp(node-\u003ename, node-\u003enext-\u003ename) == 0) {\r\n\t\t\t\tnode = node-\u003enext;\r\n\t\t\t\tLM_ERR(\"break it \\n\");\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tnode = node-\u003enext;\r\n\t\t\tLM_ERR(\"node-\u003enext \\n\");\r\n\t\t} while(node != NULL);\r\n\t}\r\n\r\ndone:\r\n\txmlFreeDoc(doc);\r\n\tLM_ERR(\"going to return rmatch %d\\n\", rmatch);\r\n\treturn rmatch;\r\n}\r\n```\r\nbody of PUBLISH, that being processed:\r\n```\r\n\u003c?xml version=\"1.0\"?\u003e\r\n\u003cdialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"109\" state=\"full\" entity=\"252\"\u003e\r\n\u003cdialog id=\"3282208261@10.100.1.24\" call-id=\"3282208261@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\"\u003e\r\n\u003cnote\u003eOn the phone\u003c/note\u003e\r\n\u003cremote\u003e\r\n\u003cidentity display=\"user252\"\u003esip:252@10.100.1.85\u003c/identity\u003e\r\n\u003ctarget uri=\"sip:252@10.100.1.85\"\u003e\r\n\u003c/target\u003e\r\n\u003c/remote\u003e\r\n\u003clocal\u003e\r\n\u003cidentity display=\"user254\"\u003esip:254@10.100.1.85\u003c/identity\u003e\r\n\u003ctarget uri=\"sip:254@10.100.1.85\"/\u003e\r\n\u003c/local\u003e\r\n\u003cstate\u003econfirmed\u003c/state\u003e\r\n\u003c/dialog\u003e\r\n\u003c/dialog-info\u003e\r\n```\r\nlogs printed by kamailio:\r\n```\r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:321]: ps_match_dialog_state_from_body(): ****** body to parse \u003c?xml version=\"1.0\"?\u003e\r\n\u003cdialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"108\" state=\"full\" entity=\"252\"\u003e\r\n\u003cdialog 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\"\u003e\r\n\u003cnote\u003eReady\u003c/note\u003e\r\n\u003cremote\u003e\r\n\u003cidentity\u003e252\u003c/identity\u003e\r\n\u003ctarget uri=\"252\"\u003e\r\n\u003c/target\u003e\r\n\u003c/remote\u003e\r\n\u003clocal\u003e\r\n\u003cidentity\u003e251\u003c/identity\u003e\r\n\u003ctarget uri=\"251\"/\u003e\r\n\u003c/local\u003e\r\n\u003cstate\u003eterminated\u003c/state\u003e\r\n\u003c/dialog\u003e\r\n\u003cdialog id=\"3282208261@10.100.1.24\" call-id=\"3282208261@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\"\u003e\r\n\u003cnote\u003eOn the phone\u003c/note\u003e\r\n\u003cremote\u003e\r\n\u003cidentity display=\"user252\"\u003esip:252@10.100.1.85\u003c/identity\u003e\r\n\u003ctarget uri=\"sip:252@10.100.1.85\"\u003e\r\n\u003c/target\u003e\r\n\u003c/remote\u003e\r\n\u003clocal\u003e\r\n\u003cidentity display=\"user254\"\u003esip:254@10.100.1.85\u003c/identity\u003e\r\n\u003ctarget uri=\"sip:254@10.100.1.85\"/\u003e\r\n\u003c/local\u003e\r\n\u003cstate\u003econfirmed\u003c/state\u003e\r\n\u003c/dialog\u003e\r\n\u003c/dialog-info\u003e\r\n\r\nFeb 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\r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:355]: ps_match_dialog_state_from_body(): do entered \r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:363]: ps_match_dialog_state_from_body(): node-\u003enext \r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:355]: ps_match_dialog_state_from_body(): do entered \r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:363]: ps_match_dialog_state_from_body(): node-\u003enext \r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:355]: ps_match_dialog_state_from_body(): do entered \r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:363]: ps_match_dialog_state_from_body(): node-\u003enext \r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:355]: ps_match_dialog_state_from_body(): do entered \r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:363]: ps_match_dialog_state_from_body(): node-\u003enext \r\nFeb 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\r\nFeb 14 09:25:48 0050562c117c /usr/sbin/kamailio[29343]: ERROR: presence [presentity.c:559]: ps_match_dialog_state(): rmatch is 1\r\n```\r\n\r\nso for some reason in `do { ... } while ()` it did not break."}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1427#issuecomment-365531427"}}}</script>