gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libebics] branch master updated: Submitting CURL jobs usin


From: gnunet
Subject: [GNUnet-SVN] [libebics] branch master updated: Submitting CURL jobs using custom XML parser.
Date: Wed, 17 Oct 2018 19:01:16 +0200

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

marcello pushed a commit to branch master
in repository libebics.

The following commit(s) were added to refs/heads/master by this push:
     new 0296a75  Submitting CURL jobs using custom XML parser.
0296a75 is described below

commit 0296a7591fe7bac559d6989b10477c52437cdd4d
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Oct 17 18:58:56 2018 +0200

    Submitting CURL jobs using custom XML parser.
    
    Not tested yet, and depending on *UNCOMMITTED*
    GNUnet patches.
---
 src/libebics.c      | 116 ++++++++++++++++++++++++++++++++++++++++++++++++----
 src/libebics.h      |  11 +++--
 src/sandbox_tests.c |  27 ++++++++++++
 src/xmlproto.c      |  14 ++++---
 4 files changed, 151 insertions(+), 17 deletions(-)

diff --git a/src/libebics.c b/src/libebics.c
index cd8d8e0..1e9da2c 100644
--- a/src/libebics.c
+++ b/src/libebics.c
@@ -618,6 +618,53 @@ free_genex_documents (struct EBICS_genex_document 
genexList[])
   }
 }
 
+
+/**
+ * Process the raw response that came from the bank.
+ *
+ * @param db buffer with the raw response
+ * @param eh handle to the HTTP connection
+ * @param http_status[out] set to the HTTP response code
+ */
+static void *
+parse_response (struct GNUNET_CURL_DownloadBuffer *db,
+                CURL *eh,
+                long *http_status)
+{
+  xmlParserCtxtPtr parser;
+  xmlDocPtr doc;
+  http_status = 0;
+
+  if (0 == db->eno)
+  {
+    char *url;
+
+    parser = xmlNewParserCtxt ();
+    curl_easy_getinfo (eh,
+                       CURLINFO_EFFECTIVE_URL,
+                       &url);
+    /* Not clear from docs what's the return value
+     * for unparsable responses.  _Assuming_ NULL */
+    if (NULL == (doc = xmlCtxtReadMemory
+        (parser,
+         db->buf,
+         db->buf_size,
+         url,
+         "UTF-8",
+         XML_PARSE_NOBLANKS)))
+      LOG (EBICS_LOGLEVEL_ERROR,
+           "Could not parse response body\n");
+    else
+      /* Parsing succeeded, extracting the status code now */
+      curl_easy_getinfo (eh,
+                         CURLINFO_RESPONSE_CODE,
+                         &http_status);
+  }
+
+  return doc;
+}
+
+
 /**
  * Initializes Libebics.  Init all the dependencies,
  * as well as it allocates the "genex" templates to
@@ -699,9 +746,10 @@ EBICS_init_library (const char *key_dir,
     return EBICS_ERROR;
   }
 
-  reschedule_ctx = GNUNET_CURL_gnunet_rc_create
-    /* Not allocated yet */
-    (ctx);
+  reschedule_ctx = GNUNET_CURL_gnunet_rc_create_with_parser
+    (ctx,
+     &parse_response,
+     (GNUNET_CURL_ResponseCleaner) &xmlFree);
 
   if (NULL == (ctx = GNUNET_CURL_init
       (GNUNET_CURL_gnunet_scheduler_reschedule,
@@ -948,6 +996,20 @@ EBICS_generate_message_camt053
   return instance;
 }
 
+
+/**
+ * Process the (parsed) response body
+ *
+ * @param cls closure
+ * @param response_code HTTP status code from the bank
+ * @param response parsed response body.
+ */
+static void
+process_response (void *cls,
+                  long response_code,
+                  const void *response);
+
+
 /**
  * Prepare and POSTs a EBICS HTTPS message to the bank.
  *
@@ -958,21 +1020,61 @@ EBICS_generate_message_camt053
  */
 int
 EBICS_send_message (const struct EBICS_genex_document *document,
-                    const char url,
+                    const char *url,
                     EBICS_ResponseCallback cb)
 {
 
   int size;
   xmlChar *buf;
+  CURL *eh;
+
+#define SETOPT(eh,opt,par) \
+  if (CURLE_OK != curl_easy_setopt (eh, opt, par)) \
+  { \
+    LOG (EBICS_LOGLEVEL_ERROR, \
+         "CURL setopt error (%s:%u)\n", \
+         __FILE__, \
+         __LINE__); \
+    curl_easy_cleanup (eh); \
+    return EBICS_ERROR; \
+  }
 
   xmlDocDumpFormatMemoryEnc (document->document,
                              &buf,
                              &size,
                              "UTF-8",
                              GNUNET_NO);
-  LOG (EBICS_LOGLEVEL_DEBUG,
-       "Upcoming body: %s\n",
-       buf);
+  eh = curl_easy_init (); 
+
+  SETOPT (eh,
+          CURLOPT_URL,
+          url);
+
+  SETOPT (eh,
+          CURLOPT_POSTFIELDS,
+          buf);
+
+  SETOPT (eh,
+          CURLOPT_POSTFIELDS,
+          buf);
+
+  GNUNET_assert
+    (GNUNET_OK == GNUNET_CURL_append_header
+      (ctx,
+       "Content-Type: text/xml"));
+
+  if (NULL == GNUNET_CURL_job_add (ctx,
+                                   eh,
+                                   GNUNET_NO,
+                                   cb,
+                                   NULL))
+  {
+    LOG (EBICS_LOGLEVEL_ERROR,
+         "Could not submit the CURL job\n");
+    curl_easy_cleanup (eh);
+    xmlFree (buf);
+    return EBICS_ERROR;
+  }
 
   xmlFree (buf);
 
diff --git a/src/libebics.h b/src/libebics.h
index c731ac0..06370f9 100644
--- a/src/libebics.h
+++ b/src/libebics.h
@@ -151,11 +151,14 @@ EBICS_generate_message_camt053
 /**
  * Callback used to process the response of a bank.
  * 
- * @param TODO need the body itself!
- * @param http_status HTTP response code.
+ * @param cls closure
+ * @param response_code HTTP response code
+ * @param response response object - no need to free.
  */
 typedef void
-(*EBICS_ResponseCallback) (long http_status);
+(*EBICS_ResponseCallback) (void *cls,
+                           long response_code,
+                           const void *response);
 
 /**
  * Prepare and POSTs a EBICS HTTPS message to the bank.
@@ -167,7 +170,7 @@ typedef void
  */
 int
 EBICS_send_message (const struct EBICS_genex_document *document,
-                    const char url,
+                    const char *url,
                     EBICS_ResponseCallback cb);
 
 #endif
diff --git a/src/sandbox_tests.c b/src/sandbox_tests.c
index 6e32635..19bc9a5 100644
--- a/src/sandbox_tests.c
+++ b/src/sandbox_tests.c
@@ -20,6 +20,7 @@
 #include "libebics.h"
 #include <gnunet/platform.h>
 #include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
 
 #define LOG(level,...) \
   EBICS_util_log_from (__LINE__, \
@@ -29,6 +30,22 @@
                        "messagedump", \
                        __VA_ARGS__)
 
+#define BANK_URL "http://localhost:9999/";
+
+/**
+ * Process responses from banks.
+ *
+ * @param response_code HTTP response given by
+ *        the bank.
+ */
+static void
+cb (void *cls,
+    long response_code,
+    const void *response)
+{
+  xmlDocPtr doc = (xmlDocPtr) response;
+}
+
 struct EBICS_ARGS_build_header header_args = {
   .hostID = "EBIXHOST",
   .partnerID = "PARTNER1",
@@ -92,7 +109,17 @@ main (int argc,
     return EBICS_ERROR;
   }
 
+  if (EBICS_SUCCESS != EBICS_send_message (msg,
+                                           BANK_URL,
+                                           cb))
+  {
+    LOG (EBICS_LOGLEVEL_ERROR,
+         "Could not POST the INI message\n");
+    return EBICS_ERROR;
+  }
+
   GNUNET_free (msg);
+  return EBICS_SUCCESS;
 
   /**
    * HIA
diff --git a/src/xmlproto.c b/src/xmlproto.c
index b1effc9..1d41ac7 100644
--- a/src/xmlproto.c
+++ b/src/xmlproto.c
@@ -158,10 +158,11 @@ EBICS_MSG_op_set_date (const char *xpath,
  * @param value UTF-8 String to set content to.
  */
 struct EBICS_MSG_Spec
-EBICS_MSG_op_set_string (const char *xpath, const char *value) 
+EBICS_MSG_op_set_string (const char *xpath,
+                         const char *value) 
 {
-  struct EBICS_MSG_Spec result = 
-    {
+  struct EBICS_MSG_Spec result = {
+
       .operation = EBICS_MSG_OP_SET_STRING,
       .xpath = xpath,
       .data.set_string.value = xmlCharStrdup(value)
@@ -177,10 +178,11 @@ EBICS_MSG_op_set_string (const char *xpath, const char 
*value)
  * @param value UTF-8 String to set content to.
  */
 struct EBICS_MSG_Spec
-EBICS_MSG_op_set_attribute (const char *xpath, const char *value) 
+EBICS_MSG_op_set_attribute (const char *xpath,
+                            const char *value) 
 {
-  struct EBICS_MSG_Spec result = 
-    {
+  struct EBICS_MSG_Spec result = {
+
       .operation = EBICS_MSG_OP_SET_ATTRIBUTE,
       .xpath = xpath,
       .data.attribute.value = xmlCharStrdup(value)

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



reply via email to

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