#include "tcp_connect.h"
#include "iksemel_extra.h"
#include "xmpp.h"
+#include "sasl.h"
int
myhook (void *data, int type, iks *stanza)
if (!iks_strcmp (iks_name (stanza), "stream:features"))
{
hc_xmpp_features (data, stanza);
- if (hc_xmpp_is_tls_supported (data))
- fprintf (stderr, "TLS is supported\n");
if (hc_xmpp_is_sasl_supported (data))
- fprintf (stderr, "SASL is supported\n");
+ {
+ hc_xmpp_sasl_authenticate (data);
+ }
+ }
+ else if (!iks_strcmp (iks_find_attrib (stanza, "xmlns"), HC_XMPP_NS_SASL))
+ {
+ hc_xmpp_sasl_iterate (data, stanza);
+ if (hc_xmpp_status (data) == HC_XMPP_AUTHENTICATED)
+ fprintf (stdout, "Authenticated\n");
}
else
{
}
void
-write_stream (hc_xmpp_t *xmpp);
+write_stream (hc_xmpp_t *xmpp)
{
char *buffer = NULL;
asprintf (&buffer, "<stream:stream xmlns='jabber:client' "
"xmlns:stream='http://etherx.jabber.org/streams' "
- "version='1.0' to='%s'>", xmpp->server);
- write (xmpp->fd, buffer, strlen (buffer));
+ "version='1.0' to='%s'>", hc_xmpp_server (xmpp));
+ hc_xmpp_send_buffer (xmpp, buffer, 0);
free (buffer);
}
void
-loop (hc_xmpp_t *xmpp);
+loop (hc_xmpp_t *xmpp)
{
- char buffer[4096];
- int r;
- while ((r = read (xmpp->fd, buffer, sizeof (buffer))) > 0)
- iks_parse (xmpp->parser, buffer, r, 0);
+ while (1)
+ hc_xmpp_read_and_parse (xmpp);
}
int
main (int argc, char **argv)
{
char *server = "jabber-br.org";
+ char *user = "pubsub";
+ char *password = "pubsub";
hc_xmpp_t *xmpp;
dns_init (NULL, 1);
- xmpp = hc_xmpp_new (myhook, server);
+ xmpp = hc_xmpp_new (myhook, server, user, password);
write_stream (xmpp);
loop (xmpp);
return 0;