Added support for resouce binding and session establishment
[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 static void
23 session (hc_xmpp_t *xmpp, iks *f)
24 {
25   iks *c;
26   xmpp->session |= SUPPORTED;
27   for (c = iks_child (f); c != NULL; c = iks_next (c))
28     {
29       if (!iks_strcmp (iks_name (c), "optional"))
30         xmpp->session |= OPTIONAL;
31       else if (!iks_strcmp (iks_name (c), "required"))
32         xmpp->session |= REQUIRED;
33     }
34 }
35
36 static void
37 xmpp_bind (hc_xmpp_t *xmpp, iks *f)
38 {
39   iks *c;
40   xmpp->bind |= SUPPORTED;
41   for (c = iks_child (f); c != NULL; c = iks_next (c))
42     {
43       if (!iks_strcmp (iks_name (c), "optional"))
44         xmpp->bind |= OPTIONAL;
45       else if (!iks_strcmp (iks_name (c), "required"))
46         xmpp->bind |= REQUIRED;
47     }
48 }
49
50 static void
51 sasl (hc_xmpp_t *xmpp, iks *f)
52 {
53   iks *c;
54   xmpp->sasl |= SUPPORTED;
55   for (c = iks_child (f); c != NULL; c = iks_next (c))
56     {
57       if (!iks_strcmp (iks_name (c), "optional"))
58         xmpp->sasl |= OPTIONAL;
59       else if (!iks_strcmp (iks_name (c), "required"))
60         xmpp->sasl |= REQUIRED;
61     }
62 }
63
64 static void
65 tls (hc_xmpp_t *xmpp, iks *f)
66 {
67   iks *c;
68   xmpp->tls |= SUPPORTED;
69   for (c = iks_child (f); c != NULL; c = iks_next (c))
70     {
71       if (!iks_strcmp (iks_name (c), "optional"))
72         xmpp->tls |= OPTIONAL;
73       else if (!iks_strcmp (iks_name (c), "required"))
74         xmpp->tls |= REQUIRED;
75     }
76 }
77
78 void
79 hc_xmpp_features (hc_xmpp_t *xmpp, iks *features)
80 {
81   iks *c;
82   for (c = iks_child (features); c != NULL; c = iks_next (c))
83     {
84       if (!iks_strcmp (iks_name (c), "starttls") &&
85           !iks_strcmp (iks_find_attrib (c, "xmlns"), HC_XMPP_NS_TLS))
86         tls (xmpp, c);
87       else if (!iks_strcmp (iks_name (c), "mechanisms") &&
88           !iks_strcmp (iks_find_attrib (c, "xmlns"), HC_XMPP_NS_SASL))
89         sasl (xmpp, c);
90       else if (!iks_strcmp (iks_name (c), "bind") &&
91           !iks_strcmp (iks_find_attrib (c, "xmlns"), HC_XMPP_NS_BIND))
92         xmpp_bind (xmpp, c);
93       else if (!iks_strcmp (iks_name (c), "session") &&
94           !iks_strcmp (iks_find_attrib (c, "xmlns"), HC_XMPP_NS_SESSION))
95         session (xmpp, c);
96     }
97 }