2012-12-14 04:34:42 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2008-2014 Mnemosyne LLC
|
2012-12-14 04:34:42 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2012-12-14 04:34:42 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-11-14 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#ifndef LIBTRANSMISSION_VARIANT_MODULE
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission/variant-*.c should #include this header.
|
2012-12-14 04:34:42 +00:00
|
|
|
#endif
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "tr-macros.h"
|
|
|
|
|
|
|
|
TR_BEGIN_DECLS
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
typedef void (* VariantWalkFunc)(tr_variant const* val, void* user_data);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
|
|
|
struct VariantWalkFuncs
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
VariantWalkFunc intFunc;
|
|
|
|
VariantWalkFunc boolFunc;
|
|
|
|
VariantWalkFunc realFunc;
|
|
|
|
VariantWalkFunc stringFunc;
|
|
|
|
VariantWalkFunc dictBeginFunc;
|
|
|
|
VariantWalkFunc listBeginFunc;
|
|
|
|
VariantWalkFunc containerEndFunc;
|
2012-12-14 04:34:42 +00:00
|
|
|
};
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_variantWalk(tr_variant const* top, struct VariantWalkFuncs const* walkFuncs, void* user_data, bool sort_dicts);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_variantToBufJson(tr_variant const* top, struct evbuffer* buf, bool lean);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_variantToBufBenc(tr_variant const* top, struct evbuffer* buf);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_variantInit(tr_variant* v, char type);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* source - such as a filename. Only when logging an error */
|
2017-04-20 16:02:19 +00:00
|
|
|
int tr_jsonParse(char const* source, void const* vbuf, size_t len, tr_variant* setme_benc, char const** setme_end);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
|
|
|
/** @brief Private function that's exposed here only for unit tests */
|
2020-08-11 18:11:55 +00:00
|
|
|
int tr_bencParseInt(void const* buf, void const* bufend, uint8_t const** setme_end, int64_t* setme_val);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
|
|
|
/** @brief Private function that's exposed here only for unit tests */
|
2020-08-11 18:11:55 +00:00
|
|
|
int tr_bencParseStr(void const* buf, void const* bufend, uint8_t const** setme_end, uint8_t const** setme_str,
|
2017-04-19 12:04:45 +00:00
|
|
|
size_t* setme_strlen);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int tr_variantParseBenc(void const* buf, void const* end, tr_variant* top, char const** setme_end);
|
2020-08-11 18:11:55 +00:00
|
|
|
|
|
|
|
TR_END_DECLS
|