Develop and Download Open Source Software

Browse CVS Repository

Contents of /xoonips/AL/xnpal.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.31 - (show annotations) (download) (as text)
Wed Feb 9 02:14:15 2005 UTC (19 years, 2 months ago) by aga
Branch: MAIN
Changes since 1.30: +8 -3 lines
File MIME type: text/x-c++src
・initializeDB()にdbtype引数を追加(SQLite用).

1 /*
2 $Revision: 1.30 $
3 XNPAL: XooNiPs Platform Abstract Layer
4
5 zend_parse_parameters??hp4.1.0??綽?荀?
6 .so???<?ゃ?????????荀????????贋????舟??鴻????
7 C++?с????extern "C"{}, BEGIN/END_EXTERN_C()??綽?荀???
8 */
9
10
11 #include <stdio.h>
12 #include "criteria.h"
13 #include "common.h"
14 #include "commonal.h"
15 #include "session.h"
16 #include "group.h"
17 #include "index.h"
18 #include "xnpal.h"
19 #include "amazonbook.h"
20
21 // for inet_aton
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
25
26 // global variables
27
28 PHP_MSHUTDOWN_FUNCTION(xnpalmod)
29 {
30 uninitializeDB();
31 return SUCCESS;
32 }
33
34 /* declaration of functions to be exported */
35 extern "C" {
36 ZEND_FUNCTION(first_module );
37 ZEND_FUNCTION(xnp_initialize_db );
38 ZEND_FUNCTION(xnp_login_user );
39 ZEND_FUNCTION(xnp_logout_user );
40 ZEND_FUNCTION(xnp_create_session );
41 ZEND_FUNCTION(xnp_get_session );
42 ZEND_FUNCTION(xnp_is_activated );
43 ZEND_FUNCTION(xnp_activate );
44 ZEND_FUNCTION(xnp_get_account_count );
45 ZEND_FUNCTION(xnp_delete_account );
46 ZEND_FUNCTION(xnp_get_account );
47 ZEND_FUNCTION(xnp_get_accounts );
48 ZEND_FUNCTION(xnp_insert_account );
49 ZEND_FUNCTION(xnp_update_account );
50 ZEND_FUNCTION(xnp_dump_uids );
51 ZEND_FUNCTION(xnp_get_group_count );
52 ZEND_FUNCTION(xnp_get_groups_by_uid );
53 ZEND_FUNCTION(xnp_is_group_admin );
54 ZEND_FUNCTION(xnp_dump_gids );
55 ZEND_FUNCTION(xnp_dump_group_admins );
56 ZEND_FUNCTION(xnp_delete_member );
57 ZEND_FUNCTION(xnp_insert_member );
58 ZEND_FUNCTION(xnp_get_members );
59 ZEND_FUNCTION(xnp_delete_group );
60 ZEND_FUNCTION(xnp_insert_group );
61 ZEND_FUNCTION(xnp_update_group );
62 ZEND_FUNCTION(xnp_get_group );
63 ZEND_FUNCTION(xnp_get_groups );
64 ZEND_FUNCTION(xnp_is_moderator );
65 ZEND_FUNCTION(xnp_get_uid );
66
67 ZEND_FUNCTION(xnp_get_all_indexes );
68 ZEND_FUNCTION(xnp_get_indexes );
69 ZEND_FUNCTION(xnp_insert_index );
70 ZEND_FUNCTION(xnp_update_index );
71 ZEND_FUNCTION(xnp_delete_index );
72 ZEND_FUNCTION(xnp_get_index );
73 ZEND_FUNCTION(xnp_is_index_readable );
74 ZEND_FUNCTION(xnp_is_index_writable );
75 ZEND_FUNCTION(xnp_swap_index_sort_number );
76
77 ZEND_FUNCTION(xnp_is_valid_session_id );
78 ZEND_FUNCTION(xnp_get_last_error_string );
79
80 ZEND_FUNCTION(xnp_test_criteria );
81 ZEND_FUNCTION(xnp_test_uids );
82
83
84 ZEND_FUNCTION(xnp_get_item_permission );
85 ZEND_FUNCTION(xnp_get_index_permission );
86 ZEND_FUNCTION(xnp_get_certify_permission );
87
88 ZEND_FUNCTION(xnp_get_certify_state );
89 ZEND_FUNCTION(xnp_set_certify_state );
90
91 ZEND_FUNCTION(xnp_insert_change_log );
92 ZEND_FUNCTION(xnp_get_change_logs );
93
94 ZEND_FUNCTION(xnp_get_config_value );
95 ZEND_FUNCTION(xnp_set_config_value );
96
97 ZEND_FUNCTION(xnp_dump_item_id );
98 ZEND_FUNCTION(xnp_get_item_id_by_binder_id );
99 ZEND_FUNCTION(xnp_get_item_id_by_index_id );
100 ZEND_FUNCTION(xnp_get_overlapped_items );
101
102 ZEND_FUNCTION(xnp_insert_item );
103 ZEND_FUNCTION(xnp_update_item );
104 ZEND_FUNCTION(xnp_delete_item );
105 ZEND_FUNCTION(xnp_get_item );
106 ZEND_FUNCTION(xnp_get_items );
107
108 ZEND_FUNCTION(xnp_pubmed_complete );
109 ZEND_FUNCTION(xnp_amazon_complete );
110
111 //ZEND_FUNCTION(xnp_uninitialize_db );
112
113 ZEND_FUNCTION(xnp_register_binder_item );
114 ZEND_FUNCTION(xnp_unregister_binder_item );
115
116 ZEND_FUNCTION(xnp_register_item );
117 ZEND_FUNCTION(xnp_unregister_item );
118
119 ZEND_FUNCTION(xnp_get_uncertified_link );
120 ZEND_FUNCTION(xnp_get_private_item_id );
121
122 ZEND_FUNCTION(xnp_get_item_types );
123 ZEND_FUNCTION(xnp_get_index_id_by_item_id );
124 ZEND_FUNCTION(xnp_get_own_public_item_id );
125
126 };
127 /* compiled function list so Zend knows what's in this module */
128 zend_function_entry xnpalmod_functions[] =
129 {
130 ZEND_FE(first_module ,NULL)
131 ZEND_FE(xnp_initialize_db ,NULL)
132 ZEND_FE(xnp_login_user ,NULL)
133 ZEND_FE(xnp_logout_user ,NULL)
134 ZEND_FE(xnp_create_session ,NULL)
135 ZEND_FE(xnp_get_session ,NULL)
136 ZEND_FE(xnp_is_activated ,NULL)
137 ZEND_FE(xnp_activate ,NULL)
138 ZEND_FE(xnp_get_account_count ,NULL)
139 ZEND_FE(xnp_delete_account ,NULL)
140 ZEND_FE(xnp_get_account ,NULL)
141 ZEND_FE(xnp_get_accounts ,NULL)
142 ZEND_FE(xnp_insert_account ,NULL)
143 ZEND_FE(xnp_update_account ,NULL)
144 ZEND_FE(xnp_dump_uids ,NULL)
145 ZEND_FE(xnp_get_group_count ,NULL)
146 ZEND_FE(xnp_get_groups_by_uid ,NULL)
147 ZEND_FE(xnp_is_group_admin ,NULL)
148 ZEND_FE(xnp_dump_gids ,NULL)
149 ZEND_FE(xnp_dump_group_admins ,NULL)
150 ZEND_FE(xnp_delete_member ,NULL)
151 ZEND_FE(xnp_insert_member ,NULL)
152 ZEND_FE(xnp_get_members ,NULL)
153 ZEND_FE(xnp_delete_group ,NULL)
154 ZEND_FE(xnp_insert_group ,NULL)
155 ZEND_FE(xnp_update_group ,NULL)
156 ZEND_FE(xnp_get_group ,NULL)
157 ZEND_FE(xnp_get_groups ,NULL)
158 ZEND_FE(xnp_is_moderator ,NULL)
159 ZEND_FE(xnp_get_uid ,NULL)
160
161 ZEND_FE(xnp_get_all_indexes ,NULL)
162 ZEND_FE(xnp_get_indexes ,NULL)
163 ZEND_FE(xnp_insert_index ,NULL)
164 ZEND_FE(xnp_update_index ,NULL)
165 ZEND_FE(xnp_delete_index ,NULL)
166 ZEND_FE(xnp_get_index ,NULL)
167 ZEND_FE(xnp_is_index_readable ,NULL)
168 ZEND_FE(xnp_is_index_writable ,NULL)
169 ZEND_FE(xnp_swap_index_sort_number ,NULL)
170
171 ZEND_FE(xnp_is_valid_session_id ,NULL)
172 ZEND_FE(xnp_get_last_error_string ,NULL)
173 ZEND_FE(xnp_test_criteria ,NULL)
174 ZEND_FE(xnp_test_uids ,NULL)
175
176 ZEND_FE(xnp_get_item_permission ,NULL)
177 ZEND_FE(xnp_get_index_permission ,NULL)
178 ZEND_FE(xnp_get_certify_permission ,NULL)
179
180 ZEND_FE(xnp_get_certify_state ,NULL)
181 ZEND_FE(xnp_set_certify_state ,NULL)
182
183 ZEND_FE(xnp_insert_change_log ,NULL)
184 ZEND_FE(xnp_get_change_logs ,NULL)
185
186 ZEND_FE(xnp_get_config_value ,NULL)
187 ZEND_FE(xnp_set_config_value ,NULL)
188
189 ZEND_FE(xnp_dump_item_id ,NULL)
190 ZEND_FE(xnp_get_item_id_by_binder_id ,NULL)
191 ZEND_FE(xnp_get_item_id_by_index_id ,NULL)
192 ZEND_FE(xnp_get_overlapped_items ,NULL)
193
194 ZEND_FE(xnp_insert_item ,NULL)
195 ZEND_FE(xnp_update_item ,NULL)
196 ZEND_FE(xnp_delete_item ,NULL)
197 ZEND_FE(xnp_get_item ,NULL)
198 ZEND_FE(xnp_get_items ,NULL)
199
200 ZEND_FE(xnp_pubmed_complete ,NULL)
201 ZEND_FE(xnp_amazon_complete ,NULL)
202
203 // ZEND_FE(xnp_uninitialize_db ,NULL)
204
205 ZEND_FE(xnp_register_binder_item ,NULL)
206 ZEND_FE(xnp_unregister_binder_item ,NULL)
207
208 ZEND_FE(xnp_register_item ,NULL)
209 ZEND_FE(xnp_unregister_item ,NULL)
210
211 ZEND_FE(xnp_get_uncertified_link ,NULL)
212 ZEND_FE(xnp_get_private_item_id ,NULL)
213
214 ZEND_FE(xnp_get_item_types ,NULL)
215
216 ZEND_FE(xnp_get_index_id_by_item_id ,NULL)
217 ZEND_FE(xnp_get_own_public_item_id ,NULL)
218
219 {NULL, NULL, NULL}
220 };
221
222 /* compiled module information */
223 zend_module_entry xnpalmod_module_entry =
224 {
225 STANDARD_MODULE_HEADER,
226 "Visiome Platform Abstract Layer",
227 xnpalmod_functions,
228 NULL,
229 PHP_MSHUTDOWN(xnpalmod),
230 NULL,
231 NULL,
232 NULL,
233 NO_VERSION_YET,
234 STANDARD_MODULE_PROPERTIES
235 };
236
237 /* implement standard "stub" routine to introduce ourselves to Zend */
238 #if COMPILE_DL_FIRST_MODULE
239 BEGIN_EXTERN_C()
240 ZEND_GET_MODULE(xnpalmod)
241 END_EXTERN_C()
242 #endif
243
244
245 /* implement function that is meant to be made available to PHP */
246 ZEND_FUNCTION(first_module)
247 {
248 long parameter;
249 // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
250 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
251 return;
252 }
253 parameter++;
254 RETURN_LONG(parameter);
255 }
256 /** zval????C????絖?????緇?????
257 */
258 char *getZvalString( zval **p ){
259 convert_to_string_ex(p);
260 return Z_STRVAL_PP(p); //(**p).value.str.val;
261 }
262
263 /** zval????int??緇?????
264 */
265 int getZvalInt( zval **p ){
266 convert_to_long_ex(p);
267 return Z_LVAL_PP(p); // (int)(**p).value.lval;
268 }
269
270 // keylen????鮎??0????????
271 static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
272 zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
273 if ( res == HASH_KEY_IS_STRING ){
274 char *p = new char[keyLen+1];
275 memcpy( p, key, keyLen );
276 p[keyLen] = 0;
277 zend_printf( " key is string[%s]<br>\n", p );
278 }
279 else {
280 zend_printf( " key is integer[%d]<br>\n", index );
281 }
282 }
283
284
285 /** zval*????criteria_t?????????????????????鴻??????紊掩??????getResult()!=RES_OK <br>
286 criteria :
287 array( 'start'=>0, 'rows'=>10,
288 'orders'=>array(
289 array('name'=>'id','order'=>'0'),
290 array('name'=>'timestamp','name'=>'1'), ...)
291 ); ??????就???f?渇????
292 */
293 class zCriteria_t : public criteria {
294 private:
295 result_t result;
296
297 // pz: array('name'=>'timestamp','name'=>'1')
298 // ????????orderby??篏???????申????
299 void setOrder( zval *pz ){
300 char *column = 0;
301 order_t order = (order_t)0;
302
303 HashPosition pos;
304 zval **ppzTmp = 0;
305 int res2;
306 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
307 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
308 char *key = 0;
309 uint keyLen = 0;
310 ulong index = 0;
311 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
312 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
313 //print_hash_key( keyType, key, keyLen, index );
314 if ( strncasecmp( key, "name", keyLen ) == 0 && keyLen == 5 ){
315 SEPARATE_ZVAL(ppzTmp);
316 column = getZvalString(ppzTmp);
317 // zend_printf( "column=%s<br>\n", column );
318 }
319 else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
320 SEPARATE_ZVAL(ppzTmp);
321 order = (order_t)getZvalInt(ppzTmp);
322 // zend_printf( "order=%d<br>\n", order );
323 }
324 }
325
326 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
327 }
328 if ( column ){
329 orderby *o = new orderby( column, order );
330 addOrderBy( o );
331 }
332
333 result = RES_OK;
334 }
335
336 // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
337 void setOrders( zval *pz ){
338 HashPosition pos;
339
340 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
341
342 zval **ppzTmp = 0;
343 int res2;
344 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
345 char *key = 0;
346 uint keyLen = 0;
347 ulong index = 0;
348 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
349 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
350 //print_hash_key( keyType, key, keyLen, index );
351 setOrder( *ppzTmp );
352 }
353 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
354 }
355 result = RES_OK;
356 }
357
358 void initialize( zval *pz ){
359 HashPosition pos;
360 zval **ppzTmp = 0;
361 int res2;
362 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
363 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
364 char *key = 0;
365 uint keyLen = 0;
366 ulong index = 0;
367 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
368 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
369 //print_hash_key( keyType, key, keyLen, index );
370 if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
371 SEPARATE_ZVAL(ppzTmp);
372 int tmp = getZvalInt(ppzTmp);
373 // zend_printf( "start=%d<br>\n", tmp );
374 setLimit( tmp, getLimitRows() );
375 }
376 else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
377 SEPARATE_ZVAL(ppzTmp);
378 int tmp = getZvalInt(ppzTmp);
379 // zend_printf( "rows=%d<br>\n", tmp );
380 setLimit( getLimitStart(), tmp );
381 }
382 else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
383 setOrders( *ppzTmp );
384 }
385 else
386 ; // ignore unknown key