gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libfints] branch master updated: Changing the API..


From: gnunet
Subject: [GNUnet-SVN] [libfints] branch master updated: Changing the API..
Date: Wed, 10 Oct 2018 14:57:15 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository libfints.

The following commit(s) were added to refs/heads/master by this push:
     new aa081a5  Changing the API..
aa081a5 is described below

commit aa081a599183af675d6ab993e8d5f654a480470d
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Oct 10 14:51:37 2018 +0200

    Changing the API..
    
    The current change gets a global allocated
    pool of XML "base" documents - the "genex" ones -,
    and each lib function that generates a particular
    message (INI/HIA/..) can now copy one document
    from the pool and instantiate it with values of
    the case.
    
    As a consequence, each message generator will
    NOT have the output document among its parameters
    anymore.
    
    This commit gets JUST the new code compiled
    but NOT tested.
---
 src/Makefile.am |  63 ++++++++--------
 src/libebics.c  | 223 ++++++++++++++++++++++++++++++++++++++++++--------------
 src/libebics.h  |  27 +++++--
 src/tests.c     |  43 +++++++++++
 src/xmlproto.c  |  15 +---
 src/xmlproto.h  |  16 ++--
 6 files changed, 280 insertions(+), 107 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 1f4dcd9..14c42eb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,33 +1,34 @@
 # This Makefile.am is in the public domain
 
-SUBDIRS = . include tests_xmlproto
-
-#lib_LTLIBRARIES = libfints_messages.la
-
-#libfints_messages_la_SOURCES = libfints_messages.c
-#libfints_messages_la_LIBADD = -lxml2
-
-bin_PROGRAMS = curlproto message_dump 
-#xmlproto_SOURCES = \
-#                 util.c \
-#                 xmlproto.c \
-#                 xmlmessages.c  \
-#                 xmlproto_test_base.c
-#
-#xmlproto_LDADD = $(XML_LIBS) $(XMLSEC1_LIBS) $(LIBGCRYPT_LIBS) $(GNUTLS_LIBS) 
$(ZLIB_LIBS)
-#xmlproto_CPPFLAGS = $(XML_CPPFLAGS) $(XMLSEC1_CFLAGS) $(LIBGCRYPT_CFLAGS) 
$(GNUTLS_CFLAGS) $(ZLIB_CFLAGS)
-
-curlproto_SOURCES = \
-                   curlproto.c
-curlproto_LDADD = $(LIBCURL)
-curlproto_CPPFLAGS = $(LIBCURL_CPPFLAGS)
-
-message_dump_SOURCES = \
-                  util.c \
-                  xmlproto.c \
-                  xmlmessages.c  \
-                  libebics.c \
-                  message_dump.c
-
-message_dump_LDADD = $(XML_LIBS) $(XMLSEC1_LIBS) $(LIBGCRYPT_LIBS) 
$(GNUTLS_LIBS) $(ZLIB_LIBS)
-message_dump_CPPFLAGS = -Wall $(XML_CPPFLAGS) $(XMLSEC1_CFLAGS) 
$(LIBGCRYPT_CFLAGS) $(GNUTLS_CFLAGS) $(ZLIB_CFLAGS)
+SUBDIRS = . include
+
+lib_LTLIBRARIES = \
+  libebics.la 
+
+libebics_la_LDFLAGS = \
+  -version-info 2:0:0 \
+  -no-undefined
+
+libebics_la_SOURCES = \
+  libebics.c
+
+libebics_la_LIBADD = \
+  $(XML_LIBS) \
+  $(XMLSEC1_LIBS) \
+  $(LIBGCRYPT_LIBS) \
+  $(GNUTLS_LIBS) \
+  $(ZLIB_LIBS) \
+  $(XLIB)
+
+libebics_CPPFLAGS = \
+  $(XML_CPPFLAGS) \
+  $(XMLSEC1_CFLAGS) \
+  $(LIBGCRYPT_CFLAGS) \
+  $(GNUTLS_CFLAGS) \
+  $(ZLIB_CFLAGS)
+
+check_PROGRAMS = tests
+TESTS = $(check_PROGRAMS)
+
+tests_SOURCES = tests.c
+tests_LDADD = libebics.la
diff --git a/src/libebics.c b/src/libebics.c
index 4cae228..c6106f0 100644
--- a/src/libebics.c
+++ b/src/libebics.c
@@ -1,17 +1,20 @@
-/*
-  This file is part of libfints
-
-  libfints 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, or (at your option) any later version.
-
-  libfints 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
-  libfints; see the file COPYING.  If not, If not, see 
<http://www.gnu.org/license>
-*/
+/**
+ * This file is part of libebics
+ *
+ * libfints 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,
+ * or (at your option) any later version.
+ *
+ * libebics 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 libebics; see the file COPYING.
+ * If not, see <http://www.gnu.org/license>
+ */
 
 #include "util.h"
 #include "xmlmessages.h"
@@ -25,10 +28,25 @@
 #include <fts.h>
 #include <zlib.h>
 #include "libebics.h"
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
 
 #define LOG(level,...) EBICS_util_log_from (__LINE__,__FILE__,__func__,level, 
"libebics",__VA_ARGS__)
 
 
+/**
+ * List of (persistent) XML templates.
+ */
+static
+struct EBICS_genex_document genexList[EBICS_GENEX_MAX_ENTRIES];
+
+
+/**
+ * List of (persistent) key material.
+ */
+static
+struct EBICS_Key keyList[EBICS_KEY_MAX_ENTRIES];
+
 
 /**
  * Utility log function.
@@ -194,7 +212,6 @@ free_libxmlsec ()
   RETURNIFERROR (xmlSecGnuTLSShutdown);
   RETURNIFERROR (xmlSecGnuTLSAppShutdown);
   RETURNIFERROR (xmlSecCryptoShutdown);
-  RETURNIFERROR (xmlSecGnuTLSCryptoAppShutdown);
   RETURNIFERROR (xmlSecShutdown);
 
 #ifndef XMLSEC_NO_XSLT
@@ -238,7 +255,7 @@ free_zlib ()
 int
 EBICS_init_keymaterial (struct EBICS_Key keyList[],
                         char *keyDir,
-                        char *keyFiles[])
+                        const char *keyFiles[])
 {
   LOG (EBICS_LOGLEVEL_DEBUG, "Initializing key material\n");
 
@@ -341,9 +358,10 @@ EBICS_free_keymaterial (struct EBICS_Key keyList[])
  * @returns EBICS_SUCCESS on success, else EBICS_ERROR.
  */
 int
-EBICS_init_genex_documents(struct EBICS_genex_document genexList[],
-                           const char *genex_schemas_dir,
-                           const char *genexFiles[])
+EBICS_init_genex_documents
+  (struct EBICS_genex_document genexList[],
+   const char *genex_schemas_dir,
+   const char *genexFiles[])
 {
   LOG (EBICS_LOGLEVEL_DEBUG, "Initializing 'genex_documents'");
 
@@ -404,30 +422,83 @@ EBICS_free_genex_documents (struct EBICS_genex_document 
genexList[])
 }
   
 
+
+/**
+ * Initializes Libebics.  Init all the dependencies,
+ * as well as it allocates the "genex" templates to
+ * be copied and instantiated during the library life.
+ *
+ * @return EBICS_SUCCESS or EBICS_ERROR.
+ */
 int
 EBICS_init_library ()
 {
   int retv;
+  char *data_dir;
+
+  const char *genexFilenames[EBICS_GENEX_MAX_ENTRIES] = {
+    "ebicsRequest.xml", 
+    "SignaturePubKeyOrderData.xml", 
+    "HIARequestOrderData.xml",
+    "ebicsUnsecuredRequest.xml", 
+    "ebicsNoPubKeyDigestsRequest.xml",
+    NULL};
+  const char *keyFilenames[EBICS_KEY_MAX_ENTRIES] = {
+    "userAuthKey",
+    "userEncKey",
+    "userSigKey",
+    "bankAuthKey",
+    "bankEncKey",
+    "bankSigKey"};
 
   xmlInitParser ();
 
   retv = init_libgcrypt ();
   if (retv)
-    return (retv);
+    return retv;
 
   retv = init_libxmlsec ();
   if (retv)
-    return (retv);
+    return retv;
 
   retv = init_libgnutls ();
   if (retv)
-    return (retv);
+    return retv;
 
   retv = init_zlib ();
   if (retv)
-    return (retv);
+    return retv;
+
+  /* Challenge: get the "shared" directory. */
+  if (NULL == (data_dir = GNUNET_OS_installation_get_path
+      (GNUNET_OS_IPK_DATADIR)))
+    return EBICS_ERROR;
+
+  if (EBICS_SUCCESS != EBICS_init_genex_documents
+      (genexList,
+       data_dir,
+       genexFilenames))
+  {
+    GNUNET_break (0);
+    return EBICS_ERROR;
+  }
+
+  if (EBICS_SUCCESS != EBICS_init_keymaterial
+      (keyList,
+       data_dir,
+       keyFilenames))
+  {
+    GNUNET_break (0);
+    return EBICS_ERROR;
+  }
+
+  GNUNET_free (data_dir);
+  return EBICS_SUCCESS;
 }
 
+/**
+ * Deinit (all) the library(-ies)
+ */
 int
 EBICS_close_library ()
 {
@@ -447,37 +518,75 @@ EBICS_close_library ()
   
   free_libgnutls ();
   xmlCleanupParser ();
-  /* cleanup */
+
+  EBICS_free_genex_documents (genexList);
+  EBICS_free_keymaterial (keyList);
 }
 
+/**
+ * Allocate a fresh genex document.
+ *
+ * @param type_index index pointing to one genex
+ * base documents into the global genex array.
+ * @return pointer to a freshly allocated copy of
+ * the base document; to be freed by the caller.
+ */
+static struct EBICS_genex_document *
+get_genex_instance (unsigned int type_index)
+{
+  struct EBICS_genex_document *ret;
+
+  ret = GNUNET_new (struct EBICS_genex_document);
+  memcpy (ret,
+          &genexList[type_index],
+          sizeof (struct EBICS_genex_document));
 
+  return ret;
+}
 
 /**
  * Customize a bunch of standard values in the tree (including
  * the HostID).
+ *
+ * @param header_args TODO
+ * @param ini_args TODO
+ * @return pointer to a freshly allocated document, NULL upon errors.
  */
-int
-EBICS_generate_message_ini (struct EBICS_genex_document *document,
-                            struct EBICS_ARGS_build_header *headerArgs,
-                            struct EBICS_ARGS_build_content_ini *iniArgs)
+struct EBICS_genex_document *
+EBICS_generate_message_ini
+  (struct EBICS_ARGS_build_header *header_args,
+   struct EBICS_ARGS_build_content_ini *ini_args)
 {
 
+  struct EBICS_genex_document *instance;
+
+  if (NULL == (instance = get_genex_instance
+    (EBICS_INI_BASE_DOCUMENT)))
+  {
+    LOG (EBICS_ERROR,
+         "Could not allocate genex instance\n");
+    return NULL;
+  }
+
   struct EBICS_MSG_Spec spec[] = {
 
     /* Notably, it sets the HostID in the request document.  */
-    EBICS_MSG_op_subcommand (EBICS_build_header_ebicsUnsecuredRequest,
-                             headerArgs, // has _another_ document in it, and 
message_dump.c does define it.
-                             NULL),
+    EBICS_MSG_op_subcommand
+      (EBICS_build_header_ebicsUnsecuredRequest,
+       header_args),
 
-    /* Set a bunch of nodes (mostly strings) taking values from 'iniArgs'.  */
+    /* Set a bunch of nodes (mostly strings)
+     * taking values from 'ini_args'.  */
     EBICS_MSG_op_subcommand (EBICS_build_content_ini,
-                             iniArgs, // has _another_ document in it, and 
message_dump.c does define it.
-                             iniArgs->document), // out, but ignored
+                             ini_args),
     EBICS_MSG_op_clean (),
     EBICS_MSG_op_end ()
   };
 
-  EBICS_MSG_parse_spec (spec, document);
+  EBICS_MSG_parse_spec (spec,
+                        instance);
+
+  return instance;
 }
 
 
@@ -495,12 +604,10 @@ EBICS_generate_message_hia (struct EBICS_genex_document 
*document,
   struct EBICS_MSG_Spec spec[] = {
 
     EBICS_MSG_op_subcommand (EBICS_build_header_ebicsUnsecuredRequest,
-                             headerArgs,
-                             NULL),
-
+                             headerArgs),
     EBICS_MSG_op_subcommand (EBICS_build_content_hia,
-                             hiaArgs,
-                             hiaArgs->document), // target, gets _this_ change.
+                             hiaArgs),
+
     EBICS_MSG_op_clean (),
     EBICS_MSG_op_end ()
   };
@@ -516,12 +623,19 @@ EBICS_generate_message_hpb (struct EBICS_genex_document 
*document,
 {
 
   struct EBICS_MSG_Spec foo[] = {
-    EBICS_MSG_op_subcommand(EBICS_build_header_ebicsNoPubKeyDigestsRequest, 
headerArgs,NULL),
-    EBICS_MSG_op_set_string("//ebics:OrderDetails//ebics:OrderType", "HPB"),
-    EBICS_MSG_op_del_node("//ds:X509Data"),
-    EBICS_MSG_op_subcommand(EBICS_build_auth_signature ,authArgs, NULL),
-    EBICS_MSG_op_clean(),
-    EBICS_MSG_op_end()
+
+    EBICS_MSG_op_subcommand (EBICS_build_header_ebicsNoPubKeyDigestsRequest,
+                             headerArgs),
+
+    EBICS_MSG_op_set_string ("//ebics:OrderDetails//ebics:OrderType",
+                             "HPB"),
+
+    EBICS_MSG_op_del_node ("//ds:X509Data"),
+
+    EBICS_MSG_op_subcommand (EBICS_build_auth_signature,
+                             authArgs),
+    EBICS_MSG_op_clean (),
+    EBICS_MSG_op_end ()
   };
 
 
@@ -535,18 +649,19 @@ EBICS_generate_message_camt053 (struct 
EBICS_genex_document *document,
                                 struct EBICS_ARGS_build_content_camt053 
*camt053Args)
 {
   struct EBICS_MSG_Spec foo[] = {
+
     EBICS_MSG_op_subcommand (EBICS_build_header_ebicsRequest,
-                             headerArgs,
-                             NULL),
+                             headerArgs),
+
     EBICS_MSG_op_subcommand (EBICS_build_content_camt053,
-                             camt053Args,
-                             NULL),
+                             camt053Args),
+
     EBICS_MSG_op_subcommand (EBICS_build_bankPubKeyDigest,
-                             authArgs,
-                             NULL),
+                             authArgs),
+
     EBICS_MSG_op_subcommand (EBICS_build_auth_signature,
-                             authArgs,
-                             NULL),
+                             authArgs),
+
     EBICS_MSG_op_clean (),
     EBICS_MSG_op_end ()
   };
diff --git a/src/libebics.h b/src/libebics.h
index c37461e..ee16b8f 100644
--- a/src/libebics.h
+++ b/src/libebics.h
@@ -35,8 +35,15 @@
 #define EBICS_KEY_MAX_ENTRIES 6
 #define EBICS_KEY_MAX_NAME 128
 
+#define EBICS_INI_BASE_DOCUMENT 0
+
+
+
 int
-EBICS_init_keymaterial (struct EBICS_Key keyList[], char *keyDir, char 
*keyFiles[]);
+EBICS_init_keymaterial
+  (struct EBICS_Key keyList[],
+   char *keyDir,
+   const char *keyFiles[]);
 
 int
 EBICS_free_keymaterial (struct EBICS_Key keyList[]);
@@ -55,10 +62,20 @@ EBICS_init_library();
 int
 EBICS_close_library();
 
-int
-EBICS_generate_message_ini (struct EBICS_genex_document *document,
-                            struct EBICS_ARGS_build_header *headerArgs,
-                            struct EBICS_ARGS_build_content_ini *iniArgs);
+
+
+/**
+ * Customize a bunch of standard values in the tree (including
+ * the HostID).
+ *
+ * @param headerArgs contains values for the "header" sub-tree.
+ * @param header_args TODO
+ * @param ini_args TODO
+ * @return pointer to a freshly allocated document, NULL upon errors.
+ */
+struct EBICS_genex_document *
+EBICS_generate_message_ini (struct EBICS_ARGS_build_header *header_args,
+                            struct EBICS_ARGS_build_content_ini *ini_args);
 
 int
 EBICS_generate_message_hia (struct EBICS_genex_document *document,
diff --git a/src/tests.c b/src/tests.c
new file mode 100644
index 0000000..e84828f
--- /dev/null
+++ b/src/tests.c
@@ -0,0 +1,43 @@
+/**
+ * This file is part of libebics
+ *
+ * libfints 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,
+ * or (at your option) any later version.
+ *
+ * libebics 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 libebics; see the file COPYING.
+ * If not, see <http://www.gnu.org/license>
+ */
+
+
+#include "libebics.h"
+
+#define LOG(level,...) \
+  EBICS_util_log_from (__LINE__, \
+                       __FILE__, \
+                       __func__, \
+                       level, \
+                       "messagedump", \
+                       __VA_ARGS__)
+
+/**
+ * This test merely instantiates documents
+ * and checks them against their schemas.
+ *
+ * @return EBICS_ERROR on errors.
+ */
+int
+main (int argc, char **argv)
+{
+  if (EBICS_SUCCESS != EBICS_init_library ()) 
+    return EBICS_ERROR;
+  
+  EBICS_close_library ();
+}
diff --git a/src/xmlproto.c b/src/xmlproto.c
index 1e45878..04f5ebc 100644
--- a/src/xmlproto.c
+++ b/src/xmlproto.c
@@ -908,22 +908,15 @@ process_del_node (const struct EBICS_MSG_Spec *operation,
  * Process a "subcommand" operation.
  *
  * @param operation the subcommand operation to run
- * @param document the output document.  NOTE, that if the
- *        operation has the target field, this document will
- *        be left untouched.
+ * @param document the output document.
  */
 static void
 process_subcommand (const struct EBICS_MSG_Spec *operation,
                     struct EBICS_genex_document *document)
 {
-  if (NULL != operation->data.subcommand.target)
-    operation->data.subcommand.function
-      (operation->data.subcommand.cls,
-       operation->data.subcommand.target);
-  else
-    operation->data.subcommand.function
-      (operation->data.subcommand.cls,
-       document);
+  operation->data.subcommand.function
+    (operation->data.subcommand.cls,
+     document)
 }
 
 /**
diff --git a/src/xmlproto.h b/src/xmlproto.h
index 68df8c7..862318a 100644
--- a/src/xmlproto.h
+++ b/src/xmlproto.h
@@ -261,11 +261,6 @@ struct EBICS_MSG_Spec
       EBICS_MSG_subcommand_fn function;
 
       /**
-       * Target document.
-       */
-      struct EBICS_genex_document *target;
-
-      /**
        * General purpose closure for the callaback.
        */
       void *cls;
@@ -323,8 +318,17 @@ EBICS_MSG_op_add_attribute (const char *xpath, const char 
*name, const char *val
 struct EBICS_MSG_Spec
 EBICS_MSG_op_del_attribute (const char *xpath);
 
+
+/**
+ * Make a "subcommand" parsing instruction.
+ *
+ * @param the subcommand to invoke upon parsing.
+ * @param cls general purpose closure for it.
+ * @return the parsing instruction
+ */
 struct EBICS_MSG_Spec
-EBICS_MSG_op_subcommand (const EBICS_MSG_subcommand_fn subcmd, void *cls, 
struct EBICS_genex_document *target); 
+EBICS_MSG_op_subcommand (const EBICS_MSG_subcommand_fn subcmd,
+                         void *cls); 
 
 struct EBICS_MSG_Spec
 EBICS_MSG_op_end ();

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]