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.22 - (show annotations) (download) (as text)
Fri Jan 14 10:37:17 2005 UTC (19 years, 2 months ago) by aga
Branch: MAIN
Changes since 1.21: +340 -2 lines
File MIME type: text/x-c++src
・index関係の関数を追加.

1 /*
2 $Revision: 1.21 $
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 ( hashGetString( ht, "subtype" , &p ) ) setSubtype ( p );
452 if ( hashGetLong ( ht, "contributor_uid" , &l ) ) setContributorUID ( l );
453 if ( hashGetString( ht, "title" , &p ) ) setTitle ( p );
454 if ( hashGetString( ht, "keywords" , &p ) ) setKeywords ( p );
455 if ( hashGetString( ht, "description" , &p ) ) setDescription ( p );
456 if ( hashGetLong ( ht, "last_update_date" , &l ) ) setLastUpdateDate ( l );
457 if ( hashGetLong ( ht, "creation_date" , &l ) ) setCreationDate ( l );
458 if ( hashGetLong ( ht, "parent_index_id" , &l ) ) setParentIndexID ( l );
459 if ( hashGetLong ( ht, "owner_uid" , &l ) ) setOwnerUID ( l );
460 if ( hashGetLong ( ht, "owner_gid" , &l ) ) setOwnerGID ( l );
461 if ( hashGetLong ( ht, "open_level" , &l ) ) setOpenLevel ( l );
462 if ( hashGetLong ( ht, "sort_number" , &l ) ) setSortNumber ( l );
463
464 result = RES_OK;
465 }
466 public:
467 zIndex_t() : index(){ result = RES_ERROR; }
468 zIndex_t( zval *pz ) : index(){ initialize(pz); }
469 zIndex_t( zval **ppz ) : index() { initialize(*ppz); }
470 result_t getResult(){ return result; };
471
472 void dump(){
473 }
474 };
475
476 /** zval*????(userid_t *puid,int uidLen)?????????????????????鴻?? <br>
477 ????紊掩??????getResult()!=RES_OK <br>
478 */
479 class zUIDs_t {
480 private:
481 result_t result;
482 userid_t *pUID;
483 int len;
484 public:
485 zUIDs_t(){
486 pUID = 0;
487 len = 0;
488 result = RES_ERROR;
489 }
490
491 /** ?潟?潟?鴻????????/span>
492 @param pza array( '1', '3', '4', '6', ... ); ??????就?????? */
493 zUIDs_t( zval *pza ){
494 pUID = 0;
495 len = 0;
496 result = RES_ERROR;
497
498 if ( Z_TYPE_P(pza) != IS_ARRAY ){
499 result = RES_ERROR;
500 }
501 else {
502 len = zend_hash_num_elements(Z_ARRVAL_P(pza));
503 if(len == 0) {
504 pUID = new userid_t[1];
505 result = RES_OK;
506 }
507 else {
508 /* php/ext/standard/string.c ? implode??????????????????
509 zend_hash_*???????ャ?<?潟???c????????????????鐚?
510 */
511 zval **tmp;
512 HashPosition pos;
513 int i = 0;
514 pUID = new userid_t[len];
515
516 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
517 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
518 SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ????/span>
519 convert_to_long_ex(tmp);
520 if ( i < len )
521 pUID[i++] = Z_LVAL_PP(tmp);
522 zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
523 }
524 len = i;
525 result = RES_OK;
526 }
527 }
528 }
529
530 ~zUIDs_t(){
531 if ( pUID ) delete[] pUID;
532 }
533 result_t getResult(){ return result; }
534 userid_t *getPUID(){ return pUID; }
535 int getLen(){ return len; }
536 void dump(){
537 zend_printf( "dumping zUIDs...<br>\n" );
538 zend_printf( "result=%d<br>\n", (int)result );
539 zend_printf( "len=%d<br>\n", len );
540 for ( int i = 0; i < len; i++ ){
541 zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
542 }
543 }
544 };
545
546 /**
547 *
548 * uids_t????????PHP???????????????
549 *
550 * @param pUID 紊???????serid_t??????
551 * @param len pUID?????????激??
552 * @param pz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
553 * @return RES_OK
554 *
555 */
556 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
557 {
558 zend_hash_clean( Z_ARRVAL_PP(ppz) );
559
560 // add UIDs
561 for ( int i = 0; i < len; i++ ){
562 add_next_index_long(*ppz, (long)(pUID[i]) );
563 }
564
565 return RES_OK;
566 }
567 /**
568 *
569 * groupid_t????????PHP???????????????
570 * @param pGID 紊???????roupid_t??????
571 * @param len pGID?????????激??
572 * @param ppz 紊???腟??????吾??莨若??????(??????羝??帥?с????????
573 * @return RES_OK
574 *
575 */
576 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
577 {
578 zend_hash_clean( Z_ARRVAL_PP(ppz) );
579
580 // add GIDs
581 for ( int i = 0; i < len; i++ ){
582 add_next_index_long(*ppz, (long)(pGID[i]) );
583 }
584
585 return RES_OK;
586 }
587
588
589 /**
590 *
591 * account_t????絎鴻??PHP???????????????
592 * @param pAccount 紊???????ccount_t*
593 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
594 * @return RES_OK
595 *
596 */
597 result_t accountToZval( const account_t *pAccount, zval *z )
598 {
599 zend_hash_clean( z -> value.ht );
600
601 add_assoc_long( z, "uid", pAccount -> getUID( ) );
602 add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
603 add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
604 add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
605 add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
606 add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
607 add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
608 add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
609 add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
610 add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
611 add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
612 add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
613 add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
614 add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
615 add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
616 add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
617 add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
618 add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
619 add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
620 add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
621 add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
622 add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
623 add_assoc_long( z, "level", pAccount -> getLevel( ) );
624 add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
625 add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
626 add_assoc_long( z, "posts", pAccount -> getPosts( ) );
627 add_assoc_long( z, "rank", pAccount -> getRank( ) );
628 add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
629 add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
630 add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
631 add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
632
633 add_assoc_long( z, "activate", pAccount -> getActivate( ) );
634 add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
635 add_assoc_string( z, "division", ( char* )pAccount -> getDivision( ), 1 );
636 add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
637 add_assoc_string( z, "company_name", ( char* )pAccount -> getCompanyName( ), 1 );
638 add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
639 add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
640 add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
641 add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
642 add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
643 add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
644 add_assoc_long( z, "private_index_id", pAccount -> getPrivateIndexID( ) );
645 return RES_OK;
646 }
647 /**
648 *
649 * 茲??違??ccount_t????絎鴻??PHP?????????????????????
650 * @param pAccounts 紊???????ccount_t*
651 * @param accountsLen pAccounts?????????激??
652 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
653 * @return RES_OK
654 *
655 z: ?????????????????????????? <br>
656 array(
657 array(
658 'uid'=>100,
659 'activate'=>1,
660 'division'=>'foo',
661 'tel'=>'123-456-789',
662 ...
663 ),
664 ...
665 )
666 */
667 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
668 {
669 zend_hash_clean( z -> value.ht );
670 for( int i = 0; i < accountsLen; i++ ){
671 zval *new_array;
672 MAKE_STD_ZVAL(new_array);
673 if(array_init(new_array) != SUCCESS){
674 return RES_ERROR;
675 }
676 add_index_zval( z, i, new_array );
677 accountToZval( &pAccounts[ i ], new_array );
678 }
679 return RES_OK;
680 }
681
682 /**
683 *
684 * 茲??違??roup_t????絎鴻??PHP?????????????????????
685 * @param pGroups 紊???????roup_t*
686 * @param groupsLen pGroups?????????激??
687 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
688 * @return RES_OK
689 *
690 z: ?????????????????????????? <br>
691 array(
692 array(
693 'gid'=>1,
694 'gname'=>'foo group',
695 'gdesc'=>'group of foo'
696 ),
697 ...
698 )
699 */
700 result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
701 {
702 zend_hash_clean( z -> value.ht );
703 for( int i = 0; i < groupsLen; i++ ){
704 zval *new_array;
705 MAKE_STD_ZVAL(new_array);
706 if(array_init(new_array) != SUCCESS){
707 return RES_ERROR;
708 }
709 add_index_zval( z, i, new_array );
710 add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
711 add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
712 add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
713 add_assoc_long( new_array, "group_index_id", pGroups[ i ].getGroupIndexID( ) );
714 }
715 return RES_OK;
716 }
717
718 /**
719 *
720 * group_t????絎鴻??PHP???f?渇?????????????
721 *
722 * @param pGroup 紊????????違???若??????/span>
723 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
724 * @return RES_OK
725 *
726 */
727 result_t groupToZval( const group_t *pGroup, zval *z )
728 {
729 zend_hash_clean( z -> value.ht );
730 add_assoc_long( z, "gid", pGroup -> getGID( ) );
731 add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
732 add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
733 add_assoc_long( z, "group_index_id", pGroup -> getGroupIndexID( ) );
734 return RES_OK;
735 }
736
737 /**
738 *
739 * PHP???f?渇????????絎鴻??group_t?????????
740 *
741 * @param z 紊????????f?渇????
742 * @param pGroup 紊???腟??????吾??莨若???違???若??
743 * @return RES_OK
744 *
745 */
746 result_t zvalToGroup( zval *z, group_t *pGroup )
747 {
748 zval **tmp;
749 HashPosition pos;
750 int i = 0;
751 char* key = 0;
752
753 key = "gid";
754 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
755 convert_to_long_ex( tmp ) ;
756 pGroup -> setGID( (*tmp) -> value.lval );
757 }
758 key = "gname";
759 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
760 convert_to_string_ex( tmp ) ;
761 pGroup -> setGname( (*tmp) -> value.str.val );
762 }
763 key = "gdesc";
764 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
765 convert_to_string_ex( tmp ) ;
766 pGroup -> setDesc( (*tmp) -> value.str.val );
767 }
768 key = "group_index_id";
769 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
770 convert_to_long_ex( tmp ) ;
771 pGroup -> setGroupIndexID( (*tmp) -> value.lval );
772 }
773 return RES_OK;
774 }
775
776 /**
777 *
778 * session_t????絎鴻??PHP???f?渇?????????????
779 *
780 * @param pSession 紊???????ession_t
781 * @param z 紊???腟??????吾??莨若???f?渇????(??????羝??帥?с????????
782 * @return RES_OK
783 *
784 */
785 result_t sessionToZval( const session_t *pSession, zval *z )
786 {
787 string sessionID(unsignedIntToString(pSession->getSessionID()));
788 add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
789
790 string date(unsignedIntToString((unsigned int)pSession->getDate()));
791 add_assoc_string(z, "date", (char *)date.c_str(), 1);
792
793 string userID(unsignedIntToString((unsigned int)pSession->getUID()));
794 add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
795
796 return RES_OK;
797 }
798
799 /**
800 *
801 * index_t????絎鴻??PHP???????????????
802 * @param pIndex 紊???????ndex_t*
803 * @param z 紊???腟??????吾??莨若??????(??????羝??帥?с????????
804 * @return RES_OK
805 *
806 */
807 result_t indexToZval( const index_t *pIndex, zval *z )
808 {
809 zend_hash_clean( z -> value.ht );
810
811 add_assoc_long( z, "item_id", pIndex -> getItemID( ) );
812 add_assoc_long( z, "item_type_id", pIndex -> getItemTypeID( ) );
813 add_assoc_string( z, "subtype", ( char* )pIndex -> getSubtype( ), 1 );
814 add_assoc_long( z, "contributor_uid", pIndex -> getContributorUID( ) );
815 add_assoc_string( z, "title", ( char* )pIndex -> getTitle( ), 1 );
816 add_assoc_string( z, "keywords", ( char* )pIndex -> getKeywords( ), 1 );
817 add_assoc_string( z, "description", ( char* )pIndex -> getDescription( ), 1 );
818 add_assoc_long( z, "last_update_date", pIndex -> getLastUpdateDate( ) );
819 add_assoc_long( z, "creation_date", pIndex-> getCreationDate( ) );
820 add_assoc_long( z, "parent_index_id", pIndex -> getParentIndexID( ) );
821 add_assoc_long( z, "owner_uid", pIndex -> getOwnerUID( ) );
822 add_assoc_long( z, "owner_gid", pIndex -> getOwnerGID( ) );
823 add_assoc_long( z, "open_level", pIndex -> getOpenLevel( ) );
824 add_assoc_long( z, "sort_number", pIndex -> getSortNumber( ) );
825 return RES_OK;
826 }
827
828 result_t indexesToZval( const index_t *pIndexes, int indexesLen, zval *z )
829 {
830 zend_hash_clean( z -> value.ht );
831 for( int i = 0; i < indexesLen; i++ ){
832 zval *new_array;
833 MAKE_STD_ZVAL(new_array);
834 if(array_init(new_array) != SUCCESS){
835 return RES_ERROR;
836 }
837 add_index_zval( z, i, new_array );
838 indexToZval( &pIndexes[ i ], new_array );
839 }
840 return RES_OK;
841 }
842
843
844
845
846 /** ??絎??????違???若???????宴??緇???<br>
847 int xnp_get_group( int sid, int gid, array group );
848 @param sid XNP???祉???激?с??D
849 @param gid XNP ? group_id
850 @param group 腟?????????????????
851 @return 0 success <br>
852 */
853 ZEND_FUNCTION(xnp_get_group)
854 {
855 long sid, gid;
856 zval *zgroup;
857
858 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
859 &sid, &gid, &zgroup) == FAILURE) {
860 return;
861 }
862
863 const group_t *pgroup;
864 result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
865 if ( RES_OK == result ){
866 groupToZval( pgroup, zgroup );
867 freeGroup( pgroup );
868 }
869
870 RETURN_LONG(result);
871 }
872
873
874 /** ??絎??????違???若??(茲????????宴??緇???<br>
875 xnp_get_groups( int sid, array gids, array criteria, array groups );
876 @param sid XNP???祉???激?с??D
877 @param gids XNP ? group_id ??????
878 @param criteria ?>散
879 @param groups 腟???????????????????????
880 @return 0 success <br>
881 */
882 ZEND_FUNCTION(xnp_get_groups)
883 {
884 result_t result;
885 long sid, uid;
886 zval *zcriteria;
887 zval *zgids;
888 zval *zgroups;
889 zval **ppzTmp = 0;
890 HashPosition pos;
891 int res2;
892 int gidsLen;
893 const group_t* groups;
894 int groupsLen;
895
896 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
897 &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
898 return;
899 }
900
901 //gids???違???若??ID???潟???若????
902 gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
903 groupid_t *gids = new groupid_t[ gidsLen ];
904 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
905 for( int i = 0; i < gidsLen; i++ ){
906 if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
907 SEPARATE_ZVAL(ppzTmp);
908 convert_to_long_ex(ppzTmp);
909 gids[ i ] = Z_LVAL_PP(ppzTmp);
910 }
911 zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
912 }
913
914 zCriteria_t zcri(zcriteria);
915 result = zcri.getResult();
916 if ( RES_OK == result ){
917 result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
918 if ( RES_OK == result ){
919 groupsToZval( groups, groupsLen, zgroups );
920 delete[] gids;
921 freeGroup( groups );
922 }
923 }
924 RETURN_LONG(result);
925 }
926
927
928 /** ??絎????????若?吟???≪?????若?帥??????????茯帥?鴻??<br>
929 int xnp_is_moderator(int sid, int uid)
930 @param sid XNP???祉???激?с??D
931 @param uid xoops ? uid (xoops_users.uid)
932 @return true ?≪?????若?帥?с???? <br>
933 */
934 ZEND_FUNCTION(xnp_is_moderator)
935 {
936 long xnpSessionID;
937 userid_t uid;
938
939 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
940 &xnpSessionID, &uid) == FAILURE) {
941 return;
942 }
943
944 bool result = isModerator( (sessionid_t)xnpSessionID, uid );
945 RETURN_BOOL(result)
946 }
947
948 /** ???若?九??????uid??茯帥?鴻??<br>
949 int xnp_get_uid(string uname,int &uid)
950 @param sid XNP???祉???激?с??D
951 @param uname xoops ? uname (xoops_users.uname)
952 @param uid xoops ? uid (xoops_users.uid) ??????????紊???/span>
953 @return 0 success
954 */
955 ZEND_FUNCTION(xnp_get_uid)
956 {
957 char *uname;
958 int unameLen;
959 zval *zuid;
960 userid_t uid;
961
962 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
963 &uname, &unameLen, &zuid) == FAILURE) {
964 return;
965 }
966
967 if (!PZVAL_IS_REF(zuid)) {
968 zend_error(E_WARNING, "2nd parameter wasn't passed by reference");
969 RETURN_LONG(RES_PHP_NONREF);
970 }
971
972 string strUname( uname, unameLen );
973 result_t result = getUid( strUname.c_str(), &uid );
974 ZVAL_LONG(zuid, (long)uid);
975 RETURN_LONG((long)result);
976 }
977
978 ZEND_FUNCTION(xnp_test_criteria)
979 {
980 zval *z;
981
982 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
983 &z) == FAILURE) {
984 return;
985 }
986 zend_printf("zend_printf...<br>\n");
987 zCriteria_t zcri(z);
988 zcri.dump();
989 RETURN_FALSE
990 }
991
992 ZEND_FUNCTION(xnp_test_uids)
993 {
994 zval *z;
995
996 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
997 &z) == FAILURE) {
998 return;
999 }
1000 zend_printf("zend_printf...<br>\n");
1001 zUIDs_t zuids(z);
1002 zuids.dump();
1003 RETURN_FALSE
1004 }
1005
1006
1007
1008 /** DB??・膓????????≪??・膓?筝???・膓???????????????<br>
1009 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
1010 @param host ?ョ????????ユ????ULL
1011 @param user DB?ョ????????若?九???????ユ????ULL
1012 @param password DB?ョ????????鴻???若???????ユ????ULL
1013 @param dbname DB?ョ?????B???????ユ????quot;"
1014 @param prefix XOOPS DB ??refix??
1015 @return 0 success <br>
1016 */
1017 ZEND_FUNCTION(xnp_initialize_db)
1018 {
1019 zval **parameters[5];
1020 char *host;
1021 char *user;
1022 char *password;
1023 char *dbname;
1024 char *prefix;
1025
1026 /* get the number of arguments */
1027 int argNum = ZEND_NUM_ARGS();
1028 if (argNum > 5)
1029 WRONG_PARAM_COUNT;
1030
1031 /* argument count is correct, now retrieve arguments */
1032 if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
1033 WRONG_PARAM_COUNT;
1034
1035 if (argNum < 1) host = NULL;
1036 else host = getZvalString( parameters[0] );
1037
1038 if (argNum < 2) user = NULL;
1039 else user = getZvalString( parameters[1] );
1040
1041 if (argNum < 3) password = NULL;
1042 else password = getZvalString( parameters[2] );
1043
1044 if (argNum < 4) dbname = "";
1045 else dbname = getZvalString( parameters[3] );
1046
1047 if (argNum < 5) prefix = "";
1048 else prefix = getZvalString( parameters[4] );
1049
1050 result_t result = initializeDB( host, user, password, dbname, prefix );
1051
1052 RETURN_LONG(result);
1053 }
1054
1055 /** ???違?ゃ?潟??????<br>
1056 int xnp_login_user(string uname, string password, int &session_id)
1057 @param uname ???若?九??(xoops_users.uname)
1058 @param password ???鴻???若??(md5(password)=xoops_users.pass)
1059 @return 0 success
1060 */
1061 ZEND_FUNCTION(xnp_login_user)
1062 {
1063 char *uname;
1064 int unameLen;
1065 char *passwd;
1066 int passwdLen;
1067 zval *zXNPSessionID;
1068
1069 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",
1070 &uname, &unameLen, &passwd, &passwdLen, &zXNPSessionID) == FAILURE) {
1071 return;
1072 }
1073
1074 if (!PZVAL_IS_REF(zXNPSessionID)) {
1075 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1076 RETURN_LONG(RES_PHP_NONREF);
1077 }
1078
1079 sessionid_t xnpSessionID;
1080 result_t result = loginUser( uname, passwd, &xnpSessionID );
1081 if ( result == RES_OK )
1082 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1083 RETURN_LONG((long)result);
1084 }
1085
1086 /** ???違?≪??????????<br>
1087 void xnp_logout_user(int xnp_session_id)
1088 @param xnp_session_id XNP???祉???激?с??D
1089 @return ????
1090 */
1091 ZEND_FUNCTION(xnp_logout_user)
1092 {
1093 long xnpSessionID;
1094
1095 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &xnpSessionID) == FAILURE) {
1096 return;
1097 }
1098 logoutUser( (sessionid_t)xnpSessionID );
1099
1100 RETURN_NULL();
1101 }
1102
1103 /** XNP???祉???激?с??D 篏???<br>
1104 int xnp_create_session( string xoops_sess_id, int uid, int &session )
1105 @param xoops_sess_id xoops???祉???激?с??D
1106 @param uid xoops ? uid (xoops_users.uid)
1107 @param session 篏???????XNP??ession??????????紊???/span>
1108 @return 0 ????
1109 */
1110 ZEND_FUNCTION(xnp_create_session)
1111 {
1112 char *xoopsSessionID;
1113 int xoopsSessionIDLen;
1114 long uid;
1115 zval *zXNPSessionID;
1116
1117 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz",
1118 &xoopsSessionID, &xoopsSessionIDLen, &uid, &zXNPSessionID) == FAILURE) {
1119 return;
1120 }
1121
1122 if (!PZVAL_IS_REF(zXNPSessionID)) {
1123 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1124 RETURN_LONG(RES_PHP_NONREF);
1125 }
1126
1127 sessionid_t xnpSessionID = 0;
1128 result_t result = createSession( xoopsSessionID, (userid_t)uid, &xnpSessionID );
1129 if ( result == RES_OK )
1130 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1131 RETURN_LONG((long)result);
1132 }
1133
1134 /** XNP ? session ???膣井???宴??緇???<br>
1135 int xnp_get_session( int xnp_session_id, array session_info )
1136 @param xnp_session_id XNP???祉???激?с??D
1137 @param session_info 腟?????????????????
1138 @return 0 success
1139 */
1140 ZEND_FUNCTION(xnp_get_session)
1141 {
1142 long xnpSessionID;
1143 zval *sessionInfo;
1144 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1145 &xnpSessionID, &sessionInfo) == FAILURE) {
1146 return;
1147 }
1148 const session_t *session = 0;
1149 result_t result = getSession( (sessionid_t)xnpSessionID, &session );
1150 if ( result == RES_OK ){
1151 sessionToZval( session, sessionInfo );
1152 freeSession( session );
1153 }
1154
1155 RETURN_LONG((long)result);
1156 }
1157
1158 /** ???若?吟??ctivate?倶??????緇?????<br>
1159 bool xnp_is_activated( int xnp_session_id, int user_id )
1160 @param xnp_session_id XNP???祉???激?с??D
1161 @param user_id xoops_users.uid
1162 @return 0 success
1163 */
1164 ZEND_FUNCTION(xnp_is_activated)
1165 {
1166 long sid, uid;
1167
1168 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
1169 return;
1170 }
1171
1172 bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
1173
1174 RETURN_BOOL(result);
1175 }
1176
1177 /** activate??????<br>
1178 bool xnp_activate( int xnp_session_id, int user_id, bool activated )
1179 @param xnp_session_id xnp ? session id
1180 @param user_id xoops_users.uid
1181 @param activated true:activate, false:inactivate
1182 @return 0 success
1183 */
1184 ZEND_FUNCTION(xnp_activate)
1185 {
1186 long sid, uid;
1187 bool activated;
1188
1189 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
1190 &sid, &uid, &activated) == FAILURE) {
1191 return;
1192 }
1193
1194 result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
1195
1196 RETURN_LONG(result);
1197 }
1198
1199 /** XNP???≪?????潟???違??緇?????<br>
1200 int xnp_get_account_count( int xnp_session_id )
1201 @param xnp_session_id XNP???祉???激?с??D
1202 @return 0 success
1203 */
1204 ZEND_FUNCTION(xnp_get_account_count)
1205 {
1206 long sid;
1207
1208 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1209 &sid) == FAILURE) {
1210 return;
1211 }
1212
1213 long count = getAccountCount( (sessionid_t)sid );
1214 RETURN_LONG(count);
1215 }
1216
1217 /** ?≪?????潟???????ゃ??????<br>
1218 bool xnp_delete_account( int xnp_session_id, int user_id )
1219 @param xnp_session_id XNP???祉???激?с??D
1220 @param user_id xoops_users.uid
1221 @return 0 success
1222 */
1223 ZEND_FUNCTION(xnp_delete_account)
1224 {
1225 long sid, uid;
1226
1227 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1228 &sid, &uid) == FAILURE) {
1229 return;
1230 }
1231
1232 result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
1233
1234 RETURN_LONG(result);
1235 }
1236
1237 /** ?≪?????潟?????宴??緇?????<br>
1238 int xnp_get_account( int xnp_session_id, int user_id, array account_info )
1239 @param xnp_session_id XNP???祉???激?с??D
1240 @param user_id xoops_users.uid
1241 @param account_info ?≪?????潟?????宴???????????f?渇????
1242 @return 0 success
1243 */
1244 ZEND_FUNCTION(xnp_get_account)
1245 {
1246 long sid, uid;
1247 zval *zaccount;
1248
1249 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1250 &sid, &uid, &zaccount) == FAILURE) {
1251 fprintf( stderr, "error occured " );
1252 return;
1253 }
1254
1255 const account_t *paccount;
1256 result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
1257 if ( RES_OK == result ){
1258 accountToZval( paccount, zaccount );
1259 freeAccount( paccount );
1260 }
1261
1262 RETURN_LONG(result);
1263 }
1264
1265 /** ?>散????眼?????≪?????潟???????宴??緇?????<br>
1266 int xnp_get_accoutns( int sid, array uids, array criteria, array accounts );
1267 @param xnp_session_id XNP???祉???激?с??D
1268 @param user_id xoops_users.uid
1269 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1270 @param account_info ?≪?????潟?????宴???????????f?渇????
1271 @return 0 success
1272 */
1273 ZEND_FUNCTION(xnp_get_accounts)
1274 {
1275 result_t result;
1276 long sid;
1277 zval *zuids;
1278 zval *zcriteria;
1279 zval *zaccount;
1280
1281 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1282 &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
1283 return;
1284 }
1285
1286 zCriteria_t zcri(zcriteria);
1287 result = zcri.getResult();
1288 if ( RES_OK == result ){
1289 zUIDs_t zUIDs(zuids);
1290 result = zUIDs.getResult();
1291 if ( RES_OK == result ){
1292 const account_t *paccounts;
1293 int accountLen;
1294 result = getAccounts( (sessionid_t)sid,
1295 zUIDs.getPUID(), zUIDs.getLen(),
1296 &zcri, &paccounts, &accountLen );
1297 if ( RES_OK == result ){
1298 accountsToZval( paccounts, accountLen, zaccount );
1299 freeAccount( paccounts );
1300 }
1301 }
1302 }
1303
1304 RETURN_LONG(result);
1305 }
1306
1307 /** ?≪?????潟?????宴??荐??蚊??????<br>
1308 int xnp_insert_account( int sid, array account_info, int &user_id );
1309 @param xnp_session_id xnp ? session id
1310 @param account_info 荐??蚊???????≪?????潟????????/span>
1311 @param user_id ???若??D(xoops_users.uid)???吾??莨若???????<???潟??/span>
1312 @return 0 success
1313 */
1314 ZEND_FUNCTION(xnp_insert_account)
1315 {
1316 result_t result;
1317 long sid;
1318 zval *zaccount;
1319 zval *zuid;
1320 userid_t uid;
1321
1322 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1323 &sid, &zaccount, &zuid) == FAILURE) {
1324 return;
1325 }
1326
1327 zAccount_t zacc(zaccount);
1328 result = zacc.getResult();
1329 if ( RES_OK == result ){
1330 result = insertAccount( (sessionid_t)sid, &zacc, &uid );
1331 }
1332 zuid -> type = IS_LONG;
1333 zuid -> value.lval = uid;
1334 RETURN_LONG(result);
1335 }
1336
1337 /** ?≪?????潟?????宴???贋?違??????<br>
1338 int xnp_update_account( int sid, array account );
1339 @param xnp_session_id XNP???祉???激?с??D
1340 @param account_info ?吾??莨若???鴻???≪?????潟?????宴??茵????f?渇????
1341 @return 0 success
1342 */
1343 ZEND_FUNCTION(xnp_update_account)
1344 {
1345 result_t result;
1346 long sid;
1347 zval *zaccount;
1348
1349 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1350 &sid, &zaccount) == FAILURE) {
1351 return;
1352 }
1353
1354 zAccount_t zacc(zaccount);
1355 result = zacc.getResult();
1356 if ( RES_OK == result ){
1357 result = updateAccount( (sessionid_t)sid, &zacc );
1358 }
1359
1360 RETURN_LONG(result);
1361 }
1362
1363 /** ?>散???????≪?????潟????id???荀с??緇?????<br>
1364 int xnp_dump_uids( int xnp_session_id, array criteria, array uids );
1365 @param xnp_session_id XNP???祉???激?с??D
1366 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1367 @param uids uid??????????????
1368 @return 0 success
1369 */
1370 ZEND_FUNCTION(xnp_dump_uids)
1371 {
1372 result_t result;
1373 long sid;
1374 zval *zcriteria;
1375 zval *zuids;
1376
1377 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1378 &sid, &zcriteria, &zuids) == FAILURE) {
1379 return;
1380 }
1381
1382 zCriteria_t zcri(zcriteria);
1383 result = zcri.getResult();
1384 if ( RES_OK == result ){
1385 userid_t *puid;
1386 int uidLen;
1387 result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1388 if ( RES_OK == result ){
1389 uidsToZval( puid, uidLen, &zuids );
1390 freeUID( puid );
1391 }
1392 }
1393
1394 RETURN_LONG(result);
1395 }
1396
1397 /** XNP???違???若?????違??緇???<br>
1398 int xnp_get_group_count( int xnp_session_id );
1399 @param xnp_session_id XNP???祉???激?с??D
1400 @return ?違???若????/span>
1401 */
1402 ZEND_FUNCTION(xnp_get_group_count)
1403 {
1404 result_t result;
1405 long sid;
1406
1407 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1408 &sid) == FAILURE) {
1409 return;
1410 }
1411
1412 int count = getGroupCount( (sessionid_t)sid );
1413
1414 RETURN_LONG(count);
1415 }
1416
1417 /** uid?ф??絎????????若?吟??絮????違???若???с?????ゆ?>散????眼?????違???若????id??緇???<br>
1418 int xnp_get_group_by_uid( int xnp_session_id, int uid, array criteria, array gids );
1419 @param xnp_session_id XNP???祉???激?с??D
1420 @param user_id xoops_users.uid
1421 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1422 @param gids gid??????????????
1423 @return 0 success
1424 */
1425 ZEND_FUNCTION(xnp_get_groups_by_uid)
1426 {
1427 result_t result;
1428 long sid, uid;
1429 zval *zcriteria;
1430 zval *zgids;
1431
1432 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1433 &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1434 return;
1435 }
1436
1437 zCriteria_t zcri(zcriteria);
1438 result = zcri.getResult();
1439 if ( RES_OK == result ){
1440 groupid_t *pgids;
1441 int gidLen;
1442 result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1443 if ( RES_OK == result ){
1444 gidsToZval( pgids, gidLen, &zgids );
1445 freeGID( pgids );
1446 }
1447 }
1448
1449 RETURN_LONG(result);
1450 }
1451
1452
1453
1454 /** uid?ф??絎????????若?吟??gid?ф??絎??????違???若?????違???若??膊∞??????????????緇???<br>
1455 int xnp_is_group_admin( int sid, int gid, int uid );
1456 @param xnp_session_id XNP???祉???激?с??D
1457 @param group_id XNP???違???若??ID
1458 @param user_id xoops_users.uid
1459 @return true: ?違???若??膊∞?????с??????
1460 @return false: ?違???若??膊∞?????с???????????????????若?с??????
1461 */
1462 ZEND_FUNCTION(xnp_is_group_admin)
1463 {
1464 result_t result;
1465 long sid, gid, uid;
1466
1467 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1468 &sid, &gid, &uid) == FAILURE) {
1469 return;
1470 }
1471
1472 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1473
1474 RETURN_BOOL(b);
1475 }
1476
1477 /** ?>散????眼?????違???若????id???荀с??緇?????<br>
1478 int xnp_dump_gids( int sid, array criteria, array gids );
1479 @param xnp_session_id XNP???祉???激?с??D
1480 @param criteria ??緇?膀??蚊?祉?純?若??????茵???????
1481 @param gids gid??????????????
1482 @return 0 success
1483 */
1484 ZEND_FUNCTION(xnp_dump_gids)
1485 {
1486 result_t result;
1487 long sid;
1488 zval *zcriteria;
1489 zval *zgids;
1490
1491 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1492 &sid, &zcriteria, &zgids) == FAILURE) {
1493 return;
1494 }
1495
1496 zCriteria_t zcri(zcriteria);
1497 result = zcri.getResult();
1498 if ( RES_OK == result ){
1499 groupid_t *pgid;
1500 int gidLen;
1501 result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
1502 if ( RES_OK == result ){
1503 gidsToZval( pgid, gidLen, &zgids );
1504 freeGID( pgid );
1505 }
1506 }
1507
1508 RETURN_LONG(result);
1509 }
1510
1511 /** gid?ф??絎??????違???若??????????с?????ゆ?>散????眼?????違???若??膊∞??????id???荀с??緇?????<br>
1512 int xnp_dump_group_admins(int sid, int group_id, array criteria, array uids )
1513 @param sid XNP???祉???激?с??D
1514 @param group_id XNP???違???若??ID
1515 @param criteria ?>散
1516 @param uids uid???荀с??????????????
1517 @return 0 success
1518 */
1519
1520 ZEND_FUNCTION(xnp_dump_group_admins)
1521 {
1522 long sid, gid;
1523 zval *zcriteria;
1524 zval *zuids;
1525
1526 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1527 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1528 return;
1529 }
1530
1531 zCriteria_t zcri(zcriteria);
1532 result_t result = zcri.getResult();
1533 if ( result == RES_OK ){
1534 userid_t *uids;
1535 int uidsLen;
1536 result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1537 if ( result == RES_OK ){
1538 uidsToZval( uids, uidsLen, &zuids );
1539 freeUID( uids );
1540 }
1541 }
1542 RETURN_LONG( result );
1543 }
1544
1545 /** ?違???若???????<?潟???若?????ゃ??????<br>
1546 int xnp_delete_member(int sid, int group_id, int user_id )
1547 @param sid XNP???祉???激?с??D
1548 @param group_id XNP???違???若??ID
1549 @param user_id ???若??D
1550 @return 0 success
1551 */
1552
1553 ZEND_FUNCTION(xnp_delete_member)
1554 {
1555 long sid, gid, uid;
1556
1557 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1558 &sid, &gid, &uid) == FAILURE) {
1559 return;
1560 }
1561
1562 result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1563 RETURN_LONG( result );
1564 }
1565
1566 /** ?違???若?????<?潟???若??菴遵??????<br>
1567 int xnp_insert_member(int sid, int group_id, int user_id, bool admin )
1568 @param sid XNP???祉???激?с??D
1569 @param group_id XNP???違???若??ID
1570 @param user_id ???若??D
1571 @param admin ?違???若??膊∞????????true
1572 @return 0 success
1573 */
1574
1575 ZEND_FUNCTION(xnp_insert_member)
1576 {
1577 long sid, gid, uid;
1578 zend_bool admin;
1579
1580 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
1581 &sid, &gid, &uid, &admin) == FAILURE) {
1582 return;
1583 }
1584
1585 result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
1586 RETURN_LONG( result );
1587 }
1588
1589 /** gid?ф??絎??????違???若?????<?潟???若??id???荀с??緇???<br>
1590 int xnp_get_members(int sid, int group_id, array criteria, array uids )
1591 @param sid XNP???祉???激?с??D
1592 @param group_id XNP???違???若??ID
1593 @param criteria ?>散
1594 @param uids uid???荀с??????????????
1595 @return 0 success
1596 */
1597
1598 ZEND_FUNCTION(xnp_get_members)
1599 {
1600 long sid, gid;
1601 zval *zcriteria;
1602 zval *zuids;
1603
1604 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1605 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1606 return;
1607 }
1608
1609 zCriteria_t zcri(zcriteria);
1610 result_t result = zcri.getResult();
1611 if ( result == RES_OK ){
1612 userid_t *uids;
1613 int uidsLen;
1614 result = getMembers( (sessionid_t)sid, (groupid_t)gid, &zcri, &uids, &uidsLen );
1615 if ( result == RES_OK ){
1616 uidsToZval( uids, uidsLen, &zuids );
1617 freeUID( uids );
1618 }
1619 }
1620 RETURN_LONG( result );
1621 }
1622
1623 /** ?違???若?????宴??紊??眼??????<br>
1624 int xnp_update_group(int sid, array group )
1625 @param sid XNP???祉???激?с??D
1626 @param group ?違???若?????宴???f?渇????
1627 @return 0 success
1628 */
1629 ZEND_FUNCTION(xnp_update_group)
1630 {
1631 long sid;
1632 zval *zgroup;
1633 group_t group;
1634
1635 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1636 &sid, &zgroup) == FAILURE) {
1637 return;
1638 }
1639
1640 zvalToGroup( zgroup, &group );
1641 result_t result = updateGroup( sid, &group );
1642 RETURN_LONG( result );
1643 }
1644
1645 /** ?違???若?????宴??菴遵????????<br>
1646 int xnp_insert_group( int sid, array group, int &gid )
1647 @param sid ?祉???激?с??D
1648 @param group ?違???若?????宴???f?渇????
1649 @param gid 絲上??????違???若??ID???吾??莨若???????<???潟??/span>
1650 @return RES_OK
1651 @return RES_DB_NOT_INITIALIZED
1652 @return RES_NO_SUCH_SESSION
1653 @return RES_DB_QUERY_ERROR
1654 */
1655 ZEND_FUNCTION(xnp_insert_group)
1656 {
1657 long sid;
1658 zval *zgroup;
1659 zval *zgid;
1660 group_t group;
1661 groupid_t gid;
1662
1663 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1664 &sid, &zgroup, &zgid ) == FAILURE) {
1665 return;
1666 }
1667
1668 zvalToGroup( zgroup, &group );
1669 result_t result = insertGroup( sid, &group, &gid );
1670 zgid -> type = IS_LONG;
1671 zgid -> value.lval = gid;
1672 RETURN_LONG( result );
1673 }
1674
1675
1676 /** ?違???若?????宴?????ゃ??????<br>
1677 int xnp_delete_group( int sid, int gid )
1678 @param sid XNP???祉???激?с??D
1679 @param gid ???ゃ???????違???若????D
1680 @return RES_OK
1681 @return RES_DB_QUERY_ERROR
1682 @return RES_NO_SUCH_SESSION
1683 @return RES_DB_NOT_INITIALIZED
1684 */
1685 ZEND_FUNCTION(xnp_delete_group)
1686 {
1687 long sid;
1688 long gid;
1689
1690 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1691 &sid, &gid) == FAILURE) {
1692 return;
1693 }
1694 RETURN_LONG( deleteGroup( sid, gid ) );
1695 }
1696
1697 /** ?違???若?????????????緇???<br>
1698 int xnp_dump_group_admins( int sid, int gid, array criteria, array uids )
1699 @param sid XNP???祉???激?с??D
1700 @param gid XNP?違???若????D
1701 @param criteria uids???吾??莨若?????????純?若???>散鐚?膀??蚊????絎?
1702 @param uids 膊∞??????ID???吾??莨若??????
1703 @return RES_OK
1704 @return RES_DB_QUERY_ERROR
1705 @return RES_NO_SUCH_SESSION
1706 @return RES_DB_NOT_INITIALIZED
1707 */
1708 /*
1709 ZEND_FUNCTION(xnp_dump_group_admins)
1710 {
1711 long sid;
1712 long gid;
1713 zval *zcriteria;
1714 zval *zuids;
1715
1716 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1717 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1718 return;
1719 }
1720 zCriteria_t zcri(zcriteria);
1721 result_t result = zcri.getResult();
1722 if ( RES_OK == result ){
1723 userid_t* uids;
1724 int uidsLen;
1725 result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
1726 if( result != RES_OK ) RETURN_LONG( result );
1727 uidsToZval( uids, uidsLen, &zuids );
1728 fprintf( stderr, "uidsLen=%d\n", uidsLen );
1729 for( int i = 0; i < uidsLen; i++ ){
1730 fprintf( stderr, "%d, \n", uids[ i ] );
1731 }
1732 freeUID( uids );
1733 RETURN_LONG( result );
1734 }
1735 RETURN_LONG( result );
1736 }
1737 */
1738
1739 /** ???????ゃ?潟???????鴻??緇???<br>
1740 * int xnp_get_all_indexes( int sid, array criteria, array indexes );
1741 * @param sid XNP???祉???激?с??D
1742 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
1743 * @return RES_OK
1744 */
1745 ZEND_FUNCTION(xnp_get_all_indexes)
1746 {
1747 long sid;
1748 zval *zcriteria;
1749 zval *zindexes;
1750
1751 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1752 &sid, &zcriteria, &zindexes) == FAILURE) {
1753 return;
1754 }
1755 zCriteria_t zcri(zcriteria);
1756 result_t result = zcri.getResult();
1757 if ( RES_OK == result ){
1758 const index_t *indexes;
1759 int indexesLen;
1760 result = getAllIndexes( sid, &zcri, &indexes, &indexesLen );
1761 if ( RES_OK == result ){
1762 result = indexesToZval( indexes, indexesLen, zindexes );
1763 freeIndex( indexes );
1764 }
1765 }
1766 RETURN_LONG(result);
1767 }
1768
1769 /** ?????ゃ?潟???????鴻??????????ゃ?潟???????鴻??緇???<br>
1770 * int xnp_get_indexes( int sid, int parentXID, array criteria, array indexes );
1771 * @param sid XNP???祉???激?с??D
1772 * @param parentXID 荀???ndexID
1773 * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
1774 * @param indexes 腟?????????????????
1775 * @return RES_OK
1776 */
1777 ZEND_FUNCTION(xnp_get_indexes)
1778 {
1779 long sid;
1780 long parentXID;
1781 zval *zcriteria;
1782 zval *zindexes;
1783
1784 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1785 &sid, &parentXID, &zcriteria, &zindexes) == FAILURE) {
1786 return;
1787 }
1788 zCriteria_t zcri(zcriteria);
1789 result_t result = zcri.getResult();
1790 if ( RES_OK == result ){
1791 const index_t *indexes;
1792 int indexesLen;
1793 result = getIndexes( sid, parentXID, &zcri, &indexes, &indexesLen );
1794 if ( RES_OK == result ){
1795 result = indexesToZval( indexes, indexesLen, zindexes );
1796 freeIndex( indexes );
1797 }
1798 }
1799 RETURN_LONG(result);
1800 }
1801
1802
1803 /** ?ゃ?潟???????鴻??篏???????<br>
1804 * int xnp_insert_index( int sid, array index, int &indexID );
1805 * @param sid XNP???祉???激?с??D
1806 * @param index 篏????????ゃ?潟????????/span>
1807 * @param indexID 篏??????????ゃ?潟???????鴻??D??????????紊???/span>
1808 * @return RES_OK
1809 */
1810 ZEND_FUNCTION(xnp_insert_index)
1811 {
1812 long sid;
1813 zval *zindex;
1814 zval *zIndexID;
1815
1816 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1817 &sid, &zindex, &zIndexID) == FAILURE) {
1818 return;
1819 }
1820
1821 if (!PZVAL_IS_REF(zIndexID)) {
1822 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1823 RETURN_LONG(RES_PHP_NONREF);
1824 }
1825 zIndex_t index( zindex );
1826 indexid_t xid;
1827 result_t result = insertIndex( sid, &index, &xid );
1828 if ( RES_OK == result )
1829 ZVAL_LONG(zIndexID, (long)xid);
1830 RETURN_LONG(result);
1831 }
1832
1833 /** ?ゃ?潟???????鴻???贋?違????<br>
1834 * int xnp_update_index( int sid, array index );
1835 * @param sid XNP???祉???激?с??D
1836 * @param index ?贋?違?????ゃ?潟????????/span>
1837 * @return RES_OK
1838 */
1839 ZEND_FUNCTION(xnp_update_index)
1840 {
1841 long sid;
1842 zval *zindex;
1843
1844 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1845 &sid, &zindex) == FAILURE) {
1846 return;
1847 }
1848 zIndex_t index(zindex);
1849 result_t result = index.getResult();
1850 if ( RES_OK == result ){
1851 result = updateIndex( sid, &index );
1852 }
1853 RETURN_LONG(result);
1854 }
1855
1856 /** ?ゃ?潟???????鴻?????ゃ????<br>
1857 * int xnp_delete_index( int sid, int indexID );
1858 * @param sid XNP???祉???激?с??D
1859 * @param indexID ???ゃ?????ゃ?潟????????/span>
1860 * @return RES_OK
1861 */
1862 ZEND_FUNCTION(xnp_delete_index)
1863 {
1864 long sid;
1865 long xid;
1866
1867 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1868 &sid, &xid) == FAILURE) {
1869 return;
1870 }
1871
1872 result_t result = deleteIndex( sid, xid );
1873 RETURN_LONG(result);
1874 }
1875
1876
1877 /** ?ゃ?潟???????鴻????緇?????<br>
1878 * int xnp_get_index( int sid, int indexID, array index );
1879 * @param sid XNP???祉???激?с??D
1880 * @param indexID ??緇??????ゃ?潟???????鴻??D
1881 * @param index ??緇?腟??????????????f?渇????
1882 * @return RES_OK
1883 */
1884 ZEND_FUNCTION(xnp_get_index)
1885 {
1886 long sid;
1887 long xid;
1888 zval *zindex;
1889
1890 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1891 &sid, &xid, &zindex) == FAILURE) {
1892 return;
1893 }
1894
1895 const index_t *index;
1896 result_t result = getIndex( sid, xid, &index );
1897 if ( RES_OK == result ){
1898 result = indexToZval( index, zindex );
1899 freeIndex( index );
1900 }
1901 RETURN_LONG(result);
1902 }
1903
1904
1905
1906 /** ?ゃ?潟???????鴻??茯??粋昭?水??純??????????茯帥?鴻??<br>
1907 * int xnp_is_index_readable( int sid, int indexID );
1908 * @param sid XNP???祉???激?с??D
1909 * @param indexID 絲乗院?ゃ?潟???????鴻??D
1910 * @return true false
1911 */
1912 ZEND_FUNCTION(xnp_is_index_readable)
1913 {
1914 long sid;
1915 long xid;
1916
1917 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1918 &sid, &xid) == FAILURE) {
1919 return;
1920 }
1921 RETURN_BOOL(isIndexReadable(sid,xid));
1922 }
1923
1924
1925 /** ?ゃ?潟???????鴻???吾??莨若?水??純??????????茯帥?鴻??<br>
1926 * int xnp_is_index_writable( int sid, int indexID );
1927 * @param sid XNP???祉???激?с??D
1928 * @param indexID 絲乗院?ゃ?潟???????鴻??D
1929 * @return true false
1930 */
1931 ZEND_FUNCTION(xnp_is_index_writable)
1932 {
1933 long sid;
1934 long xid;
1935
1936 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1937 &sid, &xid) == FAILURE) {
1938 return;
1939 }
1940 RETURN_BOOL(isIndexWritable(sid,xid));
1941 }
1942
1943 /** ?ゃ?潟???????鴻????綺???ャ???帥????<br>
1944 * int xnp_swap_index_sort_number( int sid, int indexID1, int indexID2 );
1945 * @param sid XNP???祉???激?с??D
1946 * @param indexID1 絲乗院?ゃ?潟???????鴻??D
1947 * @param indexID2 絲乗院?ゃ?潟???????鴻??D
1948 * @return true false
1949 */
1950 ZEND_FUNCTION(xnp_swap_index_sort_number)
1951 {
1952 long sid;
1953 long xid1, xid2;
1954
1955 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1956 &sid, &xid1, &xid2) == FAILURE) {
1957 return;
1958 }
1959
1960 result_t result = swapIndexSortNumber( sid, xid1, xid2 );
1961 RETURN_LONG(result);
1962 }
1963
1964
1965
1966 /** XNP??ession_id???綵??с???с????lt;br>
1967 bool xnp_is_valid_session_id( int xnp_session_id)
1968 @return true ???鴻??NP??ession_id?с????<br>
1969 @return false ?≦?鴻??ession_id?障??????????/span>
1970 */
1971 ZEND_FUNCTION(xnp_is_valid_session_id)
1972 {
1973 long sid;
1974 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
1975 return;
1976 }
1977
1978 RETURN_BOOL(isValidSessionID((sessionid_t)sid));
1979 }
1980
1981 /** ?????惹??絖?????緇???<br>
1982 string xnp_get_last_error_string()
1983 @return 0 success
1984 */
1985 ZEND_FUNCTION(xnp_get_last_error_string)
1986 {
1987 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
1988 return;
1989 }
1990
1991 string str( getLastErrorString() );
1992 RETURN_STRING((char *)str.c_str(), 1);
1993 }
1994

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