xref: /PHP-7.1/ext/pdo_oci/pdo_oci.c (revision ccd4716e)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2018 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: Wez Furlong <wez@php.net>                                    |
16   +----------------------------------------------------------------------+
17 */
18 
19 /* $Id$ */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include "php.h"
26 #include "php_ini.h"
27 #include "ext/standard/info.h"
28 #include "pdo/php_pdo.h"
29 #include "pdo/php_pdo_driver.h"
30 #include "php_pdo_oci.h"
31 #include "php_pdo_oci_int.h"
32 #ifdef ZTS
33 #include <TSRM/TSRM.h>
34 #endif
35 
36 /* {{{ pdo_oci_functions[] */
37 const zend_function_entry pdo_oci_functions[] = {
38 	PHP_FE_END
39 };
40 /* }}} */
41 
42 /* {{{ pdo_oci_module_entry */
43 
44 static const zend_module_dep pdo_oci_deps[] = {
45 	ZEND_MOD_REQUIRED("pdo")
46 	ZEND_MOD_END
47 };
48 
49 zend_module_entry pdo_oci_module_entry = {
50 	STANDARD_MODULE_HEADER_EX, NULL,
51 	pdo_oci_deps,
52 	"PDO_OCI",
53 	pdo_oci_functions,
54 	PHP_MINIT(pdo_oci),
55 	PHP_MSHUTDOWN(pdo_oci),
56 	PHP_RINIT(pdo_oci),
57 	NULL,
58 	PHP_MINFO(pdo_oci),
59 	PHP_PDO_OCI_VERSION,
60 	STANDARD_MODULE_PROPERTIES
61 };
62 /* }}} */
63 
64 #ifdef COMPILE_DL_PDO_OCI
65 ZEND_GET_MODULE(pdo_oci)
66 #endif
67 
68 const ub4 PDO_OCI_INIT_MODE =
69 #if 0 && defined(OCI_SHARED)
70 			/* shared mode is known to be bad for PHP */
71 			OCI_SHARED
72 #else
73 			OCI_DEFAULT
74 #endif
75 #ifdef OCI_OBJECT
76 			|OCI_OBJECT
77 #endif
78 #ifdef ZTS
79 			|OCI_THREADED
80 #endif
81 			;
82 
83 /* true global environment */
84 OCIEnv *pdo_oci_Env = NULL;
85 
86 #ifdef ZTS
87 /* lock for pdo_oci_Env initialization */
88 static MUTEX_T pdo_oci_env_mutex;
89 #endif
90 
91 /* {{{ PHP_MINIT_FUNCTION
92  */
PHP_MINIT_FUNCTION(pdo_oci)93 PHP_MINIT_FUNCTION(pdo_oci)
94 {
95 	php_pdo_register_driver(&pdo_oci_driver);
96 
97 	// Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
98 	// NLS_LANG is not yet available here.
99 
100 #ifdef ZTS
101 	pdo_oci_env_mutex = tsrm_mutex_alloc();
102 #endif
103 
104 	return SUCCESS;
105 }
106 /* }}} */
107 
108 /* {{{ PHP_RINIT_FUNCTION
109  */
PHP_RINIT_FUNCTION(pdo_oci)110 PHP_RINIT_FUNCTION(pdo_oci)
111 {
112 	if (!pdo_oci_Env) {
113 #ifdef ZTS
114 		tsrm_mutex_lock(pdo_oci_env_mutex);
115 		if (!pdo_oci_Env) { // double-checked locking idiom
116 #endif
117 #if HAVE_OCIENVCREATE
118 		OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
119 #else
120 		OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
121 		OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL);
122 #endif
123 #ifdef ZTS
124 		}
125 		tsrm_mutex_unlock(pdo_oci_env_mutex);
126 #endif
127 	}
128 
129 	return SUCCESS;
130 }
131 /* }}} */
132 
133 /* {{{ PHP_MSHUTDOWN_FUNCTION
134  */
PHP_MSHUTDOWN_FUNCTION(pdo_oci)135 PHP_MSHUTDOWN_FUNCTION(pdo_oci)
136 {
137 	php_pdo_unregister_driver(&pdo_oci_driver);
138 
139 	if (pdo_oci_Env) {
140 		OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
141 	}
142 
143 #ifdef ZTS
144 	tsrm_mutex_free(pdo_oci_env_mutex);
145 #endif
146 
147 	return SUCCESS;
148 }
149 /* }}} */
150 
151 /* {{{ PHP_MINFO_FUNCTION
152  */
PHP_MINFO_FUNCTION(pdo_oci)153 PHP_MINFO_FUNCTION(pdo_oci)
154 {
155 	php_info_print_table_start();
156 	php_info_print_table_header(2, "PDO Driver for OCI 8 and later", "enabled");
157 	php_info_print_table_end();
158 }
159 /* }}} */
160 
161 /*
162  * Local variables:
163  * tab-width: 4
164  * c-basic-offset: 4
165  * End:
166  * vim600: noet sw=4 ts=4 fdm=marker
167  * vim<600: noet sw=4 ts=4
168  */
169