Hopefully last changes for building with MSC.
[gpgme.git] / src / engine-g13.c
index 8ecdcdfe6e9a4bd314d7ca1f3635622e791a9fbf..6ba49c42008582b6df3058292e1f157a27be526f 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
 #include <assert.h>
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef HAVE_LOCALE_H
 #include <locale.h>
+#endif
 #include <fcntl.h> /* FIXME */
 #include <errno.h>
 
@@ -69,10 +75,6 @@ struct engine_g13
 
   struct gpgme_io_cbs io_cbs;
 
-  /* Internal callbacks.  */
-  engine_assuan_result_cb_t result_cb;
-  void *result_cb_value; 
-
   /* User provided callbacks.  */
   struct {
     gpgme_assuan_data_cb_t data_cb;
@@ -215,7 +217,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
   gpgme_error_t err = 0;
   engine_g13_t g13;
   int argc;
-  char *argv[5];
+  const char *argv[5];
   char *dft_display = NULL;
   char dft_ttyname[64];
   char *dft_ttytype = NULL;
@@ -358,7 +360,10 @@ g13_set_locale (void *engine, int category, const char *value)
   /* FIXME: If value is NULL, we need to reset the option to default.
      But we can't do this.  So we error out here.  G13 needs support
      for this.  */
-  if (category == LC_CTYPE)
+  if (0)
+    ;
+#ifdef LC_CTYPE
+  else if (category == LC_CTYPE)
     {
       catstr = "lc-ctype";
       if (!value && g13->lc_ctype_set)
@@ -366,6 +371,7 @@ g13_set_locale (void *engine, int category, const char *value)
       if (value)
        g13->lc_ctype_set = 1;
     }
+#endif
 #ifdef LC_MESSAGES
   else if (category == LC_MESSAGES)
     {
@@ -396,10 +402,11 @@ g13_set_locale (void *engine, int category, const char *value)
 }
 
 
+#if USE_DESCRIPTOR_PASSING
 static gpgme_error_t
 g13_assuan_simple_command (assuan_context_t ctx, char *cmd,
-                            engine_status_handler_t status_fnc,
-                            void *status_fnc_value)
+                          engine_status_handler_t status_fnc,
+                          void *status_fnc_value)
 {
   gpg_error_t err;
   char *line;
@@ -446,6 +453,7 @@ g13_assuan_simple_command (assuan_context_t ctx, char *cmd,
 
   return err;
 }
+#endif
 
 
 static gpgme_error_t
@@ -480,17 +488,13 @@ status_handler (void *opaque, int fd)
                  "fd 0x%x: ERR line: %s",
                   fd, err ? gpg_strerror (err) : "ok");
          
-         /* In g13, command execution errors are not fatal, as we use
+         /* Command execution errors are not fatal, as we use
             a session based protocol.  */
-          if (g13->result_cb)
-            err = g13->result_cb (g13->result_cb_value, err);
-          else
-            err = 0;
-          if (!err)
-            {
-              _gpgme_io_close (g13->status_cb.fd);
-              return 0;
-           }
+         data->op_err = err;
+
+         /* The caller will do the rest (namely, call cancel_op,
+            which closes status_fd).  */
+         return 0;
        }
       else if (linelen >= 2
               && line[0] == 'O' && line[1] == 'K'
@@ -498,15 +502,9 @@ status_handler (void *opaque, int fd)
        {
           TRACE1 (DEBUG_CTX, "gpgme:status_handler", g13,
                  "fd 0x%x: OK line", fd);
-          if (g13->result_cb)
-            err = g13->result_cb (g13->result_cb_value, 0);
-          else
-            err = 0;
-         if (!err)
-            {
-              _gpgme_io_close (g13->status_cb.fd);
-              return 0;
-            }
+
+         _gpgme_io_close (g13->status_cb.fd);
+         return 0;
        }
       else if (linelen > 2
               && line[0] == 'D' && line[1] == ' ')
@@ -644,16 +642,21 @@ static gpgme_error_t
 start (engine_g13_t g13, const char *command)
 {
   gpgme_error_t err;
+  assuan_fd_t afdlist[5];
   int fdlist[5];
   int nfds;
+  int i;
 
   /* We need to know the fd used by assuan for reads.  We do this by
      using the assumption that the first returned fd from
      assuan_get_active_fds() is always this one.  */
   nfds = assuan_get_active_fds (g13->assuan_ctx, 0 /* read fds */,
-                                fdlist, DIM (fdlist));
+                                afdlist, DIM (afdlist));
   if (nfds < 1)
     return gpg_error (GPG_ERR_GENERAL);        /* FIXME */
+  /* For now... */
+  for (i = 0; i < nfds; i++)
+    fdlist[i] = (int) afdlist[i];
 
   /* We "duplicate" the file descriptor, so we can close it here (we
      can't close fdlist[0], as that is closed by libassuan, and
@@ -704,8 +707,6 @@ g13_reset (void *engine)
 static gpgme_error_t
 g13_transact (void *engine,
                 const char *command,
-                engine_assuan_result_cb_t result_cb,
-                void *result_cb_value,
                 gpgme_assuan_data_cb_t data_cb,
                 void *data_cb_value,
                 gpgme_assuan_inquire_cb_t inq_cb,
@@ -719,8 +720,6 @@ g13_transact (void *engine,
   if (!g13 || !command || !*command)
     return gpg_error (GPG_ERR_INV_VALUE);
 
-  g13->result_cb = result_cb;
-  g13->result_cb_value = result_cb_value;
   g13->user.data_cb = data_cb;
   g13->user.data_cb_value = data_cb_value;
   g13->user.inq_cb = inq_cb;
@@ -775,7 +774,9 @@ struct engine_ops _gpgme_engine_ops_g13 =
     NULL,              /* set_command_handler */
     NULL,               /* set_colon_line_handler */
     g13_set_locale,
+    NULL,              /* set_protocol */
     NULL,               /* decrypt */
+    NULL,               /* decrypt_verify */
     NULL,               /* delete */
     NULL,              /* edit */
     NULL,               /* encrypt */