From: Piotr S. <ps...@us...> - 2009-09-17 12:05:39
|
Update of /cvsroot/ayttm/ayttm/modules/aycryption In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv12682/modules/aycryption Modified Files: aycryption.c select-keys.c select-keys.h Log Message: reformatted source code Index: aycryption.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/aycryption/aycryption.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- aycryption.c 26 Aug 2009 09:26:14 -0000 1.26 +++ aycryption.c 17 Sep 2009 12:04:58 -0000 1.27 @@ -47,42 +47,40 @@ ******************************************************************************/ /* Module defines */ #ifndef USE_POSIX_DLOPEN - #define plugin_info aycryption_LTX_plugin_info - #define module_version aycryption_LTX_module_version +#define plugin_info aycryption_LTX_plugin_info +#define module_version aycryption_LTX_module_version #endif - /* Function Prototypes */ -static char *aycryption_out(const eb_local_account * local, const eb_account * remote, - struct contact *contact, const char * s); -static char *aycryption_in(const eb_local_account * local, const eb_account * remote, - const struct contact *contact, const char * s); +static char *aycryption_out(const eb_local_account *local, + const eb_account *remote, struct contact *contact, const char *s); +static char *aycryption_in(const eb_local_account *local, + const eb_account *remote, const struct contact *contact, const char *s); static void set_gpg_key(ebmCallbackData *data); static void show_gpg_log(ebmCallbackData *data); -void pgp_encrypt ( gpgme_data_t plain, gpgme_data_t *cipher, gpgme_key_t *kset, int sign ); +void pgp_encrypt(gpgme_data_t plain, gpgme_data_t *cipher, gpgme_key_t *kset, + int sign); -gpgme_error_t gpgmegtk_passphrase_cb (void *opaque, - const char *desc, - const char *passphrase_info, - int prev_was_bad, - int fd); +gpgme_error_t gpgmegtk_passphrase_cb(void *opaque, + const char *desc, + const char *passphrase_info, int prev_was_bad, int fd); static int aycryption_init(); static int aycryption_finish(); struct passphrase_cb_info_s { - gpgme_ctx_t c; - int did_it; + gpgme_ctx_t c; + int did_it; }; static int store_passphrase = 0; static char mykey[MAX_PREF_LEN] = ""; static int ref_count = 0; -static void *tag1=NULL; -static void *tag2=NULL; -static void *tag3=NULL; -static void *tag4=NULL; +static void *tag1 = NULL; +static void *tag2 = NULL; +static void *tag3 = NULL; +static void *tag4 = NULL; static GtkWidget *gpg_log_window = NULL; static GtkWidget *gpg_log_text = NULL; @@ -95,7 +93,7 @@ PLUGIN_FILTER, "Aycryption", "Encrypts messages with GPG.\n" - "WARNING: Apparently MSN servers randomly truncates GPG signed/encrypted messages.", + "WARNING: Apparently MSN servers randomly truncates GPG signed/encrypted messages.", "$Revision$", "$Date$", &ref_count, @@ -103,9 +101,13 @@ aycryption_finish, NULL }; + /* End Module Exports */ -unsigned int module_version() {return CORE_VERSION;} +unsigned int module_version() +{ + return CORE_VERSION; +} static int aycryption_init() { @@ -120,69 +122,81 @@ il->type = EB_INPUT_CHECKBOX; il->next = g_new0(input_list, 1); - il = il->next; + il = il->next; il->widget.entry.value = mykey; il->name = "mykey"; il->label = strdup(_("Private key for signing:")); il->type = EB_INPUT_ENTRY; il->next = g_new0(input_list, 1); - il = il->next; + il = il->next; il->widget.checkbox.value = &do_aycryption_debug; il->name = "do_aycryption_debug"; il->label = strdup(_("Enable debugging")); il->type = EB_INPUT_CHECKBOX; - outgoing_message_filters = l_list_append(outgoing_message_filters, &aycryption_out); - incoming_message_filters = l_list_append(incoming_message_filters, &aycryption_in); - + outgoing_message_filters = + l_list_append(outgoing_message_filters, &aycryption_out); + incoming_message_filters = + l_list_append(incoming_message_filters, &aycryption_in); + gpg_log_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gpg_log_text = gtk_text_view_new(); - gpg_log_swindow = gtk_scrolled_window_new(NULL,NULL); - - gtk_window_set_title(GTK_WINDOW(gpg_log_window), _("Aycryption - status")); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gpg_log_swindow), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + gpg_log_swindow = gtk_scrolled_window_new(NULL, NULL); + + gtk_window_set_title(GTK_WINDOW(gpg_log_window), + _("Aycryption - status")); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gpg_log_swindow), + GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); html_text_view_init(GTK_TEXT_VIEW(gpg_log_text), HTML_IGNORE_FONT); gtk_widget_set_size_request(gpg_log_text, 450, 150); - + gtk_container_add(GTK_CONTAINER(gpg_log_swindow), gpg_log_text); gtk_container_add(GTK_CONTAINER(gpg_log_window), gpg_log_swindow); gtk_widget_show(gpg_log_text); gtk_widget_show(gpg_log_swindow); - + g_signal_connect(gpg_log_window, "delete-event", - G_CALLBACK(gtk_widget_hide_on_delete), NULL); - + G_CALLBACK(gtk_widget_hide_on_delete), NULL); + gtk_widget_realize(gpg_log_window); gtk_widget_realize(gpg_log_swindow); gtk_widget_realize(gpg_log_text); - tag1=eb_add_menu_item(_("GPG settings..."), EB_CHAT_WINDOW_MENU, set_gpg_key, ebmCONTACTDATA, NULL); - if(!tag1) { - eb_debug(DBG_MOD, "Error! Unable to add aycryption menu to chat window menu\n"); - return(-1); - } - tag2=eb_add_menu_item(_("GPG settings..."), EB_CONTACT_MENU, set_gpg_key, ebmCONTACTDATA, NULL); - if(!tag2) { + tag1 = eb_add_menu_item(_("GPG settings..."), EB_CHAT_WINDOW_MENU, + set_gpg_key, ebmCONTACTDATA, NULL); + if (!tag1) { + eb_debug(DBG_MOD, + "Error! Unable to add aycryption menu to chat window menu\n"); + return (-1); + } + tag2 = eb_add_menu_item(_("GPG settings..."), EB_CONTACT_MENU, + set_gpg_key, ebmCONTACTDATA, NULL); + if (!tag2) { eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag1); - eb_debug(DBG_MOD, "Error! Unable to add aycryption menu to contact menu\n"); - return(-1); - } - tag3=eb_add_menu_item(_("GPG status..."), EB_CHAT_WINDOW_MENU, show_gpg_log, ebmCONTACTDATA, NULL); - if(!tag3) { + eb_debug(DBG_MOD, + "Error! Unable to add aycryption menu to contact menu\n"); + return (-1); + } + tag3 = eb_add_menu_item(_("GPG status..."), EB_CHAT_WINDOW_MENU, + show_gpg_log, ebmCONTACTDATA, NULL); + if (!tag3) { eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag1); eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag2); - eb_debug(DBG_MOD, "Error! Unable to add aycryption menu to chat window menu\n"); - return(-1); - } - tag4=eb_add_menu_item(_("GPG status..."), EB_CONTACT_MENU, show_gpg_log, ebmCONTACTDATA, NULL); - if(!tag4) { + eb_debug(DBG_MOD, + "Error! Unable to add aycryption menu to chat window menu\n"); + return (-1); + } + tag4 = eb_add_menu_item(_("GPG status..."), EB_CONTACT_MENU, + show_gpg_log, ebmCONTACTDATA, NULL); + if (!tag4) { eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag1); eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag2); eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag3); - eb_debug(DBG_MOD, "Error! Unable to add aycryption menu to contact menu\n"); - return(-1); + eb_debug(DBG_MOD, + "Error! Unable to add aycryption menu to contact menu\n"); + return (-1); } return 0; @@ -190,10 +204,12 @@ static int aycryption_finish() { - outgoing_message_filters = l_list_remove(outgoing_message_filters, &aycryption_out); - incoming_message_filters = l_list_remove(incoming_message_filters, &aycryption_in); - - while(plugin_info.prefs) { + outgoing_message_filters = + l_list_remove(outgoing_message_filters, &aycryption_out); + incoming_message_filters = + l_list_remove(incoming_message_filters, &aycryption_in); + + while (plugin_info.prefs) { input_list *il = plugin_info.prefs->next; free(plugin_info.prefs); plugin_info.prefs = il; @@ -207,7 +223,7 @@ eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag3); if (tag4) eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag4); - + gtk_widget_destroy(gpg_log_window); return 0; } @@ -217,27 +233,23 @@ ******************************************************************************/ /* removes the <br/> crap that kopete adds */ -static void br_to_nl(char * text) +static void br_to_nl(char *text) { int i, j; int visible = 1; - for (i=0, j=0; text[i]; i++) - { - if(text[i] == '<') - { - if (!strncasecmp(text+i+1, "br/", 3)) { + for (i = 0, j = 0; text[i]; i++) { + if (text[i] == '<') { + if (!strncasecmp(text + i + 1, "br/", 3)) { /* Kopete compat */ visible = 0; text[j++] = '\n'; - } else if (!strncasecmp(text+i+1, "br", 2)) { + } else if (!strncasecmp(text + i + 1, "br", 2)) { /* Fire compat */ visible = 0; text[j++] = '\n'; } - } - else if (text[i] == '>') - { - if(!visible) { + } else if (text[i] == '>') { + if (!visible) { visible = 1; continue; } @@ -250,8 +262,8 @@ static gpgme_error_t mygpgme_data_rewind(gpgme_data_t dh) { - return (gpgme_data_seek (dh, 0, SEEK_SET) == -1) - ? gpgme_error_from_errno (errno) : 0; + return (gpgme_data_seek(dh, 0, SEEK_SET) == -1) + ? gpgme_error_from_errno(errno) : 0; } static void show_gpg_log(ebmCallbackData *data) @@ -264,26 +276,27 @@ static void set_gpg_key(ebmCallbackData *data) { - ebmContactData *ecd=NULL; + ebmContactData *ecd = NULL; struct contact *ct = NULL; struct select_keys_s keys; GSList *recp_names = NULL; - if(IS_ebmContactData(data)) - ecd=(ebmContactData *)data; - + if (IS_ebmContactData(data)) + ecd = (ebmContactData *)data; + if (ecd) ct = find_contact_by_nick(ecd->contact); - + if (!ct) { eb_debug(DBG_CRYPT, "contact is null !\n"); return; } recp_names = g_slist_append(recp_names, strdup(ct->nick)); - if (ct->gpg_key && ct->gpg_key[0]); - recp_names = g_slist_append(recp_names, strdup(ct->gpg_key)); - keys = gpgmegtk_recipient_selection(recp_names, ct->gpg_do_encryption, ct->gpg_do_signature); + if (ct->gpg_key && ct->gpg_key[0]) ; + recp_names = g_slist_append(recp_names, strdup(ct->gpg_key)); + keys = gpgmegtk_recipient_selection(recp_names, ct->gpg_do_encryption, + ct->gpg_do_signature); if (keys.kset && keys.key) { - eb_debug(DBG_CRYPT,"got key %s\n", keys.key); + eb_debug(DBG_CRYPT, "got key %s\n", keys.key); strncpy(ct->gpg_key, keys.key, 48); ct->gpg_do_encryption = keys.do_crypt; @@ -296,21 +309,25 @@ ct->gpg_do_signature = keys.do_sign; } write_contact_list(); - + } -static char *logcolor[3] = {"#ffa8a8", "#a8a8a8", "#a8ffa8"}; +static char *logcolor[3] = { "#ffa8a8", "#a8a8a8", "#a8ffa8" }; + typedef enum { - LOG_ERR=0, + LOG_ERR = 0, LOG_NORM, LOG_OK } LogLevel; - -static void log_action(const struct contact *ct, int loglevel, const char *string) + +static void log_action(const struct contact *ct, int loglevel, + const char *string) { - + char buf[1024]; - snprintf(buf, 1024, _("<font color=%s><b>%s</b>: %s</font><br>"),logcolor[loglevel], ct->nick, string); - html_text_buffer_append(GTK_TEXT_VIEW(gpg_log_text), buf, HTML_IGNORE_NONE); + snprintf(buf, 1024, _("<font color=%s><b>%s</b>: %s</font><br>"), + logcolor[loglevel], ct->nick, string); + html_text_buffer_append(GTK_TEXT_VIEW(gpg_log_text), buf, + HTML_IGNORE_NONE); if (loglevel == LOG_ERR) { show_gpg_log(NULL); } @@ -325,7 +342,7 @@ err = gpgme_new(&ctx); g_assert(!err); - err = gpgme_op_keylist_start (ctx, ct->gpg_key, 0); + err = gpgme_op_keylist_start(ctx, ct->gpg_key, 0); if (err) { eb_debug(DBG_CRYPT, "err: %s\n", gpgme_strerror(err)); *kset = NULL; @@ -334,21 +351,19 @@ *kset = g_malloc(sizeof(gpgme_key_t)); - while ( !(err = gpgme_op_keylist_next ( ctx, &(*kset)[num_keys] )) ) { - eb_debug(DBG_CRYPT,"found a key for %s with name %s\n", - ct->gpg_key, - (*kset)[num_keys]->uids->name); + while (!(err = gpgme_op_keylist_next(ctx, &(*kset)[num_keys]))) { + eb_debug(DBG_CRYPT, "found a key for %s with name %s\n", + ct->gpg_key, (*kset)[num_keys]->uids->name); - *kset = g_realloc( *kset, sizeof(gpgme_key_t) * (num_keys + 1) ); + *kset = g_realloc(*kset, sizeof(gpgme_key_t) * (num_keys + 1)); num_keys++; } gpgme_release(ctx); } - -static char *aycryption_out(const eb_local_account * local, const eb_account * remote, - struct contact *ct, const char * s) +static char *aycryption_out(const eb_local_account *local, + const eb_account *remote, struct contact *ct, const char *s) { char *p = NULL; char buf[4096]; @@ -360,67 +375,69 @@ int err; if ((!ct->gpg_do_encryption || !ct->gpg_key || ct->gpg_key == '\0') - && !ct->gpg_do_signature) { + && !ct->gpg_do_signature) { if (ct->gpg_do_encryption) log_action(ct, LOG_ERR, "Could not encrypt message."); return strdup(s); } - if( ct->gpg_do_encryption && ct->gpg_key && ct->gpg_key[0] ) + if (ct->gpg_do_encryption && ct->gpg_key && ct->gpg_key[0]) gpg_get_kset(ct, &kset); - - if ( ct->gpg_do_encryption && ct->gpg_key && ct->gpg_key[0] && !kset ) { - eb_debug(DBG_CRYPT,"can't init outgoing crypt: %d %p %c\n", - ct->gpg_do_encryption, ct->gpg_key, ct->gpg_key[0]); - log_action(ct, LOG_ERR, "Could not encrypt message - you may have to set your contact's key."); + if (ct->gpg_do_encryption && ct->gpg_key && ct->gpg_key[0] && !kset) { + eb_debug(DBG_CRYPT, "can't init outgoing crypt: %d %p %c\n", + ct->gpg_do_encryption, ct->gpg_key, ct->gpg_key[0]); + log_action(ct, LOG_ERR, + "Could not encrypt message - you may have to set your contact's key."); return strdup(s); } - + error = gpgme_data_new(&plain); err = gpgme_data_write(plain, s, strlen(s)); - + /* encrypt only */ if (ct->gpg_do_encryption && kset && !ct->gpg_do_signature) { - pgp_encrypt (plain, &cipher, kset, FALSE); - gpgme_data_release (plain); plain = NULL; + pgp_encrypt(plain, &cipher, kset, FALSE); + gpgme_data_release(plain); + plain = NULL; log_action(ct, LOG_NORM, "Sent encrypted, unsigned message."); - /* sign only */ + /* sign only */ } else if (!(ct->gpg_do_encryption && kset) && ct->gpg_do_signature) { pgp_encrypt(plain, &cipher, NULL, TRUE); - gpgme_data_release (plain); plain = NULL; - log_action(ct, LOG_NORM, "Sent uncrypted, signed message."); - /* encrypt and sign */ + gpgme_data_release(plain); + plain = NULL; + log_action(ct, LOG_NORM, "Sent uncrypted, signed message."); + /* encrypt and sign */ } else if (ct->gpg_do_encryption && kset && ct->gpg_do_signature) { - pgp_encrypt (plain, &cipher, kset, TRUE); - gpgme_data_release (plain); plain = NULL; + pgp_encrypt(plain, &cipher, kset, TRUE); + gpgme_data_release(plain); + plain = NULL; log_action(ct, LOG_NORM, "Sent encrypted, signed message."); } - err = mygpgme_data_rewind (cipher); + err = mygpgme_data_rewind(cipher); if (err) - eb_debug(DBG_CRYPT,"error: %s\n", - gpgme_strerror(err)); - + eb_debug(DBG_CRYPT, "error: %s\n", gpgme_strerror(err)); + memset(buf, 0, sizeof(buf)); - while ( gpgme_data_read (cipher, buf, 4096) >0 ) { + while (gpgme_data_read(cipher, buf, 4096) > 0) { char tmp[4096]; - - snprintf(tmp, sizeof(tmp), "%s%s",(p!=NULL)?p:"", buf); + + snprintf(tmp, sizeof(tmp), "%s%s", (p != NULL) ? p : "", buf); if (p) free(p); p = strdup(tmp); memset(buf, 0, sizeof(buf)); } - if(cipher) - gpgme_data_release(cipher); + if (cipher) + gpgme_data_release(cipher); return p; } -static char *aycryption_in(const eb_local_account * local, const eb_account * remote, - const struct contact *ct, const char * s) +static char *aycryption_in(const eb_local_account *local, + const eb_account *remote, const struct contact *ct, const char *s) { char *p = NULL, *res = NULL, *s_nohtml = NULL; gpgme_data_t plain = NULL, cipher = NULL; @@ -438,102 +455,104 @@ int sig_code = 0; memset(buf, 0, 4096); - if (strncmp (s, "-----BEGIN PGP ", strlen("-----BEGIN PGP "))) { + if (strncmp(s, "-----BEGIN PGP ", strlen("-----BEGIN PGP "))) { eb_debug(DBG_CRYPT, "Incoming message isn't PGP formatted\n"); return strdup(s); } - err = gpgme_new (&ctx); + err = gpgme_new(&ctx); if (err) { - eb_debug(DBG_CRYPT,"gpgme_new failed: %s\n", gpgme_strerror (err)); - log_action(ct, LOG_ERR, "Memory error."); - return strdup(s); + eb_debug(DBG_CRYPT, "gpgme_new failed: %s\n", + gpgme_strerror(err)); + log_action(ct, LOG_ERR, "Memory error."); + return strdup(s); } gpgme_data_new(&plain); gpgme_data_new(&cipher); - + /* Clean out kopete HTML crap * < vdanen> so like KDE to just bloat stuff for the hell of it */ s_nohtml = strdup(s); - if (!s_nohtml) - { - eb_debug(DBG_CRYPT,"Couldn't copy message to strip html"); + if (!s_nohtml) { + eb_debug(DBG_CRYPT, "Couldn't copy message to strip html"); log_action(ct, LOG_ERR, "Memory error while stripping html."); return strdup(s); } br_to_nl(s_nohtml); - eb_debug(DBG_CRYPT,"html stripped: %s\n",s_nohtml); + eb_debug(DBG_CRYPT, "html stripped: %s\n", s_nohtml); err = gpgme_data_write(cipher, s_nohtml, strlen(s_nohtml)); - if(err == -1) + if (err == -1) perror("cipher write error"); free(s_nohtml); mygpgme_data_rewind(cipher); mygpgme_data_rewind(plain); - + if (!getenv("GPG_AGENT_INFO")) { - gpgme_set_passphrase_cb (ctx, gpgmegtk_passphrase_cb, NULL); - } - err = gpgme_op_decrypt_verify (ctx, cipher, plain); + gpgme_set_passphrase_cb(ctx, gpgmegtk_passphrase_cb, NULL); + } + err = gpgme_op_decrypt_verify(ctx, cipher, plain); if (err && gpg_err_code(err) != GPG_ERR_NO_DATA) { - log_action(ct, LOG_ERR, "Cannot decrypt message - maybe your contact uses an incorrect key."); + log_action(ct, LOG_ERR, + "Cannot decrypt message - maybe your contact uses an incorrect key."); return strdup(s); - } else if (gpg_err_code(err) == GPG_ERR_NO_DATA) { /*plaintext signed*/ + } else if (gpg_err_code(err) == GPG_ERR_NO_DATA) { /*plaintext signed */ was_crypted = 0; mygpgme_data_rewind(cipher); mygpgme_data_rewind(plain); err = gpgme_op_verify(ctx, cipher, sigstat, plain); if (err) - eb_debug(DBG_CRYPT, "plaintext err: %s\n", gpgme_strerror(err)); + eb_debug(DBG_CRYPT, "plaintext err: %s\n", + gpgme_strerror(err)); } - + verify_result = gpgme_op_verify_result(ctx); - - if(verify_result && verify_result->signatures) { - err = gpgme_get_key(ctx, verify_result->signatures->fpr, &key, 0); + + if (verify_result && verify_result->signatures) { + err = gpgme_get_key(ctx, verify_result->signatures->fpr, &key, + 0); if (err) { - eb_debug(DBG_CRYPT, "getkey err %s\n", gpgme_strerror(err)); + eb_debug(DBG_CRYPT, "getkey err %s\n", + gpgme_strerror(err)); key = NULL; } - } - else + } else key = NULL; err = mygpgme_data_rewind(plain); if (err) eb_debug(DBG_CRYPT, "rewind err %d\n", err); - memset(buf, 0, sizeof(buf)); - while ( gpgme_data_read (plain, buf, 4096) > 0 ) { + while (gpgme_data_read(plain, buf, 4096) > 0) { char tmp[4096]; memset(tmp, 0, 4096); - snprintf(tmp, sizeof(tmp), "%s%s",(p!=NULL)?p:"", buf); + snprintf(tmp, sizeof(tmp), "%s%s", (p != NULL) ? p : "", buf); if (p) free(p); p = strdup(tmp); memset(buf, 0, sizeof(buf)); } - + if (p) { - while (p[strlen(p)-1] == '\n' || p[strlen(p)-1] == '\r') - p[strlen(p)-1] = '\0'; + while (p[strlen(p) - 1] == '\n' || p[strlen(p) - 1] == '\r') + p[strlen(p) - 1] = '\0'; } gpgme_release(ctx); - if( verify_result && verify_result->signatures ) { + if (verify_result && verify_result->signatures) { sig_code = gpg_err_code(verify_result->signatures->status); - - switch( sig_code ) { + + switch (sig_code) { case GPG_ERR_NO_DATA: curloglevel = LOG_NORM; break; @@ -544,11 +563,12 @@ curloglevel = LOG_ERR; break; } - + strcpy(s_sigstat, _("Got an ")); - strcat(s_sigstat, was_crypted?_("encrypted"):_("unencrypted")); - - switch( sig_code ) { + strcat(s_sigstat, + was_crypted ? _("encrypted") : _("unencrypted")); + + switch (sig_code) { case GPG_ERR_NO_DATA: strcat(s_sigstat, _(", unsigned message.")); break; @@ -566,12 +586,15 @@ strcat(s_sigstat, _(" message with no key.")); break; case GPG_ERR_CERT_REVOKED: - strcat(s_sigstat, _(" message ; signature is valid but the signing key has been revoked")); + strcat(s_sigstat, + _ + (" message ; signature is valid but the signing key has been revoked")); break; case GPG_ERR_BAD_SIGNATURE: strcat(s_sigstat, _(" correctly signed (by ")); strcat(s_sigstat, key->uids->email); - strcat(s_sigstat, _(") message, but signature has expired.")); + strcat(s_sigstat, + _(") message, but signature has expired.")); break; case GPG_ERR_KEY_EXPIRED: strcat(s_sigstat, _(" correctly signed (by ")); @@ -579,10 +602,14 @@ strcat(s_sigstat, _(") message, but key has expired.")); break; case GPG_ERR_GENERAL: - strcat(s_sigstat, _(") message, but there was an error verifying the signature")); + strcat(s_sigstat, + _ + (") message, but there was an error verifying the signature")); break; default: - strcat(s_sigstat, _(" message - Unknown signature status (file a bugreport)!")); + strcat(s_sigstat, + _ + (" message - Unknown signature status (file a bugreport)!")); break; } @@ -597,7 +624,7 @@ return p; } -static GSList *create_signers_list (const char *keyid) +static GSList *create_signers_list(const char *keyid) { GSList *key_list = NULL; gpgme_ctx_t list_ctx = NULL; @@ -605,18 +632,18 @@ gpgme_error_t err; gpgme_key_t key; - err = gpgme_new (&list_ctx); - if ( gpg_err_code(err) != GPG_ERR_NO_ERROR ) { + err = gpgme_new(&list_ctx); + if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { goto leave; } - err = gpgme_op_keylist_start (list_ctx, keyid, 1); - if ( gpg_err_code(err) != GPG_ERR_NO_ERROR ) { + err = gpgme_op_keylist_start(list_ctx, keyid, 1); + if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { goto leave; } err = gpgme_op_keylist_next(list_ctx, &key); - while ( gpg_err_code(err) != GPG_ERR_NO_ERROR ) { - key_list = g_slist_append (key_list, key); + while (gpg_err_code(err) != GPG_ERR_NO_ERROR) { + key_list = g_slist_append(key_list, key); err = gpgme_op_keylist_next(list_ctx, &key); } if (gpg_err_code(err) != GPG_ERR_EOF) { @@ -624,18 +651,19 @@ } err = 0; if (key_list == NULL) { - eb_debug (DBG_CRYPT,"no keys found for keyid \"%s\"\n", keyid); + eb_debug(DBG_CRYPT, "no keys found for keyid \"%s\"\n", keyid); } -leave: + leave: if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { - eb_debug (DBG_CRYPT,"create_signers_list failed: %s\n", gpgme_strerror (err)); + eb_debug(DBG_CRYPT, "create_signers_list failed: %s\n", + gpgme_strerror(err)); for (p = key_list; p != NULL; p = p->next) - gpgme_key_unref ((gpgme_key_t) p->data); - g_slist_free (key_list); + gpgme_key_unref((gpgme_key_t) p->data); + g_slist_free(key_list); } if (list_ctx) - gpgme_release (list_ctx); + gpgme_release(list_ctx); return err ? NULL : key_list; } @@ -645,87 +673,89 @@ * the file or NULL in case of error. */ void -pgp_encrypt ( gpgme_data_t plain, gpgme_data_t *cipher, gpgme_key_t *kset, int sign ) +pgp_encrypt(gpgme_data_t plain, gpgme_data_t *cipher, gpgme_key_t *kset, + int sign) { gpgme_ctx_t ctx = NULL; - gpgme_error_t err ; + gpgme_error_t err; GSList *p; GSList *key_list = NULL; - - if(sign && mykey[0]) { + if (sign && mykey[0]) { key_list = create_signers_list(mykey); } - - err = gpgme_new (&ctx); + + err = gpgme_new(&ctx); if (gpg_err_code(err) == GPG_ERR_NO_ERROR) - err = gpgme_data_new (cipher); + err = gpgme_data_new(cipher); if (gpg_err_code(err) == GPG_ERR_NO_ERROR && sign) { - + if (!getenv("GPG_AGENT_INFO")) { - gpgme_set_passphrase_cb (ctx, gpgmegtk_passphrase_cb, NULL); + gpgme_set_passphrase_cb(ctx, gpgmegtk_passphrase_cb, + NULL); } if (kset != NULL) { - gpgme_set_textmode (ctx, 1); - gpgme_set_armor (ctx, 1); + gpgme_set_textmode(ctx, 1); + gpgme_set_armor(ctx, 1); } - gpgme_signers_clear (ctx); + gpgme_signers_clear(ctx); for (p = key_list; p != NULL; p = p->next) { - err = gpgme_signers_add (ctx, (gpgme_key_t) p->data); + err = gpgme_signers_add(ctx, (gpgme_key_t) p->data); } if (kset != NULL) { mygpgme_data_rewind(plain); - err = gpgme_op_encrypt_sign(ctx, kset, 0, plain, *cipher); + err = gpgme_op_encrypt_sign(ctx, kset, 0, plain, + *cipher); } else { mygpgme_data_rewind(plain); - err = gpgme_op_sign (ctx, plain, *cipher, GPGME_SIG_MODE_CLEAR); + err = gpgme_op_sign(ctx, plain, *cipher, + GPGME_SIG_MODE_CLEAR); } for (p = key_list; p != NULL; p = p->next) - gpgme_key_unref ((gpgme_key_t) p->data); - g_slist_free (key_list); - } - else if (gpg_err_code(err) == GPG_ERR_NO_ERROR) { - gpgme_set_armor (ctx, 1); + gpgme_key_unref((gpgme_key_t) p->data); + g_slist_free(key_list); + } else if (gpg_err_code(err) == GPG_ERR_NO_ERROR) { + gpgme_set_armor(ctx, 1); mygpgme_data_rewind(plain); - err = gpgme_op_encrypt (ctx, kset, 0, plain, *cipher); + err = gpgme_op_encrypt(ctx, kset, 0, plain, *cipher); } - + if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { - eb_debug(DBG_CRYPT, "pgp_encrypt failed: %s\n", gpgme_strerror(err)); - gpgme_data_release (*cipher); + eb_debug(DBG_CRYPT, "pgp_encrypt failed: %s\n", + gpgme_strerror(err)); + gpgme_data_release(*cipher); *cipher = NULL; } - gpgme_release (ctx); + gpgme_release(ctx); } gpgme_error_t -gpgmegtk_passphrase_cb (void *opaque, const char *desc, const char *passphrase_info, int prev_was_bad, int fd) +gpgmegtk_passphrase_cb(void *opaque, const char *desc, + const char *passphrase_info, int prev_was_bad, int fd) { const char *pass; - + if (store_passphrase && aycrypt_last_pass != NULL && !prev_was_bad) { write(fd, aycrypt_last_pass, strlen(aycrypt_last_pass)); write(fd, "\n", 1); return GPG_ERR_NO_ERROR; } - pass = passphrase_mbox (desc, prev_was_bad); + pass = passphrase_mbox(desc, prev_was_bad); if (!pass) { eb_debug(DBG_CRYPT, "Cancelled passphrase entry\n"); write(fd, "\n", 1); return GPG_ERR_CANCELED; - } - else { + } else { if (store_passphrase) { if (aycrypt_last_pass) g_free(aycrypt_last_pass); aycrypt_last_pass = g_strdup(pass); } } - write (fd, pass, strlen(pass)); - write (fd, "\n", 1); + write(fd, pass, strlen(pass)); + write(fd, "\n", 1); return GPG_ERR_NO_ERROR; } - Index: select-keys.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/aycryption/select-keys.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- select-keys.c 7 Sep 2009 07:52:50 -0000 1.8 +++ select-keys.c 17 Sep 2009 12:04:58 -0000 1.9 @@ -38,7 +38,7 @@ #define DIM(v) (sizeof(v)/sizeof((v)[0])) #define DIMof(type,member) DIM(((type *)0)->member) -enum col_titles { +enum col_titles { COL_ALGO, COL_KEYID, COL_NAME, @@ -48,41 +48,37 @@ N_COL_TITLES }; -static void set_row (GtkListStore *clist_store, gpgme_key_t key); -static void fill_clist (struct select_keys_s *sk, const char *pattern); -static void create_dialog (struct select_keys_s *sk); -static void open_dialog (struct select_keys_s *sk); -static void close_dialog (struct select_keys_s *sk); -static gint delete_event_cb (GtkWidget *widget, - GdkEventAny *event, gpointer data); -static void key_pressed_cb (GtkWidget *widget, - GdkEventKey *event, gpointer data); -static void select_btn_cb (GtkWidget *widget, gpointer data); -static void cancel_btn_cb (GtkWidget *widget, gpointer data); -static void other_btn_cb (GtkWidget *widget, gpointer data); - +static void set_row(GtkListStore *clist_store, gpgme_key_t key); +static void fill_clist(struct select_keys_s *sk, const char *pattern); +static void create_dialog(struct select_keys_s *sk); +static void open_dialog(struct select_keys_s *sk); +static void close_dialog(struct select_keys_s *sk); +static gint delete_event_cb(GtkWidget *widget, + GdkEventAny *event, gpointer data); +static void key_pressed_cb(GtkWidget *widget, + GdkEventKey *event, gpointer data); +static void select_btn_cb(GtkWidget *widget, gpointer data); +static void cancel_btn_cb(GtkWidget *widget, gpointer data); +static void other_btn_cb(GtkWidget *widget, gpointer data); char *aycrypt_last_pass = NULL; int aycrypt_pass_ack = 0; static void -update_progress (struct select_keys_s *sk, int running, const char *pattern) +update_progress(struct select_keys_s *sk, int running, const char *pattern) { static int windmill[] = { '-', '\\', '|', '/' }; char *buf; if (!running) - buf = g_strdup_printf (_("Please select key for `%s'"), - pattern); - else - buf = g_strdup_printf (_("Collecting info for `%s' ... %c"), - pattern, - windmill[running%DIM(windmill)]); - gtk_label_set_text (sk->toplabel, buf); - g_free (buf); + buf = g_strdup_printf(_("Please select key for `%s'"), pattern); + else + buf = g_strdup_printf(_("Collecting info for `%s' ... %c"), + pattern, windmill[running % DIM(windmill)]); + gtk_label_set_text(sk->toplabel, buf); + g_free(buf); } - /** * select_keys_get_recipients: * @recp_names: A list of email addresses @@ -94,65 +90,65 @@ * Return value: NULL on error or a list of list of recipients. **/ struct select_keys_s -gpgmegtk_recipient_selection (GSList *recp_names, int crypt, int sign) +gpgmegtk_recipient_selection(GSList *recp_names, int crypt, int sign) { struct select_keys_s sk; GSList *recp_walk = recp_names; - memset (&sk, 0, sizeof sk); + memset(&sk, 0, sizeof sk); sk.do_crypt = crypt; sk.do_sign = sign; - open_dialog (&sk); + open_dialog(&sk); - gtk_list_store_clear (GTK_LIST_STORE(gtk_tree_view_get_model(sk.clist))); + gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(sk.clist))); do { - sk.pattern = recp_walk? recp_walk->data:NULL; - printf("sk.pattern = %s\n",sk.pattern); - fill_clist (&sk, sk.pattern); - update_progress (&sk, 0, recp_names?recp_names->data:NULL); - + sk.pattern = recp_walk ? recp_walk->data : NULL; + printf("sk.pattern = %s\n", sk.pattern); + fill_clist(&sk, sk.pattern); + update_progress(&sk, 0, recp_names ? recp_names->data : NULL); + if (recp_walk) recp_walk = recp_walk->next; } while (recp_walk); - gtk_main (); + gtk_main(); - close_dialog (&sk); + close_dialog(&sk); if (!sk.okay) { - g_free (sk.kset); - sk.kset = NULL; sk.key = NULL; + g_free(sk.kset); + sk.kset = NULL; + sk.key = NULL; } else { /* Terminating the key list with a NULL */ - sk.kset = g_realloc( sk.kset, sizeof(gpgme_key_t) * (sk.num_keys + 1) ); + sk.kset = + g_realloc(sk.kset, + sizeof(gpgme_key_t) * (sk.num_keys + 1)); sk.kset[sk.num_keys] = NULL; } return sk; -} +} /* Release key data */ -static gboolean destroy_key(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +static gboolean destroy_key(GtkTreeModel *model, GtkTreePath *path, + GtkTreeIter *iter, gpointer data) { gpgme_key_t key; - gtk_tree_model_get(model, iter, - COL_GPG_KEY, &key, - -1); + gtk_tree_model_get(model, iter, COL_GPG_KEY, &key, -1); - if(key) - gpgme_key_release (key); + if (key) + gpgme_key_release(key); return FALSE; } -static void -destroy_keys (GtkWidget *widget, gpointer data) +static void destroy_keys(GtkWidget *widget, gpointer data) { GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); gtk_tree_model_foreach(model, destroy_key, NULL); } -static void -set_row (GtkListStore *clist_store, gpgme_key_t key) +static void set_row(GtkListStore *clist_store, gpgme_key_t key) { const char *s; const char *text[N_COL_TITLES]; @@ -161,38 +157,39 @@ gpgme_key_t temp; gboolean finished = FALSE; - if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(clist_store), &row)) - gtk_tree_model_get(GTK_TREE_MODEL(clist_store), &row, - COL_GPG_KEY, &temp, -1); - - while ( !temp->subkeys && !finished ) { - if ( !strcmp(key->subkeys->keyid, temp->subkeys->keyid) ) - return; /* already found */ - if( !gtk_tree_model_iter_next(GTK_TREE_MODEL(clist_store), &row)) + if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(clist_store), &row)) + gtk_tree_model_get(GTK_TREE_MODEL(clist_store), &row, + COL_GPG_KEY, &temp, -1); + + while (!temp->subkeys && !finished) { + if (!strcmp(key->subkeys->keyid, temp->subkeys->keyid)) + return; /* already found */ + if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(clist_store), + &row)) finished = TRUE; else - gtk_tree_model_get(GTK_TREE_MODEL(clist_store), &row, - COL_GPG_KEY, &temp, -1); + gtk_tree_model_get(GTK_TREE_MODEL(clist_store), &row, + COL_GPG_KEY, &temp, -1); } - if(key->subkeys) + if (key->subkeys) printf("Found key: %s\n", key->uids->email); /* first check whether the key is capable of encryption which is not * the case for revoked, expired or sign-only keys */ - if ( !key->can_encrypt ) { + if (!key->can_encrypt) { printf("Cannot encrypt\n"); return; } - - algo_buf = g_strdup_printf ("%u/%s", - key->subkeys->length, - gpgme_pubkey_algo_name (key->subkeys->pubkey_algo ) ); + + algo_buf = g_strdup_printf("%u/%s", + key->subkeys->length, + gpgme_pubkey_algo_name(key->subkeys->pubkey_algo)); text[COL_ALGO] = algo_buf; s = key->subkeys->keyid; - if (strlen (s) == 16) - s += 8; /* show only the short keyID */ + if (strlen(s) == 16) + s += 8; /* show only the short keyID */ text[COL_KEYID] = s; s = key->uids->name; @@ -201,26 +198,25 @@ s = key->uids->email; text[COL_EMAIL] = s; - switch (key->uids->validity) - { + switch (key->uids->validity) { case GPGME_VALIDITY_UNDEFINED: - s="q"; + s = "q"; break; case GPGME_VALIDITY_NEVER: - s="n"; + s = "n"; break; case GPGME_VALIDITY_MARGINAL: - s="m"; + s = "m"; break; case GPGME_VALIDITY_FULL: - s="f"; + s = "f"; break; case GPGME_VALIDITY_ULTIMATE: - s="u"; + s = "u"; break; case GPGME_VALIDITY_UNKNOWN: default: - s="?"; + s = "?"; break; } @@ -228,55 +224,53 @@ gtk_list_store_append(clist_store, &newrow); gtk_list_store_set(clist_store, &newrow, - COL_ALGO, text[COL_ALGO], - COL_KEYID, text[COL_KEYID], - COL_NAME, text[COL_NAME], - COL_EMAIL, text[COL_EMAIL], - COL_VALIDITY, text[COL_VALIDITY], - COL_GPG_KEY, key, - -1); + COL_ALGO, text[COL_ALGO], + COL_KEYID, text[COL_KEYID], + COL_NAME, text[COL_NAME], + COL_EMAIL, text[COL_EMAIL], + COL_VALIDITY, text[COL_VALIDITY], COL_GPG_KEY, key, -1); - g_free (algo_buf); + g_free(algo_buf); } - -static void -fill_clist (struct select_keys_s *sk, const char *pattern) +static void fill_clist(struct select_keys_s *sk, const char *pattern) { GtkListStore *clist_store; gpgme_ctx_t ctx; gpgme_error_t err; gpgme_key_t key; - int running=0; + int running = 0; - g_return_if_fail (sk); - clist_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sk->clist))); - g_return_if_fail (clist_store); + g_return_if_fail(sk); + clist_store = + GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sk-> + clist))); + g_return_if_fail(clist_store); - err = gpgme_new (&ctx); - g_assert (!err); + err = gpgme_new(&ctx); + g_assert(!err); sk->select_ctx = ctx; - update_progress (sk, ++running, pattern); - while (gtk_events_pending ()) - gtk_main_iteration (); + update_progress(sk, ++running, pattern); + while (gtk_events_pending()) + gtk_main_iteration(); - err = gpgme_op_keylist_start (ctx, pattern, 0); + err = gpgme_op_keylist_start(ctx, pattern, 0); if (err) { sk->select_ctx = NULL; return; } - update_progress (sk, ++running, pattern); - while ( !(err = gpgme_op_keylist_next ( ctx, &key )) ) { - set_row (clist_store, key ); + update_progress(sk, ++running, pattern); + while (!(err = gpgme_op_keylist_next(ctx, &key))) { + set_row(clist_store, key); key = NULL; - update_progress (sk, ++running, pattern); - while (gtk_events_pending ()) - gtk_main_iteration (); + update_progress(sk, ++running, pattern); + while (gtk_events_pending()) + gtk_main_iteration(); } sk->select_ctx = NULL; - gpgme_release (ctx); + gpgme_release(ctx); } static void crypt_changed_cb(GtkWidget *w, void *data) @@ -291,56 +285,48 @@ sk->do_sign = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); } - /* Sorting function for Name column */ -static gint cmp_name (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data) +static gint cmp_name(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, + gpointer data) { - gpgme_key_t pa,pb; + gpgme_key_t pa, pb; const char *sa, *sb; - gtk_tree_model_get(model, a, - COL_GPG_KEY, &pa, - -1); - gtk_tree_model_get(model, b, - COL_GPG_KEY, &pb, - -1); + gtk_tree_model_get(model, a, COL_GPG_KEY, &pa, -1); + gtk_tree_model_get(model, b, COL_GPG_KEY, &pb, -1); - sa = pa?pa->uids->name:NULL; - sb = pb?pb->uids->name:NULL; + sa = pa ? pa->uids->name : NULL; + sb = pb ? pb->uids->name : NULL; - if(!sa) + if (!sa) return !!sb; - if(!sb) + if (!sb) return -1; return strcasecmp(sa, sb); } /* Sorting function for email column */ -static gint cmp_email (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data) +static gint cmp_email(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, + gpointer data) { - gpgme_key_t pa,pb; + gpgme_key_t pa, pb; const char *sa, *sb; - gtk_tree_model_get(model, a, - COL_GPG_KEY, &pa, - -1); - gtk_tree_model_get(model, b, - COL_GPG_KEY, &pb, - -1); + gtk_tree_model_get(model, a, COL_GPG_KEY, &pa, -1); + gtk_tree_model_get(model, b, COL_GPG_KEY, &pb, -1); - sa = pa?pa->uids->email:NULL; - sb = pb?pb->uids->email:NULL; + sa = pa ? pa->uids->email : NULL; + sb = pb ? pb->uids->email : NULL; - if(!sa) + if (!sa) return !!sb; - if(!sb) + if (!sb) return -1; return strcasecmp(sa, sb); } -static void -create_dialog (struct select_keys_s *sk) +static void create_dialog(struct select_keys_s *sk) { GtkWidget *window; GtkWidget *vbox, *vbox2, *hbox; @@ -350,178 +336,172 @@ GtkListStore *clist_store; GtkWidget *label; GtkWidget *vbox3; - GtkWidget *select_btn, *cancel_btn, *other_btn, *do_crypt_btn, *do_sign_btn; + GtkWidget *select_btn, *cancel_btn, *other_btn, *do_crypt_btn, + *do_sign_btn; const char *titles[N_COL_TITLES]; GtkTreeViewColumn *column; GtkCellRenderer *renderer; - g_assert (!sk->window); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_widget_set_size_request (window, 520, 280); - gtk_container_set_border_width (GTK_CONTAINER (window), 8); - gtk_window_set_title (GTK_WINDOW (window), _("Select Keys")); - g_signal_connect (window, "delete-event", G_CALLBACK (delete_event_cb), sk); - g_signal_connect (window, "key-press-event", G_CALLBACK (key_pressed_cb), sk); + g_assert(!sk->window); + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_set_size_request(window, 520, 280); + gtk_container_set_border_width(GTK_CONTAINER(window), 8); + gtk_window_set_title(GTK_WINDOW(window), _("Select Keys")); + g_signal_connect(window, "delete-event", G_CALLBACK(delete_event_cb), + sk); + g_signal_connect(window, "key-press-event", G_CALLBACK(key_pressed_cb), + sk); - vbox = gtk_vbox_new (FALSE, 8); - gtk_container_add (GTK_CONTAINER (window), vbox); + vbox = gtk_vbox_new(FALSE, 8); + gtk_container_add(GTK_CONTAINER(window), vbox); - hbox = gtk_hbox_new(FALSE, 4); + hbox = gtk_hbox_new(FALSE, 4); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); - label = gtk_label_new ( "" ); + label = gtk_label_new(""); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); - hbox = gtk_hbox_new (FALSE, 8); - gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 2); - - scrolledwin = gtk_scrolled_window_new (NULL, NULL); - gtk_box_pack_start (GTK_BOX (hbox), scrolledwin, TRUE, TRUE, 0); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - titles[COL_ALGO] = _("Size"); - titles[COL_KEYID] = _("Key ID"); - titles[COL_NAME] = _("Name"); - titles[COL_EMAIL] = _("Address"); - titles[COL_VALIDITY] = _("Val"); + hbox = gtk_hbox_new(FALSE, 8); + gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(hbox), 2); + + scrolledwin = gtk_scrolled_window_new(NULL, NULL); + gtk_box_pack_start(GTK_BOX(hbox), scrolledwin, TRUE, TRUE, 0); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + titles[COL_ALGO] = _("Size"); + titles[COL_KEYID] = _("Key ID"); + titles[COL_NAME] = _("Name"); + titles[COL_EMAIL] = _("Address"); + titles[COL_VALIDITY] = _("Val"); clist_store = gtk_list_store_new(N_COL_TITLES, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_POINTER); - - clist = gtk_tree_view_new_with_model( GTK_TREE_MODEL(clist_store) ); - gtk_container_add (GTK_CONTAINER (scrolledwin), clist); - gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(clist)), GTK_SELECTION_BROWSE); + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); + + clist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(clist_store)); + gtk_container_add(GTK_CONTAINER(scrolledwin), clist); + gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW + (clist)), GTK_SELECTION_BROWSE); renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes(titles[COL_ALGO], renderer, - "text", COL_ALGO, - NULL); + column = gtk_tree_view_column_new_with_attributes(titles[COL_ALGO], + renderer, "text", COL_ALGO, NULL); g_object_set(column, "min-width", 72, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(clist), column); renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes(titles[COL_KEYID], renderer, - "text", COL_KEYID, - NULL); + column = gtk_tree_view_column_new_with_attributes(titles[COL_KEYID], + renderer, "text", COL_KEYID, NULL); g_object_set(column, "min-width", 76, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(clist), column); renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes(titles[COL_NAME], renderer, - "text", COL_NAME, - NULL); + column = gtk_tree_view_column_new_with_attributes(titles[COL_NAME], + renderer, "text", COL_NAME, NULL); g_object_set(column, "min-width", 130, NULL); gtk_tree_view_column_set_sort_column_id(column, COL_NAME); gtk_tree_view_append_column(GTK_TREE_VIEW(clist), column); renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes(titles[COL_EMAIL], renderer, - "text", COL_EMAIL, - NULL); + column = gtk_tree_view_column_new_with_attributes(titles[COL_EMAIL], + renderer, "text", COL_EMAIL, NULL); g_object_set(column, "min-width", 130, NULL); gtk_tree_view_column_set_sort_column_id(column, COL_EMAIL); gtk_tree_view_append_column(GTK_TREE_VIEW(clist), column); renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes(titles[COL_VALIDITY], renderer, - "text", COL_VALIDITY, - NULL); + column = gtk_tree_view_column_new_with_attributes(titles[COL_VALIDITY], + renderer, "text", COL_VALIDITY, NULL); g_object_set(column, "min-width", 20, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(clist), column); gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(clist_store), - COL_NAME, cmp_name, sk, NULL); + COL_NAME, cmp_name, sk, NULL); gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(clist_store), - COL_EMAIL, cmp_email, sk, NULL); + COL_EMAIL, cmp_email, sk, NULL); g_signal_connect(clist, "destroy", G_CALLBACK(destroy_keys), NULL); - hbox = gtk_hbox_new (FALSE, 8); - gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + hbox = gtk_hbox_new(FALSE, 8); + gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + bbox = gtk_hbox_new(FALSE, 2); + select_btn = + gtkut_create_label_button(_("Select"), + G_CALLBACK(select_btn_cb), sk); + cancel_btn = + gtkut_create_label_button(_("Cancel"), + G_CALLBACK(cancel_btn_cb), sk); + other_btn = + gtkut_create_label_button(_("Other..."), + G_CALLBACK(other_btn_cb), sk); + vbox3 = gtk_vbox_new(FALSE, 2); + do_crypt_btn = + gtkut_check_button(vbox3, _("Enable encryption"), sk->do_crypt, + (GCallback) crypt_changed_cb, sk); + do_sign_btn = + gtkut_check_button(vbox3, _("Enable signing"), sk->do_sign, + (GCallback) sign_changed_cb, sk); + + gtk_box_pack_end(GTK_BOX(hbox), select_btn, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(hbox), other_btn, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(hbox), cancel_btn, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(hbox), vbox3, FALSE, FALSE, 0); - bbox = gtk_hbox_new (FALSE, 2); - select_btn = gtkut_create_label_button (_("Select"), G_CALLBACK (select_btn_cb), sk); - cancel_btn = gtkut_create_label_button (_("Cancel"), G_CALLBACK (cancel_btn_cb), sk); - other_btn = gtkut_create_label_button (_("Other..."), G_CALLBACK (other_btn_cb), sk); - vbox3 = gtk_vbox_new(FALSE,2); - do_crypt_btn = gtkut_check_button( vbox3, _("Enable encryption"), sk->do_crypt, - (GCallback) crypt_changed_cb, sk ); - do_sign_btn = gtkut_check_button( vbox3, _("Enable signing"), sk->do_sign, - (GCallback) sign_changed_cb, sk ); - - gtk_box_pack_end (GTK_BOX (hbox), select_btn, FALSE, FALSE, 0); - gtk_box_pack_end (GTK_BOX (hbox), other_btn, FALSE, FALSE, 0); - gtk_box_pack_end (GTK_BOX (hbox), cancel_btn, FALSE, FALSE, 0); - gtk_box_pack_end (GTK_BOX (hbox), vbox3, FALSE, FALSE, 0); - - gtk_box_pack_end (GTK_BOX (hbox), bbox, FALSE, FALSE, 0); - - vbox2 = gtk_vbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(hbox), bbox, FALSE, FALSE, 0); - gtk_widget_show_all (window); + vbox2 = gtk_vbox_new(FALSE, 4); + gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 0); + + gtk_widget_show_all(window); sk->window = window; - sk->toplabel = GTK_LABEL (label); - sk->clist = GTK_TREE_VIEW (clist); + sk->toplabel = GTK_LABEL(label); + sk->clist = GTK_TREE_VIEW(clist); } - -static void -open_dialog (struct select_keys_s *sk) +static void open_dialog(struct select_keys_s *sk) { if (!sk->window) - create_dialog (sk); + create_dialog(sk); sk->okay = 0; - sk->sort_column = N_COL_TITLES; /* use an invalid value */ + sk->sort_column = N_COL_TITLES; /* use an invalid value */ sk->sort_type = GTK_SORT_ASCENDING; - gtk_widget_show (sk->window); + gtk_widget_show(sk->window); } - -static void -close_dialog (struct select_keys_s *sk) +static void close_dialog(struct select_keys_s *sk) { - g_return_if_fail (sk); - gtk_widget_destroy (sk->window); + g_return_if_fail(sk); + gtk_widget_destroy(sk->window); sk->window = NULL; } - static gint -delete_event_cb (GtkWidget *widget, GdkEventAny *event, gpointer data) +delete_event_cb(GtkWidget *widget, GdkEventAny *event, gpointer data) { struct select_keys_s *sk = data; sk->okay = 0; - gtk_main_quit (); + gtk_main_quit(); return TRUE; } - -static void -key_pressed_cb (GtkWidget *widget, GdkEventKey *event, gpointer data) +static void key_pressed_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) { struct select_keys_s *sk = data; - g_return_if_fail (sk); + g_return_if_fail(sk); if (event && event->keyval == GDK_Escape) { sk->okay = 0; - gtk_main_quit (); + gtk_main_quit(); } } - -static void -select_btn_cb (GtkWidget *widget, gpointer data) +static void select_btn_cb(GtkWidget *widget, gpointer data) { struct select_keys_s *sk = (struct select_keys_s *)data; @@ -530,78 +510,72 @@ GtkTreeSelection *selection; GtkTreeModel *model; - g_return_if_fail (sk); + g_return_if_fail(sk); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sk->clist)); model = gtk_tree_view_get_model(GTK_TREE_VIEW(sk->clist)); - if(!gtk_tree_selection_get_selected(selection, NULL, &selected)) + if (!gtk_tree_selection_get_selected(selection, NULL, &selected)) return; - gtk_tree_model_get(model, &selected, - COL_GPG_KEY, &key, - -1); + gtk_tree_model_get(model, &selected, COL_GPG_KEY, &key, -1); if (key) { const char *s = key->subkeys->fpr; - if ( key->uids->validity < GPGME_VALIDITY_FULL ) { + if (key->uids->validity < GPGME_VALIDITY_FULL) { } - - sk->kset = g_realloc( sk->kset, sizeof(gpgme_key_t) * (sk->num_keys + 1) ); + + sk->kset = + g_realloc(sk->kset, + sizeof(gpgme_key_t) * (sk->num_keys + 1)); gpgme_key_ref(key); sk->kset[sk->num_keys] = key; sk->num_keys++; sk->okay = 1; sk->key = strdup(s); - gtk_main_quit (); + gtk_main_quit(); } } - -static void -cancel_btn_cb (GtkWidget *widget, gpointer data) +static void cancel_btn_cb(GtkWidget *widget, gpointer data) { struct select_keys_s *sk = data; - g_return_if_fail (sk); + g_return_if_fail(sk); sk->okay = 0; if (sk->select_ctx) - gpgme_cancel (sk->select_ctx); - gtk_main_quit (); + gpgme_cancel(sk->select_ctx); + gtk_main_quit(); } -static void -other_selected_cb(const char *text, void *data) +static void other_selected_cb(const char *text, void *data) { struct select_keys_s *sk = data; if (!text) return; - fill_clist (sk, text); - update_progress (sk, 0, sk->pattern); + fill_clist(sk, text); + update_progress(sk, 0, sk->pattern); } -static void -other_btn_cb (GtkWidget *widget, gpointer data) +static void other_btn_cb(GtkWidget *widget, gpointer data) { struct select_keys_s *sk = data; - g_return_if_fail (sk); - do_text_input_window( _("Enter another user or key ID:"), _(""), other_selected_cb, sk); + g_return_if_fail(sk); + do_text_input_window(_("Enter another user or key ID:"), _(""), + other_selected_cb, sk); } -static void -passphrase_ok_cb(GtkWidget *widget, gpointer data) +static void passphrase_ok_cb(GtkWidget *widget, gpointer data) { aycrypt_pass_ack = TRUE; gtk_main_quit(); } - -static void -passphrase_cancel_cb(GtkWidget *widget, gpointer data) +static void passphrase_cancel_cb(GtkWidget *widget, gpointer data) { aycrypt_pass_ack = FALSE; gtk_main_quit(); @@ -614,8 +588,7 @@ return TRUE; } - -static gboolean +static gboolean passphrase_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data) { if (event && event->keyval == GDK_Escape) { @@ -625,8 +598,7 @@ return FALSE; } -static GtkWidget * -create_description (const gchar *desc, int prev_was_bad) +static GtkWidget *create_description(const gchar *desc, int prev_was_bad) { const gchar *uid = NULL; gchar *buf; @@ -637,19 +609,18 @@ if (!uid) uid = _("[no user id]"); - buf = g_strdup_printf (_("%sPlease enter the passphrase for:\n\n" - " %.*s \n"), - prev_was_bad ? _("Bad passphrase! Try again...\n\n") : "", - (int)strlen (uid), uid); + buf = g_strdup_printf(_("%sPlease enter the passphrase for:\n\n" + " %.*s \n"), + prev_was_bad ? _("Bad passphrase! Try again...\n\n") : "", + (int)strlen(uid), uid); - label = gtk_label_new (buf); - g_free (buf); + label = gtk_label_new(buf); + g_free(buf); return label; } -const char* -passphrase_mbox (const char *desc, int prev_was_bad) +const char *passphrase_mbox(const char *desc, int prev_was_bad) { char *the_passphrase = NULL; GtkWidget *vbox; @@ -668,16 +639,18 @@ gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_window_set_modal(GTK_WINDOW(window), TRUE); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); - g_signal_connect(window, "delete-event", G_CALLBACK(passphrase_deleted), NULL); - g_signal_connect(window, "key-press-event", G_CALLBACK(passphrase_key_pressed), NULL); + g_signal_connect(window, "delete-event", G_CALLBACK(passphrase_deleted), + NULL); + g_signal_connect(window, "key-press-event", + G_CALLBACK(passphrase_key_pressed), NULL); vbox = gtk_vbox_new(FALSE, 8); gtk_container_add(GTK_CONTAINER(window), vbox); if (desc) { GtkWidget *label; - label = create_description (desc, prev_was_bad); - gtk_box_pack_start (GTK_BOX(vbox), label, TRUE, TRUE, 0); + label = create_description(desc, prev_was_bad); + gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); } table = gtk_table_new(2, 2, FALSE); @@ -686,46 +659,48 @@ gtk_table_set_row_spacings(GTK_TABLE(table), 12); gtk_table_set_col_spacings(GTK_TABLE(table), 8); - pass_label = gtk_label_new(""); - gtk_table_attach (GTK_TABLE(table), pass_label, 0, 1, 0, 1, - GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0); - gtk_misc_set_alignment (GTK_MISC (pass_label), 1, 0.5); + gtk_table_attach(GTK_TABLE(table), pass_label, 0, 1, 0, 1, + GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC(pass_label), 1, 0.5); pass_entry = gtk_entry_new(); - gtk_table_attach (GTK_TABLE(table), pass_entry, 1, 2, 0, 1, - GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); - gtk_entry_set_visibility (GTK_ENTRY(pass_entry), FALSE); - gtk_widget_grab_focus (pass_entry); - - - confirm_box = gtk_hbutton_box_new (); - gtk_button_box_set_layout (GTK_BUTTON_BOX(confirm_box), GTK_BUTTONBOX_END); + gtk_table_attach(GTK_TABLE(table), pass_entry, 1, 2, 0, 1, + GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0, 0); + gtk_entry_set_visibility(GTK_ENTRY(pass_entry), FALSE); + gtk_widget_grab_focus(pass_entry); + + confirm_box = gtk_hbutton_box_new(); + gtk_button_box_set_layout(GTK_BUTTON_BOX(confirm_box), + GTK_BUTTONBOX_END); - ok_button = gtk_button_new_with_label (_("OK")); - gtk_box_pack_start (GTK_BOX(confirm_box), ok_button, TRUE, TRUE, 0); + ok_button = gtk_button_new_with_label(_("OK")); + gtk_box_pack_start(GTK_BOX(confirm_box), ok_button, TRUE, TRUE, 0); - cancel_button = gtk_button_new_with_label (_("Cancel")); + cancel_button = gtk_button_new_with_label(_("Cancel")); gtk_box_pack_start(GTK_BOX(confirm_box), cancel_button, TRUE, TRUE, 0); gtk_box_pack_end(GTK_BOX(vbox), confirm_box, FALSE, FALSE, 0); - g_signal_connect(ok_button, "clicked", G_CALLBACK(passphrase_ok_cb), NULL); - g_signal_connect(pass_entry, "activate", G_CALLBACK(passphrase_ok_cb), NULL); - g_signal_connect(cancel_button, "clicked", G_CALLBACK(passphrase_cancel_cb), NULL); - - gtk_window_set_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_window_set_resizable (GTK_WINDOW(window), FALSE); - + g_signal_connect(ok_button, "clicked", G_CALLBACK(passphrase_ok_cb), + NULL); + g_signal_connect(pass_entry, "activate", G_CALLBACK(passphrase_ok_cb), + NULL); + g_signal_connect(cancel_button, "clicked", + G_CALLBACK(passphrase_cancel_cb), NULL); + + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + gtk_widget_show_all(window); gtk_main(); if (aycrypt_pass_ack) { - the_passphrase = gtk_editable_get_chars(GTK_EDITABLE(pass_entry), 0, -1); + the_passphrase = + gtk_editable_get_chars(GTK_EDITABLE(pass_entry), 0, -1); } - gtk_widget_destroy (window); + gtk_widget_destroy(window); return the_passphrase; } - Index: select-keys.h =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/aycryption/select-keys.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- select-keys.h 3 Aug 2007 20:38:38 -0000 1.3 +++ select-keys.h 17 Sep 2009 12:04:58 -0000 1.4 @@ -23,25 +23,26 @@ #include <gpgme.h> struct select_keys_s { - int okay; - void *window; - void *toplabel; - void *clist; - const char *pattern; - gpgme_key_t *kset; - unsigned int num_keys; - gpgme_ctx_t select_ctx; - char *key; - int sort_type; - int sort_column; - int do_crypt; - int do_sign; + int okay; + void *window; + void *toplabel; + void *clist; + const char *pattern; + gpgme_key_t *kset; + unsigned int num_keys; + gpgme_ctx_t select_ctx; + char *key; + int sort_type; + int sort_column; + int do_crypt; + int do_sign; }; extern char *aycrypt_last_pass; extern int aycrypt_pass_ack; -struct select_keys_s gpgmegtk_recipient_selection (GSList *recp_names, int crypt, int sign); -const char *passphrase_mbox (const char *desc, int prev_was_bad); +struct select_keys_s gpgmegtk_recipient_selection(GSList *recp_names, int crypt, + int sign); +const char *passphrase_mbox(const char *desc, int prev_was_bad); -#endif /* GPGMEGTK_SELECT_KEYS_H */ +#endif /* GPGMEGTK_SELECT_KEYS_H */ |