void p2tgl_got_im (struct tgl_state *TLS, tgl_peer_id_t who, const char *msg, int flags, time_t when) { char *name = peer_strdup_id(who); serv_got_im(tg_get_conn(TLS), name, msg,flags, when); g_free (name); }
void hon_parse_userinfo(PurpleConnection* gc,gchar* buffer,guint16 packet_id){ hon_account* hon = gc->proto_data; /* TODO: this is not right .. conversation could be closed already */ gchar* message = NULL; gchar* name = NULL,*strtime = NULL; gchar* user = read_string(buffer); if (!hon->whois_conv) return; switch (packet_id){ case 0x2b: message = g_strdup_printf(_("Cannot find user %s"),user); break; case 0x2c: message = g_strdup_printf(_("User %s is offline, last seen %s"),user,buffer); break; case 0x2d: { GString* msg = g_string_new(NULL); guint32 chan_count = read_guint32(buffer); if (chan_count > 0) g_string_printf(msg,_("User %s is online and in channels: "),user); else g_string_printf(msg,_("User %s is online."),user); while (chan_count--) { msg = g_string_append(msg,buffer); if (chan_count == 0) msg = g_string_append(msg,"."); else msg = g_string_append(msg,", "); read_string(buffer); } message = g_string_free(msg,FALSE); } break; case 0x2e: name = read_string(buffer); strtime = read_string(buffer); message = g_strdup_printf(_("User %s is ingame, game name: %s, game time: %s"),user,name,strtime); break; } purple_conversation_write(hon->whois_conv, "",message, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL)); g_free(message); #ifdef MINBIF if (packet_id == 0x2e) message = g_strdup_printf("%s %s %d %s %s", MINBIF_INFO,user,packet_id, strtime, name); else message = g_strdup_printf("%s %s %d", MINBIF_INFO,user,packet_id); serv_got_im(gc,MINBIF_USER,message,PURPLE_MESSAGE_RECV,time(NULL)); g_free(message); #endif hon->whois_conv = NULL; }
void hon_parse_tmm_invite(PurpleConnection *gc,gchar* buffer) { PurpleMessageFlags receive_flags; gchar* tmp; gchar* upcase; gchar* split; gchar* message; gchar* map; gchar* modes; gchar* regions; gchar* from_username = NULL; from_username = read_string(buffer); read_guint32(buffer); // id read_byte(buffer); //flags / read_byte(buffer); // ?? read_string(buffer); // color read_string(buffer); // icon read_guint32(buffer); // ?? map = read_string(buffer); if (from_username[0] == '[') { while (from_username[0] != ']') from_username++; from_username++; } read_byte(buffer); // ?? // uppercase mode/region // show array of mode/region more nicely tmp = read_string(buffer); upcase = g_ascii_strup(tmp, -1); split = g_strsplit(upcase, _("|"),-1); modes = g_strchomp(g_strjoinv(_(" "),split)); g_free(upcase); g_strfreev(split); tmp = read_string(buffer); upcase = g_ascii_strup(tmp, -1); split = g_strsplit(upcase, _("|"),-1); regions = g_strchomp(g_strjoinv(_(" "),split)); g_free(upcase); g_strfreev(split); receive_flags = PURPLE_MESSAGE_WHISPER; message = g_strdup_printf("%s %s %s %s %s %s" ,_("I invited you to matchmaking:\nMap:"),map,_("\nModes:"),modes,_("\nRegions:"),regions); serv_got_im(gc, from_username, message, receive_flags, time(NULL)); g_free(message); g_free(modes); g_free(regions); }
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 sipe_backend_im_message(struct sipe_core_public *sipe_public, const gchar *from, const gchar *html) { struct sipe_backend_private *purple_private = sipe_public->backend_private; serv_got_im(purple_private->gc, from, html, 0, time(NULL)); }
/*------------------------------------------------------------------------ * This gets called when a new chat conversation is opened by the user * * @param conv The conversation object * @param session The MXit session object */ static void mxit_cb_chat_created( PurpleConversation* conv, struct MXitSession* session ) { PurpleConnection* gc; struct contact* contact; PurpleBuddy* buddy; const char* who; char* tmp; gc = purple_conversation_get_gc( conv ); if ( session->con != gc ) { /* not our conversation */ return; } else if ( purple_conversation_get_type( conv ) != PURPLE_CONV_TYPE_IM ) { /* wrong type of conversation */ return; } /* get the contact name */ who = purple_conversation_get_name( conv ); if ( !who ) return; purple_debug_info( MXIT_PLUGIN_ID, "Conversation started with '%s'\n", who ); /* find the buddy object */ buddy = purple_find_buddy( session->acc, who ); if ( !buddy ) return; contact = purple_buddy_get_protocol_data( buddy ); if ( !contact ) return; /* we ignore all conversations with which we have chatted with in this session */ if ( find_active_chat( session->active_chats, who ) ) return; /* determine if this buddy is a MXit service */ switch ( contact->type ) { case MXIT_TYPE_BOT : case MXIT_TYPE_CHATROOM : case MXIT_TYPE_GALLERY : case MXIT_TYPE_INFO : tmp = g_strdup_printf("<font color=\"#999999\">%s</font>\n", _( "Loading menu..." )); serv_got_im( session->con, who, tmp, PURPLE_MESSAGE_NOTIFY, time( NULL ) ); g_free( tmp ); mxit_send_message( session, who, " ", FALSE, FALSE ); default : break; } }
void hon_parse_initiall_statuses(PurpleConnection *gc,gchar* buffer){ guint32 status,flags; hon_account* hon; guint32 id,count = read_guint32(buffer); hon = gc->proto_data; purple_debug_info(HON_DEBUG_PREFIX, "parsing status for %d buddies\n",count); while (count-- > 0) { gchar* raw_gamename = NULL; gchar* nick,*gamename=NULL, *server=NULL,*status_id = HON_STATUS_ONLINE_S, *color = NULL, *icon = NULL; guint32 matchid = 0; id = read_guint32(buffer); status = read_byte(buffer); flags = read_byte(buffer); color = read_string(buffer); icon = read_string(buffer); nick = g_hash_table_lookup(hon->id2nick,GINT_TO_POINTER(id)); if (status == HON_STATUS_INLOBBY || status == HON_STATUS_INGAME) { server = read_string(buffer); status_id = HON_STATUS_INGAME_S; raw_gamename = read_string(buffer); gamename = hon_strip(raw_gamename,TRUE); matchid = read_guint32(buffer); } if(!status) status_id = HON_STATUS_OFFLINE_S; purple_debug_info(HON_DEBUG_PREFIX, "status for %s,flags:%d,status:%d,game:%s,server:%s\n",nick,flags,status,gamename,server); if (nick) purple_prpl_got_user_status(gc->account, nick, status_id, HON_BUDDYID_ATTR , id, HON_STATUS_ATTR,status,HON_FLAGS_ATTR,flags, server ? HON_SERVER_ATTR : NULL,server,gamename ? HON_GAME_ATTR : NULL,gamename,NULL); g_free(gamename); #ifdef MINBIF if (nick) { if (status == HON_STATUS_INGAME) status_id = g_strdup_printf("%s %s %d 0 %s",MINBIF_STATUS, nick,status,raw_gamename); else status_id = g_strdup_printf("%s %s %d",MINBIF_STATUS, nick,status); serv_got_im(gc,MINBIF_USER,status_id,PURPLE_MESSAGE_RECV,time(NULL)); g_free(status_id); } #endif } }
static int purplemot_send_im(PurpleConnection *gc, const char *who, const char *message, PurpleMessageFlags flags) { const char *from_username = gc->account->username; PurpleMessageFlags receive_flags = ((flags & ~PURPLE_MESSAGE_SEND) | PURPLE_MESSAGE_RECV); PurpleAccount *to_acct = purple_accounts_find(who, PURPLEMOT_ID); PurpleConnection *to; purple_debug_info("purplemot", "sending message from %s to %s: %s\n", from_username, who, message); /* is the sender blocked by the recipient's privacy settings? */ if (to_acct && !purple_privacy_check(to_acct, gc->account->username)) { char *msg = g_strdup_printf( _("Your message was blocked by %s's privacy settings."), who); purple_debug_info("purplemot", "discarding; %s is blocked by %s's privacy settings\n", from_username, who); purple_conv_present_error(who, gc->account, msg); g_free(msg); return 0; } /* is the recipient online? */ to = get_purplemot_gc(who); if (to) { /* yes, send */ serv_got_im(to, from_username, message, receive_flags, time(NULL)); } else { /* nope, store as an offline message */ GOfflineMessage *offline_message; GList *messages; purple_debug_info("purplemot", "%s is offline, sending as offline message\n", who); offline_message = g_new0(GOfflineMessage, 1); offline_message->from = g_strdup(from_username); offline_message->message = g_strdup(message); offline_message->mtime = time(NULL); offline_message->flags = receive_flags; messages = g_hash_table_lookup(goffline_messages, who); messages = g_list_append(messages, offline_message); g_hash_table_insert(goffline_messages, g_strdup(who), messages); } return 1; }
void tgp_msg_err_out (struct tgl_state *TLS, const char *error, tgl_peer_id_t to) { int flags = PURPLE_MESSAGE_ERROR | PURPLE_MESSAGE_SYSTEM; time_t now; time (&now); switch (tgl_get_peer_type (to)) { case TGL_PEER_CHAT: p2tgl_got_chat_in (TLS, to, to, error, flags, now); break; case TGL_PEER_USER: case TGL_PEER_ENCR_CHAT: serv_got_im (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, to), error, flags, now); break; } }
static void purple_xfer_ask_recv(PurpleXfer *xfer) { char *buf, *size_buf; size_t size; gconstpointer thumb; gsize thumb_size; /* If we have already accepted the request, ask the destination file name directly */ if (purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_ACCEPTED) { PurpleBuddy *buddy = purple_find_buddy(xfer->account, xfer->who); if (purple_xfer_get_filename(xfer) != NULL) { size = purple_xfer_get_size(xfer); size_buf = purple_str_size_to_units(size); buf = g_strdup_printf(_("%s wants to send you %s (%s)"), buddy ? purple_buddy_get_alias(buddy) : xfer->who, purple_xfer_get_filename(xfer), size_buf); g_free(size_buf); } else { buf = g_strdup_printf(_("%s wants to send you a file"), buddy ? purple_buddy_get_alias(buddy) : xfer->who); } if (xfer->message != NULL) serv_got_im(purple_account_get_connection(xfer->account), xfer->who, xfer->message, 0, time(NULL)); if ((thumb = purple_xfer_get_thumbnail(xfer, &thumb_size))) { purple_request_accept_cancel_with_icon(xfer, NULL, buf, NULL, PURPLE_DEFAULT_ACTION_NONE, xfer->account, xfer->who, NULL, thumb, thumb_size, xfer, G_CALLBACK(purple_xfer_choose_file), G_CALLBACK(cancel_recv_cb)); } else { purple_request_accept_cancel(xfer, NULL, buf, NULL, PURPLE_DEFAULT_ACTION_NONE, xfer->account, xfer->who, NULL, xfer, G_CALLBACK(purple_xfer_choose_file), G_CALLBACK(cancel_recv_cb)); } g_free(buf); } else purple_xfer_choose_file(xfer); }
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 qq_got_message(PurpleConnection *gc, const gchar *msg) { qq_data *qd; gchar *from; time_t now = time(NULL); g_return_if_fail(gc != NULL && gc->proto_data != NULL); qd = gc->proto_data; g_return_if_fail(qd->uid > 0); qq_buddy_find_or_new(gc, qd->uid); from = uid_to_purple_name(qd->uid); serv_got_im(gc, from, msg, PURPLE_MESSAGE_SYSTEM, now); g_free(from); }
void hon_parse_pm_whisper(PurpleConnection *gc,gchar* buffer,guint16 is_whisper) { PurpleMessageFlags receive_flags; gchar* message; guint8 pm_type; guint32 unk32; gchar* from_username = NULL; if(!is_whisper) pm_type = read_byte(buffer); from_username = read_string(buffer); if(!is_whisper && pm_type == 1) { read_guint32(buffer); // id read_byte(buffer); //flags / read_byte(buffer); // ?? read_string(buffer); // color read_string(buffer); // icon unk32 = read_guint32(buffer); } message = hon2html(buffer); if (from_username[0] == '[') { while (from_username[0] != ']') from_username++; from_username++; } receive_flags = PURPLE_MESSAGE_RECV; if (is_whisper) { #ifndef MINBIF gchar* tmp = message; if (is_whisper > 1) message = g_strdup_printf("[%s] %s" , _("WHISPERED TO BUDDIES"),message); else message = g_strdup_printf("[%s] %s" , _("WHISPER"),message); g_free(tmp); #endif receive_flags |= PURPLE_MESSAGE_WHISPER; } serv_got_im(gc, from_username, message, receive_flags, time(NULL)); g_free(message); }
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); }
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 flist_sfc_report(PurpleConnection *pc, JsonObject *root) { PurpleAccount *pa = purple_connection_get_account(pc); const gchar *callid, *reporter, *report; gchar *s, *escaped_reporter, *escaped_report, *message; GString *message_str; gdouble timestamp; gint logid; gboolean has_logid; callid = json_object_get_string_member(root, "callid"); reporter = json_object_get_string_member(root, "character"); report = json_object_get_string_member(root, "report"); logid = json_object_get_parse_int_member(root, "logid", &has_logid); timestamp = json_object_get_double_member(root, "timestamp"); g_return_if_fail(callid); g_return_if_fail(reporter); g_return_if_fail(report); message_str = g_string_new(NULL); s = g_strdup(purple_url_encode(flist_serialize_account(pa))); escaped_reporter = purple_markup_escape_text(reporter, -1); escaped_report = purple_markup_escape_text(report, -1); g_string_append_printf(message_str, "Moderator Alert. %s writes:\n", escaped_reporter); g_string_append_printf(message_str, "%s\n", escaped_report); g_string_append_printf(message_str, "<a href=\"flistsfc://%s/%s\">Confirm Alert</a>", s, purple_url_encode(callid)); g_string_append(message_str, ", "); if(has_logid) { g_string_append_printf(message_str, "<a href=\"http://www.f-list.net/fchat/getLog.php?log=%d\">View Log</a>", logid); } else { g_string_append_printf(message_str, "(No Log)"); } message = g_string_free(message_str, FALSE); serv_got_im(pc, GLOBAL_NAME, message, PURPLE_MESSAGE_RECV, time(NULL)); g_free(escaped_report); g_free(escaped_reporter); g_free(message); g_free(s); }
static void flist_sfc_confirm(PurpleConnection *pc, JsonObject *root) { FListAccount *fla = pc->proto_data; const gchar *moderator, *reporter; gchar *message, *escaped_message, *bbcode_message; gdouble timestamp; moderator = json_object_get_string_member(root, "moderator"); reporter = json_object_get_string_member(root, "character"); timestamp = json_object_get_double_member(root, "timestamp"); g_return_if_fail(moderator); g_return_if_fail(reporter); message = g_strdup_printf("Alert Confirmed. [b]%s[/b] is handling [b]%s[/b]'s report.", moderator, reporter); escaped_message = purple_markup_escape_text(message, -1); bbcode_message = flist_bbcode_to_html(fla, NULL, escaped_message); serv_got_im(pc, GLOBAL_NAME, bbcode_message, PURPLE_MESSAGE_RECV, time(NULL)); g_free(bbcode_message); g_free(escaped_message); g_free(message); }
void irc_msg_away(struct irc_conn *irc, const char *name, const char *from, char **args) { PurpleConnection *gc; char *msg; if (!args || !args[1]) return; if (irc->whois.nick && !purple_utf8_strcasecmp(irc->whois.nick, args[1])) { /* We're doing a whois, show this in the whois dialog */ irc_msg_whois(irc, name, from, args); return; } gc = purple_account_get_connection(irc->account); if (gc) { msg = g_markup_escape_text(args[2], -1); serv_got_im(gc, args[1], msg, PURPLE_MESSAGE_AUTO_RESP, 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); }
/****************************************************************************** * helpers *****************************************************************************/ static inline void stress_send_im(PurpleAccount *account, PurpleBuddy *buddy, const gchar *name) { PurpleConnection *pc = NULL; GString *msg = NULL; gint length = 0, i = 0; /* build the message */ msg = g_string_new(""); length = (rand() % (message_max - message_min)) + message_min; for(i = 0; i < length; i += 4) { gint value = rand() % 65536; g_string_append_printf(msg, "%04x", value); } /* send the im */ pc = purple_account_get_connection(account); serv_got_im(pc, name, msg->str, 0, time(NULL)); /* cleanup */ g_string_free(msg, TRUE); }
/*Post the Offline Instant Message to User Conversation*/ static void msn_oim_report_to_user(MsnOimRecvData *rdata, const char *msg_str) { MsnMessage *message; const char *date; const char *from; const char *boundary; char *decode_msg = NULL; gsize body_len; char **tokens; char *passport = NULL; time_t stamp; message = msn_message_new(MSN_MSG_UNKNOWN); msn_message_parse_payload(message, msg_str, strlen(msg_str), MSG_OIM_LINE_DEM, MSG_OIM_BODY_DEM); purple_debug_info("msn", "oim body:{%s}\n", message->body); boundary = msn_message_get_attr(message, "boundary"); if (boundary != NULL) { char *bounds; char **part; bounds = g_strdup_printf("--%s" MSG_OIM_LINE_DEM, boundary); tokens = g_strsplit(message->body, bounds, 0); /* tokens+1 to skip the "This is a multipart message..." text */ for (part = tokens+1; *part != NULL; part++) { MsnMessage *multipart; const char *type; multipart = msn_message_new(MSN_MSG_UNKNOWN); msn_message_parse_payload(multipart, *part, strlen(*part), MSG_OIM_LINE_DEM, MSG_OIM_BODY_DEM); type = msn_message_get_content_type(multipart); if (type && !strcmp(type, "text/plain")) { decode_msg = (char *)purple_base64_decode(multipart->body, &body_len); msn_message_destroy(multipart); break; } msn_message_destroy(multipart); } g_strfreev(tokens); g_free(bounds); if (decode_msg == NULL) { purple_debug_error("msn", "Couldn't find text/plain OIM message.\n"); msn_message_destroy(message); return; } } else { decode_msg = (char *)purple_base64_decode(message->body, &body_len); } from = msn_message_get_attr(message, "X-OIM-originatingSource"); /* Match number to user's mobile number, FROM is a phone number if the other side pages you using your phone number */ if (from && !strncmp(from, "tel:+", 5)) { MsnUser *user = msn_userlist_find_user_with_mobile_phone( rdata->oim->session->userlist, from + 4); if (user && user->passport) passport = g_strdup(user->passport); } if (passport == NULL) { char *start, *end; from = msn_message_get_attr(message, "From"); tokens = g_strsplit(from, " ", 2); if (tokens[1] != NULL) from = (const char *)tokens[1]; start = strchr(from, '<'); if (start != NULL) { start++; end = strchr(from, '>'); if (end != NULL) passport = g_strndup(start, end - start); } if (passport == NULL) passport = g_strdup(_("Unknown")); g_strfreev(tokens); } date = msn_message_get_attr(message, "Date"); stamp = msn_oim_parse_timestamp(date); purple_debug_info("msn", "oim Date:{%s},passport{%s}\n", date, passport); serv_got_im(rdata->oim->session->account->gc, passport, decode_msg, 0, stamp); /*Now get the oim message ID from the oim_list. * and append to read list to prepare for deleting the Offline Message when sign out */ msn_oim_post_delete_msg(rdata); g_free(passport); g_free(decode_msg); msn_message_destroy(message); }
static void _jabber_parse_and_write_message_to_ui(xmlnode *message_node, PurpleBuddy *pb) { xmlnode *body_node, *html_node, *events_node; PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(pb)); gchar *body = NULL; body_node = xmlnode_get_child(message_node, "body"); html_node = xmlnode_get_child(message_node, "html"); if (body_node == NULL && html_node == NULL) { purple_debug_error("bonjour", "No body or html node found, discarding message.\n"); return; } events_node = xmlnode_get_child_with_namespace(message_node, "x", "jabber:x:event"); if (events_node != NULL) { #if 0 if (xmlnode_get_child(events_node, "composing") != NULL) composing_event = TRUE; #endif if (xmlnode_get_child(events_node, "id") != NULL) { /* The user is just typing */ /* TODO: Deal with typing notification */ return; } } if (html_node != NULL) { xmlnode *html_body_node; html_body_node = xmlnode_get_child(html_node, "body"); if (html_body_node != NULL) { xmlnode *html_body_font_node; html_body_font_node = xmlnode_get_child(html_body_node, "font"); /* Types of messages sent by iChat */ if (html_body_font_node != NULL) { gchar *html_body; const char *font_face, *font_size, *ichat_balloon_color, *ichat_text_color; font_face = xmlnode_get_attrib(html_body_font_node, "face"); /* The absolute iChat font sizes should be converted to 1..7 range */ font_size = xmlnode_get_attrib(html_body_font_node, "ABSZ"); if (font_size != NULL) font_size = _font_size_ichat_to_purple(atoi(font_size)); /*font_color = xmlnode_get_attrib(html_body_font_node, "color");*/ ichat_balloon_color = xmlnode_get_attrib(html_body_node, "ichatballooncolor"); ichat_text_color = xmlnode_get_attrib(html_body_node, "ichattextcolor"); html_body = get_xmlnode_contents(html_body_font_node); if (html_body == NULL) /* This is the kind of formatted messages that Purple creates */ html_body = xmlnode_to_str(html_body_font_node, NULL); if (html_body != NULL) { GString *str = g_string_new("<font"); if (font_face) g_string_append_printf(str, " face='%s'", font_face); if (font_size) g_string_append_printf(str, " size='%s'", font_size); if (ichat_text_color) g_string_append_printf(str, " color='%s'", ichat_text_color); if (ichat_balloon_color) g_string_append_printf(str, " back='%s'", ichat_balloon_color); g_string_append_printf(str, ">%s</font>", html_body); body = g_string_free(str, FALSE); g_free(html_body); } } } } /* Compose the message */ if (body == NULL && body_node != NULL) body = xmlnode_get_data(body_node); if (body == NULL) { purple_debug_error("bonjour", "No html body or regular body found.\n"); return; } /* Send the message to the UI */ serv_got_im(gc, purple_buddy_get_name(pb), body, 0, time(NULL)); g_free(body); }
static void pb_got_everything(PushBulletAccount *pba, JsonNode *node, gpointer user_data) { JsonObject *rootobj = json_node_get_object(node); JsonArray *devices = json_object_has_member(rootobj, "devices") ? json_object_get_array_member(rootobj, "devices") : NULL; JsonArray *pushes = json_object_has_member(rootobj, "pushes") ? json_object_get_array_member(rootobj, "pushes") : NULL; JsonArray *contacts = json_object_has_member(rootobj, "contacts") ? json_object_get_array_member(rootobj, "contacts") : NULL; JsonArray *chats = json_object_has_member(rootobj, "chats") ? json_object_get_array_member(rootobj, "chats") : NULL; JsonArray *texts = json_object_has_member(rootobj, "texts") ? json_object_get_array_member(rootobj, "texts") : NULL; gint i; guint len; PurpleGroup *pbgroup; pbgroup = purple_find_group("PushBullet"); if (!pbgroup) { pbgroup = purple_group_new("PushBullet"); purple_blist_add_group(pbgroup, NULL); } if (json_object_has_member(rootobj, "error")) { JsonObject *error = json_object_get_object_member(rootobj, "error"); const gchar *type = json_object_get_string_member(error, "type"); const gchar *message = json_object_get_string_member(error, "message"); //TODO check type purple_connection_error_reason(pba->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, message); return; } if (devices != NULL) { for(i = 0, len = json_array_get_length(devices); i < len; i++) { JsonObject *device = json_array_get_object_element(devices, i); if (pba->main_sms_device == NULL && json_object_get_boolean_member(device, "has_sms")) { pba->main_sms_device = g_strdup(json_object_get_string_member(device, "iden")); purple_account_set_string(pba->account, "main_sms_device", pba->main_sms_device); pb_get_phonebook(pba, pba->main_sms_device); if (!pba->websocket) { pb_start_polling(pba); } break; //TODO handle more than one } } } if (pushes != NULL) { gint last_message_timestamp = purple_account_get_int(pba->account, "last_message_timestamp", 0); for(i = json_array_get_length(pushes); i > 0; i--) { JsonObject *push = json_array_get_object_element(pushes, i - 1); const gchar *type = json_object_get_string_member(push, "type"); gdouble modified; time_t timestamp; gboolean dismissed; if (!type) continue; modified = json_object_get_double_member(push, "modified"); timestamp = (time_t) modified; dismissed = json_object_get_boolean_member(push, "dismissed"); if (timestamp <= last_message_timestamp || dismissed) { continue; } // {"active":true,"iden":"uffvytgsjApuAUIFRk","created":1.438895081423904e+09,"modified":1.438895081432786e+09,"type":"file","dismissed":false,"guid":"153b70f0-f7a6-4db9-a6f4-28b99fa416f1","direction":"self","sender_iden":"uffvytg","sender_email":"*****@*****.**","sender_email_normalized":"*****@*****.**","sender_name":"Eion Robb","receiver_iden":"uffvytg","receiver_email":"*****@*****.**","receiver_email_normalized":"*****@*****.**","target_device_iden":"uffvytgsjz7O3P0Jl6","source_device_iden":"uffvytgsjAoIRwhIL6","file_name":"IMG_20150807_084618.jpg","file_type":"image/jpeg","file_url":"https://dl.pushbulletusercontent.com/FHOZdyzfvnoYZY0DP6oK1rGKiJpWCPc0/IMG_20150807_084618.jpg","image_width":4128,"image_height":2322,"image_url":"https://lh3.googleusercontent.com/WY5TK7h3mzD32qMcnxtqt-4PrYcWW1uWDHnRW2x1oJK8mnYk2v4HbZrRjIQkiYdxMKQSdNI8GGPqfO6s6tEyuRVLzeA"} if (purple_strequal(type, "note") || purple_strequal(type, "link") || purple_strequal(type, "file")) { const gchar *from = json_object_get_string_member(push, "sender_email_normalized"); const gchar *body = json_object_get_string_member(push, "body"); const gchar *direction = json_object_get_string_member(push, "direction"); gchar *body_html; if (from == NULL) { if (!json_object_has_member(push, "sender_name")) { purple_debug_error("pushbullet", "no sender name/email\n"); continue; } from = json_object_get_string_member(push, "sender_name"); } if (body && *body) { body_html = purple_strdup_withhtml(body); } else { const gchar *title = json_object_get_string_member(push, "title"); if (title && *title) { body_html = purple_strdup_withhtml(title); } else { body_html = "Message"; } } if (json_object_has_member(push, "url")) { gchar *body_with_link = g_strconcat("<a href=\"", json_object_get_string_member(push, "url"), "\">", body_html, "</a>", NULL); g_free(body_html); body_html = body_with_link; } else if (json_object_has_member(push, "image_url")) { const gchar *image_url = json_object_get_string_member(push, "image_url"); PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, from, pba->account); if (conv == NULL) { conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, pba->account, from); } pb_download_image_to_conv(image_url, conv); } else if (json_object_has_member(push, "file_url")) { gchar *body_with_link; const gchar *file_name = json_object_get_string_member(push, "file_name"); if (file_name && *file_name) { g_free(body_html); body_html = purple_strdup_withhtml(file_name); } body_with_link= g_strconcat("<a href=\"", json_object_get_string_member(push, "file_url"), "\">", json_object_get_string_member(push, "file_name"), "</a>", NULL); g_free(body_html); body_html = body_with_link; } if (direction[0] != 'o') { serv_got_im(pba->pc, from, body_html, PURPLE_MESSAGE_RECV, timestamp); } else { const gchar *guid = json_object_get_string_member(push, "guid"); from = json_object_get_string_member(push, "receiver_email_normalized"); if (!guid || !g_hash_table_remove(pba->sent_messages_hash, guid)) { PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, from, pba->account); if (conv == NULL) { conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, pba->account, from); } purple_conversation_write(conv, from, body_html, PURPLE_MESSAGE_SEND, timestamp); } } g_free(body_html); } purple_account_set_int(pba->account, "last_message_timestamp", MAX(purple_account_get_int(pba->account, "last_message_timestamp", 0), timestamp)); } } if (contacts != NULL) { for(i = 0, len = json_array_get_length(contacts); i < len; i++) { JsonObject *contact = json_array_get_object_element(contacts, i); const gchar *email = json_object_get_string_member(contact, "email_normalized"); const gchar *name = json_object_get_string_member(contact, "name"); const gchar *image_url = json_object_get_string_member(contact, "image_url"); PurpleBuddy *buddy = purple_find_buddy(pba->account, email); if (buddy == NULL) { buddy = purple_buddy_new(pba->account, email, name); purple_blist_add_buddy(buddy, NULL, pbgroup, NULL); } purple_prpl_got_user_status(pba->account, email, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL); } } if (chats != NULL) { for(i = 0, len = json_array_get_length(chats); i < len; i++) { JsonObject *chat = json_array_get_object_element(chats, i); JsonObject *contact = json_object_get_object_member(chat, "with"); const gchar *email = json_object_get_string_member(contact, "email_normalized"); const gchar *name = json_object_get_string_member(contact, "name"); const gchar *image_url = json_object_get_string_member(contact, "image_url"); PurpleBuddy *buddy = purple_find_buddy(pba->account, email); if (buddy == NULL) { buddy = purple_buddy_new(pba->account, email, name); purple_blist_add_buddy(buddy, NULL, pbgroup, NULL); } purple_prpl_got_user_status(pba->account, email, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL); } } if (texts != NULL) { for(i = 0, len = json_array_get_length(texts); i < len; i++) { JsonObject *text = json_array_get_object_element(texts, i); } } }
/************************************************************************** * 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); }
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); } } } }
static void sippy_recv_cb(gpointer data, gint source, GaimInputCondition condition) { GaimConnection *gc = data; int len; int command; static char buf[4096]; static char bufFrom[4096]; static char bufTo[4096]; len = read( FD_GAG_TO_GAIM, &command, sizeof(command ) ); if ( len == -1 ) { int err = errno; gaim_debug(GAIM_DEBUG_INFO,"sippy","err=%d\n",err); /* something really bad happened */ resip_assert(0); } if ( len == 0 ) { /* not ready */ return; } resip_assert( len == sizeof(command) ); switch ( command ) { case SIMPLE_IM: { gaim_debug(GAIM_DEBUG_INFO,"sippy","got an IM messages from gag\n"); sippy_get_string( bufTo, sizeof(bufTo) ); sippy_get_string( bufFrom, sizeof(bufFrom) ); sippy_get_string( buf, sizeof(buf) ); gaim_debug(GAIM_DEBUG_INFO,"sippy","got an IM from=%s to=%s data=%s\n",bufFrom,bufTo,buf); serv_got_im(gc,bufFrom,buf,0,time(NULL)); } break; case SIMPLE_LOGIN_STATUS: { unsigned char success; int sipCode; /* bool success, int sipCode, data message */ sippy_get_bool( &success ); sippy_get_int( &sipCode ); sippy_get_string( buf, sizeof(buf) ); gaim_debug(GAIM_DEBUG_INFO,"sippy","got a LOGIN_STATUS status=%d msg=%s\n",sipCode,buf); if (gaim_connection_get_state(gc) != GAIM_CONNECTED) { if (success) { gaim_connection_update_progress(gc,_("Connecting"),1,2); gaim_connection_set_state(gc, GAIM_CONNECTED); } else { gaim_connection_error(gc, _(buf)); } } } break; case SIMPLE_PRESENCE: /* uri aor, bool available, Data status */ { unsigned char open; int lastReportedUCStatus; gaim_debug(GAIM_DEBUG_INFO,"sippy","got a PRES messages from gag\n"); sippy_get_string( bufFrom, sizeof(bufFrom) ); sippy_get_bool( &open ); sippy_get_string( buf, sizeof(buf) ); gaim_debug(GAIM_DEBUG_INFO,"sippy","got a PRES messages from gag from=%s open=%d, msg=%s\n",bufFrom,open,buf); { struct simple_connection_cache *sc_cache = gc->proto_data; struct simple_friend_cache *sf; sf = g_hash_table_lookup(sc_cache->friends,bufFrom); if (!sf) { sf = simple_friend_cache_new(); g_hash_table_insert(sc_cache->friends,g_strdup(bufFrom),sf); } if (sf->status_string) { g_free(sf->status_string); } sf->status_string = g_strdup(buf); lastReportedUCStatus = (sf->status_int ^= 2); } /* AFAICT, there is a half-done change to the use of * the last argument to serv_got_update that is messing * up Yahoo as well as us. The code above the prpl abstraction * claims the integer is ours to do with as we please, but they * use the lowest order bit to mean available or not. * * Other code looks for changes to this integer - if it has * not changed it shortcuts all the GUI updates. So... * We're going to game gaim for now by toggling the second * lowest order bit each time we call this function. * * TODO: This was true in the gaim 0.71 code - need to review to * see if this is still appropriate. */ serv_got_update(gc, bufFrom, (int)open, 0, 0, 0, lastReportedUCStatus); } break; case SIMPLE_HELLO: /* bool ok */ { unsigned char ok; sippy_get_bool( &ok ); gaim_debug(GAIM_DEBUG_INFO,"sippy","got a HELLO ok=%d\n",ok); } case SIMPLE_ERROR: { gaim_debug(GAIM_DEBUG_INFO,"sippy","got an ERROR messages from gag\n"); sippy_get_string( buf, sizeof(buf) ); gaim_debug(GAIM_DEBUG_INFO,"sippy","gag ERROR %s\n",buf); gaim_request_action(gc, _("SIP Error"), _("SIP Error"), buf, 0, NULL, 1, _("Okay"), 0); } break; default: resip_assert(0); } }
gboolean flist_process_RTB(PurpleConnection *pc, JsonObject *root) { FListAccount *fla = pc->proto_data; const gchar *subject = NULL, *name = NULL, *title = NULL; gchar *url = NULL; gchar *msg = NULL; gint id; gboolean has_id; gint target_id; gboolean has_target_id; const gchar *type_str = json_object_get_string_member(root, "type"); /* Ignore notification if the user doesn't want to see it */ if (!fla->receive_rtb) { return TRUE; } purple_debug_info(FLIST_DEBUG, "Processing RTB... (Character: %s, Type: %s)\n", fla->character, type_str); RTB_TYPE type = flist_rtb_get_type(type_str); if (type == None) { purple_debug_error(FLIST_DEBUG, "Error parsing RTB: Unknown type (Character: %s, Type: %s)\n", fla->character, type_str); return TRUE; } // Handle friend list notifications switch(type) { case FriendRequest: flist_friends_received_request(fla); return TRUE; case FriendAdd: flist_friends_added_friend(fla); return TRUE; case FriendRemove: flist_friends_removed_friend(fla); return TRUE; default: // We will handle other cases further below break; } // --- Past this point, we're going to build a message. // Fields in some RTB message are named differently, depending on their type // Normalize this here if (type == TicketCreate) { name = json_object_get_string_member(root, "user"); title = json_object_get_string_member(root, "subject"); id = json_object_get_parse_int_member(root, "id", &has_id); } else if (type == Note) { name = json_object_get_string_member(root, "sender"); title = json_object_get_string_member(root, "subject"); id = json_object_get_parse_int_member(root, "id", &has_id); } else if (type == Comment) { name = json_object_get_string_member(root, "name"); title = json_object_get_string_member(root, "target"); id = json_object_get_parse_int_member(root, "id", &has_id); } else { name = json_object_get_string_member(root, "name"); title = json_object_get_string_member(root, "title"); id = json_object_get_parse_int_member(root, "id", &has_id); } if (!has_id) { purple_debug_error(FLIST_DEBUG, "Error parsing RTB: Could not parse id (Character: %s, Type: %s)\n", fla->character, type_str); return TRUE; } switch(type) { case Note: msg = g_strdup_printf("New note received from <a href=\"" FLIST_URL_CHARACTER "\">%s</a>: %s (<a href=\"" FLIST_URL_NOTE "\">Open Note</a>)", name, name, title, id); break; case BugReport: msg = g_strdup_printf("<a href=\"" FLIST_URL_CHARACTER "\">%s</a> submitted a bugreport, \"<a href=\"" FLIST_URL_BUGREPORT "\">%s</a>\"", name, name, id, title); break; case FeatureRequest: msg = g_strdup_printf("<a href=\"" FLIST_URL_CHARACTER "\">%s</a> submitted a feature request, \"<a href=\"" FLIST_URL_FEATUREREQUEST "\">%s</a>\"", name, name, id, title); break; // Helpdesk Tickets case HelpdeskTicket: msg = g_strdup_printf("<a href=\"" FLIST_URL_CHARACTER "\">%s</a> submitted a helpdesk ticket, \"<a href=\"" FLIST_URL_HELPDESKTICKET "\">%s</a>\"", name, name, id, title); break; case TicketCreate: msg = g_strdup_printf("<a href=\"" FLIST_URL_CHARACTER "\">%s</a> submitted a helpdesk ticket via email, \"<a href=\"" FLIST_URL_HELPDESKTICKET "\">%s</a>\"", name, name, id, title); break; case HelpdeskReply: msg = g_strdup_printf("<a href=\"" FLIST_URL_CHARACTER "\">%s</a> submitted a reply to your helpdesk ticket, \"<a href=\"" FLIST_URL_HELPDESKTICKET "\">%s</a>\"", name, name, id, title); break; case Comment: subject = json_object_get_string_member(root, "target_type"); target_id = json_object_get_parse_int_member(root, "target_id", &has_target_id); if (!has_target_id) { purple_debug_error(FLIST_DEBUG, "Error parsing RTB: Could not parse target_id (Character: %s, Type: %s)\n", fla->character, type_str); return TRUE; } url = flist_rtb_get_comment_url(subject, target_id, id); msg = g_strdup_printf("<a href=\"" FLIST_URL_CHARACTER "\">%s</a> submitted a comment on the %s \"<a href=\"%s\">%s</a>\"", name, name, subject, url, title); g_free(url); break; default: // We should actually never come here, all other cases are handled above. purple_debug_error(FLIST_DEBUG, "Error parsing RTB: Unhandled type reached(Character: %s, Type: %s)\n", fla->character, type_str); return TRUE; } serv_got_im(pc, GLOBAL_NAME, msg, PURPLE_MESSAGE_RECV, time(NULL)); g_free(msg); return TRUE; }
static gboolean plain_receive(gpointer data) { purple_debug_info("plainprpl", "plain_receive called\n"); char msgbuf[MAX_MESSAGE_SIZE]; int msgbuf_len; IP addr; const char *status; PurpleConnection *gc; PurpleAccount *account; PurpleBuddy *buddy; plain_plugin_state *pstate; plain_buddy_state *bstate; /* Get time in seconds since 1970 */ time_t now = time(NULL); gc = (PurpleConnection *) data; account = purple_connection_get_account(gc); pstate = purple_connection_get_protocol_data(gc); /* Check if we need to ping any buddy */ ping_buddies(gc, now); msgbuf_len = sizeof(msgbuf); buddy = receive_msg(pstate, &addr, msgbuf, &msgbuf_len); /* Nothing to receive or error */ if (msgbuf_len <= 0) { return TRUE; } if (!g_utf8_validate(msgbuf, -1, NULL)) { purple_debug_info("plainprpl", "Received invalid UTF8 message from %s - ignore.\n", str_addr(&addr)); return TRUE; } /* We got a message and identified the sender */ purple_debug_info("plainprpl", "Received message from %s (%d Bytes): %s\n", str_addr(&addr), strlen(msgbuf), msgbuf); /* We got a message from a source we don't know */ gboolean allow_unknown = purple_account_get_bool(account, "allow_unknown", FALSE); if (buddy == NULL) { purple_debug_info("plainprpl", "Packet from unknown buddy from address %s.\n", str_addr(&addr)); if (allow_unknown && !pstate->block_unknown) { //temporary disable the setting pstate->block_unknown = TRUE; plainprpl_add_buddy_by_contact_request(gc, str_addr(&addr), msgbuf); } return TRUE; } bstate = purple_buddy_get_protocol_data(buddy); if (bstate == NULL) { purple_debug_info("plainprpl", "bstate of buddy %s is NULL.\n", buddy->name); return TRUE; } status = PLAIN_STATUS_ONLINE; if (strcmp(msgbuf, "/ping") == 0) { /* Received a ping from a buddy */ if ((bstate->time_recv + 5) < now) { /* Send pong at most every 5 seconds */ send_msg(pstate, bstate, "/pong"); } else { /* Ignore ping */ } } else if (strcmp(msgbuf, "/pong") == 0) { /* Nothing to do */ } else if (strcmp(msgbuf, "/bye") == 0) { status = PLAIN_STATUS_OFFLINE; } else if (msgbuf[0] != '/') { /* Display message */ serv_got_im(gc, bstate->name, msgbuf, PURPLE_MESSAGE_RECV, now); } else { /* Unknown command - ignore */ } bstate->time_recv = now; /* Set buddy status to online */ purple_prpl_got_user_status(account, bstate->name, status, NULL); return TRUE; //continue loop }
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); }
void hon_parse_user_status(PurpleConnection *gc,gchar* buffer){ gchar* nick,*gamename=NULL, *server=NULL,*status_id = HON_STATUS_ONLINE_S; gchar* clan = NULL; // or channel? gchar* shield = NULL,*icon = NULL,*flag = NULL; guint32 clanid; hon_account* hon = gc->proto_data; guint32 status; guint32 flags; guint32 matchid = 0; gchar* raw_gamename = NULL; guint32 id = read_guint32(buffer); status = read_byte(buffer); flags = read_byte(buffer); nick = g_hash_table_lookup(hon->id2nick,GINT_TO_POINTER(id)); /* TODO: figure this out */ clanid = read_guint32(buffer); clan = read_string(buffer); // huh ? flag = read_string(buffer); shield = read_string(buffer); icon = read_string(buffer); if (status == HON_STATUS_INLOBBY || status == HON_STATUS_INGAME) { server = read_string(buffer); status_id = HON_STATUS_INGAME_S; } if (status == HON_STATUS_INGAME) { raw_gamename = read_string(buffer); gamename = hon_strip(raw_gamename,TRUE); matchid = read_guint32(buffer); } if(!status) status_id = HON_STATUS_OFFLINE_S; purple_debug_info(HON_DEBUG_PREFIX, "status for %s,flags:%d,status:%d,game:%s,server:%s\nclanid:%d, clan?:%s matchid:%d\nflag:%s,shield:%s,icon:%s\n" ,nick,flags,status,gamename,server,clanid,clan,matchid,flag,shield,icon); #if 0 if (status == HON_STATUS_ONLINE) honpurple_get_icon(gc->account, nick, icon,id); #endif if (nick) purple_prpl_got_user_status(gc->account, nick, status_id, HON_STATUS_ATTR,status,HON_FLAGS_ATTR,flags, HON_BUDDYID_ATTR , id, server ? HON_SERVER_ATTR : NULL,server,gamename ? HON_GAME_ATTR : NULL,gamename, matchid > 0 ? HON_MATCHID_ATTR : NULL, matchid, NULL); g_free(gamename); #ifdef MINBIF if (nick) { if (status == HON_STATUS_INGAME) status_id = g_strdup_printf("%s %s %d %d %s",MINBIF_STATUS, nick,status,matchid,raw_gamename); else status_id = g_strdup_printf("%s %s %d",MINBIF_STATUS, nick,status); serv_got_im(gc,MINBIF_USER,status_id,PURPLE_MESSAGE_RECV,time(NULL)); g_free(status_id); } #endif }