#include "gnunet_util_lib.h"
#include "gnunet_gnsrecord_lib.h"
#include <jansson.h>
-
+#include <microhttpd.h>
/* ****************** Generic parser interface ******************* */
* @return #GNUNET_SYSERR on error,
* #GNUNET_OK on success
*/
-typedef int
-(*GNUNET_JSON_Parser)(void *cls,
- json_t *root,
- struct GNUNET_JSON_Specification *spec);
+typedef int (*GNUNET_JSON_Parser) (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec);
/**
* @param cls closure
* @param spec our specification entry with data to clean.
*/
-typedef void
-(*GNUNET_JSON_Cleaner)(void *cls,
- struct GNUNET_JSON_Specification *spec);
+typedef void (*GNUNET_JSON_Cleaner) (void *cls,
+ struct GNUNET_JSON_Specification *spec);
/**
* Where should we store the final size of @e ptr.
*/
size_t *size_ptr;
-
};
GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec);
-
/* ****************** Canonical parser specifications ******************* */
* @param size number of bytes expected in @a obj
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_fixed (const char *name,
- void *obj,
- size_t size);
+GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size);
/**
* @param name name of the JSON field
* @param obj pointer where to write the data (type of `*obj` will determine size)
*/
-#define GNUNET_JSON_spec_fixed_auto(name,obj) GNUNET_JSON_spec_fixed (name, obj, sizeof (*obj))
+#define GNUNET_JSON_spec_fixed_auto(name, obj) \
+ GNUNET_JSON_spec_fixed (name, obj, sizeof (*obj))
/**
* @param[out] size where to store the number of bytes allocated for @a obj
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_varsize (const char *name,
- void **obj,
- size_t *size);
+GNUNET_JSON_spec_varsize (const char *name, void **obj, size_t *size);
/**
* @param strptr where to store a pointer to the field
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_string (const char *name,
- const char **strptr);
+GNUNET_JSON_spec_string (const char *name, const char **strptr);
/**
* JSON object.
* @param[out] jsonp where to store the JSON found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_json (const char *name,
- json_t **jsonp);
+GNUNET_JSON_spec_json (const char *name, json_t **jsonp);
/**
* @param[out] u8 where to store the integer found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_uint8 (const char *name,
- uint8_t *u8);
+GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8);
/**
* @param[out] u16 where to store the integer found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_uint16 (const char *name,
- uint16_t *u16);
+GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16);
/**
* @param[out] u32 where to store the integer found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_uint32 (const char *name,
- uint32_t *u32);
+GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32);
/**
* @param[out] u64 where to store the integer found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_uint64 (const char *name,
- uint64_t *u64);
+GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64);
/**
* Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO).
* @param[out] boolean where to store the boolean found under @a name
*/
struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_boolean (const char *name,
- int *boolean);
+GNUNET_JSON_spec_boolean (const char *name, int *boolean);
/* ************ GNUnet-specific parser specifications ******************* */
*/
struct GNUNET_JSON_Specification
GNUNET_JSON_spec_absolute_time_nbo (const char *name,
- struct GNUNET_TIME_AbsoluteNBO *at);
+ struct GNUNET_TIME_AbsoluteNBO *at);
/**
struct GNUNET_CRYPTO_RsaSignature **sig);
-
/**
* JSON Specification for GNS Records.
*
* @return json string that encodes @a data
*/
json_t *
-GNUNET_JSON_from_data (const void *data,
- size_t size);
+GNUNET_JSON_from_data (const void *data, size_t size);
/**
* @param ptr binary data, sizeof (*ptr) must yield correct size
* @return json string that encodes @a data
*/
-#define GNUNET_JSON_from_data_auto(ptr) GNUNET_JSON_from_data(ptr, sizeof (*ptr))
+#define GNUNET_JSON_from_data_auto(ptr) \
+ GNUNET_JSON_from_data (ptr, sizeof (*ptr))
/**
* @return corresponding JSON encoding
*/
json_t *
-GNUNET_JSON_from_gnsrecord (const char* rname,
+GNUNET_JSON_from_gnsrecord (const char *rname,
const struct GNUNET_GNSRECORD_Data *rd,
unsigned int rd_count);
/**
* Return codes from #GNUNET_JSON_post_parser().
*/
-enum GNUNET_JSON_PostResult {
+enum GNUNET_JSON_PostResult
+{
/**
* Parsing successful, JSON result is in `*json`.
*/
* #GNUNET_JSON_post_parser_callback().
*
* @param buffer_max maximum allowed size for the buffer
+ * @param connection MHD connection handle (for meta data about the upload)
* @param con_cls the closure (will point to a `struct Buffer *`)
* @param upload_data the POST data
* @param upload_data_size number of bytes in @a upload_data
*/
enum GNUNET_JSON_PostResult
GNUNET_JSON_post_parser (size_t buffer_max,
+ struct MHD_Connection *connection,
void **con_cls,
const char *upload_data,
size_t *upload_data_size,
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "platform.h"
#include "gnunet_json_lib.h"
+
/**
* Initial size for POST request buffers. Should be big enough to
* usually not require a reallocation, but not so big that it hurts in
* terms of memory use.
*/
-#define REQUEST_BUFFER_INITIAL (2*1024)
+#define REQUEST_BUFFER_INITIAL (2 * 1024)
/**
size_t alloc_size,
size_t max_size)
{
- if ( (data_size > max_size) ||
- (alloc_size > max_size) )
+ if ((data_size > max_size) || (alloc_size > max_size))
return GNUNET_SYSERR;
if (data_size > alloc_size)
alloc_size = data_size;
* #GNUNET_JSON_post_parser_callback().
*
* @param buffer_max maximum allowed size for the buffer
+ * @param connection MHD connection handle (for meta data about the upload)
* @param con_cls the closure (will point to a `struct Buffer *`)
* @param upload_data the POST data
* @param upload_data_size number of bytes in @a upload_data
*/
enum GNUNET_JSON_PostResult
GNUNET_JSON_post_parser (size_t buffer_max,
+ struct MHD_Connection *connection,
void **con_cls,
const char *upload_data,
size_t *upload_data_size,
{
/* We are seeing a fresh POST request. */
r = GNUNET_new (struct Buffer);
- if (GNUNET_OK !=
- buffer_init (r,
- upload_data,
- *upload_data_size,
- REQUEST_BUFFER_INITIAL,
- buffer_max))
+ if (GNUNET_OK != buffer_init (r,
+ upload_data,
+ *upload_data_size,
+ REQUEST_BUFFER_INITIAL,
+ buffer_max))
{
*con_cls = NULL;
buffer_deinit (r);
/* We are seeing an old request with more data available. */
if (GNUNET_OK !=
- buffer_append (r,
- upload_data,
- *upload_data_size,
- buffer_max))
+ buffer_append (r, upload_data, *upload_data_size, buffer_max))
{
/* Request too long */
*con_cls = NULL;
/* We have seen the whole request. */
- *json = json_loadb (r->data,
- r->fill,
- 0,
- NULL);
+ *json = json_loadb (r->data, r->fill, 0, NULL);
if (NULL == *json)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,