Revert "Merge plugin improvement commit"
[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         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
61     } else if ( capability == CAPABILITY_SOCK_PROTOCOL ) {
62         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
63     } else if ( capability == CAPABILITY_ROOT_ONOFF ) {
64         if ( access ( "/bin/su", F_OK ) == 0 ) {
65             make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
66         } else {
67             make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_DISABLED );
68         }
69     } else if ( capability == CAPABILITY_CAN_LAUNCH ) {
70         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_UNKNOWN );
71     } else if ( capability == CAPABILITY_PLUGIN_VER ) {
72         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_UNKNOWN );
73     } else if ( capability == CAPABILITY_PRODUCT_VER ) {
74         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_UNKNOWN );
75     } else if ( capability == CAPABILITY_LOG_ENABLE ) {
76         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
77     } else if ( capability == CAPABILITY_LOG_PATH ) {
78         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", LOG_DIRECTORY );
79     } else if ( capability == CAPABILITY_APPCMD ) {
80         make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", PLUGIN_RET_ENABLED );
81     } else {
82         out->number_of_parameter = 0;
83         free ( out->array_of_parameter );
84         out->array_of_parameter = NULL;
85         return PLUGIN_CMD_NOT_SUPPORT;
86     }
87
88     return PLUGIN_CMD_SUCCESS;
89 }
90
91 int verify_shell_cmd ( parameters* in, parameters* out )
92 {
93     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
94             || in->array_of_parameter[0].type != type_string ) {
95         D ( "Invalid argument\n" );
96         return PLUGIN_CMD_FAIL;
97     }
98
99     if ( out == NULL ) {
100         D ( "Invalid argument\n" );
101         return PLUGIN_CMD_FAIL;
102     }
103
104     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
105
106     out->number_of_parameter = 1;
107     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
108     out->array_of_parameter[0].type = type_int32;
109     out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
110
111     return PLUGIN_CMD_SUCCESS;
112 }
113
114 int convert_shell_cmd ( parameters* in, parameters* out )
115 {
116     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
117             || in->array_of_parameter[0].type != type_string ) {
118         D ( "Invalid argument\n" );
119         return PLUGIN_CMD_FAIL;
120     }
121
122     if ( out == NULL ) {
123         D ( "Invalid argument\n" );
124         return PLUGIN_CMD_FAIL;
125     }
126
127     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
128
129     out->number_of_parameter = 1;
130     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
131
132     make_string_parameter ( & ( out->array_of_parameter[0] ), "%s", in->array_of_parameter[0].v_string.data );
133     return PLUGIN_CMD_SUCCESS;
134 }
135
136 int verify_peer_ip ( parameters* in, parameters* out )
137 {
138     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
139             || in->array_of_parameter[0].type != type_string ) {
140         D ( "Invalid argument\n" );
141         return PLUGIN_CMD_FAIL;
142     }
143
144     if ( out == NULL ) {
145         D ( "Invalid argument\n" );
146         return PLUGIN_CMD_FAIL;
147     }
148
149     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
150
151     out->number_of_parameter = 1;
152     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
153     out->array_of_parameter[0].type = type_int32;
154     out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
155
156     return PLUGIN_CMD_SUCCESS;
157 }
158
159 int verify_sdbd_launch ( parameters* in, parameters* out )
160 {
161     if ( out == NULL ) {
162         D ( "Invalid argument\n" );
163         return PLUGIN_CMD_FAIL;
164     }
165
166     out->number_of_parameter = 1;
167     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
168     out->array_of_parameter[0].type = type_int32;
169     out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
170
171     return PLUGIN_CMD_SUCCESS;
172 }
173
174 int verify_root_cmd ( parameters* in, parameters* out )
175 {
176     if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
177             || in->array_of_parameter[0].type != type_string ) {
178         D ( "Invalid argument\n" );
179         return PLUGIN_CMD_FAIL;
180     }
181
182     if ( out == NULL ) {
183         D ( "Invalid argument\n" );
184         return PLUGIN_CMD_FAIL;
185     }
186
187     D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
188
189     out->number_of_parameter = 1;
190     out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
191     out->array_of_parameter[0].type = type_int32;
192
193     if ( verify_root_commands ( in->array_of_parameter[0].v_string.data ) ) {
194         out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID;
195     } else {
196         out->array_of_parameter[0].v_int32 = PLUGIN_RET_INVALID;
197     }
198
199     return PLUGIN_CMD_SUCCESS;
200 }