# HG changeset patch # User Andreas Monitzer # Date 1182112261 0 # Node ID 3e437e86bd6e7613340acc1dcef7dc778ef28b17 # Parent f108b91e2fee12c9ebe776af68b3b3150755a8c0 Implemented user tune, currently untested. diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/gg/gg.c --- a/libpurple/protocols/gg/gg.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/gg/gg.c Sun Jun 17 20:31:01 2007 +0000 @@ -2123,6 +2123,7 @@ NULL, /* whiteboard_prpl_ops */ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/irc/irc.c --- a/libpurple/protocols/irc/irc.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/irc/irc.c Sun Jun 17 20:31:01 2007 +0000 @@ -876,6 +876,7 @@ NULL, /* whiteboard_prpl_ops */ irc_send_raw, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/jabber/jabber.c --- a/libpurple/protocols/jabber/jabber.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/jabber/jabber.c Sun Jun 17 20:31:01 2007 +0000 @@ -1299,6 +1299,15 @@ "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), + "tune_artist", _("Tune Artist"), purple_value_new(PURPLE_TYPE_STRING), + "tune_title", _("Tune Title"), purple_value_new(PURPLE_TYPE_STRING), + "tune_album", _("Tune Album"), purple_value_new(PURPLE_TYPE_STRING), + "tune_genre", _("Tune Genre"), purple_value_new(PURPLE_TYPE_STRING), + "tune_comment", _("Tune Comment"), purple_value_new(PURPLE_TYPE_STRING), + "tune_track", _("Tune Track"), purple_value_new(PURPLE_TYPE_STRING), + "tune_time", _("Tune Time"), purple_value_new(PURPLE_TYPE_INT), + "tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT), + "tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING), NULL); types = g_list_append(types, type); @@ -1311,6 +1320,15 @@ "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), + "tune_artist", _("Tune Artist"), purple_value_new(PURPLE_TYPE_STRING), + "tune_title", _("Tune Title"), purple_value_new(PURPLE_TYPE_STRING), + "tune_album", _("Tune Album"), purple_value_new(PURPLE_TYPE_STRING), + "tune_genre", _("Tune Genre"), purple_value_new(PURPLE_TYPE_STRING), + "tune_comment", _("Tune Comment"), purple_value_new(PURPLE_TYPE_STRING), + "tune_track", _("Tune Track"), purple_value_new(PURPLE_TYPE_STRING), + "tune_time", _("Tune Time"), purple_value_new(PURPLE_TYPE_INT), + "tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT), + "tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING), NULL); types = g_list_append(types, type); @@ -1323,6 +1341,15 @@ "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), + "tune_artist", _("Tune Artist"), purple_value_new(PURPLE_TYPE_STRING), + "tune_title", _("Tune Title"), purple_value_new(PURPLE_TYPE_STRING), + "tune_album", _("Tune Album"), purple_value_new(PURPLE_TYPE_STRING), + "tune_genre", _("Tune Genre"), purple_value_new(PURPLE_TYPE_STRING), + "tune_comment", _("Tune Comment"), purple_value_new(PURPLE_TYPE_STRING), + "tune_track", _("Tune Track"), purple_value_new(PURPLE_TYPE_STRING), + "tune_time", _("Tune Time"), purple_value_new(PURPLE_TYPE_INT), + "tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT), + "tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING), NULL); types = g_list_append(types, type); @@ -1335,6 +1362,15 @@ "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), + "tune_artist", _("Tune Artist"), purple_value_new(PURPLE_TYPE_STRING), + "tune_title", _("Tune Title"), purple_value_new(PURPLE_TYPE_STRING), + "tune_album", _("Tune Album"), purple_value_new(PURPLE_TYPE_STRING), + "tune_genre", _("Tune Genre"), purple_value_new(PURPLE_TYPE_STRING), + "tune_comment", _("Tune Comment"), purple_value_new(PURPLE_TYPE_STRING), + "tune_track", _("Tune Track"), purple_value_new(PURPLE_TYPE_STRING), + "tune_time", _("Tune Time"), purple_value_new(PURPLE_TYPE_INT), + "tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT), + "tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING), NULL); types = g_list_append(types, type); @@ -1347,6 +1383,15 @@ "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), + "tune_artist", _("Tune Artist"), purple_value_new(PURPLE_TYPE_STRING), + "tune_title", _("Tune Title"), purple_value_new(PURPLE_TYPE_STRING), + "tune_album", _("Tune Album"), purple_value_new(PURPLE_TYPE_STRING), + "tune_genre", _("Tune Genre"), purple_value_new(PURPLE_TYPE_STRING), + "tune_comment", _("Tune Comment"), purple_value_new(PURPLE_TYPE_STRING), + "tune_track", _("Tune Track"), purple_value_new(PURPLE_TYPE_STRING), + "tune_time", _("Tune Time"), purple_value_new(PURPLE_TYPE_INT), + "tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT), + "tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING), NULL); types = g_list_append(types, type); diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/jabber/libxmpp.c --- a/libpurple/protocols/jabber/libxmpp.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/jabber/libxmpp.c Sun Jun 17 20:31:01 2007 +0000 @@ -39,6 +39,7 @@ #include "presence.h" #include "google.h" #include "pep.h" +#include "usertune.h" static PurplePluginProtocolInfo prpl_info = { @@ -109,6 +110,7 @@ NULL, /* whiteboard_prpl_ops */ jabber_prpl_send_raw, /* send_raw */ jabber_roomlist_room_serialize, /* roomlist_room_serialize */ + jabber_tune_set, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/jabber/usertune.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/protocols/jabber/usertune.c Sun Jun 17 20:31:01 2007 +0000 @@ -0,0 +1,123 @@ +/* + * purple - Jabber Protocol Plugin + * + * Copyright (C) 2007, Andreas Monitzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "usertune.h" +#include "pep.h" +#include +#include +#include "internal.h" +#include "request.h" + +static void jabber_tune_cb(JabberStream *js, const char *from, xmlnode *items) { + /* it doesn't make sense to have more than one item here, so let's just pick the first one */ + xmlnode *item = xmlnode_get_child(items, "item"); + JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); + xmlnode *tuneinfo, *tune; + PurpleTuneInfo tuneinfodata; + + /* ignore the tune of people not on our buddy list */ + if (!buddy || !item) + return; + + tuneinfodata.artist = ""; + tuneinfodata.title = ""; + tuneinfodata.album = ""; + tuneinfodata.genre = ""; + tuneinfodata.comment = ""; + tuneinfodata.track = ""; + tuneinfodata.time = -1; + tuneinfodata.year = -1; + tuneinfodata.url = ""; + + tune = xmlnode_get_child_with_namespace(item, "tune", "http://jabber.org/protocol/tune"); + if (!tune) + return; + for (tuneinfo = tune->child; tuneinfo; tuneinfo = tuneinfo->next) { + if (tuneinfo->type == XMLNODE_TYPE_TAG) { + if (!strcmp(tuneinfo->name, "artist")) { + if (tuneinfodata.artist[0] != '\0') /* only pick the first one */ + tuneinfodata.artist = xmlnode_get_data(tuneinfo); + } else if (!strcmp(tuneinfo->name, "length")) { + if (tuneinfodata.time == -1) { + char *length = xmlnode_get_data(tuneinfo); + if (length) + tuneinfodata.time = strtol(length, NULL, 10); + } + } else if (!strcmp(tuneinfo->name, "source")) { + if (tuneinfodata.album[0] != '\0') /* only pick the first one */ + tuneinfodata.album = xmlnode_get_data(tuneinfo); + } else if (!strcmp(tuneinfo->name, "title")) { + if (tuneinfodata.title[0] != '\0') /* only pick the first one */ + tuneinfodata.title = xmlnode_get_data(tuneinfo); + } else if (!strcmp(tuneinfo->name, "track")) { + if (tuneinfodata.track[0] != '\0') /* only pick the first one */ + tuneinfodata.track = xmlnode_get_data(tuneinfo); + } else if (!strcmp(tuneinfo->name, "uri")) { + if (tuneinfodata.url[0] != '\0') /* only pick the first one */ + tuneinfodata.url = xmlnode_get_data(tuneinfo); + } + } + } + JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL); + const char *status_id = jabber_buddy_state_get_status_id(resource->state); + + purple_prpl_got_user_status(js->gc->account, from, status_id, "tune_artist", tuneinfodata.artist, "tune_title", tuneinfodata.title, "tune_album", tuneinfodata.album, "tune_genre", tuneinfodata.genre, "tune_comment", tuneinfodata.comment, "tune_track", tuneinfodata.track, "tune_time", tuneinfodata.time, "tune_year", tuneinfodata.year, "tune_url", tuneinfodata.url, NULL); +} + +void jabber_tune_init(void) { + jabber_add_feature("tune", "http://jabber.org/protocol/tune", jabber_pep_namespace_only_when_pep_enabled_cb); + jabber_pep_register_handler("tunen", "http://jabber.org/protocol/tune", jabber_tune_cb); +} + +void jabber_tune_set(PurpleConnection *gc, const PurpleTuneInfo *tuneinfo) { + xmlnode *publish, *tunenode; + JabberStream *js = gc->proto_data; + + publish = xmlnode_new("publish"); + xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/tune"); + tunenode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "tune"); + xmlnode_set_namespace(tunenode, "http://jabber.org/protocol/tune"); + + if(tuneinfo) { + if(tuneinfo->artist) + xmlnode_insert_data(xmlnode_new_child(tunenode, "artist"),tuneinfo->artist,-1); + if(tuneinfo->title) + xmlnode_insert_data(xmlnode_new_child(tunenode, "title"),tuneinfo->title,-1); + if(tuneinfo->album) + xmlnode_insert_data(xmlnode_new_child(tunenode, "source"),tuneinfo->album,-1); + if(tuneinfo->url) + xmlnode_insert_data(xmlnode_new_child(tunenode, "uri"),tuneinfo->url,-1); + if(tuneinfo->time >= 0) { + char *length = g_strdup_printf("%d", tuneinfo->time); + xmlnode_insert_data(xmlnode_new_child(tunenode, "length"),tuneinfo->artist,-1); + g_free(length); + } + if(tuneinfo->track >= 0) { + char *track = g_strdup_printf("%d", tuneinfo->year); + xmlnode_insert_data(xmlnode_new_child(tunenode, "track"),tuneinfo->track,-1); + g_free(track); + } + } + + jabber_pep_publish(js, publish); + /* publish is freed by jabber_pep_publish -> jabber_iq_send -> jabber_iq_free + (yay for well-defined memory management rules) */ +} diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/jabber/usertune.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/protocols/jabber/usertune.h Sun Jun 17 20:31:01 2007 +0000 @@ -0,0 +1,33 @@ +/* + * purple - Jabber Protocol Plugin + * + * Copyright (C) 2007, Andreas Monitzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _PURPLE_JABBER_USERTUNE_H_ +#define _PURPLE_JABBER_USERTUNE_H_ + +#include "jabber.h" + +/* Implementation of XEP-0118 */ + +void jabber_tune_init(void); + +void jabber_tune_set(PurpleConnection *gc, const PurpleTuneInfo *tuneinfo); + +#endif /* _PURPLE_JABBER_USERTUNE_H_ */ diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/msn/msn.c --- a/libpurple/protocols/msn/msn.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/msn/msn.c Sun Jun 17 20:31:01 2007 +0000 @@ -2082,6 +2082,7 @@ NULL, /* whiteboard_prpl_ops */ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/novell/novell.c --- a/libpurple/protocols/novell/novell.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/novell/novell.c Sun Jun 17 20:31:01 2007 +0000 @@ -3494,6 +3494,7 @@ NULL, /* whiteboard_prpl_ops */ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/oscar/libaim.c --- a/libpurple/protocols/oscar/libaim.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/oscar/libaim.c Sun Jun 17 20:31:01 2007 +0000 @@ -92,6 +92,7 @@ NULL, /* whiteboard_prpl_ops */ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/oscar/libicq.c --- a/libpurple/protocols/oscar/libicq.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/oscar/libicq.c Sun Jun 17 20:31:01 2007 +0000 @@ -92,6 +92,7 @@ NULL, /* whiteboard_prpl_ops */ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/qq/qq.c --- a/libpurple/protocols/qq/qq.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/qq/qq.c Sun Jun 17 20:31:01 2007 +0000 @@ -698,6 +698,7 @@ NULL, /* PurpleWhiteboardPrplOps */ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/sametime/sametime.c --- a/libpurple/protocols/sametime/sametime.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/sametime/sametime.c Sun Jun 17 20:31:01 2007 +0000 @@ -5132,7 +5132,8 @@ .new_xfer = mw_prpl_new_xfer, .offline_message = NULL, .whiteboard_prpl_ops = NULL, - .send_raw = NULL + .send_raw = NULL, + .publish_tune = NULL }; diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/simple/simple.c --- a/libpurple/protocols/simple/simple.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/simple/simple.c Sun Jun 17 20:31:01 2007 +0000 @@ -1798,6 +1798,7 @@ NULL, /* whiteboard_prpl_ops */ simple_send_raw, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/yahoo/yahoo.c --- a/libpurple/protocols/yahoo/yahoo.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/yahoo/yahoo.c Sun Jun 17 20:31:01 2007 +0000 @@ -4019,6 +4019,7 @@ &yahoo_whiteboard_prpl_ops, NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/protocols/zephyr/zephyr.c --- a/libpurple/protocols/zephyr/zephyr.c Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/protocols/zephyr/zephyr.c Sun Jun 17 20:31:01 2007 +0000 @@ -2921,6 +2921,7 @@ NULL, /* whiteboard_prpl_ops */ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ + NULL, /* publish_tune */ /* padding */ NULL, diff -r f108b91e2fee -r 3e437e86bd6e libpurple/prpl.h --- a/libpurple/prpl.h Sun Jun 17 19:38:24 2007 +0000 +++ b/libpurple/prpl.h Sun Jun 17 20:31:01 2007 +0000 @@ -91,6 +91,20 @@ gboolean secret; }; +typedef struct _PurpleTuneInfo PurpleTuneInfo; + +struct _PurpleTuneInfo { + char *artist; + char *title; + char *album; + char *genre; + char *comment; + char *track; /* either the index of the track in the album or the URL for a stream */ + int time; /* in seconds, -1 for unknown */ + int year; /* -1 for unknown (not compatible with very old music I guess) */ + char *url; +}; + /** * Protocol options * @@ -317,6 +331,8 @@ /* room list serialize */ char *(*roomlist_room_serialize)(PurpleRoomlistRoom *room); + + void (*publish_tune)(PurpleConnection *gc, const PurpleTuneInfo *tuneinfo); void (*_purple_reserved1)(void); void (*_purple_reserved2)(void);