📄 silc.c
字号:
purple_request_field_group_add_field(g, f);#endif#ifdef HAVE_SYS_UTSNAME_H f = purple_request_field_bool_new("device", _("Let others see what computer you are using"), device); purple_request_field_group_add_field(g, f);#endif purple_request_fields_add_group(fields, g); g = purple_request_field_group_new(NULL); f = purple_request_field_string_new("vcard", _("Your VCard File"), purple_account_get_string(sg->account, "vcard", ""), FALSE); purple_request_field_group_add_field(g, f); silc_timezone(tz, sizeof(tz)); f = purple_request_field_string_new("timezone", _("Timezone (UTC)"), tz, FALSE); purple_request_field_group_add_field(g, f); purple_request_fields_add_group(fields, g); purple_request_fields(gc, _("User Online Status Attributes"), _("User Online Status Attributes"), _("You can let other users see your online status information " "and your personal information. Please fill the information " "you would like other users to see about yourself."), fields, _("OK"), G_CALLBACK(silcpurple_attrs_cb), _("Cancel"), G_CALLBACK(silcpurple_attrs_cancel), gc->account, NULL, NULL, gc);}static voidsilcpurple_detach(PurplePluginAction *action){ PurpleConnection *gc = (PurpleConnection *) action->context; SilcPurple sg; if (!gc) return; sg = gc->proto_data; if (!sg) return; /* Call DETACH */ silc_client_command_call(sg->client, sg->conn, "DETACH"); sg->detaching = TRUE;}static voidsilcpurple_view_motd(PurplePluginAction *action){ PurpleConnection *gc = (PurpleConnection *) action->context; SilcPurple sg; char *tmp; if (!gc) return; sg = gc->proto_data; if (!sg) return; if (!sg->motd) { purple_notify_error( gc, _("Message of the Day"), _("No Message of the Day available"), _("There is no Message of the Day associated with this connection")); return; } tmp = g_markup_escape_text(sg->motd, -1); purple_notify_formatted(gc, NULL, _("Message of the Day"), NULL, tmp, NULL, NULL); g_free(tmp);}static voidsilcpurple_create_keypair_cancel(PurpleConnection *gc, PurpleRequestFields *fields){ /* Nothing */}static voidsilcpurple_create_keypair_cb(PurpleConnection *gc, PurpleRequestFields *fields){ SilcPurple sg = gc->proto_data; PurpleRequestField *f; const char *val, *pkfile = NULL, *prfile = NULL; const char *pass1 = NULL, *pass2 = NULL, *un = NULL, *hn = NULL; const char *rn = NULL, *e = NULL, *o = NULL, *c = NULL; char *identifier; int keylen = SILCPURPLE_DEF_PKCS_LEN; SilcPublicKey public_key; sg = gc->proto_data; if (!sg) return; val = NULL; f = purple_request_fields_get_field(fields, "pass1"); if (f) val = purple_request_field_string_get_value(f); if (val && *val) pass1 = val; else pass1 = ""; val = NULL; f = purple_request_fields_get_field(fields, "pass2"); if (f) val = purple_request_field_string_get_value(f); if (val && *val) pass2 = val; else pass2 = ""; if (strcmp(pass1, pass2)) { purple_notify_error( gc, _("Create New SILC Key Pair"), _("Passphrases do not match"), NULL); return; } val = NULL; f = purple_request_fields_get_field(fields, "key"); if (f) val = purple_request_field_string_get_value(f); if (val && *val) keylen = atoi(val); f = purple_request_fields_get_field(fields, "pkfile"); if (f) pkfile = purple_request_field_string_get_value(f); f = purple_request_fields_get_field(fields, "prfile"); if (f) prfile = purple_request_field_string_get_value(f); f = purple_request_fields_get_field(fields, "un"); if (f) un = purple_request_field_string_get_value(f); f = purple_request_fields_get_field(fields, "hn"); if (f) hn = purple_request_field_string_get_value(f); f = purple_request_fields_get_field(fields, "rn"); if (f) rn = purple_request_field_string_get_value(f); f = purple_request_fields_get_field(fields, "e"); if (f) e = purple_request_field_string_get_value(f); f = purple_request_fields_get_field(fields, "o"); if (f) o = purple_request_field_string_get_value(f); f = purple_request_fields_get_field(fields, "c"); if (f) c = purple_request_field_string_get_value(f); identifier = silc_pkcs_silc_encode_identifier((char *)un, (char *)hn, (char *)rn, (char *)e, (char *)o, (char *)c, NULL); /* Create the key pair */ if (!silc_create_key_pair(SILCPURPLE_DEF_PKCS, keylen, pkfile, prfile, identifier, pass1, &public_key, NULL, FALSE)) { purple_notify_error( gc, _("Create New SILC Key Pair"), _("Key Pair Generation failed"), NULL); return; } silcpurple_show_public_key(sg, NULL, public_key, NULL, NULL); silc_pkcs_public_key_free(public_key); silc_free(identifier);}static voidsilcpurple_create_keypair(PurplePluginAction *action){ PurpleConnection *gc = (PurpleConnection *) action->context; SilcPurple sg = gc->proto_data; PurpleRequestFields *fields; PurpleRequestFieldGroup *g; PurpleRequestField *f; const char *username, *realname; char *hostname, **u; char tmp[256], pkd[256], pkd2[256], prd[256], prd2[256]; username = purple_account_get_username(sg->account); u = g_strsplit(username, "@", 2); username = u[0]; realname = purple_account_get_user_info(sg->account); hostname = silc_net_localhost(); g_snprintf(tmp, sizeof(tmp), "%s@%s", username, hostname); g_snprintf(pkd2, sizeof(pkd2), "%s" G_DIR_SEPARATOR_S"public_key.pub", silcpurple_silcdir()); g_snprintf(prd2, sizeof(prd2), "%s" G_DIR_SEPARATOR_S"private_key.prv", silcpurple_silcdir()); g_snprintf(pkd, sizeof(pkd) - 1, "%s", purple_account_get_string(gc->account, "public-key", pkd2)); g_snprintf(prd, sizeof(prd) - 1, "%s", purple_account_get_string(gc->account, "private-key", prd2)); fields = purple_request_fields_new(); g = purple_request_field_group_new(NULL); f = purple_request_field_string_new("key", _("Key length"), "2048", FALSE); purple_request_field_group_add_field(g, f); f = purple_request_field_string_new("pkfile", _("Public key file"), pkd, FALSE); purple_request_field_group_add_field(g, f); f = purple_request_field_string_new("prfile", _("Private key file"), prd, FALSE); purple_request_field_group_add_field(g, f); purple_request_fields_add_group(fields, g); g = purple_request_field_group_new(NULL); f = purple_request_field_string_new("un", _("Username"), username ? username : "", FALSE); purple_request_field_group_add_field(g, f); f = purple_request_field_string_new("hn", _("Hostname"), hostname ? hostname : "", FALSE); purple_request_field_group_add_field(g, f); f = purple_request_field_string_new("rn", _("Real name"), realname ? realname : "", FALSE); purple_request_field_group_add_field(g, f); f = purple_request_field_string_new("e", _("E-mail"), tmp, FALSE); purple_request_field_group_add_field(g, f); f = purple_request_field_string_new("o", _("Organization"), "", FALSE); purple_request_field_group_add_field(g, f); f = purple_request_field_string_new("c", _("Country"), "", FALSE); purple_request_field_group_add_field(g, f); purple_request_fields_add_group(fields, g); g = purple_request_field_group_new(NULL); f = purple_request_field_string_new("pass1", _("Passphrase"), "", FALSE); purple_request_field_string_set_masked(f, TRUE); purple_request_field_group_add_field(g, f); f = purple_request_field_string_new("pass2", _("Passphrase (retype)"), "", FALSE); purple_request_field_string_set_masked(f, TRUE); purple_request_field_group_add_field(g, f); purple_request_fields_add_group(fields, g); purple_request_fields(gc, _("Create New SILC Key Pair"), _("Create New SILC Key Pair"), NULL, fields, _("Generate Key Pair"), G_CALLBACK(silcpurple_create_keypair_cb), _("Cancel"), G_CALLBACK(silcpurple_create_keypair_cancel), gc->account, NULL, NULL, gc); g_strfreev(u); silc_free(hostname);}static voidsilcpurple_change_pass(PurplePluginAction *action){ PurpleConnection *gc = (PurpleConnection *) action->context; purple_account_request_change_password(purple_connection_get_account(gc));}static voidsilcpurple_change_passwd(PurpleConnection *gc, const char *old, const char *new){ char prd[256]; g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.pub", silcpurple_silcdir()); silc_change_private_key_passphrase(purple_account_get_string(gc->account, "private-key", prd), old, new);}static voidsilcpurple_show_set_info(PurplePluginAction *action){ PurpleConnection *gc = (PurpleConnection *) action->context; purple_account_request_change_user_info(purple_connection_get_account(gc));}static voidsilcpurple_set_info(PurpleConnection *gc, const char *text){}static GList *silcpurple_actions(PurplePlugin *plugin, gpointer context){ GList *list = NULL; PurplePluginAction *act; act = purple_plugin_action_new(_("Online Status"), silcpurple_attrs); list = g_list_append(list, act); act = purple_plugin_action_new(_("Detach From Server"), silcpurple_detach); list = g_list_append(list, act); act = purple_plugin_action_new(_("View Message of the Day"), silcpurple_view_motd); list = g_list_append(list, act); act = purple_plugin_action_new(_("Create SILC Key Pair..."), silcpurple_create_keypair); list = g_list_append(list, act); act = purple_plugin_action_new(_("Change Password..."), silcpurple_change_pass); list = g_list_append(list, act); act = purple_plugin_action_new(_("Set User Info..."), silcpurple_show_set_info); list = g_list_append(list, act); return list;}/******************************* IM Routines *********************************/typedef struct { char *nick; char *message; SilcUInt32 message_len; SilcMessageFlags flags; PurpleMessageFlags gflags;} *SilcPurpleIM;static voidsilcpurple_send_im_resolved(SilcClient client, SilcClientConnection conn, SilcStatus status, SilcDList clients, void *context){ PurpleConnection *gc = client->application; SilcPurple sg = gc->proto_data; SilcPurpleIM im = context; PurpleConversation *convo; char tmp[256]; SilcClientEntry client_entry; SilcDList list; convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, im->nick, sg->account); if (!convo) return; if (!clients) goto err; if (silc_dlist_count(clients) > 1) { /* Find the correct one. The im->nick might be a formatted nick so this will find the correct one. */ clients = silc_client_get_clients_local(client, conn, im->nick, FALSE); if (!clients) goto err; } silc_dlist_start(clients); client_entry = silc_dlist_get(clients); /* Check for images */ if (im->gflags & PURPLE_MESSAGE_IMAGES) { list = silcpurple_image_message(im->message, (SilcUInt32 *)(void *)&im->flags); if (list) { /* Send one or more MIME message. If more than one, they are MIME fragments due to over large message */ SilcBuffer buf; silc_dlist_start(list); while ((buf = silc_dlist_get(list)) != SILC_LIST_END) silc_client_send_private_message(client, conn, client_entry, im->flags, NULL, buf->data, silc_buffer_len(buf)); silc_mime_partial_free(list); purple_conv_im_write(PURPLE_CONV_IM(convo), conn->local_entry->nickname, im->message, 0, time(NULL)); goto out; } } /* Send the message */ silc_client_send_private_message(client, conn, client_entry, im->flags, NULL, (unsigned char *)im->message, im->message_len); purple_conv_im_write(PURPLE_CONV_IM(convo), conn->local_entry->nickname, im->message, 0, time(NULL)); goto out; err: g_snprintf(tmp, sizeof(tmp), _("User <I>%s</I> is not present in the network"), im->nick); purple_conversation_write(convo, NULL, tmp, PURPLE_MESSAGE_SYSTEM, time(NULL)); out: g_free(im->nick); g_free(im->message); silc_free(im);}static intsilcpurple_send_im(PurpleConnection *gc, const char *who, const char *message, PurpleMessageFlags flags){ SilcPurple sg = gc->proto_data; SilcClient client = sg->client;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -