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.23 - (show annotations) (download) (as text)
Sat Jan 15 00:39:16 2005 UTC (19 years, 2 months ago) by aga
Branch: MAIN
Changes since 1.22: +1 -3 lines
File MIME type: text/x-c++src
・x_xnpaccount_item_basicの構造を変更.

1 /*
2 $Revision: 1.22 $
3 XNPAL: XooNiPs Platform Abstract Layer
4
5 zend_parse_parameters??hp4.1.0??綽?荀?
6 .so???<?ゃ?????????荀????????贋????舟??鴻????
7 C++?с????extern "C"{}, BEGIN/END_EXTERN_C()??綽?荀???
8 */
9
10
11 #include <stdio.h>
12 #include "criteria.h"
13 #include "common.h"
14 #include "commonal.h"
15 #include "session.h"
16 #include "group.h"
17 #include "account.h"
18 #include "xnpal.h"
19
20 // for inet_aton
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24
25 // global variables
26
27 PHP_MSHUTDOWN_FUNCTION(xnpalmod)
28 {
29 uninitializeDB();
30 return SUCCESS;
31 }
32
33 /* declaration of functions to be exported */
34 extern "C" {
35 ZEND_FUNCTION(first_module );
36 ZEND_FUNCTION(xnp_initialize_db );
37 ZEND_FUNCTION(xnp_login_user );
38 ZEND_FUNCTION(xnp_logout_user );
39 ZEND_FUNCTION(xnp_create_session );
40 ZEND_FUNCTION(xnp_get_session );
41 ZEND_FUNCTION(xnp_is_activated );
42 ZEND_FUNCTION(xnp_activate );
43 ZEND_FUNCTION(xnp_get_account_count );
44 ZEND_FUNCTION(xnp_delete_account );
45 ZEND_FUNCTION(xnp_get_account );
46 ZEND_FUNCTION(xnp_get_accounts );
47 ZEND_FUNCTION(xnp_insert_account );
48 ZEND_FUNCTION(xnp_update_account );
49 ZEND_FUNCTION(xnp_dump_uids );
50 ZEND_FUNCTION(xnp_get_group_count );
51 ZEND_FUNCTION(xnp_get_groups_by_uid );
52 ZEND_FUNCTION(xnp_is_group_admin );
53 ZEND_FUNCTION(xnp_dump_gids );
54 ZEND_FUNCTION(xnp_dump_group_admins );
55 ZEND_FUNCTION(xnp_delete_member );
56 ZEND_FUNCTION(xnp_insert_member );
57 ZEND_FUNCTION(xnp_get_members );
58 ZEND_FUNCTION(xnp_delete_group );
59 ZEND_FUNCTION(xnp_insert_group );
60 ZEND_FUNCTION(xnp_update_group );
61 ZEND_FUNCTION(xnp_get_group );
62 ZEND_FUNCTION(xnp_get_groups );
63 ZEND_FUNCTION(xnp_is_moderator );
64 ZEND_FUNCTION(xnp_get_uid );
65
66 ZEND_FUNCTION(xnp_get_all_indexes );
67 ZEND_FUNCTION(xnp_get_indexes );
68 ZEND_FUNCTION(xnp_insert_index );
69 ZEND_FUNCTION(xnp_update_index );
70 ZEND_FUNCTION(xnp_delete_index );
71 ZEND_FUNCTION(xnp_get_index );
72 ZEND_FUNCTION(xnp_is_index_readable );
73 ZEND_FUNCTION(xnp_is_index_writable );
74 ZEND_FUNCTION(xnp_swap_index_sort_number );
75
76 ZEND_FUNCTION(xnp_is_valid_session_id );
77 ZEND_FUNCTION(xnp_get_last_error_string );
78
79 ZEND_FUNCTION(xnp_test_criteria );
80 ZEND_FUNCTION(xnp_test_uids );
81 };
82 /* compiled function list so Zend knows what's in this module */
83 zend_function_entry xnpalmod_functions[] =
84 {
85 ZEND_FE(first_module ,NULL)
86 ZEND_FE(xnp_initialize_db ,NULL)
87 ZEND_FE(xnp_login_user ,NULL)
88 ZEND_FE(xnp_logout_user ,NULL)
89 ZEND_FE(xnp_create_session ,NULL)
90 ZEND_FE(xnp_get_session ,NULL)
91 ZEND_FE(xnp_is_activated ,NULL)
92 ZEND_FE(xnp_activate ,NULL)
93 ZEND_FE(xnp_get_account_count ,NULL)
94 ZEND_FE(xnp_delete_account ,NULL)
95 ZEND_FE(xnp_get_account ,NULL)
96 ZEND_FE(xnp_get_accounts ,NULL)
97 ZEND_FE(xnp_insert_account ,NULL)
98 ZEND_FE(xnp_update_account ,NULL)
99 ZEND_FE(xnp_dump_uids ,NULL)
100 ZEND_FE(xnp_get_group_count ,NULL)
101 ZEND_FE(xnp_get_groups_by_uid ,NULL)
102 ZEND_FE(xnp_is_group_admin ,NULL)
103 ZEND_FE(xnp_dump_gids ,NULL)
104 ZEND_FE(xnp_dump_group_admins ,NULL)
105 ZEND_FE(xnp_delete_member ,NULL)
106 ZEND_FE(xnp_insert_member ,NULL)
107 ZEND_FE(xnp_get_members ,NULL)
108 ZEND_FE(xnp_delete_group ,NULL)
109 ZEND_FE(xnp_insert_group ,NULL)
110 ZEND_FE(xnp_update_group ,NULL)
111 ZEND_FE(xnp_get_group ,NULL)
112 ZEND_FE(xnp_get_groups ,NULL)
113 ZEND_FE(xnp_is_moderator ,NULL)
114 ZEND_FE(xnp_get_uid ,NULL)
115
116 ZEND_FE(xnp_get_all_indexes ,NULL)
117 ZEND_FE(xnp_get_indexes ,NULL)
118 ZEND_FE(xnp_insert_index ,NULL)
119 ZEND_FE(xnp_update_index ,NULL)
120 ZEND_FE(xnp_delete_index ,NULL)
121 ZEND_FE(xnp_get_index ,NULL)
122 ZEND_FE(xnp_is_index_readable ,NULL)
123 ZEND_FE(xnp_is_index_writable ,NULL)
124 ZEND_FE(xnp_swap_index_sort_number ,NULL)
125
126 ZEND_FE(xnp_is_valid_session_id ,NULL)
127 ZEND_FE(xnp_get_last_error_string ,NULL)
128 ZEND_FE(xnp_test_criteria ,NULL)
129 ZEND_FE(xnp_test_uids ,NULL)
130 {NULL, NULL, NULL}
131 };
132
133 /* compiled module information */
134 zend_module_entry xnpalmod_module_entry =
135 {
136 STANDARD_MODULE_HEADER,
137 "Visiome Platform Abstract Layer",
138 xnpalmod_functions,
139 NULL,
140 PHP_MSHUTDOWN(xnpalmod),
141 NULL,
142 NULL,
143 NULL,
144 NO_VERSION_YET,
145 STANDARD_MODULE_PROPERTIES
146 };
147
148 /* implement standard "stub" routine to introduce ourselves to Zend */
149 #if COMPILE_DL_FIRST_MODULE
150 BEGIN_EXTERN_C()
151 ZEND_GET_MODULE(xnpalmod)
152 END_EXTERN_C()
153 #endif
154
155
156 /* implement function that is meant to be made available to PHP */
157 ZEND_FUNCTION(first_module)
158 {
159 long parameter;
160 // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
161 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
162 return;
163 }
164 parameter++;
165 RETURN_LONG(parameter);
166 }
167 /** zval????C????絖?????緇?????
168 */
169 char *getZvalString( zval **p ){
170 convert_to_string_ex(p);
171 return Z_STRVAL_PP(p); //(**p).value.str.val;
172 }
173
174 /** zval????int??緇?????
175 */
176 int getZvalInt( zval **p ){
177 convert_to_long_ex(p);
178 return Z_LVAL_PP(p); // (int)(**p).value.lval;
179 }
180
181 // keylen????鮎??0????????
182 static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
183 zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
184 if ( res == HASH_KEY_IS_STRING ){
185 char *p = new char[keyLen+1];
186 memcpy( p, key, keyLen );
187 p[keyLen] = 0;
188 zend_printf( " key is string[%s]<br>\n", p );
189 }
190 else {
191 zend_printf( " key is integer[%d]<br>\n", index );
192 }
193 }
194
195
196 /** zval*????criteria_t?????????????????????鴻??????紊掩??????getResult()!=RES_OK <br>
197 criteria :
198 array( 'start'=>0, 'rows'=>10,
199 'orders'=>array(
200 array('name'=>'id','order'=>'0'),
201 array('name'=>'timestamp','name'=>'1'), ...)
202 ); ??????就???f?渇????
203 */
204 class zCriteria_t : public criteria {
205 private:
206 result_t result;
207
208 // pz: array('name'=>'timestamp','name'=>'1')
209 // ????????orderby??篏???????申????
210 void setOrder( zval *pz ){
211 char *column = 0;
212 order_t order = (order_t)0;
213
214 HashPosition pos;
215 zval **ppzTmp = 0;
216 int res2;
217 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
218 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
219 char *key = 0;
220 uint keyLen = 0;
221 ulong index = 0;
222 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
223 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
224 //print_hash_key( keyType, key, keyLen, index );
225 if ( strncasecmp( key, "name", keyLen ) == 0 && keyLen == 5 ){
226 SEPARATE_ZVAL(ppzTmp);
227 column = getZvalString(ppzTmp);
228 // zend_printf( "column=%s<br>\n", column );
229 }
230 else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
231 SEPARATE_ZVAL(ppzTmp);
232 order = (order_t)getZvalInt(ppzTmp);
233 // zend_printf( "order=%d<br>\n", order );
234 }
235 }
236
237 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
238 }
239 if ( column ){
240 orderby *o = new orderby( column, order );
241 addOrderBy( o );
242 }
243
244 result = RES_OK;
245 }
246
247 // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
248 void setOrders( zval *pz ){
249 HashPosition pos;
250
251 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
252
253 zval **ppzTmp = 0;
254 int res2;
255 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
256 char *key = 0;
257 uint keyLen = 0;
258 ulong index = 0;
259 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
260 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
261 //print_hash_key( keyType, key, keyLen, index );
262 setOrder( *ppzTmp );
263 }
264 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
265 }
266 result = RES_OK;
267 }
268
269 void initialize( zval *pz ){
270 HashPosition pos;
271 zval **ppzTmp = 0;
272 int res2;
273 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
274 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
275 char *key = 0;
276 uint keyLen = 0;
277 ulong index = 0;
278 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
279 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
280 //print_hash_key( keyType, key, keyLen, index );
281 if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
282 SEPARATE_ZVAL(ppzTmp);
283 int tmp = getZvalInt(ppzTmp);
284 // zend_printf( "start=%d<br>\n", tmp );
285 setLimit( tmp, getLimitRows() );
286 }
287 else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
288 SEPARATE_ZVAL(ppzTmp);
289 int tmp = getZvalInt(ppzTmp);
290 // zend_printf( "rows=%d<br>\n", tmp );
291 setLimit( getLimitStart(), tmp );
292 }
293 else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
294 setOrders( *ppzTmp );
295 }
296 else
297 ; // ignore unknown key
298 }
299 else
300 ; // ignore bad key
301 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
302 }
303 result = RES_OK;
304 }
305
306 public:
307 zCriteria_t() : criteria(){ result = RES_ERROR; }
308 zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
309 zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
310 result_t getResult(){ return result; };
311
312 void dump(){
313 zend_printf( "dumping zCriteria...<br>\n" );
314 zend_printf( "result=%d<br>\n", (int)result );
315 zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() );
316 const orderby *p = headOrderBy();
317 while ( p ){
318 zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() );
319 p = nextOrderBy();
320 }
321 }
322 };
323
324
325 /** ?f?渇???????≪???祉?鴻????ong?ゃ??緇?????
326 @param ht ?f?渇????
327 @param key ????/span>
328 @param val long?ゃ?????????????ゃ?潟??/span>
329 @return ????????true
330 */
331 static bool hashGetLong( HashTable *ht, const char *key, long *val ){
332 zval **tmp;
333 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
334 convert_to_long_ex( tmp );
335 *val = Z_LVAL_PP(tmp);
336 return true;
337 }
338 return false;
339 }
340
341 /** ?f?渇???????≪???祉?鴻??????絖?????緇?????
342 @param ht ?f?渇????
343 @param key ????/span>
344 @param val ??絖????????????????ゃ?潟??/span>
345 @return ????????true
346 */
347 static bool hashGetString( HashTable *ht, const char *key, char **val ){
348 zval **tmp;
349 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
350 convert_to_string_ex( tmp );
351 *val = Z_STRVAL_PP(tmp);
352 return true;
353 }
354 return false;
355 }
356
357 /** ?f?渇???????≪???祉?鴻????ouble?ゃ??緇?????
358 @param ht ?f?渇????
359 @param key ????/span>
360 @param val double?ゃ?????????????ゃ?潟??/span>
361 @return ????????true
362 */
363 static bool hashGetDouble( HashTable *ht, const char *key, double *val ){
364 zval **tmp;
365 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
366 convert_to_double_ex( tmp );
367 *val = Z_DVAL_PP(tmp);
368 return true;
369 }
370 return false;
371 }
372
373 /** zval*????account?????????????????????鴻?? <br>
374 ????紊掩??????getResult()!=RES_OK <br>
375 */
376 class zAccount_t : public account {
377 private:
378 result_t result;
379 void initialize(zval *pz){
380 HashTable *ht = Z_ARRVAL_P(pz);
381 long l;
382 char *p;
383 double d;
384 if ( hashGetLong ( ht, "uid" , &l ) ) setUID ( l );
385 if ( hashGetString( ht, "uname" , &p ) ) setUname ( p );
386 if ( hashGetString( ht, "name" , &p ) ) setName ( p );
387 if ( hashGetString( ht, "email" , &p ) ) setEmail ( p );
388 if ( hashGetString( ht, "url" , &p ) ) setURL ( p );
389 if ( hashGetString( ht, "user_avatar" , &p ) ) setUserAvatar ( p );
390 if ( hashGetString( ht, "user_icq" , &p ) ) setUserIcq ( p );
391 if ( hashGetString( ht, "user_from" , &p ) ) setUserFrom ( p );
392 if ( hashGetString( ht, "user_sig" , &p ) ) setUserSig ( p );
393 if ( hashGetString( ht, "actkey" , &p ) ) setActkey ( p );
394 if ( hashGetString( ht, "user_aim" , &p ) ) setUserAim ( p );
395 if ( hashGetString( ht, "user_yim" , &p ) ) setUserYim ( p );
396 if ( hashGetString( ht, "user_msnm" , &p ) ) setUserMsnm ( p );
397 if ( hashGetString( ht, "pass" , &p ) ) setPass ( p );
398 if ( hashGetString( ht, "theme" , &p ) ) setTheme ( p );
399 if ( hashGetString( ht, "umode" , &p ) ) setUmode ( p );
400 if ( hashGetString( ht, "user_occ" , &p ) ) setUserOcc ( p );
401 if ( hashGetString( ht, "bio" , &p ) ) setBio ( p );
402 if ( hashGetString( ht, "user_intrest" , &p ) ) setUserIntrest ( p );
403 if ( hashGetDouble( ht, "timezone_offset" , &d ) ) setTimezoneOffset ( d );
404 if ( hashGetLong ( ht, "attachsig" , &l ) ) setAttachsig ( l );
405 if ( hashGetLong ( ht, "last_login" , &l ) ) setLastLogin ( l );
406 if ( hashGetLong ( ht, "level" , &l ) ) setLevel ( l );
407 if ( hashGetLong ( ht, "notify_method" , &l ) ) setNotifyMethod ( l );
408 if ( hashGetLong ( ht, "notify_mode" , &l ) ) setNotifyMode ( l );
409 if ( hashGetLong ( ht, "posts" , &l ) ) setPosts ( l );
410 if ( hashGetLong ( ht, "rank" , &l ) ) setRank ( l );
411 if ( hashGetLong ( ht, "uorder" , &l ) ) setUorder ( l );
412 if ( hashGetLong ( ht, "user_mailok" , &l ) ) setUserMailok ( l );
413 if ( hashGetLong ( ht, "user_regdate" , &l ) ) setUserRegdate ( l );
414 if ( hashGetLong ( ht, "user_viewemail" , &l ) ) setUserViewemail ( l );
415 if ( hashGetLong ( ht, "activate" , &l ) ) setActivate ( l );
416 if ( hashGetString( ht, "address" , &p ) ) setAddress ( p );
417 if ( hashGetString( ht, "division" , &p ) ) setDivision ( p );
418 if ( hashGetString( ht, "tel" , &p ) ) setTel ( p );
419 if ( hashGetString( ht, "company_name" , &p ) ) setCompanyName ( p );
420 if ( hashGetString( ht, "country" , &p ) ) setCountry ( p );
421 if ( hashGetString( ht, "zipcode" , &p ) ) setZipcode ( p );
422 if ( hashGetString( ht, "fax" , &p ) ) setFax ( p );
423 if ( hashGetString( ht, "base_url" , &p ) ) setBaseURL ( p );
424 if ( hashGetLong ( ht, "notice_mail" , &l ) ) setNoticeMail ( l );
425 if ( hashGetLong ( ht, "notice_mail_since" , &l ) ) setNoticeMailSince ( l );
426 if ( hashGetLong ( ht, "private_index_id " , &l ) ) setPrivateIndexID ( l );
427
428 result = RES_OK;
429 }
430 public:
431 zAccount_t() : account(){ result = RES_ERROR; }
432
433 /** ?潟?潟?鴻????????/span>
434 @param pz array( 'uid'=>1, 'uname'=>'root', ... ); ??????就???f?渇???? */
435 zAccount_t( zval *pz ) : account(){ initialize(pz); }
436 zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
437 result_t getResult(){ return result; };
438 };
439
440 class zIndex_t : public index {
441 private:
442 result_t result;
443
444 void initialize(zval *pz){
445 HashTable *ht = Z_ARRVAL_P(pz);
446 long l;
447 char *p;
448 double d;
449 if ( hashGetLong ( ht, "item_id" , &l ) ) setItemID ( l );
450 if ( hashGetLong ( ht, "item_type_id" , &l ) ) setItemTypeID ( l );
451 if ( hashGetLong ( ht, "contributor_uid" , &l ) ) setContributorUID ( l );
452 if ( hashGetString( ht, "title" , &p ) ) setTitle ( p );
453 if ( hashGetString( ht, "keywords" , &p ) ) setKeywords ( p );
454 if ( hashGetString( ht, "description" , &p ) ) setDescription ( p );
455 if ( hashGetLong ( ht, "last_update_date" , &l ) ) setLastUpdateDate ( l );
456 if ( hashGetLong ( ht, "creation_date" , &l ) ) setCreationDate ( l );
457 if ( hashGetLong ( ht, "parent_index_id" , &l ) ) setParentIndexID ( l );
458 if ( hashGetLong ( ht, "owner_uid" , &l ) ) setOwnerUID ( l );
459 if ( hashGetLong ( ht, "owner_gid" , &l ) ) setOwnerGID ( l );
460 if ( hashGetLong ( ht, "open_level" , &l ) ) setOpenLevel ( l );
461 if ( hashGetLong ( ht, "sort_number" , &l ) ) setSortNumber ( l );
462
463 result = RES_OK;
464 }
465 public:
466 zIndex_t() : index(){ result = RES_ERROR; }
467 zIndex_t( zval *pz ) : index(){ initialize(pz); }
468 zIndex_t( zval **ppz ) : index() { initialize(*ppz); }
469 result_t getResult(){ return result; };
470
471 void dump(){
472 }
473 };
474
475 /** zval*????(userid_t *puid,int uidLen)?????????????????????鴻?? <br>
476 ????紊掩??????getResult()!=RES_OK <br>
477 */
478 class zUIDs_t {
479 private:
480 result_t result;
481 userid_t *pUID;
482 int len;
483 public:
484 zUIDs_t(){
485 pUID = 0;
486 len = 0;
487 result = RES_ERROR;
488 }
489
490 /** ?潟?潟?鴻????????/span>
491 @param pza array( '1', '3', '4', '6', ... ); ??????就?????? */
492 zUIDs_t( zval *pza ){
493 pUID = 0;
494 len = 0;
495 result = RES_ERROR;
496
497 if ( Z_TYPE_P(pza) != IS_ARRAY ){
498 result = RES_ERROR;
499 }
500 else {
501 len = zend_hash_num_elements(Z_ARRVAL_P(pza));
502 if(len == 0) {
503 pUID = new userid_t[1];
504 result = RES_OK;
505 }
506 else {
507 /* php/ext/standard/string.c ? implode??????????????????
508 zend_hash_*???????ャ?<?潟???c????????????????鐚?
509 */
510 zval **tmp;
511 HashPosition pos;
512 int i = 0;
513 pUID = new userid_t[len];
514
515 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
516 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
517 SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
518 convert_to_long_ex(tmp);
519 if ( i < len )
520 pUID[i++] = Z_LVAL_PP(tmp);
521 zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
522 }
523 len = i;
524 result = RES_OK;
525 }
526 }
527 }
528
529 ~zUIDs_t(){
530 if ( pUID ) delete[] pUID;
531 }
532 result_t getResult(){ return result; }
533 userid_t *getPUID(){ return pUID; }
534 int getLen(){ return len; }
535 void dump(){
536 zend_printf( "dumping zUIDs...<br>\n" );
537 zend_printf( "result=%d<br>\n", (int)result );
538 zend_printf( "len=%d<br>\n", len );
539 for ( int i = 0; i < len; i++ ){
540 zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
541 }
542 }
543 };
544
545 /**
546 *
547 * uids_t????????PHP???????????????
548 *
549 * @param pUID 紊???????serid_t??????
550 * @param len pUID?????????激??
551 * @param pz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
552 * @return RES_OK
553 *
554 */
555 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
556 {
557 zend_hash_clean( Z_ARRVAL_PP(ppz) );
558
559 // add UIDs
560 for ( int i = 0; i < len; i++ ){
561 add_next_index_long(*ppz, (long)(pUID[i]) );
562 }
563
564 return RES_OK;
565 }
566 /**
567 *
568 * groupid_t????????PHP???????????????
569 * @param pGID 紊???????roupid_t??????
570 * @param len pGID?????????激??
571 * @param ppz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
572 * @return RES_OK
573 *
574 */
575 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
576 {
577 zend_hash_clean( Z_ARRVAL_PP(ppz) );
578
579 // add GIDs
580 for ( int i = 0; i < len; i++ ){
581 add_next_index_long(*ppz, (long)(pGID[i]) );
582 }
583
584 return RES_OK;
585 }
586
587
588 /**
589 *
590 * account_t????絎鴻??PHP???????????????
591 * @param pAccount 紊???????ccount_t*
592 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
593 * @return RES_OK
594 *
595 */
596 result_t accountToZval( const account_t *pAccount, zval *z )
597 {
598 zend_hash_clean( z -> value.ht );
599
600 add_assoc_long( z, "uid", pAccount -> getUID( ) );
601 add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
602 add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
603 add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
604 add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
605 add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
606 add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
607 add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
608 add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
609 add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
610 add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
611 add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
612 add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
613 add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
614 add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
615 add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
616 add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
617 add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
618 add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
619 add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
620 add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
621 add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
622 add_assoc_long( z, "level", pAccount -> getLevel( ) );
623 add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
624 add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
625 add_assoc_long( z, "posts", pAccount -> getPosts( ) );
626 add_assoc_long( z, "rank", pAccount -> getRank( ) );
627 add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
628 add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
629 add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
630 add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
631
632 add_assoc_long( z, "activate", pAccount -> getActivate( ) );
633 add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
634 add_assoc_string( z, "division", ( char* )pAccount -> getDivision( ), 1 );
635 add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
636 add_assoc_string( z, "company_name", ( char* )pAccount -> getCompanyName( ), 1 );
637 add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
638 add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
639 add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
640 add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
641 add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
642 add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
643 add_assoc_long( z, "private_index_id", pAccount -> getPrivateIndexID( ) );
644 return RES_OK;
645 }
646 /**
647 *
648 * 茲??違??ccount_t????絎鴻??PHP?????????????????????
649 * @param pAccounts 紊???????ccount_t*
650 * @param accountsLen pAccounts?????????激??
651 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
652 * @return RES_OK
653 *
654 z: ?????????????????????????? <br>
655 array(
656 array(
657 'uid'=>100,
658 'activate'=>1,
659 'division'=>'foo',
660 'tel'=>'123-456-789',
661 ...
662 ),
663 ...
664 )
665 */
666 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
667 {
668 zend_hash_clean( z -> value.ht );
669 for( int i = 0; i < accountsLen; i++ ){
670 zval *new_array;
671 MAKE_STD_ZVAL(new_array);
672 if(array_init(new_array) != SUCCESS){
673 return RES_ERROR;
674 }
675 add_index_zval( z, i, new_array );
676 accountToZval( &pAccounts[ i ], new_array );
677 }
678 return RES_OK;
679 }
680
681 /**
682 *
683 * 茲??違??roup_t????絎鴻??PHP?????????????????????
684 * @param pGroups 紊???????roup_t*
685 * @param groupsLen pGroups?????????激??
686 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
687 * @return RES_OK
688 *
689 z: ?????????????????????????? <br>
690 array(
691 array(
692 'gid'=>1,
693 'gname'=>'foo group',
694 'gdesc'=>'group of foo'
695 ),
696 ...
697 )
698 */
699 result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
700 {
701 zend_hash_clean( z -> value.ht );
702 for( int i = 0; i < groupsLen; i++ ){
703 zval *new_array;
704 MAKE_STD_ZVAL(new_array);
705 if(array_init(new_array) != SUCCESS){
706 return RES_ERROR;
707 }
708 add_index_zval( z, i, new_array );
709 add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
710 add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
711 add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
712 add_assoc_long( new_array, "group_index_id", pGroups[ i ].getGroupIndexID( ) );
713 }
714 return RES_OK;
715 }
716
717 /**
718 *
719 * group_t????絎鴻??PHP???f?渇?????????????
720 *
721 * @param pGroup 紊????????違???若??????/span>
722 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
723 * @return RES_OK
724 *
725 */
726 result_t groupToZval( const group_t *pGroup, zval *z )
727 {
728 zend_hash_clean( z -> value.ht );
729 add_assoc_long( z, "gid", pGroup -> getGID( ) );
730 add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
731 add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
732 add_assoc_long( z, "group_index_id", pGroup -> getGroupIndexID( ) );
733 return RES_OK;
734 }
735
736 /**
737 *
738 * PHP???f?渇????????絎鴻??group_t?????????
739 *
740 * @param z 紊????????f?渇????
741 * @param pGroup 紊???腟??????吾??莨若???違???若??
742 * @return RES_OK
743 *
744 */
745 result_t zvalToGroup( zval *z, group_t *pGroup )
746 {
747 zval **tmp;
748 HashPosition pos;
749 int i = 0;
750 char* key = 0;
751
752 key = "gid";
753 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
754 convert_to_long_ex( tmp ) ;
755 pGroup -> setGID( (*tmp) -> value.lval );
756 }
757 key = "gname";
758 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
759 convert_to_string_ex( tmp ) ;
760 pGroup -> setGname( (*tmp) -> value.str.val );
761 }
762 key = "gdesc";
763 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
764 convert_to_string_ex( tmp ) ;
765 pGroup -> setDesc( (*tmp) -> value.str.val );
766 }
767 key = "group_index_id";
768 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
769 convert_to_long_ex( tmp ) ;
770 pGroup -> setGroupIndexID( (*tmp) -> value.lval );
771 }
772 return RES_OK;
773 }
774
775 /**
776 *
777 * session_t????絎鴻??PHP???f?渇?????????????
778 *
779 * @param pSession 紊???????ession_t
780 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
781 * @return RES_OK
782 *
783 */
784 result_t sessionToZval( const session_t *pSession, zval *z )
785 {
786 string sessionID(unsignedIntToString(pSession->getSessionID()));
787 add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
788
789 string date(unsignedIntToString((unsigned int)pSession->getDate()));
790 add_assoc_string(z, "date", (char *)date.c_str(), 1);
791
792 string userID(unsignedIntToString((unsigned int)pSession->getUID()));
793 add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
794
795 return RES_OK;
796 }
797
798 /**
799 *
800 * index_t????絎鴻??PHP???????????????
801 * @param pIndex 紊???????ndex_t*
802 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
803 * @return RES_OK
804 *
805 */
806 result_t indexToZval( const index_t *pIndex, zval *z )
807 {
808 zend_hash_clean( z -> value.ht );
809
810 add_assoc_long( z, "item_id", pIndex -> getItemID( ) );
811 add_assoc_long( z, "item_type_id", pIndex -> getItemTypeID( ) );
812 add_assoc_long( z, "contributor_uid", pIndex -> getContributorUID( ) );
813 add_assoc_string( z, "title", ( char* )pIndex -> getTitle( ), 1 );
814 add_assoc_string( z, "keywords", ( char* )pIndex -> getKeywords( ), 1 );
815 add_assoc_string( z, "description", ( char* )pIndex -> getDescription( ), 1 );
816 add_assoc_long( z, "last_update_date", pIndex -> getLastUpdateDate( ) );
817 add_assoc_long( z, "creation_date", pIndex-> getCreationDate( ) );
818 add_assoc_long( z, "parent_index_id", pIndex -> getParentIndexID( ) );
819 add_assoc_long( z, "owner_uid", pIndex -> getOwnerUID( ) );
820 add_assoc_long( z, "owner_gid", pIndex -> getOwnerGID( ) );
821 add_assoc_long( z, "open_level", pIndex -> getOpenLevel( ) );
822 add_assoc_long( z, "sort_number", pIndex -> getSortNumber( ) );
823 return RES_OK;
824 }
825
826 result_t indexesToZval( const index_t *pIndexes, int indexesLen, zval *z )
827 {
828 zend_hash_clean( z -> value.ht );
829 for( int i = 0; i < indexesLen; i++ ){
830 zval *new_array;
831 MAKE_STD_ZVAL(new_array);
832 if(array_init(new_array) != SUCCESS){
833 return RES_ERROR;
834 }
835 add_index_zval( z, i, new_array );
836 indexToZval( &pIndexes[ i ], new_array );
837 }
838 return RES_OK;
839 }
840
841
842
843
844 /** ??絎??????違???若???????宴??緇???<br>
845 int xnp_get_group( int sid, int gid, array group );
846 @param sid XNP???祉???激?с??D
847 @param gid XNP ? group_id
848 @param group 腟?????????????????
849 @return 0 success <br>
850 */
851 ZEND_FUNCTION(xnp_get_group)
852 {
853 long sid, gid;
854 zval *zgroup;
855
856 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
857 &sid, &gid, &zgroup) == FAILURE) {
858 return;
859 }
860
861 const group_t *pgroup;
862 result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
863 if ( RES_OK == result ){
864 groupToZval( pgroup, zgroup );
865 freeGroup( pgroup );
866 }
867
868 RETURN_LONG(result);
869 }
870
871
872 /** ??絎??????違???若??(茲????????宴??緇???<br>
873 xnp_get_groups( int sid, array gids, array criteria, array groups );
874 @param sid XNP???祉???激?с??D
875 @param gids XNP ? group_id ??????
876 @param criteria ?>散
877 @param groups 腟???????????????????????
878 @return 0 success <br>
879 */
880 ZEND_FUNCTION(xnp_get_groups)
881 {
882 result_t result;
883 long sid, uid;
884 zval *zcriteria;
885 zval *zgids;
886 zval *zgroups;
887 zval **ppzTmp = 0;
888 HashPosition pos;
889 int res2;
890 int gidsLen;
891 const group_t* groups;
892 int groupsLen;
893
894 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
895 &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
896 return;
897 }
898
899 //gids???違???若??ID???潟???若????
900 gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
901 groupid_t *gids = new groupid_t[ gidsLen ];
902 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
903 for( int i = 0; i < gidsLen; i++ ){
904 if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
905 SEPARATE_ZVAL(ppzTmp);
906 convert_to_long_ex(ppzTmp);
907 gids[ i ] = Z_LVAL_PP(ppzTmp);
908 }
909 zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
910 }
911
912 zCriteria_t zcri(zcriteria);
913 result = zcri.getResult();
914 if ( RES_OK == result ){
915 result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
916 if ( RES_OK == result ){
917 groupsToZval( groups, groupsLen, zgroups );
918 delete[] gids;
919 freeGroup( groups );
920 }
921 }
922 RETURN_LONG(result);
923 }
924
925
926 /** ??絎????????若?吟???≪?????若?帥??????????茯帥?鴻??<br>
927 int xnp_is_moderator(int sid, int uid)
928 @param sid XNP???祉???激?с??D
929 @param uid xoops ? uid (xoops_users.uid)
930 @return true ?≪?????若?帥?с???? <br>
931 */
932 ZEND_FUNCTION(xnp_is_moderator)
933 {
934 long xnpSessionID;
935 userid_t uid;
936
937 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
938 &xnpSessionID, &uid) == FAILURE) {
939 return;
940 }
941
942 bool result = isModerator( (sessionid_t)xnpSessionID, uid );
943 RETURN_BOOL(result)
944 }
945
946 /** ???若?九??????uid??茯帥?鴻??<br>
947 int xnp_get_uid(string uname,int &uid)
948 @param sid XNP???祉???激?с??D
949 @param uname xoops ? uname (xoops_users.uname)
950 @param uid xoops ? uid (xoops_users.uid) ??????????紊???/span>
951 @return 0 success
952 */
953 ZEND_FUNCTION(xnp_get_uid)
954 {
955 char *uname;
956 int unameLen;
957 zval *zuid;
958 userid_t uid;
959
960 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
961 &uname, &unameLen, &zuid) == FAILURE) {
962 return;
963 }
964
965 if (!PZVAL_IS_REF(zuid)) {
966 zend_error(E_WARNING, "2nd parameter wasn't passed by reference");
967 RETURN_LONG(RES_PHP_NONREF);
968 }
969
970 string strUname( uname, unameLen );
971 result_t result = getUid( strUname.c_str(), &uid );
972 ZVAL_LONG(zuid, (long)uid);
973 RETURN_LONG((long)result);
974 }
975
976 ZEND_FUNCTION(xnp_test_criteria)
977 {
978 zval *z;
979
980 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
981 &z) == FAILURE) {
982 return;
983 }
984 zend_printf("zend_printf...<br>\n");
985 zCriteria_t zcri(z);
986 zcri.dump();
987 RETURN_FALSE
988 }
989
990 ZEND_FUNCTION(xnp_test_uids)
991 {
992 zval *z;
993
994 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
995 &z) == FAILURE) {
996 return;
997 }
998 zend_printf("zend_printf...<br>\n");
999 zUIDs_t zuids(z);
1000 zuids.dump();
1001 RETURN_FALSE
1002 }
1003
1004
1005
1006 /** DB??・膓????????≪??・膓?筝???・膓???????????????<br>
1007 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
1008 @param host ?ョ????????ユ????ULL
1009 @param user DB?ョ????????若?九???????ユ????ULL
1010 @param password DB?ョ????????鴻???若???????ユ????ULL
1011 @param dbname DB?ョ?????B???????ユ????quot;"
1012 @param prefix XOOPS DB ??refix??
1013 @return 0 success <br>
1014 */
1015 ZEND_FUNCTION(xnp_initialize_db)
1016 {
1017 zval **parameters[5];
1018 char *host;
1019 char *user;
1020 char *password;
1021 char *dbname;
1022 char *prefix;
1023
1024 /* get the number of arguments */
1025 int argNum = ZEND_NUM_ARGS();
1026 if (argNum > 5)
1027 WRONG_PARAM_COUNT;
1028
1029 /* argument count is correct, now retrieve arguments */
1030 if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
1031 WRONG_PARAM_COUNT;
1032
1033 if (argNum < 1) host = NULL;
1034 else host = getZvalString( parameters[0] );
1035
1036 if (argNum < 2) user = NULL;
1037 else user = getZvalString( parameters[1] );
1038
1039 if (argNum < 3) password = NULL;
1040 else password = getZvalString( parameters[2] );
1041
1042 if (argNum < 4) dbname = "";
1043 else dbname = getZvalString( parameters[3] );
1044
1045 if (argNum < 5) prefix = "";
1046 else prefix = getZvalString( parameters[4] );
1047
1048 result_t result = initializeDB( host, user, password, dbname, prefix );
1049
1050 RETURN_LONG(result);
1051 }
1052
1053 /** ???違?ゃ?潟??????<br>
1054 int xnp_login_user(string uname, string password, int &session_id)
1055 @param uname ???若?九??(xoops_users.uname)
1056 @param password ???鴻???若??(md5(password)=xoops_users.pass)
1057 @return 0 success
1058 */
1059 ZEND_FUNCTION(xnp_login_user)
1060 {
1061 char *uname;
1062 int unameLen;
1063 char *passwd;
1064 int passwdLen;
1065 zval *zXNPSessionID;
1066
1067 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",
1068 &uname, &unameLen, &passwd, &passwdLen, &zXNPSessionID) == FAILURE) {
1069 return;
1070 }
1071
1072 if (!PZVAL_IS_REF(zXNPSessionID)) {
1073 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1074 RETURN_LONG(RES_PHP_NONREF);
1075 }
1076
1077 sessionid_t xnpSessionID;
1078 result_t result = loginUser( uname, passwd, &xnpSessionID );
1079 if ( result == RES_OK )
1080 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1081 RETURN_LONG((long)result);
1082 }
1083
1084 /** ???違?≪??????????<br>
1085 void xnp_logout_user(int xnp_session_id)
1086 @param xnp_session_id XNP???祉???激?с??D
1087 @return ????
1088 */
1089 ZEND_FUNCTION(xnp_logout_user)
1090 {
1091 long xnpSessionID;
1092
1093 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &xnpSessionID) == FAILURE) {
1094 return;
1095 }
1096 logoutUser( (sessionid_t)xnpSessionID );
1097
1098 RETURN_NULL();
1099 }
1100
1101 /** XNP???祉???激?с??D 篏???<br>
1102 int xnp_create_session( string xoops_sess_id, int uid, int &session )
1103 @param xoops_sess_id xoops???祉???激?с??D
1104 @param uid xoops ? uid (xoops_users.uid)
1105 @param session 篏???????XNP??ession??????????紊???/span>
1106 @return 0 ????
1107 */
1108 ZEND_FUNCTION(xnp_create_session)
1109 {
1110 char *xoopsSessionID;
1111 int xoopsSessionIDLen;
1112 long uid;
1113 zval *zXNPSessionID;
1114
1115 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz",
1116 &xoopsSessionID, &xoopsSessionIDLen, &uid, &zXNPSessionID) == FAILURE) {
1117 return;
1118 }
1119
1120 if (!PZVAL_IS_REF(zXNPSessionID)) {
1121 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1122 RETURN_LONG(RES_PHP_NONREF);
1123 }
1124
1125 sessionid_t xnpSessionID = 0;
1126 result_t result = createSession( xoopsSessionID, (userid_t)uid, &xnpSessionID );
1127 if ( result == RES_OK )
1128 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1129 RETURN_LONG((long)result);
1130 }
1131
1132 /** XNP ? session ???膣井???宴??緇???<br>
1133 int xnp_get_session( int xnp_session_id, array session_info )
1134 @param xnp_session_id XNP???祉???激?с??D
1135 @param session_info 腟?????????????????
1136 @return 0 success
1137 */
1138 ZEND_FUNCTION(xnp_get_session)
1139 {
1140 long xnpSessionID;
1141 zval *sessionInfo;
1142 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1143 &xnpSessionID, &sessionInfo) == FAILURE) {
1144 return;
1145 }
1146 const session_t *session = 0;
1147 result_t result = getSession( (sessionid_t)xnpSessionID, &session );
1148 if ( result == RES_OK ){
1149 sessionToZval( session, sessionInfo );
1150 freeSession( session );
1151 }
1152
1153 RETURN_LONG((long)result);
1154 }
1155
1156 /** ???若?吟??ctivate?倶??????緇?????<br>
1157 bool xnp_is_activated( int xnp_session_id, int user_id )
1158 @param xnp_session_id XNP???祉???激?с??D
1159 @param user_id xoops_users.uid
1160 @return 0 success
1161 */
1162 ZEND_FUNCTION(xnp_is_activated)
1163 {
1164 long sid, uid;
1165
1166 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
1167 return;
1168 }
1169
1170 bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
1171
1172 RETURN_BOOL(result);
1173 }
1174
1175 /** activate??????<br>
1176 bool xnp_activate( int xnp_session_id, int user_id, bool activated )
1177 @param xnp_session_id xnp ? session id
1178 @param user_id xoops_users.uid
1179 @param activated true:activate, false:inactivate
1180 @return 0 success
1181 */
1182 ZEND_FUNCTION(xnp_activate)
1183 {
1184 long sid, uid;
1185 bool activated;
1186
1187 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
1188 &sid, &uid, &activated) == FAILURE) {
1189 return;
1190 }
1191
1192 result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
1193
1194 RETURN_LONG(result);
1195 }
1196
1197 /** XNP???≪?????潟???違??緇?????<br>
1198 int xnp_get_account_count( int xnp_session_id )
1199 @param xnp_session_id XNP???祉???激?с??D
1200 @return 0 success
1201 */
1202 ZEND_FUNCTION(xnp_get_account_count)
1203 {
1204 long sid;
1205
1206 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1207 &sid) == FAILURE) {
1208 return;
1209 }
1210
1211 long count = getAccountCount( (sessionid_t)sid );
1212 RETURN_LONG(count);
1213 }
1214
1215 /** ?≪?????潟???????ゃ??????<br>
1216 bool xnp_delete_account( int xnp_session_id, int user_id )
1217 @param xnp_session_id XNP???祉???激?с??D
1218 @param user_id xoops_users.uid
1219 @return 0 success
1220 */
1221 ZEND_FUNCTION(xnp_delete_account)
1222 {
1223 long sid, uid;
1224
1225 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1226 &sid, &uid) == FAILURE) {
1227 return;
1228 }
1229
1230 result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
1231
1232 RETURN_LONG(result);
1233 }
1234
1235 /** ?≪?????潟?????宴??緇?????<br>
1236 int xnp_get_account( int xnp_session_id, int user_id, array account_info )
1237 @param xnp_session_id XNP???祉???激?с??D
1238 @param user_id xoops_users.uid
1239 @param account_info ?≪?????潟?????宴???????????f?渇????
1240 @return 0 success
1241 */
1242 ZEND_FUNCTION(xnp_get_account)
1243 {
1244 long sid, uid;
1245 zval *zaccount;
1246
1247 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1248 &sid, &uid, &zaccount) == FAILURE) {
1249 fprintf( stderr, "error occured " );
1250 return;
1251 }
1252
1253 const account_t *paccount;
1254 result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
1255 if ( RES_OK == result ){
1256 accountToZval( paccount, zaccount );
1257 freeAccount( paccount );
1258 }
1259
1260 RETURN_LONG(result);
1261 }
1262
1263 /** ?>散????眼?????≪?????潟???????宴??緇?????<br>
1264 int xnp_get_accoutns( int sid, array uids, array criteria, array accounts );
1265 @param xnp_session_id XNP???祉???激?с??D
1266 @param user_id xoops_users.uid
1267 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1268 @param account_info ?≪?????潟?????宴???????????f?渇????
1269 @return 0 success
1270 */
1271 ZEND_FUNCTION(xnp_get_accounts)
1272 {
1273 result_t result;
1274 long sid;
1275 zval *zuids;
1276 zval *zcriteria;
1277 zval *zaccount;
1278
1279 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1280 &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
1281 return;
1282 }
1283
1284 zCriteria_t zcri(zcriteria);
1285 result = zcri.getResult();
1286 if ( RES_OK == result ){
1287 zUIDs_t zUIDs(zuids);
1288 result = zUIDs.getResult();
1289 if ( RES_OK == result ){
1290 const account_t *paccounts;
1291 int accountLen;
1292 result = getAccounts( (sessionid_t)sid,
1293 zUIDs.getPUID(), zUIDs.getLen(),
1294 &zcri, &paccounts, &accountLen );
1295 if ( RES_OK == result ){
1296 accountsToZval( paccounts, accountLen, zaccount );
1297 freeAccount( paccounts );
1298 }
1299 }
1300 }
1301
1302 RETURN_LONG(result);
1303 }
1304
1305 /** ?≪?????潟?????宴??荐??蚊??????<br>
1306 int xnp_insert_account( int sid, array account_info, int &user_id );
1307 @param xnp_session_id xnp ? session id
1308 @param account_info 荐??蚊???????≪?????潟????????/span>
1309 @param user_id ???若??D(xoops_users.uid)???吾??莨若???????<???潟??/span>
1310 @return 0 success
1311 */
1312 ZEND_FUNCTION(xnp_insert_account)
1313 {
1314 result_t result;
1315 long sid;
1316 zval *zaccount;
1317 zval *zuid;
1318 userid_t uid;
1319
1320 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1321 &sid, &zaccount, &zuid) == FAILURE) {
1322 return;
1323 }
1324
1325 zAccount_t zacc(zaccount);
1326 result = zacc.getResult();
1327 if ( RES_OK == result ){
1328 result = insertAccount( (sessionid_t)sid, &zacc, &uid );
1329 }
1330 zuid -> type = IS_LONG;
1331 zuid -> value.lval = uid;
1332 RETURN_LONG(result);
1333 }
1334
1335 /** ?≪?????潟?????宴???贋?違??????<br>
1336 int xnp_update_account( int sid, array account );
1337 @param xnp_session_id XNP???祉???激?с??D
1338 @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
1339 @return 0 success
1340 */
1341 ZEND_FUNCTION(xnp_update_account)
1342 {
1343 result_t result;
1344 long sid;
1345 zval *zaccount;
1346
1347 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1348 &sid, &zaccount) == FAILURE) {
1349 return;
1350 }
1351
1352 zAccount_t zacc(zaccount);
1353 result = zacc.getResult();
1354 if ( RES_OK == result ){
1355 result = updateAccount( (sessionid_t)sid, &zacc );
1356 }
1357
1358 RETURN_LONG(result);
1359 }
1360
1361 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
1362 int xnp_dump_uids( int xnp_session_id, array criteria, array uids );
1363 @param xnp_session_id XNP???祉???激?с??D
1364 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1365 @param uids uid??????????????
1366 @return 0 success
1367 */
1368 ZEND_FUNCTION(xnp_dump_uids)
1369 {
1370 result_t result;
1371 long sid;
1372 zval *zcriteria;
1373 zval *zuids;
1374
1375 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1376 &sid, &zcriteria, &zuids) == FAILURE) {
1377 return;
1378 }
1379
1380 zCriteria_t zcri(zcriteria);
1381 result = zcri.getResult();
1382 if ( RES_OK == result ){
1383 userid_t *puid;
1384 int uidLen;
1385 result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1386 if ( RES_OK == result ){
1387 uidsToZval( puid, uidLen, &zuids );
1388 freeUID( puid );
1389 }
1390 }
1391
1392 RETURN_LONG(result);
1393 }
1394
1395 /** XNP???違???若?????違??緇???<br>
1396 int xnp_get_group_count( int xnp_session_id );
1397 @param xnp_session_id XNP???祉???激?с??D
1398 @return ?違???若????/span>
1399 */
1400 ZEND_FUNCTION(xnp_get_group_count)
1401 {
1402 result_t result;
1403 long sid;
1404
1405 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1406 &sid) == FAILURE) {
1407 return;
1408 }
1409
1410 int count = getGroupCount( (sessionid_t)sid );
1411
1412 RETURN_LONG(count);
1413 }
1414
1415 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
1416 int xnp_get_group_by_uid( int xnp_session_id, int uid, array criteria, array gids );
1417 @param xnp_session_id XNP???祉???激?с??D
1418 @param user_id xoops_users.uid
1419 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1420 @param gids gid??????????????
1421 @return 0 success
1422 */
1423 ZEND_FUNCTION(xnp_get_groups_by_uid)
1424 {
1425 result_t result;
1426 long sid, uid;
1427 zval *zcriteria;
1428 zval *zgids;
1429
1430 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1431 &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1432 return;
1433 }
1434
1435 zCriteria_t zcri(zcriteria);
1436 result = zcri.getResult();
1437 if ( RES_OK == result ){
1438 groupid_t *pgids;
1439 int gidLen;
1440 result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1441 if ( RES_OK == result ){
1442 gidsToZval( pgids, gidLen, &zgids );
1443 freeGID( pgids );
1444 }
1445 }
1446
1447 RETURN_LONG(result);
1448 }
1449
1450
1451
1452 /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
1453 int xnp_is_group_admin( int sid, int gid, int uid );
1454 @param xnp_session_id XNP???祉???激?с??D
1455 @param group_id XNP???違???若??ID
1456 @param user_id xoops_users.uid
1457 @return true: ?違???若??膊∞?????с??????
1458 @return false: ?違???若??膊∞?????с???????????????????若?с??????
1459 */
1460 ZEND_FUNCTION(xnp_is_group_admin)
1461 {
1462 result_t result;
1463 long sid, gid, uid;
1464
1465 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1466 &sid, &gid, &uid) == FAILURE) {
1467 return;
1468 }
1469
1470 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1471
1472 RETURN_BOOL(b);
1473 }
1474
1475 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
1476 int xnp_dump_gids( int sid, array criteria, array gids );
1477 @param xnp_session_id XNP???祉???激?с??D
1478 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1479 @param gids gid??????????????
1480 @return 0 success
1481 */
1482 ZEND_FUNCTION(xnp_dump_gids)
1483 {
1484 result_t result;
1485 long sid;
1486 zval *zcriteria;
1487 zval *zgids;
1488
1489 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1490 &sid, &zcriteria, &zgids) == FAILURE) {
1491 return;
1492 }
1493
1494 zCriteria_t zcri(zcriteria);
1495 result = zcri.getResult();
1496 if ( RES_OK == result ){
1497 groupid_t *pgid;
1498 int gidLen;
1499 result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1500 if ( RES_OK == result ){
1501 gidsToZval( pgid, gidLen, &zgids );
1502 freeGID( pgid );
1503 }
1504 }
1505
1506 RETURN_LONG(result);
1507 }
1508
1509 /** gid?ф??絎??????違???若??????????с?????ゆ?>散????眼?????違???若??膊∞??????id???荀с??緇?????<br>
1510 int xnp_dump_group_admins(int sid, int group_id, array criteria, array uids )
1511 @param sid XNP???祉???激?с??D
1512 @param group_id XNP???違???若??ID
1513 @param criteria ?>散
1514 @param uids uid???荀с??????????????
1515 @return 0 success
1516 */
1517
1518 ZEND_FUNCTION(xnp_dump_group_admins)
1519 {
1520 long sid, gid;
1521 zval *zcriteria;
1522 zval *zuids;
1523
1524 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1525 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1526 return;
1527 }
1528
1529 zCriteria_t zcri(zcriteria);
1530 result_t result = zcri.getResult();
1531 if ( result == RES_OK ){
1532 userid_t *uids;
1533 int uidsLen;
1534 result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1535 if ( result == RES_OK ){
1536 uidsToZval( uids, uidsLen, &zuids );
1537 freeUID( uids );
1538 }
1539 }
1540 RETURN_LONG( result );
1541 }
1542
1543 /** ?違???若???????<?潟???若?????ゃ??????<br>
1544 int xnp_delete_member(int sid, int group_id, int user_id )
1545 @param sid XNP???祉???激?с??D
1546 @param group_id XNP???違???若??ID
1547 @param user_id ???若??D
1548 @return 0 success
1549 */
1550
1551 ZEND_FUNCTION(xnp_delete_member)
1552 {
1553 long sid, gid, uid;
1554
1555 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1556 &sid, &gid, &uid) == FAILURE) {
1557 return;
1558 }
1559
1560 result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1561 RETURN_LONG( result );
1562 }
1563
1564 /** ?違???若?????<?潟???若??菴遵??????<br>
1565 int xnp_insert_member(int sid, int group_id, int user_id, bool admin )
1566 @param sid XNP???祉???激?с??D
1567 @param group_id XNP???違???若??ID
1568 @param user_id ???若??D
1569 @param admin ?違???若??膊∞????????true
1570 @return 0 success
1571 */
1572
1573 ZEND_FUNCTION(xnp_insert_member)
1574 {
1575 long sid, gid, uid;
1576 zend_bool admin;
1577
1578 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
1579 &sid, &gid, &uid, &admin) == FAILURE) {
1580 return;
1581 }
1582
1583 result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
1584 RETURN_LONG( result );
1585 }
1586
1587 /** gid?ф??絎??????違???若?????<?潟???若??id???荀с??緇???<br>
1588 int xnp_get_members(int sid, int group_id, array criteria, array uids )
1589 @param sid XNP???祉???激?с??D
1590 @param group_id XNP???違???若??ID
1591 @param criteria ?>散
1592 @param uids uid???荀с??????????????
1593 @return 0 success
1594 */
1595
1596 ZEND_FUNCTION(xnp_get_members)
1597 {
1598 long sid, gid;
1599 zval *zcriteria;
1600 zval *zuids;
1601
1602 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1603 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1604 return;
1605 }
1606
1607 zCriteria_t zcri(zcriteria);
1608 result_t result = zcri.getResult();
1609 if ( result == RES_OK ){
1610 userid_t *uids;
1611 int uidsLen;
1612 result = getMembers( (sessionid_t)sid, (groupid_t)gid, &zcri, &uids, &uidsLen );
1613 if ( result == RES_OK ){
1614 uidsToZval( uids, uidsLen, &zuids );
1615 freeUID( uids );
1616 }
1617 }
1618 RETURN_LONG( result );
1619 }
1620
1621 /** ?違???若?????宴??紊??眼??????<br>
1622 int xnp_update_group(int sid, array group )
1623 @param sid XNP???祉???激?с??D
1624 @param group ?違???若?????宴???f?渇????
1625 @return 0 success
1626 */
1627 ZEND_FUNCTION(xnp_update_group)
1628 {
1629 long sid;
1630 zval *zgroup;
1631 group_t group;
1632
1633 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1634 &sid, &zgroup) == FAILURE) {
1635 return;
1636 }
1637
1638 zvalToGroup( zgroup, &group );
1639 result_t result = updateGroup( sid, &group );
1640 RETURN_LONG( result );
1641 }
1642
1643 /** ?違???若?????宴??菴遵????????<br>
1644 int xnp_insert_group( int sid, array group, int &gid )
1645 @param sid ?祉???激?с??D
1646 @param group ?違???若?????宴???f?渇????
1647 @param gid 絲上??????違???若??ID???吾??莨若???????<???潟??/span>
1648 @return RES_OK
1649 @return RES_DB_NOT_INITIALIZED
1650 @return RES_NO_SUCH_SESSION
1651 @return RES_DB_QUERY_ERROR
1652 */
1653 ZEND_FUNCTION(xnp_insert_group)
1654 {
1655 long sid;
1656 zval *zgroup;
1657 zval *zgid;
1658 group_t group;
1659 groupid_t gid;
1660
1661 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1662 &sid, &zgroup, &zgid ) == FAILURE) {
1663 return;
1664 }
1665
1666 zvalToGroup( zgroup, &group );
1667 result_t result = insertGroup( sid, &group, &gid );
1668 zgid -> type = IS_LONG;
1669 zgid -> value.lval = gid;
1670 RETURN_LONG( result );
1671 }
1672
1673
1674 /** ?違???若?????宴?????ゃ??????<br>
1675 int xnp_delete_group( int sid, int gid )
1676 @param sid XNP???祉???激?с??D
1677 @param gid ???ゃ???????違???若????D
1678 @return RES_OK
1679 @return RES_DB_QUERY_ERROR
1680 @return RES_NO_SUCH_SESSION
1681 @return RES_DB_NOT_INITIALIZED
1682 */
1683 ZEND_FUNCTION(xnp_delete_group)
1684 {
1685 long sid;
1686 long gid;
1687
1688 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1689 &sid, &gid) == FAILURE) {
1690 return;
1691 }
1692 RETURN_LONG( deleteGroup( sid, gid ) );
1693 }
1694
1695 /** ?違???若?????????????緇???<br>
1696 int xnp_dump_group_admins( int sid, int gid, array criteria, array uids )
1697 @param sid XNP???祉???激?с??D
1698 @param gid XNP?違???若????D
1699 @param criteria uids???吾??莨若?????????純?若???>散鐚?膀??蚊????絎?
1700 @param uids 膊∞??????ID???吾??莨若??????
1701 @return RES_OK
1702 @return RES_DB_QUERY_ERROR
1703 @return RES_NO_SUCH_SESSION
1704 @return RES_DB_NOT_INITIALIZED
1705 */
1706 /*
1707 ZEND_FUNCTION(xnp_dump_group_admins)
1708 {
1709 long sid;
1710 long gid;
1711 zval *zcriteria;
1712 zval *zuids;
1713
1714 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1715 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1716 return;
1717 }
1718 zCriteria_t zcri(zcriteria);
1719 result_t result = zcri.getResult();
1720 if ( RES_OK == result ){
1721 userid_t* uids;
1722 int uidsLen;
1723 result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1724 if( result != RES_OK ) RETURN_LONG( result );
1725 uidsToZval( uids, uidsLen, &zuids );
1726 fprintf( stderr, "uidsLen=%d\n", uidsLen );
1727 for( int i = 0; i < uidsLen; i++ ){
1728 fprintf( stderr, "%d, \n", uids[ i ] );
1729 }
1730 freeUID( uids );
1731 RETURN_LONG( result );
1732 }
1733 RETURN_LONG( result );
1734 }
1735 */
1736
1737 /** ???????ゃ?潟???????鴻??緇???<br>
1738 * int xnp_get_all_indexes( int sid, array criteria, array indexes );
1739 * @param sid XNP???祉???激?с??D
1740 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
1741 * @return RES_OK
1742 */
1743 ZEND_FUNCTION(xnp_get_all_indexes)
1744 {
1745 long sid;
1746 zval *zcriteria;
1747 zval *zindexes;
1748
1749 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1750 &sid, &zcriteria, &zindexes) == FAILURE) {
1751 return;
1752 }
1753 zCriteria_t zcri(zcriteria);
1754 result_t result = zcri.getResult();
1755 if ( RES_OK == result ){
1756 const index_t *indexes;
1757 int indexesLen;
1758 result = getAllIndexes( sid, &zcri, &indexes, &indexesLen );
1759 if ( RES_OK == result ){
1760 result = indexesToZval( indexes, indexesLen, zindexes );
1761 freeIndex( indexes );
1762 }
1763 }
1764 RETURN_LONG(result);
1765 }
1766
1767 /** ?????ゃ?潟???????鴻??????????ゃ?潟???????鴻??緇???<br>
1768 * int xnp_get_indexes( int sid, int parentXID, array criteria, array indexes );
1769 * @param sid XNP???祉???激?с??D
1770 * @param parentXID 荀???ndexID
1771 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
1772 * @param indexes 腟?????????????????
1773 * @return RES_OK
1774 */
1775 ZEND_FUNCTION(xnp_get_indexes)
1776 {
1777 long sid;
1778 long parentXID;
1779 zval *zcriteria;
1780 zval *zindexes;
1781
1782 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1783 &sid, &parentXID, &zcriteria, &zindexes) == FAILURE) {
1784 return;
1785 }
1786 zCriteria_t zcri(zcriteria);
1787 result_t result = zcri.getResult();
1788 if ( RES_OK == result ){
1789 const index_t *indexes;
1790 int indexesLen;
1791 result = getIndexes( sid, parentXID, &zcri, &indexes, &indexesLen );
1792 if ( RES_OK == result ){
1793 result = indexesToZval( indexes, indexesLen, zindexes );
1794 freeIndex( indexes );
1795 }
1796 }
1797 RETURN_LONG(result);
1798 }
1799
1800
1801 /** ?ゃ?潟???????鴻??篏???????<br>
1802 * int xnp_insert_index( int sid, array index, int &indexID );
1803 * @param sid XNP???祉???激?с??D
1804 * @param index 篏????????ゃ?潟????????/span>
1805 * @param indexID 篏??????????ゃ?潟???????鴻??D??????????紊???/span>
1806 * @return RES_OK
1807 */
1808 ZEND_FUNCTION(xnp_insert_index)
1809 {
1810 long sid;
1811 zval *zindex;
1812 zval *zIndexID;
1813
1814 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1815 &sid, &zindex, &zIndexID) == FAILURE) {
1816 return;
1817 }
1818
1819 if (!PZVAL_IS_REF(zIndexID)) {
1820 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1821 RETURN_LONG(RES_PHP_NONREF);
1822 }
1823 zIndex_t index( zindex );
1824 indexid_t xid;
1825 result_t result = insertIndex( sid, &index, &xid );
1826 if ( RES_OK == result )
1827 ZVAL_LONG(zIndexID, (long)xid);
1828 RETURN_LONG(result);
1829 }
1830
1831 /** ?ゃ?潟???????鴻???贋?違????<br>
1832 * int xnp_update_index( int sid, array index );
1833 * @param sid XNP???祉???激?с??D
1834 * @param index ?贋?違?????ゃ?潟????????/span>
1835 * @return RES_OK
1836 */
1837 ZEND_FUNCTION(xnp_update_index)
1838 {
1839 long sid;
1840 zval *zindex;
1841
1842 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1843 &sid, &zindex) == FAILURE) {
1844 return;
1845 }
1846 zIndex_t index(zindex);
1847 result_t result = index.getResult();
1848 if ( RES_OK == result ){
1849 result = updateIndex( sid, &index );
1850 }
1851 RETURN_LONG(result);
1852 }
1853
1854 /** ?ゃ?潟???????鴻?????ゃ????<br>
1855 * int xnp_delete_index( int sid, int indexID );
1856 * @param sid XNP???祉???激?с??D
1857 * @param indexID ???ゃ?????ゃ?潟????????/span>
1858 * @return RES_OK
1859 */
1860 ZEND_FUNCTION(xnp_delete_index)
1861 {
1862 long sid;
1863 long xid;
1864
1865 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1866 &sid, &xid) == FAILURE) {
1867 return;
1868 }
1869
1870 result_t result = deleteIndex( sid, xid );
1871 RETURN_LONG(result);
1872 }
1873
1874
1875 /** ?ゃ?潟???????鴻????緇?????<br>
1876 * int xnp_get_index( int sid, int indexID, array index );
1877 * @param sid XNP???祉???激?с??D
1878 * @param indexID ??緇??????ゃ?潟???????鴻??D
1879 * @param index ??緇?腟??????????????f?渇????
1880 * @return RES_OK
1881 */
1882 ZEND_FUNCTION(xnp_get_index)
1883 {
1884 long sid;
1885 long xid;
1886 zval *zindex;
1887
1888 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1889 &sid, &xid, &zindex) == FAILURE) {
1890 return;
1891 }
1892
1893 const index_t *index;
1894 result_t result = getIndex( sid, xid, &index );
1895 if ( RES_OK == result ){
1896 result = indexToZval( index, zindex );
1897 freeIndex( index );
1898 }
1899 RETURN_LONG(result);
1900 }
1901
1902
1903
1904 /** ?ゃ?潟???????鴻??茯??粋昭?水??純??????????茯帥?鴻??<br>
1905 * int xnp_is_index_readable( int sid, int indexID );
1906 * @param sid XNP???祉???激?с??D
1907 * @param indexID 絲乗院?ゃ?潟???????鴻??D
1908 * @return true false
1909 */
1910 ZEND_FUNCTION(xnp_is_index_readable)
1911 {
1912 long sid;
1913 long xid;
1914
1915 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1916 &sid, &xid) == FAILURE) {
1917 return;
1918 }
1919 RETURN_BOOL(isIndexReadable(sid,xid));
1920 }
1921
1922
1923 /** ?ゃ?潟???????鴻???吾??莨若?水??純??????????茯帥?鴻??<br>
1924 * int xnp_is_index_writable( int sid, int indexID );
1925 * @param sid XNP???祉???激?с??D
1926 * @param indexID 絲乗院?ゃ?潟???????鴻??D
1927 * @return true false
1928 */
1929 ZEND_FUNCTION(xnp_is_index_writable)
1930 {
1931 long sid;
1932 long xid;
1933
1934 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1935 &sid, &xid) == FAILURE) {
1936 return;
1937 }
1938 RETURN_BOOL(isIndexWritable(sid,xid));
1939 }
1940
1941 /** ?ゃ?潟???????鴻????綺???ャ???帥????<br>
1942 * int xnp_swap_index_sort_number( int sid, int indexID1, int indexID2 );
1943 * @param sid XNP???祉???激?с??D
1944 * @param indexID1 絲乗院?ゃ?潟???????鴻??D
1945 * @param indexID2 絲乗院?ゃ?潟???????鴻??D
1946 * @return true false
1947 */
1948 ZEND_FUNCTION(xnp_swap_index_sort_number)
1949 {
1950 long sid;
1951 long xid1, xid2;
1952
1953 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1954 &sid, &xid1, &xid2) == FAILURE) {
1955 return;
1956 }
1957
1958 result_t result = swapIndexSortNumber( sid, xid1, xid2 );
1959 RETURN_LONG(result);
1960 }
1961
1962
1963
1964 /** XNP??ession_id???綵??с???с????lt;br>
1965 bool xnp_is_valid_session_id( int xnp_session_id)
1966 @return true ???鴻??NP??ession_id?с????<br>
1967 @return false ?≦?鴻??ession_id?障??????????/span>
1968 */
1969 ZEND_FUNCTION(xnp_is_valid_session_id)
1970 {
1971 long sid;
1972 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
1973 return;
1974 }
1975
1976 RETURN_BOOL(isValidSessionID((sessionid_t)sid));
1977 }
1978
1979 /** ?????惹??絖?????緇???<br>
1980 string xnp_get_last_error_string()
1981 @return 0 success
1982 */
1983 ZEND_FUNCTION(xnp_get_last_error_string)
1984 {
1985 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
1986 return;
1987 }
1988
1989 string str( getLastErrorString() );
1990 RETURN_STRING((char *)str.c_str(), 1);
1991 }
1992

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