1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
/*
* Copyright (C) 2012 VoIP Embedded, Inc.
*
* This file is part of Kamailio, a free SIP server.
*
* Kamailio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* Kamailio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* 2012-10-18 initial version (osas)
*/
#include <stdio.h>
#include <stdlib.h>
#include "../../lib/srdb1/db.h"
#include "xhttp_pi_fnc.h"
int connect_http_db(ph_framework_t *framework_data, int index)
{
ph_db_url_t *ph_db_urls = framework_data->ph_db_urls;
if (ph_db_urls[index].http_db_handle) {
LM_CRIT("BUG - db connection found already open\n");
return -1;
}
if ((ph_db_urls[index].http_db_handle =
ph_db_urls[index].http_dbf.init(&ph_db_urls[index].db_url)) == NULL) {
return -1;
}
return 0;
}
int use_table(ph_db_table_t *db_table)
{
ph_db_url_t *db_url;
if(db_table==NULL){
LM_ERR("null db_table handler\n");
return -1;
}
if(db_table->db_url==NULL){
LM_ERR("null db_url for table [%s]\n", db_table->name.s);
return -1;
}
db_url = db_table->db_url;
if(db_url->http_db_handle==NULL){
LM_ERR("null db handle for table [%s]\n", db_table->name.s);
return -1;
}
db_table->db_url->http_dbf.use_table(db_table->db_url->http_db_handle,
&db_table->name);
return 0;
}
int init_http_db(ph_framework_t *framework_data, int index)
{
ph_db_url_t *ph_db_urls = framework_data->ph_db_urls;
if (db_bind_mod(&ph_db_urls[index].db_url,
&ph_db_urls[index].http_dbf) < 0) {
LM_ERR("Unable to bind to a database driver\n");
return -1;
}
if (connect_http_db(framework_data, index)!=0){
LM_ERR("unable to connect to the database\n");
return -1;
}
ph_db_urls[index].http_dbf.close(ph_db_urls[index].http_db_handle);
ph_db_urls[index].http_db_handle = NULL;
return 0;
}
void destroy_http_db(ph_framework_t *framework_data)
{
int i;
ph_db_url_t *ph_db_urls;
if (framework_data == NULL) return;
ph_db_urls = framework_data->ph_db_urls;
/* close the DB connections */
for(i=0;i<framework_data->ph_db_urls_size;i++){
if (ph_db_urls[i].http_db_handle) {
ph_db_urls[i].http_dbf.close(ph_db_urls[i].http_db_handle);
ph_db_urls[i].http_db_handle = NULL;
}
}
}
|