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.38 - (show annotations) (download) (as text)
Sat Mar 5 01:48:36 2005 UTC (19 years, 1 month ago) by aga4096
Branch: MAIN
Changes since 1.37: +40 -1 lines
File MIME type: text/x-c++src
・getItemCountGroupByIndexを作成.

1 /*
2 $Revision: 1.37 $
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 ZEND_FUNCTION(xnp_get_group_item_id );
122
123 ZEND_FUNCTION(xnp_get_item_types );
124 ZEND_FUNCTION(xnp_get_index_id_by_item_id );
125 ZEND_FUNCTION(xnp_get_own_public_item_id );
126
127 ZEND_FUNCTION(xnp_zip_create );
128 ZEND_FUNCTION(xnp_get_item_count );
129 ZEND_FUNCTION(xnp_get_item_count_group_by_index );
130 };
131 /* compiled function list so Zend knows what's in this module */
132 zend_function_entry xnpalmod_functions[] =
133 {
134 ZEND_FE(first_module ,NULL)
135 ZEND_FE(xnp_initialize_db ,NULL)
136 ZEND_FE(xnp_login_user ,NULL)
137 ZEND_FE(xnp_logout_user ,NULL)
138 ZEND_FE(xnp_create_session ,NULL)
139 ZEND_FE(xnp_get_session ,NULL)
140 ZEND_FE(xnp_is_activated ,NULL)
141 ZEND_FE(xnp_activate ,NULL)
142 ZEND_FE(xnp_get_account_count ,NULL)
143 ZEND_FE(xnp_delete_account ,NULL)
144 ZEND_FE(xnp_get_account ,NULL)
145 ZEND_FE(xnp_get_accounts ,NULL)
146 ZEND_FE(xnp_insert_account ,NULL)
147 ZEND_FE(xnp_update_account ,NULL)
148 ZEND_FE(xnp_dump_uids ,NULL)
149 ZEND_FE(xnp_get_group_count ,NULL)
150 ZEND_FE(xnp_get_groups_by_uid ,NULL)
151 ZEND_FE(xnp_is_group_admin ,NULL)
152 ZEND_FE(xnp_dump_gids ,NULL)
153 ZEND_FE(xnp_dump_group_admins ,NULL)
154 ZEND_FE(xnp_delete_member ,NULL)
155 ZEND_FE(xnp_insert_member ,NULL)
156 ZEND_FE(xnp_get_members ,NULL)
157 ZEND_FE(xnp_delete_group ,NULL)
158 ZEND_FE(xnp_insert_group ,NULL)
159 ZEND_FE(xnp_update_group ,NULL)
160 ZEND_FE(xnp_get_group ,NULL)
161 ZEND_FE(xnp_get_groups ,NULL)
162 ZEND_FE(xnp_is_moderator ,NULL)
163 ZEND_FE(xnp_get_uid ,NULL)
164
165 ZEND_FE(xnp_get_all_indexes ,NULL)
166 ZEND_FE(xnp_get_indexes ,NULL)
167 ZEND_FE(xnp_insert_index ,NULL)
168 ZEND_FE(xnp_update_index ,NULL)
169 ZEND_FE(xnp_delete_index ,NULL)
170 ZEND_FE(xnp_get_index ,NULL)
171 ZEND_FE(xnp_is_index_readable ,NULL)
172 ZEND_FE(xnp_is_index_writable ,NULL)
173 ZEND_FE(xnp_swap_index_sort_number ,NULL)
174
175 ZEND_FE(xnp_is_valid_session_id ,NULL)
176 ZEND_FE(xnp_get_last_error_string ,NULL)
177 ZEND_FE(xnp_test_criteria ,NULL)
178 ZEND_FE(xnp_test_uids ,NULL)
179
180 ZEND_FE(xnp_get_item_permission ,NULL)
181 ZEND_FE(xnp_get_index_permission ,NULL)
182 ZEND_FE(xnp_get_certify_permission ,NULL)
183
184 ZEND_FE(xnp_get_certify_state ,NULL)
185 ZEND_FE(xnp_set_certify_state ,NULL)
186
187 ZEND_FE(xnp_insert_change_log ,NULL)
188 ZEND_FE(xnp_get_change_logs ,NULL)
189
190 ZEND_FE(xnp_get_config_value ,NULL)
191 ZEND_FE(xnp_set_config_value ,NULL)
192
193 ZEND_FE(xnp_dump_item_id ,NULL)
194 ZEND_FE(xnp_get_item_id_by_binder_id ,NULL)
195 ZEND_FE(xnp_get_item_id_by_index_id ,NULL)
196 ZEND_FE(xnp_get_overlapped_items ,NULL)
197
198 ZEND_FE(xnp_insert_item ,NULL)
199 ZEND_FE(xnp_update_item ,NULL)
200 ZEND_FE(xnp_delete_item ,NULL)
201 ZEND_FE(xnp_get_item ,NULL)
202 ZEND_FE(xnp_get_items ,NULL)
203
204 ZEND_FE(xnp_pubmed_complete ,NULL)
205 ZEND_FE(xnp_amazon_complete ,NULL)
206
207 // ZEND_FE(xnp_uninitialize_db ,NULL)
208
209 ZEND_FE(xnp_register_binder_item ,NULL)
210 ZEND_FE(xnp_unregister_binder_item ,NULL)
211
212 ZEND_FE(xnp_register_item ,NULL)
213 ZEND_FE(xnp_unregister_item ,NULL)
214
215 ZEND_FE(xnp_get_uncertified_link ,NULL)
216 ZEND_FE(xnp_get_private_item_id ,NULL)
217 ZEND_FE(xnp_get_group_item_id ,NULL)
218
219 ZEND_FE(xnp_get_item_types ,NULL)
220
221 ZEND_FE(xnp_get_index_id_by_item_id ,NULL)
222 ZEND_FE(xnp_get_own_public_item_id ,NULL)
223
224 ZEND_FE(xnp_zip_create ,NULL)
225 ZEND_FE(xnp_get_item_count ,NULL)
226 ZEND_FE(xnp_get_item_count_group_by_index ,NULL)
227
228 {NULL, NULL, NULL}
229 };
230
231 /* compiled module information */
232 zend_module_entry xnpalmod_module_entry =
233 {
234 STANDARD_MODULE_HEADER,
235 "Visiome Platform Abstract Layer",
236 xnpalmod_functions,
237 NULL,
238 PHP_MSHUTDOWN(xnpalmod),
239 NULL,
240 NULL,
241 NULL,
242 NO_VERSION_YET,
243 STANDARD_MODULE_PROPERTIES
244 };
245
246 /* implement standard "stub" routine to introduce ourselves to Zend */
247 #if COMPILE_DL_FIRST_MODULE
248 BEGIN_EXTERN_C()
249 ZEND_GET_MODULE(xnpalmod)
250 END_EXTERN_C()
251 #endif
252
253
254 /* implement function that is meant to be made available to PHP */
255 ZEND_FUNCTION(first_module)
256 {
257 long parameter;
258 // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
259 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
260 return;
261 }
262 parameter++;
263 RETURN_LONG(parameter);
264 }
265 /** zval????C????絖?????緇?????
266 */
267 char *getZvalString( zval **p ){
268 convert_to_string_ex(p);
269 return Z_STRVAL_PP(p); //(**p).value.str.val;
270 }
271
272 /** zval????int??緇?????
273 */
274 int getZvalInt( zval **p ){
275 convert_to_long_ex(p);
276 return Z_LVAL_PP(p); // (int)(**p).value.lval;
277 }
278
279 // keylen????鮎??0????????
280 static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
281 zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
282 if ( res == HASH_KEY_IS_STRING ){
283 char *p = new char[keyLen+1];
284 memcpy( p, key, keyLen );
285 p[keyLen] = 0;
286 zend_printf( " key is string[%s]<br>\n", p );
287 }
288 else {
289 zend_printf( " key is integer[%d]<br>\n", index );
290 }
291 }
292
293
294 /** zval*????criteria_t?????????????????????鴻??????紊掩??????getResult()!=RES_OK <br>
295 criteria :
296 array( 'start'=>0, 'rows'=>10,
297 'orders'=>array(
298 array('name'=>'id','order'=>'0'),
299 array('name'=>'timestamp','name'=>'1'), ...)
300 ); ??????就???f?渇????
301 */
302 class zCriteria_t : public criteria {
303 private:
304 result_t result;
305
306 // pz: array('name'=>'timestamp','name'=>'1')
307 // ????????orderby??篏???????申????
308 void setOrder( zval *pz ){
309 char *column = 0;
310 order_t order = (order_t)0;
311
312 HashPosition pos;
313 zval **ppzTmp = 0;
314 int res2;
315 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
316 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
317 char *key = 0;
318 uint keyLen = 0;
319 ulong index = 0;
320 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
321 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
322 //print_hash_key( keyType, key, keyLen, index );
323 if ( strncasecmp( key, "name", keyLen ) == 0 && keyLen == 5 ){
324 SEPARATE_ZVAL(ppzTmp);
325 column = getZvalString(ppzTmp);
326 // zend_printf( "column=%s<br>\n", column );
327 }
328 else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
329 SEPARATE_ZVAL(ppzTmp);
330 order = (order_t)getZvalInt(ppzTmp);
331 // zend_printf( "order=%d<br>\n", order );
332 }
333 }
334
335 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
336 }
337 if ( column ){
338 orderby *o = new orderby( column, order );
339 addOrderBy( o );
340 }
341
342 result = RES_OK;
343 }
344
345 // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
346 void setOrders( zval *pz ){
347 HashPosition pos;
348
349 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
350
351 zval **ppzTmp = 0;
352 int res2;
353 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
354 char *key = 0;
355 uint keyLen = 0;
356 ulong index = 0;
357 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
358 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
359 //print_hash_key( keyType, key, keyLen, index );
360 setOrder( *ppzTmp );
361 }
362 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
363 }
364 result = RES_OK;
365 }
366
367 void initialize( zval *pz ){
368 HashPosition pos;
369 zval **ppzTmp = 0;
370 int res2;
371 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
372 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
373 char *key = 0;
374 uint keyLen = 0;
375 ulong index = 0;
376 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
377 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
378 //print_hash_key( keyType, key, keyLen, index );
379 if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
380 SEPARATE_ZVAL(ppzTmp);
381 int tmp = getZvalInt(ppzTmp);
382 // zend_printf( "start=%d<br>\n", tmp );
383 setLimit( tmp, getLimitRows() );
384 }
385 else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
386 SEPARATE_ZVAL(ppzTmp);
387 int tmp = getZvalInt(ppzTmp);
388 // zend_printf( "rows=%d<br>\n", tmp );
389 setLimit( getLimitStart(), tmp );
390 }
391 else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
392 setOrders( *ppzTmp );
393 }
394 else
395 ; // ignore unknown key
396 }
397 else
398 ; // ignore bad key
399 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
400 }
401 result = RES_OK;
402 }
403
404 public:
405 zCriteria_t() : criteria(){ result = RES_ERROR; }
406 zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
407 zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
408 result_t getResult(){ return result; };
409
410 void dump(){
411 zend_printf( "dumping zCriteria...<br>\n" );
412 zend_printf( "result=%d<br>\n", (int)result );
413 zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() );
414 const orderby *p = headOrderBy();
415 while ( p ){
416 zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() );
417 p = nextOrderBy();
418 }
419 }
420 };
421
422
423 /** ?f?渇???????≪???祉?鴻????ong?ゃ??緇?????
424 @param ht ?f?渇????
425 @param key ????/span>
426 @param val long?ゃ?????????????ゃ?潟??/span>
427 @return ????????true
428 */
429 static bool hashGetLong( HashTable *ht, const char *key, long *val ){
430 zval **tmp;
431 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
432 convert_to_long_ex( tmp );
433 *val = Z_LVAL_PP(tmp);
434 return true;
435 }
436 return false;
437 }
438
439 /** ?f?渇???????≪???祉?鴻??????絖?????緇?????
440 @param ht ?f?渇????
441 @param key ????/span>
442 @param val ??絖????????????????ゃ?潟??/span>
443 @return ????????true
444 */
445 static bool hashGetString( HashTable *ht, const char *key, char **val ){
446 zval **tmp;
447 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
448 convert_to_string_ex( tmp );
449 *val = Z_STRVAL_PP(tmp);
450 return true;
451 }
452 return false;
453 }
454
455 /** ?f?渇???????≪???祉?鴻????ouble?ゃ??緇?????
456 @param ht ?f?渇????
457 @param key ????/span>
458 @param val double?ゃ?????????????ゃ?潟??/span>
459 @return ????????true
460 */
461 static bool hashGetDouble( HashTable *ht, const char *key, double *val ){
462 zval **tmp;
463 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
464 convert_to_double_ex( tmp );
465 *val = Z_DVAL_PP(tmp);
466 return true;
467 }
468 return false;
469 }
470
471 /** zval*????account?????????????????????鴻?? <br>
472 ????紊掩??????getResult()!=RES_OK <br>
473 */
474 class zAccount_t : public account {
475 private:
476 result_t result;
477 void initialize(zval *pz){
478 HashTable *ht = Z_ARRVAL_P(pz);
479 long l;
480 char *p;
481 double d;
482 if ( hashGetLong ( ht, "uid" , &l ) ) setUID ( l );
483 if ( hashGetString( ht, "uname" , &p ) ) setUname ( p );
484 if ( hashGetString( ht, "name" , &p ) ) setName ( p );
485 if ( hashGetString( ht, "email" , &p ) ) setEmail ( p );
486 if ( hashGetString( ht, "url" , &p ) ) setURL ( p );
487 if ( hashGetString( ht, "user_avatar" , &p ) ) setUserAvatar ( p );
488 if ( hashGetString( ht, "user_icq" , &p ) ) setUserIcq ( p );
489 if ( hashGetString( ht, "user_from" , &p ) ) setUserFrom ( p );
490 if ( hashGetString( ht, "user_sig" , &p ) ) setUserSig ( p );
491 if ( hashGetString( ht, "actkey" , &p ) ) setActkey ( p );
492 if ( hashGetString( ht, "user_aim" , &p ) ) setUserAim ( p );
493 if ( hashGetString( ht, "user_yim" , &p ) ) setUserYim ( p );
494 if ( hashGetString( ht, "user_msnm" , &p ) ) setUserMsnm ( p );
495 if ( hashGetString( ht, "pass" , &p ) ) setPass ( p );
496 if ( hashGetString( ht, "theme" , &p ) ) setTheme ( p );
497 if ( hashGetString( ht, "umode" , &p ) ) setUmode ( p );
498 if ( hashGetString( ht, "user_occ" , &p ) ) setUserOcc ( p );
499 if ( hashGetString( ht, "bio" , &p ) ) setBio ( p );
500 if ( hashGetString( ht, "user_intrest" , &p ) ) setUserIntrest ( p );
501 if ( hashGetDouble( ht, "timezone_offset" , &d ) ) setTimezoneOffset ( d );
502 if ( hashGetLong ( ht, "attachsig" , &l ) ) setAttachsig ( l );
503 if ( hashGetLong ( ht, "last_login" , &l ) ) setLastLogin ( l );
504 if ( hashGetLong ( ht, "level" , &l ) ) setLevel ( l );
505 if ( hashGetLong ( ht, "notify_method" , &l ) ) setNotifyMethod ( l );
506 if ( hashGetLong ( ht, "notify_mode" , &l ) ) setNotifyMode ( l );
507 if ( hashGetLong ( ht, "posts" , &l ) ) setPosts ( l );
508 if ( hashGetLong ( ht, "rank" , &l ) ) setRank ( l );
509 if ( hashGetLong ( ht, "uorder" , &l ) ) setUorder ( l );
510 if ( hashGetLong ( ht, "user_mailok" , &l ) ) setUserMailok ( l );
511 if ( hashGetLong ( ht, "user_regdate" , &l ) ) setUserRegdate ( l );
512 if ( hashGetLong ( ht, "user_viewemail" , &l ) ) setUserViewemail ( l );
513 if ( hashGetLong ( ht, "activate" , &l ) ) setActivate ( l );
514 if ( hashGetString( ht, "address" , &p ) ) setAddress ( p );
515 if ( hashGetString( ht, "division" , &p ) ) setDivision ( p );
516 if ( hashGetString( ht, "tel" , &p ) ) setTel ( p );
517 if ( hashGetString( ht, "company_name" , &p ) ) setCompanyName ( p );
518 if ( hashGetString( ht, "country" , &p ) ) setCountry ( p );
519 if ( hashGetString( ht, "zipcode" , &p ) ) setZipcode ( p );
520 if ( hashGetString( ht, "fax" , &p ) ) setFax ( p );
521 if ( hashGetLong ( ht, "notice_mail" , &l ) ) setNoticeMail ( l );
522 if ( hashGetLong ( ht, "notice_mail_since" , &l ) ) setNoticeMailSince ( l );
523 if ( hashGetLong ( ht, "private_index_id " , &l ) ) setPrivateIndexID ( l );
524 if ( hashGetLong ( ht, "item_number_limit" , &l ) ) setItemNumberLimit ( l );
525 if ( hashGetLong ( ht, "index_number_limit", &l ) ) setIndexNumberLimit ( l );
526 if ( hashGetDouble( ht, "item_storage_limit", &d ) ) setItemStorageLimit ( d );
527
528 result = RES_OK;
529 }
530 public:
531 zAccount_t() : account(){ result = RES_ERROR; }
532
533 /** ?潟?潟?鴻????????/span>
534 @param pz array( 'uid'=>1, 'uname'=>'root', ... ); ??????就???f?渇???? */
535 zAccount_t( zval *pz ) : account(){ initialize(pz); }
536 zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
537 result_t getResult(){ return result; };
538 };
539
540 class zIndex_t : public index {
541 private:
542 result_t result;
543
544 void initialize(zval *pz){
545 HashTable *ht = Z_ARRVAL_P(pz);
546 long l;
547 char *p;
548 if ( hashGetLong ( ht, "item_id" , &l ) ) setItemID ( l );
549 if ( hashGetLong ( ht, "item_type_id" , &l ) ) setItemTypeID ( l );
550 if ( hashGetLong ( ht, "contributor_uid" , &l ) ) setContributorUID ( l );
551 if ( hashGetString( ht, "title" , &p ) ) setTitle ( p );
552 if ( hashGetString( ht, "keywords" , &p ) ) setKeywords ( p );
553 if ( hashGetString( ht, "description" , &p ) ) setDescription ( p );
554 if ( hashGetLong ( ht, "last_update_date" , &l ) ) setLastUpdateDate ( l );
555 if ( hashGetLong ( ht, "creation_date" , &l ) ) setCreationDate ( l );
556 if ( hashGetLong ( ht, "parent_index_id" , &l ) ) setParentIndexID ( l );
557 if ( hashGetLong ( ht, "owner_uid" , &l ) ) setOwnerUID ( l );
558 if ( hashGetLong ( ht, "owner_gid" , &l ) ) setOwnerGID ( l );
559 if ( hashGetLong ( ht, "open_level" , &l ) ) setOpenLevel ( l );
560 if ( hashGetLong ( ht, "sort_number" , &l ) ) setSortNumber ( l );
561
562 result = RES_OK;
563 }
564 public:
565 zIndex_t() : index(){ result = RES_ERROR; }
566 zIndex_t( zval *pz ) : index(){ initialize(pz); }
567 zIndex_t( zval **ppz ) : index() { initialize(*ppz); }
568 result_t getResult(){ return result; };
569
570 void dump(){
571 }
572 };
573
574 /** zval*????(userid_t *puid,int uidLen)?????????????????????鴻?? <br>
575 ????紊掩??????getResult()!=RES_OK <br>
576 */
577 class zUIDs_t {
578 private:
579 result_t result;
580 userid_t *pUID;
581 int len;
582 public:
583 zUIDs_t(){
584 pUID = 0;
585 len = 0;
586 result = RES_ERROR;
587 }
588
589 /** ?潟?潟?鴻????????/span>
590 @param pza array( '1', '3', '4', '6', ... ); ??????就?????? */
591 zUIDs_t( zval *pza ){
592 pUID = 0;
593 len = 0;
594 result = RES_ERROR;
595
596 if ( Z_TYPE_P(pza) != IS_ARRAY ){
597 result = RES_ERROR;
598 }
599 else {
600 len = zend_hash_num_elements(Z_ARRVAL_P(pza));
601 if(len == 0) {
602 pUID = new userid_t[1];
603 result = RES_OK;
604 }
605 else {
606 /* php/ext/standard/string.c ? implode??????????????????
607 zend_hash_*???????ャ?<?潟???c????????????????鐚?
608 */
609 zval **tmp;
610 HashPosition pos;
611 int i = 0;
612 pUID = new userid_t[len];
613
614 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
615 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
616 SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
617 convert_to_long_ex(tmp);
618 if ( i < len )
619 pUID[i++] = Z_LVAL_PP(tmp);
620 zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
621 }
622 len = i;
623 result = RES_OK;
624 }
625 }
626 }
627
628 ~zUIDs_t(){
629 if ( pUID ) delete[] pUID;
630 }
631 result_t getResult(){ return result; }
632 userid_t *getPUID(){ return pUID; }
633 int getLen(){ return len; }
634 void dump(){
635 zend_printf( "dumping zUIDs...<br>\n" );
636 zend_printf( "result=%d<br>\n", (int)result );
637 zend_printf( "len=%d<br>\n", len );
638 for ( int i = 0; i < len; i++ ){
639 zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
640 }
641 }
642 };
643
644 /** zval*????(itemid_t *piid,int iidLen)?????????????????????鴻?? <br>
645 ????紊掩??????getResult()!=RES_OK <br>
646 */
647 class zIIDs_t {
648 private:
649 result_t result;
650 itemid_t *pIID;
651 int len;
652 public:
653 zIIDs_t(){
654 pIID = 0;
655 len = 0;
656 result = RES_ERROR;
657 }
658
659 /** ?潟?潟?鴻????????/span>
660 @param pza array( '1', '3', '4', '6', ... ); ??????就?????? */
661 zIIDs_t( zval *pza ){
662 pIID = 0;
663 len = 0;
664 result = RES_ERROR;
665
666 if ( Z_TYPE_P(pza) != IS_ARRAY ){
667 result = RES_ERROR;
668 }
669 else {
670 len = zend_hash_num_elements(Z_ARRVAL_P(pza));
671 if(len == 0) {
672 pIID = new itemid_t[1];
673 result = RES_OK;
674 }
675 else {
676 /* php/ext/standard/string.c ? implode??????????????????
677 zend_hash_*???????ャ?<?潟???c????????????????鐚?
678 */
679 zval **tmp;
680 HashPosition pos;
681 int i = 0;
682 pIID = new itemid_t[len];
683
684 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
685 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
686 SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
687 convert_to_long_ex(tmp);
688 if ( i < len )
689 pIID[i++] = Z_LVAL_PP(tmp);
690 zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
691 }
692 len = i;
693 result = RES_OK;
694 }
695 }
696 }
697
698 ~zIIDs_t(){
699 if ( pIID ) delete[] pIID;
700 }
701 result_t getResult(){ return result; }
702 itemid_t *getPIID(){ return pIID; }
703 int getLen(){ return len; }
704 void dump(){
705 zend_printf( "dumping zIIDs...<br>\n" );
706 zend_printf( "result=%d<br>\n", (int)result );
707 zend_printf( "len=%d<br>\n", len );
708 for ( int i = 0; i < len; i++ ){
709 zend_printf( "pIID[%d] = %d<br>\n", i, pIID[i] );
710 }
711 }
712 };
713
714 /**
715 *
716 * amazonbook_t????絎鴻??PHP???????????????
717 * @param pAmazonbook 紊???????mazonbook_t*
718 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
719 * @return RES_OK
720 *
721 */
722 result_t amazonbookToZval( const amazonbook_t *pAmazonbook, zval *z )
723 {
724 zend_hash_clean( z -> value.ht );
725
726 add_assoc_string( z, "title", ( char* )pAmazonbook -> getTitle( ), 1 );
727 add_assoc_string( z, "author", ( char* )pAmazonbook -> getAuthor( ), 1 );
728 add_assoc_string( z, "publisher", ( char* )pAmazonbook -> getPublisher( ), 1 );
729 add_assoc_long( z, "year_of_publication", pAmazonbook -> getYearOfPublication( ) );
730 add_assoc_string( z, "isbn", ( char* )pAmazonbook -> getISBN( ), 1 );
731 add_assoc_string( z, "url", ( char* )pAmazonbook -> getURL( ), 1 );
732
733 return RES_OK;
734 }
735
736 /**
737 *
738 * pubmed_t????絎鴻??PHP???????????????
739 * @param pPubmed 紊???????ubmed_t*
740 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
741 * @return RES_OK
742 *
743 */
744 result_t pubmedToZval( const pubmed_t *pPubmed, zval *z )
745 {
746 zend_hash_clean( z -> value.ht );
747
748 add_assoc_long( z, "pmid", pPubmed -> getID( ) );
749 add_assoc_string( z, "title", ( char* )pPubmed -> getTitle( ), 1 );
750 add_assoc_string( z, "author", ( char* )pPubmed -> getAuthor( ), 1 );
751 add_assoc_string( z, "journal", ( char* )pPubmed -> getJournal( ), 1 );
752 add_assoc_long( z, "year_of_publication", pPubmed -> getYearOfPublication( ) );
753 add_assoc_long( z, "volume", pPubmed -> getVolume( ) );
754 add_assoc_long( z, "number", pPubmed -> getNumber( ) );
755 add_assoc_string( z, "page", ( char* )pPubmed -> getPage( ), 1 );
756 add_assoc_string( z, "abstract", ( char* )pPubmed -> getAbstract( ), 1 );
757
758 return RES_OK;
759 }
760
761 /**
762 *
763 * itemid_t????????PHP???????????????
764 * @param piid 紊???????temid_t??????
765 * @param len piid?????????激??
766 * @param ppz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
767 * @return RES_OK
768 *
769 */
770 result_t itemidsToZval( const itemid_t *piid, int len, zval **ppz )
771 {
772 zend_hash_clean( Z_ARRVAL_PP(ppz) );
773
774 // add IDs
775 for ( int i = 0; i < len; i++ ){
776 add_next_index_long(*ppz, (long)(piid[i]) );
777 }
778
779 return RES_OK;
780 }
781
782 /**
783 *
784 * indexid_t????????PHP???????????????
785 * @param piid 紊???????ndexid_t??????
786 * @param len piid?????????激??
787 * @param ppz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
788 * @return RES_OK
789 *
790 */
791 result_t indexidsToZval( const indexid_t *piid, int len, zval **ppz )
792 {
793 zend_hash_clean( Z_ARRVAL_PP(ppz) );
794
795 // add IDs
796 for ( int i = 0; i < len; i++ ){
797 add_next_index_long(*ppz, (long)(piid[i]) );
798 }
799
800 return RES_OK;
801 }
802
803 /**
804 *
805 * uids_t????????PHP???????????????
806 *
807 * @param pUID 紊???????serid_t??????
808 * @param len pUID?????????激??
809 * @param pz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
810 * @return RES_OK
811 *
812 */
813 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
814 {
815 zend_hash_clean( Z_ARRVAL_PP(ppz) );
816
817 // add UIDs
818 for ( int i = 0; i < len; i++ ){
819 add_next_index_long(*ppz, (long)(pUID[i]) );
820 }
821
822 return RES_OK;
823 }
824
825 /**
826 *
827 * groupid_t????????PHP???????????????
828 * @param pGID 紊???????roupid_t??????
829 * @param len pGID?????????激??
830 * @param ppz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
831 * @return RES_OK
832 *
833 */
834 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
835 {
836 zend_hash_clean( Z_ARRVAL_PP(ppz) );
837
838 // add GIDs
839 for ( int i = 0; i < len; i++ ){
840 add_next_index_long(*ppz, (long)(pGID[i]) );
841 }
842
843 return RES_OK;
844 }
845
846 /**
847 *
848 * changelog_t????絎鴻??PHP???????????????
849 * @param pChangelog 紊???????hangelog_t*
850 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
851 * @return RES_OK
852 *
853 */
854 result_t changelogToZval( const changelog_t *pChangelog, zval *z )
855 {
856 zend_hash_clean( z -> value.ht );
857
858 add_assoc_long( z, "log_id", pChangelog -> getChangelogID( ) );
859 add_assoc_long( z, "item_id", pChangelog -> getItemID( ) );
860 add_assoc_long( z, "log_date", pChangelog -> getDate( ) );
861 add_assoc_string( z, "log", ( char* )pChangelog -> getLog( ), 1 );
862
863 return RES_OK;
864 }
865
866 /**
867 *
868 * item_t????絎鴻??PHP???????????????
869 * @param pItem 紊???????tem_t*
870 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
871 * @return RES_OK
872 *
873 */
874 result_t itemToZval( const item_t *pItem, zval *z )
875 {
876 zend_hash_clean( z -> value.ht );
877
878 add_assoc_long( z, "item_id", pItem -> getItemID( ) );
879 add_assoc_long( z, "item_type_id", pItem -> getItemTypeID( ) );
880 add_assoc_long( z, "uid", pItem -> getContributorUID( ) );
881 add_assoc_string( z, "title", ( char* )pItem -> getTitle( ), 1 );
882 add_assoc_string( z, "keywords", ( char* )pItem -> getKeywords( ), 1 );
883 add_assoc_string( z, "description", ( char* )pItem -> getDescription( ), 1 );
884 add_assoc_string( z, "doi", ( char* )pItem -> getDOI( ), 1 );
885 add_assoc_long( z, "last_update_date", pItem -> getLastUpdateDate( ) );
886 add_assoc_long( z, "creation_date", pItem -> getCreationDate( ) );
887 add_assoc_long( z, "publication_year", pItem -> getPublicationYear( ) );
888 add_assoc_long( z, "publication_month", pItem -> getPublicationMonth( ) );
889 add_assoc_long( z, "publication_mday", pItem -> getPublicationMday( ) );
890
891 return RES_OK;
892 }
893
894
895 result_t itemsToZval( const item_t *pItems, int itemsLen, zval *z )
896 {
897 zend_hash_clean( z -> value.ht );
898 for( int i = 0; i < itemsLen; i++ ){
899 zval *new_array;
900 MAKE_STD_ZVAL(new_array);
901 if(array_init(new_array) != SUCCESS){
902 return RES_ERROR;
903 }
904 add_index_zval( z, i, new_array );
905 itemToZval( &pItems[ i ], new_array );
906 }
907 return RES_OK;
908 }
909
910 /**
911 *
912 * PHP???f?渇????????絎鴻??group_t?????????
913 *
914 * @param z 紊????????f?渇????
915 * @param pGroup 紊???腟??????吾??莨若???違???若??
916 * @return RES_OK
917 *
918 */
919 result_t zvalToItem( zval *z, item_t* pItem )
920 {
921 zval **tmp;
922 char* key = 0;
923
924 key = "item_id";
925 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
926 convert_to_long_ex( tmp ) ;
927 pItem -> setItemID( (*tmp) -> value.lval );
928 }
929 key = "item_type_id";
930 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
931 convert_to_long_ex( tmp ) ;
932 pItem -> setItemTypeID( (*tmp) -> value.lval );
933 }
934 key = "uid";
935 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
936 convert_to_long_ex( tmp ) ;
937 pItem -> setContributorUID( (*tmp) -> value.lval );
938 }
939 key = "title";
940 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
941 convert_to_string_ex( tmp ) ;
942 pItem -> setTitle( (*tmp) -> value.str.val );
943 }
944 key = "keywords";
945 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
946 convert_to_string_ex( tmp ) ;
947 pItem -> setKeywords( (*tmp) -> value.str.val );
948 }
949 key = "description";
950 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
951 convert_to_string_ex( tmp ) ;
952 pItem -> setDescription( (*tmp) -> value.str.val );
953 }
954 key = "doi";
955 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
956 convert_to_string_ex( tmp ) ;
957 pItem -> setDOI( (*tmp) -> value.str.val );
958 }
959 key = "last_update_date";
960 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
961 convert_to_long_ex( tmp ) ;
962 pItem -> setLastUpdateDate( (*tmp) -> value.lval );
963 }
964 key = "creation_date";
965 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
966 convert_to_long_ex( tmp ) ;
967 pItem -> setCreationDate( (*tmp) -> value.lval );
968 }
969 key = "publication_year";
970 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
971 convert_to_long_ex( tmp ) ;
972 pItem -> setPublicationYear( (*tmp) -> value.lval );
973 }
974 key = "publication_month";
975 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
976 convert_to_long_ex( tmp ) ;
977 pItem -> setPublicationMonth( (*tmp) -> value.lval );
978 }
979 key = "publication_mday";
980 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
981 convert_to_long_ex( tmp ) ;
982 pItem -> setPublicationMday( (*tmp) -> value.lval );
983 }
984 return RES_OK;
985 }
986
987 /**
988 *
989 * account_t????絎鴻??PHP???????????????
990 * @param pAccount 紊???????ccount_t*
991 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
992 * @return RES_OK
993 *
994 */
995 result_t accountToZval( const account_t *pAccount, zval *z )
996 {
997 zend_hash_clean( z -> value.ht );
998
999 add_assoc_long( z, "uid", pAccount -> getUID( ) );
1000 add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
1001 add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
1002 add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
1003 add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
1004 add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
1005 add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
1006 add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
1007 add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
1008 add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
1009 add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
1010 add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
1011 add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
1012 add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
1013 add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
1014 add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
1015 add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
1016 add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
1017 add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
1018 add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
1019 add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
1020 add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
1021 add_assoc_long( z, "level", pAccount -> getLevel( ) );
1022 add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
1023 add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
1024 add_assoc_long( z, "posts", pAccount -> getPosts( ) );
1025 add_assoc_long( z, "rank", pAccount -> getRank( ) );
1026 add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
1027 add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
1028 add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
1029 add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
1030
1031 add_assoc_long( z, "activate", pAccount -> getActivate( ) );
1032 add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
1033 add_assoc_string( z, "division", ( char* )pAccount -> getDivision( ), 1 );
1034 add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
1035 add_assoc_string( z, "company_name", ( char* )pAccount -> getCompanyName( ), 1 );
1036 add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
1037 add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
1038 add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
1039 add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
1040 add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
1041 add_assoc_long( z, "private_index_id", pAccount -> getPrivateIndexID( ) );
1042 add_assoc_long( z, "item_number_limit", pAccount -> getItemNumberLimit( ) );
1043 add_assoc_long( z, "index_number_limit", pAccount -> getIndexNumberLimit( ) );
1044 add_assoc_double( z, "item_storage_limit", pAccount -> getItemStorageLimit( ) );
1045 return RES_OK;
1046 }
1047
1048 /**
1049 *
1050 * 茲??違??ccount_t????絎鴻??PHP?????????????????????
1051 * @param pAccounts 紊???????ccount_t*
1052 * @param accountsLen pAccounts?????????激??
1053 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
1054 * @return RES_OK
1055 *
1056 z: ?????????????????????????? <br>
1057 array(
1058 array(
1059 'uid'=>100,
1060 'activate'=>1,
1061 'division'=>'foo',
1062 'tel'=>'123-456-789',
1063 ...
1064 ),
1065 ...
1066 )
1067 */
1068 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
1069 {
1070 zend_hash_clean( z -> value.ht );
1071 for( int i = 0; i < accountsLen; i++ ){
1072 zval *new_array;
1073 MAKE_STD_ZVAL(new_array);
1074 if(array_init(new_array) != SUCCESS){
1075 return RES_ERROR;
1076 }
1077 add_index_zval( z, i, new_array );
1078 accountToZval( &pAccounts[ i ], new_array );
1079 }
1080 return RES_OK;
1081 }
1082
1083 /**
1084 *
1085 * 茲??違??roup_t????絎鴻??PHP?????????????????????
1086 * @param pGroups 紊???????roup_t*
1087 * @param groupsLen pGroups?????????激??
1088 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
1089 * @return RES_OK
1090 *
1091 z: ?????????????????????????? <br>
1092 array(
1093 array(
1094 'gid'=>1,
1095 'gname'=>'foo group',
1096 'gdesc'=>'group of foo'
1097 ),
1098 ...
1099 )
1100 */
1101 result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
1102 {
1103 zend_hash_clean( z -> value.ht );
1104 for( int i = 0; i < groupsLen; i++ ){
1105 zval *new_array;
1106 MAKE_STD_ZVAL(new_array);
1107 if(array_init(new_array) != SUCCESS){
1108 return RES_ERROR;
1109 }
1110 add_index_zval( z, i, new_array );
1111 add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
1112 add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
1113 add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
1114 add_assoc_long( new_array, "group_index_id", pGroups[ i ].getGroupIndexID( ) );
1115 add_assoc_long( new_array, "item_number_limit", pGroups[ i ].getItemNumberLimit( ) );
1116 add_assoc_long( new_array, "index_number_limit", pGroups[ i ].getIndexNumberLimit( ) );
1117 add_assoc_double( new_array, "item_storage_limit", pGroups[ i ].getItemStorageLimit( ) );
1118 }
1119 return RES_OK;
1120 }
1121
1122 /**
1123 *
1124 * group_t????絎鴻??PHP???f?渇?????????????
1125 *
1126 * @param pGroup 紊????????違???若??????/span>
1127 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
1128 * @return RES_OK
1129 *
1130 */
1131 result_t groupToZval( const group_t *pGroup, zval *z )
1132 {
1133 zend_hash_clean( z -> value.ht );
1134 add_assoc_long( z, "gid", pGroup -> getGID( ) );
1135 add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
1136 add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
1137 add_assoc_long( z, "group_index_id", pGroup -> getGroupIndexID( ) );
1138 add_assoc_long( z, "item_number_limit", pGroup -> getItemNumberLimit( ) );
1139 add_assoc_long( z, "index_number_limit", pGroup -> getIndexNumberLimit( ) );
1140 add_assoc_double( z, "item_storage_limit", pGroup -> getItemStorageLimit( ) );
1141 return RES_OK;
1142 }
1143
1144 /**
1145 *
1146 * PHP???f?渇????????絎鴻??group_t?????????
1147 *
1148 * @param z 紊????????f?渇????
1149 * @param pGroup 紊???腟??????吾??莨若???違???若??
1150 * @return RES_OK
1151 *
1152 */
1153 result_t zvalToGroup( zval *z, group_t *pGroup )
1154 {
1155 zval **tmp;
1156 char* key = 0;
1157
1158 key = "gid";
1159 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1160 convert_to_long_ex( tmp ) ;
1161 pGroup -> setGID( (*tmp) -> value.lval );
1162 }
1163 key = "gname";
1164 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1165 convert_to_string_ex( tmp ) ;
1166 pGroup -> setGname( (*tmp) -> value.str.val );
1167 }
1168 key = "gdesc";
1169 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1170 convert_to_string_ex( tmp ) ;
1171 pGroup -> setDesc( (*tmp) -> value.str.val );
1172 }
1173 key = "group_index_id";
1174 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1175 convert_to_long_ex( tmp ) ;
1176 pGroup -> setGroupIndexID( (*tmp) -> value.lval );
1177 }
1178 key = "item_number_limit";
1179 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1180 convert_to_long_ex( tmp ) ;
1181 pGroup -> setItemNumberLimit( (*tmp) -> value.lval );
1182 }
1183 key = "index_number_limit";
1184 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1185 convert_to_long_ex( tmp ) ;
1186 pGroup -> setIndexNumberLimit( (*tmp) -> value.lval );
1187 }
1188 key = "item_storage_limit";
1189 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1190 convert_to_double_ex( tmp ) ;
1191 pGroup -> setItemStorageLimit( (*tmp) -> value.dval );
1192 }
1193 return RES_OK;
1194 }
1195
1196 /**
1197 *
1198 * session_t????絎鴻??PHP???f?渇?????????????
1199 *
1200 * @param pSession 紊???????ession_t
1201 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
1202 * @return RES_OK
1203 *
1204 */
1205 result_t sessionToZval( const session_t *pSession, zval *z )
1206 {
1207 string sessionID(unsignedIntToString(pSession->getSessionID()));
1208 add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
1209
1210 string date(unsignedIntToString((unsigned int)pSession->getDate()));
1211 add_assoc_string(z, "date", (char *)date.c_str(), 1);
1212
1213 string userID(unsignedIntToString((unsigned int)pSession->getUID()));
1214 add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
1215
1216 return RES_OK;
1217 }
1218
1219 /**
1220 *
1221 * index_t????絎鴻??PHP???????????????
1222 * @param pIndex 紊???????ndex_t*
1223 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
1224 * @return RES_OK
1225 *
1226 */
1227 result_t indexToZval( const index_t *pIndex, zval *z )
1228 {
1229 zend_hash_clean( z -> value.ht );
1230
1231 add_assoc_long( z, "item_id", pIndex -> getItemID( ) );
1232 add_assoc_long( z, "item_type_id", pIndex -> getItemTypeID( ) );
1233 add_assoc_long( z, "contributor_uid", pIndex -> getContributorUID( ) );
1234 add_assoc_string( z, "title", ( char* )pIndex -> getTitle( ), 1 );
1235 add_assoc_string( z, "keywords", ( char* )pIndex -> getKeywords( ), 1 );
1236 add_assoc_string( z, "description", ( char* )pIndex -> getDescription( ), 1 );
1237 add_assoc_long( z, "last_update_date", pIndex -> getLastUpdateDate( ) );
1238 add_assoc_long( z, "creation_date", pIndex-> getCreationDate( ) );
1239 add_assoc_long( z, "parent_index_id", pIndex -> getParentIndexID( ) );
1240 add_assoc_long( z, "owner_uid", pIndex -> getOwnerUID( ) );
1241 add_assoc_long( z, "owner_gid", pIndex -> getOwnerGID( ) );
1242 add_assoc_long( z, "open_level", pIndex -> getOpenLevel( ) );
1243 add_assoc_long( z, "sort_number", pIndex -> getSortNumber( ) );
1244 return RES_OK;
1245 }
1246
1247 result_t indexesToZval( const index_t *pIndexes, int indexesLen, zval *z )
1248 {
1249 zend_hash_clean( z -> value.ht );
1250 for( int i = 0; i < indexesLen; i++ ){
1251 zval *new_array;
1252 MAKE_STD_ZVAL(new_array);
1253 if(array_init(new_array) != SUCCESS){
1254 return RES_ERROR;
1255 }
1256 add_index_zval( z, i, new_array );
1257 indexToZval( &pIndexes[ i ], new_array );
1258 }
1259 return RES_OK;
1260 }
1261
1262
1263
1264
1265 /** ??絎??????違???若???????宴??緇???<br>
1266 int xnp_get_group( int sid, int gid, array group );
1267 @param sid XNP???祉???激?с??D
1268 @param gid XNP ? group_id
1269 @param group 腟?????????????????
1270 @return 0 success <br>
1271 */
1272 ZEND_FUNCTION(xnp_get_group)
1273 {
1274 long sid, gid;
1275 zval *zgroup;
1276
1277 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1278 &sid, &gid, &zgroup) == FAILURE) {
1279 return;
1280 }
1281
1282 const group_t *pgroup;
1283 result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
1284 if ( RES_OK == result ){
1285 groupToZval( pgroup, zgroup );
1286 freeGroup( pgroup );
1287 }
1288
1289 RETURN_LONG(result);
1290 }
1291
1292
1293 /** ??絎??????違???若??(茲????????宴??緇???<br>
1294 xnp_get_groups( int sid, array gids, array criteria, array groups );
1295 @param sid XNP???祉???激?с??D
1296 @param gids XNP ? group_id ??????
1297 @param criteria ?>散
1298 @param groups 腟???????????????????????
1299 @return 0 success <br>
1300 */
1301 ZEND_FUNCTION(xnp_get_groups)
1302 {
1303 result_t result;
1304 long sid;
1305 zval *zcriteria;
1306 zval *zgids;
1307 zval *zgroups;
1308 zval **ppzTmp = 0;
1309 HashPosition pos;
1310 int res2;
1311 int gidsLen;
1312 const group_t* groups;
1313 int groupsLen;
1314
1315 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1316 &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
1317 return;
1318 }
1319
1320 //gids???違???若??ID???潟???若????
1321 gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
1322 groupid_t *gids = new groupid_t[ gidsLen ];
1323 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
1324 for( int i = 0; i < gidsLen; i++ ){
1325 if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
1326 SEPARATE_ZVAL(ppzTmp);
1327 convert_to_long_ex(ppzTmp);
1328 gids[ i ] = Z_LVAL_PP(ppzTmp);
1329 }
1330 zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
1331 }
1332
1333 zCriteria_t zcri(zcriteria);
1334 result = zcri.getResult();
1335 if ( RES_OK == result ){
1336 result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
1337 if ( RES_OK == result ){
1338 groupsToZval( groups, groupsLen, zgroups );
1339 delete[] gids;
1340 freeGroup( groups );
1341 }
1342 }
1343 RETURN_LONG(result);
1344 }
1345
1346
1347 /** ??絎????????若?吟???≪?????若?帥??????????茯帥?鴻??<br>
1348 int xnp_is_moderator(int sid, int uid)
1349 @param sid XNP???祉???激?с??D
1350 @param uid xoops ? uid (xoops_users.uid)
1351 @return true ?≪?????若?帥?с???? <br>
1352 */
1353 ZEND_FUNCTION(xnp_is_moderator)
1354 {
1355 long xnpSessionID;
1356 userid_t uid;
1357
1358 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1359 &xnpSessionID, &uid) == FAILURE) {
1360 return;
1361 }
1362
1363 bool result = isModerator( (sessionid_t)xnpSessionID, uid );
1364 RETURN_BOOL(result)
1365 }
1366
1367 /** ???若?九??????uid??茯帥?鴻??<br>
1368 int xnp_get_uid(string uname,int &uid)
1369 @param sid XNP???祉???激?с??D
1370 @param uname xoops ? uname (xoops_users.uname)
1371 @param uid xoops ? uid (xoops_users.uid) ??????????紊???/span>
1372 @return 0 success
1373 */
1374 ZEND_FUNCTION(xnp_get_uid)
1375 {
1376 char *uname;
1377 int unameLen;
1378 zval *zuid;
1379 userid_t uid;
1380
1381 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
1382 &uname, &unameLen, &zuid) == FAILURE) {
1383 return;
1384 }
1385
1386 if (!PZVAL_IS_REF(zuid)) {
1387 zend_error(E_WARNING, "2nd parameter wasn't passed by reference");
1388 RETURN_LONG(RES_PHP_NONREF);
1389 }
1390
1391 string strUname( uname, unameLen );
1392 result_t result = getUid( strUname.c_str(), &uid );
1393 ZVAL_LONG(zuid, (long)uid);
1394 RETURN_LONG((long)result);
1395 }
1396
1397 ZEND_FUNCTION(xnp_test_criteria)
1398 {
1399 zval *z;
1400
1401 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
1402 &z) == FAILURE) {
1403 return;
1404 }
1405 zend_printf("zend_printf...<br>\n");
1406 zCriteria_t zcri(z);
1407 zcri.dump();
1408 RETURN_FALSE
1409 }
1410
1411 ZEND_FUNCTION(xnp_test_uids)
1412 {
1413 zval *z;
1414
1415 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
1416 &z) == FAILURE) {
1417 return;
1418 }
1419 zend_printf("zend_printf...<br>\n");
1420 zUIDs_t zuids(z);
1421 zuids.dump();
1422 RETURN_FALSE
1423 }
1424
1425
1426
1427 /** DB??・膓????????≪??・膓?筝???・膓???????????????<br>
1428 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix, int dbtype]]]] );
1429 @param host ?ョ????????ユ????ULL
1430 @param user DB?ョ????????若?九???????ユ????ULL
1431 @param password DB?ョ????????鴻???若???????ユ????ULL
1432 @param dbname DB?ョ?????B???????ユ????quot;"
1433 @param prefix XOOPS DB ??refix??
1434 @param dbtype 1=MySQL 2=SQLite??common.h????/span>
1435 @return 0 success <br>
1436 */
1437 ZEND_FUNCTION(xnp_initialize_db)
1438 {
1439 zval **parameters[5];
1440 char *host;
1441 char *user;
1442 char *password;
1443 char *dbname;
1444 char *prefix;
1445 long dbtype;
1446
1447 /* get the number of arguments */
1448 int argNum = ZEND_NUM_ARGS();
1449 if (argNum > 5)
1450 WRONG_PARAM_COUNT;
1451
1452 /* argument count is correct, now retrieve arguments */
1453 if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
1454 WRONG_PARAM_COUNT;
1455
1456 if (argNum < 1) host = NULL;
1457 else host = getZvalString( parameters[0] );
1458
1459 if (argNum < 2) user = NULL;
1460 else user = getZvalString( parameters[1] );
1461
1462 if (argNum < 3) password = NULL;
1463 else password = getZvalString( parameters[2] );
1464
1465 if (argNum < 4) dbname = "";
1466 else dbname = getZvalString( parameters[3] );
1467
1468 if (argNum < 5) prefix = "";
1469 else prefix = getZvalString( parameters[4] );
1470
1471 if (argNum < 6) dbtype = DBTYPE_MYSQL;
1472 else dbtype = getZvalInt( parameters[5] );
1473
1474 result_t result = initializeDB( host, user, password, dbname, prefix, (dbtype_t)dbtype );
1475
1476 RETURN_LONG(result);
1477 }
1478
1479 /** ???違?ゃ?潟??????<br>
1480 int xnp_login_user(string uname, string password, int &session_id)
1481 @param uname ???若?九??(xoops_users.uname)
1482 @param password ???鴻???若??(md5(password)=xoops_users.pass)
1483 @return 0 success
1484 */
1485 ZEND_FUNCTION(xnp_login_user)
1486 {
1487 char *uname;
1488 int unameLen;
1489 char *passwd;
1490 int passwdLen;
1491 zval *zXNPSessionID;
1492
1493 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",
1494 &uname, &unameLen, &passwd, &passwdLen, &zXNPSessionID) == FAILURE) {
1495 return;
1496 }
1497
1498 if (!PZVAL_IS_REF(zXNPSessionID)) {
1499 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1500 RETURN_LONG(RES_PHP_NONREF);
1501 }
1502
1503 sessionid_t xnpSessionID;
1504 result_t result = loginUser( uname, passwd, &xnpSessionID );
1505 if ( result == RES_OK )
1506 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1507 RETURN_LONG((long)result);
1508 }
1509
1510 /** ???違?≪??????????<br>
1511 void xnp_logout_user(int xnp_session_id)
1512 @param xnp_session_id XNP???祉???激?с??D
1513 @return ????
1514 */
1515 ZEND_FUNCTION(xnp_logout_user)
1516 {
1517 long xnpSessionID;
1518
1519 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &xnpSessionID) == FAILURE) {
1520 return;
1521 }
1522 logoutUser( (sessionid_t)xnpSessionID );
1523
1524 RETURN_NULL();
1525 }
1526
1527 /** XNP???祉???激?с??D 篏???<br>
1528 int xnp_create_session( string xoops_sess_id, int uid, int &session )
1529 @param xoops_sess_id xoops???祉???激?с??D
1530 @param uid xoops ? uid (xoops_users.uid)
1531 @param session 篏???????XNP??ession??????????紊???/span>
1532 @return 0 ????
1533 */
1534 ZEND_FUNCTION(xnp_create_session)
1535 {
1536 char *xoopsSessionID;
1537 int xoopsSessionIDLen;
1538 long uid;
1539 zval *zXNPSessionID;
1540
1541 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz",
1542 &xoopsSessionID, &xoopsSessionIDLen, &uid, &zXNPSessionID) == FAILURE) {
1543 return;
1544 }
1545
1546 if (!PZVAL_IS_REF(zXNPSessionID)) {
1547 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1548 RETURN_LONG(RES_PHP_NONREF);
1549 }
1550
1551 sessionid_t xnpSessionID = 0;
1552 result_t result = createSession( xoopsSessionID, (userid_t)uid, &xnpSessionID );
1553 if ( result == RES_OK )
1554 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1555 RETURN_LONG((long)result);
1556 }
1557
1558 /** XNP ? session ???膣井???宴??緇???<br>
1559 int xnp_get_session( int xnp_session_id, array session_info )
1560 @param xnp_session_id XNP???祉???激?с??D
1561 @param session_info 腟?????????????????
1562 @return 0 success
1563 */
1564 ZEND_FUNCTION(xnp_get_session)
1565 {
1566 long xnpSessionID;
1567 zval *sessionInfo;
1568 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1569 &xnpSessionID, &sessionInfo) == FAILURE) {
1570 return;
1571 }
1572 const session_t *session = 0;
1573 result_t result = getSession( (sessionid_t)xnpSessionID, &session );
1574 if ( result == RES_OK ){
1575 sessionToZval( session, sessionInfo );
1576 freeSession( session );
1577 }
1578
1579 RETURN_LONG((long)result);
1580 }
1581
1582 /** ???若?吟??ctivate?倶??????緇?????<br>
1583 bool xnp_is_activated( int xnp_session_id, int user_id )
1584 @param xnp_session_id XNP???祉???激?с??D
1585 @param user_id xoops_users.uid
1586 @return 0 success
1587 */
1588 ZEND_FUNCTION(xnp_is_activated)
1589 {
1590 long sid, uid;
1591
1592 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
1593 return;
1594 }
1595
1596 bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
1597
1598 RETURN_BOOL(result);
1599 }
1600
1601 /** activate??????<br>
1602 bool xnp_activate( int xnp_session_id, int user_id, bool activated )
1603 @param xnp_session_id xnp ? session id
1604 @param user_id xoops_users.uid
1605 @param activated true:activate, false:inactivate
1606 @return 0 success
1607 */
1608 ZEND_FUNCTION(xnp_activate)
1609 {
1610 long sid, uid;
1611 bool activated;
1612
1613 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
1614 &sid, &uid, &activated) == FAILURE) {
1615 return;
1616 }
1617
1618 result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
1619
1620 RETURN_LONG(result);
1621 }
1622
1623 /** XNP???≪?????潟???違??緇?????<br>
1624 int xnp_get_account_count( int xnp_session_id )
1625 @param xnp_session_id XNP???祉???激?с??D
1626 @return 0 success
1627 */
1628 ZEND_FUNCTION(xnp_get_account_count)
1629 {
1630 long sid;
1631
1632 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1633 &sid) == FAILURE) {
1634 return;
1635 }
1636
1637 long count = getAccountCount( (sessionid_t)sid );
1638 RETURN_LONG(count);
1639 }
1640
1641 /** ?≪?????潟???????ゃ??????<br>
1642 bool xnp_delete_account( int xnp_session_id, int user_id )
1643 @param xnp_session_id XNP???祉???激?с??D
1644 @param user_id xoops_users.uid
1645 @return 0 success
1646 */
1647 ZEND_FUNCTION(xnp_delete_account)
1648 {
1649 long sid, uid;
1650
1651 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1652 &sid, &uid) == FAILURE) {
1653 return;
1654 }
1655
1656 result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
1657
1658 RETURN_LONG(result);
1659 }
1660
1661 /** ?≪?????潟?????宴??緇?????<br>
1662 int xnp_get_account( int xnp_session_id, int user_id, array account_info )
1663 @param xnp_session_id XNP???祉???激?с??D
1664 @param user_id xoops_users.uid
1665 @param account_info ?≪?????潟?????宴???????????f?渇????
1666 @return 0 success
1667 */
1668 ZEND_FUNCTION(xnp_get_account)
1669 {
1670 long sid, uid;
1671 zval *zaccount;
1672
1673 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1674 &sid, &uid, &zaccount) == FAILURE) {
1675 fprintf( stderr, "error occured " );
1676 return;
1677 }
1678
1679 const account_t *paccount;
1680 result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
1681 if ( RES_OK == result ){
1682 accountToZval( paccount, zaccount );
1683 freeAccount( paccount );
1684 }
1685
1686 RETURN_LONG(result);
1687 }
1688
1689 /** ?>散????眼?????≪?????潟???????宴??緇?????<br>
1690 int xnp_get_accoutns( int sid, array uids, array criteria, array accounts );
1691 @param xnp_session_id XNP???祉???激?с??D
1692 @param user_id xoops_users.uid
1693 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1694 @param account_info ?≪?????潟?????宴???????????f?渇????
1695 @return 0 success
1696 */
1697 ZEND_FUNCTION(xnp_get_accounts)
1698 {
1699 result_t result;
1700 long sid;
1701 zval *zuids;
1702 zval *zcriteria;
1703 zval *zaccount;
1704
1705 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1706 &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
1707 return;
1708 }
1709
1710 zCriteria_t zcri(zcriteria);
1711 result = zcri.getResult();
1712 if ( RES_OK == result ){
1713 zUIDs_t zUIDs(zuids);
1714 result = zUIDs.getResult();
1715 if ( RES_OK == result ){
1716 const account_t *paccounts;
1717 int accountLen;
1718 result = getAccounts( (sessionid_t)sid,
1719 zUIDs.getPUID(), zUIDs.getLen(),
1720 &zcri, &paccounts, &accountLen );
1721 if ( RES_OK == result ){
1722 accountsToZval( paccounts, accountLen, zaccount );
1723 freeAccount( paccounts );
1724 }
1725 }
1726 }
1727
1728 RETURN_LONG(result);
1729 }
1730
1731 /** ?≪?????潟?????宴??荐??蚊??????<br>
1732 int xnp_insert_account( int sid, array account_info, int &user_id );
1733 @param xnp_session_id xnp ? session id
1734 @param account_info 荐??蚊???????≪?????潟????????/span>
1735 @param user_id ???若??D(xoops_users.uid)???吾??莨若???????<???潟??/span>
1736 @return 0 success
1737 */
1738 ZEND_FUNCTION(xnp_insert_account)
1739 {
1740 result_t result;
1741 long sid;
1742 zval *zaccount;
1743 zval *zuid;
1744 userid_t uid;
1745
1746 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1747 &sid, &zaccount, &zuid) == FAILURE) {
1748 return;
1749 }
1750
1751 zAccount_t zacc(zaccount);
1752 result = zacc.getResult();
1753 if ( RES_OK == result ){
1754 result = insertAccount( (sessionid_t)sid, &zacc, &uid );
1755 }
1756 zuid -> type = IS_LONG;
1757 zuid -> value.lval = uid;
1758 RETURN_LONG(result);
1759 }
1760
1761 /** ?≪?????潟?????宴???贋?違??????<br>
1762 int xnp_update_account( int sid, array account );
1763 @param xnp_session_id XNP???祉???激?с??D
1764 @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
1765 @return 0 success
1766 */
1767 ZEND_FUNCTION(xnp_update_account)
1768 {
1769 result_t result;
1770 long sid;
1771 zval *zaccount;
1772
1773 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1774 &sid, &zaccount) == FAILURE) {
1775 return;
1776 }
1777
1778 zAccount_t zacc(zaccount);
1779 result = zacc.getResult();
1780 if ( RES_OK == result ){
1781 result = updateAccount( (sessionid_t)sid, &zacc );
1782 }
1783
1784 RETURN_LONG(result);
1785 }
1786
1787 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
1788 int xnp_dump_uids( int xnp_session_id, array criteria, array uids );
1789 @param xnp_session_id XNP???祉???激?с??D
1790 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1791 @param uids uid??????????????
1792 @return 0 success
1793 */
1794 ZEND_FUNCTION(xnp_dump_uids)
1795 {
1796 result_t result;
1797 long sid;
1798 zval *zcriteria;
1799 zval *zuids;
1800
1801 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1802 &sid, &zcriteria, &zuids) == FAILURE) {
1803 return;
1804 }
1805
1806 zCriteria_t zcri(zcriteria);
1807 result = zcri.getResult();
1808 if ( RES_OK == result ){
1809 userid_t *puid;
1810 int uidLen;
1811 result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1812 if ( RES_OK == result ){
1813 uidsToZval( puid, uidLen, &zuids );
1814 freeUID( puid );
1815 }
1816 }
1817
1818 RETURN_LONG(result);
1819 }
1820
1821 /** XNP???違???若?????違??緇???<br>
1822 int xnp_get_group_count( int xnp_session_id );
1823 @param xnp_session_id XNP???祉???激?с??D
1824 @return ?違???若????/span>
1825 */
1826 ZEND_FUNCTION(xnp_get_group_count)
1827 {
1828 long sid;
1829
1830 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1831 &sid) == FAILURE) {
1832 return;
1833 }
1834
1835 int count = getGroupCount( (sessionid_t)sid );
1836
1837 RETURN_LONG(count);
1838 }
1839
1840 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
1841 int xnp_get_group_by_uid( int xnp_session_id, int uid, array criteria, array gids );
1842 @param xnp_session_id XNP???祉???激?с??D
1843 @param user_id xoops_users.uid
1844 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1845 @param gids gid??????????????
1846 @return 0 success
1847 */
1848 ZEND_FUNCTION(xnp_get_groups_by_uid)
1849 {
1850 result_t result;
1851 long sid, uid;
1852 zval *zcriteria;
1853 zval *zgids;
1854
1855 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1856 &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1857 return;
1858 }
1859
1860 zCriteria_t zcri(zcriteria);
1861 result = zcri.getResult();
1862 if ( RES_OK == result ){
1863 groupid_t *pgids;
1864 int gidLen;
1865 result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1866 if ( RES_OK == result ){
1867 gidsToZval( pgids, gidLen, &zgids );
1868 freeGID( pgids );
1869 }
1870 }
1871
1872 RETURN_LONG(result);
1873 }
1874
1875
1876
1877 /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
1878 int xnp_is_group_admin( int sid, int gid, int uid );
1879 @param xnp_session_id XNP???祉???激?с??D
1880 @param group_id XNP???違???若??ID
1881 @param user_id xoops_users.uid
1882 @return true: ?違???若??膊∞?????с??????
1883 @return false: ?違???若??膊∞?????с???????????????????若?с??????
1884 */
1885 ZEND_FUNCTION(xnp_is_group_admin)
1886 {
1887 long sid, gid, uid;
1888
1889 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1890 &sid, &gid, &uid) == FAILURE) {
1891 return;
1892 }
1893
1894 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1895
1896 RETURN_BOOL(b);
1897 }
1898
1899 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
1900 int xnp_dump_gids( int sid, array criteria, array gids );
1901 @param xnp_session_id XNP???祉???激?с??D
1902 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1903 @param gids gid??????????????
1904 @return 0 success
1905 */
1906 ZEND_FUNCTION(xnp_dump_gids)
1907 {
1908 result_t result;
1909 long sid;
1910 zval *zcriteria;
1911 zval *zgids;
1912
1913 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1914 &sid, &zcriteria, &zgids) == FAILURE) {
1915 return;
1916 }
1917
1918 zCriteria_t zcri(zcriteria);
1919 result = zcri.getResult();
1920 if ( RES_OK == result ){
1921 groupid_t *pgid;
1922 int gidLen;
1923 result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1924 if ( RES_OK == result ){
1925 gidsToZval( pgid, gidLen, &zgids );
1926 freeGID( pgid );
1927 }
1928 }
1929
1930 RETURN_LONG(result);
1931 }
1932
1933 /** gid?ф??絎??????違???若??????????с?????ゆ?>散????眼?????違???若??膊∞??????id???荀с??緇?????<br>
1934 int xnp_dump_group_admins(int sid, int group_id, array criteria, array uids )
1935 @param sid XNP???祉???激?с??D
1936 @param group_id XNP???違???若??ID
1937 @param criteria ?>散
1938 @param uids uid???荀с??????????????
1939 @return 0 success
1940 */
1941
1942 ZEND_FUNCTION(xnp_dump_group_admins)
1943 {
1944 long sid, gid;
1945 zval *zcriteria;
1946 zval *zuids;
1947
1948 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1949 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1950 return;
1951 }
1952
1953 zCriteria_t zcri(zcriteria);
1954 result_t result = zcri.getResult();
1955 if ( result == RES_OK ){
1956 userid_t *uids;
1957 int uidsLen;
1958 result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1959 if ( result == RES_OK ){
1960 uidsToZval( uids, uidsLen, &zuids );
1961 freeUID( uids );
1962 }
1963 }
1964 RETURN_LONG( result );
1965 }
1966
1967 /** ?違???若???????<?潟???若?????ゃ??????<br>
1968 int xnp_delete_member(int sid, int group_id, int user_id )
1969 @param sid XNP???祉???激?с??D
1970 @param group_id XNP???違???若??ID
1971 @param user_id ???若??D
1972 @return 0 success
1973 */
1974
1975 ZEND_FUNCTION(xnp_delete_member)
1976 {
1977 long sid, gid, uid;
1978
1979 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1980 &sid, &gid, &uid) == FAILURE) {
1981 return;
1982 }
1983
1984 result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1985 RETURN_LONG( result );
1986 }
1987
1988 /** ?違???若?????<?潟???若??菴遵??????<br>
1989 int xnp_insert_member(int sid, int group_id, int user_id, bool admin )
1990 @param sid XNP???祉???激?с??D
1991 @param group_id XNP???違???若??ID
1992 @param user_id ???若??D
1993 @param admin ?違???若??膊∞????????true
1994 @return 0 success
1995 */
1996
1997 ZEND_FUNCTION(xnp_insert_member)
1998 {
1999 long sid, gid, uid;
2000 zend_bool admin;
2001
2002 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
2003 &sid, &gid, &uid, &admin) == FAILURE) {
2004 return;
2005 }
2006
2007 result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
2008 RETURN_LONG( result );
2009 }
2010
2011 /** gid?ф??絎??????違???若?????<?潟???若??id???荀с??緇???<br>
2012 int xnp_get_members(int sid, int group_id, array criteria, array uids )
2013 @param sid XNP???祉???激?с??D
2014 @param group_id XNP???違???若??ID
2015 @param criteria ?>散
2016 @param uids uid???荀с??????????????
2017 @return 0 success
2018 */
2019
2020 ZEND_FUNCTION(xnp_get_members)
2021 {
2022 long sid, gid;
2023 zval *zcriteria;
2024 zval *zuids;
2025
2026 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2027 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
2028 return;
2029 }
2030
2031 zCriteria_t zcri(zcriteria);
2032 result_t result = zcri.getResult();
2033 if ( result == RES_OK ){
2034 userid_t *uids;
2035 int uidsLen;
2036 result = getMembers( (sessionid_t)sid, (groupid_t)gid, &zcri, &uids, &uidsLen );
2037 if ( result == RES_OK ){
2038 uidsToZval( uids, uidsLen, &zuids );
2039 freeUID( uids );
2040 }
2041 }
2042 RETURN_LONG( result );
2043 }
2044
2045 /** ?違???若?????宴??紊??眼??????<br>
2046 int xnp_update_group(int sid, array group )
2047 @param sid XNP???祉???激?с??D
2048 @param group ?違???若?????宴???f?渇????
2049 @return 0 success
2050 */
2051 ZEND_FUNCTION(xnp_update_group)
2052 {
2053 long sid;
2054 zval *zgroup;
2055 group_t group;
2056
2057 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
2058 &sid, &zgroup) == FAILURE) {
2059 return;
2060 }
2061
2062 zvalToGroup( zgroup, &group );
2063 result_t result = updateGroup( sid, &group );
2064 RETURN_LONG( result );
2065 }
2066
2067 /** ?違???若?????宴??菴遵????????<br>
2068 int xnp_insert_group( int sid, array group, int &gid )
2069 @param sid ?祉???激?с??D
2070 @param group ?違???若?????宴???f?渇????
2071 @param gid 絲上??????違???若??ID???吾??莨若???????<???潟??/span>
2072 @return RES_OK
2073 @return RES_DB_NOT_INITIALIZED
2074 @return RES_NO_SUCH_SESSION
2075 @return RES_DB_QUERY_ERROR
2076 */
2077 ZEND_FUNCTION(xnp_insert_group)
2078 {
2079 long sid;
2080 zval *zgroup;
2081 zval *zgid;
2082 group_t group;
2083 groupid_t gid;
2084
2085 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2086 &sid, &zgroup, &zgid ) == FAILURE) {
2087 return;
2088 }
2089
2090 zvalToGroup( zgroup, &group );
2091 result_t result = insertGroup( sid, &group, &gid );
2092 zgid -> type = IS_LONG;
2093 zgid -> value.lval = gid;
2094 RETURN_LONG( result );
2095 }
2096
2097
2098 /** ?違???若?????宴?????ゃ??????<br>
2099 int xnp_delete_group( int sid, int gid )
2100 @param sid XNP???祉???激?с??D
2101 @param gid ???ゃ???????違???若????D
2102 @return RES_OK
2103 @return RES_DB_QUERY_ERROR
2104 @return RES_NO_SUCH_SESSION
2105 @return RES_DB_NOT_INITIALIZED
2106 */
2107 ZEND_FUNCTION(xnp_delete_group)
2108 {
2109 long sid;
2110 long gid;
2111
2112 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2113 &sid, &gid) == FAILURE) {
2114 return;
2115 }
2116 RETURN_LONG( deleteGroup( sid, gid ) );
2117 }
2118
2119 /** ?違???若?????????????緇???<br>
2120 int xnp_dump_group_admins( int sid, int gid, array criteria, array uids )
2121 @param sid XNP???祉???激?с??D
2122 @param gid XNP?違???若????D
2123 @param criteria uids???吾??莨若?????????純?若???>散鐚?膀??蚊????絎?
2124 @param uids 膊∞??????ID???吾??莨若??????
2125 @return RES_OK
2126 @return RES_DB_QUERY_ERROR
2127 @return RES_NO_SUCH_SESSION
2128 @return RES_DB_NOT_INITIALIZED
2129 */
2130 /*
2131 ZEND_FUNCTION(xnp_dump_group_admins)
2132 {
2133 long sid;
2134 long gid;
2135 zval *zcriteria;
2136 zval *zuids;
2137
2138 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2139 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
2140 return;
2141 }
2142 zCriteria_t zcri(zcriteria);
2143 result_t result = zcri.getResult();
2144 if ( RES_OK == result ){
2145 userid_t* uids;
2146 int uidsLen;
2147 result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
2148 if( result != RES_OK ) RETURN_LONG( result );
2149 uidsToZval( uids, uidsLen, &zuids );
2150 fprintf( stderr, "uidsLen=%d\n", uidsLen );
2151 for( int i = 0; i < uidsLen; i++ ){
2152 fprintf( stderr, "%d, \n", uids[ i ] );
2153 }
2154 freeUID( uids );
2155 RETURN_LONG( result );
2156 }
2157 RETURN_LONG( result );
2158 }
2159 */
2160
2161 /** ???????ゃ?潟???????鴻??緇???<br>
2162 * int xnp_get_all_indexes( int sid, array criteria, array indexes );
2163 * @param sid XNP???祉???激?с??D
2164 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
2165 * @return RES_OK
2166 */
2167 ZEND_FUNCTION(xnp_get_all_indexes)
2168 {
2169 long sid;
2170 zval *zcriteria;
2171 zval *zindexes;
2172
2173 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
2174 &sid, &zcriteria, &zindexes) == FAILURE) {
2175 return;
2176 }
2177 zCriteria_t zcri(zcriteria);
2178 result_t result = zcri.getResult();
2179 if ( RES_OK == result ){
2180 const index_t *indexes;
2181 int indexesLen;
2182 result = getAllIndexes( sid, &zcri, &indexes, &indexesLen );
2183 if ( RES_OK == result ){
2184 result = indexesToZval( indexes, indexesLen, zindexes );
2185 freeIndex( indexes );
2186 }
2187 }
2188 RETURN_LONG(result);
2189 }
2190
2191 /** ?????ゃ?潟???????鴻??????????ゃ?潟???????鴻??緇???<br>
2192 * int xnp_get_indexes( int sid, int parentXID, array criteria, array indexes );
2193 * @param sid XNP???祉???激?с??D
2194 * @param parentXID 荀???ndexID
2195 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
2196 * @param indexes 腟?????????????????
2197 * @return RES_OK
2198 */
2199 ZEND_FUNCTION(xnp_get_indexes)
2200 {
2201 long sid;
2202 long parentXID;
2203 zval *zcriteria;
2204 zval *zindexes;
2205
2206 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2207 &sid, &parentXID, &zcriteria, &zindexes) == FAILURE) {
2208 return;
2209 }
2210 zCriteria_t zcri(zcriteria);
2211 result_t result = zcri.getResult();
2212 if ( RES_OK == result ){
2213 const index_t *indexes;
2214 int indexesLen;
2215 result = getIndexes( sid, parentXID, &zcri, &indexes, &indexesLen );
2216 if ( RES_OK == result ){
2217 result = indexesToZval( indexes, indexesLen, zindexes );
2218 freeIndex( indexes );
2219 }
2220 }
2221 RETURN_LONG(result);
2222 }
2223
2224
2225 /** ?ゃ?潟???????鴻??篏???????<br>
2226 * int xnp_insert_index( int sid, array index, int &indexID );
2227 * @param sid XNP???祉???激?с??D
2228 * @param index 篏????????ゃ?潟????????/span>
2229 * @param indexID 篏??????????ゃ?潟???????鴻??D??????????紊???/span>
2230 * @return RES_OK
2231 */
2232 ZEND_FUNCTION(xnp_insert_index)
2233 {
2234 long sid;
2235 zval *zindex;
2236 zval *zIndexID;
2237
2238 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2239 &sid, &zindex, &zIndexID) == FAILURE) {
2240 return;
2241 }
2242
2243 if (!PZVAL_IS_REF(zIndexID)) {
2244 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
2245 RETURN_LONG(RES_PHP_NONREF);
2246 }
2247 zIndex_t index( zindex );
2248 indexid_t xid;
2249 result_t result = insertIndex( sid, &index, &xid );
2250 if ( RES_OK == result )
2251 ZVAL_LONG(zIndexID, (long)xid);
2252 RETURN_LONG(result);
2253 }
2254
2255 /** ?ゃ?潟???????鴻???贋?違????<br>
2256 * int xnp_update_index( int sid, array index );
2257 * @param sid XNP???祉???激?с??D
2258 * @param index ?贋?違?????ゃ?潟????????/span>
2259 * @return RES_OK
2260 */
2261 ZEND_FUNCTION(xnp_update_index)
2262 {
2263 long sid;
2264 zval *zindex;
2265
2266 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
2267 &sid, &zindex) == FAILURE) {
2268 return;
2269 }
2270 zIndex_t index(zindex);
2271 result_t result = index.getResult();
2272 if ( RES_OK == result ){
2273 result = updateIndex( sid, &index );
2274 }
2275 RETURN_LONG(result);
2276 }
2277
2278 /** ?ゃ?潟???????鴻?????ゃ????<br>
2279 * int xnp_delete_index( int sid, int indexID );
2280 * @param sid XNP???祉???激?с??D
2281 * @param indexID ???ゃ?????ゃ?潟????????/span>
2282 * @return RES_OK
2283 */
2284 ZEND_FUNCTION(xnp_delete_index)
2285 {
2286 long sid;
2287 long xid;
2288
2289 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2290 &sid, &xid) == FAILURE) {
2291 return;
2292 }
2293
2294 result_t result = deleteIndex( sid, xid );
2295 RETURN_LONG(result);
2296 }
2297
2298
2299 /** ?ゃ?潟???????鴻????緇?????<br>
2300 * int xnp_get_index( int sid, int indexID, array index );
2301 * @param sid XNP???祉???激?с??D
2302 * @param indexID ??緇??????ゃ?潟???????鴻??D
2303 * @param index ??緇?腟??????????????f?渇????
2304 * @return RES_OK
2305 */
2306 ZEND_FUNCTION(xnp_get_index)
2307 {
2308 long sid;
2309 long xid;
2310 zval *zindex;
2311
2312 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
2313 &sid, &xid, &zindex) == FAILURE) {
2314 return;
2315 }
2316
2317 const index_t *index;
2318 result_t result = getIndex( sid, xid, &index );
2319 if ( RES_OK == result ){
2320 result = indexToZval( index, zindex );
2321 freeIndex( index );
2322 }
2323 RETURN_LONG(result);
2324 }
2325
2326
2327
2328 /** ?ゃ?潟???????鴻??茯??粋昭?水??純??????????茯帥?鴻??<br>
2329 * int xnp_is_index_readable( int sid, int indexID );
2330 * @param sid XNP???祉???激?с??D
2331 * @param indexID 絲乗院?ゃ?潟???????鴻??D
2332 * @return true false
2333 */
2334 ZEND_FUNCTION(xnp_is_index_readable)
2335 {
2336 long sid;
2337 long xid;
2338
2339 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2340 &sid, &xid) == FAILURE) {
2341 return;
2342 }
2343 RETURN_BOOL(isIndexReadable(sid,xid));
2344 }
2345
2346
2347 /** ?ゃ?潟???????鴻???吾??莨若?水??純??????????茯帥?鴻??<br>
2348 * int xnp_is_index_writable( int sid, int indexID );
2349 * @param sid XNP???祉???激?с??D
2350 * @param indexID 絲乗院?ゃ?潟???????鴻??D
2351 * @return true false
2352 */
2353 ZEND_FUNCTION(xnp_is_index_writable)
2354 {
2355 long sid;
2356 long xid;
2357
2358 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2359 &sid, &xid) == FAILURE) {
2360 return;
2361 }
2362 RETURN_BOOL(isIndexWritable(sid,xid));
2363 }
2364
2365 /** ?ゃ?潟???????鴻????綺???ャ???帥????<br>
2366 * int xnp_swap_index_sort_number( int sid, int indexID1, int indexID2 );
2367 * @param sid XNP???祉???激?с??D
2368 * @param indexID1 絲乗院?ゃ?潟???????鴻??D
2369 * @param indexID2 絲乗院?ゃ?潟???????鴻??D
2370 * @return true false
2371 */
2372 ZEND_FUNCTION(xnp_swap_index_sort_number)
2373 {
2374 long sid;
2375 long xid1, xid2;
2376
2377 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2378 &sid, &xid1, &xid2) == FAILURE) {
2379 return;
2380 }
2381
2382 result_t result = swapIndexSortNumber( sid, xid1, xid2 );
2383 RETURN_LONG(result);
2384 }
2385
2386
2387
2388 /** XNP??ession_id???綵??с???с????lt;br>
2389 bool xnp_is_valid_session_id( int xnp_session_id)
2390 @return true ???鴻??NP??ession_id?с????<br>
2391 @return false ?≦?鴻??ession_id?障??????????/span>
2392 */
2393 ZEND_FUNCTION(xnp_is_valid_session_id)
2394 {
2395 long sid;
2396 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
2397 return;
2398 }
2399
2400 RETURN_BOOL(isValidSessionID((sessionid_t)sid));
2401 }
2402
2403 /** ?????惹??絖?????緇???<br>
2404 string xnp_get_last_error_string()
2405 @return 0 success
2406 */
2407 ZEND_FUNCTION(xnp_get_last_error_string)
2408 {
2409 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
2410 return;
2411 }
2412
2413 string str( getLastErrorString() );
2414 RETURN_STRING((char *)str.c_str(), 1);
2415 }
2416
2417
2418 /**
2419 *
2420 * ?≪?ゃ?????吾???≪???祉?号┤???????с????????
2421 *
2422 * @refer itemop_t
2423 * @param sid ?祉???激?с??D
2424 * @param iid ???с?????莟<???????≪?ゃ??????D
2425 * @param op ?≪???祉?鴻??┏蕁?
2426 * @return true 罔???????
2427 * @return false 罔???????
2428 *
2429 */
2430 ZEND_FUNCTION(xnp_get_item_permission)
2431 {
2432 long sid;
2433 itemid_t iid;
2434 long op;
2435
2436 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2437 &sid, &iid, &op) == FAILURE) {
2438 fprintf( stderr, "error occured " );
2439 return;
2440 }
2441 RETURN_BOOL( getItemPermission( (sessionid_t)sid, iid, op ) );
2442 }
2443
2444
2445 /**
2446 *
2447 * ?ゃ?潟???????鴻?吾???≪???祉?号┤???????с????????
2448 *
2449 * @refer indexop_t
2450 * @param sid ?祉???激?с??D
2451 * @param xid ???с?????莟<???????ゃ?潟???????鴻??D
2452 * @param op ?≪???祉?鴻??┏蕁?
2453 * @return true 罔???????
2454 * @return false 罔???????
2455 *
2456 */
2457 ZEND_FUNCTION(xnp_get_index_permission)
2458 {
2459 long sid;
2460 indexid_t xid;
2461 long op;
2462
2463 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2464 &sid, &xid, &op) == FAILURE) {
2465 fprintf( stderr, "error occured " );
2466 return;
2467 }
2468 RETURN_BOOL( getIndexPermission( (sessionid_t)sid, xid, op ) );
2469 }
2470
2471
2472 /**
2473 *
2474 * ?≪?ゃ???????粋??倶????紊??眼????罔????????<??茯帥?鴻?障??鐚?/span>
2475 * @refer certify_t
2476 * @param sid ?祉???激?с??D
2477 * @param xid 紊??翫?莟<?≪?ゃ???????脂?蚊???????????ゃ?潟???????鴻??D
2478 * @param iid 紊??翫?莟<?≪?ゃ??????D
2479 * @param state ?違???鎀??眼???????粋??倶??
2480 * @return true 罔???????
2481 * @return false 罔???????
2482 *
2483 */
2484 ZEND_FUNCTION(xnp_get_certify_permission)
2485 {
2486 long sid;
2487 itemid_t iid;
2488 indexid_t xid;
2489 certify_t state;
2490
2491 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll",
2492 &sid, &xid, &iid, &state) == FAILURE) {
2493 fprintf( stderr, "error occured " );
2494 return;
2495 }
2496 RETURN_BOOL( getCertifyPermission( (sessionid_t)sid, xid, iid, state ) );
2497 }
2498
2499
2500 /**
2501 *
2502 * ?≪?ゃ???????粋??倶??????緇????障??鐚?/span>
2503 * @refer certify_t
2504 * @param sid ?祉???激?с??D
2505 * @param xid 絲乗院?≪?ゃ???????脂?蚊???????????ゃ?潟???????鴻??D
2506 * @param iid 絲乗院?≪?ゃ??????D
2507 * @param state ?粋??倶????????????綣???/span>
2508 * @return RES_OK
2509 * @return RES_NO_WRITE_ACCESS_RIGHT
2510 *
2511 */
2512 ZEND_FUNCTION(xnp_get_certify_state)
2513 {
2514 long sid;
2515 indexid_t xid;
2516 itemid_t iid;
2517 zval *zstate;
2518 result_t result = RES_ERROR;
2519
2520 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllz",
2521 &sid, &xid, &iid, &zstate) == FAILURE) {
2522 fprintf( stderr, "error occured " );
2523 return;
2524 }
2525 certify_t st;
2526 result = getCertifyState( (sessionid_t)sid, xid, iid, &st );
2527 if ( RES_OK == result ){
2528 zstate -> type = IS_LONG;
2529 zstate -> value.lval = st;
2530 }
2531 RETURN_LONG( result );
2532 }
2533
2534
2535 /**
2536 *
2537 * ?≪?ゃ???????粋??倶????紊??眼???障??鐚?/span>
2538 * @refer certify_t
2539 * @param sid ?祉???激?с??D
2540 * @param xid 紊??翫?莟<?≪?ゃ???????脂?蚊???????????ゃ?潟???????鴻??D
2541 * @param iid 紊??翫?莟<?≪?ゃ??????D
2542 * @param state ?違???鎀??眼???????粋??倶??
2543 * @return RES_OK
2544 * @return RES_NO_WRITE_ACCESS_RIGHT
2545 *
2546 */
2547 ZEND_FUNCTION(xnp_set_certify_state)
2548 {
2549 long sid;
2550 indexid_t xid;
2551 itemid_t iid;
2552 certify_t state;
2553 result_t result = RES_ERROR;
2554
2555 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll",
2556 &sid, &xid, &iid, &state) == FAILURE) {
2557 fprintf( stderr, "error occured " );
2558 return;
2559 }
2560 result = setCertifyState( (sessionid_t)sid, xid, iid, state );
2561 RETURN_LONG( result );
2562 }
2563
2564
2565 /**
2566 *
2567 * 紊??翫吋罩眼???違??荐??蚊????鐚?/span>
2568 *
2569 * @param sid ?祉???激?с??D
2570 * @param itemid 紊??翫吋罩眼??荐??蚊?????≪?ゃ??????D
2571 * @param log ???医??絎?/span>
2572 * @return RES_OK
2573 * @return RES_NO_SUCH_SESSION
2574 * @return RES_DB_QUERY_ERROR
2575 * @return RES_NO_WRITE_ACCESS_RIGHT
2576 * @return RES_DB_NOT_INITIALIZED
2577 * @return RES_ERROR
2578 *
2579 */
2580 ZEND_FUNCTION(xnp_insert_change_log)
2581 {
2582 long sid;
2583 itemid_t iid;
2584 zval *zlog;
2585 result_t result = RES_ERROR;
2586
2587 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llz",
2588 &sid, &iid, &zlog) == FAILURE) {
2589 fprintf( stderr, "error occured " );
2590 return;
2591 }
2592
2593 result = insertChangeLog( sid, iid, getZvalString( &zlog ) );
2594 RETURN_LONG( result );
2595 }
2596
2597
2598 /**
2599 *
2600 * ?≪?ゃ????????翫吋罩眼???違????緇?????鐚?/span>
2601 *
2602 * @param sid ?祉???激?с??D
2603 * @param itemid 紊??翫吋罩眼????緇??????≪?ゃ??????D
2604 * @param logs ???医??絎鴻?????????????ゃ?潟??/span>
2605 * @param logsLen logs???主??????????違??????/span>
2606 * @return RES_OK
2607 * @return RES_NO_SUCH_SESSION
2608 * @return RES_NO_READ_ACCESS_RIGHT
2609 * @return RES_DB_NOT_INITIALIZED
2610 * @return RES_ERROR
2611 *
2612 */
2613 ZEND_FUNCTION(xnp_get_change_logs)
2614 {
2615 result_t result;
2616 long sid;
2617 itemid_t iid;
2618 zval *zlogs;
2619
2620 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
2621 &sid, &iid, &zlogs) == FAILURE) {
2622 return;
2623 }
2624
2625 const changelog_t *plogs;
2626 int logLen;
2627 result = getChangeLogs( (sessionid_t)sid, iid, &plogs, &logLen );
2628 if ( RES_OK == result ){
2629 zend_hash_clean( zlogs -> value.ht );
2630 for( int i = 0; i < logLen; i++ ){
2631 zval *new_array;
2632 MAKE_STD_ZVAL(new_array);
2633 if(array_init(new_array) != SUCCESS){
2634 result = RES_ERROR;
2635 break;
2636 }
2637 add_index_zval( zlogs, i, new_array );
2638 changelogToZval( &plogs[ i ], new_array );
2639 }
2640 freeChangeLog( plogs );
2641 }
2642 RETURN_LONG(result);
2643 }
2644
2645
2646 /**
2647 *
2648 * 荐????key???綽??????ゃ??vaule????????鐚?/span>
2649 * value??戎?????reeString?цВ?障????鐚?/span>
2650 * @param key 荐?????弱??
2651 * @param value 荐???ゃ?????????????ゃ?潟??/span>
2652 *
2653 * @return RES_OK
2654 * @return RES_DB_QUERY_ERROR
2655 * @return RES_ERROR
2656 */
2657 ZEND_FUNCTION(xnp_get_config_value)
2658 {
2659 zval *zname;
2660 zval *zvalue;
2661 char* value;
2662 result_t result = RES_ERROR;
2663
2664 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",
2665 &zname, &zvalue) == FAILURE) {
2666 return;
2667 }
2668 result = getConfigValue( getZvalString( &zname ), &value );
2669 if( result == RES_OK ){
2670 zvalue -> type = IS_STRING;
2671 zvalue -> value.str.len = strlen(value);
2672 zvalue -> value.str.val = estrdup(value);
2673 freeString( value );
2674 }
2675 RETURN_LONG( result );
2676 }
2677
2678
2679 /**
2680 *
2681 * 荐????key???ゃ??vaule??荐??????
2682 *
2683 * @param key 荐?????弱??
2684 * @param value 荐????/span>
2685 *
2686 * @return RES_OK
2687 * @return RES_DB_QUERY_ERROR
2688 * @return RES_ERROR
2689 */
2690 ZEND_FUNCTION(xnp_set_config_value)
2691 {
2692 zval *zname;
2693 zval *zvalue;
2694 result_t result = RES_ERROR;
2695
2696 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",
2697 &zname, &zvalue) == FAILURE) {
2698 return;
2699 }
2700 result = setConfigValue( getZvalString( &zname ), getZvalString( &zvalue ) );
2701 RETURN_LONG( result );
2702 }
2703
2704
2705 /**
2706 *
2707 * ?≪?ゃ????ID???荀у??.
2708 * ?≪???祉?劫??純???≪?ゃ??????D??菴???.
2709 *
2710 * int xnp_dump_item_id( int sid, array cri, array iids )
2711 * @param sid ?祉???激?с??D
2712 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
2713 * @param iids ??緇?腟?????????????????
2714 * @return RES_OK
2715 * @return RES_DB_NOT_INITIALIZED
2716 * @return RES_NO_SUCH_SESSION
2717 * @return RES_DB_QUERY_ERROR
2718 *
2719 */
2720 ZEND_FUNCTION(xnp_dump_item_id)
2721 {
2722 long sid;
2723 zval *zcriteria;
2724 zval *ziids;
2725 result_t result = RES_ERROR;
2726
2727 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
2728 &sid, &zcriteria, &ziids) == FAILURE) {
2729 fprintf( stderr, "error occured " );
2730 return;
2731 }
2732
2733 zCriteria_t zcri(zcriteria);
2734 result = zcri.getResult();
2735 if ( RES_OK == result ){
2736 const itemid_t *piids;
2737 int iidsLen;
2738 result = dumpItemID( (sessionid_t)sid, &zcri, &piids, &iidsLen );
2739 if ( RES_OK == result ){
2740 itemidsToZval( piids, iidsLen, &ziids );
2741 freeItemID( piids );
2742 }
2743 }
2744
2745 RETURN_LONG( result );
2746 }
2747
2748
2749 /**
2750 *
2751 * ???ゃ?潟???若???脂?蚊???????≪?ゃ??????D????緇????障??鐚?/span>
2752 * @param sid ?祉???激?с??D
2753 * @param binderid 絲乗院???ゃ?潟???若??D
2754 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
2755 * @param iids ?脂?蚊???????≪?ゃ????ID??????????綣???/span>
2756 * @param iidsLen iids???主??????????違??????????綣???/span>
2757 * @return RES_OK
2758 * @return RES_DB_NOT_INITIALIZED
2759 * @return RES_NO_SUCH_SESSION
2760 * @return RES_DB_QUERY_ERROR
2761 * @return RES_ERROR
2762 *
2763 */
2764 ZEND_FUNCTION(xnp_get_item_id_by_binder_id)
2765 {
2766 result_t result;
2767 long sid;
2768 itemid_t iid;
2769 zval *zcriteria;
2770 zval *ziids;
2771
2772 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2773 &sid, &iid, &zcriteria, &ziids) == FAILURE) {
2774 return;
2775 }
2776
2777 zCriteria_t zcri(zcriteria);
2778 result = zcri.getResult();
2779 if ( RES_OK == result ){
2780 const itemid_t *pitemids;
2781 int itemidLen;
2782 result = getItemIDByBinderID( (sessionid_t)sid, iid, &zcri, &pitemids, &itemidLen );
2783 if ( RES_OK == result ){
2784 itemidsToZval( pitemids, itemidLen, &ziids );
2785 freeItemID( pitemids );
2786 }
2787 }
2788 RETURN_LONG(result);
2789 }
2790
2791
2792 /**
2793 *
2794 * ?ゃ?潟???????鴻???脂?蚊???????≪?ゃ??????D????緇????障??鐚?/span>
2795 * 罔??????<????????????????????????帥?障????鐚?/span>
2796 * ???粋??ц?????????????腟????????帥?障????鐚?/span>
2797 *
2798 * @param sid ?祉???激?с??D
2799 * @param xid 絲乗院?ゃ?潟???????鴻??D
2800 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
2801 * @param iids ?脂?蚊???????≪?ゃ????ID??????????綣???/span>
2802 * @param iidsLen iids???主??????????違??????????綣???/span>
2803 * @return RES_OK
2804 * @return RES_DB_NOT_INITIALIZED
2805 * @return RES_NO_SUCH_SESSION
2806 * @return RES_DB_QUERY_ERROR
2807 * @return RES_ERROR
2808 *
2809 */
2810 ZEND_FUNCTION(xnp_get_item_id_by_index_id)
2811 {
2812 result_t result;
2813 long sid;
2814 indexid_t xid;
2815 zval *zcriteria;
2816 zval *ziids;
2817
2818 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2819 &sid, &xid, &zcriteria, &ziids) == FAILURE) {
2820 return;
2821 }
2822
2823 zCriteria_t zcri(zcriteria);
2824 result = zcri.getResult();
2825 if ( RES_OK == result ){
2826 const itemid_t *pitemids;
2827 int itemidLen;
2828 result = getItemIDByIndexID( (sessionid_t)sid, xid, &zcri, &pitemids, &itemidLen );
2829 if ( RES_OK == result ){
2830 itemidsToZval( pitemids, itemidLen, &ziids );
2831 freeItemID( pitemids );
2832 }
2833 }
2834 RETURN_LONG(result);
2835 }
2836
2837
2838 ZEND_FUNCTION(xnp_get_overlapped_items)
2839 {
2840 RETURN_LONG( RES_ERROR );
2841 }
2842
2843 /**
2844 *
2845 * ?≪?ゃ????(Basic Information)???脂?蚊????.
2846 * Platform???若?銀札筝???┤????綽?荀?.
2847 *
2848 * @param sid ?祉???激?с??D
2849 * @param item ?脂?蚊???????≪?ゃ??????????/span>
2850 * @param itemid ?脂?蚊?????≪?ゃ??????D??????????綣???/span>
2851 * @return RES_OK
2852 * @return RES_ERROR
2853 * @return RES_NO_SUCH_SESSION
2854 * @return RES_DB_QUERY_ERROR
2855 * @return RES_DB_NOT_INITIALIZED
2856 * @return RES_NO_WRITE_ACCESS_RIGHT
2857 *
2858 */
2859 ZEND_FUNCTION(xnp_insert_item)
2860 {
2861 long sid;
2862 zval *ziid;
2863 zval *zitem;
2864 item_t item;
2865 itemid_t iid;
2866 result_t result = RES_ERROR;
2867
2868 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2869 &sid, &zitem, &ziid) == FAILURE) {
2870 fprintf( stderr, "error occured " );
2871 return;
2872 }
2873
2874 zvalToItem( zitem, &item );
2875 result = insertItem( (sessionid_t)sid, &item, &iid );
2876 if ( RES_OK == result ){
2877 ziid -> type = IS_LONG;
2878 ziid -> value.lval = iid;
2879 }
2880 RETURN_LONG( result );
2881 }
2882
2883 /**
2884 *
2885 * ?≪?ゃ????(Basic Information)???贋?違????.
2886 * Platform???若?銀札筝???┤????綽?荀?.
2887 * item??tem_id??罩c????祉????????????
2888 *
2889 * @param sid ?祉???激?с??D
2890 * @param item ?贋?違???????≪?ゃ??????????/span>
2891 * @return RES_OK
2892 * @return RES_ERROR
2893 * @return RES_NO_SUCH_SESSION
2894 * @return RES_DB_QUERY_ERROR
2895 * @return RES_DB_NOT_INITIALIZED
2896 * @return RES_NO_WRITE_ACCESS_RIGHT
2897 */
2898 ZEND_FUNCTION(xnp_update_item)
2899 {
2900 long sid;
2901 zval *zitem;
2902 item_t item;
2903 result_t result = RES_ERROR;
2904
2905 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
2906 &sid, &zitem) == FAILURE) {
2907 fprintf( stderr, "error occured " );
2908 return;
2909 }
2910
2911 zvalToItem( zitem, &item );
2912 result = updateItem( (sessionid_t)sid, &item );
2913 RETURN_LONG( result );
2914 }
2915
2916 /**
2917 *
2918 * ?≪?ゃ????(Basic Information)?????ゃ????.
2919 *
2920 * @param sid ?祉???激?с??D
2921 * @param item ???ゃ???????≪?ゃ??????????/span>
2922 * @return RES_OK
2923 * @return RES_ERROR
2924 * @return RES_NO_SUCH_SESSION
2925 * @return RES_DB_QUERY_ERROR
2926 * @return RES_DB_NOT_INITIALIZED
2927 * @return RES_NO_WRITE_ACCESS_RIGHT
2928 */
2929 ZEND_FUNCTION(xnp_delete_item)
2930 {
2931 long sid;
2932 itemid_t iid;
2933 result_t result = RES_ERROR;
2934
2935 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2936 &sid, &iid) == FAILURE) {
2937 fprintf( stderr, "error occured " );
2938 return;
2939 }
2940 result = deleteItem( (sessionid_t)sid, iid );
2941 RETURN_LONG( result );
2942 }
2943
2944
2945 /**
2946 *
2947 * ??篋冴?????????≪?ゃ??????D????緇????障??鐚?/span>
2948 * ?????ゃ?潟???????鴻???脂?我?粋?????????????????????帥?障????
2949 *
2950 * @param sid ?祉???激?с??D
2951 * @param uid 絲乗院???若?吟??D
2952 * @param iids ?脂?蚊???????≪?ゃ????ID??????????綣???/span>
2953 * @param iidsLen iids???主??????????違??????????綣???/span>
2954 * @return RES_OK
2955 * @return RES_DB_NOT_INITIALIZED
2956 * @return RES_NO_SUCH_SESSION
2957 * @return RES_DB_QUERY_ERROR
2958 * @return RES_ERROR
2959 *
2960 */
2961 //result_t getPrivateItemID( sessionid_t sid, userid_t uid, const itemid_t** iids, int* iidsLen )
2962 ZEND_FUNCTION(xnp_get_private_item_id)
2963 {
2964 long sid;
2965 userid_t uid;
2966 zval* ziids;
2967
2968 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
2969 &sid, &uid, &ziids) == FAILURE) {
2970 return;
2971 }
2972
2973 const itemid_t *piids;
2974 int iidsLen;
2975 result_t result = getPrivateItemID( (sessionid_t)sid, uid, &piids, &iidsLen );
2976 if ( RES_OK == result ){
2977 itemidsToZval( piids, iidsLen, &ziids );
2978 freeItemID( piids );
2979 }
2980
2981 RETURN_LONG( result );
2982
2983 }
2984
2985 /**
2986 *
2987 * ?違???若???ゃ?潟???????鴻???脂?蚊???????≪?ゃ??????D????緇????障??鐚?/span>
2988 *
2989 * @param sid ?祉???激?с??D
2990 * @param uid 絲乗院?違???若????D
2991 * @param iids ?脂?蚊???????≪?ゃ????ID??????????綣???/span>
2992 * @param iidsLen iids???主??????????違??????????綣???/span>
2993 * @return RES_OK
2994 * @return RES_DB_NOT_INITIALIZED
2995 * @return RES_NO_SUCH_SESSION
2996 * @return RES_DB_QUERY_ERROR
2997 * @return RES_ERROR
2998 *
2999 */
3000 //result_t getGroupItemID( sessionid_t sid, groupid_t gid, const itemid_t** iids, int* iidsLen )
3001 ZEND_FUNCTION(xnp_get_group_item_id)
3002 {
3003 long sid;
3004 groupid_t gid;
3005 zval* ziids;
3006
3007 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
3008 &sid, &gid, &ziids) == FAILURE) {
3009 return;
3010 }
3011
3012 const itemid_t *piids;
3013 int iidsLen;
3014 result_t result = getGroupItemID( (sessionid_t)sid, gid, &piids, &iidsLen );
3015 if ( RES_OK == result ){
3016 itemidsToZval( piids, iidsLen, &ziids );
3017 freeItemID( piids );
3018 }
3019
3020 RETURN_LONG( result );
3021 }
3022
3023
3024 /**
3025 *
3026 * ?≪?ゃ???????怨??.
3027 * ??緇??????≪?ゃ???????篏睡???freeItem?цВ?障????.
3028 *
3029 * @refer freeItem
3030 * @param sid ?祉???激?с??D
3031 * @param iid ??緇????????≪?ゃ??????D
3032 * @param item 腟??????≪?ゃ???????宴??????????綣???/span>
3033 * @return RES_OK
3034 * @return RES_DB_NOT_INITIALIZED
3035 * @return RES_NO_SUCH_SESSION
3036 * @return RES_NO_SUCH_ITEM
3037 * @return RES_DB_QUERY_ERROR
3038 *
3039 */
3040 ZEND_FUNCTION(xnp_get_item)
3041 {
3042 long sid;
3043 long iid;
3044 zval *zitem;
3045 result_t result = RES_ERROR;
3046
3047 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
3048 &sid, &iid, &zitem) == FAILURE) {
3049 fprintf( stderr, "error occured " );
3050 return;
3051 }
3052
3053 const item_t* pitem;
3054 result = getItem( (sessionid_t)sid, iid, &pitem );
3055 if ( RES_OK == result ){
3056 itemToZval( pitem, zitem );
3057 freeItem( pitem );
3058 }
3059 RETURN_LONG( result );
3060 }
3061
3062
3063 /**
3064 *
3065 * ?≪?ゃ???????怨??.
3066 * ??緇??????≪?ゃ???????篏睡???freeItem?цВ?障????.
3067 *
3068 * @refer freeItem
3069 * @param sid ?祉???激?с??D
3070 * @param iids ??緇????????≪?ゃ??????D??????
3071 * @param iidsLen iids???????膣???/span>
3072 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
3073 * @param items 罎?膣∝??????????????ゃ?潟?帥???吾??莨若??綣???/span>
3074 * @param itemsLen 罎?膣∝???????????*items???膣???
3075 * @return RES_OK
3076 * @return RES_DB_NOT_INITIALIZED
3077 * @return RES_NO_SUCH_SESSION
3078 * @return RES_DB_QUERY_ERROR
3079 *
3080 */
3081 ZEND_FUNCTION(xnp_get_items)
3082 {
3083 result_t result;
3084 long sid;
3085 zval *ziids;
3086 zval *zcriteria;
3087 zval *zitem;
3088
3089 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
3090 &sid, &ziids, &zcriteria, &zitem) == FAILURE) {
3091 return;
3092 }
3093
3094 zCriteria_t zcri(zcriteria);
3095 result = zcri.getResult();
3096 if ( RES_OK == result ){
3097 zIIDs_t zIIDs(ziids);
3098 result = zIIDs.getResult();
3099 if ( RES_OK == result ){
3100 const item_t *pitems;
3101 int itemLen;
3102 result = getItems( (sessionid_t)sid,
3103 zIIDs.getPIID(), zIIDs.getLen(),
3104 &zcri, &pitems, &itemLen );
3105 if ( RES_OK == result ){
3106 itemsToZval( pitems, itemLen, zitem );
3107 freeItem( pitems );
3108 }
3109 }
3110 }
3111
3112 RETURN_LONG(result);
3113 }
3114
3115
3116 /**
3117 *
3118 *
3119 * @param pmid PUBMEDID
3120 * @param pubmed 腟??????吾??莨若??pubmed_t?????ゃ?潟?水???/span>
3121 *
3122 *
3123 *
3124 */
3125 ZEND_FUNCTION(xnp_pubmed_complete)
3126 {
3127 long pmid;
3128 zval *zpubmed;
3129 result_t result = RES_ERROR;
3130
3131 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
3132 &pmid, &zpubmed) == FAILURE) {
3133 fprintf( stderr, "error occured " );
3134 return;
3135 }
3136
3137 const pubmed_t* ppubmed;
3138 result = pubmedComplete( pmid, &ppubmed );
3139 if ( RES_OK == result ){
3140 pubmedToZval( ppubmed, zpubmed );
3141 freePubmed( ppubmed );
3142 }
3143 RETURN_LONG( result );
3144 }
3145
3146
3147 /**
3148 *
3149 *
3150 * @param isbn ISBN
3151 * @param amazonbook 腟??????吾??莨若??amazonbook_t?????ゃ?潟?水???/span>
3152 *
3153 *
3154 *
3155 */
3156 ZEND_FUNCTION(xnp_amazon_complete)
3157 {
3158 zval *zurl;
3159 zval *zamazonbook;
3160 result_t result = RES_ERROR;
3161
3162 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za",
3163 &zurl, &zamazonbook) == FAILURE) {
3164 fprintf( stderr, "error occured " );
3165 return;
3166 }
3167
3168 const amazonbook_t* pamazonbook;
3169 result = amazonComplete( getZvalString( &zurl ) , &pamazonbook );
3170 if ( RES_OK == result ){
3171 amazonbookToZval( pamazonbook, zamazonbook );
3172 //freeAmazonbook( pamazonbook );
3173 }
3174 RETURN_LONG( result );
3175 }
3176
3177
3178 //ZEND_FUNCTION(xnp_uninitialize_db)
3179 //{
3180 // RETURN_LONG( RES_ERROR );
3181 //}
3182
3183
3184 /**
3185 *
3186 * ???ゃ?潟???若???≪?ゃ??????菴遵??????
3187 *
3188 * @param sid ?祉???激?с??D
3189 * @param binderid ????絲乗院?????ゃ?潟???若??D
3190 * @param iid ???ゃ?潟???若??申?????????≪?ゃ??????D
3191 * @return RES_OK
3192 * @return RES_DB_QUERY_ERROR
3193 * @return RES_NO_SUCH_SESSION
3194 * @return RES_NO_WRITE_ACCESS_RIGHT
3195 * @return RES_ERROR
3196 *
3197 */
3198 ZEND_FUNCTION(xnp_register_binder_item)
3199 {
3200 result_t result = RES_ERROR;
3201 long sid;
3202 long bid;
3203 long iid;
3204
3205 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3206 &sid, &bid, &iid) == FAILURE) {
3207 return;
3208 }
3209
3210 result = registerBinderItem( (sessionid_t)sid, bid, iid );
3211 RETURN_LONG(result);
3212 }
3213
3214
3215 /**
3216 *
3217 * ???ゃ?潟???若?????≪?ゃ?????????ゃ????
3218 *
3219 * @param sid ?祉???激?с??D
3220 * @param binderid ????絲乗院?????ゃ?潟???若??D
3221 * @param iid ???ゃ?潟???若???????ゃ???????≪?ゃ??????D
3222 * @return RES_OK
3223 * @return RES_DB_QUERY_ERROR
3224 * @return RES_NO_SUCH_SESSION
3225 * @return RES_NO_WRITE_ACCESS_RIGHT
3226 * @return RES_ERROR
3227 *
3228 */
3229 ZEND_FUNCTION(xnp_unregister_binder_item)
3230 {
3231 result_t result = RES_ERROR;
3232 long sid;
3233 long bid;
3234 long iid;
3235
3236 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3237 &sid, &bid, &iid) == FAILURE) {
3238 return;
3239 }
3240
3241 result = registerBinderItem( (sessionid_t)sid, bid, iid );
3242 RETURN_LONG(result);
3243 }
3244
3245
3246 /**
3247 *
3248 * ?ゃ?潟???????鴻???≪?ゃ??????菴遵??????
3249 *
3250 * @param sid ?祉???激?с??D
3251 * @param xid ????絲乗院???ゃ?潟???????鴻??D
3252 * @param iid ?ゃ?潟???????鴻??申?????????≪?ゃ??????D
3253 * @return RES_OK
3254 * @return RES_DB_QUERY_ERROR
3255 * @return RES_NO_SUCH_SESSION
3256 * @return RES_NO_WRITE_ACCESS_RIGHT
3257 * @return RES_ERROR
3258 *
3259 */
3260 ZEND_FUNCTION(xnp_register_item)
3261 {
3262 result_t result = RES_ERROR;
3263 long sid;
3264 long xid;
3265 long iid;
3266
3267 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3268 &sid, &xid, &iid) == FAILURE) {
3269 return;
3270 }
3271
3272 result = registerItem( (sessionid_t)sid, xid, iid );
3273 RETURN_LONG(result);
3274 }
3275
3276
3277 /**
3278 *
3279 * ?ゃ?潟???????鴻?????≪?ゃ?????????ゃ????
3280 *
3281 * @param sid ?祉???激?с??D
3282 * @param xid ????絲乗院???ゃ?潟???????鴻??D
3283 * @param iid ?ゃ?潟???????鴻???????ゃ???????≪?ゃ??????D
3284 * @return RES_OK
3285 * @return RES_DB_QUERY_ERROR
3286 * @return RES_NO_SUCH_SESSION
3287 * @return RES_NO_WRITE_ACCESS_RIGHT
3288 * @return RES_ERROR
3289 *
3290 */
3291 ZEND_FUNCTION(xnp_unregister_item)
3292 {
3293 result_t result = RES_ERROR;
3294 long sid;
3295 long xid;
3296 long iid;
3297
3298 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3299 &sid, &xid, &iid) == FAILURE) {
3300 return;
3301 }
3302
3303 result = unregisterItem( (sessionid_t)sid, xid, iid );
3304 RETURN_LONG(result);
3305 }
3306
3307
3308 /**
3309 *
3310 * ?粋?緇??∞?倶?????≪?ゃ?????????¥??粋?罔??????????≪?ゃ??????D???脂?峨???ゃ?潟???????鴻??D?????≪?у?????障??.
3311 * ?≪?ゃ????iids[i]???上??ids[i]?吾???脂?蚊???粋?緇??∞?倶??????????????菴????障??鐚?/span>
3312 *
3313 * @param sid ?祉???激?с??D
3314 * @param xids ?粋?緇??<?≪?ゃ???????脂?蚊?????ゃ?潟????????D??????????綣???/span>
3315 * @param iids ?粋?緇??<?≪?ゃ????ID??????????綣???/span>
3316 * @param len iids,xids???主??????????違??????????綣???/span>
3317 * @return RES_OK
3318 * @return RES_DB_NOT_INITIALIZED
3319 * @return RES_NO_SUCH_SESSION
3320 * @return RES_DB_QUERY_ERROR
3321 * @return RES_ERROR
3322 *
3323 */
3324 //result_t getUncertifiedLink( sessionid_t sid, const itemid_t** xids, const itemid_t** iids, int* len )
3325 ZEND_FUNCTION(xnp_get_uncertified_link)
3326 {
3327 long sid;
3328 zval* zxids;
3329 zval* ziids;
3330
3331 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
3332 &sid, &zxids, &ziids) == FAILURE) {
3333 return;
3334 }
3335
3336 const itemid_t *pxids;
3337 const itemid_t *piids;
3338 int len;
3339 result_t result = getUncertifiedLink( (sessionid_t)sid, &pxids, &piids, &len );
3340 if ( RES_OK == result ){
3341 indexidsToZval( pxids, len, &zxids );
3342 itemidsToZval( piids, len, &ziids );
3343 freeIndexID( pxids );
3344 freeItemID( piids );
3345 }
3346 RETURN_LONG( result );
3347 }
3348
3349 /**
3350 *
3351 * @param types
3352 * @return RES_OK
3353 * @return RES_DB_NOT_INITIALIZED
3354 * @return RES_NO_SUCH_SESSION
3355 * @return RES_DB_QUERY_ERROR
3356 * @return RES_ERROR
3357 *
3358 */
3359 ZEND_FUNCTION(xnp_get_item_types)
3360 {
3361 zval* ztypes;
3362
3363 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
3364 &ztypes) == FAILURE) {
3365 return;
3366 }
3367
3368 const itemtype_t *ptypes;
3369 int len;
3370 result_t result = getItemTypes( &ptypes, &len );
3371 if ( RES_OK == result ){
3372
3373 zend_hash_clean( ztypes -> value.ht );
3374 for( int i = 0; i < len; i++ ){
3375 zval *new_array;
3376 MAKE_STD_ZVAL(new_array);
3377