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