Browse Source

MT#55283 add abstract dict_add/list/list_add

Change-Id: Id0cfcfa1504135473b7e4d355bfe5e28d089a6d1
pull/1848/head
Richard Fuchs 1 year ago
parent
commit
8f6b8b206b
3 changed files with 15 additions and 3 deletions
  1. +9
    -0
      daemon/control_ng.c
  2. +3
    -3
      daemon/statistics.c
  3. +3
    -0
      include/control_ng.h

+ 9
- 0
daemon/control_ng.c View File

@ -130,6 +130,9 @@ static long long bencode_get_int(bencode_item_t *arg) {
static bencode_item_t *__bencode_dict(ng_parser_ctx_t *ctx) {
return bencode_dictionary(&ctx->ngbuf->buffer);
}
static bencode_item_t *__bencode_list(ng_parser_ctx_t *ctx) {
return bencode_list(&ctx->ngbuf->buffer);
}
const ng_parser_t ng_parser_native = {
.collapse = bencode_collapse_str,
@ -142,11 +145,14 @@ const ng_parser_t ng_parser_native = {
.get_int = bencode_get_int,
.dict = __bencode_dict,
.dict_get_str = bencode_dictionary_get_str,
.dict_add = bencode_dictionary_add,
.dict_add_string = bencode_dictionary_add_string,
.dict_add_str = bencode_dictionary_add_str,
.dict_add_int = bencode_dictionary_add_integer,
.dict_add_dict = bencode_dictionary_add_dictionary,
.dict_add_list = bencode_dictionary_add_list,
.list = __bencode_list,
.list_add = bencode_list_add,
.list_add_dict = bencode_list_add_dictionary,
.list_add_string = bencode_list_add_string,
};
@ -161,11 +167,14 @@ const ng_parser_t ng_parser_json = {
.get_int = bencode_get_int,
.dict = __bencode_dict,
.dict_get_str = bencode_dictionary_get_str,
.dict_add = bencode_dictionary_add,
.dict_add_string = bencode_dictionary_add_string,
.dict_add_str = bencode_dictionary_add_str,
.dict_add_int = bencode_dictionary_add_integer,
.dict_add_dict = bencode_dictionary_add_dictionary,
.dict_add_list = bencode_dictionary_add_list,
.list = __bencode_list,
.list_add = bencode_list_add,
.list_add_dict = bencode_list_add_dictionary,
.list_add_string = bencode_list_add_string,
};


+ 3
- 3
daemon/statistics.c View File

@ -998,17 +998,17 @@ const char *statistics_ng(ng_parser_ctx_t *ctx) {
if (m->is_brace)
sub = ctx->parser->dict(ctx);
else
sub = bencode_list(buf);
sub = ctx->parser->list(ctx);
assert(sub != NULL);
// is this a dictionary?
if (dict->type == BENCODE_DICTIONARY) {
assert(sub_label != NULL);
bencode_dictionary_add(dict, bencode_strdup(buf, sub_label), sub);
ctx->parser->dict_add(dict, bencode_strdup(buf, sub_label), sub);
}
else if (ctx->parser->is_list(dict))
bencode_list_add(dict, sub);
ctx->parser->list_add(dict, sub);
else
abort();


+ 3
- 0
include/control_ng.h View File

@ -123,11 +123,14 @@ struct ng_parser {
long long (*get_int)(bencode_item_t *);
bencode_item_t *(*dict)(ng_parser_ctx_t *);
char *(*dict_get_str)(bencode_item_t *, const char *, str *);
bencode_item_t *(*dict_add)(bencode_item_t *, const char *, bencode_item_t *);
void (*dict_add_string)(bencode_item_t *, const char *, const char *);
void (*dict_add_str)(bencode_item_t *, const char *, const str *);
void (*dict_add_int)(bencode_item_t *, const char *, long long);
bencode_item_t *(*dict_add_dict)(bencode_item_t *, const char *);
bencode_item_t *(*dict_add_list)(bencode_item_t *, const char *);
bencode_item_t *(*list)(ng_parser_ctx_t *);
bencode_item_t *(*list_add)(bencode_item_t *, bencode_item_t *);
bencode_item_t *(*list_add_dict)(bencode_item_t *);
void (*list_add_string)(bencode_item_t *, const char *);
};


Loading…
Cancel
Save