#include <sys/stat.h>
#include <string.h>
#include <bluetooth.h>
-#include <wifi.h>
+#include <wifi-manager.h>
#include <tzplatform_config.h>
#include <sys/types.h>
#include <fcntl.h>
.handle = NULL,
};
-#define SQLITE3_RETURN(ret, msg, state) \
+#define SQLITE3_RETURN(ret, msg, state, query) \
if (ret != SQLITE_OK) { \
LOGI_GEOFENCE("sqlite3 Error[%d] : %s", ret, msg); \
sqlite3_reset(state); \
sqlite3_clear_bindings(state); \
sqlite3_finalize(state); \
+ sqlite3_free(query); \
return FENCE_ERR_SQLITE_FAIL; \
}
if (sqlite3_exec(db_info_s.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
LOGI_GEOFENCE("Failed to execute the DDL (%s)", err);
sqlite3_free(ddl);
+ sqlite3_free(err);
return FENCE_ERR_SQLITE_FAIL;
}
if (sqlite3_exec(db_info_s.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
LOGI_GEOFENCE("Failed to execute the DDL (%s)", err);
sqlite3_free(ddl);
+ sqlite3_free(err);
return FENCE_ERR_SQLITE_FAIL;
}
if (sqlite3_exec(db_info_s.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
LOGI_GEOFENCE("Failed to execute the DDL (%s)", err);
sqlite3_free(ddl);
+ sqlite3_free(err);
return FENCE_ERR_SQLITE_FAIL;
}
if (sqlite3_exec(db_info_s.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
LOGI_GEOFENCE("Failed to execute the DDL (%s)", err);
sqlite3_free(ddl);
+ sqlite3_free(err);
return FENCE_ERR_SQLITE_FAIL;
}
if (sqlite3_exec(db_info_s.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
LOGI_GEOFENCE("Failed to execute the DDL (%s)", err);
sqlite3_free(ddl);
+ sqlite3_free(err);
return FENCE_ERR_SQLITE_FAIL;
}
}
if (count > 0) {
LOGI_GEOFENCE("count = %d", count);
+ sqlite3_free(query);
return FENCE_ERR_NONE;
}
}
ret = sqlite3_bind_int(state, ++index, fence_id);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_text(state, ++index, bssid_info, -1, SQLITE_STATIC);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_text(state, ++index, ssid, -1, SQLITE_STATIC);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_step(state);
if (ret != SQLITE_DONE) {
}
ret = sqlite3_bind_int(state, ++index, *fence_id);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_text(state, ++index, wifi_info->bssid, -1, SQLITE_STATIC);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_step(state);
if (ret != SQLITE_DONE) {
if (ret != BT_ERROR_NONE)
LOGD_GEOFENCE("bt address get fail %d", ret);
- ret = wifi_get_mac_address(&wifi_address);
- if (ret != WIFI_ERROR_NONE)
+ ret = wifi_manager_get_mac_address(&wifi_address);
+ if (ret != WIFI_MANAGER_ERROR_NONE)
LOGD_GEOFENCE("wifi address get fail %d", ret);
if (bt_address) {
LOGD_GEOFENCE("appid[%s] access_type[%d] place_name[%s]", place_info->appid, place_info->access_type, place_info->place_name);
ret = sqlite3_bind_int(state, ++index, place_info->access_type);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_text(state, ++index, place_info->place_name, -1, SQLITE_STATIC);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_text(state, ++index, place_info->appid, -1, SQLITE_STATIC);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_step(state);
if (ret != SQLITE_DONE) {
return FENCE_ERR_PREPARE;
}
- LOGD_GEOFENCE("place_id[%d], enable[%d], appid[%s] geofence_type[%d] access_type[%d] running_status[%d]", fence_info->place_id, fence_info->enable, fence_info->appid, fence_info->running_status, fence_info->type, fence_info->access_type, fence_info->place_id);
+ LOGD_GEOFENCE("place_id[%d], enable[%d], appid[%s] geofence_type[%d] access_type[%d] running_status[%d]", fence_info->place_id, fence_info->enable, fence_info->appid, fence_info->type, fence_info->access_type, fence_info->running_status);
ret = sqlite3_bind_int(state, ++index, fence_info->place_id);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_int(state, ++index, fence_info->enable);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_text(state, ++index, fence_info->appid, -1, SQLITE_STATIC);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_int(state, ++index, fence_info->type);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_int(state, ++index, fence_info->access_type);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_int(state, ++index, fence_info->running_status);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_step(state);
if (ret != SQLITE_DONE) {
}
ret = sqlite3_bind_int(state, ++index, fence_id);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
#ifdef SUPPORT_ENCRYPTION
if (password == NULL)
ret = sqlite3_bind_text(state, ++index, data_name_lat, -1, SQLITE_STATIC);
/*ret = sqlite3_bind_double (state, ++index, geocoordinate_info->latitude);*/
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = snprintf(data_name_lon, MAX_DATA_NAME, "%lf", geocoordinate_info->longitude);
if (ret < 0) {
LOGD_GEOFENCE("ERROR: String will be truncated");
+ sqlite3_free(query);
+ sqlite3_finalize(state);
return FENCE_ERR_STRING_TRUNCATED;
}
ret = sqlite3_bind_text(state, ++index, data_name_lon, -1, SQLITE_STATIC);
/*ret = sqlite3_bind_double (state, ++index, geocoordinate_info->longitude);*/
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = snprintf(data_name_rad, MAX_DATA_NAME, "%lf", geocoordinate_info->radius);
if (ret < 0) {
LOGD_GEOFENCE("ERROR: String will be truncated");
+ sqlite3_free(query);
+ sqlite3_finalize(state);
return FENCE_ERR_STRING_TRUNCATED;
}
ret = sqlite3_bind_text(state, ++index, data_name_rad, -1, SQLITE_STATIC);
/*ret = sqlite3_bind_double (state, ++index, geocoordinate_info->radius);*/
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_bind_text(state, ++index, geocoordinate_info->address, -1, SQLITE_STATIC);
- SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+ SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
ret = sqlite3_step(state);
if (ret != SQLITE_DONE) {
LOGI_GEOFENCE("sqlite3_step Error[%d] : %s", ret, sqlite3_errmsg(db_info_s.handle));
+ sqlite3_free(query);
sqlite3_finalize(state);
return FENCE_ERR_SQLITE_FAIL;
}
}
*geocoordinate_info = (geocoordinate_info_s *)g_malloc0(sizeof(geocoordinate_info_s));
+ if (*geocoordinate_info == NULL) {
+ sqlite3_finalize(state);
+ sqlite3_free(query);
+ }
g_return_val_if_fail(*geocoordinate_info, FENCE_ERR_INVALID_PARAMETER);
#ifdef SUPPORT_ENCRYPTION
break;
}
wifi_info = g_slice_new0(wifi_info_s);
+ if (wifi_info == NULL) {
+ sqlite3_free(query2);
+ sqlite3_finalize(state);
+ }
g_return_val_if_fail(wifi_info, -1);
if (wifi_info) {
bssid = (const char *) sqlite3_column_text(state, 1);
return FENCE_ERR_SQLITE_FAIL;
}
*place_info = (place_info_s *)g_malloc0(sizeof(place_info_s));
- g_return_val_if_fail(*place_info, FENCE_ERR_INVALID_PARAMETER);
+ if (*place_info == NULL) {
+ sqlite3_free(query);
+ sqlite3_finalize(state);
+ }
+ g_return_val_if_fail(*place_info, FENCE_ERR_INTERNAL);
data_name = (char *)sqlite3_column_text(state, ++index);
if (!data_name || !strlen(data_name))
break;
}
bssid_info_from_db = g_slice_new0(bssid_info_s);
+ if (bssid_info_from_db == NULL) {
+ sqlite3_free(query2);
+ sqlite3_finalize(state);
+ }
g_return_val_if_fail(bssid_info_from_db, -1);
if (bssid_info_from_db) {
bssid = (const char *)sqlite3_column_text(state, 1);
LOGD_GEOFENCE("current fence id is [%d]", fence_id);
LOGD_GEOFENCE("current place id is [%d]", place_id);
+
+ if (query == NULL)
+ return FENCE_ERR_INVALID_PARAMETER;
+
ret = sqlite3_prepare_v2(db_info_s.handle, query, -1, &state, &tail);
if (ret != SQLITE_OK) {
LOGI_GEOFENCE("Error: %s", sqlite3_errmsg(db_info_s.handle));
return FENCE_ERR_SQLITE_FAIL;
}
sqlite3_reset(state);
+ sqlite3_finalize(state);
sqlite3_free(query_two);
char *query_three = sqlite3_mprintf("UPDATE sqlite_sequence SET seq = 0 where name = %Q;", menu_table[FENCE_MAIN_TABLE]);
if (*count <= 0) {
LOGI_GEOFENCE("ERROR: count = %d", *count);
+ sqlite3_finalize(state);
+ sqlite3_free(query);
return FENCE_ERR_COUNT;
} else {
LOGI_GEOFENCE("count[%d]", *count);
if (*count < 0) {
LOGI_GEOFENCE("ERROR: count = %d", *count);
+ sqlite3_finalize(state);
+ sqlite3_free(query);
return FENCE_ERR_COUNT;
} else {
LOGI_GEOFENCE("count[%d]", *count);
if (*count < 0) {
LOGI_GEOFENCE("ERROR: place count = %d", *count);
+ sqlite3_finalize(state);
+ sqlite3_free(query);
return FENCE_ERR_COUNT;
} else {
LOGI_GEOFENCE("place count[%d]", *count);