Merge in changes from my cdr-tds-conversion branch. This changes the internal
[asterisk/asterisk.git] / cdr / cdr_pgsql.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2003 - 2006
5  *
6  * Matthew D. Hardeman <mhardemn@papersoft.com> 
7  * Adapted from the MySQL CDR logger originally by James Sharp 
8  *
9  * Modified September 2003
10  * Matthew D. Hardeman <mhardemn@papersoft.com>
11  *
12  * See http://www.asterisk.org for more information about
13  * the Asterisk project. Please do not directly contact
14  * any of the maintainers of this project for assistance;
15  * the project provides a web site, mailing lists and IRC
16  * channels for your use.
17  *
18  * This program is free software, distributed under the terms of
19  * the GNU General Public License Version 2. See the LICENSE file
20  * at the top of the source tree.
21  */
22
23 /*! \file
24  *
25  * \brief PostgreSQL CDR logger 
26  * 
27  * \author Matthew D. Hardeman <mhardemn@papersoft.com> 
28  * \extref PostgreSQL http://www.postgresql.org/
29  *
30  * See also
31  * \arg \ref Config_cdr
32  * \arg http://www.postgresql.org/
33  * \ingroup cdr_drivers
34  */
35
36 /*** MODULEINFO
37         <depend>pgsql</depend>
38  ***/
39
40 #include "asterisk.h"
41
42 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
43
44 #include <time.h>
45
46 #include <libpq-fe.h>
47
48 #include "asterisk/config.h"
49 #include "asterisk/channel.h"
50 #include "asterisk/cdr.h"
51 #include "asterisk/module.h"
52
53 #define DATE_FORMAT "'%Y-%m-%d %T'"
54
55 static char *name = "pgsql";
56 static char *config = "cdr_pgsql.conf";
57 static char *pghostname = NULL, *pgdbname = NULL, *pgdbuser = NULL, *pgpassword = NULL, *pgdbport = NULL, *table = NULL;
58 static int connected = 0;
59 static int maxsize = 512, maxsize2 = 512;
60
61 AST_MUTEX_DEFINE_STATIC(pgsql_lock);
62
63 static PGconn   *conn = NULL;
64
65 struct columns {
66         char *name;
67         char *type;
68         int len;
69         unsigned int notnull:1;
70         unsigned int hasdefault:1;
71         AST_RWLIST_ENTRY(columns) list;
72 };
73
74 static AST_RWLIST_HEAD_STATIC(psql_columns, columns);
75
76 #define LENGTHEN_BUF1(size)                                                                                                             \
77                         do {                                                                                                                            \
78                                 /* Lengthen buffer, if necessary */                                                             \
79                                 if ((newsize = lensql + (size) + 3) > sizesql) {        \
80                                         if ((tmp = ast_realloc(sql, (newsize / 512 + 1) * 512))) {      \
81                                                 sql = tmp;                                                                                              \
82                                                 sizesql = (newsize / 512 + 1) * 512;                                    \
83                                         } else {                                                                                                        \
84                                                 ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR failed.\n"); \
85                                                 ast_free(sql);                                                                                  \
86                                                 ast_free(sql2);                                                                                 \
87                                                 AST_RWLIST_UNLOCK(&psql_columns);                                               \
88                                                 return -1;                                                                                              \
89                                         }                                                                                                                       \
90                                 }                                                                                                                               \
91                         } while (0)
92
93 #define LENGTHEN_BUF2(size)                                                                                                             \
94                         do {                                                                                                                            \
95                                 if ((newsize = lensql2 + (size) + 3) > sizesql2) {                              \
96                                         if ((tmp = ast_realloc(sql2, (newsize / 512 + 1) * 512))) {     \
97                                                 sql2 = tmp;                                                                                             \
98                                                 sizesql2 = (newsize / 512 + 1) * 512;                                   \
99                                         } else {                                                                                                        \
100                                                 ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR failed.\n");      \
101                                                 ast_free(sql);                                                                                  \
102                                                 ast_free(sql2);                                                                                 \
103                                                 AST_RWLIST_UNLOCK(&psql_columns);                                               \
104                                                 return -1;                                                                                              \
105                                         }                                                                                                                       \
106                                 }                                                                                                                               \
107                         } while (0)
108
109 static int pgsql_log(struct ast_cdr *cdr)
110 {
111         struct ast_tm tm;
112         char *pgerror;
113         PGresult *result;
114
115         ast_mutex_lock(&pgsql_lock);
116
117         if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
118                 conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
119                 if (PQstatus(conn) != CONNECTION_BAD) {
120                         connected = 1;
121                 } else {
122                         pgerror = PQerrorMessage(conn);
123                         ast_log(LOG_ERROR, "Unable to connect to database server %s.  Calls will not be logged!\n", pghostname);
124                         ast_log(LOG_ERROR, "Reason: %s\n", pgerror);
125                         PQfinish(conn);
126                         conn = NULL;
127                 }
128         }
129
130         if (connected) {
131                 struct columns *cur;
132                 int lensql, lensql2, sizesql = maxsize, sizesql2 = maxsize2, newsize;
133                 char *sql = ast_calloc(sizeof(char), sizesql), *sql2 = ast_calloc(sizeof(char), sizesql2), *tmp, *value;
134                 char buf[257], escapebuf[513];
135   
136                 lensql = snprintf(sql, sizesql, "INSERT INTO %s (", table);
137                 lensql2 = snprintf(sql2, sizesql2, " VALUES (");
138   
139                 AST_RWLIST_RDLOCK(&psql_columns);
140                 AST_RWLIST_TRAVERSE(&psql_columns, cur, list) {
141                         /* For fields not set, simply skip them */
142                         ast_cdr_getvar(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
143                         if (strcmp(cur->name, "calldate") == 0 && !value) {
144                                 ast_cdr_getvar(cdr, "start", &value, buf, sizeof(buf), 0, 0);
145                         }
146                         if (!value) {
147                                 if (cur->notnull && !cur->hasdefault) {
148                                         /* Field is NOT NULL (but no default), must include it anyway */
149                                         LENGTHEN_BUF1(strlen(cur->name));
150                                         lensql += snprintf(sql + lensql, sizesql - lensql, "%s,", cur->name);
151                                         LENGTHEN_BUF2(3);
152                                         strcat(sql2, "'',");
153                                         lensql2 += 3;
154                                 }
155                                 continue;
156                         }
157                         
158                         LENGTHEN_BUF1(strlen(cur->name));
159                         lensql += snprintf(sql + lensql, sizesql - lensql, "%s,", cur->name);
160
161                         if (strcmp(cur->name, "start") == 0 || strcmp(cur->name, "calldate") == 0) {
162                                 if (strncmp(cur->type, "int", 3) == 0) {
163                                         LENGTHEN_BUF2(12);
164                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%ld", cdr->start.tv_sec);
165                                 } else if (strncmp(cur->type, "float", 5) == 0) {
166                                         LENGTHEN_BUF2(30);
167                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%f", (double)cdr->start.tv_sec + (double)cdr->start.tv_usec / 1000000.0);
168                                 } else {
169                                         /* char, hopefully */
170                                         LENGTHEN_BUF2(30);
171                                         ast_localtime(&cdr->start, &tm, NULL);
172                                         lensql2 += ast_strftime(sql2 + lensql2, sizesql2 - lensql2, DATE_FORMAT, &tm);
173                                 }
174                         } else if (strcmp(cur->name, "answer") == 0) {
175                                 if (strncmp(cur->type, "int", 3) == 0) {
176                                         LENGTHEN_BUF2(12);
177                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%ld", cdr->answer.tv_sec);
178                                 } else if (strncmp(cur->type, "float", 5) == 0) {
179                                         LENGTHEN_BUF2(30);
180                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%f", (double)cdr->answer.tv_sec + (double)cdr->answer.tv_usec / 1000000.0);
181                                 } else {
182                                         /* char, hopefully */
183                                         LENGTHEN_BUF2(30);
184                                         ast_localtime(&cdr->start, &tm, NULL);
185                                         lensql2 += ast_strftime(sql2 + lensql2, sizesql2 - lensql2, DATE_FORMAT, &tm);
186                                 }
187                         } else if (strcmp(cur->name, "end") == 0) {
188                                 if (strncmp(cur->type, "int", 3) == 0) {
189                                         LENGTHEN_BUF2(12);
190                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%ld", cdr->end.tv_sec);
191                                 } else if (strncmp(cur->type, "float", 5) == 0) {
192                                         LENGTHEN_BUF2(30);
193                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%f", (double)cdr->end.tv_sec + (double)cdr->end.tv_usec / 1000000.0);
194                                 } else {
195                                         /* char, hopefully */
196                                         LENGTHEN_BUF2(30);
197                                         ast_localtime(&cdr->end, &tm, NULL);
198                                         lensql2 += ast_strftime(sql2 + lensql2, sizesql2 - lensql2, DATE_FORMAT, &tm);
199                                 }
200                         } else if (strcmp(cur->name, "duration") == 0 || strcmp(cur->name, "billsec") == 0) {
201                                 if (cur->type[0] == 'i') {
202                                         /* Get integer, no need to escape anything */
203                                         ast_cdr_getvar(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
204                                         LENGTHEN_BUF2(12);
205                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%s", value);
206                                 } else if (strncmp(cur->type, "float", 5) == 0) {
207                                         struct timeval *tv = cur->name[0] == 'd' ? &cdr->start : &cdr->answer;
208                                         LENGTHEN_BUF2(30);
209                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%f", (double)cdr->end.tv_sec - tv->tv_sec + cdr->end.tv_usec / 1000000.0 - tv->tv_usec / 1000000.0);
210                                 } else {
211                                         /* Char field, probably */
212                                         struct timeval *tv = cur->name[0] == 'd' ? &cdr->start : &cdr->answer;
213                                         LENGTHEN_BUF2(30);
214                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "'%f'", (double)cdr->end.tv_sec - tv->tv_sec + cdr->end.tv_usec / 1000000.0 - tv->tv_usec / 1000000.0);
215                                 }
216                         } else if (strcmp(cur->name, "disposition") == 0 || strcmp(cur->name, "amaflags") == 0) {
217                                 if (strncmp(cur->type, "int", 3) == 0) {
218                                         /* Integer, no need to escape anything */
219                                         ast_cdr_getvar(cdr, cur->name, &value, buf, sizeof(buf), 0, 1);
220                                         LENGTHEN_BUF2(12);
221                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%s", value);
222                                 } else {
223                                         /* Although this is a char field, there are no special characters in the values for these fields */
224                                         ast_cdr_getvar(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
225                                         LENGTHEN_BUF2(30);
226                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "'%s'", value);
227                                 }
228                         } else {
229                                 /* Arbitrary field, could be anything */
230                                 ast_cdr_getvar(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
231                                 if (strncmp(cur->type, "int", 3) == 0) {
232                                         long long whatever;
233                                         if (value && sscanf(value, "%lld", &whatever) == 1) {
234                                                 LENGTHEN_BUF2(25);
235                                                 lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%lld", whatever);
236                                         } else {
237                                                 LENGTHEN_BUF2(1);
238                                                 lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "0");
239                                         }
240                                 } else if (strncmp(cur->type, "float", 5) == 0) {
241                                         long double whatever;
242                                         if (value && sscanf(value, "%Lf", &whatever) == 1) {
243                                                 LENGTHEN_BUF2(50);
244                                                 lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "%30Lf", whatever);
245                                         } else {
246                                                 LENGTHEN_BUF2(1);
247                                                 lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "0");
248                                         }
249                                 /* XXX Might want to handle dates, times, and other misc fields here XXX */
250                                 } else {
251                                         if (value)
252                                                 PQescapeStringConn(conn, escapebuf, value, strlen(value), NULL);
253                                         else
254                                                 escapebuf[0] = '\0';
255                                         LENGTHEN_BUF2(strlen(escapebuf) + 2);
256                                         lensql2 += snprintf(sql2 + lensql2, sizesql2 - lensql2, "'%s'", escapebuf);
257                                 }
258                         }
259                         LENGTHEN_BUF2(1);
260                         strcat(sql2 + lensql2, ",");
261                         lensql2++;
262                 }
263                 AST_RWLIST_UNLOCK(&psql_columns);
264                 LENGTHEN_BUF1(lensql2);
265                 sql[lensql - 1] = ')';
266                 sql2[lensql2 - 1] = ')';
267                 strcat(sql + lensql, sql2);
268                 ast_verb(11, "[%s]\n", sql);
269
270                 ast_debug(2, "inserting a CDR record.\n");
271
272                 /* Test to be sure we're still connected... */
273                 /* If we're connected, and connection is working, good. */
274                 /* Otherwise, attempt reconnect.  If it fails... sorry... */
275                 if (PQstatus(conn) == CONNECTION_OK) {
276                         connected = 1;
277                 } else {
278                         ast_log(LOG_ERROR, "Connection was lost... attempting to reconnect.\n");
279                         PQreset(conn);
280                         if (PQstatus(conn) == CONNECTION_OK) {
281                                 ast_log(LOG_ERROR, "Connection reestablished.\n");
282                                 connected = 1;
283                         } else {
284                                 pgerror = PQerrorMessage(conn);
285                                 ast_log(LOG_ERROR, "Unable to reconnect to database server %s. Calls will not be logged!\n", pghostname);
286                                 ast_log(LOG_ERROR, "Reason: %s\n", pgerror);
287                                 PQfinish(conn);
288                                 conn = NULL;
289                                 connected = 0;
290                                 ast_mutex_unlock(&pgsql_lock);
291                                 return -1;
292                         }
293                 }
294                 result = PQexec(conn, sql);
295                 if (PQresultStatus(result) != PGRES_COMMAND_OK) {
296                         pgerror = PQresultErrorMessage(result);
297                         ast_log(LOG_ERROR, "Failed to insert call detail record into database!\n");
298                         ast_log(LOG_ERROR, "Reason: %s\n", pgerror);
299                         ast_log(LOG_ERROR, "Connection may have been lost... attempting to reconnect.\n");
300                         PQreset(conn);
301                         if (PQstatus(conn) == CONNECTION_OK) {
302                                 ast_log(LOG_ERROR, "Connection reestablished.\n");
303                                 connected = 1;
304                                 PQclear(result);
305                                 result = PQexec(conn, sql);
306                                 if (PQresultStatus(result) != PGRES_COMMAND_OK) {
307                                         pgerror = PQresultErrorMessage(result);
308                                         ast_log(LOG_ERROR, "HARD ERROR!  Attempted reconnection failed.  DROPPING CALL RECORD!\n");
309                                         ast_log(LOG_ERROR, "Reason: %s\n", pgerror);
310                                 }
311                         }
312                         ast_mutex_unlock(&pgsql_lock);
313                         PQclear(result);
314                         return -1;
315                 }
316                 PQclear(result);
317         }
318         ast_mutex_unlock(&pgsql_lock);
319         return 0;
320 }
321
322 static int unload_module(void)
323 {
324         struct columns *cur;
325         ast_cdr_unregister(name);
326
327         /* Give all threads time to finish */
328         usleep(1);
329         PQfinish(conn);
330
331         if (pghostname)
332                 ast_free(pghostname);
333         if (pgdbname)
334                 ast_free(pgdbname);
335         if (pgdbuser)
336                 ast_free(pgdbuser);
337         if (pgpassword)
338                 ast_free(pgpassword);
339         if (pgdbport)
340                 ast_free(pgdbport);
341         if (table)
342                 ast_free(table);
343
344         AST_RWLIST_WRLOCK(&psql_columns);
345         while ((cur = AST_RWLIST_REMOVE_HEAD(&psql_columns, list))) {
346                 ast_free(cur);
347         }
348         AST_RWLIST_UNLOCK(&psql_columns);
349
350         return 0;
351 }
352
353 static int config_module(int reload)
354 {
355         struct ast_variable *var;
356         char *pgerror;
357         struct columns *cur;
358         PGresult *result;
359         const char *tmp;
360         struct ast_config *cfg;
361         struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
362
363         if ((cfg = ast_config_load(config, config_flags)) == NULL) {
364                 ast_log(LOG_WARNING, "Unable to load config for PostgreSQL CDR's: %s\n", config);
365                 return -1;
366         } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
367                 return 0;
368
369         if (!(var = ast_variable_browse(cfg, "global"))) {
370                 ast_config_destroy(cfg);
371                 return 0;
372         }
373
374         if (!(tmp = ast_variable_retrieve(cfg, "global", "hostname"))) {
375                 ast_log(LOG_WARNING, "PostgreSQL server hostname not specified.  Assuming unix socket connection\n");
376                 tmp = "";       /* connect via UNIX-socket by default */
377         }
378
379         if (pghostname)
380                 ast_free(pghostname);
381         if (!(pghostname = ast_strdup(tmp))) {
382                 ast_config_destroy(cfg);
383                 return -1;
384         }
385
386         if (!(tmp = ast_variable_retrieve(cfg, "global", "dbname"))) {
387                 ast_log(LOG_WARNING, "PostgreSQL database not specified.  Assuming asterisk\n");
388                 tmp = "asteriskcdrdb";
389         }
390
391         if (pgdbname)
392                 ast_free(pgdbname);
393         if (!(pgdbname = ast_strdup(tmp))) {
394                 ast_config_destroy(cfg);
395                 return -1;
396         }
397
398         if (!(tmp = ast_variable_retrieve(cfg, "global", "user"))) {
399                 ast_log(LOG_WARNING, "PostgreSQL database user not specified.  Assuming asterisk\n");
400                 tmp = "asterisk";
401         }
402
403         if (pgdbuser)
404                 ast_free(pgdbuser);
405         if (!(pgdbuser = ast_strdup(tmp))) {
406                 ast_config_destroy(cfg);
407                 return -1;
408         }
409
410         if (!(tmp = ast_variable_retrieve(cfg, "global", "password"))) {
411                 ast_log(LOG_WARNING, "PostgreSQL database password not specified.  Assuming blank\n");
412                 tmp = "";
413         }
414
415         if (pgpassword)
416                 ast_free(pgpassword);
417         if (!(pgpassword = ast_strdup(tmp))) {
418                 ast_config_destroy(cfg);
419                 return -1;
420         }
421
422         if (!(tmp = ast_variable_retrieve(cfg, "global", "port"))) {
423                 ast_log(LOG_WARNING, "PostgreSQL database port not specified.  Using default 5432.\n");
424                 tmp = "5432";
425         }
426
427         if (pgdbport)
428                 ast_free(pgdbport);
429         if (!(pgdbport = ast_strdup(tmp))) {
430                 ast_config_destroy(cfg);
431                 return -1;
432         }
433
434         if (!(tmp = ast_variable_retrieve(cfg, "global", "table"))) {
435                 ast_log(LOG_WARNING, "CDR table not specified.  Assuming cdr\n");
436                 tmp = "cdr";
437         }
438
439         if (table)
440                 ast_free(table);
441         if (!(table = ast_strdup(tmp))) {
442                 ast_config_destroy(cfg);
443                 return -1;
444         }
445
446         if (option_debug) {
447                 if (ast_strlen_zero(pghostname)) {
448                         ast_debug(1, "using default unix socket\n");
449                 } else {
450                         ast_debug(1, "got hostname of %s\n", pghostname);
451                 }
452                 ast_debug(1, "got port of %s\n", pgdbport);
453                 ast_debug(1, "got user of %s\n", pgdbuser);
454                 ast_debug(1, "got dbname of %s\n", pgdbname);
455                 ast_debug(1, "got password of %s\n", pgpassword);
456                 ast_debug(1, "got sql table name of %s\n", table);
457         }
458
459         conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
460         if (PQstatus(conn) != CONNECTION_BAD) {
461                 char sqlcmd[512];
462                 char *fname, *ftype, *flen, *fnotnull, *fdef;
463                 int i, rows;
464                 ast_debug(1, "Successfully connected to PostgreSQL database.\n");
465                 connected = 1;
466
467                 /* Query the columns */
468                 snprintf(sqlcmd, sizeof(sqlcmd), "select a.attname, t.typname, a.attlen, a.attnotnull, d.adsrc from pg_class c, pg_type t, pg_attribute a left outer join pg_attrdef d on a.atthasdef and d.adrelid = a.attrelid and d.adnum = a.attnum where c.oid = a.attrelid and a.atttypid = t.oid and (a.attnum > 0) and c.relname = '%s' order by c.relname, attnum", table);
469                 result = PQexec(conn, sqlcmd);
470                 if (PQresultStatus(result) != PGRES_TUPLES_OK) {
471                         pgerror = PQresultErrorMessage(result);
472                         ast_log(LOG_ERROR, "Failed to query database columns: %s\n", pgerror);
473                         PQclear(result);
474                         unload_module();
475                         return AST_MODULE_LOAD_DECLINE;
476                 }
477
478                 rows = PQntuples(result);
479                 for (i = 0; i < rows; i++) {
480                         fname = PQgetvalue(result, i, 0);
481                         ftype = PQgetvalue(result, i, 1);
482                         flen = PQgetvalue(result, i, 2);
483                         fnotnull = PQgetvalue(result, i, 3);
484                         fdef = PQgetvalue(result, i, 4);
485                         ast_verb(4, "Found column '%s' of type '%s'\n", fname, ftype);
486                         cur = ast_calloc(1, sizeof(*cur) + strlen(fname) + strlen(ftype) + 2);
487                         if (cur) {
488                                 sscanf(flen, "%d", &cur->len);
489                                 cur->name = (char *)cur + sizeof(*cur);
490                                 cur->type = (char *)cur + sizeof(*cur) + strlen(fname) + 1;
491                                 strcpy(cur->name, fname);
492                                 strcpy(cur->type, ftype);
493                                 if (*fnotnull == 't') {
494                                         cur->notnull = 1;
495                                 } else {
496                                         cur->notnull = 0;
497                                 }
498                                 if (!ast_strlen_zero(fdef)) {
499                                         cur->hasdefault = 1;
500                                 } else {
501                                         cur->hasdefault = 0;
502                                 }
503                                 AST_RWLIST_INSERT_TAIL(&psql_columns, cur, list);
504                         }
505                 }
506                 PQclear(result);
507         } else {
508                 pgerror = PQerrorMessage(conn);
509                 ast_log(LOG_ERROR, "Unable to connect to database server %s.  CALLS WILL NOT BE LOGGED!!\n", pghostname);
510                 ast_log(LOG_ERROR, "Reason: %s\n", pgerror);
511                 connected = 0;
512         }
513
514         ast_config_destroy(cfg);
515
516         return ast_cdr_register(name, ast_module_info->description, pgsql_log);
517 }
518
519 static int load_module(void)
520 {
521         return config_module(0) ? AST_MODULE_LOAD_DECLINE : 0;
522 }
523
524 static int reload(void)
525 {
526         return config_module(1);
527 }
528
529 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "PostgreSQL CDR Backend",
530                 .load = load_module,
531                 .unload = unload_module,
532                 .reload = reload,
533                );