Develop and Download Open Source Software

Browse CVS Repository

Annotation of /xoonips/AL/xnpal.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.25 - (hide annotations) (download) (as text)
Mon Jan 24 01:53:03 2005 UTC (19 years, 2 months ago) by youi
Branch: MAIN
Changes since 1.24: +5 -5 lines
File MIME type: text/x-c++src
引数の型修飾を変更.
itemidsToZval, dumpItemID, getItemIDByBinderID, getItemIDByIndexID

1 aga 1.1 /*
2 youi 1.25 $Revision: 1.24 $
3 youi 1.21 XNPAL: XooNiPs Platform Abstract Layer
4 youi 1.24
5 aga 1.1 zend_parse_parameters??hp4.1.0??綽?荀?
6     .so???<?ゃ?????????荀????????贋????舟??鴻????
7     C++?с????extern "C"{}, BEGIN/END_EXTERN_C()??綽?荀???
8     */
9    
10    
11     #include <stdio.h>
12 aga 1.2 #include "criteria.h"
13     #include "common.h"
14     #include "commonal.h"
15     #include "session.h"
16     #include "group.h"
17 youi 1.24 #include "index.h"
18 youi 1.21 #include "xnpal.h"
19 youi 1.24 #include "amazonbook.h"
20 aga 1.1
21 aga 1.2 // for inet_aton
22     #include <sys/socket.h>
23     #include <netinet/in.h>
24     #include <arpa/inet.h>
25    
26 aga 1.1 // global variables
27    
28 youi 1.21 PHP_MSHUTDOWN_FUNCTION(xnpalmod)
29 aga 1.18 {
30     uninitializeDB();
31     return SUCCESS;
32     }
33 aga 1.1
34     /* declaration of functions to be exported */
35     extern "C" {
36 aga 1.2 ZEND_FUNCTION(first_module );
37 youi 1.21 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 aga 1.2
67 aga 1.22 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 youi 1.21 ZEND_FUNCTION(xnp_is_valid_session_id );
78     ZEND_FUNCTION(xnp_get_last_error_string );
79 aga 1.9
80 youi 1.21 ZEND_FUNCTION(xnp_test_criteria );
81     ZEND_FUNCTION(xnp_test_uids );
82 youi 1.24
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 aga 1.1 };
120     /* compiled function list so Zend knows what's in this module */
121 youi 1.21 zend_function_entry xnpalmod_functions[] =
122 aga 1.1 {
123 youi 1.24 ZEND_FE(first_module ,NULL)
124     ZEND_FE(xnp_initialize_db ,NULL)
125     ZEND_FE(xnp_login_user ,NULL)
126     ZEND_FE(xnp_logout_user ,NULL)
127     ZEND_FE(xnp_create_session ,NULL)
128     ZEND_FE(xnp_get_session ,NULL)
129     ZEND_FE(xnp_is_activated ,NULL)
130     ZEND_FE(xnp_activate ,NULL)
131     ZEND_FE(xnp_get_account_count ,NULL)
132     ZEND_FE(xnp_delete_account ,NULL)
133     ZEND_FE(xnp_get_account ,NULL)
134     ZEND_FE(xnp_get_accounts ,NULL)
135     ZEND_FE(xnp_insert_account ,NULL)
136     ZEND_FE(xnp_update_account ,NULL)
137     ZEND_FE(xnp_dump_uids ,NULL)
138     ZEND_FE(xnp_get_group_count ,NULL)
139     ZEND_FE(xnp_get_groups_by_uid ,NULL)
140     ZEND_FE(xnp_is_group_admin ,NULL)
141     ZEND_FE(xnp_dump_gids ,NULL)
142     ZEND_FE(xnp_dump_group_admins ,NULL)
143     ZEND_FE(xnp_delete_member ,NULL)
144     ZEND_FE(xnp_insert_member ,NULL)
145     ZEND_FE(xnp_get_members ,NULL)
146     ZEND_FE(xnp_delete_group ,NULL)
147     ZEND_FE(xnp_insert_group ,NULL)
148     ZEND_FE(xnp_update_group ,NULL)
149     ZEND_FE(xnp_get_group ,NULL)
150     ZEND_FE(xnp_get_groups ,NULL)
151     ZEND_FE(xnp_is_moderator ,NULL)
152     ZEND_FE(xnp_get_uid ,NULL)
153    
154     ZEND_FE(xnp_get_all_indexes ,NULL)
155     ZEND_FE(xnp_get_indexes ,NULL)
156     ZEND_FE(xnp_insert_index ,NULL)
157     ZEND_FE(xnp_update_index ,NULL)
158     ZEND_FE(xnp_delete_index ,NULL)
159     ZEND_FE(xnp_get_index ,NULL)
160     ZEND_FE(xnp_is_index_readable ,NULL)
161     ZEND_FE(xnp_is_index_writable ,NULL)
162     ZEND_FE(xnp_swap_index_sort_number ,NULL)
163    
164     ZEND_FE(xnp_is_valid_session_id ,NULL)
165     ZEND_FE(xnp_get_last_error_string ,NULL)
166     ZEND_FE(xnp_test_criteria ,NULL)
167     ZEND_FE(xnp_test_uids ,NULL)
168    
169     ZEND_FE(xnp_get_item_permission ,NULL)
170     ZEND_FE(xnp_get_index_permission ,NULL)
171     ZEND_FE(xnp_get_certify_permission ,NULL)
172    
173     ZEND_FE(xnp_get_certify_state ,NULL)
174     ZEND_FE(xnp_set_certify_state ,NULL)
175    
176     ZEND_FE(xnp_insert_change_log ,NULL)
177     ZEND_FE(xnp_get_change_logs ,NULL)
178    
179     ZEND_FE(xnp_get_config_value ,NULL)
180     ZEND_FE(xnp_set_config_value ,NULL)
181    
182     ZEND_FE(xnp_dump_item_id ,NULL)
183     ZEND_FE(xnp_get_item_id_by_binder_id ,NULL)
184     ZEND_FE(xnp_get_item_id_by_index_id ,NULL)
185     ZEND_FE(xnp_get_overlapped_items ,NULL)
186    
187     ZEND_FE(xnp_insert_item ,NULL)
188     ZEND_FE(xnp_update_item ,NULL)
189     ZEND_FE(xnp_delete_item ,NULL)
190     ZEND_FE(xnp_get_item ,NULL)
191     ZEND_FE(xnp_get_items ,NULL)
192    
193     ZEND_FE(xnp_pubmed_complete ,NULL)
194     ZEND_FE(xnp_amazon_complete ,NULL)
195    
196     // ZEND_FE(xnp_uninitialize_db ,NULL)
197    
198     ZEND_FE(xnp_register_binder_item ,NULL)
199     ZEND_FE(xnp_unregister_binder_item ,NULL)
200    
201     ZEND_FE(xnp_register_item ,NULL)
202     ZEND_FE(xnp_unregister_item ,NULL)
203    
204     {NULL, NULL, NULL}
205 aga 1.1 };
206    
207     /* compiled module information */
208 youi 1.21 zend_module_entry xnpalmod_module_entry =
209 aga 1.1 {
210 youi 1.24 STANDARD_MODULE_HEADER,
211     "Visiome Platform Abstract Layer",
212     xnpalmod_functions,
213     NULL,
214 youi 1.21 PHP_MSHUTDOWN(xnpalmod),
215 youi 1.24 NULL,
216     NULL,
217     NULL,
218     NO_VERSION_YET,
219     STANDARD_MODULE_PROPERTIES
220 aga 1.1 };
221    
222     /* implement standard "stub" routine to introduce ourselves to Zend */
223     #if COMPILE_DL_FIRST_MODULE
224     BEGIN_EXTERN_C()
225 youi 1.21 ZEND_GET_MODULE(xnpalmod)
226 aga 1.1 END_EXTERN_C()
227     #endif
228    
229 aga 1.16
230 aga 1.1 /* implement function that is meant to be made available to PHP */
231     ZEND_FUNCTION(first_module)
232     {
233 youi 1.24 long parameter;
234 aga 1.1 // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
235 youi 1.24 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
236     return;
237     }
238 aga 1.1 parameter++;
239 youi 1.24 RETURN_LONG(parameter);
240 aga 1.1 }
241     /** zval????C????絖?????緇?????
242     */
243     char *getZvalString( zval **p ){
244     convert_to_string_ex(p);
245     return Z_STRVAL_PP(p); //(**p).value.str.val;
246     }
247    
248     /** zval????int??緇?????
249     */
250     int getZvalInt( zval **p ){
251     convert_to_long_ex(p);
252     return Z_LVAL_PP(p); // (int)(**p).value.lval;
253     }
254    
255 aga 1.2 // keylen????鮎??0????????
256     static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
257     zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
258     if ( res == HASH_KEY_IS_STRING ){
259     char *p = new char[keyLen+1];
260     memcpy( p, key, keyLen );
261     p[keyLen] = 0;
262     zend_printf( " key is string[%s]<br>\n", p );
263     }
264     else {
265     zend_printf( " key is integer[%d]<br>\n", index );
266     }
267     }
268    
269    
270 aga 1.16 /** zval*????criteria_t?????????????????????鴻??????紊掩??????getResult()!=RES_OK <br>
271 youi 1.24 criteria :
272     array( 'start'=>0, 'rows'=>10,
273     'orders'=>array(
274     array('name'=>'id','order'=>'0'),
275     array('name'=>'timestamp','name'=>'1'), ...)
276     ); ??????就???f?渇????
277 aga 1.2 */
278     class zCriteria_t : public criteria {
279     private:
280     result_t result;
281 aga 1.16
282 aga 1.2 // pz: array('name'=>'timestamp','name'=>'1')
283     // ????????orderby??篏???????申????
284     void setOrder( zval *pz ){
285     char *column = 0;
286     order_t order = (order_t)0;
287 youi 1.24
288 aga 1.2 HashPosition pos;
289     zval **ppzTmp = 0;
290     int res2;
291     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
292     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
293     char *key = 0;
294     uint keyLen = 0;
295     ulong index = 0;
296     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
297     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
298 aga 1.14 //print_hash_key( keyType, key, keyLen, index );
299     if ( strncasecmp( key, "name", keyLen ) == 0 && keyLen == 5 ){
300 aga 1.2 SEPARATE_ZVAL(ppzTmp);
301     column = getZvalString(ppzTmp);
302     // zend_printf( "column=%s<br>\n", column );
303     }
304     else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
305     SEPARATE_ZVAL(ppzTmp);
306     order = (order_t)getZvalInt(ppzTmp);
307     // zend_printf( "order=%d<br>\n", order );
308     }
309     }
310 youi 1.24
311 aga 1.2 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
312     }
313     if ( column ){
314     orderby *o = new orderby( column, order );
315     addOrderBy( o );
316     }
317 youi 1.24
318 aga 1.2 result = RES_OK;
319     }
320 youi 1.24
321 aga 1.2 // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
322     void setOrders( zval *pz ){
323     HashPosition pos;
324 youi 1.24
325 aga 1.2 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
326 youi 1.24
327 aga 1.2 zval **ppzTmp = 0;
328     int res2;
329     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
330     char *key = 0;
331     uint keyLen = 0;
332     ulong index = 0;
333     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
334     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
335 aga 1.14 //print_hash_key( keyType, key, keyLen, index );
336 aga 1.2 setOrder( *ppzTmp );
337     }
338     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
339     }
340     result = RES_OK;
341     }
342 youi 1.24
343 aga 1.2 void initialize( zval *pz ){
344     HashPosition pos;
345     zval **ppzTmp = 0;
346     int res2;
347     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
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 aga 1.14 //print_hash_key( keyType, key, keyLen, index );
355 aga 1.2 if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
356     SEPARATE_ZVAL(ppzTmp);
357     int tmp = getZvalInt(ppzTmp);
358     // zend_printf( "start=%d<br>\n", tmp );
359     setLimit( tmp, getLimitRows() );
360     }
361     else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
362     SEPARATE_ZVAL(ppzTmp);
363     int tmp = getZvalInt(ppzTmp);
364     // zend_printf( "rows=%d<br>\n", tmp );
365     setLimit( getLimitStart(), tmp );
366     }
367     else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
368     setOrders( *ppzTmp );
369     }
370     else
371     ; // ignore unknown key
372     }
373     else
374     ; // ignore bad key
375     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
376     }
377     result = RES_OK;
378     }
379 aga 1.16
380     public:
381 aga 1.2 zCriteria_t() : criteria(){ result = RES_ERROR; }
382     zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
383     zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
384     result_t getResult(){ return result; };
385 youi 1.24
386 aga 1.2 void dump(){
387     zend_printf( "dumping zCriteria...<br>\n" );
388     zend_printf( "result=%d<br>\n", (int)result );
389     zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() );
390     const orderby *p = headOrderBy();
391     while ( p ){
392     zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() );
393     p = nextOrderBy();
394     }
395     }
396     };
397    
398 aga 1.16
399     /** ?f?渇???????≪???祉?鴻????ong?ゃ??緇?????
400     @param ht ?f?渇????
401     @param key ????/span>
402     @param val long?ゃ?????????????ゃ?潟??/span>
403     @return ????????true
404     */
405     static bool hashGetLong( HashTable *ht, const char *key, long *val ){
406 youi 1.24 zval **tmp;
407     if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
408     convert_to_long_ex( tmp );
409     *val = Z_LVAL_PP(tmp);
410     return true;
411     }
412     return false;
413 aga 1.14 }
414    
415 aga 1.16 /** ?f?渇???????≪???祉?鴻??????絖?????緇?????
416     @param ht ?f?渇????
417     @param key ????/span>
418     @param val ??絖????????????????ゃ?潟??/span>
419     @return ????????true
420     */
421     static bool hashGetString( HashTable *ht, const char *key, char **val ){
422 youi 1.24 zval **tmp;
423     if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
424     convert_to_string_ex( tmp );
425     *val = Z_STRVAL_PP(tmp);
426     return true;
427     }
428     return false;
429 aga 1.14 }
430    
431 aga 1.16 /** ?f?渇???????≪???祉?鴻????ouble?ゃ??緇?????
432     @param ht ?f?渇????
433     @param key ????/span>
434     @param val double?ゃ?????????????ゃ?潟??/span>
435     @return ????????true
436     */
437     static bool hashGetDouble( HashTable *ht, const char *key, double *val ){
438 youi 1.24 zval **tmp;
439     if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
440     convert_to_double_ex( tmp );
441     *val = Z_DVAL_PP(tmp);
442     return true;
443     }
444     return false;
445 aga 1.14 }
446 aga 1.2
447 aga 1.16 /** zval*????account?????????????????????鴻?? <br>
448 youi 1.24 ????紊掩??????getResult()!=RES_OK <br>
449 aga 1.16 */
450 aga 1.2 class zAccount_t : public account {
451     private:
452     result_t result;
453     void initialize(zval *pz){
454 aga 1.14 HashTable *ht = Z_ARRVAL_P(pz);
455     long l;
456     char *p;
457     double d;
458     if ( hashGetLong ( ht, "uid" , &l ) ) setUID ( l );
459     if ( hashGetString( ht, "uname" , &p ) ) setUname ( p );
460     if ( hashGetString( ht, "name" , &p ) ) setName ( p );
461     if ( hashGetString( ht, "email" , &p ) ) setEmail ( p );
462     if ( hashGetString( ht, "url" , &p ) ) setURL ( p );
463     if ( hashGetString( ht, "user_avatar" , &p ) ) setUserAvatar ( p );
464     if ( hashGetString( ht, "user_icq" , &p ) ) setUserIcq ( p );
465     if ( hashGetString( ht, "user_from" , &p ) ) setUserFrom ( p );
466     if ( hashGetString( ht, "user_sig" , &p ) ) setUserSig ( p );
467     if ( hashGetString( ht, "actkey" , &p ) ) setActkey ( p );
468     if ( hashGetString( ht, "user_aim" , &p ) ) setUserAim ( p );
469     if ( hashGetString( ht, "user_yim" , &p ) ) setUserYim ( p );
470     if ( hashGetString( ht, "user_msnm" , &p ) ) setUserMsnm ( p );
471     if ( hashGetString( ht, "pass" , &p ) ) setPass ( p );
472     if ( hashGetString( ht, "theme" , &p ) ) setTheme ( p );
473     if ( hashGetString( ht, "umode" , &p ) ) setUmode ( p );
474     if ( hashGetString( ht, "user_occ" , &p ) ) setUserOcc ( p );
475     if ( hashGetString( ht, "bio" , &p ) ) setBio ( p );
476     if ( hashGetString( ht, "user_intrest" , &p ) ) setUserIntrest ( p );
477     if ( hashGetDouble( ht, "timezone_offset" , &d ) ) setTimezoneOffset ( d );
478     if ( hashGetLong ( ht, "attachsig" , &l ) ) setAttachsig ( l );
479     if ( hashGetLong ( ht, "last_login" , &l ) ) setLastLogin ( l );
480     if ( hashGetLong ( ht, "level" , &l ) ) setLevel ( l );
481     if ( hashGetLong ( ht, "notify_method" , &l ) ) setNotifyMethod ( l );
482     if ( hashGetLong ( ht, "notify_mode" , &l ) ) setNotifyMode ( l );
483     if ( hashGetLong ( ht, "posts" , &l ) ) setPosts ( l );
484     if ( hashGetLong ( ht, "rank" , &l ) ) setRank ( l );
485     if ( hashGetLong ( ht, "uorder" , &l ) ) setUorder ( l );
486     if ( hashGetLong ( ht, "user_mailok" , &l ) ) setUserMailok ( l );
487     if ( hashGetLong ( ht, "user_regdate" , &l ) ) setUserRegdate ( l );
488     if ( hashGetLong ( ht, "user_viewemail" , &l ) ) setUserViewemail ( l );
489     if ( hashGetLong ( ht, "activate" , &l ) ) setActivate ( l );
490     if ( hashGetString( ht, "address" , &p ) ) setAddress ( p );
491 aga 1.16 if ( hashGetString( ht, "division" , &p ) ) setDivision ( p );
492 aga 1.14 if ( hashGetString( ht, "tel" , &p ) ) setTel ( p );
493 aga 1.16 if ( hashGetString( ht, "company_name" , &p ) ) setCompanyName ( p );
494 aga 1.14 if ( hashGetString( ht, "country" , &p ) ) setCountry ( p );
495     if ( hashGetString( ht, "zipcode" , &p ) ) setZipcode ( p );
496     if ( hashGetString( ht, "fax" , &p ) ) setFax ( p );
497     if ( hashGetString( ht, "base_url" , &p ) ) setBaseURL ( p );
498     if ( hashGetLong ( ht, "notice_mail" , &l ) ) setNoticeMail ( l );
499     if ( hashGetLong ( ht, "notice_mail_since" , &l ) ) setNoticeMailSince ( l );
500 aga 1.22 if ( hashGetLong ( ht, "private_index_id " , &l ) ) setPrivateIndexID ( l );
501 aga 1.14
502     result = RES_OK;
503 aga 1.2 }
504 aga 1.16 public:
505 aga 1.2 zAccount_t() : account(){ result = RES_ERROR; }
506 youi 1.24
507     /** ?潟?潟?鴻????????/span>
508     @param pz array( 'uid'=>1, 'uname'=>'root', ... ); ??????就???f?渇???? */
509 aga 1.2 zAccount_t( zval *pz ) : account(){ initialize(pz); }
510     zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
511     result_t getResult(){ return result; };
512     };
513    
514 aga 1.22 class zIndex_t : public index {
515     private:
516     result_t result;
517 youi 1.24
518 aga 1.22 void initialize(zval *pz){
519     HashTable *ht = Z_ARRVAL_P(pz);
520     long l;
521     char *p;
522     double d;
523     if ( hashGetLong ( ht, "item_id" , &l ) ) setItemID ( l );
524     if ( hashGetLong ( ht, "item_type_id" , &l ) ) setItemTypeID ( l );
525     if ( hashGetLong ( ht, "contributor_uid" , &l ) ) setContributorUID ( l );
526     if ( hashGetString( ht, "title" , &p ) ) setTitle ( p );
527     if ( hashGetString( ht, "keywords" , &p ) ) setKeywords ( p );
528     if ( hashGetString( ht, "description" , &p ) ) setDescription ( p );
529     if ( hashGetLong ( ht, "last_update_date" , &l ) ) setLastUpdateDate ( l );
530     if ( hashGetLong ( ht, "creation_date" , &l ) ) setCreationDate ( l );
531     if ( hashGetLong ( ht, "parent_index_id" , &l ) ) setParentIndexID ( l );
532     if ( hashGetLong ( ht, "owner_uid" , &l ) ) setOwnerUID ( l );
533     if ( hashGetLong ( ht, "owner_gid" , &l ) ) setOwnerGID ( l );
534     if ( hashGetLong ( ht, "open_level" , &l ) ) setOpenLevel ( l );
535     if ( hashGetLong ( ht, "sort_number" , &l ) ) setSortNumber ( l );
536    
537     result = RES_OK;
538     }
539     public:
540     zIndex_t() : index(){ result = RES_ERROR; }
541     zIndex_t( zval *pz ) : index(){ initialize(pz); }
542     zIndex_t( zval **ppz ) : index() { initialize(*ppz); }
543     result_t getResult(){ return result; };
544 youi 1.24
545 aga 1.22 void dump(){
546     }
547     };
548    
549 aga 1.16 /** zval*????(userid_t *puid,int uidLen)?????????????????????鴻?? <br>
550 youi 1.24 ????紊掩??????getResult()!=RES_OK <br>
551 aga 1.2 */
552     class zUIDs_t {
553     private:
554     result_t result;
555     userid_t *pUID;
556     int len;
557     public:
558     zUIDs_t(){
559     pUID = 0;
560     len = 0;
561     result = RES_ERROR;
562     }
563 youi 1.24
564     /** ?潟?潟?鴻????????/span>
565     @param pza array( '1', '3', '4', '6', ... ); ??????就?????? */
566 aga 1.2 zUIDs_t( zval *pza ){
567     pUID = 0;
568     len = 0;
569     result = RES_ERROR;
570 youi 1.24
571 aga 1.2 if ( Z_TYPE_P(pza) != IS_ARRAY ){
572     result = RES_ERROR;
573     }
574     else {
575     len = zend_hash_num_elements(Z_ARRVAL_P(pza));
576     if(len == 0) {
577     pUID = new userid_t[1];
578     result = RES_OK;
579     }
580     else {
581     /* php/ext/standard/string.c ? implode??????????????????
582     zend_hash_*???????ャ?<?潟???c????????????????鐚?
583     */
584     zval **tmp;
585     HashPosition pos;
586     int i = 0;
587     pUID = new userid_t[len];
588 youi 1.24
589 aga 1.2 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
590     while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
591     SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
592     convert_to_long_ex(tmp);
593     if ( i < len )
594     pUID[i++] = Z_LVAL_PP(tmp);
595     zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
596     }
597     len = i;
598     result = RES_OK;
599     }
600     }
601     }
602 youi 1.24
603 aga 1.2 ~zUIDs_t(){
604     if ( pUID ) delete[] pUID;
605     }
606     result_t getResult(){ return result; }
607     userid_t *getPUID(){ return pUID; }
608     int getLen(){ return len; }
609     void dump(){
610 youi 1.24 zend_printf( "dumping zUIDs...<br>\n" );
611 aga 1.2 zend_printf( "result=%d<br>\n", (int)result );
612     zend_printf( "len=%d<br>\n", len );
613     for ( int i = 0; i < len; i++ ){
614     zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
615     }
616     }
617     };
618    
619 youi 1.24 /** zval*????(itemid_t *piid,int iidLen)?????????????????????鴻?? <br>
620     ????紊掩??????getResult()!=RES_OK <br>
621     */
622     class zIIDs_t {
623     private:
624     result_t result;
625     itemid_t *pIID;
626     int len;
627     public:
628     zIIDs_t(){
629     pIID = 0;
630     len = 0;
631     result = RES_ERROR;
632     }
633    
634     /** ?潟?潟?鴻????????/span>
635     @param pza array( '1', '3', '4', '6', ... ); ??????就?????? */
636     zIIDs_t( zval *pza ){
637     pIID = 0;
638     len = 0;
639     result = RES_ERROR;
640    
641     if ( Z_TYPE_P(pza) != IS_ARRAY ){
642     result = RES_ERROR;
643     }
644     else {
645     len = zend_hash_num_elements(Z_ARRVAL_P(pza));
646     if(len == 0) {
647     pIID = new itemid_t[1];
648     result = RES_OK;
649     }
650     else {
651     /* php/ext/standard/string.c ? implode??????????????????
652     zend_hash_*???????ャ?<?潟???c????????????????鐚?
653     */
654     zval **tmp;
655     HashPosition pos;
656     int i = 0;
657     pIID = new itemid_t[len];
658    
659     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
660     while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
661     SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
662     convert_to_long_ex(tmp);
663     if ( i < len )
664     pIID[i++] = Z_LVAL_PP(tmp);
665     zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
666     }
667     len = i;
668     result = RES_OK;
669     }
670     }
671     }
672    
673     ~zIIDs_t(){
674     if ( pIID ) delete[] pIID;
675     }
676     result_t getResult(){ return result; }
677     itemid_t *getPIID(){ return pIID; }
678     int getLen(){ return len; }
679     void dump(){
680     zend_printf( "dumping zIIDs...<br>\n" );
681     zend_printf( "result=%d<br>\n", (int)result );
682     zend_printf( "len=%d<br>\n", len );
683     for ( int i = 0; i < len; i++ ){
684     zend_printf( "pIID[%d] = %d<br>\n", i, pIID[i] );
685     }
686     }
687     };
688    
689     /**
690     *
691     * amazonbook_t????絎鴻??PHP???????????????
692     * @param pAmazonbook 紊???????mazonbook_t*
693     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
694     * @return RES_OK
695     *
696     */
697     result_t amazonbookToZval( const amazonbook_t *pAmazonbook, zval *z )
698     {
699     zend_hash_clean( z -> value.ht );
700    
701     add_assoc_string( z, "title", ( char* )pAmazonbook -> getTitle( ), 1 );
702     add_assoc_string( z, "author", ( char* )pAmazonbook -> getAuthor( ), 1 );
703     add_assoc_string( z, "publisher", ( char* )pAmazonbook -> getPublisher( ), 1 );
704     add_assoc_long( z, "year_of_publication", pAmazonbook -> getYearOfPublication( ) );
705     add_assoc_string( z, "isbn", ( char* )pAmazonbook -> getISBN( ), 1 );
706     add_assoc_string( z, "url", ( char* )pAmazonbook -> getURL( ), 1 );
707    
708     return RES_OK;
709     }
710    
711     /**
712     *
713     * pubmed_t????絎鴻??PHP???????????????
714     * @param pPubmed 紊???????ubmed_t*
715     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
716     * @return RES_OK
717     *
718     */
719     result_t pubmedToZval( const pubmed_t *pPubmed, zval *z )
720     {
721     zend_hash_clean( z -> value.ht );
722    
723     add_assoc_long( z, "pmid", pPubmed -> getID( ) );
724     add_assoc_string( z, "title", ( char* )pPubmed -> getTitle( ), 1 );
725     add_assoc_string( z, "author", ( char* )pPubmed -> getAuthor( ), 1 );
726     add_assoc_string( z, "journal", ( char* )pPubmed -> getJournal( ), 1 );
727     add_assoc_long( z, "year_of_publication", pPubmed -> getYearOfPublication( ) );
728     add_assoc_long( z, "volume", pPubmed -> getVolume( ) );
729     add_assoc_long( z, "number", pPubmed -> getNumber( ) );
730     add_assoc_string( z, "page", ( char* )pPubmed -> getPage( ), 1 );
731     add_assoc_string( z, "abstract", ( char* )pPubmed -> getAbstract( ), 1 );
732    
733     return RES_OK;
734     }
735    
736     /**
737     *
738     * itemid_t????????PHP???????????????
739     * @param piid 紊???????temid_t??????
740     * @param len piid?????????激??
741     * @param ppz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
742     * @return RES_OK
743     *
744     */
745 youi 1.25 result_t itemidsToZval( const itemid_t *piid, int len, zval **ppz )
746 youi 1.24 {
747     zend_hash_clean( Z_ARRVAL_PP(ppz) );
748    
749     // add GIDs
750     for ( int i = 0; i < len; i++ ){
751     add_next_index_long(*ppz, (long)(piid[i]) );
752     }
753    
754     return RES_OK;
755     }
756    
757 aga 1.8 /**
758 youi 1.24 *
759 aga 1.8 * uids_t????????PHP???????????????
760 youi 1.24 *
761 aga 1.16 * @param pUID 紊???????serid_t??????
762 aga 1.8 * @param len pUID?????????激??
763     * @param pz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
764     * @return RES_OK
765 youi 1.24 *
766 aga 1.8 */
767 aga 1.4 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
768     {
769 youi 1.24 zend_hash_clean( Z_ARRVAL_PP(ppz) );
770    
771 aga 1.2 // add UIDs
772     for ( int i = 0; i < len; i++ ){
773 aga 1.8 add_next_index_long(*ppz, (long)(pUID[i]) );
774 aga 1.2 }
775 youi 1.24
776 aga 1.2 return RES_OK;
777     }
778 youi 1.24
779 aga 1.16 /**
780     *
781     * groupid_t????????PHP???????????????
782     * @param pGID 紊???????roupid_t??????
783     * @param len pGID?????????激??
784     * @param ppz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
785     * @return RES_OK
786     *
787     */
788 aga 1.4 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
789     {
790 youi 1.24 zend_hash_clean( Z_ARRVAL_PP(ppz) );
791    
792 aga 1.2 // add GIDs
793     for ( int i = 0; i < len; i++ ){
794 aga 1.8 add_next_index_long(*ppz, (long)(pGID[i]) );
795 aga 1.2 }
796 youi 1.24
797     return RES_OK;
798     }
799    
800     /**
801     *
802     * changelog_t????絎鴻??PHP???????????????
803     * @param pChangelog 紊???????hangelog_t*
804     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
805     * @return RES_OK
806     *
807     */
808     result_t changelogToZval( const changelog_t *pChangelog, zval *z )
809     {
810     zend_hash_clean( z -> value.ht );
811    
812     add_assoc_long( z, "log_id", pChangelog -> getChangelogID( ) );
813     add_assoc_long( z, "item_id", pChangelog -> getItemID( ) );
814     add_assoc_long( z, "log_date", pChangelog -> getDate( ) );
815     add_assoc_string( z, "log", ( char* )pChangelog -> getLog( ), 1 );
816    
817     return RES_OK;
818     }
819    
820     /**
821     *
822     * item_t????絎鴻??PHP???????????????
823     * @param pItem 紊???????tem_t*
824     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
825     * @return RES_OK
826     *
827     */
828     result_t itemToZval( const item_t *pItem, zval *z )
829     {
830     zend_hash_clean( z -> value.ht );
831    
832     add_assoc_long( z, "item_id", pItem -> getItemID( ) );
833     add_assoc_long( z, "item_type_id", pItem -> getItemTypeID( ) );
834     add_assoc_long( z, "uid", pItem -> getContributorUID( ) );
835     add_assoc_string( z, "title", ( char* )pItem -> getTitle( ), 1 );
836     add_assoc_string( z, "keywords", ( char* )pItem -> getKeywords( ), 1 );
837     add_assoc_string( z, "description", ( char* )pItem -> getDescription( ), 1 );
838     add_assoc_string( z, "doi", ( char* )pItem -> getDOI( ), 1 );
839     add_assoc_long( z, "last_update_date", pItem -> getLastUpdateDate( ) );
840     add_assoc_long( z, "creation_date", pItem -> getCreationDate( ) );
841    
842     return RES_OK;
843     }
844    
845    
846     result_t itemsToZval( const item_t *pItems, int itemsLen, zval *z )
847     {
848     zend_hash_clean( z -> value.ht );
849     for( int i = 0; i < itemsLen; i++ ){
850     zval *new_array;
851     MAKE_STD_ZVAL(new_array);
852     if(array_init(new_array) != SUCCESS){
853     return RES_ERROR;
854     }
855     add_index_zval( z, i, new_array );
856     itemToZval( &pItems[ i ], new_array );
857     }
858 aga 1.2 return RES_OK;
859     }
860    
861 youi 1.24 /**
862     *
863     * PHP???f?渇????????絎鴻??group_t?????????
864     *
865     * @param z 紊????????f?渇????
866     * @param pGroup 紊???腟??????吾??莨若???違???若??
867     * @return RES_OK
868     *
869     */
870     result_t zvalToItem( zval *z, item_t* pItem )
871     {
872     zval **tmp;
873     HashPosition pos;
874     int i = 0;
875     char* key = 0;
876    
877     key = "item_id";
878     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
879     convert_to_long_ex( tmp ) ;
880     pItem -> setItemID( (*tmp) -> value.lval );
881     }
882     key = "item_type_id";
883     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
884     convert_to_long_ex( tmp ) ;
885     pItem -> setItemTypeID( (*tmp) -> value.lval );
886     }
887     key = "uid";
888     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
889     convert_to_long_ex( tmp ) ;
890     pItem -> setContributorUID( (*tmp) -> value.lval );
891     }
892     key = "title";
893     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
894     convert_to_string_ex( tmp ) ;
895     pItem -> setTitle( (*tmp) -> value.str.val );
896     }
897     key = "keywords";
898     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
899     convert_to_string_ex( tmp ) ;
900     pItem -> setKeywords( (*tmp) -> value.str.val );
901     }
902     key = "description";
903     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
904     convert_to_string_ex( tmp ) ;
905     pItem -> setDescription( (*tmp) -> value.str.val );
906     }
907     key = "doi";
908     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
909     convert_to_string_ex( tmp ) ;
910     pItem -> setDOI( (*tmp) -> value.str.val );
911     }
912     key = "last_update_date";
913     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
914     convert_to_long_ex( tmp ) ;
915     pItem -> setLastUpdateDate( (*tmp) -> value.lval );
916     }
917     key = "creation_date";
918     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
919     convert_to_long_ex( tmp ) ;
920     pItem -> setCreationDate( (*tmp) -> value.lval );
921     }
922     return RES_OK;
923     }
924 aga 1.16
925     /**
926     *
927     * account_t????絎鴻??PHP???????????????
928     * @param pAccount 紊???????ccount_t*
929     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
930     * @return RES_OK
931     *
932     */
933 youi 1.6 result_t accountToZval( const account_t *pAccount, zval *z )
934     {
935 youi 1.24 zend_hash_clean( z -> value.ht );
936    
937     add_assoc_long( z, "uid", pAccount -> getUID( ) );
938     add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
939     add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
940     add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
941     add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
942     add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
943     add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
944     add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
945     add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
946     add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
947     add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
948     add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
949     add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
950     add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
951     add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
952     add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
953     add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
954     add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
955     add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
956     add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
957     add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
958     add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
959     add_assoc_long( z, "level", pAccount -> getLevel( ) );
960     add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
961     add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
962     add_assoc_long( z, "posts", pAccount -> getPosts( ) );
963     add_assoc_long( z, "rank", pAccount -> getRank( ) );
964     add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
965     add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
966     add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
967     add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
968    
969     add_assoc_long( z, "activate", pAccount -> getActivate( ) );
970     add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
971     add_assoc_string( z, "division", ( char* )pAccount -> getDivision( ), 1 );
972     add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
973     add_assoc_string( z, "company_name", ( char* )pAccount -> getCompanyName( ), 1 );
974     add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
975     add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
976     add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
977     add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
978     add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
979     add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
980     add_assoc_long( z, "private_index_id", pAccount -> getPrivateIndexID( ) );
981 youi 1.6 return RES_OK;
982     }
983 youi 1.24
984 aga 1.16 /**
985     *
986     * 茲??違??ccount_t????絎鴻??PHP?????????????????????
987     * @param pAccounts 紊???????ccount_t*
988     * @param accountsLen pAccounts?????????激??
989     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
990     * @return RES_OK
991     *
992     z: ?????????????????????????? <br>
993 youi 1.24 array(
994     array(
995     'uid'=>100,
996     'activate'=>1,
997     'division'=>'foo',
998     'tel'=>'123-456-789',
999     ...
1000     ),
1001     ...
1002     )
1003 aga 1.16 */
1004 youi 1.6 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
1005 aga 1.4 {
1006 youi 1.24 zend_hash_clean( z -> value.ht );
1007     for( int i = 0; i < accountsLen; i++ ){
1008     zval *new_array;
1009     MAKE_STD_ZVAL(new_array);
1010     if(array_init(new_array) != SUCCESS){
1011     return RES_ERROR;
1012     }
1013     add_index_zval( z, i, new_array );
1014     accountToZval( &pAccounts[ i ], new_array );
1015     }
1016 youi 1.6 return RES_OK;
1017 aga 1.2 }
1018    
1019 aga 1.16 /**
1020     *
1021     * 茲??違??roup_t????絎鴻??PHP?????????????????????
1022     * @param pGroups 紊???????roup_t*
1023     * @param groupsLen pGroups?????????激??
1024     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
1025     * @return RES_OK
1026     *
1027     z: ?????????????????????????? <br>
1028 youi 1.24 array(
1029     array(
1030     'gid'=>1,
1031     'gname'=>'foo group',
1032     'gdesc'=>'group of foo'
1033     ),
1034     ...
1035     )
1036 aga 1.16 */
1037 youi 1.6 result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
1038 aga 1.4 {
1039 youi 1.24 zend_hash_clean( z -> value.ht );
1040     for( int i = 0; i < groupsLen; i++ ){
1041     zval *new_array;
1042     MAKE_STD_ZVAL(new_array);
1043     if(array_init(new_array) != SUCCESS){
1044     return RES_ERROR;
1045     }
1046     add_index_zval( z, i, new_array );
1047     add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
1048     add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
1049     add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
1050     add_assoc_long( new_array, "group_index_id", pGroups[ i ].getGroupIndexID( ) );
1051     }
1052 youi 1.6 return RES_OK;
1053 aga 1.2 }
1054    
1055 youi 1.7 /**
1056 youi 1.24 *
1057 youi 1.7 * group_t????絎鴻??PHP???f?渇?????????????
1058 youi 1.24 *
1059 aga 1.16 * @param pGroup 紊????????違???若??????/span>
1060 youi 1.7 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
1061     * @return RES_OK
1062 youi 1.24 *
1063 youi 1.7 */
1064     result_t groupToZval( const group_t *pGroup, zval *z )
1065 youi 1.6 {
1066 youi 1.24 zend_hash_clean( z -> value.ht );
1067     add_assoc_long( z, "gid", pGroup -> getGID( ) );
1068     add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
1069     add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
1070     add_assoc_long( z, "group_index_id", pGroup -> getGroupIndexID( ) );
1071 youi 1.6 return RES_OK;
1072     }
1073    
1074 aga 1.16 /**
1075 youi 1.24 *
1076 aga 1.16 * PHP???f?渇????????絎鴻??group_t?????????
1077 youi 1.24 *
1078 aga 1.16 * @param z 紊????????f?渇????
1079     * @param pGroup 紊???腟??????吾??莨若???違???若??
1080     * @return RES_OK
1081 youi 1.24 *
1082 aga 1.16 */
1083 youi 1.7 result_t zvalToGroup( zval *z, group_t *pGroup )
1084     {
1085 youi 1.24 zval **tmp;
1086     HashPosition pos;
1087     int i = 0;
1088     char* key = 0;
1089    
1090     key = "gid";
1091     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1092     convert_to_long_ex( tmp ) ;
1093     pGroup -> setGID( (*tmp) -> value.lval );
1094     }
1095     key = "gname";
1096     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1097     convert_to_string_ex( tmp ) ;
1098     pGroup -> setGname( (*tmp) -> value.str.val );
1099     }
1100     key = "gdesc";
1101     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1102     convert_to_string_ex( tmp ) ;
1103     pGroup -> setDesc( (*tmp) -> value.str.val );
1104     }
1105     key = "group_index_id";
1106     if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1107     convert_to_long_ex( tmp ) ;
1108     pGroup -> setGroupIndexID( (*tmp) -> value.lval );
1109     }
1110 youi 1.7 return RES_OK;
1111     }
1112    
1113 aga 1.16 /**
1114 youi 1.24 *
1115 aga 1.16 * session_t????絎鴻??PHP???f?渇?????????????
1116 youi 1.24 *
1117 aga 1.16 * @param pSession 紊???????ession_t
1118     * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
1119     * @return RES_OK
1120 youi 1.24 *
1121 aga 1.16 */
1122     result_t sessionToZval( const session_t *pSession, zval *z )
1123     {
1124     string sessionID(unsignedIntToString(pSession->getSessionID()));
1125     add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
1126 youi 1.24
1127 aga 1.16 string date(unsignedIntToString((unsigned int)pSession->getDate()));
1128     add_assoc_string(z, "date", (char *)date.c_str(), 1);
1129 youi 1.24
1130 aga 1.20 string userID(unsignedIntToString((unsigned int)pSession->getUID()));
1131 aga 1.16 add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
1132 youi 1.24
1133 aga 1.16 return RES_OK;
1134     }
1135    
1136 aga 1.22 /**
1137     *
1138     * index_t????絎鴻??PHP???????????????
1139     * @param pIndex 紊???????ndex_t*
1140     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
1141     * @return RES_OK
1142     *
1143     */
1144     result_t indexToZval( const index_t *pIndex, zval *z )
1145     {
1146 youi 1.24 zend_hash_clean( z -> value.ht );
1147    
1148     add_assoc_long( z, "item_id", pIndex -> getItemID( ) );
1149     add_assoc_long( z, "item_type_id", pIndex -> getItemTypeID( ) );
1150     add_assoc_long( z, "contributor_uid", pIndex -> getContributorUID( ) );
1151     add_assoc_string( z, "title", ( char* )pIndex -> getTitle( ), 1 );
1152     add_assoc_string( z, "keywords", ( char* )pIndex -> getKeywords( ), 1 );
1153     add_assoc_string( z, "description", ( char* )pIndex -> getDescription( ), 1 );
1154     add_assoc_long( z, "last_update_date", pIndex -> getLastUpdateDate( ) );
1155     add_assoc_long( z, "creation_date", pIndex-> getCreationDate( ) );
1156     add_assoc_long( z, "parent_index_id", pIndex -> getParentIndexID( ) );
1157     add_assoc_long( z, "owner_uid", pIndex -> getOwnerUID( ) );
1158     add_assoc_long( z, "owner_gid", pIndex -> getOwnerGID( ) );
1159     add_assoc_long( z, "open_level", pIndex -> getOpenLevel( ) );
1160     add_assoc_long( z, "sort_number", pIndex -> getSortNumber( ) );
1161 aga 1.22 return RES_OK;
1162     }
1163    
1164     result_t indexesToZval( const index_t *pIndexes, int indexesLen, zval *z )
1165     {
1166 youi 1.24 zend_hash_clean( z -> value.ht );
1167     for( int i = 0; i < indexesLen; i++ ){
1168     zval *new_array;
1169     MAKE_STD_ZVAL(new_array);
1170     if(array_init(new_array) != SUCCESS){
1171     return RES_ERROR;
1172     }
1173     add_index_zval( z, i, new_array );
1174     indexToZval( &pIndexes[ i ], new_array );
1175     }
1176 aga 1.22 return RES_OK;
1177     }
1178    
1179    
1180 youi 1.7
1181 aga 1.16
1182     /** ??絎??????違???若???????宴??緇???<br>
1183 youi 1.24 int xnp_get_group( int sid, int gid, array group );
1184     @param sid XNP???祉???激?с??D
1185     @param gid XNP ? group_id
1186     @param group 腟?????????????????
1187     @return 0 success <br>
1188 aga 1.16 */
1189 youi 1.21 ZEND_FUNCTION(xnp_get_group)
1190 aga 1.4 {
1191 youi 1.6 long sid, gid;
1192     zval *zgroup;
1193 youi 1.24
1194 youi 1.6 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1195 youi 1.24 &sid, &gid, &zgroup) == FAILURE) {
1196 youi 1.6 return;
1197     }
1198 youi 1.24
1199 youi 1.6 const group_t *pgroup;
1200     result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
1201     if ( RES_OK == result ){
1202 youi 1.7 groupToZval( pgroup, zgroup );
1203 youi 1.19 freeGroup( pgroup );
1204 youi 1.6 }
1205 youi 1.24
1206     RETURN_LONG(result);
1207 youi 1.6 }
1208    
1209 aga 1.2
1210 aga 1.16 /** ??絎??????違???若??(茲????????宴??緇???<br>
1211 youi 1.24 xnp_get_groups( int sid, array gids, array criteria, array groups );
1212     @param sid XNP???祉???激?с??D
1213     @param gids XNP ? group_id ??????
1214     @param criteria ?>散
1215     @param groups 腟???????????????????????
1216     @return 0 success <br>
1217 aga 1.16 */
1218 youi 1.21 ZEND_FUNCTION(xnp_get_groups)
1219 youi 1.6 {
1220     result_t result;
1221     long sid, uid;
1222     zval *zcriteria;
1223     zval *zgids;
1224     zval *zgroups;
1225 youi 1.24 zval **ppzTmp = 0;
1226     HashPosition pos;
1227     int res2;
1228     int gidsLen;
1229     const group_t* groups;
1230     int groupsLen;
1231    
1232 youi 1.6 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1233 youi 1.24 &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
1234 youi 1.6 return;
1235     }
1236 youi 1.24
1237     //gids???違???若??ID???潟???若????
1238     gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
1239     groupid_t *gids = new groupid_t[ gidsLen ];
1240     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
1241     for( int i = 0; i < gidsLen; i++ ){
1242     if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
1243     SEPARATE_ZVAL(ppzTmp);
1244     convert_to_long_ex(ppzTmp);
1245     gids[ i ] = Z_LVAL_PP(ppzTmp);
1246     }
1247     zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
1248     }
1249    
1250 youi 1.6 zCriteria_t zcri(zcriteria);
1251     result = zcri.getResult();
1252     if ( RES_OK == result ){
1253 youi 1.24 result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
1254     if ( RES_OK == result ){
1255     groupsToZval( groups, groupsLen, zgroups );
1256     delete[] gids;
1257     freeGroup( groups );
1258     }
1259     }
1260     RETURN_LONG(result);
1261 youi 1.6 }
1262    
1263    
1264 aga 1.16 /** ??絎????????若?吟???≪?????若?帥??????????茯帥?鴻??<br>
1265 youi 1.24 int xnp_is_moderator(int sid, int uid)
1266     @param sid XNP???祉???激?с??D
1267     @param uid xoops ? uid (xoops_users.uid)
1268     @return true ?≪?????若?帥?с???? <br>
1269 aga 1.16 */
1270 youi 1.21 ZEND_FUNCTION(xnp_is_moderator)
1271 youi 1.6 {
1272 youi 1.21 long xnpSessionID;
1273 youi 1.6 userid_t uid;
1274 youi 1.24
1275     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1276     &xnpSessionID, &uid) == FAILURE) {
1277 youi 1.6 return;
1278     }
1279 youi 1.24
1280 youi 1.21 bool result = isModerator( (sessionid_t)xnpSessionID, uid );
1281 youi 1.24 RETURN_BOOL(result)
1282 youi 1.6 }
1283    
1284 aga 1.16 /** ???若?九??????uid??茯帥?鴻??<br>
1285 youi 1.24 int xnp_get_uid(string uname,int &uid)
1286     @param sid XNP???祉???激?с??D
1287     @param uname xoops ? uname (xoops_users.uname)
1288     @param uid xoops ? uid (xoops_users.uid) ??????????紊???/span>
1289     @return 0 success
1290 aga 1.16 */
1291 youi 1.21 ZEND_FUNCTION(xnp_get_uid)
1292 youi 1.6 {
1293     char *uname;
1294     int unameLen;
1295 aga 1.14 zval *zuid;
1296 youi 1.6 userid_t uid;
1297 youi 1.24
1298     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
1299 aga 1.14 &uname, &unameLen, &zuid) == FAILURE) {
1300 youi 1.6 return;
1301     }
1302 youi 1.24
1303 aga 1.14 if (!PZVAL_IS_REF(zuid)) {
1304     zend_error(E_WARNING, "2nd parameter wasn't passed by reference");
1305     RETURN_LONG(RES_PHP_NONREF);
1306     }
1307 youi 1.24
1308 youi 1.6 string strUname( uname, unameLen );
1309     result_t result = getUid( strUname.c_str(), &uid );
1310 aga 1.14 ZVAL_LONG(zuid, (long)uid);
1311     RETURN_LONG((long)result);
1312 aga 1.2 }
1313    
1314 youi 1.21 ZEND_FUNCTION(xnp_test_criteria)
1315 aga 1.2 {
1316     zval *z;
1317 youi 1.24
1318     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
1319 aga 1.2 &z) == FAILURE) {
1320     return;
1321     }
1322     zend_printf("zend_printf...<br>\n");
1323     zCriteria_t zcri(z);
1324     zcri.dump();
1325     RETURN_FALSE
1326     }
1327    
1328 youi 1.21 ZEND_FUNCTION(xnp_test_uids)
1329 aga 1.2 {
1330     zval *z;
1331 youi 1.24
1332     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
1333 aga 1.2 &z) == FAILURE) {
1334     return;
1335     }
1336     zend_printf("zend_printf...<br>\n");
1337     zUIDs_t zuids(z);
1338     zuids.dump();
1339     RETURN_FALSE
1340     }
1341    
1342    
1343    
1344 aga 1.4 /** DB??・膓????????≪??・膓?筝???・膓???????????????<br>
1345 youi 1.24 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
1346     @param host ?ョ????????ユ????ULL
1347     @param user DB?ョ????????若?九???????ユ????ULL
1348     @param password DB?ョ????????鴻???若???????ユ????ULL
1349     @param dbname DB?ョ?????B???????ユ????quot;"
1350     @param prefix XOOPS DB ??refix??
1351     @return 0 success <br>
1352 aga 1.1 */
1353 youi 1.21 ZEND_FUNCTION(xnp_initialize_db)
1354 aga 1.1 {
1355     zval **parameters[5];
1356     char *host;
1357     char *user;
1358 aga 1.2 char *password;
1359     char *dbname;
1360     char *prefix;
1361 aga 1.1
1362     /* get the number of arguments */
1363     int argNum = ZEND_NUM_ARGS();
1364     if (argNum > 5)
1365     WRONG_PARAM_COUNT;
1366    
1367     /* argument count is correct, now retrieve arguments */
1368     if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
1369     WRONG_PARAM_COUNT;
1370    
1371 aga 1.2 if (argNum < 1) host = NULL;
1372 aga 1.1 else host = getZvalString( parameters[0] );
1373 youi 1.24
1374 aga 1.1 if (argNum < 2) user = NULL;
1375     else user = getZvalString( parameters[1] );
1376 youi 1.24
1377 aga 1.2 if (argNum < 3) password = NULL;
1378     else password = getZvalString( parameters[2] );
1379 youi 1.24
1380 aga 1.2 if (argNum < 4) dbname = "";
1381     else dbname = getZvalString( parameters[3] );
1382 youi 1.24
1383 aga 1.2 if (argNum < 5) prefix = "";
1384     else prefix = getZvalString( parameters[4] );
1385 youi 1.24
1386 aga 1.2 result_t result = initializeDB( host, user, password, dbname, prefix );
1387 youi 1.24
1388 aga 1.2 RETURN_LONG(result);
1389 aga 1.1 }
1390    
1391 aga 1.4 /** ???違?ゃ?潟??????<br>
1392 youi 1.24 int xnp_login_user(string uname, string password, int &session_id)
1393     @param uname ???若?九??(xoops_users.uname)
1394     @param password ???鴻???若??(md5(password)=xoops_users.pass)
1395     @return 0 success
1396 aga 1.4 */
1397 youi 1.21 ZEND_FUNCTION(xnp_login_user)
1398 aga 1.1 {
1399     char *uname;
1400     int unameLen;
1401     char *passwd;
1402     int passwdLen;
1403 youi 1.21 zval *zXNPSessionID;
1404 youi 1.24
1405     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",
1406 youi 1.21 &uname, &unameLen, &passwd, &passwdLen, &zXNPSessionID) == FAILURE) {
1407 aga 1.1 return;
1408     }
1409 youi 1.24
1410 youi 1.21 if (!PZVAL_IS_REF(zXNPSessionID)) {
1411 aga 1.14 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1412     RETURN_LONG(RES_PHP_NONREF);
1413     }
1414 youi 1.24
1415 youi 1.21 sessionid_t xnpSessionID;
1416     result_t result = loginUser( uname, passwd, &xnpSessionID );
1417 aga 1.14 if ( result == RES_OK )
1418 youi 1.21 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1419 aga 1.14 RETURN_LONG((long)result);
1420 aga 1.1 }
1421    
1422 aga 1.4 /** ???違?≪??????????<br>
1423 youi 1.24 void xnp_logout_user(int xnp_session_id)
1424     @param xnp_session_id XNP???祉???激?с??D
1425     @return ????
1426 aga 1.4 */
1427 youi 1.21 ZEND_FUNCTION(xnp_logout_user)
1428 aga 1.1 {
1429 youi 1.21 long xnpSessionID;
1430 youi 1.24
1431 youi 1.21 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &xnpSessionID) == FAILURE) {
1432 aga 1.1 return;
1433     }
1434 youi 1.21 logoutUser( (sessionid_t)xnpSessionID );
1435 youi 1.24
1436     RETURN_NULL();
1437 aga 1.1 }
1438    
1439 youi 1.21 /** XNP???祉???激?с??D 篏???<br>
1440 youi 1.24 int xnp_create_session( string xoops_sess_id, int uid, int &session )
1441     @param xoops_sess_id xoops???祉???激?с??D
1442     @param uid xoops ? uid (xoops_users.uid)
1443     @param session 篏???????XNP??ession??????????紊???/span>
1444     @return 0 ????
1445 aga 1.4 */
1446 youi 1.21 ZEND_FUNCTION(xnp_create_session)
1447 aga 1.2 {
1448     char *xoopsSessionID;
1449     int xoopsSessionIDLen;
1450 aga 1.5 long uid;
1451 youi 1.21 zval *zXNPSessionID;
1452 youi 1.24
1453 aga 1.14 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz",
1454 youi 1.21 &xoopsSessionID, &xoopsSessionIDLen, &uid, &zXNPSessionID) == FAILURE) {
1455 aga 1.2 return;
1456     }
1457 youi 1.24
1458 youi 1.21 if (!PZVAL_IS_REF(zXNPSessionID)) {
1459 aga 1.14 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1460     RETURN_LONG(RES_PHP_NONREF);
1461     }
1462 youi 1.24
1463 youi 1.21 sessionid_t xnpSessionID = 0;
1464     result_t result = createSession( xoopsSessionID, (userid_t)uid, &xnpSessionID );
1465 aga 1.14 if ( result == RES_OK )
1466 youi 1.21 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1467 aga 1.14 RETURN_LONG((long)result);
1468 aga 1.4 }
1469    
1470 youi 1.21 /** XNP ? session ???膣井???宴??緇???<br>
1471 youi 1.24 int xnp_get_session( int xnp_session_id, array session_info )
1472     @param xnp_session_id XNP???祉???激?с??D
1473     @param session_info 腟?????????????????
1474     @return 0 success
1475 aga 1.4 */
1476 youi 1.21 ZEND_FUNCTION(xnp_get_session)
1477 aga 1.4 {
1478 youi 1.21 long xnpSessionID;
1479 aga 1.4 zval *sessionInfo;
1480     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1481 youi 1.21 &xnpSessionID, &sessionInfo) == FAILURE) {
1482 aga 1.4 return;
1483     }
1484     const session_t *session = 0;
1485 youi 1.21 result_t result = getSession( (sessionid_t)xnpSessionID, &session );
1486 aga 1.4 if ( result == RES_OK ){
1487     sessionToZval( session, sessionInfo );
1488 youi 1.19 freeSession( session );
1489 aga 1.4 }
1490 youi 1.24
1491 aga 1.4 RETURN_LONG((long)result);
1492 aga 1.2 }
1493 aga 1.1
1494 aga 1.16 /** ???若?吟??ctivate?倶??????緇?????<br>
1495 youi 1.24 bool xnp_is_activated( int xnp_session_id, int user_id )
1496     @param xnp_session_id XNP???祉???激?с??D
1497     @param user_id xoops_users.uid
1498     @return 0 success
1499 aga 1.5 */
1500 youi 1.21 ZEND_FUNCTION(xnp_is_activated)
1501 aga 1.2 {
1502     long sid, uid;
1503 youi 1.24
1504 aga 1.5 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
1505 aga 1.2 return;
1506     }
1507 youi 1.24
1508 aga 1.2 bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
1509 youi 1.24
1510     RETURN_BOOL(result);
1511 aga 1.2 }
1512 aga 1.1
1513 youi 1.17 /** activate??????<br>
1514 youi 1.24 bool xnp_activate( int xnp_session_id, int user_id, bool activated )
1515     @param xnp_session_id xnp ? session id
1516     @param user_id xoops_users.uid
1517     @param activated true:activate, false:inactivate
1518     @return 0 success
1519 aga 1.5 */
1520 youi 1.21 ZEND_FUNCTION(xnp_activate)
1521 aga 1.2 {
1522     long sid, uid;
1523     bool activated;
1524 youi 1.24
1525 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
1526     &sid, &uid, &activated) == FAILURE) {
1527     return;
1528     }
1529 youi 1.24
1530 aga 1.2 result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
1531 youi 1.24
1532     RETURN_LONG(result);
1533 aga 1.2 }
1534 aga 1.1
1535 youi 1.21 /** XNP???≪?????潟???違??緇?????<br>
1536 youi 1.24 int xnp_get_account_count( int xnp_session_id )
1537     @param xnp_session_id XNP???祉???激?с??D
1538     @return 0 success
1539 aga 1.5 */
1540 youi 1.21 ZEND_FUNCTION(xnp_get_account_count)
1541 aga 1.2 {
1542     long sid;
1543 youi 1.24
1544 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1545     &sid) == FAILURE) {
1546     return;
1547     }
1548 youi 1.24
1549 aga 1.2 long count = getAccountCount( (sessionid_t)sid );
1550 youi 1.24 RETURN_LONG(count);
1551 aga 1.2 }
1552 aga 1.1
1553 aga 1.5 /** ?≪?????潟???????ゃ??????<br>
1554 youi 1.24 bool xnp_delete_account( int xnp_session_id, int user_id )
1555     @param xnp_session_id XNP???祉???激?с??D
1556     @param user_id xoops_users.uid
1557     @return 0 success
1558 aga 1.5 */
1559 youi 1.21 ZEND_FUNCTION(xnp_delete_account)
1560 aga 1.2 {
1561     long sid, uid;
1562 youi 1.24
1563 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1564     &sid, &uid) == FAILURE) {
1565     return;
1566     }
1567 youi 1.24
1568 aga 1.2 result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
1569 youi 1.24
1570     RETURN_LONG(result);
1571 aga 1.2 }
1572 aga 1.1
1573 aga 1.5 /** ?≪?????潟?????宴??緇?????<br>
1574 youi 1.24 int xnp_get_account( int xnp_session_id, int user_id, array account_info )
1575     @param xnp_session_id XNP???祉???激?с??D
1576     @param user_id xoops_users.uid
1577     @param account_info ?≪?????潟?????宴???????????f?渇????
1578     @return 0 success
1579 aga 1.5 */
1580 youi 1.21 ZEND_FUNCTION(xnp_get_account)
1581 aga 1.2 {
1582     long sid, uid;
1583     zval *zaccount;
1584 youi 1.24
1585 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1586     &sid, &uid, &zaccount) == FAILURE) {
1587 youi 1.24 fprintf( stderr, "error occured " );
1588 aga 1.2 return;
1589     }
1590 youi 1.24
1591 aga 1.2 const account_t *paccount;
1592     result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
1593     if ( RES_OK == result ){
1594     accountToZval( paccount, zaccount );
1595 youi 1.19 freeAccount( paccount );
1596 aga 1.2 }
1597 youi 1.24
1598     RETURN_LONG(result);
1599 aga 1.2 }
1600 aga 1.1
1601 aga 1.5 /** ?>散????眼?????≪?????潟???????宴??緇?????<br>
1602 youi 1.24 int xnp_get_accoutns( int sid, array uids, array criteria, array accounts );
1603     @param xnp_session_id XNP???祉???激?с??D
1604     @param user_id xoops_users.uid
1605     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1606     @param account_info ?≪?????潟?????宴???????????f?渇????
1607     @return 0 success
1608 aga 1.5 */
1609 youi 1.21 ZEND_FUNCTION(xnp_get_accounts)
1610 aga 1.2 {
1611     result_t result;
1612     long sid;
1613     zval *zuids;
1614     zval *zcriteria;
1615     zval *zaccount;
1616 youi 1.24
1617 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1618     &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
1619     return;
1620     }
1621 youi 1.24
1622 aga 1.2 zCriteria_t zcri(zcriteria);
1623     result = zcri.getResult();
1624     if ( RES_OK == result ){
1625     zUIDs_t zUIDs(zuids);
1626     result = zUIDs.getResult();
1627     if ( RES_OK == result ){
1628     const account_t *paccounts;
1629     int accountLen;
1630 youi 1.24 result = getAccounts( (sessionid_t)sid,
1631 aga 1.2 zUIDs.getPUID(), zUIDs.getLen(),
1632     &zcri, &paccounts, &accountLen );
1633     if ( RES_OK == result ){
1634     accountsToZval( paccounts, accountLen, zaccount );
1635 youi 1.19 freeAccount( paccounts );
1636 aga 1.2 }
1637     }
1638     }
1639 youi 1.24
1640     RETURN_LONG(result);
1641 aga 1.2 }
1642 aga 1.1
1643 youi 1.17 /** ?≪?????潟?????宴??荐??蚊??????<br>
1644 youi 1.24 int xnp_insert_account( int sid, array account_info, int &user_id );
1645     @param xnp_session_id xnp ? session id
1646     @param account_info 荐??蚊???????≪?????潟????????/span>
1647     @param user_id ???若??D(xoops_users.uid)???吾??莨若???????<???潟??/span>
1648     @return 0 success
1649 aga 1.5 */
1650 youi 1.21 ZEND_FUNCTION(xnp_insert_account)
1651 aga 1.2 {
1652     result_t result;
1653     long sid;
1654     zval *zaccount;
1655 youi 1.17 zval *zuid;
1656 youi 1.24 userid_t uid;
1657    
1658 youi 1.17 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1659     &sid, &zaccount, &zuid) == FAILURE) {
1660 aga 1.2 return;
1661     }
1662 youi 1.24
1663 aga 1.2 zAccount_t zacc(zaccount);
1664     result = zacc.getResult();
1665     if ( RES_OK == result ){
1666 youi 1.17 result = insertAccount( (sessionid_t)sid, &zacc, &uid );
1667 aga 1.2 }
1668 youi 1.24 zuid -> type = IS_LONG;
1669     zuid -> value.lval = uid;
1670     RETURN_LONG(result);
1671 aga 1.2 }
1672 aga 1.1
1673 aga 1.5 /** ?≪?????潟?????宴???贋?違??????<br>
1674 youi 1.24 int xnp_update_account( int sid, array account );
1675     @param xnp_session_id XNP???祉???激?с??D
1676     @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
1677     @return 0 success
1678 aga 1.5 */
1679 youi 1.21 ZEND_FUNCTION(xnp_update_account)
1680 aga 1.2 {
1681     result_t result;
1682     long sid;
1683     zval *zaccount;
1684 youi 1.24
1685 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1686     &sid, &zaccount) == FAILURE) {
1687     return;
1688     }
1689 youi 1.24
1690 aga 1.2 zAccount_t zacc(zaccount);
1691     result = zacc.getResult();
1692     if ( RES_OK == result ){
1693     result = updateAccount( (sessionid_t)sid, &zacc );
1694     }
1695 youi 1.24
1696     RETURN_LONG(result);
1697 aga 1.2 }
1698 aga 1.1
1699 aga 1.5 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
1700 youi 1.24 int xnp_dump_uids( int xnp_session_id, array criteria, array uids );
1701     @param xnp_session_id XNP???祉???激?с??D
1702     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1703     @param uids uid??????????????
1704     @return 0 success
1705 aga 1.5 */
1706 youi 1.21 ZEND_FUNCTION(xnp_dump_uids)
1707 aga 1.2 {
1708     result_t result;
1709     long sid;
1710     zval *zcriteria;
1711     zval *zuids;
1712 youi 1.24
1713 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1714     &sid, &zcriteria, &zuids) == FAILURE) {
1715     return;
1716     }
1717 youi 1.24
1718 aga 1.2 zCriteria_t zcri(zcriteria);
1719     result = zcri.getResult();
1720     if ( RES_OK == result ){
1721     userid_t *puid;
1722     int uidLen;
1723     result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1724     if ( RES_OK == result ){
1725     uidsToZval( puid, uidLen, &zuids );
1726 youi 1.19 freeUID( puid );
1727 aga 1.2 }
1728     }
1729 youi 1.24
1730     RETURN_LONG(result);
1731 aga 1.2 }
1732 aga 1.1
1733 youi 1.21 /** XNP???違???若?????違??緇???<br>
1734 youi 1.24 int xnp_get_group_count( int xnp_session_id );
1735     @param xnp_session_id XNP???祉???激?с??D
1736     @return ?違???若????/span>
1737 aga 1.5 */
1738 youi 1.21 ZEND_FUNCTION(xnp_get_group_count)
1739 aga 1.1 {
1740 aga 1.2 result_t result;
1741     long sid;
1742 youi 1.24
1743 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1744     &sid) == FAILURE) {
1745     return;
1746     }
1747 youi 1.24
1748 aga 1.2 int count = getGroupCount( (sessionid_t)sid );
1749 youi 1.24
1750     RETURN_LONG(count);
1751 aga 1.2 }
1752 aga 1.1
1753 aga 1.5 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
1754 youi 1.24 int xnp_get_group_by_uid( int xnp_session_id, int uid, array criteria, array gids );
1755     @param xnp_session_id XNP???祉???激?с??D
1756     @param user_id xoops_users.uid
1757     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1758     @param gids gid??????????????
1759     @return 0 success
1760 aga 1.5 */
1761 youi 1.21 ZEND_FUNCTION(xnp_get_groups_by_uid)
1762 aga 1.2 {
1763     result_t result;
1764     long sid, uid;
1765     zval *zcriteria;
1766     zval *zgids;
1767 youi 1.24
1768 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1769     &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1770     return;
1771 aga 1.1 }
1772 youi 1.24
1773 aga 1.2 zCriteria_t zcri(zcriteria);
1774     result = zcri.getResult();
1775     if ( RES_OK == result ){
1776     groupid_t *pgids;
1777     int gidLen;
1778     result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1779     if ( RES_OK == result ){
1780     gidsToZval( pgids, gidLen, &zgids );
1781 youi 1.19 freeGID( pgids );
1782 aga 1.2 }
1783 aga 1.1 }
1784 youi 1.24
1785     RETURN_LONG(result);
1786 aga 1.2 }
1787    
1788    
1789 aga 1.5
1790     /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
1791 youi 1.24 int xnp_is_group_admin( int sid, int gid, int uid );
1792     @param xnp_session_id XNP???祉???激?с??D
1793     @param group_id XNP???違???若??ID
1794     @param user_id xoops_users.uid
1795     @return true: ?違???若??膊∞?????с??????
1796     @return false: ?違???若??膊∞?????с???????????????????若?с??????
1797 aga 1.5 */
1798 youi 1.21 ZEND_FUNCTION(xnp_is_group_admin)
1799 aga 1.2 {
1800     result_t result;
1801     long sid, gid, uid;
1802 youi 1.24
1803 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1804     &sid, &gid, &uid) == FAILURE) {
1805     return;
1806 aga 1.1 }
1807 youi 1.24
1808 aga 1.2 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1809 youi 1.24
1810     RETURN_BOOL(b);
1811 aga 1.2 }
1812    
1813 aga 1.5 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
1814 youi 1.24 int xnp_dump_gids( int sid, array criteria, array gids );
1815     @param xnp_session_id XNP???祉???激?с??D
1816     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1817     @param gids gid??????????????
1818     @return 0 success
1819 aga 1.5 */
1820 youi 1.21 ZEND_FUNCTION(xnp_dump_gids)
1821 aga 1.2 {
1822     result_t result;
1823     long sid;
1824     zval *zcriteria;
1825     zval *zgids;
1826 youi 1.24
1827 aga 1.2 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1828     &sid, &zcriteria, &zgids) == FAILURE) {
1829     return;
1830     }
1831 youi 1.24
1832 aga 1.2 zCriteria_t zcri(zcriteria);
1833     result = zcri.getResult();
1834     if ( RES_OK == result ){
1835     groupid_t *pgid;
1836     int gidLen;
1837     result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1838     if ( RES_OK == result ){
1839     gidsToZval( pgid, gidLen, &zgids );
1840 youi 1.19 freeGID( pgid );
1841 aga 1.1 }
1842     }
1843 youi 1.24
1844     RETURN_LONG(result);
1845 aga 1.1 }
1846 aga 1.8
1847     /** gid?ф??絎??????違???若??????????с?????ゆ?>散????眼?????違???若??膊∞??????id???荀с??緇?????<br>
1848 youi 1.24 int xnp_dump_group_admins(int sid, int group_id, array criteria, array uids )
1849     @param sid XNP???祉???激?с??D
1850     @param group_id XNP???違???若??ID
1851     @param criteria ?>散
1852     @param uids uid???荀с??????????????
1853     @return 0 success
1854 aga 1.8 */
1855    
1856 youi 1.21 ZEND_FUNCTION(xnp_dump_group_admins)
1857 aga 1.8 {
1858     long sid, gid;
1859     zval *zcriteria;
1860     zval *zuids;
1861 youi 1.24
1862     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1863     &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1864 aga 1.8 return;
1865     }
1866 youi 1.24
1867 aga 1.8 zCriteria_t zcri(zcriteria);
1868     result_t result = zcri.getResult();
1869     if ( result == RES_OK ){
1870     userid_t *uids;
1871     int uidsLen;
1872     result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1873     if ( result == RES_OK ){
1874     uidsToZval( uids, uidsLen, &zuids );
1875 youi 1.19 freeUID( uids );
1876 aga 1.8 }
1877     }
1878     RETURN_LONG( result );
1879     }
1880    
1881 aga 1.11 /** ?違???若???????<?潟???若?????ゃ??????<br>
1882 youi 1.24 int xnp_delete_member(int sid, int group_id, int user_id )
1883     @param sid XNP???祉???激?с??D
1884     @param group_id XNP???違???若??ID
1885     @param user_id ???若??D
1886     @return 0 success
1887 aga 1.11 */
1888    
1889 youi 1.21 ZEND_FUNCTION(xnp_delete_member)
1890 aga 1.11 {
1891     long sid, gid, uid;
1892 youi 1.24
1893     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1894     &sid, &gid, &uid) == FAILURE) {
1895 aga 1.11 return;
1896     }
1897 youi 1.24
1898 aga 1.11 result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1899     RETURN_LONG( result );
1900     }
1901    
1902     /** ?違???若?????<?潟???若??菴遵??????<br>
1903 youi 1.24 int xnp_insert_member(int sid, int group_id, int user_id, bool admin )
1904     @param sid XNP???祉???激?с??D
1905     @param group_id XNP???違???若??ID
1906     @param user_id ???若??D
1907     @param admin ?違???若??膊∞????????true
1908     @return 0 success
1909 aga 1.11 */
1910    
1911 youi 1.21 ZEND_FUNCTION(xnp_insert_member)
1912 aga 1.11 {
1913     long sid, gid, uid;
1914     zend_bool admin;
1915 youi 1.24
1916     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
1917     &sid, &gid, &uid, &admin) == FAILURE) {
1918 aga 1.11 return;
1919     }
1920 youi 1.24
1921 aga 1.11 result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
1922     RETURN_LONG( result );
1923     }
1924    
1925     /** gid?ф??絎??????違???若?????<?潟???若??id???荀с??緇???<br>
1926 youi 1.24 int xnp_get_members(int sid, int group_id, array criteria, array uids )
1927     @param sid XNP???祉???激?с??D
1928     @param group_id XNP???違???若??ID
1929     @param criteria ?>散
1930     @param uids uid???荀с??????????????
1931     @return 0 success
1932 aga 1.11 */
1933    
1934 youi 1.21 ZEND_FUNCTION(xnp_get_members)
1935 aga 1.11 {
1936     long sid, gid;
1937     zval *zcriteria;
1938     zval *zuids;
1939 youi 1.24
1940     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1941     &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1942 aga 1.11 return;
1943     }
1944 youi 1.24
1945 aga 1.11 zCriteria_t zcri(zcriteria);
1946     result_t result = zcri.getResult();
1947     if ( result == RES_OK ){
1948     userid_t *uids;
1949     int uidsLen;
1950     result = getMembers( (sessionid_t)sid, (groupid_t)gid, &zcri, &uids, &uidsLen );
1951     if ( result == RES_OK ){
1952     uidsToZval( uids, uidsLen, &zuids );
1953 youi 1.19 freeUID( uids );
1954 aga 1.11 }
1955     }
1956     RETURN_LONG( result );
1957     }
1958 youi 1.7
1959     /** ?違???若?????宴??紊??眼??????<br>
1960 youi 1.24 int xnp_update_group(int sid, array group )
1961     @param sid XNP???祉???激?с??D
1962     @param group ?違???若?????宴???f?渇????
1963     @return 0 success
1964 youi 1.7 */
1965 youi 1.21 ZEND_FUNCTION(xnp_update_group)
1966 youi 1.7 {
1967     long sid;
1968     zval *zgroup;
1969 youi 1.24 group_t group;
1970    
1971     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1972     &sid, &zgroup) == FAILURE) {
1973 youi 1.7 return;
1974     }
1975 youi 1.24
1976     zvalToGroup( zgroup, &group );
1977     result_t result = updateGroup( sid, &group );
1978     RETURN_LONG( result );
1979 aga 1.10 }
1980    
1981 youi 1.12 /** ?違???若?????宴??菴遵????????<br>
1982 youi 1.24 int xnp_insert_group( int sid, array group, int &gid )
1983     @param sid ?祉???激?с??D
1984     @param group ?違???若?????宴???f?渇????
1985     @param gid 絲上??????違???若??ID???吾??莨若???????<???潟??/span>
1986     @return RES_OK
1987     @return RES_DB_NOT_INITIALIZED
1988     @return RES_NO_SUCH_SESSION
1989     @return RES_DB_QUERY_ERROR
1990 youi 1.12 */
1991 youi 1.21 ZEND_FUNCTION(xnp_insert_group)
1992 youi 1.12 {
1993     long sid;
1994     zval *zgroup;
1995 youi 1.24 zval *zgid;
1996     group_t group;
1997     groupid_t gid;
1998    
1999     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2000     &sid, &zgroup, &zgid ) == FAILURE) {
2001 youi 1.12 return;
2002     }
2003 youi 1.24
2004     zvalToGroup( zgroup, &group );
2005     result_t result = insertGroup( sid, &group, &gid );
2006     zgid -> type = IS_LONG;
2007     zgid -> value.lval = gid;
2008     RETURN_LONG( result );
2009 youi 1.12 }
2010    
2011    
2012     /** ?違???若?????宴?????ゃ??????<br>
2013 youi 1.24 int xnp_delete_group( int sid, int gid )
2014     @param sid XNP???祉???激?с??D
2015     @param gid ???ゃ???????違???若????D
2016     @return RES_OK
2017     @return RES_DB_QUERY_ERROR
2018     @return RES_NO_SUCH_SESSION
2019     @return RES_DB_NOT_INITIALIZED
2020 youi 1.12 */
2021 youi 1.21 ZEND_FUNCTION(xnp_delete_group)
2022 youi 1.12 {
2023     long sid;
2024     long gid;
2025 youi 1.24
2026     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2027     &sid, &gid) == FAILURE) {
2028 youi 1.12 return;
2029     }
2030 youi 1.24 RETURN_LONG( deleteGroup( sid, gid ) );
2031 youi 1.12 }
2032    
2033     /** ?違???若?????????????緇???<br>
2034 youi 1.24 int xnp_dump_group_admins( int sid, int gid, array criteria, array uids )
2035     @param sid XNP???祉???激?с??D
2036     @param gid XNP?違???若????D
2037     @param criteria uids???吾??莨若?????????純?若???>散鐚?膀??蚊????絎?
2038     @param uids 膊∞??????ID???吾??莨若??????
2039     @return RES_OK
2040     @return RES_DB_QUERY_ERROR
2041     @return RES_NO_SUCH_SESSION
2042     @return RES_DB_NOT_INITIALIZED
2043 youi 1.12 */
2044     /*
2045 youi 1.21 ZEND_FUNCTION(xnp_dump_group_admins)
2046 youi 1.12 {
2047     long sid;
2048     long gid;
2049     zval *zcriteria;
2050     zval *zuids;
2051 youi 1.24
2052     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2053     &sid, &gid, &zcriteria, &zuids) == FAILURE) {
2054 youi 1.12 return;
2055     }
2056     zCriteria_t zcri(zcriteria);
2057     result_t result = zcri.getResult();
2058     if ( RES_OK == result ){
2059 youi 1.24 userid_t* uids;
2060     int uidsLen;
2061     result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
2062     if( result != RES_OK ) RETURN_LONG( result );
2063     uidsToZval( uids, uidsLen, &zuids );
2064     fprintf( stderr, "uidsLen=%d\n", uidsLen );
2065     for( int i = 0; i < uidsLen; i++ ){
2066     fprintf( stderr, "%d, \n", uids[ i ] );
2067     }
2068     freeUID( uids );
2069     RETURN_LONG( result );
2070     }
2071     RETURN_LONG( result );
2072 youi 1.12 }
2073     */
2074 aga 1.22
2075     /** ???????ゃ?潟???????鴻??緇???<br>
2076     * int xnp_get_all_indexes( int sid, array criteria, array indexes );
2077     * @param sid XNP???祉???激?с??D
2078     * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
2079     * @return RES_OK
2080     */
2081     ZEND_FUNCTION(xnp_get_all_indexes)
2082     {
2083     long sid;
2084     zval *zcriteria;
2085     zval *zindexes;
2086 youi 1.24
2087     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
2088     &sid, &zcriteria, &zindexes) == FAILURE) {
2089 aga 1.22 return;
2090     }
2091     zCriteria_t zcri(zcriteria);
2092     result_t result = zcri.getResult();
2093     if ( RES_OK == result ){
2094     const index_t *indexes;
2095     int indexesLen;
2096     result = getAllIndexes( sid, &zcri, &indexes, &indexesLen );
2097     if ( RES_OK == result ){
2098     result = indexesToZval( indexes, indexesLen, zindexes );
2099     freeIndex( indexes );
2100     }
2101     }
2102     RETURN_LONG(result);
2103     }
2104    
2105     /** ?????ゃ?潟???????鴻??????????ゃ?潟???????鴻??緇???<br>
2106     * int xnp_get_indexes( int sid, int parentXID, array criteria, array indexes );
2107     * @param sid XNP???祉???激?с??D
2108     * @param parentXID 荀???ndexID
2109     * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
2110     * @param indexes 腟?????????????????
2111     * @return RES_OK
2112     */
2113     ZEND_FUNCTION(xnp_get_indexes)
2114     {
2115     long sid;
2116     long parentXID;
2117     zval *zcriteria;
2118     zval *zindexes;
2119 youi 1.24
2120     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2121     &sid, &parentXID, &zcriteria, &zindexes) == FAILURE) {
2122 aga 1.22 return;
2123     }
2124     zCriteria_t zcri(zcriteria);
2125     result_t result = zcri.getResult();
2126     if ( RES_OK == result ){
2127     const index_t *indexes;
2128     int indexesLen;
2129     result = getIndexes( sid, parentXID, &zcri, &indexes, &indexesLen );
2130     if ( RES_OK == result ){
2131     result = indexesToZval( indexes, indexesLen, zindexes );
2132     freeIndex( indexes );
2133     }
2134     }
2135     RETURN_LONG(result);
2136     }
2137    
2138    
2139     /** ?ゃ?潟???????鴻??篏???????<br>
2140     * int xnp_insert_index( int sid, array index, int &indexID );
2141     * @param sid XNP???祉???激?с??D
2142     * @param index 篏????????ゃ?潟????????/span>
2143     * @param indexID 篏??????????ゃ?潟???????鴻??D??????????紊???/span>
2144     * @return RES_OK
2145     */
2146     ZEND_FUNCTION(xnp_insert_index)
2147     {
2148     long sid;
2149     zval *zindex;
2150     zval *zIndexID;
2151 youi 1.24
2152     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2153     &sid, &zindex, &zIndexID) == FAILURE) {
2154 aga 1.22 return;
2155     }
2156 youi 1.24
2157 aga 1.22 if (!PZVAL_IS_REF(zIndexID)) {
2158     zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
2159     RETURN_LONG(RES_PHP_NONREF);
2160     }
2161     zIndex_t index( zindex );
2162     indexid_t xid;
2163     result_t result = insertIndex( sid, &index, &xid );
2164     if ( RES_OK == result )
2165     ZVAL_LONG(zIndexID, (long)xid);
2166     RETURN_LONG(result);
2167     }
2168    
2169     /** ?ゃ?潟???????鴻???贋?違????<br>
2170     * int xnp_update_index( int sid, array index );
2171     * @param sid XNP???祉???激?с??D
2172     * @param index ?贋?違?????ゃ?潟????????/span>
2173     * @return RES_OK
2174     */
2175     ZEND_FUNCTION(xnp_update_index)
2176     {
2177     long sid;
2178     zval *zindex;
2179 youi 1.24
2180     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
2181     &sid, &zindex) == FAILURE) {
2182 aga 1.22 return;
2183     }
2184     zIndex_t index(zindex);
2185     result_t result = index.getResult();
2186     if ( RES_OK == result ){
2187     result = updateIndex( sid, &index );
2188     }
2189     RETURN_LONG(result);
2190     }
2191    
2192     /** ?ゃ?潟???????鴻?????ゃ????<br>
2193     * int xnp_delete_index( int sid, int indexID );
2194     * @param sid XNP???祉???激?с??D
2195     * @param indexID ???ゃ?????ゃ?潟????????/span>
2196     * @return RES_OK
2197     */
2198     ZEND_FUNCTION(xnp_delete_index)
2199     {
2200     long sid;
2201     long xid;
2202 youi 1.24
2203     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2204     &sid, &xid) == FAILURE) {
2205 aga 1.22 return;
2206     }
2207 youi 1.24
2208 aga 1.22 result_t result = deleteIndex( sid, xid );
2209     RETURN_LONG(result);
2210     }
2211    
2212    
2213     /** ?ゃ?潟???????鴻????緇?????<br>
2214     * int xnp_get_index( int sid, int indexID, array index );
2215     * @param sid XNP???祉???激?с??D
2216     * @param indexID ??緇??????ゃ?潟???????鴻??D
2217     * @param index ??緇?腟??????????????f?渇????
2218     * @return RES_OK
2219     */
2220     ZEND_FUNCTION(xnp_get_index)
2221     {
2222     long sid;
2223     long xid;
2224     zval *zindex;
2225 youi 1.24
2226     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
2227     &sid, &xid, &zindex) == FAILURE) {
2228 aga 1.22 return;
2229     }
2230 youi 1.24
2231 aga 1.22 const index_t *index;
2232     result_t result = getIndex( sid, xid, &index );
2233     if ( RES_OK == result ){
2234     result = indexToZval( index, zindex );
2235     freeIndex( index );
2236     }
2237     RETURN_LONG(result);
2238     }
2239    
2240    
2241    
2242     /** ?ゃ?潟???????鴻??茯??粋昭?水??純??????????茯帥?鴻??<br>
2243     * int xnp_is_index_readable( int sid, int indexID );
2244     * @param sid XNP???祉???激?с??D
2245     * @param indexID 絲乗院?ゃ?潟???????鴻??D
2246     * @return true false
2247     */
2248     ZEND_FUNCTION(xnp_is_index_readable)
2249     {
2250     long sid;
2251     long xid;
2252 youi 1.24
2253     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2254     &sid, &xid) == FAILURE) {
2255 aga 1.22 return;
2256     }
2257     RETURN_BOOL(isIndexReadable(sid,xid));
2258     }
2259    
2260    
2261     /** ?ゃ?潟???????鴻???吾??莨若?水??純??????????茯帥?鴻??<br>
2262     * int xnp_is_index_writable( int sid, int indexID );
2263     * @param sid XNP???祉???激?с??D
2264     * @param indexID 絲乗院?ゃ?潟???????鴻??D
2265     * @return true false
2266     */
2267     ZEND_FUNCTION(xnp_is_index_writable)
2268     {
2269     long sid;
2270     long xid;
2271 youi 1.24
2272     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2273     &sid, &xid) == FAILURE) {
2274 aga 1.22 return;
2275     }
2276     RETURN_BOOL(isIndexWritable(sid,xid));
2277     }
2278    
2279     /** ?ゃ?潟???????鴻????綺???ャ???帥????<br>
2280     * int xnp_swap_index_sort_number( int sid, int indexID1, int indexID2 );
2281     * @param sid XNP???祉???激?с??D
2282     * @param indexID1 絲乗院?ゃ?潟???????鴻??D
2283     * @param indexID2 絲乗院?ゃ?潟???????鴻??D
2284     * @return true false
2285     */
2286     ZEND_FUNCTION(xnp_swap_index_sort_number)
2287     {
2288     long sid;
2289     long xid1, xid2;
2290 youi 1.24
2291     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2292     &sid, &xid1, &xid2) == FAILURE) {
2293 aga 1.22 return;
2294     }
2295 youi 1.24
2296 aga 1.22 result_t result = swapIndexSortNumber( sid, xid1, xid2 );
2297     RETURN_LONG(result);
2298     }
2299    
2300    
2301    
2302 youi 1.21 /** XNP??ession_id???綵??с???с????lt;br>
2303 youi 1.24 bool xnp_is_valid_session_id( int xnp_session_id)
2304     @return true ???鴻??NP??ession_id?с????<br>
2305     @return false ?≦?鴻??ession_id?障??????????/span>
2306 aga 1.10 */
2307 youi 1.21 ZEND_FUNCTION(xnp_is_valid_session_id)
2308 aga 1.10 {
2309     long sid;
2310     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
2311     return;
2312     }
2313 youi 1.24
2314 aga 1.10 RETURN_BOOL(isValidSessionID((sessionid_t)sid));
2315 aga 1.9 }
2316    
2317     /** ?????惹??絖?????緇???<br>
2318 youi 1.24 string xnp_get_last_error_string()
2319     @return 0 success
2320 aga 1.9 */
2321 youi 1.21 ZEND_FUNCTION(xnp_get_last_error_string)
2322 aga 1.9 {
2323     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
2324     return;
2325     }
2326 youi 1.24
2327 aga 1.9 string str( getLastErrorString() );
2328     RETURN_STRING((char *)str.c_str(), 1);
2329 youi 1.7 }
2330    
2331 youi 1.24
2332     /**
2333     *
2334     * ?≪?ゃ?????吾???≪???祉?号┤???????с????????
2335     *
2336     * @refer itemop_t
2337     * @param sid ?祉???激?с??D
2338     * @param iid ???с?????莟<???????≪?ゃ??????D
2339     * @param op ?≪???祉?鴻??┏蕁?
2340     * @return true 罔???????
2341     * @return false 罔???????
2342     *
2343     */
2344     ZEND_FUNCTION(xnp_get_item_permission)
2345     {
2346     RETURN_LONG( RES_ERROR );
2347     }
2348    
2349    
2350     /**
2351     *
2352     * ?ゃ?潟???????鴻?吾???≪???祉?号┤???????с????????
2353     *
2354     * @refer indexop_t
2355     * @param sid ?祉???激?с??D
2356     * @param xid ???с?????莟<???????ゃ?潟???????鴻??D
2357     * @param op ?≪???祉?鴻??┏蕁?
2358     * @return true 罔???????
2359     * @return false 罔???????
2360     *
2361     */
2362     ZEND_FUNCTION(xnp_get_index_permission)
2363     {
2364     RETURN_LONG( RES_ERROR );
2365     }
2366    
2367    
2368     /**
2369     *
2370     * ?≪?ゃ???????粋??倶????紊??眼????罔????????<??茯帥?鴻?障??鐚?/span>
2371     * @refer certify_t
2372     * @param sid ?祉???激?с??D
2373     * @param xid 紊??翫?莟<?≪?ゃ???????脂?蚊???????????ゃ?潟???????鴻??D
2374     * @param iid 紊??翫?莟<?≪?ゃ??????D
2375     * @param state ?違???鎀??眼???????粋??倶??
2376     * @return true 罔???????
2377     * @return false 罔???????
2378     *
2379     */
2380     ZEND_FUNCTION(xnp_get_certify_permission)
2381     {
2382     RETURN_LONG( RES_ERROR );
2383     }
2384    
2385    
2386     /**
2387     *
2388     * ?≪?ゃ???????粋??倶??????緇????障??鐚?/span>
2389     * @refer certify_t
2390     * @param sid ?祉???激?с??D
2391     * @param xid 絲乗院?≪?ゃ???????脂?蚊???????????ゃ?潟???????鴻??D
2392     * @param iid 絲乗院?≪?ゃ??????D
2393     * @param state ?粋??倶????????????綣???/span>
2394     * @return RES_OK
2395     * @return RES_NO_WRITE_ACCESS_RIGHT
2396     *
2397     */
2398     ZEND_FUNCTION(xnp_get_certify_state)
2399     {
2400     long sid;
2401     indexid_t xid;
2402     itemid_t iid;
2403     zval *zstate;
2404     result_t result = RES_ERROR;
2405    
2406     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllz",
2407     &sid, &xid, &iid, &zstate) == FAILURE) {
2408     fprintf( stderr, "error occured " );
2409     return;
2410     }
2411     certify_t st;
2412     result = getCertifyState( (sessionid_t)sid, xid, iid, &st );
2413     if ( RES_OK == result ){
2414     zstate -> type = IS_LONG;
2415     zstate -> value.lval = st;
2416     }
2417     RETURN_LONG( result );
2418     }
2419    
2420    
2421     /**
2422     *
2423     * ?≪?ゃ???????粋??倶????紊??眼???障??鐚?/span>
2424     * @refer certify_t
2425     * @param sid ?祉???激?с??D
2426     * @param xid 紊??翫?莟<?≪?ゃ???????脂?蚊???????????ゃ?潟???????鴻??D
2427     * @param iid 紊??翫?莟<?≪?ゃ??????D
2428     * @param state ?違???鎀??眼???????粋??倶??
2429     * @return RES_OK
2430     * @return RES_NO_WRITE_ACCESS_RIGHT
2431     *
2432     */
2433     ZEND_FUNCTION(xnp_set_certify_state)
2434     {
2435     long sid;
2436     indexid_t xid;
2437     itemid_t iid;
2438     certify_t state;
2439     result_t result = RES_ERROR;
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     certify_t st;
2447     result = setCertifyState( (sessionid_t)sid, xid, iid, state );
2448     RETURN_LONG( result );
2449     }
2450    
2451    
2452     /**
2453     *
2454     * 紊??翫吋罩眼???違??荐??蚊????鐚?/span>
2455     *
2456     * @param sid ?祉???激?с??D
2457     * @param itemid 紊??翫吋罩眼??荐??蚊?????≪?ゃ??????D
2458