Mercurial > hg > freeDiameter
annotate extensions/app_acct/acct_db.c @ 292:a77ed0e30ac9
Fix non-working timestamp field
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Mon, 10 May 2010 14:26:42 +0900 |
parents | 0daf6fc2b751 |
children | 26aafbbc1640 |
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) * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
5 * Copyright (c) 2010, WIDE Project and NICT * |
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 /* Database interface module */ |
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 #include "app_acct.h" |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
39 #include <libpq-fe.h> |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
40 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
41 const char * diam2db_types_mapping[AVP_TYPE_MAX + 1] = { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
42 "" /* AVP_TYPE_GROUPED */, |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
43 "bytea" /* AVP_TYPE_OCTETSTRING */, |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
44 "integer" /* AVP_TYPE_INTEGER32 */, |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
45 "bigint" /* AVP_TYPE_INTEGER64 */, |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
46 "integer" /* AVP_TYPE_UNSIGNED32 + cast */, |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
47 "bigint" /* AVP_TYPE_UNSIGNED64 + cast */, |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
48 "real" /* AVP_TYPE_FLOAT32 */, |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
49 "double precision" /* AVP_TYPE_FLOAT64 */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
50 }; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
52 static const char * stmt = "acct_db_stmt"; |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
53 #ifndef TEST_DEBUG |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
54 static |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
55 #endif /* TEST_DEBUG */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
56 PGconn *conn = NULL; |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
57 |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
58 /* Initialize the database context: connection to the DB, prepared statement to insert new records */ |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
59 int acct_db_init(void) |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
60 { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
61 struct acct_record_list emptyrecords; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
62 struct fd_list * li; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
63 char * sql=NULL; /* The buffer that will contain the SQL query */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
64 size_t sql_allocd = 0; /* The malloc'd size of the buffer */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
65 size_t sql_offset = 0; /* The actual data already written in this buffer */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
66 size_t p; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
67 int idx = 0; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
68 PGresult * res; |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
69 #define REALLOC_SIZE 1024 /* We extend the buffer by this amount */ |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
70 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
71 TRACE_ENTRY(); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
72 CHECK_PARAMS( acct_config && acct_config->conninfo && acct_config->tablename ); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
73 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
74 /* Use the information from acct_config to create the connection and prepare the query */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
75 conn = PQconnectdb(acct_config->conninfo); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
76 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
77 /* Check to see that the backend connection was successfully made */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
78 if (PQstatus(conn) != CONNECTION_OK) { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
79 fd_log_debug("Connection to database failed: %s\n", PQerrorMessage(conn)); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
80 acct_db_free(); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
81 return EINVAL; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
82 } |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
83 if (PQprotocolVersion(conn) < 3) { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
84 fd_log_debug("Database protocol version is too old, version 3 is required for prepared statements.\n"); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
85 acct_db_free(); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
86 return EINVAL; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
87 } |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
88 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
89 TRACE_DEBUG(FULL, "Connection to database successful, server version %d.", PQserverVersion(conn)); |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
90 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
91 /* Now, prepare the request object */ |
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 /* First, we build the list of AVP we will insert in the database */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
94 CHECK_FCT( acct_rec_prepare(&emptyrecords) ); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
95 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
96 /* Now, prepare the text of the request */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
97 CHECK_MALLOC(sql = malloc(REALLOC_SIZE)); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
98 sql_allocd = REALLOC_SIZE; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
99 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
100 /* This macro hides the details of extending the buffer on each sprintf... */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
101 #define ADD_EXTEND(args...) { \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
102 size_t p; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
103 int loop = 0; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
104 do { \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
105 p = snprintf(sql + sql_offset, sql_allocd - sql_offset, ##args); \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
106 if (p >= sql_allocd - sql_offset) { \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
107 /* Too short, extend the buffer and start again */ \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
108 CHECK_MALLOC( sql = realloc(sql, sql_allocd + REALLOC_SIZE) ); \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
109 sql_allocd += REALLOC_SIZE; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
110 loop++; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
111 ASSERT(loop < 100); /* detect infinite loops */ \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
112 continue; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
113 } \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
114 sql_offset += p; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
115 break; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
116 } while (1); \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
117 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
118 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
119 /* This macro allows to add a value in the SQL buffer while escaping in properly */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
120 #define ADD_ESCAPE(str) { \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
121 char * __s = (char *)str; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
122 /* Check we have at least twice the size available +1 */ \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
123 size_t p = strlen(__s); \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
124 \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
125 while (sql_allocd - sql_offset < 2 * p + 1) { \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
126 /* Too short, extend the buffer */ \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
127 CHECK_MALLOC( sql = realloc(sql, sql_allocd + REALLOC_SIZE) ); \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
128 sql_allocd += REALLOC_SIZE; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
129 } \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
130 \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
131 /* Now add the escaped string */ \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
132 p = PQescapeStringConn(conn, sql+sql_offset, __s, p, NULL); \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
133 sql_offset += p; \ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
134 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
135 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
136 /* INSERT INTO table (tsfield, field1, field2, ...) VALUES (now, $1::bytea, $2::integer, ...) */ |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
137 ADD_EXTEND("INSERT INTO %s (", acct_config->tablename); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
138 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
139 if (acct_config->tsfield) { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
140 ADD_EXTEND("\""); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
141 ADD_ESCAPE(acct_config->tsfield); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
142 ADD_EXTEND("\", "); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
143 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
144 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
145 for (li = emptyrecords.all.next; li != &emptyrecords.all; li = li->next) { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
146 struct acct_record_item * i = (struct acct_record_item *)(li->o); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
147 ADD_EXTEND("\""); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
148 ADD_ESCAPE(i->param->field?:i->param->avpname); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
149 if (i->index) { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
150 ADD_EXTEND("%d", i->index); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
151 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
152 if (li->next != &emptyrecords.all) { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
153 ADD_EXTEND("\", "); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
154 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
155 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
156 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
157 ADD_EXTEND("\") VALUES ("); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
158 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
159 if (acct_config->tsfield) { |
292
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
160 ADD_EXTEND("$%d, ", ++idx); |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
161 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
162 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
163 for (li = emptyrecords.all.next; li != &emptyrecords.all; li = li->next) { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
164 struct acct_record_item * i = (struct acct_record_item *)(li->o); |
292
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
165 ADD_EXTEND("$%d::%s", ++idx, diam2db_types_mapping[i->param->avptype]); |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
166 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
167 if (li->next != &emptyrecords.all) { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
168 ADD_EXTEND(", "); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
169 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
170 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
171 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
172 ADD_EXTEND(");"); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
173 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
174 TRACE_DEBUG(FULL, "Preparing the following SQL statement:\n%s\n", sql); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
175 res = PQprepare(conn, stmt, sql, emptyrecords.nball, NULL); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
176 if (PQresultStatus(res) != PGRES_COMMAND_OK) { |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
177 TRACE_DEBUG(INFO, "Preparing statement '%s' failed: %s", |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
178 sql, PQerrorMessage(conn)); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
179 PQclear(res); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
180 return EINVAL; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
181 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
182 PQclear(res); |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
183 |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
184 free(sql); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
185 acct_rec_empty(&emptyrecords); |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
186 |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
187 /* Ok, ready */ |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
188 return 0; |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
189 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
190 |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
191 /* Terminate the connection to the DB */ |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
192 void acct_db_free(void) |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
193 { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
194 if (conn) { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
195 /* Note: the prepared statement is automatically freed when the session terminates */ |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
196 PQfinish(conn); |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
197 conn = NULL; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
198 } |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
199 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
200 |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
201 /* When a new message has been received, insert the content of the parsed mapping into the DB (using prepared statement) */ |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
202 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
|
203 { |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
204 char **val; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
205 int *val_len; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
206 int *val_isbin; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
207 int idx = 0; |
292
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
208 int size = 0; |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
209 PGresult *res; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
210 struct fd_list *li; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
211 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
212 TRACE_ENTRY("%p", records); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
213 CHECK_PARAMS( conn && records ); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
214 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
215 /* First, check if the connection with the DB has not staled, and eventually try to fix it */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
216 if (PQstatus(conn) != CONNECTION_OK) { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
217 /* Attempt a reset */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
218 PQreset(conn); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
219 if (PQstatus(conn) != CONNECTION_OK) { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
220 TRACE_DEBUG(INFO, "Lost connection to the database server, and attempt to reestablish it failed"); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
221 TODO("Terminate the freeDiameter instance completly?"); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
222 return ENOTCONN; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
223 } |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
224 } |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
225 |
292
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
226 size = acct_config->tsfield ? records->nball + 1 : records->nball; |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
227 |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
228 /* Alloc the arrays of parameters */ |
292
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
229 CHECK_MALLOC( val = calloc(size, sizeof(const char *)) ); |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
230 CHECK_MALLOC( val_len = calloc(size, sizeof(const int)) ); |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
231 CHECK_MALLOC( val_isbin = calloc(size, sizeof(const int)) ); |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
232 |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
233 if (acct_config->tsfield) { |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
234 val[idx] = "now"; |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
235 val_len[idx] = 3; |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
236 val_isbin[idx] = 0; |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
237 idx++; |
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
238 } |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
239 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
240 /* Now write all the map'd records in these arrays */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
241 for (li = records->all.next; li != &records->all; li = li->next) { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
242 struct acct_record_item * r = (struct acct_record_item *)(li->o); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
243 if (r->value) { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
244 val_isbin[idx] = 1; /* We always pass binary parameters */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
245 switch (r->param->avptype) { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
246 case AVP_TYPE_OCTETSTRING: |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
247 val[idx] = (void *)(r->value->os.data); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
248 val_len[idx] = r->value->os.len; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
249 break; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
250 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
251 case AVP_TYPE_INTEGER32: |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
252 case AVP_TYPE_UNSIGNED32: |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
253 case AVP_TYPE_FLOAT32: |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
254 r->scalar.v32 = htonl(r->value->u32); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
255 val[idx] = &r->scalar.c; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
256 val_len[idx] = sizeof(uint32_t); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
257 break; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
258 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
259 case AVP_TYPE_INTEGER64: |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
260 case AVP_TYPE_UNSIGNED64: |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
261 case AVP_TYPE_FLOAT64: |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
262 r->scalar.v64 = htonll(r->value->u64); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
263 val[idx] = &r->scalar.c; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
264 val_len[idx] = sizeof(uint64_t); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
265 break; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
266 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
267 default: |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
268 ASSERT(0); /* detect bugs */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
269 } |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
270 } |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
271 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
272 idx++; |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
273 } |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
274 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
275 /* OK, now execute the SQL statement */ |
292
a77ed0e30ac9
Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
285
diff
changeset
|
276 res = PQexecPrepared(conn, stmt, size, (const char * const *)val, val_len, val_isbin, 1 /* We actually don't care here */); |
285
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
277 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
278 /* Done with the parameters */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
279 free(val); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
280 free(val_len); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
281 free(val_isbin); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
282 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
283 /* Now check the result code */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
284 if (PQresultStatus(res) != PGRES_COMMAND_OK) { |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
285 TRACE_DEBUG(INFO, "An error occurred while INSERTing in the database: %s", PQerrorMessage(conn)); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
286 PQclear(res); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
287 return EINVAL; /* It was probably a mistake in configuration file... */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
288 } |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
289 PQclear(res); |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
290 |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
291 /* Ok, we are done */ |
0daf6fc2b751
Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
284
diff
changeset
|
292 return 0; |
284
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
293 } |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
294 |
397cdcd41f53
New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
295 |