Work on SQL support.
FossilOrigin-Name: d0d1624520afe2bc9fe84e98a2ee1bad2eb75df2b38efbd59fdf553d50cb5ed6
This commit is contained in:
parent
3b466158a4
commit
bc4aa16f9b
@ -63,6 +63,27 @@ int main (int argc, const char * argv[])
|
||||
{
|
||||
int rc =0;
|
||||
|
||||
/*
|
||||
int n;
|
||||
cw_itemdefheap_t h=cw_itemdefheap_create();
|
||||
n=cw_itemdefheap_register(h,capwap_itemdefs);
|
||||
printf("Registered: %d\n",n);
|
||||
|
||||
const cw_itemdef_t * id = cw_itemdef_get(h,"wtp_name",NULL);
|
||||
|
||||
if (id) {
|
||||
printf("Found %s is of type %s\n",id->id,id->type->name);
|
||||
}
|
||||
else{
|
||||
printf("Not found, why?\n");
|
||||
}
|
||||
|
||||
mavl_destroy(h);
|
||||
|
||||
|
||||
exit(0);
|
||||
*/
|
||||
|
||||
cw_log_name="AC-Tube";
|
||||
|
||||
read_config("ac.conf");
|
||||
@ -113,7 +134,7 @@ int main (int argc, const char * argv[])
|
||||
|
||||
/* Load bindings */
|
||||
cw_dbg(DBG_INFO,"Loading 802.11 Bindings ...");
|
||||
regn += cw_register_actions_capwap_80211_ac(&capwap_actions);
|
||||
// regn += cw_register_actions_capwap_80211_ac(&capwap_actions);
|
||||
|
||||
cw_dbg(DBG_INFO,"Registered %d protocol actions and strings.",regn);
|
||||
|
||||
|
60
src/ac/db.c
60
src/ac/db.c
@ -3,6 +3,8 @@
|
||||
|
||||
#include "capwap/log.h"
|
||||
#include "capwap/dbg.h"
|
||||
#include "capwap/capwap_items.h"
|
||||
#include "capwap/conn.h"
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
@ -87,7 +89,7 @@ int db_start()
|
||||
|
||||
|
||||
|
||||
sql = "SELECT * FROM wtpprops WHERE upd=0 AND wtpid=?";
|
||||
sql = "SELECT * FROM wtpprops WHERE upd>0 AND wtpid=?";
|
||||
rc = sqlite3_prepare_v2(handle, sql,-1, &get_tasks_stmt,0);
|
||||
if (rc)
|
||||
goto errX;
|
||||
@ -116,6 +118,8 @@ void db_put_wtp_prop(const char *wtp_id,int rid, const char * prop,const char *
|
||||
{
|
||||
int rc;
|
||||
|
||||
DBGX("Putting %s:%s",prop,val);
|
||||
|
||||
sqlite3_reset(put_wtp_prop_stmt);
|
||||
sqlite3_clear_bindings(put_wtp_prop_stmt);
|
||||
|
||||
@ -147,7 +151,7 @@ errX:
|
||||
}
|
||||
|
||||
|
||||
int db_get_tasks(const char * wtpid)
|
||||
int db_get_tasks(struct conn * conn,const char * wtpid)
|
||||
{
|
||||
|
||||
sqlite3_reset(get_tasks_stmt);
|
||||
@ -158,16 +162,50 @@ int db_get_tasks(const char * wtpid)
|
||||
|
||||
int rc;
|
||||
|
||||
rc = sqlite3_step(get_tasks_stmt);
|
||||
if (rc == SQLITE_ROW) {
|
||||
/* DBGX("Have a rowi %s",sqlite3_column_text(get_tasks_stmt,0));
|
||||
DBGX("Have a rowi %s",sqlite3_column_text(get_tasks_stmt,1));
|
||||
DBGX("Have a rowi %s",sqlite3_column_text(get_tasks_stmt,2));
|
||||
DBGX("Have a rowi %s",sqlite3_column_text(get_tasks_stmt,3));
|
||||
DBGX("Have a rowi %s",sqlite3_column_text(get_tasks_stmt,4));
|
||||
*/
|
||||
|
||||
//rc = sqlite3_step(get_tasks_stmt);
|
||||
while (SQLITE_ROW == sqlite3_step(get_tasks_stmt)) {
|
||||
|
||||
const char *prop = (const char*)sqlite3_column_text(get_tasks_stmt,2);
|
||||
const char *val = (const char*)sqlite3_column_text(get_tasks_stmt,3);
|
||||
|
||||
DBGX("Prop: %s Val: %s",prop,val);
|
||||
|
||||
struct cw_itemdef * cwi = cw_item_get_by_name(prop,capwap_itemdefs);
|
||||
if (!cwi) {
|
||||
DBGX("Not found: %s",prop);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t data[1024];
|
||||
printf("Type: %s\n",cwi->type->name);
|
||||
|
||||
if (!cwi->type->from_str) {
|
||||
cw_log(LOG_ERR,"Can't convert from SQL %s",prop);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
mbag_item_t * i = cwi->type->from_str(val);
|
||||
i->id=cwi->id;
|
||||
DBGX("Item made: %s",i->id);
|
||||
DBGX("Item data: %s",i->data);
|
||||
|
||||
mbag_set(conn->outgoing,i);
|
||||
|
||||
|
||||
/*
|
||||
if (i->type == MBAG_STR) {
|
||||
mbag_set_strn(conn->outgoing, a->item_id, (char *) data, len);
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// DBGX("The SQL RC: %d\n",rc);
|
||||
return 1;
|
||||
|
||||
@ -182,3 +220,5 @@ errX:
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@ extern void db_ping();
|
||||
extern int db_init();
|
||||
int db_start();
|
||||
void db_put_wtp_prop(const char *wtp_id,int rid, const char * prop,const char * val);
|
||||
int db_get_tasks(const char * wtpid);
|
||||
int db_get_tasks(struct conn * conn,const char * wtpid);
|
||||
|
||||
|
||||
|
||||
|
@ -224,6 +224,7 @@ static int wtpman_join(void *arg, time_t timer)
|
||||
|
||||
wtpman->conn->outgoing = mbag_create();
|
||||
wtpman->conn->incomming = mbag_create();
|
||||
conn->config=conn->incomming;
|
||||
// wtpman->conn->local = ac_config;
|
||||
|
||||
mbag_set_str(conn->local,CW_ITEM_AC_NAME,conf_acname);
|
||||
@ -338,16 +339,21 @@ void config_to_sql(struct conn *conn)
|
||||
mavliter_foreach(&it){
|
||||
mbag_item_t * i = mavliter_get(&it);
|
||||
|
||||
struct cw_item * cwi = cw_item_get_by_name(i->id,capwap_itemdefs);
|
||||
const struct cw_itemdef * cwi = cw_itemdef_get(conn->actions->items,i->id,NULL);
|
||||
if (cwi){
|
||||
DBGX("ID %d,%s",i->id,cwi->id);
|
||||
|
||||
// printf("%s != %s ?\n",i->type->name,cwi->type->name);
|
||||
char str[256];
|
||||
if (i->type->to_str)
|
||||
if (i->type->to_str){
|
||||
i->type->to_str(i,str);
|
||||
db_put_wtp_prop(wtp_id,-1,cwi->id,str);
|
||||
}
|
||||
else{
|
||||
cw_log(LOG_ERR,"Can_'t converto to str");
|
||||
|
||||
}
|
||||
|
||||
db_put_wtp_prop(wtp_id,-1,cwi->id,str);
|
||||
|
||||
}
|
||||
else{
|
||||
@ -441,7 +447,29 @@ static void wtpman_run(void *arg)
|
||||
break;
|
||||
}
|
||||
|
||||
db_get_tasks(sock_addr2str(&conn->addr));
|
||||
mavl_del_all(conn->outgoing);
|
||||
db_get_tasks(conn,sock_addr2str(&conn->addr));
|
||||
|
||||
|
||||
|
||||
//printf("Conn: %d\n",conn->outgoing->count);
|
||||
|
||||
if ( conn->outgoing->count ) {
|
||||
rc = cw_send_request(conn, CW_MSG_CONFIGURATION_UPDATE_REQUEST);
|
||||
DBGX("CU RC: %d",rc);
|
||||
|
||||
DBGX("MAV MERGE","");
|
||||
mavl_merge(conn->config,conn->outgoing);
|
||||
DBGX("MAV MERGE DONE","");
|
||||
|
||||
|
||||
printf("Conn aa: %d\n",conn->outgoing->count);
|
||||
config_to_sql(conn);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user