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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-05-04 19:58:34 +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
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
typedef void (* VariantWalkFunc)(const tr_variant* 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-19 12:04:45 +00:00
|
|
|
void tr_variantWalk(const tr_variant* top, const struct VariantWalkFuncs* walkFuncs, void* user_data, bool sort_dicts);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_variantToBufJson(const tr_variant* top, struct evbuffer* buf, bool lean);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_variantToBufBenc(const tr_variant* 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 */
|
|
|
|
int tr_jsonParse(const char* source, const void* vbuf, size_t len, tr_variant* setme_benc, const char** setme_end);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
|
|
|
/** @brief Private function that's exposed here only for unit tests */
|
2017-04-19 12:04:45 +00:00
|
|
|
int tr_bencParseInt(const uint8_t* buf, const uint8_t* bufend, const uint8_t** 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 */
|
2017-04-19 12:04:45 +00:00
|
|
|
int tr_bencParseStr(const uint8_t* buf, const uint8_t* bufend, const uint8_t** setme_end, const uint8_t** setme_str,
|
|
|
|
size_t* setme_strlen);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int tr_variantParseBenc(const void* buf, const void* end, tr_variant* top, const char** setme_end);
|