2 * Copyright (C) 2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "iksemel_extra.h"
30 hc_xmpp_hook (void *data, int type, iks *stanza)
32 if (!iks_strcmp (iks_name (stanza), "iq"))
34 char *ns = iks_find_attrib (iks_child (stanza), "xmlns");
35 if (!iks_strcmp (ns, HC_XMPP_NS_BIND))
37 hc_xmpp_bind_result (data, stanza);
38 if (hc_xmpp_status (data) == HC_XMPP_BOUND &&
39 hc_xmpp_is_session_supported (data))
40 hc_xmpp_session (data);
42 else if (!iks_strcmp (ns, HC_XMPP_NS_SESSION))
44 hc_xmpp_session_result (data, stanza);
45 if (hc_xmpp_status (data) == HC_XMPP_SESSION)
46 hc_xmpp_send_disco_info (data, hc_xmpp_server (data));
48 else if (!iks_strcmp (ns, HC_XMPP_NS_DISCO_INFO))
50 hc_xmpp_recv_disco (data, stanza);
53 else if (!iks_strcmp (iks_name (stanza), "stream:features"))
55 hc_xmpp_features (data, stanza);
56 if (hc_xmpp_is_sasl_supported (data) & !hc_xmpp_is_sasl_enabled (data))
58 hc_xmpp_sasl_authenticate (data);
60 if (hc_xmpp_is_bind_supported (data))
65 else if (!iks_strcmp (iks_find_attrib (stanza, "xmlns"), HC_XMPP_NS_SASL))
67 hc_xmpp_sasl_iterate (data, stanza);
68 if (hc_xmpp_status (data) == HC_XMPP_AUTHENTICATED)
70 hc_xmpp_send_stream (data);
77 hc_xmpp_send_stream (hc_xmpp_t *xmpp)
80 asprintf (&buffer, "<stream:stream xmlns='jabber:client' "
81 "xmlns:stream='http://etherx.jabber.org/streams' "
82 "version='1.0' to='%s'>", hc_xmpp_server (xmpp));
83 hc_xmpp_send_buffer (xmpp, buffer, 0);