xref: /PHP-7.2/ext/pdo_oci/pdo_oci.c (revision 38363f48)
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 	REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_ACTION", (zend_long)PDO_OCI_ATTR_ACTION);
96 	REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long)PDO_OCI_ATTR_CLIENT_INFO);
97 	REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_IDENTIFIER", (zend_long)PDO_OCI_ATTR_CLIENT_IDENTIFIER);
98 	REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_MODULE", (zend_long)PDO_OCI_ATTR_MODULE);
99 
100 	php_pdo_register_driver(&pdo_oci_driver);
101 
102 	// Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
103 	// NLS_LANG is not yet available here.
104 
105 #ifdef ZTS
106 	pdo_oci_env_mutex = tsrm_mutex_alloc();
107 #endif
108 
109 	return SUCCESS;
110 }
111 /* }}} */
112 
113 /* {{{ PHP_RINIT_FUNCTION
114  */
PHP_RINIT_FUNCTION(pdo_oci)115 PHP_RINIT_FUNCTION(pdo_oci)
116 {
117 	if (!pdo_oci_Env) {
118 #ifdef ZTS
119 		tsrm_mutex_lock(pdo_oci_env_mutex);
120 		if (!pdo_oci_Env) { // double-checked locking idiom
121 #endif
122 #if HAVE_OCIENVCREATE
123 		OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
124 #else
125 		OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
126 		OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL);
127 #endif
128 #ifdef ZTS
129 		}
130 		tsrm_mutex_unlock(pdo_oci_env_mutex);
131 #endif
132 	}
133 
134 	return SUCCESS;
135 }
136 /* }}} */
137 
138 /* {{{ PHP_MSHUTDOWN_FUNCTION
139  */
PHP_MSHUTDOWN_FUNCTION(pdo_oci)140 PHP_MSHUTDOWN_FUNCTION(pdo_oci)
141 {
142 	php_pdo_unregister_driver(&pdo_oci_driver);
143 
144 	if (pdo_oci_Env) {
145 		OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
146 	}
147 
148 #ifdef ZTS
149 	tsrm_mutex_free(pdo_oci_env_mutex);
150 #endif
151 
152 	return SUCCESS;
153 }
154 /* }}} */
155 
156 /* {{{ PHP_MINFO_FUNCTION
157  */
PHP_MINFO_FUNCTION(pdo_oci)158 PHP_MINFO_FUNCTION(pdo_oci)
159 {
160 	php_info_print_table_start();
161 	php_info_print_table_header(2, "PDO Driver for OCI 8 and later", "enabled");
162 	php_info_print_table_end();
163 }
164 /* }}} */
165 
166 /*
167  * Local variables:
168  * tab-width: 4
169  * c-basic-offset: 4
170  * End:
171  * vim600: noet sw=4 ts=4 fdm=marker
172  * vim<600: noet sw=4 ts=4
173  */
174