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.17 - (show annotations) (download) (as text)
Mon Dec 6 07:22:38 2004 UTC (19 years, 4 months ago) by youi
Branch: MAIN
Changes since 1.16: +26 -18 lines
File MIME type: text/x-c++src
vi_insert_account 書き込んだアカウント情報のユーザIDを第三引数に書き込む.
vp_insert_group 書き込んだグループ情報のグループIDを第三引数に書き込む.

1 /*
2 $Revision: 1.16 $
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, int user_id, bool activated )
1064 @param vp_session_id vp ? session id
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, int &user_id );
1194 @param vp_session_id vp ? session id
1195 @param account_info 荐??蚊???????≪?????潟????????/span>
1196 @param user_id ???若??D(xoops_users.uid)???吾??莨若???????<???潟??/span>
1197 @return 0 success
1198 */
1199 ZEND_FUNCTION(vp_insert_account)
1200 {
1201 result_t result;
1202 long sid;
1203 zval *zaccount;
1204 zval *zuid;
1205 userid_t uid;
1206
1207 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1208 &sid, &zaccount, &zuid) == FAILURE) {
1209 return;
1210 }
1211
1212 zAccount_t zacc(zaccount);
1213 result = zacc.getResult();
1214 if ( RES_OK == result ){
1215 result = insertAccount( (sessionid_t)sid, &zacc, &uid );
1216 }
1217 zuid -> type = IS_LONG;
1218 zuid -> value.lval = uid;
1219 RETURN_LONG(result);
1220 }
1221
1222 /** ?≪?????潟?????宴???贋?違??????<br>
1223 int vp_update_account( int sid, array account );
1224 @param vp_session_id VP???祉???激?с??D
1225 @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
1226 @return 0 success
1227 */
1228 ZEND_FUNCTION(vp_update_account)
1229 {
1230 result_t result;
1231 long sid;
1232 zval *zaccount;
1233
1234 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1235 &sid, &zaccount) == FAILURE) {
1236 return;
1237 }
1238
1239 zAccount_t zacc(zaccount);
1240 result = zacc.getResult();
1241 if ( RES_OK == result ){
1242 result = updateAccount( (sessionid_t)sid, &zacc );
1243 }
1244
1245 RETURN_LONG(result);
1246 }
1247
1248 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
1249 int vp_dump_uids( int vp_session_id, array criteria, array uids );
1250 @param vp_session_id VP???祉???激?с??D
1251 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1252 @param uids uid??????????????
1253 @return 0 success
1254 */
1255 ZEND_FUNCTION(vp_dump_uids)
1256 {
1257 result_t result;
1258 long sid;
1259 zval *zcriteria;
1260 zval *zuids;
1261
1262 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1263 &sid, &zcriteria, &zuids) == FAILURE) {
1264 return;
1265 }
1266
1267 zCriteria_t zcri(zcriteria);
1268 result = zcri.getResult();
1269 if ( RES_OK == result ){
1270 userid_t *puid;
1271 int uidLen;
1272 result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1273 if ( RES_OK == result ){
1274 uidsToZval( puid, uidLen, &zuids );
1275 freeResult( puid );
1276 }
1277 }
1278
1279 RETURN_LONG(result);
1280 }
1281
1282 /** VP???違???若?????違??緇???<br>
1283 int vp_get_group_count( int vp_session_id );
1284 @param vp_session_id VP???祉???激?с??D
1285 @return ?違???若????/span>
1286 */
1287 ZEND_FUNCTION(vp_get_group_count)
1288 {
1289 result_t result;
1290 long sid;
1291
1292 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1293 &sid) == FAILURE) {
1294 return;
1295 }
1296
1297 int count = getGroupCount( (sessionid_t)sid );
1298
1299 RETURN_LONG(count);
1300 }
1301
1302 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
1303 int vp_get_group_by_uid( int vp_session_id, int uid, array criteria, array gids );
1304 @param vp_session_id VP???祉???激?с??D
1305 @param user_id xoops_users.uid
1306 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1307 @param gids gid??????????????
1308 @return 0 success
1309 */
1310 ZEND_FUNCTION(vp_get_groups_by_uid)
1311 {
1312 result_t result;
1313 long sid, uid;
1314 zval *zcriteria;
1315 zval *zgids;
1316
1317 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1318 &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1319 return;
1320 }
1321
1322 zCriteria_t zcri(zcriteria);
1323 result = zcri.getResult();
1324 if ( RES_OK == result ){
1325 groupid_t *pgids;
1326 int gidLen;
1327 result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1328 if ( RES_OK == result ){
1329 gidsToZval( pgids, gidLen, &zgids );
1330 freeResult( pgids );
1331 }
1332 }
1333
1334 RETURN_LONG(result);
1335 }
1336
1337
1338
1339 /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
1340 int vp_is_group_admin( int sid, int gid, int uid );
1341 @param vp_session_id VP???祉???激?с??D
1342 @param group_id VP???違???若??ID
1343 @param user_id xoops_users.uid
1344 @return true: ?違???若??膊∞?????с??????
1345 @return false: ?違???若??膊∞?????с???????????????????若?с??????
1346 */
1347 ZEND_FUNCTION(vp_is_group_admin)
1348 {
1349 result_t result;
1350 long sid, gid, uid;
1351
1352 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1353 &sid, &gid, &uid) == FAILURE) {
1354 return;
1355 }
1356
1357 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1358
1359 RETURN_BOOL(b);
1360 }
1361
1362 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
1363 int vp_dump_gids( int sid, array criteria, array gids );
1364 @param vp_session_id VP???祉???激?с??D
1365 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1366 @param gids gid??????????????
1367 @return 0 success
1368 */
1369 ZEND_FUNCTION(vp_dump_gids)
1370 {
1371 result_t result;
1372 long sid;
1373 zval *zcriteria;
1374 zval *zgids;
1375
1376 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1377 &sid, &zcriteria, &zgids) == FAILURE) {
1378 return;
1379 }
1380
1381 zCriteria_t zcri(zcriteria);
1382 result = zcri.getResult();
1383 if ( RES_OK == result ){
1384 groupid_t *pgid;
1385 int gidLen;
1386 result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1387 if ( RES_OK == result ){
1388 gidsToZval( pgid, gidLen, &zgids );
1389 freeResult( pgid );
1390 }
1391 }
1392
1393 RETURN_LONG(result);
1394 }
1395
1396 /** gid?ф??絎??????違???若??????????с?????ゆ?>散????眼?????違???若??膊∞??????id???荀с??緇?????<br>
1397 int vp_dump_group_admins(int sid, int group_id, array criteria, array uids )
1398 @param sid VP???祉???激?с??D
1399 @param group_id VP???違???若??ID
1400 @param criteria ?>散
1401 @param uids uid???荀с??????????????
1402 @return 0 success
1403 */
1404
1405 ZEND_FUNCTION(vp_dump_group_admins)
1406 {
1407 long sid, gid;
1408 zval *zcriteria;
1409 zval *zuids;
1410
1411 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1412 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1413 return;
1414 }
1415
1416 zCriteria_t zcri(zcriteria);
1417 result_t result = zcri.getResult();
1418 if ( result == RES_OK ){
1419 userid_t *uids;
1420 int uidsLen;
1421 result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1422 if ( result == RES_OK ){
1423 uidsToZval( uids, uidsLen, &zuids );
1424 freeResult( uids );
1425 }
1426 }
1427 RETURN_LONG( result );
1428 }
1429
1430 /** ?違???若???????<?潟???若?????ゃ??????<br>
1431 int vp_delete_member(int sid, int group_id, int user_id )
1432 @param sid VP???祉???激?с??D
1433 @param group_id VP???違???若??ID
1434 @param user_id ???若??D
1435 @return 0 success
1436 */
1437
1438 ZEND_FUNCTION(vp_delete_member)
1439 {
1440 long sid, gid, uid;
1441
1442 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1443 &sid, &gid, &uid) == FAILURE) {
1444 return;
1445 }
1446
1447 result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1448 RETURN_LONG( result );
1449 }
1450
1451 /** ?違???若?????<?潟???若??菴遵??????<br>
1452 int vp_insert_member(int sid, int group_id, int user_id, bool admin )
1453 @param sid VP???祉???激?с??D
1454 @param group_id VP???違???若??ID
1455 @param user_id ???若??D
1456 @param admin ?違???若??膊∞????????true
1457 @return 0 success
1458 */
1459
1460 ZEND_FUNCTION(vp_insert_member)
1461 {
1462 long sid, gid, uid;
1463 zend_bool admin;
1464
1465 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
1466 &sid, &gid, &uid, &admin) == FAILURE) {
1467 return;
1468 }
1469
1470 result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
1471 RETURN_LONG( result );
1472 }
1473
1474 /** gid?ф??絎??????違???若?????<?潟???若??id???荀с??緇???<br>
1475 int vp_get_members(int sid, int group_id, array criteria, array uids )
1476 @param sid VP???祉???激?с??D
1477 @param group_id VP???違???若??ID
1478 @param criteria ?>散
1479 @param uids uid???荀с??????????????
1480 @return 0 success
1481 */
1482
1483 ZEND_FUNCTION(vp_get_members)
1484 {
1485 long sid, gid;
1486 zval *zcriteria;
1487 zval *zuids;
1488
1489 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1490 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1491 return;
1492 }
1493
1494 zCriteria_t zcri(zcriteria);
1495 result_t result = zcri.getResult();
1496 if ( result == RES_OK ){
1497 userid_t *uids;
1498 int uidsLen;
1499 result = getMembers( (sessionid_t)sid, (groupid_t)gid, &zcri, &uids, &uidsLen );
1500 if ( result == RES_OK ){
1501 uidsToZval( uids, uidsLen, &zuids );
1502 freeResult( uids );
1503 }
1504 }
1505 RETURN_LONG( result );
1506 }
1507
1508 /** ?違???若?????宴??紊??眼??????<br>
1509 int vp_update_group(int sid, array group )
1510 @param sid VP???祉???激?с??D
1511 @param group ?違???若?????宴???f?渇????
1512 @return 0 success
1513 */
1514 ZEND_FUNCTION(vp_update_group)
1515 {
1516 long sid;
1517 zval *zgroup;
1518 group_t group;
1519
1520 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1521 &sid, &zgroup) == FAILURE) {
1522 return;
1523 }
1524
1525 zvalToGroup( zgroup, &group );
1526 result_t result = updateGroup( sid, &group );
1527 RETURN_LONG( result );
1528 }
1529
1530 /** ?違???若?????宴??菴遵????????<br>
1531 int vp_insert_group( int sid, array group, int &gid )
1532 @param sid ?祉???激?с??D
1533 @param group ?違???若?????宴???f?渇????
1534 @param gid 絲上??????違???若??ID???吾??莨若???????<???潟??/span>
1535 @return RES_OK
1536 @return RES_DB_NOT_INITIALIZED
1537 @return RES_NO_SUCH_SESSION
1538 @return RES_DB_QUERY_ERROR
1539 */
1540 ZEND_FUNCTION(vp_insert_group)
1541 {
1542 long sid;
1543 zval *zgroup;
1544 zval *zgid;
1545 group_t group;
1546 groupid_t gid;
1547
1548 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1549 &sid, &zgroup, &zgid ) == FAILURE) {
1550 return;
1551 }
1552
1553 zvalToGroup( zgroup, &group );
1554 result_t result = insertGroup( sid, &group, &gid );
1555 zgid -> type = IS_LONG;
1556 zgid -> value.lval = gid;
1557 RETURN_LONG( result );
1558 }
1559
1560
1561 /** ?違???若?????宴?????ゃ??????<br>
1562 int vp_delete_group( int sid, int gid )
1563 @param sid VP???祉???激?с??D
1564 @param gid ???ゃ???????違???若????D
1565 @return RES_OK
1566 @return RES_DB_QUERY_ERROR
1567 @return RES_NO_SUCH_SESSION
1568 @return RES_DB_NOT_INITIALIZED
1569 */
1570 ZEND_FUNCTION(vp_delete_group)
1571 {
1572 long sid;
1573 long gid;
1574
1575 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1576 &sid, &gid) == FAILURE) {
1577 return;
1578 }
1579 RETURN_LONG( deleteGroup( sid, gid ) );
1580 }
1581
1582 /** ?違???若?????????????緇???<br>
1583 int vp_dump_group_admins( int sid, int gid, array criteria, array uids )
1584 @param sid VP???祉???激?с??D
1585 @param gid VP?違???若????D
1586 @param criteria uids???吾??莨若?????????純?若???>散鐚?膀??蚊????絎?
1587 @param uids 膊∞??????ID???吾??莨若??????
1588 @return RES_OK
1589 @return RES_DB_QUERY_ERROR
1590 @return RES_NO_SUCH_SESSION
1591 @return RES_DB_NOT_INITIALIZED
1592 */
1593 /*
1594 ZEND_FUNCTION(vp_dump_group_admins)
1595 {
1596 long sid;
1597 long gid;
1598 zval *zcriteria;
1599 zval *zuids;
1600
1601 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1602 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1603 return;
1604 }
1605 zCriteria_t zcri(zcriteria);
1606 result_t result = zcri.getResult();
1607 if ( RES_OK == result ){
1608 userid_t* uids;
1609 int uidsLen;
1610 result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1611 if( result != RES_OK ) RETURN_LONG( result );
1612 uidsToZval( uids, uidsLen, &zuids );
1613 fprintf( stderr, "uidsLen=%d\n", uidsLen );
1614 for( int i = 0; i < uidsLen; i++ ){
1615 fprintf( stderr, "%d, \n", uids[ i ] );
1616 }
1617 freeResult( uids );
1618 RETURN_LONG( result );
1619 }
1620 RETURN_LONG( result );
1621 }
1622 */
1623
1624 /** VP??ession_id???綵??с???с????lt;br>
1625 bool vp_is_valid_session_id( int vp_session_id)
1626 @return true ???鴻??P??ession_id?с????<br>
1627 @return false ?≦?鴻??ession_id?障??????????/span>
1628 */
1629 ZEND_FUNCTION(vp_is_valid_session_id)
1630 {
1631 long sid;
1632 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
1633 return;
1634 }
1635
1636 RETURN_BOOL(isValidSessionID((sessionid_t)sid));
1637 }
1638
1639 /** ?????惹??絖?????緇???<br>
1640 string vp_get_last_error_string()
1641 @return 0 success
1642 */
1643 ZEND_FUNCTION(vp_get_last_error_string)
1644 {
1645 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
1646 return;
1647 }
1648
1649 string str( getLastErrorString() );
1650 RETURN_STRING((char *)str.c_str(), 1);
1651 }
1652

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