Created XMPP context and better features parser
[cascardo/chat.git] / features.c
1 /*
2  *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19
20 #include "xmpp_internal.h"
21
22 void
23 sasl (hc_xmpp_t *xmpp, iks *f)
24 {
25   iks *c;
26   xmpp->sasl |= SUPPORTED;
27   for (c = iks_child (f); c != NULL; c = iks_next (c))
28     {
29       if (!iks_strcmp (iks_name (c), "optional"))
30         xmpp->sasl |= OPTIONAL;
31       else if (!iks_strcmp (iks_name (c), "required"))
32         xmpp->sasl |= REQUIRED;
33     }
34 }
35
36 void
37 tls (hc_xmpp_t *xmpp, iks *f)
38 {
39   iks *c;
40   xmpp->tls |= SUPPORTED;
41   for (c = iks_child (f); c != NULL; c = iks_next (c))
42     {
43       if (!iks_strcmp (iks_name (c), "optional"))
44         xmpp->tls |= OPTIONAL;
45       else if (!iks_strcmp (iks_name (c), "required"))
46         xmpp->tls |= REQUIRED;
47     }
48 }
49
50 void
51 hc_xmpp_features (hc_xmpp_t *xmpp, iks *features)
52 {
53   iks *c;
54   for (c = iks_child (features); c != NULL; c = iks_next (c))
55     {
56       if (!iks_strcmp (iks_name (c), "starttls") &&
57           !iks_strcmp (iks_find_attrib (c, "xmlns"), HC_XMPP_NS_TLS))
58         tls (xmpp, c);
59       if (!iks_strcmp (iks_name (c), "mechanisms") &&
60           !iks_strcmp (iks_find_attrib (c, "xmlns"), HC_XMPP_NS_SASL))
61         sasl (xmpp, c);
62     }
63 }