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 | http://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 php_pdo_register_driver(&pdo_oci_driver);
91
92 // Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
93 // NLS_LANG is not yet available here.
94
95 #ifdef ZTS
96 pdo_oci_env_mutex = tsrm_mutex_alloc();
97 #endif
98
99 return SUCCESS;
100 }
101 /* }}} */
102
103 /* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(pdo_oci)104 PHP_RINIT_FUNCTION(pdo_oci)
105 {
106 if (!pdo_oci_Env) {
107 #ifdef ZTS
108 tsrm_mutex_lock(pdo_oci_env_mutex);
109 if (!pdo_oci_Env) { // double-checked locking idiom
110 #endif
111 #ifdef HAVE_OCIENVCREATE
112 OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
113 #else
114 OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
115 OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL);
116 #endif
117 #ifdef ZTS
118 }
119 tsrm_mutex_unlock(pdo_oci_env_mutex);
120 #endif
121 }
122
123 return SUCCESS;
124 }
125 /* }}} */
126
127 /* {{{ PHP_MSHUTDOWN_FUNCTION */
PHP_MSHUTDOWN_FUNCTION(pdo_oci)128 PHP_MSHUTDOWN_FUNCTION(pdo_oci)
129 {
130 php_pdo_unregister_driver(&pdo_oci_driver);
131
132 if (pdo_oci_Env) {
133 OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
134 }
135
136 #ifdef ZTS
137 tsrm_mutex_free(pdo_oci_env_mutex);
138 #endif
139
140 return SUCCESS;
141 }
142 /* }}} */
143
144 /* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(pdo_oci)145 PHP_MINFO_FUNCTION(pdo_oci)
146 {
147 php_info_print_table_start();
148 php_info_print_table_header(2, "PDO Driver for OCI 8 and later", "enabled");
149 php_info_print_table_end();
150 }
151 /* }}} */
152