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