[svn] GnuPG - r3880 - trunk/g10

svn author dshaw cvs at cvs.gnupg.org
Thu Sep 1 22:51:17 CEST 2005


Author: dshaw
Date: 2005-09-01 22:51:13 +0200 (Thu, 01 Sep 2005)
New Revision: 3880

Modified:
   trunk/g10/ChangeLog
   trunk/g10/keyedit.c
   trunk/g10/photoid.c
   trunk/g10/photoid.h
Log:
* photoid.h, photoid.c (generate_photo_id): Allow passing in a
suggested filename.

* keyedit.c (keyedit_menu, menu_adduid): Call it here so "addphoto
filename" works.


Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog	2005-09-01 13:44:49 UTC (rev 3879)
+++ trunk/g10/ChangeLog	2005-09-01 20:51:13 UTC (rev 3880)
@@ -1,3 +1,11 @@
+2005-09-01  David Shaw  <dshaw at jabberwocky.com>
+
+	* photoid.h, photoid.c (generate_photo_id): Allow passing in a
+	suggested filename.
+
+	* keyedit.c (keyedit_menu, menu_adduid): Call it here so "addphoto
+	filename" works.
+
 2005-08-31  David Shaw  <dshaw at jabberwocky.com>
 
 	* photoid.c (generate_photo_id): Enable readline completion and

Modified: trunk/g10/keyedit.c
===================================================================
--- trunk/g10/keyedit.c	2005-09-01 13:44:49 UTC (rev 3879)
+++ trunk/g10/keyedit.c	2005-09-01 20:51:13 UTC (rev 3880)
@@ -51,7 +51,8 @@
 static void show_key_with_all_names( KBNODE keyblock, int only_marked,
 	    int with_revoker, int with_fpr, int with_subkeys, int with_prefs );
 static void show_key_and_fingerprint( KBNODE keyblock );
-static int menu_adduid( KBNODE keyblock, KBNODE sec_keyblock, int photo );
+static int menu_adduid( KBNODE keyblock, KBNODE sec_keyblock,
+			int photo, const char *photo_name );
 static void menu_deluid( KBNODE pub_keyblock, KBNODE sec_keyblock );
 static int menu_delsig( KBNODE pub_keyblock );
 static int menu_clean_sigs_from_uids(KBNODE keyblock);
@@ -1788,7 +1789,7 @@
 	    /* fall through */
 
 	  case cmdADDUID:
-	    if( menu_adduid( keyblock, sec_keyblock, photo ) )
+	    if( menu_adduid( keyblock, sec_keyblock, photo, arg_string ) )
 	      {
 	        update_trust = 1;
 		redisplay = 1;
@@ -2910,7 +2911,8 @@
  * Return true if there is a new user id
  */
 static int
-menu_adduid( KBNODE pub_keyblock, KBNODE sec_keyblock, int photo)
+menu_adduid( KBNODE pub_keyblock, KBNODE sec_keyblock,
+	     int photo, const char *photo_name)
 {
     PKT_user_id *uid;
     PKT_public_key *pk=NULL;
@@ -2976,7 +2978,7 @@
 	    }
 	}
 
-      uid = generate_photo_id(pk);
+      uid = generate_photo_id(pk,photo_name);
     } else
       uid = generate_user_id();
     if( !uid )

Modified: trunk/g10/photoid.c
===================================================================
--- trunk/g10/photoid.c	2005-09-01 13:44:49 UTC (rev 3879)
+++ trunk/g10/photoid.c	2005-09-01 20:51:13 UTC (rev 3880)
@@ -44,12 +44,12 @@
 
 /* Generate a new photo id packet, or return NULL if canceled */
 PKT_user_id *
-generate_photo_id(PKT_public_key *pk)
+generate_photo_id(PKT_public_key *pk,const char *photo_name)
 {
   PKT_user_id *uid;
   int error=1,i;
   unsigned int len;
-  char *filename=NULL;
+  char *filename;
   byte *photo=NULL;
   byte header[16];
   IOBUF file;
@@ -65,35 +65,44 @@
 #define EXTRA_UID_NAME_SPACE 71
   uid=xmalloc_clear(sizeof(*uid)+71);
 
-  tty_printf(_("\nPick an image to use for your photo ID.  "
-           "The image must be a JPEG file.\n"
-	   "Remember that the image is stored within your public key.  "
-	   "If you use a\n"
-	   "very large picture, your key will become very large as well!\n"
-	   "Keeping the image close to 240x288 is a good size to use.\n"));
+  if(photo_name && *photo_name)
+    filename=make_filename(photo_name,(void *)NULL);
+  else
+    {
+      tty_printf(_("\nPick an image to use for your photo ID."
+		   "  The image must be a JPEG file.\n"
+		   "Remember that the image is stored within your public key."
+		   "  If you use a\n"
+		   "very large picture, your key will become very large"
+		   " as well!\n"
+		   "Keeping the image close to 240x288 is a good size"
+		   " to use.\n"));
+      filename=NULL;
+    }
 
   while(photo==NULL)
     {
-      char *tempname;
+      if(filename==NULL)
+	{
+	  char *tempname;
 
-      tty_printf("\n");
+	  tty_printf("\n");
 
-      xfree(filename);
+	  tty_enable_completion(NULL);
 
-      tty_enable_completion(NULL);
+	  tempname=cpr_get("photoid.jpeg.add",
+			   _("Enter JPEG filename for photo ID: "));
 
-      tempname=cpr_get("photoid.jpeg.add",
-		       _("Enter JPEG filename for photo ID: "));
+	  tty_disable_completion();
 
-      tty_disable_completion();
+	  filename=make_filename(tempname,(void *)NULL);
 
-      filename=make_filename(tempname,(void *)NULL);
+	  xfree(tempname);
 
-      xfree(tempname);
+	  if(strlen(filename)==0)
+	    goto scram;
+	}
 
-      if(strlen(filename)==0)
-	goto scram;
-
       file=iobuf_open(filename);
       if (file && is_secured_file (iobuf_get_fd (file)))
         {
@@ -105,6 +114,8 @@
 	{
 	  log_error(_("unable to open JPEG file `%s': %s\n"),
 		    filename,strerror(errno));
+	  xfree(filename);
+	  filename=NULL;
 	  continue;
 	}
 
@@ -116,6 +127,8 @@
 			    _("Are you sure you want to use it? (y/N) ")))
 	  {
 	    iobuf_close(file);
+	    xfree(filename);
+	    filename=NULL;
 	    continue;
 	  }
 	}
@@ -131,6 +144,8 @@
 	  log_error(_("`%s' is not a JPEG file\n"),filename);
 	  xfree(photo);
 	  photo=NULL;
+	  xfree(filename);
+	  filename=NULL;
 	  continue;
 	}
 
@@ -153,6 +168,8 @@
 	      free_attributes(uid);
 	      xfree(photo);
 	      photo=NULL;
+	      xfree(filename);
+	      filename=NULL;
 	      continue;
 	    }
 	}

Modified: trunk/g10/photoid.h
===================================================================
--- trunk/g10/photoid.h	2005-09-01 13:44:49 UTC (rev 3879)
+++ trunk/g10/photoid.h	2005-09-01 20:51:13 UTC (rev 3880)
@@ -26,7 +26,7 @@
 
 #include "packet.h"
 
-PKT_user_id *generate_photo_id(PKT_public_key *pk);
+PKT_user_id *generate_photo_id(PKT_public_key *pk,const char *filename);
 int parse_image_header(const struct user_attribute *attr,byte *type,u32 *len);
 char *image_type_to_string(byte type,int style);
 void show_photos(const struct user_attribute *attrs,




More information about the Gnupg-commits mailing list