GNUnet 0.22.1
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 651 of file curl.c.

654{
655 json_t *json;
656 char *ct;
657
658#if DEBUG
660 "Downloaded body: %.*s\n",
661 (int) db->buf_size,
662 (char *) db->buf);
663#endif
664 if (CURLE_OK !=
665 curl_easy_getinfo (eh,
666 CURLINFO_RESPONSE_CODE,
667 response_code))
668 {
669 /* unexpected error... */
670 GNUNET_break (0);
671 *response_code = 0;
672 }
673 if (MHD_HTTP_NO_CONTENT == *response_code)
674 return NULL;
675 if ((CURLE_OK !=
676 curl_easy_getinfo (eh,
677 CURLINFO_CONTENT_TYPE,
678 &ct)) ||
679 (NULL == ct) ||
680 (! is_json (ct)))
681 {
682 /* No content type or explicitly not JSON, refuse to parse
683 (but keep response code) */
684 if (0 != db->buf_size)
685 {
686 const char *url;
687
688 if (CURLE_OK !=
689 curl_easy_getinfo (eh,
690 CURLINFO_EFFECTIVE_URL,
691 &url))
692 url = "<unknown URL>";
694 "Request to `%s' was expected to return a body of type `application/json', got `%s'\n",
695 url,
696 ct);
697 }
698 return NULL;
699 }
700 if (0 == *response_code)
701 {
702 const char *url;
703
704 if (CURLE_OK !=
705 curl_easy_getinfo (eh,
706 CURLINFO_EFFECTIVE_URL,
707 &url))
708 url = "<unknown URL>";
710 "Failed to download response from `%s': \n",
711 url);
712 return NULL;
713 }
714 json = NULL;
715 if (0 == db->eno)
716 {
717 json_error_t error;
718
719 json = json_loadb (db->buf,
720 db->buf_size,
721 JSON_REJECT_DUPLICATES | JSON_DISABLE_EOF_CHECK,
722 &error);
723 if (NULL == json)
724 {
725 JSON_WARN (error);
726 *response_code = 0;
728 "Failed to parse JSON response: %s\n",
729 error.text);
730 }
731 }
732 GNUNET_free (db->buf);
733 db->buf = NULL;
734 db->buf_size = 0;
735 return json;
736}
static bool is_json(const char *ct)
Test if the given content type ct is JSON.
Definition: curl.c:623
#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.
@ MHD_HTTP_NO_CONTENT
No Content [RFC7231, Section 6.3.5].

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

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: