Revert "modify default plugin's behavior by emulator"
[sdk/target/sdbd.git] / src / default_plugin_basic.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 <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <stdarg.h>
21 #include <unistd.h>
22
23 #define TRACE_TAG TRACE_SDB
24 #include "log.h"
25
26 #include "sdb.h"
27 #include "parameter.h"
28 #include "sdbd_plugin.h"
29 #include "sdktools.h"
30
31 #define LOG_DIRECTORY   "/tmp"
32
33 int get_plugin_capability ( parameters* in, parameters* out )
34 {
35     int capability;
36
37     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
38             || in->array_of_parameter[0].type != type_int32 ) {
39         D ( "Invalid argument\n" );
40         return PLUGIN_CMD_FAIL;
41     }
42
43     if ( out == NULL ) {
44         D ( "Invalid argument\n" );
45         return PLUGIN_CMD_FAIL;
46     }
47
48     out->number_of_parameter = 1;
49     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
50
51     capability = in->array_of_parameter[0].v_int32;
52
53     if ( capability == CAPABILITY_SECURE ) {
54         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_DISABLED );
55     } else if ( capability == CAPABILITY_INTER_SHELL ) {
56         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
57     } else if ( capability == CAPABILITY_FILESYNC ) {
58         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_PUSHPULL );
59     } else if ( capability == CAPABILITY_USB_PROTOCOL ) {
60         if ( is_emulator() ) {
61             make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_DISABLED );
62         } else {
63             make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
64         }
65     } else if ( capability == CAPABILITY_SOCK_PROTOCOL ) {
66         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
67     } else if ( capability == CAPABILITY_ROOT_ONOFF ) {
68         if ( access ( "/bin/su", F_OK ) == 0 ) {
69             make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
70         } else {
71             make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_DISABLED );
72         }
73     } else if ( capability == CAPABILITY_CAN_LAUNCH ) {
74         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_UNKNOWN );
75     } else if ( capability == CAPABILITY_PLUGIN_VER ) {
76         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_UNKNOWN );
77     } else if ( capability == CAPABILITY_PRODUCT_VER ) {
78         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_UNKNOWN );
79     } else if ( capability == CAPABILITY_LOG_ENABLE ) {
80         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_DISABLED );
81     } else if ( capability == CAPABILITY_LOG_PATH ) {
82         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", LOG_DIRECTORY );
83     } else if ( capability == CAPABILITY_APPCMD ) {
84         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
85     } else {
86         out->number_of_parameter = 0;
87         free ( out->array_of_parameter );
88         out->array_of_parameter = NULL;
89         return PLUGIN_CMD_NOT_SUPPORT;
90     }
91
92     return PLUGIN_CMD_SUCCESS;
93 }
94
95 int verify_shell_cmd ( parameters* in, parameters* out )
96 {
97     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
98             || in->array_of_parameter[0].type != type_string ) {
99         D ( "Invalid argument\n" );
100         return PLUGIN_CMD_FAIL;
101     }
102
103     if ( out == NULL ) {
104         D ( "Invalid argument\n" );
105         return PLUGIN_CMD_FAIL;
106     }
107
108     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
109
110     out->number_of_parameter = 1;
111     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
112     out->array_of_parameter[0].type = type_int32;
113     out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
114
115     return PLUGIN_CMD_SUCCESS;
116 }
117
118 int convert_shell_cmd ( parameters* in, parameters* out )
119 {
120     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
121             || in->array_of_parameter[0].type != type_string ) {
122         D ( "Invalid argument\n" );
123         return PLUGIN_CMD_FAIL;
124     }
125
126     if ( out == NULL ) {
127         D ( "Invalid argument\n" );
128         return PLUGIN_CMD_FAIL;
129     }
130
131     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
132
133     out->number_of_parameter = 1;
134     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
135
136     make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", in->array_of_parameter[0].v_string.data );
137     return PLUGIN_CMD_SUCCESS;
138 }
139
140 int verify_peer_ip ( parameters* in, parameters* out )
141 {
142     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
143             || in->array_of_parameter[0].type != type_string ) {
144         D ( "Invalid argument\n" );
145         return PLUGIN_CMD_FAIL;
146     }
147
148     if ( out == NULL ) {
149         D ( "Invalid argument\n" );
150         return PLUGIN_CMD_FAIL;
151     }
152
153     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
154
155     out->number_of_parameter = 1;
156     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
157     out->array_of_parameter[0].type = type_int32;
158     out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
159
160     return PLUGIN_CMD_SUCCESS;
161 }
162
163 int verify_sdbd_launch ( parameters* in, parameters* out )
164 {
165     if ( out == NULL ) {
166         D ( "Invalid argument\n" );
167         return PLUGIN_CMD_FAIL;
168     }
169
170     out->number_of_parameter = 1;
171     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
172     out->array_of_parameter[0].type = type_int32;
173     out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
174
175     return PLUGIN_CMD_SUCCESS;
176 }
177
178 int verify_root_cmd ( parameters* in, parameters* out )
179 {
180     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
181             || in->array_of_parameter[0].type != type_string ) {
182         D ( "Invalid argument\n" );
183         return PLUGIN_CMD_FAIL;
184     }
185
186     if ( out == NULL ) {
187         D ( "Invalid argument\n" );
188         return PLUGIN_CMD_FAIL;
189     }
190
191     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
192
193     out->number_of_parameter = 1;
194     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
195     out->array_of_parameter[0].type = type_int32;
196
197     if ( verify_root_commands ( in->array_of_parameter[0].v_string.data ) ) {
198         out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
199     } else {
200         out->array_of_parameter[0].v_int32 = PLUGIN_RET_INVALID;
201     }
202
203     return PLUGIN_CMD_SUCCESS;
204 }