X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fchat.git;a=blobdiff_plain;f=tictactoe.c;h=e9296633522e7f709afaab145ab89c15a5ed525b;hp=b77451201b5b09a1fd448a73614eddb9f0403ffa;hb=282bba49cf4dcad9e844e61d70d0ab7ea1c7cb22;hpb=5cbc971e8563b2c364da4c014fb0418706720a94 diff --git a/tictactoe.c b/tictactoe.c index b774512..e929663 100644 --- a/tictactoe.c +++ b/tictactoe.c @@ -26,81 +26,8 @@ #include "tcp_connect.h" #include "iksemel_extra.h" #include "xmpp.h" -#include "sasl.h" -#include "bind.h" #include "disco.h" -static void write_stream (hc_xmpp_t *); - -static void -send_message_test (hc_xmpp_t *xmpp) -{ - hc_xmpp_send_disco_info (xmpp, ""); -} - -static int -myhook (void *data, int type, iks *stanza) -{ - if (!iks_strcmp (iks_name (stanza), "iq")) - { - char *ns = iks_find_attrib (iks_child (stanza), "xmlns"); - if (!iks_strcmp (ns, HC_XMPP_NS_BIND)) - { - hc_xmpp_bind_result (data, stanza); - if (hc_xmpp_status (data) == HC_XMPP_BOUND && - hc_xmpp_is_session_supported (data)) - hc_xmpp_session (data); - } - else if (!iks_strcmp (ns, HC_XMPP_NS_SESSION)) - { - hc_xmpp_session_result (data, stanza); - if (hc_xmpp_status (data) == HC_XMPP_SESSION) - send_message_test (data); - } - else if (!iks_strcmp (ns, HC_XMPP_NS_DISCO_INFO)) - { - hc_xmpp_recv_disco (data, stanza); - } - } - else if (!iks_strcmp (iks_name (stanza), "stream:features")) - { - hc_xmpp_features (data, stanza); - if (hc_xmpp_is_sasl_supported (data) & !hc_xmpp_is_sasl_enabled (data)) - { - hc_xmpp_sasl_authenticate (data); - } - if (hc_xmpp_is_bind_supported (data)) - { - hc_xmpp_bind (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) - { - write_stream (data); - fprintf (stdout, "Authenticated\n"); - } - } - else - { - fprintf (stderr, "Other: %s\n", iks_string (iks_stack (stanza), stanza)); - } - return IKS_OK; -} - -static void -write_stream (hc_xmpp_t *xmpp) -{ - char *buffer = NULL; - asprintf (&buffer, "", hc_xmpp_server (xmpp)); - hc_xmpp_send_buffer (xmpp, buffer, 0); - free (buffer); -} - static void loop (hc_xmpp_t *xmpp) { @@ -111,13 +38,21 @@ loop (hc_xmpp_t *xmpp) int main (int argc, char **argv) { - char *server = "jabber-br.org"; - char *user = "pubsub"; - char *password = "pubsub"; + char *server; + char *user; + char *password; hc_xmpp_t *xmpp; + if (argc < 4) + { + printf ("tictactoe server user password\n"); + return 1; + } + server = argv[1]; + user = argv[2]; + password = argv[3]; dns_init (NULL, 1); - xmpp = hc_xmpp_new (myhook, server, user, password); - write_stream (xmpp); + xmpp = hc_xmpp_new (hc_xmpp_hook, server, user, password); + hc_xmpp_send_stream (xmpp); loop (xmpp); return 0; }