* Corrected spelling of my name in several .c files
[freeradius.git] / src / main / acct.c
1 /*
2  * acct.c       Accounting routines.
3  *
4  * Version:     $Id$
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * Copyright 2000  The FreeRADIUS server project
21  * Copyright 2000  Miquel van Smoorenburg <miquels@cistron.nl>
22  * Copyright 2000  Alan DeKok <aland@ox.org>
23  * Copyright 2000  Alan Curry <pacman-radius@cqc.com>
24  */
25
26 static const char rcsid[] = "$Id$";
27
28 #include        "autoconf.h"
29 #include        "libradius.h"
30
31 #include        <stdlib.h>
32 #include        <string.h>
33
34 #include        "radiusd.h"
35 #include        "modules.h"
36
37
38 /*
39  *      rad_accounting: call modules.
40  *
41  *      The return value of this function isn't actually used right now, so
42  *      it's not entirely clear if it is returning the right things. --Pac.
43  */
44 int rad_accounting(REQUEST *request)
45 {
46         int             reply;
47
48         if(!request->proxy) { /* Only need to do this once, before proxying */
49                 reply = module_preacct(request);
50                 if (reply != RLM_MODULE_NOOP &&
51                     reply != RLM_MODULE_OK &&
52                     reply != RLM_MODULE_UPDATED)
53                         return reply;
54                 
55                 /*
56                  *      Maybe one of the preacct modules has decided
57                  *      that a proxy should be used. If so, get out of
58                  *      here and send the packet.
59                  */
60                 if(pairfind(request->config_items, PW_PROXY_TO_REALM))
61                         return reply;
62         }
63
64         reply = RLM_MODULE_OK;
65         if (!request->proxy) {
66                 /*
67                  *      Do accounting and if OK, reply.
68                  */
69                 reply = module_accounting(request);
70         }
71         if (reply == RLM_MODULE_NOOP ||
72             reply == RLM_MODULE_OK ||
73             reply == RLM_MODULE_UPDATED) {
74                 /*
75                  *      Now send back an ACK to the NAS.
76                  */
77                 request->reply->code = PW_ACCOUNTING_RESPONSE;
78         }
79
80         return reply;
81 }
82