1 /*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Wez Furlong <wez@php.net> |
14 +----------------------------------------------------------------------+
15 */
16
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include "php.h"
22 #include "php_ini.h"
23 #include "ext/standard/info.h"
24 #include "pdo/php_pdo.h"
25 #include "pdo/php_pdo_driver.h"
26 #include "php_pdo_oci.h"
27 #include "php_pdo_oci_int.h"
28 #ifdef ZTS
29 #include <TSRM/TSRM.h>
30 #endif
31
32 /* {{{ pdo_oci_module_entry */
33
34 static const zend_module_dep pdo_oci_deps[] = {
35 ZEND_MOD_REQUIRED("pdo")
36 ZEND_MOD_END
37 };
38
39 zend_module_entry pdo_oci_module_entry = {
40 STANDARD_MODULE_HEADER_EX, NULL,
41 pdo_oci_deps,
42 "PDO_OCI",
43 NULL,
44 PHP_MINIT(pdo_oci),
45 PHP_MSHUTDOWN(pdo_oci),
46 PHP_RINIT(pdo_oci),
47 NULL,
48 PHP_MINFO(pdo_oci),
49 PHP_PDO_OCI_VERSION,
50 STANDARD_MODULE_PROPERTIES
51 };
52 /* }}} */
53
54 #ifdef COMPILE_DL_PDO_OCI
55 ZEND_GET_MODULE(pdo_oci)
56 #endif
57
58 const ub4 PDO_OCI_INIT_MODE =
59 #if 0 && defined(OCI_SHARED)
60 /* shared mode is known to be bad for PHP */
61 OCI_SHARED
62 #else
63 OCI_DEFAULT
64 #endif
65 #ifdef OCI_OBJECT
66 |OCI_OBJECT
67 #endif
68 #ifdef ZTS
69 |OCI_THREADED
70 #endif
71 ;
72
73 /* true global environment */
74 OCIEnv *pdo_oci_Env = NULL;
75
76 #ifdef ZTS
77 /* lock for pdo_oci_Env initialization */
78 static MUTEX_T pdo_oci_env_mutex;
79 #endif
80
81 /* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(pdo_oci)82 PHP_MINIT_FUNCTION(pdo_oci)
83 {
84 REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_ACTION", (zend_long)PDO_OCI_ATTR_ACTION);
85 REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long)PDO_OCI_ATTR_CLIENT_INFO);
86 REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_IDENTIFIER", (zend_long)PDO_OCI_ATTR_CLIENT_IDENTIFIER);
87 REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_MODULE", (zend_long)PDO_OCI_ATTR_MODULE);
88 REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CALL_TIMEOUT", (zend_long)PDO_OCI_ATTR_CALL_TIMEOUT);
89
90 if (FAILURE == php_pdo_register_driver(&pdo_oci_driver)) {
91 return FAILURE;
92 }
93
94 // Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
95 // NLS_LANG is not yet available here.
96
97 #ifdef ZTS
98 pdo_oci_env_mutex = tsrm_mutex_alloc();
99 #endif
100
101 return SUCCESS;
102 }
103 /* }}} */
104
105 /* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(pdo_oci)106 PHP_RINIT_FUNCTION(pdo_oci)
107 {
108 if (!pdo_oci_Env) {
109 #ifdef ZTS
110 tsrm_mutex_lock(pdo_oci_env_mutex);
111 if (!pdo_oci_Env) { // double-checked locking idiom
112 #endif
113 #ifdef HAVE_OCIENVCREATE
114 OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
115 #else
116 OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
117 OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL);
118 #endif
119 #ifdef ZTS
120 }
121 tsrm_mutex_unlock(pdo_oci_env_mutex);
122 #endif
123 }
124
125 return SUCCESS;
126 }
127 /* }}} */
128
129 /* {{{ PHP_MSHUTDOWN_FUNCTION */
PHP_MSHUTDOWN_FUNCTION(pdo_oci)130 PHP_MSHUTDOWN_FUNCTION(pdo_oci)
131 {
132 php_pdo_unregister_driver(&pdo_oci_driver);
133
134 if (pdo_oci_Env) {
135 OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
136 }
137
138 #ifdef ZTS
139 tsrm_mutex_free(pdo_oci_env_mutex);
140 #endif
141
142 return SUCCESS;
143 }
144 /* }}} */
145
146 /* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(pdo_oci)147 PHP_MINFO_FUNCTION(pdo_oci)
148 {
149 php_info_print_table_start();
150 php_info_print_table_row(2, "PDO Driver for OCI 8 and later", "enabled");
151 php_info_print_table_end();
152 }
153 /* }}} */
154