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.34 - (show annotations) (download) (as text)
Thu Feb 17 02:05:48 2005 UTC (19 years, 1 month ago) by youi
Branch: MAIN
CVS Tags: mv_to_sourceforge_20050217
Changes since 1.33: +19 -1 lines
File MIME type: text/x-c++src
itemToZval, zvalToItem: publication_year/month/mdayに対応.

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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26