fix library version in PHPinfo
[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-events.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 if (libpq_v < 100000) {
109 slprintf(libpq_version, sizeof(libpq_version), "%d.%d.%d", libpq_v/10000, libpq_v/100%100, libpq_v%100);
110 } else {
111 slprintf(libpq_version, sizeof(libpq_version), "%d.%d", libpq_v/10000, libpq_v%100);
112 }
113 #endif
114 php_info_print_table_row(3, "libpq", PHP_PQ_LIBVERSION, libpq_version);
115 php_info_print_table_end();
116 }
117
118 static const zend_function_entry pq_functions[] = {
119 {0}
120 };
121
122 static zend_module_dep pq_module_deps[] = {
123 ZEND_MOD_REQUIRED("raphf")
124 ZEND_MOD_REQUIRED("spl")
125 ZEND_MOD_OPTIONAL("json")
126 ZEND_MOD_END
127 };
128
129 zend_module_entry pq_module_entry = {
130 STANDARD_MODULE_HEADER_EX,
131 NULL,
132 pq_module_deps,
133 "pq",
134 pq_functions,
135 PHP_MINIT(pq),
136 PHP_MSHUTDOWN(pq),
137 NULL,/*PHP_RINIT(pq),*/
138 NULL,/*PHP_RSHUTDOWN(pq),*/
139 PHP_MINFO(pq),
140 PHP_PQ_VERSION,
141 STANDARD_MODULE_PROPERTIES
142 };
143
144 #ifdef COMPILE_DL_PQ
145 ZEND_GET_MODULE(pq)
146 #endif
147
148
149 /*
150 * Local variables:
151 * tab-width: 4
152 * c-basic-offset: 4
153 * End:
154 * vim600: noet sw=4 ts=4 fdm=marker
155 * vim<600: noet sw=4 ts=4
156 */