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.16 - (show annotations) (download) (as text)
Sat Dec 4 09:22:24 2004 UTC (19 years, 4 months ago) by aga
Branch: MAIN
Changes since 1.15: +191 -82 lines
File MIME type: text/x-c++src
・コメントつけ.

1 /*
2 $Revision$
3 VPAL: Visiome Platform Abstract Layer
4
5 zend_parse_parameters??hp4.1.0??綽?荀?
6 .so???<?ゃ?????????荀????????贋????舟??鴻????
7 C++?с????extern "C"{}, BEGIN/END_EXTERN_C()??綽?荀???
8 */
9
10
11 #include <stdio.h>
12 #include "criteria.h"
13 #include "common.h"
14 #include "commonal.h"
15 #include "session.h"
16 #include "group.h"
17 #include "account.h"
18 #include "vpal.h"
19
20 // for inet_aton
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24
25 // global variables
26 MYSQL *mysql = NULL;
27
28
29 /* declaration of functions to be exported */
30 extern "C" {
31 ZEND_FUNCTION(first_module );
32 ZEND_FUNCTION(vp_initialize_db );
33 ZEND_FUNCTION(vp_login_user );
34 ZEND_FUNCTION(vp_logout_user );
35 ZEND_FUNCTION(vp_create_session );
36 ZEND_FUNCTION(vp_get_session );
37 ZEND_FUNCTION(vp_is_activated );
38 ZEND_FUNCTION(vp_activate );
39 ZEND_FUNCTION(vp_get_account_count );
40 ZEND_FUNCTION(vp_delete_account );
41 ZEND_FUNCTION(vp_get_account );
42 ZEND_FUNCTION(vp_get_accounts );
43 ZEND_FUNCTION(vp_insert_account );
44 ZEND_FUNCTION(vp_update_account );
45 ZEND_FUNCTION(vp_dump_uids );
46 ZEND_FUNCTION(vp_get_group_count );
47 ZEND_FUNCTION(vp_get_groups_by_uid );
48 ZEND_FUNCTION(vp_is_group_admin );
49 ZEND_FUNCTION(vp_dump_gids );
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 ZEND_FUNCTION(vp_is_valid_session_id );
63 ZEND_FUNCTION(vp_get_last_error_string );
64
65 ZEND_FUNCTION(vp_test_criteria );
66 ZEND_FUNCTION(vp_test_uids );
67 };
68 /* compiled function list so Zend knows what's in this module */
69 zend_function_entry vpalmod_functions[] =
70 {
71 ZEND_FE(first_module ,NULL)
72 ZEND_FE(vp_initialize_db ,NULL)
73 ZEND_FE(vp_login_user ,NULL)
74 ZEND_FE(vp_logout_user ,NULL)
75 ZEND_FE(vp_create_session ,NULL)
76 ZEND_FE(vp_get_session ,NULL)
77 ZEND_FE(vp_is_activated ,NULL)
78 ZEND_FE(vp_activate ,NULL)
79 ZEND_FE(vp_get_account_count ,NULL)
80 ZEND_FE(vp_delete_account ,NULL)
81 ZEND_FE(vp_get_account ,NULL)
82 ZEND_FE(vp_get_accounts ,NULL)
83 ZEND_FE(vp_insert_account ,NULL)
84 ZEND_FE(vp_update_account ,NULL)
85 ZEND_FE(vp_dump_uids ,NULL)
86 ZEND_FE(vp_get_group_count ,NULL)
87 ZEND_FE(vp_get_groups_by_uid ,NULL)
88 ZEND_FE(vp_is_group_admin ,NULL)
89 ZEND_FE(vp_dump_gids ,NULL)
90 ZEND_FE(vp_dump_group_admins ,NULL)
91 ZEND_FE(vp_delete_member ,NULL)
92 ZEND_FE(vp_insert_member ,NULL)
93 ZEND_FE(vp_get_members ,NULL)
94 ZEND_FE(vp_delete_group ,NULL)
95 ZEND_FE(vp_insert_group ,NULL)
96 ZEND_FE(vp_update_group ,NULL)
97 ZEND_FE(vp_get_group ,NULL)
98 ZEND_FE(vp_get_groups ,NULL)
99 ZEND_FE(vp_is_moderator ,NULL)
100 ZEND_FE(vp_get_uid ,NULL)
101 ZEND_FE(vp_is_valid_session_id ,NULL)
102 ZEND_FE(vp_get_last_error_string ,NULL)
103 ZEND_FE(vp_test_criteria ,NULL)
104 ZEND_FE(vp_test_uids ,NULL)
105 {NULL, NULL, NULL}
106 };
107
108 /* compiled module information */
109 zend_module_entry vpalmod_module_entry =
110 {
111 STANDARD_MODULE_HEADER,
112 "Visiome Platform Abstract Layer",
113 vpalmod_functions,
114 NULL,
115 NULL,
116 NULL,
117 NULL,
118 NULL,
119 NO_VERSION_YET,
120 STANDARD_MODULE_PROPERTIES
121 };
122
123 /* implement standard "stub" routine to introduce ourselves to Zend */
124 #if COMPILE_DL_FIRST_MODULE
125 BEGIN_EXTERN_C()
126 ZEND_GET_MODULE(vpalmod)
127 END_EXTERN_C()
128 #endif
129
130
131 /* implement function that is meant to be made available to PHP */
132 ZEND_FUNCTION(first_module)
133 {
134 long parameter;
135 // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
136 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
137 return;
138 }
139 parameter++;
140 RETURN_LONG(parameter);
141 }
142 /** zval????C????絖?????緇?????
143 */
144 char *getZvalString( zval **p ){
145 convert_to_string_ex(p);
146 return Z_STRVAL_PP(p); //(**p).value.str.val;
147 }
148
149 /** zval????int??緇?????
150 */
151 int getZvalInt( zval **p ){
152 convert_to_long_ex(p);
153 return Z_LVAL_PP(p); // (int)(**p).value.lval;
154 }
155
156 // keylen????鮎??0????????
157 static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
158 zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
159 if ( res == HASH_KEY_IS_STRING ){
160 char *p = new char[keyLen+1];
161 memcpy( p, key, keyLen );
162 p[keyLen] = 0;
163 zend_printf( " key is string[%s]<br>\n", p );
164 }
165 else {
166 zend_printf( " key is integer[%d]<br>\n", index );
167 }
168 }
169
170
171 /** zval*????criteria_t?????????????????????鴻??????紊掩??????getResult()!=RES_OK <br>
172 criteria :
173 array( 'start'=>0, 'rows'=>10,
174 'orders'=>array(
175 array('name'=>'id','order'=>'0'),
176 array('name'=>'timestamp','name'=>'1'), ...)
177 ); ??????就???f?渇????
178 */
179 class zCriteria_t : public criteria {
180 private:
181 result_t result;
182
183 // pz: array('name'=>'timestamp','name'=>'1')
184 // ????????orderby??篏???????申????
185 void setOrder( zval *pz ){
186 char *column = 0;
187 order_t order = (order_t)0;
188
189 HashPosition pos;
190 zval **ppzTmp = 0;
191 int res2;
192 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
193 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
194 char *key = 0;
195 uint keyLen = 0;
196 ulong index = 0;
197 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
198 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
199 //print_hash_key( keyType, key, keyLen, index );
200 if ( strncasecmp( key, "name", keyLen ) == 0 && keyLen == 5 ){
201 SEPARATE_ZVAL(ppzTmp);
202 column = getZvalString(ppzTmp);
203 // zend_printf( "column=%s<br>\n", column );
204 }
205 else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
206 SEPARATE_ZVAL(ppzTmp);
207 order = (order_t)getZvalInt(ppzTmp);
208 // zend_printf( "order=%d<br>\n", order );
209 }
210 }
211
212 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
213 }
214 if ( column ){
215 orderby *o = new orderby( column, order );
216 addOrderBy( o );
217 }
218
219 result = RES_OK;
220 }
221
222 // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
223 void setOrders( zval *pz ){
224 HashPosition pos;
225
226 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
227
228 zval **ppzTmp = 0;
229 int res2;
230 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
231 char *key = 0;
232 uint keyLen = 0;
233 ulong index = 0;
234 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
235 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
236 //print_hash_key( keyType, key, keyLen, index );
237 setOrder( *ppzTmp );
238 }
239 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
240 }
241 result = RES_OK;
242 }
243
244 void initialize( zval *pz ){
245 HashPosition pos;
246 zval **ppzTmp = 0;
247 int res2;
248 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
249 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
250 char *key = 0;
251 uint keyLen = 0;
252 ulong index = 0;
253 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
254 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
255 //print_hash_key( keyType, key, keyLen, index );
256 if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
257 SEPARATE_ZVAL(ppzTmp);
258 int tmp = getZvalInt(ppzTmp);
259 // zend_printf( "start=%d<br>\n", tmp );
260 setLimit( tmp, getLimitRows() );
261 }
262 else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
263 SEPARATE_ZVAL(ppzTmp);
264 int tmp = getZvalInt(ppzTmp);
265 // zend_printf( "rows=%d<br>\n", tmp );
266 setLimit( getLimitStart(), tmp );
267 }
268 else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
269 setOrders( *ppzTmp );
270 }
271 else
272 ; // ignore unknown key
273 }
274 else
275 ; // ignore bad key
276 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
277 }
278 result = RES_OK;
279 }
280
281 public:
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 /** ?f?渇???????≪???祉?鴻????ong?ゃ??緇?????
301 @param ht ?f?渇????
302 @param key ????/span>
303 @param val long?ゃ?????????????ゃ?潟??/span>
304 @return ????????true
305 */
306 static bool hashGetLong( HashTable *ht, const char *key, long *val ){
307 zval **tmp;
308 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
309 convert_to_long_ex( tmp );
310 *val = Z_LVAL_PP(tmp);
311 return true;
312 }
313 return false;
314 }
315
316 /** ?f?渇???????≪???祉?鴻??????絖?????緇?????
317 @param ht ?f?渇????
318 @param key ????/span>
319 @param val ??絖????????????????ゃ?潟??/span>
320 @return ????????true
321 */
322 static bool hashGetString( HashTable *ht, const char *key, char **val ){
323 zval **tmp;
324 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
325 convert_to_string_ex( tmp );
326 *val = Z_STRVAL_PP(tmp);
327 return true;
328 }
329 return false;
330 }
331
332 /** ?f?渇???????≪???祉?鴻????ouble?ゃ??緇?????
333 @param ht ?f?渇????
334 @param key ????/span>
335 @param val double?ゃ?????????????ゃ?潟??/span>
336 @return ????????true
337 */
338 static bool hashGetDouble( HashTable *ht, const char *key, double *val ){
339 zval **tmp;
340 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
341 convert_to_double_ex( tmp );
342 *val = Z_DVAL_PP(tmp);
343 return true;
344 }
345 return false;
346 }
347
348 /** zval*????account?????????????????????鴻?? <br>
349 ????紊掩??????getResult()!=RES_OK <br>
350 */
351 class zAccount_t : public account {
352 private:
353 result_t result;
354 void initialize(zval *pz){
355 HashTable *ht = Z_ARRVAL_P(pz);
356 long l;
357 char *p;
358 double d;
359 if ( hashGetLong ( ht, "uid" , &l ) ) setUID ( l );
360 if ( hashGetString( ht, "uname" , &p ) ) setUname ( p );
361 if ( hashGetString( ht, "name" , &p ) ) setName ( p );
362 if ( hashGetString( ht, "email" , &p ) ) setEmail ( p );
363 if ( hashGetString( ht, "url" , &p ) ) setURL ( p );
364 if ( hashGetString( ht, "user_avatar" , &p ) ) setUserAvatar ( p );
365 if ( hashGetString( ht, "user_icq" , &p ) ) setUserIcq ( p );
366 if ( hashGetString( ht, "user_from" , &p ) ) setUserFrom ( p );
367 if ( hashGetString( ht, "user_sig" , &p ) ) setUserSig ( p );
368 if ( hashGetString( ht, "actkey" , &p ) ) setActkey ( p );
369 if ( hashGetString( ht, "user_aim" , &p ) ) setUserAim ( p );
370 if ( hashGetString( ht, "user_yim" , &p ) ) setUserYim ( p );
371 if ( hashGetString( ht, "user_msnm" , &p ) ) setUserMsnm ( p );
372 if ( hashGetString( ht, "pass" , &p ) ) setPass ( p );
373 if ( hashGetString( ht, "theme" , &p ) ) setTheme ( p );
374 if ( hashGetString( ht, "umode" , &p ) ) setUmode ( p );
375 if ( hashGetString( ht, "user_occ" , &p ) ) setUserOcc ( p );
376 if ( hashGetString( ht, "bio" , &p ) ) setBio ( p );
377 if ( hashGetString( ht, "user_intrest" , &p ) ) setUserIntrest ( p );
378 if ( hashGetDouble( ht, "timezone_offset" , &d ) ) setTimezoneOffset ( d );
379 if ( hashGetLong ( ht, "attachsig" , &l ) ) setAttachsig ( l );
380 if ( hashGetLong ( ht, "last_login" , &l ) ) setLastLogin ( l );
381 if ( hashGetLong ( ht, "level" , &l ) ) setLevel ( l );
382 if ( hashGetLong ( ht, "notify_method" , &l ) ) setNotifyMethod ( l );
383 if ( hashGetLong ( ht, "notify_mode" , &l ) ) setNotifyMode ( l );
384 if ( hashGetLong ( ht, "posts" , &l ) ) setPosts ( l );
385 if ( hashGetLong ( ht, "rank" , &l ) ) setRank ( l );
386 if ( hashGetLong ( ht, "uorder" , &l ) ) setUorder ( l );
387 if ( hashGetLong ( ht, "user_mailok" , &l ) ) setUserMailok ( l );
388 if ( hashGetLong ( ht, "user_regdate" , &l ) ) setUserRegdate ( l );
389 if ( hashGetLong ( ht, "user_viewemail" , &l ) ) setUserViewemail ( l );
390 if ( hashGetLong ( ht, "activate" , &l ) ) setActivate ( l );
391 if ( hashGetString( ht, "address" , &p ) ) setAddress ( p );
392 if ( hashGetString( ht, "division" , &p ) ) setDivision ( p );
393 if ( hashGetString( ht, "tel" , &p ) ) setTel ( p );
394 if ( hashGetString( ht, "company_name" , &p ) ) setCompanyName ( p );
395 if ( hashGetString( ht, "country" , &p ) ) setCountry ( p );
396 if ( hashGetString( ht, "zipcode" , &p ) ) setZipcode ( p );
397 if ( hashGetString( ht, "fax" , &p ) ) setFax ( p );
398 if ( hashGetString( ht, "base_url" , &p ) ) setBaseURL ( p );
399 if ( hashGetLong ( ht, "notice_mail" , &l ) ) setNoticeMail ( l );
400 if ( hashGetLong ( ht, "notice_mail_since" , &l ) ) setNoticeMailSince ( l );
401
402 result = RES_OK;
403 }
404 public:
405 zAccount_t() : account(){ result = RES_ERROR; }
406
407 /** ?潟?潟?鴻????????/span>
408 @param pz array( 'uid'=>1, 'uname'=>'root', ... ); ??????就???f?渇???? */
409 zAccount_t( zval *pz ) : account(){ initialize(pz); }
410 zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
411 result_t getResult(){ return result; };
412 };
413
414 /** zval*????(userid_t *puid,int uidLen)?????????????????????鴻?? <br>
415 ????紊掩??????getResult()!=RES_OK <br>
416 */
417 class zUIDs_t {
418 private:
419 result_t result;
420 userid_t *pUID;
421 int len;
422 public:
423 zUIDs_t(){
424 pUID = 0;
425 len = 0;
426 result = RES_ERROR;
427 }
428
429 /** ?潟?潟?鴻????????/span>
430 @param pza array( '1', '3', '4', '6', ... ); ??????就?????? */
431 zUIDs_t( zval *pza ){
432 pUID = 0;
433 len = 0;
434 result = RES_ERROR;
435
436 if ( Z_TYPE_P(pza) != IS_ARRAY ){
437 result = RES_ERROR;
438 }
439 else {
440 len = zend_hash_num_elements(Z_ARRVAL_P(pza));
441 if(len == 0) {
442 pUID = new userid_t[1];
443 result = RES_OK;
444 }
445 else {
446 /* php/ext/standard/string.c ? implode??????????????????
447 zend_hash_*???????ャ?<?潟???c????????????????鐚?
448 */
449 zval **tmp;
450 HashPosition pos;
451 int i = 0;
452 pUID = new userid_t[len];
453
454 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
455 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
456 SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
457 convert_to_long_ex(tmp);
458 if ( i < len )
459 pUID[i++] = Z_LVAL_PP(tmp);
460 zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
461 }
462 len = i;
463 result = RES_OK;
464 }
465 }
466 }
467
468 ~zUIDs_t(){
469 if ( pUID ) delete[] pUID;
470 }
471 result_t getResult(){ return result; }
472 userid_t *getPUID(){ return pUID; }
473 int getLen(){ return len; }
474 void dump(){
475 zend_printf( "dumping zUIDs...<br>\n" );
476 zend_printf( "result=%d<br>\n", (int)result );
477 zend_printf( "len=%d<br>\n", len );
478 for ( int i = 0; i < len; i++ ){
479 zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
480 }
481 }
482 };
483
484 /**
485 *
486 * uids_t????????PHP???????????????
487 *
488 * @param pUID 紊???????serid_t??????
489 * @param len pUID?????????激??
490 * @param pz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
491 * @return RES_OK
492 *
493 */
494 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
495 {
496 zend_hash_clean( Z_ARRVAL_PP(ppz) );
497
498 // add UIDs
499 for ( int i = 0; i < len; i++ ){
500 add_next_index_long(*ppz, (long)(pUID[i]) );
501 }
502
503 return RES_OK;
504 }
505 /**
506 *
507 * groupid_t????????PHP???????????????
508 * @param pGID 紊???????roupid_t??????
509 * @param len pGID?????????激??
510 * @param ppz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
511 * @return RES_OK
512 *
513 */
514 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
515 {
516 zend_hash_clean( Z_ARRVAL_PP(ppz) );
517
518 // add GIDs
519 for ( int i = 0; i < len; i++ ){
520 add_next_index_long(*ppz, (long)(pGID[i]) );
521 }
522
523 return RES_OK;
524 }
525
526
527 /**
528 *
529 * account_t????絎鴻??PHP???????????????
530 * @param pAccount 紊???????ccount_t*
531 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
532 * @return RES_OK
533 *
534 */
535 result_t accountToZval( const account_t *pAccount, zval *z )
536 {
537 zend_hash_clean( z -> value.ht );
538
539 add_assoc_long( z, "uid", pAccount -> getUID( ) );
540 add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
541 add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
542 add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
543 add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
544 add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
545 add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
546 add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
547 add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
548 add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
549 add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
550 add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
551 add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
552 add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
553 add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
554 add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
555 add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
556 add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
557 add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
558 add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
559 add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
560 add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
561 add_assoc_long( z, "level", pAccount -> getLevel( ) );
562 add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
563 add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
564 add_assoc_long( z, "posts", pAccount -> getPosts( ) );
565 add_assoc_long( z, "rank", pAccount -> getRank( ) );
566 add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
567 add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
568 add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
569 add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
570
571 add_assoc_long( z, "activate", pAccount -> getActivate( ) );
572 add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
573 add_assoc_string( z, "division", ( char* )pAccount -> getDivision( ), 1 );
574 add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
575 add_assoc_string( z, "company_name", ( char* )pAccount -> getCompanyName( ), 1 );
576 add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
577 add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
578 add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
579 add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
580 add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
581 add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
582 return RES_OK;
583 }
584 /**
585 *
586 * 茲??違??ccount_t????絎鴻??PHP?????????????????????
587 * @param pAccounts 紊???????ccount_t*
588 * @param accountsLen pAccounts?????????激??
589 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
590 * @return RES_OK
591 *
592 z: ?????????????????????????? <br>
593 array(
594 array(
595 'uid'=>100,
596 'activate'=>1,
597 'division'=>'foo',
598 'tel'=>'123-456-789',
599 ...
600 ),
601 ...
602 )
603 */
604 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
605 {
606 zend_hash_clean( z -> value.ht );
607 for( int i = 0; i < accountsLen; i++ ){
608 zval *new_array;
609 MAKE_STD_ZVAL(new_array);
610 if(array_init(new_array) != SUCCESS){
611 return RES_ERROR;
612 }
613 add_index_zval( z, i, new_array );
614 accountToZval( &pAccounts[ i ], new_array );
615 }
616 return RES_OK;
617 }
618
619 /**
620 *
621 * 茲??違??roup_t????絎鴻??PHP?????????????????????
622 * @param pGroups 紊???????roup_t*
623 * @param groupsLen pGroups?????????激??
624 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
625 * @return RES_OK
626 *
627 z: ?????????????????????????? <br>
628 array(
629 array(
630 'gid'=>1,
631 'gname'=>'foo group',
632 'gdesc'=>'group of foo'
633 ),
634 ...
635 )
636 */
637 result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
638 {
639 zend_hash_clean( z -> value.ht );
640 for( int i = 0; i < groupsLen; i++ ){
641 zval *new_array;
642 MAKE_STD_ZVAL(new_array);
643 if(array_init(new_array) != SUCCESS){
644 return RES_ERROR;
645 }
646 add_index_zval( z, i, new_array );
647 add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
648 add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
649 add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
650 }
651 return RES_OK;
652 }
653
654 /**
655 *
656 * group_t????絎鴻??PHP???f?渇?????????????
657 *
658 * @param pGroup 紊????????違???若??????/span>
659 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
660 * @return RES_OK
661 *
662 */
663 result_t groupToZval( const group_t *pGroup, zval *z )
664 {
665 zend_hash_clean( z -> value.ht );
666 add_assoc_long( z, "gid", pGroup -> getGID( ) );
667 add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
668 add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
669 return RES_OK;
670 }
671
672 /**
673 *
674 * PHP???f?渇????????絎鴻??group_t?????????
675 *
676 * @param z 紊????????f?渇????
677 * @param pGroup 紊???腟??????吾??莨若???違???若??
678 * @return RES_OK
679 *
680 */
681 result_t zvalToGroup( zval *z, group_t *pGroup )
682 {
683 zval **tmp;
684 HashPosition pos;
685 int i = 0;
686 char* key = 0;
687
688 key = "gid";
689 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
690 convert_to_long_ex( tmp ) ;
691 pGroup -> setGID( (*tmp) -> value.lval );
692 }
693 key = "gname";
694 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
695 convert_to_string_ex( tmp ) ;
696 pGroup -> setGname( (*tmp) -> value.str.val );
697 }
698 key = "gdesc";
699 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
700 convert_to_string_ex( tmp ) ;
701 pGroup -> setDesc( (*tmp) -> value.str.val );
702 }
703 return RES_OK;
704 }
705
706 /**
707 *
708 * session_t????絎鴻??PHP???f?渇?????????????
709 *
710 * @param pSession 紊???????ession_t
711 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
712 * @return RES_OK
713 *
714 */
715 result_t sessionToZval( const session_t *pSession, zval *z )
716 {
717 string sessionID(unsignedIntToString(pSession->getSessionID()));
718 add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
719
720 string date(unsignedIntToString((unsigned int)pSession->getDate()));
721 add_assoc_string(z, "date", (char *)date.c_str(), 1);
722
723 string userID(unsignedIntToString((unsigned int)pSession->getUserID()));
724 add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
725
726 return RES_OK;
727 }
728
729
730
731 /** ??絎??????違???若???????宴??緇???<br>
732 int vp_get_group( int sid, int gid, array group );
733 @param sid VP???祉???激?с??D
734 @param gid VP ? group_id
735 @param group 腟?????????????????
736 @return 0 success <br>
737 */
738 ZEND_FUNCTION(vp_get_group)
739 {
740 long sid, gid;
741 zval *zgroup;
742
743 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
744 &sid, &gid, &zgroup) == FAILURE) {
745 return;
746 }
747
748 const group_t *pgroup;
749 result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
750 if ( RES_OK == result ){
751 groupToZval( pgroup, zgroup );
752 freeResult( pgroup );
753 }
754
755 RETURN_LONG(result);
756 }
757
758
759 /** ??絎??????違???若??(茲????????宴??緇???<br>
760 vp_get_groups( int sid, array gids, array criteria, array groups );
761 @param sid VP???祉???激?с??D
762 @param gids VP ? group_id ??????
763 @param criteria ?>散
764 @param groups 腟???????????????????????
765 @return 0 success <br>
766 */
767 ZEND_FUNCTION(vp_get_groups)
768 {
769 result_t result;
770 long sid, uid;
771 zval *zcriteria;
772 zval *zgids;
773 zval *zgroups;
774 zval **ppzTmp = 0;
775 HashPosition pos;
776 int res2;
777 int gidsLen;
778 const group_t* groups;
779 int groupsLen;
780
781 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
782 &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
783 return;
784 }
785
786 //gids???違???若??ID???潟???若????
787 gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
788 groupid_t *gids = new groupid_t[ gidsLen ];
789 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
790 for( int i = 0; i < gidsLen; i++ ){
791 if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
792 SEPARATE_ZVAL(ppzTmp);
793 convert_to_long_ex(ppzTmp);
794 gids[ i ] = Z_LVAL_PP(ppzTmp);
795 }
796 zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
797 }
798
799 zCriteria_t zcri(zcriteria);
800 result = zcri.getResult();
801 if ( RES_OK == result ){
802 result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
803 if ( RES_OK == result ){
804 groupsToZval( groups, groupsLen, zgroups );
805 delete[] gids;
806 freeResult( groups );
807 }
808 }
809 RETURN_LONG(result);
810 }
811
812
813 /** ??絎????????若?吟???≪?????若?帥??????????茯帥?鴻??<br>
814 int vp_is_moderator(int sid, int uid)
815 @param sid VP???祉???激?с??D
816 @param uid xoops ? uid (xoops_users.uid)
817 @return true ?≪?????若?帥?с???? <br>
818 */
819 ZEND_FUNCTION(vp_is_moderator)
820 {
821 long vpSessionID;
822 userid_t uid;
823
824 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
825 &vpSessionID, &uid) == FAILURE) {
826 return;
827 }
828
829 bool result = isModerator( (sessionid_t)vpSessionID, uid );
830 RETURN_BOOL(result)
831 }
832
833 /** ???若?九??????uid??茯帥?鴻??<br>
834 int vp_get_uid(string uname,int &uid)
835 @param sid VP???祉???激?с??D
836 @param uname xoops ? uname (xoops_users.uname)
837 @param uid xoops ? uid (xoops_users.uid) ??????????紊???/span>
838 @return 0 success
839 */
840 ZEND_FUNCTION(vp_get_uid)
841 {
842 char *uname;
843 int unameLen;
844 zval *zuid;
845 userid_t uid;
846
847 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
848 &uname, &unameLen, &zuid) == FAILURE) {
849 return;
850 }
851
852 if (!PZVAL_IS_REF(zuid)) {
853 zend_error(E_WARNING, "2nd parameter wasn't passed by reference");
854 RETURN_LONG(RES_PHP_NONREF);
855 }
856
857 string strUname( uname, unameLen );
858 result_t result = getUid( strUname.c_str(), &uid );
859 ZVAL_LONG(zuid, (long)uid);
860 RETURN_LONG((long)result);
861 }
862
863 ZEND_FUNCTION(vp_test_criteria)
864 {
865 zval *z;
866
867 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
868 &z) == FAILURE) {
869 return;
870 }
871 zend_printf("zend_printf...<br>\n");
872 zCriteria_t zcri(z);
873 zcri.dump();
874 RETURN_FALSE
875 }
876
877 ZEND_FUNCTION(vp_test_uids)
878 {
879 zval *z;
880
881 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
882 &z) == FAILURE) {
883 return;
884 }
885 zend_printf("zend_printf...<br>\n");
886 zUIDs_t zuids(z);
887 zuids.dump();
888 RETURN_FALSE
889 }
890
891
892
893 /** DB??・膓????????≪??・膓?筝???・膓???????????????<br>
894 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
895 @param host ?ョ????????ユ????ULL
896 @param user DB?ョ????????若?九???????ユ????ULL
897 @param password DB?ョ????????鴻???若???????ユ????ULL
898 @param dbname DB?ョ?????B???????ユ????quot;"
899 @param prefix XOOPS DB ??refix??
900 @return 0 success <br>
901 */
902 ZEND_FUNCTION(vp_initialize_db)
903 {
904 zval **parameters[5];
905 char *host;
906 char *user;
907 char *password;
908 char *dbname;
909 char *prefix;
910
911 /* get the number of arguments */
912 int argNum = ZEND_NUM_ARGS();
913 if (argNum > 5)
914 WRONG_PARAM_COUNT;
915
916 /* argument count is correct, now retrieve arguments */
917 if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
918 WRONG_PARAM_COUNT;
919
920 if (argNum < 1) host = NULL;
921 else host = getZvalString( parameters[0] );
922
923 if (argNum < 2) user = NULL;
924 else user = getZvalString( parameters[1] );
925
926 if (argNum < 3) password = NULL;
927 else password = getZvalString( parameters[2] );
928
929 if (argNum < 4) dbname = "";
930 else dbname = getZvalString( parameters[3] );
931
932 if (argNum < 5) prefix = "";
933 else prefix = getZvalString( parameters[4] );
934
935 result_t result = initializeDB( host, user, password, dbname, prefix );
936
937 RETURN_LONG(result);
938 }
939
940 /** ???違?ゃ?潟??????<br>
941 int vp_login_user(string uname, string password, int &session_id)
942 @param uname ???若?九??(xoops_users.uname)
943 @param password ???鴻???若??(md5(password)=xoops_users.pass)
944 @return 0 success
945 */
946 ZEND_FUNCTION(vp_login_user)
947 {
948 char *uname;
949 int unameLen;
950 char *passwd;
951 int passwdLen;
952 zval *zVPSessionID;
953
954 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",
955 &uname, &unameLen, &passwd, &passwdLen, &zVPSessionID) == FAILURE) {
956 return;
957 }
958
959 if (!PZVAL_IS_REF(zVPSessionID)) {
960 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
961 RETURN_LONG(RES_PHP_NONREF);
962 }
963
964 sessionid_t vpSessionID;
965 result_t result = loginUser( uname, passwd, &vpSessionID );
966 if ( result == RES_OK )
967 ZVAL_LONG(zVPSessionID, (long)vpSessionID);
968 RETURN_LONG((long)result);
969 }
970
971 /** ???違?≪??????????<br>
972 void vp_logout_user(int vp_session_id)
973 @param vp_session_id VP???祉???激?с??D
974 @return ????
975 */
976 ZEND_FUNCTION(vp_logout_user)
977 {
978 long vpSessionID;
979
980 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &vpSessionID) == FAILURE) {
981 return;
982 }
983 logoutUser( (sessionid_t)vpSessionID );
984
985 RETURN_NULL();
986 }
987
988 /** VP???祉???激?с??D 篏???<br>
989 int vp_create_session( string xoops_sess_id, int uid, int &session )
990 @param xoops_sess_id xoops???祉???激?с??D
991 @param uid xoops ? uid (xoops_users.uid)
992 @param session 篏???????VP??ession??????????紊???/span>
993 @return 0 ????
994 */
995 ZEND_FUNCTION(vp_create_session)
996 {
997 char *xoopsSessionID;
998 int xoopsSessionIDLen;
999 long uid;
1000 zval *zVPSessionID;
1001
1002 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz",
1003 &xoopsSessionID, &xoopsSessionIDLen, &uid, &zVPSessionID) == FAILURE) {
1004 return;
1005 }
1006
1007 if (!PZVAL_IS_REF(zVPSessionID)) {
1008 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1009 RETURN_LONG(RES_PHP_NONREF);
1010 }
1011
1012 sessionid_t vpSessionID = 0;
1013 result_t result = createSession( xoopsSessionID, (userid_t)uid, &vpSessionID );
1014 if ( result == RES_OK )
1015 ZVAL_LONG(zVPSessionID, (long)vpSessionID);
1016 RETURN_LONG((long)result);
1017 }
1018
1019 /** VP ? session ???膣井???宴??緇???<br>
1020 int vp_get_session( int vp_session_id, array session_info )
1021 @param vp_session_id VP???祉???激?с??D
1022 @param session_info 腟?????????????????
1023 @return 0 success
1024 */
1025 ZEND_FUNCTION(vp_get_session)
1026 {
1027 long vpSessionID;
1028 zval *sessionInfo;
1029 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1030 &vpSessionID, &sessionInfo) == FAILURE) {
1031 return;
1032 }
1033 const session_t *session = 0;
1034 result_t result = getSession( (sessionid_t)vpSessionID, &session );
1035 if ( result == RES_OK ){
1036 sessionToZval( session, sessionInfo );
1037 freeResult( session );
1038 }
1039
1040 RETURN_LONG((long)result);
1041 }
1042
1043 /** ???若?吟??ctivate?倶??????緇?????<br>
1044 bool vp_is_activated( int vp_session_id, int user_id )
1045 @param vp_session_id VP???祉???激?с??D
1046 @param user_id xoops_users.uid
1047 @return 0 success
1048 */
1049 ZEND_FUNCTION(vp_is_activated)
1050 {
1051 long sid, uid;
1052
1053 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
1054 return;
1055 }
1056
1057 bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
1058
1059 RETURN_BOOL(result);
1060 }
1061
1062 /** ???若?吟??activate??????<br>
1063 bool vp_activate( int vp_session_id, bool activated )
1064 @param vp_session_id VP???祉???激?с??D
1065 @param user_id xoops_users.uid
1066 @param activated true:activate, false:inactivate
1067 @return 0 success
1068 */
1069 ZEND_FUNCTION(vp_activate)
1070 {
1071 long sid, uid;
1072 bool activated;
1073
1074 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
1075 &sid, &uid, &activated) == FAILURE) {
1076 return;
1077 }
1078
1079 result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
1080
1081 RETURN_LONG(result);
1082 }
1083
1084 /** VP???≪?????潟???違??緇?????<br>
1085 int vp_get_account_count( int vp_session_id )
1086 @param vp_session_id VP???祉???激?с??D
1087 @return 0 success
1088 */
1089 ZEND_FUNCTION(vp_get_account_count)
1090 {
1091 long sid;
1092
1093 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1094 &sid) == FAILURE) {
1095 return;
1096 }
1097
1098 long count = getAccountCount( (sessionid_t)sid );
1099 RETURN_LONG(count);
1100 }
1101
1102 /** ?≪?????潟???????ゃ??????<br>
1103 bool vp_delete_account( int vp_session_id, int user_id )
1104 @param vp_session_id VP???祉???激?с??D
1105 @param user_id xoops_users.uid
1106 @return 0 success
1107 */
1108 ZEND_FUNCTION(vp_delete_account)
1109 {
1110 long sid, uid;
1111
1112 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1113 &sid, &uid) == FAILURE) {
1114 return;
1115 }
1116
1117 result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
1118
1119 RETURN_LONG(result);
1120 }
1121
1122 /** ?≪?????潟?????宴??緇?????<br>
1123 int vp_get_account( int vp_session_id, int user_id, array account_info )
1124 @param vp_session_id VP???祉???激?с??D
1125 @param user_id xoops_users.uid
1126 @param account_info ?≪?????潟?????宴???????????f?渇????
1127 @return 0 success
1128 */
1129 ZEND_FUNCTION(vp_get_account)
1130 {
1131 long sid, uid;
1132 zval *zaccount;
1133
1134 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1135 &sid, &uid, &zaccount) == FAILURE) {
1136 fprintf( stderr, "error occured " );
1137 return;
1138 }
1139
1140 const account_t *paccount;
1141 result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
1142 if ( RES_OK == result ){
1143 accountToZval( paccount, zaccount );
1144 freeResult( paccount );
1145 }
1146
1147 RETURN_LONG(result);
1148 }
1149
1150 /** ?>散????眼?????≪?????潟???????宴??緇?????<br>
1151 int vp_get_accoutns( int sid, array uids, array criteria, array accounts );
1152 @param vp_session_id VP???祉???激?с??D
1153 @param user_id xoops_users.uid
1154 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1155 @param account_info ?≪?????潟?????宴???????????f?渇????
1156 @return 0 success
1157 */
1158 ZEND_FUNCTION(vp_get_accounts)
1159 {
1160 result_t result;
1161 long sid;
1162 zval *zuids;
1163 zval *zcriteria;
1164 zval *zaccount;
1165
1166 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1167 &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
1168 return;
1169 }
1170
1171 zCriteria_t zcri(zcriteria);
1172 result = zcri.getResult();
1173 if ( RES_OK == result ){
1174 zUIDs_t zUIDs(zuids);
1175 result = zUIDs.getResult();
1176 if ( RES_OK == result ){
1177 const account_t *paccounts;
1178 int accountLen;
1179 result = getAccounts( (sessionid_t)sid,
1180 zUIDs.getPUID(), zUIDs.getLen(),
1181 &zcri, &paccounts, &accountLen );
1182 if ( RES_OK == result ){
1183 accountsToZval( paccounts, accountLen, zaccount );
1184 freeResult( paccounts );
1185 }
1186 }
1187 }
1188
1189 RETURN_LONG(result);
1190 }
1191
1192 /** ?≪?????潟?????宴??緇?????<br>
1193 int vp_insert_account( int sid, array account_info );
1194 @param vp_session_id VP???祉???激?с??D
1195 @param user_id xoops_users.uid
1196 @param account_info ?≪?????潟?????宴???????????f?渇????
1197 @return 0 success
1198 */
1199 ZEND_FUNCTION(vp_insert_account)
1200 {
1201 result_t result;
1202 long sid;
1203 zval *zaccount;
1204
1205 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1206 &sid, &zaccount) == FAILURE) {
1207 return;
1208 }
1209
1210 zAccount_t zacc(zaccount);
1211 result = zacc.getResult();
1212 if ( RES_OK == result ){
1213 result = insertAccount( (sessionid_t)sid, &zacc );
1214 }
1215
1216 RETURN_LONG(result);
1217 }
1218
1219 /** ?≪?????潟?????宴???贋?違??????<br>
1220 int vp_update_account( int sid, array account );
1221 @param vp_session_id VP???祉???激?с??D
1222 @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
1223 @return 0 success
1224 */
1225 ZEND_FUNCTION(vp_update_account)
1226 {
1227 result_t result;
1228 long sid;
1229 zval *zaccount;
1230
1231 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1232 &sid, &zaccount) == FAILURE) {
1233 return;
1234 }
1235
1236 zAccount_t zacc(zaccount);
1237 result = zacc.getResult();
1238 if ( RES_OK == result ){
1239 result = updateAccount( (sessionid_t)sid, &zacc );
1240 }
1241
1242 RETURN_LONG(result);
1243 }
1244
1245 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
1246 int vp_dump_uids( int vp_session_id, array criteria, array uids );
1247 @param vp_session_id VP???祉???激?с??D
1248 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1249 @param uids uid??????????????
1250 @return 0 success
1251 */
1252 ZEND_FUNCTION(vp_dump_uids)
1253 {
1254 result_t result;
1255 long sid;
1256 zval *zcriteria;
1257 zval *zuids;
1258
1259 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1260 &sid, &zcriteria, &zuids) == FAILURE) {
1261 return;
1262 }
1263
1264 zCriteria_t zcri(zcriteria);
1265 result = zcri.getResult();
1266 if ( RES_OK == result ){
1267 userid_t *puid;
1268 int uidLen;
1269 result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1270 if ( RES_OK == result ){
1271 uidsToZval( puid, uidLen, &zuids );
1272 freeResult( puid );
1273 }
1274 }
1275
1276 RETURN_LONG(result);
1277 }
1278
1279 /** VP???違???若?????違??緇???<br>
1280 int vp_get_group_count( int vp_session_id );
1281 @param vp_session_id VP???祉???激?с??D
1282 @return ?違???若????/span>
1283 */
1284 ZEND_FUNCTION(vp_get_group_count)
1285 {
1286 result_t result;
1287 long sid;
1288
1289 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1290 &sid) == FAILURE) {
1291 return;
1292 }
1293
1294 int count = getGroupCount( (sessionid_t)sid );
1295
1296 RETURN_LONG(count);
1297 }
1298
1299 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
1300 int vp_get_group_by_uid( int vp_session_id, int uid, array criteria, array gids );
1301 @param vp_session_id VP???祉???激?с??D
1302 @param user_id xoops_users.uid
1303 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1304 @param gids gid??????????????
1305 @return 0 success
1306 */
1307 ZEND_FUNCTION(vp_get_groups_by_uid)
1308 {
1309 result_t result;
1310 long sid, uid;
1311 zval *zcriteria;
1312 zval *zgids;
1313
1314 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1315 &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1316 return;
1317 }
1318
1319 zCriteria_t zcri(zcriteria);
1320 result = zcri.getResult();
1321 if ( RES_OK == result ){
1322 groupid_t *pgids;
1323 int gidLen;
1324 result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1325 if ( RES_OK == result ){
1326 gidsToZval( pgids, gidLen, &zgids );
1327 freeResult( pgids );
1328 }
1329 }
1330
1331 RETURN_LONG(result);
1332 }
1333
1334
1335
1336 /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
1337 int vp_is_group_admin( int sid, int gid, int uid );
1338 @param vp_session_id VP???祉???激?с??D
1339 @param group_id VP???違???若??ID
1340 @param user_id xoops_users.uid
1341 @return true: ?違???若??膊∞?????с??????
1342 @return false: ?違???若??膊∞?????с???????????????????若?с??????
1343 */
1344 ZEND_FUNCTION(vp_is_group_admin)
1345 {
1346 result_t result;
1347 long sid, gid, uid;
1348
1349 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1350 &sid, &gid, &uid) == FAILURE) {
1351 return;
1352 }
1353
1354 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1355
1356 RETURN_BOOL(b);
1357 }
1358
1359 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
1360 int vp_dump_gids( int sid, array criteria, array gids );
1361 @param vp_session_id VP???祉???激?с??D
1362 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1363 @param gids gid??????????????
1364 @return 0 success
1365 */
1366 ZEND_FUNCTION(vp_dump_gids)
1367 {
1368 result_t result;
1369 long sid;
1370 zval *zcriteria;
1371 zval *zgids;
1372
1373 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1374 &sid, &zcriteria, &zgids) == FAILURE) {
1375 return;
1376 }
1377
1378 zCriteria_t zcri(zcriteria);
1379 result = zcri.getResult();
1380 if ( RES_OK == result ){
1381 groupid_t *pgid;
1382 int gidLen;
1383 result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1384 if ( RES_OK == result ){
1385 gidsToZval( pgid, gidLen, &zgids );
1386 freeResult( pgid );
1387 }
1388 }
1389
1390 RETURN_LONG(result);
1391 }
1392
1393 /** gid?ф??絎??????違???若??????????с?????ゆ?>散????眼?????違???若??膊∞??????id???荀с??緇?????<br>
1394 int vp_dump_group_admins(int sid, int group_id, array criteria, array uids )
1395 @param sid VP???祉???激?с??D
1396 @param group_id VP???違???若??ID
1397 @param criteria ?>散
1398 @param uids uid???荀с??????????????
1399 @return 0 success
1400 */
1401
1402 ZEND_FUNCTION(vp_dump_group_admins)
1403 {
1404 long sid, gid;
1405 zval *zcriteria;
1406 zval *zuids;
1407
1408 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1409 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1410 return;
1411 }
1412
1413 zCriteria_t zcri(zcriteria);
1414 result_t result = zcri.getResult();
1415 if ( result == RES_OK ){
1416 userid_t *uids;
1417 int uidsLen;
1418 result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1419 if ( result == RES_OK ){
1420 uidsToZval( uids, uidsLen, &zuids );
1421 freeResult( uids );
1422 }
1423 }
1424 RETURN_LONG( result );
1425 }
1426
1427 /** ?違???若???????<?潟???若?????ゃ??????<br>
1428 int vp_delete_member(int sid, int group_id, int user_id )
1429 @param sid VP???祉???激?с??D
1430 @param group_id VP???違???若??ID
1431 @param user_id ???若??D
1432 @return 0 success
1433 */
1434
1435 ZEND_FUNCTION(vp_delete_member)
1436 {
1437 long sid, gid, uid;
1438
1439 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1440 &sid, &gid, &uid) == FAILURE) {
1441 return;
1442 }
1443
1444 result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1445 RETURN_LONG( result );
1446 }
1447
1448 /** ?違???若?????<?潟???若??菴遵??????<br>
1449 int vp_insert_member(int sid, int group_id, int user_id, bool admin )
1450 @param sid VP???祉???激?с??D
1451 @param group_id VP???違???若??ID
1452 @param user_id ???若??D
1453 @param admin ?違???若??膊∞????????true
1454 @return 0 success
1455 */
1456
1457 ZEND_FUNCTION(vp_insert_member)
1458 {
1459 long sid, gid, uid;
1460 zend_bool admin;
1461
1462 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
1463 &sid, &gid, &uid, &admin) == FAILURE) {
1464 return;
1465 }
1466
1467 result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
1468 RETURN_LONG( result );
1469 }
1470
1471 /** gid?ф??絎??????違???若?????<?潟???若??id???荀с??緇???<br>
1472 int vp_get_members(int sid, int group_id, array criteria, array uids )
1473 @param sid VP???祉???激?с??D
1474 @param group_id VP???違???若??ID
1475 @param criteria ?>散
1476 @param uids uid???荀с??????????????
1477 @return 0 success
1478 */
1479
1480 ZEND_FUNCTION(vp_get_members)
1481 {
1482 long sid, gid;
1483 zval *zcriteria;
1484 zval *zuids;
1485
1486 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1487 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1488 return;
1489 }
1490
1491 zCriteria_t zcri(zcriteria);
1492 result_t result = zcri.getResult();
1493 if ( result == RES_OK ){
1494 userid_t *uids;
1495 int uidsLen;
1496 result = getMembers( (sessionid_t)sid, (groupid_t)gid, &zcri, &uids, &uidsLen );
1497 if ( result == RES_OK ){
1498 uidsToZval( uids, uidsLen, &zuids );
1499 freeResult( uids );
1500 }
1501 }
1502 RETURN_LONG( result );
1503 }
1504
1505 /** ?違???若?????宴??紊??眼??????<br>
1506 int vp_update_group(int sid, array group )
1507 @param sid VP???祉???激?с??D
1508 @param group ?違???若?????宴???f?渇????
1509 @return 0 success
1510 */
1511 ZEND_FUNCTION(vp_update_group)
1512 {
1513 long sid;
1514 zval *zgroup;
1515 group_t group;
1516
1517 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1518 &sid, &zgroup) == FAILURE) {
1519 return;
1520 }
1521
1522 zvalToGroup( zgroup, &group );
1523 result_t result = updateGroup( sid, &group );
1524 RETURN_LONG( result );
1525 }
1526
1527 /** ?違???若?????宴??菴遵????????<br>
1528 int vp_insert_group( int sid, array group )
1529 @param sid VP???祉???激?с??D
1530 @param group ?違???若?????宴???f?渇????
1531 @return RES_OK
1532 @return RES_DB_NOT_INITIALIZED
1533 @return RES_NO_SUCH_SESSION
1534 @return RES_DB_QUERY_ERROR
1535 */
1536 ZEND_FUNCTION(vp_insert_group)
1537 {
1538 long sid;
1539 zval *zgroup;
1540 group_t group;
1541
1542 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1543 &sid, &zgroup) == FAILURE) {
1544 return;
1545 }
1546
1547 zvalToGroup( zgroup, &group );
1548 result_t result = insertGroup( sid, &group );
1549 RETURN_LONG( result );
1550 }
1551
1552
1553 /** ?違???若?????宴?????ゃ??????<br>
1554 int vp_delete_group( int sid, int gid )
1555 @param sid VP???祉???激?с??D
1556 @param gid ???ゃ???????違???若????D
1557 @return RES_OK
1558 @return RES_DB_QUERY_ERROR
1559 @return RES_NO_SUCH_SESSION
1560 @return RES_DB_NOT_INITIALIZED
1561 */
1562 ZEND_FUNCTION(vp_delete_group)
1563 {
1564 long sid;
1565 long gid;
1566
1567 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1568 &sid, &gid) == FAILURE) {
1569 return;
1570 }
1571 RETURN_LONG( deleteGroup( sid, gid ) );
1572 }
1573
1574 /** ?違???若?????????????緇???<br>
1575 int vp_dump_group_admins( int sid, int gid, array criteria, array uids )
1576 @param sid VP???祉???激?с??D
1577 @param gid VP?違???若????D
1578 @param criteria uids???吾??莨若?????????純?若???>散鐚?膀??蚊????絎?
1579 @param uids 膊∞??????ID???吾??莨若??????
1580 @return RES_OK
1581 @return RES_DB_QUERY_ERROR
1582 @return RES_NO_SUCH_SESSION
1583 @return RES_DB_NOT_INITIALIZED
1584 */
1585 /*
1586 ZEND_FUNCTION(vp_dump_group_admins)
1587 {
1588 long sid;
1589 long gid;
1590 zval *zcriteria;
1591 zval *zuids;
1592
1593 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1594 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1595 return;
1596 }
1597 zCriteria_t zcri(zcriteria);
1598 result_t result = zcri.getResult();
1599 if ( RES_OK == result ){
1600 userid_t* uids;
1601 int uidsLen;
1602 result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1603 if( result != RES_OK ) RETURN_LONG( result );
1604 uidsToZval( uids, uidsLen, &zuids );
1605 fprintf( stderr, "uidsLen=%d\n", uidsLen );
1606 for( int i = 0; i < uidsLen; i++ ){
1607 fprintf( stderr, "%d, \n", uids[ i ] );
1608 }
1609 freeResult( uids );
1610 RETURN_LONG( result );
1611 }
1612 RETURN_LONG( result );
1613 }
1614 */
1615
1616 /** VP??ession_id???綵??с???с????lt;br>
1617 bool vp_is_valid_session_id( int vp_session_id)
1618 @return true ???鴻??P??ession_id?с????<br>
1619 @return false ?≦?鴻??ession_id?障??????????/span>
1620 */
1621 ZEND_FUNCTION(vp_is_valid_session_id)
1622 {
1623 long sid;
1624 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
1625 return;
1626 }
1627
1628 RETURN_BOOL(isValidSessionID((sessionid_t)sid));
1629 }
1630
1631 /** ?????惹??絖?????緇???<br>
1632 string vp_get_last_error_string()
1633 @return 0 success
1634 */
1635 ZEND_FUNCTION(vp_get_last_error_string)
1636 {
1637 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
1638 return;
1639 }
1640
1641 string str( getLastErrorString() );
1642 RETURN_STRING((char *)str.c_str(), 1);
1643 }
1644

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