Add feature to take extra capabilities from plugin
[sdk/target/sdbd.git] / src / default_plugin_main.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "parameter.h"
18 #include "sdbd_plugin.h"
19 #include "default_plugin.h"
20 #include "plugin.h"
21
22 eventfunc event_handler = NULL;
23
24 int default_plugin_init ( eventfunc event_cb, registerfunc register_func )
25 {
26     // default plugin do not need to register command
27     // because unsupported command by plugin should be called with default plugin anyway
28     event_handler = event_cb;
29
30     if (is_supported_by_plugin(PLUGIN_EVENT_PWLOCK) == 0) {
31         create_pwlock_thread();
32     }
33
34     return PLUGIN_CMD_SUCCESS;
35 }
36
37 int default_plugin_sync_proc ( int cmd, parameters* in, parameters* out )
38 {
39     int ret = PLUGIN_CMD_NOT_SUPPORT;
40
41     if ( cmd == PLUGIN_SYNC_CMD_CAPABILITY ) {
42         ret = get_plugin_capability ( in, out );
43     } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_SHELLCMD ) {
44         ret = verify_shell_cmd ( in, out );
45     } else if ( cmd == PLUGIN_SYNC_CMD_CONVERT_SHELLCMD ) {
46         ret = convert_shell_cmd ( in, out );
47     } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_PEERIP ) {
48         ret = verify_peer_ip ( in, out );
49     } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_PEERIPV6 ) {
50         ret = verify_peer_ipv6 ( in, out );
51     } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_LAUNCH ) {
52         ret = verify_sdbd_launch ( in, out );
53     } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_ROOTCMD ) {
54         ret = verify_root_cmd ( in, out );
55     } else if ( cmd == PLUGIN_SYNC_CMD_AUTH_SUPPORT ) {
56         ret = auth_support ( in, out );
57     } else if ( cmd == PLUGIN_SYNC_CMD_AUTH_GET_KEY_FILEPATHS ) {
58         ret = auth_get_key_file_paths ( in, out );
59     } else if ( cmd == PLUGIN_SYNC_CMD_GET_LOCK_STATE ) {
60         ret = get_lock_state ( in, out );
61     } else if ( cmd == PLUGIN_SYNC_CMD_GET_SHELL_ENV ) {
62         ret = get_shell_env ( in, out );
63     } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_PUSH ) {
64         ret = verify_push ( in, out );
65     } else if ( cmd == PLUGIN_SYNC_CMD_VERIFY_PULL ) {
66         ret = verify_pull ( in, out );
67     } else if ( cmd == PLUGIN_SYNC_CMD_HANDLE_BY_PLUGIN ) {
68         ret = verify_handle_by_plugin ( in, out );
69     } else if ( cmd == PLUGIN_SYNC_CMD_EXTRA_CAPABILITY ) {
70         ret = get_plugin_extra_capability ( in, out );
71     } else {
72         ret = PLUGIN_CMD_NOT_SUPPORT;
73     }
74
75     return ret;
76 }
77
78 int default_plugin_async_proc ( int cmd, parameters* in, int out_fd )
79 {
80     int ret = PLUGIN_CMD_NOT_SUPPORT;
81
82     if ( cmd == PLUGIN_ASYNC_CMD_AUTH_CONFIRM_PUBLIC ) {
83         ret = confirm_public_key ( in, out_fd );
84     } else if ( cmd == PLUGIN_ASYNC_CMD_APPCMD_SERVICE ) {
85         ret = appcmd_service ( in, out_fd );
86     } else if ( cmd == PLUGIN_ASYNC_CMD_HANDLEBYPLUGIN_SERVICE ) {
87         ret = shellcmd_service ( in, out_fd );
88     } else {
89         ret = PLUGIN_CMD_NOT_SUPPORT;
90     }
91
92     return ret;
93 }
94