1 /* 2 * This file Copyright (C) 2008-2014 Mnemosyne LLC 3 * 4 * It may be used under the GNU GPL versions 2 or 3 5 * or any future license endorsed by Mnemosyne LLC. 6 * 7 */ 8 9 #pragma once 10 11 #ifndef __LIBTRANSMISSION_VARIANT_MODULE__ 12 #error only libtransmission/variant-*.c should #include this header. 13 #endif 14 15 typedef void (* VariantWalkFunc)(tr_variant const* val, void* user_data); 16 17 struct VariantWalkFuncs 18 { 19 VariantWalkFunc intFunc; 20 VariantWalkFunc boolFunc; 21 VariantWalkFunc realFunc; 22 VariantWalkFunc stringFunc; 23 VariantWalkFunc dictBeginFunc; 24 VariantWalkFunc listBeginFunc; 25 VariantWalkFunc containerEndFunc; 26 }; 27 28 void tr_variantWalk(tr_variant const* top, struct VariantWalkFuncs const* walkFuncs, void* user_data, bool sort_dicts); 29 30 void tr_variantToBufJson(tr_variant const* top, struct evbuffer* buf, bool lean); 31 32 void tr_variantToBufBenc(tr_variant const* top, struct evbuffer* buf); 33 34 void tr_variantInit(tr_variant* v, char type); 35 36 /* source - such as a filename. Only when logging an error */ 37 int tr_jsonParse(char const* source, void const* vbuf, size_t len, tr_variant* setme_benc, char const** setme_end); 38 39 /** @brief Private function that's exposed here only for unit tests */ 40 int tr_bencParseInt(uint8_t const* buf, uint8_t const* bufend, uint8_t const** setme_end, int64_t* setme_val); 41 42 /** @brief Private function that's exposed here only for unit tests */ 43 int tr_bencParseStr(uint8_t const* buf, uint8_t const* bufend, uint8_t const** setme_end, uint8_t const** setme_str, 44 size_t* setme_strlen); 45 46 int tr_variantParseBenc(void const* buf, void const* end, tr_variant* top, char const** setme_end); 47