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.11 - (show annotations) (download) (as text)
Wed Dec 1 02:21:38 2004 UTC (19 years, 4 months ago) by aga
Branch: MAIN
Changes since 1.10: +79 -2 lines
File MIME type: text/x-c++src
。ヲvp_delete_member(), vp_insert_member(), vp_get_members()コ?ョ.

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 #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 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 /*
54 ZEND_FUNCTION(vp_delete_group );
55 ZEND_FUNCTION(vp_insert_group );
56 */
57 ZEND_FUNCTION(vp_update_group );
58 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_is_valid_session_id );
64 ZEND_FUNCTION(vp_get_last_error_string );
65
66 ZEND_FUNCTION(vp_test_criteria );
67 ZEND_FUNCTION(vp_test_uids );
68 };
69 /* compiled function list so Zend knows what's in this module */
70 zend_function_entry vpalmod_functions[] =
71 {
72 ZEND_FE(first_module ,NULL)
73 ZEND_FE(vp_initialize_db ,NULL)
74 ZEND_FE(vp_login_user ,NULL)
75 ZEND_FE(vp_logout_user ,NULL)
76 ZEND_FE(vp_create_session ,NULL)
77 ZEND_FE(vp_get_session ,NULL)
78 ZEND_FE(vp_is_activated ,NULL)
79 ZEND_FE(vp_activate ,NULL)
80 ZEND_FE(vp_get_account_count ,NULL)
81 ZEND_FE(vp_delete_account ,NULL)
82 ZEND_FE(vp_get_account ,NULL)
83 ZEND_FE(vp_get_accounts ,NULL)
84 ZEND_FE(vp_insert_account ,NULL)
85 ZEND_FE(vp_update_account ,NULL)
86 ZEND_FE(vp_dump_uids ,NULL)
87 ZEND_FE(vp_get_group_count ,NULL)
88 ZEND_FE(vp_get_groups_by_uid ,NULL)
89 ZEND_FE(vp_is_group_admin ,NULL)
90 ZEND_FE(vp_dump_gids ,NULL)
91 ZEND_FE(vp_dump_group_admins ,NULL)
92 ZEND_FE(vp_delete_member ,NULL)
93 ZEND_FE(vp_insert_member ,NULL)
94 ZEND_FE(vp_get_members ,NULL)
95 /*
96 ZEND_FE(vp_delete_group ,NULL)
97 ZEND_FE(vp_insert_group ,NULL)
98 */
99 ZEND_FE(vp_update_group ,NULL)
100 ZEND_FE(vp_get_group ,NULL)
101 ZEND_FE(vp_get_groups ,NULL)
102 ZEND_FE(vp_is_moderator ,NULL)
103 ZEND_FE(vp_get_uid ,NULL)
104 ZEND_FE(vp_is_valid_session_id ,NULL)
105 ZEND_FE(vp_get_last_error_string ,NULL)
106 ZEND_FE(vp_test_criteria ,NULL)
107 ZEND_FE(vp_test_uids ,NULL)
108 {NULL, NULL, NULL}
109 };
110
111 /* compiled module information */
112 zend_module_entry vpalmod_module_entry =
113 {
114 STANDARD_MODULE_HEADER,
115 "Visiome Platform Abstract Layer",
116 vpalmod_functions,
117 NULL,
118 NULL,
119 NULL,
120 NULL,
121 NULL,
122 NO_VERSION_YET,
123 STANDARD_MODULE_PROPERTIES
124 };
125
126 /* implement standard "stub" routine to introduce ourselves to Zend */
127 #if COMPILE_DL_FIRST_MODULE
128 BEGIN_EXTERN_C()
129 ZEND_GET_MODULE(vpalmod)
130 END_EXTERN_C()
131 #endif
132
133 /* implement function that is meant to be made available to PHP */
134 ZEND_FUNCTION(first_module)
135 {
136 long parameter;
137 // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
138 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
139 return;
140 }
141 parameter++;
142 RETURN_LONG(parameter);
143 }
144 /** zval縺九iC縺ョ譁?ュ怜?繧貞セ励k縲?/span>
145 */
146 char *getZvalString( zval **p ){
147 convert_to_string_ex(p);
148 return Z_STRVAL_PP(p); //(**p).value.str.val;
149 }
150
151 /** zval縺九iint繧貞セ励k縲?/span>
152 */
153 int getZvalInt( zval **p ){
154 convert_to_long_ex(p);
155 return Z_LVAL_PP(p); // (int)(**p).value.lval;
156 }
157
158 // keylen縺ッ譛ォ蟆セ縺ョ\0繧貞性繧?縲?/span>
159 static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
160 zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
161 if ( res == HASH_KEY_IS_STRING ){
162 char *p = new char[keyLen+1];
163 memcpy( p, key, keyLen );
164 p[keyLen] = 0;
165 zend_printf( " key is string[%s]<br>\n", p );
166 }
167 else {
168 zend_printf( " key is integer[%d]<br>\n", index );
169 }
170 }
171
172
173 /** zval**縺九icriteria_t繧堤函謌舌☆繧九◆繧√?繧ッ繝ゥ繧ケ縲ら函謌仙、ア謨励↑繧曳etResult()!=RES_OK
174 * criteria :
175 array( 'start'=>0, 'rows'=>10,
176 'orders'=>array(
177 array('name'=>'id','order'=>'0'),
178 array('name'=>'timestamp','name'=>'1'), ...)
179 ); 縺薙s縺ェ蠖「縺ョ騾」諠ウ驟榊?
180 */
181 class zCriteria_t : public criteria {
182 private:
183 result_t result;
184 public:
185 // pz: array('name'=>'timestamp','name'=>'1')
186 // 縺薙l縺九iorderby繧剃ス懈?縺励※霑ス蜉?縲?/span>
187 void setOrder( zval *pz ){
188 char *column = 0;
189 order_t order = (order_t)0;
190
191 HashPosition pos;
192 zval **ppzTmp = 0;
193 int res2;
194 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
195 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
196 char *key = 0;
197 uint keyLen = 0;
198 ulong index = 0;
199 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
200 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
201 print_hash_key( keyType, key, keyLen, index );
202 if ( strncasecmp( key, "column", keyLen ) == 0 && keyLen == 7 ){
203 SEPARATE_ZVAL(ppzTmp);
204 column = getZvalString(ppzTmp);
205 // zend_printf( "column=%s<br>\n", column );
206 }
207 else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
208 SEPARATE_ZVAL(ppzTmp);
209 order = (order_t)getZvalInt(ppzTmp);
210 // zend_printf( "order=%d<br>\n", order );
211 }
212 }
213
214 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
215 }
216 if ( column ){
217 orderby *o = new orderby( column, order );
218 addOrderBy( o );
219 }
220
221 result = RES_OK;
222 }
223
224 // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
225 void setOrders( zval *pz ){
226 HashPosition pos;
227
228 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
229
230 zval **ppzTmp = 0;
231 int res2;
232 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
233 char *key = 0;
234 uint keyLen = 0;
235 ulong index = 0;
236 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
237 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
238 print_hash_key( keyType, key, keyLen, index );
239 setOrder( *ppzTmp );
240 }
241 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
242 }
243 result = RES_OK;
244 }
245
246 void initialize( zval *pz ){
247 HashPosition pos;
248 zval **ppzTmp = 0;
249 int res2;
250 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
251 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
252 char *key = 0;
253 uint keyLen = 0;
254 ulong index = 0;
255 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
256 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
257 print_hash_key( keyType, key, keyLen, index );
258 if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
259 SEPARATE_ZVAL(ppzTmp);
260 int tmp = getZvalInt(ppzTmp);
261 // zend_printf( "start=%d<br>\n", tmp );
262 setLimit( tmp, getLimitRows() );
263 }
264 else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
265 SEPARATE_ZVAL(ppzTmp);
266 int tmp = getZvalInt(ppzTmp);
267 // zend_printf( "rows=%d<br>\n", tmp );
268 setLimit( getLimitStart(), tmp );
269 }
270 else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
271 setOrders( *ppzTmp );
272 }
273 else
274 ; // ignore unknown key
275 }
276 else
277 ; // ignore bad key
278 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
279 }
280 result = RES_OK;
281 }
282 zCriteria_t() : criteria(){ result = RES_ERROR; }
283 zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
284 zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
285 result_t getResult(){ return result; };
286
287 void dump(){
288 zend_printf( "dumping zCriteria...<br>\n" );
289 zend_printf( "result=%d<br>\n", (int)result );
290 zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() );
291 const orderby *p = headOrderBy();
292 while ( p ){
293 zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() );
294 p = nextOrderBy();
295 }
296 }
297 };
298
299
300 class zAccount_t : public account {
301 private:
302 result_t result;
303 public:
304 void initialize(zval *pz){
305 ; // todo
306 }
307 zAccount_t() : account(){ result = RES_ERROR; }
308 zAccount_t( zval *pz ) : account(){ initialize(pz); }
309 zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
310 result_t getResult(){ return result; };
311 };
312
313 /** zval**縺九i(userid_t *puid,int uidLen)繧堤函謌舌☆繧九◆繧√?繧ッ繝ゥ繧ケ縲ら函謌仙、ア謨励↑繧曳etResult()!=RES_OK
314 uids : array( '1', '3', '4', '6', ... ); 縺薙s縺ェ蠖「縺ョ驟榊?
315 */
316 class zUIDs_t {
317 private:
318 result_t result;
319 userid_t *pUID;
320 int len;
321 public:
322 zUIDs_t(){
323 pUID = 0;
324 len = 0;
325 result = RES_ERROR;
326 }
327
328 zUIDs_t( zval *pza ){
329 pUID = 0;
330 len = 0;
331 result = RES_ERROR;
332
333 if ( Z_TYPE_P(pza) != IS_ARRAY ){
334 result = RES_ERROR;
335 }
336 else {
337 len = zend_hash_num_elements(Z_ARRVAL_P(pza));
338 if(len == 0) {
339 pUID = new userid_t[1];
340 result = RES_OK;
341 }
342 else {
343 /* php/ext/standard/string.c 縺ョ implode縺ョ縺ゅ◆繧翫r蜿り??↓縲?/span>
344 zend_hash_*縺ョ繝峨く繝・繝。繝ウ繝医▲縺ヲ縺ゅk縺ョ縺?繧阪≧縺具シ?/span>
345 */
346 zval **tmp;
347 HashPosition pos;
348 int i = 0;
349 pUID = new userid_t[len];
350
351 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
352 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
353 SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html 蜿ら?
354 convert_to_long_ex(tmp);
355 if ( i < len )
356 pUID[i++] = Z_LVAL_PP(tmp);
357 zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
358 }
359 len = i;
360 result = RES_OK;
361 }
362 }
363 }
364
365 ~zUIDs_t(){
366 if ( pUID ) delete[] pUID;
367 }
368 result_t getResult(){ return result; }
369 userid_t *getPUID(){ return pUID; }
370 int getLen(){ return len; }
371 void dump(){
372 zend_printf( "dumping zUIDs...<br>\n" );
373 zend_printf( "result=%d<br>\n", (int)result );
374 zend_printf( "len=%d<br>\n", len );
375 for ( int i = 0; i < len; i++ ){
376 zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
377 }
378 }
379 };
380
381 /**
382 *
383 * uids_t縺ョ驟榊?繧単HP縺ョ驟榊?縺ォ螟画鋤縺吶k
384 *
385 * @param pUID 螟画鋤繧ゅ→縺ョuserid_t縺ョ驟榊?
386 * @param len pUID縺ョ驟榊?縺ョ髟キ縺?/span>
387 * @param pz 螟画鋤邨先棡繧呈嶌縺崎セシ繧?驟榊?(蛻晄悄蛹匁ク医∩縺ァ縺ゅk縺薙→)
388 * @return RES_OK
389 *
390 */
391 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
392 {
393 zend_hash_clean( Z_ARRVAL_PP(ppz) );
394
395 // add UIDs
396 for ( int i = 0; i < len; i++ ){
397 add_next_index_long(*ppz, (long)(pUID[i]) );
398 }
399
400 return RES_OK;
401 }
402 /** groupid_t 竊 zval
403 */
404 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
405 {
406 zend_hash_clean( Z_ARRVAL_PP(ppz) );
407
408 // add GIDs
409 for ( int i = 0; i < len; i++ ){
410 add_next_index_long(*ppz, (long)(pGID[i]) );
411 }
412
413 return RES_OK;
414 }
415
416 result_t accountToZval( const account_t *pAccount, zval *z )
417 {
418 zend_hash_clean( z -> value.ht );
419
420 add_assoc_long( z, "uid", pAccount -> getUID( ) );
421 add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
422 add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
423 add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
424 add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
425 add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
426 add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
427 add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
428 add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
429 add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
430 add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
431 add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
432 add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
433 add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
434 add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
435 add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
436 add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
437 add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
438 add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
439 add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
440 add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
441 add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
442 add_assoc_long( z, "level", pAccount -> getLevel( ) );
443 add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
444 add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
445 add_assoc_long( z, "posts", pAccount -> getPosts( ) );
446 add_assoc_long( z, "rank", pAccount -> getRank( ) );
447 add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
448 add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
449 add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
450 add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
451
452 add_assoc_long( z, "activate", pAccount -> getActivate( ) );
453 add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
454 add_assoc_string( z, "institute", ( char* )pAccount -> getInstitute( ), 1 );
455 add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
456 add_assoc_string( z, "organization", ( char* )pAccount -> getOrganization( ), 1 );
457 add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
458 add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
459 add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
460 add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
461 add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
462 add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
463 return RES_OK;
464 }
465
466 /** accounts 竊 zval
467 * accounts: 縺薙s縺ェ諢溘§縺ョ驟榊?
468 array(
469 array(
470 'uid'=>100,
471 'activate'=>1,
472 'institute'=>'foo',
473 'tel'=>'123-456-789',
474 ...
475 ),
476 ...
477 )
478 */
479 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
480 {
481 zend_hash_clean( z -> value.ht );
482 for( int i = 0; i < accountsLen; i++ ){
483 zval *new_array;
484 MAKE_STD_ZVAL(new_array);
485 if(array_init(new_array) != SUCCESS){
486 return RES_ERROR;
487 }
488 add_index_zval( z, i, new_array );
489 accountToZval( &pAccounts[ i ], new_array );
490 }
491 return RES_OK;
492 }
493
494 /** groups 竊 zval
495 */
496 result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
497 {
498 zend_hash_clean( z -> value.ht );
499 for( int i = 0; i < groupsLen; i++ ){
500 zval *new_array;
501 MAKE_STD_ZVAL(new_array);
502 if(array_init(new_array) != SUCCESS){
503 return RES_ERROR;
504 }
505 add_index_zval( z, i, new_array );
506 add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
507 add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
508 add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
509 }
510 return RES_OK;
511 }
512
513 /**
514 *
515 * group_t縺ョ蜀?ョケ繧単HP縺ョ騾」諠ウ驟榊?縺ォ螟画鋤縺吶k
516 *
517 * @param pGroup 螟画鋤繧ゅ→縺ョ繧ー繝ォ繝シ繝玲ュ蝣ア
518 * @param z 螟画鋤邨先棡繧呈嶌縺崎セシ繧?騾」諠ウ驟榊?(蛻晄悄蛹匁ク医∩縺ァ縺ゅk縺薙→)
519 * @return RES_OK
520 *
521 */
522 result_t groupToZval( const group_t *pGroup, zval *z )
523 {
524 zend_hash_clean( z -> value.ht );
525 add_assoc_long( z, "gid", pGroup -> getGID( ) );
526 add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
527 add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
528 return RES_OK;
529 }
530
531 /** zval 竊 group
532 */
533 result_t zvalToGroup( zval *z, group_t *pGroup )
534 {
535 zval **tmp;
536 HashPosition pos;
537 int i = 0;
538 char* key = 0;
539
540 key = "gid";
541 zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp );
542 convert_to_long_ex( tmp ) ;
543 pGroup -> setGID( (*tmp) -> value.lval );
544
545 key = "gname";
546 zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp );
547 convert_to_string_ex( tmp ) ;
548 pGroup -> setGname( (*tmp) -> value.str.val );
549
550 key = "gdesc";
551 zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp );
552 convert_to_string_ex( tmp ) ;
553 pGroup -> setDesc( (*tmp) -> value.str.val );
554
555 return RES_OK;
556 }
557
558
559 // int vp_get_group( int sid, int gid, array group );
560 ZEND_FUNCTION(vp_get_group)
561 {
562 long sid, gid;
563 zval *zgroup;
564
565 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
566 &sid, &gid, &zgroup) == FAILURE) {
567 return;
568 }
569
570 const group_t *pgroup;
571 result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
572 if ( RES_OK == result ){
573 groupToZval( pgroup, zgroup );
574 freeResult( pgroup );
575 }
576
577 RETURN_LONG(result);
578 }
579
580
581 // int vp_get_groups( int sid, array gids, array criteria, array groups );
582 ZEND_FUNCTION(vp_get_groups)
583 {
584 result_t result;
585 long sid, uid;
586 zval *zcriteria;
587 zval *zgids;
588 zval *zgroups;
589 zval **ppzTmp = 0;
590 HashPosition pos;
591 int res2;
592 int gidsLen;
593 const group_t* groups;
594 int groupsLen;
595
596 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
597 &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
598 return;
599 }
600
601 //gids縺ォ繧ー繝ォ繝シ繝悠D繧偵さ繝斐?縺吶k
602 gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
603 groupid_t *gids = new groupid_t[ gidsLen ];
604 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
605 for( int i = 0; i < gidsLen; i++ ){
606 if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
607 SEPARATE_ZVAL(ppzTmp);
608 convert_to_long_ex(ppzTmp);
609 gids[ i ] = Z_LVAL_PP(ppzTmp);
610 }
611 zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
612 }
613
614 zCriteria_t zcri(zcriteria);
615 result = zcri.getResult();
616 if ( RES_OK == result ){
617 result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
618 if ( RES_OK == result ){
619 delete[] gids;
620 freeResult( groups );
621 }
622 }
623 groupsToZval( groups, groupsLen, zgroups );
624 RETURN_LONG(result);
625 }
626
627
628 // int vp_is_moderator(string uname)
629 ZEND_FUNCTION(vp_is_moderator)
630 {
631 long vpSessionID;
632 userid_t uid;
633
634 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
635 &vpSessionID, &uid) == FAILURE) {
636 return;
637 }
638
639 bool result = isModerator( (sessionid_t)vpSessionID, uid );
640 RETURN_BOOL(result)
641 }
642
643 // int vp_get_uid(string uname)
644 ZEND_FUNCTION(vp_get_uid)
645 {
646 char *uname;
647 int unameLen;
648 userid_t uid;
649
650 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
651 &uname, &unameLen) == FAILURE) {
652 return;
653 }
654
655 string strUname( uname, unameLen );
656 result_t result = getUid( strUname.c_str(), &uid );
657 if ( result == RES_OK ){
658 RETURN_LONG((long)uid);
659 }
660 else {
661 //zend_printf( "vpal_debug: vp_get_uid(%s): result=%d<br>\n", strUname.c_str(),(int)result );
662 RETURN_FALSE
663 }
664 }
665
666 /** session 竊 zval
667 */
668 result_t sessionToZval( const session_t *pSession, zval *z )
669 {
670 string sessionID(unsignedIntToString(pSession->getSessionID()));
671 add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
672
673 string date(unsignedIntToString((unsigned int)pSession->getDate()));
674 add_assoc_string(z, "date", (char *)date.c_str(), 1);
675
676 string userID(unsignedIntToString((unsigned int)pSession->getUserID()));
677 add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
678
679 return RES_OK;
680 }
681
682 ZEND_FUNCTION(vp_test_criteria)
683 {
684 zval *z;
685
686 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
687 &z) == FAILURE) {
688 return;
689 }
690 zend_printf("zend_printf...<br>\n");
691 zCriteria_t zcri(z);
692 zcri.dump();
693 RETURN_FALSE
694 }
695
696 ZEND_FUNCTION(vp_test_uids)
697 {
698 zval *z;
699
700 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
701 &z) == FAILURE) {
702 return;
703 }
704 zend_printf("zend_printf...<br>\n");
705 zUIDs_t zuids(z);
706 zuids.dump();
707 RETURN_FALSE
708 }
709
710
711
712 /** DB縺ォ謗・邯壹☆繧九?よ里縺ォ謗・邯壻クュ縺ョ謗・邯壹?髢峨§繧峨l繧九??lt;br>
713 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
714 @param host 謗・邯壼?縲ら怐逡・譎ゅ?NULL
715 @param user DB謗・邯壽凾縺ョ繝ヲ繝シ繧カ蜷阪?ら怐逡・譎ゅ?NULL
716 @param password DB謗・邯壽凾縺ョ繝代せ繝ッ繝シ繝峨?ら怐逡・譎ゅ?NULL
717 @param dbname DB謗・邯壽凾縺ョDB蜷阪?ら怐逡・譎ゅ?""
718 @param prefix XOOPS DB 縺ョprefix縲?/span>
719 @return 0 success <br>
720 */
721 ZEND_FUNCTION(vp_initialize_db)
722 {
723 zval **parameters[5];
724 char *host;
725 char *user;
726 char *password;
727 char *dbname;
728 char *prefix;
729
730 /* get the number of arguments */
731 int argNum = ZEND_NUM_ARGS();
732 if (argNum > 5)
733 WRONG_PARAM_COUNT;
734
735 /* argument count is correct, now retrieve arguments */
736 if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
737 WRONG_PARAM_COUNT;
738
739 if (argNum < 1) host = NULL;
740 else host = getZvalString( parameters[0] );
741
742 if (argNum < 2) user = NULL;
743 else user = getZvalString( parameters[1] );
744
745 if (argNum < 3) password = NULL;
746 else password = getZvalString( parameters[2] );
747
748 if (argNum < 4) dbname = "";
749 else dbname = getZvalString( parameters[3] );
750
751 if (argNum < 5) prefix = "";
752 else prefix = getZvalString( parameters[4] );
753
754 result_t result = initializeDB( host, user, password, dbname, prefix );
755
756 RETURN_LONG(result);
757 }
758
759 /** 繝ュ繧ー繧、繝ウ縺吶k縲?lt;br>
760 int vp_login_user(string uname, string password)
761 @param uname 繝ヲ繝シ繧カ蜷?xoops_users.uname)
762 @param password 繝代せ繝ッ繝シ繝?md5(password)=xoops_users.pass)
763 @return 0 success
764 */
765 ZEND_FUNCTION(vp_login_user)
766 {
767 char *uname;
768 int unameLen;
769 char *passwd;
770 int passwdLen;
771
772 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
773 &uname, &unameLen, &passwd, &passwdLen) == FAILURE) {
774 return;
775 }
776
777 sessionid_t vpSessionID;
778 result_t result = loginUser( uname, passwd, &vpSessionID );
779 if ( result == RES_OK ){
780 RETURN_LONG((long)vpSessionID);
781 }
782 else {
783 //zend_printf( "vpal_debug: vp_login_user(%s, %s): cannot login. result=%d<br>\n", strUname.c_str(), strPasswd.c_str(), (int)result );
784 RETURN_FALSE
785 }
786 }
787
788 /** 繝ュ繧ー繧「繧ヲ繝医☆繧九??lt;br>
789 void vp_logout_user(int vp_session_id)
790 @param vp_session_id vp縺ョsessionid
791 @return 縺ェ縺?/span>
792 */
793 ZEND_FUNCTION(vp_logout_user)
794 {
795 long vpSessionID;
796
797 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &vpSessionID) == FAILURE) {
798 return;
799 }
800 logoutUser( (sessionid_t)vpSessionID );
801
802 RETURN_NULL();
803 }
804
805 /** vp 縺ョ session id 菴懈?<br>
806 int vp_create_session( string xoops_sess_id, int uid, string remote_host )
807 @param xoops_sess_id xoops縺ョsession id
808 @param uid xoops 縺ョ uid (xoops_users.uid)
809 @return FALSE莉・螟? vp 縺ョ session id
810 @return FALSE: 螟ア謨?/span>
811 */
812 ZEND_FUNCTION(vp_create_session)
813 {
814 char *xoopsSessionID;
815 int xoopsSessionIDLen;
816 long uid;
817
818 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",
819 &xoopsSessionID, &xoopsSessionIDLen, &uid) == FAILURE) {
820 return;
821 }
822
823 sessionid_t vpSessionID = 0;
824 result_t result = createSession( xoopsSessionID, (userid_t)uid, &vpSessionID );
825 if ( result == RES_OK ){
826 RETURN_LONG((long)vpSessionID);
827 }
828 else {
829 RETURN_FALSE;
830 }
831 }
832
833 /** vp 縺ョ session 縺ョ隧ウ邏ー諠??ア繧貞セ励k<br>
834 int vp_get_session( int vp_session_id, array session_info )
835 @param vp_session_id vp 縺ョ session id
836 @param session_info 邨先棡繧貞女縺大叙繧矩?蛻?/span>
837 @return 0 success
838 */
839 ZEND_FUNCTION(vp_get_session)
840 {
841 long vpSessionID;
842 zval *sessionInfo;
843 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
844 &vpSessionID, &sessionInfo) == FAILURE) {
845 return;
846 }
847 const session_t *session = 0;
848 result_t result = getSession( (sessionid_t)vpSessionID, &session );
849 if ( result == RES_OK ){
850 sessionToZval( session, sessionInfo );
851 freeResult( session );
852 }
853
854 RETURN_LONG((long)result);
855 }
856
857 /** activate迥カ諷 蜿門セ?lt;br>
858 bool vp_is_activated( int vp_session_id, int user_id )
859 @param vp_session_id vp 縺ョ session id
860 @param user_id xoops_users.uid
861 @return 0 success
862 */
863 ZEND_FUNCTION(vp_is_activated)
864 {
865 long sid, uid;
866
867 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
868 return;
869 }
870
871 bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
872
873 RETURN_BOOL(result);
874 }
875
876 /** activate縺吶k縲?lt;br>
877 bool vp_activate( int vp_session_id, bool activated )
878 @param vp_session_id vp 縺ョ session id
879 @param user_id xoops_users.uid
880 @param activated true:activate, false:inactivate
881 @return 0 success
882 */
883 ZEND_FUNCTION(vp_activate)
884 {
885 long sid, uid;
886 bool activated;
887
888 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
889 &sid, &uid, &activated) == FAILURE) {
890 return;
891 }
892
893 result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
894
895 RETURN_LONG(result);
896 }
897
898 /** vp縺ョ繧「繧ォ繧ヲ繝ウ繝域焚繧貞セ励k縲?lt;br>
899 int vp_get_account_count( int vp_session_id )
900 @param vp_session_id vp 縺ョ session id
901 @return 0 success
902 */
903 ZEND_FUNCTION(vp_get_account_count)
904 {
905 long sid;
906
907 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
908 &sid) == FAILURE) {
909 return;
910 }
911
912 long count = getAccountCount( (sessionid_t)sid );
913
914 RETURN_LONG(count);
915 }
916
917 /** 繧「繧ォ繧ヲ繝ウ繝医r蜑企勁縺吶k縲?lt;br>
918 bool vp_delete_account( int vp_session_id, int user_id )
919 @param vp_session_id vp 縺ョ session id
920 @param user_id xoops_users.uid
921 @return 0 success
922 */
923 ZEND_FUNCTION(vp_delete_account)
924 {
925 long sid, uid;
926
927 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
928 &sid, &uid) == FAILURE) {
929 return;
930 }
931
932 result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
933
934 RETURN_LONG(result);
935 }
936
937 /** 繧「繧ォ繧ヲ繝ウ繝域ュ蝣ア繧貞セ励k縲?lt;br>
938 int vp_get_account( int vp_session_id, int user_id, array account_info )
939 @param vp_session_id vp 縺ョ session id
940 @param user_id xoops_users.uid
941 @param account_info 繧「繧ォ繧ヲ繝ウ繝域ュ蝣ア繧貞女縺大叙繧矩?」諠ウ驟榊?
942 @return 0 success
943 */
944 ZEND_FUNCTION(vp_get_account)
945 {
946 long sid, uid;
947 zval *zaccount;
948
949 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
950 &sid, &uid, &zaccount) == FAILURE) {
951 fprintf( stderr, "error occured " );
952 return;
953 }
954
955 const account_t *paccount;
956 result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
957 if ( RES_OK == result ){
958 accountToZval( paccount, zaccount );
959 freeResult( paccount );
960 }
961
962 RETURN_LONG(result);
963 }
964
965 /** 譚。莉カ縺ォ荳?閾エ縺吶k繧「繧ォ繧ヲ繝ウ繝医?諠??ア繧貞セ励k縲?lt;br>
966 int vp_get_accoutns( int sid, array uids, array criteria, array accounts );
967 @param vp_session_id vp 縺ョ session id
968 @param user_id xoops_users.uid
969 @param criteria 蜿門セ礼ッ?峇繝サ繧ス繝シ繝磯??r陦ィ縺咎?蛻?/span>
970 @param account_info 繧「繧ォ繧ヲ繝ウ繝域ュ蝣ア繧貞女縺大叙繧矩?」諠ウ驟榊?
971 @return 0 success
972 */
973 ZEND_FUNCTION(vp_get_accounts)
974 {
975 result_t result;
976 long sid;
977 zval *zuids;
978 zval *zcriteria;
979 zval *zaccount;
980
981 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
982 &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
983 return;
984 }
985
986 zCriteria_t zcri(zcriteria);
987 result = zcri.getResult();
988 if ( RES_OK == result ){
989 zUIDs_t zUIDs(zuids);
990 result = zUIDs.getResult();
991 if ( RES_OK == result ){
992 const account_t *paccounts;
993 int accountLen;
994 result = getAccounts( (sessionid_t)sid,
995 zUIDs.getPUID(), zUIDs.getLen(),
996 &zcri, &paccounts, &accountLen );
997 if ( RES_OK == result ){
998 accountsToZval( paccounts, accountLen, zaccount );
999 freeResult( paccounts );
1000 }
1001 }
1002 }
1003
1004 RETURN_LONG(result);
1005 }
1006
1007 /** 繧「繧ォ繧ヲ繝ウ繝域ュ蝣ア繧貞セ励k縲?lt;br>
1008 int vp_insert_account( int sid, array account_info );
1009 @param vp_session_id vp 縺ョ session id
1010 @param user_id xoops_users.uid
1011 @param account_info 繧「繧ォ繧ヲ繝ウ繝域ュ蝣ア繧貞女縺大叙繧矩?」諠ウ驟榊?
1012 @return 0 success
1013 */
1014 ZEND_FUNCTION(vp_insert_account)
1015 {
1016 result_t result;
1017 long sid;
1018 zval *zaccount;
1019
1020 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1021 &sid, &zaccount) == FAILURE) {
1022 return;
1023 }
1024
1025 zAccount_t zacc(zaccount);
1026 result = zacc.getResult();
1027 if ( RES_OK == result ){
1028 result = insertAccount( (sessionid_t)sid, &zacc );
1029 }
1030
1031 RETURN_LONG(result);
1032 }
1033
1034 /** 繧「繧ォ繧ヲ繝ウ繝域ュ蝣ア繧呈峩譁ー縺吶k縲?lt;br>
1035 int vp_update_account( int sid, array account );
1036 @param vp_session_id vp 縺ョ session id
1037 @param account_info 譖ク縺崎セシ繧?縺ケ縺阪い繧ォ繧ヲ繝ウ繝域ュ蝣ア繧定。ィ縺咎?」諠ウ驟榊?
1038 @return 0 success
1039 */
1040 ZEND_FUNCTION(vp_update_account)
1041 {
1042 result_t result;
1043 long sid;
1044 zval *zaccount;
1045
1046 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1047 &sid, &zaccount) == FAILURE) {
1048 return;
1049 }
1050
1051 zAccount_t zacc(zaccount);
1052 result = zacc.getResult();
1053 if ( RES_OK == result ){
1054 result = updateAccount( (sessionid_t)sid, &zacc );
1055 }
1056
1057 RETURN_LONG(result);
1058 }
1059
1060 /** 譚。莉カ縺ォ蜷医≧繧「繧ォ繧ヲ繝ウ繝医?uid縺ョ荳?隕ァ繧貞セ励k縲?lt;br>
1061 int vp_dump_uids( int vp_session_id, array criteria, array uids );
1062 @param vp_session_id vp 縺ョ session id
1063 @param criteria 蜿門セ礼ッ?峇繝サ繧ス繝シ繝磯??r陦ィ縺咎?蛻?/span>
1064 @param uids uid繧貞女縺大叙繧矩?蛻?/span>
1065 @return 0 success
1066 */
1067 ZEND_FUNCTION(vp_dump_uids)
1068 {
1069 result_t result;
1070 long sid;
1071 zval *zcriteria;
1072 zval *zuids;
1073
1074 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1075 &sid, &zcriteria, &zuids) == FAILURE) {
1076 return;
1077 }
1078
1079 zCriteria_t zcri(zcriteria);
1080 result = zcri.getResult();
1081 if ( RES_OK == result ){
1082 userid_t *puid;
1083 int uidLen;
1084 result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1085 if ( RES_OK == result ){
1086 uidsToZval( puid, uidLen, &zuids );
1087 freeResult( puid );
1088 }
1089 }
1090
1091 RETURN_LONG(result);
1092 }
1093
1094 /** VP縺ョ繧ー繝ォ繝シ繝励?謨ー繧貞セ励k<br>
1095 int vp_get_group_count( int sid );
1096 @param vp_session_id vp 縺ョ session id
1097 @return 繧ー繝ォ繝シ繝玲焚
1098 */
1099 ZEND_FUNCTION(vp_get_group_count)
1100 {
1101 result_t result;
1102 long sid;
1103
1104 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1105 &sid) == FAILURE) {
1106 return;
1107 }
1108
1109 int count = getGroupCount( (sessionid_t)sid );
1110
1111 RETURN_LONG(count);
1112 }
1113
1114 /** uid縺ァ謖?ョ壹@縺溘Θ繝シ繧カ縺悟ア槭☆繧ー繝ォ繝シ繝励〒縲√°縺、譚。莉カ縺ォ荳?閾エ縺吶k繧ー繝ォ繝シ繝励?gid繧貞セ励k<br>
1115 int vp_get_group_by_uid( int sid, int uid, array criteria, array gids );
1116 @param vp_session_id vp 縺ョ session id
1117 @param user_id xoops_users.uid
1118 @param criteria 蜿門セ礼ッ?峇繝サ繧ス繝シ繝磯??r陦ィ縺咎?蛻?/span>
1119 @param gids gid繧貞女縺大叙繧矩?蛻?/span>
1120 @return 0 success
1121 */
1122 ZEND_FUNCTION(vp_get_groups_by_uid)
1123 {
1124 result_t result;
1125 long sid, uid;
1126 zval *zcriteria;
1127 zval *zgids;
1128
1129 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1130 &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1131 return;
1132 }
1133
1134 zCriteria_t zcri(zcriteria);
1135 result = zcri.getResult();
1136 if ( RES_OK == result ){
1137 groupid_t *pgids;
1138 int gidLen;
1139 result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1140 if ( RES_OK == result ){
1141 gidsToZval( pgids, gidLen, &zgids );
1142 freeResult( pgids );
1143 }
1144 }
1145
1146 RETURN_LONG(result);
1147 }
1148
1149
1150
1151 /** uid縺ァ謖?ョ壹@縺溘Θ繝シ繧カ縺携id縺ァ謖?ョ壹@縺溘げ繝ォ繝シ繝励?繧ー繝ォ繝シ繝礼ョ。逅???°縺ゥ縺?°繧貞セ励k<br>
1152 int vp_is_group_admin( int sid, int gid, int uid );
1153 @param vp_session_id vp 縺ョ session id
1154 @param group_id VP縺ョ繧ー繝ォ繝シ繝悠D
1155 @param user_id xoops_users.uid
1156 @return true: 繧ー繝ォ繝シ繝礼ョ。逅???〒縺ゅk縲?/span>
1157 @return false: 繧ー繝ォ繝シ繝礼ョ。逅???〒縺ェ縺??ゅ≠繧九>縺ッ繧ィ繝ゥ繝シ縺ァ縺ゅk縲?/span>
1158 */
1159 ZEND_FUNCTION(vp_is_group_admin)
1160 {
1161 result_t result;
1162 long sid, gid, uid;
1163
1164 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1165 &sid, &gid, &uid) == FAILURE) {
1166 return;
1167 }
1168
1169 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1170
1171 RETURN_BOOL(b);
1172 }
1173
1174 /** 譚。莉カ縺ォ荳?閾エ縺吶k繧ー繝ォ繝シ繝励?gid縺ョ荳?隕ァ繧貞セ励k縲?lt;br>
1175 int vp_dump_gids( int sid, array criteria, array gids );
1176 @param vp_session_id vp 縺ョ session id
1177 @param criteria 蜿門セ礼ッ?峇繝サ繧ス繝シ繝磯??r陦ィ縺咎?蛻?/span>
1178 @param gids gid繧貞女縺大叙繧矩?蛻?/span>
1179 @return 0 success
1180 */
1181 ZEND_FUNCTION(vp_dump_gids)
1182 {
1183 result_t result;
1184 long sid;
1185 zval *zcriteria;
1186 zval *zgids;
1187
1188 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1189 &sid, &zcriteria, &zgids) == FAILURE) {
1190 return;
1191 }
1192
1193 zCriteria_t zcri(zcriteria);
1194 result = zcri.getResult();
1195 if ( RES_OK == result ){
1196 groupid_t *pgid;
1197 int gidLen;
1198 result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1199 if ( RES_OK == result ){
1200 gidsToZval( pgid, gidLen, &zgids );
1201 freeResult( pgid );
1202 }
1203 }
1204
1205 RETURN_LONG(result);
1206 }
1207
1208 /** gid縺ァ謖?ョ壹@縺溘げ繝ォ繝シ繝励?邂。逅???〒縲√°縺、譚。莉カ縺ォ荳?閾エ縺吶k繧ー繝ォ繝シ繝礼ョ。逅????uid縺ョ荳?隕ァ繧貞セ励k縲?lt;br>
1209 int vp_dump_group_admins(int sid, int group_id, array criteria, array uids )
1210 @param sid 繧サ繝?す繝ァ繝ウID
1211 @param group_id VP繧ー繝ォ繝シ繝悠D
1212 @param criteria 譚。莉カ
1213 @param uids uid縺ョ荳?隕ァ繧貞女縺大叙繧矩?蛻?/span>
1214 @return 0 success
1215 */
1216
1217 ZEND_FUNCTION(vp_dump_group_admins)
1218 {
1219 long sid, gid;
1220 zval *zcriteria;
1221 zval *zuids;
1222
1223 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1224 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1225 return;
1226 }
1227
1228 zCriteria_t zcri(zcriteria);
1229 result_t result = zcri.getResult();
1230 if ( result == RES_OK ){
1231 userid_t *uids;
1232 int uidsLen;
1233 result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1234 if ( result == RES_OK ){
1235 uidsToZval( uids, uidsLen, &zuids );
1236 freeResult( uids );
1237 }
1238 }
1239 RETURN_LONG( result );
1240 }
1241
1242 /** 繧ー繝ォ繝シ繝励°繧峨Γ繝ウ繝舌?繧貞炎髯、縺吶k縲?lt;br>
1243 int vp_delete_member(int sid, int group_id, int user_id )
1244 @param sid 繧サ繝?す繝ァ繝ウID
1245 @param group_id VP繧ー繝ォ繝シ繝悠D
1246 @param user_id 繝ヲ繝シ繧カID
1247 @return 0 success
1248 */
1249
1250 ZEND_FUNCTION(vp_delete_member)
1251 {
1252 long sid, gid, uid;
1253
1254 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1255 &sid, &gid, &uid) == FAILURE) {
1256 return;
1257 }
1258
1259 result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1260 RETURN_LONG( result );
1261 }
1262
1263 /** 繧ー繝ォ繝シ繝励↓繝。繝ウ繝舌?繧定ソス蜉?縺吶k<br>
1264 int vp_insert_member(int sid, int group_id, int user_id, bool admin )
1265 @param sid 繧サ繝?す繝ァ繝ウID
1266 @param group_id VP繧ー繝ォ繝シ繝悠D
1267 @param user_id 繝ヲ繝シ繧カID
1268 @param admin 繧ー繝ォ繝シ繝礼ョ。逅???↑繧液rue
1269 @return 0 success
1270 */
1271
1272 ZEND_FUNCTION(vp_insert_member)
1273 {
1274 long sid, gid, uid;
1275 zend_bool admin;
1276
1277 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
1278 &sid, &gid, &uid, &admin) == FAILURE) {
1279 return;
1280 }
1281
1282 result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
1283 RETURN_LONG( result );
1284 }
1285
1286 /** gid縺ァ謖?ョ壹@縺溘げ繝ォ繝シ繝励?繝。繝ウ繝舌?縺ョuid縺ョ荳?隕ァ繧貞セ励k<br>
1287 int vp_get_members(int sid, int group_id, array criteria, array uids )
1288 @param sid 繧サ繝?す繝ァ繝ウID
1289 @param group_id VP繧ー繝ォ繝シ繝悠D
1290 @param criteria 譚。莉カ
1291 @param uids uid縺ョ荳?隕ァ繧貞女縺大叙繧矩?蛻?/span>
1292 @return 0 success
1293 */
1294
1295 ZEND_FUNCTION(vp_get_members)
1296 {
1297 long sid, gid;
1298 zval *zcriteria;
1299 zval *zuids;
1300
1301 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1302 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1303 return;
1304 }
1305
1306 zCriteria_t zcri(zcriteria);
1307 result_t result = zcri.getResult();
1308 if ( result == RES_OK ){
1309 userid_t *uids;
1310 int uidsLen;
1311 result = getMembers( (sessionid_t)sid, (groupid_t)gid, &zcri, &uids, &uidsLen );
1312 if ( result == RES_OK ){
1313 uidsToZval( uids, uidsLen, &zuids );
1314 freeResult( uids );
1315 }
1316 }
1317 RETURN_LONG( result );
1318 }
1319
1320 /** 繧ー繝ォ繝シ繝玲ュ蝣ア繧貞、画峩縺吶k縲?lt;br>
1321 int vp_update_group(int sid, array group )
1322 @param sid 繧サ繝?す繝ァ繝ウID
1323 @param group 繧ー繝ォ繝シ繝玲ュ蝣ア縺ョ騾」諠ウ驟榊?
1324 @return 0 success
1325 */
1326 ZEND_FUNCTION(vp_update_group)
1327 {
1328 long sid;
1329 zval *zgroup;
1330 group_t group;
1331
1332 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1333 &sid, &zgroup) == FAILURE) {
1334 return;
1335 }
1336
1337 zvalToGroup( zgroup, &group );
1338 result_t result = updateGroup( sid, &group );
1339 RETURN_LONG( result );
1340 }
1341
1342 /** vp縺ョsession_id縺ョ豁」蠖捺?ァ繝√ぉ繝?け<br>
1343 bool vp_is_valid_session_id( int vp_session_id)
1344 @return true 譛牙柑縺ェvp縺ョsession_id縺ァ縺ゅk
1345 @return false 辟。蜉ケ縺ェsession_id縺セ縺溘?繧ィ繝ゥ繝シ
1346 */
1347 ZEND_FUNCTION(vp_is_valid_session_id)
1348 {
1349 long sid;
1350 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
1351 return;
1352 }
1353
1354 RETURN_BOOL(isValidSessionID((sessionid_t)sid));
1355 }
1356
1357 /** 繧ィ繝ゥ繝シ譁?ュ怜?繧貞セ励k<br>
1358 string vp_get_last_error_string()
1359 @return 0 success
1360 */
1361 ZEND_FUNCTION(vp_get_last_error_string)
1362 {
1363 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
1364 return;
1365 }
1366
1367 string str( getLastErrorString() );
1368 RETURN_STRING((char *)str.c_str(), 1);
1369 }
1370

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