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.3 - (hide annotations) (download) (as text)
Tue Nov 30 05:46:32 2004 UTC (19 years, 4 months ago) by aga
Branch: MAIN
Changes since 1.2: +4 -18 lines
File MIME type: text/x-c++src
・sessionからremoteHostを削除.

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     //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????C????絖?????緇?????
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????int??緇?????
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????????
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**????criteria_t?????????????????????鴻??????紊掩??????getResult()!=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     ); ??????就???f?渇????
173     */
174     class zCriteria_t : public criteria {
175     private:
176     result_t result;
177     public:
178     // pz: array('name'=>'timestamp','name'=>'1')
179     // ????????orderby??篏???????申????
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**????(userid_t *puid,int uidLen)?????????????????????鴻??????紊掩??????getResult()!=RES_OK
307     uids : array( '1', '3', '4', '6', ... ); ??????就??????
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??????????????????
337     zend_hash_*???????ャ?<?潟???c????????????????鐚?
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 ????/span>
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: ????????????????
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??・膓????????≪??・膓?筝???・膓???????????????
470 aga 1.2 @param host ?ョ????????ユ????ULL
471 aga 1.1 @param user DB?ョ????????若?九???????ユ????ULL
472     @param password DB?ョ????????鴻???若???????ユ????ULL
473 aga 1.2 @param dbname DB?ョ?????B???????ユ????quot;"
474     @param prefix XOOPS DB ??refix??
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.3 // int vp_create_session( string xoops_sess_id, int uid )
557 aga 1.2 ZEND_FUNCTION(vp_create_session)
558     {
559     char *xoopsSessionID;
560     int xoopsSessionIDLen;
561     long sid, uid;
562    
563 aga 1.3 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",
564     &xoopsSessionID, &xoopsSessionIDLen, &uid) == FAILURE) {
565 aga 1.2 return;
566     }
567    
568     sessionid_t vpsid;
569 aga 1.3 result_t result = createSession( xoopsSessionID, (sessionid_t)sid, &vpsid );
570 aga 1.2
571     RETURN_LONG((long)vpsid);
572     }
573 aga 1.1
574 aga 1.2 ZEND_FUNCTION(vp_is_activated)
575     {
576     long sid, uid;
577    
578     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
579     &sid, &uid) == FAILURE) {
580     return;
581     }
582    
583     bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
584    
585     RETURN_BOOL(result);
586     }
587 aga 1.1
588 aga 1.2 ZEND_FUNCTION(vp_activate)
589     {
590     long sid, uid;
591     bool activated;
592    
593     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
594     &sid, &uid, &activated) == FAILURE) {
595     return;
596     }
597    
598     result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
599    
600     RETURN_LONG(result);
601     }
602 aga 1.1
603 aga 1.2 ZEND_FUNCTION(vp_get_account_count)
604     {
605     long sid;
606    
607     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
608     &sid) == FAILURE) {
609     return;
610     }
611    
612     long count = getAccountCount( (sessionid_t)sid );
613    
614     RETURN_LONG(count);
615     }
616 aga 1.1
617 aga 1.2 ZEND_FUNCTION(vp_delete_account)
618     {
619     long sid, uid;
620    
621     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
622     &sid, &uid) == FAILURE) {
623     return;
624     }
625    
626     result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
627    
628     RETURN_LONG(result);
629     }
630 aga 1.1
631 aga 1.2 // int vp_get_account( int sid, int uid, array account )
632     ZEND_FUNCTION(vp_get_account)
633     {
634     long sid, uid;
635     zval *zaccount;
636    
637     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
638     &sid, &uid, &zaccount) == FAILURE) {
639     return;
640     }
641    
642     const account_t *paccount;
643     result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
644     if ( RES_OK == result ){
645     accountToZval( paccount, zaccount );
646     freeResult( paccount );
647     }
648    
649     RETURN_LONG(result);
650     }
651 aga 1.1
652 aga 1.2 // int vp_get_accoutns( int sid, array uids, array criteria, array accounts );
653     ZEND_FUNCTION(vp_get_accounts)
654     {
655     result_t result;
656     long sid;
657     zval *zuids;
658     zval *zcriteria;
659     zval *zaccount;
660    
661     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
662     &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
663     return;
664     }
665    
666     zCriteria_t zcri(zcriteria);
667     result = zcri.getResult();
668     if ( RES_OK == result ){
669     zUIDs_t zUIDs(zuids);
670     result = zUIDs.getResult();
671     if ( RES_OK == result ){
672     const account_t *paccounts;
673     int accountLen;
674     result = getAccounts( (sessionid_t)sid,
675     zUIDs.getPUID(), zUIDs.getLen(),
676     &zcri, &paccounts, &accountLen );
677     if ( RES_OK == result ){
678     accountsToZval( paccounts, accountLen, zaccount );
679     freeResult( paccounts );
680     }
681     }
682     }
683    
684     RETURN_LONG(result);
685     }
686 aga 1.1
687 aga 1.2 // int vp_insert_account( int sid, array account );
688     ZEND_FUNCTION(vp_insert_account)
689     {
690     result_t result;
691     long sid;
692     zval *zaccount;
693    
694     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
695     &sid, &zaccount) == FAILURE) {
696     return;
697     }
698    
699     zAccount_t zacc(zaccount);
700     result = zacc.getResult();
701     if ( RES_OK == result ){
702     result = insertAccount( (sessionid_t)sid, &zacc );
703     }
704    
705     RETURN_LONG(result);
706     }
707 aga 1.1
708 aga 1.2 // int vp_update_account( int sid, array account );
709     ZEND_FUNCTION(vp_update_account)
710     {
711     result_t result;
712     long sid;
713     zval *zaccount;
714    
715     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
716     &sid, &zaccount) == FAILURE) {
717     return;
718     }
719    
720     zAccount_t zacc(zaccount);
721     result = zacc.getResult();
722     if ( RES_OK == result ){
723     result = updateAccount( (sessionid_t)sid, &zacc );
724     }
725    
726     RETURN_LONG(result);
727     }
728 aga 1.1
729 aga 1.2 // int vp_dump_uids( int sid, array criteria, array uids );
730     ZEND_FUNCTION(vp_dump_uids)
731     {
732     result_t result;
733     long sid;
734     zval *zcriteria;
735     zval *zuids;
736    
737     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
738     &sid, &zcriteria, &zuids) == FAILURE) {
739     return;
740     }
741    
742     zCriteria_t zcri(zcriteria);
743     result = zcri.getResult();
744     if ( RES_OK == result ){
745     userid_t *puid;
746     int uidLen;
747     result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
748     if ( RES_OK == result ){
749     uidsToZval( puid, uidLen, &zuids );
750     freeResult( puid );
751     }
752     }
753    
754     RETURN_LONG(result);
755     }
756 aga 1.1
757 aga 1.2 // int vp_get_group_count( int sid );
758     ZEND_FUNCTION(vp_get_group_count)
759 aga 1.1 {
760 aga 1.2 result_t result;
761     long sid;
762    
763     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
764     &sid) == FAILURE) {
765     return;
766     }
767    
768     int count = getGroupCount( (sessionid_t)sid );
769    
770     RETURN_LONG(count);
771     }
772 aga 1.1
773 aga 1.2 // int vp_get_group_by_uid( int sid, int uid, array criteria, array gids );
774     ZEND_FUNCTION(vp_get_groups_by_uid)
775     {
776     result_t result;
777     long sid, uid;
778     zval *zcriteria;
779     zval *zgids;
780    
781     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
782     &sid, &uid, &zcriteria, &zgids) == FAILURE) {
783     return;
784 aga 1.1 }
785    
786 aga 1.2 zCriteria_t zcri(zcriteria);
787     result = zcri.getResult();
788     if ( RES_OK == result ){
789     groupid_t *pgids;
790     int gidLen;
791     result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
792     if ( RES_OK == result ){
793     gidsToZval( pgids, gidLen, &zgids );
794     freeResult( pgids );
795     }
796 aga 1.1 }
797    
798 aga 1.2 RETURN_LONG(result);
799     }
800    
801    
802     // int vp_is_group_admin( int sid, int gid, int uid );
803     ZEND_FUNCTION(vp_is_group_admin)
804     {
805     result_t result;
806     long sid, gid, uid;
807    
808     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
809     &sid, &gid, &uid) == FAILURE) {
810     return;
811 aga 1.1 }
812    
813 aga 1.2 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
814 aga 1.1
815 aga 1.2 RETURN_BOOL(b);
816     }
817    
818     // int vp_dump_gids( int sid, array criteria, array gids );
819     ZEND_FUNCTION(vp_dump_gids)
820     {
821     result_t result;
822     long sid;
823     zval *zcriteria;
824     zval *zgids;
825    
826     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
827     &sid, &zcriteria, &zgids) == FAILURE) {
828     return;
829     }
830 aga 1.1
831 aga 1.2 zCriteria_t zcri(zcriteria);
832     result = zcri.getResult();
833     if ( RES_OK == result ){
834     groupid_t *pgid;
835     int gidLen;
836     result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
837     if ( RES_OK == result ){
838     gidsToZval( pgid, gidLen, &zgids );
839     freeResult( pgid );
840 aga 1.1 }
841     }
842    
843 aga 1.2 RETURN_LONG(result);
844 aga 1.1 }

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