/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* lib/krad/code.c - RADIUS code name table for libkrad */2/*3* Copyright 2013 Red Hat, Inc. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions are met:7*8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10*11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in13* the documentation and/or other materials provided with the14* distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS17* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED18* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A19* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER20* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,21* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,22* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR23* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF24* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING25* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27*/2829#include "internal.h"3031#include <string.h>3233static const char *codes[UCHAR_MAX] = {34"Access-Request",35"Access-Accept",36"Access-Reject",37"Accounting-Request",38"Accounting-Response",39"Accounting-Status",40"Password-Request",41"Password-Ack",42"Password-Reject",43"Accounting-Message",44"Access-Challenge",45"Status-Server",46"Status-Client",47NULL,48NULL,49NULL,50NULL,51NULL,52NULL,53NULL,54"Resource-Free-Request",55"Resource-Free-Response",56"Resource-Query-Request",57"Resource-Query-Response",58"Alternate-Resource-Reclaim-Request",59"NAS-Reboot-Request",60"NAS-Reboot-Response",61NULL,62"Next-Passcode",63"New-Pin",64"Terminate-Session",65"Password-Expired",66"Event-Request",67"Event-Response",68NULL,69NULL,70NULL,71NULL,72NULL,73"Disconnect-Request",74"Disconnect-Ack",75"Disconnect-Nak",76"Change-Filters-Request",77"Change-Filters-Ack",78"Change-Filters-Nak",79NULL,80NULL,81NULL,82NULL,83"IP-Address-Allocate",84"IP-Address-Release",85};8687krad_code88krad_code_name2num(const char *name)89{90unsigned char i;9192for (i = 0; i < UCHAR_MAX; i++) {93if (codes[i] == NULL)94continue;9596if (strcmp(codes[i], name) == 0)97return ++i;98}99100return 0;101}102103const char *104krad_code_num2name(krad_code code)105{106if (code == 0)107return NULL;108109return codes[code - 1];110}111112113