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.38 - (hide annotations) (download) (as text)
Sat Mar 5 01:48:36 2005 UTC (19 years, 1 month ago) by aga4096
Branch: MAIN
Changes since 1.37: +40 -1 lines
File MIME type: text/x-c++src
・getItemCountGroupByIndexを作成.

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