xref: /PHP-5.3/ext/mysqli/mysqli_embedded.c (revision a2045ff3)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 5                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2013 The PHP Group                                |
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: Georg Richter <georg@php.net>                                |
16   +----------------------------------------------------------------------+
17 
18 */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include <signal.h>
24 
25 #include "php.h"
26 #include "php_ini.h"
27 #include "ext/standard/info.h"
28 #include "php_mysqli_structs.h"
29 
30 /* {{{ proto bool mysqli_embedded_server_start(bool start, array arguments, array groups)
31    initialize and start embedded server */
PHP_FUNCTION(mysqli_embedded_server_start)32 PHP_FUNCTION(mysqli_embedded_server_start)
33 {
34 #ifdef HAVE_EMBEDDED_MYSQLI
35 	long start;
36 	zval *args;
37 	zval *grps;
38 
39 	int	argc = 0;
40 	char **arguments;
41 	char **groups;
42 	HashPosition pos;
43 	int index, rc;
44 
45 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa", &start, &args, &grps) == FAILURE) {
46 		return;
47 	}
48 
49 	if (!start) {
50 		mysql_server_init(-1,NULL, NULL);
51 		RETURN_TRUE;
52 	}
53 	/* get arguments */
54 	if ((argc = zend_hash_num_elements(HASH_OF(args)))) {
55 		arguments = safe_emalloc(sizeof(char *), argc + 1, 0);
56 		arguments[0] = NULL;
57 
58 		zend_hash_internal_pointer_reset_ex(HASH_OF(args), &pos);
59 
60 		for (index = 0;; zend_hash_move_forward_ex(HASH_OF(args), &pos))	{
61 			zval **item;
62 
63 			if (zend_hash_get_current_data_ex(HASH_OF(args), (void **) &item, &pos) == FAILURE) {
64 				break;
65 			}
66 
67 			convert_to_string_ex(item);
68 
69 			arguments[++index] = Z_STRVAL_PP(item);
70 		}
71 		argc++;
72 	}
73 
74 	/* get groups */
75 	if ((zend_hash_num_elements(HASH_OF(grps)))) {
76 		groups = safe_emalloc(sizeof(char *), zend_hash_num_elements(HASH_OF(grps)) + 1, 0);
77 		groups[0] = NULL;
78 
79 		zend_hash_internal_pointer_reset_ex(HASH_OF(grps), &pos);
80 
81 		for (index = 0;; zend_hash_move_forward_ex(HASH_OF(grps), &pos))	{
82 			zval ** item;
83 
84 			if (zend_hash_get_current_data_ex(HASH_OF(grps), (void **) &item, &pos) == FAILURE) {
85 				break;
86 			}
87 
88 			convert_to_string_ex(item);
89 
90 			groups[++index] = Z_STRVAL_PP(item);
91 		}
92 		groups[index] = NULL;
93 	} else {
94 		groups = safe_emalloc(sizeof(char *), 1, 0);
95 		groups[0] = NULL;
96 	}
97 
98 	rc = mysql_server_init(argc, arguments, groups);
99 
100 	if (argc) {
101 		efree(arguments);
102 	}
103 	efree(groups);
104 
105 	if (rc) {
106 		RETURN_FALSE;
107 	}
108 	RETURN_TRUE;
109 #endif
110 }
111 /* }}} */
112 
113 /* {{{ proto void mysqli_embedded_server_end(void)
114 */
PHP_FUNCTION(mysqli_embedded_server_end)115 PHP_FUNCTION(mysqli_embedded_server_end)
116 {
117 #ifdef HAVE_MYSQLI_EMBEDDED
118 	mysql_server_end();
119 #endif
120 }
121 /* }}} */
122 
123 /*
124  * Local variables:
125  * tab-width: 4
126  * c-basic-offset: 4
127  * indent-tabs-mode: t
128  * End:
129  * vim600: noet sw=4 ts=4 fdm=marker
130  * vim<600: noet sw=4 ts=4
131  */
132