*/
+#include <glib.h>
#include <iksemel.h>
#include <stdio.h>
#include <stdlib.h>
iks_delete (iq);
}
+iks *
+createtune (char *line)
+{
+ iks *tune;
+ tune = iks_new ("tune");
+ iks_insert_attrib (tune, "xmlns", "http://jabber.org/protocol/tune");
+ iks_insert_cdata (iks_insert (tune, "artist"), line, 0);
+ return tune;
+}
+
+void
+pushtune (iksparser *parser, char *node, char *line)
+{
+ iks *iq;
+ iks *query;
+ iks *publish;
+ iks *item;
+ iks *tune;
+ iq = createiq ("set", pbservice, "pubsub",
+ "http://jabber.org/protocol/pubsub", &query);
+ publish = iks_insert (query, "publish");
+ iks_insert_attrib (publish, "node", node);
+ item = iks_insert (publish, "item");
+ tune = createtune (line);
+ iks_insert_node (item, tune);
+ printf ("debug: %s\n", iks_string (iks_stack (iq), iq));
+ iks_send (parser, iq);
+ iks_delete (iq);
+}
+
+
void
process_mood (iksparser *parser, char *cmdline)
{
createnode (parser, cmdline);
else if (!strcmp (cmd, "get"))
getnode (parser, cmdline);
- else if (!strcmp (cmd, "push"))
+ else if (!strcmp (cmd, "mood"))
{
char *node;
- node = strsep (&cmdline, " ");
+ node = "http://jabber.org/protocol/mood";
pushmood (parser, node, cmdline);
}
+ else if (!strcmp (cmd, "tune"))
+ {
+ char *node;
+ node = "http://jabber.org/protocol/tune";
+ pushtune (parser, node, cmdline);
+ }
free (orig_cmdline);
}
return IKS_OK;
}
+gboolean
+handler (GIOChannel *channel, GIOCondition cond, gpointer data)
+{
+ iksparser *parser = data;
+ iks_recv (parser, 0);
+ return TRUE;
+}
+
+void
+loop (iksparser *parser)
+{
+ GIOChannel *channel;
+ channel = g_io_channel_unix_new (iks_fd (parser));
+ g_io_add_watch (channel, G_IO_IN, handler, parser);
+ g_main_loop_run (g_main_loop_new (g_main_context_default (), TRUE));
+}
+
int
main (int argc, char **argv)
{
}
parser = iks_stream_new ("jabber:client", &parser, hook);
iks_connect_tcp (parser, server, 5222);
- while (1)
- iks_recv (parser, -1);
+ loop (parser);
return 0;
}