]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Rename json xlat functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 22 Jan 2024 22:33:53 +0000 (16:33 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 22 Jan 2024 22:34:03 +0000 (16:34 -0600)
doc/antora/modules/raddb/pages/mods-available/json.adoc
raddb/mods-available/json
src/lib/server/tmpl_dcursor.c
src/modules/rlm_json/rlm_json.c
src/tests/modules/json/json_quote.unlang
src/tests/modules/json/parser.unlang

index e4880392c5352ce22a60d1ac67d0bc0cd6be5ede..fc671513a8f0d0d72281003400b584ef31a99821 100644 (file)
@@ -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
index 01cd8bd521e6d4472703c6d3759fdeaa6ca331f8..fcb7f246157b073863f0ba07f1468da5435e5b6b 100644 (file)
@@ -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
index f4e75dd6a5de93f88af8914da655410580566661..89fa6a6ee22e0be64aeddf267b31ab3d1026f47f 100644 (file)
@@ -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);
 }
index 6a1f344ae6e59415f7ba50cb15f28e5853d7f8f6..2276522a81d86780f2a6aed87294e8d87bb166d2 100644 (file)
@@ -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");
 }
 
 /*
index fc3f9449f89631616111eef0c7b6bff2a01ac225..97f0799c6e280172d6a6d5114809206b86e7351e 100644 (file)
@@ -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
 }
 
index adb364dad102ada89c5b049c127d18356c13287a..5774b87bd0fbeab5216f582a09bf15819af60d87 100644 (file)
 #
 
 # 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
 }