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

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