static void silcpurple_buddy_keyagr_cb(SilcClient client, SilcClientConnection conn, SilcClientEntry client_entry, SilcKeyAgreementStatus status, SilcSKEKeyMaterial *key, void *context) { PurpleConnection *gc = client->application; SilcPurple sg = gc->proto_data; SilcPurpleKeyAgr a = context; if (!sg->conn) return; switch (status) { case SILC_KEY_AGREEMENT_OK: { PurpleConversation *convo; char tmp[128]; /* Set the private key for this client */ silc_client_del_private_message_key(client, conn, client_entry); silc_client_add_private_message_key_ske(client, conn, client_entry, NULL, NULL, key, a->responder); silc_ske_free_key_material(key); /* Open IM window */ convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, client_entry->nickname, sg->account); if (convo) { /* we don't have windows in the core anymore...but we may want to * provide some method for asking the UI to show the window purple_conv_window_show(purple_conversation_get_window(convo)); */ } else { convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, sg->account, client_entry->nickname); } g_snprintf(tmp, sizeof(tmp), "%s [private key]", client_entry->nickname); purple_conversation_set_title(convo, tmp); } break; case SILC_KEY_AGREEMENT_ERROR: purple_notify_error(gc, _("Key Agreement"), _("Error occurred during key agreement"), NULL); break; case SILC_KEY_AGREEMENT_FAILURE: purple_notify_error(gc, _("Key Agreement"), _("Key Agreement failed"), NULL); break; case SILC_KEY_AGREEMENT_TIMEOUT: purple_notify_error(gc, _("Key Agreement"), _("Timeout during key agreement"), NULL); break; case SILC_KEY_AGREEMENT_ABORTED: purple_notify_error(gc, _("Key Agreement"), _("Key agreement was aborted"), NULL); break; case SILC_KEY_AGREEMENT_ALREADY_STARTED: purple_notify_error(gc, _("Key Agreement"), _("Key agreement is already started"), NULL); break; case SILC_KEY_AGREEMENT_SELF_DENIED: purple_notify_error(gc, _("Key Agreement"), _("Key agreement cannot be started with yourself"), NULL); break; default: break; } silc_free(a); }
static void parse_new_messages(PurpleConnection *pc, FacebookAccount *fba, JsonArray *messages) { int i; PurpleBuddy *buddy; purple_debug_info("facebook", "parsing new messages\n"); for (i = 0; i < json_array_get_length(messages); i++) { const gchar *type; gchar *from, *to; JsonObject *object = json_node_get_object(json_array_get_element(messages, i)); type = json_node_get_string(json_object_get_member(object, "type")); from = g_strdup_printf("%" G_GINT64_FORMAT, (gint64)json_node_get_int(json_object_get_member(object, "from"))); to = g_strdup_printf("%" G_GINT64_FORMAT, (gint64)json_node_get_int(json_object_get_member(object, "to"))); /* Use the in-line buddy name if the buddy list hasn't been downloaded yet */ buddy = purple_find_buddy(pc->account, from); if (buddy == NULL || buddy->server_alias == NULL || buddy->alias == NULL) { if (json_object_has_member(object, "from_name")) { const gchar *from_name = json_node_get_string(json_object_get_member( object, "from_name")); fb_blist_set_alias(fba, from, from_name); } } if (from && to && g_str_equal(type, "msg")) { JsonObject *messageObj = json_node_get_object(json_object_get_member(object, "msg")); parse_message(pc, fba, messageObj, from, to, PURPLE_CONV_TYPE_IM); } else if (from && g_str_equal(type, "typ")) { purple_debug_info("facebook", "handling typing notification\n"); gint typing = json_node_get_int(json_object_get_member(object, "st")); if (typing == 0) { serv_got_typing(pc, from, 10, PURPLE_NOT_TYPING); } else { serv_got_typing(pc, from, 10, PURPLE_TYPING); } } else if (g_str_equal(type, "group_msg")) { PurpleConversation *conv = fb_find_chat(fba, to); if (conv != NULL) { if (json_object_has_member(object, "to_name")) { const gchar *to_name = json_node_get_string(json_object_get_member( object, "to_name")); purple_conversation_set_title(conv, to_name); PurpleChat *chat = purple_blist_find_chat(fba->account, to); purple_blist_alias_chat(chat, to_name); } if (!purple_conv_chat_cb_find(PURPLE_CONV_CHAT(conv), from)) { purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv), from, NULL, PURPLE_CBFLAGS_NONE, FALSE); } if (!purple_find_buddy(fba->account, from)) { const char *from_name = json_node_get_string(json_object_get_member( object, "from_name")); buddy = purple_buddy_new(fba->account, from, from_name); purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE); purple_blist_add_buddy(buddy, NULL, purple_find_group(DEFAULT_GROUP_NAME), NULL); } } JsonObject *messageObj = json_node_get_object(json_object_get_member(object, "msg")); parse_message(pc, fba, messageObj, from, to, PURPLE_CONV_TYPE_CHAT); } /* * we've received something from a buddy, assume they're online * only if it's not from ourselves */ if (from && fba->uid != atoll(from)) { purple_prpl_got_user_status( fba->account, from, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL); } g_free(from); g_free(to); fba->message_fetch_sequence++; } }