From: Alan T. DeKok Date: Tue, 10 Aug 2021 13:44:59 +0000 (-0400) Subject: rearrange and add "decode.internal" for the internal protocol X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e44cd4f1b326ac92b5e14cb4fc51a352160c1144;p=thirdparty%2Ffreeradius-server.git rearrange and add "decode.internal" for the internal protocol --- diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 0149589863d..5ccd37c2249 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -3115,49 +3115,59 @@ static int protocol_decode_xlat_instantiate(void *xlat_inst, UNUSED xlat_exp_t c return 0; } +static int xlat_protocol_register(fr_dict_t const *dict) +{ + fr_test_point_pair_decode_t *tp_decode; + xlat_t *xlat; + dl_t *dl = fr_dict_dl(dict); + char *p, buffer[256], name[256]; + + if (!dl) return -1; + + strlcpy(name, fr_dict_root(dict)->name, sizeof(name)); + for (p = name; *p != '\0'; p++) { + *p = tolower((int) *p); + } + + /* + * See if there's a decode function for it. + */ + snprintf(buffer, sizeof(buffer), "%s_tp_decode_pair", name); + + /* + * No decode == soft fail. + */ + tp_decode = dlsym(dl->handle, buffer); + if (!tp_decode) return 0; + + snprintf(buffer, sizeof(buffer), "decode.%s", name); + + xlat = xlat_register(NULL, buffer, protocol_decode_xlat, false); + xlat_func_args(xlat, protocol_decode_xlat_args); + xlat_async_instantiate_set(xlat, protocol_decode_xlat_instantiate, fr_test_point_pair_decode_t *, NULL, tp_decode); + + return 0; +} static int xlat_protocol_init(void) { fr_dict_t *dict; fr_dict_global_ctx_iter_t iter; - char *p, buffer[256], name[256]; /* * @todo - add encoder, too - * - * @todo - and for the "internal" protocol, too. */ for (dict = fr_dict_global_ctx_iter_init(&iter); dict != NULL; dict = fr_dict_global_ctx_iter_next(&iter)) { - dl_t *dl = fr_dict_dl(dict); - fr_test_point_pair_decode_t *tp_decode; - xlat_t *xlat; - - strlcpy(name, fr_dict_root(dict)->name, sizeof(name)); - for (p = name; *p != '\0'; p++) { - *p = tolower((int) *p); - } - - /* - * See if there's a decode function for it. - */ - snprintf(buffer, sizeof(buffer), "%s_tp_decode_pair", name); - - /* - * No decode == soft fail. - */ - tp_decode = dlsym(dl->handle, buffer); - if (!tp_decode) continue; - - snprintf(buffer, sizeof(buffer), "decode.%s", name); - ERROR("TP Decode %s -> %p", name, tp_decode); - - xlat = xlat_register(NULL, buffer, protocol_decode_xlat, false); - xlat_func_args(xlat, protocol_decode_xlat_args); - xlat_async_instantiate_set(xlat, protocol_decode_xlat_instantiate, fr_test_point_pair_decode_t *, NULL, tp_decode); + if (xlat_protocol_register(dict) < 0) return -1; } + /* + * And the internal protocol, too. + */ + if (xlat_protocol_register(fr_dict_internal()) < 0) return -1; + return 0; } @@ -3196,7 +3206,7 @@ int xlat_init(void) } /* - * Define encode/decode for the various protocols. + * Define encode/decode xlats for the various protocols. */ if (xlat_protocol_init() < 0) return -1;