ul_db_handle.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 #include "ul_check.h"
00023 #include "../../str.h"
00024 #include "../../lib/srdb1/db.h"
00025 
00026 #ifndef SP_P_USRLOC_UL_DB_HANDLE_H
00027 #define SP_P_USRLOC_UL_DB_HANDLE_H
00028 
00029 #define DB_NUM 2
00030 
00031 #define DB_OFF 0
00032 #define DB_ON 1
00033 #define DB_INACTIVE 2
00034 
00035 #define UL_DB_URL_LEN 260
00036 
00037 typedef struct str2s {
00038         char s[UL_DB_URL_LEN];
00039         int len;
00040 } str2;
00041 
00042 typedef struct ul_db {
00043         str2 url;
00044         int no;
00045         time_t failover_time;
00046         time_t retry;
00047         int errors;
00048         int status;
00049         int spare;
00050         int rg;
00051         db1_con_t * dbh;
00052         db_func_t dbf;
00053 }ul_db_t;
00054 
00055 typedef struct ul_db_handle {
00056         unsigned int id;
00057         struct check_data * check;
00058         int working;
00059         time_t expires;
00060         int active;
00061         ul_db_t db[DB_NUM];
00062 }ul_db_handle_t;
00063 
00064 typedef struct ul_db_handle_list {
00065         ul_db_handle_t * handle;
00066         struct ul_db_handle_list * next;
00067 }ul_db_handle_list_t;
00068 
00069 void destroy_handles(void);
00070 
00071 int refresh_handles(db_func_t * dbf, db1_con_t * dbh);
00072 
00073 int load_location_number(db_func_t * dbf, db1_con_t * dbh, int*);
00074 int load_handles(db_func_t * dbf, db1_con_t * dbh);
00075 
00076 ul_db_handle_t * get_handle(db_func_t * dbf, db1_con_t * dbh, str * first, str * second);
00077 
00078 int load_data(db_func_t * dbf, db1_con_t * dbh, ul_db_handle_t * handle, int id);
00079 
00080 int refresh_handle(ul_db_handle_t * handle, ul_db_handle_t * new_data, int error_handling);
00081 
00082 ul_db_t * get_db_by_num(ul_db_handle_t * handle, int no);
00083 
00084 int check_handle(db_func_t * dbf, db1_con_t * dbh, ul_db_handle_t * handle);
00085 
00086 #endif