Revert "Revert "improve plugin architecture"" 91/96691/1
authorJaewon Lim <jaewon81.lim@samsung.com>
Thu, 10 Nov 2016 01:47:42 +0000 (17:47 -0800)
committerJaewon Lim <jaewon81.lim@samsung.com>
Thu, 10 Nov 2016 01:47:42 +0000 (17:47 -0800)
This reverts commit eb26b877fe2db374ffa875bbb1e6c1cf19921c86.

Change-Id: Id98f5e6d21f4f96bc3ffb4ca6ae928ea07232b04

27 files changed:
CMakeLists.txt
src/default_plugin.h [new file with mode: 0644]
src/default_plugin_auth.c [new file with mode: 0644]
src/default_plugin_basic.c [new file with mode: 0644]
src/default_plugin_event.c [new file with mode: 0644]
src/default_plugin_main.c [new file with mode: 0644]
src/file_sync_service.c
src/hashtable.c [new file with mode: 0644]
src/hashtable.h [new file with mode: 0644]
src/log.h [new file with mode: 0644]
src/parameter.h [new file with mode: 0644]
src/plugin.c [new file with mode: 0644]
src/plugin.h [new file with mode: 0644]
src/properties.c
src/qemu_pipe.h
src/sdb.c
src/sdb.h
src/sdbd_plugin.h
src/sdktools.c
src/services.c
src/sockets.c
src/transport.c
src/transport_local.c
src/transport_usb.c
src/usb_funcfs_client.c
src/usb_linux.c
src/usb_linux_client.c

index f160f95..ae6f310 100644 (file)
@@ -51,6 +51,12 @@ SET(SDBD_SRCS
        src/commandline_sdbd.c
        src/usb_linux_client.c
        src/usb_funcfs_client.c
+       src/default_plugin_auth.c
+       src/default_plugin_basic.c
+       src/default_plugin_main.c
+       src/default_plugin_event.c
+       src/hashtable.c
+       src/plugin.c
 )
 
 include(FindPkgConfig)
diff --git a/src/default_plugin.h b/src/default_plugin.h
new file mode 100644 (file)
index 0000000..b8d44f3
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DEFAULT_PLUGIN_H
+#define __DEFAULT_PLUGIN_H
+
+extern eventfunc event_handler;
+
+int get_plugin_capability ( parameters* in, parameters* out );
+int verify_shell_cmd ( parameters* in, parameters* out );
+int convert_shell_cmd ( parameters* in, parameters* out );
+int verify_peer_ip ( parameters* in, parameters* out );
+int verify_sdbd_launch ( parameters* in, parameters* out );
+int verify_root_cmd ( parameters* in, parameters* out );
+int get_lock_state ( parameters* in, parameters* out );
+
+int auth_support ( parameters* in, parameters* out );
+int auth_get_key_file_paths ( parameters* in, parameters* out );
+
+int confirm_public_key ( parameters* in, int out_fd );
+
+void create_pwlock_thread();
+
+#endif // __DEFAULT_PLUGIN_H
diff --git a/src/default_plugin_auth.c b/src/default_plugin_auth.c
new file mode 100644 (file)
index 0000000..8fa743a
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+
+#define TRACE_TAG TRACE_SDB
+#include "log.h"
+
+#include "parameter.h"
+#include "sdbd_plugin.h"
+#include "default_plugin.h"
+
+int auth_support ( parameters* in, parameters* out )
+{
+    if ( out == NULL ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    out->number_of_parameter = 1;
+    out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    out->array_of_parameter[0].type = type_int32;
+    out->array_of_parameter[0].v_int32 = PLUGIN_RET_INVALID;
+
+    return PLUGIN_CMD_SUCCESS;
+}
+
+int auth_get_key_file_paths ( parameters* in, parameters* out )
+{
+    return PLUGIN_CMD_FAIL;
+    
+}
+
+int confirm_public_key( parameters* in, int out_fd )
+{
+    return PLUGIN_CMD_FAIL;
+}
diff --git a/src/default_plugin_basic.c b/src/default_plugin_basic.c
new file mode 100644 (file)
index 0000000..58464c7
--- /dev/null
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+#define TRACE_TAG TRACE_SDB
+#include "log.h"
+
+#include "sdb.h"
+#include "parameter.h"
+#include "sdbd_plugin.h"
+#include "sdktools.h"
+
+#define LOG_DIRECTORY   "/tmp"
+
+int get_plugin_capability ( parameters* in, parameters* out )
+{
+    int capability;
+
+    if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
+            || in->array_of_parameter[0].type != type_int32 ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    if ( out == NULL ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    out->number_of_parameter = 1;
+    out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+
+    capability = in->array_of_parameter[0].v_int32;
+
+    if ( capability == CAPABILITY_SECURE ) {
+        make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_DISABLED );
+    } else if ( capability == CAPABILITY_INTER_SHELL ) {
+        make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
+    } else if ( capability == CAPABILITY_FILESYNC ) {
+        make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_PUSHPULL );
+    } else if ( capability == CAPABILITY_USB_PROTOCOL ) {
+        if ( is_emulator() ) {
+            make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_DISABLED );
+        } else {
+            make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
+        }
+    } else if ( capability == CAPABILITY_SOCK_PROTOCOL ) {
+        make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
+    } else if ( capability == CAPABILITY_ROOT_ONOFF ) {
+        if ( access ( "/bin/su", F_OK ) == 0 ) {
+            make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
+        } else {
+            make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_DISABLED );
+        }
+    } else if ( capability == CAPABILITY_CAN_LAUNCH ) {
+        make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_UNKNOWN );
+    } else if ( capability == CAPABILITY_PLUGIN_VER ) {
+        make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_UNKNOWN );
+    } else if ( capability == CAPABILITY_PRODUCT_VER ) {
+        make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_UNKNOWN );
+    } else if ( capability == CAPABILITY_LOG_ENABLE ) {
+        make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_DISABLED );
+    } else if ( capability == CAPABILITY_LOG_PATH ) {
+        make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", LOG_DIRECTORY );
+    } else {
+        out->number_of_parameter = 0;
+        free ( out->array_of_parameter );
+        out->array_of_parameter = NULL;
+        return PLUGIN_CMD_NOT_SUPPORT;
+    }
+
+    return PLUGIN_CMD_SUCCESS;
+}
+
+int verify_shell_cmd ( parameters* in, parameters* out )
+{
+    if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
+            || in->array_of_parameter[0].type != type_string ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    if ( out == NULL ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
+
+    out->number_of_parameter = 1;
+    out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    out->array_of_parameter[0].type = type_int32;
+    out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
+
+    return PLUGIN_CMD_SUCCESS;
+}
+
+int convert_shell_cmd ( parameters* in, parameters* out )
+{
+    if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
+            || in->array_of_parameter[0].type != type_string ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    if ( out == NULL ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
+
+    out->number_of_parameter = 1;
+    out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+
+    make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", in->array_of_parameter[0].v_string.data );
+    return PLUGIN_CMD_SUCCESS;
+}
+
+int verify_peer_ip ( parameters* in, parameters* out )
+{
+    if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
+            || in->array_of_parameter[0].type != type_string ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    if ( out == NULL ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
+
+    out->number_of_parameter = 1;
+    out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    out->array_of_parameter[0].type = type_int32;
+    out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
+
+    return PLUGIN_CMD_SUCCESS;
+}
+
+int verify_sdbd_launch ( parameters* in, parameters* out )
+{
+    if ( out == NULL ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    out->number_of_parameter = 1;
+    out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    out->array_of_parameter[0].type = type_int32;
+    out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
+
+    return PLUGIN_CMD_SUCCESS;
+}
+
+int verify_root_cmd ( parameters* in, parameters* out )
+{
+    if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
+            || in->array_of_parameter[0].type != type_string ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    if ( out == NULL ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
+
+    out->number_of_parameter = 1;
+    out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    out->array_of_parameter[0].type = type_int32;
+
+    if ( verify_root_commands ( in->array_of_parameter[0].v_string.data ) ) {
+        out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
+    } else {
+        out->array_of_parameter[0].v_int32 = PLUGIN_RET_INVALID;
+    }
+
+    return PLUGIN_CMD_SUCCESS;
+}
diff --git a/src/default_plugin_event.c b/src/default_plugin_event.c
new file mode 100644 (file)
index 0000000..a336f94
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vconf.h>
+#include <glib.h>
+
+#define TRACE_TAG TRACE_SDB
+#include "log.h"
+
+#include "sysdeps.h"
+#include "sdbd_plugin.h"
+#include "default_plugin.h"
+
+int get_lock_state ( parameters* in, parameters* out )
+{
+    if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
+            || in->array_of_parameter[0].type != type_int32 ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    if ( out == NULL ) {
+        D ( "Invalid argument\n" );
+        return PLUGIN_CMD_FAIL;
+    }
+
+    D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
+
+    out->number_of_parameter = 1;
+    out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    out->array_of_parameter[0].type = type_int32;
+    out->array_of_parameter[0].v_int32 = ( plugin_pwlocked() == 1 ) ? PLUGIN_RET_ON : PLUGIN_RET_OFF;
+
+    return PLUGIN_CMD_SUCCESS;
+}
+
+int plugin_pwlocked ( void )
+{
+    int pwlock_status = 0;
+    int pwlock_type = 0;
+
+    if ( vconf_get_int ( VCONFKEY_IDLE_LOCK_STATE, &pwlock_status ) ) {
+        pwlock_status = 0;
+        PLUGIN_LOG ( "failed to get pw lock status\n" );
+    }
+#ifdef _WEARABLE
+    PLUGIN_LOG ( "wearable lock applied\n" );
+    // for wearable which uses different VCONF key (lock type)
+    if ( vconf_get_int ( VCONFKEY_SETAPPL_PRIVACY_LOCK_TYPE_INT, &pwlock_type ) ) {
+        pwlock_type = 0;
+        PLUGIN_LOG ( "failed to get pw lock type\n" );
+    }
+    if ( ( pwlock_status == VCONFKEY_IDLE_LOCK ) && ( pwlock_type != SETTING_PRIVACY_LOCK_TYPE_NONE ) ) {
+        PLUGIN_LOG ( "device has been locked\n" );
+        return 1; // locked!
+    }
+#else
+    PLUGIN_LOG ( "mobile lock applied\n" );
+    // for mobile
+    if ( vconf_get_int ( VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &pwlock_type ) ) {
+        pwlock_type = 0;
+        PLUGIN_LOG ( "failed to get pw lock type\n" );
+    }
+    if ( pwlock_status == VCONFKEY_IDLE_LOCK && ( ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_NONE ) && ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_SWIPE ) ) ) {
+        PLUGIN_LOG ( "device has been locked\n" );
+        return 1; // locked!
+    }
+#endif
+    return 0; // unlocked!
+}
+
+static void pwlock_cb ( keynode_t *key, void* data )
+{
+    PLUGIN_LOG ( "pwlock callback is issued\n" );
+    int pwlocked = plugin_pwlocked();
+
+    parameters* out = ( parameters* ) malloc ( sizeof ( parameters ) );
+    out->number_of_parameter = 1;
+    out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    out->array_of_parameter[0].type = type_int32;
+    out->array_of_parameter[0].v_int32 = ( pwlocked == 1 ) ? PLUGIN_RET_ON : PLUGIN_RET_OFF;
+
+    event_handler ( PLUGIN_EVENT_PWLOCK, out );
+}
+
+static void register_pwlock_cb()
+{
+    int ret = vconf_notify_key_changed ( VCONFKEY_IDLE_LOCK_STATE, pwlock_cb, NULL );
+    if ( ret != 0 ) {
+        PLUGIN_LOG ( "cannot register vconf callback.\n" );
+        return;
+    }
+    PLUGIN_LOG ( "registered vconf callback\n" );
+}
+
+static void unregister_pwlock_cb()
+{
+    int ret = vconf_ignore_key_changed ( VCONFKEY_IDLE_LOCK_STATE, pwlock_cb );
+    if ( ret != 0 ) {
+        PLUGIN_LOG ( "cannot unregister vconf callback.\n" );
+        return;
+    }
+    PLUGIN_LOG ( "unregistered vconf callback\n" );
+}
+
+static void *pwlock_thread ( void *x )
+{
+    GMainLoop *loop;
+    loop = g_main_loop_new ( NULL, FALSE );
+    register_pwlock_cb();
+    g_main_loop_run ( loop );
+    g_main_loop_unref ( loop );
+    unregister_pwlock_cb();
+    return NULL;
+}
+
+void create_pwlock_thread()
+{
+    sdb_thread_t t;
+    if ( sdb_thread_create ( &t, pwlock_thread, NULL ) ) {
+        PLUGIN_LOG ( "cannot create_pwlock_thread.\n" );
+        return;
+    }
+    PLUGIN_LOG ( "created pwlock_thread\n" );
+}
diff --git a/src/default_plugin_main.c b/src/default_plugin_main.c
new file mode 100644 (file)
index 0000000..4bcecb0
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "parameter.h"
+#include "sdbd_plugin.h"
+#include "default_plugin.h"
+#include "plugin.h"
+
+#define MAX_OUT_BUF_SIZE 128
+
+eventfunc event_handler = NULL;
+
+int default_plugin_init ( eventfunc event_cb, registerfunc register_func )
+{
+    // default plugin do not need to register command
+    // because unsupported command by plugin should be called with default plugin anyway
+    event_handler = event_cb;
+    
+    if (is_supported_by_plugin(PLUGIN_EVENT_PWLOCK) == 0) {
+        create_pwlock_thread();
+    } 
+    
+    return PLUGIN_CMD_SUCCESS;
+}
+
+int default_plugin_sync_proc ( int cmd, parameters* in, parameters* out )
+{
+    int ret = PLUGIN_CMD_NOT_SUPPORT;
+
+    if ( cmd == PLUGIN_SYNC_CMD_CAPABILITY ) {
+        ret = get_plugin_capability ( in, out );
+    } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_SHELLCMD ) {
+        ret = verify_shell_cmd ( in, out );
+    } else if ( cmd == PLUGIN_SYNC_CMD_CONVERT_SHELLCMD ) {
+        ret = convert_shell_cmd ( in, out );
+    } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_PEERIP ) {
+        ret = verify_peer_ip ( in, out );
+    } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_LAUNCH ) {
+        ret = verify_sdbd_launch ( in, out );
+    } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_ROOTCMD ) {
+        ret = verify_root_cmd ( in, out );
+    } else if ( cmd == PLUGIN_SYNC_CMD_AUTH_SUPPORT ) {
+        ret = auth_support ( in, out );
+    } else if ( cmd == PLUGIN_SYNC_CMD_AUTH_GET_KEY_FILEPATHS ) {
+        ret = auth_get_key_file_paths ( in, out );
+    } else if ( cmd == PLUGIN_SYNC_CMD_GET_LOCK_STATE ) {
+        ret = get_lock_state ( in, out );
+    } else {
+        ret = PLUGIN_CMD_NOT_SUPPORT;
+    }
+
+    return ret;
+}
+
+int default_plugin_async_proc ( int cmd, parameters* in, int out_fd )
+{
+    int ret = PLUGIN_CMD_NOT_SUPPORT;
+
+    if ( cmd == PLUGIN_ASYNC_CMD_AUTH_CONFIRM_PUBLIC ) {
+        ret = confirm_public_key ( in, out_fd );
+    } else {
+        ret = PLUGIN_CMD_NOT_SUPPORT;
+    }
+
+    return ret;
+}
+
index bd0bf98..ffaf0bc 100644 (file)
@@ -31,6 +31,8 @@
 #include <tzplatform_config.h>
 
 #define TRACE_TAG  TRACE_SYNC
+#include "log.h"
+
 #include "sdb.h"
 #include "file_sync_service.h"
 #include "sdktools.h"
@@ -470,14 +472,14 @@ static int handle_send_link(int s, int noti_fd, char *path, char *buffer)
 
 static int is_support_push()
 {
-    return (!strncmp(g_capabilities.filesync_support, SDBD_CAP_RET_PUSHPULL, strlen(SDBD_CAP_RET_PUSHPULL))
-            || !strncmp(g_capabilities.filesync_support, SDBD_CAP_RET_PUSH, strlen(SDBD_CAP_RET_PUSH)));
+    return (!strncmp(g_capabilities.filesync_support, PLUGIN_RET_PUSHPULL, strlen(PLUGIN_RET_PUSHPULL))
+            || !strncmp(g_capabilities.filesync_support, PLUGIN_RET_PUSH, strlen(PLUGIN_RET_PUSH)));
 }
 
 static int is_support_pull()
 {
-    return (!strncmp(g_capabilities.filesync_support, SDBD_CAP_RET_PUSHPULL, strlen(SDBD_CAP_RET_PUSHPULL))
-            || !strncmp(g_capabilities.filesync_support, SDBD_CAP_RET_PULL, strlen(SDBD_CAP_RET_PULL)));
+    return (!strncmp(g_capabilities.filesync_support, PLUGIN_RET_PUSHPULL, strlen(PLUGIN_RET_PUSHPULL))
+            || !strncmp(g_capabilities.filesync_support, PLUGIN_RET_PULL, strlen(PLUGIN_RET_PULL)));
 }
 
 static int do_send(int s, int noti_fd, char *path, char *buffer)
diff --git a/src/hashtable.c b/src/hashtable.c
new file mode 100644 (file)
index 0000000..fee79fd
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+
+#include "hashtable.h"
+
+static int get_hash_value ( hashtable* ht_table, int key )
+{
+    return key % ht_table->size;
+}
+
+hashtable* hashtable_create ( ht_size_t tablesize )
+{
+    hashtable* htable = NULL;
+    int size = 0;
+    int i;
+
+    switch ( tablesize ) {
+    case ht_size_7:
+        size = 7;
+        break;
+    case ht_size_13:
+        size = 13;
+        break;
+    case ht_size_31:
+        size = 31;
+        break;
+    case ht_size_127:
+        size = 127;
+        break;
+    case ht_size_1021:
+        size = 1021;
+        break;
+    case ht_size_8191:
+        size = 8191;
+        break;
+    default:
+        size = 31;
+        break;
+    }
+
+    // allocate hash table
+    htable = ( hashtable* ) malloc ( sizeof ( hashtable ) );
+    if ( htable == NULL ) {
+        return NULL;
+    }
+
+    // allocate hash table entries
+    htable->table = ( ht_entry** ) malloc ( sizeof ( ht_entry* ) * size );
+    if ( htable->table == NULL ) {
+        free ( htable );
+        return NULL;
+    }
+
+    // initialize hash table entries
+    for ( i = 0; i < size; i++ ) {
+        htable->table[i] = NULL;
+    }
+
+    htable->size = size;
+
+    return htable;
+}
+
+void hashtable_destroy ( hashtable* ht_table )
+{
+    if ( ht_table != NULL ) {
+        if ( ht_table->table != NULL ) {
+            int i;
+            for ( i = 0; i < ht_table->size; i++ ) {
+                ht_entry* entry = ht_table->table[i];
+                while ( entry != NULL ) {
+                    ht_entry* tmp = entry;
+                    entry = entry->next;
+                    free ( tmp );
+                }
+            }
+
+            free ( ht_table->table );
+        }
+
+        free ( ht_table );
+    }
+}
+
+// return 1 if put is successful
+// return 0 if put is failed
+int hashtable_put ( hashtable* ht_table, int key, int value )
+{
+    int hash;
+    ht_entry* entry = NULL;
+
+    hash = get_hash_value ( ht_table, key );
+    entry = ht_table->table[hash];
+
+    while ( entry != NULL ) {
+        if ( entry->key != key ) {
+            entry = entry->next;
+        } else {
+            break;
+        }
+    }
+
+    if ( entry != NULL ) {
+        // there is a entry which has same key
+        entry->value = value;
+    } else {
+        // there is no entry which has same key
+
+        // make new entry
+        ht_entry* new_entry = ( ht_entry* ) malloc ( sizeof ( ht_entry ) );
+        if ( new_entry == NULL ) {
+            return 0;
+        }
+        new_entry->key = key;
+        new_entry->value = value;
+
+        // add to entry list at first position
+        new_entry->next = ht_table->table[hash];
+        ht_table->table[hash] = new_entry;
+    }
+
+    return 1;
+}
+
+// return 1 if a entry is found in hash table
+// return 0 if a entry is not found in hash table
+// output value is stored in (*value)
+int hashtable_get ( hashtable* ht_table, int key, int* value )
+{
+    int hash;
+    ht_entry* entry = NULL;
+
+    hash = get_hash_value ( ht_table, key );
+    entry = ht_table->table[hash];
+
+    while ( entry != NULL ) {
+        if ( entry->key != key ) {
+            entry = entry->next;
+        } else {
+            break;
+        }
+    }
+
+    if ( entry != NULL ) {
+        // there is a entry which has same key
+        *value = entry->value;
+        return 1;
+    } else {
+        // there is no entry which has same key
+        return 0;
+    }
+}
+
diff --git a/src/hashtable.h b/src/hashtable.h
new file mode 100644 (file)
index 0000000..25cded0
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __HASHTABLE_H
+#define __HASHTABLE_H
+
+typedef enum _hashtable_size {
+    ht_size_7,
+    ht_size_13,
+    ht_size_31,
+    ht_size_127,
+    ht_size_1021,
+    ht_size_8191
+} ht_size_t;
+
+typedef struct _ht_entry {
+    int key;
+    int value;
+    struct _ht_entry* next;
+} ht_entry;
+
+typedef struct _hashtable {
+    int size;
+    ht_entry** table;
+} hashtable;
+
+hashtable* hashtable_create ( ht_size_t tablesize );
+void hashtable_destroy ( hashtable* ht_table );
+
+// return 1 if put is successful
+// return 0 if put is failed
+int hashtable_put ( hashtable* ht_table, int key, int value );
+
+// return 1 if a entry is found in hash table
+// return 0 if a entry is not found in hash table
+// output value is stored in (*value)
+int hashtable_get ( hashtable* ht_table, int key, int* value );
+
+#endif // __HASHTABLE_H
diff --git a/src/log.h b/src/log.h
new file mode 100644 (file)
index 0000000..f910f90
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LOG_H
+#define __LOG_H
+
+#include <errno.h>
+
+#include "sysdeps.h"
+
+/* define SDB_TRACE to 1 to enable tracing support, or 0 to disable it */
+
+#define  SDB_TRACE    1
+
+/* IMPORTANT: if you change the following list, don't
+ * forget to update the corresponding 'tags' table in
+ * the sdb_trace_init() function implemented in sdb.c
+ */
+typedef enum {
+    TRACE_SDB = 0,
+    TRACE_SOCKETS,
+    TRACE_PACKETS,
+    TRACE_TRANSPORT,
+    TRACE_RWX,
+    TRACE_USB,
+    TRACE_SYNC,
+    TRACE_SYSDEPS,
+    TRACE_JDWP,
+    TRACE_SERVICES,
+    TRACE_PROPERTIES,
+    TRACE_SDKTOOLS
+} SdbTrace;
+
+#if SDB_TRACE
+
+#if !SDB_HOST
+/*
+ * When running inside the emulator, guest's sdbd can connect to 'sdb-debug'
+ * qemud service that can display sdb trace messages (on condition that emulator
+ * has been started with '-debug sdb' option).
+ */
+
+/* Delivers a trace message to the emulator via QEMU pipe. */
+void sdb_qemu_trace(const char* fmt, ...);
+
+/* Macro to use to send SDB trace messages to the emulator. */
+#define DQ(...)    sdb_qemu_trace(__VA_ARGS__)
+#else
+#define DQ(...) ((void)0)
+#endif  /* !SDB_HOST */
+
+  extern int     sdb_trace_mask;
+  extern unsigned char    sdb_trace_output_count;
+  void    sdb_trace_init(void);
+
+#  define SDB_TRACING  ((sdb_trace_mask & (1 << TRACE_TAG)) != 0)
+
+  /* you must define TRACE_TAG before using this macro */
+#  define  D(...)                                      \
+        do {                                           \
+            if (SDB_TRACING) {                         \
+                int save_errno = errno;                \
+                sdb_mutex_lock(&D_lock);               \
+                fprintf(stderr, "%s::%s():",           \
+                        __FILE__, __FUNCTION__);       \
+                errno = save_errno;                    \
+                fprintf(stderr, __VA_ARGS__ );         \
+                fflush(stderr);                        \
+                sdb_mutex_unlock(&D_lock);             \
+                errno = save_errno;                    \
+           }                                           \
+        } while (0)
+#  define  DR(...)                                     \
+        do {                                           \
+            if (SDB_TRACING) {                         \
+                int save_errno = errno;                \
+                sdb_mutex_lock(&D_lock);               \
+                errno = save_errno;                    \
+                fprintf(stderr, __VA_ARGS__ );         \
+                fflush(stderr);                        \
+                sdb_mutex_unlock(&D_lock);             \
+                errno = save_errno;                    \
+           }                                           \
+        } while (0)
+#else
+#  define  D(...)          ((void)0)
+#  define  DR(...)         ((void)0)
+#  define  SDB_TRACING     0
+#endif
+
+#endif // __LOG_H
diff --git a/src/parameter.h b/src/parameter.h
new file mode 100644 (file)
index 0000000..c526bb7
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SRC_PARAMETER_H_
+#define SRC_PARAMETER_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdint.h>
+
+typedef enum _datatype {
+    type_int8,
+    type_int16,
+    type_int32,
+    type_uint8,
+    type_uint16,
+    type_uint32,
+    type_voidp,
+    type_string,
+    type_chunk
+} datatype;
+
+typedef struct _sstring {
+    size_t length;
+    char* data;
+} sstring;
+
+typedef struct _chunk {
+    size_t size;            // byte size of data
+    unsigned char* data;    // byte array of data
+} chunk;
+
+typedef struct _parameter {
+    datatype type;
+    union {
+        int8_t      v_int8;
+        int16_t     v_int16;
+        int32_t     v_int32;
+        uint8_t     v_uint8;
+        uint16_t    v_uint16;
+        uint32_t    v_uint32;
+        void*       v_pointer;
+        sstring     v_string;
+        chunk       v_chunk;
+    };
+} parameter;
+
+typedef struct _parameters {
+    size_t number_of_parameter;
+    parameter* array_of_parameter;
+} parameters;
+
+#define MAX_OUT_BUF_SIZE 128
+
+static __inline__ void make_string_parameter ( parameter* pstring, const char* format, ... )
+{
+    va_list args;
+    char buf[MAX_OUT_BUF_SIZE];
+
+    va_start ( args, format );
+    vsnprintf ( buf, MAX_OUT_BUF_SIZE, format, args );
+    va_end ( args );
+
+    pstring->type = type_string;
+    pstring->v_string.length = strlen ( buf );
+    pstring->v_string.data = ( char* ) malloc ( pstring->v_string.length + 1 );
+    strcpy ( pstring->v_string.data, buf );
+}
+
+static __inline__ void release_parameters ( parameters* param )
+{
+    if ( param != NULL ) {
+        int i;
+        for ( i = 0; i < param->number_of_parameter; i++ ) {
+            if ( param->array_of_parameter[i].type == type_string
+                    && param->array_of_parameter[i].v_string.data != NULL ) {
+                free ( param->array_of_parameter[i].v_string.data );
+            } else if ( param->array_of_parameter[i].type == type_chunk
+                        && param->array_of_parameter[i].v_chunk.data != NULL ) {
+                free ( param->array_of_parameter[i].v_chunk.data );
+            } else if ( param->array_of_parameter[i].type == type_voidp
+                        && param->array_of_parameter[i].v_pointer != NULL ) {
+                free ( param->array_of_parameter[i].v_pointer );
+            }
+        }
+        if ( param->array_of_parameter != NULL ) {
+            free ( param->array_of_parameter );
+        }
+    }
+}
+
+#endif /* SRC_PARAMETER_H_ */
diff --git a/src/plugin.c b/src/plugin.c
new file mode 100644 (file)
index 0000000..7ef796f
--- /dev/null
@@ -0,0 +1,295 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <dlfcn.h>
+
+#define TRACE_TAG TRACE_SDB
+#include "log.h"
+
+#include "sdb.h"
+
+#include "hashtable.h"
+#include "parameter.h"
+#include "plugin.h"
+#include "sdbd_plugin.h"
+
+static void* plugin_handle = NULL;
+
+PLUGIN_INIT plugin_init_proc = NULL;
+PLUGIN_SYNCHRONOUS_CMD_PROC plugin_sync_proc = NULL;
+PLUGIN_ASYNCHRONOUS_CMD_PROC plugin_async_proc = NULL;
+
+hashtable* plugin_cmd_hashtable = NULL;
+
+// handler of event to be detected by plugin
+int plugin_event_handler ( int event_type, parameters* data )
+{
+    // TODO : implement event handler
+    if ( event_type == PLUGIN_EVENT_PWLOCK || event_type == PLUGIN_EVENT_FMMLOCK ) {
+        if ( data != NULL && data->number_of_parameter == 1 && data->array_of_parameter != NULL
+                && data->array_of_parameter[0].type == type_int32 ) {
+
+            if ( data->array_of_parameter[0].v_int32 == PLUGIN_RET_ON ) {
+                // locked
+                is_pwlocked = 1;
+            } else {
+                // unlocked
+                is_pwlocked = 0;
+            }
+
+            send_device_status();
+
+            if ( data != NULL ) {
+                release_parameters ( data );
+                free ( data );
+            }
+        }
+    }
+
+    return 0;
+}
+
+// register commands that are supported by plugin
+static int plugin_register_command ( int command, priority cmd_priority )
+{
+    if ( plugin_cmd_hashtable ) {
+        hashtable_put ( plugin_cmd_hashtable, command, cmd_priority );
+    }
+    return 0;
+}
+
+// return 0 if fail to load sdbd plugin (use default plugin)
+// return 1 if succeed to load sdbd plugin and get function pointer of plugin_init
+static int load_plugin_not_default()
+{
+    plugin_init_proc = NULL;
+    plugin_sync_proc = NULL;
+    plugin_async_proc = NULL;
+
+    plugin_handle = dlopen ( PLUGIN_PATH, RTLD_NOW );
+    if ( plugin_handle == NULL ) {
+        D ( "failed to dlopen(%s). error: %s\n", PLUGIN_PATH, dlerror() );
+        return 0;
+    }
+
+    plugin_init_proc = dlsym ( plugin_handle, PLUGIN_PROC_NAME_INIT );
+    if ( plugin_init_proc == NULL ) {
+        D ( "failed to get the sdbd plugin init function. error: %s\n", dlerror() );
+        dlclose ( plugin_handle );
+        plugin_handle = NULL;
+        return 0;
+    }
+
+    // if there is no implementation of plugin_sync_proc and plugin_async_proc,
+    // then use default_plugin_sync_proc and default_plugin_async_proc
+    plugin_sync_proc = dlsym ( plugin_handle, PLUGIN_PROC_NAME_SYNC_CMD );
+    if ( plugin_sync_proc == NULL ) {
+        plugin_sync_proc = default_plugin_sync_proc;
+    }
+
+    plugin_async_proc = dlsym ( plugin_handle, PLUGIN_PROC_NAME_ASYNC_CMD );
+    if ( plugin_async_proc == NULL ) {
+        plugin_async_proc = default_plugin_async_proc;
+    }
+
+    return 1;
+}
+
+void load_sdbd_plugin()
+{
+    int ret;
+
+    plugin_cmd_hashtable = hashtable_create ( ht_size_31 );
+
+    ret = load_plugin_not_default();
+    if ( ret == 0 ) {
+        // use default plugin
+        plugin_init_proc = default_plugin_init;
+        plugin_sync_proc = default_plugin_sync_proc;
+        plugin_async_proc = default_plugin_async_proc;
+
+        D ( "using default plugin interface.\n" );
+    } else {
+        D ( "using sdbd plugin interface.(%s)\n", PLUGIN_PATH );
+
+        plugin_init_proc ( plugin_event_handler, plugin_register_command );
+    }
+
+    // use default plugin feature for the commands or events that are not supported by plugin
+    default_plugin_init ( plugin_event_handler, plugin_register_command );
+}
+
+void unload_sdbd_plugin()
+{
+    if ( plugin_cmd_hashtable ) {
+        hashtable_destroy ( plugin_cmd_hashtable );
+        plugin_cmd_hashtable = NULL;
+    }
+
+    if ( plugin_handle ) {
+        dlclose ( plugin_handle );
+        plugin_handle = NULL;
+    }
+}
+
+// return 1 if plugin support given command
+// return 0 if plugin does not support given command
+int is_supported_by_plugin ( int cmd )
+{
+    int ret = 0;
+
+    if ( plugin_cmd_hashtable ) {
+        int value;
+        ret = hashtable_get ( plugin_cmd_hashtable, cmd, &value );
+    }
+
+    return ret;
+}
+
+static int request_sync_cmd ( int cmd, parameters* in, parameters* out )
+{
+    int ret, pr;
+
+    out->number_of_parameter = 0;
+    out->array_of_parameter = NULL;
+
+    ret = hashtable_get ( plugin_cmd_hashtable, cmd, &pr );
+    if ( ret == 1 ) {
+        // supported by plugin
+        ret = plugin_sync_proc ( cmd, in, out );
+        if ( ret == PLUGIN_CMD_NOT_SUPPORT ) {
+            // not supported by plugin
+            ret = default_plugin_sync_proc ( cmd, in, out );
+        }
+    } else {
+        // not supported by plugin
+        ret = default_plugin_sync_proc ( cmd, in, out );
+    }
+
+    return ret;
+}
+
+
+// return 1 if succeed to get capability from plugin
+// return 0 otherwise
+int request_capability_to_plugin ( int cap, char* out_buf, unsigned int out_len )
+{
+    int success = 0;
+    int ret;
+    parameters in, out;
+
+    in.number_of_parameter = 1;
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    in.array_of_parameter[0].type = type_int32;
+    in.array_of_parameter[0].v_int32 = cap;
+
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_CAPABILITY, &in, &out );
+    if ( ret == PLUGIN_CMD_SUCCESS ) {
+        strncpy ( out_buf, out.array_of_parameter[0].v_string.data, out_len - 1 );
+        out_buf[out_len - 1] = '\0';
+        success = 1;
+        release_parameters ( &out );
+    }
+
+    release_parameters ( &in );
+    return success;
+}
+
+// return 1 if allowed by plugin (valid)
+// return 0 if disallowed by plugin (invalid)
+int request_validity_to_plugin ( int cmd, const char* in_buf )
+{
+    int success = 0;
+    int ret;
+    parameters in, out;
+
+    if ( in_buf != NULL ) {
+        in.number_of_parameter = 1;
+        in.array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+        in.array_of_parameter[0].type = type_string;
+        in.array_of_parameter[0].v_string.length = strlen ( in_buf );
+        in.array_of_parameter[0].v_string.data = strdup ( in_buf );
+    } else {
+        in.number_of_parameter = 0;
+        in.array_of_parameter = NULL;
+    }
+
+    ret = request_sync_cmd ( cmd, &in, &out );
+    if ( ret == PLUGIN_CMD_SUCCESS ) {
+        success = ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_VALID ) ? 1 : 0;
+        release_parameters ( &out );
+    }
+
+    release_parameters ( &in );
+    return success;
+}
+
+// return 1 if succeed to convert
+// return 0 otherwise
+int request_conversion_to_plugin ( int cmd, const char* in_buf, char* out_buf, unsigned int out_len )
+{
+    int success = 0;
+    int ret;
+    parameters in, out;
+
+    in.number_of_parameter = 1;
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    in.array_of_parameter[0].type = type_string;
+    in.array_of_parameter[0].v_string.length = strlen ( in_buf );
+    in.array_of_parameter[0].v_string.data = strdup ( in_buf );
+
+    ret = request_sync_cmd ( cmd, &in, &out );
+    if ( ret == PLUGIN_CMD_SUCCESS ) {
+        strncpy ( out_buf, out.array_of_parameter[0].v_string.data, out_len - 1 );
+        out_buf[out_len - 1] = '\0';
+        success = 1;
+        release_parameters ( &out );
+    }
+
+    release_parameters ( &in );
+    return success;
+}
+
+// return 1 if locked
+// return 0 if unlocked
+// return -1 if request failed
+int request_lock_state_to_plugin ( int lock_type )
+{
+    int result = -1;
+    int ret;
+    parameters in, out;
+
+    in.number_of_parameter = 1;
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+    in.array_of_parameter[0].type = type_int32;
+    in.array_of_parameter[0].v_int32 = lock_type;
+
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_GET_LOCK_STATE, &in, &out );
+    if ( ret == PLUGIN_CMD_SUCCESS ) {
+        if ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_ON ) {
+            result = 1;
+        } else {
+            result = 0;
+        }
+        is_pwlocked = result;
+        release_parameters ( &out );
+    }
+
+    release_parameters ( &in );
+
+    return result;
+}
diff --git a/src/plugin.h b/src/plugin.h
new file mode 100644 (file)
index 0000000..a553e95
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PLUGIN_H
+#define __PLUGIN_H
+
+#include "sdbd_plugin.h"
+
+#define PLUGIN_PATH    "/usr/lib/libsdbd_plugin.so"
+
+int default_plugin_init ( eventfunc event_cb, registerfunc register_func );
+int default_plugin_sync_proc ( int cmd, parameters* in, parameters* out );
+int default_plugin_async_proc ( int cmd, parameters* in, int out_fd );
+
+void load_sdbd_plugin();
+void unload_sdbd_plugin();
+
+// return 1 if plugin support given command
+// return 0 if plugin does not support given command
+int is_supported_by_plugin ( int cmd );
+
+// return 1 if succeed to get capability from plugin
+// return 0 otherwise
+int request_capability_to_plugin ( int cap, char* out_buf, unsigned int out_len );
+
+// return 1 if allowed by plugin (valid)
+// return 0 if disallowed by plugin (invalid)
+int request_validity_to_plugin ( int cmd, const char* in_buf );
+
+// return 1 if succeed to convert
+// return 0 otherwise
+int request_conversion_to_plugin ( int cmd, const char* in_buf, char* out_buf, unsigned int out_len );
+
+// return 1 if locked
+// return 0 if unlocked
+// return -1 if request failed
+int request_lock_state_to_plugin ( int lock_type );
+
+#endif //__PLUGIN_H
index 1127655..aa14fe7 100644 (file)
@@ -27,6 +27,8 @@
 //#include "loghack.h"
 #include "sysdeps.h"
 #define  TRACE_TAG   TRACE_PROPERTIES
+#include "log.h"
+
 #include "sdb.h"
 
 #define HAVE_TIZEN_PROPERTY
index 0cb5f93..715476d 100644 (file)
@@ -23,6 +23,7 @@
 #include <pthread.h>  /* for pthread_once() */
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <errno.h>
 
 #ifndef D
index 0d8cf47..727a7aa 100644 (file)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -33,6 +33,7 @@
 #include <dlfcn.h>
 
 #include "sysdeps.h"
+#include "log.h"
 #include "sdb.h"
 #include "strutils.h"
 #if !SDB_HOST
@@ -40,6 +41,8 @@
 #endif
 #include "utils.h"
 #include "sdktools.h"
+#include "plugin.h"
+#include "sdbd_plugin.h"
 
 #if !SDB_HOST
 #include <linux/prctl.h>
@@ -48,7 +51,6 @@
 #include <system_info.h>
 #include <vconf.h>
 #include <glib.h>
-#include "utils.h"
 
 #define PROC_CMDLINE_PATH "/proc/cmdline"
 #define USB_SERIAL_PATH "/sys/class/usb_mode/usb0/iSerial"
@@ -88,6 +90,7 @@ struct group_info g_default_groups[] = {
 #define SDB_DEFAULT_GROUPS_CNT  ((sizeof(g_default_groups)/sizeof(g_default_groups[0]))-1)
 
 int is_init_sdk_userinfo = 0;
+int is_pwlocked = 0;    // 0 if unlocked, 1 otherwise
 
 #if !SDB_HOST
 SdbdCommandlineArgs sdbd_commandline_args;
@@ -134,9 +137,6 @@ int is_container_enabled(void) {
     }
 }
 
-void* g_sdbd_plugin_handle = NULL;
-SDBD_PLUGIN_CMD_PROC_PTR sdbd_plugin_cmd_proc = NULL;
-
 void handle_sig_term(int sig) {
 #ifdef SDB_PIDPATH
     if (access(SDB_PIDPATH, F_OK) == 0)
@@ -170,7 +170,7 @@ void fatal_errno(const char *fmt, ...)
 
 static int is_enable_sdbd_log()
 {
-    return (!strncmp(g_capabilities.log_enable, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED)));
+    return (!strncmp(g_capabilities.log_enable, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
 }
 
 int   sdb_trace_mask;
@@ -398,7 +398,7 @@ static void send_connect(atransport *t)
     char device_name[256]={0,};
     int r = 0;
     int status = 0;
-    if (is_pwlocked()) {
+    if (request_lock_state_to_plugin(LOCKTYPE_PASSWORD) == 1) {
         status = 1;
         t->connection_state = CS_PWLOCK;
     }
@@ -425,12 +425,12 @@ static void send_connect(atransport *t)
 #endif
 }
 
-static void send_device_status()
+void send_device_status()
 {
     D("broadcast device status\n");
     apacket* cp = get_apacket();
     cp->msg.command = A_STAT;
-    cp->msg.arg0 = is_pwlocked();
+    cp->msg.arg0 = is_pwlocked;
     cp->msg.arg1 = 0;
 
     broadcast_transport(cp);
@@ -683,7 +683,8 @@ void handle_packet(apacket *p, atransport *t)
         break;
 
     case A_OPEN: /* OPEN(local-id, 0, "destination") */
-        if (is_pwlocked() && t->connection_state == CS_PWLOCK) { // in case of already locked before get A_CNXN
+        if (request_lock_state_to_plugin(LOCKTYPE_PASSWORD) == 1 && t->connection_state == CS_PWLOCK) {
+            // in case of already locked before get A_CNXN
             D("open failed due to password locked before get A_CNXN:%d\n", t->connection_state);
             send_close(0, p->msg.arg0, t);
         } else {
@@ -967,10 +968,8 @@ static void sdb_cleanup(void)
 //    if(required_pid > 0) {
 //        kill(required_pid, SIGKILL);
 //    }
-    if (g_sdbd_plugin_handle) {
-        dlclose(g_sdbd_plugin_handle);
-        g_sdbd_plugin_handle = NULL;
-    }
+
+    unload_sdbd_plugin();
 }
 
 void start_logging(void)
@@ -1272,40 +1271,6 @@ static void init_drop_privileges() {
 #endif
 }
 
-int is_pwlocked(void) {
-    int pwlock_status = 0;
-    int pwlock_type = 0;
-
-    if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &pwlock_status)) {
-        pwlock_status = 0;
-        D("failed to get pw lock status\n");
-    }
-#ifdef _WEARABLE
-    D("wearable lock applied\n");
-    // for wearable which uses different VCONF key (lock type)
-       if (vconf_get_int(VCONFKEY_SETAPPL_PRIVACY_LOCK_TYPE_INT, &pwlock_type)) {
-               pwlock_type = 0;
-               D("failed to get pw lock type\n");
-       }
-         if ((pwlock_status == VCONFKEY_IDLE_LOCK) && (pwlock_type != SETTING_PRIVACY_LOCK_TYPE_NONE)) {
-                  D("device has been locked\n");
-                  return 1; // locked!
-         }
-#else
-       D("mobile lock applied\n");
-    // for mobile
-    if (vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &pwlock_type)) {
-        pwlock_type = 0;
-        D("failed to get pw lock type\n");
-    }
-    if (pwlock_status == VCONFKEY_IDLE_LOCK && ((pwlock_type != SETTING_SCREEN_LOCK_TYPE_NONE) && (pwlock_type != SETTING_SCREEN_LOCK_TYPE_SWIPE))) {
-        D("device has been locked\n");
-        return 1; // locked!
-    }
-#endif
-    return 0; // unlocked!
-}
-
 int should_drop_privileges() {
     if (rootshell_mode == 1) { // if root, then don't drop
         return 0;
@@ -1313,48 +1278,6 @@ int should_drop_privileges() {
     return 1;
 }
 
-static void pwlock_cb(keynode_t *key, void* data) {
-       D("pwlock callback is issued\n");
-    send_device_status();
-}
-
-void register_pwlock_cb() {
-    int ret = vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE, pwlock_cb, NULL);
-    if(ret != 0) {
-        D("cannot register vconf callback.\n");
-        return;
-    }
-    D("registered vconf callback\n");
-}
-
-void unregister_pwlock_cb() {
-    int ret = vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE, pwlock_cb);
-    if(ret != 0) {
-        D("cannot unregister vconf callback.\n");
-        return;
-    }
-    D("unregistered vconf callback\n");
-}
-
-static void *pwlock_thread(void *x) {
-       GMainLoop *loop;
-       loop = g_main_loop_new(NULL, FALSE);
-       register_pwlock_cb();
-       g_main_loop_run(loop);
-       g_main_loop_unref(loop);
-       unregister_pwlock_cb();
-       return 0;
-}
-
-void create_pwlock_thread() {
-    sdb_thread_t t;
-    if(sdb_thread_create( &t, pwlock_thread, NULL)) {
-        D("cannot create_pwlock_thread.\n");
-        return;
-    }
-    D("created pwlock_thread\n");
-}
-
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
@@ -1563,237 +1486,6 @@ int set_sdk_user_privileges() {
     return 0;
 }
 
-/* default plugin proc */
-static int get_plugin_capability(const char* in_buf, sdbd_plugin_param out) {
-    int ret = SDBD_PLUGIN_RET_NOT_SUPPORT;
-
-    if (in_buf == NULL) {
-        D("Invalid argument\n");
-        return SDBD_PLUGIN_RET_FAIL;
-    }
-
-    if (SDBD_CMP_CAP(in_buf, SECURE)) {
-        snprintf(out.data, out.len, "%s", SDBD_CAP_RET_DISABLED);
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, INTER_SHELL)) {
-        snprintf(out.data, out.len, "%s", SDBD_CAP_RET_ENABLED);
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, FILESYNC)) {
-        // - push : SDBD_CAP_RET_PUSH
-        // - pull : SDBD_CAP_RET_PULL
-        // - both : SDBD_CAP_RET_PUSHPULL
-        // - disabled : SDBD_CAP_RET_DISABLED
-        snprintf(out.data, out.len, "%s", SDBD_CAP_RET_PUSHPULL);
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, USBPROTO)) {
-        if (is_emulator()) {
-            snprintf(out.data, out.len, "%s", SDBD_CAP_RET_DISABLED);
-        } else {
-            snprintf(out.data, out.len, "%s", SDBD_CAP_RET_ENABLED);
-        }
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, SOCKPROTO)) {
-        if (is_emulator()) {
-            snprintf(out.data, out.len, "%s", SDBD_CAP_RET_ENABLED);
-        } else {
-            snprintf(out.data, out.len, "%s", SDBD_CAP_RET_ENABLED);
-        }
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, ROOTONOFF)) {
-        if (access("/bin/su", F_OK) == 0) {
-            snprintf(out.data, out.len, "%s", SDBD_CAP_RET_ENABLED);
-        } else {
-            snprintf(out.data, out.len, "%s", SDBD_CAP_RET_DISABLED);
-        }
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, CANLAUNCH)) {
-        snprintf(out.data, out.len, "%s", UNKNOWN);
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, PLUGIN_VER)) {
-        snprintf(out.data, out.len, "%s", UNKNOWN);
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, PRODUCT_VER)) {
-        snprintf(out.data, out.len, "%s", UNKNOWN);
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, LOG_ENABLE)) {
-        snprintf(out.data, out.len, "%s", SDBD_CAP_RET_DISABLED);
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    } else if (SDBD_CMP_CAP(in_buf, LOG_PATH)) {
-        snprintf(out.data, out.len, "%s", "/tmp");
-        ret = SDBD_PLUGIN_RET_SUCCESS;
-    }
-
-    return ret;
-}
-
-static int verify_shell_cmd(const char* in_buf, sdbd_plugin_param out) {
-    int ret = SDBD_PLUGIN_RET_FAIL;
-
-    if (in_buf == NULL) {
-        D("Invalid argument\n");
-        return SDBD_PLUGIN_RET_FAIL;
-    }
-
-    D("shell command : %s\n", in_buf);
-
-    snprintf(out.data, out.len, "%s", SDBD_RET_VALID);
-    ret = SDBD_PLUGIN_RET_SUCCESS;
-
-    return ret;
-}
-
-static int convert_shell_cmd(const char* in_buf, sdbd_plugin_param out) {
-    int ret = SDBD_PLUGIN_RET_FAIL;
-
-    if (in_buf == NULL) {
-        D("Invalid argument\n");
-        return SDBD_PLUGIN_RET_FAIL;
-    }
-
-    snprintf(out.data, out.len, "%s", in_buf);
-    ret = SDBD_PLUGIN_RET_SUCCESS;
-
-    return ret;
-}
-
-static int verify_peer_ip(const char* in_buf, sdbd_plugin_param out) {
-    int ret = SDBD_PLUGIN_RET_FAIL;
-
-    if (in_buf == NULL) {
-        D("Invalid argument\n");
-        return SDBD_PLUGIN_RET_FAIL;
-    }
-
-    D("peer ip : %s\n", in_buf);
-
-    snprintf(out.data, out.len, "%s", SDBD_RET_VALID);
-    ret = SDBD_PLUGIN_RET_SUCCESS;
-
-    return ret;
-}
-
-static int verify_sdbd_launch(const char* in_buf, sdbd_plugin_param out) {
-    snprintf(out.data, out.len, "%s", SDBD_RET_VALID);
-    return SDBD_PLUGIN_RET_SUCCESS;
-}
-
-static int verify_root_cmd(const char* in_buf, sdbd_plugin_param out) {
-    int ret = SDBD_PLUGIN_RET_FAIL;
-
-    if (in_buf == NULL) {
-        D("Invalid argument\n");
-        return SDBD_PLUGIN_RET_FAIL;
-    }
-
-    D("shell command : %s\n", in_buf);
-
-    if (verify_root_commands(in_buf)) {
-        snprintf(out.data, out.len, "%s", SDBD_RET_VALID);
-    } else {
-        snprintf(out.data, out.len, "%s", SDBD_RET_INVALID);
-    }
-    ret = SDBD_PLUGIN_RET_SUCCESS;
-
-    return ret;
-}
-
-static int get_shell_env(const char* in_buf, sdbd_plugin_param out) {
-    snprintf(out.data, out.len, "%s", "");
-    return SDBD_PLUGIN_RET_SUCCESS;
-}
-
-int default_cmd_proc(const char* cmd,
-                    const char* in_buf, sdbd_plugin_param out) {
-    int ret = SDBD_PLUGIN_RET_NOT_SUPPORT;
-
-    /* Check the arguments */
-    if (cmd == NULL || out.data == NULL) {
-        D("Invalid argument\n");
-        return SDBD_PLUGIN_RET_FAIL;
-    }
-
-    D("handle the command : %s\n", cmd);
-
-    /* Handle the request from sdbd */
-    if (SDBD_CMP_CMD(cmd, PLUGIN_CAP)) {
-        ret = get_plugin_capability(in_buf, out);
-    } else if (SDBD_CMP_CMD(cmd, VERIFY_SHELLCMD)) {
-        ret = verify_shell_cmd(in_buf, out);
-    } else if (SDBD_CMP_CMD(cmd, CONV_SHELLCMD)) {
-        ret = convert_shell_cmd(in_buf, out);
-    } else if (SDBD_CMP_CMD(cmd, VERIFY_PEERIP)) {
-        ret = verify_peer_ip(in_buf, out);
-    } else if (SDBD_CMP_CMD(cmd, VERIFY_LAUNCH)) {
-        ret = verify_sdbd_launch(in_buf, out);
-    } else if (SDBD_CMP_CMD(cmd, VERIFY_ROOTCMD)) {
-        ret = verify_root_cmd(in_buf, out);
-    } else if (SDBD_CMP_CMD(cmd, SHELL_ENVVAR)) {
-        ret = get_shell_env(in_buf, out);
-    } else {
-        D("Not supported command : %s\n", cmd);
-        ret = SDBD_PLUGIN_RET_NOT_SUPPORT;
-    }
-
-    return ret;
-}
-
-int request_plugin_cmd(const char* cmd, const char* in_buf,
-                        char *out_buf, unsigned int out_len)
-{
-    int ret = SDBD_PLUGIN_RET_FAIL;
-    sdbd_plugin_param out;
-
-    if (out_len > SDBD_PLUGIN_OUTBUF_MAX) {
-        D("invalid parameter : %s\n", cmd);
-        return 0;
-    }
-
-    out.data = out_buf;
-    out.len = out_len;
-
-    ret = sdbd_plugin_cmd_proc(cmd, in_buf, out);
-    if (ret == SDBD_PLUGIN_RET_FAIL) {
-        D("failed to request : %s\n", cmd);
-        return 0;
-    }
-    if (ret == SDBD_PLUGIN_RET_NOT_SUPPORT) {
-        // retry in default handler
-        ret = default_cmd_proc(cmd, in_buf, out);
-        if (ret == SDBD_PLUGIN_RET_FAIL) {
-            D("failed to request : %s\n", cmd);
-            return 0;
-        }
-    }
-
-    // add null character.
-    out_buf[out_len-1] = '\0';
-    D("return value: %s\n", out_buf);
-
-    return 1;
-}
-
-static void load_sdbd_plugin() {
-    sdbd_plugin_cmd_proc = NULL;
-
-    g_sdbd_plugin_handle = dlopen(SDBD_PLUGIN_PATH, RTLD_NOW);
-    if (!g_sdbd_plugin_handle) {
-        D("failed to dlopen(%s). error: %s\n", SDBD_PLUGIN_PATH, dlerror());
-        sdbd_plugin_cmd_proc = default_cmd_proc;
-        return;
-    }
-
-    sdbd_plugin_cmd_proc = dlsym(g_sdbd_plugin_handle, SDBD_PLUGIN_INTF);
-    if (!sdbd_plugin_cmd_proc) {
-        D("failed to get the sdbd plugin interface. error: %s\n", dlerror());
-        dlclose(g_sdbd_plugin_handle);
-        g_sdbd_plugin_handle = NULL;
-        sdbd_plugin_cmd_proc = default_cmd_proc;
-        return;
-    }
-
-    D("using sdbd plugin interface.(%s)\n", SDBD_PLUGIN_PATH);
-}
-
 #define SDB_PW_GR_DEFAULT_SIZE  (16*1024)
 static long get_passwd_bufsize() {
     long bufsize = 0;
@@ -1921,28 +1613,9 @@ static void init_sdk_requirements() {
     if (is_emulator()) {
         register_bootdone_cb();
     }
-
-    create_pwlock_thread();
 }
 #endif /* !SDB_HOST */
 
-int request_plugin_verification(const char* cmd, const char* in_buf) {
-    char out_buf[32] = {0,};
-
-    if(!request_plugin_cmd(cmd, in_buf, out_buf, sizeof(out_buf))) {
-        D("failed to request plugin command. : %s\n", SDBD_CMD_VERIFY_LAUNCH);
-        return 0;
-    }
-
-    if (strlen(out_buf) == 7 && !strncmp(out_buf, SDBD_RET_INVALID, 7)) {
-        D("[%s] is NOT verified.\n", cmd);
-        return 0;
-    }
-
-    D("[%s] is verified.\n", cmd);
-    return 1;
-}
-
 static void init_capabilities(void) {
     int ret = -1;
     char *value = NULL;
@@ -1965,60 +1638,54 @@ static void init_capabilities(void) {
 
 
     // Secure protocol support
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_SECURE,
-                            g_capabilities.secure_protocol,
+    if(!request_capability_to_plugin(CAPABILITY_SECURE, g_capabilities.secure_protocol,
                             sizeof(g_capabilities.secure_protocol))) {
-        D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_SECURE);
+        D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_SECURE);
         snprintf(g_capabilities.secure_protocol, sizeof(g_capabilities.secure_protocol),
                     "%s", DISABLED);
     }
 
 
     // Interactive shell support
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_INTER_SHELL,
-                            g_capabilities.intershell_support,
+    if(!request_capability_to_plugin(CAPABILITY_INTER_SHELL, g_capabilities.intershell_support,
                             sizeof(g_capabilities.intershell_support))) {
-        D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_INTER_SHELL);
+        D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_INTER_SHELL);
         snprintf(g_capabilities.intershell_support, sizeof(g_capabilities.intershell_support),
                     "%s", DISABLED);
     }
 
 
     // File push/pull support
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_FILESYNC,
-                            g_capabilities.filesync_support,
+    if(!request_capability_to_plugin(CAPABILITY_FILESYNC, g_capabilities.filesync_support,
                             sizeof(g_capabilities.filesync_support))) {
-        D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_FILESYNC);
+        D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_FILESYNC);
         snprintf(g_capabilities.filesync_support, sizeof(g_capabilities.filesync_support),
                     "%s", DISABLED);
     }
 
 
     // USB protocol support
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_USBPROTO,
-                            g_capabilities.usbproto_support,
+    if(!request_capability_to_plugin(CAPABILITY_USB_PROTOCOL, g_capabilities.usbproto_support,
                             sizeof(g_capabilities.usbproto_support))) {
-        D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_USBPROTO);
+        D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_USB_PROTOCOL);
         snprintf(g_capabilities.usbproto_support, sizeof(g_capabilities.usbproto_support),
                     "%s", DISABLED);
     }
 
 
     // Socket protocol support
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_SOCKPROTO,
-                            g_capabilities.sockproto_support,
+    if(!request_capability_to_plugin(CAPABILITY_SOCK_PROTOCOL, g_capabilities.sockproto_support,
                             sizeof(g_capabilities.sockproto_support))) {
-        D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_SOCKPROTO);
+        D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_SOCK_PROTOCOL);
         snprintf(g_capabilities.sockproto_support, sizeof(g_capabilities.sockproto_support),
                     "%s", DISABLED);
     }
 
 
     // Root command support
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_ROOTONOFF,
-                            g_capabilities.rootonoff_support,
+    if(!request_capability_to_plugin(CAPABILITY_ROOT_ONOFF, g_capabilities.rootonoff_support,
                             sizeof(g_capabilities.rootonoff_support))) {
-        D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_ROOTONOFF);
+        D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_ROOT_ONOFF);
         snprintf(g_capabilities.rootonoff_support, sizeof(g_capabilities.rootonoff_support),
                     "%s", DISABLED);
     }
@@ -2112,10 +1779,9 @@ static void init_capabilities(void) {
 
 
     // Product version
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_PRODUCT_VER,
-                            g_capabilities.product_version,
+    if(!request_capability_to_plugin(CAPABILITY_PRODUCT_VER, g_capabilities.product_version,
                             sizeof(g_capabilities.product_version))) {
-        D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_PRODUCT_VER);
+        D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_PRODUCT_VER);
         snprintf(g_capabilities.product_version, sizeof(g_capabilities.product_version),
                     "%s", UNKNOWN);
     }
@@ -2127,29 +1793,26 @@ static void init_capabilities(void) {
 
 
     // Sdbd plugin version
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_PLUGIN_VER,
-                            g_capabilities.sdbd_plugin_version,
+    if(!request_capability_to_plugin(CAPABILITY_PLUGIN_VER, g_capabilities.sdbd_plugin_version,
                             sizeof(g_capabilities.sdbd_plugin_version))) {
-        D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_PLUGIN_VER);
+        D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_PLUGIN_VER);
         snprintf(g_capabilities.sdbd_plugin_version, sizeof(g_capabilities.sdbd_plugin_version),
                     "%s", UNKNOWN);
     }
 
 
     // sdbd log enable
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_LOG_ENABLE,
-                               g_capabilities.log_enable,
+    if(!request_capability_to_plugin(CAPABILITY_LOG_ENABLE, g_capabilities.log_enable,
                                sizeof(g_capabilities.log_enable))) {
-           D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_LOG_ENABLE);
+           D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_LOG_ENABLE);
            snprintf(g_capabilities.log_enable, sizeof(g_capabilities.log_enable),
                        "%s", DISABLED);
     }
 
-    // sdbd log path
-    if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_LOG_PATH,
-                               g_capabilities.log_path,
+     // sdbd log path
+    if(!request_capability_to_plugin(CAPABILITY_LOG_PATH, g_capabilities.log_path,
                                sizeof(g_capabilities.log_path))) {
-           D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_LOG_PATH);
+           D("failed to request. (%d:%d) \n", PLUGIN_SYNC_CMD_CAPABILITY, CAPABILITY_LOG_PATH);
            snprintf(g_capabilities.log_path, sizeof(g_capabilities.log_path),
                        "%s", UNKNOWN);
     }
@@ -2162,12 +1825,12 @@ static void init_capabilities(void) {
 
 static int is_support_usbproto()
 {
-    return (!strncmp(g_capabilities.usbproto_support, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED)));
+    return (!strncmp(g_capabilities.usbproto_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
 }
 
 static int is_support_sockproto()
 {
-    return (!strncmp(g_capabilities.sockproto_support, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED)));
+    return (!strncmp(g_capabilities.sockproto_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
 }
 
 #define EMULATOR_MODEL_NAME     "Emulator"
@@ -2198,6 +1861,7 @@ int sdb_main(int is_daemon, int server_port)
     check_emulator_or_device();
 
     load_sdbd_plugin();
+    
     init_capabilities();
 
     sdb_trace_init();
@@ -2205,7 +1869,7 @@ int sdb_main(int is_daemon, int server_port)
 
     init_drop_privileges();
     init_sdk_requirements();
-    if (!request_plugin_verification(SDBD_CMD_VERIFY_LAUNCH, NULL)) {
+    if (!request_validity_to_plugin(PLUGIN_SYNC_CMD_VERIFY_LAUNCH, NULL)) {
         D("sdbd should be launched in develop mode.\n");
         return -1;
     }
@@ -2713,3 +2377,4 @@ int main(int argc, char **argv)
     return sdb_main(0, DEFAULT_SDB_PORT);
 #endif
 }
+
index b3b78f3..5d7bd94 100644 (file)
--- a/src/sdb.h
+++ b/src/sdb.h
@@ -23,7 +23,6 @@
 
 #include "transport.h"  /* readx(), writex() */
 #include "fdevent.h"
-#include "sdbd_plugin.h"
 #if !SDB_HOST
 #include "commandline_sdbd.h"
 #endif
@@ -275,13 +274,6 @@ typedef struct platform_capabilities
 } pcap;
 extern pcap g_capabilities;
 
-#define SDBD_PLUGIN_PATH    "/usr/lib/libsdbd_plugin.so"
-#define SDBD_PLUGIN_INTF    "sdbd_plugin_cmd_proc"
-typedef int (*SDBD_PLUGIN_CMD_PROC_PTR)(const char*, const char*, sdbd_plugin_param);
-extern SDBD_PLUGIN_CMD_PROC_PTR sdbd_plugin_cmd_proc;
-int request_plugin_cmd(const char* cmd, const char* in_buf, char *out_buf, unsigned int out_len);
-int request_plugin_verification(const char* cmd, const char* in_buf);
-
 void print_packet(const char *label, apacket *p);
 
 asocket *find_local_socket(unsigned id);
@@ -384,6 +376,9 @@ char * get_log_file_path(const char * log_name);
 extern int rootshell_mode; // 0: sdk user, 1: root
 extern int booting_done; // 0: platform booting is in progess 1: platform booting is done
 
+// 1 if locked, 0 if unlocked
+extern int is_pwlocked;
+
 // This is the users and groups config for the platform
 
 #define SID_ROOT        0    /* traditional unix root user */
@@ -399,10 +394,10 @@ extern char* g_sdk_home_dir;
 extern char* g_sdk_home_dir_env;
 #endif
 
-int is_pwlocked(void);
 int should_drop_privileges(void);
 int set_sdk_user_privileges();
 void set_root_privileges();
+void send_device_status();
 
 int get_emulator_forward_port(void);
 int get_emulator_name(char str[], int str_size);
@@ -417,86 +412,6 @@ void put_apacket(apacket *p);
 int check_header(apacket *p);
 int check_data(apacket *p);
 
-/* define SDB_TRACE to 1 to enable tracing support, or 0 to disable it */
-
-#define  SDB_TRACE    1
-
-/* IMPORTANT: if you change the following list, don't
- * forget to update the corresponding 'tags' table in
- * the sdb_trace_init() function implemented in sdb.c
- */
-typedef enum {
-    TRACE_SDB = 0,
-    TRACE_SOCKETS,
-    TRACE_PACKETS,
-    TRACE_TRANSPORT,
-    TRACE_RWX,
-    TRACE_USB,
-    TRACE_SYNC,
-    TRACE_SYSDEPS,
-    TRACE_JDWP,
-    TRACE_SERVICES,
-    TRACE_PROPERTIES,
-    TRACE_SDKTOOLS
-} SdbTrace;
-
-#if SDB_TRACE
-
-#if !SDB_HOST
-/*
- * When running inside the emulator, guest's sdbd can connect to 'sdb-debug'
- * qemud service that can display sdb trace messages (on condition that emulator
- * has been started with '-debug sdb' option).
- */
-
-/* Delivers a trace message to the emulator via QEMU pipe. */
-void sdb_qemu_trace(const char* fmt, ...);
-/* Macro to use to send SDB trace messages to the emulator. */
-#define DQ(...)    sdb_qemu_trace(__VA_ARGS__)
-#else
-#define DQ(...) ((void)0)
-#endif  /* !SDB_HOST */
-
-  extern int     sdb_trace_mask;
-  extern unsigned char    sdb_trace_output_count;
-  void    sdb_trace_init(void);
-
-#  define SDB_TRACING  ((sdb_trace_mask & (1 << TRACE_TAG)) != 0)
-
-  /* you must define TRACE_TAG before using this macro */
-#  define  D(...)                                      \
-        do {                                           \
-            if (SDB_TRACING) {                         \
-                int save_errno = errno;                \
-                sdb_mutex_lock(&D_lock);               \
-                fprintf(stderr, "%s::%s():",           \
-                        __FILE__, __FUNCTION__);       \
-                errno = save_errno;                    \
-                fprintf(stderr, __VA_ARGS__ );         \
-                fflush(stderr);                        \
-                sdb_mutex_unlock(&D_lock);             \
-                errno = save_errno;                    \
-           }                                           \
-        } while (0)
-#  define  DR(...)                                     \
-        do {                                           \
-            if (SDB_TRACING) {                         \
-                int save_errno = errno;                \
-                sdb_mutex_lock(&D_lock);               \
-                errno = save_errno;                    \
-                fprintf(stderr, __VA_ARGS__ );         \
-                fflush(stderr);                        \
-                sdb_mutex_unlock(&D_lock);             \
-                errno = save_errno;                    \
-           }                                           \
-        } while (0)
-#else
-#  define  D(...)          ((void)0)
-#  define  DR(...)         ((void)0)
-#  define  SDB_TRACING     0
-#endif
-
-
 #if !TRACE_PACKETS
 #define print_packet(tag,p) do {} while (0)
 #endif
@@ -586,6 +501,7 @@ extern SdbdCommandlineArgs sdbd_commandline_args;
 #endif
 
 #define CHUNK_SIZE (64*1024)
+#define SDBD_SHELL_CMD_MAX 4096
 
 int sendfailmsg(int fd, const char *reason);
 int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s);
index dce56e1..45f2be2 100644 (file)
 #ifndef __SDBD_PLUGIN_H
 #define __SDBD_PLUGIN_H
 
-#include <string.h>
-
-/* plugin commands */
-#define SDBD_CMD_PLUGIN_CAP             "plugin_capability"
-#define SDBD_CMD_VERIFY_SHELLCMD        "verify_shell_cmd"
-#define SDBD_CMD_CONV_SHELLCMD          "convert_shell_cmd"
-#define SDBD_CMD_VERIFY_PEERIP          "verify_peer_ip"
-#define SDBD_CMD_VERIFY_LAUNCH          "verify_sdbd_launch"
-#define SDBD_CMD_VERIFY_ROOTCMD         "verify_root_cmd"
-#define SDBD_CMD_SHELL_ENVVAR           "sdbd_shell_env_var"
-
-/* plugin capabilities */
-#define SDBD_CAP_TYPE_SECURE            "secure_protocol_support"
-#define SDBD_CAP_TYPE_INTER_SHELL       "interactive_shell_support"
-#define SDBD_CAP_TYPE_FILESYNC          "file_sync_support"
-#define SDBD_CAP_TYPE_USBPROTO          "usb_protocol_support"
-#define SDBD_CAP_TYPE_SOCKPROTO         "socket_protocol_support"
-#define SDBD_CAP_TYPE_ROOTONOFF         "root_onoff_support"
-#define SDBD_CAP_TYPE_CANLAUNCH         "can_launch_target"
-#define SDBD_CAP_TYPE_PLUGIN_VER        "sdbd_plugin_version"
-#define SDBD_CAP_TYPE_PRODUCT_VER       "product_version"
-#define SDBD_CAP_TYPE_LOG_ENABLE        "sdbd_log_enable"
-#define SDBD_CAP_TYPE_LOG_PATH          "sdbd_log_path"
-
-/* capability return string */
-#define SDBD_CAP_RET_ENABLED            "enabled"
-#define SDBD_CAP_RET_DISABLED           "disabled"
-#define SDBD_CAP_RET_PUSH               "push"
-#define SDBD_CAP_RET_PULL               "pull"
-#define SDBD_CAP_RET_PUSHPULL           "pushpull"
-
-/* verification return string */
-#define SDBD_RET_VALID                  "valid"
-#define SDBD_RET_INVALID                "invalid"
-
-/* proc interface return value */
-#define SDBD_PLUGIN_RET_SUCCESS         (0)
-#define SDBD_PLUGIN_RET_FAIL            (-1)
-#define SDBD_PLUGIN_RET_NOT_SUPPORT     (-2)
-
-/* utility macro */
-#define SDBD_CMP_CMD(cmd, type)                             \
-    ((strlen(cmd) == strlen(SDBD_CMD_##type)                \
-    && !strncmp(cmd, SDBD_CMD_##type, strlen(cmd)))?1:0)
-
-#define SDBD_CMP_CAP(cap, type)                             \
-    ((strlen(cap) == (strlen(SDBD_CAP_TYPE_##type))         \
-    && !strncmp(cap, SDBD_CAP_TYPE_##type, strlen(cap)))?1:0)
-
-/* out parameter structure */
-#define SDBD_SHELL_CMD_MAX      4096
-#define SDBD_PLUGIN_OUTBUF_MAX  4096
-typedef struct sdbd_plugin_param {
-    unsigned int len;
-    char *data;
-} sdbd_plugin_param;
-
-/* log system */
-// 1. set the environment value. : SDB_TRACE=all
-// 2. restart the sdbd deamon.
-// 3. log is output to the /tmp/sdbd-[date].txt
-#define SDBD_PLUGIN_LOG(...)                \
-        fprintf(stderr, "%s::%s():",        \
-                __FILE__, __FUNCTION__);    \
+#include "parameter.h"
+
+// ===========================================================================
+// command && event definition
+// ===========================================================================
+
+// synchronous command
+#define PLUGIN_SYNC_CMD_CAPABILITY                  1000
+#define PLUGIN_SYNC_CMD_VERIFY_SHELLCMD             1001
+#define PLUGIN_SYNC_CMD_CONVERT_SHELLCMD            1002
+#define PLUGIN_SYNC_CMD_VERIFY_PEERIP               1003
+#define PLUGIN_SYNC_CMD_VERIFY_LAUNCH               1004
+#define PLUGIN_SYNC_CMD_VERIFY_ROOTCMD              1005
+#define PLUGIN_SYNC_CMD_AUTH_SUPPORT                1006
+#define PLUGIN_SYNC_CMD_AUTH_GET_KEY_FILEPATHS      1007
+#define PLUGIN_SYNC_CMD_GET_LOCK_STATE              1008
+
+// asynchronous command
+#define PLUGIN_ASYNC_CMD_AUTH_CONFIRM_PUBLIC        2000
+
+// event
+#define PLUGIN_EVENT_PWLOCK                         3000
+#define PLUGIN_EVENT_FMMLOCK                        3001
+
+// message
+#define PLUGIN_MESSAGE_CONFIRM_PUBLIC               4000
+
+// ==============================================================================
+// capability definition
+// ==============================================================================
+#define CAPABILITY_SECURE               10000
+#define CAPABILITY_INTER_SHELL          10001
+#define CAPABILITY_FILESYNC             10002
+#define CAPABILITY_USB_PROTOCOL         10003
+#define CAPABILITY_SOCK_PROTOCOL        10004
+#define CAPABILITY_ROOT_ONOFF           10005
+#define CAPABILITY_CAN_LAUNCH           10006
+#define CAPABILITY_PLUGIN_VER           10007
+#define CAPABILITY_PRODUCT_VER          10008
+#define CAPABILITY_LOG_ENABLE           10009
+#define CAPABILITY_LOG_PATH             10010
+
+// ===============================================================================
+// priority definition
+// ===============================================================================
+typedef enum _priority {
+    PRIORITY_VERYLOW,
+    PRIORITY_LOW,
+    PRIORITY_NORMAL,
+    PRIORITY_HIGH,
+    PRIORITY_VERYHIGH
+} priority;
+
+// ===============================================================================
+// misc.
+// ===============================================================================
+#define LOCKTYPE_PASSWORD               20000
+#define LOCKTYPE_FMM                    20001
+
+// ===============================================================================
+// return value definition
+// ===============================================================================
+#define PLUGIN_RET_ON                   10
+#define PLUGIN_RET_OFF                  11
+#define PLUGIN_RET_VALID                12
+#define PLUGIN_RET_INVALID              13
+#define PLUGIN_CMD_SUCCESS              101
+#define PLUGIN_CMD_FAIL                 102
+#define PLUGIN_CMD_NOT_SUPPORT          103
+
+#define PLUGIN_RET_UNKNOWN              "unknown"
+#define PLUGIN_RET_ENABLED              "enabled"
+#define PLUGIN_RET_DISABLED             "disabled"
+#define PLUGIN_RET_PUSH                 "push"
+#define PLUGIN_RET_PULL                 "pull"
+#define PLUGIN_RET_PUSHPULL             "pushpull"
+
+// ================================================================================
+// callback and interface function definition
+// ================================================================================
+
+// definition of callback functions (implemented by sdbd)
+typedef int ( *eventfunc ) ( int event_type, parameters* data );
+typedef int ( *registerfunc ) ( int command, priority cmd_priority );
+
+// definition of interface functions (implemented by plugin)
+#define PLUGIN_PROC_NAME_INIT       "plugin_init"
+#define PLUGIN_PROC_NAME_SYNC_CMD   "plugin_synchronous_cmd_proc"
+#define PLUGIN_PROC_NAME_ASYNC_CMD  "plugin_asynchronous_cmd_proc"
+
+typedef int ( *PLUGIN_INIT ) ( eventfunc event_func_ptr, registerfunc register_cmd_func_ptr );
+typedef int ( *PLUGIN_SYNCHRONOUS_CMD_PROC ) ( int cmd, parameters* in, parameters* out );
+typedef int ( *PLUGIN_ASYNCHRONOUS_CMD_PROC ) ( int cmd, parameters* in, int out_fd );
+
+#define PLUGIN_LOG(...)                                         \
+        fprintf(stderr, "%s::%s():", __FILE__, __FUNCTION__);   \
         fprintf(stderr, __VA_ARGS__);
 
-#endif
+#endif // __SDBD_PLUGIN_H
index 7780101..ac7d21e 100644 (file)
@@ -12,6 +12,8 @@
 #include "sdktools.h"
 
 #define  TRACE_TAG  TRACE_SERVICES
+#include "log.h"
+
 #include "sdb.h"
 #include "sdktools.h"
 #include "strutils.h"
index 2478680..22b9dda 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
@@ -24,6 +24,8 @@
 #include "sysdeps.h"
 
 #define  TRACE_TAG  TRACE_SERVICES
+#include "log.h"
+
 #include "sdb.h"
 #include "file_sync_service.h"
 
@@ -49,6 +51,9 @@
 #include <termios.h>
 #include <sys/ioctl.h>
 
+#include "sdbd_plugin.h"
+#include "plugin.h"
+
 typedef struct stinfo stinfo;
 
 struct stinfo {
@@ -89,7 +94,7 @@ static void dns_service(int fd, void *cookie)
 
 static int is_support_interactive_shell()
 {
-    return (!strncmp(g_capabilities.intershell_support, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED)));
+    return (!strncmp(g_capabilities.intershell_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
 }
 
 #if 0
@@ -174,7 +179,7 @@ void restart_tcp_service(int fd, void *cookie)
 
 static int is_support_rootonoff()
 {
-    return (!strncmp(g_capabilities.rootonoff_support, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED)));
+    return (!strncmp(g_capabilities.rootonoff_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
 }
 
 void rootshell_service(int fd, void *cookie)
@@ -489,7 +494,7 @@ static int create_subprocess(const char *cmd, pid_t *pid, char * const argv[], c
         }
 
         if (should_drop_privileges()) {
-            if (argv[2] != NULL && getuid() == 0 && request_plugin_verification(SDBD_CMD_VERIFY_ROOTCMD, argv[2])) {
+            if (argv[2] != NULL && getuid() == 0 && request_validity_to_plugin(PLUGIN_SYNC_CMD_VERIFY_ROOTCMD, argv[2])) {
                 // do nothing
                 D("sdb: executes root commands!!:%s\n", argv[2]);
             } else {
@@ -664,7 +669,7 @@ static int create_subproc_thread(const char *name, int lines, int columns)
 
     if(name) { // in case of shell execution directly
         // Check the shell command validation.
-        if (!request_plugin_verification(SDBD_CMD_VERIFY_SHELLCMD, name)) {
+        if (!request_validity_to_plugin(PLUGIN_SYNC_CMD_VERIFY_SHELLCMD, name)) {
             D("This shell command is invalid. (%s)\n", name);
             return -1;
         }
@@ -678,7 +683,7 @@ static int create_subproc_thread(const char *name, int lines, int columns)
         }
 
         memset(new_cmd, 0, SDBD_SHELL_CMD_MAX);
-        if(!request_plugin_cmd(SDBD_CMD_CONV_SHELLCMD, name, new_cmd, SDBD_SHELL_CMD_MAX)) {
+        if(!request_conversion_to_plugin(PLUGIN_SYNC_CMD_CONVERT_SHELLCMD, name, new_cmd, SDBD_SHELL_CMD_MAX)) {
             D("Failed to convert the shell command. (%s)\n", name);
             free(new_cmd);
             return -1;
index 4f3ec83..574820a 100644 (file)
@@ -24,6 +24,8 @@
 #include "sysdeps.h"
 
 #define  TRACE_TAG  TRACE_SOCKETS
+#include "log.h"
+
 #include "sdb.h"
 #include "strutils.h"
 
index 2083fbc..7e2af39 100644 (file)
@@ -23,6 +23,8 @@
 #include "sysdeps.h"
 
 #define   TRACE_TAG  TRACE_TRANSPORT
+#include "log.h"
+
 #include "sdb.h"
 
 static void transport_unref(atransport *t);
@@ -1042,13 +1044,19 @@ void broadcast_transport(apacket *p)
         D("broadcast device transport:%d\n", t->connection_state);
         apacket* ap = get_apacket();
         copy_packet(ap, p);
-
         send_packet(ap, t);
-        if (is_pwlocked()) {
-            t->connection_state = CS_PWLOCK;
-        } else {
-            t->connection_state = CS_DEVICE;
+        
+        if (ap->msg.command == A_STAT && ap->msg.arg1 == 0) {
+            // lock state message
+            if (ap->msg.arg0 == 0) {
+                // unlocked
+                t->connection_state = CS_DEVICE;
+            } else {
+                // locked
+                t->connection_state = CS_PWLOCK;
+            }
         }
+        
      }
     sdb_mutex_unlock(&transport_lock);
 }
@@ -1186,3 +1194,4 @@ int check_data(apacket *p)
         return 0;
     }
 }
+
index 32e1f49..849fe05 100644 (file)
 #endif
 
 #define  TRACE_TAG  TRACE_TRANSPORT
+#include "log.h"
+
 #include "sdb.h"
 #include "strutils.h"
 #if !SDB_HOST
 #include "commandline_sdbd.h"
 #endif
-#include "utils.h"
+#include "sdbd_plugin.h"
+#include "plugin.h"
 
 #ifdef HAVE_BIG_ENDIAN
 #define H4(x)  (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
@@ -292,7 +295,7 @@ static void *server_socket_thread(void * arg)
 
             // Check the peer ip validation.
             if (!is_emulator()
-                && !request_plugin_verification(SDBD_CMD_VERIFY_PEERIP, inet_ntoa(addr.sin_addr))) {
+                && !request_validity_to_plugin(PLUGIN_SYNC_CMD_VERIFY_PEERIP, inet_ntoa(addr.sin_addr))) {
                 sdb_close(fd);
             } else {
                 int ret = -1;
index 0eafc4d..932e170 100644 (file)
@@ -21,6 +21,8 @@
 #include <sysdeps.h>
 
 #define  TRACE_TAG  TRACE_TRANSPORT
+#include "log.h"
+
 #include "sdb.h"
 
 #ifdef HAVE_BIG_ENDIAN
index 75d90aa..241d368 100644 (file)
@@ -31,6 +31,8 @@
 #include "sysdeps.h"
 
 #define   TRACE_TAG  TRACE_USB
+#include "log.h"
+
 #include "sdb.h"
 
 #define MAX_PACKET_SIZE_FS     64
index 95f2ee9..7bf435b 100644 (file)
@@ -39,6 +39,8 @@
 #include "sysdeps.h"
 
 #define   TRACE_TAG  TRACE_USB
+#include "log.h"
+
 #include "sdb.h"
 
 
index ec8c159..5d722b4 100644 (file)
@@ -27,6 +27,8 @@
 #include "sysdeps.h"
 
 #define   TRACE_TAG  TRACE_USB
+#include "log.h"
+
 #include "sdb.h"