*/
static int curl_fail;
-
-/**
- * @brief Buffer data structure we use to buffer the HTTP download
- * before giving it to the JSON parser.
- */
-struct DownloadBuffer
-{
-
- /**
- * Download buffer
- */
- void *buf;
-
- /**
- * The size of the download buffer
- */
- size_t buf_size;
-
- /**
- * Error code (based on libc errno) if we failed to download
- * (i.e. response too large).
- */
- int eno;
-
-};
-
-
/**
* Jobs are CURL requests running within a `struct GNUNET_CURL_Context`.
*/
/**
* Buffer for response received from CURL.
*/
- struct DownloadBuffer db;
+ struct GNUNET_CURL_DownloadBuffer db;
};
size_t nitems,
void *cls)
{
- struct DownloadBuffer *db = cls;
+ struct GNUNET_CURL_DownloadBuffer *db = cls;
size_t msize;
void *buf;
* (or zero if we aborted the download, i.e.
* because the response was too big, or if
* the JSON we received was malformed).
- * @return NULL if downloading a JSON reply failed
+ * @return NULL if downloading a JSON reply failed.
*/
-static json_t *
-download_get_result (struct DownloadBuffer *db,
+static void *
+download_get_result (struct GNUNET_CURL_DownloadBuffer *db,
CURL *eh,
long *response_code)
{
return json;
}
-
/**
* Add custom request header.
*
* Run the main event loop for the Taler interaction.
*
* @param ctx the library context
+ * @param rp parses the raw response returned from
+ * the Web server.
+ * @param rc cleans/frees the response
*/
void
-GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx)
+GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx,
+ GNUNET_CURL_RawParser rp,
+ GNUNET_CURL_ResponseCleaner rc)
{
CURLMsg *cmsg;
struct GNUNET_CURL_Job *job;
int n_running;
int n_completed;
long response_code;
- json_t *j;
+ void *response;
(void) curl_multi_perform (ctx->multi,
&n_running);
CURLINFO_PRIVATE,
(char **) &job));
GNUNET_assert (job->ctx == ctx);
- response_code = 0;
- j = download_get_result (&job->db,
- job->easy_handle,
- &response_code);
+ response_code = 0 ;
+ response = rp (&job->db,
+ job->easy_handle,
+ &response_code);
#if ENABLE_BENCHMARK
{
char *url = NULL;
#endif
job->jcc (job->jcc_cls,
response_code,
- j);
- json_decref (j);
+ /* NOTE: jcc is now in charge of decref-ing */
+ response);
+ rc (response);
GNUNET_CURL_job_cancel (job);
}
}
+/**
+ * Run the main event loop for the Taler interaction.
+ *
+ * @param ctx the library context
+ */
+void
+GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx)
+{
+
+ GNUNET_CURL_perform2 (ctx,
+ download_get_result,
+ (GNUNET_CURL_ResponseCleaner) &json_decref);
+}
+
+
/**
* Obtain the information for a select() call to wait until
* #GNUNET_CURL_perform() is ready again. Note that calling
typedef void
(*GNUNET_CURL_RescheduleCallback)(void *cls);
+/**
+ * @brief Buffer data structure we use to buffer the HTTP download
+ * before giving it to the JSON parser.
+ */
+struct GNUNET_CURL_DownloadBuffer
+{
+
+ /**
+ * Download buffer
+ */
+ void *buf;
+
+ /**
+ * The size of the download buffer
+ */
+ size_t buf_size;
+
+ /**
+ * Error code (based on libc errno) if we failed to download
+ * (i.e. response too large).
+ */
+ int eno;
+
+};
+
+
+/**
+ * Parses the raw response we got from the Web server.
+ *
+ * @param db the raw data
+ * @param eh handle
+ * @param response_code HTTP response code
+ * @return the parsed object
+ */
+typedef void *
+(*GNUNET_CURL_RawParser) (struct GNUNET_CURL_DownloadBuffer *db,
+ CURL *eh,
+ long *response_code);
+
+/**
+ * Deallocate the response.
+ *
+ * @param response object to clean
+ */
+typedef void
+(*GNUNET_CURL_ResponseCleaner) (void *response);
/**
* Initialise this library. This function should be called before using any of
GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx);
+/**
+ * Run the main event loop for the Taler interaction.
+ *
+ * @param ctx the library context
+ * @param rp parses the raw response returned from
+ * the Web server.
+ * @param rc cleans/frees the response
+ */
+void
+GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx,
+ GNUNET_CURL_RawParser rp,
+ GNUNET_CURL_ResponseCleaner rc);
+
/**
* Cleanup library initialisation resources. This function should be called
* after using this library to cleanup the resources occupied during library's