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

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