ul_db.h

00001 /* sp-ul_db module
00002  *
00003  * Copyright (C) 2007 1&1 Internet AG
00004  *
00005  * This file is part of openser, a free SIP server.
00006  *
00007  * openser is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version
00011  *
00012  * openser is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License 
00018  * along with this program; if not, write to the Free Software 
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00022 #ifndef SP_P_USRLOC_UL_DB_H
00023 #define SP_P_USRLOC_UL_DB_H
00024 
00025 #include "../../lib/srdb1/db.h"
00026 #include "ul_db_handle.h"
00027 
00028 #define UL_DB_QUERY_LEN 2048
00029 
00030 #define DB_ERR_PRI 0
00031 #define DB_ERR_SEC 1
00032 #define DB_MODE_PRI 0
00033 #define DB_MODE_SEC 1
00034 #define DB_MODE_BOTH 2
00035 #define DB_MODE_OFF 3
00036 
00037 #define DB_POL_OP 0
00038 #define DB_POL_QUERY 1
00039 #define DB_POL_MOD 2
00040 
00041 #ifdef __i386__
00042     #define UL_DB_ZERO_TIME 0x80000000
00043 #else
00044     #define UL_DB_ZERO_TIME 0xFFFFFFFF80000000
00045 #endif
00046 
00047 typedef struct ul_master_db {
00048         str * url;
00049         db_func_t dbf;
00050         db1_con_t * dbh;
00051 } ul_master_db_t;
00052 
00053 typedef struct ul_master_db_set {
00054         ul_master_db_t read;
00055         ul_master_db_t write;
00056 } ul_master_db_set_t;
00057 
00058 extern int required_caps;
00059 
00060 int ul_db_init();
00061 
00062 int ul_db_child_init();
00063 
00064 int ul_db_child_locnr_init();
00065 
00066 void ul_db_shutdown();
00067 
00068 int db_handle_error(ul_db_handle_t * handle, int no);
00069 
00070 int db_reactivate(ul_db_handle_t * handle, int no);
00071 
00072 int db_reset_failover_time(ul_db_handle_t * handle, int no);
00073 
00074 int db_check_policy(int pol, int ok, int working);
00075 
00076 int ul_db_insert(str * table, str * first, str * second,
00077                           db_key_t* _k, db_val_t* _v, int _n);
00078 
00079 int ul_db_update(str * table, str * first, str * second,
00080                                 db_key_t* _k, db_op_t * _op, db_val_t* _v,
00081                                 db_key_t* _uk, db_val_t* _uv, int _n, int _un);
00082 
00083 int ul_db_replace(str * table, str * first, str * second,
00084                           db_key_t* _k, db_val_t* _v, int _n, int _un);
00085 
00086 int ul_db_delete(str * table, str * first, str * second,
00087                           db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n);
00088 
00089 int ul_db_query(str * table, str * first, str * second, db1_con_t *** _r_h,
00090                                 db_key_t* _k, db_op_t* _op, db_val_t* _v, db_key_t* _c,
00091                                 int _n, int _nc, db_key_t _o, db1_res_t** _r);
00092 
00093 int ul_db_free_result(db1_con_t ** dbh, db1_res_t * res);
00094 
00095 int ul_db_check(ul_db_handle_t * handle);
00096 
00097 #endif