📄 gg.c
字号:
if (NULL == tmp || strlen(tmp) == 0) { ret = 0; } else if (strlen(tmp) > GG_MSG_MAXSIZE) { ret = -E2BIG; } else if (gg_send_message(info->session, GG_CLASS_CHAT, ggp_str_to_uin(who), (unsigned char *)tmp) < 0) { ret = -1; } else { ret = 1; } g_free(plain); g_free(tmp); return ret;}/* }}} *//* static void ggp_get_info(PurpleConnection *gc, const char *name) { {{{ */static void ggp_get_info(PurpleConnection *gc, const char *name){ GGPInfo *info = gc->proto_data; GGPSearchForm *form; guint32 seq; form = ggp_search_form_new(GGP_SEARCH_TYPE_INFO); form->user_data = info; form->uin = g_strdup(name); form->offset = g_strdup("0"); form->last_uin = g_strdup("0"); seq = ggp_search_start(gc, form); ggp_search_add(info->searches, seq, form);}/* }}} *//* static void ggp_set_status(PurpleAccount *account, PurpleStatus *status) {{{ */static void ggp_set_status(PurpleAccount *account, PurpleStatus *status){ PurpleConnection *gc; GGPInfo *info; const char *status_id, *msg; int new_status, new_status_descr; if (!purple_status_is_active(status)) return; gc = purple_account_get_connection(account); info = gc->proto_data; status_id = purple_status_get_id(status); purple_debug_info("gg", "ggp_set_status: Requested status = %s\n", status_id); if (strcmp(status_id, "available") == 0) { new_status = GG_STATUS_AVAIL; new_status_descr = GG_STATUS_AVAIL_DESCR; } else if (strcmp(status_id, "away") == 0) { new_status = GG_STATUS_BUSY; new_status_descr = GG_STATUS_BUSY_DESCR; } else if (strcmp(status_id, "invisible") == 0) { new_status = GG_STATUS_INVISIBLE; new_status_descr = GG_STATUS_INVISIBLE_DESCR; } else if (strcmp(status_id, "offline") == 0) { new_status = GG_STATUS_NOT_AVAIL; new_status_descr = GG_STATUS_NOT_AVAIL_DESCR; } else { new_status = GG_STATUS_AVAIL; new_status_descr = GG_STATUS_AVAIL_DESCR; purple_debug_info("gg", "ggp_set_status: uknown status requested (status_id=%s)\n", status_id); } msg = purple_status_get_attr_string(status, "message"); if (msg == NULL) { gg_change_status(info->session, new_status); } else { gchar *tmp, *new_msg; tmp = charset_convert(msg, "UTF-8", "CP1250"); new_msg = purple_markup_strip_html(tmp); g_free(tmp); gg_change_status_descr(info->session, new_status_descr, new_msg); g_free(new_msg); }}/* }}} *//* static void ggp_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) {{{ */static void ggp_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group){ GGPInfo *info = gc->proto_data; gg_add_notify(info->session, ggp_str_to_uin(buddy->name));}/* }}} *//* static void ggp_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) {{{ */static void ggp_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group){ GGPInfo *info = gc->proto_data; gg_remove_notify(info->session, ggp_str_to_uin(buddy->name));}/* }}} *//* static void ggp_join_chat(PurpleConnection *gc, GHashTable *data) {{{ */static void ggp_join_chat(PurpleConnection *gc, GHashTable *data){ GGPInfo *info = gc->proto_data; GGPChat *chat; char *chat_name; GList *l; PurpleConversation *conv; PurpleAccount *account = purple_connection_get_account(gc); chat_name = g_hash_table_lookup(data, "name"); if (chat_name == NULL) return; purple_debug_info("gg", "joined %s chat\n", chat_name); for (l = info->chats; l != NULL; l = l->next) { chat = l->data; if (chat != NULL && g_utf8_collate(chat->name, chat_name) == 0) { purple_notify_error(gc, _("Chat error"), _("This chat name is already in use"), NULL); return; } } ggp_confer_add_new(gc, chat_name); conv = serv_got_joined_chat(gc, info->chats_count, chat_name); purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv), purple_account_get_username(account), NULL, PURPLE_CBFLAGS_NONE, TRUE);}/* }}} *//* static char *ggp_get_chat_name(GHashTable *data) { {{{ */static char *ggp_get_chat_name(GHashTable *data) { return g_strdup(g_hash_table_lookup(data, "name"));}/* }}} *//* static int ggp_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags) {{{ */static int ggp_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags){ PurpleConversation *conv; GGPInfo *info = gc->proto_data; GGPChat *chat = NULL; GList *l; char *msg, *plain; uin_t *uins; int count = 0; if ((conv = purple_find_chat(gc, id)) == NULL) return -EINVAL; for (l = info->chats; l != NULL; l = l->next) { chat = l->data; if (g_utf8_collate(chat->name, conv->name) == 0) { break; } chat = NULL; } if (chat == NULL) { purple_debug_error("gg", "ggp_chat_send: Hm... that's strange. No such chat?\n"); return -EINVAL; } uins = g_new0(uin_t, g_list_length(chat->participants)); for (l = chat->participants; l != NULL; l = l->next) { uin_t uin = GPOINTER_TO_INT(l->data); uins[count++] = uin; } plain = purple_unescape_html(message); msg = charset_convert(plain, "UTF-8", "CP1250"); g_free(plain); gg_send_message_confer(info->session, GG_CLASS_CHAT, count, uins, (unsigned char *)msg); g_free(msg); g_free(uins); serv_got_chat_in(gc, id, purple_account_get_username(purple_connection_get_account(gc)), 0, message, time(NULL)); return 0;}/* }}} *//* static void ggp_keepalive(PurpleConnection *gc) {{{ */static void ggp_keepalive(PurpleConnection *gc){ GGPInfo *info = gc->proto_data; /* purple_debug_info("gg", "Keeping connection alive....\n"); */ if (gg_ping(info->session) < 0) { purple_debug_info("gg", "Not connected to the server " "or gg_session is not correct\n"); purple_connection_error(gc, _("Not connected to the server.")); }}/* }}} *//* static void ggp_register_user(PurpleAccount *account) {{{ */static void ggp_register_user(PurpleAccount *account){ PurpleConnection *gc = purple_account_get_connection(account); GGPInfo *info; info = gc->proto_data = g_new0(GGPInfo, 1); ggp_token_request(gc, ggp_register_user_dialog);}/* }}} *//* static GList *ggp_actions(PurplePlugin *plugin, gpointer context) {{{ */static GList *ggp_actions(PurplePlugin *plugin, gpointer context){ GList *m = NULL; PurplePluginAction *act; act = purple_plugin_action_new(_("Find buddies..."), ggp_find_buddies); m = g_list_append(m, act); m = g_list_append(m, NULL); act = purple_plugin_action_new(_("Change password..."), ggp_change_passwd); m = g_list_append(m, act); m = g_list_append(m, NULL); act = purple_plugin_action_new(_("Upload buddylist to Server"), ggp_action_buddylist_put); m = g_list_append(m, act); act = purple_plugin_action_new(_("Download buddylist from Server"), ggp_action_buddylist_get); m = g_list_append(m, act); act = purple_plugin_action_new(_("Delete buddylist from Server"), ggp_action_buddylist_delete); m = g_list_append(m, act); act = purple_plugin_action_new(_("Save buddylist to file..."), ggp_action_buddylist_save); m = g_list_append(m, act); act = purple_plugin_action_new(_("Load buddylist from file..."), ggp_action_buddylist_load); m = g_list_append(m, act); return m;}/* }}} *//* static gboolean ggp_offline_message(const PurpleBuddy *buddy) {{{ */static gboolean ggp_offline_message(const PurpleBuddy *buddy){ return TRUE;}/* }}} *//* prpl_info setup {{{ */static PurplePluginProtocolInfo prpl_info ={ OPT_PROTO_REGISTER_NOSCREENNAME, NULL, /* user_splits */ NULL, /* protocol_options */ NO_BUDDY_ICONS, /* icon_spec */ ggp_list_icon, /* list_icon */ NULL, /* list_emblem */ ggp_status_text, /* status_text */ ggp_tooltip_text, /* tooltip_text */ ggp_status_types, /* status_types */ ggp_blist_node_menu, /* blist_node_menu */ ggp_chat_info, /* chat_info */ NULL, /* chat_info_defaults */ ggp_login, /* login */ ggp_close, /* close */ ggp_send_im, /* send_im */ NULL, /* set_info */ NULL, /* send_typing */ ggp_get_info, /* get_info */ ggp_set_status, /* set_away */ NULL, /* set_idle */ NULL, /* change_passwd */ ggp_add_buddy, /* add_buddy */ NULL, /* add_buddies */ ggp_remove_buddy, /* remove_buddy */ NULL, /* remove_buddies */ NULL, /* add_permit */ NULL, /* add_deny */ NULL, /* rem_permit */ NULL, /* rem_deny */ NULL, /* set_permit_deny */ ggp_join_chat, /* join_chat */ NULL, /* reject_chat */ ggp_get_chat_name, /* get_chat_name */ NULL, /* chat_invite */ NULL, /* chat_leave */ NULL, /* chat_whisper */ ggp_chat_send, /* chat_send */ ggp_keepalive, /* keepalive */ ggp_register_user, /* register_user */ NULL, /* get_cb_info */ NULL, /* get_cb_away */ NULL, /* alias_buddy */ NULL, /* group_buddy */ NULL, /* rename_group */ NULL, /* buddy_free */ NULL, /* convo_closed */ NULL, /* normalize */ NULL, /* set_buddy_icon */ NULL, /* remove_group */ NULL, /* get_cb_real_name */ NULL, /* set_chat_topic */ NULL, /* find_blist_chat */ NULL, /* roomlist_get_list */ NULL, /* roomlist_cancel */ NULL, /* roomlist_expand_category */ NULL, /* can_receive_file */ NULL, /* send_file */ NULL, /* new_xfer */ ggp_offline_message, /* offline_message */ NULL, /* whiteboard_prpl_ops */ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ /* padding */ NULL, NULL, NULL, NULL};/* }}} *//* PurplePluginInfo setup {{{ */static PurplePluginInfo info = { PURPLE_PLUGIN_MAGIC, /* magic */ PURPLE_MAJOR_VERSION, /* major_version */ PURPLE_MINOR_VERSION, /* minor_version */ PURPLE_PLUGIN_PROTOCOL, /* plugin type */ NULL, /* ui_requirement */ 0, /* flags */ NULL, /* dependencies */ PURPLE_PRIORITY_DEFAULT, /* priority */ "prpl-gg", /* id */ "Gadu-Gadu", /* name */ VERSION, /* version */ N_("Gadu-Gadu Protocol Plugin"), /* summary */ N_("Polish popular IM"), /* description */ "boler@sourceforge.net", /* author */ PURPLE_WEBSITE, /* homepage */ NULL, /* load */ NULL, /* unload */ NULL, /* destroy */ NULL, /* ui_info */ &prpl_info, /* extra_info */ NULL, /* prefs_info */ ggp_actions, /* actions */ /* padding */ NULL, NULL, NULL, NULL};/* }}} *//* static void purple_gg_debug_handler(int level, const char * format, va_list args) {{{ */static void purple_gg_debug_handler(int level, const char * format, va_list args) { PurpleDebugLevel purple_level; char *msg = g_strdup_vprintf(format, args); /* This is pretty pointless since the GG_DEBUG levels don't correspond to * the purple ones */ switch (level) { case GG_DEBUG_FUNCTION: purple_level = PURPLE_DEBUG_INFO; break; case GG_DEBUG_MISC: case GG_DEBUG_NET: case GG_DEBUG_DUMP: case GG_DEBUG_TRAFFIC: default: purple_level = PURPLE_DEBUG_MISC; break; } purple_debug(purple_level, "gg", msg); g_free(msg);}/* }}} *//* *//* static void init_plugin(PurplePlugin *plugin) {{{ */static void init_plugin(PurplePlugin *plugin){ PurpleAccountOption *option; option = purple_account_option_string_new(_("Nickname"), "nick", _("Gadu-Gadu User")); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); my_protocol = plugin; gg_debug_handler = purple_gg_debug_handler;}/* }}} */PURPLE_INIT_PLUGIN(gg, init_plugin, info);/* vim: set ts=8 sts=0 sw=8 noet: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -