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.
24 #include "xmpp_internal.h"
25 #include "iksemel_extra.h"
26 #include "tcp_connect.h"
29 hc_xmpp_new (iksStreamHook *hook, char *server, char *user, char *pass)
31 hc_xmpp_t *xmpp = malloc (sizeof (hc_xmpp_t));
32 xmpp->server = strdup (server);
33 xmpp->user = strdup (user);
34 xmpp->password = strdup (pass);
35 xmpp->parser = iks_extra_stream_new (xmpp, hook);
36 gsasl_init (&xmpp->sasl_ctx);
37 xmpp->fd = hc_tcp_connect (server, "xmpp-client");
40 xmpp->status = HC_XMPP_NONE;
45 hc_xmpp_is_tls_supported (hc_xmpp_t *xmpp)
47 return xmpp->tls & SUPPORTED;
51 hc_xmpp_is_tls_required (hc_xmpp_t *xmpp)
53 return xmpp->tls & REQUIRED;
57 hc_xmpp_is_tls_optional (hc_xmpp_t *xmpp)
59 return xmpp->tls & OPTIONAL;
63 hc_xmpp_is_tls_enabled (hc_xmpp_t *xmpp)
65 return xmpp->tls & ENABLED;
69 hc_xmpp_is_sasl_supported (hc_xmpp_t *xmpp)
71 return xmpp->sasl & SUPPORTED;
75 hc_xmpp_is_sasl_required (hc_xmpp_t *xmpp)
77 return xmpp->sasl & REQUIRED;
81 hc_xmpp_is_sasl_optional (hc_xmpp_t *xmpp)
83 return xmpp->sasl & OPTIONAL;
87 hc_xmpp_is_sasl_enabled (hc_xmpp_t *xmpp)
89 return xmpp->sasl & ENABLED;
93 hc_xmpp_is_bind_supported (hc_xmpp_t *xmpp)
95 return xmpp->bind & SUPPORTED;
99 hc_xmpp_is_session_supported (hc_xmpp_t *xmpp)
101 return xmpp->session & SUPPORTED;
105 hc_xmpp_is_session_required (hc_xmpp_t *xmpp)
107 return xmpp->session & REQUIRED;
111 hc_xmpp_server (hc_xmpp_t *xmpp)
117 hc_xmpp_send_buffer (hc_xmpp_t *xmpp, char *buffer, size_t len)
120 len = strlen (buffer);
121 write (xmpp->fd, buffer, len);
125 hc_xmpp_send_iks (hc_xmpp_t *xmpp, iks *x)
128 str = iks_string (iks_stack (x), x);
129 write (xmpp->fd, str, strlen (str));
133 hc_xmpp_read_and_parse (hc_xmpp_t *xmpp)
137 r = read (xmpp->fd, buffer, sizeof (buffer));
138 iks_parse (xmpp->parser, buffer, r, 0);
142 hc_xmpp_status (hc_xmpp_t *xmpp)