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.59 - (show annotations) (download) (as text)
Sat Dec 10 06:26:56 2005 UTC (18 years, 3 months ago) by yamaji
Branch: MAIN
CVS Tags: AL_PORTING, REL20051226, REL20060323, tag20060615, tag20070307current, tag20061115, tag20061130, merge_to_20060605, tag20070307, REL20060213, RELENG_2_0_0a_RELEASE, tag20060622, merge_to_20060411, HEAD
Branch point for: XOONIPS_STABLE_32, XOONIPS_STABLE_3, XOONIPS_STABLE_2
Changes since 1.58: +2 -2 lines
File MIME type: text/x-c++src
Space characters are not usually used in the internal module name??

1 /*
2 * --------------------------------------------------------------------------
3 * XooNiPs Xoops modules for Neuroinformatics Platforms
4 * Copyright (C) 2005 RIKEN, Japan. All rights reserved.
5 * http://sourceforge.jp/projects/xoonips/
6 * --------------------------------------------------------------------------
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * --------------------------------------------------------------------------
21 *
22 * $Revision: 1.58 $
23 * XNPAL: XooNiPs Platform Abstract Layer
24 * zend_parse_parameters��php4.1.0������
25 * .so����������������������������������������
26 * C++������extern "C"{}, BEGIN/END_EXTERN_C()��������
27 */
28
29
30 #include <stdio.h>
31 #include "criteria.h"
32 #include "common.h"
33 #include "commonal.h"
34 #include "session.h"
35 #include "group.h"
36 #include "index.h"
37 #include "xnpal.h"
38 #include "amazonbook.h"
39
40 // for inet_aton
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
44
45 // global variables
46
47 PHP_MSHUTDOWN_FUNCTION(xnpalmod)
48 {
49 uninitializeDB();
50 return SUCCESS;
51 }
52
53 PHP_RINIT_FUNCTION(xnpalmod)
54 {
55 useSyslog(false);
56 return SUCCESS;
57 }
58
59 /* declaration of functions to be exported */
60 extern "C" {
61 ZEND_FUNCTION(first_module );
62 ZEND_FUNCTION(xnp_initialize_db );
63 ZEND_FUNCTION(xnp_login_user );
64 ZEND_FUNCTION(xnp_logout_user );
65 ZEND_FUNCTION(xnp_create_session );
66 ZEND_FUNCTION(xnp_get_session );
67 ZEND_FUNCTION(xnp_is_activated );
68 ZEND_FUNCTION(xnp_activate );
69 ZEND_FUNCTION(xnp_get_account_count );
70 ZEND_FUNCTION(xnp_delete_account );
71 ZEND_FUNCTION(xnp_get_account );
72 ZEND_FUNCTION(xnp_get_accounts );
73 ZEND_FUNCTION(xnp_insert_account );
74 ZEND_FUNCTION(xnp_update_account );
75 ZEND_FUNCTION(xnp_dump_uids );
76 ZEND_FUNCTION(xnp_get_group_count );
77 ZEND_FUNCTION(xnp_get_groups_by_uid );
78 ZEND_FUNCTION(xnp_is_group_admin );
79 ZEND_FUNCTION(xnp_dump_gids );
80 ZEND_FUNCTION(xnp_dump_group_admins );
81 ZEND_FUNCTION(xnp_delete_member );
82 ZEND_FUNCTION(xnp_insert_member );
83 ZEND_FUNCTION(xnp_get_members );
84 ZEND_FUNCTION(xnp_delete_group );
85 ZEND_FUNCTION(xnp_insert_group );
86 ZEND_FUNCTION(xnp_update_group );
87 ZEND_FUNCTION(xnp_get_group );
88 ZEND_FUNCTION(xnp_get_groups );
89 ZEND_FUNCTION(xnp_is_moderator );
90 ZEND_FUNCTION(xnp_get_uid );
91
92 ZEND_FUNCTION(xnp_get_all_indexes );
93 ZEND_FUNCTION(xnp_get_indexes );
94 ZEND_FUNCTION(xnp_insert_index );
95 ZEND_FUNCTION(xnp_update_index );
96 ZEND_FUNCTION(xnp_delete_index );
97 ZEND_FUNCTION(xnp_get_index );
98 ZEND_FUNCTION(xnp_is_index_readable );
99 ZEND_FUNCTION(xnp_is_index_writable );
100 ZEND_FUNCTION(xnp_swap_index_sort_number );
101
102 ZEND_FUNCTION(xnp_is_valid_session_id );
103 ZEND_FUNCTION(xnp_get_last_error_string );
104
105 ZEND_FUNCTION(xnp_test_criteria );
106 ZEND_FUNCTION(xnp_test_uids );
107
108
109 ZEND_FUNCTION(xnp_get_item_permission );
110 ZEND_FUNCTION(xnp_get_index_permission );
111 ZEND_FUNCTION(xnp_get_certify_permission );
112
113 ZEND_FUNCTION(xnp_get_certify_state );
114 ZEND_FUNCTION(xnp_set_certify_state );
115
116 ZEND_FUNCTION(xnp_insert_change_log );
117 ZEND_FUNCTION(xnp_get_change_logs );
118
119 ZEND_FUNCTION(xnp_get_config_value );
120 ZEND_FUNCTION(xnp_set_config_value );
121
122 ZEND_FUNCTION(xnp_dump_item_id );
123 ZEND_FUNCTION(xnp_get_item_id_by_binder_id );
124 ZEND_FUNCTION(xnp_get_item_id_by_index_id );
125 ZEND_FUNCTION(xnp_get_overlapped_items );
126
127 ZEND_FUNCTION(xnp_insert_item );
128 ZEND_FUNCTION(xnp_insert_item_direct );
129 ZEND_FUNCTION(xnp_update_item );
130 ZEND_FUNCTION(xnp_delete_item );
131 ZEND_FUNCTION(xnp_get_item );
132 ZEND_FUNCTION(xnp_get_items );
133
134 ZEND_FUNCTION(xnp_pubmed_complete );
135 ZEND_FUNCTION(xnp_amazon_complete );
136
137 //ZEND_FUNCTION(xnp_uninitialize_db );
138
139 ZEND_FUNCTION(xnp_register_binder_item );
140 ZEND_FUNCTION(xnp_unregister_binder_item );
141
142 ZEND_FUNCTION(xnp_register_item );
143 ZEND_FUNCTION(xnp_unregister_item );
144
145 ZEND_FUNCTION(xnp_get_uncertified_link );
146 ZEND_FUNCTION(xnp_get_private_item_id );
147 ZEND_FUNCTION(xnp_get_group_item_id );
148
149 ZEND_FUNCTION(xnp_get_item_types );
150 ZEND_FUNCTION(xnp_get_index_id_by_item_id );
151 ZEND_FUNCTION(xnp_get_own_public_item_id );
152
153 ZEND_FUNCTION(xnp_zip_create );
154 ZEND_FUNCTION(xnp_get_item_count );
155 ZEND_FUNCTION(xnp_get_item_count_group_by_index );
156
157 ZEND_FUNCTION(xnp_extract_public_item_id);
158 ZEND_FUNCTION(xnp_extract_nonbinder_item_id);
159 ZEND_FUNCTION(xnp_insert_event);
160 ZEND_FUNCTION(xnp_get_events);
161 ZEND_FUNCTION(xnp_get_events_for_rss);
162
163 ZEND_FUNCTION(xnp_update_item_status );
164 ZEND_FUNCTION(xnp_refresh_item_status );
165 ZEND_FUNCTION(xnp_selective_harvesting );
166 ZEND_FUNCTION(xnp_get_item_status );
167
168 ZEND_FUNCTION(xnp_insert_related_to );
169 ZEND_FUNCTION(xnp_delete_related_to );
170 ZEND_FUNCTION(xnp_get_related_to );
171
172 ZEND_FUNCTION(xnp_use_syslog );
173 };
174
175
176 #ifdef ZEND_ENGINE_2
177 static
178 ZEND_BEGIN_ARG_INFO(second_and_third_args_force_ref, 0)
179 ZEND_ARG_PASS_INFO(0)
180 ZEND_ARG_PASS_INFO(1)
181 ZEND_ARG_PASS_INFO(1)
182 ZEND_END_ARG_INFO();
183 #else
184 static unsigned char fourth_arg_force_ref[] = { 4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE };
185 static unsigned char second_and_third_args_force_ref[] = { 3, BYREF_NONE, BYREF_FORCE, BYREF_FORCE };
186 #endif
187
188
189 /* compiled function list so Zend knows what's in this module */
190 zend_function_entry xnpalmod_functions[] =
191 {
192 ZEND_FE(first_module ,NULL)
193 ZEND_FE(xnp_initialize_db ,NULL)
194 ZEND_FE(xnp_login_user ,third_arg_force_ref)
195 ZEND_FE(xnp_logout_user ,NULL)
196 ZEND_FE(xnp_create_session ,third_arg_force_ref)
197 ZEND_FE(xnp_get_session ,second_arg_force_ref )
198 ZEND_FE(xnp_is_activated ,NULL)
199 ZEND_FE(xnp_activate ,NULL)
200 ZEND_FE(xnp_get_account_count ,NULL)
201 ZEND_FE(xnp_delete_account ,NULL)
202 ZEND_FE(xnp_get_account ,third_arg_force_ref)
203 ZEND_FE(xnp_get_accounts ,fourth_arg_force_ref)
204 ZEND_FE(xnp_insert_account ,third_arg_force_ref)
205 ZEND_FE(xnp_update_account ,NULL)
206 ZEND_FE(xnp_dump_uids ,third_arg_force_ref)
207 ZEND_FE(xnp_get_group_count ,NULL)
208 ZEND_FE(xnp_get_groups_by_uid ,fourth_arg_force_ref)
209 ZEND_FE(xnp_is_group_admin ,NULL)
210 ZEND_FE(xnp_dump_gids ,third_arg_force_ref)
211 ZEND_FE(xnp_dump_group_admins ,NULL)
212 ZEND_FE(xnp_delete_member ,NULL)
213 ZEND_FE(xnp_insert_member ,NULL)
214 ZEND_FE(xnp_get_members ,fourth_arg_force_ref)
215 ZEND_FE(xnp_delete_group ,NULL)
216 ZEND_FE(xnp_insert_group ,third_arg_force_ref)
217 ZEND_FE(xnp_update_group ,NULL)
218 ZEND_FE(xnp_get_group ,third_arg_force_ref)
219 ZEND_FE(xnp_get_groups ,fourth_arg_force_ref)
220 ZEND_FE(xnp_is_moderator ,NULL)
221 ZEND_FE(xnp_get_uid ,second_arg_force_ref)
222
223 ZEND_FE(xnp_get_all_indexes ,third_arg_force_ref)
224 ZEND_FE(xnp_get_indexes ,fourth_arg_force_ref)
225 ZEND_FE(xnp_insert_index ,third_arg_force_ref)
226 ZEND_FE(xnp_update_index ,NULL)
227 ZEND_FE(xnp_delete_index ,NULL)
228 ZEND_FE(xnp_get_index ,third_arg_force_ref)
229 ZEND_FE(xnp_is_index_readable ,NULL)
230 ZEND_FE(xnp_is_index_writable ,NULL)
231 ZEND_FE(xnp_swap_index_sort_number ,NULL)
232
233 ZEND_FE(xnp_is_valid_session_id ,NULL)
234 ZEND_FE(xnp_get_last_error_string ,NULL)
235 ZEND_FE(xnp_test_criteria ,NULL)
236 ZEND_FE(xnp_test_uids ,NULL)
237
238 ZEND_FE(xnp_get_item_permission ,NULL)
239 ZEND_FE(xnp_get_index_permission ,NULL)
240 ZEND_FE(xnp_get_certify_permission ,NULL)
241
242 ZEND_FE(xnp_get_certify_state ,fourth_arg_force_ref)
243 ZEND_FE(xnp_set_certify_state ,NULL)
244
245 ZEND_FE(xnp_insert_change_log ,NULL)
246 ZEND_FE(xnp_get_change_logs ,third_arg_force_ref)
247
248 ZEND_FE(xnp_get_config_value ,second_arg_force_ref)
249 ZEND_FE(xnp_set_config_value ,NULL)
250
251 ZEND_FE(xnp_dump_item_id ,NULL)
252 ZEND_FE(xnp_get_item_id_by_binder_id ,fourth_arg_force_ref)
253 ZEND_FE(xnp_get_item_id_by_index_id ,fourth_arg_force_ref)
254 ZEND_FE(xnp_get_overlapped_items ,NULL) /*?*/
255
256 ZEND_FE(xnp_insert_item ,third_arg_force_ref)
257 ZEND_FE(xnp_insert_item_direct ,third_arg_force_ref)
258 ZEND_FE(xnp_update_item ,NULL)
259 ZEND_FE(xnp_delete_item ,NULL)
260 ZEND_FE(xnp_get_item ,third_arg_force_ref)
261 ZEND_FE(xnp_get_items ,fourth_arg_force_ref)
262
263 ZEND_FE(xnp_pubmed_complete ,second_arg_force_ref)
264 ZEND_FE(xnp_amazon_complete ,second_arg_force_ref)
265
266 // ZEND_FE(xnp_uninitialize_db ,NULL)
267
268 ZEND_FE(xnp_register_binder_item ,NULL)
269 ZEND_FE(xnp_unregister_binder_item ,NULL)
270
271 ZEND_FE(xnp_register_item ,NULL)
272 ZEND_FE(xnp_unregister_item ,NULL)
273
274 ZEND_FE(xnp_get_uncertified_link ,second_and_third_args_force_ref)
275 ZEND_FE(xnp_get_private_item_id ,third_arg_force_ref)
276 ZEND_FE(xnp_get_group_item_id ,third_arg_force_ref)
277
278 ZEND_FE(xnp_get_item_types ,first_arg_force_ref)
279
280 ZEND_FE(xnp_get_index_id_by_item_id ,third_arg_force_ref)
281 ZEND_FE(xnp_get_own_public_item_id ,third_arg_force_ref)
282
283 ZEND_FE(xnp_zip_create ,NULL)
284 ZEND_FE(xnp_get_item_count ,NULL)
285 ZEND_FE(xnp_get_item_count_group_by_index ,second_arg_force_ref)
286
287 ZEND_FE(xnp_extract_public_item_id ,third_arg_force_ref)
288 ZEND_FE(xnp_extract_nonbinder_item_id,third_arg_force_ref)
289 ZEND_FE(xnp_insert_event ,NULL)
290 ZEND_FE(xnp_get_events ,second_arg_force_ref)
291 ZEND_FE(xnp_get_events_for_rss ,NULL)
292
293 ZEND_FE(xnp_update_item_status ,NULL)
294 ZEND_FE(xnp_refresh_item_status ,NULL)
295 ZEND_FE(xnp_selective_harvesting ,NULL)
296 ZEND_FE(xnp_get_item_status ,NULL)
297
298 ZEND_FE(xnp_insert_related_to ,NULL)
299 ZEND_FE(xnp_delete_related_to ,NULL)
300 ZEND_FE(xnp_get_related_to ,NULL)
301
302 ZEND_FE(xnp_use_syslog ,NULL)
303 {NULL, NULL, NULL}
304 };
305
306 /* compiled module information */
307 zend_module_entry xnpalmod_module_entry =
308 {
309 STANDARD_MODULE_HEADER,
310 "XNPAL",
311 xnpalmod_functions,
312 NULL,
313 PHP_MSHUTDOWN(xnpalmod),
314 PHP_RINIT(xnpalmod),
315 NULL,
316 NULL,
317 NO_VERSION_YET,
318 STANDARD_MODULE_PROPERTIES
319 };
320
321 /* implement standard "stub" routine to introduce ourselves to Zend */
322 #if COMPILE_DL_FIRST_MODULE
323 BEGIN_EXTERN_C()
324 ZEND_GET_MODULE(xnpalmod)
325 END_EXTERN_C()
326 #endif
327
328
329 /* implement function that is meant to be made available to PHP */
330 ZEND_FUNCTION(first_module)
331 {
332 long parameter;
333 // if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
334 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
335 return;
336 }
337 parameter++;
338 RETURN_LONG(parameter);
339 }
340 /** zval����C����������������
341 */
342 char *getZvalString( zval **p ){
343 convert_to_string_ex(p);
344 return Z_STRVAL_PP(p); //(**p).value.str.val;
345 }
346
347 /** zval����int��������
348 */
349 int getZvalInt( zval **p ){
350 convert_to_long_ex(p);
351 return Z_LVAL_PP(p); // (int)(**p).value.lval;
352 }
353
354 // keylen��������\0��������
355 static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
356 zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br> ", key, keyLen, index );
357 if ( res == HASH_KEY_IS_STRING ){
358 char *p = new char[keyLen+1];
359 memcpy( p, key, keyLen );
360 p[keyLen] = 0;
361 zend_printf( " key is string[%s]<br>\n", p );
362 }
363 else {
364 zend_printf( " key is integer[%d]<br>\n", index );
365 }
366 }
367
368
369 /** zval*����criteria_t������������������������������������getResult()!=RES_OK <br>
370 criteria :
371 array( 'start'=>0, 'rows'=>10,
372 'orders'=>array(
373 array('name'=>'id','order'=>'0'),
374 array('name'=>'timestamp','name'=>'1'), ...)
375 ); ������������������
376 */
377 class zCriteria_t : public criteria {
378 private:
379 result_t result;
380
381 // pz: array('name'=>'timestamp','name'=>'1')
382 // ��������orderby����������������
383 void setOrder( zval *pz ){
384 char *column = 0;
385 order_t order = (order_t)0;
386
387 HashPosition pos;
388 zval **ppzTmp = 0;
389 int res2;
390 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
391 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
392 char *key = 0;
393 uint keyLen = 0;
394 ulong index = 0;
395 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
396 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
397 //print_hash_key( keyType, key, keyLen, index );
398 if ( strncasecmp( key, "name", keyLen ) == 0 && keyLen == 5 ){
399 SEPARATE_ZVAL(ppzTmp);
400 column = getZvalString(ppzTmp);
401 // zend_printf( "column=%s<br>\n", column );
402 }
403 else if ( strncasecmp( key, "order", keyLen ) == 0 && keyLen == 6 ){
404 SEPARATE_ZVAL(ppzTmp);
405 order = (order_t)getZvalInt(ppzTmp);
406 // zend_printf( "order=%d<br>\n", order );
407 }
408 }
409
410 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
411 }
412 if ( column ){
413 orderby *o = new orderby( column, order );
414 addOrderBy( o );
415 }
416
417 result = RES_OK;
418 }
419
420 // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
421 void setOrders( zval *pz ){
422 HashPosition pos;
423
424 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
425
426 zval **ppzTmp = 0;
427 int res2;
428 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
429 char *key = 0;
430 uint keyLen = 0;
431 ulong index = 0;
432 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
433 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
434 //print_hash_key( keyType, key, keyLen, index );
435 setOrder( *ppzTmp );
436 }
437 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
438 }
439 result = RES_OK;
440 }
441
442 void initialize( zval *pz ){
443 HashPosition pos;
444 zval **ppzTmp = 0;
445 int res2;
446 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
447 while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
448 char *key = 0;
449 uint keyLen = 0;
450 ulong index = 0;
451 int keyType = zend_hash_get_current_key_ex(Z_ARRVAL_P(pz), &key, &keyLen, &index, false/*duplicate flag*/, &pos );
452 if ( keyType == HASH_KEY_IS_STRING/*1*/ || keyType == HASH_KEY_IS_LONG/*2*/ ){
453 //print_hash_key( keyType, key, keyLen, index );
454 if ( strncasecmp( key, "start", keyLen ) == 0 && keyLen == 6 ){
455 SEPARATE_ZVAL(ppzTmp);
456 int tmp = getZvalInt(ppzTmp);
457 // zend_printf( "start=%d<br>\n", tmp );
458 setLimit( tmp, getLimitRows() );
459 }
460 else if ( strncasecmp( key, "rows", keyLen ) == 0 && keyLen == 5 ){
461 SEPARATE_ZVAL(ppzTmp);
462 int tmp = getZvalInt(ppzTmp);
463 // zend_printf( "rows=%d<br>\n", tmp );
464 setLimit( getLimitStart(), tmp );
465 }
466 else if ( strncasecmp( key, "orders", keyLen ) == 0 && keyLen == 7 ){
467 setOrders( *ppzTmp );
468 }
469 else
470 ; // ignore unknown key
471 }
472 else
473 ; // ignore bad key
474 zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
475 }
476 result = RES_OK;
477 }
478
479 public:
480 zCriteria_t() : criteria(){ result = RES_ERROR; }
481 zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
482 zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
483 result_t getResult(){ return result; };
484
485 void dump(){
486 zend_printf( "dumping zCriteria...<br>\n" );
487 zend_printf( "result=%d<br>\n", (int)result );
488 zend_printf( "start=%d, rows=%d<br>\n", getLimitStart(), getLimitRows() );
489 const orderby *p = headOrderBy();
490 while ( p ){
491 zend_printf( "column=%s, order=%d<br>\n", p->getColumn(), p->getOrder() );
492 p = nextOrderBy();
493 }
494 }
495 };
496
497
498 /** ����������������������long����������
499 @param ht ��������
500 @param key ����
501 @param val long��������������������
502 @return ��������true
503 */
504 static bool hashGetLong( HashTable *ht, const char *key, long *val ){
505 zval **tmp;
506 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
507 convert_to_long_ex( tmp );
508 *val = Z_LVAL_PP(tmp);
509 return true;
510 }
511 return false;
512 }
513
514 /** ������������������������������������
515 @param ht ��������
516 @param key ����
517 @param val ������������������������
518 @return ��������true
519 */
520 static bool hashGetString( HashTable *ht, const char *key, char **val ){
521 zval **tmp;
522 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
523 convert_to_string_ex( tmp );
524 *val = Z_STRVAL_PP(tmp);
525 return true;
526 }
527 return false;
528 }
529
530 /** ����������������������double����������
531 @param ht ��������
532 @param key ����
533 @param val double��������������������
534 @return ��������true
535 */
536 static bool hashGetDouble( HashTable *ht, const char *key, double *val ){
537 zval **tmp;
538 if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
539 convert_to_double_ex( tmp );
540 *val = Z_DVAL_PP(tmp);
541 return true;
542 }
543 return false;
544 }
545
546 /** zval*����account������������������������ <br>
547 ������������getResult()!=RES_OK <br>
548 */
549 class zAccount_t : public account {
550 private:
551 result_t result;
552 void initialize(zval *pz){
553 HashTable *ht = Z_ARRVAL_P(pz);
554 long l;
555 char *p;
556 double d;
557 if ( hashGetLong ( ht, "uid" , &l ) ) setUID ( l );
558 if ( hashGetString( ht, "uname" , &p ) ) setUname ( p );
559 if ( hashGetString( ht, "name" , &p ) ) setName ( p );
560 if ( hashGetString( ht, "email" , &p ) ) setEmail ( p );
561 if ( hashGetString( ht, "url" , &p ) ) setURL ( p );
562 if ( hashGetString( ht, "user_avatar" , &p ) ) setUserAvatar ( p );
563 if ( hashGetString( ht, "user_icq" , &p ) ) setUserIcq ( p );
564 if ( hashGetString( ht, "user_from" , &p ) ) setUserFrom ( p );
565 if ( hashGetString( ht, "user_sig" , &p ) ) setUserSig ( p );
566 if ( hashGetString( ht, "actkey" , &p ) ) setActkey ( p );
567 if ( hashGetString( ht, "user_aim" , &p ) ) setUserAim ( p );
568 if ( hashGetString( ht, "user_yim" , &p ) ) setUserYim ( p );
569 if ( hashGetString( ht, "user_msnm" , &p ) ) setUserMsnm ( p );
570 if ( hashGetString( ht, "pass" , &p ) ) setPass ( p );
571 if ( hashGetString( ht, "theme" , &p ) ) setTheme ( p );
572 if ( hashGetString( ht, "umode" , &p ) ) setUmode ( p );
573 if ( hashGetString( ht, "user_occ" , &p ) ) setUserOcc ( p );
574 if ( hashGetString( ht, "bio" , &p ) ) setBio ( p );
575 if ( hashGetString( ht, "user_intrest" , &p ) ) setUserIntrest ( p );
576 if ( hashGetDouble( ht, "timezone_offset" , &d ) ) setTimezoneOffset ( d );
577 if ( hashGetLong ( ht, "attachsig" , &l ) ) setAttachsig ( l );
578 if ( hashGetLong ( ht, "last_login" , &l ) ) setLastLogin ( l );
579 if ( hashGetLong ( ht, "level" , &l ) ) setLevel ( l );
580 if ( hashGetLong ( ht, "notify_method" , &l ) ) setNotifyMethod ( l );
581 if ( hashGetLong ( ht, "notify_mode" , &l ) ) setNotifyMode ( l );
582 if ( hashGetLong ( ht, "posts" , &l ) ) setPosts ( l );
583 if ( hashGetLong ( ht, "rank" , &l ) ) setRank ( l );
584 if ( hashGetLong ( ht, "uorder" , &l ) ) setUorder ( l );
585 if ( hashGetLong ( ht, "user_mailok" , &l ) ) setUserMailok ( l );
586 if ( hashGetLong ( ht, "user_regdate" , &l ) ) setUserRegdate ( l );
587 if ( hashGetLong ( ht, "user_viewemail" , &l ) ) setUserViewemail ( l );
588 if ( hashGetLong ( ht, "activate" , &l ) ) setActivate ( l );
589 if ( hashGetString( ht, "address" , &p ) ) setAddress ( p );
590 if ( hashGetString( ht, "division" , &p ) ) setDivision ( p );
591 if ( hashGetString( ht, "tel" , &p ) ) setTel ( p );
592 if ( hashGetString( ht, "company_name" , &p ) ) setCompanyName ( p );
593 if ( hashGetString( ht, "country" , &p ) ) setCountry ( p );
594 if ( hashGetString( ht, "zipcode" , &p ) ) setZipcode ( p );
595 if ( hashGetString( ht, "fax" , &p ) ) setFax ( p );
596 if ( hashGetLong ( ht, "notice_mail" , &l ) ) setNoticeMail ( l );
597 if ( hashGetLong ( ht, "notice_mail_since" , &l ) ) setNoticeMailSince ( l );
598 if ( hashGetLong ( ht, "private_index_id " , &l ) ) setPrivateIndexID ( l );
599 if ( hashGetLong ( ht, "item_number_limit" , &l ) ) setItemNumberLimit ( l );
600 if ( hashGetLong ( ht, "index_number_limit", &l ) ) setIndexNumberLimit ( l );
601 if ( hashGetDouble( ht, "item_storage_limit", &d ) ) setItemStorageLimit ( d );
602
603 result = RES_OK;
604 }
605 public:
606 zAccount_t() : account(){ result = RES_ERROR; }
607
608 /** ��������������
609 @param pz array( 'uid'=>1, 'uname'=>'root', ... ); ������������������ */
610 zAccount_t( zval *pz ) : account(){ initialize(pz); }
611 zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
612 result_t getResult(){ return result; };
613 };
614
615 class zIndex_t : public index {
616 private:
617 result_t result;
618
619 void initialize(zval *pz){
620 HashTable *ht = Z_ARRVAL_P(pz);
621 long l;
622 char *p;
623 if ( hashGetLong ( ht, "item_id" , &l ) ) setItemID ( l );
624 if ( hashGetLong ( ht, "item_type_id" , &l ) ) setItemTypeID ( l );
625 if ( hashGetLong ( ht, "contributor_uid" , &l ) ) setContributorUID ( l );
626 if ( hashGetString( ht, "title" , &p ) ) setTitle ( p );
627 if ( hashGetString( ht, "keywords" , &p ) ) setKeywords ( p );
628 if ( hashGetString( ht, "description" , &p ) ) setDescription ( p );
629 if ( hashGetLong ( ht, "last_update_date" , &l ) ) setLastUpdateDate ( l );
630 if ( hashGetLong ( ht, "creation_date" , &l ) ) setCreationDate ( l );
631 if ( hashGetLong ( ht, "parent_index_id" , &l ) ) setParentIndexID ( l );
632 if ( hashGetLong ( ht, "owner_uid" , &l ) ) setOwnerUID ( l );
633 if ( hashGetLong ( ht, "owner_gid" , &l ) ) setOwnerGID ( l );
634 if ( hashGetLong ( ht, "open_level" , &l ) ) setOpenLevel ( l );
635 if ( hashGetLong ( ht, "sort_number" , &l ) ) setSortNumber ( l );
636
637 result = RES_OK;
638 }
639 public:
640 zIndex_t() : index(){ result = RES_ERROR; }
641 zIndex_t( zval *pz ) : index(){ initialize(pz); }
642 zIndex_t( zval **ppz ) : index() { initialize(*ppz); }
643 result_t getResult(){ return result; };
644
645 void dump(){
646 }
647 };
648
649 /** zval*����(userid_t *puid,int uidLen)������������������������ <br>
650 ������������getResult()!=RES_OK <br>
651 */
652 class zUIDs_t {
653 private:
654 result_t result;
655 userid_t *pUID;
656 int len;
657 public:
658 zUIDs_t(){
659 pUID = 0;
660 len = 0;
661 result = RES_ERROR;
662 }
663
664 /** ��������������
665 @param pza array( '1', '3', '4', '6', ... ); �������������� */
666 zUIDs_t( zval *pza ){
667 pUID = 0;
668 len = 0;
669 result = RES_ERROR;
670
671 if ( Z_TYPE_P(pza) != IS_ARRAY ){
672 result = RES_ERROR;
673 }
674 else {
675 len = zend_hash_num_elements(Z_ARRVAL_P(pza));
676 if(len == 0) {
677 pUID = new userid_t[1];
678 result = RES_OK;
679 }
680 else {
681 /* php/ext/standard/string.c �� implode������������������
682 zend_hash_*����������������������������������
683 */
684 zval **tmp;
685 HashPosition pos;
686 int i = 0;
687 pUID = new userid_t[len];
688
689 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
690 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
691 SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ����
692 convert_to_long_ex(tmp);
693 if ( i < len )
694 pUID[i++] = Z_LVAL_PP(tmp);
695 zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
696 }
697 len = i;
698 result = RES_OK;
699 }
700 }
701 }
702
703 ~zUIDs_t(){
704 if ( pUID ) delete[] pUID;
705 }
706 result_t getResult(){ return result; }
707 userid_t *getPUID(){ return pUID; }
708 int getLen(){ return len; }
709 void dump(){
710 zend_printf( "dumping zUIDs...<br>\n" );
711 zend_printf( "result=%d<br>\n", (int)result );
712 zend_printf( "len=%d<br>\n", len );
713 for ( int i = 0; i < len; i++ ){
714 zend_printf( "pUID[%d] = %d<br>\n", i, pUID[i] );
715 }
716 }
717 };
718
719 /** zval*����(itemid_t *piid,int iidLen)������������������������ <br>
720 ������������getResult()!=RES_OK <br>
721 */
722 class zIIDs_t {
723 private:
724 result_t result;
725 itemid_t *pIID;
726 int len;
727 public:
728 zIIDs_t(){
729 pIID = 0;
730 len = 0;
731 result = RES_ERROR;
732 }
733
734 /** ��������������
735 @param pza array( '1', '3', '4', '6', ... ); �������������� */
736 zIIDs_t( zval *pza ){
737 pIID = 0;
738 len = 0;
739 result = RES_ERROR;
740
741 if ( Z_TYPE_P(pza) != IS_ARRAY ){
742 result = RES_ERROR;
743 }
744 else {
745 len = zend_hash_num_elements(Z_ARRVAL_P(pza));
746 if(len == 0) {
747 pIID = new itemid_t[1];
748 result = RES_OK;
749 }
750 else {
751 /* php/ext/standard/string.c �� implode������������������
752 zend_hash_*����������������������������������
753 */
754 zval **tmp;
755 HashPosition pos;
756 int i = 0;
757 pIID = new itemid_t[len];
758
759 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
760 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
761 SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html ����
762 convert_to_long_ex(tmp);
763 if ( i < len )
764 pIID[i++] = Z_LVAL_PP(tmp);
765 zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
766 }
767 len = i;
768 result = RES_OK;
769 }
770 }
771 }
772
773 ~zIIDs_t(){
774 if ( pIID ) delete[] pIID;
775 }
776 result_t getResult(){ return result; }
777 itemid_t *getPIID(){ return pIID; }
778 int getLen(){ return len; }
779 void dump(){
780 zend_printf( "dumping zIIDs...<br>\n" );
781 zend_printf( "result=%d<br>\n", (int)result );
782 zend_printf( "len=%d<br>\n", len );
783 for ( int i = 0; i < len; i++ ){
784 zend_printf( "pIID[%d] = %d<br>\n", i, pIID[i] );
785 }
786 }
787 };
788
789 /**
790 *
791 * amazonbook_t��������PHP����������������
792 * @param pAmazonbook ��������amazonbook_t*
793 * @param z ����������������������(��������������������)
794 * @return RES_OK
795 *
796 */
797 result_t amazonbookToZval( const amazonbook_t *pAmazonbook, zval *z )
798 {
799 zend_hash_clean( z -> value.ht );
800
801 add_assoc_string( z, "title", ( char* )pAmazonbook -> getTitle( ), 1 );
802 add_assoc_string( z, "author", ( char* )pAmazonbook -> getAuthor( ), 1 );
803 add_assoc_string( z, "publisher", ( char* )pAmazonbook -> getPublisher( ), 1 );
804 add_assoc_long( z, "year_of_publication", pAmazonbook -> getYearOfPublication( ) );
805 add_assoc_string( z, "isbn", ( char* )pAmazonbook -> getISBN( ), 1 );
806 add_assoc_string( z, "url", ( char* )pAmazonbook -> getURL( ), 1 );
807
808 return RES_OK;
809 }
810
811 /**
812 *
813 * pubmed_t��������PHP����������������
814 * @param pPubmed ��������pubmed_t*
815 * @param z ����������������������(��������������������)
816 * @return RES_OK
817 *
818 */
819 result_t pubmedToZval( const pubmed_t *pPubmed, zval *z )
820 {
821 zend_hash_clean( z -> value.ht );
822
823 add_assoc_long( z, "pmid", pPubmed -> getID( ) );
824 add_assoc_string( z, "title", ( char* )pPubmed -> getTitle( ), 1 );
825 add_assoc_string( z, "author", ( char* )pPubmed -> getAuthor( ), 1 );
826 add_assoc_string( z, "journal", ( char* )pPubmed -> getJournal( ), 1 );
827 add_assoc_long( z, "year_of_publication", pPubmed -> getYearOfPublication( ) );
828 add_assoc_long( z, "volume", pPubmed -> getVolume( ) );
829 add_assoc_long( z, "number", pPubmed -> getNumber( ) );
830 add_assoc_string( z, "page", ( char* )pPubmed -> getPage( ), 1 );
831 add_assoc_string( z, "abstract", ( char* )pPubmed -> getAbstract( ), 1 );
832
833 return RES_OK;
834 }
835
836 /**
837 *
838 * itemid_t��������PHP����������������
839 * @param piid ��������itemid_t������
840 * @param len piid������������
841 * @param ppz ����������������������(��������������������)
842 * @return RES_OK
843 *
844 */
845 result_t itemidsToZval( const itemid_t *piid, int len, zval **ppz )
846 {
847 zend_hash_clean( Z_ARRVAL_PP(ppz) );
848
849 // add IDs
850 for ( int i = 0; i < len; i++ ){
851 add_next_index_long(*ppz, (long)(piid[i]) );
852 }
853
854 return RES_OK;
855 }
856
857 /**
858 *
859 * indexid_t��������PHP����������������
860 * @param piid ��������indexid_t������
861 * @param len piid������������
862 * @param ppz ����������������������(��������������������)
863 * @return RES_OK
864 *
865 */
866 result_t indexidsToZval( const indexid_t *piid, int len, zval **ppz )
867 {
868 zend_hash_clean( Z_ARRVAL_PP(ppz) );
869
870 // add IDs
871 for ( int i = 0; i < len; i++ ){
872 add_next_index_long(*ppz, (long)(piid[i]) );
873 }
874
875 return RES_OK;
876 }
877
878 /**
879 *
880 * uids_t��������PHP����������������
881 *
882 * @param pUID ��������userid_t������
883 * @param len pUID������������
884 * @param pz ����������������������(��������������������)
885 * @return RES_OK
886 *
887 */
888 result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
889 {
890 zend_hash_clean( Z_ARRVAL_PP(ppz) );
891
892 // add UIDs
893 for ( int i = 0; i < len; i++ ){
894 add_next_index_long(*ppz, (long)(pUID[i]) );
895 }
896
897 return RES_OK;
898 }
899
900 /**
901 *
902 * groupid_t��������PHP����������������
903 * @param pGID ��������groupid_t������
904 * @param len pGID������������
905 * @param ppz ����������������������(��������������������)
906 * @return RES_OK
907 *
908 */
909 result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
910 {
911 zend_hash_clean( Z_ARRVAL_PP(ppz) );
912
913 // add GIDs
914 for ( int i = 0; i < len; i++ ){
915 add_next_index_long(*ppz, (long)(pGID[i]) );
916 }
917
918 return RES_OK;
919 }
920
921 /**
922 *
923 * changelog_t��������PHP����������������
924 * @param pChangelog ��������changelog_t*
925 * @param z ����������������������(��������������������)
926 * @return RES_OK
927 *
928 */
929 result_t changelogToZval( const changelog_t *pChangelog, zval *z )
930 {
931 zend_hash_clean( z -> value.ht );
932
933 add_assoc_long( z, "log_id", pChangelog -> getChangelogID( ) );
934 add_assoc_long( z, "item_id", pChangelog -> getItemID( ) );
935 add_assoc_long( z, "log_date", pChangelog -> getDate( ) );
936 add_assoc_string( z, "log", ( char* )pChangelog -> getLog( ), 1 );
937
938 return RES_OK;
939 }
940
941 /**
942 *
943 * item_t��������PHP����������������
944 * @param pItem ��������item_t*
945 * @param z ����������������������(��������������������)
946 * @return RES_OK
947 *
948 */
949 result_t itemToZval( const item_t *pItem, zval *z )
950 {
951 zend_hash_clean( z -> value.ht );
952
953 add_assoc_long( z, "item_id", pItem -> getItemID( ) );
954 add_assoc_long( z, "item_type_id", pItem -> getItemTypeID( ) );
955 add_assoc_long( z, "uid", pItem -> getContributorUID( ) );
956 add_assoc_string( z, "title", ( char* )pItem -> getTitle( ), 1 );
957 add_assoc_string( z, "keywords", ( char* )pItem -> getKeywords( ), 1 );
958 add_assoc_string( z, "description", ( char* )pItem -> getDescription( ), 1 );
959 add_assoc_string( z, "doi", ( char* )pItem -> getDOI( ), 1 );
960 add_assoc_long( z, "last_update_date", pItem -> getLastUpdateDate( ) );
961 add_assoc_long( z, "creation_date", pItem -> getCreationDate( ) );
962 add_assoc_long( z, "publication_year", pItem -> getPublicationYear( ) );
963 add_assoc_long( z, "publication_month", pItem -> getPublicationMonth( ) );
964 add_assoc_long( z, "publication_mday", pItem -> getPublicationMday( ) );
965 add_assoc_string( z, "lang", ( char* )pItem -> getLang( ), 1 );
966
967 return RES_OK;
968 }
969
970
971 result_t itemsToZval( const item_t *pItems, int itemsLen, zval *z )
972 {
973 zend_hash_clean( z -> value.ht );
974 for( int i = 0; i < itemsLen; i++ ){
975 zval *new_array;
976 MAKE_STD_ZVAL(new_array);
977 if(array_init(new_array) != SUCCESS){
978 return RES_ERROR;
979 }
980 add_index_zval( z, i, new_array );
981 itemToZval( &pItems[ i ], new_array );
982 }
983 return RES_OK;
984 }
985
986 /**
987 *
988 * PHP������������������group_t����������
989 *
990 * @param z ����������������
991 * @param pGroup ��������������������������
992 * @return RES_OK
993 *
994 */
995 result_t zvalToItem( zval *z, item_t* pItem )
996 {
997 zval **tmp;
998 char* key = 0;
999
1000 key = "item_id";
1001 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1002 convert_to_long_ex( tmp ) ;
1003 pItem -> setItemID( (*tmp) -> value.lval );
1004 }
1005 key = "item_type_id";
1006 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1007 convert_to_long_ex( tmp ) ;
1008 pItem -> setItemTypeID( (*tmp) -> value.lval );
1009 }
1010 key = "uid";
1011 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1012 convert_to_long_ex( tmp ) ;
1013 pItem -> setContributorUID( (*tmp) -> value.lval );
1014 }
1015 key = "title";
1016 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1017 convert_to_string_ex( tmp ) ;
1018 pItem -> setTitle( (*tmp) -> value.str.val );
1019 }
1020 key = "keywords";
1021 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1022 convert_to_string_ex( tmp ) ;
1023 pItem -> setKeywords( (*tmp) -> value.str.val );
1024 }
1025 key = "description";
1026 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1027 convert_to_string_ex( tmp ) ;
1028 pItem -> setDescription( (*tmp) -> value.str.val );
1029 }
1030 key = "doi";
1031 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1032 convert_to_string_ex( tmp ) ;
1033 pItem -> setDOI( (*tmp) -> value.str.val );
1034 }
1035 key = "last_update_date";
1036 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1037 convert_to_long_ex( tmp ) ;
1038 pItem -> setLastUpdateDate( (*tmp) -> value.lval );
1039 }
1040 key = "creation_date";
1041 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1042 convert_to_long_ex( tmp ) ;
1043 pItem -> setCreationDate( (*tmp) -> value.lval );
1044 }
1045 key = "publication_year";
1046 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1047 convert_to_long_ex( tmp ) ;
1048 pItem -> setPublicationYear( (*tmp) -> value.lval );
1049 }
1050 key = "publication_month";
1051 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1052 convert_to_long_ex( tmp ) ;
1053 pItem -> setPublicationMonth( (*tmp) -> value.lval );
1054 }
1055 key = "publication_mday";
1056 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1057 convert_to_long_ex( tmp ) ;
1058 pItem -> setPublicationMday( (*tmp) -> value.lval );
1059 }
1060 key = "lang";
1061 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1062 convert_to_string_ex( tmp ) ;
1063 pItem -> setLang( (*tmp) -> value.str.val );
1064 }
1065 return RES_OK;
1066 }
1067
1068 /**
1069 *
1070 * account_t��������PHP����������������
1071 * @param pAccount ��������account_t*
1072 * @param z ����������������������(��������������������)
1073 * @return RES_OK
1074 *
1075 */
1076 result_t accountToZval( const account_t *pAccount, zval *z )
1077 {
1078 zend_hash_clean( z -> value.ht );
1079
1080 add_assoc_long( z, "uid", pAccount -> getUID( ) );
1081 add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
1082 add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
1083 add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
1084 add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
1085 add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
1086 add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
1087 add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
1088 add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
1089 add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
1090 add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
1091 add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
1092 add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
1093 add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
1094 add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
1095 add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
1096 add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
1097 add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
1098 add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
1099 add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
1100 add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
1101 add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
1102 add_assoc_long( z, "level", pAccount -> getLevel( ) );
1103 add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
1104 add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
1105 add_assoc_long( z, "posts", pAccount -> getPosts( ) );
1106 add_assoc_long( z, "rank", pAccount -> getRank( ) );
1107 add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
1108 add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
1109 add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
1110 add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
1111
1112 add_assoc_long( z, "activate", pAccount -> getActivate( ) );
1113 add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
1114 add_assoc_string( z, "division", ( char* )pAccount -> getDivision( ), 1 );
1115 add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
1116 add_assoc_string( z, "company_name", ( char* )pAccount -> getCompanyName( ), 1 );
1117 add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
1118 add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
1119 add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
1120 add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
1121 add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
1122 add_assoc_long( z, "private_index_id", pAccount -> getPrivateIndexID( ) );
1123 add_assoc_long( z, "item_number_limit", pAccount -> getItemNumberLimit( ) );
1124 add_assoc_long( z, "index_number_limit", pAccount -> getIndexNumberLimit( ) );
1125 add_assoc_double( z, "item_storage_limit", pAccount -> getItemStorageLimit( ) );
1126 return RES_OK;
1127 }
1128
1129 /**
1130 *
1131 * ������account_t��������PHP����������������������
1132 * @param pAccounts ��������account_t*
1133 * @param accountsLen pAccounts������������
1134 * @param z ����������������������(��������������������)
1135 * @return RES_OK
1136 *
1137 z: �������������������������� <br>
1138 array(
1139 array(
1140 'uid'=>100,
1141 'activate'=>1,
1142 'division'=>'foo',
1143 'tel'=>'123-456-789',
1144 ...
1145 ),
1146 ...
1147 )
1148 */
1149 result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
1150 {
1151 zend_hash_clean( z -> value.ht );
1152 for( int i = 0; i < accountsLen; i++ ){
1153 zval *new_array;
1154 MAKE_STD_ZVAL(new_array);
1155 if(array_init(new_array) != SUCCESS){
1156 return RES_ERROR;
1157 }
1158 add_index_zval( z, i, new_array );
1159 accountToZval( &pAccounts[ i ], new_array );
1160 }
1161 return RES_OK;
1162 }
1163
1164 /**
1165 *
1166 * ������group_t��������PHP����������������������
1167 * @param pGroups ��������group_t*
1168 * @param groupsLen pGroups������������
1169 * @param z ����������������������(��������������������)
1170 * @return RES_OK
1171 *
1172 z: �������������������������� <br>
1173 array(
1174 array(
1175 'gid'=>1,
1176 'gname'=>'foo group',
1177 'gdesc'=>'group of foo'
1178 ),
1179 ...
1180 )
1181 */
1182 result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
1183 {
1184 zend_hash_clean( z -> value.ht );
1185 for( int i = 0; i < groupsLen; i++ ){
1186 zval *new_array;
1187 MAKE_STD_ZVAL(new_array);
1188 if(array_init(new_array) != SUCCESS){
1189 return RES_ERROR;
1190 }
1191 add_index_zval( z, i, new_array );
1192 add_assoc_long( new_array, "gid", pGroups[ i ].getGID( ) );
1193 add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
1194 add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
1195 add_assoc_long( new_array, "group_index_id", pGroups[ i ].getGroupIndexID( ) );
1196 add_assoc_long( new_array, "item_number_limit", pGroups[ i ].getItemNumberLimit( ) );
1197 add_assoc_long( new_array, "index_number_limit", pGroups[ i ].getIndexNumberLimit( ) );
1198 add_assoc_double( new_array, "item_storage_limit", pGroups[ i ].getItemStorageLimit( ) );
1199 }
1200 return RES_OK;
1201 }
1202
1203 /**
1204 *
1205 * group_t��������PHP��������������������
1206 *
1207 * @param pGroup ��������������������
1208 * @param z ��������������������������(��������������������)
1209 * @return RES_OK
1210 *
1211 */
1212 result_t groupToZval( const group_t *pGroup, zval *z )
1213 {
1214 zend_hash_clean( z -> value.ht );
1215 add_assoc_long( z, "gid", pGroup -> getGID( ) );
1216 add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
1217 add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
1218 add_assoc_long( z, "group_index_id", pGroup -> getGroupIndexID( ) );
1219 add_assoc_long( z, "item_number_limit", pGroup -> getItemNumberLimit( ) );
1220 add_assoc_long( z, "index_number_limit", pGroup -> getIndexNumberLimit( ) );
1221 add_assoc_double( z, "item_storage_limit", pGroup -> getItemStorageLimit( ) );
1222 return RES_OK;
1223 }
1224
1225 /**
1226 *
1227 * PHP������������������group_t����������
1228 *
1229 * @param z ����������������
1230 * @param pGroup ��������������������������
1231 * @return RES_OK
1232 *
1233 */
1234 result_t zvalToGroup( zval *z, group_t *pGroup )
1235 {
1236 zval **tmp;
1237 char* key = 0;
1238
1239 key = "gid";
1240 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1241 convert_to_long_ex( tmp ) ;
1242 pGroup -> setGID( (*tmp) -> value.lval );
1243 }
1244 key = "gname";
1245 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1246 convert_to_string_ex( tmp ) ;
1247 pGroup -> setGname( (*tmp) -> value.str.val );
1248 }
1249 key = "gdesc";
1250 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1251 convert_to_string_ex( tmp ) ;
1252 pGroup -> setDesc( (*tmp) -> value.str.val );
1253 }
1254 key = "group_index_id";
1255 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1256 convert_to_long_ex( tmp ) ;
1257 pGroup -> setGroupIndexID( (*tmp) -> value.lval );
1258 }
1259 key = "item_number_limit";
1260 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1261 convert_to_long_ex( tmp ) ;
1262 pGroup -> setItemNumberLimit( (*tmp) -> value.lval );
1263 }
1264 key = "index_number_limit";
1265 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1266 convert_to_long_ex( tmp ) ;
1267 pGroup -> setIndexNumberLimit( (*tmp) -> value.lval );
1268 }
1269 key = "item_storage_limit";
1270 if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1271 convert_to_double_ex( tmp ) ;
1272 pGroup -> setItemStorageLimit( (*tmp) -> value.dval );
1273 }
1274 return RES_OK;
1275 }
1276
1277 /**
1278 *
1279 * session_t��������PHP��������������������
1280 *
1281 * @param pSession ��������session_t
1282 * @param z ��������������������������(��������������������)
1283 * @return RES_OK
1284 *
1285 */
1286 result_t sessionToZval( const session_t *pSession, zval *z )
1287 {
1288 string sessionID(unsignedIntToString(pSession->getSessionID()));
1289 add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
1290
1291 string date(unsignedIntToString((unsigned int)pSession->getDate()));
1292 add_assoc_string(z, "date", (char *)date.c_str(), 1);
1293
1294 string userID(unsignedIntToString((unsigned int)pSession->getUID()));
1295 add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
1296
1297 return RES_OK;
1298 }
1299
1300 /**
1301 *
1302 * index_t��������PHP����������������
1303 * @param pIndex ��������index_t*
1304 * @param z ����������������������(��������������������)
1305 * @return RES_OK
1306 *
1307 */
1308 result_t indexToZval( const index_t *pIndex, zval *z )
1309 {
1310 zend_hash_clean( z -> value.ht );
1311
1312 add_assoc_long( z, "item_id", pIndex -> getItemID( ) );
1313 add_assoc_long( z, "item_type_id", pIndex -> getItemTypeID( ) );
1314 add_assoc_long( z, "contributor_uid", pIndex -> getContributorUID( ) );
1315 add_assoc_string( z, "title", ( char* )pIndex -> getTitle( ), 1 );
1316 add_assoc_string( z, "keywords", ( char* )pIndex -> getKeywords( ), 1 );
1317 add_assoc_string( z, "description", ( char* )pIndex -> getDescription( ), 1 );
1318 add_assoc_long( z, "last_update_date", pIndex -> getLastUpdateDate( ) );
1319 add_assoc_long( z, "creation_date", pIndex-> getCreationDate( ) );
1320 add_assoc_long( z, "parent_index_id", pIndex -> getParentIndexID( ) );
1321 add_assoc_long( z, "owner_uid", pIndex -> getOwnerUID( ) );
1322 add_assoc_long( z, "owner_gid", pIndex -> getOwnerGID( ) );
1323 add_assoc_long( z, "open_level", pIndex -> getOpenLevel( ) );
1324 add_assoc_long( z, "sort_number", pIndex -> getSortNumber( ) );
1325 return RES_OK;
1326 }
1327
1328 result_t indexesToZval( const index_t *pIndexes, int indexesLen, zval *z )
1329 {
1330 zend_hash_clean( z -> value.ht );
1331 for( int i = 0; i < indexesLen; i++ ){
1332 zval *new_array;
1333 MAKE_STD_ZVAL(new_array);
1334 if(array_init(new_array) != SUCCESS){
1335 return RES_ERROR;
1336 }
1337 add_index_zval( z, i, new_array );
1338 indexToZval( &pIndexes[ i ], new_array );
1339 }
1340 return RES_OK;
1341 }
1342
1343 /**
1344 *
1345 * event_t��������PHP����������������
1346 * @param pevent ��������event_t*
1347 * @param z ����������������������(��������������������)
1348 * @return RES_OK
1349 *
1350 */
1351 result_t eventToZval( const event_t *pEvent, zval *z )
1352 {
1353 zend_hash_clean( z -> value.ht );
1354
1355 add_assoc_long ( z, "event_id" , pEvent -> getEventID() );
1356 add_assoc_long ( z, "event_type_id" , pEvent -> getEventTypeID() );
1357
1358 if ( pEvent->isValidTimestamp () ) add_assoc_long ( z, "timestamp" , pEvent -> getTimestamp() );
1359 if ( pEvent->isValidExecUID () ) add_assoc_long ( z, "exec_uid" , pEvent -> getExecUID() );
1360 if ( pEvent->isValidIndexID () ) add_assoc_long ( z, "index_id" , pEvent -> getIndexID() );
1361 if ( pEvent->isValidItemID () ) add_assoc_long ( z, "item_id" , pEvent -> getItemID() );
1362 if ( pEvent->isValidFileID () ) add_assoc_long ( z, "file_id" , pEvent -> getFileID() );
1363 if ( pEvent->isValidUID () ) add_assoc_long ( z, "uid" , pEvent -> getUID() );
1364 if ( pEvent->isValidGID () ) add_assoc_long ( z, "gid" , pEvent -> getGID() );
1365 if ( pEvent->isValidRemoteHost () ) add_assoc_string( z, "remote_host" , (char*)pEvent -> getRemoteHost() , 1 );
1366 if ( pEvent->isValidSearchKeyword () ) add_assoc_string( z, "search_keyword" , (char*)pEvent -> getSearchKeyword() , 1 );
1367 if ( pEvent->isValidAdditionalInfo() ) add_assoc_string( z, "additional_info", (char*)pEvent -> getAdditionalInfo(), 1 );
1368
1369 return RES_OK;
1370 }
1371
1372 result_t eventsToZval( const event_t *pevents, int eventsLen, zval *z )
1373 {
1374 zend_hash_clean( z -> value.ht );
1375 for( int i = 0; i < eventsLen; i++ ){
1376 zval *new_array;
1377 MAKE_STD_ZVAL(new_array);
1378 if(array_init(new_array) != SUCCESS){
1379 return RES_ERROR;
1380 }
1381 add_index_zval( z, i, new_array );
1382 eventToZval( &pevents[ i ], new_array );
1383 }
1384 return RES_OK;
1385 }
1386
1387
1388
1389
1390 /** ����������������������������<br>
1391 int xnp_get_group( int sid, int gid, array group );
1392 @param sid XNP������������ID
1393 @param gid XNP �� group_id
1394 @param group ������������������
1395 @return 0 success <br>
1396 */
1397 ZEND_FUNCTION(xnp_get_group)
1398 {
1399 long sid, gid;
1400 zval *zgroup;
1401
1402 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1403 &sid, &gid, &zgroup) == FAILURE) {
1404 return;
1405 }
1406
1407 const group_t *pgroup;
1408 result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
1409 if ( RES_OK == result ){
1410 groupToZval( pgroup, zgroup );
1411 freeGroup( pgroup );
1412 }
1413
1414 RETURN_LONG(result);
1415 }
1416
1417
1418 /** ����������������(����)������������<br>
1419 xnp_get_groups( int sid, array gids, array criteria, array groups );
1420 @param sid XNP������������ID
1421 @param gids XNP �� group_id ������
1422 @param criteria ����
1423 @param groups ������������������������
1424 @return 0 success <br>
1425 */
1426 ZEND_FUNCTION(xnp_get_groups)
1427 {
1428 result_t result;
1429 long sid;
1430 zval *zcriteria;
1431 zval *zgids;
1432 zval *zgroups;
1433 zval **ppzTmp = 0;
1434 HashPosition pos;
1435 int res2;
1436 int gidsLen;
1437 const group_t* groups;
1438 int groupsLen;
1439
1440 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1441 &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
1442 return;
1443 }
1444
1445 //gids����������ID������������
1446 gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
1447 groupid_t *gids = new groupid_t[ gidsLen ];
1448 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
1449 for( int i = 0; i < gidsLen; i++ ){
1450 if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
1451 SEPARATE_ZVAL(ppzTmp);
1452 convert_to_long_ex(ppzTmp);
1453 gids[ i ] = Z_LVAL_PP(ppzTmp);
1454 }
1455 zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
1456 }
1457
1458 zCriteria_t zcri(zcriteria);
1459 result = zcri.getResult();
1460 if ( RES_OK == result ){
1461 result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
1462 if ( RES_OK == result ){
1463 groupsToZval( groups, groupsLen, zgroups );
1464 delete[] gids;
1465 freeGroup( groups );
1466 }
1467 }
1468 RETURN_LONG(result);
1469 }
1470
1471
1472 /** ������������������������������������������<br>
1473 int xnp_is_moderator(int sid, int uid)
1474 @param sid XNP������������ID
1475 @param uid xoops �� uid (xoops_users.uid)
1476 @return true ���������������� <br>
1477 */
1478 ZEND_FUNCTION(xnp_is_moderator)
1479 {
1480 long xnpSessionID;
1481 userid_t uid;
1482
1483 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1484 &xnpSessionID, &uid) == FAILURE) {
1485 return;
1486 }
1487
1488 bool result = isModerator( (sessionid_t)xnpSessionID, uid );
1489 RETURN_BOOL(result)
1490 }
1491
1492 /** ������������uid��������<br>
1493 int xnp_get_uid(string uname,int &uid)
1494 @param sid XNP������������ID
1495 @param uname xoops �� uname (xoops_users.uname)
1496 @param uid xoops �� uid (xoops_users.uid) ��������������
1497 @return 0 success
1498 */
1499 ZEND_FUNCTION(xnp_get_uid)
1500 {
1501 char *uname;
1502 int unameLen;
1503 zval *zuid;
1504 userid_t uid;
1505
1506 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
1507 &uname, &unameLen, &zuid) == FAILURE) {
1508 return;
1509 }
1510
1511 if (!PZVAL_IS_REF(zuid)) {
1512 zend_error(E_WARNING, "2nd parameter wasn't passed by reference");
1513 RETURN_LONG(RES_PHP_NONREF);
1514 }
1515
1516 string strUname( uname, unameLen );
1517 result_t result = getUid( strUname.c_str(), &uid );
1518 ZVAL_LONG(zuid, (long)uid);
1519 RETURN_LONG((long)result);
1520 }
1521
1522 ZEND_FUNCTION(xnp_test_criteria)
1523 {
1524 zval *z;
1525
1526 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
1527 &z) == FAILURE) {
1528 return;
1529 }
1530 zend_printf("zend_printf...<br>\n");
1531 zCriteria_t zcri(z);
1532 zcri.dump();
1533 RETURN_FALSE
1534 }
1535
1536 ZEND_FUNCTION(xnp_test_uids)
1537 {
1538 zval *z;
1539
1540 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
1541 &z) == FAILURE) {
1542 return;
1543 }
1544 zend_printf("zend_printf...<br>\n");
1545 zUIDs_t zuids(z);
1546 zuids.dump();
1547 RETURN_FALSE
1548 }
1549
1550
1551
1552 /** DB������������������������������������������<br>
1553 int initialize_db( string host[, string user[, string password[, string dbname[, string prefix, int dbtype]]]] );
1554 @param host ����������������NULL
1555 @param user DB��������������������������NULL
1556 @param password DB����������������������������NULL
1557 @param dbname DB��������DB������������""
1558 @param prefix XOOPS DB ��prefix��
1559 @param dbtype 1=MySQL 2=SQLite��common.h����
1560 @return 0 success <br>
1561 */
1562 ZEND_FUNCTION(xnp_initialize_db)
1563 {
1564 zval **parameters[5];
1565 char *host;
1566 char *user;
1567 char *password;
1568 char *dbname;
1569 char *prefix;
1570 long dbtype;
1571
1572 /* get the number of arguments */
1573 int argNum = ZEND_NUM_ARGS();
1574 if (argNum > 5)
1575 WRONG_PARAM_COUNT;
1576
1577 /* argument count is correct, now retrieve arguments */
1578 if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
1579 WRONG_PARAM_COUNT;
1580
1581 if (argNum < 1) host = NULL;
1582 else host = getZvalString( parameters[0] );
1583
1584 if (argNum < 2) user = NULL;
1585 else user = getZvalString( parameters[1] );
1586
1587 if (argNum < 3) password = NULL;
1588 else password = getZvalString( parameters[2] );
1589
1590 if (argNum < 4) dbname = "";
1591 else dbname = getZvalString( parameters[3] );
1592
1593 if (argNum < 5) prefix = "";
1594 else prefix = getZvalString( parameters[4] );
1595
1596 if (argNum < 6) dbtype = DBTYPE_MYSQL;
1597 else dbtype = getZvalInt( parameters[5] );
1598
1599 result_t result = initializeDB( host, user, password, dbname, prefix, (dbtype_t)dbtype );
1600
1601 RETURN_LONG(result);
1602 }
1603
1604 /** ��������������<br>
1605 int xnp_login_user(string uname, string password, int &session_id)
1606 @param uname ��������(xoops_users.uname)
1607 @param password ����������(md5(password)=xoops_users.pass)
1608 @return 0 success
1609 */
1610 ZEND_FUNCTION(xnp_login_user)
1611 {
1612 char *uname;
1613 int unameLen;
1614 char *passwd;
1615 int passwdLen;
1616 zval *zXNPSessionID;
1617
1618 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",
1619 &uname, &unameLen, &passwd, &passwdLen, &zXNPSessionID) == FAILURE) {
1620 return;
1621 }
1622
1623 if (!PZVAL_IS_REF(zXNPSessionID)) {
1624 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1625 RETURN_LONG(RES_PHP_NONREF);
1626 }
1627
1628 sessionid_t xnpSessionID;
1629 result_t result = loginUser( uname, passwd, &xnpSessionID );
1630 if ( result == RES_OK )
1631 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1632 RETURN_LONG((long)result);
1633 }
1634
1635 /** ����������������<br>
1636 void xnp_logout_user(int xnp_session_id)
1637 @param xnp_session_id XNP������������ID
1638 @return ����
1639 */
1640 ZEND_FUNCTION(xnp_logout_user)
1641 {
1642 long xnpSessionID;
1643
1644 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &xnpSessionID) == FAILURE) {
1645 return;
1646 }
1647 logoutUser( (sessionid_t)xnpSessionID );
1648
1649 RETURN_NULL();
1650 }
1651
1652 /** XNP������������ID ����<br>
1653 int xnp_create_session( string xoops_sess_id, int uid, int &session )
1654 @param xoops_sess_id xoops������������ID
1655 @param uid xoops �� uid (xoops_users.uid)
1656 @param session ��������XNP��session��������������
1657 @return 0 ����
1658 */
1659 ZEND_FUNCTION(xnp_create_session)
1660 {
1661 char *xoopsSessionID;
1662 int xoopsSessionIDLen;
1663 long uid;
1664 zval *zXNPSessionID;
1665
1666 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz",
1667 &xoopsSessionID, &xoopsSessionIDLen, &uid, &zXNPSessionID) == FAILURE) {
1668 return;
1669 }
1670
1671 if (!PZVAL_IS_REF(zXNPSessionID)) {
1672 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1673 RETURN_LONG(RES_PHP_NONREF);
1674 }
1675
1676 sessionid_t xnpSessionID = 0;
1677 result_t result = createSession( xoopsSessionID, (userid_t)uid, &xnpSessionID );
1678 if ( result == RES_OK )
1679 ZVAL_LONG(zXNPSessionID, (long)xnpSessionID);
1680 RETURN_LONG((long)result);
1681 }
1682
1683 /** XNP �� session ����������������<br>
1684 int xnp_get_session( int xnp_session_id, array session_info )
1685 @param xnp_session_id XNP������������ID
1686 @param session_info ������������������
1687 @return 0 success
1688 */
1689 ZEND_FUNCTION(xnp_get_session)
1690 {
1691 long xnpSessionID;
1692 zval *sessionInfo;
1693 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1694 &xnpSessionID, &sessionInfo) == FAILURE) {
1695 return;
1696 }
1697 const session_t *session = 0;
1698 result_t result = getSession( (sessionid_t)xnpSessionID, &session );
1699 if ( result == RES_OK ){
1700 sessionToZval( session, sessionInfo );
1701 freeSession( session );
1702 }
1703
1704 RETURN_LONG((long)result);
1705 }
1706
1707 /** ��������activate��������������<br>
1708 bool xnp_is_activated( int xnp_session_id, int user_id )
1709 @param xnp_session_id XNP������������ID
1710 @param user_id xoops_users.uid
1711 @return 0 success
1712 */
1713 ZEND_FUNCTION(xnp_is_activated)
1714 {
1715 long sid, uid;
1716
1717 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
1718 return;
1719 }
1720
1721 bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
1722
1723 RETURN_BOOL(result);
1724 }
1725
1726 /** activate������<br>
1727 bool xnp_activate( int xnp_session_id, int user_id, bool activated )
1728 @param xnp_session_id xnp �� session id
1729 @param user_id xoops_users.uid
1730 @param activated true:activate, false:inactivate
1731 @return 0 success
1732 */
1733 ZEND_FUNCTION(xnp_activate)
1734 {
1735 long sid, uid;
1736 bool activated;
1737
1738 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
1739 &sid, &uid, &activated) == FAILURE) {
1740 return;
1741 }
1742
1743 result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
1744
1745 RETURN_LONG(result);
1746 }
1747
1748 /** XNP����������������������<br>
1749 int xnp_get_account_count( int xnp_session_id )
1750 @param xnp_session_id XNP������������ID
1751 @return 0 success
1752 */
1753 ZEND_FUNCTION(xnp_get_account_count)
1754 {
1755 long sid;
1756
1757 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1758 &sid) == FAILURE) {
1759 return;
1760 }
1761
1762 long count = getAccountCount( (sessionid_t)sid );
1763 RETURN_LONG(count);
1764 }
1765
1766 /** ����������������������<br>
1767 bool xnp_delete_account( int xnp_session_id, int user_id )
1768 @param xnp_session_id XNP������������ID
1769 @param user_id xoops_users.uid
1770 @return 0 success
1771 */
1772 ZEND_FUNCTION(xnp_delete_account)
1773 {
1774 long sid, uid;
1775
1776 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1777 &sid, &uid) == FAILURE) {
1778 return;
1779 }
1780
1781 result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
1782
1783 RETURN_LONG(result);
1784 }
1785
1786 /** ����������������������<br>
1787 int xnp_get_account( int xnp_session_id, int user_id, array account_info )
1788 @param xnp_session_id XNP������������ID
1789 @param user_id xoops_users.uid
1790 @param account_info ��������������������������������
1791 @return 0 success
1792 */
1793 ZEND_FUNCTION(xnp_get_account)
1794 {
1795 long sid, uid;
1796 zval *zaccount;
1797
1798 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1799 &sid, &uid, &zaccount) == FAILURE) {
1800 fprintf( stderr, "error occured " );
1801 return;
1802 }
1803
1804 const account_t *paccount;
1805 result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
1806 if ( RES_OK == result ){
1807 accountToZval( paccount, zaccount );
1808 freeAccount( paccount );
1809 }
1810
1811 RETURN_LONG(result);
1812 }
1813
1814 /** ��������������������������������������<br>
1815 int xnp_get_accoutns( int sid, array uids, array criteria, array accounts );
1816 @param xnp_session_id XNP������������ID
1817 @param user_id xoops_users.uid
1818 @param criteria ����������������������������
1819 @param account_info ��������������������������������
1820 @return 0 success
1821 */
1822 ZEND_FUNCTION(xnp_get_accounts)
1823 {
1824 result_t result;
1825 long sid;
1826 zval *zuids;
1827 zval *zcriteria;
1828 zval *zaccount;
1829
1830 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1831 &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
1832 return;
1833 }
1834
1835 zCriteria_t zcri(zcriteria);
1836 result = zcri.getResult();
1837 if ( RES_OK == result ){
1838 zUIDs_t zUIDs(zuids);
1839 result = zUIDs.getResult();
1840 if ( RES_OK == result ){
1841 const account_t *paccounts;
1842 int accountLen;
1843 result = getAccounts( (sessionid_t)sid,
1844 zUIDs.getPUID(), zUIDs.getLen(),
1845 &zcri, &paccounts, &accountLen );
1846 if ( RES_OK == result ){
1847 accountsToZval( paccounts, accountLen, zaccount );
1848 freeAccount( paccounts );
1849 }
1850 }
1851 }
1852
1853 RETURN_LONG(result);
1854 }
1855
1856 /** ��������������������������<br>
1857 int xnp_insert_account( int sid, array account_info, int &user_id );
1858 @param xnp_session_id xnp �� session id
1859 @param account_info ��������������������������
1860 @param user_id ������ID(xoops_users.uid)����������������������
1861 @return 0 success
1862 */
1863 ZEND_FUNCTION(xnp_insert_account)
1864 {
1865 result_t result;
1866 long sid;
1867 zval *zaccount;
1868 zval *zuid;
1869 userid_t uid;
1870
1871 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1872 &sid, &zaccount, &zuid) == FAILURE) {
1873 return;
1874 }
1875
1876 zAccount_t zacc(zaccount);
1877 result = zacc.getResult();
1878 if ( RES_OK == result ){
1879 result = insertAccount( (sessionid_t)sid, &zacc, &uid );
1880 }
1881 zuid -> type = IS_LONG;
1882 zuid -> value.lval = uid;
1883 RETURN_LONG(result);
1884 }
1885
1886 /** ��������������������������<br>
1887 int xnp_update_account( int sid, array account );
1888 @param xnp_session_id XNP������������ID
1889 @param account_info ����������������������������������������
1890 @return 0 success
1891 */
1892 ZEND_FUNCTION(xnp_update_account)
1893 {
1894 result_t result;
1895 long sid;
1896 zval *zaccount;
1897
1898 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1899 &sid, &zaccount) == FAILURE) {
1900 return;
1901 }
1902
1903 zAccount_t zacc(zaccount);
1904 result = zacc.getResult();
1905 if ( RES_OK == result ){
1906 result = updateAccount( (sessionid_t)sid, &zacc );
1907 }
1908
1909 RETURN_LONG(result);
1910 }
1911
1912 /** ����������������������uid��������������<br>
1913 int xnp_dump_uids( int xnp_session_id, array criteria, array uids );
1914 @param xnp_session_id XNP������������ID
1915 @param criteria ����������������������������
1916 @param uids uid��������������
1917 @return 0 success
1918 */
1919 ZEND_FUNCTION(xnp_dump_uids)
1920 {
1921 result_t result;
1922 long sid;
1923 zval *zcriteria;
1924 zval *zuids;
1925
1926 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1927 &sid, &zcriteria, &zuids) == FAILURE) {
1928 return;
1929 }
1930
1931 zCriteria_t zcri(zcriteria);
1932 result = zcri.getResult();
1933 if ( RES_OK == result ){
1934 userid_t *puid;
1935 int uidLen;
1936 result = dumpUids( (sessionid_t)sid, &zcri, &puid, &uidLen );
1937 if ( RES_OK == result ){
1938 uidsToZval( puid, uidLen, &zuids );
1939 freeUID( puid );
1940 }
1941 }
1942
1943 RETURN_LONG(result);
1944 }
1945
1946 /** XNP��������������������<br>
1947 int xnp_get_group_count( int xnp_session_id );
1948 @param xnp_session_id XNP������������ID
1949 @return ����������
1950 */
1951 ZEND_FUNCTION(xnp_get_group_count)
1952 {
1953 long sid;
1954
1955 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1956 &sid) == FAILURE) {
1957 return;
1958 }
1959
1960 int count = getGroupCount( (sessionid_t)sid );
1961
1962 RETURN_LONG(count);
1963 }
1964
1965 /** uid��������������������������������������������������������������gid������<br>
1966 int xnp_get_group_by_uid( int xnp_session_id, int uid, array criteria, array gids );
1967 @param xnp_session_id XNP������������ID
1968 @param user_id xoops_users.uid
1969 @param criteria ����������������������������
1970 @param gids gid��������������
1971 @return 0 success
1972 */
1973 ZEND_FUNCTION(xnp_get_groups_by_uid)
1974 {
1975 result_t result;
1976 long sid, uid;
1977 zval *zcriteria;
1978 zval *zgids;
1979
1980 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1981 &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1982 return;
1983 }
1984
1985 zCriteria_t zcri(zcriteria);
1986 result = zcri.getResult();
1987 if ( RES_OK == result ){
1988 groupid_t *pgids;
1989 int gidLen;
1990 result = getGroupsByUid( (sessionid_t)sid, (userid_t)uid, &zcri, &pgids, &gidLen );
1991 if ( RES_OK == result ){
1992 gidsToZval( pgids, gidLen, &zgids );
1993 freeGID( pgids );
1994 }
1995 }
1996
1997 RETURN_LONG(result);
1998 }
1999
2000
2001
2002 /** uid������������������gid������������������������������������������������<br>
2003 int xnp_is_group_admin( int sid, int gid, int uid );
2004 @param xnp_session_id XNP������������ID
2005 @param group_id XNP����������ID
2006 @param user_id xoops_users.uid
2007 @return true: ����������������������
2008 @return false: ��������������������������������������������
2009 */
2010 ZEND_FUNCTION(xnp_is_group_admin)
2011 {
2012 long sid, gid, uid;
2013
2014 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2015 &sid, &gid, &uid) == FAILURE) {
2016 return;
2017 }
2018
2019 bool b = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
2020
2021 RETURN_BOOL(b);
2022 }
2023
2024 /** ������������������������gid��������������<br>
2025 int xnp_dump_gids( int sid, array criteria, array gids );
2026 @param xnp_session_id XNP������������ID
2027 @param criteria ����������������������������
2028 @param gids gid��������������
2029 @return 0 success
2030 */
2031 ZEND_FUNCTION(xnp_dump_gids)
2032 {
2033 result_t result;
2034 long sid;
2035 zval *zcriteria;
2036 zval *zgids;
2037
2038 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
2039 &sid, &zcriteria, &zgids) == FAILURE) {
2040 return;
2041 }
2042
2043 zCriteria_t zcri(zcriteria);
2044 result = zcri.getResult();
2045 if ( RES_OK == result ){
2046 groupid_t *pgid;
2047 int gidLen;
2048 result = dumpGids( (sessionid_t)sid, &zcri, &pgid, &gidLen );
2049 if ( RES_OK == result ){
2050 gidsToZval( pgid, gidLen, &zgids );
2051 freeGID( pgid );
2052 }
2053 }
2054
2055 RETURN_LONG(result);
2056 }
2057
2058 /** gid����������������������������������������������������������������uid��������������<br>
2059 int xnp_dump_group_admins(int sid, int group_id, array criteria, array uids )
2060 @param sid XNP������������ID
2061 @param group_id XNP����������ID
2062 @param criteria ����
2063 @param uids uid��������������������
2064 @return 0 success
2065 */
2066
2067 ZEND_FUNCTION(xnp_dump_group_admins)
2068 {
2069 long sid, gid;
2070 zval *zcriteria;
2071 zval *zuids;
2072
2073 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2074 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
2075 return;
2076 }
2077
2078 zCriteria_t zcri(zcriteria);
2079 result_t result = zcri.getResult();
2080 if ( result == RES_OK ){
2081 userid_t *uids;
2082 int uidsLen;
2083 result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
2084 if ( result == RES_OK ){
2085 uidsToZval( uids, uidsLen, &zuids );
2086 freeUID( uids );
2087 }
2088 }
2089 RETURN_LONG( result );
2090 }
2091
2092 /** ��������������������������������<br>
2093 int xnp_delete_member(int sid, int group_id, int user_id )
2094 @param sid XNP������������ID
2095 @param group_id XNP����������ID
2096 @param user_id ������ID
2097 @return 0 success
2098 */
2099
2100 ZEND_FUNCTION(xnp_delete_member)
2101 {
2102 long sid, gid, uid;
2103
2104 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2105 &sid, &gid, &uid) == FAILURE) {
2106 return;
2107 }
2108
2109 result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
2110 RETURN_LONG( result );
2111 }
2112
2113 /** ����������������������������<br>
2114 int xnp_insert_member(int sid, int group_id, int user_id, bool admin )
2115 @param sid XNP������������ID
2116 @param group_id XNP����������ID
2117 @param user_id ������ID
2118 @param admin ������������������true
2119 @return 0 success
2120 */
2121
2122 ZEND_FUNCTION(xnp_insert_member)
2123 {
2124 long sid, gid, uid;
2125 zend_bool admin;
2126
2127 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
2128 &sid, &gid, &uid, &admin) == FAILURE) {
2129 return;
2130 }
2131
2132 result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
2133 RETURN_LONG( result );
2134 }
2135
2136 /** gid������������������������������uid������������<br>
2137 int xnp_get_members(int sid, int group_id, array criteria, array uids )
2138 @param sid XNP������������ID
2139 @param group_id XNP����������ID
2140 @param criteria ����
2141 @param uids uid��������������������
2142 @return 0 success
2143 */
2144
2145 ZEND_FUNCTION(xnp_get_members)
2146 {
2147 long sid, gid;
2148 zval *zcriteria;
2149 zval *zuids;
2150
2151 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2152 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
2153 return;
2154 }
2155
2156 zCriteria_t zcri(zcriteria);
2157 result_t result = zcri.getResult();
2158 if ( result == RES_OK ){
2159 userid_t *uids;
2160 int uidsLen;
2161 result = getMembers( (sessionid_t)sid, (groupid_t)gid, &zcri, &uids, &uidsLen );
2162 if ( result == RES_OK ){
2163 uidsToZval( uids, uidsLen, &zuids );
2164 freeUID( uids );
2165 }
2166 }
2167 RETURN_LONG( result );
2168 }
2169
2170 /** ������������������������<br>
2171 int xnp_update_group(int sid, array group )
2172 @param sid XNP������������ID
2173 @param group ����������������������
2174 @return 0 success
2175 */
2176 ZEND_FUNCTION(xnp_update_group)
2177 {
2178 long sid;
2179 zval *zgroup;
2180 group_t group;
2181
2182 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
2183 &sid, &zgroup) == FAILURE) {
2184 return;
2185 }
2186
2187 zvalToGroup( zgroup, &group );
2188 result_t result = updateGroup( sid, &group );
2189 RETURN_LONG( result );
2190 }
2191
2192 /** ������������������������<br>
2193 int xnp_insert_group( int sid, array group, int &gid )
2194 @param sid ����������ID
2195 @param group ����������������������
2196 @param gid ����������������ID����������������������
2197 @return RES_OK
2198 @return RES_DB_NOT_INITIALIZED
2199 @return RES_NO_SUCH_SESSION
2200 @return RES_DB_QUERY_ERROR
2201 */
2202 ZEND_FUNCTION(xnp_insert_group)
2203 {
2204 long sid;
2205 zval *zgroup;
2206 zval *zgid;
2207 group_t group;
2208 groupid_t gid;
2209
2210 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2211 &sid, &zgroup, &zgid ) == FAILURE) {
2212 return;
2213 }
2214
2215 zvalToGroup( zgroup, &group );
2216 result_t result = insertGroup( sid, &group, &gid );
2217 zgid -> type = IS_LONG;
2218 zgid -> value.lval = gid;
2219 RETURN_LONG( result );
2220 }
2221
2222
2223 /** ������������������������<br>
2224 int xnp_delete_group( int sid, int gid )
2225 @param sid XNP������������ID
2226 @param gid ��������������������ID
2227 @return RES_OK
2228 @return RES_DB_QUERY_ERROR
2229 @return RES_NO_SUCH_SESSION
2230 @return RES_DB_NOT_INITIALIZED
2231 */
2232 ZEND_FUNCTION(xnp_delete_group)
2233 {
2234 long sid;
2235 long gid;
2236
2237 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2238 &sid, &gid) == FAILURE) {
2239 return;
2240 }
2241 RETURN_LONG( deleteGroup( sid, gid ) );
2242 }
2243
2244 /** ������������������������<br>
2245 int xnp_dump_group_admins( int sid, int gid, array criteria, array uids )
2246 @param sid XNP������������ID
2247 @param gid XNP����������ID
2248 @param criteria uids��������������������������������������
2249 @param uids ��������UID��������������
2250 @return RES_OK
2251 @return RES_DB_QUERY_ERROR
2252 @return RES_NO_SUCH_SESSION
2253 @return RES_DB_NOT_INITIALIZED
2254 */
2255 /*
2256 ZEND_FUNCTION(xnp_dump_group_admins)
2257 {
2258 long sid;
2259 long gid;
2260 zval *zcriteria;
2261 zval *zuids;
2262
2263 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2264 &sid, &gid, &zcriteria, &zuids) == FAILURE) {
2265 return;
2266 }
2267 zCriteria_t zcri(zcriteria);
2268 result_t result = zcri.getResult();
2269 if ( RES_OK == result ){
2270 userid_t* uids;
2271 int uidsLen;
2272 result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
2273 if( result != RES_OK ) RETURN_LONG( result );
2274 uidsToZval( uids, uidsLen, &zuids );
2275 fprintf( stderr, "uidsLen=%d\n", uidsLen );
2276 for( int i = 0; i < uidsLen; i++ ){
2277 fprintf( stderr, "%d, \n", uids[ i ] );
2278 }
2279 freeUID( uids );
2280 RETURN_LONG( result );
2281 }
2282 RETURN_LONG( result );
2283 }
2284 */
2285
2286 /** ������������������������<br>
2287 * int xnp_get_all_indexes( int sid, array criteria, array indexes );
2288 * @param sid XNP������������ID
2289 * @param cri ������������������������������
2290 * @return RES_OK
2291 */
2292 ZEND_FUNCTION(xnp_get_all_indexes)
2293 {
2294 long sid;
2295 zval *zcriteria;
2296 zval *zindexes;
2297
2298 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
2299 &sid, &zcriteria, &zindexes) == FAILURE) {
2300 return;
2301 }
2302 zCriteria_t zcri(zcriteria);
2303 result_t result = zcri.getResult();
2304 if ( RES_OK == result ){
2305 const index_t *indexes;
2306 int indexesLen;
2307 result = getAllIndexes( sid, &zcri, &indexes, &indexesLen );
2308 if ( RES_OK == result ){
2309 result = indexesToZval( indexes, indexesLen, zindexes );
2310 freeIndex( indexes );
2311 }
2312 }
2313 RETURN_LONG(result);
2314 }
2315
2316 /** ��������������������������������������������<br>
2317 * int xnp_get_indexes( int sid, int parentXID, array criteria, array indexes );
2318 * @param sid XNP������������ID
2319 * @param parentXID ����indexID
2320 * @param cri ������������������������������
2321 * @param indexes ������������������
2322 * @return RES_OK
2323 */
2324 ZEND_FUNCTION(xnp_get_indexes)
2325 {
2326 long sid;
2327 long parentXID;
2328 zval *zcriteria;
2329 zval *zindexes;
2330
2331 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2332 &sid, &parentXID, &zcriteria, &zindexes) == FAILURE) {
2333 return;
2334 }
2335 zCriteria_t zcri(zcriteria);
2336 result_t result = zcri.getResult();
2337 if ( RES_OK == result ){
2338 const index_t *indexes;
2339 int indexesLen;
2340 result = getIndexes( sid, parentXID, &zcri, &indexes, &indexesLen );
2341 if ( RES_OK == result ){
2342 result = indexesToZval( indexes, indexesLen, zindexes );
2343 freeIndex( indexes );
2344 }
2345 }
2346 RETURN_LONG(result);
2347 }
2348
2349
2350 /** ����������������������<br>
2351 * int xnp_insert_index( int sid, array index, int &indexID );
2352 * @param sid XNP������������ID
2353 * @param index ��������������������
2354 * @param indexID ������������������������ID��������������
2355 * @return RES_OK
2356 */
2357 ZEND_FUNCTION(xnp_insert_index)
2358 {
2359 long sid;
2360 zval *zindex;
2361 zval *zIndexID;
2362
2363 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2364 &sid, &zindex, &zIndexID) == FAILURE) {
2365 return;
2366 }
2367
2368 if (!PZVAL_IS_REF(zIndexID)) {
2369 zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
2370 RETURN_LONG(RES_PHP_NONREF);
2371 }
2372 zIndex_t index( zindex );
2373 indexid_t xid;
2374 result_t result = insertIndex( sid, &index, &xid );
2375 if ( RES_OK == result )
2376 ZVAL_LONG(zIndexID, (long)xid);
2377 RETURN_LONG(result);
2378 }
2379
2380 /** ����������������������<br>
2381 * int xnp_update_index( int sid, array index );
2382 * @param sid XNP������������ID
2383 * @param index ��������������������
2384 * @return RES_OK
2385 */
2386 ZEND_FUNCTION(xnp_update_index)
2387 {
2388 long sid;
2389 zval *zindex;
2390
2391 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
2392 &sid, &zindex) == FAILURE) {
2393 return;
2394 }
2395 zIndex_t index(zindex);
2396 result_t result = index.getResult();
2397 if ( RES_OK == result ){
2398 result = updateIndex( sid, &index );
2399 }
2400 RETURN_LONG(result);
2401 }
2402
2403 /** ����������������������<br>
2404 * int xnp_delete_index( int sid, int indexID );
2405 * @param sid XNP������������ID
2406 * @param indexID ��������������������
2407 * @return RES_OK
2408 */
2409 ZEND_FUNCTION(xnp_delete_index)
2410 {
2411 long sid;
2412 long xid;
2413
2414 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2415 &sid, &xid) == FAILURE) {
2416 return;
2417 }
2418
2419 result_t result = deleteIndex( sid, xid );
2420 RETURN_LONG(result);
2421 }
2422
2423
2424 /** ����������������������<br>
2425 * int xnp_get_index( int sid, int indexID, array index );
2426 * @param sid XNP������������ID
2427 * @param indexID ����������������������ID
2428 * @param index ��������������������������
2429 * @return RES_OK
2430 */
2431 ZEND_FUNCTION(xnp_get_index)
2432 {
2433 long sid;
2434 long xid;
2435 zval *zindex;
2436
2437 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
2438 &sid, &xid, &zindex) == FAILURE) {
2439 return;
2440 }
2441
2442 const index_t *index;
2443 result_t result = getIndex( sid, xid, &index );
2444 if ( RES_OK == result ){
2445 result = indexToZval( index, zindex );
2446 freeIndex( index );
2447 }
2448 RETURN_LONG(result);
2449 }
2450
2451
2452
2453 /** ������������������������������������������<br>
2454 * int xnp_is_index_readable( int sid, int indexID );
2455 * @param sid XNP������������ID
2456 * @param indexID ������������������ID
2457 * @return true false
2458 */
2459 ZEND_FUNCTION(xnp_is_index_readable)
2460 {
2461 long sid;
2462 long xid;
2463
2464 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2465 &sid, &xid) == FAILURE) {
2466 return;
2467 }
2468 RETURN_BOOL(isIndexReadable(sid,xid));
2469 }
2470
2471
2472 /** ������������������������������������������<br>
2473 * int xnp_is_index_writable( int sid, int indexID );
2474 * @param sid XNP������������ID
2475 * @param indexID ������������������ID
2476 * @return true false
2477 */
2478 ZEND_FUNCTION(xnp_is_index_writable)
2479 {
2480 long sid;
2481 long xid;
2482
2483 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2484 &sid, &xid) == FAILURE) {
2485 return;
2486 }
2487 RETURN_BOOL(isIndexWritable(sid,xid));
2488 }
2489
2490 /** ������������������������������<br>
2491 * int xnp_swap_index_sort_number( int sid, int indexID1, int indexID2 );
2492 * @param sid XNP������������ID
2493 * @param indexID1 ������������������ID
2494 * @param indexID2 ������������������ID
2495 * @return true false
2496 */
2497 ZEND_FUNCTION(xnp_swap_index_sort_number)
2498 {
2499 long sid;
2500 long xid1, xid2;
2501
2502 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2503 &sid, &xid1, &xid2) == FAILURE) {
2504 return;
2505 }
2506
2507 result_t result = swapIndexSortNumber( sid, xid1, xid2 );
2508 RETURN_LONG(result);
2509 }
2510
2511
2512
2513 /** XNP��session_id����������������<br>
2514 bool xnp_is_valid_session_id( int xnp_session_id)
2515 @return true ������XNP��session_id������<br>
2516 @return false ������session_id������������
2517 */
2518 ZEND_FUNCTION(xnp_is_valid_session_id)
2519 {
2520 long sid;
2521 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
2522 return;
2523 }
2524
2525 RETURN_BOOL(isValidSessionID((sessionid_t)sid));
2526 }
2527
2528 /** ������������������<br>
2529 string xnp_get_last_error_string()
2530 @return 0 success
2531 */
2532 ZEND_FUNCTION(xnp_get_last_error_string)
2533 {
2534 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
2535 return;
2536 }
2537
2538 string str( getLastErrorString() );
2539 RETURN_STRING((char *)str.c_str(), 1);
2540 }
2541
2542
2543 /**
2544 *
2545 * ��������������������������������������
2546 *
2547 * @refer itemop_t
2548 * @param sid ����������ID
2549 * @param iid ����������������������������ID
2550 * @param op ��������������
2551 * @return true ��������
2552 * @return false ��������
2553 *
2554 */
2555 ZEND_FUNCTION(xnp_get_item_permission)
2556 {
2557 long sid;
2558 itemid_t iid;
2559 long op;
2560
2561 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2562 &sid, &iid, &op) == FAILURE) {
2563 fprintf( stderr, "error occured " );
2564 return;
2565 }
2566 RETURN_BOOL( getItemPermission( (sessionid_t)sid, iid, op ) );
2567 }
2568
2569
2570 /**
2571 *
2572 * ������������������������������������������
2573 *
2574 * @refer indexop_t
2575 * @param sid ����������ID
2576 * @param xid ��������������������������������ID
2577 * @param op ��������������
2578 * @return true ��������
2579 * @return false ��������
2580 *
2581 */
2582 ZEND_FUNCTION(xnp_get_index_permission)
2583 {
2584 long sid;
2585 indexid_t xid;
2586 long op;
2587
2588 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2589 &sid, &xid, &op) == FAILURE) {
2590 fprintf( stderr, "error occured " );
2591 return;
2592 }
2593 RETURN_BOOL( getIndexPermission( (sessionid_t)sid, xid, op ) );
2594 }
2595
2596
2597 /**
2598 *
2599 * ��������������������������������������������������
2600 * @refer certify_t
2601 * @param sid ����������ID
2602 * @param xid ����������������������������������������������ID
2603 * @param iid ������������������ID
2604 * @param state ������������������������
2605 * @return true ��������
2606 * @return false ��������
2607 *
2608 */
2609 ZEND_FUNCTION(xnp_get_certify_permission)
2610 {
2611 long sid;
2612 itemid_t iid;
2613 indexid_t xid;
2614 certify_t state;
2615
2616 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll",
2617 &sid, &xid, &iid, &state) == FAILURE) {
2618 fprintf( stderr, "error occured " );
2619 return;
2620 }
2621 RETURN_BOOL( getCertifyPermission( (sessionid_t)sid, xid, iid, state ) );
2622 }
2623
2624
2625 /**
2626 *
2627 * ��������������������������������
2628 * @refer certify_t
2629 * @param sid ����������ID
2630 * @param xid ������������������������������������������ID
2631 * @param iid ��������������ID
2632 * @param state ����������������������
2633 * @return RES_OK
2634 * @return RES_NO_WRITE_ACCESS_RIGHT
2635 *
2636 */
2637 ZEND_FUNCTION(xnp_get_certify_state)
2638 {
2639 long sid;
2640 indexid_t xid;
2641 itemid_t iid;
2642 zval *zstate;
2643 result_t result = RES_ERROR;
2644
2645 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllz",
2646 &sid, &xid, &iid, &zstate) == FAILURE) {
2647 fprintf( stderr, "error occured " );
2648 return;
2649 }
2650 certify_t st;
2651 result = getCertifyState( (sessionid_t)sid, xid, iid, &st );
2652 if ( RES_OK == result ){
2653 zstate -> type = IS_LONG;
2654 zstate -> value.lval = st;
2655 }
2656 RETURN_LONG( result );
2657 }
2658
2659
2660 /**
2661 *
2662 * ��������������������������������
2663 * @refer certify_t
2664 * @param sid ����������ID
2665 * @param xid ����������������������������������������������ID
2666 * @param iid ������������������ID
2667 * @param state ������������������������
2668 * @return RES_OK
2669 * @return RES_NO_WRITE_ACCESS_RIGHT
2670 *
2671 */
2672 ZEND_FUNCTION(xnp_set_certify_state)
2673 {
2674 long sid;
2675 indexid_t xid;
2676 itemid_t iid;
2677 certify_t state;
2678 result_t result = RES_ERROR;
2679
2680 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll",
2681 &sid, &xid, &iid, &state) == FAILURE) {
2682 fprintf( stderr, "error occured " );
2683 return;
2684 }
2685 result = setCertifyState( (sessionid_t)sid, xid, iid, state );
2686 RETURN_LONG( result );
2687 }
2688
2689
2690 /**
2691 *
2692 * ������������������������
2693 *
2694 * @param sid ����������ID
2695 * @param itemid ����������������������������ID
2696 * @param log ��������
2697 * @return RES_OK
2698 * @return RES_NO_SUCH_SESSION
2699 * @return RES_DB_QUERY_ERROR
2700 * @return RES_NO_WRITE_ACCESS_RIGHT
2701 * @return RES_DB_NOT_INITIALIZED
2702 * @return RES_ERROR
2703 *
2704 */
2705 ZEND_FUNCTION(xnp_insert_change_log)
2706 {
2707 long sid;
2708 itemid_t iid;
2709 zval *zlog;
2710 result_t result = RES_ERROR;
2711
2712 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llz",
2713 &sid, &iid, &zlog) == FAILURE) {
2714 fprintf( stderr, "error occured " );
2715 return;
2716 }
2717
2718 result = insertChangeLog( sid, iid, getZvalString( &zlog ) );
2719 RETURN_LONG( result );
2720 }
2721
2722
2723 /**
2724 *
2725 * ����������������������������������
2726 *
2727 * @param sid ����������ID
2728 * @param itemid ����������������������������ID
2729 * @param logs ��������������������������
2730 * @param logsLen logs����������������������
2731 * @return RES_OK
2732 * @return RES_NO_SUCH_SESSION
2733 * @return RES_NO_READ_ACCESS_RIGHT
2734 * @return RES_DB_NOT_INITIALIZED
2735 * @return RES_ERROR
2736 *
2737 */
2738 ZEND_FUNCTION(xnp_get_change_logs)
2739 {
2740 result_t result;
2741 long sid;
2742 itemid_t iid;
2743 zval *zlogs;
2744
2745 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
2746 &sid, &iid, &zlogs) == FAILURE) {
2747 return;
2748 }
2749
2750 const changelog_t *plogs;
2751 int logLen;
2752 result = getChangeLogs( (sessionid_t)sid, iid, &plogs, &logLen );
2753 if ( RES_OK == result ){
2754 zend_hash_clean( zlogs -> value.ht );
2755 for( int i = 0; i < logLen; i++ ){
2756 zval *new_array;
2757 MAKE_STD_ZVAL(new_array);
2758 if(array_init(new_array) != SUCCESS){
2759 result = RES_ERROR;
2760 break;
2761 }
2762 add_index_zval( zlogs, i, new_array );
2763 changelogToZval( &plogs[ i ], new_array );
2764 }
2765 freeChangeLog( plogs );
2766 }
2767 RETURN_LONG(result);
2768 }
2769
2770
2771 /**
2772 *
2773 * ������key��������������vaule������������
2774 * value����������freeString������������
2775 * @param key ����������
2776 * @param value ������������������������
2777 *
2778 * @return RES_OK
2779 * @return RES_DB_QUERY_ERROR
2780 * @return RES_ERROR
2781 */
2782 ZEND_FUNCTION(xnp_get_config_value)
2783 {
2784 char* name;
2785 int nameLen;
2786 zval* zvalue;
2787 char* value = 0;
2788
2789 result_t result = RES_ERROR;
2790
2791 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
2792 &name, &nameLen, &zvalue ) == FAILURE) {
2793 return;
2794 }
2795
2796 result = getConfigValue( name, &value );
2797 if( result == RES_OK ){
2798 ZVAL_STRING( zvalue, value, true/*duplicate*/ );
2799 }
2800 if ( value != 0 )
2801 freeString( value );
2802 RETURN_LONG( result );
2803 }
2804
2805
2806 /**
2807 *
2808 * ������key������vaule����������
2809 *
2810 * @param key ����������
2811 * @param value ������
2812 *
2813 * @return RES_OK
2814 * @return RES_DB_QUERY_ERROR
2815 * @return RES_ERROR
2816 */
2817 ZEND_FUNCTION(xnp_set_config_value)
2818 {
2819 char *name;
2820 int nameLen;
2821 char *value;
2822 int valueLen;
2823 result_t result = RES_ERROR;
2824 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
2825 &name, &nameLen, &value, &valueLen ) == FAILURE) {
2826 return;
2827 }
2828 result = setConfigValue( name, value );
2829 RETURN_LONG( result );
2830 }
2831
2832
2833 /**
2834 *
2835 * ��������ID����������.
2836 * ������������������������ID������.
2837 *
2838 * int xnp_dump_item_id( int sid, array cri, array iids )
2839 * @param sid ����������ID
2840 * @param cri ������������������������������
2841 * @param iids ����������������������
2842 * @return RES_OK
2843 * @return RES_DB_NOT_INITIALIZED
2844 * @return RES_NO_SUCH_SESSION
2845 * @return RES_DB_QUERY_ERROR
2846 *
2847 */
2848 ZEND_FUNCTION(xnp_dump_item_id)
2849 {
2850 long sid;
2851 zval *zcriteria;
2852 zval *ziids;
2853 result_t result = RES_ERROR;
2854
2855 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
2856 &sid, &zcriteria, &ziids) == FAILURE) {
2857 fprintf( stderr, "error occured " );
2858 return;
2859 }
2860
2861 zCriteria_t zcri(zcriteria);
2862 result = zcri.getResult();
2863 if ( RES_OK == result ){
2864 const itemid_t *piids;
2865 int iidsLen;
2866 result = dumpItemID( (sessionid_t)sid, &zcri, &piids, &iidsLen );
2867 if ( RES_OK == result ){
2868 itemidsToZval( piids, iidsLen, &ziids );
2869 freeItemID( piids );
2870 }
2871 }
2872
2873 RETURN_LONG( result );
2874 }
2875
2876
2877 /**
2878 *
2879 * ��������������������������������ID��������������
2880 * @param sid ����������ID
2881 * @param binderid ����������������ID
2882 * @param cri ������������������������������
2883 * @param iids ������������������ID��������������
2884 * @param iidsLen iids������������������������������
2885 * @return RES_OK
2886 * @return RES_DB_NOT_INITIALIZED
2887 * @return RES_NO_SUCH_SESSION
2888 * @return RES_DB_QUERY_ERROR
2889 * @return RES_ERROR
2890 *
2891 */
2892 ZEND_FUNCTION(xnp_get_item_id_by_binder_id)
2893 {
2894 result_t result;
2895 long sid;
2896 itemid_t iid;
2897 zval *zcriteria;
2898 zval *ziids;
2899
2900 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2901 &sid, &iid, &zcriteria, &ziids) == FAILURE) {
2902 return;
2903 }
2904
2905 zCriteria_t zcri(zcriteria);
2906 result = zcri.getResult();
2907 if ( RES_OK == result ){
2908 const itemid_t *pitemids;
2909 int itemidLen;
2910 result = getItemIDByBinderID( (sessionid_t)sid, iid, &zcri, &pitemids, &itemidLen );
2911 if ( RES_OK == result ){
2912 itemidsToZval( pitemids, itemidLen, &ziids );
2913 freeItemID( pitemids );
2914 }
2915 }
2916 RETURN_LONG(result);
2917 }
2918
2919
2920 /**
2921 *
2922 * ����������������������������������ID��������������
2923 * ��������������������������������������������
2924 * ����������������������������������������
2925 *
2926 * @param sid ����������ID
2927 * @param xid ������������������ID
2928 * @param cri ������������������������������
2929 * @param iids ������������������ID��������������
2930 * @param iidsLen iids������������������������������
2931 * @return RES_OK
2932 * @return RES_DB_NOT_INITIALIZED
2933 * @return RES_NO_SUCH_SESSION
2934 * @return RES_DB_QUERY_ERROR
2935 * @return RES_ERROR
2936 *
2937 */
2938 ZEND_FUNCTION(xnp_get_item_id_by_index_id)
2939 {
2940 result_t result;
2941 long sid;
2942 indexid_t xid;
2943 zval *zcriteria;
2944 zval *ziids;
2945
2946 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2947 &sid, &xid, &zcriteria, &ziids) == FAILURE) {
2948 return;
2949 }
2950
2951 zCriteria_t zcri(zcriteria);
2952 result = zcri.getResult();
2953 if ( RES_OK == result ){
2954 const itemid_t *pitemids;
2955 int itemidLen;
2956 result = getItemIDByIndexID( (sessionid_t)sid, xid, &zcri, &pitemids, &itemidLen );
2957 if ( RES_OK == result ){
2958 itemidsToZval( pitemids, itemidLen, &ziids );
2959 freeItemID( pitemids );
2960 }
2961 }
2962 RETURN_LONG(result);
2963 }
2964
2965
2966 ZEND_FUNCTION(xnp_get_overlapped_items)
2967 {
2968 RETURN_LONG( RES_ERROR );
2969 }
2970
2971 /**
2972 *
2973 * ��������(Basic Information)����������.
2974 * Platform����������������������.
2975 *
2976 * @param sid ����������ID
2977 * @param item ������������������������
2978 * @param itemid ������������������ID��������������
2979 * @return RES_OK
2980 * @return RES_ERROR
2981 * @return RES_NO_SUCH_SESSION
2982 * @return RES_DB_QUERY_ERROR
2983 * @return RES_DB_NOT_INITIALIZED
2984 * @return RES_NO_WRITE_ACCESS_RIGHT
2985 *
2986 */
2987 ZEND_FUNCTION(xnp_insert_item)
2988 {
2989 long sid;
2990 zval *ziid;
2991 zval *zitem;
2992 item_t item;
2993 itemid_t iid;
2994 result_t result = RES_ERROR;
2995
2996 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2997 &sid, &zitem, &ziid) == FAILURE) {
2998 fprintf( stderr, "error occured " );
2999 return;
3000 }
3001
3002 zvalToItem( zitem, &item );
3003 result = insertItem( (sessionid_t)sid, &item, &iid );
3004 if ( RES_OK == result ){
3005 ziid -> type = IS_LONG;
3006 ziid -> value.lval = iid;
3007 }
3008 RETURN_LONG( result );
3009 }
3010
3011 /**
3012 *
3013 * ��������(Basic Information)����������.
3014 * Platform����������������������.
3015 *
3016 * @param sid ����������ID
3017 * @param item ������������������������
3018 * @param itemid ������������������ID��������������
3019 * @return RES_OK
3020 * @return RES_ERROR
3021 * @return RES_NO_SUCH_SESSION
3022 * @return RES_DB_QUERY_ERROR
3023 * @return RES_DB_NOT_INITIALIZED
3024 * @return RES_NO_WRITE_ACCESS_RIGHT
3025 *
3026 */
3027 ZEND_FUNCTION(xnp_insert_item_direct)
3028 {
3029 long sid;
3030 zval *ziid;
3031 zval *zitem;
3032 item_t item;
3033 itemid_t iid;
3034 result_t result = RES_ERROR;
3035
3036 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
3037 &sid, &zitem, &ziid) == FAILURE) {
3038 fprintf( stderr, "error occured " );
3039 return;
3040 }
3041
3042 zvalToItem( zitem, &item );
3043 result = insertItemDirect( (sessionid_t)sid, &item, &iid );
3044 if ( RES_OK == result ){
3045 ziid -> type = IS_LONG;
3046 ziid -> value.lval = iid;
3047 }
3048 RETURN_LONG( result );
3049 }
3050
3051 /**
3052 *
3053 * ��������(Basic Information)����������.
3054 * Platform����������������������.
3055 * item��item_id����������������������.
3056 *
3057 * @param sid ����������ID
3058 * @param item ������������������������
3059 * @return RES_OK
3060 * @return RES_ERROR
3061 * @return RES_NO_SUCH_SESSION
3062 * @return RES_DB_QUERY_ERROR
3063 * @return RES_DB_NOT_INITIALIZED
3064 * @return RES_NO_WRITE_ACCESS_RIGHT
3065 */
3066 ZEND_FUNCTION(xnp_update_item)
3067 {
3068 long sid;
3069 zval *zitem;
3070 item_t item;
3071 result_t result = RES_ERROR;
3072
3073 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
3074 &sid, &zitem) == FAILURE) {
3075 fprintf( stderr, "error occured " );
3076 return;
3077 }
3078
3079 zvalToItem( zitem, &item );
3080 result = updateItem( (sessionid_t)sid, &item );
3081 RETURN_LONG( result );
3082 }
3083
3084 /**
3085 *
3086 * ��������(Basic Information)����������.
3087 *
3088 * @param sid ����������ID
3089 * @param item ������������������������
3090 * @return RES_OK
3091 * @return RES_ERROR
3092 * @return RES_NO_SUCH_SESSION
3093 * @return RES_DB_QUERY_ERROR
3094 * @return RES_DB_NOT_INITIALIZED
3095 * @return RES_NO_WRITE_ACCESS_RIGHT
3096 */
3097 ZEND_FUNCTION(xnp_delete_item)
3098 {
3099 long sid;
3100 itemid_t iid;
3101 result_t result = RES_ERROR;
3102
3103 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
3104 &sid, &iid) == FAILURE) {
3105 fprintf( stderr, "error occured " );
3106 return;
3107 }
3108 result = deleteItem( (sessionid_t)sid, iid );
3109 RETURN_LONG( result );
3110 }
3111
3112
3113 /**
3114 *
3115 * ����������������������ID��������������
3116 * ������������������������������������������������������
3117 *
3118 * @param sid ����������ID
3119 * @param uid ������������ID
3120 * @param iids ������������������ID��������������
3121 * @param iidsLen iids������������������������������
3122 * @return RES_OK
3123 * @return RES_DB_NOT_INITIALIZED
3124 * @return RES_NO_SUCH_SESSION
3125 * @return RES_DB_QUERY_ERROR
3126 * @return RES_ERROR
3127 *
3128 */
3129 //result_t getPrivateItemID( sessionid_t sid, userid_t uid, const itemid_t** iids, int* iidsLen )
3130 ZEND_FUNCTION(xnp_get_private_item_id)
3131 {
3132 long sid;
3133 userid_t uid;
3134 zval* ziids;
3135
3136 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
3137 &sid, &uid, &ziids) == FAILURE) {
3138 return;
3139 }
3140
3141 const itemid_t *piids;
3142 int iidsLen;
3143 result_t result = getPrivateItemID( (sessionid_t)sid, uid, &piids, &iidsLen );
3144 if ( RES_OK == result ){
3145 itemidsToZval( piids, iidsLen, &ziids );
3146 freeItemID( piids );
3147 }
3148
3149 RETURN_LONG( result );
3150
3151 }
3152
3153 /**
3154 *
3155 * ������������������������������������������ID��������������
3156 *
3157 * @param sid ����������ID
3158 * @param uid ��������������ID
3159 * @param iids ������������������ID��������������
3160 * @param iidsLen iids������������������������������
3161 * @return RES_OK
3162 * @return RES_DB_NOT_INITIALIZED
3163 * @return RES_NO_SUCH_SESSION
3164 * @return RES_DB_QUERY_ERROR
3165 * @return RES_ERROR
3166 *
3167 */
3168 //result_t getGroupItemID( sessionid_t sid, groupid_t gid, const itemid_t** iids, int* iidsLen )
3169 ZEND_FUNCTION(xnp_get_group_item_id)
3170 {
3171 long sid;
3172 groupid_t gid;
3173 zval* ziids;
3174
3175 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
3176 &sid, &gid, &ziids) == FAILURE) {
3177 return;
3178 }
3179
3180 const itemid_t *piids;
3181 int iidsLen;
3182 result_t result = getGroupItemID( (sessionid_t)sid, gid, &piids, &iidsLen );
3183 if ( RES_OK == result ){
3184 itemidsToZval( piids, iidsLen, &ziids );
3185 freeItemID( piids );
3186 }
3187
3188 RETURN_LONG( result );
3189 }
3190
3191
3192 /**
3193 *
3194 * ����������������.
3195 * ��������������������������freeItem����������.
3196 *
3197 * @refer freeItem
3198 * @param sid ����������ID
3199 * @param iid ��������������������ID
3200 * @param item ��������������������������������
3201 * @return RES_OK
3202 * @return RES_DB_NOT_INITIALIZED
3203 * @return RES_NO_SUCH_SESSION
3204 * @return RES_NO_SUCH_ITEM
3205 * @return RES_DB_QUERY_ERROR
3206 *
3207 */
3208 ZEND_FUNCTION(xnp_get_item)
3209 {
3210 long sid;
3211 long iid;
3212 zval *zitem;
3213 result_t result = RES_ERROR;
3214
3215 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
3216 &sid, &iid, &zitem) == FAILURE) {
3217 fprintf( stderr, "error occured " );
3218 return;
3219 }
3220
3221 const item_t* pitem;
3222 result = getItem( (sessionid_t)sid, iid, &pitem );
3223 if ( RES_OK == result ){
3224 itemToZval( pitem, zitem );
3225 freeItem( pitem );
3226 }
3227 RETURN_LONG( result );
3228 }
3229
3230
3231 /**
3232 *
3233 * ����������������.
3234 * ��������������������������freeItem����������.
3235 *
3236 * @refer freeItem
3237 * @param sid ����������ID
3238 * @param iids ��������������������ID������
3239 * @param iidsLen iids������������
3240 * @param cri ������������������������������
3241 * @param items ��������������������������������������
3242 * @param itemsLen ������������(����*items��������)
3243 * @return RES_OK
3244 * @return RES_DB_NOT_INITIALIZED
3245 * @return RES_NO_SUCH_SESSION
3246 * @return RES_DB_QUERY_ERROR
3247 *
3248 */
3249 ZEND_FUNCTION(xnp_get_items)
3250 {
3251 result_t result;
3252 long sid;
3253 zval *ziids;
3254 zval *zcriteria;
3255 zval *zitem;
3256
3257 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
3258 &sid, &ziids, &zcriteria, &zitem) == FAILURE) {
3259 return;
3260 }
3261
3262 zCriteria_t zcri(zcriteria);
3263 result = zcri.getResult();
3264 if ( RES_OK == result ){
3265 zIIDs_t zIIDs(ziids);
3266 result = zIIDs.getResult();
3267 if ( RES_OK == result ){
3268 const item_t *pitems;
3269 int itemLen;
3270 result = getItems( (sessionid_t)sid,
3271 zIIDs.getPIID(), zIIDs.getLen(),
3272 &zcri, &pitems, &itemLen );
3273 if ( RES_OK == result ){
3274 itemsToZval( pitems, itemLen, zitem );
3275 freeItem( pitems );
3276 }
3277 }
3278 }
3279
3280 RETURN_LONG(result);
3281 }
3282
3283
3284 /**
3285 *
3286 *
3287 * @param p