* keygen.c (ask_key_flags): New. (ask_algo): Call it here in --expert mode
[gnupg.git] / sm / server.c
index e8200fe..dda1509 100644 (file)
@@ -1,5 +1,5 @@
 /* server.c - Server mode and main entry point 
- *     Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ *     Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -27,8 +27,9 @@
 #include <ctype.h>
 #include <unistd.h>
 
+#include <assuan.h>
+
 #include "gpgsm.h"
-#include "../assuan/assuan.h"
 
 #define set_error(e,t) assuan_set_error (ctx, ASSUAN_ ## e, (t))
 
@@ -244,18 +245,21 @@ cmd_recipient (ASSUAN_CONTEXT ctx, char *line)
 
   rc = gpgsm_add_to_certlist (ctrl, line, 0, &ctrl->server_local->recplist);
   if (rc)
-    gpgsm_status2 (ctrl, STATUS_INV_RECP,
-                   rc == -1? "1":
-                   rc == GNUPG_No_Public_Key?       "1":
-                   rc == GNUPG_Ambiguous_Name?      "2":
-                   rc == GNUPG_Wrong_Key_Usage?     "3":
-                   rc == GNUPG_Certificate_Revoked? "4":
-                   rc == GNUPG_Certificate_Expired? "5":
-                   rc == GNUPG_No_CRL_Known?        "6":
-                   rc == GNUPG_CRL_Too_Old?         "7":
-                   rc == GNUPG_No_Policy_Match?     "8":
+    {
+      gpg_err_code_t r = gpg_err_code (rc);
+      gpgsm_status2 (ctrl, STATUS_INV_RECP,
+                   r == -1? "1":
+                   r == GPG_ERR_NO_PUBKEY?       "1":
+                   r == GPG_ERR_AMBIGUOUS_NAME?  "2":
+                   r == GPG_ERR_WRONG_KEY_USAGE? "3":
+                   r == GPG_ERR_CERT_REVOKED?    "4":
+                   r == GPG_ERR_CERT_EXPIRED?    "5":
+                   r == GPG_ERR_NO_CRL_KNOWN?    "6":
+                   r == GPG_ERR_CRL_TOO_OLD?     "7":
+                   r == GPG_ERR_NO_POLICY_MATCH? "8":
                    "0",
                    line, NULL);
+    }
 
   return map_to_assuan_status (rc);
 }
@@ -284,20 +288,22 @@ cmd_signer (ASSUAN_CONTEXT ctx, char *line)
 
   rc = gpgsm_add_to_certlist (ctrl, line, 1, &ctrl->server_local->signerlist);
   if (rc)
-    gpgsm_status2 (ctrl, STATUS_INV_RECP,
-                   rc == -1? "1":
-                   rc == GNUPG_No_Public_Key?       "1":
-                   rc == GNUPG_Ambiguous_Name?      "2":
-                   rc == GNUPG_Wrong_Key_Usage?     "3":
-                   rc == GNUPG_Certificate_Revoked? "4":
-                   rc == GNUPG_Certificate_Expired? "5":
-                   rc == GNUPG_No_CRL_Known?        "6":
-                   rc == GNUPG_CRL_Too_Old?         "7":
-                   rc == GNUPG_No_Policy_Match?     "8":
-                   rc == GNUPG_No_Secret_Key?       "9":
+    {
+      gpg_err_code_t r = gpg_err_code (rc);
+      gpgsm_status2 (ctrl, STATUS_INV_RECP,
+                   r == -1?                          "1":
+                   r == GPG_ERR_NO_PUBKEY?           "1":
+                   r == GPG_ERR_AMBIGUOUS_NAME?      "2":
+                   r == GPG_ERR_WRONG_KEY_USAGE?     "3":
+                   r == GPG_ERR_CERT_REVOKED?        "4":
+                   r == GPG_ERR_CERT_EXPIRED?        "5":
+                   r == GPG_ERR_NO_CRL_KNOWN?        "6":
+                   r == GPG_ERR_CRL_TOO_OLD?         "7":
+                   r == GPG_ERR_NO_POLICY_MATCH?     "8":
+                   r == GPG_ERR_NO_SECKEY?           "9":
                    "0",
-                   line, NULL);
-
+                  line, NULL);
+    }
   return map_to_assuan_status (rc);
 }
 
@@ -719,34 +725,30 @@ register_commands (ASSUAN_CONTEXT ctx)
 {
   static struct {
     const char *name;
-    int cmd_id;
     int (*handler)(ASSUAN_CONTEXT, char *line);
   } table[] = {
-    { "RECIPIENT",  0,  cmd_recipient },
-    { "SIGNER",     0,  cmd_signer },
-    { "ENCRYPT",    0,  cmd_encrypt },
-    { "DECRYPT",    0,  cmd_decrypt },
-    { "VERIFY",     0,  cmd_verify },
-    { "SIGN",       0,  cmd_sign },
-    { "IMPORT",     0,  cmd_import },
-    { "EXPORT",     0,  cmd_export },
-    { "",     ASSUAN_CMD_INPUT, NULL }, 
-    { "",     ASSUAN_CMD_OUTPUT, NULL }, 
-    { "MESSAGE",    0,  cmd_message },
-    { "LISTKEYS",   0,  cmd_listkeys },
-    { "LISTSECRETKEYS",  0,  cmd_listsecretkeys },
-    { "GENKEY",     0,  cmd_genkey },
-    { "DELKEYS",    0,  cmd_delkeys },
+    { "RECIPIENT",     cmd_recipient },
+    { "SIGNER",        cmd_signer },
+    { "ENCRYPT",       cmd_encrypt },
+    { "DECRYPT",       cmd_decrypt },
+    { "VERIFY",        cmd_verify },
+    { "SIGN",          cmd_sign },
+    { "IMPORT",        cmd_import },
+    { "EXPORT",        cmd_export },
+    { "INPUT",         NULL }, 
+    { "OUTPUT",        NULL }, 
+    { "MESSAGE",       cmd_message },
+    { "LISTKEYS",      cmd_listkeys },
+    { "LISTSECRETKEYS",cmd_listsecretkeys },
+    { "GENKEY",        cmd_genkey },
+    { "DELKEYS",       cmd_delkeys },
     { NULL }
   };
-  int i, j, rc;
+  int i, rc;
 
-  for (i=j=0; table[i].name; i++)
+  for (i=0; table[i].name; i++)
     {
-      rc = assuan_register_command (ctx,
-                                    table[i].cmd_id? table[i].cmd_id
-                                                   : (ASSUAN_CMD_USER + j++),
-                                    table[i].name, table[i].handler);
+      rc = assuan_register_command (ctx, table[i].name, table[i].handler);
       if (rc)
         return rc;
     } 
@@ -989,7 +991,18 @@ gpgsm_status (CTRL ctrl, int no, const char *text)
   gpgsm_status2 (ctrl, no, text, NULL);
 }
 
+void
+gpgsm_status_with_err_code (CTRL ctrl, int no, const char *text,
+                            gpg_err_code_t ec)
+{
+  char buf[30];
 
+  sprintf (buf, "%u", (unsigned int)ec);
+  if (text)
+    gpgsm_status2 (ctrl, no, text, buf, NULL);
+  else
+    gpgsm_status2 (ctrl, no, buf, NULL);
+}
 
 #if 0
 /*