static gboolean timer_cb(void *p) { serv_got_chat_in(p, CHAT_ID, "who", 0, "message1", time(NULL)); serv_got_chat_in(p, CHAT_ID, "who", 0, "message2", time(NULL)); serv_got_chat_in(p, CHAT_ID, "who", 0, "message3", time(NULL)); return TRUE; }
int yahoo_c_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags) { PurpleConversation *c; int ret; YahooData *yd; yd = (YahooData *) gc->proto_data; if (!yd) return -1; c = purple_find_chat(gc, id); if (!c) return -1; if (id != YAHOO_CHAT_ID) { ret = yahoo_conf_send(gc, purple_connection_get_display_name(gc), purple_conversation_get_name(c), purple_conv_chat_get_users(PURPLE_CONV_CHAT(c)), what); } else { ret = yahoo_chat_send(gc, purple_connection_get_display_name(gc), purple_conversation_get_name(c), what, flags); if (!ret) serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)), purple_connection_get_display_name(gc), flags, what, time(NULL)); } return ret; }
/*------------------------------------------------------------------------ * User has entered a message in a chatroom window, send it to the MXit server. * * @param gc The connection object * @param id The chat room ID * @param message The sent message data * @param flags The message flags * @return Indicates success / failure */ int mxit_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags) { struct MXitSession* session = (struct MXitSession*) gc->proto_data; struct multimx* multimx = NULL; const char* nickname; purple_debug_info(MXIT_PLUGIN_ID, "Groupchat %i message send: '%s'\n", id, message); /* Find matching MultiMX group */ multimx = find_room_by_id(session, id); if (multimx == NULL) { purple_debug_error(MXIT_PLUGIN_ID, "Could not find groupchat %i\n", id); return -1; } /* Send packet to MXit */ mxit_send_message(session, multimx->roomid, message, TRUE, FALSE); /* Determine our nickname to display */ if (multimx->nickname) nickname = multimx->nickname; else nickname = purple_account_get_alias(purple_connection_get_account(gc)); /* local alias */ /* Display message in chat window */ serv_got_chat_in(gc, id, nickname, flags, message, time(NULL)); return 0; }
static int waprpl_send_chat(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags) { whatsapp_connection * wconn = purple_connection_get_protocol_data(gc); PurpleAccount *account = purple_connection_get_account(gc); PurpleConversation *convo = purple_find_chat(gc, id); PurpleBlistNode* node = purple_blist_get_root(); GHashTable* hasht = NULL; while (node != 0) { if (PURPLE_BLIST_NODE_IS_CHAT(node)) { PurpleChat * ch = PURPLE_CHAT(node); if (purple_chat_get_account(ch) == account) { hasht = purple_chat_get_components(ch); if (chatid_to_convo(g_hash_table_lookup(hasht, "id")) == id) { break; } } } node = purple_blist_node_next(node,FALSE); } char * chat_id = g_hash_table_lookup(hasht, "id"); waAPI_sendchat(wconn->waAPI,chat_id,message); waprpl_check_output(gc); serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)), purple_connection_get_display_name(gc), PURPLE_MESSAGE_SEND, message, time(NULL)); purple_conv_im_write(PURPLE_CONV_CHAT(convo), purple_connection_get_display_name(gc), message, PURPLE_MESSAGE_SEND, time(NULL)); return 1; }
static int irc_chat_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags) { struct irc_conn *irc = gc->proto_data; PurpleConversation *convo = purple_find_chat(gc, id); const char *args[2]; char *tmp; if (!convo) { purple_debug(PURPLE_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); return -EINVAL; } #if 0 if (*what == '/') { return irc_parse_cmd(irc, convo->name, what + 1); } #endif purple_markup_html_to_xhtml(what, NULL, &tmp); args[0] = convo->name; args[1] = tmp; irc_cmd_privmsg(irc, "msg", NULL, args); serv_got_chat_in(gc, id, purple_connection_get_display_name(gc), 0, what, time(NULL)); g_free(tmp); return 0; }
void p2tgl_got_chat_in (struct tgl_state *TLS, tgl_peer_id_t chat, tgl_peer_id_t who, const char *message, int flags, time_t when) { char *name = peer_strdup_id(who); serv_got_chat_in(tg_get_conn(TLS), tgl_get_peer_id (chat), name, flags, message, when); g_free (name); }
int yahoo_c_send(GaimConnection *gc, int id, const char *what, GaimMessageFlags flags) { GaimConversation *c; int ret; struct yahoo_data *yd; yd = (struct yahoo_data *) gc->proto_data; if (!yd) return -1; c = gaim_find_chat(gc, id); if (!c) return -1; if (id != YAHOO_CHAT_ID) { ret = yahoo_conf_send(gc, gaim_connection_get_display_name(gc), gaim_conversation_get_name(c), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)), what); } else { ret = yahoo_chat_send(gc, gaim_connection_get_display_name(gc), gaim_conversation_get_name(c), what, flags); if (!ret) serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), gaim_connection_get_display_name(gc), 0, what, time(NULL)); } return ret; }
void yahoo_process_conference_message(GaimConnection *gc, struct yahoo_packet *pkt) { GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; GaimConversation *c; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: room = pair->value; break; case 3: who = pair->value; break; case 14: msg = pair->value; break; } } if (room && who && msg) { c = yahoo_find_conference(gc, room); if (!c) return; msg = yahoo_codes_to_html(msg); serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(c)), who, 0, msg, time(NULL)); g_free(msg); } }
static int gaym_chat_send(GaimConnection * gc, int id, const char *what) { struct gaym_conn *gaym = gc->proto_data; GaimConversation *convo = gaim_find_chat(gc, id); const char *args[2]; char *tmp; if (!convo) { gaim_debug(GAIM_DEBUG_ERROR, "gaym", "chat send on nonexistent chat\n"); return -EINVAL; } #if 0 if (*what == '/') { return gaym_parse_cmd(gaym, convo->name, what + 1); } #endif args[0] = convo->name; args[1] = what; gaym_cmd_privmsg(gaym, "msg", NULL, args); tmp = gaim_escape_html(what); serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, tmp, time(NULL)); g_free(tmp); return 0; }
static int irc_chat_send(GaimConnection *gc, int id, const char *what, GaimMessageFlags flags) { struct irc_conn *irc = gc->proto_data; GaimConversation *convo = gaim_find_chat(gc, id); const char *args[2]; char *tmp; if (!convo) { gaim_debug(GAIM_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); return -EINVAL; } #if 0 if (*what == '/') { return irc_parse_cmd(irc, convo->name, what + 1); } #endif tmp = gaim_unescape_html(what); args[0] = convo->name; args[1] = tmp; irc_cmd_privmsg(irc, "msg", NULL, args); serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, what, time(NULL)); g_free(tmp); return 0; }
void yahoo_process_conference_decline(PurpleConnection *gc, struct yahoo_packet *pkt) { GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; PurpleConversation *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: who = pair->value; 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_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); serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)), who, 0, msg, time(NULL)); g_free(msg_tmp); g_free(msg); } tmp = g_strdup_printf(_("%s has declined to join."), who); purple_conversation_write(c, NULL, tmp, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LINKIFY, time(NULL)); g_free(tmp); } g_free(room); } }
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 */ PurpleConversation *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: who = pair->value; break; case 117: msg = pair->value; break; case 124: msgtype = strtol(pair->value, NULL, 10); break; } } c = purple_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; } serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, msg, time(NULL)); g_free(msg); g_free(room); }
static void conv_add_message(PurpleConnection * gc, const char *who, const char *msg, const char *author, unsigned long timestamp) { if (isgroup(who)) { PurpleConversation *convo = get_open_combo(who, gc); if (convo) serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)), author, PURPLE_MESSAGE_RECV, msg, timestamp); } else { serv_got_im(gc, who, msg, PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_IMAGES, timestamp); } }
void yahoo_process_chat_message(GaimConnection *gc, struct yahoo_packet *pkt) { char *room = NULL, *who = NULL, *msg = NULL; int msgtype = 1; GaimConversation *c = NULL; GSList *l; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 104: room = pair->value; break; case 109: who = pair->value; break; case 117: msg = pair->value; break; case 124: msgtype = strtol(pair->value, NULL, 10); break; } } if (!who) return; c = gaim_find_chat(gc, YAHOO_CHAT_ID); if (!c) { /* we still get messages after we part, funny that */ return; } if (!msg) { gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Got a message packet with no message.\nThis probably means something important, but we're ignoring it.\n"); return; } msg = yahoo_codes_to_html(msg); if (msgtype == 2 || msgtype == 3) { char *tmp; tmp = g_strdup_printf("/me %s", msg); g_free(msg); msg = tmp; } serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, msg, time(NULL)); g_free(msg); }
void hon_parse_chat_message(PurpleConnection *gc,gchar* buffer){ hon_account *hon = gc->proto_data; guint32 account_id; guint32 chan_id; gchar* msg; gchar* sender; account_id = read_guint32(buffer); chan_id = read_guint32(buffer); msg = hon2html(buffer); sender = g_hash_table_lookup(hon->id2nick,GINT_TO_POINTER(account_id)); serv_got_chat_in(gc,chan_id,sender? sender : "unknown user" ,PURPLE_MESSAGE_RECV,msg,time(NULL)); g_free(msg); }
static void purplemot_chat_whisper(PurpleConnection *gc, int id, const char *who, const char *message) { const char *username = gc->account->username; PurpleConversation *conv = purple_find_chat(gc, id); purple_debug_info("purplemot", "%s receives whisper from %s in chat room %s: %s\n", username, who, conv->name, message); // receive whisper on recipient's account serv_got_chat_in(gc, id, who, PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_WHISPER, message, time(NULL)); }
static void datacast_inform_user(NPSwitchBoard *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_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 |= NP_SB_FLAG_IM; if (swboard->current_users > 1) chat = TRUE; else chat = FALSE; if (swboard->conv == NULL) { if (chat) swboard->conv = purple_find_chat(account->gc, swboard->chat_id); else { swboard->conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, account); if (swboard->conv == NULL) swboard->conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, who); } } if (chat) serv_got_chat_in(pc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(swboard->conv)), who, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM, str, time(NULL)); else serv_got_im(pc, who, str, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM, time(NULL)); g_free(str); }
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; PurpleConversation *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: who = pair->value; 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); serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)), who, 0, msg, time(NULL)); g_free(msg); g_free(msg2); } g_free(room); }
static void got_attention(PurpleConnection *gc, int id, const char *who, guint type_code) { PurpleMessageFlags flags; PurpleAttentionType *attn; PurpleBuddy *buddy; const char *alias; gchar *description; time_t mtime; mtime = time(NULL); attn = purple_get_attention_type_from_code(gc->account, type_code); /* PURPLE_MESSAGE_NOTIFY is for attention messages. */ flags = PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NOTIFY | PURPLE_MESSAGE_RECV; /* TODO: if (attn->icon_name) is non-null, use it to lookup an emoticon and display * it next to the attention command. And if it is null, display a generic icon. */ if ((buddy = purple_find_buddy(purple_connection_get_account(gc), who)) != NULL) alias = purple_buddy_get_contact_alias(buddy); else alias = who; if (attn && purple_attention_type_get_incoming_desc(attn)) { description = g_strdup_printf(purple_attention_type_get_incoming_desc(attn), alias); } else { description = g_strdup_printf(_("%s has requested your attention!"), alias); } purple_debug_info("server", "got_attention: got '%s' from %s\n", description, who); if (id == -1) serv_got_im(gc, who, description, flags, mtime); else serv_got_chat_in(gc, id, who, flags, description, mtime); /* TODO: sounds (depending on PurpleAttentionType), shaking, etc. */ g_free(description); }
static void irc_msg_handle_privmsg(struct irc_conn *irc, const char *name, const char *from, const char *to, const char *rawmsg, gboolean notice) { PurpleConnection *gc = purple_account_get_connection(irc->account); PurpleConversation *convo; char *tmp; char *msg; char *nick; if (!gc) return; nick = irc_mask_nick(from); tmp = irc_parse_ctcp(irc, nick, to, rawmsg, notice); if (!tmp) { g_free(nick); return; } msg = irc_escape_privmsg(tmp, -1); g_free(tmp); tmp = irc_mirc2html(msg); g_free(msg); msg = tmp; if (notice) { tmp = g_strdup_printf("(notice) %s", msg); g_free(msg); msg = tmp; } if (!purple_utf8_strcasecmp(to, purple_connection_get_display_name(gc))) { serv_got_im(gc, nick, msg, 0, time(NULL)); } else { convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, to, irc->account); if (convo) serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)), nick, 0, msg, time(NULL)); else purple_debug_error("irc", "Got a %s on %s, which does not exist\n", notice ? "NOTICE" : "PRIVMSG", to); } g_free(msg); g_free(nick); }
void qq_room_got_chat_in(PurpleConnection *gc, guint32 room_id, guint32 uid_from, const gchar *msg, time_t in_time) { PurpleConversation *conv; qq_data *qd; qq_buddy_data *bd; qq_room_data *rmd; gchar *from; g_return_if_fail(gc != NULL && room_id != 0); g_return_if_fail(msg != NULL); qd = (qq_data *)gc->proto_data; conv = purple_find_chat(gc, room_id); rmd = qq_room_data_find(gc, room_id); g_return_if_fail(rmd != NULL); purple_debug_info("QQ", "is_show_chat:%d\n", qd->is_show_chat); if (NULL == conv && qd->is_show_chat) { conv = qq_room_conv_open(gc, rmd); } if (NULL == conv) { purple_debug_info("QQ", "Conversion of %u is not open, missing from %d:/n%s/v\n", room_id, uid_from, msg); return; } if (uid_from != 0) { bd = qq_room_buddy_find(rmd, uid_from); if (bd == NULL || bd->nickname == NULL) from = g_strdup_printf("%u", uid_from); else from = g_strdup(bd->nickname); } else { from = g_strdup(""); } serv_got_chat_in(gc, room_id, from, 0, msg, in_time); g_free(from); }
void hon_parse_emote_roll(PurpleConnection *gc,gchar* buffer, guint16 packet_id){ hon_account *hon = gc->proto_data; guint32 account_id; guint32 chan_id; gchar* msg; PurpleConversation* chat; gchar* sender; account_id = read_guint32(buffer); chan_id = read_guint32(buffer); msg = hon2html(buffer); gchar* tmp = msg; if (packet_id == HON_SC_CHANNEL_EMOTE) msg = g_strdup_printf("[%s] %s" , _("EMOTE"),msg); else msg = g_strdup_printf("[%s] %s" , _("ROLL"),msg); g_free(tmp); chat = purple_find_chat(gc,chan_id); sender = g_hash_table_lookup(hon->id2nick,GINT_TO_POINTER(account_id)); serv_got_chat_in(gc,chan_id,sender ,PURPLE_MESSAGE_RECV,msg,time(NULL)); g_free(msg); }
void msn_switchboard_show_ink(MsnSwitchBoard *swboard, const char *passport, const char *data) { PurpleConnection *gc; guchar *image_data; size_t image_len; int imgid; char *image_msg; if (!purple_str_has_prefix(data, "base64:")) { purple_debug_error("msn", "Ignoring Ink not in Base64 format.\n"); return; } gc = purple_account_get_connection(swboard->session->account); data += sizeof("base64:") - 1; image_data = purple_base64_decode(data, &image_len); if (!image_data || !image_len) { purple_debug_error("msn", "Unable to decode Ink from Base64 format.\n"); return; } imgid = purple_imgstore_add_with_id(image_data, image_len, NULL); image_msg = g_strdup_printf("<IMG ID='%d'/>", imgid); if (swboard->current_users > 1 || ((swboard->conv != NULL) && purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT)) serv_got_chat_in(gc, swboard->chat_id, passport, 0, image_msg, time(NULL)); else serv_got_im(gc, passport, image_msg, 0, time(NULL)); purple_imgstore_unref_by_id(imgid); g_free(image_msg); }
void PurpleLine::write_message(line::Message &msg, bool replay) { std::string text; int flags = 0; time_t mtime = (time_t)(msg.createdTime / 1000); bool sent = (msg.from == profile.mid); if (std::find(recent_messages.cbegin(), recent_messages.cend(), msg.id) != recent_messages.cend()) { // We already processed this message. User is probably talking with himself. return; } // Hack if (msg.from == msg.to) push_recent_message(msg.id); PurpleConversation *conv = purple_find_conversation_with_account( (msg.toType == line::MIDType::USER ? PURPLE_CONV_TYPE_IM : PURPLE_CONV_TYPE_CHAT), ((!sent && msg.toType == line::MIDType::USER) ? msg.from.c_str() : msg.to.c_str()), acct); // If this is a new received IM, create the conversation if it doesn't exist if (!conv && !sent && msg.toType == line::MIDType::USER) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, msg.from.c_str()); // If this is a new conversation, we're not replaying history and history hasn't been fetched // yet, queue the message instead of showing it. if (conv && !replay) { auto *queue = (std::vector<line::Message> *) purple_conversation_get_data(conv, "line-message-queue"); if (queue) { queue->push_back(msg); return; } } // Replaying messages from history // Unfortunately Pidgin displays messages with this flag with odd formatting and no username. // Disable for now. //if (replay) // flags |= PURPLE_MESSAGE_NO_LOG; switch (msg.contentType) { case line::ContentType::NONE: // actually text case line::ContentType::LOCATION: if (msg.__isset.location) { line::Location &loc = msg.location; text = markup_escape(loc.title) + " | <a href=\"https://maps.google.com/?q=" + url_encode(loc.address) + "&ll=" + std::to_string(loc.latitude) + "," + std::to_string(loc.longitude) + "\">" + (loc.address.size() ? markup_escape(loc.address) : "(no address)") + "</a>"; } else { text = markup_escape(msg.text); } break; case line::ContentType::STICKER: { std::string id = get_sticker_id(msg); if (id == "") { text = "<em>[Broken sticker]</em>"; purple_debug_warning("line", "Got a broken sticker.\n"); } else { text = id; if (conv && purple_conv_custom_smiley_add(conv, id.c_str(), "id", id.c_str(), TRUE)) { http.request(get_sticker_url(msg), [this, id, conv](int status, const guchar *data, gsize len) { if (status == 200 && data && len > 0) { purple_conv_custom_smiley_write( conv, id.c_str(), data, len); } else { purple_debug_warning( "line", "Couldn't download sticker. Status: %d\n", status); } purple_conv_custom_smiley_close(conv, id.c_str()); }); } } } break; case line::ContentType::IMAGE: case line::ContentType::VIDEO: // Videos could really benefit from streaming... { std::string type_std = line::_ContentType_VALUES_TO_NAMES.at(msg.contentType); std::string id = "[LINE " + type_std + " " + msg.id + "]"; text = id; if (conv) { text += " <font color=\"#888888\">/open " + conv_attachment_add(conv, msg.contentType, msg.id) + "</font>"; } if (!conv || !purple_conv_custom_smiley_add(conv, id.c_str(), "id", id.c_str(), TRUE)) { break; } if (msg.contentPreview.size() > 0) { purple_conv_custom_smiley_write( conv, id.c_str(), (const guchar *)msg.contentPreview.c_str(), msg.contentPreview.size()); purple_conv_custom_smiley_close(conv, id.c_str()); } else { std::string preview_url = msg.contentMetadata.count("PREVIEW_URL") ? msg.contentMetadata["PREVIEW_URL"] : std::string(LINE_OS_URL) + "os/m/" + msg.id + "/preview"; http.request(preview_url, HTTPFlag::AUTH | HTTPFlag::LARGE, [this, id, conv](int status, const guchar *data, gsize len) { if (status == 200 && data && len > 0) { purple_conv_custom_smiley_write( conv, id.c_str(), data, len); } else { purple_debug_warning( "line", "Couldn't download image message. Status: %d\n", status); } purple_conv_custom_smiley_close(conv, id.c_str()); }); } } break; case line::ContentType::AUDIO: { text = "[Audio message"; if (msg.contentMetadata.count("AUDLEN")) { int len = 0; try { len = std::stoi(msg.contentMetadata["AUDLEN"]); } catch(...) { /* ignore */ } if (len > 0) { text += " " + std::to_string(len / 1000) + "." + std::to_string((len % 1000) / 100) + "s"; } } text += "]"; if (conv) { text += " <font color=\"#888888\">/open " + conv_attachment_add(conv, msg.contentType, msg.id) + "</font>"; } } break; // TODO: other content types default: text = "<em>[Not implemented: "; text += line::_ContentType_VALUES_TO_NAMES.at(msg.contentType); text += " message]</em>"; break; } if (sent) { // Messages sent by user (sync from other devices) write_message(conv, msg.from, text, mtime, flags | PURPLE_MESSAGE_SEND); } else { // Messages received from other users flags |= PURPLE_MESSAGE_RECV; if (replay) { // Write replayed messages instead of serv_got_* to avoid Pidgin's IM sound write_message(conv, msg.from, text, mtime, flags); } else { if (msg.toType == line::MIDType::USER) { serv_got_im( conn, msg.from.c_str(), text.c_str(), (PurpleMessageFlags)flags, mtime); } else if (msg.toType == line::MIDType::GROUP || msg.toType == line::MIDType::ROOM) { serv_got_chat_in( conn, purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)), msg.from.c_str(), (PurpleMessageFlags)flags, text.c_str(), mtime); } } } }
/*------------------------------------------------------------------------ * Received a message from a MultiMX room. * */ void multimx_message_received(struct RXMsgData* mx, char* msg, int msglen, short msgtype, int msgflags) { struct multimx* multimx = NULL; purple_debug_info(MXIT_PLUGIN_ID, "Groupchat message received: %s\n", msg); /* Find matching multimx group */ multimx = find_room_by_username(mx->session, mx->from); if (multimx == NULL) { purple_debug_error(MXIT_PLUGIN_ID, "Groupchat '%s' not found\n", mx->from); return; } /* Determine if system message or a message from a contact */ if (msg[0] == '<') { /* Message contains embedded nickname - must be from contact */ unsigned int i; for (i = 1; i < strlen(msg); i++) { /* search for end of nickname */ if (msg[i] == '>') { msg[i] = '\0'; g_free(mx->from); mx->from = g_strdup(&msg[1]); msg = &msg[i+2]; /* skip '>' and newline */ break; } } /* now do markup processing on the message */ mx->chatid = multimx->chatid; mxit_parse_markup(mx, msg, strlen(msg), msgtype, msgflags); } else { /* Must be a service message */ char* ofs; /* Determine if somebody has joined or left - update member-list */ if ((ofs = strstr(msg, " has joined")) != NULL) { /* Somebody has joined */ *ofs = '\0'; member_added(mx->session, multimx, msg); mx->processed = TRUE; } else if ((ofs = strstr(msg, " has left")) != NULL) { /* Somebody has left */ *ofs = '\0'; member_removed(mx->session, multimx, msg); mx->processed = TRUE; } else if ((ofs = strstr(msg, " has been kicked")) != NULL) { /* Somebody has been kicked */ *ofs = '\0'; member_kicked(mx->session, multimx, msg); mx->processed = TRUE; } else if (g_str_has_prefix(msg, "The following users are in this MultiMx:") == TRUE) { member_update(mx->session, multimx, msg + strlen("The following users are in this MultiMx:") + 1); mx->processed = TRUE; } else { /* Display server message in chat window */ serv_got_chat_in(mx->session->con, multimx->chatid, "MXit", PURPLE_MESSAGE_SYSTEM, msg, mx->timestamp); mx->processed = TRUE; } } }
/*------------------------------------------------------------------------ * Insert custom emoticons and inline images into the message (if there * are any), then give the message to the UI to display to the user. * * @param mx The received message object */ void mxit_show_message( struct RXMsgData* mx ) { char* pos; int start; unsigned int end; int emo_ofs; char* ii; char tag[64]; int* img_id; if ( mx->got_img ) { /* search and replace all emoticon tags with proper image tags */ while ( ( pos = strstr( mx->msg->str, MXIT_II_TAG ) ) != NULL ) { start = pos - mx->msg->str; /* offset at which MXIT_II_TAG starts */ emo_ofs = start + strlen( MXIT_II_TAG ); /* offset at which EMO's ID starts */ end = emo_ofs + 1; /* offset at which MXIT_II_TAG ends */ while ( ( end < mx->msg->len ) && ( mx->msg->str[end] != '>' ) ) end++; if ( end == mx->msg->len ) /* end of emoticon tag not found */ break; ii = g_strndup( &mx->msg->str[emo_ofs], end - emo_ofs ); /* remove inline image tag */ g_string_erase( mx->msg, start, ( end - start ) + 1 ); /* find the image entry */ img_id = (int*) g_hash_table_lookup( mx->session->iimages, ii ); if ( !img_id ) { /* inline image not found, so we will just skip it */ purple_debug_error( MXIT_PLUGIN_ID, "inline image NOT found (%s)\n", ii ); } else { /* insert img tag */ g_snprintf( tag, sizeof( tag ), "<img id=\"%i\">", *img_id ); g_string_insert( mx->msg, start, tag ); } g_free( ii ); } } #ifdef MXIT_DEBUG_MARKUP purple_debug_info( MXIT_PLUGIN_ID, "Markup RX (converted): '%s'\n", mx->msg->str ); #endif if ( mx->processed ) { /* this message has already been taken care of, so just ignore it here */ } else if ( mx->chatid < 0 ) { /* normal chat message */ mxit_show_split_message( mx ); } else { /* this is a multimx message */ serv_got_chat_in( mx->session->con, mx->chatid, mx->from, mx->flags, mx->msg->str, mx->timestamp); } /* freeup resource */ free_markupdata( mx ); }
static void nap_callback(gpointer data, gint source, PurpleInputCondition condition) { PurpleConnection *gc = data; struct nap_data *ndata = gc->proto_data; PurpleAccount *account = NULL; PurpleConversation *c = NULL; PurpleNotifyUserInfo *pnui = NULL; gchar *buf = NULL, *buf2 = NULL, *buf3 = NULL, **res = NULL; unsigned short header[2] = { 0 , 0 }; int len = 0; int command = 0; int i; account = purple_connection_get_account(gc); if (read(source, (void*)header, 4) != 4) { purple_connection_error(gc, _("Unable to read header from server")); return; } len = header[0]; command = header[1]; buf = (gchar *)g_malloc((len + 1) * sizeof(gchar)); buf[len] = '\0'; i = 0; do { int tmp = read(source, buf + i, len - i); if (tmp <= 0) { g_free(buf); buf = g_strdup_printf(_("Unable to read message from server: %s. Command is %hd, length is %hd."), strerror(errno), len, command); purple_connection_error(gc, buf); g_free(buf); return; } i += tmp; } while (i != len); purple_debug(PURPLE_DEBUG_MISC, "napster", "R %3hd: %s\n", command, buf); switch (command) { case 000: /* MSG_SERVER_ERROR */ purple_notify_error(gc, NULL, buf, NULL); purple_input_remove(gc->inpa); gc->inpa = 0; close(source); purple_connection_error(gc, _("Unknown server error.")); break; case 003: /* MSG_SERVER_EMAIL */ purple_debug(PURPLE_DEBUG_MISC, "napster", "Registered with e-mail address: %s\n", buf); ndata->email = g_strdup(buf); /* Our signon is complete */ purple_connection_set_state(gc, PURPLE_CONNECTED); /* Send the server our buddy list */ nap_send_buddylist(gc); break; case 201: /* MSG_SERVER_SEARCH_RESULT */ res = g_strsplit(buf, " ", 0); purple_prpl_got_user_status(account, res[0], "available", NULL); g_strfreev(res); break; case 202: /* MSG_SERVER_SEARCH_END */ purple_prpl_got_user_status(account, buf, "offline", NULL); break; case 205: /* MSG_CLIENT_PRIVMSG */ res = g_strsplit(buf, " ", 2); buf2 = g_markup_escape_text(res[1], -1); serv_got_im(gc, res[0], buf2, 0, time(NULL)); g_free(buf2); g_strfreev(res); break; case 209: /* MSG_SERVER_USER_SIGNON */ /* USERNAME SPEED */ res = g_strsplit(buf, " ", 2); purple_prpl_got_user_status(account, res[0], "available", NULL); g_strfreev(res); break; case 210: /* MSG_SERVER_USER_SIGNOFF */ /* USERNAME SPEED */ res = g_strsplit(buf, " ", 2); purple_prpl_got_user_status(account, res[0], "offline", NULL); g_strfreev(res); break; case 214: /* MSG_SERVER_STATS */ res = g_strsplit(buf, " ", 3); buf2 = g_strdup_printf(_("users: %s, files: %s, size: %sGB"), res[0], res[1], res[2]); serv_got_im(gc, "server", buf2, 0, time(NULL)); g_free(buf2); g_strfreev(res); break; case 301: /* MSG_SERVER_HOTLIST_ACK */ /* Our buddy was added successfully */ break; case 302: /* MSG_SERVER_HOTLIST_ERROR */ buf2 = g_strdup_printf(_("Unable to add \"%s\" to your Napster hotlist"), buf); purple_notify_error(gc, NULL, buf2, NULL); g_free(buf2); break; case 316: /* MSG_SERVER_DISCONNECTING */ /* we have been kicked off =^( */ purple_connection_error(gc, _("You were disconnected from the server.")); break; case 401: /* MSG_CLIENT_PART */ c = nap_find_chat(gc, buf); if (c) serv_got_chat_left(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c))); break; case 403: /* MSG_SERVER_PUBLIC */ res = g_strsplit(buf, " ", 3); c = nap_find_chat(gc, res[0]); if (c) serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)), res[1], 0, res[2], time((time_t)NULL)); g_strfreev(res); break; case 404: /* MSG_SERVER_NOSUCH */ /* abused by opennap servers to broadcast stuff */ buf2 = g_markup_escape_text(buf, -1); serv_got_im(gc, "server", buf2, 0, time(NULL)); g_free(buf2); break; case 405: /* MSG_SERVER_JOIN_ACK */ c = nap_find_chat(gc, buf); if (!c) serv_got_joined_chat(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)), buf); break; case 407: /* MSG_SERVER_PART */ res = g_strsplit(buf, " ", 0); c = nap_find_chat(gc, res[0]); purple_conv_chat_remove_user(PURPLE_CONV_CHAT(c), res[1], NULL); g_strfreev(res); break; case 406: /* MSG_SERVER_JOIN */ case 408: /* MSG_SERVER_CHANNEL_USER_LIST */ res = g_strsplit(buf, " ", 4); c = nap_find_chat(gc, res[0]); purple_conv_chat_add_user(PURPLE_CONV_CHAT(c), res[1], NULL, PURPLE_CBFLAGS_NONE, TRUE); g_strfreev(res); break; case 409: /* MSG_SERVER_CHANNEL_USER_LIST_END */ break; case 410: /* MSG_SERVER_TOPIC */ /* display the topic in the channel */ res = g_strsplit(buf, " ", 2); c = nap_find_chat(gc, res[0]); purple_conv_chat_set_topic(PURPLE_CONV_CHAT(c), res[0], res[1]); g_strfreev(res); break; case 603: /* MSG_CLIENT_WHOIS */ buf2 = g_strdup_printf(_("%s requested your information"), buf); serv_got_im(gc, "server", buf2, 0, time(NULL)); g_free(buf2); break; case 604: /* MSG_SERVER_WHOIS_RESPONSE */ /* XXX - Format is: "Elite" 37 " " "Active" 0 0 0 0 "purple 0.63cvs" 0 0 192.168.1.41 32798 0 unknown flounder */ res = g_strsplit(buf, " ", 2); /* res[0] == username */ pnui = purple_notify_user_info_new(); purple_notify_user_info_add_pair(pnui, _("Napster User Info:"), res[1]); purple_notify_userinfo(gc, res[0], pnui, NULL, NULL); g_strfreev(res); break; case 621: case 622: /* MSG_CLIENT_MOTD */ /* also replaces MSG_SERVER_MOTD, so we should display it */ buf2 = g_markup_escape_text(buf, -1); serv_got_im(gc, "motd", buf2, 0, time(NULL)); g_free(buf2); break; case 627: /* MSG_CLIENT_WALLOP */ /* abused by opennap server maintainers to broadcast stuff */ buf2 = g_markup_escape_text(buf, -1); serv_got_im(gc, "wallop", buf2, 0, time(NULL)); g_free(buf2); break; case 628: /* MSG_CLIENT_ANNOUNCE */ buf2 = g_markup_escape_text(buf, -1); serv_got_im(gc, "announce", buf2, 0, time(NULL)); g_free(buf); break; case 748: /* MSG_SERVER_GHOST */ /* Looks like someone logged in as us! =-O */ purple_connection_error(gc, _("You have signed on from another location.")); break; case 751: /* MSG_CLIENT_PING */ buf2 = g_strdup_printf(_("%s requested a PING"), buf); serv_got_im(gc, "server", buf2, 0, time(NULL)); g_free(buf2); /* send back a pong */ /* MSG_CLIENT_PONG */ nap_write_packet(gc, 752, "%s", buf); break; case 752: /* MSG_CLIENT_PONG */ buf2 = g_strdup_printf("Received pong from %s", buf); purple_notify_info(gc, NULL, buf2, NULL); g_free(buf2); break; case 824: /* MSG_CLIENT_EMOTE */ res = g_strsplit(buf, " ", 3); buf2 = g_strndup(res[2]+1, strlen(res[2]) - 2); /* chomp off the surround quotes */ buf3 = g_strdup_printf("/me %s", buf2); g_free(buf2); if ((c = nap_find_chat(gc, res[0]))) { purple_conv_chat_write(PURPLE_CONV_CHAT(c), res[1], buf3, PURPLE_MESSAGE_NICK, time(NULL)); } g_free(buf3); g_strfreev(res); break; default: purple_debug(PURPLE_DEBUG_MISC, "napster", "Unknown packet %hd: %s\n", command, buf); break; } g_free(buf); }
static void waprpl_process_incoming_events(PurpleConnection *gc) { whatsapp_connection * wconn = purple_connection_get_protocol_data(gc); PurpleAccount * acc = purple_connection_get_account(gc); switch (waAPI_loginstatus(wconn->waAPI)) { case 0: purple_connection_update_progress(gc, "Connecting", 0, 4); break; case 1: purple_connection_update_progress(gc, "Sending auth", 1, 4); break; case 2: purple_connection_update_progress(gc, "Waiting response", 2, 4); break; case 3: purple_connection_update_progress(gc, "Connected", 3, 4); purple_connection_set_state(gc, PURPLE_CONNECTED); if (!wconn->connected) waprpl_insert_contacts(gc); wconn->connected = 1; break; default: break; }; char * msg, * who, * prev, * url, *author; int status; int size; double lat,lng; // Incoming messages while (waAPI_querychat(wconn->waAPI, &who, &msg, &author)) { purple_debug_info(WHATSAPP_ID, "Got chat message from %s: %s\n", who,msg); if (isgroup(who)) { // Search fot the combo PurpleBlistNode* node = purple_blist_get_root(); GHashTable* hasht = NULL; while (node != 0) { if (PURPLE_BLIST_NODE_IS_CHAT(node)) { PurpleChat * ch = PURPLE_CHAT(node); if (purple_chat_get_account(ch) == acc) { hasht = purple_chat_get_components(ch); if (strcmp(g_hash_table_lookup(hasht, "id"),who) == 0) { break; } } } node = purple_blist_node_next(node,FALSE); } int convo_id = chatid_to_convo(who); PurpleConversation *convo = purple_find_chat(gc, convo_id); // Create a window if it's not open yet if (!convo) waprpl_chat_join(gc,hasht); if (convo != NULL) { serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)), author, PURPLE_MESSAGE_RECV, msg, time(NULL)); }else{ printf("Received group message but could not find the group! %s\n",msg); } }else{ // Search fot the combo PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, acc); if (!convo) convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, who); serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_IM(convo)), who, PURPLE_MESSAGE_RECV, msg, time(NULL)); purple_conv_im_write(PURPLE_CONV_IM(convo), who, msg, PURPLE_MESSAGE_RECV, time(NULL)); } } while (waAPI_querychatimage(wconn->waAPI, &who, &prev, &size, &url)) { printf("Got chat image %s %s\n",who,url); purple_debug_info(WHATSAPP_ID, "Got image from %s: %s\n", who,url); // Search fot the combo PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, acc); if (!convo) convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, who); int imgid = purple_imgstore_add_with_id(g_memdup(prev, size), size, NULL); serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_IM(convo)), who, PURPLE_MESSAGE_RECV, msg, time(NULL)); purple_conv_im_write(PURPLE_CONV_IM(convo), who, g_strdup_printf("<a href=\"%s\"><img id=\"%u\"></a>",url,imgid), PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_IMAGES, time(NULL)); } while (waAPI_querychatlocation(wconn->waAPI, &who, &prev, &size, &lat, &lng)) { purple_debug_info(WHATSAPP_ID, "Got geomessage from: %s Coordinates (%f %f)\n", who,(float)lat,(float)lng); // Search fot the combo PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, acc); if (!convo) convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, who); int imgid = purple_imgstore_add_with_id(g_memdup(prev, size), size, NULL); serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_IM(convo)), who, PURPLE_MESSAGE_RECV, msg, time(NULL)); purple_conv_im_write(PURPLE_CONV_IM(convo), who, g_strdup_printf("<a href=\"http://openstreetmap.org/?lat=%f&lon=%f&zoom=16\"><img src=\"%u\"></a>",lat,lng,imgid), PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_IMAGES, time(NULL)); } while (waAPI_querychatsound(wconn->waAPI, &who, &url)) { purple_debug_info(WHATSAPP_ID, "Got chat sound from %s: %s\n", who,url); // Search fot the combo PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, acc); if (!convo) convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, who); serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_IM(convo)), who, PURPLE_MESSAGE_RECV, msg, time(NULL)); purple_conv_im_write(PURPLE_CONV_IM(convo), who, g_strdup_printf("<a href=\"%s\">%s</a>",url,url), PURPLE_MESSAGE_RECV , time(NULL)); } // User status change while (waAPI_querystatus(wconn->waAPI, &who, &status)) { if (status == 1) { purple_prpl_got_user_status(acc, who, "available", "message","", NULL); } else { purple_prpl_got_user_status(acc, who, "unavailable", "message","", NULL); } } // User typing info notify while (waAPI_querytyping(wconn->waAPI, &who, &status)) { if (status == 1) { serv_got_typing(gc,who,0,PURPLE_TYPING); } else { serv_got_typing_stopped(gc,who); } } // User profile picture char * icon, * hash; int len; while (waAPI_queryicon(wconn->waAPI, &who, &icon, &len, &hash)) { purple_buddy_icons_set_for_user(acc,who, g_memdup(icon,len),len, hash); } // Groups update if (waAPI_getgroupsupdated(wconn->waAPI)) { // Delete/update the chats that are in our list PurpleBlistNode* node = purple_blist_get_root(); while (node != 0) { if (PURPLE_BLIST_NODE_IS_CHAT(node)) { PurpleChat * ch = PURPLE_CHAT(node); if (purple_chat_get_account(ch) == acc) { int found = 0; GHashTable *hasht = purple_chat_get_components(ch); char * grid = g_hash_table_lookup(hasht, "id"); char * glist = waAPI_getgroups(wconn->waAPI); gchar **gplist = g_strsplit(glist,",",0); while (*gplist) { if (strcmp(*gplist,grid) == 0) { // The group is in the system, update the fields char *id,*sub,*own; waAPI_getgroupinfo(wconn->waAPI, *gplist, &sub, &own, 0); g_hash_table_insert(hasht, g_strdup("subject"), g_strdup(sub)); g_hash_table_insert(hasht, g_strdup("owner"), g_strdup(own)); found = 1; break; } gplist++; } // The group was deleted if (!found) { PurpleBlistNode* del = node; node = purple_blist_node_next(node,FALSE); purple_blist_remove_chat(del); } } } node = purple_blist_node_next(node,FALSE); } // Add new groups char * glist = waAPI_getgroups(wconn->waAPI); gchar **gplist = g_strsplit(glist,",",0); while (*gplist) { int found = 0; PurpleBlistNode* node = purple_blist_get_root(); PurpleChat * ch; while (node != 0) { if (PURPLE_BLIST_NODE_IS_CHAT(node)) { ch = PURPLE_CHAT(node); if (purple_chat_get_account(ch) == acc) { char * grid = g_hash_table_lookup(purple_chat_get_components(ch), "id"); if (strcmp(*gplist,grid) == 0) { found = 1; break; } } } node = purple_blist_node_next(node,FALSE); } if (!found) { char *sub,*own; waAPI_getgroupinfo(wconn->waAPI, *gplist, &sub, &own, 0); purple_debug_info("waprpl", "New group found %s %s\n", *gplist,sub); GHashTable * htable = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); g_hash_table_insert(htable, g_strdup("subject"), g_strdup(sub)); g_hash_table_insert(htable, g_strdup("id"), g_strdup(*gplist)); g_hash_table_insert(htable, g_strdup("owner"), g_strdup(own)); ch = purple_chat_new(acc,sub,htable); purple_blist_add_chat(ch,NULL,NULL); } // Now update the open conversation that may exist char * id = g_hash_table_lookup(purple_chat_get_components(ch), "id"); int prplid = chatid_to_convo(id); PurpleConversation * conv = purple_find_chat(gc, prplid); if (conv) { char *subject, *owner, *part; if (!waAPI_getgroupinfo(wconn->waAPI, id, &subject, &owner, &part)) return; purple_conv_chat_clear_users(purple_conversation_get_chat_data(conv)); gchar **plist = g_strsplit(part,",",0); while (*plist) { purple_conv_chat_add_user (purple_conversation_get_chat_data(conv), *plist,"",PURPLE_CBFLAGS_NONE | (!strcmp(owner,*plist) ? PURPLE_CBFLAGS_FOUNDER : 0),FALSE); plist++; } } gplist++; } } }
void coincoin_parse_message(HttpHandler* handler, gchar* response, gsize len, gpointer userdata) { CoinCoinAccount* cca = handler->data; PurpleConversation* convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, "board", cca->account); if(!convo) return; // not on the board channel xmlnode* node = coincoin_xmlparse(response, len); xmlnode* post; GSList *last_msg = cca->messages; GSList *iter; GSList *messages = NULL; unsigned i; if(!node) { purple_debug(PURPLE_DEBUG_ERROR, "coincoin", "Unable to parse response.\n"); return; } for(post = xmlnode_get_child(node, "post"); post; post = xmlnode_get_next_twin(post)) { CoinCoinMessage* msg; gint64 id = strtoul(xmlnode_get_attrib(post, "id"), NULL, 10); /* Check if this message has already been showed. */ for(iter = last_msg; iter && ((CoinCoinMessage*)iter->data)->id != id; iter = iter->next) ; if(iter) break; msg = coincoin_message_new(id, post); if(!msg) continue; messages = g_slist_prepend(messages, msg); if(strcmp(msg->from, purple_connection_get_display_name(cca->pc))) { PurpleConvChatBuddy* cb = purple_conv_chat_cb_find(PURPLE_CONV_CHAT(convo), msg->from); if(!cb) purple_conv_chat_add_user(PURPLE_CONV_CHAT(convo), msg->from, msg->info, PURPLE_CBFLAGS_NONE, FALSE); } } /* Flush messages (in reversed order) */ for(iter = messages; iter; ) { CoinCoinMessage* msg = iter->data; if(!purple_account_get_bool(cca->account, "no_reformat_messages", FALSE)) coincoin_message_ref(msg, cca->messages); serv_got_chat_in(cca->pc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)), msg->from, PURPLE_MESSAGE_DELAYED, msg->message, msg->timestamp); if(cca->messages && ((CoinCoinMessage*)cca->messages->data)->timestamp == msg->timestamp) { msg->multiple = ((CoinCoinMessage*)cca->messages->data)->multiple = TRUE; msg->ref = ((CoinCoinMessage*)cca->messages->data)->ref + 1; } GSList* link = iter; iter = iter->next; link->next = cca->messages; cca->messages = link; } /* Now purge extra-messages */ for(i = 0, iter = last_msg; iter; ++i) { if(i < CC_LAST_MESSAGE_MAX) iter = iter->next; else if(i == CC_LAST_MESSAGE_MAX) { GSList* prev; prev = iter; iter = iter->next; prev->next = NULL; } else { /* This user doesn't participate to conversation * anymore. So it can leave channel. */ CoinCoinMessage* cur = iter->data; if(strcmp(cur->from, purple_connection_get_display_name(cca->pc)) && purple_conv_chat_cb_find(PURPLE_CONV_CHAT(convo), cur->from)) { GSList* it = cca->messages; while(it && it != iter && strcmp(((CoinCoinMessage*)it->data)->from, cur->from)) it = it->next; if(it == iter || !it) purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), cur->from, NULL); } coincoin_message_free(cur); iter->data = NULL; iter = g_slist_delete_link(iter, iter); } } xmlnode_free(node); }
/************************************************************************** * Message Handlers **************************************************************************/ static void plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { GaimConnection *gc; MsnSwitchBoard *swboard; const char *body; char *body_str; char *body_enc; char *body_final; size_t body_len; const char *passport; const char *value; gc = cmdproc->session->account->gc; swboard = cmdproc->data; body = msn_message_get_bin_data(msg, &body_len); body_str = g_strndup(body, body_len); body_enc = g_markup_escape_text(body_str, -1); g_free(body_str); passport = msg->remote_user; if (!strcmp(passport, "*****@*****.**") && strstr(body, "immediate security update")) { return; } #if 0 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) { gaim_debug_misc("msn", "User-Agent = '%s'\n", value); } #endif if ((value = msn_message_get_attr(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; } swboard->flag |= MSN_SB_FLAG_IM; if (swboard->current_users > 1 || ((swboard->conv != NULL) && gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT)) { /* 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) gaim_debug_misc("msn", "plain_msg: current_users(%d)\n", swboard->current_users); serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, time(NULL)); if (swboard->conv == NULL) { swboard->conv = gaim_find_chat(gc, swboard->chat_id); swboard->flag |= MSN_SB_FLAG_IM; } } else { serv_got_im(gc, passport, body_final, 0, time(NULL)); if (swboard->conv == NULL) { swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, passport, gaim_connection_get_account(gc)); swboard->flag |= MSN_SB_FLAG_IM; } } g_free(body_final); }