sl@0
|
1 |
/* crypto/engine/eng_ctrl.c */
|
sl@0
|
2 |
/* ====================================================================
|
sl@0
|
3 |
* Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
|
sl@0
|
4 |
*
|
sl@0
|
5 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
6 |
* modification, are permitted provided that the following conditions
|
sl@0
|
7 |
* are met:
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
10 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
13 |
* notice, this list of conditions and the following disclaimer in
|
sl@0
|
14 |
* the documentation and/or other materials provided with the
|
sl@0
|
15 |
* distribution.
|
sl@0
|
16 |
*
|
sl@0
|
17 |
* 3. All advertising materials mentioning features or use of this
|
sl@0
|
18 |
* software must display the following acknowledgment:
|
sl@0
|
19 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
20 |
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
sl@0
|
21 |
*
|
sl@0
|
22 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
sl@0
|
23 |
* endorse or promote products derived from this software without
|
sl@0
|
24 |
* prior written permission. For written permission, please contact
|
sl@0
|
25 |
* licensing@OpenSSL.org.
|
sl@0
|
26 |
*
|
sl@0
|
27 |
* 5. Products derived from this software may not be called "OpenSSL"
|
sl@0
|
28 |
* nor may "OpenSSL" appear in their names without prior written
|
sl@0
|
29 |
* permission of the OpenSSL Project.
|
sl@0
|
30 |
*
|
sl@0
|
31 |
* 6. Redistributions of any form whatsoever must retain the following
|
sl@0
|
32 |
* acknowledgment:
|
sl@0
|
33 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
34 |
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
sl@0
|
35 |
*
|
sl@0
|
36 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
sl@0
|
37 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
38 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
sl@0
|
39 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
sl@0
|
40 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
41 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
sl@0
|
42 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
sl@0
|
43 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
44 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
45 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
sl@0
|
46 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
sl@0
|
47 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
48 |
* ====================================================================
|
sl@0
|
49 |
*
|
sl@0
|
50 |
* This product includes cryptographic software written by Eric Young
|
sl@0
|
51 |
* (eay@cryptsoft.com). This product includes software written by Tim
|
sl@0
|
52 |
* Hudson (tjh@cryptsoft.com).
|
sl@0
|
53 |
*
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
/*
|
sl@0
|
56 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
#include "eng_int.h"
|
sl@0
|
59 |
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
|
sl@0
|
60 |
#include "libcrypto_wsd_macros.h"
|
sl@0
|
61 |
#include "libcrypto_wsd.h"
|
sl@0
|
62 |
#endif
|
sl@0
|
63 |
|
sl@0
|
64 |
/* When querying a ENGINE-specific control command's 'description', this string
|
sl@0
|
65 |
* is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */
|
sl@0
|
66 |
#ifndef EMULATOR
|
sl@0
|
67 |
static const char *int_no_description = "";
|
sl@0
|
68 |
#else
|
sl@0
|
69 |
static const char *const int_no_description = "";
|
sl@0
|
70 |
#endif
|
sl@0
|
71 |
|
sl@0
|
72 |
/* These internal functions handle 'CMD'-related control commands when the
|
sl@0
|
73 |
* ENGINE in question has asked us to take care of it (ie. the ENGINE did not
|
sl@0
|
74 |
* set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */
|
sl@0
|
75 |
|
sl@0
|
76 |
static int int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
if((defn->cmd_num == 0) || (defn->cmd_name == NULL))
|
sl@0
|
79 |
return 1;
|
sl@0
|
80 |
return 0;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
static int int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
int idx = 0;
|
sl@0
|
86 |
while(!int_ctrl_cmd_is_null(defn) && (strcmp(defn->cmd_name, s) != 0))
|
sl@0
|
87 |
{
|
sl@0
|
88 |
idx++;
|
sl@0
|
89 |
defn++;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
if(int_ctrl_cmd_is_null(defn))
|
sl@0
|
92 |
/* The given name wasn't found */
|
sl@0
|
93 |
return -1;
|
sl@0
|
94 |
return idx;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
int idx = 0;
|
sl@0
|
100 |
/* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So
|
sl@0
|
101 |
* our searches don't need to take any longer than necessary. */
|
sl@0
|
102 |
while(!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num))
|
sl@0
|
103 |
{
|
sl@0
|
104 |
idx++;
|
sl@0
|
105 |
defn++;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
if(defn->cmd_num == num)
|
sl@0
|
108 |
return idx;
|
sl@0
|
109 |
/* The given cmd_num wasn't found */
|
sl@0
|
110 |
return -1;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p,
|
sl@0
|
114 |
void (*f)(void))
|
sl@0
|
115 |
{
|
sl@0
|
116 |
int idx;
|
sl@0
|
117 |
char *s = (char *)p;
|
sl@0
|
118 |
/* Take care of the easy one first (eg. it requires no searches) */
|
sl@0
|
119 |
if(cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
if((e->cmd_defns == NULL) || int_ctrl_cmd_is_null(e->cmd_defns))
|
sl@0
|
122 |
return 0;
|
sl@0
|
123 |
return e->cmd_defns->cmd_num;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
/* One or two commands require that "p" be a valid string buffer */
|
sl@0
|
126 |
if((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) ||
|
sl@0
|
127 |
(cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) ||
|
sl@0
|
128 |
(cmd == ENGINE_CTRL_GET_DESC_FROM_CMD))
|
sl@0
|
129 |
{
|
sl@0
|
130 |
if(s == NULL)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
|
sl@0
|
133 |
ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
134 |
return -1;
|
sl@0
|
135 |
}
|
sl@0
|
136 |
}
|
sl@0
|
137 |
/* Now handle cmd_name -> cmd_num conversion */
|
sl@0
|
138 |
if(cmd == ENGINE_CTRL_GET_CMD_FROM_NAME)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_name(
|
sl@0
|
141 |
e->cmd_defns, s)) < 0))
|
sl@0
|
142 |
{
|
sl@0
|
143 |
ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
|
sl@0
|
144 |
ENGINE_R_INVALID_CMD_NAME);
|
sl@0
|
145 |
return -1;
|
sl@0
|
146 |
}
|
sl@0
|
147 |
return e->cmd_defns[idx].cmd_num;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
/* For the rest of the commands, the 'long' argument must specify a
|
sl@0
|
150 |
* valie command number - so we need to conduct a search. */
|
sl@0
|
151 |
if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_num(e->cmd_defns,
|
sl@0
|
152 |
(unsigned int)i)) < 0))
|
sl@0
|
153 |
{
|
sl@0
|
154 |
ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
|
sl@0
|
155 |
ENGINE_R_INVALID_CMD_NUMBER);
|
sl@0
|
156 |
return -1;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
/* Now the logic splits depending on command type */
|
sl@0
|
159 |
switch(cmd)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
|
sl@0
|
162 |
idx++;
|
sl@0
|
163 |
if(int_ctrl_cmd_is_null(e->cmd_defns + idx))
|
sl@0
|
164 |
/* end-of-list */
|
sl@0
|
165 |
return 0;
|
sl@0
|
166 |
else
|
sl@0
|
167 |
return e->cmd_defns[idx].cmd_num;
|
sl@0
|
168 |
case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
|
sl@0
|
169 |
return strlen(e->cmd_defns[idx].cmd_name);
|
sl@0
|
170 |
case ENGINE_CTRL_GET_NAME_FROM_CMD:
|
sl@0
|
171 |
return BIO_snprintf(s,strlen(e->cmd_defns[idx].cmd_name) + 1,
|
sl@0
|
172 |
"%s", e->cmd_defns[idx].cmd_name);
|
sl@0
|
173 |
case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
|
sl@0
|
174 |
if(e->cmd_defns[idx].cmd_desc)
|
sl@0
|
175 |
return strlen(e->cmd_defns[idx].cmd_desc);
|
sl@0
|
176 |
return strlen(int_no_description);
|
sl@0
|
177 |
case ENGINE_CTRL_GET_DESC_FROM_CMD:
|
sl@0
|
178 |
if(e->cmd_defns[idx].cmd_desc)
|
sl@0
|
179 |
return BIO_snprintf(s,
|
sl@0
|
180 |
strlen(e->cmd_defns[idx].cmd_desc) + 1,
|
sl@0
|
181 |
"%s", e->cmd_defns[idx].cmd_desc);
|
sl@0
|
182 |
return BIO_snprintf(s, strlen(int_no_description) + 1,"%s",
|
sl@0
|
183 |
int_no_description);
|
sl@0
|
184 |
case ENGINE_CTRL_GET_CMD_FLAGS:
|
sl@0
|
185 |
return e->cmd_defns[idx].cmd_flags;
|
sl@0
|
186 |
}
|
sl@0
|
187 |
/* Shouldn't really be here ... */
|
sl@0
|
188 |
ENGINEerr(ENGINE_F_INT_CTRL_HELPER,ENGINE_R_INTERNAL_LIST_ERROR);
|
sl@0
|
189 |
return -1;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
EXPORT_C int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
|
sl@0
|
193 |
{
|
sl@0
|
194 |
int ctrl_exists, ref_exists;
|
sl@0
|
195 |
if(e == NULL)
|
sl@0
|
196 |
{
|
sl@0
|
197 |
ENGINEerr(ENGINE_F_ENGINE_CTRL,ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
198 |
return 0;
|
sl@0
|
199 |
}
|
sl@0
|
200 |
CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
|
sl@0
|
201 |
ref_exists = ((e->struct_ref > 0) ? 1 : 0);
|
sl@0
|
202 |
CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
|
sl@0
|
203 |
ctrl_exists = ((e->ctrl == NULL) ? 0 : 1);
|
sl@0
|
204 |
if(!ref_exists)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_REFERENCE);
|
sl@0
|
207 |
return 0;
|
sl@0
|
208 |
}
|
sl@0
|
209 |
/* Intercept any "root-level" commands before trying to hand them on to
|
sl@0
|
210 |
* ctrl() handlers. */
|
sl@0
|
211 |
switch(cmd)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
case ENGINE_CTRL_HAS_CTRL_FUNCTION:
|
sl@0
|
214 |
return ctrl_exists;
|
sl@0
|
215 |
case ENGINE_CTRL_GET_FIRST_CMD_TYPE:
|
sl@0
|
216 |
case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
|
sl@0
|
217 |
case ENGINE_CTRL_GET_CMD_FROM_NAME:
|
sl@0
|
218 |
case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
|
sl@0
|
219 |
case ENGINE_CTRL_GET_NAME_FROM_CMD:
|
sl@0
|
220 |
case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
|
sl@0
|
221 |
case ENGINE_CTRL_GET_DESC_FROM_CMD:
|
sl@0
|
222 |
case ENGINE_CTRL_GET_CMD_FLAGS:
|
sl@0
|
223 |
if(ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL))
|
sl@0
|
224 |
return int_ctrl_helper(e,cmd,i,p,f);
|
sl@0
|
225 |
if(!ctrl_exists)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
|
sl@0
|
228 |
/* For these cmd-related functions, failure is indicated
|
sl@0
|
229 |
* by a -1 return value (because 0 is used as a valid
|
sl@0
|
230 |
* return in some places). */
|
sl@0
|
231 |
return -1;
|
sl@0
|
232 |
}
|
sl@0
|
233 |
default:
|
sl@0
|
234 |
break;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
/* Anything else requires a ctrl() handler to exist. */
|
sl@0
|
237 |
if(!ctrl_exists)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
|
sl@0
|
240 |
return 0;
|
sl@0
|
241 |
}
|
sl@0
|
242 |
return e->ctrl(e, cmd, i, p, f);
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
EXPORT_C int ENGINE_cmd_is_executable(ENGINE *e, int cmd)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
int flags;
|
sl@0
|
248 |
if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, NULL, NULL)) < 0)
|
sl@0
|
249 |
{
|
sl@0
|
250 |
ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,
|
sl@0
|
251 |
ENGINE_R_INVALID_CMD_NUMBER);
|
sl@0
|
252 |
return 0;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
if(!(flags & ENGINE_CMD_FLAG_NO_INPUT) &&
|
sl@0
|
255 |
!(flags & ENGINE_CMD_FLAG_NUMERIC) &&
|
sl@0
|
256 |
!(flags & ENGINE_CMD_FLAG_STRING))
|
sl@0
|
257 |
return 0;
|
sl@0
|
258 |
return 1;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
EXPORT_C int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
|
sl@0
|
262 |
long i, void *p, void (*f)(void), int cmd_optional)
|
sl@0
|
263 |
{
|
sl@0
|
264 |
int num;
|
sl@0
|
265 |
|
sl@0
|
266 |
if((e == NULL) || (cmd_name == NULL))
|
sl@0
|
267 |
{
|
sl@0
|
268 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
|
sl@0
|
269 |
ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
270 |
return 0;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
|
sl@0
|
273 |
ENGINE_CTRL_GET_CMD_FROM_NAME,
|
sl@0
|
274 |
0, (void *)cmd_name, NULL)) <= 0))
|
sl@0
|
275 |
{
|
sl@0
|
276 |
/* If the command didn't *have* to be supported, we fake
|
sl@0
|
277 |
* success. This allows certain settings to be specified for
|
sl@0
|
278 |
* multiple ENGINEs and only require a change of ENGINE id
|
sl@0
|
279 |
* (without having to selectively apply settings). Eg. changing
|
sl@0
|
280 |
* from a hardware device back to the regular software ENGINE
|
sl@0
|
281 |
* without editing the config file, etc. */
|
sl@0
|
282 |
if(cmd_optional)
|
sl@0
|
283 |
{
|
sl@0
|
284 |
ERR_clear_error();
|
sl@0
|
285 |
return 1;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
|
sl@0
|
288 |
ENGINE_R_INVALID_CMD_NAME);
|
sl@0
|
289 |
return 0;
|
sl@0
|
290 |
}
|
sl@0
|
291 |
/* Force the result of the control command to 0 or 1, for the reasons
|
sl@0
|
292 |
* mentioned before. */
|
sl@0
|
293 |
if (ENGINE_ctrl(e, num, i, p, f))
|
sl@0
|
294 |
return 1;
|
sl@0
|
295 |
return 0;
|
sl@0
|
296 |
}
|
sl@0
|
297 |
|
sl@0
|
298 |
EXPORT_C int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
|
sl@0
|
299 |
int cmd_optional)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
int num, flags;
|
sl@0
|
302 |
long l;
|
sl@0
|
303 |
char *ptr;
|
sl@0
|
304 |
if((e == NULL) || (cmd_name == NULL))
|
sl@0
|
305 |
{
|
sl@0
|
306 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
|
sl@0
|
307 |
ERR_R_PASSED_NULL_PARAMETER);
|
sl@0
|
308 |
return 0;
|
sl@0
|
309 |
}
|
sl@0
|
310 |
if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
|
sl@0
|
311 |
ENGINE_CTRL_GET_CMD_FROM_NAME,
|
sl@0
|
312 |
0, (void *)cmd_name, NULL)) <= 0))
|
sl@0
|
313 |
{
|
sl@0
|
314 |
/* If the command didn't *have* to be supported, we fake
|
sl@0
|
315 |
* success. This allows certain settings to be specified for
|
sl@0
|
316 |
* multiple ENGINEs and only require a change of ENGINE id
|
sl@0
|
317 |
* (without having to selectively apply settings). Eg. changing
|
sl@0
|
318 |
* from a hardware device back to the regular software ENGINE
|
sl@0
|
319 |
* without editing the config file, etc. */
|
sl@0
|
320 |
if(cmd_optional)
|
sl@0
|
321 |
{
|
sl@0
|
322 |
ERR_clear_error();
|
sl@0
|
323 |
return 1;
|
sl@0
|
324 |
}
|
sl@0
|
325 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
|
sl@0
|
326 |
ENGINE_R_INVALID_CMD_NAME);
|
sl@0
|
327 |
return 0;
|
sl@0
|
328 |
}
|
sl@0
|
329 |
if(!ENGINE_cmd_is_executable(e, num))
|
sl@0
|
330 |
{
|
sl@0
|
331 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
|
sl@0
|
332 |
ENGINE_R_CMD_NOT_EXECUTABLE);
|
sl@0
|
333 |
return 0;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, NULL, NULL)) < 0)
|
sl@0
|
336 |
{
|
sl@0
|
337 |
/* Shouldn't happen, given that ENGINE_cmd_is_executable()
|
sl@0
|
338 |
* returned success. */
|
sl@0
|
339 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
|
sl@0
|
340 |
ENGINE_R_INTERNAL_LIST_ERROR);
|
sl@0
|
341 |
return 0;
|
sl@0
|
342 |
}
|
sl@0
|
343 |
/* If the command takes no input, there must be no input. And vice
|
sl@0
|
344 |
* versa. */
|
sl@0
|
345 |
if(flags & ENGINE_CMD_FLAG_NO_INPUT)
|
sl@0
|
346 |
{
|
sl@0
|
347 |
if(arg != NULL)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
|
sl@0
|
350 |
ENGINE_R_COMMAND_TAKES_NO_INPUT);
|
sl@0
|
351 |
return 0;
|
sl@0
|
352 |
}
|
sl@0
|
353 |
/* We deliberately force the result of ENGINE_ctrl() to 0 or 1
|
sl@0
|
354 |
* rather than returning it as "return data". This is to ensure
|
sl@0
|
355 |
* usage of these commands is consistent across applications and
|
sl@0
|
356 |
* that certain applications don't understand it one way, and
|
sl@0
|
357 |
* others another. */
|
sl@0
|
358 |
if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
|
sl@0
|
359 |
return 1;
|
sl@0
|
360 |
return 0;
|
sl@0
|
361 |
}
|
sl@0
|
362 |
/* So, we require input */
|
sl@0
|
363 |
if(arg == NULL)
|
sl@0
|
364 |
{
|
sl@0
|
365 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
|
sl@0
|
366 |
ENGINE_R_COMMAND_TAKES_INPUT);
|
sl@0
|
367 |
return 0;
|
sl@0
|
368 |
}
|
sl@0
|
369 |
/* If it takes string input, that's easy */
|
sl@0
|
370 |
if(flags & ENGINE_CMD_FLAG_STRING)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
/* Same explanation as above */
|
sl@0
|
373 |
if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
|
sl@0
|
374 |
return 1;
|
sl@0
|
375 |
return 0;
|
sl@0
|
376 |
}
|
sl@0
|
377 |
/* If it doesn't take numeric either, then it is unsupported for use in
|
sl@0
|
378 |
* a config-setting situation, which is what this function is for. This
|
sl@0
|
379 |
* should never happen though, because ENGINE_cmd_is_executable() was
|
sl@0
|
380 |
* used. */
|
sl@0
|
381 |
if(!(flags & ENGINE_CMD_FLAG_NUMERIC))
|
sl@0
|
382 |
{
|
sl@0
|
383 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
|
sl@0
|
384 |
ENGINE_R_INTERNAL_LIST_ERROR);
|
sl@0
|
385 |
return 0;
|
sl@0
|
386 |
}
|
sl@0
|
387 |
l = strtol(arg, &ptr, 10);
|
sl@0
|
388 |
if((arg == ptr) || (*ptr != '\0'))
|
sl@0
|
389 |
{
|
sl@0
|
390 |
ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
|
sl@0
|
391 |
ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
|
sl@0
|
392 |
return 0;
|
sl@0
|
393 |
}
|
sl@0
|
394 |
/* Force the result of the control command to 0 or 1, for the reasons
|
sl@0
|
395 |
* mentioned before. */
|
sl@0
|
396 |
if(ENGINE_ctrl(e, num, l, NULL, NULL))
|
sl@0
|
397 |
return 1;
|
sl@0
|
398 |
return 0;
|
sl@0
|
399 |
}
|