cleaning up #include files
[freeradius.git] / src / main / acct.c
1 /*
2  * acct.c       Accounting routines.
3  *
4  * Version:     @(#)acct.c  2.12  07-Aug-1999  miquels@cistron.nl
5  */
6 char acct_sccsid[] =
7 "@(#)acct.c     2.12 Copyright 1999 Cistron Internet Services B.V.";
8
9 #include        "autoconf.h"
10
11 #include        <stdlib.h>
12 #include        <string.h>
13
14 #include        "radiusd.h"
15 #include        "modules.h"
16
17
18 /*
19  *      rad_accounting: call modules.
20  */
21 int rad_accounting(REQUEST *request)
22 {
23         int             reply;
24
25         /*
26          *      FIXME: Prefix= and Suffix= support needs to be added!
27          *
28          *      We need to get the Prefix= and Suffix= things from
29          *      the users file to apply.
30          *      In 1.5.4.3, we used presuf_setup() but that is
31          *      not possible anymore. Perhaps we need an extra
32          *      module entry point for this ?
33          */
34         /* Like preacct? */
35
36         if(!request->proxy) { /* Only need to do this once, before proxying */
37           reply = module_preacct(request);
38           if (reply != RLM_MODULE_OK)
39                   return RLM_MODULE_FAIL;
40
41           /* Maybe one of the preacct modules has decided that a proxy should
42            * be used. If so, get out of here and send the packet. */
43           if(pairfind(request->config_items, PW_PROXY_TO_REALM))
44                   return 0;
45         }
46
47         reply = RLM_MODULE_OK;
48         if (!request->proxy) {
49                 /*
50                  *      Keep the radutmp file in sync.
51                  */
52                 radutmp_add(request);
53
54                 /*
55                  *      Do accounting and if OK, reply.
56                  */
57                 reply = module_accounting(request);
58         }
59         if (reply == RLM_MODULE_OK) {
60                 /*
61                  *      Now send back an ACK to the NAS.
62                  */
63                 request->reply = build_reply(PW_ACCOUNTING_RESPONSE, request,
64                                              NULL, NULL);
65                 reply = RLM_MODULE_OK;
66         }
67
68         return reply;
69 }
70