| 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 |
/* |
| 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 |
|
| 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 |
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 |
*/ |
| 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", ¶meter) == FAILURE) { |
| 134 |
return; |
| 135 |
} |
| 136 |
parameter++; |
| 137 |
RETURN_LONG(parameter); |
| 138 |
} |
| 139 |
/** zval縺九iC縺ョ譁?ュ怜?繧貞セ励k縲?/span> |
| 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縺九iint繧貞セ励k縲?/span> |
| 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繧貞性繧?縲?/span> |
| 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**縺九icriteria_t繧堤函謌舌☆繧九◆繧√?繧ッ繝ゥ繧ケ縲ら函謌仙、ア謨励↑繧曳etResult()!=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 |
); 縺薙s縺ェ蠖「縺ョ騾」諠ウ驟榊? |
| 175 |
*/ |
| 176 |
class zCriteria_t : public criteria { |
| 177 |
private: |
| 178 |
result_t result; |
| 179 |
public: |
| 180 |
// pz: array('name'=>'timestamp','name'=>'1') |
| 181 |
// 縺薙l縺九iorderby繧剃ス懈?縺励※霑ス蜉?縲?/span> |
| 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**縺九i(userid_t *puid,int uidLen)繧堤函謌舌☆繧九◆繧√?繧ッ繝ゥ繧ケ縲ら函謌仙、ア謨励↑繧曳etResult()!=RES_OK |
| 309 |
uids : array( '1', '3', '4', '6', ... ); 縺薙s縺ェ蠖「縺ョ驟榊? |
| 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縺ョ縺ゅ◆繧翫r蜿り??↓縲?/span> |
| 339 |
zend_hash_*縺ョ繝峨く繝・繝。繝ウ繝医▲縺ヲ縺ゅk縺ョ縺?繧阪≧縺具シ?/span> |
| 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 蜿ら? |
| 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 |
/** accounts 竊 zval |
| 416 |
* accounts: 縺薙s縺ェ諢溘§縺ョ驟榊? |
| 417 |
array( |
| 418 |
array( |
| 419 |
'uid'=>100, |
| 420 |
'activate'=>1, |
| 421 |
'institute'=>'foo', |
| 422 |
'tel'=>'123-456-789', |
| 423 |
... |
| 424 |
), |
| 425 |
... |
| 426 |
) |
| 427 |
*/ |
| 428 |
result_t accountsToZval( const account_t *pAccounts, int accountLen, zval *z ) |
| 429 |
{ |
| 430 |
return RES_ERROR; |
| 431 |
} |
| 432 |
|
| 433 |
result_t accountToZval( const account_t *pAccount, zval *z ) |
| 434 |
{ |
| 435 |
return RES_ERROR; |
| 436 |
} |
| 437 |
|
| 438 |
/** groups 竊 zval |
| 439 |
*/ |
| 440 |
result_t groupsToZval( const group_t *pGroups, int groupLen, zval *z ) |
| 441 |
{ |
| 442 |
|
| 443 |
return RES_ERROR; |
| 444 |
} |
| 445 |
|
| 446 |
/** session 竊 zval |
| 447 |
*/ |
| 448 |
result_t sessionToZval( const session_t *pSession, zval *z ) |
| 449 |
{ |
| 450 |
string sessionID(unsignedIntToString(pSession->getSessionID())); |
| 451 |
add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1); |
| 452 |
|
| 453 |
string date(unsignedIntToString((unsigned int)pSession->getDate())); |
| 454 |
add_assoc_string(z, "date", (char *)date.c_str(), 1); |
| 455 |
|
| 456 |
string userID(unsignedIntToString((unsigned int)pSession->getUserID())); |
| 457 |
add_assoc_string(z, "user_id", (char *)userID.c_str(), 1); |
| 458 |
|
| 459 |
return RES_OK; |
| 460 |
} |
| 461 |
|
| 462 |
ZEND_FUNCTION(vp_test_criteria) |
| 463 |
{ |
| 464 |
zval *z; |
| 465 |
|
| 466 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", |
| 467 |
&z) == FAILURE) { |
| 468 |
return; |
| 469 |
} |
| 470 |
zend_printf("zend_printf...<br>\n"); |
| 471 |
zCriteria_t zcri(z); |
| 472 |
zcri.dump(); |
| 473 |
RETURN_FALSE |
| 474 |
} |
| 475 |
|
| 476 |
ZEND_FUNCTION(vp_test_uids) |
| 477 |
{ |
| 478 |
zval *z; |
| 479 |
|
| 480 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", |
| 481 |
&z) == FAILURE) { |
| 482 |
return; |
| 483 |
} |
| 484 |
zend_printf("zend_printf...<br>\n"); |
| 485 |
zUIDs_t zuids(z); |
| 486 |
zuids.dump(); |
| 487 |
RETURN_FALSE |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
/** DB縺ォ謗・邯壹☆繧九?よ里縺ォ謗・邯壻クュ縺ョ謗・邯壹?髢峨§繧峨l繧九??lt;br> |
| 493 |
int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] ); |
| 494 |
@param host 謗・邯壼?縲ら怐逡・譎ゅ?NULL |
| 495 |
@param user DB謗・邯壽凾縺ョ繝ヲ繝シ繧カ蜷阪?ら怐逡・譎ゅ?NULL |
| 496 |
@param password DB謗・邯壽凾縺ョ繝代せ繝ッ繝シ繝峨?ら怐逡・譎ゅ?NULL |
| 497 |
@param dbname DB謗・邯壽凾縺ョDB蜷阪?ら怐逡・譎ゅ?"" |
| 498 |
@param prefix XOOPS DB 縺ョprefix縲?/span> |
| 499 |
@return 0 success <br> |
| 500 |
*/ |
| 501 |
ZEND_FUNCTION(vp_initialize_db) |
| 502 |
{ |
| 503 |
zval **parameters[5]; |
| 504 |
char *host; |
| 505 |
char *user; |
| 506 |
char *password; |
| 507 |
char *dbname; |
| 508 |
char *prefix; |
| 509 |
|
| 510 |
/* get the number of arguments */ |
| 511 |
int argNum = ZEND_NUM_ARGS(); |
| 512 |
if (argNum > 5) |
| 513 |
WRONG_PARAM_COUNT; |
| 514 |
|
| 515 |
/* argument count is correct, now retrieve arguments */ |
| 516 |
if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS) |
| 517 |
WRONG_PARAM_COUNT; |
| 518 |
|
| 519 |
if (argNum < 1) host = NULL; |
| 520 |
else host = getZvalString( parameters[0] ); |
| 521 |
|
| 522 |
if (argNum < 2) user = NULL; |
| 523 |
else user = getZvalString( parameters[1] ); |
| 524 |
|
| 525 |
if (argNum < 3) password = NULL; |
| 526 |
else password = getZvalString( parameters[2] ); |
| 527 |
|
| 528 |
if (argNum < 4) dbname = ""; |
| 529 |
else dbname = getZvalString( parameters[3] ); |
| 530 |
|
| 531 |
if (argNum < 5) prefix = ""; |
| 532 |
else prefix = getZvalString( parameters[4] ); |
| 533 |
|
| 534 |
result_t result = initializeDB( host, user, password, dbname, prefix ); |
| 535 |
|
| 536 |
RETURN_LONG(result); |
| 537 |
} |
| 538 |
|
| 539 |
/** 繝ュ繧ー繧、繝ウ縺吶k縲?lt;br> |
| 540 |
int vp_login_user(string uname, string password) |
| 541 |
@param uname 繝ヲ繝シ繧カ蜷?xoops_users.uname) |
| 542 |
@param password 繝代せ繝ッ繝シ繝?md5(password)=xoops_users.pass) |
| 543 |
@return 0 success |
| 544 |
*/ |
| 545 |
ZEND_FUNCTION(vp_login_user) |
| 546 |
{ |
| 547 |
char *uname; |
| 548 |
int unameLen; |
| 549 |
char *passwd; |
| 550 |
int passwdLen; |
| 551 |
|
| 552 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", |
| 553 |
&uname, &unameLen, &passwd, &passwdLen) == FAILURE) { |
| 554 |
return; |
| 555 |
} |
| 556 |
|
| 557 |
string strUname( uname, unameLen ); |
| 558 |
string strPasswd( passwd, passwdLen ); |
| 559 |
sessionid_t vpSessionID; |
| 560 |
result_t result = loginUser( strUname.c_str(), strPasswd.c_str(), &vpSessionID ); |
| 561 |
if ( result == RES_OK ){ |
| 562 |
RETURN_LONG((long)vpSessionID); |
| 563 |
} |
| 564 |
else { |
| 565 |
//zend_printf( "vpal_debug: vp_login_user(%s, %s): cannot login. result=%d<br>\n", strUname.c_str(), strPasswd.c_str(), (int)result ); |
| 566 |
RETURN_FALSE |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
/** 繝ュ繧ー繧「繧ヲ繝医☆繧九??lt;br> |
| 571 |
void vp_logout_user(int vp_session_id) |
| 572 |
@param vp_session_id vp縺ョsessionid |
| 573 |
@return 縺ェ縺?/span> |
| 574 |
*/ |
| 575 |
ZEND_FUNCTION(vp_logout_user) |
| 576 |
{ |
| 577 |
long vpSessionID; |
| 578 |
|
| 579 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &vpSessionID) == FAILURE) { |
| 580 |
return; |
| 581 |
} |
| 582 |
|
| 583 |
logoutUser( (sessionid_t)vpSessionID ); |
| 584 |
|
| 585 |
RETURN_NULL(); |
| 586 |
} |
| 587 |
|
| 588 |
/** vp 縺ョ session id 菴懈?<br> |
| 589 |
int vp_create_session( string xoops_sess_id, int uid, string remote_host ) |
| 590 |
@param xoops_sess_id xoops縺ョsession id |
| 591 |
@param uid xoops 縺ョ uid (xoops_users.uid) |
| 592 |
@return FALSE莉・螟? vp 縺ョ session id |
| 593 |
@return FALSE: 螟ア謨?/span> |
| 594 |
*/ |
| 595 |
ZEND_FUNCTION(vp_create_session) |
| 596 |
{ |
| 597 |
char *xoopsSessionID; |
| 598 |
int xoopsSessionIDLen; |
| 599 |
long sid, uid; |
| 600 |
|
| 601 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", |
| 602 |
&xoopsSessionID, &xoopsSessionIDLen, &uid) == FAILURE) { |
| 603 |
return; |
| 604 |
} |
| 605 |
|
| 606 |
sessionid_t vpSessionID = 0; |
| 607 |
result_t result = createSession( xoopsSessionID, (userid_t)uid, &vpSessionID ); |
| 608 |
if ( result == RES_OK ){ |
| 609 |
RETURN_LONG((long)vpSessionID); |
| 610 |
} |
| 611 |
else { |
| 612 |
RETURN_FALSE; |
| 613 |
} |
| 614 |
} |
| 615 |
|
| 616 |
/** vp 縺ョ session 縺ョ隧ウ邏ー諠??ア繧貞セ励k<br> |
| 617 |
int vp_get_session( int vp_session_id, array session_info ) |
| 618 |
@param vp_session_id vp 縺ョ session id |
| 619 |
@param session_info 邨先棡繧貞女縺大叙繧矩?蛻?/span> |
| 620 |
@return 0 success |
| 621 |
*/ |
| 622 |
ZEND_FUNCTION(vp_get_session) |
| 623 |
{ |
| 624 |
long vpSessionID; |
| 625 |
zval *sessionInfo; |
| 626 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la", |
| 627 |
&vpSessionID, &sessionInfo) == FAILURE) { |
| 628 |
return; |
| 629 |
} |
| 630 |
const session_t *session = 0; |
| 631 |
result_t result = getSession( (sessionid_t)vpSessionID, &session ); |
| 632 |
if ( result == RES_OK ){ |
| 633 |
sessionToZval( session, sessionInfo ); |
| 634 |
freeResult( session ); |
| 635 |
} |
| 636 |
|
| 637 |
RETURN_LONG((long)result); |
| 638 |
} |
| 639 |
|
| 640 |
ZEND_FUNCTION(vp_is_activated) |
| 641 |
{ |
| 642 |
long sid, uid; |
| 643 |
|
| 644 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", |
| 645 |
&sid, &uid) == FAILURE) { |
| 646 |
return; |
| 647 |
} |
| 648 |
|
| 649 |
bool result = isActivated( (sessionid_t)sid, (userid_t)uid ); |
| 650 |
|
| 651 |
RETURN_BOOL(result); |
| 652 |
} |
| 653 |
|
| 654 |
ZEND_FUNCTION(vp_activate) |
| 655 |
{ |
| 656 |
long sid, uid; |
| 657 |
bool activated; |
| 658 |
|
| 659 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb", |
| 660 |
&sid, &uid, &activated) == FAILURE) { |
| 661 |
return; |
| 662 |
} |
| 663 |
|
| 664 |
result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated ); |
| 665 |
|
| 666 |
RETURN_LONG(result); |
| 667 |
} |
| 668 |
|
| 669 |
ZEND_FUNCTION(vp_get_account_count) |
| 670 |
{ |
| 671 |
long sid; |
| 672 |
|
| 673 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", |
| 674 |
&sid) == FAILURE) { |
| 675 |
return; |
| 676 |
} |
| 677 |
|
| 678 |
long count = getAccountCount( (sessionid_t)sid ); |
| 679 |
|
| 680 |
RETURN_LONG(count); |
| 681 |
} |
| 682 |
|
| 683 |
ZEND_FUNCTION(vp_delete_account) |
| 684 |
{ |
| 685 |
long sid, uid; |
| 686 |
|
| 687 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", |
| 688 |
&sid, &uid) == FAILURE) { |
| 689 |
return; |
| 690 |
} |
| 691 |
|
| 692 |
result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid ); |
| 693 |
|
| 694 |
RETURN_LONG(result); |
| 695 |
} |
| 696 |
|
| 697 |
// int vp_get_account( int sid, int uid, array account ) |
| 698 |
ZEND_FUNCTION(vp_get_account) |
| 699 |
{ |
| 700 |
long sid, uid; |
| 701 |
zval *zaccount; |
| 702 |
|
| 703 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla", |
| 704 |
&sid, &uid, &zaccount) == FAILURE) { |
| 705 |
return; |
| 706 |
} |
| 707 |
|
| 708 |
const account_t *paccount; |
| 709 |
result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount ); |
| 710 |
if ( RES_OK == result ){ |
| 711 |
accountToZval( paccount, zaccount ); |
| 712 |
freeResult( paccount ); |
| 713 |
} |
| 714 |
|
| 715 |
RETURN_LONG(result); |
| 716 |
} |
| 717 |
|
| 718 |
// int vp_get_accoutns( int sid, array uids, array criteria, array accounts ); |
| 719 |
ZEND_FUNCTION(vp_get_accounts) |
| 720 |
{ |
| 721 |
result_t result; |
| 722 |
long sid; |
| 723 |
zval *zuids; |
| 724 |
zval *zcriteria; |
| 725 |
zval *zaccount; |
| 726 |
|
| 727 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa", |
| 728 |
&sid, &zuids, &zcriteria, &zaccount) == FAILURE) { |
| 729 |
return; |
| 730 |
} |
| 731 |
|
| 732 |
zCriteria_t zcri(zcriteria); |
| 733 |
result = zcri.getResult(); |
| 734 |
if ( RES_OK == result ){ |
| 735 |
zUIDs_t zUIDs(zuids); |
| 736 |
result = zUIDs.getResult(); |
| 737 |
if ( RES_OK == result ){ |
| 738 |
const account_t *paccounts; |
| 739 |
int accountLen; |
| 740 |
result = getAccounts( (sessionid_t)sid, |
| 741 |
zUIDs.getPUID(), zUIDs.getLen(), |
| 742 |
&zcri, &paccounts, &accountLen ); |
| 743 |
if ( RES_OK == result ){ |
| 744 |
accountsToZval( paccounts, accountLen, zaccount ); |
| 745 |
freeResult( paccounts ); |
| 746 |
} |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
RETURN_LONG(result); |
| 751 |
} |
| 752 |
|
| 753 |
// int vp_insert_account( int sid, array account ); |
| 754 |
ZEND_FUNCTION(vp_insert_account) |
| 755 |
{ |
| 756 |
result_t result; |
| 757 |
long sid; |
| 758 |
zval *zaccount; |
| 759 |
|
| 760 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la", |
| 761 |
&sid, &zaccount) == FAILURE) { |
| 762 |
return; |
| 763 |
} |
| 764 |
|
| 765 |
zAccount_t zacc(zaccount); |
| 766 |
result = zacc.getResult(); |
| 767 |
if ( RES_OK == result ){ |
| 768 |
result = insertAccount( (sessionid_t)sid, &zacc ); |
| 769 |
} |
| 770 |
|
| 771 |
RETURN_LONG(result); |
| 772 |
} |
| 773 |
|
| 774 |
// int vp_update_account( int sid, array account ); |
| 775 |
ZEND_FUNCTION(vp_update_account) |
| 776 |
{ |
| 777 |
result_t result; |
| 778 |
long sid; |
| 779 |
zval *zaccount; |
| 780 |
|
| 781 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la", |
| 782 |
&sid, &zaccount) == FAILURE) { |
| 783 |
return; |
| 784 |
} |
| 785 |
|
| 786 |
zAccount_t zacc(zaccount); |
| 787 |
result = zacc.getResult(); |
| 788 |
if ( RES_OK == result ){ |
| 789 |
result = updateAccount( (sessionid_t)sid, &zacc ); |
| 790 |
} |
| 791 |
|
| 792 |
RETURN_LONG(result); |
| 793 |
} |
| 794 |
|
| 795 |
// int vp_dump_uids( int sid, array criteria, array uids ); |
| 796 |
ZEND_FUNCTION(vp_dump_uids) |
| 797 |
{ |
| 798 |
result_t result; |
| 799 |
long sid; |
| 800 |
zval *zcriteria; |
| 801 |
zval *zuids; |
| 802 |
|
| 803 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa", |
| 804 |
&sid, &zcriteria, &zuids) == FAILURE) { |
| 805 |
return; |
| 806 |
} |
| 807 |
|
| 808 |
zCriteria_t zcri(zcriteria); |
| 809 |
result = zcri.getResult(); |
| 810 |
if ( RES_OK == result ){ |
| 811 |
userid_t *puid; |
| 812 |
int uidLen; |
| 813 |
result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen ); |
| 814 |
if ( RES_OK == result ){ |
| 815 |
uidsToZval( puid, uidLen, &zuids ); |
| 816 |
freeResult( puid ); |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
RETURN_LONG(result); |
| 821 |
} |
| 822 |
|
| 823 |
// int vp_get_group_count( int sid ); |
| 824 |
ZEND_FUNCTION(vp_get_group_count) |
| 825 |
{ |
| 826 |
result_t result; |
| 827 |
long sid; |
| 828 |
|
| 829 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", |
| 830 |
&sid) == FAILURE) { |
| 831 |
return; |
| 832 |
} |
| 833 |
|
| 834 |
int count = getGroupCount( (sessionid_t)sid ); |
| 835 |
|
| 836 |
RETURN_LONG(count); |
| 837 |
} |
| 838 |
|
| 839 |
// int vp_get_group_by_uid( int sid, int uid, array criteria, array gids ); |
| 840 |
ZEND_FUNCTION(vp_get_groups_by_uid) |
| 841 |
{ |
| 842 |
result_t result; |
| 843 |
long sid, uid; |
| 844 |
zval *zcriteria; |
| 845 |
zval *zgids; |
| 846 |
|
| 847 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa", |
| 848 |
&sid, &uid, &zcriteria, &zgids) == FAILURE) { |
| 849 |
return; |
| 850 |
} |
| 851 |
|
| 852 |
zCriteria_t zcri(zcriteria); |
| 853 |
result = zcri.getResult(); |
| 854 |
if ( RES_OK == result ){ |
| 855 |
groupid_t *pgids; |
| 856 |
int gidLen; |
| 857 |
result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen ); |
| 858 |
if ( RES_OK == result ){ |
| 859 |
gidsToZval( pgids, gidLen, &zgids ); |
| 860 |
freeResult( pgids ); |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
RETURN_LONG(result); |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
// int vp_is_group_admin( int sid, int gid, int uid ); |
| 869 |
ZEND_FUNCTION(vp_is_group_admin) |
| 870 |
{ |
| 871 |
result_t result; |
| 872 |
long sid, gid, uid; |
| 873 |
|
| 874 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", |
| 875 |
&sid, &gid, &uid) == FAILURE) { |
| 876 |
return; |
| 877 |
} |
| 878 |
|
| 879 |
bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid ); |
| 880 |
|
| 881 |
RETURN_BOOL(b); |
| 882 |
} |
| 883 |
|
| 884 |
// int vp_dump_gids( int sid, array criteria, array gids ); |
| 885 |
ZEND_FUNCTION(vp_dump_gids) |
| 886 |
{ |
| 887 |
result_t result; |
| 888 |
long sid; |
| 889 |
zval *zcriteria; |
| 890 |
zval *zgids; |
| 891 |
|
| 892 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa", |
| 893 |
&sid, &zcriteria, &zgids) == FAILURE) { |
| 894 |
return; |
| 895 |
} |
| 896 |
|
| 897 |
zCriteria_t zcri(zcriteria); |
| 898 |
result = zcri.getResult(); |
| 899 |
if ( RES_OK == result ){ |
| 900 |
groupid_t *pgid; |
| 901 |
int gidLen; |
| 902 |
result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen ); |
| 903 |
if ( RES_OK == result ){ |
| 904 |
gidsToZval( pgid, gidLen, &zgids ); |
| 905 |
freeResult( pgid ); |
| 906 |
} |
| 907 |
} |
| 908 |
|
| 909 |
RETURN_LONG(result); |
| 910 |
} |