Merge branch 'v1.0.x'
[m6w6/ext-pq] / src / php_pq_module.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: pq |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2013, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
16
17
18 #include <php.h>
19 #include <ext/standard/info.h>
20
21 #include <libpq-fe.h>
22
23 #include "php_pq.h"
24 #include "php_pq_misc.h"
25 #include "php_pqcancel.h"
26 #include "php_pqconn.h"
27 #include "php_pqcopy.h"
28 #include "php_pqcur.h"
29 #include "php_pqexc.h"
30 #include "php_pqlob.h"
31 #include "php_pqres.h"
32 #include "php_pqstm.h"
33 #include "php_pqtxn.h"
34 #include "php_pqtypes.h"
35
36 ZEND_DECLARE_MODULE_GLOBALS(php_pq);
37
38 static void php_pq_globals_init_once(zend_php_pq_globals *G)
39 {
40 memset(G, 0, sizeof(*G));
41 }
42
43 #define PHP_MINIT_CALL(i) do { \
44 if (SUCCESS != PHP_MINIT(i)(type, module_number)) { \
45 return FAILURE; \
46 } \
47 } while(0)
48
49 static PHP_MINIT_FUNCTION(pq)
50 {
51 ZEND_INIT_MODULE_GLOBALS(php_pq, php_pq_globals_init_once, NULL);
52
53 PHP_MINIT_CALL(pq_misc);
54 PHP_MINIT_CALL(pqexc);
55
56 PHP_MINIT_CALL(pqconn);
57 PHP_MINIT_CALL(pqcancel);
58 PHP_MINIT_CALL(pqtypes);
59
60 PHP_MINIT_CALL(pqres);
61 PHP_MINIT_CALL(pqstm);
62 PHP_MINIT_CALL(pqtxn);
63 PHP_MINIT_CALL(pqcur);
64
65 PHP_MINIT_CALL(pqcopy);
66 PHP_MINIT_CALL(pqlob);
67
68 return SUCCESS;
69 }
70
71 #define PHP_MSHUT_CALL(i) do { \
72 if (SUCCESS != PHP_MSHUTDOWN(i)(type, module_number)) { \
73 return FAILURE; \
74 } \
75 } while(0)
76
77 static PHP_MSHUTDOWN_FUNCTION(pq)
78 {
79 PHP_MSHUT_CALL(pqlob);
80 PHP_MSHUT_CALL(pqcopy);
81 PHP_MSHUT_CALL(pqcur);
82 PHP_MSHUT_CALL(pqtxn);
83 PHP_MSHUT_CALL(pqstm);
84 PHP_MSHUT_CALL(pqres);
85 PHP_MSHUT_CALL(pqtypes);
86 PHP_MSHUT_CALL(pqcancel);
87 PHP_MSHUT_CALL(pqconn);
88
89 return SUCCESS;
90 }
91
92 static PHP_MINFO_FUNCTION(pq)
93 {
94 #ifdef HAVE_PQLIBVERSION
95 int libpq_v;
96 #endif
97 char libpq_version[10] = "pre-9.1";
98
99 php_info_print_table_start();
100 php_info_print_table_header(2, "PQ Support", "enabled");
101 php_info_print_table_row(2, "Extension Version", PHP_PQ_VERSION);
102 php_info_print_table_end();
103
104 php_info_print_table_start();
105 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
106 #ifdef HAVE_PQLIBVERSION
107 libpq_v = PQlibVersion();
108 slprintf(libpq_version, sizeof(libpq_version), "%d.%d.%d", libpq_v/10000%100, libpq_v/100%100, libpq_v%100);
109 #endif
110 php_info_print_table_row(3, "libpq", PHP_PQ_LIBVERSION, libpq_version);
111 php_info_print_table_end();
112 }
113
114 static const zend_function_entry pq_functions[] = {
115 {0}
116 };
117
118 static zend_module_dep pq_module_deps[] = {
119 ZEND_MOD_REQUIRED("raphf")
120 ZEND_MOD_REQUIRED("spl")
121 ZEND_MOD_OPTIONAL("json")
122 ZEND_MOD_END
123 };
124
125 zend_module_entry pq_module_entry = {
126 STANDARD_MODULE_HEADER_EX,
127 NULL,
128 pq_module_deps,
129 "pq",
130 pq_functions,
131 PHP_MINIT(pq),
132 PHP_MSHUTDOWN(pq),
133 NULL,/*PHP_RINIT(pq),*/
134 NULL,/*PHP_RSHUTDOWN(pq),*/
135 PHP_MINFO(pq),
136 PHP_PQ_VERSION,
137 STANDARD_MODULE_PROPERTIES
138 };
139
140 #ifdef COMPILE_DL_PQ
141 ZEND_GET_MODULE(pq)
142 #endif
143
144
145 /*
146 * Local variables:
147 * tab-width: 4
148 * c-basic-offset: 4
149 * End:
150 * vim600: noet sw=4 ts=4 fdm=marker
151 * vim<600: noet sw=4 ts=4
152 */