summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvichal <avichal.a@samsung.com>2019-02-12 17:32:29 +0530
committerAvichal <avichal.a@samsung.com>2019-02-13 11:47:38 +0530
commita58db5553ca379480bb85de4cb455262daf6c5a0 (patch)
treefd3360bedf13716fd9acfc7d4877fca98d7ee4b1
parentf2bfe46537d02d5cb0c3c47845de5603fa62ee11 (diff)
downloadgeofence-server-a58db5553ca379480bb85de4cb455262daf6c5a0.tar.gz
geofence-server-a58db5553ca379480bb85de4cb455262daf6c5a0.tar.bz2
geofence-server-a58db5553ca379480bb85de4cb455262daf6c5a0.zip
WGIDS: 370880,370928,370929,370931,370932,370933,370934,370936, 370938,370939,370940,370941,370942 Change-Id: I0c54ca2901747b5af8fbd4a25abd24cd847760e8 Signed-off-by: Avichal <avichal.a@samsung.com>
-rwxr-xr-xgeofence-server/src/geofence_server_db.c56
1 files changed, 36 insertions, 20 deletions
diff --git a/geofence-server/src/geofence_server_db.c b/geofence-server/src/geofence_server_db.c
index 3a6a340..fd1e969 100755
--- a/geofence-server/src/geofence_server_db.c
+++ b/geofence-server/src/geofence_server_db.c
@@ -67,12 +67,13 @@ static struct {
.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; \
}
@@ -351,6 +352,7 @@ static int __geofence_manager_db_insert_bssid_info(const int fence_id, char *bss
}
if (count > 0) {
LOGI_GEOFENCE("count = %d", count);
+ sqlite3_free(query);
return FENCE_ERR_NONE;
}
@@ -362,13 +364,13 @@ static int __geofence_manager_db_insert_bssid_info(const int fence_id, char *bss
}
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) {
@@ -420,10 +422,10 @@ static int __geofence_manager_db_insert_wifi_data_info(gpointer data, gpointer u
}
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) {
@@ -772,13 +774,13 @@ int geofence_manager_set_place_info(place_info_s *place_info, int *place_id)
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) {
@@ -823,22 +825,22 @@ int geofence_manager_set_common_info(fence_common_info_s *fence_info, int *fence
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) {
@@ -1130,7 +1132,7 @@ int geofence_manager_set_geocoordinate_info(int fence_id, geocoordinate_info_s *
}
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)
@@ -1142,36 +1144,39 @@ int geofence_manager_set_geocoordinate_info(int fence_id, geocoordinate_info_s *
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;
}
@@ -1221,6 +1226,7 @@ int geofence_manager_get_geocoordinate_info(int fence_id, geocoordinate_info_s *
*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);
@@ -1320,6 +1326,7 @@ int geofence_manager_get_ap_info(const int fence_id, GList **ap_list)
}
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);
@@ -1368,6 +1375,7 @@ int geofence_manager_get_place_info(int place_id, place_info_s **place_info)
}
*place_info = (place_info_s *)g_malloc0(sizeof(place_info_s));
if (*place_info == NULL) {
+ sqlite3_free(query);
sqlite3_finalize(state);
}
g_return_val_if_fail(*place_info, FENCE_ERR_INTERNAL);
@@ -1483,6 +1491,7 @@ int geofence_manager_get_bssid_info(const int fence_id, bssid_info_s **bssid_inf
}
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);
@@ -2054,6 +2063,10 @@ int geofence_manager_get_access_type(int fence_id, int place_id, access_type_e *
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));
@@ -2543,6 +2556,7 @@ int geofence_manager_get_count_by_params(const char *app_id, geofence_type_e fen
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);
@@ -2640,6 +2654,7 @@ int geofence_manager_get_count_of_fences(int *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);
@@ -2679,6 +2694,7 @@ int geofence_manager_get_place_count_by_placeid(int place_id, int *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);