658{
659 json_t *json;
660 char *ct;
661
662#if DEBUG
664 "Downloaded body: %.*s\n",
667#endif
668 if (CURLE_OK !=
669 curl_easy_getinfo (eh,
670 CURLINFO_RESPONSE_CODE,
671 response_code))
672 {
673
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) ||
685 {
686
687
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;
720 {
721 json_error_t error;
722
723 json = json_loadb (
db->buf,
725 JSON_REJECT_DUPLICATES | JSON_DISABLE_EOF_CHECK,
726 &error);
727 if (NULL == json)
728 {
730 *response_code = 0;
732 "Failed to parse JSON response: %s\n",
733 error.text);
734 }
735 }
739 return json;
740}
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.