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.6 - (hide annotations) (download) (as text)
Tue Nov 30 11:55:24 2004 UTC (19 years, 4 months ago) by youi
Branch: MAIN
Changes since 1.5: +197 -9 lines
File MIME type: text/x-c++src
vp_get_groups, vp_get_group, vp_is_mediator, vp_get_uidを定義.
accountToZval, accountsToZval, groupsToZval, groupToZvalを定義.

1 aga 1.1 /*
2     VPAL: Visiome Platform Abstract Layer
3    
4     zend_parse_parameters??hp4.1.0??綽?荀?
5     .so???<?ゃ?????????荀????????贋????舟??鴻????
6     C++?с????extern "C"{}, BEGIN/END_EXTERN_C()??綽?荀???
7     */
8    
9    
10     #include <stdio.h>
11 aga 1.2 #include "criteria.h"
12     #include "common.h"
13     #include "commonal.h"
14     #include "session.h"
15     #include "group.h"
16     #include "account.h"
17 aga 1.1 #include "vpal.h"
18    
19 aga 1.2 // for inet_aton
20     #include <sys/socket.h>
21     #include <netinet/in.h>
22     #include <arpa/inet.h>
23    
24 aga 1.1 // global variables
25     MYSQL *mysql = NULL;
26    
27    
28     /* declaration of functions to be exported */
29     extern "C" {
30 aga 1.2 ZEND_FUNCTION(first_module );
31     ZEND_FUNCTION(vp_initialize_db );
32     ZEND_FUNCTION(vp_login_user );
33     ZEND_FUNCTION(vp_logout_user );
34 aga 1.4 ZEND_FUNCTION(vp_create_session );
35     ZEND_FUNCTION(vp_get_session );
36 aga 1.2 ZEND_FUNCTION(vp_is_activated );
37     ZEND_FUNCTION(vp_activate );
38     ZEND_FUNCTION(vp_get_account_count );
39     ZEND_FUNCTION(vp_delete_account );
40     ZEND_FUNCTION(vp_get_account );
41     ZEND_FUNCTION(vp_get_accounts );
42     ZEND_FUNCTION(vp_insert_account );
43     ZEND_FUNCTION(vp_update_account );
44     ZEND_FUNCTION(vp_dump_uids );
45     ZEND_FUNCTION(vp_get_group_count );
46     ZEND_FUNCTION(vp_get_groups_by_uid );
47     ZEND_FUNCTION(vp_is_group_admin );
48     ZEND_FUNCTION(vp_dump_gids );
49     /*
50     ZEND_FUNCTION(vp_dump_group_admins );
51     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 youi 1.6 */
58 aga 1.2 ZEND_FUNCTION(vp_get_group );
59     ZEND_FUNCTION(vp_get_groups );
60     ZEND_FUNCTION(vp_is_moderator );
61     ZEND_FUNCTION(vp_get_uid );
62    
63     ZEND_FUNCTION(vp_test_criteria );
64     ZEND_FUNCTION(vp_test_uids );
65 aga 1.1 };
66     /* compiled function list so Zend knows what's in this module */
67     zend_function_entry vpalmod_functions[] =
68     {
69 aga 1.2 ZEND_FE(first_module ,NULL)
70     ZEND_FE(vp_initialize_db ,NULL)
71     ZEND_FE(vp_login_user ,NULL)
72     ZEND_FE(vp_logout_user ,NULL)
73 aga 1.4 ZEND_FE(vp_create_session ,NULL)
74     ZEND_FE(vp_get_session ,NULL)
75 aga 1.2 ZEND_FE(vp_is_activated ,NULL)
76     ZEND_FE(vp_activate ,NULL)
77     ZEND_FE(vp_get_account_count ,NULL)
78     ZEND_FE(vp_delete_account ,NULL)
79     ZEND_FE(vp_get_account ,NULL)
80     ZEND_FE(vp_get_accounts ,NULL)
81     ZEND_FE(vp_insert_account ,NULL)
82     ZEND_FE(vp_update_account ,NULL)
83     ZEND_FE(vp_dump_uids ,NULL)
84     ZEND_FE(vp_get_group_count ,NULL)
85     ZEND_FE(vp_get_groups_by_uid ,NULL)
86     ZEND_FE(vp_is_group_admin ,NULL)
87     ZEND_FE(vp_dump_gids ,NULL)
88     /*
89     ZEND_FE(vp_dump_group_admins ,NULL)
90     ZEND_FE(vp_delete_member ,NULL)
91     ZEND_FE(vp_insert_member ,NULL)
92     ZEND_FE(vp_get_members ,NULL)
93     ZEND_FE(vp_delete_group ,NULL)
94     ZEND_FE(vp_insert_group ,NULL)
95     ZEND_FE(vp_update_group ,NULL)
96 youi 1.6 */
97 aga 1.2 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     ZEND_FE(vp_test_criteria ,NULL)
102     ZEND_FE(vp_test_uids ,NULL)
103 aga 1.1 {NULL, NULL, NULL}
104     };
105    
106     /* compiled module information */
107     zend_module_entry vpalmod_module_entry =
108     {
109     STANDARD_MODULE_HEADER,
110     "Visiome Platform Abstract Layer",
111     vpalmod_functions,
112     NULL,
113     NULL,
114     NULL,
115     NULL,
116     NULL,
117     NO_VERSION_YET,
118     STANDARD_MODULE_PROPERTIES
119     };
120    
121     /* implement standard "stub" routine to introduce ourselves to Zend */
122     #if COMPILE_DL_FIRST_MODULE
123     BEGIN_EXTERN_C()
124     ZEND_GET_MODULE(vpalmod)
125     END_EXTERN_C()
126     #endif
127    
128     /* implement function that is meant to be made available to PHP */
129     ZEND_FUNCTION(first_module)
130     {
131     long parameter;
132     // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
133     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
134     return;
135     }
136     parameter++;
137     RETURN_LONG(parameter);
138     }
139     /** zval????C????絖?????緇?????
140     */
141     char *getZvalString( zval **p ){
142     convert_to_string_ex(p);
143     return Z_STRVAL_PP(p); //(**p).value.str.val;
144     }
145    
146     /** zval????int??緇?????
147     */
148     int getZvalInt( zval **p ){
149     convert_to_long_ex(p);
150     return Z_LVAL_PP(p); // (int)(**p).value.lval;
151     }
152    
153 aga 1.2 // keylen????鮎??0????????
154     static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
155     zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
156     if ( res == HASH_KEY_IS_STRING ){
157     char *p = new char[keyLen+1];
158     memcpy( p, key, keyLen );
159     p[keyLen] = 0;
160     zend_printf( " key is string[%s]<br>\n", p );
161     }
162     else {
163     zend_printf( " key is integer[%d]<br>\n", index );
164     }
165     }
166    
167    
168     /** zval**????criteria_t?????????????????????鴻??????紊掩??????getResult()!=RES_OK
169     * criteria :
170     array( 'start'=>0, 'rows'=>10,
171     'orders'=>array(
172     array('name'=>'id','order'=>'0'),
173     array('name'=>'timestamp','name'=>'1'), ...)
174     ); ??????就???f?渇????
175     */
176     class zCriteria_t : public criteria {
177     private:
178     result_t result;
179     public:
180     // pz: array('name'=>'timestamp','name'=>'1')
181     // ????????orderby??篏???????申????
182     void setOrder( zval *pz ){
183     char *column = 0;
184     order_t order = (order_t)0;
185    
186     HashPosition pos;
187     zval **ppzTmp = 0;
188     int res2;
189     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
190     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
191     char *key = 0;
192     uint keyLen = 0;
193     ulong index = 0;
194     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
195     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
196     print_hash_key( keyType, key, keyLen, index );
197     if ( strncasecmp( key, "column", keyLen ) == 0 && keyLen == 7 ){
198     SEPARATE_ZVAL(ppzTmp);
199     column = getZvalString(ppzTmp);
200     // zend_printf( "column=%s<br>\n", column );
201     }
202     else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
203     SEPARATE_ZVAL(ppzTmp);
204     order = (order_t)getZvalInt(ppzTmp);
205     // zend_printf( "order=%d<br>\n", order );
206     }
207     }
208    
209     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
210     }
211     if ( column ){
212     orderby *o = new orderby( column, order );
213     addOrderBy( o );
214     }
215    
216     result = RES_OK;
217     }
218    
219     // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
220     void setOrders( zval *pz ){
221     HashPosition pos;
222    
223     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
224    
225     zval **ppzTmp = 0;
226     int res2;
227     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
228     char *key = 0;
229     uint keyLen = 0;
230     ulong index = 0;
231     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
232     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
233     print_hash_key( keyType, key, keyLen, index );
234     setOrder( *ppzTmp );
235     }
236     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
237     }
238     result = RES_OK;
239     }
240    
241     void initialize( zval *pz ){
242     HashPosition pos;
243     zval **ppzTmp = 0;
244     int res2;
245     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
246     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
247     char *key = 0;
248     uint keyLen = 0;
249     ulong index = 0;
250     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
251     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
252     print_hash_key( keyType, key, keyLen, index );
253     if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
254     SEPARATE_ZVAL(ppzTmp);
255     int tmp = getZvalInt(ppzTmp);
256     // zend_printf( "start=%d<br>\n", tmp );
257     setLimit( tmp, getLimitRows() );
258     }
259     else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
260     SEPARATE_ZVAL(ppzTmp);
261     int tmp = getZvalInt(ppzTmp);
262     // zend_printf( "rows=%d<br>\n", tmp );
263     setLimit( getLimitStart(), tmp );
264     }
265     else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
266     setOrders( *ppzTmp );
267     }
268     else
269     ; // ignore unknown key
270     }
271     else
272     ; // ignore bad key
273     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
274     }
275     result = RES_OK;
276     }
277     zCriteria_t() : criteria(){ result = RES_ERROR; }
278     zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
279     zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
280     result_t getResult(){ return result; };
281    
282     void dump(){
283     zend_printf( "dumping zCriteria...<br>\n" );
284     zend_printf( "result=%d<br>\n", (int)result );
285     zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() );
286     const orderby *p = headOrderBy();
287     while ( p ){
288     zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() );
289     p = nextOrderBy();
290     }
291     }
292     };
293    
294    
295     class zAccount_t : public account {
296     private:
297     result_t result;
298     public:
299     void initialize(zval *pz){
300     ; // todo
301     }
302     zAccount_t() : account(){ result = RES_ERROR; }
303     zAccount_t( zval *pz ) : account(){ initialize(pz); }
304     zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
305     result_t getResult(){ return result; };
306     };
307    
308     /** zval**????(userid_t *puid,int uidLen)?????????????????????鴻??????紊掩??????getResult()!=RES_OK
309     uids : array( '1', '3', '4', '6', ... ); ??????就??????
310     */
311     class zUIDs_t {
312     private:
313     result_t result;
314     userid_t *pUID;
315     int len;
316     public:
317     zUIDs_t(){
318     pUID = 0;
319     len = 0;
320     result = RES_ERROR;
321     }
322    
323     zUIDs_t( zval *pza ){
324     pUID = 0;
325     len = 0;
326     result = RES_ERROR;
327    
328     if ( Z_TYPE_P(pza) != IS_ARRAY ){
329     result = RES_ERROR;
330     }
331     else {
332     len = zend_hash_num_elements(Z_ARRVAL_P(pza));
333     if(len == 0) {
334     pUID = new userid_t[1];
335     result = RES_OK;
336     }
337     else {
338     /* php/ext/standard/string.c ? implode??????????????????
339     zend_hash_*???????ャ?<?潟???c????????????????鐚?
340     */
341     zval **tmp;
342     HashPosition pos;
343     int i = 0;
344     pUID = new userid_t[len];
345    
346     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
347     while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
348     SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
349     convert_to_long_ex(tmp);
350     if ( i < len )
351     pUID[i++] = Z_LVAL_PP(tmp);
352     zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
353     }
354     len = i;
355     result = RES_OK;
356     }
357     }
358     }
359    
360     ~zUIDs_t(){
361     if ( pUID ) delete[] pUID;
362     }
363     result_t getResult(){ return result; }
364     userid_t *getPUID(){ return pUID; }
365     int getLen(){ return len; }
366     void dump(){
367     zend_printf( "dumping zUIDs...<br>\n" );
368     zend_printf( "result=%d<br>\n", (int)result );
369     zend_printf( "len=%d<br>\n", len );
370     for ( int i = 0; i < len; i++ ){
371     zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
372     }
373     }
374     };
375    
376     /** uids_t ?? zval
377     */
378 aga 1.4 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
379     {
380 aga 1.2 zval *pz;
381    
382     // create new array
383     MAKE_STD_ZVAL(pz);
384     array_init(pz);
385    
386     // add UIDs
387     for ( int i = 0; i < len; i++ ){
388     add_next_index_long(pz, (long)(pUID[i]) );
389     }
390    
391     // return array
392     *ppz = pz;
393     return RES_OK;
394     }
395     /** uids_t ?? zval
396     */
397 aga 1.4 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
398     {
399 aga 1.2 zval *pz;
400    
401     // create new array
402     MAKE_STD_ZVAL(pz);
403     array_init(pz);
404    
405     // add GIDs
406     for ( int i = 0; i < len; i++ ){
407     add_next_index_long(pz, (long)(pGID[i]) );
408     }
409    
410     // return array
411     *ppz = pz;
412     return RES_OK;
413     }
414    
415 youi 1.6 result_t accountToZval( const account_t *pAccount, zval *z )
416     {
417     zend_hash_clean( z -> value.ht );
418    
419     if( add_assoc_long( z, "uid", pAccount -> getUID( ) ) != SUCCESS ){
420     fprintf( stderr, "aaaaaaaaaaaaaaaa" );
421     abort( );
422     }
423     add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
424     add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
425     add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
426     add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
427     add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
428     add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
429     add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
430     add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
431     add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
432     add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
433     add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
434     add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
435     add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
436     add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
437     add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
438     add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
439     add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
440     add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
441     add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
442     add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
443     add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
444     add_assoc_long( z, "level", pAccount -> getLevel( ) );
445     add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
446     add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
447     add_assoc_long( z, "posts", pAccount -> getPosts( ) );
448     add_assoc_long( z, "rank", pAccount -> getRank( ) );
449     add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
450     add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
451     add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
452     add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
453    
454     add_assoc_long( z, "activate", pAccount -> getActivate( ) );
455     add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
456     add_assoc_string( z, "institute", ( char* )pAccount -> getInstitute( ), 1 );
457     add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
458     add_assoc_string( z, "organization", ( char* )pAccount -> getOrganization( ), 1 );
459     add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
460     add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
461     add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
462     add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
463     add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
464     add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
465     return RES_OK;
466     }
467    
468 aga 1.2 /** accounts ?? zval
469     * accounts: ????????????????
470     array(
471     array(
472     'uid'=>100,
473     'activate'=>1,
474     'institute'=>'foo',
475     'tel'=>'123-456-789',
476     ...
477     ),
478     ...
479     )
480     */
481 youi 1.6 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
482 aga 1.4 {
483 youi 1.6 zend_hash_clean( z -> value.ht );
484     for( int i = 0; i < accountsLen; i++ ){
485     zval *new_array;
486     MAKE_STD_ZVAL(new_array);
487     if(array_init(new_array) != SUCCESS){
488     return RES_ERROR;
489     }
490     add_index_zval( z, i, new_array );
491     accountToZval( &pAccounts[ i ], new_array );
492     }
493     return RES_OK;
494 aga 1.2 }
495    
496 youi 1.6 /** groups ?? zval
497     */
498     result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
499 aga 1.4 {
500 youi 1.6 zend_hash_clean( z -> value.ht );
501     for( int i = 0; i < groupsLen; i++ ){
502     zval *new_array;
503     MAKE_STD_ZVAL(new_array);
504     if(array_init(new_array) != SUCCESS){
505     return RES_ERROR;
506     }
507     add_index_zval( z, i, new_array );
508     add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
509     add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
510     add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
511     }
512     return RES_OK;
513 aga 1.2 }
514    
515 youi 1.6 /** group ?? zval
516 aga 1.2 */
517 youi 1.6 result_t groupToZval( const group_t *pGroup, int groupLen, zval *z )
518     {
519     zend_hash_clean( z -> value.ht );
520     add_assoc_long( z, "gid", pGroup -> getGID( ) );
521     add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
522     add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
523     return RES_OK;
524     }
525    
526     // int vp_get_group( int sid, int gid, array group );
527     ZEND_FUNCTION(vp_get_group)
528 aga 1.4 {
529 youi 1.6 long sid, gid;
530     zval *zgroup;
531    
532     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
533     &sid, &gid, &zgroup) == FAILURE) {
534     return;
535     }
536    
537     const group_t *pgroup;
538     result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
539     if ( RES_OK == result ){
540     //groupToZval( pgroup, zgroup );
541     freeResult( pgroup );
542     }
543    
544     RETURN_LONG(result);
545     }
546    
547 aga 1.2
548 youi 1.6 // int vp_get_groups( int sid, array gids, array criteria, array groups );
549     ZEND_FUNCTION(vp_get_groups)
550     {
551     result_t result;
552     long sid, uid;
553     zval *zcriteria;
554     zval *zgids;
555     zval *zgroups;
556     zval **ppzTmp = 0;
557     HashPosition pos;
558     int res2;
559     int gidsLen;
560     const group_t* groups;
561     int groupsLen;
562    
563     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
564     &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
565     return;
566     }
567    
568     //gids???違???若??ID???潟???若????
569     gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
570     groupid_t *gids = new groupid_t[ gidsLen ];
571     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
572     for( int i = 0; i < gidsLen; i++ ){
573     if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
574     SEPARATE_ZVAL(ppzTmp);
575     convert_to_long_ex(ppzTmp);
576     gids[ i ] = Z_LVAL_PP(ppzTmp);
577     }
578     zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
579     }
580    
581     zCriteria_t zcri(zcriteria);
582     result = zcri.getResult();
583     if ( RES_OK == result ){
584     result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
585     if ( RES_OK == result ){
586     delete[] gids;
587     freeResult( groups );
588     }
589     }
590     groupsToZval( groups, groupsLen, zgroups );
591     RETURN_LONG(result);
592     }
593    
594    
595     // int vp_is_moderator(string uname)
596     ZEND_FUNCTION(vp_is_moderator)
597     {
598     long vpSessionID;
599     userid_t uid;
600    
601     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
602     &vpSessionID, &uid) == FAILURE) {
603     return;
604     }
605    
606     bool result = isModerator( (sessionid_t)vpSessionID, uid );
607     RETURN_BOOL(result)
608     }
609    
610     // int vp_get_uid(string uname)
611     ZEND_FUNCTION(vp_get_uid)
612     {
613     char *uname;
614     int unameLen;
615     userid_t uid;
616    
617     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
618     &uname, &unameLen) == FAILURE) {
619     return;
620     }
621    
622     string strUname( uname, unameLen );
623     result_t result = getUid( strUname.c_str(), &uid );
624     if ( result == RES_OK ){
625     RETURN_LONG((long)uid);
626     }
627     else {
628     //zend_printf( "vpal_debug: vp_get_uid(%s): result=%d<br>\n", strUname.c_str(),(int)result );
629     RETURN_FALSE
630     }
631 aga 1.2 }
632    
633 aga 1.4 /** session ?? zval
634     */
635     result_t sessionToZval( const session_t *pSession, zval *z )
636     {
637     string sessionID(unsignedIntToString(pSession->getSessionID()));
638     add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
639    
640     string date(unsignedIntToString((unsigned int)pSession->getDate()));
641     add_assoc_string(z, "date", (char *)date.c_str(), 1);
642    
643     string userID(unsignedIntToString((unsigned int)pSession->getUserID()));
644     add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
645    
646     return RES_OK;
647     }
648    
649 aga 1.2 ZEND_FUNCTION(vp_test_criteria)
650     {
651     zval *z;
652    
653     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
654     &z) == FAILURE) {
655     return;
656     }
657     zend_printf("zend_printf...<br>\n");
658     zCriteria_t zcri(z);
659     zcri.dump();
660     RETURN_FALSE
661     }
662    
663     ZEND_FUNCTION(vp_test_uids)
664     {
665     zval *z;
666    
667     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
668     &z) == FAILURE) {
669     return;
670     }
671     zend_printf("zend_printf...<br>\n");
672     zUIDs_t zuids(z);
673     zuids.dump();
674     RETURN_FALSE
675     }
676    
677    
678    
679 aga 1.4 /** DB??・膓????????≪??・膓?筝???・膓???????????????<br>
680     int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
681 aga 1.2 @param host ?ョ????????ユ????ULL
682 aga 1.1 @param user DB?ョ????????若?九???????ユ????ULL
683     @param password DB?ョ????????鴻???若???????ユ????ULL
684 aga 1.2 @param dbname DB?ョ?????B???????ユ????quot;"
685     @param prefix XOOPS DB ??refix??
686 aga 1.1 @return 0 success <br>
687     */
688     ZEND_FUNCTION(vp_initialize_db)
689     {
690     zval **parameters[5];
691     char *host;
692     char *user;
693 aga 1.2 char *password;
694     char *dbname;
695     char *prefix;
696 aga 1.1
697     /* get the number of arguments */
698     int argNum = ZEND_NUM_ARGS();
699     if (argNum > 5)
700     WRONG_PARAM_COUNT;
701    
702     /* argument count is correct, now retrieve arguments */
703     if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
704     WRONG_PARAM_COUNT;
705    
706 aga 1.2 if (argNum < 1) host = NULL;
707 aga 1.1 else host = getZvalString( parameters[0] );
708    
709     if (argNum < 2) user = NULL;
710     else user = getZvalString( parameters[1] );
711    
712 aga 1.2 if (argNum < 3) password = NULL;
713     else password = getZvalString( parameters[2] );
714 aga 1.1
715 aga 1.2 if (argNum < 4) dbname = "";
716     else dbname = getZvalString( parameters[3] );
717 aga 1.1
718 aga 1.2 if (argNum < 5) prefix = "";
719     else prefix = getZvalString( parameters[4] );
720 aga 1.1
721 aga 1.2 result_t result = initializeDB( host, user, password, dbname, prefix );
722 aga 1.1
723 aga 1.2 RETURN_LONG(result);
724 aga 1.1 }
725    
726 aga 1.4 /** ???違?ゃ?潟??????<br>
727     int vp_login_user(string uname, string password)
728     @param uname ???若?九??(xoops_users.uname)
729     @param password ???鴻???若??(md5(password)=xoops_users.pass)
730     @return 0 success
731     */
732 aga 1.1 ZEND_FUNCTION(vp_login_user)
733     {
734     char *uname;
735     int unameLen;
736     char *passwd;
737     int passwdLen;
738    
739     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
740     &uname, &unameLen, &passwd, &passwdLen) == FAILURE) {
741     return;
742     }
743    
744 aga 1.4 sessionid_t vpSessionID;
745 aga 1.5 result_t result = loginUser( uname, passwd, &vpSessionID );
746 aga 1.2 if ( result == RES_OK ){
747 aga 1.4 RETURN_LONG((long)vpSessionID);
748 aga 1.2 }
749     else {
750     //zend_printf( "vpal_debug: vp_login_user(%s, %s): cannot login. result=%d<br>\n", strUname.c_str(), strPasswd.c_str(), (int)result );
751     RETURN_FALSE
752     }
753 aga 1.1 }
754    
755 aga 1.4 /** ???違?≪??????????<br>
756     void vp_logout_user(int vp_session_id)
757     @param vp_session_id vp??essionid
758     @return ????
759     */
760 aga 1.1 ZEND_FUNCTION(vp_logout_user)
761     {
762 aga 1.4 long vpSessionID;
763 aga 1.1
764 aga 1.4 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &vpSessionID) == FAILURE) {
765 aga 1.1 return;
766     }
767 aga 1.4 logoutUser( (sessionid_t)vpSessionID );
768 aga 1.1
769     RETURN_NULL();
770     }
771    
772 aga 1.4 /** vp ? session id 篏???<br>
773     int vp_create_session( string xoops_sess_id, int uid, string remote_host )
774     @param xoops_sess_id xoops??ession id
775     @param uid xoops ? uid (xoops_users.uid)
776     @return FALSE篁ュ?: vp ? session id
777     @return FALSE: 紊掩??
778     */
779 aga 1.2 ZEND_FUNCTION(vp_create_session)
780     {
781     char *xoopsSessionID;
782     int xoopsSessionIDLen;
783 aga 1.5 long uid;
784 aga 1.2
785 aga 1.3 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",
786     &xoopsSessionID, &xoopsSessionIDLen, &uid) == FAILURE) {
787 aga 1.2 return;
788     }
789    
790 aga 1.4 sessionid_t vpSessionID = 0;
791     result_t result = createSession( xoopsSessionID, (userid_t)uid, &vpSessionID );
792     if ( result == RES_OK ){
793     RETURN_LONG((long)vpSessionID);
794     }
795     else {
796     RETURN_FALSE;
797     }
798     }
799    
800     /** vp ? session ???膣井???宴??緇???<br>
801     int vp_get_session( int vp_session_id, array session_info )
802     @param vp_session_id vp ? session id
803     @param session_info 腟?????????????????
804     @return 0 success
805     */
806     ZEND_FUNCTION(vp_get_session)
807     {
808     long vpSessionID;
809     zval *sessionInfo;
810     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
811     &vpSessionID, &sessionInfo) == FAILURE) {
812     return;
813     }
814     const session_t *session = 0;
815     result_t result = getSession( (sessionid_t)vpSessionID, &session );
816     if ( result == RES_OK ){
817     sessionToZval( session, sessionInfo );
818     freeResult( session );
819     }
820 aga 1.2
821 aga 1.4 RETURN_LONG((long)result);
822 aga 1.2 }
823 aga 1.1
824 aga 1.5 /** activate?倶?? ??緇?<br>
825     bool vp_is_activated( int vp_session_id, int user_id )
826     @param vp_session_id vp ? session id
827     @param user_id xoops_users.uid
828     @return 0 success
829     */
830 aga 1.2 ZEND_FUNCTION(vp_is_activated)
831     {
832     long sid, uid;
833    
834 aga 1.5 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
835 aga 1.2 return;
836     }
837    
838     bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
839    
840     RETURN_BOOL(result);
841     }
842 aga 1.1
843 aga 1.5 /** activate??????<br>
844     bool vp_activate( int vp_session_id, bool activated )
845     @param vp_session_id vp ? session id
846     @param user_id xoops_users.uid
847     @param activated true:activate, false:inactivate
848     @return 0 success
849     */
850 aga 1.2 ZEND_FUNCTION(vp_activate)
851     {
852     long sid, uid;
853     bool activated;
854    
855     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
856     &sid, &uid, &activated) == FAILURE) {
857     return;
858     }
859    
860     result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
861    
862     RETURN_LONG(result);
863     }
864 aga 1.1
865 aga 1.5 /** vp???≪?????潟???違??緇?????<br>
866     int vp_get_account_count( int vp_session_id )
867     @param vp_session_id vp ? session id
868     @return 0 success
869     */
870 aga 1.2 ZEND_FUNCTION(vp_get_account_count)
871     {
872     long sid;
873    
874     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
875     &sid) == FAILURE) {
876     return;
877     }
878    
879     long count = getAccountCount( (sessionid_t)sid );
880    
881     RETURN_LONG(count);
882     }
883 aga 1.1
884 aga 1.5 /** ?≪?????潟???????ゃ??????<br>
885     bool vp_delete_account( int vp_session_id, int user_id )
886     @param vp_session_id vp ? session id
887     @param user_id xoops_users.uid
888     @return 0 success
889     */
890 aga 1.2 ZEND_FUNCTION(vp_delete_account)
891     {
892     long sid, uid;
893    
894     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
895     &sid, &uid) == FAILURE) {
896     return;
897     }
898    
899     result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
900    
901     RETURN_LONG(result);
902     }
903 aga 1.1
904 aga 1.5 /** ?≪?????潟?????宴??緇?????<br>
905     int vp_get_account( int vp_session_id, int user_id, array account_info )
906     @param vp_session_id vp ? session id
907     @param user_id xoops_users.uid
908     @param account_info ?≪?????潟?????宴???????????f?渇????
909     @return 0 success
910     */
911 aga 1.2 ZEND_FUNCTION(vp_get_account)
912     {
913     long sid, uid;
914     zval *zaccount;
915    
916     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
917     &sid, &uid, &zaccount) == FAILURE) {
918 youi 1.6 fprintf( stderr, "error occured " );
919 aga 1.2 return;
920     }
921    
922     const account_t *paccount;
923     result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
924     if ( RES_OK == result ){
925     accountToZval( paccount, zaccount );
926     freeResult( paccount );
927     }
928    
929     RETURN_LONG(result);
930     }
931 aga 1.1
932 aga 1.5 /** ?>散????眼?????≪?????潟???????宴??緇?????<br>
933     int vp_get_accoutns( int sid, array uids, array criteria, array accounts );
934     @param vp_session_id vp ? session id
935     @param user_id xoops_users.uid
936     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
937     @param account_info ?≪?????潟?????宴???????????f?渇????
938     @return 0 success
939     */
940 aga 1.2 ZEND_FUNCTION(vp_get_accounts)
941     {
942     result_t result;
943     long sid;
944     zval *zuids;
945     zval *zcriteria;
946     zval *zaccount;
947    
948     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
949     &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
950     return;
951     }
952    
953     zCriteria_t zcri(zcriteria);
954     result = zcri.getResult();
955     if ( RES_OK == result ){
956     zUIDs_t zUIDs(zuids);
957     result = zUIDs.getResult();
958     if ( RES_OK == result ){
959     const account_t *paccounts;
960     int accountLen;
961     result = getAccounts( (sessionid_t)sid,
962     zUIDs.getPUID(), zUIDs.getLen(),
963     &zcri, &paccounts, &accountLen );
964     if ( RES_OK == result ){
965     accountsToZval( paccounts, accountLen, zaccount );
966     freeResult( paccounts );
967     }
968     }
969     }
970    
971     RETURN_LONG(result);
972     }
973 aga 1.1
974 aga 1.5 /** ?≪?????潟?????宴??緇?????<br>
975     int vp_insert_account( int sid, array account_info );
976     @param vp_session_id vp ? session id
977     @param user_id xoops_users.uid
978     @param account_info ?≪?????潟?????宴???????????f?渇????
979     @return 0 success
980     */
981 aga 1.2 ZEND_FUNCTION(vp_insert_account)
982     {
983     result_t result;
984     long sid;
985     zval *zaccount;
986    
987     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
988     &sid, &zaccount) == FAILURE) {
989     return;
990     }
991    
992     zAccount_t zacc(zaccount);
993     result = zacc.getResult();
994     if ( RES_OK == result ){
995     result = insertAccount( (sessionid_t)sid, &zacc );
996     }
997    
998     RETURN_LONG(result);
999     }
1000 aga 1.1
1001 aga 1.5 /** ?≪?????潟?????宴???贋?違??????<br>
1002     int vp_update_account( int sid, array account );
1003     @param vp_session_id vp ? session id
1004     @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
1005     @return 0 success
1006     */
1007 aga 1.2 ZEND_FUNCTION(vp_update_account)
1008     {
1009     result_t result;
1010     long sid;
1011     zval *zaccount;
1012    
1013     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1014     &sid, &zaccount) == FAILURE) {
1015     return;
1016     }
1017    
1018     zAccount_t zacc(zaccount);
1019     result = zacc.getResult();
1020     if ( RES_OK == result ){
1021     result = updateAccount( (sessionid_t)sid, &zacc );
1022     }
1023    
1024     RETURN_LONG(result);
1025     }
1026 aga 1.1
1027 aga 1.5 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
1028     int vp_dump_uids( int vp_session_id, array criteria, array uids );
1029     @param vp_session_id vp ? session id
1030     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1031     @param uids uid??????????????
1032     @return 0 success
1033     */
1034 aga 1.2 ZEND_FUNCTION(vp_dump_uids)
1035     {
1036     result_t result;
1037     long sid;
1038     zval *zcriteria;
1039     zval *zuids;
1040    
1041     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1042     &sid, &zcriteria, &zuids) == FAILURE) {
1043     return;
1044     }
1045    
1046     zCriteria_t zcri(zcriteria);
1047     result = zcri.getResult();
1048     if ( RES_OK == result ){
1049     userid_t *puid;
1050     int uidLen;
1051     result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1052     if ( RES_OK == result ){
1053     uidsToZval( puid, uidLen, &zuids );
1054     freeResult( puid );
1055     }
1056     }
1057    
1058     RETURN_LONG(result);
1059     }
1060 aga 1.1
1061 aga 1.5 /** VP???違???若?????違??緇???<br>
1062     int vp_get_group_count( int sid );
1063     @param vp_session_id vp ? session id
1064     @return ?違???若????/span>
1065     */
1066 aga 1.2 ZEND_FUNCTION(vp_get_group_count)
1067 aga 1.1 {
1068 aga 1.2 result_t result;
1069     long sid;
1070    
1071     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1072     &sid) == FAILURE) {
1073     return;
1074     }
1075    
1076     int count = getGroupCount( (sessionid_t)sid );
1077    
1078     RETURN_LONG(count);
1079     }
1080 aga 1.1
1081 aga 1.5 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
1082     int vp_get_group_by_uid( int sid, int uid, array criteria, array gids );
1083     @param vp_session_id vp ? session id
1084     @param user_id xoops_users.uid
1085     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1086     @param gids gid??????????????
1087     @return 0 success
1088     */
1089 aga 1.2 ZEND_FUNCTION(vp_get_groups_by_uid)
1090     {
1091     result_t result;
1092     long sid, uid;
1093     zval *zcriteria;
1094     zval *zgids;
1095    
1096     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1097     &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1098     return;
1099 aga 1.1 }
1100    
1101 aga 1.2 zCriteria_t zcri(zcriteria);
1102     result = zcri.getResult();
1103     if ( RES_OK == result ){
1104     groupid_t *pgids;
1105     int gidLen;
1106     result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1107     if ( RES_OK == result ){
1108     gidsToZval( pgids, gidLen, &zgids );
1109     freeResult( pgids );
1110     }
1111 aga 1.1 }
1112    
1113 aga 1.2 RETURN_LONG(result);
1114     }
1115    
1116    
1117 aga 1.5
1118     /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
1119     int vp_is_group_admin( int sid, int gid, int uid );
1120     @param vp_session_id vp ? session id
1121     @param group_id VP???違???若??ID
1122     @param user_id xoops_users.uid
1123     @return true: ?違???若??膊∞?????с??????
1124     @return false: ?違???若??膊∞?????с???????????????????若?с??????
1125     */
1126 aga 1.2 ZEND_FUNCTION(vp_is_group_admin)
1127     {
1128     result_t result;
1129     long sid, gid, uid;
1130    
1131     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1132     &sid, &gid, &uid) == FAILURE) {
1133     return;
1134 aga 1.1 }
1135    
1136 aga 1.2 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1137 aga 1.1
1138 aga 1.2 RETURN_BOOL(b);
1139     }
1140    
1141 aga 1.5 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
1142     int vp_dump_gids( int sid, array criteria, array gids );
1143     @param vp_session_id vp ? session id
1144     @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1145     @param gids gid??????????????
1146     @return 0 success
1147     */
1148 aga 1.2 ZEND_FUNCTION(vp_dump_gids)
1149     {
1150     result_t result;
1151     long sid;
1152     zval *zcriteria;
1153     zval *zgids;
1154    
1155     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1156     &sid, &zcriteria, &zgids) == FAILURE) {
1157     return;
1158     }
1159 aga 1.1
1160 aga 1.2 zCriteria_t zcri(zcriteria);
1161     result = zcri.getResult();
1162     if ( RES_OK == result ){
1163     groupid_t *pgid;
1164     int gidLen;
1165     result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1166     if ( RES_OK == result ){
1167     gidsToZval( pgid, gidLen, &zgids );
1168     freeResult( pgid );
1169 aga 1.1 }
1170     }
1171    
1172 aga 1.2 RETURN_LONG(result);
1173 aga 1.1 }

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