[Gpa-commits] r901 - in trunk: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Jul 15 22:44:09 CEST 2008


Author: marcus
Date: 2008-07-15 22:44:07 +0200 (Tue, 15 Jul 2008)
New Revision: 901

Modified:
   trunk/TODO
   trunk/src/ChangeLog
   trunk/src/encryptdlg.c
   trunk/src/encryptdlg.h
   trunk/src/fileman.c
   trunk/src/gpafiledecryptop.c
   trunk/src/gpafiledecryptop.h
   trunk/src/gpafileencryptop.c
   trunk/src/gpafileencryptop.h
   trunk/src/gpafileverifyop.c
   trunk/src/server.c
Log:
2008-07-15  Marcus Brinkmann  <marcus at g10code.de>

        * server.c: Include "gpafileop.h", "gpafileencryptop.h",
        "gpafilesignop.h", "gpafiledecryptop.h" and "gpafileverifyop.h".
        (struct conn_ctrl_s): New member FILES and FILES_FINISHED.
        (free_file_item, release_files, hextobyte, decode_percent_string)
        (cmd_file, impl_encrypt_sign_files, cmd_encrypt_files)
        (cmd_sign_files, cmd_encrypt_sign_files)
        (impl_decrypt_verify_files, cmd_decrypt_files, cmd_verify_files)
        (cmd_decrypt_verify_files, cmd_import_files)
        (cmd_checksum_create_files, cmd_checksum_verify_files): New static
        functions.
        (register_commands): Add commands FILE, ENCRYPT_FILES, SIGN_FILES<
        ENCRYPT_SIGN_FILES, DECRYPT_FILES, VERIFY_FILES,
        DECRYPT_VERIFY_FILES, IMPORT_FILES, CHECKSUM_CREATE_FILES,
        CHECKSUM_VERIFY_FILES.
        * fileman.c (file_decrypt): Use
        gpa_file_decrypt_verify_operation_new instead of
        gpa_file_decrypt_operation_new.
        * encrpytdlg.h (gpa_file_encrypt_dialog_sign): Rename prototype to ...
        (gpa_file_encrypt_dialog_get_sign): ... this.
        (gpa_file_encrypt_dialog_set_armor)
        (gpa_file_encrypt_dialog_set_sign): New prototypes.
        * encryptdlg.c: New properties PROP_ARMOR, PROP_SIGN.
        (gpa_file_encrypt_dialog_get_property)
        (gpa_file_encrypt_dialog_set_property): Handle these.
        (gpa_file_encrypt_dialog_class_init): Install these.
        (gpa_file_encrypt_dialog_sign): Rename function to ...
        (gpa_file_encrypt_dialog_get_sign): ... this.
        (gpa_file_encrypt_dialog_set_armor)
        (gpa_file_encrypt_dialog_set_sign): New functions.
        * gpafileencryptop.h (gpa_file_encrypt_sign_operation_new): New
        prototype.
        * gpafileencryptop.c (gpa_file_encrypt_sign_operation_new): New
        interface.
        * gpafiledecryptop.h (struct _GpaFileDecryptOperation): New
        members VERIFY, ERR, SIGNED_FILES, and DIALOG.
        (gpa_file_decrypt_verify_operation_new): New prototype.
        * gpafiledecryptop.c: Include "verifydlg.h".  New property
        PROP_VERIFY.
        (gpa_file_decrypt_operation_get_property)
        (gpa_file_decrypt_operation_set_property)
        (gpa_file_decrypt_operation_response_cb): New static functions.
        (gpa_file_decrypt_operation_finalize): Destroy OP->dialog.
        (gpa_file_decrypt_operation_constructor): Create verify dialog.
        (gpa_file_decrypt_operation_class_init): Set property hooks and
        install PROP_VERIFY property.
        (gpa_file_decrypt_verify_operation_new): New interface.
        (gpa_file_decrypt_operation_start): Use
        gpgme_op_decrypt_verify_start instead of gpgme_op_decrypt_start.
        (gpa_file_decrypt_operation_next): When completed and in verify
        mode, pop up the verification status dialog.
        (gpa_file_decrypt_operation_done_cb): Gather verification status
        summary if needed.



Modified: trunk/TODO
===================================================================
--- trunk/TODO	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/TODO	2008-07-15 20:44:07 UTC (rev 901)
@@ -17,6 +17,10 @@
    checked.
 
 * The file decrypt operation should also show signatures, if available.
+** Problem: If we do a file-based operation and the file list contains
+   mixed files like detached signatures and inline decrypted files,
+   should a Decrypt/Verify operation should do its best to do the
+   right thing for each file?
 
 * Add more options to the "Edit key" dialog.
 ** Manage UID's.
@@ -91,3 +95,7 @@
    -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -DPANGO_DISABLE_DEPRECATED
    -DGDK_MULTIHEAD_SAFE -DGTK_MULTIHEAD_SAFE
    This is mostly done, except for multi-head safeness and gtk marshalling.
+** multi-file operations and errors
+   When doing multi-file verify/decrypt, we may ignore more errors as
+   to make more progress.  This seems more useful than the current
+   behavior.

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/ChangeLog	2008-07-15 20:44:07 UTC (rev 901)
@@ -1,3 +1,58 @@
+2008-07-15  Marcus Brinkmann  <marcus at g10code.de>
+
+	* server.c: Include "gpafileop.h", "gpafileencryptop.h",
+	"gpafilesignop.h", "gpafiledecryptop.h" and "gpafileverifyop.h".
+	(struct conn_ctrl_s): New member FILES and FILES_FINISHED.
+	(free_file_item, release_files, hextobyte, decode_percent_string)
+	(cmd_file, impl_encrypt_sign_files, cmd_encrypt_files)
+	(cmd_sign_files, cmd_encrypt_sign_files)
+	(impl_decrypt_verify_files, cmd_decrypt_files, cmd_verify_files)
+	(cmd_decrypt_verify_files, cmd_import_files)
+	(cmd_checksum_create_files, cmd_checksum_verify_files): New static
+	functions.
+	(register_commands): Add commands FILE, ENCRYPT_FILES, SIGN_FILES<
+	ENCRYPT_SIGN_FILES, DECRYPT_FILES, VERIFY_FILES,
+	DECRYPT_VERIFY_FILES, IMPORT_FILES, CHECKSUM_CREATE_FILES,
+	CHECKSUM_VERIFY_FILES.
+	* fileman.c (file_decrypt): Use
+	gpa_file_decrypt_verify_operation_new instead of
+	gpa_file_decrypt_operation_new.
+	* encrpytdlg.h (gpa_file_encrypt_dialog_sign): Rename prototype to ...
+	(gpa_file_encrypt_dialog_get_sign): ... this.
+	(gpa_file_encrypt_dialog_set_armor)
+	(gpa_file_encrypt_dialog_set_sign): New prototypes.
+	* encryptdlg.c: New properties PROP_ARMOR, PROP_SIGN.
+	(gpa_file_encrypt_dialog_get_property)
+	(gpa_file_encrypt_dialog_set_property): Handle these.
+	(gpa_file_encrypt_dialog_class_init): Install these.
+	(gpa_file_encrypt_dialog_sign): Rename function to ...
+	(gpa_file_encrypt_dialog_get_sign): ... this.
+	(gpa_file_encrypt_dialog_set_armor)
+	(gpa_file_encrypt_dialog_set_sign): New functions.
+	* gpafileencryptop.h (gpa_file_encrypt_sign_operation_new): New
+	prototype.
+	* gpafileencryptop.c (gpa_file_encrypt_sign_operation_new): New
+	interface.
+	* gpafiledecryptop.h (struct _GpaFileDecryptOperation): New
+	members VERIFY, ERR, SIGNED_FILES, and DIALOG.
+	(gpa_file_decrypt_verify_operation_new): New prototype.
+	* gpafiledecryptop.c: Include "verifydlg.h".  New property
+	PROP_VERIFY.
+	(gpa_file_decrypt_operation_get_property)
+	(gpa_file_decrypt_operation_set_property)
+	(gpa_file_decrypt_operation_response_cb): New static functions.
+	(gpa_file_decrypt_operation_finalize): Destroy OP->dialog.
+	(gpa_file_decrypt_operation_constructor): Create verify dialog.
+	(gpa_file_decrypt_operation_class_init): Set property hooks and
+	install PROP_VERIFY property.
+	(gpa_file_decrypt_verify_operation_new): New interface.
+	(gpa_file_decrypt_operation_start): Use
+	gpgme_op_decrypt_verify_start instead of gpgme_op_decrypt_start.
+	(gpa_file_decrypt_operation_next): When completed and in verify
+	mode, pop up the verification status dialog.
+	(gpa_file_decrypt_operation_done_cb): Gather verification status
+	summary if needed.
+
 2008-06-26  Werner Koch  <wk at g10code.com>
 
 	* gpagenkeyadvop.c (gpa_gen_key_advanced_operation_idle_cb): Do
@@ -7,7 +62,7 @@
 
 	* gpastreamverifyop.c (done_cb): Take care not to write a SIGSTATUS
 	line ala "invalid signature foo: Success".
-	
+
 	* gpastreamdecryptop.c (gpa_stream_decrypt_operation_new): Ditto.
 	* server.c (cmd_decrypt, cmd_verify): Pass title arg.
 	* verifydlg.c (gpa_file_verify_dialog_set_title): New.

Modified: trunk/src/encryptdlg.c
===================================================================
--- trunk/src/encryptdlg.c	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/encryptdlg.c	2008-07-15 20:44:07 UTC (rev 901)
@@ -46,7 +46,9 @@
 {
   PROP_0,
   PROP_WINDOW,
-  PROP_FORCE_ARMOR
+  PROP_FORCE_ARMOR,
+  PROP_ARMOR,
+  PROP_SIGN
 };
 
 static GObjectClass *parent_class = NULL;
@@ -68,6 +70,12 @@
     case PROP_FORCE_ARMOR:
       g_value_set_boolean (value, dialog->force_armor);
       break;
+    case PROP_ARMOR:
+      g_value_set_boolean (value, gpa_file_encrypt_dialog_get_armor (dialog));
+      break;
+    case PROP_SIGN:
+      g_value_set_boolean (value, gpa_file_encrypt_dialog_get_sign (dialog));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -92,6 +100,12 @@
     case PROP_FORCE_ARMOR:
       dialog->force_armor = g_value_get_boolean (value);
       break;
+    case PROP_ARMOR:
+      gpa_file_encrypt_dialog_set_armor (dialog, g_value_get_boolean (value));
+      break;
+    case PROP_SIGN:
+      gpa_file_encrypt_dialog_set_sign (dialog, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -253,6 +267,18 @@
 				   ("force-armor", "Force armor",
 				    "Force armor mode", FALSE,
 				    G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
+  g_object_class_install_property (object_class,
+				   PROP_ARMOR,
+				   g_param_spec_boolean
+				   ("armor", "Armor",
+				    "Armor mode", FALSE, G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+				   PROP_SIGN,
+				   g_param_spec_boolean
+				   ("sign", "Sign",
+				    "Sign", FALSE, G_PARAM_WRITABLE));
 }
 
 
@@ -286,7 +312,8 @@
 
 /* API */
 
-GtkWidget *gpa_file_encrypt_dialog_new (GtkWidget *parent, gboolean force_armor)
+GtkWidget *
+gpa_file_encrypt_dialog_new (GtkWidget *parent, gboolean force_armor)
 {
   GpaFileEncryptDialog *dialog;
   
@@ -298,28 +325,48 @@
   return GTK_WIDGET(dialog);
 }
 
-GList *gpa_file_encrypt_dialog_recipients (GpaFileEncryptDialog *dialog)
+GList *
+gpa_file_encrypt_dialog_recipients (GpaFileEncryptDialog *dialog)
 {
   return gpa_key_selector_get_selected_keys (GPA_KEY_SELECTOR (dialog->clist_keys));
 }
 
-gboolean gpa_file_encrypt_dialog_sign (GpaFileEncryptDialog *dialog)
+
+GList *
+gpa_file_encrypt_dialog_signers (GpaFileEncryptDialog *dialog)
 {
-  return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->check_sign));
+  return gpa_key_selector_get_selected_keys (GPA_KEY_SELECTOR (dialog->clist_who));
 }
 
-GList *gpa_file_encrypt_dialog_signers (GpaFileEncryptDialog *dialog)
+
+gboolean
+gpa_file_encrypt_dialog_get_armor (GpaFileEncryptDialog *dialog)
 {
-  return gpa_key_selector_get_selected_keys (GPA_KEY_SELECTOR (dialog->clist_who));
+  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->check_armor));
 }
 
 
-gboolean gpa_file_encrypt_dialog_get_armor (GpaFileEncryptDialog *dialog)
+void
+gpa_file_encrypt_dialog_set_armor (GpaFileEncryptDialog *dialog, gboolean armor)
 {
-  return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->check_armor));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->check_armor), armor);
 }
 
 
+gboolean
+gpa_file_encrypt_dialog_get_sign (GpaFileEncryptDialog *dialog)
+{
+  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->check_sign));
+}
+
+
+void
+gpa_file_encrypt_dialog_set_sign (GpaFileEncryptDialog *dialog, gboolean sign)
+{
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->check_sign), sign);
+}
+
+
 static void
 changed_select_row_cb (GtkTreeSelection *treeselection, gpointer user_data)
 {

Modified: trunk/src/encryptdlg.h
===================================================================
--- trunk/src/encryptdlg.h	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/encryptdlg.h	2008-07-15 20:44:07 UTC (rev 901)
@@ -61,11 +61,14 @@
 
 GList *gpa_file_encrypt_dialog_recipients (GpaFileEncryptDialog *dialog);
 
-gboolean gpa_file_encrypt_dialog_sign (GpaFileEncryptDialog *dialog);
+gboolean gpa_file_encrypt_dialog_get_sign (GpaFileEncryptDialog *dialog);
+void gpa_file_encrypt_dialog_set_sign (GpaFileEncryptDialog *dialog,
+				       gboolean sign);
 
 GList *gpa_file_encrypt_dialog_signers (GpaFileEncryptDialog *dialog);
 
 gboolean gpa_file_encrypt_dialog_get_armor (GpaFileEncryptDialog *dialog);
+void gpa_file_encrypt_dialog_set_armor (GpaFileEncryptDialog *dialog,
+					gboolean armor);
 
-
 #endif /* ENCRYPTDLG_H */

Modified: trunk/src/fileman.c
===================================================================
--- trunk/src/fileman.c	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/fileman.c	2008-07-15 20:44:07 UTC (rev 901)
@@ -476,7 +476,7 @@
   if (!files)
     return;
 
-  op = gpa_file_decrypt_operation_new (GTK_WIDGET (fileman), files);
+  op = gpa_file_decrypt_verify_operation_new (GTK_WIDGET (fileman), files);
 
   register_operation (fileman, GPA_FILE_OPERATION (op));
 }

Modified: trunk/src/gpafiledecryptop.c
===================================================================
--- trunk/src/gpafiledecryptop.c	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/gpafiledecryptop.c	2008-07-15 20:44:07 UTC (rev 901)
@@ -36,6 +36,7 @@
 #include "gtktools.h"
 #include "gpgmetools.h"
 #include "gpafiledecryptop.h"
+#include "verifydlg.h"
 
 /* Internal functions */
 static gboolean gpa_file_decrypt_operation_idle_cb (gpointer data);
@@ -50,9 +51,58 @@
 
 static GObjectClass *parent_class = NULL;
 
+/* Properties */
+enum
+{
+  PROP_0,
+  PROP_VERIFY
+};
+
+
 static void
+gpa_file_decrypt_operation_get_property (GObject *object, guint prop_id,
+					 GValue *value, GParamSpec *pspec)
+{
+  GpaFileDecryptOperation *op = GPA_FILE_DECRYPT_OPERATION (object);
+  
+  switch (prop_id)
+    {
+    case PROP_VERIFY:
+      g_value_set_boolean (value, op->verify);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+gpa_file_decrypt_operation_set_property (GObject *object, guint prop_id,
+					 const GValue *value, GParamSpec *pspec)
+{
+  GpaFileDecryptOperation *op = GPA_FILE_DECRYPT_OPERATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_VERIFY:
+      op->verify = g_value_get_boolean (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
 gpa_file_decrypt_operation_finalize (GObject *object)
 {  
+  GpaFileDecryptOperation *op = GPA_FILE_DECRYPT_OPERATION (object);
+
+  if (op->dialog)
+    gtk_widget_destroy (op->dialog);
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -67,6 +117,16 @@
 }
 
 
+static void
+gpa_file_decrypt_operation_response_cb (GtkDialog *dialog,
+					gint response, gpointer user_data)
+{
+  GpaFileDecryptOperation *op = GPA_FILE_DECRYPT_OPERATION (user_data);
+
+  g_signal_emit_by_name (GPA_OPERATION (op), "completed", op->err);
+}
+
+
 static GObject*
 gpa_file_decrypt_operation_constructor 
 (GType type, 
@@ -93,6 +153,15 @@
   gtk_window_set_title (GTK_WINDOW (GPA_FILE_OPERATION (op)->progress_dialog),
 			_("Decrypting..."));
 
+  if (op->verify)
+    {
+      /* Create the verification dialog */
+      op->dialog = gpa_file_verify_dialog_new (GPA_OPERATION (op)->window);
+      g_signal_connect (G_OBJECT (op->dialog), "response",
+			G_CALLBACK (gpa_file_decrypt_operation_response_cb),
+			op);
+    }
+
   return object;
 }
 
@@ -105,6 +174,16 @@
 
   object_class->constructor = gpa_file_decrypt_operation_constructor;
   object_class->finalize = gpa_file_decrypt_operation_finalize;
+  object_class->set_property = gpa_file_decrypt_operation_set_property;
+  object_class->get_property = gpa_file_decrypt_operation_get_property;
+
+  /* Properties */
+  g_object_class_install_property (object_class,
+				   PROP_VERIFY,
+				   g_param_spec_boolean
+				   ("verify", "Verify",
+				    "Verify", FALSE,
+				    G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 }
 
 GType
@@ -151,6 +230,23 @@
   return op;
 }
 
+
+GpaFileDecryptOperation*
+gpa_file_decrypt_verify_operation_new (GtkWidget *window,
+				       GList *files)
+{
+  GpaFileDecryptOperation *op;
+  
+  op = g_object_new (GPA_FILE_DECRYPT_OPERATION_TYPE,
+		     "window", window,
+		     "input_files", files,
+		     "verify", TRUE,
+		     NULL);
+
+  return op;
+}
+
+
 /* Internal */
 
 static gchar *
@@ -226,8 +322,8 @@
     }
 
   /* Start the operation.  */
-  err = gpgme_op_decrypt_start (GPA_OPERATION (op)->context->ctx, op->cipher, 
-				op->plain);
+  err = gpgme_op_decrypt_verify_start (GPA_OPERATION (op)->context->ctx,
+				       op->cipher, op->plain);
   if (err)
     {
       gpa_gpgme_warning (err);
@@ -262,14 +358,29 @@
 
   if (! GPA_FILE_OPERATION (op)->current)
     {
-      g_signal_emit_by_name (GPA_OPERATION (op), "completed", 0);
+      if (op->verify && op->signed_files)
+	{
+	  op->err = 0;
+	  gtk_widget_show_all (op->dialog);
+	}
+      else
+	g_signal_emit_by_name (GPA_OPERATION (op), "completed", 0);
       return;
     }
 
   err = gpa_file_decrypt_operation_start
     (op, GPA_FILE_OPERATION (op)->current->data);
   if (err)
-    g_signal_emit_by_name (GPA_OPERATION (op), "completed", err);
+    {
+      if (op->verify && op->signed_files)
+	{
+	  /* All files have been verified: show the results dialog */
+	  op->err = err;
+	  gtk_widget_show_all (op->dialog);
+	}
+      else
+	g_signal_emit_by_name (GPA_OPERATION (op), "completed", err);
+    }
 }
 
 
@@ -332,6 +443,25 @@
       /* We've just created a file */
       g_signal_emit_by_name (GPA_OPERATION (op), "created_file", file_item);
 
+      if (op->verify)
+	{
+	  gpgme_verify_result_t result;
+ 
+	  result = gpgme_op_verify_result (GPA_OPERATION (op)->context->ctx);
+	  if (result->signatures)
+	    {
+	      /* Add the file to the result dialog.  FIXME: Maybe we
+		 should use the filename without the directory.  */
+	      gpa_file_verify_dialog_add_file (GPA_FILE_VERIFY_DIALOG (op->dialog),
+					       file_item->direct_name
+					       ? file_item->direct_name
+					       : file_item->filename_in,
+					       NULL, NULL,
+					       result->signatures);
+	      op->signed_files++;
+	    }
+	}
+
       /* Go to the next file in the list and decrypt it */
       GPA_FILE_OPERATION (op)->current = g_list_next 
 	(GPA_FILE_OPERATION (op)->current);
@@ -339,6 +469,7 @@
     }
 }
 
+
 static gboolean
 gpa_file_decrypt_operation_idle_cb (gpointer data)
 {
@@ -349,6 +480,7 @@
   return FALSE;
 }
 
+
 static void
 gpa_file_decrypt_operation_done_error_cb (GpaContext *context, gpg_error_t err,
 					  GpaFileDecryptOperation *op)

Modified: trunk/src/gpafiledecryptop.h
===================================================================
--- trunk/src/gpafiledecryptop.h	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/gpafiledecryptop.h	2008-07-15 20:44:07 UTC (rev 901)
@@ -42,6 +42,11 @@
 
   int cipher_fd, plain_fd;
   gpgme_data_t cipher, plain;
+ 
+  gboolean verify;
+  gpg_error_t err;
+  int signed_files;
+  GtkWidget *dialog;  
 };
 
 struct _GpaFileDecryptOperationClass {
@@ -54,8 +59,10 @@
 
 /* Creates a new decryption operation.
  */
-GpaFileDecryptOperation*
-gpa_file_decrypt_operation_new (GtkWidget *window,
-				GList *files);
+GpaFileDecryptOperation *gpa_file_decrypt_operation_new (GtkWidget *window,
+							 GList *files);
 
+GpaFileDecryptOperation *gpa_file_decrypt_verify_operation_new
+  (GtkWidget *window, GList *files);
+
 #endif

Modified: trunk/src/gpafileencryptop.c
===================================================================
--- trunk/src/gpafileencryptop.c	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/gpafileencryptop.c	2008-07-15 20:44:07 UTC (rev 901)
@@ -227,6 +227,25 @@
 
 
 GpaFileEncryptOperation*
+gpa_file_encrypt_sign_operation_new (GtkWidget *window, GList *files,
+				     gboolean force_armor)
+{
+  GpaFileEncryptOperation *op;
+  
+  op = g_object_new (GPA_FILE_ENCRYPT_OPERATION_TYPE,
+		     "window", window,
+		     "input_files", files,
+		     "force-armor", force_armor,
+		     NULL);
+
+  gpa_file_encrypt_dialog_set_sign
+    (GPA_FILE_ENCRYPT_DIALOG (op->encrypt_dialog), TRUE);
+
+  return op;
+}
+
+
+GpaFileEncryptOperation*
 gpa_file_encrypt_operation_new_for_server (GList *files, void *server_ctx)
 {
   GpaFileEncryptOperation *op;
@@ -318,7 +337,7 @@
   /* Start the operation.  */
   /* Always trust keys, because any untrusted keys were already
      confirmed by the user.  */
-  if (gpa_file_encrypt_dialog_sign 
+  if (gpa_file_encrypt_dialog_get_sign 
       (GPA_FILE_ENCRYPT_DIALOG (op->encrypt_dialog)))
     err = gpgme_op_encrypt_sign_start (GPA_OPERATION (op)->context->ctx,
 				       op->rset, GPGME_ENCRYPT_ALWAYS_TRUST,
@@ -710,7 +729,7 @@
       /* Set the armor value */
       gpgme_set_armor (GPA_OPERATION (op)->context->ctx, armor);
       /* Set the signers for the context.  */
-      if (gpa_file_encrypt_dialog_sign 
+      if (gpa_file_encrypt_dialog_get_sign
 	  (GPA_FILE_ENCRYPT_DIALOG (op->encrypt_dialog)))
 	success = set_signers (op, signers);
 

Modified: trunk/src/gpafileencryptop.h
===================================================================
--- trunk/src/gpafileencryptop.h	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/gpafileencryptop.h	2008-07-15 20:44:07 UTC (rev 901)
@@ -75,10 +75,13 @@
 /* API */
 
 /* Creates a new encryption operation. */
-GpaFileEncryptOperation *
-gpa_file_encrypt_operation_new (GtkWidget *window, GList *files,
-				gboolean force_armor);
+GpaFileEncryptOperation *gpa_file_encrypt_operation_new (GtkWidget *window,
+							 GList *files,
+							 gboolean force_armor);
 
+GpaFileEncryptOperation *gpa_file_encrypt_sign_operation_new
+(GtkWidget *window, GList *files, gboolean force_armor);
+
 /* Create a new encryption operaion for the UI server.  */
 GpaFileEncryptOperation*
 gpa_file_encrypt_operation_new_for_server (GList *files, void *server_ctx);

Modified: trunk/src/gpafileverifyop.c
===================================================================
--- trunk/src/gpafileverifyop.c	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/gpafileverifyop.c	2008-07-15 20:44:07 UTC (rev 901)
@@ -76,9 +76,10 @@
 }
 
 static GObject*
-gpa_file_verify_operation_constructor (GType type,
-					guint n_construct_properties,
-					GObjectConstructParam *construct_properties)
+gpa_file_verify_operation_constructor
+(GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties)
 {
   GObject *object;
   GpaFileVerifyOperation *op;
@@ -99,6 +100,7 @@
   /* Give a title to the progress dialog */
   gtk_window_set_title (GTK_WINDOW (GPA_FILE_OPERATION (op)->progress_dialog),
 			_("Verifying..."));
+
   /* Create the verification dialog */
   op->dialog = gpa_file_verify_dialog_new (GPA_OPERATION (op)->window);
   g_signal_connect (G_OBJECT (op->dialog), "response",
@@ -107,6 +109,7 @@
   return object;
 }
 
+
 static void
 gpa_file_verify_operation_class_init (GpaFileVerifyOperationClass *klass)
 {

Modified: trunk/src/server.c
===================================================================
--- trunk/src/server.c	2008-07-02 15:28:44 UTC (rev 900)
+++ trunk/src/server.c	2008-07-15 20:44:07 UTC (rev 901)
@@ -40,6 +40,11 @@
 #include "gpastreamsignop.h"
 #include "gpastreamdecryptop.h"
 #include "gpastreamverifyop.h"
+#include "gpafileop.h"
+#include "gpafileencryptop.h"
+#include "gpafilesignop.h"
+#include "gpafiledecryptop.h"
+#include "gpafileverifyop.h"
 
 
 #define set_error(e,t) assuan_set_error (ctx, gpg_error (e), (t))
@@ -95,6 +100,10 @@
   /* Session information:  A session number and a malloced title or NULL.  */
   unsigned int session_number;
   char *session_title;
+
+  /* The list of all files to be processed.  */
+  GList *files;
+  gboolean files_finished;
 };
 
 
@@ -316,7 +325,31 @@
     }
 }
 
+
 static void
+free_file_item (gpa_file_item_t item)
+{
+  if (item->filename_in)
+    g_free (item->filename_in);
+  if (item->filename_out)
+    g_free (item->filename_out);
+}
+
+
+static void
+release_files (conn_ctrl_t ctrl)
+{
+  if (! ctrl->files)
+    return;
+
+  g_list_foreach (ctrl->files, (GFunc) free_file_item, NULL);
+  g_list_free (ctrl->files);
+  ctrl->files = NULL;
+  ctrl->files_finished = FALSE;
+}
+
+
+static void
 release_keys (gpgme_key_t *keys)
 {
   if (keys)
@@ -1156,14 +1189,414 @@
   return assuan_process_done (ctx, err);
 }
 
+
 
+/* Convert two hexadecimal digits from STR to the value they
+   represent.  Returns -1 if one of the characters is not a
+   hexadecimal digit.  */
+static int
+hextobyte (const char *str)
+{
+  int val = 0;
+  int i;
+
+#define NROFHEXDIGITS 2
+  for (i = 0; i < NROFHEXDIGITS; i++)
+    {
+      if (*str >= '0' && *str <= '9')
+        val += *str - '0';
+      else if (*str >= 'A' && *str <= 'F')
+        val += 10 + *str - 'A';
+      else if (*str >= 'a' && *str <= 'f')
+        val += 10 + *str - 'a';
+      else
+        return -1;
+      if (i < NROFHEXDIGITS - 1)
+        val *= 16;
+      str++;
+    }
+  return val;
+}
+
+
+/* Decode the percent escaped string STR in place.  */
 static void
+decode_percent_string (char *str)
+{
+  char *src = str;
+  char *dest = str;
+
+  /* Convert the string.  */
+  while (*src)
+    {
+      if (*src != '%')
+        {
+          *(dest++) = *(src++);
+          continue;
+        }
+      else
+        {
+          int val = hextobyte (&src[1]);
+          
+          if (val == -1)
+            {
+              /* Should not happen.  */
+              *(dest++) = *(src++);
+              if (*src)
+                *(dest++) = *(src++);
+              if (*src)
+                *(dest++) = *(src++);
+            }
+          else
+            {
+              if (!val)
+                {
+                  /* A binary zero is not representable in a C
+                     string.  */
+                  *(dest++) = '\\';
+                  *(dest++) = '0'; 
+                }
+              else 
+                *((unsigned char *) dest++) = val;
+              src += 3;
+            }
+        }
+    }
+  *(dest++) = 0;
+}
+
+
+/* FILE <file> [--continued]
+
+   Set the files on which to operate.
+ */
+static int
+cmd_file (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err = 0;
+  conn_ctrl_t ctrl = assuan_get_pointer (ctx);
+  gboolean continued;
+  gpa_file_item_t file_item;
+  char *tail;
+
+  continued = has_option (line, "--continued");
+
+  if (ctrl->files_finished)
+    release_files (ctrl);
+
+  tail = line;
+  while (*tail && ! spacep (tail))
+    tail++;
+  *tail = '\0';
+  decode_percent_string (line);
+
+  file_item = g_malloc0 (sizeof (*file_item));
+  file_item->filename_in = g_strdup (line);
+  ctrl->files = g_list_append (ctrl->files, file_item);
+
+  if (! continued)
+    ctrl->files_finished = TRUE;
+
+  return assuan_process_done (ctx, err);
+}
+
+
+static gpg_error_t
+impl_encrypt_sign_files (assuan_context_t ctx, int encrypt, int sign)
+{
+  gpg_error_t err = 0;
+  conn_ctrl_t ctrl = assuan_get_pointer (ctx);
+  GpaFileOperation *op;
+
+  if (! ctrl->files)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, "no files specified");
+      return assuan_process_done (ctx, err);
+    }
+  else if (! ctrl->files_finished)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, "more files expected");
+      return assuan_process_done (ctx, err);
+    }
+
+  /* FIXME: Needs a root window.  Need to set "sign" default.  */
+  if (encrypt && sign)
+    op = (GpaFileOperation *)
+      gpa_file_encrypt_sign_operation_new (NULL, ctrl->files, FALSE);
+  if (encrypt)
+    op = (GpaFileOperation *)
+      gpa_file_encrypt_operation_new (NULL, ctrl->files, FALSE);
+  else
+    op = (GpaFileOperation *)
+      gpa_file_sign_operation_new (NULL, ctrl->files, FALSE);
+
+  /* Ownership of CTRL->files was passed to callee.  */
+  ctrl->files = NULL;
+  ctrl->files_finished = FALSE;
+  g_signal_connect (G_OBJECT (op), "completed",
+		    G_CALLBACK (g_object_unref), NULL);
+
+  return assuan_process_done (ctx, err);
+}
+
+
+/* ENCRYPT_FILES --nohup  */
+static int
+cmd_encrypt_files (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (! has_option (line, "--nohup"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "file ops require --nohup");
+      return assuan_process_done (ctx, err);
+    }
+
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      return assuan_process_done (ctx, err);
+    }
+
+  return impl_encrypt_sign_files (ctx, 1, 0);
+}
+
+
+/* SIGN_FILES --nohup  */
+static int
+cmd_sign_files (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (! has_option (line, "--nohup"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "file ops require --nohup");
+      return assuan_process_done (ctx, err);
+    }
+
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      return assuan_process_done (ctx, err);
+    }
+
+  return impl_encrypt_sign_files (ctx, 0, 1);
+}
+
+
+/* ENCRYPT_SIGN_FILES --nohup  */
+static int
+cmd_encrypt_sign_files (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (! has_option (line, "--nohup"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "file ops require --nohup");
+      return assuan_process_done (ctx, err);
+    }
+
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      return assuan_process_done (ctx, err);
+    }
+
+  return impl_encrypt_sign_files (ctx, 1, 1);
+}
+
+
+static gpg_error_t
+impl_decrypt_verify_files (assuan_context_t ctx, int decrypt, int verify)
+{
+  gpg_error_t err = 0;
+  conn_ctrl_t ctrl = assuan_get_pointer (ctx);
+  GpaFileOperation *op;
+
+  if (! ctrl->files)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, "no files specified");
+      return assuan_process_done (ctx, err);
+    }
+  else if (! ctrl->files_finished)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, "more files expected");
+      return assuan_process_done (ctx, err);
+    }
+
+  /* FIXME: Needs a root window.  Need to enable "verify".  */
+  if (decrypt && verify)
+    op = (GpaFileOperation *)
+      gpa_file_decrypt_verify_operation_new (NULL, ctrl->files);
+  else if (decrypt)
+    op = (GpaFileOperation *)
+      gpa_file_decrypt_operation_new (NULL, ctrl->files);
+  else
+    op = (GpaFileOperation *)
+      gpa_file_verify_operation_new (NULL, ctrl->files);
+
+  /* Ownership of CTRL->files was passed to callee.  */
+  ctrl->files = NULL;
+  ctrl->files_finished = FALSE;
+  g_signal_connect (G_OBJECT (op), "completed",
+		    G_CALLBACK (g_object_unref), NULL);
+
+  return assuan_process_done (ctx, err);
+}
+
+
+/* DECRYPT_FILES --nohup  */
+static int
+cmd_decrypt_files (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (! has_option (line, "--nohup"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "file ops require --nohup");
+      return assuan_process_done (ctx, err);
+    }
+
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      return assuan_process_done (ctx, err);
+    }
+
+  return impl_decrypt_verify_files (ctx, 1, 0);
+}
+
+
+/* VERIFY_FILES --nohup  */
+static int
+cmd_verify_files (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (! has_option (line, "--nohup"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "file ops require --nohup");
+      return assuan_process_done (ctx, err);
+    }
+
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      return assuan_process_done (ctx, err);
+    }
+
+  return impl_decrypt_verify_files (ctx, 0, 1);
+}
+
+
+/* DECRYPT_VERIFY_FILES --nohup  */
+static int
+cmd_decrypt_verify_files (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (! has_option (line, "--nohup"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "file ops require --nohup");
+      return assuan_process_done (ctx, err);
+    }
+
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      return assuan_process_done (ctx, err);
+    }
+
+  return impl_decrypt_verify_files (ctx, 1, 1);
+}
+
+
+/* IMPORT_FILES --nohup  */
+static int
+cmd_import_files (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (! has_option (line, "--nohup"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "file ops require --nohup");
+      return assuan_process_done (ctx, err);
+    }
+
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      return assuan_process_done (ctx, err);
+    }
+
+  err = set_error (GPG_ERR_NOT_IMPLEMENTED, "not implemented");
+  return assuan_process_done (ctx, err);
+}
+
+
+/* CHECKSUM_CREATE_FILES --nohup  */
+static int
+cmd_checksum_create_files (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (! has_option (line, "--nohup"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "file ops require --nohup");
+      return assuan_process_done (ctx, err);
+    }
+
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      return assuan_process_done (ctx, err);
+    }
+
+  err = set_error (GPG_ERR_NOT_IMPLEMENTED, "not implemented");
+  return assuan_process_done (ctx, err);
+}
+
+
+/* CHECKSUM_VERIFY_FILES --nohup  */
+static int
+cmd_checksum_verify_files (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (! has_option (line, "--nohup"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "file ops require --nohup");
+      return assuan_process_done (ctx, err);
+    }
+
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      return assuan_process_done (ctx, err);
+    }
+
+  err = set_error (GPG_ERR_NOT_IMPLEMENTED, "not implemented");
+  return assuan_process_done (ctx, err);
+}
+
+
+static void
 reset_notify (assuan_context_t ctx)
 {
   conn_ctrl_t ctrl = assuan_get_pointer (ctx);
 
   reset_prepared_keys (ctrl);
   release_recipients (ctrl);
+  release_files (ctrl);
   xfree (ctrl->sender);
   ctrl->sender = NULL;
   finish_io_streams (ctx, NULL, NULL, NULL);
@@ -1182,8 +1615,6 @@
   ctrl->session_title = NULL;
 }
 
-
-
 
 /* Tell the assuan library about our commands.   */
 static int
@@ -1193,20 +1624,30 @@
     const char *name;
     int (*handler)(assuan_context_t, char *line);
   } table[] = {
-    { "SESSION",   cmd_session },
+    { "SESSION", cmd_session },
     { "RECIPIENT", cmd_recipient },
-    { "INPUT",     NULL },
-    { "OUTPUT",    NULL },
-    { "MESSAGE",   cmd_message },
-    { "ENCRYPT",   cmd_encrypt },
+    { "INPUT", NULL },
+    { "OUTPUT", NULL },
+    { "MESSAGE", cmd_message },
+    { "ENCRYPT", cmd_encrypt },
     { "PREP_ENCRYPT", cmd_prep_encrypt },
-    { "SENDER",    cmd_sender },
-    { "SIGN",      cmd_sign   },
-    { "DECRYPT",   cmd_decrypt },
-    { "VERIFY",    cmd_verify },
+    { "SENDER", cmd_sender },
+    { "SIGN", cmd_sign   },
+    { "DECRYPT", cmd_decrypt },
+    { "VERIFY", cmd_verify },
     { "START_KEYMANAGER", cmd_start_keymanager },
     { "START_CONFDIALOG", cmd_start_confdialog },
-    { "GETINFO",   cmd_getinfo },
+    { "GETINFO", cmd_getinfo },
+    { "FILE", cmd_file },
+    { "ENCRYPT_FILES", cmd_encrypt_files },
+    { "SIGN_FILES", cmd_sign_files },
+    { "ENCRYPT_SIGN_FILES", cmd_encrypt_sign_files },
+    { "DECRYPT_FILES", cmd_decrypt_files },
+    { "VERIFY_FILES", cmd_verify_files },
+    { "DECRYPT_VERIFY_FILES", cmd_decrypt_verify_files },
+    { "IMPORT_FILES", cmd_import_files },
+    { "CHECKSUM_CREATE_FILES", cmd_checksum_create_files },
+    { "CHECKSUM_VERIFY_FILES", cmd_checksum_verify_files },
     { NULL }
   };
   int i, rc;



More information about the Gpa-commits mailing list