re-simplify
[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 #define PHP_MINIT_CALL(i) do { \
37 if (SUCCESS != PHP_MINIT(i)(type, module_number TSRMLS_CC)) { \
38 return FAILURE; \
39 } \
40 } while(0)
41
42 static PHP_MINIT_FUNCTION(pq)
43 {
44 PHP_MINIT_CALL(pq_misc);
45 PHP_MINIT_CALL(pqexc);
46
47 PHP_MINIT_CALL(pqconn);
48 PHP_MINIT_CALL(pqcancel);
49 PHP_MINIT_CALL(pqtypes);
50
51 PHP_MINIT_CALL(pqres);
52 PHP_MINIT_CALL(pqstm);
53 PHP_MINIT_CALL(pqtxn);
54 PHP_MINIT_CALL(pqcur);
55
56 PHP_MINIT_CALL(pqcopy);
57 PHP_MINIT_CALL(pqlob);
58
59 return php_persistent_handle_provide(ZEND_STRL("pq\\Connection"), php_pqconn_get_resource_factory_ops(), NULL, NULL TSRMLS_CC);
60 }
61
62 #define PHP_MSHUT_CALL(i) do { \
63 if (SUCCESS != PHP_MSHUTDOWN(i)(type, module_number TSRMLS_CC)) { \
64 return FAILURE; \
65 } \
66 } while(0)
67
68 static PHP_MSHUTDOWN_FUNCTION(pq)
69 {
70 php_persistent_handle_cleanup(ZEND_STRL("pq\\Connection"), NULL, 0 TSRMLS_CC);
71
72 PHP_MSHUT_CALL(pqlob);
73 PHP_MSHUT_CALL(pqcopy);
74 PHP_MSHUT_CALL(pqcur);
75 PHP_MSHUT_CALL(pqtxn);
76 PHP_MSHUT_CALL(pqstm);
77 PHP_MSHUT_CALL(pqres);
78 PHP_MSHUT_CALL(pqtypes);
79 PHP_MSHUT_CALL(pqcancel);
80 PHP_MSHUT_CALL(pqconn);
81
82 return SUCCESS;
83 }
84
85 static PHP_MINFO_FUNCTION(pq)
86 {
87 #ifdef HAVE_PQLIBVERSION
88 int libpq_v;
89 #endif
90 char libpq_version[10] = "pre-9.1";
91
92 php_info_print_table_start();
93 php_info_print_table_header(2, "PQ Support", "enabled");
94 php_info_print_table_row(2, "Extension Version", PHP_PQ_VERSION);
95 php_info_print_table_end();
96
97 php_info_print_table_start();
98 php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
99 #ifdef HAVE_PQLIBVERSION
100 libpq_v = PQlibVersion();
101 slprintf(libpq_version, sizeof(libpq_version), "%d.%d.%d", libpq_v/10000%100, libpq_v/100%100, libpq_v%100);
102 #endif
103 php_info_print_table_row(3, "libpq", PHP_PQ_LIBVERSION, libpq_version);
104 php_info_print_table_end();
105 }
106
107 static const zend_function_entry pq_functions[] = {
108 {0}
109 };
110
111 static zend_module_dep pq_module_deps[] = {
112 ZEND_MOD_REQUIRED("raphf")
113 ZEND_MOD_REQUIRED("spl")
114 ZEND_MOD_OPTIONAL("json")
115 ZEND_MOD_END
116 };
117
118 zend_module_entry pq_module_entry = {
119 STANDARD_MODULE_HEADER_EX,
120 NULL,
121 pq_module_deps,
122 "pq",
123 pq_functions,
124 PHP_MINIT(pq),
125 PHP_MSHUTDOWN(pq),
126 NULL,/*PHP_RINIT(pq),*/
127 NULL,/*PHP_RSHUTDOWN(pq),*/
128 PHP_MINFO(pq),
129 PHP_PQ_VERSION,
130 STANDARD_MODULE_PROPERTIES
131 };
132
133 #ifdef COMPILE_DL_PQ
134 ZEND_GET_MODULE(pq)
135 #endif
136
137
138 /*
139 * Local variables:
140 * tab-width: 4
141 * c-basic-offset: 4
142 * End:
143 * vim600: noet sw=4 ts=4 fdm=marker
144 * vim<600: noet sw=4 ts=4
145 */