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.
24 xmpp_session_hook (iksparser *parser, iks *node)
28 iks_insert_attrib (iq, "type", "set");
29 iks_insert_attrib (iq, "id", "session1");
30 iks_insert_attrib (iks_insert (iq, "session"),
31 "xmlns", "urn:ietf:params:xml:ns:xmpp-session");
32 iks_send (parser, iq);
38 xmpp_initial_presence_hook (iksparser *parser, iks *node)
41 pres = iks_make_pres (IKS_SHOW_AVAILABLE, "Microblogging here!\n");
42 iks_send (parser, pres);
48 xmpp_id_hook (iksparser *parser, iks *node, char *id)
50 if (!iks_strcmp (id, "bind1"))
52 xmpp_session_hook (parser, node);
55 else if (!iks_strcmp (id, "session1"))
57 xmpp_initial_presence_hook (parser, node);
64 xmpp_ns_hook (iksparser *parser, iks *node, char *ns)
70 xmpp_iq_error (iksparser *parser, iks *node)
75 if (!iks_strcmp (iks_find_attrib (node, "type"), "error"))
77 to = iks_find_attrib (node, "to");
78 from = iks_find_attrib (node, "from");
80 iks_insert_attrib (node, "from", to);
82 iks_insert_attrib (node, "from", NULL);
84 iks_insert_attrib (node, "to", from);
86 iks_insert_attrib (node, "to", NULL);
87 iks_insert_attrib (node, "type", "error");
88 enode = iks_insert (node, "error");
89 iks_insert_attrib (enode, "type", "cancel");
90 iks_insert_attrib (iks_insert (enode, "feature-not-implemented"),
91 "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
92 iks_send (parser, node);
97 xmpp_tls_hook (iksparser *parser, iks *node)
99 iks_start_tls (parser);
104 xmpp_sasl_hook (iksparser *parser, iks* node)
106 iks_start_sasl (parser, IKS_SASL_DIGEST_MD5, "pubsub", "pubsub");
111 xmpp_bind_hook (iksparser *parser, iks *node)
115 iks_insert_attrib (iq, "type", "set");
116 iks_insert_attrib (iq, "id", "bind1");
117 iks_insert_attrib (iks_insert (iq, "bind"),
118 "xmlns", "urn:ietf:params:xml:ns:xmpp-bind");
119 iks_send (parser, iq);
125 xmpp_features_hook (iksparser *parser, iks *node)
129 for (feat = iks_child (node); feat != NULL; feat = iks_next (feat))
131 ns = iks_find_attrib (feat, "xmlns");
132 if (!iks_strcmp (ns, "urn:ietf:params:xml:ns:xmpp-tls"))
134 xmpp_tls_hook (parser, node);
137 else if (!iks_strcmp (ns, "urn:ietf:params:xml:ns:xmpp-sasl"))
139 xmpp_sasl_hook (parser, node);
142 else if (!iks_strcmp (ns, "urn:ietf:params:xml:ns:xmpp-bind"))
144 xmpp_bind_hook (parser, node);
152 xmpp_other_hook (iksparser *parser, iks *node, char *ns)
154 if (!iks_strcmp (ns, "urn:ietf:params:xml:ns:xmpp-sasl"))
156 if (!iks_strcmp (iks_name (node), "success"))
157 iks_send_header (parser, "jabber-br.org");
164 hook (void *data, int type, iks *node)
171 parser = *(iksparser **) data;
172 name = iks_name (node);
173 id = iks_find_attrib (node, "id");
174 ns = iks_find_attrib (node, "xmlns");
175 iqns = iks_find_attrib (iks_child (node), "xmlns");
176 if (!iks_strcmp (name, "message"))
178 printf ("Got milk?\n");
181 else if (!iks_strcmp (name, "presence"))
183 printf ("I sense a disturbance in the force!\n");
185 else if (!iks_strcmp (name, "iq"))
187 if (xmpp_id_hook (parser, node, id) == 0)
189 if (xmpp_ns_hook (parser, node, iqns) == 0)
191 xmpp_iq_error (parser, node);
193 else if (!iks_strcmp (name, "stream:features"))
195 if (xmpp_features_hook (parser, node) == 0)
200 if (xmpp_other_hook (parser, node, ns) == 0)
202 printf ("No no: %s\n", name);
208 main (int argc, char **argv)
211 parser = iks_stream_new ("jabber:client", &parser, hook);
212 iks_connect_tcp (parser, "jabber-br.org", 5222);
214 iks_recv (parser, -1);