-
Notifications
You must be signed in to change notification settings - Fork 3
/
couchdb.c
249 lines (217 loc) · 8.11 KB
/
couchdb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Lochemem Bruno Michael |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "ext/standard/info.h"
#include "php_couchdb.h"
#include "src/php/couch.c"
#include "src/couch/couch.c"
#include "couchdb_arginfo.c"
/* {{{ proto CouchDb CouchDb::connect( array config ) */
PHP_METHOD(CouchDb, connect)
{
couchdb_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto array CouchDb::transaction( array transactions ) */
PHP_METHOD(CouchDb, transaction)
{
couchdb_transaction(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto string|array CouchDb::documents( string database [, array keys ] ) */
PHP_METHOD(CouchDb, documents)
{
couchdb_all_docs(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto string|array Couchdb::databases() */
PHP_METHOD(CouchDb, databases)
{
couchdb_all_dbs(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto string|array CouchDb::uuids( int count ) */
PHP_METHOD(CouchDb, uuids)
{
couchdb_uuids(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto string|array CouchDb::find( string database [, array query ] ) */
PHP_METHOD(CouchDb, find)
{
couchdb_find(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto string|array CouchDb::document( string database [, string documentId ] ) */
PHP_METHOD(CouchDb, document)
{
couchdb_get_doc(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto bool CouchDb::createIndex( string database [, array options ] ) */
PHP_METHOD(CouchDb, createIndex)
{
couchdb_create_index(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto bool CouchDb::createDatabase( string database ) */
PHP_METHOD(CouchDb, createDatabase)
{
couchdb_database_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, HTTP_PUT, 0);
}
/* }}} */
/* {{{ proto bool CouchDb::available() */
PHP_METHOD(CouchDb, available)
{
couchdb_is_available(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto bool CouchDb::insertDocuments( string database [, array documents ] ) */
PHP_METHOD(CouchDb, insertDocuments)
{
couchdb_create_docs(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto bool CouchDb::deleteDocuments( string database [, array documents ] ) */
PHP_METHOD(CouchDb, deleteDocuments)
{
couchdb_delete_docs(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto bool CouchDb::updateDocuments( string database [, array documents ] ) */
PHP_METHOD(CouchDb, updateDocuments)
{
couchdb_update_docs(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto CouchDb CouchDb::session() */
PHP_METHOD(CouchDb, session)
{
couchdb_session_init(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto string|array CouchDb::database( string database ) */
PHP_METHOD(CouchDb, database)
{
couchdb_database_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, HTTP_GET, 1);
}
/* }}} */
/* {{{ proto bool CouchDb::deleteDatabase( string database ) */
PHP_METHOD(CouchDb, deleteDatabase)
{
couchdb_database_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, HTTP_DELETE, 0);
}
/* }}} */
/* {{{ proto string|array CouchDb::changes( string database [, array options ] ) */
PHP_METHOD(CouchDb, changes)
{
couchdb_changes(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
/* {{{ proto string|array CouchDb::view( string database [, string designDocument [, string view [, array options ]]] ) */
PHP_METHOD(CouchDb, view)
{
couchdb_query_view(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
static const zend_function_entry ext_functions[] = {
PHP_ME(CouchDb, connect, arginfo_connect, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(CouchDb, available, arginfo_null, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, databases, arginfo_null, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, documents, arginfo_all_docs, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, uuids, arginfo_uuids, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, find, arginfo_find, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, document, arginfo_get_doc, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, createIndex, arginfo_create_index, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, createDatabase, arginfo_create_db, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, deleteDatabase, arginfo_create_db, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, database, arginfo_create_db, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, insertDocuments, arginfo_create_docs, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, deleteDocuments, arginfo_create_docs, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, updateDocuments, arginfo_create_docs, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, session, arginfo_null, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, changes, arginfo_create_index, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, view, arginfo_query_view, ZEND_ACC_PUBLIC)
PHP_ME(CouchDb, transaction, arginfo_transaction, ZEND_ACC_PUBLIC)
PHP_FE_END};
PHP_MINIT_FUNCTION(couchdb)
{
zend_class_entry couchdb_ce;
zend_class_entry couchdb_exception_ce;
INIT_CLASS_ENTRY(couchdb_ce, "CouchDb", ext_functions);
INIT_CLASS_ENTRY(couchdb_exception_ce, "CouchDbException", NULL);
couch_ce = zend_register_internal_class(&couchdb_ce);
couch_ce->create_object = php_couchdb_connection_create_object;
memcpy(&couchdb_object_handlers, zend_get_std_object_handlers(), sizeof(couchdb_object_handlers));
couchdb_object_handlers.free_obj = php_couchdb_connection_free_object;
couchdb_object_handlers.dtor_obj = php_couchdb_connection_destroy_object;
couchdb_object_handlers.get_properties = php_couchdb_get_properties;
zend_declare_class_constant_long(couch_ce, "RETURN_ARRAY", sizeof("RETURN_ARRAY") - 1, 1);
zend_declare_class_constant_long(couch_ce, "RETURN_JSON", sizeof("RETURN_JSON") - 1, 0);
#ifdef HAVE_SPL
couch_exception_ce = zend_register_internal_class_ex(&couchdb_exception_ce, spl_ce_RuntimeException);
#else
couch_exception_ce = zend_register_internal_class_ex(&couchdb_exception_ce, zend_exception_get_default());
#endif
return SUCCESS;
}
/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(couchdb)
{
#if defined(ZTS) && defined(COMPILE_DL_COUCHDB)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(couchdb)
{
php_info_print_table_start();
php_info_print_table_header(2, "couchdb support", "enabled");
php_info_print_table_header(2, "couchdb version", PHP_COUCHDB_VERSION);
php_info_print_table_header(2, "couchdb async transaction support",
#ifdef ASYNC_H
"enabled"
#else
"disabled"
#endif
);
php_info_print_table_end();
}
/* }}} */
/* {{{ couchdb_module_entry */
zend_module_entry couchdb_module_entry = {
STANDARD_MODULE_HEADER,
"couchdb", /* Extension name */
ext_functions, /* zend_function_entry */
PHP_MINIT(couchdb), /* PHP_MINIT - Module initialization */
NULL, /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(couchdb), /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(couchdb), /* PHP_MINFO - Module info */
PHP_COUCHDB_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES};
/* }}} */
#ifdef COMPILE_DL_COUCHDB
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
ZEND_GET_MODULE(couchdb)
#endif