Revert "Revert "improve plugin architecture""
[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 {
84         out->number_of_parameter = 0;
85         free ( out->array_of_parameter );
86         out->array_of_parameter = NULL;
87         return PLUGIN_CMD_NOT_SUPPORT;
88     }
89
90     return PLUGIN_CMD_SUCCESS;
91 }
92
93 int verify_shell_cmd ( parameters* in, parameters* out )
94 {
95     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
96             || in->array_of_parameter[0].type != type_string ) {
97         D ( "Invalid argument\n" );
98         return PLUGIN_CMD_FAIL;
99     }
100
101     if ( out == NULL ) {
102         D ( "Invalid argument\n" );
103         return PLUGIN_CMD_FAIL;
104     }
105
106     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
107
108     out->number_of_parameter = 1;
109     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
110     out->array_of_parameter[0].type = type_int32;
111     out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
112
113     return PLUGIN_CMD_SUCCESS;
114 }
115
116 int convert_shell_cmd ( parameters* in, parameters* out )
117 {
118     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
119             || in->array_of_parameter[0].type != type_string ) {
120         D ( "Invalid argument\n" );
121         return PLUGIN_CMD_FAIL;
122     }
123
124     if ( out == NULL ) {
125         D ( "Invalid argument\n" );
126         return PLUGIN_CMD_FAIL;
127     }
128
129     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
130
131     out->number_of_parameter = 1;
132     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
133
134     make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", in->array_of_parameter[0].v_string.data );
135     return PLUGIN_CMD_SUCCESS;
136 }
137
138 int verify_peer_ip ( parameters* in, parameters* out )
139 {
140     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
141             || in->array_of_parameter[0].type != type_string ) {
142         D ( "Invalid argument\n" );
143         return PLUGIN_CMD_FAIL;
144     }
145
146     if ( out == NULL ) {
147         D ( "Invalid argument\n" );
148         return PLUGIN_CMD_FAIL;
149     }
150
151     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
152
153     out->number_of_parameter = 1;
154     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
155     out->array_of_parameter[0].type = type_int32;
156     out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
157
158     return PLUGIN_CMD_SUCCESS;
159 }
160
161 int verify_sdbd_launch ( parameters* in, parameters* out )
162 {
163     if ( out == NULL ) {
164         D ( "Invalid argument\n" );
165         return PLUGIN_CMD_FAIL;
166     }
167
168     out->number_of_parameter = 1;
169     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
170     out->array_of_parameter[0].type = type_int32;
171     out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
172
173     return PLUGIN_CMD_SUCCESS;
174 }
175
176 int verify_root_cmd ( parameters* in, parameters* out )
177 {
178     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
179             || in->array_of_parameter[0].type != type_string ) {
180         D ( "Invalid argument\n" );
181         return PLUGIN_CMD_FAIL;
182     }
183
184     if ( out == NULL ) {
185         D ( "Invalid argument\n" );
186         return PLUGIN_CMD_FAIL;
187     }
188
189     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
190
191     out->number_of_parameter = 1;
192     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
193     out->array_of_parameter[0].type = type_int32;
194
195     if ( verify_root_commands ( in->array_of_parameter[0].v_string.data ) ) {
196         out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
197     } else {
198         out->array_of_parameter[0].v_int32 = PLUGIN_RET_INVALID;
199     }
200
201     return PLUGIN_CMD_SUCCESS;
202 }