]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
print grouped options as Foo = { attr = 1, attr = 2 }
authorAlan T. DeKok <aland@freeradius.org>
Wed, 15 Jan 2020 18:55:44 +0000 (13:55 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 15 Jan 2020 21:28:25 +0000 (16:28 -0500)
src/lib/util/pair.c

index 34d3a88b86960007b8a60b2e1b9d1af71b9c6fcf..15a1a6c5fc854e0eb04691ff957a0d302e81d692 100644 (file)
@@ -2310,6 +2310,47 @@ size_t fr_pair_value_snprint(char *out, size_t outlen, VALUE_PAIR const *vp, cha
 
        if (vp->type == VT_XLAT) return snprintf(out, outlen, "%c%s%c", quote, vp->xlat, quote);
 
+       if (vp->da->type == FR_TYPE_GROUP) {
+               VALUE_PAIR *child, *head = vp->vp_ptr;
+               fr_cursor_t cursor;
+               char *p, *end;
+               size_t len;
+
+               if (!fr_cond_assert(head != NULL)) return 0;
+
+               /*
+                *      "{  }"
+                */
+               if (outlen < 4) return 0;
+
+               p = out;
+               end = out + outlen - 2; /* need room for the last " }" */
+
+               *(p++) = '{';
+               *(p++) = ' ';
+
+               for (child = fr_cursor_init(&cursor, &head);
+                    child != NULL;
+                    child = fr_cursor_next(&cursor)) {
+                       VP_VERIFY(child);
+
+                       len = fr_pair_snprint(p, end - p, child);
+                       if (len == 0) goto done;
+
+                       p += len;
+                       *(p++) = ',';
+                       *(p++) = ' ';
+
+               }
+
+               p -= 2;         /* over-write the last ", " */
+
+       done:
+               *(p++) = ' ';
+               *(p++) = '}';
+               return p - out;
+       }
+
        return fr_value_box_snprint(out, outlen, &vp->data, quote);
 }