GNUnet 0.24.1-15-gab6ed22f1
curl_internal.h File Reference
#include "platform.h"
#include <jansson.h>
#include <microhttpd.h>
#include "gnunet_curl_lib.h"
Include dependency graph for curl_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void * GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code)
 

Function Documentation

◆ GNUNET_CURL_download_get_result_()

void * GNUNET_CURL_download_get_result_ ( struct GNUNET_CURL_DownloadBuffer db,
CURL *  eh,
long *  response_code 
)

Definition at line 655 of file curl.c.

658{
659 json_t *json;
660 char *ct;
661
662#if DEBUG
664 "Downloaded body: %.*s\n",
665 (int) db->buf_size,
666 (char *) db->buf);
667#endif
668 if (CURLE_OK !=
669 curl_easy_getinfo (eh,
670 CURLINFO_RESPONSE_CODE,
671 response_code))
672 {
673 /* unexpected error... */
674 GNUNET_break (0);
675 *response_code = 0;
676 }
677 if (MHD_HTTP_NO_CONTENT == *response_code)
678 return NULL;
679 if ((CURLE_OK !=
680 curl_easy_getinfo (eh,
681 CURLINFO_CONTENT_TYPE,
682 &ct)) ||
683 (NULL == ct) ||
684 (! is_json (ct)))
685 {
686 /* No content type or explicitly not JSON, refuse to parse
687 (but keep response code) */
688 if (0 != db->buf_size)
689 {
690 const char *url;
691
692 if (CURLE_OK !=
693 curl_easy_getinfo (eh,
694 CURLINFO_EFFECTIVE_URL,
695 &url))
696 url = "<unknown URL>";
698 "Request to `%s' was expected to return a body of type `application/json', got `%s'\n",
699 url,
700 ct);
701 }
702 return NULL;
703 }
704 if (0 == *response_code)
705 {
706 const char *url;
707
708 if (CURLE_OK !=
709 curl_easy_getinfo (eh,
710 CURLINFO_EFFECTIVE_URL,
711 &url))
712 url = "<unknown URL>";
714 "Failed to download response from `%s': \n",
715 url);
716 return NULL;
717 }
718 json = NULL;
719 if (0 == db->eno)
720 {
721 json_error_t error;
722
723 json = json_loadb (db->buf,
724 db->buf_size,
725 JSON_REJECT_DUPLICATES | JSON_DISABLE_EOF_CHECK,
726 &error);
727 if (NULL == json)
728 {
729 JSON_WARN (error);
730 *response_code = 0;
732 "Failed to parse JSON response: %s\n",
733 error.text);
734 }
735 }
736 GNUNET_free (db->buf);
737 db->buf = NULL;
738 db->buf_size = 0;
739 return json;
740}
static bool is_json(const char *ct)
Test if the given content type ct is JSON.
Definition: curl.c:627
#define JSON_WARN(error)
Print JSON parsing related error information.
Definition: curl.c:59
static struct GNUNET_FS_DirectoryBuilder * db
#define GNUNET_log(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.

References db, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, is_json(), and JSON_WARN.

Referenced by GNUNET_CURL_gnunet_rc_create(), and GNUNET_CURL_perform().

Here is the call graph for this function:
Here is the caller graph for this function: