MT#55283 direct string parsing for received-from=

Change-Id: I8dd868ef24fafca71b857eccf397e2794c5d66a2
pull/1848/head
Richard Fuchs 1 year ago
parent edd28770e9
commit 94cea16603

@ -1402,6 +1402,10 @@ static void call_ng_flags_freqs(ng_parser_ctx_t *ctx, bencode_item_t *value) {
}
}
static void call_ng_received_from_string(ng_parser_ctx_t *ctx, str *s) {
ctx->flags->received_from_family = STR_NULL;
ctx->flags->received_from_address = *s;
}
static void call_ng_received_from_iter(ng_parser_ctx_t *ctx, str *key, helper_arg arg) {
switch ((*arg.i)++) {
case 0:
@ -1796,8 +1800,10 @@ void call_ng_main_flags(ng_parser_ctx_t *ctx, str *key, bencode_item_t *value, h
case CSH_LOOKUP("received from"):
case CSH_LOOKUP("received-from"):
if (!parser->is_list(value))
if (!parser->is_list(value)) {
call_ng_received_from_string(ctx, &s);
break;
}
int i = 0;
parser->list_iter(ctx, value, call_ng_received_from_iter, NULL, &i);
break;

@ -26,39 +26,6 @@ static const char *transports[] = {
* Helpers.
*/
static int get_ip_type(char *str_addr)
{
struct addrinfo hint, *info = NULL;
int ret;
memset(&hint, '\0', sizeof hint);
hint.ai_family = PF_UNSPEC;
hint.ai_flags = AI_NUMERICHOST;
ret = getaddrinfo(str_addr, NULL, &hint, &info);
if(ret) {
/* Invalid ip addinfos */
return -1;
}
if(info->ai_family == AF_INET) {
ilogs(control, LOG_DEBUG, "%s is an ipv4 addinfos", str_addr);
} else if(info->ai_family == AF_INET6) {
ilogs(control, LOG_DEBUG, "%s is an ipv6 addinfos", str_addr);
} else {
ilogs(control, LOG_DEBUG, "%s is an unknown addinfos format AF=%d", str_addr,
info->ai_family);
freeaddrinfo(info);
return -1;
}
ret = info->ai_family;
freeaddrinfo(info);
return ret;
}
/* parsing of key and val from string */
static bool get_key_val(str * key, str * val, str *in_out)
{
@ -100,29 +67,6 @@ static bool str_key_val_prefix(const str * p, const char * q,
* Work with bencode objects.
*/
/* parse `received-from` */
static bool parse_received_from(str * key, str * val, bencode_buffer_t * buf,
ng_parser_ctx_t *ctx)
{
bencode_item_t * item;
int ip_af = AF_UNSPEC;
str ipfamily, s;
if(str_key_val_prefix(key, "received-from", val, &s)) {
item = bencode_list(buf);
ip_af = get_ip_type(s.s);
ipfamily.len = 3;
ipfamily.s = (ip_af == AF_INET) ? "IP4" : "IP6";
bencode_list_add_str(item, &ipfamily);
bencode_list_add_str(item, &s);
call_ng_main_flags(ctx, &STR_CONST("received-from"), item, NULL);
return true;
}
return false;
}
static bool parse_codec_to_dict(str * key, str * val, const char *cmp1, const char *cmp2,
const char * dictstr, ng_parser_ctx_t *ctx, bencode_buffer_t * buf)
{
@ -229,10 +173,6 @@ void parse_rtpp_flags(const str * rtpp_flags, ng_parser_ctx_t *ctx)
if (!get_key_val(&key, &val, &remainder))
break;
/* specific received-from parsing */
if (parse_received_from(&key, &val, buf, ctx))
goto next;
/* codecs have own specific parsing as well */
if (parse_codecs(ctx, buf, &key, &val))
goto next;

Loading…
Cancel
Save