int ggp_chat_send(PurpleConnection *gc, int local_id, PurpleMessage *msg) { GGPInfo *info = purple_connection_get_protocol_data(gc); PurpleChatConversation *conv; ggp_chat_local_info *chat; gboolean succ = TRUE; const gchar *me; gchar *gg_msg; chat = ggp_chat_get_local(gc, local_id); if (!chat) { purple_debug_error("gg", "ggp_chat_send: " "chat %u doesn't exists\n", local_id); return -1; } conv = purple_conversations_find_chat_with_account( ggp_chat_get_name_from_id(chat->id), purple_connection_get_account(gc)); gg_msg = ggp_message_format_to_gg(PURPLE_CONVERSATION(conv), purple_message_get_contents(msg)); if (gg_chat_send_message(info->session, chat->id, gg_msg, TRUE) < 0) succ = FALSE; g_free(gg_msg); me = purple_account_get_username(purple_connection_get_account(gc)); purple_serv_got_chat_in(gc, chat->local_id, me, purple_message_get_flags(msg), purple_message_get_contents(msg), purple_message_get_time(msg)); return succ ? 0 : -1; }
static void displayed_chat_msg_cb(PurpleConversation *conv, PurpleMessage *msg, gpointer data) { purple_debug_misc("gtk-signals test", "displayed-chat-msg (%s, %s)\n", purple_conversation_get_name(conv), purple_message_get_contents(msg)); }
int yahoo_c_send(PurpleConnection *gc, int id, PurpleMessage *msg) { PurpleChatConversation *c; int ret; YahooData *yd; const gchar *what = purple_message_get_contents(msg); PurpleMessageFlags flags = purple_message_get_flags(msg); yd = purple_connection_get_protocol_data(gc); if (!yd) return -1; c = purple_conversations_find_chat(gc, id); if (!c) return -1; if (id != YAHOO_CHAT_ID) { GList *users; users = purple_chat_conversation_get_users(c); ret = yahoo_conf_send(gc, purple_connection_get_display_name(gc), purple_conversation_get_name(PURPLE_CONVERSATION(c)), users, what); g_list_free(users); } else { ret = yahoo_chat_send(gc, purple_connection_get_display_name(gc), purple_conversation_get_name(PURPLE_CONVERSATION(c)), what, flags); if (!ret) purple_serv_got_chat_in(gc, purple_chat_conversation_get_id(c), purple_connection_get_display_name(gc), flags, what, time(NULL)); } return ret; }
static gboolean writing_msg(PurpleConversation *conv, PurpleMessage *msg, gpointer _unused) { GString *t; GList *iter, *urls, *next; int c = 0; if (purple_message_get_flags(msg) & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_INVISIBLE)) return FALSE; urls = g_object_get_data(G_OBJECT(conv), "TinyURLs"); if (urls != NULL) /* message was cancelled somewhere? Reset. */ g_list_foreach(urls, free_urls, NULL); g_list_free(urls); urls = extract_urls(purple_message_get_contents(msg)); if (!urls) return FALSE; t = g_string_new(g_strdup(purple_message_get_contents(msg))); for (iter = urls; iter; iter = next) { next = iter->next; if (g_utf8_strlen((char *)iter->data, -1) >= purple_prefs_get_int(PREF_LENGTH)) { int pos, x = 0; gchar *j, *s, *str, *orig; glong len = g_utf8_strlen(iter->data, -1); s = g_strdup(t->str); orig = s; str = g_strdup_printf("[%d]", ++c); while ((j = strstr(s, iter->data))) { /* replace all occurrences */ pos = j - orig + (x++ * 3); s = j + len; t = g_string_insert(t, pos + len, str); if (*s == '\0') break; } g_free(orig); g_free(str); continue; } else { g_free(iter->data); urls = g_list_delete_link(urls, iter); } } purple_message_set_contents(msg, t->str); g_string_free(t, TRUE); if (conv != NULL) g_object_set_data(G_OBJECT(conv), "TinyURLs", urls); return FALSE; }
/*------------------------------------------------------------------------ * Send a message to a contact * * @param gc The connection object * @param who The username of the recipient * @param message The message text * @param flags Message flags (defined in conversation.h) * @return Positive value (success, and echo to conversation window) Zero (success, no echo) Negative value (error) */ static int mxit_send_im(PurpleConnection* gc, PurpleMessage *msg) { mxit_send_message(purple_connection_get_protocol_data(gc), purple_message_get_recipient(msg), purple_message_get_contents(msg), TRUE, FALSE); return 1; /* echo to conversation window */ }
static gboolean displaying_chat_msg_cb(PurpleConversation *conv, PurpleMessage *pmsg, gpointer data) { purple_debug_misc("gtk-signals test", "displaying-chat-msg (%s, %s)\n", purple_conversation_get_name(conv), purple_message_get_contents(pmsg)); return FALSE; }
int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args) { PurpleConnection *gc = purple_account_get_connection(irc->account); char *action, *escaped, *dst, **newargs; const char *src; char *msg; PurpleConversation *convo; PurpleMessage *pmsg; if (!args || !args[0] || !gc) return 0; convo = purple_conversations_find_with_account(target, irc->account); msg = g_strdup_printf("/me %s", args[0]); /* XXX: we'd prefer to keep this in conversation.c */ if (PURPLE_IS_IM_CONVERSATION(convo)) { pmsg = purple_message_new_outgoing( purple_conversation_get_name(convo), msg, 0); purple_signal_emit(purple_conversations_get_handle(), "sending-im-msg", irc->account, pmsg); } else { pmsg = purple_message_new_outgoing(NULL, msg, 0); purple_signal_emit(purple_conversations_get_handle(), "sending-chat-msg", irc->account, pmsg, purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(convo))); } g_free(msg); if (purple_message_is_empty(pmsg)) return 0; msg = g_strdup(purple_message_get_contents(pmsg)); /* XXX: is it really necessary? */ if (strncmp(msg, "/me ", 4) != 0) { newargs = g_new0(char *, 2); newargs[0] = g_strdup(target); newargs[1] = msg; irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); g_free(newargs[0]); g_free(newargs); } else {
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; }
/* sent-im-msg */ static void sent_im_msg(PurpleAccount *account, PurpleMessage *msg, gpointer _unused) { PurpleBuddy *buddy; guint interval, words; CapStatistics *stats = NULL; buddy = purple_blist_find_buddy(account, purple_message_get_recipient(msg)); if (buddy == NULL) return; interval = purple_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 60; words = word_count(purple_message_get_contents(msg)); stats = get_stats_for(buddy); insert_word_count(purple_account_get_username(account), purple_message_get_recipient(msg), words); stats->last_message = time(NULL); stats->last_message_status_id = purple_status_get_id(get_status_for(buddy)); if(stats->timeout_source_id != 0) purple_timeout_remove(stats->timeout_source_id); stats->timeout_source_id = purple_timeout_add_seconds(interval, max_message_difference_cb, stats); }