2 * print.c Routines to print stuff.
4 * Version: @(#)print.c 1.00 26-Oct-1998 miquels@cistron.nl
12 #include <sys/types.h>
18 #include "libradius.h"
21 * Convert a string to something printable.
22 * The output string has to be _at least_ 4x the size
23 * of the input string!
25 static void librad_safeprint(char *in, int inlen, char *out, int outlen)
27 unsigned char *str = (unsigned char *)in;
31 if (inlen < 0) inlen = strlen(str);
33 while (inlen-- > 0 && (done + 3) < outlen) {
35 * Hack: never print trailing zero.
36 * Some clients send strings with an off-by-one
37 * length (confused with strings in C).
39 if (inlen == 0 && *str == 0)
58 if (*str < 32 || (*str >= 128 && *str <= 160)){
59 sprintf(out, "\\%03o", *str);
79 * Print one attribute and value into a string.
81 void vp_prints(char *out, int outlen, VALUE_PAIR *vp)
90 if (strlen(vp->name) + 3 > outlen)
93 sprintf(out, "%s = ", vp->name);
100 if (vp->attribute == PW_NAS_PORT_ID)
104 librad_safeprint(vp->strvalue, vp->length,
105 buf + 1, sizeof(buf) - 2);
110 case PW_TYPE_INTEGER:
111 if ((v = dict_valbyattr(vp->attribute, vp->lvalue))
115 sprintf(buf, "%d", vp->lvalue);
121 strftime(buf, sizeof(buf), "\"%b %e %Y\"",
129 a = ip_ntoa(NULL, vp->lvalue);
135 strncpy(out, a, outlen);
141 * Print one attribute and value.
143 void vp_print(FILE *fp, VALUE_PAIR *vp)
147 vp_prints(buf, sizeof(buf), vp);
153 * Print a whole list of attributes, indented by a TAB
154 * and with a newline at the end.
156 void vp_printlist(FILE *fp, VALUE_PAIR *vp)
158 for (; vp; vp = vp->next) {