Develop and Download Open Source Software

Browse CVS Repository

Contents of /xoonips/AL/xnpal.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Tue Nov 30 09:49:49 2004 UTC (19 years, 4 months ago) by aga
Branch: MAIN
Changes since 1.4: +91 -16 lines
File MIME type: text/x-c++src
・関数のコメントつけ.

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 #include "criteria.h"
12 #include "common.h"
13 #include "commonal.h"
14 #include "session.h"
15 #include "group.h"
16 #include "account.h"
17 #include "vpal.h"
18
19 // for inet_aton
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
23
24 // global variables
25 MYSQL *mysql = NULL;
26
27
28 /* declaration of functions to be exported */
29 extern "C" {
30 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_get_session );
36 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 ZEND_FUNCTION(vp_get_group );
58 ZEND_FUNCTION(vp_get_groups );
59 ZEND_FUNCTION(vp_is_moderator );
60 ZEND_FUNCTION(vp_get_uid );
61 */
62
63 ZEND_FUNCTION(vp_test_criteria );
64 ZEND_FUNCTION(vp_test_uids );
65 };
66 /* compiled function list so Zend knows what's in this module */
67 zend_function_entry vpalmod_functions[] =
68 {
69 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 ZEND_FE(vp_create_session ,NULL)
74 ZEND_FE(vp_get_session ,NULL)
75 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 ZEND_FE(vp_get_group ,NULL)
97 ZEND_FE(vp_get_groups ,NULL)
98 ZEND_FE(vp_is_moderator ,NULL)
99 ZEND_FE(vp_get_uid ,NULL)
100 */
101 ZEND_FE(vp_test_criteria ,NULL)
102 ZEND_FE(vp_test_uids ,NULL)
103 {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 // 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 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
379 {
380 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 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
398 {
399 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 /** accounts ?? zval
416 * accounts: ????????????????
417 array(
418 array(
419 'uid'=>100,
420 'activate'=>1,
421 'institute'=>'foo',
422 'tel'=>'123-456-789',
423 ...
424 ),
425 ...
426 )
427 */
428 result_t accountsToZval( const account_t *pAccounts, int accountLen, zval *z )
429 {
430 return RES_ERROR;
431 }
432
433 result_t accountToZval( const account_t *pAccount, zval *z )
434 {
435 return RES_ERROR;
436 }
437
438 /** groups ?? zval
439 */
440 result_t groupsToZval( const group_t *pGroups, int groupLen, zval *z )
441 {
442
443 return RES_ERROR;
444 }
445
446 /** session ?? zval
447 */
448 result_t sessionToZval( const session_t *pSession, zval *z )
449 {
450 string sessionID(unsignedIntToString(pSession->getSessionID()));
451 add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
452
453 string date(unsignedIntToString((unsigned int)pSession->getDate()));
454 add_assoc_string(z, "date", (char *)date.c_str(), 1);
455
456 string userID(unsignedIntToString((unsigned int)pSession->getUserID()));
457 add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
458
459 return RES_OK;
460 }
461
462 ZEND_FUNCTION(vp_test_criteria)
463 {
464 zval *z;
465
466 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
467 &z) == FAILURE) {
468 return;
469 }
470 zend_printf("zend_printf...<br>\n");
471 zCriteria_t zcri(z);
472 zcri.dump();
473 RETURN_FALSE
474 }
475
476 ZEND_FUNCTION(vp_test_uids)
477 {
478 zval *z;
479
480 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
481 &z) == FAILURE) {
482 return;
483 }
484 zend_printf("zend_printf...<br>\n");
485 zUIDs_t zuids(z);
486 zuids.dump();
487 RETURN_FALSE
488 }
489
490
491
492 /** DB??・膓????????≪??・膓?筝???・膓???????????????<br>
493 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
494 @param host ?ョ????????ユ????ULL
495 @param user DB?ョ????????若?九???????ユ????ULL
496 @param password DB?ョ????????鴻???若???????ユ????ULL
497 @param dbname DB?ョ?????B???????ユ????quot;"
498 @param prefix XOOPS DB ??refix??
499 @return 0 success <br>
500 */
501 ZEND_FUNCTION(vp_initialize_db)
502 {
503 zval **parameters[5];
504 char *host;
505 char *user;
506 char *password;
507 char *dbname;
508 char *prefix;
509
510 /* get the number of arguments */
511 int argNum = ZEND_NUM_ARGS();
512 if (argNum > 5)
513 WRONG_PARAM_COUNT;
514
515 /* argument count is correct, now retrieve arguments */
516 if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
517 WRONG_PARAM_COUNT;
518
519 if (argNum < 1) host = NULL;
520 else host = getZvalString( parameters[0] );
521
522 if (argNum < 2) user = NULL;
523 else user = getZvalString( parameters[1] );
524
525 if (argNum < 3) password = NULL;
526 else password = getZvalString( parameters[2] );
527
528 if (argNum < 4) dbname = "";
529 else dbname = getZvalString( parameters[3] );
530
531 if (argNum < 5) prefix = "";
532 else prefix = getZvalString( parameters[4] );
533
534 result_t result = initializeDB( host, user, password, dbname, prefix );
535
536 RETURN_LONG(result);
537 }
538
539 /** ???違?ゃ?潟??????<br>
540 int vp_login_user(string uname, string password)
541 @param uname ???若?九??(xoops_users.uname)
542 @param password ???鴻???若??(md5(password)=xoops_users.pass)
543 @return 0 success
544 */
545 ZEND_FUNCTION(vp_login_user)
546 {
547 char *uname;
548 int unameLen;
549 char *passwd;
550 int passwdLen;
551
552 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
553 &uname, &unameLen, &passwd, &passwdLen) == FAILURE) {
554 return;
555 }
556
557 sessionid_t vpSessionID;
558 result_t result = loginUser( uname, passwd, &vpSessionID );
559 if ( result == RES_OK ){
560 RETURN_LONG((long)vpSessionID);
561 }
562 else {
563 //zend_printf( "vpal_debug: vp_login_user(%s, %s): cannot login. result=%d<br>\n", strUname.c_str(), strPasswd.c_str(), (int)result );
564 RETURN_FALSE
565 }
566 }
567
568 /** ???違?≪??????????<br>
569 void vp_logout_user(int vp_session_id)
570 @param vp_session_id vp??essionid
571 @return ????
572 */
573 ZEND_FUNCTION(vp_logout_user)
574 {
575 long vpSessionID;
576
577 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &vpSessionID) == FAILURE) {
578 return;
579 }
580 logoutUser( (sessionid_t)vpSessionID );
581
582 RETURN_NULL();
583 }
584
585 /** vp ? session id 篏???<br>
586 int vp_create_session( string xoops_sess_id, int uid, string remote_host )
587 @param xoops_sess_id xoops??ession id
588 @param uid xoops ? uid (xoops_users.uid)
589 @return FALSE篁ュ?: vp ? session id
590 @return FALSE: 紊掩??
591 */
592 ZEND_FUNCTION(vp_create_session)
593 {
594 char *xoopsSessionID;
595 int xoopsSessionIDLen;
596 long uid;
597
598 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",
599 &xoopsSessionID, &xoopsSessionIDLen, &uid) == FAILURE) {
600 return;
601 }
602
603 sessionid_t vpSessionID = 0;
604 result_t result = createSession( xoopsSessionID, (userid_t)uid, &vpSessionID );
605 if ( result == RES_OK ){
606 RETURN_LONG((long)vpSessionID);
607 }
608 else {
609 RETURN_FALSE;
610 }
611 }
612
613 /** vp ? session ???膣井???宴??緇???<br>
614 int vp_get_session( int vp_session_id, array session_info )
615 @param vp_session_id vp ? session id
616 @param session_info 腟?????????????????
617 @return 0 success
618 */
619 ZEND_FUNCTION(vp_get_session)
620 {
621 long vpSessionID;
622 zval *sessionInfo;
623 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
624 &vpSessionID, &sessionInfo) == FAILURE) {
625 return;
626 }
627 const session_t *session = 0;
628 result_t result = getSession( (sessionid_t)vpSessionID, &session );
629 if ( result == RES_OK ){
630 sessionToZval( session, sessionInfo );
631 freeResult( session );
632 }
633
634 RETURN_LONG((long)result);
635 }
636
637 /** activate?倶?? ??緇?<br>
638 bool vp_is_activated( int vp_session_id, int user_id )
639 @param vp_session_id vp ? session id
640 @param user_id xoops_users.uid
641 @return 0 success
642 */
643 ZEND_FUNCTION(vp_is_activated)
644 {
645 long sid, uid;
646
647 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
648 return;
649 }
650
651 bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
652
653 RETURN_BOOL(result);
654 }
655
656 /** activate??????<br>
657 bool vp_activate( int vp_session_id, bool activated )
658 @param vp_session_id vp ? session id
659 @param user_id xoops_users.uid
660 @param activated true:activate, false:inactivate
661 @return 0 success
662 */
663 ZEND_FUNCTION(vp_activate)
664 {
665 long sid, uid;
666 bool activated;
667
668 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
669 &sid, &uid, &activated) == FAILURE) {
670 return;
671 }
672
673 result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
674
675 RETURN_LONG(result);
676 }
677
678 /** vp???≪?????潟???違??緇?????<br>
679 int vp_get_account_count( int vp_session_id )
680 @param vp_session_id vp ? session id
681 @return 0 success
682 */
683 ZEND_FUNCTION(vp_get_account_count)
684 {
685 long sid;
686
687 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
688 &sid) == FAILURE) {
689 return;
690 }
691
692 long count = getAccountCount( (sessionid_t)sid );
693
694 RETURN_LONG(count);
695 }
696
697 /** ?≪?????潟???????ゃ??????<br>
698 bool vp_delete_account( int vp_session_id, int user_id )
699 @param vp_session_id vp ? session id
700 @param user_id xoops_users.uid
701 @return 0 success
702 */
703 ZEND_FUNCTION(vp_delete_account)
704 {
705 long sid, uid;
706
707 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
708 &sid, &uid) == FAILURE) {
709 return;
710 }
711
712 result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
713
714 RETURN_LONG(result);
715 }
716
717 /** ?≪?????潟?????宴??緇?????<br>
718 int vp_get_account( int vp_session_id, int user_id, array account_info )
719 @param vp_session_id vp ? session id
720 @param user_id xoops_users.uid
721 @param account_info ?≪?????潟?????宴???????????f?渇????
722 @return 0 success
723 */
724 ZEND_FUNCTION(vp_get_account)
725 {
726 long sid, uid;
727 zval *zaccount;
728
729 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
730 &sid, &uid, &zaccount) == FAILURE) {
731 return;
732 }
733
734 const account_t *paccount;
735 result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
736 if ( RES_OK == result ){
737 accountToZval( paccount, zaccount );
738 freeResult( paccount );
739 }
740
741 RETURN_LONG(result);
742 }
743
744 /** ?>散????眼?????≪?????潟???????宴??緇?????<br>
745 int vp_get_accoutns( int sid, array uids, array criteria, array accounts );
746 @param vp_session_id vp ? session id
747 @param user_id xoops_users.uid
748 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
749 @param account_info ?≪?????潟?????宴???????????f?渇????
750 @return 0 success
751 */
752 ZEND_FUNCTION(vp_get_accounts)
753 {
754 result_t result;
755 long sid;
756 zval *zuids;
757 zval *zcriteria;
758 zval *zaccount;
759
760 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
761 &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
762 return;
763 }
764
765 zCriteria_t zcri(zcriteria);
766 result = zcri.getResult();
767 if ( RES_OK == result ){
768 zUIDs_t zUIDs(zuids);
769 result = zUIDs.getResult();
770 if ( RES_OK == result ){
771 const account_t *paccounts;
772 int accountLen;
773 result = getAccounts( (sessionid_t)sid,
774 zUIDs.getPUID(), zUIDs.getLen(),
775 &zcri, &paccounts, &accountLen );
776 if ( RES_OK == result ){
777 accountsToZval( paccounts, accountLen, zaccount );
778 freeResult( paccounts );
779 }
780 }
781 }
782
783 RETURN_LONG(result);
784 }
785
786 /** ?≪?????潟?????宴??緇?????<br>
787 int vp_insert_account( int sid, array account_info );
788 @param vp_session_id vp ? session id
789 @param user_id xoops_users.uid
790 @param account_info ?≪?????潟?????宴???????????f?渇????
791 @return 0 success
792 */
793 ZEND_FUNCTION(vp_insert_account)
794 {
795 result_t result;
796 long sid;
797 zval *zaccount;
798
799 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
800 &sid, &zaccount) == FAILURE) {
801 return;
802 }
803
804 zAccount_t zacc(zaccount);
805 result = zacc.getResult();
806 if ( RES_OK == result ){
807 result = insertAccount( (sessionid_t)sid, &zacc );
808 }
809
810 RETURN_LONG(result);
811 }
812
813 /** ?≪?????潟?????宴???贋?違??????<br>
814 int vp_update_account( int sid, array account );
815 @param vp_session_id vp ? session id
816 @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
817 @return 0 success
818 */
819 ZEND_FUNCTION(vp_update_account)
820 {
821 result_t result;
822 long sid;
823 zval *zaccount;
824
825 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
826 &sid, &zaccount) == FAILURE) {
827 return;
828 }
829
830 zAccount_t zacc(zaccount);
831 result = zacc.getResult();
832 if ( RES_OK == result ){
833 result = updateAccount( (sessionid_t)sid, &zacc );
834 }
835
836 RETURN_LONG(result);
837 }
838
839 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
840 int vp_dump_uids( int vp_session_id, array criteria, array uids );
841 @param vp_session_id vp ? session id
842 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
843 @param uids uid??????????????
844 @return 0 success
845 */
846 ZEND_FUNCTION(vp_dump_uids)
847 {
848 result_t result;
849 long sid;
850 zval *zcriteria;
851 zval *zuids;
852
853 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
854 &sid, &zcriteria, &zuids) == FAILURE) {
855 return;
856 }
857
858 zCriteria_t zcri(zcriteria);
859 result = zcri.getResult();
860 if ( RES_OK == result ){
861 userid_t *puid;
862 int uidLen;
863 result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
864 if ( RES_OK == result ){
865 uidsToZval( puid, uidLen, &zuids );
866 freeResult( puid );
867 }
868 }
869
870 RETURN_LONG(result);
871 }
872
873 /** VP???違???若?????違??緇???<br>
874 int vp_get_group_count( int sid );
875 @param vp_session_id vp ? session id
876 @return ?違???若????/span>
877 */
878 ZEND_FUNCTION(vp_get_group_count)
879 {
880 result_t result;
881 long sid;
882
883 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
884 &sid) == FAILURE) {
885 return;
886 }
887
888 int count = getGroupCount( (sessionid_t)sid );
889
890 RETURN_LONG(count);
891 }
892
893 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
894 int vp_get_group_by_uid( int sid, int uid, array criteria, array gids );
895 @param vp_session_id vp ? session id
896 @param user_id xoops_users.uid
897 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
898 @param gids gid??????????????
899 @return 0 success
900 */
901 ZEND_FUNCTION(vp_get_groups_by_uid)
902 {
903 result_t result;
904 long sid, uid;
905 zval *zcriteria;
906 zval *zgids;
907
908 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
909 &sid, &uid, &zcriteria, &zgids) == FAILURE) {
910 return;
911 }
912
913 zCriteria_t zcri(zcriteria);
914 result = zcri.getResult();
915 if ( RES_OK == result ){
916 groupid_t *pgids;
917 int gidLen;
918 result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
919 if ( RES_OK == result ){
920 gidsToZval( pgids, gidLen, &zgids );
921 freeResult( pgids );
922 }
923 }
924
925 RETURN_LONG(result);
926 }
927
928
929
930 /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
931 int vp_is_group_admin( int sid, int gid, int uid );
932 @param vp_session_id vp ? session id
933 @param group_id VP???違???若??ID
934 @param user_id xoops_users.uid
935 @return true: ?違???若??膊∞?????с??????
936 @return false: ?違???若??膊∞?????с???????????????????若?с??????
937 */
938 ZEND_FUNCTION(vp_is_group_admin)
939 {
940 result_t result;
941 long sid, gid, uid;
942
943 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
944 &sid, &gid, &uid) == FAILURE) {
945 return;
946 }
947
948 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
949
950 RETURN_BOOL(b);
951 }
952
953 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
954 int vp_dump_gids( int sid, array criteria, array gids );
955 @param vp_session_id vp ? session id
956 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
957 @param gids gid??????????????
958 @return 0 success
959 */
960 ZEND_FUNCTION(vp_dump_gids)
961 {
962 result_t result;
963 long sid;
964 zval *zcriteria;
965 zval *zgids;
966
967 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
968 &sid, &zcriteria, &zgids) == FAILURE) {
969 return;
970 }
971
972 zCriteria_t zcri(zcriteria);
973 result = zcri.getResult();
974 if ( RES_OK == result ){
975 groupid_t *pgid;
976 int gidLen;
977 result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
978 if ( RES_OK == result ){
979 gidsToZval( pgid, gidLen, &zgids );
980 freeResult( pgid );
981 }
982 }
983
984 RETURN_LONG(result);
985 }

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