Skip to content
Snippets Groups Projects
Commit 12cf9253 authored by clohr's avatar clohr
Browse files

misc

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/C/trunk@1969 b32b6428-25c9-4566-ad07-03861ab6144f
parent 21db50cb
Branches
Tags
No related merge requests found
......@@ -260,8 +260,10 @@ void manage_msg(const xAAL_businfo_t *bus, const xAAL_devinfo_t *me,
if ( strcmp(action, "alive") == 0 ) {
device_t *device = insert_device(devices, source, devType);
device->timeout = xAAL_read_aliveTimeout(jbody);
if ( LIST_EMPTY(&(device->attributes)) ) {
if ( !xAAL_write_busl(bus, me, "request", "getAttributes", NULL, source, NULL) )
fprintf(xAAL_error_log, "Could not send getAttributes\n");
}
} else if ( strcmp(action, "attributesChange") == 0 ) {
device_t *device = insert_device(devices, source, devType);
......
No preview for this file type
......@@ -96,6 +96,7 @@ bool insert_item(sqlite3 *db, const char *tbl, const char *cel, const char *item
int rc;
sql = malloc(strlen(query)+strlen(tbl)+strlen(cel)+strlen(item)+1);
if (!sql) fprintf(stderr, "Malloc error 1\n");
sprintf(sql, query, tbl, cel, item);
rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
free(sql);
......@@ -115,6 +116,7 @@ bool delete_item(sqlite3 *db, const char *tbl, const char *cel, const char *item
int rc;
sql = malloc(strlen(query)+strlen(tbl)+strlen(cel)+strlen(item)+1);
if (!sql) fprintf(stderr, "Malloc error 2\n");
sprintf(sql, query, tbl, cel, item);
rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
free(sql);
......@@ -151,6 +153,8 @@ bool validate_str(const char *str) {
if (!preg) {
preg = (regex_t *)malloc(sizeof(regex_t));
if (!preg) fprintf(stderr, "Malloc error 3\n");
r = regcomp(preg, "^[^'\\\"]*$", REG_NOSUB); // safe but too restrictive, to be improved
if ( r != 0 ) {
preg = NULL;
......@@ -206,6 +210,7 @@ bool insert_device_kv(sqlite3 *db, const char *addr, const char *key, const char
if ( !validate_str(key) || !validate_str(value) || (uuid_parse(addr, uuid) == -1) )
return false;
sql = malloc(strlen(query)+strlen(addr)+strlen(key)+strlen(value)+1);
if (!sql) fprintf(stderr, "Malloc error 4\n");
sprintf(sql, query, addr, key, value);
rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
free(sql);
......@@ -233,6 +238,7 @@ bool delete_device_kv(sqlite3 *db, const char *addr, const char *key, const char
if ( !validate_str(key) || !validate_str(value) || (uuid_parse(addr, uuid) == -1) )
return false;
sql = malloc(strlen(query)+strlen(addr)+strlen(key)+strlen(value)+1);
if (!sql) fprintf(stderr, "Malloc error 5\n");
sprintf(sql, query, addr, key, value);
rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
free(sql);
......@@ -265,7 +271,9 @@ static int callback_map(void *data, int argc, char **argv, char **azColName){
static int callback_str(void *data, int argc, char **argv, char **azColName){
char **str = data;
if (argv[0])
*str = strdup(argv[0]);
{ *str = strdup(argv[0]);
if (!*str) fprintf(stderr, "Strdup error 1\n");
}
return 0;
}
......@@ -285,6 +293,7 @@ bool select_keys_values(sqlite3 *db, const char *addr,
if ( (uuid_parse(addr, uuid) == -1) )
return false;
sql = malloc(strlen(query)+strlen(addr)+1);
if (!sql) fprintf(stderr, "Malloc error 6\n");
sprintf(sql, query, addr);
rc = sqlite3_exec(db, sql, callback_map, jmap, &zErrMsg);
free(sql);
......@@ -311,6 +320,7 @@ bool select_value(sqlite3 *db, const char *addr, const char *key, char **value)
if ( !validate_str(key) || (uuid_parse(addr, uuid) == -1) )
return false;
sql = malloc(strlen(query)+strlen(addr)+strlen(key)+1);
if (!sql) fprintf(stderr, "Malloc error 7\n");
sprintf(sql, query, addr, key);
rc = sqlite3_exec(db, sql, callback_str, value, &zErrMsg);
free(sql);
......@@ -336,6 +346,7 @@ bool select_devices_with_kv(sqlite3 *db, const char *key, const char *value, str
if ( !validate_str(key) || !validate_str(value) )
return false;
sql = malloc(strlen(query)+strlen(key)+strlen(value)+1);
if (!sql) fprintf(stderr, "Malloc error 8\n");
sprintf(sql, query, key, value);
rc = sqlite3_exec(db, sql, callback_array, jarray, &zErrMsg);
free(sql);
......@@ -361,6 +372,7 @@ bool select_devices_with_key(sqlite3 *db, const char *key, struct json_object **
if ( !validate_str(key) )
return false;
sql = malloc(strlen(query)+strlen(key)+1);
if (!sql) fprintf(stderr, "Malloc error 9\n");
sprintf(sql, query, key);
rc = sqlite3_exec(db, sql, callback_array, jdevices, &zErrMsg);
free(sql);
......@@ -385,6 +397,7 @@ bool select_devices_with_value(sqlite3 *db, const char *value, struct json_objec
if ( !validate_str(value) )
return false;
sql = malloc(strlen(query)+strlen(value)+1);
if (!sql) fprintf(stderr, "Malloc error 10\n");
sprintf(sql, query, value);
rc = sqlite3_exec(db, sql, callback_array, jdevices, &zErrMsg);
free(sql);
......
......@@ -40,7 +40,7 @@
#include "db.h"
#define ALIVE_PERIOD 120
#define CHECKING_PERIOD 30
#define CHECKING_PERIOD 120
#define GRACE_DELAY 120
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment