static void ycht_progress_chatmsg(YchtConn *ycht, YchtPkt *pkt) { char *who, *what, *msg; PurpleChatConversation *c; PurpleConnection *gc = ycht->gc; who = g_list_nth_data(pkt->data, 1); what = g_list_nth_data(pkt->data, 2); if (!who || !what) return; c = purple_conversations_find_chat(gc, YAHOO_CHAT_ID); if (!c) return; msg = yahoo_string_decode(gc, what, 1); what = yahoo_codes_to_html(msg); g_free(msg); if (pkt->service == YCHT_SERVICE_CHATMSG_EMOTE) { char *tmp = g_strdup_printf("/me %s", what); g_free(what); what = tmp; } purple_serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, what, time(NULL)); g_free(what); }
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; }
void ggp_chat_got_message(PurpleConnection *gc, uint64_t chat_id, const char *message, time_t time, uin_t who) { ggp_chat_local_info *chat; uin_t me; me = ggp_str_to_uin(purple_account_get_username( purple_connection_get_account(gc))); chat = ggp_chat_get(gc, chat_id); if (!chat) { purple_debug_error("gg", "ggp_chat_got_message: " "chat %" G_GUINT64_FORMAT " doesn't exists\n", chat_id); return; } ggp_chat_open_conv(chat); if (who == me) { PurpleMessage *pmsg; pmsg = purple_message_new_outgoing( ggp_uin_to_str(who), message, 0); purple_message_set_time(pmsg, time); purple_conversation_write_message( PURPLE_CONVERSATION(chat->conv), pmsg); } else { purple_serv_got_chat_in(gc, chat->local_id, ggp_uin_to_str(who), PURPLE_MESSAGE_RECV, message, time); } }
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 void receive_chat_message(PurpleChatConversation *from, PurpleChatConversation *to, int id, const char *room, gpointer userdata) { const char *message = (const char *)userdata; PurpleConnection *to_gc = get_nullprpl_gc(purple_chat_conversation_get_nick(to)); purple_debug_info("nullprpl", "%s receives message from %s in chat room %s: %s\n", purple_chat_conversation_get_nick(to), purple_chat_conversation_get_nick(from), room, message); purple_serv_got_chat_in(to_gc, id, purple_chat_conversation_get_nick(from), PURPLE_MESSAGE_RECV, message, time(NULL)); }
void yahoo_process_conference_message(PurpleConnection *gc, struct yahoo_packet *pkt) { GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; int utf8 = 0; PurpleChatConversation *c; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: g_free(room); room = yahoo_string_decode(gc, pair->value, FALSE); break; case 3: if (g_utf8_validate(pair->value, -1, NULL)) { who = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_conference_message " "got non-UTF-8 string for key %d\n", pair->key); } break; case 14: msg = pair->value; break; case 97: utf8 = strtol(pair->value, NULL, 10); break; } } if (room && who && msg) { char *msg2; c = yahoo_find_conference(gc, room); if (!c) { g_free(room); return; } msg2 = yahoo_string_decode(gc, msg, utf8); msg = yahoo_codes_to_html(msg2); purple_serv_got_chat_in(gc, purple_chat_conversation_get_id(c), who, PURPLE_MESSAGE_RECV, msg, time(NULL)); g_free(msg); g_free(msg2); } g_free(room); }
static void nullprpl_chat_whisper(PurpleConnection *gc, int id, const char *who, const char *message) { const char *username = purple_account_get_username(purple_connection_get_account(gc)); PurpleChatConversation *chat = purple_conversations_find_chat(gc, id); purple_debug_info("nullprpl", "%s receives whisper from %s in chat room %s: %s\n", username, who, purple_conversation_get_name(PURPLE_CONVERSATION(chat)), message); /* receive whisper on recipient's account */ purple_serv_got_chat_in(gc, id, who, PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_WHISPER, message, time(NULL)); }
static void datacast_inform_user(MsnSwitchBoard *swboard, const char *who, const char *msg, const char *filename) { char *username, *str; PurpleAccount *account; PurpleBuddy *b; PurpleConnection *pc; gboolean chat; account = swboard->session->account; pc = purple_account_get_connection(account); if ((b = purple_blist_find_buddy(account, who)) != NULL) username = g_markup_escape_text(purple_buddy_get_alias(b), -1); else username = g_markup_escape_text(who, -1); str = g_strdup_printf(msg, username, filename); g_free(username); swboard->flag |= MSN_SB_FLAG_IM; if (swboard->current_users > 1) chat = TRUE; else chat = FALSE; if (swboard->conv == NULL) { if (chat) swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_chat( purple_account_get_connection(account), swboard->chat_id)); else { swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account( who, account)); if (swboard->conv == NULL) swboard->conv = PURPLE_CONVERSATION(purple_im_conversation_new(account, who)); } } if (chat) purple_serv_got_chat_in(pc, purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(swboard->conv)), who, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM, str, time(NULL)); else purple_serv_got_im(pc, who, str, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM, time(NULL)); g_free(str); }
void fb_util_serv_got_chat_in(PurpleConnection *gc, gint id, const gchar *who, const gchar *text, PurpleMessageFlags flags, guint64 timestamp) { const gchar *name; PurpleAccount *acct; PurpleChatConversation *conv; PurpleMessage *msg; if (!(flags & PURPLE_MESSAGE_SEND)) { purple_serv_got_chat_in(gc, id, who, flags, text, timestamp); return; } acct = purple_connection_get_account(gc); conv = purple_conversations_find_chat(gc, id); name = purple_account_get_username(acct); msg = purple_message_new_outgoing(name, text, flags); purple_message_set_time(msg, timestamp); purple_conversation_write_message(PURPLE_CONVERSATION(conv), msg); }
/************************************************************************** * Message Handlers **************************************************************************/ void msn_plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { PurpleConnection *gc; const char *body; char *body_enc; char *body_final; size_t body_len; const char *passport; const char *value; gc = purple_account_get_connection(cmdproc->session->account); body = msn_message_get_bin_data(msg, &body_len); body_enc = g_markup_escape_text(body, body_len); passport = msg->remote_user; if (!strcmp(passport, "*****@*****.**") && strstr(body, "immediate security update")) { return; } #if 0 if ((value = msn_message_get_header_value(msg, "User-Agent")) != NULL) { purple_debug_misc("msn", "User-Agent = '%s'\n", value); } #endif if ((value = msn_message_get_header_value(msg, "X-MMS-IM-Format")) != NULL) { char *pre, *post; msn_parse_format(value, &pre, &post); body_final = g_strdup_printf("%s%s%s", pre ? pre : "", body_enc ? body_enc : "", post ? post : ""); g_free(pre); g_free(post); g_free(body_enc); } else { body_final = body_enc; } if (cmdproc->servconn->type == MSN_SERVCONN_SB) { MsnSwitchBoard *swboard = cmdproc->data; swboard->flag |= MSN_SB_FLAG_IM; if (swboard->current_users > 1 || ((swboard->conv != NULL) && PURPLE_IS_CHAT_CONVERSATION(swboard->conv))) { /* If current_users is always ok as it should then there is no need to * check if this is a chat. */ if (swboard->current_users <= 1) purple_debug_misc("msn", "plain_msg: current_users(%d)\n", swboard->current_users); purple_serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, time(NULL)); if (swboard->conv == NULL) { swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_chat(gc, swboard->chat_id)); swboard->flag |= MSN_SB_FLAG_IM; } } else if (!g_str_equal(passport, purple_account_get_username(purple_connection_get_account(gc)))) { /* Don't im ourselves ... */ purple_serv_got_im(gc, passport, body_final, 0, time(NULL)); if (swboard->conv == NULL) { swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account( passport, purple_connection_get_account(gc))); swboard->flag |= MSN_SB_FLAG_IM; } } } else { purple_serv_got_im(gc, passport, body_final, 0, time(NULL)); } g_free(body_final); }
void yahoo_process_chat_message(PurpleConnection *gc, struct yahoo_packet *pkt) { char *room = NULL, *who = NULL, *msg = NULL, *msg2; int msgtype = 1, utf8 = 1; /* default to utf8 */ PurpleChatConversation *c = NULL; GSList *l; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 97: utf8 = strtol(pair->value, NULL, 10); break; case 104: g_free(room); room = yahoo_string_decode(gc, pair->value, TRUE); break; case 109: if (g_utf8_validate(pair->value, -1, NULL)) { who = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_chat_message " "got non-UTF-8 string for key %d\n", pair->key); } break; case 117: if (g_utf8_validate(pair->value, -1, NULL)) { msg = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_chat_message " "got non-UTF-8 string for key %d\n", pair->key); } break; case 124: msgtype = strtol(pair->value, NULL, 10); break; } } c = purple_conversations_find_chat(gc, YAHOO_CHAT_ID); if (!who || !c) { if (room) g_free(room); /* we still get messages after we part, funny that */ return; } if (!msg) { purple_debug_misc("yahoo", "Got a message packet with no message.\nThis probably means something important, but we're ignoring it.\n"); return; } msg2 = yahoo_string_decode(gc, msg, utf8); msg = yahoo_codes_to_html(msg2); g_free(msg2); if (msgtype == 2 || msgtype == 3) { char *tmp; tmp = g_strdup_printf("/me %s", msg); g_free(msg); msg = tmp; } purple_serv_got_chat_in(gc, YAHOO_CHAT_ID, who, PURPLE_MESSAGE_RECV, msg, time(NULL)); g_free(msg); g_free(room); }
void yahoo_process_conference_decline(PurpleConnection *gc, struct yahoo_packet *pkt) { GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; PurpleChatConversation *c = NULL; int utf8 = 0; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: g_free(room); room = yahoo_string_decode(gc, pair->value, FALSE); break; case 54: if (g_utf8_validate(pair->value, -1, NULL)) { who = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_conference_decline " "got non-UTF-8 string for key %d\n", pair->key); } break; case 14: g_free(msg); msg = yahoo_string_decode(gc, pair->value, FALSE); break; case 97: utf8 = strtol(pair->value, NULL, 10); break; } } if (!purple_account_privacy_check(purple_connection_get_account(gc), who)) { g_free(room); g_free(msg); return; } if (who && room) { /* make sure we're in the room before we process a decline message for it */ if((c = yahoo_find_conference(gc, room))) { char *tmp = NULL, *msg_tmp = NULL; if(msg) { msg_tmp = yahoo_string_decode(gc, msg, utf8); msg = yahoo_codes_to_html(msg_tmp); purple_serv_got_chat_in(gc, purple_chat_conversation_get_id(c), who, PURPLE_MESSAGE_RECV, msg, time(NULL)); g_free(msg_tmp); g_free(msg); } tmp = g_strdup_printf(_("%s has declined to join."), who); purple_conversation_write_system_message(PURPLE_CONVERSATION(c), tmp, PURPLE_MESSAGE_NO_LINKIFY); g_free(tmp); } g_free(room); } }