73 #define REDIS_DEFAULT_PORT 6379 90 static DBPool *pool = NULL;
97 static void dlr_redis_shutdown()
103 static void dlr_redis_add(
struct dlr_entry *entry)
110 debug(
"dlr.redis", 0,
"Adding DLR into keystore");
115 error(0,
"DLR: REDIS: No connection available - dropping DLR");
141 #ifdef REDIS_PRECHECK 145 error(0,
"DLR: REDIS: DLR for %s already exists! Duplicate Message ID?",
189 error(0,
"DLR: REDIS: Error while adding dlr entry %s",
219 static inline void get_octstr_value(
Octstr **os,
const List *r,
const int i)
233 List *result = NULL, *row;
238 error(0,
"DLR: REDIS: No connection available");
277 #define LO2CSTR(r, i) octstr_get_cstr(gwlist_get(r, i)) 292 get_octstr_value(&res->
service, row, 1);
293 get_octstr_value(&res->
url, row, 2);
295 get_octstr_value(&res->
source, row, 3);
297 get_octstr_value(&res->
boxc_id, row, 5);
316 debug(
"dlr.redis", 0,
"Removing DLR from keystore");
321 error(0,
"DLR: REDIS: No connection available");
349 error(0,
"DLR: REDIS: Error while removing dlr entry for %s",
363 Octstr *key, *sql, *os_status;
368 debug(
"dlr.redis", 0,
"Updating DLR status in keystore");
373 error(0,
"DLR: REDIS: No connection available");
396 error(0,
"DLR: REDIS: Error while updating dlr entry for %s",
407 static long dlr_redis_messages(
void)
437 static void dlr_redis_flush(
void)
446 error(0,
"DLR: REDIS: No connection available");
453 error(0,
"DLR: REDIS: Error while flushing dlr entries from database");
455 debug(
"dlr.redis", 0,
"Flushed %d DLR entries from database", rows);
462 .dlr_add = dlr_redis_add,
463 .dlr_get = dlr_redis_get,
464 .dlr_update = dlr_redis_update,
465 .dlr_remove = dlr_redis_remove,
466 .dlr_shutdown = dlr_redis_shutdown,
467 .dlr_messages = dlr_redis_messages,
468 .dlr_flush = dlr_redis_flush
475 Octstr *redis_host, *redis_pass, *redis_id;
476 long redis_port = 0, redis_database = -1, redis_idle_timeout = -1;
486 panic(0,
"DLR: Redis: group 'dlr-db' is not specified!");
489 panic(0,
"DLR: Redis: directive 'id' is not specified!");
524 panic(0,
"DLR: Redis: connection settings for id '%s' are not specified!",
535 panic(0,
"DLR: Redis: directive 'host' is not specified!");
537 redis_port = REDIS_DEFAULT_PORT;
546 db_conf = gw_malloc(
sizeof(
DBConf));
565 panic(0,
"DLR: Redis: database pool has no connections!");
void error(int err, const char *fmt,...)
void octstr_replace(Octstr *haystack, Octstr *needle, Octstr *repl)
long dbpool_conn_count(DBPool *p)
DBPool * dbpool_create(enum db_type db_type, DBConf *conf, unsigned int connections)
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwlist_append(List *list, void *item)
void dlr_db_fields_destroy(struct dlr_db_fields *fields)
struct dlr_entry * dlr_entry_create(void)
long gwlist_len(List *list)
void * gwlist_get(List *list, long pos)
int octstr_url_decode(Octstr *ostr)
#define cfg_get(grp, varname)
#define octstr_get_cstr(ostr)
static struct pid_list * found
void dbpool_conn_produce(DBPoolConn *conn)
static struct dlr_storage * handles
Octstr * octstr_imm(const char *cstr)
void * gwlist_extract_first(List *list)
void octstr_delete(Octstr *ostr1, long pos, long len)
#define octstr_duplicate(ostr)
List * cfg_get_multi_group(Cfg *cfg, Octstr *name)
Octstr * octstr_format(const char *fmt,...)
void octstr_destroy(Octstr *ostr)
#define octstr_create(cstr)
void octstr_destroy_item(void *os)
long octstr_len(const Octstr *ostr)
void dbpool_destroy(DBPool *p)
int dbpool_conn_update(DBPoolConn *conn, const Octstr *sql, List *binds)
void dlr_entry_destroy(struct dlr_entry *dlr)
void debug(const char *place, int err, const char *fmt,...)
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
int octstr_str_compare(const Octstr *ostr, const char *str)
int dbpool_conn_select(DBPoolConn *conn, const Octstr *sql, List *binds, List **result)
struct dlr_storage * dlr_init_redis(Cfg *cfg)
DBPoolConn * dbpool_conn_consume(DBPool *p)
CfgGroup * cfg_get_single_group(Cfg *cfg, Octstr *name)
struct dlr_db_fields * dlr_db_fields_create(CfgGroup *grp)
void octstr_url_encode(Octstr *ostr)
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)