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.35 - (show annotations) (download) (as text)
Mon Feb 21 05:45:20 2005 UTC (19 years, 1 month ago) by tani
Branch: MAIN
Changes since 1.34: +26 -2 lines
File MIME type: text/x-c++src
xnp_item_countを追加.

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