annotate extensions/app_acct/acct_db.c @ 528:1b3b9790e7cb

Add a new field in the app_acct.fdx database to receive the name of the local server. Update your existing tables with the following SQL command: ALTER TABLE "incoming" ADD "recorded_serv" bytea NOT NULL;
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 03 Sep 2010 16:46:16 +0900
parents 26aafbbc1640
children 6af365b6f955
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 int idx = 0;
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 PGresult * res;
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
68 #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
69
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 TRACE_ENTRY();
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 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
72
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 /* 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
74 conn = PQconnectdb(acct_config->conninfo);
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 /* 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
77 if (PQstatus(conn) != CONNECTION_OK) {
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 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
79 acct_db_free();
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80 return EINVAL;
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81 }
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
82 if (PQprotocolVersion(conn) < 3) {
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
83 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
84 acct_db_free();
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
85 return EINVAL;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
86 }
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 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
89
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90 /* Now, prepare the request object */
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92 /* 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
93 CHECK_FCT( acct_rec_prepare(&emptyrecords) );
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95 /* Now, prepare the text of the request */
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
96 CHECK_MALLOC(sql = malloc(REALLOC_SIZE));
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97 sql_allocd = REALLOC_SIZE;
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 /* 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
100 #define ADD_EXTEND(args...) { \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 size_t p; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102 int loop = 0; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103 do { \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104 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
105 if (p >= sql_allocd - sql_offset) { \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 /* 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
107 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
108 sql_allocd += REALLOC_SIZE; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
109 loop++; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110 ASSERT(loop < 100); /* detect infinite loops */ \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
111 continue; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
112 } \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113 sql_offset += p; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114 break; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115 } while (1); \
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
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 /* 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
119 #define ADD_ESCAPE(str) { \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120 char * __s = (char *)str; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
121 /* 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
122 size_t p = strlen(__s); \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123 \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124 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
125 /* Too short, extend the buffer */ \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 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
127 sql_allocd += REALLOC_SIZE; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
128 } \
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 /* Now add the escaped string */ \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131 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
132 sql_offset += p; \
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
133 }
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 /* 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
136 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
137
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
138 if (acct_config->tsfield) {
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
139 ADD_EXTEND("\"");
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140 ADD_ESCAPE(acct_config->tsfield);
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141 ADD_EXTEND("\", ");
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142 }
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143
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: 403
diff changeset
144 if (acct_config->srvnfield) {
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: 403
diff changeset
145 ADD_EXTEND("\"");
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: 403
diff changeset
146 ADD_ESCAPE(acct_config->srvnfield);
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: 403
diff changeset
147 ADD_EXTEND("\", ");
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: 403
diff changeset
148 }
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: 403
diff changeset
149
284
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
150 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
151 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
152 ADD_EXTEND("\"");
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
153 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
154 if (i->index) {
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 ADD_EXTEND("%d", i->index);
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 if (li->next != &emptyrecords.all) {
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158 ADD_EXTEND("\", ");
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 }
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160 }
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 ADD_EXTEND("\") VALUES (");
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 if (acct_config->tsfield) {
292
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
165 ADD_EXTEND("$%d, ", ++idx);
284
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 }
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: 403
diff changeset
167 if (acct_config->srvnfield) {
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: 403
diff changeset
168 ADD_EXTEND("\"");
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: 403
diff changeset
169 ADD_ESCAPE(fd_g_config->cnf_diamid);
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: 403
diff changeset
170 ADD_EXTEND("\", ");
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: 403
diff changeset
171 }
284
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
173 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
174 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
175 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
176
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177 if (li->next != &emptyrecords.all) {
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178 ADD_EXTEND(", ");
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179 }
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 }
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 ADD_EXTEND(");");
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184 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
185 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
186 if (PQresultStatus(res) != PGRES_COMMAND_OK) {
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 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
188 sql, PQerrorMessage(conn));
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 PQclear(res);
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190 return EINVAL;
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
191 }
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
192 PQclear(res);
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
194 free(sql);
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
195 acct_rec_empty(&emptyrecords);
284
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
197 /* Ok, ready */
284
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198 return 0;
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 /* Terminate the connection to the DB */
284
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202 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
203 {
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
204 if (conn) {
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
205 /* 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
206 PQfinish(conn);
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
207 conn = NULL;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
208 }
284
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209 }
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
211 /* 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
212 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
213 {
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
214 char **val;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
215 int *val_len;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
216 int *val_isbin;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
217 int idx = 0;
292
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
218 int size = 0;
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
219 PGresult *res;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
220 struct fd_list *li;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
221
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
222 TRACE_ENTRY("%p", records);
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
223 CHECK_PARAMS( conn && records );
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 /* 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
226 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
227 /* Attempt a reset */
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
228 PQreset(conn);
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
229 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
230 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
231 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
232 return ENOTCONN;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
233 }
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
234 }
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
235
292
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
236 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
237
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
238 /* Alloc the arrays of parameters */
292
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
239 CHECK_MALLOC( val = calloc(size, sizeof(const char *)) );
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
240 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
241 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
242
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
243 if (acct_config->tsfield) {
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
244 val[idx] = "now";
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
245 val_len[idx] = 3;
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
246 val_isbin[idx] = 0;
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
247 idx++;
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
248 }
285
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
249
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
250 /* 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
251 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
252 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
253 if (r->value) {
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
254 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
255 switch (r->param->avptype) {
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
256 case AVP_TYPE_OCTETSTRING:
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
257 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
258 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
259 break;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
260
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
261 case AVP_TYPE_INTEGER32:
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
262 case AVP_TYPE_UNSIGNED32:
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
263 case AVP_TYPE_FLOAT32:
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
264 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
265 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
266 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
267 break;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
268
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
269 case AVP_TYPE_INTEGER64:
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
270 case AVP_TYPE_UNSIGNED64:
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
271 case AVP_TYPE_FLOAT64:
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
272 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
273 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
274 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
275 break;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
276
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
277 default:
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
278 ASSERT(0); /* detect bugs */
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
279 }
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
280 }
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
281
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
282 idx++;
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
283 }
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
284
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
285 /* OK, now execute the SQL statement */
292
a77ed0e30ac9 Fix non-working timestamp field
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 285
diff changeset
286 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
287
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
288 /* Done with the parameters */
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
289 free(val);
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
290 free(val_len);
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
291 free(val_isbin);
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
292
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
293 /* 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
294 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
295 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
296 PQclear(res);
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
297 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
298 }
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
299 PQclear(res);
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
300
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
301 /* Ok, we are done */
0daf6fc2b751 Added a test case for the app_acct extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 284
diff changeset
302 return 0;
284
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
303 }
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
304
397cdcd41f53 New app_acct in progress, backup only
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
305
"Welcome to our mercurial repository"