X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=lib%2Fdebug.c;h=903c7931c492578be00411d846571481ce5c57b3;hb=fed9094cd8cda69605d0c103acd14308379b6eb0;hp=d2d8d9cda38a6176ec860a5587fa02324a325f0c;hpb=7ec20f4101e5a1ef0b5f2537f25a4f8d74ad1104;p=radsecproxy.git diff --git a/lib/debug.c b/lib/debug.c index d2d8d9c..903c793 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -1,81 +1,46 @@ -/* See the file COPYING for licensing information. */ +/* Copyright 2011 NORDUnet A/S. All rights reserved. + See LICENSE for licensing information. */ +#if defined HAVE_CONFIG_H +#include +#endif + +#include #include -#include -#include "libradsec.h" -#include "libradsec-impl.h" +#include +#include +#include +#include #include "debug.h" -/* From freeradius-server/src/lib/radius.c */ -static void print_hex(RADIUS_PACKET *packet) +void +rs_dump_packet (const struct rs_packet *pkt) { - int i; - - if (!packet->data) return; - - printf(" Code:\t\t%u\n", packet->data[0]); - printf(" Id:\t\t%u\n", packet->data[1]); - printf(" Length:\t%u\n", ((packet->data[2] << 8) | - (packet->data[3]))); - printf(" Vector:\t"); - for (i = 4; i < 20; i++) { - printf("%02x", packet->data[i]); - } - printf("\n"); - - if (packet->data_len > 20) { - int total; - const uint8_t *ptr; - printf(" Data:"); - - total = packet->data_len - 20; - ptr = packet->data + 20; - - while (total > 0) { - int attrlen; - - printf("\t\t"); - if (total < 2) { /* too short */ - printf("%02x\n", *ptr); - break; - } + const RADIUS_PACKET *p = NULL; - if (ptr[1] > total) { /* too long */ - for (i = 0; i < total; i++) { - printf("%02x ", ptr[i]); - } - break; - } + if (!pkt || !pkt->rpkt) + return; + p = pkt->rpkt; - printf("%02x %02x ", ptr[0], ptr[1]); - attrlen = ptr[1] - 2; - ptr += 2; - total -= 2; - - for (i = 0; i < attrlen; i++) { - if ((i > 0) && ((i & 0x0f) == 0x00)) - printf("\t\t\t"); - printf("%02x ", ptr[i]); - if ((i & 0x0f) == 0x0f) printf("\n"); - } - - if ((attrlen & 0x0f) != 0x00) printf("\n"); - - ptr += attrlen; - total -= attrlen; - } - } - fflush(stdout); + fprintf (stderr, "\tCode: %u, Identifier: %u, Lenght: %zu\n", + p->code, + p->id, + p->sizeof_data); + fflush (stderr); } -void -rs_dump_packet (const struct rs_packet *pkt) +#if defined DEBUG +int +_rs_debug (const char *fmt, ...) { - print_hex (pkt->rpkt); -} + int n; + va_list args; -void -rs_dump_attr (const struct rs_attr *attr) -{ - vp_printlist (stderr, attr->vp); + va_start (args, fmt); + n = vfprintf (stderr, fmt, args); + va_end (args); + fflush (stderr); + + return n; } +#endif