~ubuntu-branches/ubuntu/natty/freeradius/natty-updates

« back to all changes in this revision

Viewing changes to src/main/xlat.c

  • Committer: Bazaar Package Importer
  • Author(s): Paul Hampson
  • Date: 2006-01-15 13:34:13 UTC
  • mto: (3.1.3 dapper) (4.1.3 sid) (1.1.14 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060115133413-zo1dslttvdoalqym
Tags: upstream-1.1.0
ImportĀ upstreamĀ versionĀ 1.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * xlat.c       Translate strings.  This is the first version of xlat
3
3
 *              incorporated to RADIUS
4
4
 *
5
 
 * Version:     $Id: xlat.c,v 1.72.2.7 2005/08/29 16:19:41 aland Exp $
 
5
 * Version:     $Id: xlat.c,v 1.72.2.7.2.1 2005/12/08 12:47:56 nbk Exp $
6
6
 *
7
7
 *   This program is free software; you can redistribute it and/or modify
8
8
 *   it under the terms of the GNU General Public License as published by
23
23
 */
24
24
 
25
25
static const char rcsid[] =
26
 
"$Id: xlat.c,v 1.72.2.7 2005/08/29 16:19:41 aland Exp $";
 
26
"$Id: xlat.c,v 1.72.2.7.2.1 2005/12/08 12:47:56 nbk Exp $";
27
27
 
28
28
#include        "autoconf.h"
29
29
#include        "libradius.h"
141
141
         *      The "format" string is the attribute name.
142
142
         */
143
143
        da = dict_attrbyname(fmt);
144
 
        if (!da) return 0;
 
144
        if (!da) {
 
145
                int index;
 
146
                const char *p = strchr(fmt, '[');
 
147
                char buffer[256];
 
148
 
 
149
                if (!p) return 0;
 
150
                if (strlen(fmt) > sizeof(buffer)) return 0;
 
151
 
 
152
                strNcpy(buffer, fmt, p - fmt + 1);
 
153
 
 
154
                index = atoi(p + 1);
 
155
 
 
156
                /*
 
157
                 *      Check the format of the index before looking
 
158
                 *      the attribute up in the dictionary, because
 
159
                 *      it's a cheap check.
 
160
                 */
 
161
                p += 1 + strspn(p + 1, "0123456789");
 
162
                if (*p != ']') {
 
163
                        DEBUG2("xlat: Invalid array reference in string at %s %s",
 
164
                               fmt, p);
 
165
                        return 0;
 
166
                }
 
167
 
 
168
                da = dict_attrbyname(buffer);
 
169
                if (!da) return 0;
 
170
 
 
171
 
 
172
                /*
 
173
                 *      Find the N'th value.
 
174
                 */
 
175
                for (vp = pairfind(vps, da->attr);
 
176
                     vp != NULL;
 
177
                     vp = pairfind(vp->next, da->attr)) {
 
178
                        if (index == 0) break;
 
179
                        index--;
 
180
                }
 
181
 
 
182
                /*
 
183
                 *      Non-existent array reference.
 
184
                 */
 
185
                if (!vp) return 0;
 
186
 
 
187
                return valuepair2str(out, outlen, vp, da->type, func);
 
188
        }
145
189
 
146
190
        vp = pairfind(vps, da->attr);
147
191
        if (!vp) {