/* Exported functions */ DBUS_EXPORT void music_messaging_change_request(const int session, const char *command, const char *parameters) { MMConversation *mmconv = (MMConversation *)g_list_nth_data(conversations, session); if (mmconv->started) { if (mmconv->originator) { const char *name = purple_conversation_get_name(mmconv->conv); send_change_request (session, name, command, parameters); } else { GString *to_send = g_string_new(""); g_string_append_printf(to_send, "##MM## request %s %s##MM##", command, parameters); purple_conversation_send(mmconv->conv, to_send->str); purple_debug_misc("musicmessaging", "Sent request: %s\n", to_send->str); } } }
static gboolean intercept_sent(PurpleAccount *account, PurpleMessage *msg, void* pData) { const gchar *cont = purple_message_get_contents(msg); if (purple_message_is_empty(msg)) return FALSE; if (0 == strncmp(cont, MUSICMESSAGING_PREFIX, strlen(MUSICMESSAGING_PREFIX))) { purple_debug_misc("purple-musicmessaging", "Sent MM Message: %s\n", cont); } else if (0 == strncmp(cont, MUSICMESSAGING_START_MSG, strlen(MUSICMESSAGING_START_MSG))) { purple_debug_misc("purple-musicmessaging", "Sent MM request.\n"); return FALSE; } else if (0 == strncmp(cont, MUSICMESSAGING_CONFIRM_MSG, strlen(MUSICMESSAGING_CONFIRM_MSG))) { purple_debug_misc("purple-musicmessaging", "Sent MM confirm.\n"); return FALSE; } else if (0 == strncmp(cont, "test1", strlen("test1"))) { purple_debug_misc("purple-musicmessaging", "\n\nTEST 1\n\n"); send_change_request(0, "test-id", "test-command", "test-parameters"); return FALSE; } else if (0 == strncmp(cont, "test2", strlen("test2"))) { purple_debug_misc("purple-musicmessaging", "\n\nTEST 2\n\n"); send_change_confirmed(1, "test-command", "test-parameters"); return FALSE; } else { return FALSE; /* Do nothing...procceed as normal */ } return TRUE; }
static gboolean intercept_sent(PurpleAccount *account, const char *who, char **message, void* pData) { if (message == NULL || *message == NULL || **message == '\0') return FALSE; if (0 == strncmp(*message, MUSICMESSAGING_PREFIX, strlen(MUSICMESSAGING_PREFIX))) { purple_debug_misc("purple-musicmessaging", "Sent MM Message: %s\n", *message); message = 0; } else if (0 == strncmp(*message, MUSICMESSAGING_START_MSG, strlen(MUSICMESSAGING_START_MSG))) { purple_debug_misc("purple-musicmessaging", "Sent MM request.\n"); return FALSE; } else if (0 == strncmp(*message, MUSICMESSAGING_CONFIRM_MSG, strlen(MUSICMESSAGING_CONFIRM_MSG))) { purple_debug_misc("purple-musicmessaging", "Sent MM confirm.\n"); return FALSE; } else if (0 == strncmp(*message, "test1", strlen("test1"))) { purple_debug_misc("purple-musicmessaging", "\n\nTEST 1\n\n"); send_change_request(0, "test-id", "test-command", "test-parameters"); return FALSE; } else if (0 == strncmp(*message, "test2", strlen("test2"))) { purple_debug_misc("purple-musicmessaging", "\n\nTEST 2\n\n"); send_change_confirmed(1, "test-command", "test-parameters"); return FALSE; } else { return FALSE; /* Do nothing...procceed as normal */ } return TRUE; }
static gboolean intercept_received(PurpleAccount *account, char **sender, char **message, PurpleConversation *conv, int *flags) { MMConversation *mmconv; if (conv == NULL) { /* XXX: This is just to avoid a crash (#2726). * We may want to create the conversation instead of returning from here */ return FALSE; } mmconv = mmconv_from_conv(conv); purple_debug_misc("purple-musicmessaging", "Intercepted: %s\n", *message); if (strstr(*message, MUSICMESSAGING_PREFIX)) { char *parsed_message = strtok(strstr(*message, MUSICMESSAGING_PREFIX), "<"); purple_debug_misc("purple-musicmessaging", "Received an MM Message: %s\n", parsed_message); if (mmconv->started) { if (strstr(parsed_message, "request")) { if (mmconv->originator) { int session = mmconv_from_conv_loc(conv); char *id = (mmconv->conv)->name; char *command; char *parameters; purple_debug_misc("purple-musicmessaging", "Sending request to gscore.\n"); /* Get past the first two terms - '##MM##' and 'request' */ strtok(parsed_message, " "); /* '##MM##' */ strtok(NULL, " "); /* 'request' */ command = strtok(NULL, " "); parameters = strtok(NULL, "#"); send_change_request (session, id, command, parameters); } } else if (strstr(parsed_message, "confirm")) { if (!mmconv->originator) { int session = mmconv_from_conv_loc(conv); char *command; char *parameters; purple_debug_misc("purple-musicmessaging", "Sending confirmation to gscore.\n"); /* Get past the first two terms - '##MM##' and 'confirm' */ strtok(parsed_message, " "); /* '##MM##' */ strtok(NULL, " "); /* 'confirm' */ command = strtok(NULL, " "); parameters = strtok(NULL, "#"); send_change_confirmed (session, command, parameters); } } else if (strstr(parsed_message, "failed")) { char *id; char *command; /* Get past the first two terms - '##MM##' and 'confirm' */ strtok(parsed_message, " "); /* '##MM##' */ strtok(NULL, " "); /* 'failed' */ id = strtok(NULL, " "); command = strtok(NULL, " "); /* char *parameters = strtok(NULL, "#"); DONT NEED PARAMETERS */ if ((mmconv->conv)->name == id) { purple_notify_message(plugin_pointer, PURPLE_NOTIFY_MSG_ERROR, _("Music Messaging"), _("There was a conflict in running the command:"), command, NULL, NULL); } } } message = 0; } else if (strstr(*message, MUSICMESSAGING_START_MSG)) { purple_debug_misc("purple-musicmessaging", "Received MM request.\n"); if (!(mmconv->originator)) { mmconv->requested = TRUE; return FALSE; } } else if (strstr(*message, MUSICMESSAGING_CONFIRM_MSG)) { purple_debug_misc("purple-musicmessagin", "Received MM confirm.\n"); if (mmconv->originator) { start_session(mmconv); return FALSE; } } else { return FALSE; /* Do nothing. */ } return TRUE; }