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.15 - (show annotations) (download) (as text)
Fri Dec 3 07:20:40 2004 UTC (19 years, 4 months ago) by youi
Branch: MAIN
Changes since 1.14: +5 -5 lines
File MIME type: text/x-c++src
DB、ホ・ォ・鬣猯セハムケケ、ヒネシ、ヲス、タオ.
	institute -> division
	organization -> company_name

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

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