Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sun, 08 Jul 2012 14:22:55 Commit: 90bcb9d11071df446c04f1699165a50d59c8ccb1 https://github.com/geany/geany-plugins/commit/90bcb9d11071df446c04f1699165a5...
Log Message: ----------- Merge branch 'fixes/geanypg'
Modified Paths: -------------- geanypg/src/decrypt_cb.c geanypg/src/encrypt_cb.c geanypg/src/geanypg.c geanypg/src/geanypg.h geanypg/src/helper_functions.c geanypg/src/key_selection_dialog.c geanypg/src/pinentry.c geanypg/src/sign_cb.c geanypg/src/verify_aux.c geanypg/src/verify_cb.c
Modified: geanypg/src/decrypt_cb.c 48 files changed, 25 insertions(+), 23 deletions(-) =================================================================== @@ -1,26 +1,27 @@ -// decrypt_cb.c -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. +/* decrypt_cb.c + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */
#include "geanypg.h"
-void geanypg_decrypt_verify(encrypt_data * ed) +static void geanypg_decrypt_verify(encrypt_data * ed) { gpgme_data_t plain, cipher; gpgme_error_t err; @@ -37,9 +38,9 @@ void geanypg_decrypt_verify(encrypt_data * ed) geanypg_load_buffer(&cipher);
err = gpgme_op_decrypt_verify(ed->ctx, cipher, plain); - if (gpgme_err_code(err) == GPG_ERR_NO_DATA) // no encription, but maybe signatures + if (gpgme_err_code(err) == GPG_ERR_NO_DATA) /* no encription, but maybe signatures */ { - // maybe reaload cipher + /* maybe reaload cipher */ gpgme_data_release(cipher); geanypg_load_buffer(&cipher); rewind(tempfile); @@ -55,7 +56,7 @@ void geanypg_decrypt_verify(encrypt_data * ed) }
fclose(tempfile); - // release buffers + /* release buffers */ gpgme_data_release(cipher); gpgme_data_release(plain); } @@ -63,8 +64,9 @@ void geanypg_decrypt_verify(encrypt_data * ed) void geanypg_decrypt_cb(GtkMenuItem * menuitem, gpointer user_data) { encrypt_data ed; + gpgme_error_t err; geanypg_init_ed(&ed); - gpgme_error_t err = gpgme_new(&ed.ctx); + err = gpgme_new(&ed.ctx); if (err && geanypg_show_err_msg(err)) return; gpgme_set_protocol(ed.ctx, GPGME_PROTOCOL_OpenPGP);
Modified: geanypg/src/encrypt_cb.c 48 files changed, 25 insertions(+), 23 deletions(-) =================================================================== @@ -1,27 +1,28 @@ -// encrypt_cb.c -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. +/* encrypt_cb.c + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */
#include "geanypg.h"
-void geanypg_encrypt(encrypt_data * ed, gpgme_key_t * recp, int sign, int flags) -{ // FACTORIZE +static void geanypg_encrypt(encrypt_data * ed, gpgme_key_t * recp, int sign, int flags) +{ /* FACTORIZE */ gpgme_data_t plain, cipher; gpgme_error_t err; FILE * tempfile; @@ -36,7 +37,7 @@ void geanypg_encrypt(encrypt_data * ed, gpgme_key_t * recp, int sign, int flags)
geanypg_load_buffer(&plain);
- // do the actual encryption + /* do the actual encryption */ if (sign) err = gpgme_op_encrypt_sign(ed->ctx, recp, flags, plain, cipher); else @@ -50,7 +51,7 @@ void geanypg_encrypt(encrypt_data * ed, gpgme_key_t * recp, int sign, int flags) }
fclose(tempfile); - // release buffers + /* release buffers */ gpgme_data_release(plain); gpgme_data_release(cipher); } @@ -59,8 +60,9 @@ void geanypg_encrypt_cb(GtkMenuItem * menuitem, gpointer user_data) { int sign; encrypt_data ed; + gpgme_error_t err; geanypg_init_ed(&ed); - gpgme_error_t err = gpgme_new(&ed.ctx); + err = gpgme_new(&ed.ctx); if (err && geanypg_show_err_msg(err)) return; gpgme_set_armor(ed.ctx, 1);
Modified: geanypg/src/geanypg.c 66 files changed, 37 insertions(+), 29 deletions(-) =================================================================== @@ -1,21 +1,22 @@ -// geanypg.c -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. +/* geanypg.c + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */
#include "geanypg.h"
@@ -41,12 +42,12 @@
static gpgme_error_t geanypg_init_gpgme(void) { - // Initialize the locale environment. + /* Initialize the locale environment. */ setlocale(LC_ALL, ""); fprintf(stderr, "GeanyPG: %s %s\n", _("Using libgpgme version:"), gpgme_check_version("1.1.0")); gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL)); -#ifdef LC_MESSAGES // only necessary for portability to W32 systems +#ifdef LC_MESSAGES /* only necessary for portability to W32 systems */ gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL)); #endif return gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); @@ -63,22 +64,29 @@ gpgme_error_t geanypg_show_err_msg(gpgme_error_t err)
void plugin_init(GeanyData *data) { + GtkWidget * submenu; + GtkWidget * encrypt; + GtkWidget * sign; + GtkWidget * decrypt; + GtkWidget * verify; + gpgme_error_t err = geanypg_init_gpgme(); if (err) { geanypg_show_err_msg(err); return; } - // Create a new menu item and show it + /* Create a new menu item and show it */ main_menu_item = gtk_menu_item_new_with_mnemonic("GeanyPG"); gtk_widget_show(main_menu_item); + ui_add_document_sensitive(main_menu_item);
- GtkWidget * submenu = gtk_menu_new(); + submenu = gtk_menu_new(); gtk_widget_show(submenu); - GtkWidget * encrypt = gtk_menu_item_new_with_mnemonic(_("Encrypt")); - GtkWidget * sign = gtk_menu_item_new_with_mnemonic(_("Sign")); - GtkWidget * decrypt = gtk_menu_item_new_with_mnemonic(_("Decrypt / Verify")); - GtkWidget * verify = gtk_menu_item_new_with_mnemonic(_("Verify detached signature")); + encrypt = gtk_menu_item_new_with_mnemonic(_("Encrypt")); + sign = gtk_menu_item_new_with_mnemonic(_("Sign")); + decrypt = gtk_menu_item_new_with_mnemonic(_("Decrypt / Verify")); + verify = gtk_menu_item_new_with_mnemonic(_("Verify detached signature"));
gtk_widget_show(encrypt); gtk_widget_show(sign); @@ -92,12 +100,12 @@ void plugin_init(GeanyData *data)
gtk_menu_item_set_submenu(GTK_MENU_ITEM(main_menu_item), submenu);
- // Attach the new menu item to the Tools menu + /* Attach the new menu item to the Tools menu */ gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), main_menu_item);
- // Connect the menu item with a callback function - // which is called when the item is clicked + /* Connect the menu item with a callback function + * which is called when the item is clicked */ g_signal_connect(encrypt, "activate", G_CALLBACK(geanypg_encrypt_cb), NULL); g_signal_connect(sign, "activate", G_CALLBACK(geanypg_sign_cb), NULL); g_signal_connect(decrypt, "activate", G_CALLBACK(geanypg_decrypt_cb), NULL);
Modified: geanypg/src/geanypg.h 47 files changed, 24 insertions(+), 23 deletions(-) =================================================================== @@ -1,21 +1,22 @@ -// geanypg.h -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. +/* geanypg.h + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */
#include <stdio.h> @@ -53,7 +54,7 @@ enum extern GeanyData *geany_data; extern GeanyFunctions *geany_functions;
-// auxiliary functions (helper_functions.c) +/* auxiliary functions (helper_functions.c) */ void geanypg_init_ed(encrypt_data * ed); int geanypg_get_keys(encrypt_data * ed); int geanypg_get_secret_keys(encrypt_data * ed); @@ -61,23 +62,23 @@ enum void geanypg_load_buffer(gpgme_data_t * buffer); void geanypg_write_file(FILE * file);
-// some more auxiliary functions (verify_aux.c) +/* some more auxiliary functions (verify_aux.c) */ void geanypg_handle_signatures(encrypt_data * ed, int need_error); void geanypg_check_sig(encrypt_data * ed, gpgme_signature_t sig); const char * geanypg_validity(gpgme_validity_t validity);
-// dialogs +/* dialogs */ int geanypg_encrypt_selection_dialog(encrypt_data * ed, gpgme_key_t ** selected, int * sign); int geanypg_sign_selection_dialog(encrypt_data * ed); gpgme_error_t geanypg_show_err_msg(gpgme_error_t err);
-// callback functions +/* callback functions */ void geanypg_encrypt_cb(GtkMenuItem * menuitem, gpointer user_data); void geanypg_sign_cb(GtkMenuItem * menuitem, gpointer user_data); void geanypg_decrypt_cb(GtkMenuItem * menuitem, gpointer user_data); void geanypg_verify_cb(GtkMenuItem * menuitem, gpointer user_data);
-// pinentry callback +/* pinentry callback */ gpgme_error_t geanypg_passphrase_cb(void *hook, const char *uid_hint, const char *passphrase_info,
Modified: geanypg/src/helper_functions.c 85 files changed, 44 insertions(+), 41 deletions(-) =================================================================== @@ -1,21 +1,22 @@ -// helper_functions.c -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. +/* helper_functions.c + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */
#include "geanypg.h" @@ -32,9 +33,9 @@ int geanypg_get_keys(encrypt_data * ed) { gpgme_error_t err; unsigned long size = SIZE; - //initialize idx to 0 + /* initialize idx to 0 */ unsigned long idx = 0; - //allocate array of size 1N + /* allocate array of size 1N */ gpgme_key_t * key; ed->key_array = (gpgme_key_t*) malloc(SIZE * sizeof(gpgme_key_t)); err = gpgme_op_keylist_start(ed->ctx, NULL, 0); @@ -44,12 +45,12 @@ int geanypg_get_keys(encrypt_data * ed) err = gpgme_op_keylist_next(ed->ctx, key); if (err) break; - if ((*key)->revoked || // key cannot be used + if ((*key)->revoked || /* key cannot be used */ (*key)->expired || (*key)->disabled || (*key)->invalid) gpgme_key_unref(*key); - else // key is valid + else /* key is valid */ ++idx; if (idx >= size) { @@ -70,9 +71,9 @@ int geanypg_get_secret_keys(encrypt_data * ed) { gpgme_error_t err; unsigned long size = SIZE; - //initialize idx to 0 + /* initialize idx to 0 */ unsigned long idx = 0; - //allocate array of size 1N + /* allocate array of size 1N */ gpgme_key_t * key; ed->skey_array = (gpgme_key_t*) malloc(SIZE * sizeof(gpgme_key_t)); err = gpgme_op_keylist_start(ed->ctx, NULL, 1); @@ -82,12 +83,12 @@ int geanypg_get_secret_keys(encrypt_data * ed) err = gpgme_op_keylist_next(ed->ctx, key); if (err) break; - if ((*key)->revoked || // key cannot be used + if ((*key)->revoked || /* key cannot be used */ (*key)->expired || (*key)->disabled || (*key)->invalid) gpgme_key_unref(*key); - else // key is valid + else /* key is valid */ ++idx; if (idx >= size) { @@ -130,14 +131,11 @@ void geanypg_release_keys(encrypt_data * ed)
void geanypg_load_buffer(gpgme_data_t * buffer) { - //gpgme_data_new_from_mem(buffer, text, size, 0); + /* gpgme_data_new_from_mem(buffer, text, size, 0); */ GeanyDocument * doc = document_get_current(); - //SCI_GETSELECTIONSTART-SCI_GETSELECTIONEND char * data = NULL; - unsigned long sstart = scintilla_send_message(doc->editor->sci, SCI_GETSELECTIONSTART, 0, 0); - unsigned long send = scintilla_send_message(doc->editor->sci, SCI_GETSELECTIONEND, 0, 0); unsigned long size = 0; - if (sstart - send) + if (sci_has_selection(doc->editor->sci)) { size = scintilla_send_message(doc->editor->sci, SCI_GETSELTEXT, 0, 0); data = (char *) malloc(size + 1); @@ -151,29 +149,34 @@ void geanypg_load_buffer(gpgme_data_t * buffer) scintilla_send_message(doc->editor->sci, SCI_GETTEXT, (uptr_t)(size + 1), (sptr_t)data); gpgme_data_new_from_mem(buffer, data, size, 1); } - if (data) // if there is no text data may still be NULL + if (data) /* if there is no text data may still be NULL */ free(data); gpgme_data_set_encoding(*buffer, GPGME_DATA_ENCODING_BINARY); }
void geanypg_write_file(FILE * file) { - unsigned bufsize = 2048; +#define BUFSIZE 2048 + unsigned long size; - char buffer[bufsize]; + char buffer[BUFSIZE] = {0}; GeanyDocument * doc = document_get_current(); - if (abs(sci_get_selection_start(doc->editor->sci) - sci_get_selection_end(doc->editor->sci))) - { // replace selected text - // clear selection, cursor should be at the end or beginneng of the selection + sci_start_undo_action(doc->editor->sci); + if (sci_has_selection(doc->editor->sci)) + { /* replace selected text + * clear selection, cursor should be at the end or beginneng of the selection */ scintilla_send_message(doc->editor->sci, SCI_REPLACESEL, 0, (sptr_t)""); - while ((size = fread(buffer, 1, bufsize, file))) - // add at the cursor + while ((size = fread(buffer, 1, BUFSIZE, file))) + /* add at the cursor */ scintilla_send_message(doc->editor->sci, SCI_ADDTEXT, (uptr_t) size, (sptr_t) buffer); } else - { //replace complete document + { /* replace complete document */ scintilla_send_message(doc->editor->sci, SCI_CLEARALL, 0, 0); - while ((size = fread(buffer, 1, bufsize, file))) + while ((size = fread(buffer, 1, BUFSIZE, file))) scintilla_send_message(doc->editor->sci, SCI_APPENDTEXT, (uptr_t) size, (sptr_t) buffer); } + sci_end_undo_action(doc->editor->sci); + +#undef BUFSIZE }
Modified: geanypg/src/key_selection_dialog.c 72 files changed, 37 insertions(+), 35 deletions(-) =================================================================== @@ -1,23 +1,24 @@ -// key_selection_dialog.c -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. - -// something about premature optimization, it still needs to be done +/* key_selection_dialog.c + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +/* something about premature optimization, it still needs to be done */
#include "geanypg.h"
@@ -69,14 +70,14 @@ static GtkListStore * geanypg_makelist(gpgme_key_t * key_array, unsigned long nk { char * name = (key_array[idx]->uids && key_array[idx]->uids->name) ? key_array[idx]->uids->name : &empty_string; char * email = (key_array[idx]->uids && key_array[idx]->uids->email) ? key_array[idx]->uids->email : &empty_string; - char buffer[strlen(name) + strlen(email) + 7]; - sprintf(buffer, "%s <%s>", name, email); + gchar * buffer = g_strdup_printf("%s <%s>", name, email); gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, TOGGLE_COLUMN, FALSE, RECIPIENT_COLUMN, buffer, KEYID_COLUMN, key_array[idx]->subkeys->keyid, -1); + g_free(buffer); } return list; } @@ -96,7 +97,7 @@ static GtkWidget * geanypg_listview(GtkListStore * list, listdata * data) GtkTreeViewColumn * column; GtkCellRenderer * togglerenderer, * textrenderer; GtkWidget * listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list)); - // checkbox column + /* checkbox column */ togglerenderer = gtk_cell_renderer_toggle_new(); g_signal_connect(G_OBJECT(togglerenderer), "toggled", G_CALLBACK(geanypg_toggled_cb), NULL); column = gtk_tree_view_column_new_with_attributes("?", @@ -107,7 +108,7 @@ static GtkWidget * geanypg_listview(GtkListStore * list, listdata * data) data->store = list; data->column = TOGGLE_COLUMN; g_signal_connect(G_OBJECT(togglerenderer), "toggled", G_CALLBACK(geanypg_toggled_cb), (gpointer) data); - // recipient column + /* recipient column */ textrenderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("recipient", textrenderer, @@ -115,7 +116,7 @@ static GtkWidget * geanypg_listview(GtkListStore * list, listdata * data) NULL); gtk_tree_view_column_set_resizable(column, TRUE); gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); - // keyid column + /* keyid column */ column = gtk_tree_view_column_new_with_attributes("keyid", textrenderer, "text", KEYID_COLUMN, @@ -134,10 +135,11 @@ int geanypg_encrypt_selection_dialog(encrypt_data * ed, gpgme_key_t ** selected, GtkTreeIter iter; listdata data; gboolean active; + GtkListStore * list;
*sign = 0;
- GtkListStore * list = geanypg_makelist(ed->key_array, ed->nkeys, 0); + list = geanypg_makelist(ed->key_array, ed->nkeys, 0); listview = geanypg_listview(list, &data); scrollwin = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollwin), @@ -153,13 +155,13 @@ int geanypg_encrypt_selection_dialog(encrypt_data * ed, gpgme_key_t ** selected, gtk_box_pack_start(GTK_BOX(contentarea), combobox, FALSE, FALSE, 0);
- // add ok and cancel buttons + /* add ok and cancel buttons */ gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_OK); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
gtk_window_set_title(GTK_WINDOW(dialog), _("Select recipients")); gtk_widget_show_all(dialog); - // make sure dialog is destroyed when user responds + /* make sure dialog is destroyed when user responds */ response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_CANCEL) { @@ -170,12 +172,12 @@ int geanypg_encrypt_selection_dialog(encrypt_data * ed, gpgme_key_t ** selected, if (idx && idx <= ed->nskeys) { *sign = 1; - gpgme_signers_add(ed->ctx, ed->skey_array[idx - 1]); // -1 because the first option is `None' + gpgme_signers_add(ed->ctx, ed->skey_array[idx - 1]); /* -1 because the first option is `None' */ } - // try to loop all the keys in the list - // if they are active (the user checked the checkbox in front of the key) - // add it to the selected array, finaly make sure that the array - // is NULL terminated + /* try to loop all the keys in the list + * if they are active (the user checked the checkbox in front of the key) + * add it to the selected array, finaly make sure that the array + * is NULL terminated */ if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list), &iter)) { capacity = SIZE; @@ -222,13 +224,13 @@ int geanypg_sign_selection_dialog(encrypt_data * ed) gtk_box_pack_start(GTK_BOX(contentarea), gtk_label_new(_("Choose a key to sign with:")), FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(contentarea), combobox, TRUE, TRUE, 0);
- // add ok and cancel buttons + /* add ok and cancel buttons */ gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_OK); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
gtk_widget_show_all(dialog); gtk_window_set_title(GTK_WINDOW(dialog), _("Select signer")); - // make sure dialog is destroyed when user responds + /* make sure dialog is destroyed when user responds */ response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_CANCEL) {
Modified: geanypg/src/pinentry.c 68 files changed, 36 insertions(+), 32 deletions(-) =================================================================== @@ -1,21 +1,22 @@ -// pinentry.c -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. +/* pinentry.c + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */
#include "geanypg.h"
@@ -44,17 +45,18 @@ static void geanypg_read_till(int fd, char delim) while (1) { char val; - unsigned long rv = read(fd, &val, 1); - if (!rv || val == delim) + ssize_t rv = read(fd, &val, 1); + if (rv <= 0 || val == delim) break; } }
static int geanypg_read(int fd, char delim, int max, char * buffer) { - int idx, rv = 1; + int idx; + ssize_t rv = 1; char ch = 0; - for (idx = 0; (idx < max - 1) && rv && ch != delim; ++idx) + for (idx = 0; (idx < max - 1) && rv > 0 && ch != delim; ++idx) { rv = read(fd, &ch, 1); buffer[idx] = ch; @@ -72,7 +74,7 @@ gpgme_error_t geanypg_passphrase_cb(void * hook, int inpipe[2]; int childpid; int status; - char readbuffer[2080]; // pinentry should at least support passphrases of up to 2048 characters + char readbuffer[2080] = {0}; /* pinentry should at least support passphrases of up to 2048 characters */ FILE * childin;
if (pipe(outpipe)) @@ -88,9 +90,11 @@ gpgme_error_t geanypg_passphrase_cb(void * hook,
childpid = fork(); if (!childpid) - { // pinentry + { /* pinentry */ char arg1[] = "pinentry"; - char * argv[] = {arg1, NULL}; + char * argv[] = {NULL, NULL}; + + argv[0] = arg1;
close(outpipe[READ]); dup2(outpipe[WRITE], STDOUT_FILENO); @@ -99,16 +103,16 @@ gpgme_error_t geanypg_passphrase_cb(void * hook, dup2(inpipe[READ], STDIN_FILENO);
execvp(*argv, argv); - // shouldn't get here + /* shouldn't get here */ fprintf(stderr, "GeanyPG: %s\n%s\n", _("Could not use pinentry."), strerror(errno)); - exit(1); // kill the child + exit(1); /* kill the child */ } - // GeanpyPG + /* GeanpyPG */ close(outpipe[WRITE]); close(inpipe[READ]); childin = fdopen(inpipe[WRITE], "w");
- // To understand what's happening here, read the pinentry documentation + /* To understand what's happening here, read the pinentry documentation */ geanypg_read(outpipe[READ], ' ', 2049, readbuffer); if (strncmp(readbuffer, "OK", 3)) { @@ -119,7 +123,7 @@ gpgme_error_t geanypg_passphrase_cb(void * hook, close(fd); return gpgme_err_make(GPG_ERR_SOURCE_PINENTRY, GPG_ERR_GENERAL); } - geanypg_read_till(outpipe[READ], '\n'); // read the rest of the first line after OK + geanypg_read_till(outpipe[READ], '\n'); /* read the rest of the first line after OK */ fprintf(childin, "SETTITLE GeanyPG %s\n", _("Passphrase entry")); fflush(childin); geanypg_read_till(outpipe[READ], '\n'); @@ -143,8 +147,8 @@ gpgme_error_t geanypg_passphrase_cb(void * hook, while (1) { char val; - register unsigned long rv = read(outpipe[READ], &val, 1); - if (!rv || val == '\n') + register ssize_t rv = read(outpipe[READ], &val, 1); + if (rv <= 0 || val == '\n') { while (!write(fd, "\n", 1)); break;
Modified: geanypg/src/sign_cb.c 46 files changed, 24 insertions(+), 22 deletions(-) =================================================================== @@ -1,26 +1,27 @@ -// sign_cb.c -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. +/* sign_cb.c + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */
#include "geanypg.h"
-void geanypg_sign(encrypt_data * ed) +static void geanypg_sign(encrypt_data * ed) { gpgme_data_t plain, cipher; gpgme_error_t err; @@ -47,7 +48,7 @@ void geanypg_sign(encrypt_data * ed) }
fclose(tempfile); - // release buffers + /* release buffers */ gpgme_data_release(plain); gpgme_data_release(cipher); } @@ -55,13 +56,14 @@ void geanypg_sign(encrypt_data * ed) void geanypg_sign_cb(GtkMenuItem * menuitem, gpointer user_data) { encrypt_data ed; + gpgme_error_t err; geanypg_init_ed(&ed); - gpgme_error_t err = gpgme_new(&ed.ctx); + err = gpgme_new(&ed.ctx); if (err && geanypg_show_err_msg(err)) return; ed.key_array = NULL; ed.nkeys = 0; - //gpgme_set_armor(ed.ctx, 1); + /*gpgme_set_armor(ed.ctx, 1);*/ gpgme_set_passphrase_cb(ed.ctx, geanypg_passphrase_cb, NULL); if (geanypg_get_secret_keys(&ed)) {
Modified: geanypg/src/verify_aux.c 56 files changed, 29 insertions(+), 27 deletions(-) =================================================================== @@ -1,27 +1,28 @@ -// verify_aux.c -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. +/* verify_aux.c + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */
#include "geanypg.h"
-void geanypg_get_keys_with_fp(encrypt_data * ed, char * buffer) +static void geanypg_get_keys_with_fp(encrypt_data * ed, char * buffer) { unsigned long idx, found = 0; char empty_string = '\0'; @@ -47,7 +48,7 @@ void geanypg_get_keys_with_fp(encrypt_data * ed, char * buffer) sprintf(buffer, "%s <%s>", name, email); else { - char tmp[62]; + char tmp[62] = {0}; strncpy(tmp, buffer, 41); sprintf(buffer, "%s %s", _("a key with fingerprint"), tmp); } @@ -74,7 +75,7 @@ const char * geanypg_validity(gpgme_validity_t validity) }
static char * geanypg_summary(gpgme_sigsum_t summary, char * buffer) -{ // buffer should be more than 105 bytes long +{ /* buffer should be more than 105 bytes long */ if (summary & GPGME_SIGSUM_VALID) strcat(buffer, _(" valid")); if (summary & GPGME_SIGSUM_GREEN) strcat(buffer, _(" green")); if (summary & GPGME_SIGSUM_RED) strcat(buffer, _(" red")); @@ -106,11 +107,11 @@ static char * geanypg_result(gpgme_signature_t sig) "other flags:%s%s\n" "notations .: %s\n"); char * buffer; - char summary[128]; + char summary[128] = {0}; const char * pubkey = gpgme_pubkey_algo_name(sig->pubkey_algo); const char * hash = gpgme_hash_algo_name(sig->hash_algo); - char created[64]; - char expires[64]; + char created[64] = {0}; + char expires[64] = {0}; size_t buffer_size; if (sig->timestamp) strncpy(created, ctime((time_t*)&sig->timestamp), 64); @@ -136,7 +137,7 @@ static char * geanypg_result(gpgme_signature_t sig) strlen(sig->pka_trust == 0 ? _("n/a") : sig->pka_trust == 1 ? _("bad") : sig->pka_trust == 2 ? _("okay"): _("RFU")) + strlen(sig->wrong_key_usage ? _(" wrong-key-usage") : "") + strlen(sig->chain_model ? _(" chain-model") : "") + - strlen(sig->notations ? _("yes") : _("no")) + 1; // and a trailing \0 + strlen(sig->notations ? _("yes") : _("no")) + 1; /* and a trailing \0 */
buffer = (char *)calloc(buffer_size, 1); memset(summary, 0, 128); @@ -160,12 +161,13 @@ void geanypg_check_sig(encrypt_data * ed, gpgme_signature_t sig) { GtkWidget * dialog; gpgme_sigsum_t summary; - char buffer[512]; + char buffer[512] = {0}; + char * result; strncpy(buffer, sig->fpr, 40); buffer[40] = 0; geanypg_get_keys_with_fp(ed, buffer); summary = sig->summary; - char * result = geanypg_result(sig); + result = geanypg_result(sig);
dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(geany->main_widgets->window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
Modified: geanypg/src/verify_cb.c 44 files changed, 23 insertions(+), 21 deletions(-) =================================================================== @@ -1,25 +1,26 @@ -// verify_cb.c -// -// Copyright 2011 Hans Alves alves.h88@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA. +/* verify_cb.c + * + * Copyright 2011 Hans Alves alves.h88@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */
#include "geanypg.h"
-char * geanypg_choose_sig() +static char * geanypg_choose_sig(void) { int response; char * file = NULL; @@ -37,7 +38,7 @@ char * geanypg_choose_sig() return file; }
-void geanypg_verify(encrypt_data * ed, char * signame) +static void geanypg_verify(encrypt_data * ed, char * signame) { gpgme_data_t sig, text; gpgme_error_t err; @@ -61,8 +62,9 @@ void geanypg_verify_cb(GtkMenuItem * menuitem, gpointer user_data) { char * sigfile = NULL; encrypt_data ed; + gpgme_error_t err; geanypg_init_ed(&ed); - gpgme_error_t err = gpgme_new(&ed.ctx); + err = gpgme_new(&ed.ctx); if (err && geanypg_show_err_msg(err)) return; gpgme_set_protocol(ed.ctx, GPGME_PROTOCOL_OpenPGP);
@@ Diff output truncated at 100000 characters. @@
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: TBD).
plugins-commits@lists.geany.org