diff --git a/daemon/control_ng.c b/daemon/control_ng.c index 0cfd0b295..a66dd0728 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -480,6 +480,7 @@ const ng_parser_t ng_parser_native = { .dict_add_string = bencode_dictionary_add_string, .dict_add_str = bencode_dictionary_add_str, .dict_add_str_dup = bencode_dictionary_add_str_dup, + .dict_add_str_dup_dup = bencode_dictionary_add_str_dup_dup, .dict_add_int = bencode_dictionary_add_integer, .dict_add_dict = __bencode_dictionary_add_dictionary, .dict_add_dict_dup = __bencode_dictionary_add_dictionary_dup, @@ -516,6 +517,7 @@ const ng_parser_t ng_parser_json = { .dict_add_string = json_dict_add_string, .dict_add_str = json_dict_add_str, .dict_add_str_dup = json_dict_add_str, + .dict_add_str_dup_dup = json_dict_add_str, .dict_add_int = json_dict_add_int, .dict_add_dict = json_dict_add_dict, .dict_add_dict_dup = json_dict_add_dict, diff --git a/include/control_ng.h b/include/control_ng.h index 078f1473e..7481b3bd1 100644 --- a/include/control_ng.h +++ b/include/control_ng.h @@ -120,6 +120,7 @@ struct ng_parser { void (*dict_add_string)(parser_arg, const char *, const char *); void (*dict_add_str)(parser_arg, const char *, const str *); void (*dict_add_str_dup)(parser_arg, const char *, const str *); + void (*dict_add_str_dup_dup)(parser_arg, const char *, const str *); void (*dict_add_int)(parser_arg, const char *, long long); parser_arg (*dict_add_dict)(parser_arg, const char *); parser_arg (*dict_add_dict_dup)(parser_arg, const char *); diff --git a/lib/bencode.h b/lib/bencode.h index 464e672da..b975b6a80 100644 --- a/lib/bencode.h +++ b/lib/bencode.h @@ -116,6 +116,7 @@ INLINE void bencode_dictionary_add_string(bencode_item_t *dict, const char *key, INLINE void bencode_dictionary_add_str(bencode_item_t *dict, const char *key, const str *val); INLINE void bencode_dictionary_str_add_str(bencode_item_t *dict, const str *key, const str *val); INLINE void bencode_dictionary_add_str_dup(bencode_item_t *dict, const char *key, const str *val); +INLINE void bencode_dictionary_add_str_dup_dup(bencode_item_t *dict, const char *key, const str *val); /* Convenience functions to add the respective (newly created) objects to a dictionary */ INLINE void bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val); @@ -427,6 +428,12 @@ INLINE void bencode_dictionary_add_str_dup(bencode_item_t *dict, const char *key bencode_dictionary_add(dict, key, bencode_str_dup(bencode_item_buffer(dict), val)); } +INLINE void bencode_dictionary_add_str_dup_dup(bencode_item_t *dict, const char *key, const str *val) { + if (val) + bencode_dictionary_add(dict, bencode_strdup(bencode_item_buffer(dict), key), + bencode_str_dup(bencode_item_buffer(dict), val)); +} + INLINE void bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val) { bencode_dictionary_add(dict, key, bencode_integer(bencode_item_buffer(dict), val)); }