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.2 - (hide annotations) (download) (as text)
Tue Nov 30 01:31:56 2004 UTC (19 years, 4 months ago) by aga
Branch: MAIN
Changes since 1.1: +705 -94 lines
File MIME type: text/x-c++src
。ヲvp_login_user, vp_logout_user、ハ、ノコ?ョ.

1 aga 1.1 /*
2     VPAL: Visiome Platform Abstract Layer
3    
4     zend_parse_parameters縺ッphp4.1.0縺悟ソ?ヲ?/span>
5     .so繝輔ぃ繧、繝ォ縺ッ螟悶°繧芽ヲ九∴縺ェ縺??エ謇?縺ォ鄂ョ縺上∋縺阪??/span>
6     C++縺ァ縺ッ縲‘xtern "C"{}, BEGIN/END_EXTERN_C()縺悟ソ?ヲ√??/span>
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     //ZEND_FUNCTION(vp_create_session );
35     ZEND_FUNCTION(vp_is_activated );
36     ZEND_FUNCTION(vp_activate );
37     ZEND_FUNCTION(vp_get_account_count );
38     ZEND_FUNCTION(vp_delete_account );
39     ZEND_FUNCTION(vp_get_account );
40     ZEND_FUNCTION(vp_get_accounts );
41     ZEND_FUNCTION(vp_insert_account );
42     ZEND_FUNCTION(vp_update_account );
43     ZEND_FUNCTION(vp_dump_uids );
44     ZEND_FUNCTION(vp_get_group_count );
45     ZEND_FUNCTION(vp_get_groups_by_uid );
46     ZEND_FUNCTION(vp_is_group_admin );
47     ZEND_FUNCTION(vp_dump_gids );
48     /*
49     ZEND_FUNCTION(vp_dump_group_admins );
50     ZEND_FUNCTION(vp_delete_member );
51     ZEND_FUNCTION(vp_insert_member );
52     ZEND_FUNCTION(vp_get_members );
53     ZEND_FUNCTION(vp_delete_group );
54     ZEND_FUNCTION(vp_insert_group );
55     ZEND_FUNCTION(vp_update_group );
56     ZEND_FUNCTION(vp_get_group );
57     ZEND_FUNCTION(vp_get_groups );
58     ZEND_FUNCTION(vp_is_moderator );
59     ZEND_FUNCTION(vp_get_uid );
60     */
61    
62     ZEND_FUNCTION(vp_test_criteria );
63     ZEND_FUNCTION(vp_test_uids );
64 aga 1.1 };
65     /* compiled function list so Zend knows what's in this module */
66     zend_function_entry vpalmod_functions[] =
67     {
68 aga 1.2 ZEND_FE(first_module ,NULL)
69     ZEND_FE(vp_initialize_db ,NULL)
70     ZEND_FE(vp_login_user ,NULL)
71     ZEND_FE(vp_logout_user ,NULL)
72     // ZEND_FE(vp_create_session ,NULL)
73     ZEND_FE(vp_is_activated ,NULL)
74     ZEND_FE(vp_activate ,NULL)
75     ZEND_FE(vp_get_account_count ,NULL)
76     ZEND_FE(vp_delete_account ,NULL)
77     ZEND_FE(vp_get_account ,NULL)
78     ZEND_FE(vp_get_accounts ,NULL)
79     ZEND_FE(vp_insert_account ,NULL)
80     ZEND_FE(vp_update_account ,NULL)
81     ZEND_FE(vp_dump_uids ,NULL)
82     ZEND_FE(vp_get_group_count ,NULL)
83     ZEND_FE(vp_get_groups_by_uid ,NULL)
84     ZEND_FE(vp_is_group_admin ,NULL)
85     ZEND_FE(vp_dump_gids ,NULL)
86     /*
87     ZEND_FE(vp_dump_group_admins ,NULL)
88     ZEND_FE(vp_delete_member ,NULL)
89     ZEND_FE(vp_insert_member ,NULL)
90     ZEND_FE(vp_get_members ,NULL)
91     ZEND_FE(vp_delete_group ,NULL)
92     ZEND_FE(vp_insert_group ,NULL)
93     ZEND_FE(vp_update_group ,NULL)
94     ZEND_FE(vp_get_group ,NULL)
95     ZEND_FE(vp_get_groups ,NULL)
96     ZEND_FE(vp_is_moderator ,NULL)
97     ZEND_FE(vp_get_uid ,NULL)
98     */
99     ZEND_FE(vp_test_criteria ,NULL)
100     ZEND_FE(vp_test_uids ,NULL)
101 aga 1.1 {NULL, NULL, NULL}
102     };
103    
104     /* compiled module information */
105     zend_module_entry vpalmod_module_entry =
106     {
107     STANDARD_MODULE_HEADER,
108     "Visiome Platform Abstract Layer",
109     vpalmod_functions,
110     NULL,
111     NULL,
112     NULL,
113     NULL,
114     NULL,
115     NO_VERSION_YET,
116     STANDARD_MODULE_PROPERTIES
117     };
118    
119     /* implement standard "stub" routine to introduce ourselves to Zend */
120     #if COMPILE_DL_FIRST_MODULE
121     BEGIN_EXTERN_C()
122     ZEND_GET_MODULE(vpalmod)
123     END_EXTERN_C()
124     #endif
125    
126     /* implement function that is meant to be made available to PHP */
127     ZEND_FUNCTION(first_module)
128     {
129     long parameter;
130     // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
131     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
132     return;
133     }
134     parameter++;
135     RETURN_LONG(parameter);
136     }
137     /** zval縺九iC縺ョ譁?ュ怜?繧貞セ励k縲?/span>
138     */
139     char *getZvalString( zval **p ){
140     convert_to_string_ex(p);
141     return Z_STRVAL_PP(p); //(**p).value.str.val;
142     }
143    
144     /** zval縺九iint繧貞セ励k縲?/span>
145     */
146     int getZvalInt( zval **p ){
147     convert_to_long_ex(p);
148     return Z_LVAL_PP(p); // (int)(**p).value.lval;
149     }
150    
151 aga 1.2 // keylen縺ッ譛ォ蟆セ縺ョ\0繧貞性繧?縲?/span>
152     static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
153     zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
154     if ( res == HASH_KEY_IS_STRING ){
155     char *p = new char[keyLen+1];
156     memcpy( p, key, keyLen );
157     p[keyLen] = 0;
158     zend_printf( " key is string[%s]<br>\n", p );
159     }
160     else {
161     zend_printf( " key is integer[%d]<br>\n", index );
162     }
163     }
164    
165    
166     /** zval**縺九icriteria_t繧堤函謌舌☆繧九◆繧√?繧ッ繝ゥ繧ケ縲ら函謌仙、ア謨励↑繧曳etResult()!=RES_OK
167     * criteria :
168     array( 'start'=>0, 'rows'=>10,
169     'orders'=>array(
170     array('name'=>'id','order'=>'0'),
171     array('name'=>'timestamp','name'=>'1'), ...)
172     ); 縺薙s縺ェ蠖「縺ョ騾」諠ウ驟榊?
173     */
174     class zCriteria_t : public criteria {
175     private:
176     result_t result;
177     public:
178     // pz: array('name'=>'timestamp','name'=>'1')
179     // 縺薙l縺九iorderby繧剃ス懈?縺励※霑ス蜉?縲?/span>
180     void setOrder( zval *pz ){
181     char *column = 0;
182     order_t order = (order_t)0;
183    
184     HashPosition pos;
185     zval **ppzTmp = 0;
186     int res2;
187     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
188     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
189     char *key = 0;
190     uint keyLen = 0;
191     ulong index = 0;
192     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
193     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
194     print_hash_key( keyType, key, keyLen, index );
195     if ( strncasecmp( key, "column", keyLen ) == 0 && keyLen == 7 ){
196     SEPARATE_ZVAL(ppzTmp);
197     column = getZvalString(ppzTmp);
198     // zend_printf( "column=%s<br>\n", column );
199     }
200     else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
201     SEPARATE_ZVAL(ppzTmp);
202     order = (order_t)getZvalInt(ppzTmp);
203     // zend_printf( "order=%d<br>\n", order );
204     }
205     }
206    
207     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
208     }
209     if ( column ){
210     orderby *o = new orderby( column, order );
211     addOrderBy( o );
212     }
213    
214     result = RES_OK;
215     }
216    
217     // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
218     void setOrders( zval *pz ){
219     HashPosition pos;
220    
221     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
222    
223     zval **ppzTmp = 0;
224     int res2;
225     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
226     char *key = 0;
227     uint keyLen = 0;
228     ulong index = 0;
229     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
230     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
231     print_hash_key( keyType, key, keyLen, index );
232     setOrder( *ppzTmp );
233     }
234     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
235     }
236     result = RES_OK;
237     }
238    
239     void initialize( zval *pz ){
240     HashPosition pos;
241     zval **ppzTmp = 0;
242     int res2;
243     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
244     while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
245     char *key = 0;
246     uint keyLen = 0;
247     ulong index = 0;
248     int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
249     if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
250     print_hash_key( keyType, key, keyLen, index );
251     if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
252     SEPARATE_ZVAL(ppzTmp);
253     int tmp = getZvalInt(ppzTmp);
254     // zend_printf( "start=%d<br>\n", tmp );
255     setLimit( tmp, getLimitRows() );
256     }
257     else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
258     SEPARATE_ZVAL(ppzTmp);
259     int tmp = getZvalInt(ppzTmp);
260     // zend_printf( "rows=%d<br>\n", tmp );
261     setLimit( getLimitStart(), tmp );
262     }
263     else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
264     setOrders( *ppzTmp );
265     }
266     else
267     ; // ignore unknown key
268     }
269     else
270     ; // ignore bad key
271     zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
272     }
273     result = RES_OK;
274     }
275     zCriteria_t() : criteria(){ result = RES_ERROR; }
276     zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
277     zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
278     result_t getResult(){ return result; };
279    
280     void dump(){
281     zend_printf( "dumping zCriteria...<br>\n" );
282     zend_printf( "result=%d<br>\n", (int)result );
283     zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() );
284     const orderby *p = headOrderBy();
285     while ( p ){
286     zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() );
287     p = nextOrderBy();
288     }
289     }
290     };
291    
292    
293     class zAccount_t : public account {
294     private:
295     result_t result;
296     public:
297     void initialize(zval *pz){
298     ; // todo
299     }
300     zAccount_t() : account(){ result = RES_ERROR; }
301     zAccount_t( zval *pz ) : account(){ initialize(pz); }
302     zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
303     result_t getResult(){ return result; };
304     };
305    
306     /** zval**縺九i(userid_t *puid,int uidLen)繧堤函謌舌☆繧九◆繧√?繧ッ繝ゥ繧ケ縲ら函謌仙、ア謨励↑繧曳etResult()!=RES_OK
307     uids : array( '1', '3', '4', '6', ... ); 縺薙s縺ェ蠖「縺ョ驟榊?
308     */
309     class zUIDs_t {
310     private:
311     result_t result;
312     userid_t *pUID;
313     int len;
314     public:
315     zUIDs_t(){
316     pUID = 0;
317     len = 0;
318     result = RES_ERROR;
319     }
320    
321     zUIDs_t( zval *pza ){
322     pUID = 0;
323     len = 0;
324     result = RES_ERROR;
325    
326     if ( Z_TYPE_P(pza) != IS_ARRAY ){
327     result = RES_ERROR;
328     }
329     else {
330     len = zend_hash_num_elements(Z_ARRVAL_P(pza));
331     if(len == 0) {
332     pUID = new userid_t[1];
333     result = RES_OK;
334     }
335     else {
336     /* php/ext/standard/string.c 縺ョ implode縺ョ縺ゅ◆繧翫r蜿り??↓縲?/span>
337     zend_hash_*縺ョ繝峨く繝・繝。繝ウ繝医▲縺ヲ縺ゅk縺ョ縺?繧阪≧縺具シ?/span>
338     */
339     zval **tmp;
340     HashPosition pos;
341     int i = 0;
342     pUID = new userid_t[len];
343    
344     zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
345     while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
346     SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html 蜿ら?
347     convert_to_long_ex(tmp);
348     if ( i < len )
349     pUID[i++] = Z_LVAL_PP(tmp);
350     zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
351     }
352     len = i;
353     result = RES_OK;
354     }
355     }
356     }
357    
358     ~zUIDs_t(){
359     if ( pUID ) delete[] pUID;
360     }
361     result_t getResult(){ return result; }
362     userid_t *getPUID(){ return pUID; }
363     int getLen(){ return len; }
364     void dump(){
365     zend_printf( "dumping zUIDs...<br>\n" );
366     zend_printf( "result=%d<br>\n", (int)result );
367     zend_printf( "len=%d<br>\n", len );
368     for ( int i = 0; i < len; i++ ){
369     zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
370     }
371     }
372     };
373    
374     /** uids_t 竊 zval
375     */
376     result_t uidsToZval( userid_t *pUID, int len, zval **ppz ){
377     zval *pz;
378    
379     // create new array
380     MAKE_STD_ZVAL(pz);
381     array_init(pz);
382    
383     // add UIDs
384     for ( int i = 0; i < len; i++ ){
385     add_next_index_long(pz, (long)(pUID[i]) );
386     }
387    
388     // return array
389     *ppz = pz;
390     return RES_OK;
391     }
392     /** uids_t 竊 zval
393     */
394     result_t gidsToZval( groupid_t *pGID, int len, zval **ppz ){
395     zval *pz;
396    
397     // create new array
398     MAKE_STD_ZVAL(pz);
399     array_init(pz);
400    
401     // add GIDs
402     for ( int i = 0; i < len; i++ ){
403     add_next_index_long(pz, (long)(pGID[i]) );
404     }
405    
406     // return array
407     *ppz = pz;
408     return RES_OK;
409     }
410    
411     /** accounts 竊 zval
412     * accounts: 縺薙s縺ェ諢溘§縺ョ驟榊?
413     array(
414     array(
415     'uid'=>100,
416     'activate'=>1,
417     'institute'=>'foo',
418     'tel'=>'123-456-789',
419     ...
420     ),
421     ...
422     )
423     */
424     result_t accountsToZval( const account_t *pAccounts, int accountLen, zval *z ){
425     return RES_ERROR;
426     }
427    
428     result_t accountToZval( const account_t *pAccount, zval *z ){
429     return RES_ERROR;
430     }
431    
432     /** groups 竊 zval
433     */
434     result_t groupsToZval( const group_t *pGroups, int groupLen, zval *z ){
435    
436     return RES_ERROR;
437     }
438    
439     ZEND_FUNCTION(vp_test_criteria)
440     {
441     zval *z;
442    
443     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
444     &z) == FAILURE) {
445     return;
446     }
447     zend_printf("zend_printf...<br>\n");
448     zCriteria_t zcri(z);
449     zcri.dump();
450     RETURN_FALSE
451     }
452    
453     ZEND_FUNCTION(vp_test_uids)
454     {
455     zval *z;
456    
457     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
458     &z) == FAILURE) {
459     return;
460     }
461     zend_printf("zend_printf...<br>\n");
462     zUIDs_t zuids(z);
463     zuids.dump();
464     RETURN_FALSE
465     }
466    
467    
468    
469 aga 1.1 /** DB縺ォ謗・邯壹☆繧九?よ里縺ォ謗・邯壻クュ縺ョ謗・邯壹?髢峨§繧峨l繧九??/span>
470 aga 1.2 @param host 謗・邯壼?縲ら怐逡・譎ゅ?NULL
471 aga 1.1 @param user DB謗・邯壽凾縺ョ繝ヲ繝シ繧カ蜷阪?ら怐逡・譎ゅ?NULL
472     @param password DB謗・邯壽凾縺ョ繝代せ繝ッ繝シ繝峨?ら怐逡・譎ゅ?NULL
473 aga 1.2 @param dbname DB謗・邯壽凾縺ョDB蜷阪?ら怐逡・譎ゅ?""
474     @param prefix XOOPS DB 縺ョprefix縲?/span>
475 aga 1.1 @return 0 success <br>
476 aga 1.2 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
477 aga 1.1 */
478     ZEND_FUNCTION(vp_initialize_db)
479     {
480     zval **parameters[5];
481     char *host;
482     char *user;
483 aga 1.2 char *password;
484     char *dbname;
485     char *prefix;
486 aga 1.1
487     /* get the number of arguments */
488     int argNum = ZEND_NUM_ARGS();
489     if (argNum > 5)
490     WRONG_PARAM_COUNT;
491    
492     /* argument count is correct, now retrieve arguments */
493     if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
494     WRONG_PARAM_COUNT;
495    
496 aga 1.2 if (argNum < 1) host = NULL;
497 aga 1.1 else host = getZvalString( parameters[0] );
498    
499     if (argNum < 2) user = NULL;
500     else user = getZvalString( parameters[1] );
501    
502 aga 1.2 if (argNum < 3) password = NULL;
503     else password = getZvalString( parameters[2] );
504 aga 1.1
505 aga 1.2 if (argNum < 4) dbname = "";
506     else dbname = getZvalString( parameters[3] );
507 aga 1.1
508 aga 1.2 if (argNum < 5) prefix = "";
509     else prefix = getZvalString( parameters[4] );
510 aga 1.1
511 aga 1.2 result_t result = initializeDB( host, user, password, dbname, prefix );
512 aga 1.1
513 aga 1.2 RETURN_LONG(result);
514 aga 1.1 }
515    
516 aga 1.2 // int vp_login_user(string uname, string password)
517 aga 1.1 ZEND_FUNCTION(vp_login_user)
518     {
519     char *uname;
520     int unameLen;
521     char *passwd;
522     int passwdLen;
523    
524     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
525     &uname, &unameLen, &passwd, &passwdLen) == FAILURE) {
526     return;
527     }
528    
529 aga 1.2 string strUname( uname, unameLen );
530     string strPasswd( passwd, passwdLen );
531     sessionid_t vpsid;
532     result_t result = loginUser( strUname.c_str(), strPasswd.c_str(), &vpsid );
533     if ( result == RES_OK ){
534     RETURN_LONG((long)vpsid);
535     }
536     else {
537     //zend_printf( "vpal_debug: vp_login_user(%s, %s): cannot login. result=%d<br>\n", strUname.c_str(), strPasswd.c_str(), (int)result );
538     RETURN_FALSE
539     }
540 aga 1.1 }
541    
542 aga 1.2 // void vp_logout_user(int vpsid)
543 aga 1.1 ZEND_FUNCTION(vp_logout_user)
544     {
545     long sid;
546    
547     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid) == FAILURE) {
548     return;
549     }
550    
551 aga 1.2 logoutUser( (sessionid_t)sid );
552 aga 1.1
553     RETURN_NULL();
554     }
555    
556 aga 1.2 // int vp_create_session( string xoops_sess_id, int uid, string remoteHost )
557     ZEND_FUNCTION(vp_create_session)
558     {
559     char *xoopsSessionID;
560     int xoopsSessionIDLen;
561     long sid, uid;
562    
563     long lRemoteHost;
564     char *pcRemoteHost;
565     int cbRemoteHost;
566     struct in_addr inRemoteHost;
567    
568     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls",
569     &xoopsSessionID, &xoopsSessionIDLen, &uid,
570     &pcRemoteHost, &cbRemoteHost) == FAILURE) {
571     return;
572     }
573    
574     // "1.2.3.4" -> 0x01020304螟画鋤縲ゆク肴ュ」縺ェ譁?ュ怜?縺ェ繧?縺ィ縺ソ縺ェ縺吶?Jpv6譛ェ蟇セ蠢?/span>
575     string strRemoteHost( pcRemoteHost, cbRemoteHost );
576     if ( inet_aton( strRemoteHost.c_str(), &inRemoteHost ) != 0 )
577     memcpy( &lRemoteHost, &inRemoteHost, 4 );
578     else
579     lRemoteHost = 0;
580    
581     string strXoopsSessionID( xoopsSessionID, xoopsSessionIDLen );
582     sessionid_t vpsid;
583     result_t result = createSession( strXoopsSessionID.c_str(), (sessionid_t)sid, (userid_t)uid, &vpsid );
584    
585     RETURN_LONG((long)vpsid);
586     }
587 aga 1.1
588 aga 1.2 ZEND_FUNCTION(vp_is_activated)
589     {
590     long sid, uid;
591    
592     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
593     &sid, &uid) == FAILURE) {
594     return;
595     }
596    
597     bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
598    
599     RETURN_BOOL(result);
600     }
601 aga 1.1
602 aga 1.2 ZEND_FUNCTION(vp_activate)
603     {
604     long sid, uid;
605     bool activated;
606    
607     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
608     &sid, &uid, &activated) == FAILURE) {
609     return;
610     }
611    
612     result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
613    
614     RETURN_LONG(result);
615     }
616 aga 1.1
617 aga 1.2 ZEND_FUNCTION(vp_get_account_count)
618     {
619     long sid;
620    
621     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
622     &sid) == FAILURE) {
623     return;
624     }
625    
626     long count = getAccountCount( (sessionid_t)sid );
627    
628     RETURN_LONG(count);
629     }
630 aga 1.1
631 aga 1.2 ZEND_FUNCTION(vp_delete_account)
632     {
633     long sid, uid;
634    
635     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
636     &sid, &uid) == FAILURE) {
637     return;
638     }
639    
640     result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
641    
642     RETURN_LONG(result);
643     }
644 aga 1.1
645 aga 1.2 // int vp_get_account( int sid, int uid, array account )
646     ZEND_FUNCTION(vp_get_account)
647     {
648     long sid, uid;
649     zval *zaccount;
650    
651     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
652     &sid, &uid, &zaccount) == FAILURE) {
653     return;
654     }
655    
656     const account_t *paccount;
657     result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
658     if ( RES_OK == result ){
659     accountToZval( paccount, zaccount );
660     freeResult( paccount );
661     }
662    
663     RETURN_LONG(result);
664     }
665 aga 1.1
666 aga 1.2 // int vp_get_accoutns( int sid, array uids, array criteria, array accounts );
667     ZEND_FUNCTION(vp_get_accounts)
668     {
669     result_t result;
670     long sid;
671     zval *zuids;
672     zval *zcriteria;
673     zval *zaccount;
674    
675     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
676     &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
677     return;
678     }
679    
680     zCriteria_t zcri(zcriteria);
681     result = zcri.getResult();
682     if ( RES_OK == result ){
683     zUIDs_t zUIDs(zuids);
684     result = zUIDs.getResult();
685     if ( RES_OK == result ){
686     const account_t *paccounts;
687     int accountLen;
688     result = getAccounts( (sessionid_t)sid,
689     zUIDs.getPUID(), zUIDs.getLen(),
690     &zcri, &paccounts, &accountLen );
691     if ( RES_OK == result ){
692     accountsToZval( paccounts, accountLen, zaccount );
693     freeResult( paccounts );
694     }
695     }
696     }
697    
698     RETURN_LONG(result);
699     }
700 aga 1.1
701 aga 1.2 // int vp_insert_account( int sid, array account );
702     ZEND_FUNCTION(vp_insert_account)
703     {
704     result_t result;
705     long sid;
706     zval *zaccount;
707    
708     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
709     &sid, &zaccount) == FAILURE) {
710     return;
711     }
712    
713     zAccount_t zacc(zaccount);
714     result = zacc.getResult();
715     if ( RES_OK == result ){
716     result = insertAccount( (sessionid_t)sid, &zacc );
717     }
718    
719     RETURN_LONG(result);
720     }
721 aga 1.1
722 aga 1.2 // int vp_update_account( int sid, array account );
723     ZEND_FUNCTION(vp_update_account)
724     {
725     result_t result;
726     long sid;
727     zval *zaccount;
728    
729     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
730     &sid, &zaccount) == FAILURE) {
731     return;
732     }
733    
734     zAccount_t zacc(zaccount);
735     result = zacc.getResult();
736     if ( RES_OK == result ){
737     result = updateAccount( (sessionid_t)sid, &zacc );
738     }
739    
740     RETURN_LONG(result);
741     }
742 aga 1.1
743 aga 1.2 // int vp_dump_uids( int sid, array criteria, array uids );
744     ZEND_FUNCTION(vp_dump_uids)
745     {
746     result_t result;
747     long sid;
748     zval *zcriteria;
749     zval *zuids;
750    
751     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
752     &sid, &zcriteria, &zuids) == FAILURE) {
753     return;
754     }
755    
756     zCriteria_t zcri(zcriteria);
757     result = zcri.getResult();
758     if ( RES_OK == result ){
759     userid_t *puid;
760     int uidLen;
761     result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
762     if ( RES_OK == result ){
763     uidsToZval( puid, uidLen, &zuids );
764     freeResult( puid );
765     }
766     }
767    
768     RETURN_LONG(result);
769     }
770 aga 1.1
771 aga 1.2 // int vp_get_group_count( int sid );
772     ZEND_FUNCTION(vp_get_group_count)
773 aga 1.1 {
774 aga 1.2 result_t result;
775     long sid;
776    
777     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
778     &sid) == FAILURE) {
779     return;
780     }
781    
782     int count = getGroupCount( (sessionid_t)sid );
783    
784     RETURN_LONG(count);
785     }
786 aga 1.1
787 aga 1.2 // int vp_get_group_by_uid( int sid, int uid, array criteria, array gids );
788     ZEND_FUNCTION(vp_get_groups_by_uid)
789     {
790     result_t result;
791     long sid, uid;
792     zval *zcriteria;
793     zval *zgids;
794    
795     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
796     &sid, &uid, &zcriteria, &zgids) == FAILURE) {
797     return;
798 aga 1.1 }
799    
800 aga 1.2 zCriteria_t zcri(zcriteria);
801     result = zcri.getResult();
802     if ( RES_OK == result ){
803     groupid_t *pgids;
804     int gidLen;
805     result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
806     if ( RES_OK == result ){
807     gidsToZval( pgids, gidLen, &zgids );
808     freeResult( pgids );
809     }
810 aga 1.1 }
811    
812 aga 1.2 RETURN_LONG(result);
813     }
814    
815    
816     // int vp_is_group_admin( int sid, int gid, int uid );
817     ZEND_FUNCTION(vp_is_group_admin)
818     {
819     result_t result;
820     long sid, gid, uid;
821    
822     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
823     &sid, &gid, &uid) == FAILURE) {
824     return;
825 aga 1.1 }
826    
827 aga 1.2 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
828 aga 1.1
829 aga 1.2 RETURN_BOOL(b);
830     }
831    
832     // int vp_dump_gids( int sid, array criteria, array gids );
833     ZEND_FUNCTION(vp_dump_gids)
834     {
835     result_t result;
836     long sid;
837     zval *zcriteria;
838     zval *zgids;
839    
840     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
841     &sid, &zcriteria, &zgids) == FAILURE) {
842     return;
843     }
844 aga 1.1
845 aga 1.2 zCriteria_t zcri(zcriteria);
846     result = zcri.getResult();
847     if ( RES_OK == result ){
848     groupid_t *pgid;
849     int gidLen;
850     result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
851     if ( RES_OK == result ){
852     gidsToZval( pgid, gidLen, &zgids );
853     freeResult( pgid );
854 aga 1.1 }
855     }
856    
857 aga 1.2 RETURN_LONG(result);
858 aga 1.1 }

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