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