Mercurial > hg > freeDiameter
annotate extensions/app_acct/app_acct.h @ 741:d59decafe9c0
Updated copyright information
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Thu, 24 Mar 2011 15:00:38 +0900 |
parents | 4a9f08d6b6ba |
children |
rev | line source |
---|---|
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
528
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
741
d59decafe9c0
Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
5 * Copyright (c) 2011, WIDE Project and NICT * |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 /* Header file for the app_acct extension. |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
38 * This extension is a simple Diameter Accounting server. |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
39 * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
40 * It receives the Diameter Accounting-Request message, and sends its content in a |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
41 * "buffer" postgreSQL database (see configuration sample file app_acct.conf.sample). |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
42 * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
43 * The intent is that another application will then pick the records from this "buffer" database |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
44 * and process it accordingly to the requirements of the end application. |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
45 */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
46 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
47 #include <freeDiameter/extension.h> |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
48 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
49 /* The structure corresponding to an AVP entry in the configuration file */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
50 struct acct_conf_avp { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 /* Chain */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
52 struct fd_list chain; /* link in the global list */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
53 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
54 /* Raw information from the configuration file */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
55 char *avpname; /* the name of the AVP, as appear in the configuration file */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
56 char *field; /* the field name in the database, or NULL if it is the same as avpname */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
57 int required; /* set to true if this AVP has to be in the message */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
58 unsigned multi; /* the number of occurrences of this AVP we convert, or 0 if it was not specified */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
59 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
60 /* Parsed information */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
61 struct dict_object *avpobj; /* the dictionary object corresponding to this AVP */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
62 enum dict_avp_basetype avptype; /* this info is extracted from avpobj. GROUPED avps are not allowed yet */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
63 }; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
64 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
65 /* This is described only inside acct_db.c */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
66 struct acct_db; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
67 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
68 /* The complete configuration */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
69 struct acct_conf { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
70 /* AVPs */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
71 struct fd_list avps; /* the list of acct_conf_avp entries */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
72 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
73 /* Raw information */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
74 char *conninfo; /* the connection string to the database, that is passed as is to the database library */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
75 char *tablename; /* the name of the table we are working with */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
76 char *tsfield; /* the name of the timestamp field, or NULL if not required */ |
528
1b3b9790e7cb
Add a new field in the app_acct.fdx database to receive the name of the local server.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
77 char *srvnfield; /* the name of the server name field, or NULL if not required */ |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
78 }; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
79 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
80 /* A successfully parsed Accounting-Request produces a list of these: */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
81 struct acct_record_item { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
82 struct fd_list chain; /* link with all others */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
83 struct fd_list unmapd;/* link with only unmap'd records */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
84 struct acct_conf_avp *param; /* the AVP entry this refers to. */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
85 unsigned index; /* in case of multi */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
86 union avp_value *value; /* If the AVP was found in the message, this points to its value. Otherwise, NULL */ |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
87 union { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
88 uint32_t v32 /* Storage area for network byte-order copy of the AVP value */; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
89 uint64_t v64; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
90 char c; /* pointer that is passed to the database */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
91 } scalar;/* for scalar AVP (all types except OCTETSTRING) we copy in this area the value in network byte order */ |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
92 }; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
93 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
94 /* The sentinel for a list of acct_record_items */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
95 struct acct_record_list { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
96 struct fd_list all; /* The list of records */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
97 int nball; /* The number of records in all */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
98 struct fd_list unmaped;/* Only the records without a value */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
99 int nbunmap;/* The number of unmap'd records */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
100 }; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
101 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
102 /* Mapping of the data types between Diameter AVP and PQ types: */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
103 extern const char * diam2db_types_mapping[]; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
104 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
105 /* In acct_conf.y */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
106 extern struct acct_conf * acct_config; /* the global configuration */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
107 int acct_conf_init(void); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
108 int acct_conf_parse(char * conffile); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
109 int acct_conf_check(char * conffile); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
110 void acct_conf_free(void); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
111 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
112 /* In acct_db.c */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
113 int acct_db_init(void); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
114 int acct_db_insert(struct acct_record_list * records); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
115 void acct_db_free(void); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
116 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
117 /* In acct_records.c */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
118 int acct_rec_prepare(struct acct_record_list * records); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
119 int acct_rec_map(struct acct_record_list * records, struct msg * msg); |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
120 int acct_rec_validate(struct acct_record_list * records); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
121 void acct_rec_empty(struct acct_record_list * records); |