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

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