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.36 - (show annotations) (download) (as text)
Fri Feb 25 09:45:45 2005 UTC (19 years, 1 month ago) by tani
Branch: MAIN
Changes since 1.35: +28 -1 lines
File MIME type: text/x-c++src
item_number_limit, item_storage_limit, index_number_limitの対応.

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