summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjomui <jongmun.woo@samsung.com>2015-09-10 15:51:02 +0900
committerjomui <jongmun.woo@samsung.com>2015-10-05 17:46:00 +0900
commite48945efb86b12734536debc7700f840d362eb8f (patch)
treef2742045edcf4ee1a5723c8e201e94b1cb44609d
parented107e0c2dce8e0795887e0ed9602d40355d9cd8 (diff)
downloadgeofence-server-e48945efb86b12734536debc7700f840d362eb8f.tar.gz
geofence-server-e48945efb86b12734536debc7700f840d362eb8f.tar.bz2
geofence-server-e48945efb86b12734536debc7700f840d362eb8f.zip
2.fix empty DB issue when first boot on Signed-off-by: jomui <jongmun.woo@samsung.com> Change-Id: I11fded5fc3a0e54fd225e74a4bb1eac82f211f43
-rw-r--r--geofence-server/src/geofence_server.c4
-rwxr-xr-xgeofence-server/src/geofence_server_db.c75
-rw-r--r--geofence-server/src/geofence_server_wifi.c3
-rw-r--r--geofence-server/src/server.c8
4 files changed, 62 insertions, 28 deletions
diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c
index 6eaedb4..0fac348 100644
--- a/geofence-server/src/geofence_server.c
+++ b/geofence-server/src/geofence_server.c
@@ -1487,6 +1487,10 @@ static void dbus_start_geofence_cb(gint fence_id, const gchar *app_id, gpointer
} else {
status_to_be_emitted = GEOFENCE_FENCE_STATE_OUT;
}
+
+ ret = bt_adapter_free_device_info(bt_device_info);
+ if (ret != BT_ERROR_NONE)
+ LOGE_GEOFENCE("bt_adapter_free_device_info fail[%d]", ret);
}
}
}
diff --git a/geofence-server/src/geofence_server_db.c b/geofence-server/src/geofence_server_db.c
index 317e7a3..78b7b6e 100755
--- a/geofence-server/src/geofence_server_db.c
+++ b/geofence-server/src/geofence_server_db.c
@@ -47,10 +47,13 @@
char *menu_table[4] = { "GeoFence", "FenceGeocoordinate", "FenceGeopointWifi", "FenceBssid" };
const char *group_id = NULL;
+
+#ifdef SUPPORT_ENCRYPTION
static char *password = "k1s2c3w4k5a6";
const char *col_latitude = "la";
const char *col_longitude = "lo";
const char *col_radius = "r";
+#endif
typedef enum {
FENCE_MAIN_TABLE = 0, /*GeoFence */
@@ -604,6 +607,7 @@ static int __geofence_manager_db_enable_foreign_keys(void)
return FENCE_ERR_NONE;
}
+#ifdef SUPPORT_ENCRYPTION
void replaceChar(char *src, char oldChar, char newChar)
{
while (*src) {
@@ -613,34 +617,47 @@ void replaceChar(char *src, char oldChar, char newChar)
}
}
-void __geofence_manager_genarate_password(char *password)
+void __geofence_manager_generate_password(char *password)
{
char *bt_address = NULL;
char *wifi_address = NULL;
- char *token = NULL;
+ char *token = NULL, *save_token = NULL;
int bt_temp[6] = {0}, wifi_temp[6] = {0};
int i = 0, fkey[6], lkey[6];
char s1[100], s2[100], result[200];
char keyword[6] = { 'b', 'w', 'd', 's', 'j', 'f' };
+ int ret = 0;
- bt_adapter_get_address(&bt_address);
- wifi_get_mac_address(&wifi_address);
+ ret = bt_adapter_get_address(&bt_address);
+ if (ret != BT_ERROR_NONE) {
+ LOGD_GEOFENCE("bt address get fail %d", ret);
+ }
- token = strtok(bt_address, ":");
- i = 0;
- while (token) {
- bt_temp[i++] = atoi(token);
- token = strtok(NULL, ":");
- if (i >= 6)
- break;
+ ret = wifi_get_mac_address(&wifi_address);
+ if (ret != WIFI_ERROR_NONE) {
+ LOGD_GEOFENCE("wifi address get fail %d", ret);
}
- token = strtok(wifi_address, ":");
- i = 0;
- while (token) {
- wifi_temp[i++] = atoi(token);
- token = strtok(NULL, ":");
- if (i >= 6)
- break;
+
+ if (bt_address) {
+ token = strtok_r(bt_address, ":", &save_token);
+ i = 0;
+ while (token) {
+ bt_temp[i++] = atoi(token);
+ token = strtok_r(NULL, ":", &save_token);
+ if (i >= 6)
+ break;
+ }
+ }
+
+ if (wifi_address) {
+ token = strtok_r(wifi_address, ":", &save_token);
+ i = 0;
+ while (token) {
+ wifi_temp[i++] = atoi(token);
+ token = strtok_r(NULL, ":", &save_token);
+ if (i >= 6)
+ break;
+ }
}
memset((void *) s1, 0, sizeof(s1));
@@ -662,11 +679,16 @@ void __geofence_manager_genarate_password(char *password)
}
sprintf(result, "%s%s", s1, s2);
+ LOGD_GEOFENCE("result : %s", result);
password = result;
- LOGD_GEOFENCE("result : %s", result);
-}
+ if (bt_address != NULL)
+ free(bt_address);
+ if (wifi_address != NULL)
+ free(wifi_address);
+}
+#endif
static int __check_db_file()
{
@@ -700,8 +722,7 @@ int geofence_manager_db_init(void)
if (__check_db_file()) {
LOGW_GEOFENCE("db(%s) file doesn't exist.", GEOFENCE_DB_FILE);
open_flag = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| SQLITE_OPEN_FULLMUTEX;
- }
- else {
+ } else {
if (lstat(GEOFENCE_DB_FILE, &stat) < 0) {
LOGE_GEOFENCE("Can't get db(%s) information.", GEOFENCE_DB_FILE);
return FENCE_ERR_SQLITE_FAIL;
@@ -714,7 +735,7 @@ int geofence_manager_db_init(void)
return FENCE_ERR_SQLITE_FAIL;
}
- if (!stat.st_size)
+ if (open_flag & SQLITE_OPEN_CREATE)
__geofence_manager_db_create_table();
return FENCE_ERR_NONE;
@@ -1160,8 +1181,10 @@ 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);
+#ifdef SUPPORT_ENCRYPTION
if (password == NULL)
- __geofence_manager_genarate_password(password);
+ __geofence_manager_generate_password(password);
+#endif
/* ssa_put : latitude*/
ret = snprintf(data_name_lat, MAX_DATA_NAME, "%lf", geocoordinate_info->latitude);
@@ -1252,8 +1275,10 @@ int geofence_manager_get_geocoordinate_info(int fence_id, geocoordinate_info_s *
*geocoordinate_info = (geocoordinate_info_s *)g_malloc0(sizeof(geocoordinate_info_s));
g_return_val_if_fail(*geocoordinate_info, FENCE_ERR_INVALID_PARAMETER);
+#ifdef SUPPORT_ENCRYPTION
if (password == NULL)
- __geofence_manager_genarate_password(password);
+ __geofence_manager_generate_password(password);
+#endif
data_name = (char *) sqlite3_column_text(state, ++index);
diff --git a/geofence-server/src/geofence_server_wifi.c b/geofence-server/src/geofence_server_wifi.c
index c8d840c..9c770e3 100644
--- a/geofence-server/src/geofence_server_wifi.c
+++ b/geofence-server/src/geofence_server_wifi.c
@@ -38,8 +38,9 @@ static void emit_wifi_geofence_inout_changed(GeofenceServer *geofence_server, in
return;
}
GeofenceItemData *item_data = __get_item_by_fence_id(fence_id, geofence_server);
- if (app_id == NULL) {
+ if (item_data == NULL) {
LOGD_GEOFENCE("getting item data failed. fence_id [%d]", fence_id);
+ g_free(app_id);
return;
}
if (fence_status == GEOFENCE_FENCE_STATE_IN) {
diff --git a/geofence-server/src/server.c b/geofence-server/src/server.c
index c21fc4b..e259c0d 100644
--- a/geofence-server/src/server.c
+++ b/geofence-server/src/server.c
@@ -262,7 +262,9 @@ int _geofence_initialize_geofence_server(GeofenceServer *geofence_server)
ret = wifi_set_connection_state_changed_cb(__geofence_wifi_device_connection_state_changed_cb, geofence_server);
if (WIFI_ERROR_NONE != ret) {
LOGD_GEOFENCE("wifi_set_connection_state_changed_cb() failed(%d).", ret);
- wifi_deinitialize();
+ ret = wifi_deinitialize();
+ if (ret != WIFI_ERROR_NONE)
+ LOGD_GEOFENCE("wifi_deinitialize() failed(%d).", ret);
return -1;
} else {
LOGD_GEOFENCE("wifi_set_connection_state_changed_cb() success.", ret);
@@ -271,7 +273,9 @@ int _geofence_initialize_geofence_server(GeofenceServer *geofence_server)
ret = wifi_set_device_state_changed_cb(__geofence_wifi_device_state_changed_cb, geofence_server);
if (WIFI_ERROR_NONE != ret) {
LOGD_GEOFENCE("wifi_set_device_state_changed_cb() failed(%d).", ret);
- wifi_deinitialize();
+ ret = wifi_deinitialize();
+ if (ret != WIFI_ERROR_NONE)
+ LOGD_GEOFENCE("wifi_deinitialize() failed(%d).", ret);
return -1;
} else {
LOGD_GEOFENCE("wifi_set_device_state_changed_cb() success.", ret);