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.33 - (show annotations) (download) (as text)
Wed Feb 9 11:12:39 2005 UTC (19 years, 2 months ago) by youi
Branch: MAIN
Changes since 1.32: +52 -1 lines
File MIME type: text/x-c++src
xnp_zip_createを追加.

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

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