2 * Copyright (C) 2009 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.
39 hook (void *data, int type, iks *node)
43 udata = (struct udata *) data;
44 if (type == IKS_NODE_START)
46 if (!iks_is_secure (udata->parser) || udata->auth == AUTH_NONE)
48 iks_start_tls (udata->parser);
49 udata->auth = AUTH_TLS;
51 else if (udata->auth == AUTH_TLS)
53 iks_start_sasl (udata->parser, IKS_SASL_PLAIN, "pubsub", "pubsub");
55 else if (udata->auth == AUTH_SASL)
57 iks_send_raw (udata->parser, "<iq type='set' id='boo'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/></iq>");
62 if (!iks_strcmp (iks_find_attrib (node, "id"), "boo"))
64 udata->auth = AUTH_BIND;
65 iks_send_raw (udata->parser, "<iq type='set' id='goo'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>");
67 else if (!iks_strcmp (iks_find_attrib (node, "id"), "goo"))
70 sub = iks_make_s10n (IKS_TYPE_SUBSCRIBED, "cascardo@jabber-br.org", "");
71 iks_send (udata->parser, sub);
73 sub = iks_make_pres (IKS_SHOW_AVAILABLE, "here");
74 iks_insert_attrib (sub, "to", "cascardo@jabber-br.org");
75 iks_send (udata->parser, sub);
78 if (!iks_strcmp (iks_name (node), "success"))
80 iks_send_header (udata->parser, "jabber-br.org");
81 udata->auth = AUTH_SASL;
83 printf ("%s\n", iks_string (iks_stack (node), node));
89 main (int argc, char **argv)
93 udata.parser = iks_stream_new ("jabber:client", &udata, hook);
94 iks_connect_tcp (udata.parser, "jabber-br.org", 5222);
96 iks_recv (udata.parser, -1);