[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libebics] 03/04: Memory and design fixes.
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libebics] 03/04: Memory and design fixes. |
Date: |
Fri, 19 Oct 2018 11:24:15 +0200 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository libebics.
commit 2d8bd28306ea3016d7bb8904840ca26aa15b39b4
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Oct 19 10:57:40 2018 +0200
Memory and design fixes.
Fixing a segfault, and making the HTTP POST
method return the GNUNET-CURL job so as to
allow the user to cancel jobs.
---
src/libebics.c | 56 +++++++++++++++++++++++++++++------------------------
src/libebics.h | 2 +-
src/sandbox_tests.c | 40 +++++++++++++++++++++++++-------------
3 files changed, 59 insertions(+), 39 deletions(-)
diff --git a/src/libebics.c b/src/libebics.c
index aee27ab..56f6482 100644
--- a/src/libebics.c
+++ b/src/libebics.c
@@ -618,6 +618,12 @@ free_genex_documents (struct EBICS_genex_document
genexList[])
}
}
+static void
+clean_response (void *response)
+{
+ if (response)
+ GNUNET_free (response);
+}
/**
* Process the raw response that came from the bank.
@@ -746,11 +752,6 @@ EBICS_init_library (const char *key_dir,
return EBICS_ERROR;
}
- 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,
&reschedule_ctx)))
@@ -760,6 +761,11 @@ EBICS_init_library (const char *key_dir,
return EBICS_ERROR;
}
+ reschedule_ctx = GNUNET_CURL_gnunet_rc_create_with_parser
+ (ctx,
+ &parse_response,
+ &clean_response);
+
GNUNET_free (data_dir);
return EBICS_SUCCESS;
}
@@ -1016,9 +1022,9 @@ process_response (void *cls,
* @param document the document to POST
* @param URL url of the EBICS endpoint
* @param cb callback to pass the response data
- * @return EBICS_SUCCESS / EBICS_ERROR
+ * @return the CURL job, or NULL upon errors.
*/
-int
+struct GNUNET_CURL_Job *
EBICS_send_message (const struct EBICS_genex_document *document,
const char *url,
EBICS_ResponseCallback cb)
@@ -1027,6 +1033,7 @@ EBICS_send_message (const struct EBICS_genex_document
*document,
int size;
xmlChar *buf;
CURL *eh;
+ struct GNUNET_CURL_Job *job;
#define SETOPT(eh,opt,par) \
if (CURLE_OK != curl_easy_setopt (eh, opt, par)) \
@@ -1036,7 +1043,7 @@ EBICS_send_message (const struct EBICS_genex_document
*document,
__FILE__, \
__LINE__); \
curl_easy_cleanup (eh); \
- return EBICS_ERROR; \
+ return NULL; \
}
xmlDocDumpFormatMemoryEnc (document->document,
@@ -1046,37 +1053,36 @@ EBICS_send_message (const struct EBICS_genex_document
*document,
GNUNET_NO);
eh = curl_easy_init ();
+ GNUNET_assert
+ (GNUNET_OK == GNUNET_CURL_append_header
+ (ctx,
+ "Content-Type: text/xml"));
+
SETOPT (eh,
CURLOPT_URL,
url);
SETOPT (eh,
- CURLOPT_POSTFIELDS,
- buf);
+ CURLOPT_POSTFIELDSIZE,
+ size);
SETOPT (eh,
- CURLOPT_POSTFIELDS,
+ CURLOPT_COPYPOSTFIELDS,
buf);
- GNUNET_assert
- (GNUNET_OK == GNUNET_CURL_append_header
- (ctx,
- "Content-Type: text/xml"));
+ xmlFree (buf);
- if (NULL == GNUNET_CURL_job_add (ctx,
- eh,
- GNUNET_NO,
- cb,
- NULL))
+ if (NULL == (job = 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;
+ return NULL;
}
- xmlFree (buf);
-
- return EBICS_SUCCESS;
+ return job;
}
diff --git a/src/libebics.h b/src/libebics.h
index 06370f9..83047ad 100644
--- a/src/libebics.h
+++ b/src/libebics.h
@@ -168,7 +168,7 @@ typedef void
* @param cb callback to pass the response data
* @return EBICS_SUCCESS / EBICS_ERROR
*/
-int
+struct GNUNET_CURL_Job *
EBICS_send_message (const struct EBICS_genex_document *document,
const char *url,
EBICS_ResponseCallback cb);
diff --git a/src/sandbox_tests.c b/src/sandbox_tests.c
index 9d96e3f..6280821 100644
--- a/src/sandbox_tests.c
+++ b/src/sandbox_tests.c
@@ -32,7 +32,8 @@
#define KEYS_DIR "./test_keys"
-#define BANK_URL
"https://server-ebics.webank.fr:28103/WbkPortalFileTransfert/EbicsProtocol"
+#define BANK_URL "http://localhost:9999/"
+// #define BANK_URL
"https://server-ebics.webank.fr:28103/WbkPortalFileTransfert/EbicsProtocol"
#define E001_DIGEST "9BF804AF2B121A5B94C82BFD8E406FFB18024D3D4BF9E"
#define X001_DIGEST "9BF804AF2B121A5B94C82BFD8E406FFB18024D3D4BF9E"
#define HOST_ID "EBIXQUAL"
@@ -43,6 +44,12 @@
int result = EBICS_ERROR;
/**
+ * Current CURL job
+ */
+struct GNUNET_CURL_Job *job;
+
+
+/**
* Process responses from banks.
*
* @param response_code HTTP response given by
@@ -56,10 +63,8 @@ cb (void *cls,
xmlDocPtr doc = (xmlDocPtr) response;
LOG (EBICS_LOGLEVEL_INFO,
- "Bank responded\n");
-
-
- GNUNET_SCHEDULER_shutdown ();
+ "Bank responded (%d)\n",
+ response_code);
}
struct EBICS_ARGS_build_header header_args = {
@@ -81,6 +86,17 @@ struct EBICS_ARGS_build_content_hia hia_args = {
.userID = "USER0001"
};
+/**
+ * Just deallocate the library
+ */
+void
+deinit ()
+{
+ LOG (EBICS_LOGLEVEL_DEBUG,
+ "Shutting the test down\n");
+ EBICS_close_library ();
+}
+
static void
run ()
{
@@ -90,6 +106,8 @@ run ()
unsetenv ("XDG_DATA_HOME");
unsetenv ("XDG_CONFIG_HOME");
+ GNUNET_SCHEDULER_add_shutdown (&deinit,
+ NULL);
struct EBICS_UserKeyFiles key_filenames = {
.es_key = "testEsKey",
.enc_key = "testEncKey",
@@ -117,19 +135,16 @@ run ()
return;
}
- LOG (EBICS_LOGLEVEL_DEBUG,
- "MSG-MADE\n");
-
- if (EBICS_SUCCESS != EBICS_send_message (msg,
- BANK_URL,
- cb))
+ if (NULL == (job = EBICS_send_message (msg,
+ BANK_URL,
+ cb)))
{
LOG (EBICS_LOGLEVEL_ERROR,
"Could not POST the INI message\n");
return;
}
- GNUNET_free (msg);
+ GNUNET_free (msg);
result = EBICS_SUCCESS;
}
@@ -146,6 +161,5 @@ main (int argc,
GNUNET_SCHEDULER_run (&run,
NULL);
- EBICS_close_library ();
return result;
}
--
To stop receiving notification emails like this one, please contact
address@hidden