2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#include <sqlite3.h>
|
|
|
|
|
2018-03-17 18:01:17 +01:00
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/log.h"
|
|
|
|
#include "cw/dbg.h"
|
2018-03-17 18:01:17 +01:00
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/conn.h"
|
2018-03-17 18:01:17 +01:00
|
|
|
|
|
|
|
|
2014-07-13 19:18:56 +02:00
|
|
|
|
2014-07-15 07:33:17 +02:00
|
|
|
#include "conf.h"
|
|
|
|
|
2014-07-13 19:18:56 +02:00
|
|
|
static sqlite3 *handle;
|
|
|
|
|
2014-07-14 22:44:46 +02:00
|
|
|
|
2016-03-28 10:43:33 +02:00
|
|
|
static const char * init_tables = "\
|
2014-07-15 07:33:17 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS acs (acid TEXT PRIMARY KEY, acname TEXT, lastseen TIMESTAMP); \
|
2016-03-28 10:43:33 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS radios (\
|
|
|
|
wtpid TEXT,\
|
2016-03-28 16:50:06 +02:00
|
|
|
rid TEXT,\
|
2016-03-28 10:43:33 +02:00
|
|
|
key TEXT,\
|
2016-03-28 16:50:06 +02:00
|
|
|
sub_key,\
|
2016-03-28 10:43:33 +02:00
|
|
|
val TEXT, \
|
|
|
|
upd INTEGER, \
|
2016-03-28 16:50:06 +02:00
|
|
|
PRIMARY KEY (wtpid,rid,key,sub_key)\
|
2016-03-28 10:43:33 +02:00
|
|
|
);\
|
2014-07-14 22:44:46 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS acips (acid TEXT,ip TEXT); \
|
2016-03-27 04:44:32 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS wtps (wtpid TEXT PRIMARY KEY, acid TEXT,lastseen TIMESTAMP); \
|
2015-04-29 12:23:12 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS wtpprops (\
|
2015-05-02 02:02:06 +02:00
|
|
|
wtpid TEXT NOT NULL,\
|
|
|
|
id TEXT NOT NULL,\
|
|
|
|
sub_id TEXT NOT NULL,\
|
2015-04-29 12:23:12 +02:00
|
|
|
val TEXT,\
|
|
|
|
upd INTEGER,\
|
2015-05-02 02:02:06 +02:00
|
|
|
PRIMARY KEY(wtpid,id,sub_id)\
|
2015-04-29 12:23:12 +02:00
|
|
|
);\
|
2015-05-16 17:10:42 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS wlans (wlanid INTEGER PRIMARY KEY);\
|
|
|
|
CREATE TABLE IF NOT EXISTS wlanprops (wlanid INTEGER, id TEXT NOT NULL, val TEXT, PRIMARY KEY(wlanid,id));\
|
2014-07-14 22:44:46 +02:00
|
|
|
";
|
2015-05-16 17:10:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-14 22:44:46 +02:00
|
|
|
|
2014-07-13 19:18:56 +02:00
|
|
|
int db_init()
|
|
|
|
{
|
2015-05-02 02:02:06 +02:00
|
|
|
|
|
|
|
int rc;
|
2014-07-13 19:18:56 +02:00
|
|
|
const char * filename="ac.sqlite3";
|
2015-04-30 14:10:59 +02:00
|
|
|
cw_dbg(DBG_INFO,"Initializing Sqlite3 DB: %s, SQLite3 Version %s",filename,SQLITE_VERSION);
|
2015-05-02 02:02:06 +02:00
|
|
|
|
|
|
|
rc = sqlite3_config(SQLITE_CONFIG_SERIALIZED);
|
|
|
|
if (rc!=SQLITE_OK){
|
|
|
|
cw_log(LOG_ERR,"Error configuring SQLite3: %s",sqlite3_errmsg(handle));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = sqlite3_initialize();
|
|
|
|
if (rc!=SQLITE_OK){
|
|
|
|
cw_log(LOG_ERR,"Error initializing SQLite3 DB : %s",sqlite3_errmsg(handle));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rc = sqlite3_open(filename,&handle);
|
2015-04-29 12:23:12 +02:00
|
|
|
if (rc != SQLITE_OK)
|
2014-07-13 19:18:56 +02:00
|
|
|
{
|
2015-04-29 12:23:12 +02:00
|
|
|
cw_log(LOG_ERR,"Error opening SQLite3 DB %s: %s",filename,sqlite3_errmsg(handle));
|
2014-07-13 19:18:56 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-14 22:44:46 +02:00
|
|
|
const char * cmd = init_tables;
|
2014-07-13 19:18:56 +02:00
|
|
|
rc = sqlite3_exec(handle,cmd,0,0,0);
|
|
|
|
if (rc)
|
|
|
|
{
|
|
|
|
const char *em = sqlite3_errmsg(handle);
|
2015-04-29 12:23:12 +02:00
|
|
|
cw_log(LOG_ERR,"Error executing SQL \"%s\"\nSQL Error Message: %s",cmd, em);
|
2014-07-13 19:18:56 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-07-15 07:33:17 +02:00
|
|
|
|
2015-04-29 19:25:09 +02:00
|
|
|
static sqlite3_stmt * ping_stmt;
|
2015-04-29 12:23:12 +02:00
|
|
|
static sqlite3_stmt * put_wtp_prop_stmt;
|
2016-03-27 04:44:32 +02:00
|
|
|
|
|
|
|
|
2015-04-30 14:10:59 +02:00
|
|
|
static sqlite3_stmt * get_tasks_stmt;
|
2015-04-29 19:25:09 +02:00
|
|
|
|
2016-04-02 09:05:07 +02:00
|
|
|
static sqlite3_stmt * stmt_get_radio_tasks;
|
|
|
|
|
2016-03-27 04:44:32 +02:00
|
|
|
static sqlite3_stmt * stmt_ping_wtp;
|
2016-03-28 16:50:06 +02:00
|
|
|
static sqlite3_stmt * stmt_put_radio_prop;
|
2014-07-15 07:33:17 +02:00
|
|
|
|
2014-07-15 00:34:41 +02:00
|
|
|
int db_start()
|
|
|
|
{
|
2015-04-29 12:23:12 +02:00
|
|
|
cw_dbg(DBG_INFO,"Starting Sqlite3 DB");
|
|
|
|
|
|
|
|
const char *sql="";
|
2014-07-15 17:11:16 +02:00
|
|
|
|
2014-07-15 07:33:17 +02:00
|
|
|
sqlite3_stmt *stmt;
|
2016-03-27 10:56:55 +02:00
|
|
|
int rc = sqlite3_prepare_v2(handle, "INSERT OR REPLACE INTO acs (acid,acname) VALUES (?,?);",-1,&stmt,0);
|
2014-07-15 17:11:16 +02:00
|
|
|
if (rc)
|
|
|
|
goto errX;
|
2014-07-15 07:33:17 +02:00
|
|
|
|
|
|
|
rc = sqlite3_bind_text(stmt,1,conf_acid,-1,SQLITE_STATIC);
|
|
|
|
|
2014-07-17 22:58:58 +02:00
|
|
|
rc = sqlite3_bind_text(stmt,2,conf_acname,-1,SQLITE_STATIC);
|
2014-07-15 07:33:17 +02:00
|
|
|
|
|
|
|
sqlite3_step(stmt);
|
|
|
|
|
|
|
|
rc = sqlite3_prepare_v2(handle, "UPDATE acs SET lastseen=datetime('now') WHERE acid=?;",-1,&ping_stmt,0);
|
|
|
|
rc = sqlite3_bind_text(ping_stmt,1,conf_acid,-1,SQLITE_STATIC);
|
|
|
|
|
2015-04-29 12:23:12 +02:00
|
|
|
|
2015-04-30 14:10:59 +02:00
|
|
|
/* Prepare statement to update a WTP property */
|
2015-04-29 12:23:12 +02:00
|
|
|
sql = "INSERT OR REPLACE INTO wtpprops\
|
2015-05-02 02:02:06 +02:00
|
|
|
(wtpid,id,sub_id,val,upd)\
|
2015-04-29 12:23:12 +02:00
|
|
|
VALUES (?,?,?,?,?)";
|
|
|
|
|
|
|
|
rc = sqlite3_prepare_v2(handle, sql,-1, &put_wtp_prop_stmt,0);
|
|
|
|
if (rc)
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
|
2016-03-28 16:50:06 +02:00
|
|
|
sql = "INSERT OR REPLACE INTO radios\
|
|
|
|
(wtpid,rid,key,sub_key,val,upd)\
|
|
|
|
VALUES (?,?,?,?,?,0)";
|
|
|
|
|
|
|
|
rc = sqlite3_prepare_v2(handle, sql,-1, &stmt_put_radio_prop,0);
|
|
|
|
if (rc)
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
|
2016-03-27 04:44:32 +02:00
|
|
|
/* Prepare WTP ping statement */
|
|
|
|
sql = "INSERT OR REPLACE INTO wtps (wtpid,acid,lastseen) VALUES(?,?,datetime('now'))";
|
|
|
|
rc = sqlite3_prepare_v2(handle, sql,-1, &stmt_ping_wtp,0);
|
|
|
|
if (rc)
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
|
2015-04-30 14:10:59 +02:00
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
sql = "SELECT wtpid,id,sub_id,val FROM wtpprops WHERE upd>0 AND wtpid=?";
|
2015-04-30 14:10:59 +02:00
|
|
|
rc = sqlite3_prepare_v2(handle, sql,-1, &get_tasks_stmt,0);
|
|
|
|
if (rc)
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
|
2016-04-02 09:05:07 +02:00
|
|
|
sql = "SELECT wtpid,rid,key,sub_key,val FROM radios WHERE upd>0 AND wtpid=?";
|
|
|
|
rc = sqlite3_prepare_v2(handle, sql,-1, &stmt_get_radio_tasks,0);
|
|
|
|
if (rc)
|
|
|
|
goto errX;
|
|
|
|
|
2015-04-30 14:10:59 +02:00
|
|
|
|
2015-04-29 12:23:12 +02:00
|
|
|
|
2014-07-15 17:15:42 +02:00
|
|
|
return 1;
|
2014-07-15 07:33:17 +02:00
|
|
|
|
2014-07-15 17:11:16 +02:00
|
|
|
errX:
|
2015-04-29 12:23:12 +02:00
|
|
|
cw_log(LOG_ERR,"Fatal: Can't start Sqlite3 DB, Error while executing '%s' - %d - %s",sql,rc,sqlite3_errmsg(handle));
|
2014-07-15 17:11:16 +02:00
|
|
|
return 0;
|
2014-07-14 22:44:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-28 16:50:06 +02:00
|
|
|
void db_put_radio_prop(const char *wtp_id,const char *rid, const char * key,const char *sub_key,const char * val)
|
|
|
|
{
|
|
|
|
int rc=0;
|
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*// DBGX("Putting %s/%s:%s",id,sub_id,val);
|
2016-03-28 16:50:06 +02:00
|
|
|
// (wtpid,rid,key,sub_key,val,upd)
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2016-03-28 16:50:06 +02:00
|
|
|
sqlite3_reset(stmt_put_radio_prop);
|
|
|
|
sqlite3_clear_bindings(stmt_put_radio_prop);
|
|
|
|
|
|
|
|
if(sqlite3_bind_text(stmt_put_radio_prop,1,wtp_id,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
if(sqlite3_bind_text(stmt_put_radio_prop,2,rid,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sqlite3_bind_text(stmt_put_radio_prop,3,key,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
|
2018-03-17 18:01:17 +01:00
|
|
|
/* if (!sub_key)
|
2016-03-28 16:50:06 +02:00
|
|
|
sub_key=CW_ITEM_NONE;
|
2018-03-17 18:01:17 +01:00
|
|
|
*/
|
2016-03-28 16:50:06 +02:00
|
|
|
if (sqlite3_bind_text(stmt_put_radio_prop,4,sub_key,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
if (sqlite3_bind_text(stmt_put_radio_prop,5,val,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2016-03-28 16:50:06 +02:00
|
|
|
// if (sqlite3_bind_int(put_wtp_prop_stmt,5,0))
|
|
|
|
// goto errX;
|
|
|
|
|
|
|
|
// cw_dbg(DBG_X,"Her I am already, next is step");
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2016-03-28 16:50:06 +02:00
|
|
|
rc = sqlite3_step(stmt_put_radio_prop);
|
|
|
|
if (rc != SQLITE_DONE)
|
|
|
|
goto errX;
|
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2016-03-28 16:50:06 +02:00
|
|
|
// cw_dbg(DBG_X,"SQL schould be fine");
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2016-03-28 16:50:06 +02:00
|
|
|
return;
|
|
|
|
errX:
|
2018-03-26 15:11:57 +02:00
|
|
|
/*// cw_dbg (DBG_X, "Iam on err %d\n",rc);*/
|
2016-03-28 16:50:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
cw_log(LOG_ERR,"Can't update database with WTP props: %d - %s",
|
|
|
|
rc,sqlite3_errmsg(handle));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-15 17:11:16 +02:00
|
|
|
void db_ping()
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2014-07-15 17:11:16 +02:00
|
|
|
int rc = sqlite3_step(ping_stmt);
|
2014-07-17 22:58:58 +02:00
|
|
|
if (rc!=SQLITE_DONE){
|
2015-04-29 19:25:09 +02:00
|
|
|
cw_log(LOG_ERR,"Error: Can't ping database, error code %d - %s",rc,sqlite3_errmsg(handle));
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2014-07-15 17:11:16 +02:00
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-03-27 04:44:32 +02:00
|
|
|
|
|
|
|
void db_ping_wtp(const char *wtpid,const char *acid)
|
|
|
|
{
|
|
|
|
int rc=0;
|
|
|
|
sqlite3_reset(stmt_ping_wtp);
|
|
|
|
sqlite3_clear_bindings(stmt_ping_wtp);
|
|
|
|
if(sqlite3_bind_text(stmt_ping_wtp,1,wtpid,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
if(sqlite3_bind_text(stmt_ping_wtp,2,acid,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
rc = sqlite3_step(stmt_ping_wtp);
|
|
|
|
errX:
|
|
|
|
if (rc!=SQLITE_DONE) {
|
|
|
|
cw_log(LOG_ERR,"Can't ping database for WTP: %d - %s",
|
|
|
|
rc,sqlite3_errmsg(handle));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
void db_put_wtp_prop(const char *wtp_id,const char * id,const char *sub_id,const char * val)
|
2015-04-29 12:23:12 +02:00
|
|
|
{
|
2016-03-27 04:44:32 +02:00
|
|
|
int rc=0;
|
2015-04-29 19:25:09 +02:00
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*// DBGX("Putting %s/%s:%s",id,sub_id,val);
|
|
|
|
*/
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2015-04-29 19:25:09 +02:00
|
|
|
sqlite3_reset(put_wtp_prop_stmt);
|
|
|
|
sqlite3_clear_bindings(put_wtp_prop_stmt);
|
|
|
|
|
|
|
|
if(sqlite3_bind_text(put_wtp_prop_stmt,1,wtp_id,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
if(sqlite3_bind_text(put_wtp_prop_stmt,2,id,-1,SQLITE_STATIC))
|
2015-04-29 19:25:09 +02:00
|
|
|
goto errX;
|
|
|
|
|
2018-03-17 18:01:17 +01:00
|
|
|
/* if (!sub_id)
|
2015-05-02 02:02:06 +02:00
|
|
|
sub_id=CW_ITEM_NONE;
|
2018-03-17 18:01:17 +01:00
|
|
|
*/
|
2015-05-02 02:02:06 +02:00
|
|
|
|
|
|
|
if (sqlite3_bind_text(put_wtp_prop_stmt,3,sub_id,-1,SQLITE_STATIC))
|
2015-04-29 19:25:09 +02:00
|
|
|
goto errX;
|
|
|
|
|
|
|
|
if (sqlite3_bind_text(put_wtp_prop_stmt,4,val,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
if (sqlite3_bind_int(put_wtp_prop_stmt,5,0))
|
|
|
|
goto errX;
|
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*// cw_dbg(DBG_X,"Her I am already, next is step");
|
|
|
|
*/
|
2016-03-27 04:44:32 +02:00
|
|
|
rc = sqlite3_step(put_wtp_prop_stmt);
|
|
|
|
if (rc != SQLITE_DONE)
|
2015-04-29 19:25:09 +02:00
|
|
|
goto errX;
|
2016-03-27 04:44:32 +02:00
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2016-03-27 16:45:17 +02:00
|
|
|
// cw_dbg(DBG_X,"SQL schould be fine");
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2015-04-29 19:25:09 +02:00
|
|
|
return;
|
|
|
|
errX:
|
2018-03-26 15:11:57 +02:00
|
|
|
/*// cw_dbg (DBG_X, "Iam on err %d\n",rc);*/
|
2016-03-27 04:44:32 +02:00
|
|
|
|
|
|
|
|
2015-04-29 19:25:09 +02:00
|
|
|
if (rc) {
|
|
|
|
cw_log(LOG_ERR,"Can't update database with WTP props: %d - %s",
|
|
|
|
rc,sqlite3_errmsg(handle));
|
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-29 12:23:12 +02:00
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*// TODO XXXX*/
|
2018-03-11 10:34:20 +01:00
|
|
|
mavl_t db_get_update_tasks(struct conn * conn,const char * wtpid)
|
2015-04-29 19:25:09 +02:00
|
|
|
{
|
2018-02-26 18:28:12 +01:00
|
|
|
/*
|
2015-05-01 00:16:54 +02:00
|
|
|
sqlite3_reset(get_tasks_stmt);
|
|
|
|
sqlite3_clear_bindings(get_tasks_stmt);
|
2015-04-29 19:25:09 +02:00
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
mavl_conststr_t r = mavl_create_conststr();
|
|
|
|
if (!r)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
2016-03-27 04:44:32 +02:00
|
|
|
int rc=0;
|
2015-05-02 02:02:06 +02:00
|
|
|
|
|
|
|
|
2015-04-30 14:10:59 +02:00
|
|
|
if(sqlite3_bind_text(get_tasks_stmt,1,wtpid,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
2015-05-01 12:50:28 +02:00
|
|
|
while (SQLITE_ROW == sqlite3_step(get_tasks_stmt)) {
|
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
int ii;
|
2015-05-02 10:45:16 +02:00
|
|
|
//DBGX("-----------------------------------------------------","");
|
2015-05-02 02:02:06 +02:00
|
|
|
for (ii=0; ii<5; ii++){
|
|
|
|
|
2015-05-02 10:45:16 +02:00
|
|
|
//DBGX("CVALL: %s",(const char*)sqlite3_column_text(get_tasks_stmt,ii));
|
2015-05-02 02:02:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *id = (const char*)sqlite3_column_text(get_tasks_stmt,1);
|
|
|
|
if (!id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *sub_id = (const char*)sqlite3_column_text(get_tasks_stmt,2);
|
|
|
|
|
2015-05-01 12:50:28 +02:00
|
|
|
const char *val = (const char*)sqlite3_column_text(get_tasks_stmt,3);
|
|
|
|
|
2015-05-02 10:45:16 +02:00
|
|
|
//DBGX("ID: (%s), SubID (%s), Val (%s)",id,sub_id,val);
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
const struct cw_itemdef * cwi = cw_itemdef_get(conn->actions->items,id,sub_id);
|
2015-05-01 12:50:28 +02:00
|
|
|
if (!cwi) {
|
2015-05-02 10:45:16 +02:00
|
|
|
//DBGX("Not item definition found for: %s/%s",id,sub_id);
|
2015-05-02 02:02:06 +02:00
|
|
|
continue;
|
2015-05-01 12:50:28 +02:00
|
|
|
}
|
|
|
|
|
2016-03-27 04:44:32 +02:00
|
|
|
//uint8_t data[2048];
|
2015-05-01 12:50:28 +02:00
|
|
|
|
|
|
|
if (!cwi->type->from_str) {
|
2015-05-02 02:02:06 +02:00
|
|
|
cw_log(LOG_ERR,"Can't convert from string %s/%s - No method defined.",id,sub_id);
|
|
|
|
continue;
|
2015-05-01 12:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mbag_item_t * i = cwi->type->from_str(val);
|
2015-05-02 02:02:06 +02:00
|
|
|
i->id=cwi->id;
|
2015-05-01 12:50:28 +02:00
|
|
|
|
|
|
|
mbag_set(conn->outgoing,i);
|
2015-05-02 02:02:06 +02:00
|
|
|
|
|
|
|
mavl_add(r,(void*)cwi->id);
|
2015-04-30 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
if (r->count)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
mavl_destroy(r);
|
|
|
|
return NULL;
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2015-04-30 14:10:59 +02:00
|
|
|
|
|
|
|
errX:
|
|
|
|
if (rc) {
|
2015-05-01 00:16:54 +02:00
|
|
|
cw_log(LOG_ERR,"Can't get tasks: %d - %s",
|
2015-04-30 14:10:59 +02:00
|
|
|
rc,sqlite3_errmsg(handle));
|
|
|
|
}
|
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
if (r)
|
|
|
|
mavl_destroy(r);
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2018-02-26 18:28:12 +01:00
|
|
|
*/
|
2015-04-29 19:25:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2018-03-11 10:34:20 +01:00
|
|
|
mavl_t db_get_radio_tasks(struct conn * conn,const char * wtpid)
|
2016-04-02 09:05:07 +02:00
|
|
|
{
|
2018-02-26 18:28:12 +01:00
|
|
|
/*
|
2016-04-02 09:05:07 +02:00
|
|
|
//cw_dbg(DBG_X,"Get Radio Tasks for %s",wtpid);
|
|
|
|
|
|
|
|
sqlite3_reset(stmt_get_radio_tasks);
|
|
|
|
sqlite3_clear_bindings(stmt_get_radio_tasks);
|
|
|
|
|
|
|
|
mavl_conststr_t r = mavl_create_conststr();
|
|
|
|
if (!r)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
int rc=0;
|
|
|
|
|
|
|
|
|
|
|
|
if(sqlite3_bind_text(stmt_get_radio_tasks,1,wtpid,-1,SQLITE_STATIC))
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
while (SQLITE_ROW == sqlite3_step(stmt_get_radio_tasks)) {
|
|
|
|
|
|
|
|
int ii;
|
|
|
|
//DBGX("-----------------------------------------------------","");
|
|
|
|
for (ii=0; ii<6; ii++){
|
|
|
|
|
|
|
|
DBGX("CVALL: %s",(const char*)sqlite3_column_text(stmt_get_radio_tasks,ii));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
const char *strrid= (const char*)sqlite3_column_text(stmt_get_radio_tasks,1);
|
|
|
|
|
|
|
|
const char *id = (const char*)sqlite3_column_text(stmt_get_radio_tasks,2);
|
|
|
|
if (!id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *sub_id = (const char*)sqlite3_column_text(stmt_get_radio_tasks,3);
|
|
|
|
|
|
|
|
const char *val = (const char*)sqlite3_column_text(stmt_get_radio_tasks,4);
|
|
|
|
|
|
|
|
//DBGX("ID: (%s), SubID (%s), Val (%s)",id,sub_id,val);
|
|
|
|
|
|
|
|
const struct cw_itemdef * cwi = cw_itemdef_get(conn->actions->radioitems,id,sub_id);
|
|
|
|
if (!cwi) {
|
|
|
|
DBGX("No item definition found for: %s/%s",id,sub_id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!cwi->type->from_str) {
|
|
|
|
cw_log(LOG_ERR,"Can't convert from string %s/%s - No method defined.",id,sub_id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mbag_item_t * i = cwi->type->from_str(val);
|
|
|
|
i->id=cwi->id;
|
|
|
|
|
|
|
|
int rid = atoi(strrid);
|
|
|
|
cw_dbg(DBG_X,"RID: %d",rid);
|
|
|
|
|
|
|
|
|
|
|
|
mbag_t radio = mbag_i_get_mbag_c(conn->radios_upd,rid,mbag_create);
|
|
|
|
mbag_set(radio,i);
|
|
|
|
|
|
|
|
|
|
|
|
//mbag_set(conn->outgoing,i);
|
|
|
|
|
|
|
|
mavl_add(r,(void*)cwi->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r->count)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
mavl_destroy(r);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
errX:
|
|
|
|
if (rc) {
|
|
|
|
cw_log(LOG_ERR,"Can't get tasks: %d - %s",
|
|
|
|
rc,sqlite3_errmsg(handle));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
mavl_destroy(r);
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2018-02-26 18:28:12 +01:00
|
|
|
*/
|
2016-04-02 09:05:07 +02:00
|
|
|
}
|
|
|
|
|
2015-05-01 12:50:28 +02:00
|
|
|
|