823{
824 json_t *json;
825 char *ct;
826
827#if DEBUG
829 "Downloaded body: %.*s\n",
832#endif
833 if (CURLE_OK !=
834 curl_easy_getinfo (eh,
835 CURLINFO_RESPONSE_CODE,
836 response_code))
837 {
838
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) ||
850 {
851
852
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;
885 {
886 json_error_t error;
887
888 json = json_loadb (
db->buf,
890 JSON_REJECT_DUPLICATES | JSON_DISABLE_EOF_CHECK,
891 &error);
892 if (NULL == json)
893 {
895 *response_code = 0;
897 "Failed to parse JSON response: %s\n",
898 error.text);
899 }
900 }
904 return json;
905}
static bool is_json(const char *ct)
Test if the given content type ct is JSON.
#define JSON_WARN(error)
Print JSON parsing related error information.
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.