1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 5                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 2013-2016 Jakub Zelenka                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Author: Jakub Zelenka <bukka@php.net>                                |
16   +----------------------------------------------------------------------+
17 */
18 
19 #include "php.h"
20 #include "php_crypto.h"
21 #include "php_crypto_object.h"
22 
23 #include <openssl/objects.h>
24 
25 /* do all parameter structure */
26 typedef struct {
27 	zend_bool aliases;
28 	char *prefix;
29 	phpc_str_size_t prefix_len;
30 	zval *return_value;
31 } php_crypto_object_do_all_param;
32 
33 /* {{{ php_crypto_object_do_all */
34 static void php_crypto_object_do_all(const OBJ_NAME *name, void *arg)
35 {
36 	php_crypto_object_do_all_param *pp = (php_crypto_object_do_all_param *) arg;
37 	if ((pp->aliases || name->alias == 0) &&
38 			(!pp->prefix || !strncmp(name->name, pp->prefix, pp->prefix_len))) {
39 		PHPC_ARRAY_ADD_NEXT_INDEX_CSTR(pp->return_value, (char *) name->name);
40 	}
41 }
42 /* }}} */
43 
44 /* {{{ php_crypto_object_fn_get_names */
45 PHP_CRYPTO_API void php_crypto_object_fn_get_names(INTERNAL_FUNCTION_PARAMETERS, int type)
46 {
47 	php_crypto_object_do_all_param param = { 0, NULL, 0, return_value };
48 
49 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bs",
50 			&param.aliases, &param.prefix, &param.prefix_len) == FAILURE) {
51 		return;
52 	}
53 	array_init(return_value);
54 	OBJ_NAME_do_all_sorted(type, php_crypto_object_do_all, &param);
55 }
56 /* }}} */
57