]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Move radius_(get_|copy)_vp into xlat_func.c
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 16 May 2018 06:41:46 +0000 (12:41 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 16 May 2018 06:41:46 +0000 (12:41 +0600)
They're only used by xlat functions and should go away once all the functions have been converted.

src/include/radiusd.h
src/include/xlat.h
src/main/pair.c
src/main/xlat_func.c
src/modules/proto_dhcpv4/rlm_dhcpv4.c
src/modules/rlm_date/rlm_date.c
src/modules/rlm_dict/rlm_dict.c
src/modules/rlm_unpack/rlm_unpack.c
src/unlang/op.c

index 4d2d2fd9d38f81c3d69653d83d2ff397f4cafe6a..9b6dfcdadd51f072fc2d230873219609912d7ae2 100644 (file)
@@ -503,9 +503,6 @@ VALUE_PAIR  *radius_pair_create(TALLOC_CTX *ctx, VALUE_PAIR **vps, unsigned int a
 void log_module_failure_msg(REQUEST *request, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
 void vlog_module_failure_msg(REQUEST *request, char const *fmt, va_list ap) CC_HINT(format (printf, 2, 0));
 
-int radius_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name);
-int radius_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, char const *name);
-
 
 /*
  *     Less code == fewer bugs
index 0c91a35ceba6259815ae65de5daf5a2ff073cf09..197d4d1c1d4255f3ae573c7164e44fa00cbc2fa2 100644 (file)
@@ -231,6 +231,9 @@ typedef int (*xlat_detach_t)(void *xlat_inst, void *uctx);
  */
 typedef int (*xlat_thread_detach_t)(void *xlat_thread_inst, void *uctx);
 
+int            xlat_fmt_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name);
+int            xlat_fmt_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, char const *name);
+
 ssize_t                xlat_eval(char *out, size_t outlen, REQUEST *request, char const *fmt, xlat_escape_t escape,
                          void const *escape_ctx)
                          CC_HINT(nonnull (1 ,3 ,4));
index f7190010bdcb9d7246ba88470812befd9384a7ad..5f377725a9219bc87a60608e430d81e0a2b43b4b 100644 (file)
@@ -811,58 +811,3 @@ void rdebug_proto_pair_list(fr_log_lvl_t level, REQUEST *request, VALUE_PAIR *vp
        }
        REXDENT();
 }
-
-/** Return a VP from the specified request.
- *
- * @param out where to write the pointer to the resolved VP. Will be NULL if the attribute couldn't
- *     be resolved.
- * @param request current request.
- * @param name attribute name including qualifiers.
- * @return
- *     - -4 if either the attribute or qualifier were invalid.
- *     - The same error codes as #tmpl_find_vp for other error conditions.
- */
-int radius_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name)
-{
-       int rcode;
-       vp_tmpl_t *vpt;
-
-       *out = NULL;
-
-       if (tmpl_afrom_attr_str(request, &vpt, name,
-                               REQUEST_CURRENT, PAIR_LIST_REQUEST, false, false) <= 0) return -4;
-
-       rcode = tmpl_find_vp(out, request, vpt);
-       talloc_free(vpt);
-
-       return rcode;
-}
-
-/** Copy VP(s) from the specified request.
- *
- * @param ctx to alloc new VALUE_PAIRs in.
- * @param out where to write the pointer to the copied VP. Will be NULL if the attribute couldn't be
- *     resolved.
- * @param request current request.
- * @param name attribute name including qualifiers.
- * @return
- *     - -4 if either the attribute or qualifier were invalid.
- *     - The same error codes as #tmpl_find_vp for other error conditions.
- */
-int radius_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, char const *name)
-{
-       int rcode;
-       vp_tmpl_t *vpt;
-
-       *out = NULL;
-
-       if (tmpl_afrom_attr_str(request, &vpt, name,
-                               REQUEST_CURRENT, PAIR_LIST_REQUEST, false, false) <= 0) return -4;
-
-       rcode = tmpl_copy_vps(ctx, out, request, vpt);
-       talloc_free(vpt);
-
-       return rcode;
-}
-
-
index caf8f5085cc8d0e8281a7babcff131e7fe60661b..aed7a3c8f5d6bf92d38415b779bbba7b87e3d472 100644 (file)
@@ -71,6 +71,59 @@ static char const hextab[] = "0123456789abcdef";
 
 static int xlat_foreach_inst[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };     /* up to 10 for foreach */
 
+/** Return a VP from the specified request.
+ *
+ * @param out where to write the pointer to the resolved VP. Will be NULL if the attribute couldn't
+ *     be resolved.
+ * @param request current request.
+ * @param name attribute name including qualifiers.
+ * @return
+ *     - -4 if either the attribute or qualifier were invalid.
+ *     - The same error codes as #tmpl_find_vp for other error conditions.
+ */
+int xlat_fmt_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name)
+{
+       int rcode;
+       vp_tmpl_t *vpt;
+
+       *out = NULL;
+
+       if (tmpl_afrom_attr_str(request, &vpt, name,
+                               REQUEST_CURRENT, PAIR_LIST_REQUEST, false, false) <= 0) return -4;
+
+       rcode = tmpl_find_vp(out, request, vpt);
+       talloc_free(vpt);
+
+       return rcode;
+}
+
+/** Copy VP(s) from the specified request.
+ *
+ * @param ctx to alloc new VALUE_PAIRs in.
+ * @param out where to write the pointer to the copied VP. Will be NULL if the attribute couldn't be
+ *     resolved.
+ * @param request current request.
+ * @param name attribute name including qualifiers.
+ * @return
+ *     - -4 if either the attribute or qualifier were invalid.
+ *     - The same error codes as #tmpl_find_vp for other error conditions.
+ */
+int xlat_fmt_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, char const *name)
+{
+       int rcode;
+       vp_tmpl_t *vpt;
+
+       *out = NULL;
+
+       if (tmpl_afrom_attr_str(request, &vpt, name,
+                               REQUEST_CURRENT, PAIR_LIST_REQUEST, false, false) <= 0) return -4;
+
+       rcode = tmpl_copy_vps(ctx, out, request, vpt);
+       talloc_free(vpt);
+
+       return rcode;
+}
+
 /** Print length of its RHS.
  *
  */
@@ -93,7 +146,7 @@ static ssize_t xlat_length(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
 
        while (isspace((int) *fmt)) fmt++;
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
 
        snprintf(*out, outlen, "%zu", fr_value_box_network_length(&vp->data));
        return strlen(*out);
@@ -113,7 +166,7 @@ static ssize_t xlat_integer(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
 
        while (isspace((int) *fmt)) fmt++;
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
 
        switch (vp->vp_type) {
        case FR_TYPE_OCTETS:
@@ -193,7 +246,7 @@ static ssize_t xlat_hex(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
 
        while (isspace((int) *fmt)) fmt++;
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) {
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) {
        error:
                return -1;
        }
@@ -246,7 +299,7 @@ static ssize_t xlat_tag(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
 
        while (isspace((int) *fmt)) fmt++;
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
 
        if (!vp->da->flags.has_tag || !TAG_VALID(vp->tag)) return 0;
 
@@ -452,7 +505,7 @@ static ssize_t xlat_foreach(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen,
        /*
         *      See modcall, "FOREACH" for how this works.
         */
-       pvp = (VALUE_PAIR **) request_data_reference(request, (void *)radius_get_vp, *(int const *) mod_inst);
+       pvp = (VALUE_PAIR **) request_data_reference(request, (void *)xlat_fmt_get_vp, *(int const *) mod_inst);
        if (!pvp || !*pvp) return 0;
 
        *out = fr_pair_value_asprint(ctx, *pvp, '\0');
@@ -481,7 +534,7 @@ static ssize_t xlat_string(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
                return 0;
        }
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing;
 
        /*
         *      These are printed specially.
@@ -524,7 +577,7 @@ static ssize_t xlat_xlat(TALLOC_CTX *ctx, char **out, size_t outlen,
                return 0;
        }
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing;
 
        RDEBUG2("EXPAND %s", fmt);
        RINDENT();
@@ -932,7 +985,7 @@ static int fr_value_box_from_fmt(TALLOC_CTX *ctx, fr_value_box_t *out, REQUEST *
         *      attribute, and then store the data in network byte
         *      order.
         */
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return -1;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return -1;
 
        fr_value_box_copy(ctx, out, &vp->data);
 
index 2002cdd9bbdf98316ab280411ee23433e71f2e8f..6ccf5f7b7d2498ff8efea0089b04e9d90ca1489e 100644 (file)
@@ -140,7 +140,7 @@ static ssize_t dhcp_xlat(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
 
        while (isspace((int) *fmt)) fmt++;
 
-       if ((radius_copy_vp(request, &vp, request, fmt) < 0) || !vp) return 0;
+       if ((xlat_fmt_copy_vp(request, &vp, request, fmt) < 0) || !vp) return 0;
        fr_cursor_init(&cursor, &vp);
 
        len = fr_dhcpv4_encode_option(binbuf, sizeof(binbuf), &cursor, NULL);
index 033f5c08e54d5a1287c8da5b83efe4ff889842c9..334129302bd9b14aec0efa17a7b8ad5cfcd2cb3b 100644 (file)
@@ -104,7 +104,7 @@ static ssize_t xlat_date_convert(UNUSED TALLOC_CTX *ctx, char **out, size_t outl
                return date_encode_strftime(out, outlen, inst, request, now.tv_sec);
        }
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
 
        switch (vp->vp_type) {
        /*
index 05aef66cff92beeafb1a3677e4d0fd8aaca7848e..1ce7ae0fb3223960a4ddc465ab598d344e2b4a0a 100644 (file)
@@ -97,7 +97,7 @@ static ssize_t xlat_vendor(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen,
 
        while (isspace((int) *fmt)) fmt++;
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
 
        vendor = fr_dict_vendor_by_da(vp->da);
        if (!vendor) return 0;
@@ -117,7 +117,7 @@ static ssize_t xlat_vendor_num(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen
 
        while (isspace((int) *fmt)) fmt++;
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
 
        *out = talloc_typed_asprintf(ctx, "%i", fr_dict_vendor_num_by_da(vp->da));
        return talloc_array_length(*out) - 1;
@@ -134,7 +134,7 @@ static ssize_t xlat_attr(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen,
 
        while (isspace((int) *fmt)) fmt++;
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
        strlcpy(*out, vp->da->name, outlen);
 
        *out = talloc_typed_strdup(ctx, vp->da->name);
@@ -152,7 +152,7 @@ static ssize_t xlat_attr_num(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen,
 
        while (isspace((int) *fmt)) fmt++;
 
-       if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
+       if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0;
 
        *out = talloc_typed_asprintf(ctx, "%i", vp->da->attr);
        return talloc_array_length(*out) - 1;
index c83a23999959ff4fa8859120f0a7043bd0a83614..190ac8e089895957cb769e4b79a15c77b30ccd17 100644 (file)
@@ -90,7 +90,7 @@ static ssize_t unpack_xlat(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
         *      Attribute reference
         */
        if (*data_name == '&') {
-               if (radius_get_vp(&vp, request, data_name) < 0) goto nothing;
+               if (xlat_fmt_get_vp(&vp, request, data_name) < 0) goto nothing;
 
                if ((vp->vp_type != FR_TYPE_OCTETS) &&
                    (vp->vp_type != FR_TYPE_STRING)) {
index 0f043704086aa235d35d4705fc686aae2d29b84b..a409a892904fb9b710c665ac00ee13f7a9682614 100644 (file)
@@ -1299,7 +1299,7 @@ static unlang_action_t unlang_return(REQUEST *request,
        RDEBUG2("%s", unlang_ops[instruction->type].name);
 
        for (i = 8; i >= 0; i--) {
-               copy_p = request_data_get(request, (void *)radius_get_vp, i);
+               copy_p = request_data_get(request, (void *)xlat_fmt_get_vp, i);
                if (copy_p) {
                        if (instruction->type == UNLANG_TYPE_BREAK) {
                                RDEBUG2("# break Foreach-Variable-%d", i);
@@ -1344,7 +1344,7 @@ static unlang_action_t unlang_foreach(REQUEST *request,
                 *      FIXME: figure this out by walking up the modcall stack instead.
                 */
                for (i = 0; i < 8; i++) {
-                       if (!request_data_reference(request, (void *)radius_get_vp, i)) {
+                       if (!request_data_reference(request, (void *)xlat_fmt_get_vp, i)) {
                                foreach_depth = i;
                                break;
                        }
@@ -1410,7 +1410,7 @@ static unlang_action_t unlang_foreach(REQUEST *request,
                         *      the xlat outside of a foreach loop and trigger a segv.
                         */
                        fr_pair_list_free(&foreach->vps);
-                       request_data_get(request, (void *)radius_get_vp, foreach->depth);
+                       request_data_get(request, (void *)xlat_fmt_get_vp, foreach->depth);
 
                        *presult = frame->result;
                        if (*presult != RLM_MODULE_UNKNOWN) *priority = instruction->actions[*presult];
@@ -1438,7 +1438,7 @@ static unlang_action_t unlang_foreach(REQUEST *request,
         *      xlat.c, xlat_foreach() can find it.
         */
        foreach->variable = vp;
-       request_data_add(request, (void *)radius_get_vp, foreach->depth, &foreach->variable,
+       request_data_add(request, (void *)xlat_fmt_get_vp, foreach->depth, &foreach->variable,
                         false, false, false);
 
        /*