From: Arran Cudbard-Bell Date: Mon, 22 Jan 2024 22:33:53 +0000 (-0600) Subject: Rename json xlat functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=252dca99c0a505f16f52965873256602477edb09;p=thirdparty%2Ffreeradius-server.git Rename json xlat functions --- diff --git a/doc/antora/modules/raddb/pages/mods-available/json.adoc b/doc/antora/modules/raddb/pages/mods-available/json.adoc index e4880392c53..fc671513a8f 100644 --- a/doc/antora/modules/raddb/pages/mods-available/json.adoc +++ b/doc/antora/modules/raddb/pages/mods-available/json.adoc @@ -145,7 +145,7 @@ strings. rlm_json provides the below xlat functions to handle the JSON documents. -### %json_jpath_validate(...) +### %json.jpath_validate(...) Determine if a jpath expression is valid. @@ -159,7 +159,7 @@ NOTE: Validate parser for everything except unions and expressions. ---- string payload payload := '$.my.json.payload[1]' -&reply.Reply-Message := "Validation of %{payload} is %json_jpath_validate($.my.json.payload[1])" +&reply.Reply-Message := "Validation of %{payload} is %json.jpath_validate($.my.json.payload[1])" ---- .Output @@ -168,7 +168,7 @@ payload := '$.my.json.payload[1]' Validation of $.my.json.payload[1] is 20:$.my.json.payload[1] ``` -### %json_quote(...) +### %json.quote(...) Escapes string for use as a JSON string. @@ -180,7 +180,7 @@ Escapes string for use as a JSON string. ---- string path &path := "caipirinha/gelada" -&reply.Reply-Message := "The string %{path} should be %json_quote(%{path}) to be a valid JSON string." +&reply.Reply-Message := "The string %{path} should be %json.quote(%{path}) to be a valid JSON string." ---- .Output diff --git a/raddb/mods-available/json b/raddb/mods-available/json index 01cd8bd521e..fcb7f246157 100644 --- a/raddb/mods-available/json +++ b/raddb/mods-available/json @@ -162,7 +162,7 @@ json { # # rlm_json provides the below xlat functions to handle the JSON documents. # -# ### %json_jpath_validate(...) +# ### %json.jpath_validate(...) # # Determine if a jpath expression is valid. # @@ -176,7 +176,7 @@ json { # ---- # string payload # payload := '$.my.json.payload[1]' -# &reply.Reply-Message := "Validation of %{payload} is %json_jpath_validate($.my.json.payload[1])" +# &reply.Reply-Message := "Validation of %{payload} is %json.jpath_validate($.my.json.payload[1])" # ---- # # .Output @@ -185,7 +185,7 @@ json { # Validation of $.my.json.payload[1] is 20:$.my.json.payload[1] # ``` # -# ### %json_quote(...) +# ### %json.quote(...) # # Escapes string for use as a JSON string. # @@ -197,7 +197,7 @@ json { # ---- # string path # &path := "caipirinha/gelada" -# &reply.Reply-Message := "The string %{path} should be %json_quote(%{path}) to be a valid JSON string." +# &reply.Reply-Message := "The string %{path} should be %json.quote(%{path}) to be a valid JSON string." # ---- # # .Output diff --git a/src/lib/server/tmpl_dcursor.c b/src/lib/server/tmpl_dcursor.c index f4e75dd6a5d..89fa6a6ee22 100644 --- a/src/lib/server/tmpl_dcursor.c +++ b/src/lib/server/tmpl_dcursor.c @@ -401,14 +401,14 @@ fr_pair_t *_tmpl_dcursor_init(int *err, TALLOC_CTX *ctx, tmpl_dcursor_ctx_t *cc, if (err) *err = 0; /* - * Navigate to the correct request context + * Navigate to the correct request context (parent, outer, curent, etc...) */ if (tmpl_request_ptr(&request, tmpl_request(vpt)) < 0) { if (err) *err = -3; memset(cc, 0, sizeof(*cc)); /* so tmpl_dcursor_clear doesn't explode */ return NULL; } - list = request->pair_root; + list = request->pair_root; /* Start navigating from the root of that request */ return tmpl_dcursor_init_relative(err, ctx, cc, cursor, request, list, vpt, build, uctx); } diff --git a/src/modules/rlm_json/rlm_json.c b/src/modules/rlm_json/rlm_json.c index 6a1f344ae6e..2276522a81d 100644 --- a/src/modules/rlm_json/rlm_json.c +++ b/src/modules/rlm_json/rlm_json.c @@ -594,11 +594,11 @@ static int mod_load(void) fr_json_version_print(); - if (unlikely(!(xlat = xlat_func_register(NULL, "json_escape", json_escape_xlat, FR_TYPE_STRING)))) return -1; + if (unlikely(!(xlat = xlat_func_register(NULL, "json.escape", json_escape_xlat, FR_TYPE_STRING)))) return -1; xlat_func_args_set(xlat, json_escape_xlat_arg); - if (unlikely(!(xlat = xlat_func_register(NULL, "json_quote", json_quote_xlat, FR_TYPE_STRING)))) return -1; + if (unlikely(!(xlat = xlat_func_register(NULL, "json.quote", json_quote_xlat, FR_TYPE_STRING)))) return -1; xlat_func_args_set(xlat, json_escape_xlat_arg); - if (unlikely(!(xlat = xlat_func_register(NULL, "json_jpath_validate", json_jpath_validate_xlat, FR_TYPE_STRING)))) return -1; + if (unlikely(!(xlat = xlat_func_register(NULL, "json.jpath_validate", json_jpath_validate_xlat, FR_TYPE_STRING)))) return -1; xlat_func_mono_set(xlat, json_jpath_validate_xlat_arg); return 0; @@ -606,8 +606,9 @@ static int mod_load(void) static void mod_unload(void) { - xlat_func_unregister("json_quote"); - xlat_func_unregister("json_jpath_validate"); + xlat_func_unregister("json.escape"); + xlat_func_unregister("json.quote"); + xlat_func_unregister("json.jpath_validate"); } /* diff --git a/src/tests/modules/json/json_quote.unlang b/src/tests/modules/json/json_quote.unlang index fc3f9449f89..97f0799c6e2 100644 --- a/src/tests/modules/json/json_quote.unlang +++ b/src/tests/modules/json/json_quote.unlang @@ -4,41 +4,41 @@ ipaddr test_ipaddr string dummy_string &test_string := "Hello\n" -if (!(%json_quote(%{test_string}) == "\"Hello\\n\"")) { +if (!(%json.quote(%{test_string}) == "\"Hello\\n\"")) { test_fail } &test_string := "Hello\nbob" -if (!(%json_quote(%{test_string}) == "\"Hello\\nbob\"")) { +if (!(%json.quote(%{test_string}) == "\"Hello\\nbob\"")) { test_fail } &test_string := "\nHello\nbob" -if (!(%json_quote(%{test_string}) == "\"\\nHello\\nbob\"")) { +if (!(%json.quote(%{test_string}) == "\"\\nHello\\nbob\"")) { test_fail } &test_string := "Hello!" -if (!(%json_quote(%{test_string}) == '"Hello!"')) { +if (!(%json.quote(%{test_string}) == '"Hello!"')) { test_fail } &test_integer := 123456 -if (!(%json_quote(%{test_integer}) == '123456')) { +if (!(%json.quote(%{test_integer}) == '123456')) { test_fail } &test_ipaddr := 127.0.0.1 -if (!(%json_quote(%{test_ipaddr}) == '"127.0.0.1"')) { +if (!(%json.quote(%{test_ipaddr}) == '"127.0.0.1"')) { test_fail } -if (!(%json_quote(%{dummy_string}) == 'null')) { +if (!(%json.quote(%{dummy_string}) == 'null')) { test_fail } # Test calls in arguments as would be passed to REST module -if (!(%test.passthrough("{\"messages\":[{\"attributes\":{\"acct_status_type\":%json_quote(%{Acct-Status-Type})}}]}") == '{"messages":[{"attributes":{"acct_status_type":null}}]}')) { +if (!(%test.passthrough("{\"messages\":[{\"attributes\":{\"acct_status_type\":%json.quote(%{Acct-Status-Type})}}]}") == '{"messages":[{"attributes":{"acct_status_type":null}}]}')) { test_fail } diff --git a/src/tests/modules/json/parser.unlang b/src/tests/modules/json/parser.unlang index adb364dad10..5774b87bd0f 100644 --- a/src/tests/modules/json/parser.unlang +++ b/src/tests/modules/json/parser.unlang @@ -3,207 +3,207 @@ # # 0. Expect success - Field selectors -if (%json_jpath_validate("$.foo.bar") != '9:$.foo.bar') { +if (%json.jpath_validate("$.foo.bar") != '9:$.foo.bar') { test_fail } # 1. Expect success - Field selectors -if (%json_jpath_validate("@.foo.bar") != '9:@.foo.bar') { +if (%json.jpath_validate("@.foo.bar") != '9:@.foo.bar') { test_fail } # 2. Expect success - Array selector -if (%json_jpath_validate("$.foo[1]") != '8:$.foo[1]') { +if (%json.jpath_validate("$.foo[1]") != '8:$.foo[1]') { test_fail } # 3. Expect success - Array selector -if (%json_jpath_validate("$.foo[1:2]") != '10:$.foo[1:2]') { +if (%json.jpath_validate("$.foo[1:2]") != '10:$.foo[1:2]') { test_fail } # 4. Expect success - Array slice selector -if (%json_jpath_validate("$.foo[:1]") != '9:$.foo[:1]') { +if (%json.jpath_validate("$.foo[:1]") != '9:$.foo[:1]') { test_fail } # 5. Expect success - Array slice selector -if (%json_jpath_validate("$.foo[1::1]") != '11:$.foo[1::1]') { +if (%json.jpath_validate("$.foo[1::1]") != '11:$.foo[1::1]') { test_fail } # 6. Expect success - Array step selector -if (%json_jpath_validate("$.foo[::2]") != '10:$.foo[::2]') { +if (%json.jpath_validate("$.foo[::2]") != '10:$.foo[::2]') { test_fail } # 7. Expect success - Array step selector -if (%json_jpath_validate("$.foo[1:1:2]") != '12:$.foo[1:1:2]') { +if (%json.jpath_validate("$.foo[1:1:2]") != '12:$.foo[1:1:2]') { test_fail } # 8. Expect success - Array multiple selectors -if (%json_jpath_validate("$.foo[1,1:1:2]") != '14:$.foo[1,1:1:2]') { +if (%json.jpath_validate("$.foo[1,1:1:2]") != '14:$.foo[1,1:1:2]') { test_fail } # 9. Expect success - Wildcard selector 1 -if (%json_jpath_validate("$.*") != '3:$.*') { +if (%json.jpath_validate("$.*") != '3:$.*') { test_fail } # 10. Expect success - Wildcard selector 2 -if (%json_jpath_validate("$.*.foo") != '7:$.*.foo') { +if (%json.jpath_validate("$.*.foo") != '7:$.*.foo') { test_fail } # 11. Expect success - Mixture of selectors -if (%json_jpath_validate("$.foo[::2].*.bar[::1]") != '21:$.foo[::2].*.bar[::1]') { +if (%json.jpath_validate("$.foo[::2].*.bar[::1]") != '21:$.foo[::2].*.bar[::1]') { test_fail } # 12. Expect success - Escape sequence -if (%json_jpath_validate("$.foo.bar\[\]") != '13:$.foo.bar\[\]') { +if (%json.jpath_validate("$.foo.bar\[\]") != '13:$.foo.bar\[\]') { test_fail } # 13. Expect success - Non escape sequence -if (%json_jpath_validate("$.foo.bar\@") != '11:$.foo.bar\@') { +if (%json.jpath_validate("$.foo.bar\@") != '11:$.foo.bar\@') { test_fail } # 14. Expect failure - Invalid starting char -if (%json_jpath_validate("[.foo") != '0:Expected root specifier \'$\', or current node specifier \'@\'') { +if (%json.jpath_validate("[.foo") != '0:Expected root specifier \'$\', or current node specifier \'@\'') { test_fail } # 15. Expect failure - Invalid char following root specifier -if (%json_jpath_validate("$[]") != '2:Empty selector') { +if (%json.jpath_validate("$[]") != '2:Empty selector') { test_fail } # 16. Expect failure - Invalid char following root specifier -if (%json_jpath_validate("$.") != '2:Expected recursive descent \'..\' wildcard \'*\' or field specifier') { +if (%json.jpath_validate("$.") != '2:Expected recursive descent \'..\' wildcard \'*\' or field specifier') { test_fail } # 17. Expect failure - Recursive descent after child delimiter -if (%json_jpath_validate("$...") != '3:Recursive descent must not be followed by child delimiter \'.\'') { +if (%json.jpath_validate("$...") != '3:Recursive descent must not be followed by child delimiter \'.\'') { test_fail } # 18. Expect failure - Missing selector terminator -if (%json_jpath_validate("$.foo[") != '6:Missing selector terminator \']\'') { +if (%json.jpath_validate("$.foo[") != '6:Missing selector terminator \']\'') { test_fail } # 19. Expect failure - Missing selector terminator -if (%json_jpath_validate("$.foo[0") != '7:Missing selector delimiter \',\' or terminator \']\'') { +if (%json.jpath_validate("$.foo[0") != '7:Missing selector delimiter \',\' or terminator \']\'') { test_fail } # 20. Expect failure - Unexpected selector terminator -if (%json_jpath_validate("$.foo]") != '5:Expected field specifier \'.\' or selector \'[\'') { +if (%json.jpath_validate("$.foo]") != '5:Expected field specifier \'.\' or selector \'[\'') { test_fail } # 21. Expect failure - Empty selector -if (%json_jpath_validate("$.foo[,") != '6:Empty selector') { +if (%json.jpath_validate("$.foo[,") != '6:Empty selector') { test_fail } # 22. Expect failure - Empty selector -if (%json_jpath_validate("$.foo[,]") != '6:Empty selector') { +if (%json.jpath_validate("$.foo[,]") != '6:Empty selector') { test_fail } # 23. Expect failure - Empty selector -if (%json_jpath_validate("$.foo[]") != '6:Empty selector') { +if (%json.jpath_validate("$.foo[]") != '6:Empty selector') { test_fail } # 24. Expect failure - Empty selector -if (%json_jpath_validate("$.foo[1,1:1:2,]") != '14:Empty selector') { +if (%json.jpath_validate("$.foo[1,1:1:2,]") != '14:Empty selector') { test_fail } # 25. Expect failure - Bad array index -if (%json_jpath_validate("$.foo[a]") != '6:Expected num, \':\' or \']\'') { +if (%json.jpath_validate("$.foo[a]") != '6:Expected num, \':\' or \']\'') { test_fail } # 26. Expect failure - Bad array end -if (%json_jpath_validate("$.foo[0:a]") != '8:Expected num, \':\' or \']\'') { +if (%json.jpath_validate("$.foo[0:a]") != '8:Expected num, \':\' or \']\'') { test_fail } # 27. Expect failure - Bad array slice -if (%json_jpath_validate("$.foo[0:0:a]") != '10:Expected num or \']\'') { +if (%json.jpath_validate("$.foo[0:0:a]") != '10:Expected num or \']\'') { test_fail } # 28. Expect failure - Bad array slice value -if (%json_jpath_validate("$.foo[0:0:0]") != '10:Step cannot be 0') { +if (%json.jpath_validate("$.foo[0:0:0]") != '10:Step cannot be 0') { test_fail } # 29. Expect failure - Field too long -if (%json_jpath_validate("$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") != '134:Exceeded maximum field name length') { +if (%json.jpath_validate("$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") != '134:Exceeded maximum field name length') { test_fail } # 30. Expect success - Field ok -if (%json_jpath_validate("$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") != '134:$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') { +if (%json.jpath_validate("$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") != '134:$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') { test_fail } # 31. Expect failure - Empty field -if (%json_jpath_validate("$.foo.[]") != '6:Empty field specifier') { +if (%json.jpath_validate("$.foo.[]") != '6:Empty field specifier') { test_fail } # 32. Expect success - Nested array -if (%json_jpath_validate("$[0][1]") != '7:$[0][1]') { +if (%json.jpath_validate("$[0][1]") != '7:$[0][1]') { test_fail } # 33. Expect success - Nested array with multiple indices -if (%json_jpath_validate("$[0][1,2]") != '9:$[0][1,2]') { +if (%json.jpath_validate("$[0][1,2]") != '9:$[0][1,2]') { test_fail } # 34. Expect failure - Recursive descent followed by nothing -if (%json_jpath_validate("$..") != '2:Path may not end in recursive descent') { +if (%json.jpath_validate("$..") != '2:Path may not end in recursive descent') { test_fail } # 35. Expect success - Recursive descent followed by field -if (%json_jpath_validate("$..foo") != '6:$..foo') { +if (%json.jpath_validate("$..foo") != '6:$..foo') { test_fail } # 36. Expect success - Recursive descent followed by selector -if (%json_jpath_validate("$..[0]") != '6:$..[0]') { +if (%json.jpath_validate("$..[0]") != '6:$..[0]') { test_fail } # 37. Expect success - Recursive descent followed by two selectors -if (%json_jpath_validate("$..foo[0]") != '9:$..foo[0]') { +if (%json.jpath_validate("$..foo[0]") != '9:$..foo[0]') { test_fail } # 38. Expect success - Recursive descent followed by wildcard -if (%json_jpath_validate("$..*") != '4:$..*') { +if (%json.jpath_validate("$..*") != '4:$..*') { test_fail } # 39. Expect failure - Filter expressions NYI -if (%json_jpath_validate("$.foo[?@.bar = baz]") != '6:Filter expressions not yet implemented') { +if (%json.jpath_validate("$.foo[?@.bar = baz]") != '6:Filter expressions not yet implemented') { test_fail } # 40. Expect failure - Expressions NYI -if (%json_jpath_validate("$.foo[(@.bar = baz)]") != '6:Expressions not yet implemented') { +if (%json.jpath_validate("$.foo[(@.bar = baz)]") != '6:Expressions not yet implemented') { test_fail }