[Gpa-commits] r782 - in trunk: . m4 src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Sep 27 12:32:40 CEST 2007


Author: werner
Date: 2007-09-27 12:32:38 +0200 (Thu, 27 Sep 2007)
New Revision: 782

Added:
   trunk/m4/gpg-error.m4
   trunk/m4/libassuan.m4
   trunk/src/server.c
   trunk/src/w32-afunix.c
   trunk/src/w32-afunix.h
Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/configure.ac
   trunk/m4/Makefile.am
   trunk/src/ChangeLog
   trunk/src/Makefile.am
   trunk/src/encryptdlg.c
   trunk/src/expirydlg.c
   trunk/src/fileman.c
   trunk/src/gpa.c
   trunk/src/gpa.h
   trunk/src/gpabackupop.c
   trunk/src/gpacontext.c
   trunk/src/gpaexportclipop.c
   trunk/src/gpaexportfileop.c
   trunk/src/gpaexportop.c
   trunk/src/gpaexportserverop.c
   trunk/src/gpafiledecryptop.c
   trunk/src/gpafileencryptop.c
   trunk/src/gpafileencryptop.h
   trunk/src/gpafileop.c
   trunk/src/gpafilesignop.c
   trunk/src/gpafileverifyop.c
   trunk/src/gpagenkeyadvop.c
   trunk/src/gpagenkeyop.c
   trunk/src/gpagenkeysimpleop.c
   trunk/src/gpaimportclipop.c
   trunk/src/gpaimportfileop.c
   trunk/src/gpaimportop.c
   trunk/src/gpaimportserverop.c
   trunk/src/gpakeydeleteop.c
   trunk/src/gpakeyexpireop.c
   trunk/src/gpakeyop.c
   trunk/src/gpakeypasswdop.c
   trunk/src/gpakeyselector.c
   trunk/src/gpakeysignop.c
   trunk/src/gpakeytrustop.c
   trunk/src/gpaoperation.c
   trunk/src/gpaoperation.h
   trunk/src/gpapastrings.c
   trunk/src/gpaprogressdlg.c
   trunk/src/gparecvkeydlg.c
   trunk/src/gpasubkeylist.c
   trunk/src/gpawidgets.c
   trunk/src/gpawindowkeeper.c
   trunk/src/gpawindowkeeper.h
   trunk/src/gpawizard.c
   trunk/src/gpgmeedit.c
   trunk/src/gpgmetools.c
   trunk/src/gtktools.c
   trunk/src/hidewnd.c
   trunk/src/icons.c
   trunk/src/keydeletedlg.c
   trunk/src/keyeditdlg.c
   trunk/src/keygendlg.c
   trunk/src/keygenwizard.c
   trunk/src/keyimpseldlg.c
   trunk/src/keylist.c
   trunk/src/keyring.c
   trunk/src/keyserver.c
   trunk/src/keysigndlg.c
   trunk/src/keytable.c
   trunk/src/options.c
   trunk/src/ownertrustdlg.c
   trunk/src/passwddlg.c
   trunk/src/qdchkpwd.c
   trunk/src/server_access.c
   trunk/src/settingsdlg.c
   trunk/src/siglist.c
   trunk/src/verifydlg.c
Log:
	* server.c: New.
	* w32-afunix.h, w32-afunix.c: New.  Taken from GnuPG.
	* gpa.c (main): Start the server.  New option --server.
	* gpa.h (gnupg_homedir): Declare it.  Add a bunch of convenience
	macros.
	* gpafileencryptop.c (gpa_file_encrypt_operation_new_for_server):
	New.
	(gpa_file_encrypt_operation_next)
	(gpa_file_encrypt_operation_done_cb) 
	(gpa_file_encrypt_operation_response_cb): Call server finish.
	* gpaoperation.c (PROP_SERVER_CTX): New property.
	(gpa_operation_set_property, gpa_operation_get_property): Set it.
	(gpa_operation_class_init): Define property.
	(gpa_operation_server_finish): New.

	* Makefile.am (AM_CFLAGS): Add assuan and gpg-error flags.
	(LDADD): Add assuan, gpg-error libs and NETLIBS

	Make sure that all file include config.h as the first header.
		      


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/ChangeLog	2007-09-27 10:32:38 UTC (rev 782)
@@ -1,3 +1,11 @@
+2007-09-27  Werner Koch  <wk at g10code.com>
+
+	* configure.ac (NETLIBS) [W32]: New.
+
+2007-09-26  Werner Koch  <wk at g10code.com>
+
+	* configure.ac: Add test for libassuan and gpg-error.
+
 2007-06-04  Marcus Brinkmann  <marcus at g10code.de>
 
 	* configure.ac (BUILD_REVISION): Invoke AC_GNU_SOURCE properly.

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/NEWS	2007-09-27 10:32:38 UTC (rev 782)
@@ -1,3 +1,9 @@
+Noteworthy changes in version 0.7.7
+------------------------------------------------
+
+ * Add basic UI server mode and option --server.
+
+
 Noteworthy changes in version 0.7.6 (2007-05-24)
 ------------------------------------------------
 

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/configure.ac	2007-09-27 10:32:38 UTC (rev 782)
@@ -1,7 +1,7 @@
 # configure.ac for GPA
 # Copyright (C) 2000, 2001  Werner Koch
 # Copyright (C) 2002, 2003, 2004  Miguel Coca
-# Copyright (C) 2005, 2006  g10 Code GmbH
+# Copyright (C) 2005, 2006, 2007  g10 Code GmbH
 # 
 # This file is part of GPA.
 # 
@@ -29,14 +29,21 @@
 # Remember to change the version number immediately *after* a release.
 # Set my_issvn to "yes" for non-released code.  Remember to run an
 # "svn up" and "autogen.sh --force" right before creating a distribution.
-m4_define(my_version, [0.7.6])
-m4_define(my_issvn, no)
+m4_define(my_version, [0.7.7])
+m4_define(my_issvn, yes)
 
 m4_define([svn_revision], m4_esyscmd([echo -n $((svn info 2>/dev/null \
           ||echo 'Revision: 0')|sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)]))
 AC_INIT([gpa], my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision]),
         [bug-gpa at gnupg.org])
 
+NEED_GPG_ERROR_VERSION=1.4
+NEED_LIBASSUAN_API=1
+NEED_LIBASSUAN_VERSION=1.0.4
+NEED_GPGME_API=1
+NEED_GPGME_VERSION=1.1.0
+
+
 AM_CONFIG_HEADER(config.h)
 AC_CONFIG_SRCDIR(src/gpa.c)
 AM_INIT_AUTOMAKE($PACKAGE_NAME, $PACKAGE_VERSION)
@@ -52,7 +59,11 @@
 AC_DEFINE_UNQUOTED(PACKAGE_BUGREPORT, "$PACKAGE_BUGREPORT",
                                       [address for reporting bugs])
 
+have_gpg_error=no
+have_gpgme=no
+have_libassuan=no
 
+
 # Generate extended version information
 if test "$have_w32_system" = yes; then
    BUILD_TIMESTAMP=`date --iso-8601=minutes`
@@ -71,6 +82,9 @@
 AC_GNU_SOURCE
 
 AH_BOTTOM([
+/* We don't want the old assuan codes anymore. */
+#define _ASSUAN_ONLY_GPG_ERRORS 1
+
 #include "gpadefs.h"
 ])
 
@@ -155,11 +169,16 @@
 dnl
 
 
-
 dnl
 dnl Checks for libraries
 dnl
+NETLIBS=
+if test "$have_w32_system" = yes; then
+   NETLIBS="${NETLIBS} -lws2_32"
+fi
+AC_SUBST(NETLIBS)
 
+
 AM_GNU_GETTEXT_VERSION(0.12.1)
 AM_GNU_GETTEXT(,[need-ngettext])
 
@@ -172,18 +191,35 @@
 dnl Where is the GTK+ toolkit
 AM_PATH_GTK_2_0(2.2.0,, AC_MSG_ERROR(Cannot find GTK+ 2.0))
 
+
 #
+# The GnuPG shared error codes library.
+#
+AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION",
+                  have_gpg_error=yes,have_gpg_error=no)
+AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_USER_4,
+          [The default error source for GPA.])
+
+#
+# Libassuan is the IPC library used for the server mode
+#
+AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_API:$NEED_LIBASSUAN_VERSION",
+                  have_libassuan=yes,have_libassuan=no)
+
+#
 # Depending on the OS we need to test for different versions of gpgme.
 #
 _AM_PATH_GPGME_CONFIG
 if test "$have_w32_system" = yes; then
-  AM_PATH_GPGME_GLIB([1:1.1.3],, AC_MSG_ERROR(Cannot find an up to date GPGME))
+  AM_PATH_GPGME_GLIB("$NEED_GPGME_API:$NEED_GPGME_VERSION",
+                     have_gpgme=yes,have_gpgme=no)
   GPGME_LIBS="$GPGME_GLIB_LIBS"
   GPGME_CFLAGS="$GPGME_GLIB_CFLAGS"
   AC_SUBST(GPGME_CFLAGS)
   AC_SUBST(GPGME_LIBS)
 else
-  AM_PATH_GPGME([1:1.1.3],, AC_MSG_ERROR(Cannot find an up to date GPGME))
+  AM_PATH_GPGME("$NEED_GPGME_API:$NEED_GPGME_VERSION",
+                have_gpgme=yes,have_gpgme=no)
 fi
 
 
@@ -260,6 +296,51 @@
 GPG=$GPG
 ]])
 
+
+#
+# Print errors here so that they are visible all
+# together and the user can acquire them all together.
+#
+die=no
+if test "$have_gpg_error" = "no"; then
+   die=yes
+   AC_MSG_NOTICE([[
+***  
+*** You need libgpg-error to build this program.
+**  This library is for example available at
+***   ftp://ftp.gnupg.org/pub/gcrypt/libgpg-error
+*** (at least version $NEED_GPG_ERROR_VERSION is required.)
+***]])
+fi
+if test "$have_gpgme" = "no"; then
+   die=yes
+   AC_MSG_NOTICE([[
+***  
+*** You need gpgme to build this program.
+**  This library is for example available at
+***   ftp://ftp.gnupg.org/gcrypt/gpgme/
+*** (at least version $NEED_GPGME_VERSION is required.)
+***]])
+fi
+if test "$have_libassuan" = "no"; then
+   die=yes
+   AC_MSG_NOTICE([[
+***
+*** You need libassuan to build this program.
+*** This library is for example available at
+***   ftp://ftp.gnupg.org/pub/gcrypt/libassuan/
+*** (at least version $NEED_LIBASSUAN_VERSION is required).
+***]])
+fi
+if test "$die" = "yes"; then
+    AC_MSG_ERROR([[
+***
+*** Required libraries not found. Please consult the above messages
+*** and install them before running configure again.
+***]])
+fi
+
+
 AC_CONFIG_FILES([ m4/Makefile 
 Makefile
 intl/Makefile
@@ -269,4 +350,4 @@
 ])
 
 
-AC_OUTPUT
\ No newline at end of file
+AC_OUTPUT

Modified: trunk/m4/Makefile.am
===================================================================
--- trunk/m4/Makefile.am	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/m4/Makefile.am	2007-09-27 10:32:38 UTC (rev 782)
@@ -2,5 +2,6 @@
       inttypes.m4 inttypes_h.m4 inttypes-pri.m4 isc-posix.m4 \
       lcmessage.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 \
       po.m4 progtest.m4 stdint_h.m4 uintmax_t.m4 ulonglong.m4 \
-      gpgme.m4 
+      gpgme.m4 gpg-error.m4 libassuan.m4
 
+

Added: trunk/m4/gpg-error.m4
===================================================================
--- trunk/m4/gpg-error.m4	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/m4/gpg-error.m4	2007-09-27 10:32:38 UTC (rev 782)
@@ -0,0 +1,65 @@
+# gpg-error.m4 - autoconf macro to detect libgpg-error.
+# Copyright (C) 2002, 2003, 2004 g10 Code GmbH
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This file is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION,
+dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
+dnl Test for libgpg-error and define GPG_ERROR_CFLAGS and GPG_ERROR_LIBS
+dnl
+AC_DEFUN([AM_PATH_GPG_ERROR],
+[ AC_ARG_WITH(gpg-error-prefix,
+            AC_HELP_STRING([--with-gpg-error-prefix=PFX],
+                           [prefix where GPG Error is installed (optional)]),
+     gpg_error_config_prefix="$withval", gpg_error_config_prefix="")
+  if test x$gpg_error_config_prefix != x ; then
+     if test x${GPG_ERROR_CONFIG+set} != xset ; then
+        GPG_ERROR_CONFIG=$gpg_error_config_prefix/bin/gpg-error-config
+     fi
+  fi
+
+  AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no)
+  min_gpg_error_version=ifelse([$1], ,0.0,$1)
+  AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version)
+  ok=no
+  if test "$GPG_ERROR_CONFIG" != "no" ; then
+    req_major=`echo $min_gpg_error_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
+    req_minor=`echo $min_gpg_error_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
+    gpg_error_config_version=`$GPG_ERROR_CONFIG $gpg_error_config_args --version`
+    major=`echo $gpg_error_config_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
+    minor=`echo $gpg_error_config_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
+    if test "$major" -gt "$req_major"; then
+        ok=yes
+    else 
+        if test "$major" -eq "$req_major"; then
+            if test "$minor" -ge "$req_minor"; then
+               ok=yes
+            fi
+        fi
+    fi
+  fi
+  if test $ok = yes; then
+    GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG $gpg_error_config_args --cflags`
+    GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG $gpg_error_config_args --libs`
+    AC_MSG_RESULT([yes ($gpg_error_config_version)])
+    ifelse([$2], , :, [$2])
+  else
+    GPG_ERROR_CFLAGS=""
+    GPG_ERROR_LIBS=""
+    AC_MSG_RESULT(no)
+    ifelse([$3], , :, [$3])
+  fi
+  AC_SUBST(GPG_ERROR_CFLAGS)
+  AC_SUBST(GPG_ERROR_LIBS)
+])
+

Added: trunk/m4/libassuan.m4
===================================================================
--- trunk/m4/libassuan.m4	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/m4/libassuan.m4	2007-09-27 10:32:38 UTC (rev 782)
@@ -0,0 +1,175 @@
+dnl Autoconf macros for libassuan
+dnl       Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl
+dnl This file is free software; as a special exception the author gives
+dnl unlimited permission to copy and/or distribute it, with or without
+dnl modifications, as long as this notice is preserved.
+dnl
+dnl This file is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+dnl
+dnl Common code used for libassuan detection [internal]
+dnl Returns ok set to yes or no.
+dnl
+AC_DEFUN([_AM_PATH_LIBASSUAN_COMMON],
+[ AC_ARG_WITH(libassuan-prefix,
+              AC_HELP_STRING([--with-libassuan-prefix=PFX],
+                             [prefix where LIBASSUAN is installed (optional)]),
+     libassuan_config_prefix="$withval", libassuan_config_prefix="")
+  if test x$libassuan_config_prefix != x ; then
+    libassuan_config_args="$libassuan_config_args --prefix=$libassuan_config_prefix"
+    if test x${LIBASSUAN_CONFIG+set} != xset ; then
+      LIBASSUAN_CONFIG=$libassuan_config_prefix/bin/libassuan-config
+    fi
+  fi
+  AC_PATH_PROG(LIBASSUAN_CONFIG, libassuan-config, no)
+
+  tmp=ifelse([$1], ,1:0.9.2,$1)
+  if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
+    req_libassuan_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
+    min_libassuan_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
+  else
+    req_libassuan_api=0
+    min_libassuan_version="$tmp"
+  fi
+
+  if test "$LIBASSUAN_CONFIG" != "no" ; then
+    libassuan_version=`$LIBASSUAN_CONFIG --version`
+  fi
+  libassuan_version_major=`echo $libassuan_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
+  libassuan_version_minor=`echo $libassuan_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
+  libassuan_version_micro=`echo $libassuan_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
+
+  AC_MSG_CHECKING(for LIBASSUAN ifelse([$2], ,,[$2 ])- version >= $min_libassuan_version)
+  ok=no
+  if test "$LIBASSUAN_CONFIG" != "no" ; then
+    ifelse([$2], ,,[if `$LIBASSUAN_CONFIG --thread=$2 2> /dev/null` ; then])
+    req_major=`echo $min_libassuan_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
+    req_minor=`echo $min_libassuan_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
+    req_micro=`echo $min_libassuan_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
+    if test "$libassuan_version_major" -gt "$req_major"; then
+        ok=yes
+    else 
+        if test "$libassuan_version_major" -eq "$req_major"; then
+            if test "$libassuan_version_minor" -gt "$req_minor"; then
+               ok=yes
+            else
+               if test "$libassuan_version_minor" -eq "$req_minor"; then
+                   if test "$libassuan_version_micro" -ge "$req_micro"; then
+                     ok=yes
+                   fi
+               fi
+            fi
+        fi
+    fi
+    ifelse([$2], ,,[fi])
+  fi
+
+  if test $ok = yes; then
+    AC_MSG_RESULT([yes ($libassuan_version)])
+  else
+    AC_MSG_RESULT(no)
+  fi
+
+  if test $ok = yes; then
+    if test "$req_libassuan_api" -gt 0 ; then
+      tmp=`$LIBASSUAN_CONFIG --api-version 2>/dev/null || echo 0`
+      if test "$tmp" -gt 0 ; then
+        AC_MSG_CHECKING([LIBASSUAN ifelse([$2], ,,[$2 ])API version])
+        if test "$req_libassuan_api" -eq "$tmp" ; then
+          AC_MSG_RESULT(okay)
+        else
+          ok=no
+          AC_MSG_RESULT([does not match.  want=$req_libassuan_api got=$tmp.])
+        fi
+      fi
+    fi
+  fi
+
+])
+
+dnl AM_CHECK_LIBASSUAN([MINIMUM-VERSION,
+dnl                    [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
+dnl Test whether libassuan has at least MINIMUM-VERSION. This is
+dnl used to test for features only available in newer versions.
+dnl
+AC_DEFUN([AM_CHECK_LIBASSUAN],
+[ _AM_PATH_LIBASSUAN_COMMON($1)
+  if test $ok = yes; then
+    ifelse([$2], , :, [$2])
+  else
+    ifelse([$3], , :, [$3])
+  fi
+])
+
+
+
+
+dnl AM_PATH_LIBASSUAN([MINIMUM-VERSION,
+dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
+dnl Test for libassuan and define LIBASSUAN_CFLAGS and LIBASSUAN_LIBS
+dnl
+AC_DEFUN([AM_PATH_LIBASSUAN],
+[ _AM_PATH_LIBASSUAN_COMMON($1)
+  if test $ok = yes; then
+    LIBASSUAN_CFLAGS=`$LIBASSUAN_CONFIG $libassuan_config_args --cflags`
+    LIBASSUAN_LIBS=`$LIBASSUAN_CONFIG $libassuan_config_args --libs`
+    ifelse([$2], , :, [$2])
+  else
+    LIBASSUAN_CFLAGS=""
+    LIBASSUAN_LIBS=""
+    ifelse([$3], , :, [$3])
+  fi
+  AC_SUBST(LIBASSUAN_CFLAGS)
+  AC_SUBST(LIBASSUAN_LIBS)
+])
+
+
+dnl AM_PATH_LIBASSUAN_PTH([MINIMUM-VERSION,
+dnl                      [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
+dnl Test for libassuan and define LIBASSUAN_PTH_CFLAGS and LIBASSUAN_PTH_LIBS
+dnl
+AC_DEFUN([AM_PATH_LIBASSUAN_PTH],
+[ _AM_PATH_LIBASSUAN_COMMON($1,pth)
+  if test $ok = yes; then
+    LIBASSUAN_PTH_CFLAGS=`$LIBASSUAN_CONFIG $libassuan_config_args --thread=pth --cflags`
+    LIBASSUAN_PTH_LIBS=`$LIBASSUAN_CONFIG $libassuan_config_args --thread=pth --libs`
+    ifelse([$2], , :, [$2])
+  else
+    LIBASSUAN_PTH_CFLAGS=""
+    LIBASSUAN_PTH_LIBS=""
+    ifelse([$3], , :, [$3])
+  fi
+  AC_SUBST(LIBASSUAN_PTH_CFLAGS)
+  AC_SUBST(LIBASSUAN_PTH_LIBS)
+])
+
+
+dnl AM_PATH_LIBASSUAN_PTHREAD([MINIMUM-VERSION,
+dnl                           [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
+dnl Test for libassuan and define LIBASSUAN_PTHREAD_CFLAGS 
+dnl                           and LIBASSUAN_PTHREAD_LIBS
+dnl
+AC_DEFUN([AM_PATH_LIBASSUAN_PTHREAD],
+[ _AM_PATH_LIBASSUAN_COMMON($1,pthread)
+  if test $ok = yes; then
+    LIBASSUAN_PTHREAD_CFLAGS=`$LIBASSUAN_CONFIG $libassuan_config_args --thread=pthread --cflags`
+    LIBASSUAN_PTHREAD_LIBS=`$LIBASSUAN_CONFIG $libassuan_config_args --thread=pthread --libs`
+    ifelse([$2], , :, [$2])
+  else
+    LIBASSUAN_PTHREAD_CFLAGS=""
+    LIBASSUAN_PTHREAD_LIBS=""
+    ifelse([$3], , :, [$3])
+  fi
+  AC_SUBST(LIBASSUAN_PTHREAD_CFLAGS)
+  AC_SUBST(LIBASSUAN_PTHREAD_LIBS)
+])
+

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/ChangeLog	2007-09-27 10:32:38 UTC (rev 782)
@@ -1,3 +1,25 @@
+2007-09-27  Werner Koch  <wk at g10code.com>
+
+	* server.c: New.
+	* w32-afunix.h, w32-afunix.c: New.  Taken from GnuPG.
+	* gpa.c (main): Start the server.  New option --server.
+	* gpa.h (gnupg_homedir): Declare it.  Add a bunch of convenience
+	macros.
+	* gpafileencryptop.c (gpa_file_encrypt_operation_new_for_server):
+	New.
+	(gpa_file_encrypt_operation_next)
+	(gpa_file_encrypt_operation_done_cb) 
+	(gpa_file_encrypt_operation_response_cb): Call server finish.
+	* gpaoperation.c (PROP_SERVER_CTX): New property.
+	(gpa_operation_set_property, gpa_operation_get_property): Set it.
+	(gpa_operation_class_init): Define property.
+	(gpa_operation_server_finish): New.
+
+	* Makefile.am (AM_CFLAGS): Add assuan and gpg-error flags.
+	(LDADD): Add assuan, gpg-error libs and NETLIBS
+
+	Make sure that all file include config.h as the first header.
+
 2007-05-24  Werner Koch  <wk at g10code.com>
 
 	* Makefile.am (.rc.o): Replace gmake style pattern rule.

Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/Makefile.am	2007-09-27 10:32:38 UTC (rev 782)
@@ -14,19 +14,22 @@
 
 gpa_res_ldflag = -Wl,gpa-resource.o
 gpa_deps = gpa-resource.o
+gpa_w32_sources = w32-afunix.c w32-afunix.h
 else
 gpa_res_ldflag =
 gpa_deps =
+gpa_w32_sources =
 endif
 
 
 bin_PROGRAMS = gpa
-noinst_PROGRAMS = dndtest
+noinst_PROGRAMS = dndtest confdialog
 
 AM_CPPFLAGS = -I$(top_srcdir)/intl -I$(top_srcdir)/pixmaps
-AM_CFLAGS = $(GPGME_CFLAGS) $(GTK_CFLAGS)
-LDADD = $(GPGME_LIBS) $(GTK_LIBS) $(LIBINTL)
-
+AM_CFLAGS = $(GPGME_CFLAGS) $(LIBASSUAN_CFLAGS) $(GPG_ERROR_CFLAGS) \
+	    $(GTK_CFLAGS)
+LDADD = $(GPGME_LIBS) $(LIBASSUAN_LIBS) $(GPG_ERROR_LIBS) \
+        $(GTK_LIBS) $(LIBINTL) $(NETLIBS)
 gpa_LDFLAGS = $(gpa_res_ldflag)
 gpa_DEPENDENCIES = $(gpa_deps)
 
@@ -92,11 +95,13 @@
 	      gpagenkeysimpleop.h gpagenkeysimpleop.c \
 	      gpabackupop.h gpabackupop.c \
 	      gpakeyselector.h gpakeyselector.c \
-	      options.c
+	      server.c \
+	      options.c $(gpa_w32_sources)
 
 
 dndtest_SOURCES = dndtest.c
 
+confdialog_SOURCES = confdialog.c
 
 
 

Modified: trunk/src/encryptdlg.c
===================================================================
--- trunk/src/encryptdlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/encryptdlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -20,6 +20,7 @@
  */
 
 #include <config.h>
+
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include <stdlib.h>

Modified: trunk/src/expirydlg.c
===================================================================
--- trunk/src/expirydlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/expirydlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -19,6 +19,7 @@
  */
 
 #include <config.h>
+
 #include <gpgme.h>
 #include <gtk/gtk.h>
 #include "gpa.h"

Modified: trunk/src/fileman.c
===================================================================
--- trunk/src/fileman.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/fileman.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -24,7 +24,6 @@
  *	The file encryption/decryption/sign window
  */
 
-#include "gpa.h"    /* Fixme - this does not belong here! */
 #include <config.h>
 
 #include <stdio.h>
@@ -38,6 +37,7 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 
+#include "gpa.h"   
 #include "gpapastrings.h"
 
 #include "gtktools.h"

Modified: trunk/src/gpa.c
===================================================================
--- trunk/src/gpa.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpa.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,9 +18,7 @@
    along with GPA; if not, write to the Free Software Foundation, Inc.,
    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-#if HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include <gtk/gtk.h>
 
@@ -349,6 +347,7 @@
 {
   gboolean start_keyring_editor;
   gboolean start_file_manager;
+  gboolean start_only_server;
   gchar *options_filename;
 } GpaCommandLineArgs;
 
@@ -358,6 +357,7 @@
   { "help", no_argument, NULL, 'h' },
   { "keyring", no_argument, NULL, 'k' },
   { "keymanager", no_argument, NULL, 'k' },
+  { "server", no_argument, NULL, 's' },
   { "files", no_argument, NULL, 'f' },
   { "options", required_argument, NULL, 'o' },
   { NULL, 0, NULL, 0 }
@@ -374,6 +374,7 @@
   {'v', "version", N_("output version information and exit")},
   {'k', "keyring", N_("open keyring editor (default)")},
   {'f', "files", N_("open filemanager")},
+  {'s', "server", N_("start only the UI server")},
   {'o', "options", N_("read options from file")},
   {0, NULL, NULL}
 };
@@ -438,6 +439,9 @@
         case 'f':
           args->start_file_manager = TRUE;
           break;
+        case 's':
+          args->start_only_server = TRUE;
+          break;
         default:
           exit (EXIT_FAILURE);
         }
@@ -457,7 +461,7 @@
 main (int argc, char **argv)
 {
   char *configname = NULL, *keyservers_configname = NULL;
-  GpaCommandLineArgs args = {FALSE, FALSE, NULL};
+  GpaCommandLineArgs args = {FALSE, FALSE, FALSE, NULL};
   int i;
   GError *err = NULL;
 
@@ -467,6 +471,7 @@
 
   parse_command_line (argc, argv, &args);
 
+
   /* Disable logging to prevent MS Windows NT from opening a console.
    */
   g_log_set_handler ("Glib", G_LOG_LEVEL_CRITICAL
@@ -554,25 +559,31 @@
   putenv ("OUTPUT_CHARSET=utf8");
 #endif
 
-  /* Don't open the keyring editor if any files are given on the command
-   * line */
-  if (args.start_keyring_editor && (optind >= argc))
+  /* Fire up the server.  */
+  gpa_start_server ();
+
+  if (!args.start_only_server)
     {
-      gpa_open_keyring_editor ();
-    }
+      /* Don't open the keyring editor if any files are given on the
+       * command line */
+      if (args.start_keyring_editor && (optind >= argc))
+        {
+          gpa_open_keyring_editor ();
+        }
   
-  if (args.start_file_manager || (optind < argc))
-    {
-      gpa_open_filemanager ();
-    }
+      if (args.start_file_manager || (optind < argc))
+        {
+          gpa_open_filemanager ();
+        }
 
-  /* If there are any command line arguments that are not options, try
-   * to open them as files in the filemanager */
-  for (i = optind; i < argc; i++)
-    {
-      gpa_file_manager_open_file (GPA_FILE_MANAGER
-				  (gpa_file_manager_get_instance ()),
-				  argv[i]);
+      /* If there are any command line arguments that are not options, try
+       * to open them as files in the filemanager */
+      for (i = optind; i < argc; i++)
+        {
+          gpa_file_manager_open_file (GPA_FILE_MANAGER
+                                      (gpa_file_manager_get_instance ()),
+                                      argv[i]);
+        }
     }
 
   gtk_main ();

Modified: trunk/src/gpa.h
===================================================================
--- trunk/src/gpa.h	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpa.h	2007-09-27 10:32:38 UTC (rev 782)
@@ -27,7 +27,8 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
-#include "config.h"
+#include <assuan.h>
+
 #include "gpadefs.h"
 #include "gpgmetools.h"
 #include "options.h"
@@ -49,6 +50,7 @@
 extern GtkWidget *global_windowMain;
 extern GtkWidget *global_windowTip;
 extern GList *global_defaultRecipients;
+extern gchar *gnupg_homedir;
 
 void gpa_open_keyring_editor (void);
 void gpa_open_filemanager (void);
@@ -58,6 +60,46 @@
 
 typedef void (*GPADefaultKeyChanged) (gpointer user_data);
 
+void gpa_run_server_continuation (assuan_context_t ctx, gpg_error_t err);
+void gpa_start_server (void);
 
+
+void gpa_show_backend_config (void);
+
+
+/*-- Convenience macros. -- */
+#define DIM(v)		     (sizeof(v)/sizeof((v)[0]))
+#define DIMof(type,member)   DIM(((type *)0)->member)
+
+/*-- Macros to replace ctype ones to avoid locale problems. --*/
+#define spacep(p)   (*(p) == ' ' || *(p) == '\t')
+#define digitp(p)   (*(p) >= '0' && *(p) <= '9')
+#define hexdigitp(a) (digitp (a)                     \
+                      || (*(a) >= 'A' && *(a) <= 'F')  \
+                      || (*(a) >= 'a' && *(a) <= 'f'))
+  /* Note this isn't identical to a C locale isspace() without \f and
+     \v, but works for the purposes used here. */
+#define ascii_isspace(a) ((a)==' ' || (a)=='\n' || (a)=='\r' || (a)=='\t')
+
+/* The atoi macros assume that the buffer has only valid digits. */
+#define atoi_1(p)   (*(p) - '0' )
+#define atoi_2(p)   ((atoi_1(p) * 10) + atoi_1((p)+1))
+#define atoi_4(p)   ((atoi_2(p) * 100) + atoi_2((p)+2))
+#define xtoi_1(p)   (*(p) <= '9'? (*(p)- '0'): \
+                     *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
+#define xtoi_2(p)   ((xtoi_1(p) * 16) + xtoi_1((p)+1))
+#define xtoi_4(p)   ((xtoi_2(p) * 256) + xtoi_2((p)+2))
+
+#define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A'))
+
+
+/*--  Error codes not yet available --*/
+#ifndef GPG_ERR_UNFINISHED
+#define GPG_ERR_UNFINISHED 199
+#endif
+#ifndef GPA_ERR_SOURCE_GPA
+#define GPA_ERR_SOURCE_GPA 12
+#endif
+
 #endif /*GPA_H */
 

Modified: trunk/src/gpabackupop.c
===================================================================
--- trunk/src/gpabackupop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpabackupop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,9 +18,7 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include <gpgme.h>
 #include "gpa.h"

Modified: trunk/src/gpacontext.c
===================================================================
--- trunk/src/gpacontext.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpacontext.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 #include <gpgme.h>
 #include "gpgmetools.h"

Modified: trunk/src/gpaexportclipop.c
===================================================================
--- trunk/src/gpaexportclipop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaexportclipop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include <unistd.h>
 #include "gpa.h"

Modified: trunk/src/gpaexportfileop.c
===================================================================
--- trunk/src/gpaexportfileop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaexportfileop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include <unistd.h>
 #include "gpa.h"

Modified: trunk/src/gpaexportop.c
===================================================================
--- trunk/src/gpaexportop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaexportop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include "gpa.h"
 #include "i18n.h"

Modified: trunk/src/gpaexportserverop.c
===================================================================
--- trunk/src/gpaexportserverop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaexportserverop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include <unistd.h>
 #include "gpa.h"

Modified: trunk/src/gpafiledecryptop.c
===================================================================
--- trunk/src/gpafiledecryptop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpafiledecryptop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 
 #ifdef G_OS_UNIX

Modified: trunk/src/gpafileencryptop.c
===================================================================
--- trunk/src/gpafileencryptop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpafileencryptop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 
 #ifdef G_OS_UNIX
@@ -57,7 +59,7 @@
   GpaFileEncryptOperation *op = GPA_FILE_ENCRYPT_OPERATION (object);
 
   /* FIXME: The use of RSET is messed up.  There is no clear concept
-     on who own the key.  This should be fixed by refing the keys
+     on who owns the key.  This should be fixed by refing the keys
      object.  I doubt that the keys are at all released. */
   g_free (op->rset);
   op->rset = NULL;
@@ -79,9 +81,10 @@
 }
 
 static GObject*
-gpa_file_encrypt_operation_constructor (GType type,
-					guint n_construct_properties,
-					GObjectConstructParam *construct_properties)
+gpa_file_encrypt_operation_constructor 
+	(GType type,
+         guint n_construct_properties,
+         GObjectConstructParam *construct_properties)
 {
   GObject *object;
   GpaFileEncryptOperation *op;
@@ -166,6 +169,21 @@
   return op;
 }
 
+
+GpaFileEncryptOperation*
+gpa_file_encrypt_operation_new_for_server (GList *files, void *server_ctx)
+{
+  GpaFileEncryptOperation *op;
+  
+  op = g_object_new (GPA_FILE_ENCRYPT_OPERATION_TYPE,
+		     "input_files", files,
+                     "server-ctx", server_ctx,
+		     NULL);
+
+  return op;
+}
+
+
 /* Internal */
 
 static gchar*
@@ -247,6 +265,7 @@
       !gpa_file_encrypt_operation_start (op, GPA_FILE_OPERATION (op)
 					 ->current->data))
     {
+      gpa_operation_server_finish (GPA_OPERATION (op), 0);
       g_signal_emit_by_name (GPA_OPERATION (op), "completed");
     }
 }
@@ -275,6 +294,7 @@
       unlink (op->cipher_filename);
       g_free (op->cipher_filename);
       op->cipher_filename = NULL;
+      gpa_operation_server_finish (GPA_OPERATION (op), err);
       g_signal_emit_by_name (GPA_OPERATION (op), "completed");
     }
   else
@@ -551,6 +571,8 @@
 	}
       else
 	{
+          gpa_operation_server_finish (GPA_OPERATION (op), 
+                                       gpg_error (GPG_ERR_GENERAL));
 	  g_signal_emit_by_name (GPA_OPERATION (op), "completed");
 	}
 
@@ -561,6 +583,8 @@
     {
       /* The dialog was canceled, so we do nothing and complete the
        * operation */
+      gpa_operation_server_finish (GPA_OPERATION (op), 
+                                   gpg_error (GPG_ERR_CANCELED));
       g_signal_emit_by_name (GPA_OPERATION (op), "completed");
     }
 }

Modified: trunk/src/gpafileencryptop.h
===================================================================
--- trunk/src/gpafileencryptop.h	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpafileencryptop.h	2007-09-27 10:32:38 UTC (rev 782)
@@ -26,19 +26,35 @@
 #include "gpafileop.h"
 
 /* GObject stuff */
-#define GPA_FILE_ENCRYPT_OPERATION_TYPE	  (gpa_file_encrypt_operation_get_type ())
-#define GPA_FILE_ENCRYPT_OPERATION(obj)	  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GPA_FILE_ENCRYPT_OPERATION_TYPE, GpaFileEncryptOperation))
-#define GPA_FILE_ENCRYPT_OPERATION_CLASS(klass)  (G_TYPE_CHECK_CLASS_CAST ((klass), GPA_FILE_ENCRYPT_OPERATION_TYPE, GpaFileEncryptOperationClass))
-#define GPA_IS_FILE_ENCRYPT_OPERATION(obj)	  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GPA_FILE_ENCRYPT_OPERATION_TYPE))
-#define GPA_IS_FILE_ENCRYPT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GPA_FILE_ENCRYPT_OPERATION_TYPE))
-#define GPA_FILE_ENCRYPT_OPERATION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GPA_FILE_ENCRYPT_OPERATION_TYPE, GpaFileEncryptOperationClass))
+#define GPA_FILE_ENCRYPT_OPERATION_TYPE	\
+          (gpa_file_encrypt_operation_get_type ())
 
+#define GPA_FILE_ENCRYPT_OPERATION(obj)	\
+          (G_TYPE_CHECK_INSTANCE_CAST   \
+            ((obj), GPA_FILE_ENCRYPT_OPERATION_TYPE, GpaFileEncryptOperation))
+
+#define GPA_FILE_ENCRYPT_OPERATION_CLASS(klass) \
+          (G_TYPE_CHECK_CLASS_CAST ((klass), GPA_FILE_ENCRYPT_OPERATION_TYPE, \
+                                    GpaFileEncryptOperationClass))
+
+#define GPA_IS_FILE_ENCRYPT_OPERATION(obj) \
+          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GPA_FILE_ENCRYPT_OPERATION_TYPE))
+
+#define GPA_IS_FILE_ENCRYPT_OPERATION_CLASS(klass) \
+          (G_TYPE_CHECK_CLASS_TYPE ((klass), GPA_FILE_ENCRYPT_OPERATION_TYPE))
+
+#define GPA_FILE_ENCRYPT_OPERATION_GET_CLASS(obj) \
+          (G_TYPE_INSTANCE_GET_CLASS ((obj), GPA_FILE_ENCRYPT_OPERATION_TYPE, \
+                                      GpaFileEncryptOperationClass))
+
 typedef struct _GpaFileEncryptOperation GpaFileEncryptOperation;
 typedef struct _GpaFileEncryptOperationClass GpaFileEncryptOperationClass;
 
-struct _GpaFileEncryptOperation {
+
+struct _GpaFileEncryptOperation 
+{
   GpaFileOperation parent;
-
+  
   GtkWidget *encrypt_dialog;
   gpgme_key_t *rset;
   int cipher_fd, plain_fd;
@@ -46,18 +62,23 @@
   gchar *cipher_filename;
 };
 
-struct _GpaFileEncryptOperationClass {
+
+struct _GpaFileEncryptOperationClass 
+{
   GpaFileOperationClass parent_class;
 };
 
+
 GType gpa_file_encrypt_operation_get_type (void) G_GNUC_CONST;
 
 /* API */
 
-/* Creates a new encryption operation.
- */
+/* Creates a new encryption operation. */
+GpaFileEncryptOperation *
+gpa_file_encrypt_operation_new (GtkWidget *window, GList *files);
+
+/* Create a new encryption operaion for the UI server.  */
 GpaFileEncryptOperation*
-gpa_file_encrypt_operation_new (GtkWidget *window,
-				GList *files);
+gpa_file_encrypt_operation_new_for_server (GList *files, void *server_ctx);
 
 #endif

Modified: trunk/src/gpafileop.c
===================================================================
--- trunk/src/gpafileop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpafileop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "i18n.h"
 #include "gtktools.h"
 #include "gpafileop.h"

Modified: trunk/src/gpafilesignop.c
===================================================================
--- trunk/src/gpafilesignop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpafilesignop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 
 #ifdef G_OS_UNIX

Modified: trunk/src/gpafileverifyop.c
===================================================================
--- trunk/src/gpafileverifyop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpafileverifyop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 
 #ifdef G_OS_UNIX

Modified: trunk/src/gpagenkeyadvop.c
===================================================================
--- trunk/src/gpagenkeyadvop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpagenkeyadvop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include "gpa.h"
 #include "i18n.h"

Modified: trunk/src/gpagenkeyop.c
===================================================================
--- trunk/src/gpagenkeyop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpagenkeyop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include "gpa.h"
 #include "i18n.h"

Modified: trunk/src/gpagenkeysimpleop.c
===================================================================
--- trunk/src/gpagenkeysimpleop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpagenkeysimpleop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include "gpa.h"
 #include "i18n.h"

Modified: trunk/src/gpaimportclipop.c
===================================================================
--- trunk/src/gpaimportclipop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaimportclipop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include <unistd.h>
 #include "gpa.h"

Modified: trunk/src/gpaimportfileop.c
===================================================================
--- trunk/src/gpaimportfileop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaimportfileop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include <unistd.h>
 #include "gpa.h"

Modified: trunk/src/gpaimportop.c
===================================================================
--- trunk/src/gpaimportop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaimportop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include "gpa.h"
 #include "i18n.h"

Modified: trunk/src/gpaimportserverop.c
===================================================================
--- trunk/src/gpaimportserverop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaimportserverop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gpgme.h>
 #include <unistd.h>
 #include "gpa.h"

Modified: trunk/src/gpakeydeleteop.c
===================================================================
--- trunk/src/gpakeydeleteop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpakeydeleteop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 
 #ifdef G_OS_UNIX

Modified: trunk/src/gpakeyexpireop.c
===================================================================
--- trunk/src/gpakeyexpireop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpakeyexpireop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 
 #ifdef G_OS_UNIX

Modified: trunk/src/gpakeyop.c
===================================================================
--- trunk/src/gpakeyop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpakeyop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "i18n.h"
 #include "gtktools.h"
 #include "gpakeyop.h"

Modified: trunk/src/gpakeypasswdop.c
===================================================================
--- trunk/src/gpakeypasswdop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpakeypasswdop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 
 #ifdef G_OS_UNIX

Modified: trunk/src/gpakeyselector.c
===================================================================
--- trunk/src/gpakeyselector.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpakeyselector.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,9 +18,7 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
-#if HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "gpa.h"
 #include "gpakeyselector.h"

Modified: trunk/src/gpakeysignop.c
===================================================================
--- trunk/src/gpakeysignop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpakeysignop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 
 #ifdef G_OS_UNIX

Modified: trunk/src/gpakeytrustop.c
===================================================================
--- trunk/src/gpakeytrustop.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpakeytrustop.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
 
 #ifdef G_OS_UNIX

Modified: trunk/src/gpaoperation.c
===================================================================
--- trunk/src/gpaoperation.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaoperation.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,12 +18,19 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "gpaoperation.h"
 #include <gtk/gtk.h>
 #include "gtktools.h"
 #include "gpgmetools.h"
 #include "i18n.h"
 
+#ifndef G_PARAM_STATIC_STRINGS
+#define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK \
+                                | G_PARAM_STATIC_BLURB)
+#endif
+
 /* Signals */
 enum
 {
@@ -36,6 +43,7 @@
 {
   PROP_0,
   PROP_WINDOW,
+  PROP_SERVER_CTX
 };
 
 static GObjectClass *parent_class = NULL;
@@ -54,6 +62,9 @@
     case PROP_WINDOW:
       g_value_set_object (value, op->window);
       break;
+    case PROP_SERVER_CTX:
+      g_value_set_pointer (value, op->server_ctx);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -73,6 +84,9 @@
     case PROP_WINDOW:
       op->window = (GtkWidget*) g_value_get_object (value);
       break;
+    case PROP_SERVER_CTX:
+      op->server_ctx = g_value_get_pointer (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -94,6 +108,7 @@
 {
   op->window = NULL;
   op->context = NULL;
+  op->server_ctx = NULL;
 }
 
 static GObject*
@@ -139,14 +154,20 @@
 		  g_cclosure_marshal_VOID__VOID,
 		  G_TYPE_NONE, 0);
   /* Properties */
-  g_object_class_install_property (object_class,
-				   PROP_WINDOW,
-				   g_param_spec_object 
-				   ("window", "Parent window",
-				    "Parent window", GTK_TYPE_WIDGET,
-				    G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property 
+    (object_class, PROP_WINDOW,
+     g_param_spec_object ("window", "Parent window",
+                          "Parent window",
+                          GTK_TYPE_WIDGET,
+                          G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property 
+    (object_class, PROP_SERVER_CTX,
+     g_param_spec_pointer ("server-ctx", "Server Context",
+                           "The Assuan context of the connection",
+                           G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS));
 }
 
+
 GType
 gpa_operation_get_type (void)
 {
@@ -187,3 +208,20 @@
 
   return gpa_context_busy (op->context);
 }
+
+
+/* Tell the UI-server that the current operation has finished with
+   error code ERR.  Note that the server context will be disabled
+   after this operation.  */
+void
+gpa_operation_server_finish (GpaOperation *op, gpg_error_t err)
+{
+  g_return_if_fail (op);
+  g_return_if_fail (GPA_IS_OPERATION (op));
+  if (op->server_ctx)
+    {
+      assuan_context_t ctx = op->server_ctx;
+      op->server_ctx = NULL;
+      gpa_run_server_continuation (ctx, err);
+    }
+}

Modified: trunk/src/gpaoperation.h
===================================================================
--- trunk/src/gpaoperation.h	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaoperation.h	2007-09-27 10:32:38 UTC (rev 782)
@@ -43,6 +43,7 @@
 
   GtkWidget *window;
   GpaContext *context;
+  void *server_ctx;
 };
 
 struct _GpaOperationClass {
@@ -54,11 +55,15 @@
 
 GType gpa_operation_get_type (void) G_GNUC_CONST;
 
-/* API */
+/*** API ***/
 
-/* Whether the operation is currently busy (i.e. gpg is running).
- */
-gboolean
-gpa_operation_busy (GpaOperation *op);
+/* Whether the operation is currently busy (i.e. gpg is running).  */
+gboolean gpa_operation_busy (GpaOperation *op);
 
+/* Tell the UI-server that the current operation has finished with
+   error code ERR.  Note that the server context will be disabled
+   after this operation. */
+void gpa_operation_server_finish (GpaOperation *op, gpg_error_t err);
+
+
 #endif

Modified: trunk/src/gpapastrings.c
===================================================================
--- trunk/src/gpapastrings.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpapastrings.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "gpa.h"
 #include <config.h>
 #include "gpapastrings.h"

Modified: trunk/src/gpaprogressdlg.c
===================================================================
--- trunk/src/gpaprogressdlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpaprogressdlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "gpaprogressdlg.h"
 #include "i18n.h"  
 

Modified: trunk/src/gparecvkeydlg.c
===================================================================
--- trunk/src/gparecvkeydlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gparecvkeydlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -19,6 +19,7 @@
  */
 
 #include <config.h>
+
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include <string.h>

Modified: trunk/src/gpasubkeylist.c
===================================================================
--- trunk/src/gpasubkeylist.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpasubkeylist.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "gpa.h"
 #include "gpasubkeylist.h"
 #include "gpapastrings.h"

Modified: trunk/src/gpawidgets.c
===================================================================
--- trunk/src/gpawidgets.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpawidgets.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -21,9 +21,7 @@
 /* Functions to construct a number of commonly used but GPA specific
    widgets.  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "gpa.h"
 #include <time.h>

Modified: trunk/src/gpawindowkeeper.c
===================================================================
--- trunk/src/gpawindowkeeper.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpawindowkeeper.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -19,6 +19,7 @@
  */
 
 #include <config.h>
+
 #include <glib.h>
 #include <gtk/gtk.h>
 #include "gpa.h"

Modified: trunk/src/gpawindowkeeper.h
===================================================================
--- trunk/src/gpawindowkeeper.h	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpawindowkeeper.h	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,7 +18,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
-#include <config.h>
+#ifndef GPAWINDOWKEEPER_H
+#define GPAWINDOWKEEPER_H
+
 #include <glib.h>
 #include <gtk/gtk.h>
 
@@ -35,3 +37,5 @@
 extern void gpa_windowKeeper_add_param (GpaWindowKeeper * keeper,
 					gpointer param);
 extern void gpa_windowKeeper_release (GpaWindowKeeper * keeper);
+
+#endif /*GPAWINDOWKEEPER*/

Modified: trunk/src/gpawizard.c
===================================================================
--- trunk/src/gpawizard.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpawizard.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -22,6 +22,8 @@
  * A simple general purpose Wizard implementation
  */
 
+#include <config.h>
+
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include "gpa.h"

Modified: trunk/src/gpgmeedit.c
===================================================================
--- trunk/src/gpgmeedit.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpgmeedit.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "gpgmeedit.h"
 #include "passwddlg.h"
 

Modified: trunk/src/gpgmetools.c
===================================================================
--- trunk/src/gpgmetools.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gpgmetools.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -21,9 +21,7 @@
 
 /* A set of auxiliary functions for common tasks related to GPGME */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include <errno.h>
 #include "gpa.h"

Modified: trunk/src/gtktools.c
===================================================================
--- trunk/src/gtktools.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/gtktools.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,11 +18,13 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
-#include "gpa.h"
 #include <config.h>
+
 #include <stdlib.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
+
+#include "gpa.h"
 #include "gtktools.h"
 #include "gpawindowkeeper.h"
 #include "icons.h"

Modified: trunk/src/hidewnd.c
===================================================================
--- trunk/src/hidewnd.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/hidewnd.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 /* This module is only used in this environment */
 #if defined(__MINGW32__) || defined(__CYGWIN__)
 #include <stdio.h>

Modified: trunk/src/icons.c
===================================================================
--- trunk/src/icons.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/icons.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gtk/gtk.h>
 #include <config.h>
 #include <stdio.h>

Modified: trunk/src/keydeletedlg.c
===================================================================
--- trunk/src/keydeletedlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keydeletedlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -19,6 +19,7 @@
  */
 
 #include <config.h>
+
 #include <gpgme.h>
 #include <gtk/gtk.h>
 #include "gpa.h"

Modified: trunk/src/keyeditdlg.c
===================================================================
--- trunk/src/keyeditdlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keyeditdlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -20,6 +20,7 @@
  */
 
 #include <config.h>
+
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include <time.h>

Modified: trunk/src/keygendlg.c
===================================================================
--- trunk/src/keygendlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keygendlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <gtk/gtk.h>
 #include "gpa.h"
 #include "gpapastrings.h"

Modified: trunk/src/keygenwizard.c
===================================================================
--- trunk/src/keygenwizard.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keygenwizard.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <sys/stat.h>
 #include <gtk/gtk.h>
 #include <errno.h>

Modified: trunk/src/keyimpseldlg.c
===================================================================
--- trunk/src/keyimpseldlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keyimpseldlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -19,6 +19,7 @@
  */
 
 #include <config.h>
+
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include <string.h>

Modified: trunk/src/keylist.c
===================================================================
--- trunk/src/keylist.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keylist.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,9 +18,7 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
-#if HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "gpa.h"
 #include "keylist.h"

Modified: trunk/src/keyring.c
===================================================================
--- trunk/src/keyring.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keyring.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,17 +18,15 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
-#if HAVE_CONFIG_H
 #include <config.h>
-#endif
 
-#include "gpa.h"
 #include <gpgme.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include "gpa.h"
 #include "gtktools.h"
 #include "icons.h"
 #include "helpmenu.h"

Modified: trunk/src/keyserver.c
===================================================================
--- trunk/src/keyserver.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keyserver.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,8 +18,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include <glib.h>
-#include <config.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>

Modified: trunk/src/keysigndlg.c
===================================================================
--- trunk/src/keysigndlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keysigndlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,9 +18,7 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
-#if HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>

Modified: trunk/src/keytable.c
===================================================================
--- trunk/src/keytable.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/keytable.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
+#include <config.h>
+
 #include <glib.h>
 #include <gtk/gtk.h>
 #include "gpa.h"

Modified: trunk/src/options.c
===================================================================
--- trunk/src/options.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/options.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
+#include <config.h>
+
 #include <glib.h>
 #include "options.h"
 #include "gpa.h"

Modified: trunk/src/ownertrustdlg.c
===================================================================
--- trunk/src/ownertrustdlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/ownertrustdlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -19,6 +19,7 @@
  */
 
 #include <config.h>
+
 #include <gpgme.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>

Modified: trunk/src/passwddlg.c
===================================================================
--- trunk/src/passwddlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/passwddlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "gpa.h"
 #include "passwddlg.h"
 #include "gtktools.h"

Modified: trunk/src/qdchkpwd.c
===================================================================
--- trunk/src/qdchkpwd.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/qdchkpwd.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -19,6 +19,8 @@
 
 /* Define MAIN if you want to generate a program instead of a library. */
 
+#include <config.h>
+
 #ifdef MAIN
 #include <stdio.h>
 #endif

Added: trunk/src/server.c
===================================================================
--- trunk/src/server.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/server.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -0,0 +1,523 @@
+/* server.c -  The UI server part of GPA.
+ * Copyright (C) 2007 g10 Code GmbH
+ *
+ * This file is part of GPA
+ *
+ * GPA 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GPA 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <errno.h>
+
+#include <gpgme.h>
+#include <glib.h>
+#include <assuan.h>
+
+#ifdef HAVE_W32_SYSTEM
+# include "w32-afunix.h"
+#else
+# include <sys/socket.h>
+# include <sys/un.h>
+#endif
+
+#include "gpa.h"
+#include "i18n.h"
+#include "gpafileencryptop.h"
+
+
+#ifdef HAVE_W32_SYSTEM
+#define myclosesock(a)  _w32_close ((a))
+#else
+#define myclosesock(a)  close ((a))
+#endif
+
+#define set_error(e,t) assuan_set_error (ctx, gpg_error (e), (t))
+
+
+/* The object used to keep track of the a connection's state.  */
+struct conn_ctrl_s;
+typedef struct conn_ctrl_s *conn_ctrl_t;
+struct conn_ctrl_s
+{
+  /* NULL or continuation function or a command.  */
+  void (*cont_cmd) (assuan_context_t, gpg_error_t);
+};
+
+
+
+
+/* Test whether LINE contains thye option NAME.  An optional argument
+   of the option is ignored.  For example with NAME being "--protocol"
+   this function returns true for "--protocol" as well as for
+   "--protocol=foo".  The returned pointer points right behind the
+   option name, which may be an equal sign, Nul or a space.  If tehre
+   is no option NAME, false (i.e. NULL) is returned.
+*/
+static const char *
+has_option_name (const char *line, const char *name)
+{
+  const char *s;
+  int n = strlen (name);
+
+  s = strstr (line, name);
+  return (s && (s == line || spacep (s-1))
+          && (!s[n] || spacep (s+n) || s[n] == '=')) ? (s+n) : NULL;
+}
+
+/* Check whether LINE coontains the option NAME.  */
+static int
+has_option (const char *line, const char *name)
+{
+  const char *s;
+  int n = strlen (name);
+  
+  s = strstr (line, name);
+  return (s && (s == line || spacep (s-1)) && (!s[n] || spacep (s+n)));
+}
+
+/* Skip over options. */
+static char *
+skip_options (char *line)
+{
+  while (spacep (line))
+    line++;
+  while ( *line == '-' && line[1] == '-' )
+    {
+      while (*line && !spacep (line))
+        line++;
+      while (spacep (line))
+        line++;
+    }
+  return line;
+}
+
+
+
+
+
+/* Continuation for cmd_encrypt.  */
+void
+cont_encrypt (assuan_context_t ctx, gpg_error_t err)
+{
+  conn_ctrl_t ctrl = assuan_get_pointer (ctx);
+
+  g_debug ("cont_encrypt called with with ERR=%s <%s>",
+           gpg_strerror (err), gpg_strsource (err));
+
+  assuan_process_done (ctx, err);
+}
+
+
+/* ENCRYPT --protocol=OPENPGP|CMS
+
+   Encrypt the data received on INPUT to OUTPUT.
+*/
+static int 
+cmd_encrypt (assuan_context_t ctx, char *line)
+{
+  conn_ctrl_t ctrl = assuan_get_pointer (ctx);
+  gpg_error_t err;
+  gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP;
+  int inp_fd, out_fd;
+
+  if (has_option (line, "--protocol=OpenPGP"))
+    ; /* This is the default.  */
+  else if (has_option (line, "--protocol=CMS"))
+    protocol = GPGME_PROTOCOL_CMS;
+  else  if (has_option_name (line, "--protocol"))
+    {
+      err = set_error (GPG_ERR_ASS_PARAMETER, "invalid protocol");
+      goto leave;
+    }
+  
+  line = skip_options (line);
+  if (*line)
+    {
+      err = set_error (GPG_ERR_ASS_SYNTAX, NULL);
+      goto leave;
+    }
+
+/*   inp_fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0); */
+/*   if (inp_fd == -1) */
+/*     { */
+/*       err = set_error (GPG_ERR_ASS_NO_INPUT, NULL); */
+/*       goto leave; */
+/*     } */
+/*   out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1); */
+/*   if (out_fd == -1) */
+/*     { */
+/*       err = set_error (GPG_ERR_ASS_NO_OUTPUT, NULL); */
+/*       goto leave; */
+/*     } */
+
+  ctrl->cont_cmd = cont_encrypt;
+  {
+    GList *files = g_list_append (NULL, g_strdup ("test.txt"));
+    GpaFileEncryptOperation *op;
+
+    op = gpa_file_encrypt_operation_new_for_server (files, ctx);
+    g_signal_connect (G_OBJECT (op), "completed",
+                      G_CALLBACK (g_object_unref), NULL);
+  }
+  return gpg_error (GPG_ERR_UNFINISHED);
+
+ leave:
+  assuan_close_input_fd (ctx);
+  assuan_close_output_fd (ctx);
+  return assuan_process_done (ctx, err);
+}
+
+
+
+
+/* GETINFO <what>
+
+   Multipurpose function to return a variety of information.
+   Supported values for WHAT are:
+
+     version     - Return the version of the program.
+ */
+static int
+cmd_getinfo (assuan_context_t ctx, char *line)
+{
+  gpg_error_t err;
+
+  if (!strcmp (line, "version"))
+    {
+      const char *s = PACKAGE_NAME " " PACKAGE_VERSION;
+      err = assuan_send_data (ctx, s, strlen (s));
+    }
+  else
+    err = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT");
+
+  return assuan_process_done (ctx, err);
+}
+
+
+
+
+/* Tell the assuan library about our commands.   */
+static int
+register_commands (assuan_context_t ctx)
+{
+  static struct {
+    const char *name;
+    int (*handler)(assuan_context_t, char *line);
+  } table[] = {
+    { "ENCRYPT",        cmd_encrypt },
+    { "GETINFO",        cmd_getinfo },
+    { NULL }
+  };
+  int i, rc;
+
+  for (i=0; table[i].name; i++)
+    {
+      rc = assuan_register_command (ctx, table[i].name, table[i].handler);
+      if (rc)
+        return rc;
+    } 
+
+  return 0;
+}
+
+
+/* Prepare for a new connection on descriptor FD.  */
+static assuan_context_t
+connection_startup (int fd)
+{
+  gpg_error_t err;
+  assuan_context_t ctx;
+  conn_ctrl_t ctrl;
+
+  /* Get an assuan context for the already accepted file descriptor
+     FD.  */
+  err = assuan_init_socket_server_ext (&ctx, fd, 2);
+  if (err)
+    {
+      g_debug ("failed to initialize the new connection: %s",
+               gpg_strerror (err));
+      return NULL;
+    }
+  err = register_commands (ctx);
+  if (err)
+    {
+      g_debug ("failed to register commands with Assuan: %s",
+               gpg_strerror (err));
+      assuan_deinit_server (ctx);
+      return NULL;
+    }
+
+  ctrl = g_malloc0 (sizeof *ctrl);
+  assuan_set_pointer (ctx, ctrl);
+  assuan_set_log_stream (ctx, stderr);
+
+  return ctx;
+}
+
+
+/* Finish a connection.  This releases all resources and needs to be
+   called becore the file descriptor is closed.  */
+static void
+connection_finish (assuan_context_t ctx)
+{
+  if (ctx)
+    {
+      conn_ctrl_t ctrl = assuan_get_pointer (ctx);
+      
+      assuan_deinit_server (ctx);
+      g_free (ctrl);
+    }
+}
+
+
+/* If the assuan context CTX has a registered continuation function,
+   run it.  */
+void
+gpa_run_server_continuation (assuan_context_t ctx, gpg_error_t err)
+{
+  conn_ctrl_t ctrl = assuan_get_pointer (ctx);
+  void (*cont_cmd) (assuan_context_t, gpg_error_t);
+
+  if (!ctrl)
+    {
+      g_debug ("no context in gpa_run_server_continuation");
+      return;
+    }
+  if (!ctrl->cont_cmd)
+    {
+      g_debug ("no continuation in gpa_run_server_continuation");
+      return;
+    }
+  cont_cmd = ctrl->cont_cmd;
+  ctrl->cont_cmd = NULL;
+  g_debug ("calling gpa_run_server_continuation (%s)", gpg_strerror (err));
+  cont_cmd (ctx, err);
+  g_debug ("leaving gpa_run_server_continuation");
+}
+
+
+/* This function is called by the main event loop if data can be read
+   from the status channel.  */
+static gboolean 
+receive_cb (GIOChannel *channel, GIOCondition condition, void *data)
+{
+  assuan_context_t ctx = data;
+  conn_ctrl_t ctrl = assuan_get_pointer (ctx);
+  gpg_error_t err;
+
+  assert (ctrl);
+  if (condition & G_IO_IN)
+    {
+      g_debug ("receive_cb");
+      if (ctrl->cont_cmd)
+        {
+          g_debug ("  input received while waiting for continuation");
+          g_usleep (2000000);
+        }
+      else
+        {
+          err = assuan_process_next (ctx);
+          g_debug ("assuan_process_next returned: %s",
+                   err == -1? "EOF": gpg_strerror (err));
+          if (gpg_err_code (err) == GPG_ERR_EOF || err == -1)
+            {
+              connection_finish (ctx);
+              /* FIXME: what about the socket? */
+              return FALSE; /* Remove from the watch.  */
+            }
+          else if (gpg_err_code (err) == GPG_ERR_UNFINISHED
+                   && !ctrl->cont_cmd)
+            {
+              /* It is quite possible that some other subsystem
+                 retruns that erro code.  Note the user about this
+                 curiosity.  */
+              g_debug ("note: Unfinished error code not emitted by us");
+            }
+        }
+    }
+  return TRUE;
+}
+
+
+/* This function is called by the main event loop if the listen fd is
+   readable.  The function runs the accept and prepares the
+   connection.  */
+static gboolean 
+accept_connection_cb (GIOChannel *listen_channel, 
+                      GIOCondition condition, void *data)
+{
+  gpg_error_t err;
+  int listen_fd, fd;
+  struct sockaddr_un paddr;
+  socklen_t plen = sizeof paddr;
+  assuan_context_t ctx;
+  GIOChannel *channel;
+  unsigned int source_id;
+
+  g_debug ("new connection request");
+#ifdef HAVE_W32_SYSTEM
+  listen_fd = g_io_channel_win32_get_fd (listen_channel);
+#else
+  listen_fd = g_io_channel_unix_get_fd (listen_channel);
+#endif
+  fd = accept (listen_fd, (struct sockaddr *)&paddr, &plen);
+  if (fd == -1)
+    {
+      g_debug ("error accepting connection: %s", strerror (errno));
+      goto leave;
+    }
+
+  g_debug ("new connection at fd %d", fd);
+  ctx = connection_startup (fd);
+  if (!ctx)
+    goto leave;
+
+#ifdef HAVE_W32_SYSTEM
+  channel = g_io_channel_win32_new_socket (fd);
+#else
+  channel = g_io_channel_unix_new (fd);
+#endif
+  if (!channel)
+    {
+      g_debug ("error creating a channel for fd %d\n", fd);
+      goto leave;
+    }
+  g_io_channel_set_encoding (channel, NULL, NULL);
+  g_io_channel_set_buffered (channel, FALSE);
+
+  source_id = g_io_add_watch (channel, G_IO_IN, receive_cb, ctx);
+  if (!source_id)
+    {
+      g_debug ("error creating watch for fd %d", fd);
+      g_io_channel_shutdown (channel, 0, NULL);
+      goto leave;
+    }
+  err = assuan_accept (ctx);
+  if (err)
+    {
+      g_debug ("assuan accept failed: %s", gpg_strerror (err));
+      g_io_channel_shutdown (channel, 0, NULL);
+      goto leave;
+    }
+  g_debug ("connection at fd %d ready", fd);
+  fd = -1;
+
+ leave:
+  if (fd != -1)
+    myclosesock (fd);
+  return TRUE; /* Keep the listen_fd in the event loop.  */
+}
+
+
+
+/* Startup the server.  */
+void
+gpa_start_server (void)
+{
+  char *socket_name;
+  int rc;
+  int fd;
+  struct sockaddr_un serv_addr;
+  socklen_t serv_addr_len = sizeof serv_addr;
+  GIOChannel *channel;
+  unsigned int source_id;
+  
+  socket_name = g_build_filename (gnupg_homedir, "S.uiserver", NULL);
+  if (strlen (socket_name)+1 >= sizeof serv_addr.sun_path ) 
+    {
+      g_debug ("name of socket too long\n");
+      g_free (socket_name);
+      return;
+    }
+    
+#ifdef HAVE_W32_SYSTEM
+  fd = _w32_sock_new (AF_UNIX, SOCK_STREAM, 0);
+#else
+  fd = socket (AF_UNIX, SOCK_STREAM, 0);
+#endif
+  if (fd == -1)
+    {
+      g_debug ("can't create socket: %s\n", strerror(errno));
+      g_free (socket_name);
+      return;
+    }
+
+  memset (&serv_addr, 0, sizeof serv_addr);
+  serv_addr.sun_family = AF_UNIX;
+  strcpy (serv_addr.sun_path, socket_name);
+  serv_addr_len = (offsetof (struct sockaddr_un, sun_path)
+                   + strlen(serv_addr.sun_path) + 1);
+
+#ifdef HAVE_W32_SYSTEM
+  rc = _w32_sock_bind (fd, (struct sockaddr*) &serv_addr, serv_addr_len);
+  if (rc == -1 && errno == WSAEADDRINUSE)
+    {
+      remove (socket_name);
+      rc = _w32_sock_bind (fd, (struct sockaddr*) &serv_addr, serv_addr_len);
+    }
+#else
+  rc = bind (fd, (struct sockaddr*)&serv_addr, serv_addr_len);
+  if (rc == -1 && errno == EADDRINUSE)
+    {
+      remove (socket_name);
+      rc = bind (fd, (struct sockaddr*)&serv_addr, serv_addr_len);
+    }
+#endif
+  if (rc == -1)
+    {
+      g_debug ("error binding socket to `%s': %s\n",
+               serv_addr.sun_path, strerror (errno) );
+      myclosesock (fd);
+      g_free (socket_name);
+      return;
+    }
+  g_free (socket_name);
+  socket_name = NULL;
+
+  if (listen (fd, 5) == -1)
+    {
+      g_debug ("listen() failed: %s\n", strerror (errno));
+      myclosesock (fd);
+      return;
+    }
+
+#ifdef HAVE_W32_SYSTEM
+  channel = g_io_channel_win32_new_socket (fd);
+#else
+  channel = g_io_channel_unix_new (fd);
+#endif
+  if (!channel)
+    {
+      g_debug ("error creating a new listening channel\n");
+      myclosesock (fd);
+      return;
+    }
+  g_io_channel_set_encoding (channel, NULL, NULL);
+  g_io_channel_set_buffered (channel, FALSE);
+
+  source_id = g_io_add_watch (channel, G_IO_IN, accept_connection_cb, NULL);
+  if (!source_id)
+    {
+      g_debug ("error creating watch for listening channel\n");
+      g_io_channel_shutdown (channel, 0, NULL);
+      myclosesock (fd);
+      return;
+    }
+
+}

Modified: trunk/src/server_access.c
===================================================================
--- trunk/src/server_access.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/server_access.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,9 +18,7 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
-#if HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "gpa.h"
 #include <glib.h>

Modified: trunk/src/settingsdlg.c
===================================================================
--- trunk/src/settingsdlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/settingsdlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "gpa.h"
 #include "settingsdlg.h"
 #include "gpakeyselector.h"

Modified: trunk/src/siglist.c
===================================================================
--- trunk/src/siglist.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/siglist.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include <config.h>
+
 #include "gpa.h"
 #include <stdlib.h>
 #include <string.h>

Modified: trunk/src/verifydlg.c
===================================================================
--- trunk/src/verifydlg.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/verifydlg.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -18,9 +18,7 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
-#if HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>

Added: trunk/src/w32-afunix.c
===================================================================
--- trunk/src/w32-afunix.c	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/w32-afunix.c	2007-09-27 10:32:38 UTC (rev 782)
@@ -0,0 +1,151 @@
+/* w32-afunix.c - AF_UNIX emulation for Windows.
+ * Copyright (C) 2004, 2006 g10 Code GmbH
+ *
+ * This file is part of JNLIB.
+ *
+ * JNLIB is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * JNLIB 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef _WIN32
+#include <config.h>
+
+#include <stdio.h>
+#include <windows.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <io.h>
+#include <errno.h>
+
+#include "w32-afunix.h"
+
+#ifndef S_IRGRP
+# define S_IRGRP 0
+# define S_IWGRP 0
+#endif
+
+
+int
+_w32_close (int fd)
+{
+  int rc = closesocket (fd);
+  if (rc && WSAGetLastError () == WSAENOTSOCK)
+      rc = close (fd);
+  return rc;
+}
+
+
+int
+_w32_sock_new (int domain, int type, int proto)
+{
+  if (domain == AF_UNIX || domain == AF_LOCAL)
+    domain = AF_INET;
+  return socket (domain, type, proto);
+}
+
+
+int
+_w32_sock_connect (int sockfd, struct sockaddr * addr, int addrlen)
+{
+  struct sockaddr_in myaddr;
+  struct sockaddr_un * unaddr;
+  FILE * fp;
+  int port;
+  
+  unaddr = (struct sockaddr_un *)addr;
+  fp = fopen (unaddr->sun_path, "rb");
+  if (!fp)
+    return -1;
+  fscanf (fp, "%d", &port);
+  fclose (fp);
+
+  if (port < 0 || port > 65535)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+  
+  myaddr.sin_family = AF_INET;
+  myaddr.sin_port = port; 
+  myaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+
+  /* we need this later. */
+  unaddr->sun_family = myaddr.sin_family;
+  unaddr->sun_port = myaddr.sin_port;
+  unaddr->sun_addr.s_addr = myaddr.sin_addr.s_addr;
+  
+  return connect (sockfd, (struct sockaddr *)&myaddr, sizeof myaddr);
+}
+
+
+int
+_w32_sock_bind (int sockfd, struct sockaddr *addr, int addrlen)
+{
+  if (addr->sa_family == AF_LOCAL || addr->sa_family == AF_UNIX)
+    {
+      struct sockaddr_in myaddr;
+      struct sockaddr_un *unaddr;
+      int filefd;
+      FILE *fp;
+      int len = sizeof myaddr;
+      int rc;
+
+      unaddr = (struct sockaddr_un *)addr;
+
+      myaddr.sin_port = 0;
+      myaddr.sin_family = AF_INET;
+      myaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+
+      filefd = open (unaddr->sun_path, 
+                     (O_WRONLY|O_CREAT|O_EXCL|O_BINARY), 
+                     (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP));
+      if (filefd == -1)
+        {
+          if (errno == EEXIST)
+            errno = WSAEADDRINUSE;
+          return -1;
+        }
+      fp = fdopen (filefd, "wb");
+      if (!fp)
+        { 
+          int save_e = errno;
+          close (filefd);
+          errno = save_e;
+          return -1;
+        }
+
+      rc = bind (sockfd, (struct sockaddr *)&myaddr, len);
+      if (!rc)
+        rc = getsockname (sockfd, (struct sockaddr *)&myaddr, &len);
+      if (rc)
+        {
+          int save_e = errno;
+          fclose (fp);
+          remove (unaddr->sun_path);
+          errno = save_e;
+          return rc;
+        }
+      fprintf (fp, "%d", myaddr.sin_port);
+      fclose (fp);
+
+      /* The caller expects these values. */
+      unaddr->sun_family = myaddr.sin_family;
+      unaddr->sun_port = myaddr.sin_port;
+      unaddr->sun_addr.s_addr = myaddr.sin_addr.s_addr;
+      
+      return 0;
+    }
+  return bind (sockfd, addr, addrlen);
+}
+
+#endif /*_WIN32*/

Added: trunk/src/w32-afunix.h
===================================================================
--- trunk/src/w32-afunix.h	2007-06-05 13:30:02 UTC (rev 781)
+++ trunk/src/w32-afunix.h	2007-09-27 10:32:38 UTC (rev 782)
@@ -0,0 +1,48 @@
+/* w32-afunix.h - AF_UNIX emulation for Windows
+ *	Copyright (C) 2004, 2006 g10 Code GmbH
+ *
+ * This file is part of JNLIB.
+ *
+ * JNLIB is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * JNLIB 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef _WIN32
+#ifndef W32AFUNIX_DEFS_H
+#define W32AFUNIX_DEFS_H
+
+#include <sys/types.h>
+#include <windows.h>
+#include <ws2tcpip.h>
+#include <unistd.h>
+
+#define DIRSEP_C '\\'
+
+#define AF_LOCAL AF_UNIX
+/* We need to prefix the structure with a sockaddr_in header so we can
+   use it later for sendto and recvfrom. */
+struct sockaddr_un
+{
+  short          sun_family;
+  unsigned short sun_port;
+  struct         in_addr sun_addr;
+  char           sun_path[108-2-4]; /* Path name.  */
+};
+
+int _w32_close (int fd);
+int _w32_sock_new (int domain, int type, int proto);
+int _w32_sock_bind (int sockfd, struct sockaddr *addr, int addrlen);
+int _w32_sock_connect (int sockfd, struct sockaddr *addr, int addrlen);
+
+#endif /*W32AFUNIX_DEFS_H*/
+#endif /*_WIN32*/



More information about the Gpa-commits mailing list