GNUnet 0.28.1-dev.5-1-gae1c02d74
 
Loading...
Searching...
No Matches
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 820 of file curl.c.

823{
824 json_t *json;
825 char *ct;
826
827#if DEBUG
829 "Downloaded body: %.*s\n",
830 (int) db->buf_size,
831 (char *) db->buf);
832#endif
833 if (CURLE_OK !=
834 curl_easy_getinfo (eh,
835 CURLINFO_RESPONSE_CODE,
836 response_code))
837 {
838 /* unexpected error... */
839 GNUNET_break (0);
840 *response_code = 0;
841 }
842 if (MHD_HTTP_NO_CONTENT == *response_code)
843 return NULL;
844 if ((CURLE_OK !=
845 curl_easy_getinfo (eh,
846 CURLINFO_CONTENT_TYPE,
847 &ct)) ||
848 (NULL == ct) ||
849 (! is_json (ct)))
850 {
851 /* No content type or explicitly not JSON, refuse to parse
852 (but keep response code) */
853 if (0 != db->buf_size)
854 {
855 const char *url;
856
857 if (CURLE_OK !=
858 curl_easy_getinfo (eh,
859 CURLINFO_EFFECTIVE_URL,
860 &url))
861 url = "<unknown URL>";
863 "Request to `%s' was expected to return a body of type `application/json', got `%s'\n",
864 url,
865 ct);
866 }
867 return NULL;
868 }
869 if (0 == *response_code)
870 {
871 const char *url;
872
873 if (CURLE_OK !=
874 curl_easy_getinfo (eh,
875 CURLINFO_EFFECTIVE_URL,
876 &url))
877 url = "<unknown URL>";
879 "Failed to download response from `%s': \n",
880 url);
881 return NULL;
882 }
883 json = NULL;
884 if (0 == db->eno)
885 {
886 json_error_t error;
887
888 json = json_loadb (db->buf,
889 db->buf_size,
890 JSON_REJECT_DUPLICATES | JSON_DISABLE_EOF_CHECK,
891 &error);
892 if (NULL == json)
893 {
894 JSON_WARN (error);
895 *response_code = 0;
897 "Failed to parse JSON response: %s\n",
898 error.text);
899 }
900 }
901 GNUNET_free (db->buf);
902 db->buf = NULL;
903 db->buf_size = 0;
904 return json;
905}
static bool is_json(const char *ct)
Test if the given content type ct is JSON.
Definition curl.c:792
#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: