Modifying the return value of cfg_set* functions, in order to make
[sip-router] / rad_dict.h
1 /*
2  * Include file for RADIUS
3  *
4  * Copyright (C) 2001-2003 FhG FOKUS
5  *
6  * This file is part of ser, a free SIP server.
7  *
8  * ser is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * For a license to use the ser software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * ser is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License 
24  * along with this program; if not, write to the Free Software 
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27
28 /*
29  * WARNING: Don't forget to update sip_router/etc/dictionary.ser if you 
30  * update this file !
31  */
32
33 #ifndef _RAD_DICT_H
34 #define _RAD_DICT_H
35
36 struct attr {
37         const char *n;
38         int v;
39 };
40
41 struct val {
42         const char *n;
43         int v;
44 };
45
46 typedef enum rad_attr {
47              /* Standard attributes according to RFC2865 and RFC2866 */
48         A_USER_NAME = 0,
49         A_NAS_IP_ADDRESS,
50         A_NAS_PORT,
51         A_SERVICE_TYPE,
52         A_CALLED_STATION_ID,
53         A_CALLING_STATION_ID,
54         A_ACCT_STATUS_TYPE,
55         A_ACCT_SESSION_ID,
56         A_ACCT_SESSION_TIME,
57
58              /* Attributes according to draft-schulzrinne-sipping-radius-accounting-00 */
59         A_SIP_METHOD,
60         A_SIP_RESPONSE_CODE,
61         A_SIP_CSEQ,
62         A_SIP_TO_TAG,
63         A_SIP_FROM_TAG,
64         A_SIP_BRANCH_ID,
65         A_SIP_TRANSLATED_REQUEST_ID,
66         A_SIP_SOURCE_IP_ADDRESS,
67         A_SIP_SOURCE_PORT,
68         
69              /* Attributes according to draft-sterman-aaa-sip-00 */
70         A_DIGEST_RESPONSE,
71         A_DIGEST_REALM,
72         A_DIGEST_NONCE,
73         A_DIGEST_METHOD,
74         A_DIGEST_URI,
75         A_DIGEST_QOP,
76         A_DIGEST_ALGORITHM,
77         A_DIGEST_BODY_DIGEST,
78         A_DIGEST_CNONCE,
79         A_DIGEST_NONCE_COUNT,
80         A_DIGEST_USER_NAME,
81
82              /* To be deprecated in the future */
83
84              /* SER-specific attributes */
85         A_SER_FROM,
86         A_SER_FLAGS,
87         A_SER_ORIGINAL_REQUEST_ID,
88         A_SER_TO,
89         A_SER_DIGEST_USERNAME,
90         A_SER_DIGEST_REALM,
91         A_SER_REQUEST_TIMESTAMP,
92         A_SER_TO_DID,
93         A_SER_FROM_UID,
94         A_SER_FROM_DID,
95         A_SER_TO_UID,
96         A_SER_RESPONSE_TIMESTAMP,
97         A_SER_ATTR,
98         A_SER_SERVICE_TYPE,
99         A_SER_DID,
100         A_SER_UID,
101         A_SER_DOMAIN,
102         A_SER_URI_USER,
103         A_SER_URI_SCHEME,
104
105              /* CISCO Vendor Specific Attributes */
106         A_CISCO_AVPAIR,
107         A_MAX
108 } rad_attr_t;
109
110
111 typedef enum rad_val {
112          /* Acct-Status-Type */
113         V_START = 0,
114         V_STOP,
115         V_INTERIM_UPDATE,
116         V_FAILED,
117
118              /* Service-Type */
119         V_SIP_SESSION,
120         V_CALL_CHECK,
121
122              /* SER-Service-Type */
123         V_GET_URI_ATTRS,
124         V_GET_USER_ATTRS,
125         V_DIGEST_AUTHENTICATION,
126         V_GET_DOMAIN_ATTRS,
127         V_GET_GLOBAL_ATTRS,
128         V_LOOKUP_DOMAIN,
129
130         V_MAX
131 } rad_val_t;
132
133
134 /*
135  * Search the RADIUS dictionary for codes of all attributes
136  * and values defined above
137  */
138 #define INIT_AV(rh, at, vl, fn, e1, e2)                                 \
139 {                                                                       \
140         int i;                                                          \
141         DICT_ATTR *da;                                                  \
142         DICT_VALUE *dv;                                                 \
143                                                                         \
144         for (i = 0; i < A_MAX; i++) {                                   \
145                 if (at[i].n == NULL)                                    \
146                         continue;                                       \
147                 da = rc_dict_findattr(rh, at[i].n);                     \
148                 if (da == NULL) {                                       \
149                         LOG(L_ERR, "ERROR: %s: can't get code for the " \
150                                    "%s attribute\n", fn, at[i].n);      \
151                         return e1;                                      \
152                 }                                                       \
153                 at[i].v = da->value;                                    \
154         }                                                               \
155         for (i = 0; i < V_MAX; i++) {                                   \
156                 if (vl[i].n == NULL)                                    \
157                         continue;                                       \
158                 dv = rc_dict_findval(rh, vl[i].n);                      \
159                 if (dv == NULL) {                                       \
160                         LOG(L_ERR, "ERROR: %s: can't get code for the " \
161                                    "%s attribute value\n", fn, vl[i].n);\
162                         return e2;                                      \
163                 }                                                       \
164                 vl[i].v = dv->value;                                    \
165         }                                                               \
166 }
167
168 #endif /* _RAD_DICT_H */