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.16 - (hide annotations) (download) (as text)
Sat Dec 4 09:22:24 2004 UTC (19 years, 4 months ago) by aga
Branch: MAIN
Changes since 1.15: +191 -82 lines
File MIME type: text/x-c++src
・コメントつけ.

1 aga 1.1 /*
2 aga 1.16 $Revision$
3 aga 1.1 VPAL: Visiome Platform Abstract Layer
4    
5     zend_parse_parameters??hp4.1.0??綽?荀?
6     .so???<?ゃ?????????荀????????贋????舟??鴻????
7     C++?с????extern "C"{}, BEGIN/END_EXTERN_C()??綽?荀???
8     */
9    
10    
11     #include <stdio.h>
12 aga 1.2 #include "criteria.h"
13     #include "common.h"
14     #include "commonal.h"
15     #include "session.h"
16     #include "group.h"
17     #include "account.h"
18 aga 1.1 #include "vpal.h"
19    
20 aga 1.2 // for inet_aton
21     #include <sys/socket.h>
22     #include <netinet/in.h>
23     #include <arpa/inet.h>
24    
25 aga 1.1 // global variables
26     MYSQL *mysql = NULL;
27    
28    
29     /* declaration of functions to be exported */
30     extern "C" {
31 aga 1.2 ZEND_FUNCTION(first_module );
32     ZEND_FUNCTION(vp_initialize_db );
33     ZEND_FUNCTION(vp_login_user );
34     ZEND_FUNCTION(vp_logout_user );
35 aga 1.4 ZEND_FUNCTION(vp_create_session );
36     ZEND_FUNCTION(vp_get_session );
37 aga 1.2 ZEND_FUNCTION(vp_is_activated );
38     ZEND_FUNCTION(vp_activate );
39     ZEND_FUNCTION(vp_get_account_count );
40     ZEND_FUNCTION(vp_delete_account );
41     ZEND_FUNCTION(vp_get_account );
42     ZEND_FUNCTION(vp_get_accounts );
43     ZEND_FUNCTION(vp_insert_account );
44     ZEND_FUNCTION(vp_update_account );
45     ZEND_FUNCTION(vp_dump_uids );
46     ZEND_FUNCTION(vp_get_group_count );
47     ZEND_FUNCTION(vp_get_groups_by_uid );
48     ZEND_FUNCTION(vp_is_group_admin );
49     ZEND_FUNCTION(vp_dump_gids );
50 aga 1.8 ZEND_FUNCTION(vp_dump_group_admins );
51 aga 1.2 ZEND_FUNCTION(vp_delete_member );
52     ZEND_FUNCTION(vp_insert_member );
53     ZEND_FUNCTION(vp_get_members );
54     ZEND_FUNCTION(vp_delete_group );
55     ZEND_FUNCTION(vp_insert_group );
56     ZEND_FUNCTION(vp_update_group );
57     ZEND_FUNCTION(vp_get_group );
58     ZEND_FUNCTION(vp_get_groups );
59     ZEND_FUNCTION(vp_is_moderator );
60     ZEND_FUNCTION(vp_get_uid );
61    
62 aga 1.10 ZEND_FUNCTION(vp_is_valid_session_id );
63 aga 1.9 ZEND_FUNCTION(vp_get_last_error_string );
64    
65 aga 1.2 ZEND_FUNCTION(vp_test_criteria );
66     ZEND_FUNCTION(vp_test_uids );
67 aga 1.1 };
68     /* compiled function list so Zend knows what's in this module */
69     zend_function_entry vpalmod_functions[] =
70     {
71 aga 1.2 ZEND_FE(first_module ,NULL)
72     ZEND_FE(vp_initialize_db ,NULL)
73     ZEND_FE(vp_login_user ,NULL)
74     ZEND_FE(vp_logout_user ,NULL)
75 aga 1.4 ZEND_FE(vp_create_session ,NULL)
76     ZEND_FE(vp_get_session ,NULL)
77 aga 1.2 ZEND_FE(vp_is_activated ,NULL)
78     ZEND_FE(vp_activate ,NULL)
79     ZEND_FE(vp_get_account_count ,NULL)
80     ZEND_FE(vp_delete_account ,NULL)
81     ZEND_FE(vp_get_account ,NULL)
82     ZEND_FE(vp_get_accounts ,NULL)
83     ZEND_FE(vp_insert_account ,NULL)
84     ZEND_FE(vp_update_account ,NULL)
85     ZEND_FE(vp_dump_uids ,NULL)
86     ZEND_FE(vp_get_group_count ,NULL)
87     ZEND_FE(vp_get_groups_by_uid ,NULL)
88     ZEND_FE(vp_is_group_admin ,NULL)
89     ZEND_FE(vp_dump_gids ,NULL)
90 aga 1.8 ZEND_FE(vp_dump_group_admins ,NULL)
91 aga 1.2 ZEND_FE(vp_delete_member ,NULL)
92     ZEND_FE(vp_insert_member ,NULL)
93     ZEND_FE(vp_get_members ,NULL)
94     ZEND_FE(vp_delete_group ,NULL)
95     ZEND_FE(vp_insert_group ,NULL)
96     ZEND_FE(vp_update_group ,NULL)
97     ZEND_FE(vp_get_group ,NULL)
98     ZEND_FE(vp_get_groups ,NULL)
99     ZEND_FE(vp_is_moderator ,NULL)
100     ZEND_FE(vp_get_uid ,NULL)
101 aga 1.10 ZEND_FE(vp_is_valid_session_id ,NULL)
102 aga 1.9 ZEND_FE(vp_get_last_error_string ,NULL)
103 aga 1.2 ZEND_FE(vp_test_criteria ,NULL)
104     ZEND_FE(vp_test_uids ,NULL)
105 aga 1.1 {NULL, NULL, NULL}
106     };
107    
108     /* compiled module information */
109     zend_module_entry vpalmod_module_entry =
110     {
111     STANDARD_MODULE_HEADER,
112     "Visiome Platform Abstract Layer",
113     vpalmod_functions,
114     NULL,
115     NULL,
116     NULL,
117     NULL,
118 aga 1.16 NULL,
119 aga 1.1 NO_VERSION_YET,
120     STANDARD_MODULE_PROPERTIES
121     };
122    
123     /* implement standard "stub" routine to introduce ourselves to Zend */
124     #if COMPILE_DL_FIRST_MODULE
125     BEGIN_EXTERN_C()
126     ZEND_GET_MODULE(vpalmod)
127     END_EXTERN_C()
128     #endif
129    
130 aga 1.16
131 aga 1.1 /* implement function that is meant to be made available to PHP */
132     ZEND_FUNCTION(first_module)
133     {
134     long parameter;
135     // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
136     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
137     return;
138     }
139     parameter++;
140     RETURN_LONG(parameter);
141     }
142     /** zval????C????絖?????緇?????
143     */
144     char *getZvalString( zval **p ){
145     convert_to_string_ex(p);
146     return Z_STRVAL_PP(p); //(**p).value.str.val;
147     }
148    
149     /** zval????int??緇?????
150     */
151     int getZvalInt( zval **p ){
152     convert_to_long_ex(p);
153     return Z_LVAL_PP(p); // (int)(**p).value.lval;
154     }
155    
156 aga 1.2 // keylen????鮎??0????????
157     static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
158     zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
159     if ( res == HASH_KEY_IS_STRING ){
160     char *p = new char[keyLen+1];
161     memcpy( p, key, keyLen );
162     p[keyLen] = 0;
163     zend_printf( " key is string[%s]<br>\n", p );
164     }
165     else {
166     zend_printf( " key is integer[%d]<br>\n", index );
167     }
168     }
169    
170    
171 aga 1.16 /** zval*????criteria_t?????????????????????鴻??????紊掩??????getResult()!=RES_OK <br>
172     criteria :
173 aga 1.2 array( 'start'=>0, 'rows'=>10,
174     'orders'=>array(
175     array('name'=>'id','order'=>'0'),
176     array('name'=>'timestamp','name'=>'1'), ...)
177     ); ??????就???f?渇????
178     */
179     class zCriteria_t : public criteria {
180     private:
181     result_t result;
182 aga 1.16
183 aga 1.2 // pz: array('name'=>'timestamp','name'=>'1')
184     // ????????orderby??篏???????申????
185     void setOrder( zval *pz ){
186     char *column = 0;
187     order_t order = (order_t)0;
188    
189     HashPosition pos;
190     zval **ppzTmp = 0;
191     int res2;
192     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
193     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
194     char *key = 0;
195     uint keyLen = 0;
196     ulong index = 0;
197     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
198     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
199 aga 1.14 //print_hash_key( keyType, key, keyLen, index );
200     if ( strncasecmp( key, "name", keyLen ) == 0 && keyLen == 5 ){
201 aga 1.2 SEPARATE_ZVAL(ppzTmp);
202     column = getZvalString(ppzTmp);
203     // zend_printf( "column=%s<br>\n", column );
204     }
205     else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
206     SEPARATE_ZVAL(ppzTmp);
207     order = (order_t)getZvalInt(ppzTmp);
208     // zend_printf( "order=%d<br>\n", order );
209     }
210     }
211    
212     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
213     }
214     if ( column ){
215     orderby *o = new orderby( column, order );
216     addOrderBy( o );
217     }
218    
219     result = RES_OK;
220     }
221    
222     // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
223     void setOrders( zval *pz ){
224     HashPosition pos;
225    
226     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
227    
228     zval **ppzTmp = 0;
229     int res2;
230     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
231     char *key = 0;
232     uint keyLen = 0;
233     ulong index = 0;
234     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
235     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
236 aga 1.14 //print_hash_key( keyType, key, keyLen, index );
237 aga 1.2 setOrder( *ppzTmp );
238     }
239     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
240     }
241     result = RES_OK;
242     }
243    
244     void initialize( zval *pz ){
245     HashPosition pos;
246     zval **ppzTmp = 0;
247     int res2;
248     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
249     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
250     char *key = 0;
251     uint keyLen = 0;
252     ulong index = 0;
253     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
254     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
255 aga 1.14 //print_hash_key( keyType, key, keyLen, index );
256 aga 1.2 if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
257     SEPARATE_ZVAL(ppzTmp);
258     int tmp = getZvalInt(ppzTmp);
259     // zend_printf( "start=%d<br>\n", tmp );
260     setLimit( tmp, getLimitRows() );
261     }
262     else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
263     SEPARATE_ZVAL(ppzTmp);
264     int tmp = getZvalInt(ppzTmp);
265     // zend_printf( "rows=%d<br>\n", tmp );
266     setLimit( getLimitStart(), tmp );
267     }
268     else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
269     setOrders( *ppzTmp );
270     }
271     else
272     ; // ignore unknown key
273     }
274     else
275     ; // ignore bad key
276     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
277     }
278     result = RES_OK;
279     }
280 aga 1.16
281     public:
282 aga 1.2 zCriteria_t() : criteria(){ result = RES_ERROR; }
283     zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
284     zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
285     result_t getResult(){ return result; };
286    
287     void dump(){
288     zend_printf( "dumping zCriteria...<br>\n" );
289     zend_printf( "result=%d<br>\n", (int)result );
290     zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() );
291     const orderby *p = headOrderBy();
292     while ( p ){
293     zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() );
294     p = nextOrderBy();
295     }
296     }
297     };
298    
299 aga 1.16
300     /** ?f?渇???????≪???祉?鴻????ong?ゃ??緇?????
301     @param ht ?f?渇????
302     @param key ????/span>
303     @param val long?ゃ?????????????ゃ?潟??/span>
304     @return ????????true
305     */
306     static bool hashGetLong( HashTable *ht, const char *key, long *val ){
307 aga 1.14 zval **tmp;
308     if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
309     convert_to_long_ex( tmp );
310     *val = Z_LVAL_PP(tmp);
311     return true;
312     }
313     return false;
314     }
315    
316 aga 1.16 /** ?f?渇???????≪???祉?鴻??????絖?????緇?????
317     @param ht ?f?渇????
318     @param key ????/span>
319     @param val ??絖????????????????ゃ?潟??/span>
320     @return ????????true
321     */
322     static bool hashGetString( HashTable *ht, const char *key, char **val ){
323 aga 1.14 zval **tmp;
324     if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
325     convert_to_string_ex( tmp );
326     *val = Z_STRVAL_PP(tmp);
327     return true;
328     }
329     return false;
330     }
331    
332 aga 1.16 /** ?f?渇???????≪???祉?鴻????ouble?ゃ??緇?????
333     @param ht ?f?渇????
334     @param key ????/span>
335     @param val double?ゃ?????????????ゃ?潟??/span>
336     @return ????????true
337     */
338     static bool hashGetDouble( HashTable *ht, const char *key, double *val ){
339 aga 1.14 zval **tmp;
340     if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
341     convert_to_double_ex( tmp );
342     *val = Z_DVAL_PP(tmp);
343     return true;
344     }
345     return false;
346     }
347 aga 1.2
348 aga 1.16 /** zval*????account?????????????????????鴻?? <br>
349     ????紊掩??????getResult()!=RES_OK <br>
350     */
351 aga 1.2 class zAccount_t : public account {
352     private:
353     result_t result;
354     void initialize(zval *pz){
355 aga 1.14 HashTable *ht = Z_ARRVAL_P(pz);
356     long l;
357     char *p;
358     double d;
359     if ( hashGetLong ( ht, "uid" , &l ) ) setUID ( l );
360     if ( hashGetString( ht, "uname" , &p ) ) setUname ( p );
361     if ( hashGetString( ht, "name" , &p ) ) setName ( p );
362     if ( hashGetString( ht, "email" , &p ) ) setEmail ( p );
363     if ( hashGetString( ht, "url" , &p ) ) setURL ( p );
364     if ( hashGetString( ht, "user_avatar" , &p ) ) setUserAvatar ( p );
365     if ( hashGetString( ht, "user_icq" , &p ) ) setUserIcq ( p );
366     if ( hashGetString( ht, "user_from" , &p ) ) setUserFrom ( p );
367     if ( hashGetString( ht, "user_sig" , &p ) ) setUserSig ( p );
368     if ( hashGetString( ht, "actkey" , &p ) ) setActkey ( p );
369     if ( hashGetString( ht, "user_aim" , &p ) ) setUserAim ( p );
370     if ( hashGetString( ht, "user_yim" , &p ) ) setUserYim ( p );
371     if ( hashGetString( ht, "user_msnm" , &p ) ) setUserMsnm ( p );
372     if ( hashGetString( ht, "pass" , &p ) ) setPass ( p );
373     if ( hashGetString( ht, "theme" , &p ) ) setTheme ( p );
374     if ( hashGetString( ht, "umode" , &p ) ) setUmode ( p );
375     if ( hashGetString( ht, "user_occ" , &p ) ) setUserOcc ( p );
376     if ( hashGetString( ht, "bio" , &p ) ) setBio ( p );
377     if ( hashGetString( ht, "user_intrest" , &p ) ) setUserIntrest ( p );
378     if ( hashGetDouble( ht, "timezone_offset" , &d ) ) setTimezoneOffset ( d );
379     if ( hashGetLong ( ht, "attachsig" , &l ) ) setAttachsig ( l );
380     if ( hashGetLong ( ht, "last_login" , &l ) ) setLastLogin ( l );
381     if ( hashGetLong ( ht, "level" , &l ) ) setLevel ( l );
382     if ( hashGetLong ( ht, "notify_method" , &l ) ) setNotifyMethod ( l );
383     if ( hashGetLong ( ht, "notify_mode" , &l ) ) setNotifyMode ( l );
384     if ( hashGetLong ( ht, "posts" , &l ) ) setPosts ( l );
385     if ( hashGetLong ( ht, "rank" , &l ) ) setRank ( l );
386     if ( hashGetLong ( ht, "uorder" , &l ) ) setUorder ( l );
387     if ( hashGetLong ( ht, "user_mailok" , &l ) ) setUserMailok ( l );
388     if ( hashGetLong ( ht, "user_regdate" , &l ) ) setUserRegdate ( l );
389     if ( hashGetLong ( ht, "user_viewemail" , &l ) ) setUserViewemail ( l );
390     if ( hashGetLong ( ht, "activate" , &l ) ) setActivate ( l );
391     if ( hashGetString( ht, "address" , &p ) ) setAddress ( p );
392 aga 1.16 if ( hashGetString( ht, "division" , &p ) ) setDivision ( p );
393 aga 1.14 if ( hashGetString( ht, "tel" , &p ) ) setTel ( p );
394 aga 1.16 if ( hashGetString( ht, "company_name" , &p ) ) setCompanyName ( p );
395 aga 1.14 if ( hashGetString( ht, "country" , &p ) ) setCountry ( p );
396     if ( hashGetString( ht, "zipcode" , &p ) ) setZipcode ( p );
397     if ( hashGetString( ht, "fax" , &p ) ) setFax ( p );
398     if ( hashGetString( ht, "base_url" , &p ) ) setBaseURL ( p );
399     if ( hashGetLong ( ht, "notice_mail" , &l ) ) setNoticeMail ( l );
400     if ( hashGetLong ( ht, "notice_mail_since" , &l ) ) setNoticeMailSince ( l );
401    
402     result = RES_OK;
403 aga 1.2 }
404 aga 1.16 public:
405 aga 1.2 zAccount_t() : account(){ result = RES_ERROR; }
406 aga 1.16
407     /** ?潟?潟?鴻????????/span>
408     @param pz array( 'uid'=>1, 'uname'=>'root', ... ); ??????就???f?渇???? */
409 aga 1.2 zAccount_t( zval *pz ) : account(){ initialize(pz); }
410     zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
411     result_t getResult(){ return result; };
412     };
413    
414 aga 1.16 /** zval*????(userid_t *puid,int uidLen)?????????????????????鴻?? <br>
415     ????紊掩??????getResult()!=RES_OK <br>
416 aga 1.2 */
417     class zUIDs_t {
418     private:
419     result_t result;
420     userid_t *pUID;
421     int len;
422     public:
423     zUIDs_t(){
424     pUID = 0;
425     len = 0;
426     result = RES_ERROR;
427     }
428    
429 aga 1.16 /** ?潟?潟?鴻????????/span>
430     @param pza array( '1', '3', '4', '6', ... ); ??????就?????? */
431 aga 1.2 zUIDs_t( zval *pza ){
432     pUID = 0;
433     len = 0;
434     result = RES_ERROR;
435    
436     if ( Z_TYPE_P(pza) != IS_ARRAY ){
437     result = RES_ERROR;
438     }
439     else {
440     len = zend_hash_num_elements(Z_ARRVAL_P(pza));
441     if(len == 0) {
442     pUID = new userid_t[1];
443     result = RES_OK;
444     }
445     else {
446     /* php/ext/standard/string.c ? implode??????????????????
447     zend_hash_*???????ャ?<?潟???c????????????????鐚?
448     */
449     zval **tmp;
450     HashPosition pos;
451     int i = 0;
452     pUID = new userid_t[len];
453    
454     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
455     while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
456     SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
457     convert_to_long_ex(tmp);
458     if ( i < len )
459     pUID[i++] = Z_LVAL_PP(tmp);
460     zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
461     }
462     len = i;
463     result = RES_OK;
464     }
465     }
466     }
467    
468     ~zUIDs_t(){
469     if ( pUID ) delete[] pUID;
470     }
471     result_t getResult(){ return result; }
472     userid_t *getPUID(){ return pUID; }
473     int getLen(){ return len; }
474     void dump(){
475     zend_printf( "dumping zUIDs...<br>\n" );
476     zend_printf( "result=%d<br>\n", (int)result );
477     zend_printf( "len=%d<br>\n", len );
478     for ( int i = 0; i < len; i++ ){
479     zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
480     }
481     }
482     };
483    
484 aga 1.8 /**
485     *
486     * uids_t????????PHP???????????????
487     *
488 aga 1.16 * @param pUID 紊???????serid_t??????
489 aga 1.8 * @param len pUID?????????激??
490     * @param pz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
491     * @return RES_OK
492     *
493     */
494 aga 1.4 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
495     {
496 aga 1.8 zend_hash_clean( Z_ARRVAL_PP(ppz) );
497 aga 1.2
498     // add UIDs
499     for ( int i = 0; i < len; i++ ){
500 aga 1.8 add_next_index_long(*ppz, (long)(pUID[i]) );
501 aga 1.2 }
502    
503     return RES_OK;
504     }
505 aga 1.16 /**
506     *
507     * groupid_t????????PHP???????????????
508     * @param pGID 紊???????roupid_t??????
509     * @param len pGID?????????激??
510     * @param ppz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
511     * @return RES_OK
512     *
513     */
514 aga 1.4 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
515     {
516 aga 1.8 zend_hash_clean( Z_ARRVAL_PP(ppz) );
517 aga 1.2
518     // add GIDs
519     for ( int i = 0; i < len; i++ ){
520 aga 1.8 add_next_index_long(*ppz, (long)(pGID[i]) );
521 aga 1.2 }
522    
523     return RES_OK;
524     }
525    
526 aga 1.16
527     /**
528     *
529     * account_t????絎鴻??PHP???????????????
530     * @param pAccount 紊???????ccount_t*
531     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
532     * @return RES_OK
533     *
534     */
535 youi 1.6 result_t accountToZval( const account_t *pAccount, zval *z )
536     {
537     zend_hash_clean( z -> value.ht );
538    
539 youi 1.7 add_assoc_long( z, "uid", pAccount -> getUID( ) );
540 youi 1.6 add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
541     add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
542     add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
543     add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
544     add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
545     add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
546     add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
547     add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
548     add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
549     add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
550     add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
551     add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
552     add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
553     add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
554     add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
555     add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
556     add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
557     add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
558     add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
559     add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
560     add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
561     add_assoc_long( z, "level", pAccount -> getLevel( ) );
562     add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
563     add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
564     add_assoc_long( z, "posts", pAccount -> getPosts( ) );
565     add_assoc_long( z, "rank", pAccount -> getRank( ) );
566     add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
567     add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
568     add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
569     add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
570    
571     add_assoc_long( z, "activate", pAccount -> getActivate( ) );
572     add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
573 youi 1.15 add_assoc_string( z, "division", ( char* )pAccount -> getDivision( ), 1 );
574 youi 1.6 add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
575 youi 1.15 add_assoc_string( z, "company_name", ( char* )pAccount -> getCompanyName( ), 1 );
576 youi 1.6 add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
577     add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
578     add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
579     add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
580     add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
581     add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
582     return RES_OK;
583     }
584 aga 1.16 /**
585     *
586     * 茲??違??ccount_t????絎鴻??PHP?????????????????????
587     * @param pAccounts 紊???????ccount_t*
588     * @param accountsLen pAccounts?????????激??
589     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
590     * @return RES_OK
591     *
592     z: ?????????????????????????? <br>
593 aga 1.2 array(
594     array(
595     'uid'=>100,
596     'activate'=>1,
597 youi 1.15 'division'=>'foo',
598 aga 1.2 'tel'=>'123-456-789',
599     ...
600     ),
601     ...
602     )
603 aga 1.16 */
604 youi 1.6 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
605 aga 1.4 {
606 youi 1.6 zend_hash_clean( z -> value.ht );
607     for( int i = 0; i < accountsLen; i++ ){
608     zval *new_array;
609     MAKE_STD_ZVAL(new_array);
610     if(array_init(new_array) != SUCCESS){
611     return RES_ERROR;
612     }
613     add_index_zval( z, i, new_array );
614     accountToZval( &pAccounts[ i ], new_array );
615     }
616     return RES_OK;
617 aga 1.2 }
618    
619 aga 1.16 /**
620     *
621     * 茲??違??roup_t????絎鴻??PHP?????????????????????
622     * @param pGroups 紊???????roup_t*
623     * @param groupsLen pGroups?????????激??
624     * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
625     * @return RES_OK
626     *
627     z: ?????????????????????????? <br>
628     array(
629     array(
630     'gid'=>1,
631     'gname'=>'foo group',
632     'gdesc'=>'group of foo'
633     ),
634     ...
635     )
636     */
637 youi 1.6 result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
638 aga 1.4 {
639 youi 1.6 zend_hash_clean( z -> value.ht );
640     for( int i = 0; i < groupsLen; i++ ){
641     zval *new_array;
642     MAKE_STD_ZVAL(new_array);
643     if(array_init(new_array) != SUCCESS){
644     return RES_ERROR;
645     }
646     add_index_zval( z, i, new_array );
647     add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
648     add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
649     add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
650     }
651     return RES_OK;
652 aga 1.2 }
653    
654 youi 1.7 /**
655     *
656     * group_t????絎鴻??PHP???f?渇?????????????
657     *
658 aga 1.16 * @param pGroup 紊????????違???若??????/span>
659 youi 1.7 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
660     * @return RES_OK
661     *
662     */
663     result_t groupToZval( const group_t *pGroup, zval *z )
664 youi 1.6 {
665     zend_hash_clean( z -> value.ht );
666     add_assoc_long( z, "gid", pGroup -> getGID( ) );
667     add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
668     add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
669     return RES_OK;
670     }
671    
672 aga 1.16 /**
673     *
674     * PHP???f?渇????????絎鴻??group_t?????????
675     *
676     * @param z 紊????????f?渇????
677     * @param pGroup 紊???腟??????吾??莨若???違???若??
678     * @return RES_OK
679     *
680     */
681 youi 1.7 result_t zvalToGroup( zval *z, group_t *pGroup )
682     {
683     zval **tmp;
684     HashPosition pos;
685     int i = 0;
686     char* key = 0;
687    
688     key = "gid";
689 youi 1.12 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
690     convert_to_long_ex( tmp ) ;
691     pGroup -> setGID( (*tmp) -> value.lval );
692     }
693 youi 1.7 key = "gname";
694 youi 1.12 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
695     convert_to_string_ex( tmp ) ;
696     pGroup -> setGname( (*tmp) -> value.str.val );
697     }
698 youi 1.7 key = "gdesc";
699 youi 1.12 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
700     convert_to_string_ex( tmp ) ;
701     pGroup -> setDesc( (*tmp) -> value.str.val );
702     }
703 youi 1.7 return RES_OK;
704     }
705    
706 aga 1.16 /**
707     *
708     * session_t????絎鴻??PHP???f?渇?????????????
709     *
710     * @param pSession 紊???????ession_t
711     * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
712     * @return RES_OK
713     *
714     */
715     result_t sessionToZval( const session_t *pSession, zval *z )
716     {
717     string sessionID(unsignedIntToString(pSession->getSessionID()));
718     add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
719    
720     string date(unsignedIntToString((unsigned int)pSession->getDate()));
721     add_assoc_string(z, "date", (char *)date.c_str(), 1);
722    
723     string userID(unsignedIntToString((unsigned int)pSession->getUserID()));
724     add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
725    
726     return RES_OK;
727     }
728    
729 youi 1.7
730 aga 1.16
731     /** ??絎??????違???若???????宴??緇???<br>
732     int vp_get_group( int sid, int gid, array group );
733     @param sid VP???祉???激?с??D
734     @param gid VP ? group_id
735     @param group 腟?????????????????
736     @return 0 success <br>
737     */
738 youi 1.6 ZEND_FUNCTION(vp_get_group)
739 aga 1.4 {
740 youi 1.6 long sid, gid;
741     zval *zgroup;
742    
743     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
744     &sid, &gid, &zgroup) == FAILURE) {
745     return;
746     }
747    
748     const group_t *pgroup;
749     result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
750     if ( RES_OK == result ){
751 youi 1.7 groupToZval( pgroup, zgroup );
752 youi 1.6 freeResult( pgroup );
753     }
754    
755     RETURN_LONG(result);
756     }
757    
758 aga 1.2
759 aga 1.16 /** ??絎??????違???若??(茲????????宴??緇???<br>
760     vp_get_groups( int sid, array gids, array criteria, array groups );
761     @param sid VP???祉???激?с??D
762     @param gids VP ? group_id ??????
763     @param criteria ?>散
764     @param groups 腟???????????????????????
765     @return 0 success <br>
766     */
767 youi 1.6 ZEND_FUNCTION(vp_get_groups)
768     {
769     result_t result;
770     long sid, uid;
771     zval *zcriteria;
772     zval *zgids;
773     zval *zgroups;
774     zval **ppzTmp = 0;
775     HashPosition pos;
776     int res2;
777     int gidsLen;
778     const group_t* groups;
779     int groupsLen;
780    
781     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
782     &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
783     return;
784     }
785    
786     //gids???違???若??ID???潟???若????
787     gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
788     groupid_t *gids = new groupid_t[ gidsLen ];
789     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
790     for( int i = 0; i < gidsLen; i++ ){
791     if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
792     SEPARATE_ZVAL(ppzTmp);
793     convert_to_long_ex(ppzTmp);
794     gids[ i ] = Z_LVAL_PP(ppzTmp);
795     }
796     zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
797     }
798    
799     zCriteria_t zcri(zcriteria);
800     result = zcri.getResult();
801     if ( RES_OK == result ){
802     result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
803     if ( RES_OK == result ){
804 aga 1.14 groupsToZval( groups, groupsLen, zgroups );
805 youi 1.6 delete[] gids;
806     freeResult( groups );
807     }
808     }
809     RETURN_LONG(result);
810     }
811    
812    
813 aga 1.16 /** ??絎????????若?吟???≪?????若?帥??????????茯帥?鴻??<br>
814     int vp_is_moderator(int sid, int uid)
815     @param sid VP???祉???激?с??D
816     @param uid xoops ? uid (xoops_users.uid)
817     @return true ?≪?????若?帥?с???? <br>
818     */
819 youi 1.6 ZEND_FUNCTION(vp_is_moderator)
820     {
821     long vpSessionID;
822     userid_t uid;
823    
824     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
825     &vpSessionID, &uid) == FAILURE) {
826     return;
827     }
828    
829     bool result = isModerator( (sessionid_t)vpSessionID, uid );
830     RETURN_BOOL(result)
831     }
832    
833 aga 1.16 /** ???若?九??????uid??茯帥?鴻??<br>
834     int vp_get_uid(string uname,int &uid)
835     @param sid VP???祉???激?с??D
836     @param uname xoops ? uname (xoops_users.uname)
837     @param uid xoops ? uid (xoops_users.uid) ??????????紊???/span>
838     @return 0 success
839     */
840 youi 1.6 ZEND_FUNCTION(vp_get_uid)
841     {
842     char *uname;
843     int unameLen;
844 aga 1.14 zval *zuid;
845 youi 1.6 userid_t uid;
846    
847 aga 1.14 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
848     &uname, &unameLen, &zuid) == FAILURE) {
849 youi 1.6 return;
850     }
851    
852 aga 1.14 if (!PZVAL_IS_REF(zuid)) {
853     zend_error(E_WARNING, "2nd parameter wasn't passed by reference");
854     RETURN_LONG(RES_PHP_NONREF);
855     }
856    
857 youi 1.6 string strUname( uname, unameLen );
858     result_t result = getUid( strUname.c_str(), &uid );
859 aga 1.14 ZVAL_LONG(zuid, (long)uid);
860     RETURN_LONG((long)result);
861 aga 1.2 }
862    
863     ZEND_FUNCTION(vp_test_criteria)
864     {
865     zval *z;
866    
867     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
868     &z) == FAILURE) {
869     return;
870     }
871     zend_printf("zend_printf...<br>\n");
872     zCriteria_t zcri(z);
873     zcri.dump();
874     RETURN_FALSE
875     }
876    
877     ZEND_FUNCTION(vp_test_uids)
878     {
879     zval *z;
880    
881     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
882     &z) == FAILURE) {
883     return;
884     }
885     zend_printf("zend_printf...<br>\n");
886     zUIDs_t zuids(z);
887     zuids.dump();
888     RETURN_FALSE
889     }
890    
891    
892    
893 aga 1.4 /** DB??・膓????????≪??・膓?筝???・膓???????????????<br>
894     int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
895 aga 1.2 @param host ?ョ????????ユ????ULL
896 aga 1.1 @param user DB?ョ????????若?九???????ユ????ULL
897     @param password DB?ョ????????鴻???若???????ユ????ULL
898 aga 1.2 @param dbname DB?ョ?????B???????ユ????quot;"
899     @param prefix XOOPS DB ??refix??
900 aga 1.1 @return 0 success <br>
901     */
902     ZEND_FUNCTION(vp_initialize_db)
903     {
904     zval **parameters[5];
905     char *host;
906     char *user;
907 aga 1.2 char *password;
908     char *dbname;
909     char *prefix;
910 aga 1.1
911     /* get the number of arguments */
912     int argNum = ZEND_NUM_ARGS();
913     if (argNum > 5)
914     WRONG_PARAM_COUNT;
915    
916     /* argument count is correct, now retrieve arguments */
917     if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
918     WRONG_PARAM_COUNT;
919    
920 aga 1.2 if (argNum < 1) host = NULL;
921 aga 1.1 else host = getZvalString( parameters[0] );
922    
923     if (argNum < 2) user = NULL;
924     else user = getZvalString( parameters[1] );
925    
926 aga 1.2 if (argNum < 3) password = NULL;
927     else password = getZvalString( parameters[2] );
928 aga 1.1
929 aga 1.2 if (argNum < 4) dbname = "";
930     else dbname = getZvalString( parameters[3] );
931 aga 1.1
932 aga 1.2 if (argNum < 5) prefix = "";
933     else prefix = getZvalString( parameters[4] );
934 aga 1.1
935 aga 1.2 result_t result = initializeDB( host, user, password, dbname, prefix );
936 aga 1.1
937 aga 1.2 RETURN_LONG(result);
938 aga 1.1 }
939    
940 aga 1.4 /** ???違?ゃ?潟??????<br>
941 aga 1.14 int vp_login_user(string uname, string password, int &session_id)
942 aga 1.4 @param uname ???若?九??(xoops_users.uname)
943     @param password ???鴻???若??(md5(password)=xoops_users.pass)
944     @return 0 success
945     */
946 aga 1.1 ZEND_FUNCTION(vp_login_user)
947     {
948     char *uname;
949     int unameLen;
950     char *passwd;
951     int passwdLen;
952 aga 1.14 zval *zVPSessionID;
953 aga 1.1
954 aga 1.14 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",
955     &uname, &unameLen, &passwd, &passwdLen, &zVPSessionID) == FAILURE) {
956 aga 1.1 return;
957     }
958    
959 aga 1.14 if (!PZVAL_IS_REF(zVPSessionID)) {
960     zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
961     RETURN_LONG(RES_PHP_NONREF);
962     }
963    
964 aga 1.4 sessionid_t vpSessionID;
965 aga 1.5 result_t result = loginUser( uname, passwd, &vpSessionID );
966 aga 1.14 if ( result == RES_OK )
967     ZVAL_LONG(zVPSessionID, (long)vpSessionID);
968     RETURN_LONG((long)result);
969 aga 1.1 }
970    
971 aga 1.4 /** ???違?≪??????????<br>
972     void vp_logout_user(int vp_session_id)
973 aga 1.16 @param vp_session_id VP???祉???激?с??D
974 aga 1.4 @return ????
975     */
976 aga 1.1 ZEND_FUNCTION(vp_logout_user)
977     {
978 aga 1.4 long vpSessionID;
979 aga 1.1
980 aga 1.4 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &vpSessionID) == FAILURE) {
981 aga 1.1 return;
982     }
983 aga 1.4 logoutUser( (sessionid_t)vpSessionID );
984 aga 1.1
985     RETURN_NULL();
986     }
987    
988 aga 1.16 /** VP???祉???激?с??D 篏???<br>
989 aga 1.14 int vp_create_session( string xoops_sess_id, int uid, int &session )
990 aga 1.16 @param xoops_sess_id xoops???祉???激?с??D
991 aga 1.4 @param uid xoops ? uid (xoops_users.uid)
992 aga 1.16 @param session 篏???????VP??ession??????????紊???/span>
993 aga 1.14 @return 0 ????
994 aga 1.4 */
995 aga 1.2 ZEND_FUNCTION(vp_create_session)
996     {
997     char *xoopsSessionID;
998     int xoopsSessionIDLen;
999 aga 1.5 long uid;
1000 aga 1.14 zval *zVPSessionID;
1001 aga 1.2
1002 aga 1.14 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz",
1003     &xoopsSessionID, &xoopsSessionIDLen, &uid, &zVPSessionID) == FAILURE) {
1004 aga 1.2 return;
1005     }
1006    
1007 aga 1.14 if (!PZVAL_IS_REF(zVPSessionID)) {
1008     zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1009     RETURN_LONG(RES_PHP_NONREF);
1010     }
1011    
1012 aga 1.4 sessionid_t vpSessionID = 0;
1013     result_t result = createSession( xoopsSessionID, (userid_t)uid, &vpSessionID );
1014 aga 1.14 if ( result == RES_OK )
1015     ZVAL_LONG(zVPSessionID, (long)vpSessionID);
1016     RETURN_LONG((long)result);
1017 aga 1.4 }
1018    
1019 aga 1.16 /** VP ? session ???膣井???宴??緇???<br>
1020 aga 1.4 int vp_get_session( int vp_session_id, array session_info )
1021 aga 1.16 @param vp_session_id VP???祉???激?с??D
1022 aga 1.4 @param session_info 腟?????????????????
1023     @return 0 success
1024     */
1025     ZEND_FUNCTION(vp_get_session)
1026     {
1027     long vpSessionID;
1028     zval *sessionInfo;
1029     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1030     &vpSessionID, &sessionInfo) == FAILURE) {
1031     return;
1032     }
1033     const session_t *session = 0;
1034     result_t result = getSession( (sessionid_t)vpSessionID, &session );
1035     if ( result == RES_OK ){
1036     sessionToZval( session, sessionInfo );
1037     freeResult( session );
1038     }
1039 aga 1.2
1040 aga 1.4 RETURN_LONG((long)result);
1041 aga 1.2 }
1042 aga 1.1
1043 aga 1.16 /** ???若?吟??ctivate?倶??????緇?????<br>
1044 aga 1.5 bool vp_is_activated( int vp_session_id, int user_id )
1045 aga 1.16 @param vp_session_id VP???祉???激?с??D
1046 aga 1.5 @param user_id xoops_users.uid
1047     @return 0 success
1048     */
1049 aga 1.2 ZEND_FUNCTION(vp_is_activated)
1050     {
1051     long sid, uid;
1052    
1053 aga 1.5 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
1054 aga 1.2 return;
1055     }
1056    
1057     bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
1058    
1059     RETURN_BOOL(result);
1060     }
1061 aga 1.1
1062 aga 1.16 /** ???若?吟??activate??????<br>
1063 aga 1.5 bool vp_activate( int vp_session_id, bool activated )
1064 aga 1.16 @param vp_session_id VP???祉???激?с??D
1065 aga 1.5 @param user_id xoops_users.uid
1066     @param activated true:activate, false:inactivate
1067     @return 0 success
1068     */
1069 aga 1.2 ZEND_FUNCTION(vp_activate)
1070     {
1071     long sid, uid;
1072     bool activated;
1073    
1074     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
1075     &sid, &uid, &activated) == FAILURE) {
1076     return;
1077     }
1078    
1079     result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
1080    
1081     RETURN_LONG(result);
1082     }
1083 aga 1.1
1084 aga 1.16 /** VP???≪?????潟???違??緇?????<br>
1085 aga 1.5 int vp_get_account_count( int vp_session_id )
1086 aga 1.16 @param vp_session_id VP???祉???激?с??D
1087 aga 1.5 @return 0 success
1088     */
1089 aga 1.2 ZEND_FUNCTION(vp_get_account_count)
1090     {
1091     long sid;
1092    
1093     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1094     &sid) == FAILURE) {
1095     return;
1096     }
1097    
1098     long count = getAccountCount( (sessionid_t)sid );
1099     RETURN_LONG(count);
1100     }
1101 aga 1.1
1102 aga 1.5 /** ?≪?????潟???????ゃ??????<br>
1103     bool vp_delete_account( int vp_session_id, int user_id )
1104 aga 1.16 @param vp_session_id VP???祉???激?с??D
1105 aga 1.5 @param user_id xoops_users.uid
1106     @return 0 success
1107     */
1108 aga 1.2 ZEND_FUNCTION(vp_delete_account)
1109     {
1110     long sid, uid;
1111    
1112     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1113     &sid, &uid) == FAILURE) {
1114     return;
1115     }
1116    
1117     result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
1118    
1119     RETURN_LONG(result);
1120     }
1121 aga 1.1
1122 aga 1.5 /** ?≪?????潟?????宴??緇?????<br>
1123     int vp_get_account( int vp_session_id, int user_id, array account_info )
1124 aga 1.16 @param vp_session_id VP???祉???激?с??D
1125 aga 1.5 @param user_id xoops_users.uid
1126     @param account_info ?≪?????潟?????宴???????????f?渇????
1127     @return 0 success
1128     */
1129 aga 1.2 ZEND_FUNCTION(vp_get_account)
1130     {
1131     long sid, uid;
1132     zval *zaccount;
1133    
1134     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1135     &sid, &uid, &zaccount) == FAILURE) {
1136 youi 1.6 fprintf( stderr, "error occured " );
1137 aga 1.2 return;
1138     }
1139    
1140     const account_t *paccount;
1141     result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
1142     if ( RES_OK == result ){
1143     accountToZval( paccount, zaccount );
1144     freeResult( paccount );
1145     }
1146    
1147     RETURN_LONG(result);
1148     }
1149 aga 1.1
1150 aga 1.5 /** ?>散????眼?????≪?????潟???????宴??緇?????<br>
1151     int vp_get_accoutns( int sid, array uids, array criteria, array accounts );
1152 aga 1.16 @param vp_session_id VP???祉???激?с??D
1153 aga 1.5 @param user_id xoops_users.uid
1154     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1155     @param account_info ?≪?????潟?????宴???????????f?渇????
1156     @return 0 success
1157     */
1158 aga 1.2 ZEND_FUNCTION(vp_get_accounts)
1159     {
1160     result_t result;
1161     long sid;
1162     zval *zuids;
1163     zval *zcriteria;
1164     zval *zaccount;
1165    
1166     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1167     &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
1168     return;
1169     }
1170    
1171     zCriteria_t zcri(zcriteria);
1172     result = zcri.getResult();
1173     if ( RES_OK == result ){
1174     zUIDs_t zUIDs(zuids);
1175     result = zUIDs.getResult();
1176     if ( RES_OK == result ){
1177     const account_t *paccounts;
1178     int accountLen;
1179     result = getAccounts( (sessionid_t)sid,
1180     zUIDs.getPUID(), zUIDs.getLen(),
1181     &zcri, &paccounts, &accountLen );
1182     if ( RES_OK == result ){
1183     accountsToZval( paccounts, accountLen, zaccount );
1184     freeResult( paccounts );
1185     }
1186     }
1187     }
1188    
1189     RETURN_LONG(result);
1190     }
1191 aga 1.1
1192 aga 1.5 /** ?≪?????潟?????宴??緇?????<br>
1193     int vp_insert_account( int sid, array account_info );
1194 aga 1.16 @param vp_session_id VP???祉???激?с??D
1195 aga 1.5 @param user_id xoops_users.uid
1196     @param account_info ?≪?????潟?????宴???????????f?渇????
1197     @return 0 success
1198     */
1199 aga 1.2 ZEND_FUNCTION(vp_insert_account)
1200     {
1201     result_t result;
1202     long sid;
1203     zval *zaccount;
1204    
1205     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1206     &sid, &zaccount) == FAILURE) {
1207     return;
1208     }
1209    
1210     zAccount_t zacc(zaccount);
1211     result = zacc.getResult();
1212     if ( RES_OK == result ){
1213     result = insertAccount( (sessionid_t)sid, &zacc );
1214     }
1215    
1216     RETURN_LONG(result);
1217     }
1218 aga 1.1
1219 aga 1.5 /** ?≪?????潟?????宴???贋?違??????<br>
1220     int vp_update_account( int sid, array account );
1221 aga 1.16 @param vp_session_id VP???祉???激?с??D
1222 aga 1.5 @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
1223     @return 0 success
1224     */
1225 aga 1.2 ZEND_FUNCTION(vp_update_account)
1226     {
1227     result_t result;
1228     long sid;
1229     zval *zaccount;
1230    
1231     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1232     &sid, &zaccount) == FAILURE) {
1233     return;
1234     }
1235    
1236     zAccount_t zacc(zaccount);
1237     result = zacc.getResult();
1238     if ( RES_OK == result ){
1239     result = updateAccount( (sessionid_t)sid, &zacc );
1240     }
1241    
1242     RETURN_LONG(result);
1243     }
1244 aga 1.1
1245 aga 1.5 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
1246     int vp_dump_uids( int vp_session_id, array criteria, array uids );
1247 aga 1.16 @param vp_session_id VP???祉???激?с??D
1248 aga 1.5 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1249     @param uids uid??????????????
1250     @return 0 success
1251     */
1252 aga 1.2 ZEND_FUNCTION(vp_dump_uids)
1253     {
1254     result_t result;
1255     long sid;
1256     zval *zcriteria;
1257     zval *zuids;
1258    
1259     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1260     &sid, &zcriteria, &zuids) == FAILURE) {
1261     return;
1262     }
1263    
1264     zCriteria_t zcri(zcriteria);
1265     result = zcri.getResult();
1266     if ( RES_OK == result ){
1267     userid_t *puid;
1268     int uidLen;
1269     result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1270     if ( RES_OK == result ){
1271     uidsToZval( puid, uidLen, &zuids );
1272     freeResult( puid );
1273     }
1274     }
1275    
1276     RETURN_LONG(result);
1277     }
1278 aga 1.1
1279 aga 1.5 /** VP???違???若?????違??緇???<br>
1280 aga 1.16 int vp_get_group_count( int vp_session_id );
1281     @param vp_session_id VP???祉???激?с??D
1282 aga 1.5 @return ?違???若????/span>
1283     */
1284 aga 1.2 ZEND_FUNCTION(vp_get_group_count)
1285 aga 1.1 {
1286 aga 1.2 result_t result;
1287     long sid;
1288    
1289     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1290     &sid) == FAILURE) {
1291     return;
1292     }
1293    
1294     int count = getGroupCount( (sessionid_t)sid );
1295    
1296     RETURN_LONG(count);
1297     }
1298 aga 1.1
1299 aga 1.5 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
1300 aga 1.16 int vp_get_group_by_uid( int vp_session_id, int uid, array criteria, array gids );
1301     @param vp_session_id VP???祉???激?с??D
1302 aga 1.5 @param user_id xoops_users.uid
1303     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1304     @param gids gid??????????????
1305     @return 0 success
1306     */
1307 aga 1.2 ZEND_FUNCTION(vp_get_groups_by_uid)
1308     {
1309     result_t result;
1310     long sid, uid;
1311     zval *zcriteria;
1312     zval *zgids;
1313    
1314     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1315     &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1316     return;
1317 aga 1.1 }
1318    
1319 aga 1.2 zCriteria_t zcri(zcriteria);
1320     result = zcri.getResult();
1321     if ( RES_OK == result ){
1322     groupid_t *pgids;
1323     int gidLen;
1324     result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1325     if ( RES_OK == result ){
1326     gidsToZval( pgids, gidLen, &zgids );
1327     freeResult( pgids );
1328     }
1329 aga 1.1 }
1330    
1331 aga 1.2 RETURN_LONG(result);
1332     }
1333    
1334    
1335 aga 1.5
1336     /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
1337     int vp_is_group_admin( int sid, int gid, int uid );
1338 aga 1.16 @param vp_session_id VP???祉???激?с??D
1339 aga 1.5 @param group_id VP???違???若??ID
1340     @param user_id xoops_users.uid
1341     @return true: ?違???若??膊∞?????с??????
1342     @return false: ?違???若??膊∞?????с???????????????????若?с??????
1343     */
1344 aga 1.2 ZEND_FUNCTION(vp_is_group_admin)
1345     {
1346     result_t result;
1347     long sid, gid, uid;
1348    
1349     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1350     &sid, &gid, &uid) == FAILURE) {
1351     return;
1352 aga 1.1 }
1353    
1354 aga 1.2 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1355 aga 1.1
1356 aga 1.2 RETURN_BOOL(b);
1357     }
1358    
1359 aga 1.5 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
1360     int vp_dump_gids( int sid, array criteria, array gids );
1361 aga 1.16 @param vp_session_id VP???祉???激?с??D
1362 aga 1.5 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1363     @param gids gid??????????????
1364     @return 0 success
1365     */
1366 aga 1.2 ZEND_FUNCTION(vp_dump_gids)
1367     {
1368     result_t result;
1369     long sid;
1370     zval *zcriteria;
1371     zval *zgids;
1372    
1373     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1374     &sid, &zcriteria, &zgids) == FAILURE) {
1375     return;
1376     }
1377 aga 1.1
1378 aga 1.2 zCriteria_t zcri(zcriteria);
1379     result = zcri.getResult();
1380     if ( RES_OK == result ){
1381     groupid_t *pgid;
1382     int gidLen;
1383     result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1384     if ( RES_OK == result ){
1385     gidsToZval( pgid, gidLen, &zgids );
1386     freeResult( pgid );
1387 aga 1.1 }
1388     }
1389    
1390 aga 1.2 RETURN_LONG(result);
1391 aga 1.1 }
1392 aga 1.8
1393     /** gid?ф??絎??????違???若??????????с?????ゆ?>散????眼?????違???若??膊∞??????id???荀с??緇?????<br>
1394     int vp_dump_group_admins(int sid, int group_id, array criteria, array uids )
1395 aga 1.16 @param sid VP???祉???激?с??D
1396     @param group_id VP???違???若??ID
1397 aga 1.8 @param criteria ?>散
1398     @param uids uid???荀с??????????????
1399     @return 0 success
1400     */
1401    
1402     ZEND_FUNCTION(vp_dump_group_admins)
1403     {
1404     long sid, gid;
1405     zval *zcriteria;
1406     zval *zuids;
1407    
1408     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1409     &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1410     return;
1411     }
1412    
1413     zCriteria_t zcri(zcriteria);
1414     result_t result = zcri.getResult();
1415     if ( result == RES_OK ){
1416     userid_t *uids;
1417     int uidsLen;
1418     result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1419     if ( result == RES_OK ){
1420     uidsToZval( uids, uidsLen, &zuids );
1421     freeResult( uids );
1422     }
1423     }
1424     RETURN_LONG( result );
1425     }
1426    
1427 aga 1.11 /** ?違???若???????<?潟???若?????ゃ??????<br>
1428     int vp_delete_member(int sid, int group_id, int user_id )
1429 aga 1.16 @param sid VP???祉???激?с??D
1430     @param group_id VP???違???若??ID
1431 aga 1.11 @param user_id ???若??D
1432     @return 0 success
1433     */
1434    
1435     ZEND_FUNCTION(vp_delete_member)
1436     {
1437     long sid, gid, uid;
1438    
1439     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1440     &sid, &gid, &uid) == FAILURE) {
1441     return;
1442     }
1443    
1444     result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1445     RETURN_LONG( result );
1446     }
1447    
1448     /** ?違???若?????<?潟???若??菴遵??????<br>
1449     int vp_insert_member(int sid, int group_id, int user_id, bool admin )
1450 aga 1.16 @param sid VP???祉???激?с??D
1451     @param group_id VP???違???若??ID
1452 aga 1.11 @param user_id ???若??D
1453     @param admin ?違???若??膊∞????????true
1454     @return 0 success
1455     */
1456    
1457     ZEND_FUNCTION(vp_insert_member)
1458     {
1459     long sid, gid, uid;
1460     zend_bool admin;
1461    
1462     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
1463     &sid, &gid, &uid, &admin) == FAILURE) {
1464     return;
1465     }
1466    
1467     result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
1468     RETURN_LONG( result );
1469     }
1470    
1471     /** gid?ф??絎??????違???若?????<?潟???若??id???荀с??緇???<br>
1472     int vp_get_members(int sid, int group_id, array criteria, array uids )
1473 aga 1.16 @param sid VP???祉???激?с??D
1474     @param group_id VP???違???若??ID
1475 aga 1.11 @param criteria ?>散
1476     @param uids uid???荀с??????????????
1477     @return 0 success
1478     */
1479    
1480     ZEND_FUNCTION(vp_get_members)
1481     {
1482     long sid, gid;
1483     zval *zcriteria;
1484     zval *zuids;
1485    
1486     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1487     &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1488     return;
1489     }
1490    
1491     zCriteria_t zcri(zcriteria);
1492     result_t result = zcri.getResult();
1493     if ( result == RES_OK ){
1494     userid_t *uids;
1495     int uidsLen;
1496     result = getMembers( (sessionid_t)sid, (groupid_t)gid, &zcri, &uids, &uidsLen );
1497     if ( result == RES_OK ){
1498     uidsToZval( uids, uidsLen, &zuids );
1499     freeResult( uids );
1500     }
1501     }
1502     RETURN_LONG( result );
1503     }
1504 youi 1.7
1505     /** ?違???若?????宴??紊??眼??????<br>
1506     int vp_update_group(int sid, array group )
1507 aga 1.16 @param sid VP???祉???激?с??D
1508 youi 1.7 @param group ?違???若?????宴???f?渇????
1509     @return 0 success
1510     */
1511     ZEND_FUNCTION(vp_update_group)
1512     {
1513     long sid;
1514     zval *zgroup;
1515     group_t group;
1516    
1517     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1518     &sid, &zgroup) == FAILURE) {
1519     return;
1520     }
1521    
1522     zvalToGroup( zgroup, &group );
1523     result_t result = updateGroup( sid, &group );
1524     RETURN_LONG( result );
1525 aga 1.10 }
1526    
1527 youi 1.12 /** ?違???若?????宴??菴遵????????<br>
1528     int vp_insert_group( int sid, array group )
1529 aga 1.16 @param sid VP???祉???激?с??D
1530 youi 1.12 @param group ?違???若?????宴???f?渇????
1531     @return RES_OK
1532     @return RES_DB_NOT_INITIALIZED
1533     @return RES_NO_SUCH_SESSION
1534     @return RES_DB_QUERY_ERROR
1535     */
1536     ZEND_FUNCTION(vp_insert_group)
1537     {
1538     long sid;
1539     zval *zgroup;
1540     group_t group;
1541    
1542     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1543     &sid, &zgroup) == FAILURE) {
1544     return;
1545     }
1546    
1547     zvalToGroup( zgroup, &group );
1548     result_t result = insertGroup( sid, &group );
1549     RETURN_LONG( result );
1550     }
1551    
1552    
1553     /** ?違???若?????宴?????ゃ??????<br>
1554     int vp_delete_group( int sid, int gid )
1555 aga 1.16 @param sid VP???祉???激?с??D
1556 youi 1.12 @param gid ???ゃ???????違???若????D
1557     @return RES_OK
1558     @return RES_DB_QUERY_ERROR
1559     @return RES_NO_SUCH_SESSION
1560     @return RES_DB_NOT_INITIALIZED
1561     */
1562     ZEND_FUNCTION(vp_delete_group)
1563     {
1564     long sid;
1565     long gid;
1566    
1567     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1568     &sid, &gid) == FAILURE) {
1569     return;
1570     }
1571     RETURN_LONG( deleteGroup( sid, gid ) );
1572     }
1573    
1574     /** ?違???若?????????????緇???<br>
1575     int vp_dump_group_admins( int sid, int gid, array criteria, array uids )
1576 aga 1.16 @param sid VP???祉???激?с??D
1577     @param gid VP?違???若????D
1578 youi 1.12 @param criteria uids???吾??莨若?????????純?若???>散鐚?膀??蚊????絎?
1579     @param uids 膊∞??????ID???吾??莨若??????
1580     @return RES_OK
1581     @return RES_DB_QUERY_ERROR
1582     @return RES_NO_SUCH_SESSION
1583     @return RES_DB_NOT_INITIALIZED
1584     */
1585     /*
1586     ZEND_FUNCTION(vp_dump_group_admins)
1587     {
1588     long sid;
1589     long gid;
1590     zval *zcriteria;
1591     zval *zuids;
1592    
1593     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1594     &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1595     return;
1596     }
1597     zCriteria_t zcri(zcriteria);
1598     result_t result = zcri.getResult();
1599     if ( RES_OK == result ){
1600     userid_t* uids;
1601     int uidsLen;
1602     result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1603     if( result != RES_OK ) RETURN_LONG( result );
1604     uidsToZval( uids, uidsLen, &zuids );
1605     fprintf( stderr, "uidsLen=%d\n", uidsLen );
1606     for( int i = 0; i < uidsLen; i++ ){
1607     fprintf( stderr, "%d, \n", uids[ i ] );
1608     }
1609     freeResult( uids );
1610     RETURN_LONG( result );
1611     }
1612     RETURN_LONG( result );
1613     }
1614     */
1615    
1616 aga 1.16 /** VP??ession_id???綵??с???с????lt;br>
1617 aga 1.10 bool vp_is_valid_session_id( int vp_session_id)
1618 aga 1.16 @return true ???鴻??P??ession_id?с????<br>
1619 aga 1.10 @return false ?≦?鴻??ession_id?障??????????/span>
1620     */
1621     ZEND_FUNCTION(vp_is_valid_session_id)
1622     {
1623     long sid;
1624     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
1625     return;
1626     }
1627    
1628     RETURN_BOOL(isValidSessionID((sessionid_t)sid));
1629 aga 1.9 }
1630    
1631     /** ?????惹??絖?????緇???<br>
1632     string vp_get_last_error_string()
1633     @return 0 success
1634     */
1635     ZEND_FUNCTION(vp_get_last_error_string)
1636     {
1637     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
1638     return;
1639     }
1640    
1641     string str( getLastErrorString() );
1642     RETURN_STRING((char *)str.c_str(), 1);
1643 youi 1.7 }
1644    

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