| 8 |
|
|
| 9 |
|
|
| 10 |
#include <stdio.h> |
#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" |
#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 |
// global variables |
| 25 |
MYSQL *mysql = NULL; |
MYSQL *mysql = NULL; |
| 26 |
|
|
| 27 |
|
|
| 28 |
/* declaration of functions to be exported */ |
/* declaration of functions to be exported */ |
| 29 |
extern "C" { |
extern "C" { |
| 30 |
ZEND_FUNCTION(first_module); |
ZEND_FUNCTION(first_module ); |
| 31 |
ZEND_FUNCTION(vp_initialize_db); |
ZEND_FUNCTION(vp_initialize_db ); |
| 32 |
ZEND_FUNCTION(vp_login_user); |
ZEND_FUNCTION(vp_login_user ); |
| 33 |
ZEND_FUNCTION(vp_logout_user); |
ZEND_FUNCTION(vp_logout_user ); |
| 34 |
|
//ZEND_FUNCTION(vp_create_session ); |
| 35 |
|
ZEND_FUNCTION(vp_is_activated ); |
| 36 |
|
ZEND_FUNCTION(vp_activate ); |
| 37 |
|
ZEND_FUNCTION(vp_get_account_count ); |
| 38 |
|
ZEND_FUNCTION(vp_delete_account ); |
| 39 |
|
ZEND_FUNCTION(vp_get_account ); |
| 40 |
|
ZEND_FUNCTION(vp_get_accounts ); |
| 41 |
|
ZEND_FUNCTION(vp_insert_account ); |
| 42 |
|
ZEND_FUNCTION(vp_update_account ); |
| 43 |
|
ZEND_FUNCTION(vp_dump_uids ); |
| 44 |
|
ZEND_FUNCTION(vp_get_group_count ); |
| 45 |
|
ZEND_FUNCTION(vp_get_groups_by_uid ); |
| 46 |
|
ZEND_FUNCTION(vp_is_group_admin ); |
| 47 |
|
ZEND_FUNCTION(vp_dump_gids ); |
| 48 |
|
/* |
| 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 |
|
|
| 62 |
|
ZEND_FUNCTION(vp_test_criteria ); |
| 63 |
|
ZEND_FUNCTION(vp_test_uids ); |
| 64 |
}; |
}; |
| 65 |
/* compiled function list so Zend knows what's in this module */ |
/* compiled function list so Zend knows what's in this module */ |
| 66 |
zend_function_entry vpalmod_functions[] = |
zend_function_entry vpalmod_functions[] = |
| 67 |
{ |
{ |
| 68 |
ZEND_FE(first_module, NULL) |
ZEND_FE(first_module ,NULL) |
| 69 |
ZEND_FE(vp_initialize_db, NULL) |
ZEND_FE(vp_initialize_db ,NULL) |
| 70 |
ZEND_FE(vp_login_user, NULL) |
ZEND_FE(vp_login_user ,NULL) |
| 71 |
ZEND_FE(vp_logout_user, NULL) |
ZEND_FE(vp_logout_user ,NULL) |
| 72 |
|
// ZEND_FE(vp_create_session ,NULL) |
| 73 |
|
ZEND_FE(vp_is_activated ,NULL) |
| 74 |
|
ZEND_FE(vp_activate ,NULL) |
| 75 |
|
ZEND_FE(vp_get_account_count ,NULL) |
| 76 |
|
ZEND_FE(vp_delete_account ,NULL) |
| 77 |
|
ZEND_FE(vp_get_account ,NULL) |
| 78 |
|
ZEND_FE(vp_get_accounts ,NULL) |
| 79 |
|
ZEND_FE(vp_insert_account ,NULL) |
| 80 |
|
ZEND_FE(vp_update_account ,NULL) |
| 81 |
|
ZEND_FE(vp_dump_uids ,NULL) |
| 82 |
|
ZEND_FE(vp_get_group_count ,NULL) |
| 83 |
|
ZEND_FE(vp_get_groups_by_uid ,NULL) |
| 84 |
|
ZEND_FE(vp_is_group_admin ,NULL) |
| 85 |
|
ZEND_FE(vp_dump_gids ,NULL) |
| 86 |
|
/* |
| 87 |
|
ZEND_FE(vp_dump_group_admins ,NULL) |
| 88 |
|
ZEND_FE(vp_delete_member ,NULL) |
| 89 |
|
ZEND_FE(vp_insert_member ,NULL) |
| 90 |
|
ZEND_FE(vp_get_members ,NULL) |
| 91 |
|
ZEND_FE(vp_delete_group ,NULL) |
| 92 |
|
ZEND_FE(vp_insert_group ,NULL) |
| 93 |
|
ZEND_FE(vp_update_group ,NULL) |
| 94 |
|
ZEND_FE(vp_get_group ,NULL) |
| 95 |
|
ZEND_FE(vp_get_groups ,NULL) |
| 96 |
|
ZEND_FE(vp_is_moderator ,NULL) |
| 97 |
|
ZEND_FE(vp_get_uid ,NULL) |
| 98 |
|
*/ |
| 99 |
|
ZEND_FE(vp_test_criteria ,NULL) |
| 100 |
|
ZEND_FE(vp_test_uids ,NULL) |
| 101 |
{NULL, NULL, NULL} |
{NULL, NULL, NULL} |
| 102 |
}; |
}; |
| 103 |
|
|
| 148 |
return Z_LVAL_PP(p); // (int)(**p).value.lval; |
return Z_LVAL_PP(p); // (int)(**p).value.lval; |
| 149 |
} |
} |
| 150 |
|
|
| 151 |
|
// keylenは末尾の\0を含む。 |
| 152 |
|
static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){ |
| 153 |
|
zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index ); |
| 154 |
|
if ( res == HASH_KEY_IS_STRING ){ |
| 155 |
|
char *p = new char[keyLen+1]; |
| 156 |
|
memcpy( p, key, keyLen ); |
| 157 |
|
p[keyLen] = 0; |
| 158 |
|
zend_printf( " key is string[%s]<br>\n", p ); |
| 159 |
|
} |
| 160 |
|
else { |
| 161 |
|
zend_printf( " key is integer[%d]<br>\n", index ); |
| 162 |
|
} |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
/** zval**からcriteria_tを生成するためのクラス。生成失敗ならgetResult()!=RES_OK |
| 167 |
|
* criteria : |
| 168 |
|
array( 'start'=>0, 'rows'=>10, |
| 169 |
|
'orders'=>array( |
| 170 |
|
array('name'=>'id','order'=>'0'), |
| 171 |
|
array('name'=>'timestamp','name'=>'1'), ...) |
| 172 |
|
); こんな形の連想配列 |
| 173 |
|
*/ |
| 174 |
|
class zCriteria_t : public criteria { |
| 175 |
|
private: |
| 176 |
|
result_t result; |
| 177 |
|
public: |
| 178 |
|
// pz: array('name'=>'timestamp','name'=>'1') |
| 179 |
|
// これからorderbyを作成して追加。 |
| 180 |
|
void setOrder( zval *pz ){ |
| 181 |
|
char *column = 0; |
| 182 |
|
order_t order = (order_t)0; |
| 183 |
|
|
| 184 |
|
HashPosition pos; |
| 185 |
|
zval **ppzTmp = 0; |
| 186 |
|
int res2; |
| 187 |
|
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos); |
| 188 |
|
while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) { |
| 189 |
|
char *key = 0; |
| 190 |
|
uint keyLen = 0; |
| 191 |
|
ulong index = 0; |
| 192 |
|
int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos ); |
| 193 |
|
if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){ |
| 194 |
|
print_hash_key( keyType, key, keyLen, index ); |
| 195 |
|
if ( strncasecmp( key, "column", keyLen ) == 0 && keyLen == 7 ){ |
| 196 |
|
SEPARATE_ZVAL(ppzTmp); |
| 197 |
|
column = getZvalString(ppzTmp); |
| 198 |
|
// zend_printf( "column=%s<br>\n", column ); |
| 199 |
|
} |
| 200 |
|
else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){ |
| 201 |
|
SEPARATE_ZVAL(ppzTmp); |
| 202 |
|
order = (order_t)getZvalInt(ppzTmp); |
| 203 |
|
// zend_printf( "order=%d<br>\n", order ); |
| 204 |
|
} |
| 205 |
|
} |
| 206 |
|
|
| 207 |
|
zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos); |
| 208 |
|
} |
| 209 |
|
if ( column ){ |
| 210 |
|
orderby *o = new orderby( column, order ); |
| 211 |
|
addOrderBy( o ); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
result = RES_OK; |
| 215 |
|
} |
| 216 |
|
|
| 217 |
|
// pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...) |
| 218 |
|
void setOrders( zval *pz ){ |
| 219 |
|
HashPosition pos; |
| 220 |
|
|
| 221 |
|
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos); |
| 222 |
|
|
| 223 |
|
zval **ppzTmp = 0; |
| 224 |
|
int res2; |
| 225 |
|
while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) { |
| 226 |
|
char *key = 0; |
| 227 |
|
uint keyLen = 0; |
| 228 |
|
ulong index = 0; |
| 229 |
|
int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos ); |
| 230 |
|
if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){ |
| 231 |
|
print_hash_key( keyType, key, keyLen, index ); |
| 232 |
|
setOrder( *ppzTmp ); |
| 233 |
|
} |
| 234 |
|
zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos); |
| 235 |
|
} |
| 236 |
|
result = RES_OK; |
| 237 |
|
} |
| 238 |
|
|
| 239 |
|
void initialize( zval *pz ){ |
| 240 |
|
HashPosition pos; |
| 241 |
|
zval **ppzTmp = 0; |
| 242 |
|
int res2; |
| 243 |
|
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos); |
| 244 |
|
while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) { |
| 245 |
|
char *key = 0; |
| 246 |
|
uint keyLen = 0; |
| 247 |
|
ulong index = 0; |
| 248 |
|
int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos ); |
| 249 |
|
if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){ |
| 250 |
|
print_hash_key( keyType, key, keyLen, index ); |
| 251 |
|
if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){ |
| 252 |
|
SEPARATE_ZVAL(ppzTmp); |
| 253 |
|
int tmp = getZvalInt(ppzTmp); |
| 254 |
|
// zend_printf( "start=%d<br>\n", tmp ); |
| 255 |
|
setLimit( tmp, getLimitRows() ); |
| 256 |
|
} |
| 257 |
|
else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){ |
| 258 |
|
SEPARATE_ZVAL(ppzTmp); |
| 259 |
|
int tmp = getZvalInt(ppzTmp); |
| 260 |
|
// zend_printf( "rows=%d<br>\n", tmp ); |
| 261 |
|
setLimit( getLimitStart(), tmp ); |
| 262 |
|
} |
| 263 |
|
else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){ |
| 264 |
|
setOrders( *ppzTmp ); |
| 265 |
|
} |
| 266 |
|
else |
| 267 |
|
; // ignore unknown key |
| 268 |
|
} |
| 269 |
|
else |
| 270 |
|
; // ignore bad key |
| 271 |
|
zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos); |
| 272 |
|
} |
| 273 |
|
result = RES_OK; |
| 274 |
|
} |
| 275 |
|
zCriteria_t() : criteria(){ result = RES_ERROR; } |
| 276 |
|
zCriteria_t( zval *pz ) : criteria(){ initialize(pz); } |
| 277 |
|
zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); } |
| 278 |
|
result_t getResult(){ return result; }; |
| 279 |
|
|
| 280 |
|
void dump(){ |
| 281 |
|
zend_printf( "dumping zCriteria...<br>\n" ); |
| 282 |
|
zend_printf( "result=%d<br>\n", (int)result ); |
| 283 |
|
zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() ); |
| 284 |
|
const orderby *p = headOrderBy(); |
| 285 |
|
while ( p ){ |
| 286 |
|
zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() ); |
| 287 |
|
p = nextOrderBy(); |
| 288 |
|
} |
| 289 |
|
} |
| 290 |
|
}; |
| 291 |
|
|
| 292 |
|
|
| 293 |
|
class zAccount_t : public account { |
| 294 |
|
private: |
| 295 |
|
result_t result; |
| 296 |
|
public: |
| 297 |
|
void initialize(zval *pz){ |
| 298 |
|
; // todo |
| 299 |
|
} |
| 300 |
|
zAccount_t() : account(){ result = RES_ERROR; } |
| 301 |
|
zAccount_t( zval *pz ) : account(){ initialize(pz); } |
| 302 |
|
zAccount_t( zval **ppz ) : account() { initialize(*ppz); } |
| 303 |
|
result_t getResult(){ return result; }; |
| 304 |
|
}; |
| 305 |
|
|
| 306 |
|
/** zval**から(userid_t *puid,int uidLen)を生成するためのクラス。生成失敗ならgetResult()!=RES_OK |
| 307 |
|
uids : array( '1', '3', '4', '6', ... ); こんな形の配列 |
| 308 |
|
*/ |
| 309 |
|
class zUIDs_t { |
| 310 |
|
private: |
| 311 |
|
result_t result; |
| 312 |
|
userid_t *pUID; |
| 313 |
|
int len; |
| 314 |
|
public: |
| 315 |
|
zUIDs_t(){ |
| 316 |
|
pUID = 0; |
| 317 |
|
len = 0; |
| 318 |
|
result = RES_ERROR; |
| 319 |
|
} |
| 320 |
|
|
| 321 |
|
zUIDs_t( zval *pza ){ |
| 322 |
|
pUID = 0; |
| 323 |
|
len = 0; |
| 324 |
|
result = RES_ERROR; |
| 325 |
|
|
| 326 |
|
if ( Z_TYPE_P(pza) != IS_ARRAY ){ |
| 327 |
|
result = RES_ERROR; |
| 328 |
|
} |
| 329 |
|
else { |
| 330 |
|
len = zend_hash_num_elements(Z_ARRVAL_P(pza)); |
| 331 |
|
if(len == 0) { |
| 332 |
|
pUID = new userid_t[1]; |
| 333 |
|
result = RES_OK; |
| 334 |
|
} |
| 335 |
|
else { |
| 336 |
|
/* php/ext/standard/string.c の implodeのあたりを参考に。 |
| 337 |
|
zend_hash_*のドキュメントってあるのだろうか? |
| 338 |
|
*/ |
| 339 |
|
zval **tmp; |
| 340 |
|
HashPosition pos; |
| 341 |
|
int i = 0; |
| 342 |
|
pUID = new userid_t[len]; |
| 343 |
|
|
| 344 |
|
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos); |
| 345 |
|
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) { |
| 346 |
|
SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html 参照 |
| 347 |
|
convert_to_long_ex(tmp); |
| 348 |
|
if ( i < len ) |
| 349 |
|
pUID[i++] = Z_LVAL_PP(tmp); |
| 350 |
|
zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos); |
| 351 |
|
} |
| 352 |
|
len = i; |
| 353 |
|
result = RES_OK; |
| 354 |
|
} |
| 355 |
|
} |
| 356 |
|
} |
| 357 |
|
|
| 358 |
|
~zUIDs_t(){ |
| 359 |
|
if ( pUID ) delete[] pUID; |
| 360 |
|
} |
| 361 |
|
result_t getResult(){ return result; } |
| 362 |
|
userid_t *getPUID(){ return pUID; } |
| 363 |
|
int getLen(){ return len; } |
| 364 |
|
void dump(){ |
| 365 |
|
zend_printf( "dumping zUIDs...<br>\n" ); |
| 366 |
|
zend_printf( "result=%d<br>\n", (int)result ); |
| 367 |
|
zend_printf( "len=%d<br>\n", len ); |
| 368 |
|
for ( int i = 0; i < len; i++ ){ |
| 369 |
|
zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] ); |
| 370 |
|
} |
| 371 |
|
} |
| 372 |
|
}; |
| 373 |
|
|
| 374 |
|
/** uids_t → zval |
| 375 |
|
*/ |
| 376 |
|
result_t uidsToZval( userid_t *pUID, int len, zval **ppz ){ |
| 377 |
|
zval *pz; |
| 378 |
|
|
| 379 |
|
// create new array |
| 380 |
|
MAKE_STD_ZVAL(pz); |
| 381 |
|
array_init(pz); |
| 382 |
|
|
| 383 |
|
// add UIDs |
| 384 |
|
for ( int i = 0; i < len; i++ ){ |
| 385 |
|
add_next_index_long(pz, (long)(pUID[i]) ); |
| 386 |
|
} |
| 387 |
|
|
| 388 |
|
// return array |
| 389 |
|
*ppz = pz; |
| 390 |
|
return RES_OK; |
| 391 |
|
} |
| 392 |
|
/** uids_t → zval |
| 393 |
|
*/ |
| 394 |
|
result_t gidsToZval( groupid_t *pGID, int len, zval **ppz ){ |
| 395 |
|
zval *pz; |
| 396 |
|
|
| 397 |
|
// create new array |
| 398 |
|
MAKE_STD_ZVAL(pz); |
| 399 |
|
array_init(pz); |
| 400 |
|
|
| 401 |
|
// add GIDs |
| 402 |
|
for ( int i = 0; i < len; i++ ){ |
| 403 |
|
add_next_index_long(pz, (long)(pGID[i]) ); |
| 404 |
|
} |
| 405 |
|
|
| 406 |
|
// return array |
| 407 |
|
*ppz = pz; |
| 408 |
|
return RES_OK; |
| 409 |
|
} |
| 410 |
|
|
| 411 |
|
/** accounts → zval |
| 412 |
|
* accounts: こんな感じの配列 |
| 413 |
|
array( |
| 414 |
|
array( |
| 415 |
|
'uid'=>100, |
| 416 |
|
'activate'=>1, |
| 417 |
|
'institute'=>'foo', |
| 418 |
|
'tel'=>'123-456-789', |
| 419 |
|
... |
| 420 |
|
), |
| 421 |
|
... |
| 422 |
|
) |
| 423 |
|
*/ |
| 424 |
|
result_t accountsToZval( const account_t *pAccounts, int accountLen, zval *z ){ |
| 425 |
|
return RES_ERROR; |
| 426 |
|
} |
| 427 |
|
|
| 428 |
|
result_t accountToZval( const account_t *pAccount, zval *z ){ |
| 429 |
|
return RES_ERROR; |
| 430 |
|
} |
| 431 |
|
|
| 432 |
|
/** groups → zval |
| 433 |
|
*/ |
| 434 |
|
result_t groupsToZval( const group_t *pGroups, int groupLen, zval *z ){ |
| 435 |
|
|
| 436 |
|
return RES_ERROR; |
| 437 |
|
} |
| 438 |
|
|
| 439 |
|
ZEND_FUNCTION(vp_test_criteria) |
| 440 |
|
{ |
| 441 |
|
zval *z; |
| 442 |
|
|
| 443 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", |
| 444 |
|
&z) == FAILURE) { |
| 445 |
|
return; |
| 446 |
|
} |
| 447 |
|
zend_printf("zend_printf...<br>\n"); |
| 448 |
|
zCriteria_t zcri(z); |
| 449 |
|
zcri.dump(); |
| 450 |
|
RETURN_FALSE |
| 451 |
|
} |
| 452 |
|
|
| 453 |
|
ZEND_FUNCTION(vp_test_uids) |
| 454 |
|
{ |
| 455 |
|
zval *z; |
| 456 |
|
|
| 457 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", |
| 458 |
|
&z) == FAILURE) { |
| 459 |
|
return; |
| 460 |
|
} |
| 461 |
|
zend_printf("zend_printf...<br>\n"); |
| 462 |
|
zUIDs_t zuids(z); |
| 463 |
|
zuids.dump(); |
| 464 |
|
RETURN_FALSE |
| 465 |
|
} |
| 466 |
|
|
| 467 |
|
|
| 468 |
|
|
| 469 |
/** DBに接続する。既に接続中の接続は閉じられる。 |
/** DBに接続する。既に接続中の接続は閉じられる。 |
| 470 |
@param host 接続先。省略時はlocalhost |
@param host 接続先。省略時はNULL |
| 471 |
@param user DB接続時のユーザ名。省略時はNULL |
@param user DB接続時のユーザ名。省略時はNULL |
| 472 |
@param password DB接続時のパスワード。省略時はNULL |
@param password DB接続時のパスワード。省略時はNULL |
| 473 |
@param dbname DB接続時のDB名。省略時はNULL |
@param dbname DB接続時のDB名。省略時は"" |
| 474 |
@param port 接続先のポート。省略時は3336 |
@param prefix XOOPS DB のprefix。 |
| 475 |
@return 0 success <br> |
@return 0 success <br> |
| 476 |
@return 1 cannot mysql_init <br> |
int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] ); |
|
@return 2 cannot mysql_real_connect <br> |
|
|
int initialize_db ( char* host="localhost", char* user=NULL, char* password=NULL, char* dbname=NULL, int port=3336 ) |
|
| 477 |
*/ |
*/ |
| 478 |
ZEND_FUNCTION(vp_initialize_db) |
ZEND_FUNCTION(vp_initialize_db) |
| 479 |
{ |
{ |
| 480 |
zval **parameters[5]; |
zval **parameters[5]; |
| 481 |
char *host; |
char *host; |
| 482 |
char *user; |
char *user; |
| 483 |
char *passwd; |
char *password; |
| 484 |
char *db; |
char *dbname; |
| 485 |
int port; |
char *prefix; |
| 486 |
|
|
| 487 |
/* get the number of arguments */ |
/* get the number of arguments */ |
| 488 |
int argNum = ZEND_NUM_ARGS(); |
int argNum = ZEND_NUM_ARGS(); |
| 493 |
if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS) |
if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS) |
| 494 |
WRONG_PARAM_COUNT; |
WRONG_PARAM_COUNT; |
| 495 |
|
|
| 496 |
if (argNum < 1) host = "localhost"; |
if (argNum < 1) host = NULL; |
| 497 |
else host = getZvalString( parameters[0] ); |
else host = getZvalString( parameters[0] ); |
| 498 |
|
|
| 499 |
if (argNum < 2) user = NULL; |
if (argNum < 2) user = NULL; |
| 500 |
else user = getZvalString( parameters[1] ); |
else user = getZvalString( parameters[1] ); |
| 501 |
|
|
| 502 |
if (argNum < 3) passwd = NULL; |
if (argNum < 3) password = NULL; |
| 503 |
else passwd = getZvalString( parameters[2] ); |
else password = getZvalString( parameters[2] ); |
| 504 |
|
|
| 505 |
if (argNum < 4) db = NULL; |
if (argNum < 4) dbname = ""; |
| 506 |
else db = getZvalString( parameters[3] ); |
else dbname = getZvalString( parameters[3] ); |
| 507 |
|
|
| 508 |
if (argNum < 5) port = 3336; |
if (argNum < 5) prefix = ""; |
| 509 |
else port = getZvalInt( parameters[4] ); |
else prefix = getZvalString( parameters[4] ); |
| 510 |
|
|
| 511 |
// 既に接続中なら、一旦切断 |
result_t result = initializeDB( host, user, password, dbname, prefix ); |
|
if ( mysql != NULL ) |
|
|
mysql_close( mysql ); |
|
| 512 |
|
|
| 513 |
// 初期化と接続 |
RETURN_LONG(result); |
|
mysql = mysql_init(NULL); |
|
|
if ( mysql == NULL ){ |
|
|
RETURN_LONG(1); |
|
|
} |
|
|
char *unix_socket = NULL; // ? |
|
|
uint flag = 0; // ? |
|
|
if ( NULL == mysql_real_connect( mysql, host, user, passwd, db, port, unix_socket, flag ) ){ |
|
|
RETURN_LONG(2); |
|
|
} |
|
|
|
|
|
RETURN_LONG(0); |
|
| 514 |
} |
} |
| 515 |
|
|
| 516 |
// session_t* login_user(char* uname, char* passwd) |
// int vp_login_user(string uname, string password) |
| 517 |
ZEND_FUNCTION(vp_login_user) |
ZEND_FUNCTION(vp_login_user) |
| 518 |
{ |
{ |
| 519 |
char *uname; |
char *uname; |
| 526 |
return; |
return; |
| 527 |
} |
} |
| 528 |
|
|
| 529 |
//ここでログイン |
string strUname( uname, unameLen ); |
| 530 |
|
string strPasswd( passwd, passwdLen ); |
| 531 |
|
sessionid_t vpsid; |
| 532 |
RETURN_LONG(0); |
result_t result = loginUser( strUname.c_str(), strPasswd.c_str(), &vpsid ); |
| 533 |
|
if ( result == RES_OK ){ |
| 534 |
|
RETURN_LONG((long)vpsid); |
| 535 |
|
} |
| 536 |
|
else { |
| 537 |
|
//zend_printf( "vpal_debug: vp_login_user(%s, %s): cannot login. result=%d<br>\n", strUname.c_str(), strPasswd.c_str(), (int)result ); |
| 538 |
|
RETURN_FALSE |
| 539 |
|
} |
| 540 |
} |
} |
| 541 |
|
|
| 542 |
// void logout_user( session_t* sid ) |
// void vp_logout_user(int vpsid) |
| 543 |
ZEND_FUNCTION(vp_logout_user) |
ZEND_FUNCTION(vp_logout_user) |
| 544 |
{ |
{ |
| 545 |
long sid; |
long sid; |
| 548 |
return; |
return; |
| 549 |
} |
} |
| 550 |
|
|
| 551 |
// ここでログアウト |
logoutUser( (sessionid_t)sid ); |
| 552 |
|
|
| 553 |
RETURN_NULL(); |
RETURN_NULL(); |
| 554 |
} |
} |
| 555 |
|
|
| 556 |
|
// int vp_create_session( string xoops_sess_id, int uid, string remoteHost ) |
| 557 |
|
ZEND_FUNCTION(vp_create_session) |
| 558 |
|
{ |
| 559 |
|
char *xoopsSessionID; |
| 560 |
|
int xoopsSessionIDLen; |
| 561 |
|
long sid, uid; |
| 562 |
|
|
| 563 |
|
long lRemoteHost; |
| 564 |
|
char *pcRemoteHost; |
| 565 |
|
int cbRemoteHost; |
| 566 |
|
struct in_addr inRemoteHost; |
| 567 |
|
|
| 568 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", |
| 569 |
|
&xoopsSessionID, &xoopsSessionIDLen, &uid, |
| 570 |
|
&pcRemoteHost, &cbRemoteHost) == FAILURE) { |
| 571 |
|
return; |
| 572 |
|
} |
| 573 |
|
|
| 574 |
|
// "1.2.3.4" -> 0x01020304変換。不正な文字列なら0とみなす。ipv6未対応 |
| 575 |
|
string strRemoteHost( pcRemoteHost, cbRemoteHost ); |
| 576 |
|
if ( inet_aton( strRemoteHost.c_str(), &inRemoteHost ) != 0 ) |
| 577 |
|
memcpy( &lRemoteHost, &inRemoteHost, 4 ); |
| 578 |
|
else |
| 579 |
|
lRemoteHost = 0; |
| 580 |
|
|
| 581 |
|
string strXoopsSessionID( xoopsSessionID, xoopsSessionIDLen ); |
| 582 |
|
sessionid_t vpsid; |
| 583 |
|
result_t result = createSession( strXoopsSessionID.c_str(), (sessionid_t)sid, (userid_t)uid, &vpsid ); |
| 584 |
|
|
| 585 |
|
RETURN_LONG((long)vpsid); |
| 586 |
|
} |
| 587 |
|
|
| 588 |
|
ZEND_FUNCTION(vp_is_activated) |
| 589 |
|
{ |
| 590 |
|
long sid, uid; |
| 591 |
|
|
| 592 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", |
| 593 |
|
&sid, &uid) == FAILURE) { |
| 594 |
|
return; |
| 595 |
|
} |
| 596 |
|
|
| 597 |
|
bool result = isActivated( (sessionid_t)sid, (userid_t)uid ); |
| 598 |
|
|
| 599 |
|
RETURN_BOOL(result); |
| 600 |
|
} |
| 601 |
|
|
| 602 |
|
ZEND_FUNCTION(vp_activate) |
| 603 |
|
{ |
| 604 |
|
long sid, uid; |
| 605 |
|
bool activated; |
| 606 |
|
|
| 607 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb", |
| 608 |
|
&sid, &uid, &activated) == FAILURE) { |
| 609 |
|
return; |
| 610 |
|
} |
| 611 |
|
|
| 612 |
|
result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated ); |
| 613 |
|
|
| 614 |
|
RETURN_LONG(result); |
| 615 |
|
} |
| 616 |
|
|
| 617 |
|
ZEND_FUNCTION(vp_get_account_count) |
| 618 |
|
{ |
| 619 |
|
long sid; |
| 620 |
|
|
| 621 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", |
| 622 |
|
&sid) == FAILURE) { |
| 623 |
|
return; |
| 624 |
|
} |
| 625 |
|
|
| 626 |
|
long count = getAccountCount( (sessionid_t)sid ); |
| 627 |
|
|
| 628 |
|
RETURN_LONG(count); |
| 629 |
|
} |
| 630 |
|
|
| 631 |
|
ZEND_FUNCTION(vp_delete_account) |
| 632 |
|
{ |
| 633 |
|
long sid, uid; |
| 634 |
|
|
| 635 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", |
| 636 |
|
&sid, &uid) == FAILURE) { |
| 637 |
|
return; |
| 638 |
|
} |
| 639 |
|
|
| 640 |
|
result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid ); |
| 641 |
|
|
| 642 |
|
RETURN_LONG(result); |
| 643 |
|
} |
| 644 |
|
|
| 645 |
|
// int vp_get_account( int sid, int uid, array account ) |
| 646 |
|
ZEND_FUNCTION(vp_get_account) |
| 647 |
|
{ |
| 648 |
|
long sid, uid; |
| 649 |
|
zval *zaccount; |
| 650 |
|
|
| 651 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla", |
| 652 |
|
&sid, &uid, &zaccount) == FAILURE) { |
| 653 |
|
return; |
| 654 |
|
} |
| 655 |
|
|
| 656 |
|
const account_t *paccount; |
| 657 |
|
result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount ); |
| 658 |
|
if ( RES_OK == result ){ |
| 659 |
|
accountToZval( paccount, zaccount ); |
| 660 |
|
freeResult( paccount ); |
| 661 |
|
} |
| 662 |
|
|
| 663 |
|
RETURN_LONG(result); |
| 664 |
|
} |
| 665 |
|
|
| 666 |
|
// int vp_get_accoutns( int sid, array uids, array criteria, array accounts ); |
| 667 |
|
ZEND_FUNCTION(vp_get_accounts) |
| 668 |
|
{ |
| 669 |
|
result_t result; |
| 670 |
|
long sid; |
| 671 |
|
zval *zuids; |
| 672 |
|
zval *zcriteria; |
| 673 |
|
zval *zaccount; |
| 674 |
|
|
| 675 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa", |
| 676 |
|
&sid, &zuids, &zcriteria, &zaccount) == FAILURE) { |
| 677 |
|
return; |
| 678 |
|
} |
| 679 |
|
|
| 680 |
|
zCriteria_t zcri(zcriteria); |
| 681 |
|
result = zcri.getResult(); |
| 682 |
|
if ( RES_OK == result ){ |
| 683 |
|
zUIDs_t zUIDs(zuids); |
| 684 |
|
result = zUIDs.getResult(); |
| 685 |
|
if ( RES_OK == result ){ |
| 686 |
|
const account_t *paccounts; |
| 687 |
|
int accountLen; |
| 688 |
|
result = getAccounts( (sessionid_t)sid, |
| 689 |
|
zUIDs.getPUID(), zUIDs.getLen(), |
| 690 |
|
&zcri, &paccounts, &accountLen ); |
| 691 |
|
if ( RES_OK == result ){ |
| 692 |
|
accountsToZval( paccounts, accountLen, zaccount ); |
| 693 |
|
freeResult( paccounts ); |
| 694 |
|
} |
| 695 |
|
} |
| 696 |
|
} |
| 697 |
|
|
| 698 |
|
RETURN_LONG(result); |
| 699 |
|
} |
| 700 |
|
|
| 701 |
|
// int vp_insert_account( int sid, array account ); |
| 702 |
|
ZEND_FUNCTION(vp_insert_account) |
|
|
|
|
/* |
|
|
MYSQL *g_mysql_a = NULL; // test db |
|
|
ZEND_FUNCTION(mysql_test1) |
|
| 703 |
{ |
{ |
| 704 |
char *host = NULL; // localhost |
result_t result; |
| 705 |
char *user = NULL; // default |
long sid; |
| 706 |
char *passwd = NULL; // default |
zval *zaccount; |
| 707 |
char *db = "test"; |
|
| 708 |
uint port = 0; // default |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la", |
| 709 |
char *unix_socket = NULL; // ? |
&sid, &zaccount) == FAILURE) { |
| 710 |
uint flag = 0; // ? |
return; |
| 711 |
|
} |
| 712 |
|
|
| 713 |
|
zAccount_t zacc(zaccount); |
| 714 |
|
result = zacc.getResult(); |
| 715 |
|
if ( RES_OK == result ){ |
| 716 |
|
result = insertAccount( (sessionid_t)sid, &zacc ); |
| 717 |
|
} |
| 718 |
|
|
| 719 |
|
RETURN_LONG(result); |
| 720 |
|
} |
| 721 |
|
|
| 722 |
|
// int vp_update_account( int sid, array account ); |
| 723 |
|
ZEND_FUNCTION(vp_update_account) |
| 724 |
|
{ |
| 725 |
|
result_t result; |
| 726 |
|
long sid; |
| 727 |
|
zval *zaccount; |
| 728 |
|
|
| 729 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la", |
| 730 |
|
&sid, &zaccount) == FAILURE) { |
| 731 |
|
return; |
| 732 |
|
} |
| 733 |
|
|
| 734 |
|
zAccount_t zacc(zaccount); |
| 735 |
|
result = zacc.getResult(); |
| 736 |
|
if ( RES_OK == result ){ |
| 737 |
|
result = updateAccount( (sessionid_t)sid, &zacc ); |
| 738 |
|
} |
| 739 |
|
|
| 740 |
|
RETURN_LONG(result); |
| 741 |
|
} |
| 742 |
|
|
| 743 |
if ( g_mysql_a != NULL ) |
// int vp_dump_uids( int sid, array criteria, array uids ); |
| 744 |
mysql_close( g_mysql_a ); |
ZEND_FUNCTION(vp_dump_uids) |
| 745 |
g_mysql_a = mysql_init(NULL); |
{ |
| 746 |
if ( g_mysql_a == NULL ){ |
result_t result; |
| 747 |
zend_error(E_WARNING, "mysql_test1: cannot mysql_init()"); |
long sid; |
| 748 |
RETURN_NULL(); |
zval *zcriteria; |
| 749 |
|
zval *zuids; |
| 750 |
|
|
| 751 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa", |
| 752 |
|
&sid, &zcriteria, &zuids) == FAILURE) { |
| 753 |
|
return; |
| 754 |
} |
} |
| 755 |
|
|
| 756 |
if (NULL == mysql_real_connect(g_mysql_a, host, user, passwd, db, port, unix_socket, flag)){ |
zCriteria_t zcri(zcriteria); |
| 757 |
zend_error(E_WARNING, "mysql_test1: cannot connect to mysql"); |
result = zcri.getResult(); |
| 758 |
RETURN_NULL(); |
if ( RES_OK == result ){ |
| 759 |
|
userid_t *puid; |
| 760 |
|
int uidLen; |
| 761 |
|
result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen ); |
| 762 |
|
if ( RES_OK == result ){ |
| 763 |
|
uidsToZval( puid, uidLen, &zuids ); |
| 764 |
|
freeResult( puid ); |
| 765 |
|
} |
| 766 |
} |
} |
| 767 |
|
|
| 768 |
int result = mysql_query(g_mysql_a, "select * from test1"); |
RETURN_LONG(result); |
| 769 |
unsigned int err = mysql_errno(g_mysql_a); |
} |
| 770 |
if (result || err){ |
|
| 771 |
zend_error(E_WARNING, "mysql_test1: mysql_query() failed."); |
// int vp_get_group_count( int sid ); |
| 772 |
RETURN_NULL(); |
ZEND_FUNCTION(vp_get_group_count) |
| 773 |
|
{ |
| 774 |
|
result_t result; |
| 775 |
|
long sid; |
| 776 |
|
|
| 777 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", |
| 778 |
|
&sid) == FAILURE) { |
| 779 |
|
return; |
| 780 |
} |
} |
| 781 |
|
|
| 782 |
MYSQL_RES *res = mysql_store_result(g_mysql_a); |
int count = getGroupCount( (sessionid_t)sid ); |
|
int num_fields = mysql_num_fields(res); |
|
|
int rows = (int)mysql_num_rows(res); |
|
| 783 |
|
|
| 784 |
zval *ar1; |
RETURN_LONG(count); |
| 785 |
MAKE_STD_ZVAL(ar1); |
} |
| 786 |
array_init(ar1); |
|
| 787 |
|
// int vp_get_group_by_uid( int sid, int uid, array criteria, array gids ); |
| 788 |
|
ZEND_FUNCTION(vp_get_groups_by_uid) |
| 789 |
|
{ |
| 790 |
|
result_t result; |
| 791 |
|
long sid, uid; |
| 792 |
|
zval *zcriteria; |
| 793 |
|
zval *zgids; |
| 794 |
|
|
| 795 |
for ( int i = 0; i < rows; i++ ){ |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa", |
| 796 |
MYSQL_ROW row = mysql_fetch_row(res); |
&sid, &uid, &zcriteria, &zgids) == FAILURE) { |
| 797 |
unsigned long *lengths = mysql_fetch_lengths(res); |
return; |
| 798 |
|
} |
| 799 |
zval *ar2; |
|
| 800 |
MAKE_STD_ZVAL(ar2); |
zCriteria_t zcri(zcriteria); |
| 801 |
array_init(ar2); |
result = zcri.getResult(); |
| 802 |
|
if ( RES_OK == result ){ |
| 803 |
for ( int j = 0; j < num_fields; j++ ){ |
groupid_t *pgids; |
| 804 |
add_index_stringl(ar2, (uint)j, row[j], lengths[j], 1); |
int gidLen; |
| 805 |
|
result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen ); |
| 806 |
|
if ( RES_OK == result ){ |
| 807 |
|
gidsToZval( pgids, gidLen, &zgids ); |
| 808 |
|
freeResult( pgids ); |
| 809 |
} |
} |
|
add_index_zval(ar1, (uint)i, ar2); |
|
| 810 |
} |
} |
| 811 |
|
|
| 812 |
mysql_free_result(res); |
RETURN_LONG(result); |
| 813 |
*return_value = *ar1; |
} |
|
zval_copy_ctor(return_value); |
|
| 814 |
|
|
| 815 |
|
|
| 816 |
|
// int vp_is_group_admin( int sid, int gid, int uid ); |
| 817 |
|
ZEND_FUNCTION(vp_is_group_admin) |
| 818 |
|
{ |
| 819 |
|
result_t result; |
| 820 |
|
long sid, gid, uid; |
| 821 |
|
|
| 822 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", |
| 823 |
|
&sid, &gid, &uid) == FAILURE) { |
| 824 |
|
return; |
| 825 |
|
} |
| 826 |
|
|
| 827 |
|
bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid ); |
| 828 |
|
|
| 829 |
|
RETURN_BOOL(b); |
| 830 |
} |
} |
|
*/ |
|
| 831 |
|
|
| 832 |
|
// int vp_dump_gids( int sid, array criteria, array gids ); |
| 833 |
|
ZEND_FUNCTION(vp_dump_gids) |
| 834 |
|
{ |
| 835 |
|
result_t result; |
| 836 |
|
long sid; |
| 837 |
|
zval *zcriteria; |
| 838 |
|
zval *zgids; |
| 839 |
|
|
| 840 |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa", |
| 841 |
|
&sid, &zcriteria, &zgids) == FAILURE) { |
| 842 |
|
return; |
| 843 |
|
} |
| 844 |
|
|
| 845 |
|
zCriteria_t zcri(zcriteria); |
| 846 |
|
result = zcri.getResult(); |
| 847 |
|
if ( RES_OK == result ){ |
| 848 |
|
groupid_t *pgid; |
| 849 |
|
int gidLen; |
| 850 |
|
result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen ); |
| 851 |
|
if ( RES_OK == result ){ |
| 852 |
|
gidsToZval( pgid, gidLen, &zgids ); |
| 853 |
|
freeResult( pgid ); |
| 854 |
|
} |
| 855 |
|
} |
| 856 |
|
|
| 857 |
|
RETURN_LONG(result); |
| 858 |
|
} |