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