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.7 - (show annotations) (download) (as text)
Wed Dec 1 01:02:35 2004 UTC (19 years, 4 months ago) by youi
Branch: MAIN
Changes since 1.6: +65 -10 lines
File MIME type: text/x-c++src
zvalToGroupを定義.
vp_update_groupを定義.

1 /*
2 VPAL: Visiome Platform Abstract Layer
3
4 zend_parse_parameters??hp4.1.0??綽?荀?
5 .so???<?ゃ?????????荀????????贋????舟??鴻????
6 C++?с????extern "C"{}, BEGIN/END_EXTERN_C()??綽?荀???
7 */
8
9
10 #include <stdio.h>
11 #include "criteria.h"
12 #include "common.h"
13 #include "commonal.h"
14 #include "session.h"
15 #include "group.h"
16 #include "account.h"
17 #include "vpal.h"
18
19 // for inet_aton
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
23
24 // global variables
25 MYSQL *mysql = NULL;
26
27
28 /* declaration of functions to be exported */
29 extern "C" {
30 ZEND_FUNCTION(first_module );
31 ZEND_FUNCTION(vp_initialize_db );
32 ZEND_FUNCTION(vp_login_user );
33 ZEND_FUNCTION(vp_logout_user );
34 ZEND_FUNCTION(vp_create_session );
35 ZEND_FUNCTION(vp_get_session );
36 ZEND_FUNCTION(vp_is_activated );
37 ZEND_FUNCTION(vp_activate );
38 ZEND_FUNCTION(vp_get_account_count );
39 ZEND_FUNCTION(vp_delete_account );
40 ZEND_FUNCTION(vp_get_account );
41 ZEND_FUNCTION(vp_get_accounts );
42 ZEND_FUNCTION(vp_insert_account );
43 ZEND_FUNCTION(vp_update_account );
44 ZEND_FUNCTION(vp_dump_uids );
45 ZEND_FUNCTION(vp_get_group_count );
46 ZEND_FUNCTION(vp_get_groups_by_uid );
47 ZEND_FUNCTION(vp_is_group_admin );
48 ZEND_FUNCTION(vp_dump_gids );
49 /*
50 ZEND_FUNCTION(vp_dump_group_admins );
51 ZEND_FUNCTION(vp_delete_member );
52 ZEND_FUNCTION(vp_insert_member );
53 ZEND_FUNCTION(vp_get_members );
54 ZEND_FUNCTION(vp_delete_group );
55 ZEND_FUNCTION(vp_insert_group );
56 */
57 ZEND_FUNCTION(vp_update_group );
58 ZEND_FUNCTION(vp_get_group );
59 ZEND_FUNCTION(vp_get_groups );
60 ZEND_FUNCTION(vp_is_moderator );
61 ZEND_FUNCTION(vp_get_uid );
62
63 ZEND_FUNCTION(vp_test_criteria );
64 ZEND_FUNCTION(vp_test_uids );
65 };
66 /* compiled function list so Zend knows what's in this module */
67 zend_function_entry vpalmod_functions[] =
68 {
69 ZEND_FE(first_module ,NULL)
70 ZEND_FE(vp_initialize_db ,NULL)
71 ZEND_FE(vp_login_user ,NULL)
72 ZEND_FE(vp_logout_user ,NULL)
73 ZEND_FE(vp_create_session ,NULL)
74 ZEND_FE(vp_get_session ,NULL)
75 ZEND_FE(vp_is_activated ,NULL)
76 ZEND_FE(vp_activate ,NULL)
77 ZEND_FE(vp_get_account_count ,NULL)
78 ZEND_FE(vp_delete_account ,NULL)
79 ZEND_FE(vp_get_account ,NULL)
80 ZEND_FE(vp_get_accounts ,NULL)
81 ZEND_FE(vp_insert_account ,NULL)
82 ZEND_FE(vp_update_account ,NULL)
83 ZEND_FE(vp_dump_uids ,NULL)
84 ZEND_FE(vp_get_group_count ,NULL)
85 ZEND_FE(vp_get_groups_by_uid ,NULL)
86 ZEND_FE(vp_is_group_admin ,NULL)
87 ZEND_FE(vp_dump_gids ,NULL)
88 /*
89 ZEND_FE(vp_dump_group_admins ,NULL)
90 ZEND_FE(vp_delete_member ,NULL)
91 ZEND_FE(vp_insert_member ,NULL)
92 ZEND_FE(vp_get_members ,NULL)
93 ZEND_FE(vp_delete_group ,NULL)
94 ZEND_FE(vp_insert_group ,NULL)
95 */
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_test_criteria ,NULL)
102 ZEND_FE(vp_test_uids ,NULL)
103 {NULL, NULL, NULL}
104 };
105
106 /* compiled module information */
107 zend_module_entry vpalmod_module_entry =
108 {
109 STANDARD_MODULE_HEADER,
110 "Visiome Platform Abstract Layer",
111 vpalmod_functions,
112 NULL,
113 NULL,
114 NULL,
115 NULL,
116 NULL,
117 NO_VERSION_YET,
118 STANDARD_MODULE_PROPERTIES
119 };
120
121 /* implement standard "stub" routine to introduce ourselves to Zend */
122 #if COMPILE_DL_FIRST_MODULE
123 BEGIN_EXTERN_C()
124 ZEND_GET_MODULE(vpalmod)
125 END_EXTERN_C()
126 #endif
127
128 /* implement function that is meant to be made available to PHP */
129 ZEND_FUNCTION(first_module)
130 {
131 long parameter;
132 // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
133 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
134 return;
135 }
136 parameter++;
137 RETURN_LONG(parameter);
138 }
139 /** zval????C????絖?????緇?????
140 */
141 char *getZvalString( zval **p ){
142 convert_to_string_ex(p);
143 return Z_STRVAL_PP(p); //(**p).value.str.val;
144 }
145
146 /** zval????int??緇?????
147 */
148 int getZvalInt( zval **p ){
149 convert_to_long_ex(p);
150 return Z_LVAL_PP(p); // (int)(**p).value.lval;
151 }
152
153 // keylen????鮎??0????????
154 static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
155 zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
156 if ( res == HASH_KEY_IS_STRING ){
157 char *p = new char[keyLen+1];
158 memcpy( p, key, keyLen );
159 p[keyLen] = 0;
160 zend_printf( " key is string[%s]<br>\n", p );
161 }
162 else {
163 zend_printf( " key is integer[%d]<br>\n", index );
164 }
165 }
166
167
168 /** zval**????criteria_t?????????????????????鴻??????紊掩??????getResult()!=RES_OK
169 * criteria :
170 array( 'start'=>0, 'rows'=>10,
171 'orders'=>array(
172 array('name'=>'id','order'=>'0'),
173 array('name'=>'timestamp','name'=>'1'), ...)
174 ); ??????就???f?渇????
175 */
176 class zCriteria_t : public criteria {
177 private:
178 result_t result;
179 public:
180 // pz: array('name'=>'timestamp','name'=>'1')
181 // ????????orderby??篏???????申????
182 void setOrder( zval *pz ){
183 char *column = 0;
184 order_t order = (order_t)0;
185
186 HashPosition pos;
187 zval **ppzTmp = 0;
188 int res2;
189 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
190 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
191 char *key = 0;
192 uint keyLen = 0;
193 ulong index = 0;
194 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
195 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
196 print_hash_key( keyType, key, keyLen, index );
197 if ( strncasecmp( key, "column", keyLen ) == 0 && keyLen == 7 ){
198 SEPARATE_ZVAL(ppzTmp);
199 column = getZvalString(ppzTmp);
200 // zend_printf( "column=%s<br>\n", column );
201 }
202 else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
203 SEPARATE_ZVAL(ppzTmp);
204 order = (order_t)getZvalInt(ppzTmp);
205 // zend_printf( "order=%d<br>\n", order );
206 }
207 }
208
209 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
210 }
211 if ( column ){
212 orderby *o = new orderby( column, order );
213 addOrderBy( o );
214 }
215
216 result = RES_OK;
217 }
218
219 // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
220 void setOrders( zval *pz ){
221 HashPosition pos;
222
223 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
224
225 zval **ppzTmp = 0;
226 int res2;
227 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
228 char *key = 0;
229 uint keyLen = 0;
230 ulong index = 0;
231 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
232 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
233 print_hash_key( keyType, key, keyLen, index );
234 setOrder( *ppzTmp );
235 }
236 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
237 }
238 result = RES_OK;
239 }
240
241 void initialize( zval *pz ){
242 HashPosition pos;
243 zval **ppzTmp = 0;
244 int res2;
245 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
246 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
247 char *key = 0;
248 uint keyLen = 0;
249 ulong index = 0;
250 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
251 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
252 print_hash_key( keyType, key, keyLen, index );
253 if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
254 SEPARATE_ZVAL(ppzTmp);
255 int tmp = getZvalInt(ppzTmp);
256 // zend_printf( "start=%d<br>\n", tmp );
257 setLimit( tmp, getLimitRows() );
258 }
259 else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
260 SEPARATE_ZVAL(ppzTmp);
261 int tmp = getZvalInt(ppzTmp);
262 // zend_printf( "rows=%d<br>\n", tmp );
263 setLimit( getLimitStart(), tmp );
264 }
265 else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
266 setOrders( *ppzTmp );
267 }
268 else
269 ; // ignore unknown key
270 }
271 else
272 ; // ignore bad key
273 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
274 }
275 result = RES_OK;
276 }
277 zCriteria_t() : criteria(){ result = RES_ERROR; }
278 zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
279 zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
280 result_t getResult(){ return result; };
281
282 void dump(){
283 zend_printf( "dumping zCriteria...<br>\n" );
284 zend_printf( "result=%d<br>\n", (int)result );
285 zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() );
286 const orderby *p = headOrderBy();
287 while ( p ){
288 zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() );
289 p = nextOrderBy();
290 }
291 }
292 };
293
294
295 class zAccount_t : public account {
296 private:
297 result_t result;
298 public:
299 void initialize(zval *pz){
300 ; // todo
301 }
302 zAccount_t() : account(){ result = RES_ERROR; }
303 zAccount_t( zval *pz ) : account(){ initialize(pz); }
304 zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
305 result_t getResult(){ return result; };
306 };
307
308 /** zval**????(userid_t *puid,int uidLen)?????????????????????鴻??????紊掩??????getResult()!=RES_OK
309 uids : array( '1', '3', '4', '6', ... ); ??????就??????
310 */
311 class zUIDs_t {
312 private:
313 result_t result;
314 userid_t *pUID;
315 int len;
316 public:
317 zUIDs_t(){
318 pUID = 0;
319 len = 0;
320 result = RES_ERROR;
321 }
322
323 zUIDs_t( zval *pza ){
324 pUID = 0;
325 len = 0;
326 result = RES_ERROR;
327
328 if ( Z_TYPE_P(pza) != IS_ARRAY ){
329 result = RES_ERROR;
330 }
331 else {
332 len = zend_hash_num_elements(Z_ARRVAL_P(pza));
333 if(len == 0) {
334 pUID = new userid_t[1];
335 result = RES_OK;
336 }
337 else {
338 /* php/ext/standard/string.c ? implode??????????????????
339 zend_hash_*???????ャ?<?潟???c????????????????鐚?
340 */
341 zval **tmp;
342 HashPosition pos;
343 int i = 0;
344 pUID = new userid_t[len];
345
346 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
347 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
348 SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
349 convert_to_long_ex(tmp);
350 if ( i < len )
351 pUID[i++] = Z_LVAL_PP(tmp);
352 zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
353 }
354 len = i;
355 result = RES_OK;
356 }
357 }
358 }
359
360 ~zUIDs_t(){
361 if ( pUID ) delete[] pUID;
362 }
363 result_t getResult(){ return result; }
364 userid_t *getPUID(){ return pUID; }
365 int getLen(){ return len; }
366 void dump(){
367 zend_printf( "dumping zUIDs...<br>\n" );
368 zend_printf( "result=%d<br>\n", (int)result );
369 zend_printf( "len=%d<br>\n", len );
370 for ( int i = 0; i < len; i++ ){
371 zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
372 }
373 }
374 };
375
376 /** uids_t ?? zval
377 */
378 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
379 {
380 zval *pz;
381
382 // create new array
383 MAKE_STD_ZVAL(pz);
384 array_init(pz);
385
386 // add UIDs
387 for ( int i = 0; i < len; i++ ){
388 add_next_index_long(pz, (long)(pUID[i]) );
389 }
390
391 // return array
392 *ppz = pz;
393 return RES_OK;
394 }
395 /** uids_t ?? zval
396 */
397 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
398 {
399 zval *pz;
400
401 // create new array
402 MAKE_STD_ZVAL(pz);
403 array_init(pz);
404
405 // add GIDs
406 for ( int i = 0; i < len; i++ ){
407 add_next_index_long(pz, (long)(pGID[i]) );
408 }
409
410 // return array
411 *ppz = pz;
412 return RES_OK;
413 }
414
415 result_t accountToZval( const account_t *pAccount, zval *z )
416 {
417 zend_hash_clean( z -> value.ht );
418
419 add_assoc_long( z, "uid", pAccount -> getUID( ) );
420 add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
421 add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
422 add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
423 add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
424 add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
425 add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
426 add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
427 add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
428 add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
429 add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
430 add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
431 add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
432 add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
433 add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
434 add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
435 add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
436 add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
437 add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
438 add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
439 add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
440 add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
441 add_assoc_long( z, "level", pAccount -> getLevel( ) );
442 add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
443 add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
444 add_assoc_long( z, "posts", pAccount -> getPosts( ) );
445 add_assoc_long( z, "rank", pAccount -> getRank( ) );
446 add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
447 add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
448 add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
449 add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
450
451 add_assoc_long( z, "activate", pAccount -> getActivate( ) );
452 add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
453 add_assoc_string( z, "institute", ( char* )pAccount -> getInstitute( ), 1 );
454 add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
455 add_assoc_string( z, "organization", ( char* )pAccount -> getOrganization( ), 1 );
456 add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
457 add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
458 add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
459 add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
460 add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
461 add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
462 return RES_OK;
463 }
464
465 /** accounts ?? zval
466 * accounts: ????????????????
467 array(
468 array(
469 'uid'=>100,
470 'activate'=>1,
471 'institute'=>'foo',
472 'tel'=>'123-456-789',
473 ...
474 ),
475 ...
476 )
477 */
478 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
479 {
480 zend_hash_clean( z -> value.ht );
481 for( int i = 0; i < accountsLen; i++ ){
482 zval *new_array;
483 MAKE_STD_ZVAL(new_array);
484 if(array_init(new_array) != SUCCESS){
485 return RES_ERROR;
486 }
487 add_index_zval( z, i, new_array );
488 accountToZval( &pAccounts[ i ], new_array );
489 }
490 return RES_OK;
491 }
492
493 /** groups ?? zval
494 */
495 result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
496 {
497 zend_hash_clean( z -> value.ht );
498 for( int i = 0; i < groupsLen; i++ ){
499 zval *new_array;
500 MAKE_STD_ZVAL(new_array);
501 if(array_init(new_array) != SUCCESS){
502 return RES_ERROR;
503 }
504 add_index_zval( z, i, new_array );
505 add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
506 add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
507 add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
508 }
509 return RES_OK;
510 }
511
512 /**
513 *
514 * group_t????絎鴻??PHP???f?渇?????????????
515 *
516 * @param pGroup 紊??????????違???若??????/span>
517 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
518 * @return RES_OK
519 *
520 */
521 result_t groupToZval( const group_t *pGroup, zval *z )
522 {
523 zend_hash_clean( z -> value.ht );
524 add_assoc_long( z, "gid", pGroup -> getGID( ) );
525 add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
526 add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
527 return RES_OK;
528 }
529
530 /** zval ?? group
531 */
532 result_t zvalToGroup( zval *z, group_t *pGroup )
533 {
534 zval **tmp;
535 HashPosition pos;
536 int i = 0;
537 char* key = 0;
538
539 key = "gid";
540 zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp );
541 convert_to_long_ex( tmp ) ;
542 pGroup -> setGID( (*tmp) -> value.lval );
543
544 key = "gname";
545 zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp );
546 convert_to_string_ex( tmp ) ;
547 pGroup -> setGname( (*tmp) -> value.str.val );
548
549 key = "gdesc";
550 zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp );
551 convert_to_string_ex( tmp ) ;
552 pGroup -> setDesc( (*tmp) -> value.str.val );
553
554 return RES_OK;
555 }
556
557
558 // int vp_get_group( int sid, int gid, array group );
559 ZEND_FUNCTION(vp_get_group)
560 {
561 long sid, gid;
562 zval *zgroup;
563
564 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
565 &sid, &gid, &zgroup) == FAILURE) {
566 return;
567 }
568
569 const group_t *pgroup;
570 result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
571 if ( RES_OK == result ){
572 groupToZval( pgroup, zgroup );
573 freeResult( pgroup );
574 }
575
576 RETURN_LONG(result);
577 }
578
579
580 // int vp_get_groups( int sid, array gids, array criteria, array groups );
581 ZEND_FUNCTION(vp_get_groups)
582 {
583 result_t result;
584 long sid, uid;
585 zval *zcriteria;
586 zval *zgids;
587 zval *zgroups;
588 zval **ppzTmp = 0;
589 HashPosition pos;
590 int res2;
591 int gidsLen;
592 const group_t* groups;
593 int groupsLen;
594
595 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
596 &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
597 return;
598 }
599
600 //gids???違???若??ID???潟???若????
601 gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
602 groupid_t *gids = new groupid_t[ gidsLen ];
603 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
604 for( int i = 0; i < gidsLen; i++ ){
605 if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
606 SEPARATE_ZVAL(ppzTmp);
607 convert_to_long_ex(ppzTmp);
608 gids[ i ] = Z_LVAL_PP(ppzTmp);
609 }
610 zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
611 }
612
613 zCriteria_t zcri(zcriteria);
614 result = zcri.getResult();
615 if ( RES_OK == result ){
616 result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
617 if ( RES_OK == result ){
618 delete[] gids;
619 freeResult( groups );
620 }
621 }
622 groupsToZval( groups, groupsLen, zgroups );
623 RETURN_LONG(result);
624 }
625
626
627 // int vp_is_moderator(string uname)
628 ZEND_FUNCTION(vp_is_moderator)
629 {
630 long vpSessionID;
631 userid_t uid;
632
633 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
634 &vpSessionID, &uid) == FAILURE) {
635 return;
636 }
637
638 bool result = isModerator( (sessionid_t)vpSessionID, uid );
639 RETURN_BOOL(result)
640 }
641
642 // int vp_get_uid(string uname)
643 ZEND_FUNCTION(vp_get_uid)
644 {
645 char *uname;
646 int unameLen;
647 userid_t uid;
648
649 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
650 &uname, &unameLen) == FAILURE) {
651 return;
652 }
653
654 string strUname( uname, unameLen );
655 result_t result = getUid( strUname.c_str(), &uid );
656 if ( result == RES_OK ){
657 RETURN_LONG((long)uid);
658 }
659 else {
660 //zend_printf( "vpal_debug: vp_get_uid(%s): result=%d<br>\n", strUname.c_str(),(int)result );
661 RETURN_FALSE
662 }
663 }
664
665 /** session ?? zval
666 */
667 result_t sessionToZval( const session_t *pSession, zval *z )
668 {
669 string sessionID(unsignedIntToString(pSession->getSessionID()));
670 add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
671
672 string date(unsignedIntToString((unsigned int)pSession->getDate()));
673 add_assoc_string(z, "date", (char *)date.c_str(), 1);
674
675 string userID(unsignedIntToString((unsigned int)pSession->getUserID()));
676 add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
677
678 return RES_OK;
679 }
680
681 ZEND_FUNCTION(vp_test_criteria)
682 {
683 zval *z;
684
685 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
686 &z) == FAILURE) {
687 return;
688 }
689 zend_printf("zend_printf...<br>\n");
690 zCriteria_t zcri(z);
691 zcri.dump();
692 RETURN_FALSE
693 }
694
695 ZEND_FUNCTION(vp_test_uids)
696 {
697 zval *z;
698
699 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
700 &z) == FAILURE) {
701 return;
702 }
703 zend_printf("zend_printf...<br>\n");
704 zUIDs_t zuids(z);
705 zuids.dump();
706 RETURN_FALSE
707 }
708
709
710
711 /** DB??・膓????????≪??・膓?筝???・膓???????????????<br>
712 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
713 @param host ?ョ????????ユ????ULL
714 @param user DB?ョ????????若?九???????ユ????ULL
715 @param password DB?ョ????????鴻???若???????ユ????ULL
716 @param dbname DB?ョ?????B???????ユ????quot;"
717 @param prefix XOOPS DB ??refix??
718 @return 0 success <br>
719 */
720 ZEND_FUNCTION(vp_initialize_db)
721 {
722 zval **parameters[5];
723 char *host;
724 char *user;
725 char *password;
726 char *dbname;
727 char *prefix;
728
729 /* get the number of arguments */
730 int argNum = ZEND_NUM_ARGS();
731 if (argNum > 5)
732 WRONG_PARAM_COUNT;
733
734 /* argument count is correct, now retrieve arguments */
735 if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
736 WRONG_PARAM_COUNT;
737
738 if (argNum < 1) host = NULL;
739 else host = getZvalString( parameters[0] );
740
741 if (argNum < 2) user = NULL;
742 else user = getZvalString( parameters[1] );
743
744 if (argNum < 3) password = NULL;
745 else password = getZvalString( parameters[2] );
746
747 if (argNum < 4) dbname = "";
748 else dbname = getZvalString( parameters[3] );
749
750 if (argNum < 5) prefix = "";
751 else prefix = getZvalString( parameters[4] );
752
753 result_t result = initializeDB( host, user, password, dbname, prefix );
754
755 RETURN_LONG(result);
756 }
757
758 /** ???違?ゃ?潟??????<br>
759 int vp_login_user(string uname, string password)
760 @param uname ???若?九??(xoops_users.uname)
761 @param password ???鴻???若??(md5(password)=xoops_users.pass)
762 @return 0 success
763 */
764 ZEND_FUNCTION(vp_login_user)
765 {
766 char *uname;
767 int unameLen;
768 char *passwd;
769 int passwdLen;
770
771 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
772 &uname, &unameLen, &passwd, &passwdLen) == FAILURE) {
773 return;
774 }
775
776 sessionid_t vpSessionID;
777 result_t result = loginUser( uname, passwd, &vpSessionID );
778 if ( result == RES_OK ){
779 RETURN_LONG((long)vpSessionID);
780 }
781 else {
782 //zend_printf( "vpal_debug: vp_login_user(%s, %s): cannot login. result=%d<br>\n", strUname.c_str(), strPasswd.c_str(), (int)result );
783 RETURN_FALSE
784 }
785 }
786
787 /** ???違?≪??????????<br>
788 void vp_logout_user(int vp_session_id)
789 @param vp_session_id vp??essionid
790 @return ????
791 */
792 ZEND_FUNCTION(vp_logout_user)
793 {
794 long vpSessionID;
795
796 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &vpSessionID) == FAILURE) {
797 return;
798 }
799 logoutUser( (sessionid_t)vpSessionID );
800
801 RETURN_NULL();
802 }
803
804 /** vp ? session id 篏???<br>
805 int vp_create_session( string xoops_sess_id, int uid, string remote_host )
806 @param xoops_sess_id xoops??ession id
807 @param uid xoops ? uid (xoops_users.uid)
808 @return FALSE篁ュ?: vp ? session id
809 @return FALSE: 紊掩??
810 */
811 ZEND_FUNCTION(vp_create_session)
812 {
813 char *xoopsSessionID;
814 int xoopsSessionIDLen;
815 long uid;
816
817 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",
818 &xoopsSessionID, &xoopsSessionIDLen, &uid) == FAILURE) {
819 return;
820 }
821
822 sessionid_t vpSessionID = 0;
823 result_t result = createSession( xoopsSessionID, (userid_t)uid, &vpSessionID );
824 if ( result == RES_OK ){
825 RETURN_LONG((long)vpSessionID);
826 }
827 else {
828 RETURN_FALSE;
829 }
830 }
831
832 /** vp ? session ???膣井???宴??緇???<br>
833 int vp_get_session( int vp_session_id, array session_info )
834 @param vp_session_id vp ? session id
835 @param session_info 腟?????????????????
836 @return 0 success
837 */
838 ZEND_FUNCTION(vp_get_session)
839 {
840 long vpSessionID;
841 zval *sessionInfo;
842 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
843 &vpSessionID, &sessionInfo) == FAILURE) {
844 return;
845 }
846 const session_t *session = 0;
847 result_t result = getSession( (sessionid_t)vpSessionID, &session );
848 if ( result == RES_OK ){
849 sessionToZval( session, sessionInfo );
850 freeResult( session );
851 }
852
853 RETURN_LONG((long)result);
854 }
855
856 /** activate?倶?? ??緇?<br>
857 bool vp_is_activated( int vp_session_id, int user_id )
858 @param vp_session_id vp ? session id
859 @param user_id xoops_users.uid
860 @return 0 success
861 */
862 ZEND_FUNCTION(vp_is_activated)
863 {
864 long sid, uid;
865
866 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
867 return;
868 }
869
870 bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
871
872 RETURN_BOOL(result);
873 }
874
875 /** activate??????<br>
876 bool vp_activate( int vp_session_id, bool activated )
877 @param vp_session_id vp ? session id
878 @param user_id xoops_users.uid
879 @param activated true:activate, false:inactivate
880 @return 0 success
881 */
882 ZEND_FUNCTION(vp_activate)
883 {
884 long sid, uid;
885 bool activated;
886
887 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
888 &sid, &uid, &activated) == FAILURE) {
889 return;
890 }
891
892 result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
893
894 RETURN_LONG(result);
895 }
896
897 /** vp???≪?????潟???違??緇?????<br>
898 int vp_get_account_count( int vp_session_id )
899 @param vp_session_id vp ? session id
900 @return 0 success
901 */
902 ZEND_FUNCTION(vp_get_account_count)
903 {
904 long sid;
905
906 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
907 &sid) == FAILURE) {
908 return;
909 }
910
911 long count = getAccountCount( (sessionid_t)sid );
912
913 RETURN_LONG(count);
914 }
915
916 /** ?≪?????潟???????ゃ??????<br>
917 bool vp_delete_account( int vp_session_id, int user_id )
918 @param vp_session_id vp ? session id
919 @param user_id xoops_users.uid
920 @return 0 success
921 */
922 ZEND_FUNCTION(vp_delete_account)
923 {
924 long sid, uid;
925
926 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
927 &sid, &uid) == FAILURE) {
928 return;
929 }
930
931 result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
932
933 RETURN_LONG(result);
934 }
935
936 /** ?≪?????潟?????宴??緇?????<br>
937 int vp_get_account( int vp_session_id, int user_id, array account_info )
938 @param vp_session_id vp ? session id
939 @param user_id xoops_users.uid
940 @param account_info ?≪?????潟?????宴???????????f?渇????
941 @return 0 success
942 */
943 ZEND_FUNCTION(vp_get_account)
944 {
945 long sid, uid;
946 zval *zaccount;
947
948 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
949 &sid, &uid, &zaccount) == FAILURE) {
950 fprintf( stderr, "error occured " );
951 return;
952 }
953
954 const account_t *paccount;
955 result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
956 if ( RES_OK == result ){
957 accountToZval( paccount, zaccount );
958 freeResult( paccount );
959 }
960
961 RETURN_LONG(result);
962 }
963
964 /** ?>散????眼?????≪?????潟???????宴??緇?????<br>
965 int vp_get_accoutns( int sid, array uids, array criteria, array accounts );
966 @param vp_session_id vp ? session id
967 @param user_id xoops_users.uid
968 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
969 @param account_info ?≪?????潟?????宴???????????f?渇????
970 @return 0 success
971 */
972 ZEND_FUNCTION(vp_get_accounts)
973 {
974 result_t result;
975 long sid;
976 zval *zuids;
977 zval *zcriteria;
978 zval *zaccount;
979
980 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
981 &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
982 return;
983 }
984
985 zCriteria_t zcri(zcriteria);
986 result = zcri.getResult();
987 if ( RES_OK == result ){
988 zUIDs_t zUIDs(zuids);
989 result = zUIDs.getResult();
990 if ( RES_OK == result ){
991 const account_t *paccounts;
992 int accountLen;
993 result = getAccounts( (sessionid_t)sid,
994 zUIDs.getPUID(), zUIDs.getLen(),
995 &zcri, &paccounts, &accountLen );
996 if ( RES_OK == result ){
997 accountsToZval( paccounts, accountLen, zaccount );
998 freeResult( paccounts );
999 }
1000 }
1001 }
1002
1003 RETURN_LONG(result);
1004 }
1005
1006 /** ?≪?????潟?????宴??緇?????<br>
1007 int vp_insert_account( int sid, array account_info );
1008 @param vp_session_id vp ? session id
1009 @param user_id xoops_users.uid
1010 @param account_info ?≪?????潟?????宴???????????f?渇????
1011 @return 0 success
1012 */
1013 ZEND_FUNCTION(vp_insert_account)
1014 {
1015 result_t result;
1016 long sid;
1017 zval *zaccount;
1018
1019 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1020 &sid, &zaccount) == FAILURE) {
1021 return;
1022 }
1023
1024 zAccount_t zacc(zaccount);
1025 result = zacc.getResult();
1026 if ( RES_OK == result ){
1027 result = insertAccount( (sessionid_t)sid, &zacc );
1028 }
1029
1030 RETURN_LONG(result);
1031 }
1032
1033 /** ?≪?????潟?????宴???贋?違??????<br>
1034 int vp_update_account( int sid, array account );
1035 @param vp_session_id vp ? session id
1036 @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
1037 @return 0 success
1038 */
1039 ZEND_FUNCTION(vp_update_account)
1040 {
1041 result_t result;
1042 long sid;
1043 zval *zaccount;
1044
1045 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1046 &sid, &zaccount) == FAILURE) {
1047 return;
1048 }
1049
1050 zAccount_t zacc(zaccount);
1051 result = zacc.getResult();
1052 if ( RES_OK == result ){
1053 result = updateAccount( (sessionid_t)sid, &zacc );
1054 }
1055
1056 RETURN_LONG(result);
1057 }
1058
1059 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
1060 int vp_dump_uids( int vp_session_id, array criteria, array uids );
1061 @param vp_session_id vp ? session id
1062 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1063 @param uids uid??????????????
1064 @return 0 success
1065 */
1066 ZEND_FUNCTION(vp_dump_uids)
1067 {
1068 result_t result;
1069 long sid;
1070 zval *zcriteria;
1071 zval *zuids;
1072
1073 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1074 &sid, &zcriteria, &zuids) == FAILURE) {
1075 return;
1076 }
1077
1078 zCriteria_t zcri(zcriteria);
1079 result = zcri.getResult();
1080 if ( RES_OK == result ){
1081 userid_t *puid;
1082 int uidLen;
1083 result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1084 if ( RES_OK == result ){
1085 uidsToZval( puid, uidLen, &zuids );
1086 freeResult( puid );
1087 }
1088 }
1089
1090 RETURN_LONG(result);
1091 }
1092
1093 /** VP???違???若?????違??緇???<br>
1094 int vp_get_group_count( int sid );
1095 @param vp_session_id vp ? session id
1096 @return ?違???若????/span>
1097 */
1098 ZEND_FUNCTION(vp_get_group_count)
1099 {
1100 result_t result;
1101 long sid;
1102
1103 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1104 &sid) == FAILURE) {
1105 return;
1106 }
1107
1108 int count = getGroupCount( (sessionid_t)sid );
1109
1110 RETURN_LONG(count);
1111 }
1112
1113 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
1114 int vp_get_group_by_uid( int sid, int uid, array criteria, array gids );
1115 @param vp_session_id vp ? session id
1116 @param user_id xoops_users.uid
1117 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1118 @param gids gid??????????????
1119 @return 0 success
1120 */
1121 ZEND_FUNCTION(vp_get_groups_by_uid)
1122 {
1123 result_t result;
1124 long sid, uid;
1125 zval *zcriteria;
1126 zval *zgids;
1127
1128 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1129 &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1130 return;
1131 }
1132
1133 zCriteria_t zcri(zcriteria);
1134 result = zcri.getResult();
1135 if ( RES_OK == result ){
1136 groupid_t *pgids;
1137 int gidLen;
1138 result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1139 if ( RES_OK == result ){
1140 gidsToZval( pgids, gidLen, &zgids );
1141 freeResult( pgids );
1142 }
1143 }
1144
1145 RETURN_LONG(result);
1146 }
1147
1148
1149
1150 /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
1151 int vp_is_group_admin( int sid, int gid, int uid );
1152 @param vp_session_id vp ? session id
1153 @param group_id VP???違???若??ID
1154 @param user_id xoops_users.uid
1155 @return true: ?違???若??膊∞?????с??????
1156 @return false: ?違???若??膊∞?????с???????????????????若?с??????
1157 */
1158 ZEND_FUNCTION(vp_is_group_admin)
1159 {
1160 result_t result;
1161 long sid, gid, uid;
1162
1163 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1164 &sid, &gid, &uid) == FAILURE) {
1165 return;
1166 }
1167
1168 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1169
1170 RETURN_BOOL(b);
1171 }
1172
1173 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
1174 int vp_dump_gids( int sid, array criteria, array gids );
1175 @param vp_session_id vp ? session id
1176 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1177 @param gids gid??????????????
1178 @return 0 success
1179 */
1180 ZEND_FUNCTION(vp_dump_gids)
1181 {
1182 result_t result;
1183 long sid;
1184 zval *zcriteria;
1185 zval *zgids;
1186
1187 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1188 &sid, &zcriteria, &zgids) == FAILURE) {
1189 return;
1190 }
1191
1192 zCriteria_t zcri(zcriteria);
1193 result = zcri.getResult();
1194 if ( RES_OK == result ){
1195 groupid_t *pgid;
1196 int gidLen;
1197 result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1198 if ( RES_OK == result ){
1199 gidsToZval( pgid, gidLen, &zgids );
1200 freeResult( pgid );
1201 }
1202 }
1203
1204 RETURN_LONG(result);
1205 }
1206
1207 /** ?違???若?????宴??紊??眼??????<br>
1208 int vp_update_group(int sid, array group )
1209 @param sid ?祉???激?с??D
1210 @param group ?違???若?????宴???f?渇????
1211 @return 0 success
1212 */
1213 ZEND_FUNCTION(vp_update_group)
1214 {
1215 long sid;
1216 zval *zgroup;
1217 group_t group;
1218
1219 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1220 &sid, &zgroup) == FAILURE) {
1221 return;
1222 }
1223
1224 zvalToGroup( zgroup, &group );
1225 result_t result = updateGroup( sid, &group );
1226 RETURN_LONG( result );
1227 }
1228

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