Develop and Download Open Source Software

Browse CVS Repository

Diff of /xoonips/AL/xnpal.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.1.1 by aga, Mon Nov 22 01:42:37 2004 UTC revision 1.59 by yamaji, Sat Dec 10 06:26:56 2005 UTC
# Line 1  Line 1 
1  /*  /*
2          VPAL: Visiome Platform Abstract Layer   * --------------------------------------------------------------------------  
3             * XooNiPs Xoops modules for Neuroinformatics Platforms                        
4          zend_parse_parametersはphp4.1.0が必要   * Copyright (C) 2005 RIKEN, Japan. All rights reserved.                      
5          .soファイルは外から見えない場所に置くべき。   * http://sourceforge.jp/projects/xoonips/                                    
6          C++では、extern "C"{}, BEGIN/END_EXTERN_C()が必要。   * --------------------------------------------------------------------------  
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$
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>  #include <stdio.h>
31  #include "vpal.h"  #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  // global variables
 MYSQL *mysql = NULL;  
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 */  /* declaration of functions to be exported */
60  extern "C" {  extern "C" {
61  ZEND_FUNCTION(first_module);  ZEND_FUNCTION(first_module         );
62  ZEND_FUNCTION(vp_initialize_db);  ZEND_FUNCTION(xnp_initialize_db     );
63  ZEND_FUNCTION(vp_login_user);  ZEND_FUNCTION(xnp_login_user        );
64  ZEND_FUNCTION(vp_logout_user);  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 */  /* compiled function list so Zend knows what's in this module */
190  zend_function_entry vpalmod_functions[] =  zend_function_entry xnpalmod_functions[] =
191  {  {
192      ZEND_FE(first_module, NULL)          ZEND_FE(first_module          ,NULL)
193      ZEND_FE(vp_initialize_db, NULL)          ZEND_FE(xnp_initialize_db     ,NULL)
194      ZEND_FE(vp_login_user, NULL)          ZEND_FE(xnp_login_user        ,third_arg_force_ref)
195      ZEND_FE(vp_logout_user, NULL)          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}      {NULL, NULL, NULL}
304  };  };
305    
306  /* compiled module information */  /* compiled module information */
307  zend_module_entry vpalmod_module_entry =  zend_module_entry xnpalmod_module_entry =
308  {  {
309      STANDARD_MODULE_HEADER,          STANDARD_MODULE_HEADER,
310      "Visiome Platform Abstract Layer",          "XNPAL",
311      vpalmod_functions,          xnpalmod_functions,
312      NULL,          NULL,
313      NULL,          PHP_MSHUTDOWN(xnpalmod),
314      NULL,          PHP_RINIT(xnpalmod),
315      NULL,          NULL,
316      NULL,          NULL,
317      NO_VERSION_YET,          NO_VERSION_YET,
318      STANDARD_MODULE_PROPERTIES          STANDARD_MODULE_PROPERTIES
319  };  };
320    
321  /* implement standard "stub" routine to introduce ourselves to Zend */  /* implement standard "stub" routine to introduce ourselves to Zend */
322  #if COMPILE_DL_FIRST_MODULE  #if COMPILE_DL_FIRST_MODULE
323  BEGIN_EXTERN_C()  BEGIN_EXTERN_C()
324  ZEND_GET_MODULE(vpalmod)  ZEND_GET_MODULE(xnpalmod)
325  END_EXTERN_C()  END_EXTERN_C()
326  #endif  #endif
327    
328    
329  /* implement function that is meant to be made available to PHP */  /* implement function that is meant to be made available to PHP */
330  ZEND_FUNCTION(first_module)  ZEND_FUNCTION(first_module)
331  {  {
332      long parameter;          long parameter;
333  //      if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;  //      if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
334      if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
335          return;                  return;
336      }          }
337          parameter++;          parameter++;
338      RETURN_LONG(parameter);          RETURN_LONG(parameter);
339  }  }
340  /** zvalからCの文字列を得る。  /** zvalからCの文字列を得る。
341    */    */
# Line 78  int getZvalInt( zval **p ){ Line 351  int getZvalInt( zval **p ){
351          return Z_LVAL_PP(p); // (int)(**p).value.lval;          return Z_LVAL_PP(p); // (int)(**p).value.lval;
352  }  }
353    
354  /** DBに接続する。既に接続中の接続は閉じられる。  // keylenは末尾の\0を含む。
355      @param host      接続先。省略時はlocalhost  static void print_hash_key( int res, const char *key, uint keyLen, ulong index ){
356      @param user      DB接続時のユーザ名。省略時はNULL          zend_printf( "print_hash_key : key=0x%08x keylen=%08d index=%08d<br>  ", key, keyLen, index );
357      @param password  DB接続時のパスワード。省略時はNULL          if ( res == HASH_KEY_IS_STRING ){
358      @param dbname    DB接続時のDB名。省略時はNULL                  char *p = new char[keyLen+1];
359      @param port      接続先のポート。省略時は3336                  memcpy( p, key, keyLen );
360      @return 0 success <br>                  p[keyLen] = 0;
361      @return 1 cannot mysql_init  <br>                  zend_printf( "  key is string[%s]<br>\n", p );
362      @return 2 cannot mysql_real_connect <br>          }
363      int initialize_db ( char* host="localhost", char* user=NULL, char* password=NULL, char* dbname=NULL, int port=3336 )          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(vp_initialize_db)  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];          zval **parameters[5];
1565          char *host;          char *host;
1566          char *user;          char *user;
1567          char *passwd;          char *password;
1568          char *db;          char *dbname;
1569          int port;          char *prefix;
1570            long dbtype;
1571    
1572          /* get the number of arguments */          /* get the number of arguments */
1573          int argNum = ZEND_NUM_ARGS();          int argNum = ZEND_NUM_ARGS();
# Line 107  ZEND_FUNCTION(vp_initialize_db) Line 1578  ZEND_FUNCTION(vp_initialize_db)
1578          if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)          if(zend_get_parameters_array_ex(argNum, parameters) != SUCCESS)
1579                  WRONG_PARAM_COUNT;                  WRONG_PARAM_COUNT;
1580    
1581          if (argNum < 1) host = "localhost";          if (argNum < 1) host = NULL;
1582          else            host = getZvalString( parameters[0] );          else            host = getZvalString( parameters[0] );
1583            
1584          if (argNum < 2) user = NULL;          if (argNum < 2) user = NULL;
1585          else            user = getZvalString( parameters[1] );          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          if (argNum < 3) passwd = NULL;          result_t result = RES_ERROR;
2790          else            passwd = getZvalString( parameters[2] );  
2791                    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
2792          if (argNum < 4) db = NULL;                                                            &name, &nameLen, &zvalue ) == FAILURE) {
2793          else            db = getZvalString( parameters[3] );                  return;
2794                    }
         if (argNum < 5) port = 3336;  
         else            port = getZvalInt( parameters[4] );  
           
         // 既に接続中なら、一旦切断  
         if ( mysql != NULL )  
                 mysql_close( mysql );  
2795                    
2796          // 初期化と接続          result = getConfigValue( name, &value );
2797          mysql = mysql_init(NULL);          if( result == RES_OK ){
2798          if ( mysql == NULL ){                  ZVAL_STRING( zvalue, value, true/*duplicate*/ );
2799                  RETURN_LONG(1);          }
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          char *unix_socket = NULL; // ?  
3002          uint flag = 0;       // ?          zvalToItem( zitem, &item );
3003          if ( NULL == mysql_real_connect( mysql, host, user, passwd, db, port, unix_socket, flag ) ){          result = insertItem( (sessionid_t)sid, &item, &iid );
3004                  RETURN_LONG(2);          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            
     RETURN_LONG(0);  
3151  }  }
3152    
3153  //              session_t* login_user(char* uname, char* passwd)  /**
3154  ZEND_FUNCTION(vp_login_user)   *
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          char *uname;          long sid;
3172          int unameLen;          groupid_t gid;
3173          char *passwd;      zval* ziids;
3174          int passwdLen;      
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 pmid PUBMEDID
3288     * @param pubmed 結果を書き込むpubmed_tのポインタ引数
3289     *
3290     *
3291     *
3292     */
3293    ZEND_FUNCTION(xnp_pubmed_complete)
3294    {
3295            long pmid;
3296            zval *zpubmed;
3297            result_t result = RES_ERROR;
3298    
3299            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
3300                                                              &pmid, &zpubmed) == FAILURE) {
3301                    fprintf( stderr, "error occured " );
3302                    return;
3303            }
3304    
3305            const pubmed_t* ppubmed;
3306            result = pubmedComplete( pmid, &ppubmed );
3307            if ( RES_OK == result ){
3308                    pubmedToZval( ppubmed,  zpubmed );
3309                    freePubmed( ppubmed );
3310            }
3311            RETURN_LONG( result );
3312    }
3313    
3314    
3315    /**
3316     *
3317     *
3318     * @param isbn ISBN
3319     * @param amazonbook 結果を書き込むamazonbook_tのポインタ引数
3320     *
3321     *
3322     *
3323     */
3324    ZEND_FUNCTION(xnp_amazon_complete)
3325    {
3326            zval *zurl;
3327            zval *zamazonbook;
3328            result_t result = RES_ERROR;
3329    
3330            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za",
3331                                                              &zurl, &zamazonbook) == FAILURE) {
3332                    fprintf( stderr, "error occured " );
3333                    return;
3334            }
3335    
3336            const amazonbook_t* pamazonbook;
3337            result = amazonComplete( getZvalString( &zurl ) , &pamazonbook );
3338            if ( RES_OK == result ){
3339                    amazonbookToZval( pamazonbook,  zamazonbook );
3340                    //freeAmazonbook( pamazonbook );
3341            }
3342            RETURN_LONG( result );
3343    }
3344    
3345    
3346    //ZEND_FUNCTION(xnp_uninitialize_db)
3347    //{
3348    //    RETURN_LONG( RES_ERROR );
3349    //}
3350    
3351    
3352    /**
3353     *
3354     * バインダーにアイテムを追加する
3355     *
3356     * @param sid セッションID
3357     * @param binderid 処理対象のバインダーのID
3358     * @param iid バインダーに追加したいアイテムのID
3359     * @return RES_OK
3360     * @return RES_DB_QUERY_ERROR
3361     * @return RES_NO_SUCH_SESSION
3362     * @return RES_NO_WRITE_ACCESS_RIGHT
3363     * @return RES_ERROR
3364     *
3365     */
3366    ZEND_FUNCTION(xnp_register_binder_item)
3367    {
3368            result_t result = RES_ERROR;
3369            long sid;
3370            long bid;
3371            long iid;
3372    
3373            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3374              &sid, &bid, &iid) == FAILURE) {
3375                    return;
3376            }
3377    
3378            result = registerBinderItem( (sessionid_t)sid, bid, iid );
3379            RETURN_LONG(result);
3380    }
3381    
3382    
3383    /**
3384     *
3385     * バインダーからアイテムを削除する
3386     *
3387     * @param sid セッションID
3388     * @param binderid 処理対象のバインダーのID
3389     * @param iid バインダーから削除したいアイテムのID
3390     * @return RES_OK
3391     * @return RES_DB_QUERY_ERROR
3392     * @return RES_NO_SUCH_SESSION
3393     * @return RES_NO_WRITE_ACCESS_RIGHT
3394     * @return RES_ERROR
3395     *
3396     */
3397    ZEND_FUNCTION(xnp_unregister_binder_item)
3398    {
3399            result_t result = RES_ERROR;
3400            long sid;
3401            long bid;
3402            long iid;
3403    
3404            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3405              &sid, &bid, &iid) == FAILURE) {
3406                    return;
3407            }
3408    
3409            result = registerBinderItem( (sessionid_t)sid, bid, iid );
3410            RETURN_LONG(result);
3411    }
3412    
3413    
3414    /**
3415     *
3416     * インデックスにアイテムを追加する
3417     *
3418     * @param sid セッションID
3419     * @param xid 処理対象のインデックスのID
3420     * @param iid インデックスに追加したいアイテムのID
3421     * @return RES_OK
3422     * @return RES_DB_QUERY_ERROR
3423     * @return RES_NO_SUCH_SESSION
3424     * @return RES_NO_WRITE_ACCESS_RIGHT
3425     * @return RES_ERROR
3426     *
3427     */
3428    ZEND_FUNCTION(xnp_register_item)
3429    {
3430            result_t result = RES_ERROR;
3431            long sid;
3432            long xid;
3433            long iid;
3434    
3435            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3436              &sid, &xid, &iid) == FAILURE) {
3437                    return;
3438            }
3439    
3440            result = registerItem( (sessionid_t)sid, xid, iid );
3441            RETURN_LONG(result);
3442    }
3443    
3444    
3445    /**
3446     *
3447     * インデックスからアイテムを削除する
3448     *
3449     * @param sid セッションID
3450     * @param xid 処理対象のインデックスのID
3451     * @param iid インデックスから削除したいアイテムのID
3452     * @return RES_OK
3453     * @return RES_DB_QUERY_ERROR
3454     * @return RES_NO_SUCH_SESSION
3455     * @return RES_NO_WRITE_ACCESS_RIGHT
3456     * @return RES_ERROR
3457     *
3458     */
3459    ZEND_FUNCTION(xnp_unregister_item)
3460    {
3461            result_t result = RES_ERROR;
3462            long sid;
3463            long xid;
3464            long iid;
3465    
3466            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3467              &sid, &xid, &iid) == FAILURE) {
3468                    return;
3469            }
3470    
3471            result = unregisterItem( (sessionid_t)sid, xid, iid );
3472            RETURN_LONG(result);
3473    }
3474    
3475    
3476    /**
3477     *
3478     * 承認待ち状態のアイテムのうち,承認権限のあるアイテムのIDと登録先インデックスのIDをペアで取得します.
3479     * アイテムiids[i]が現在xids[i]への登録の承認待ち状態にあることを返します.
3480     *
3481     * @param sid セッションID
3482     * @param xids 承認待ちアイテムを登録するインデックスIDを受け取る引数
3483     * @param iids 承認待ちアイテムIDを受け取る引数
3484     * @param len iids,xidsに格納された個数を受け取る引数
3485     * @return RES_OK
3486     * @return RES_DB_NOT_INITIALIZED
3487     * @return RES_NO_SUCH_SESSION
3488     * @return RES_DB_QUERY_ERROR
3489     * @return RES_ERROR
3490     *
3491     */
3492    //result_t getUncertifiedLink( sessionid_t sid, const itemid_t** xids, const itemid_t** iids, int* len )
3493    ZEND_FUNCTION(xnp_get_uncertified_link)
3494    {
3495            long sid;
3496        zval* zxids;
3497        zval* ziids;
3498        
3499            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
3500                                  &sid, &zxids, &ziids) == FAILURE) {
3501                    return;
3502            }
3503        
3504        const itemid_t *pxids;
3505        const itemid_t *piids;
3506        int len;
3507        result_t result = getUncertifiedLink( (sessionid_t)sid, &pxids, &piids, &len );
3508        if ( RES_OK == result ){
3509            indexidsToZval( pxids, len, &zxids );
3510            itemidsToZval( piids, len, &ziids );
3511            freeIndexID( pxids );
3512            freeItemID( piids );
3513        }
3514            RETURN_LONG( result );
3515    }
3516    
3517    /**
3518     *
3519     * @param types
3520     * @return RES_OK
3521     * @return RES_DB_NOT_INITIALIZED
3522     * @return RES_NO_SUCH_SESSION
3523     * @return RES_DB_QUERY_ERROR
3524     * @return RES_ERROR
3525     *
3526     */
3527    ZEND_FUNCTION(xnp_get_item_types)
3528    {
3529        zval* ztypes;
3530        
3531            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
3532                                  &ztypes) == FAILURE) {
3533                    return;
3534            }
3535        
3536        const itemtype_t *ptypes;
3537        int len;
3538        result_t result = getItemTypes( &ptypes, &len );
3539        if ( RES_OK == result ){
3540    
3541            zend_hash_clean( ztypes -> value.ht );
3542            for( int i = 0; i < len; i++ ){
3543                zval *new_array;
3544                MAKE_STD_ZVAL(new_array);
3545                if(array_init(new_array) != SUCCESS){
3546                    result = RES_ERROR;
3547                    break;
3548                }
3549                add_index_zval( ztypes, i, new_array );
3550                
3551                zend_hash_clean( new_array -> value.ht );
3552                add_assoc_long( new_array, "item_type_id", ptypes[ i ].getItemTypeID( ) );
3553                add_assoc_long( new_array, "mid", ptypes[ i ].getModuleID( ) );
3554                add_assoc_string( new_array, "name", ( char* )ptypes[ i ].getName( ), 1 );
3555                add_assoc_string( new_array, "display_name", ( char* )ptypes[ i ].getDisplayName( ), 1 );
3556                add_assoc_string( new_array, "viewphp", ( char* )ptypes[ i ].getViewphp( ), 1 );
3557            }
3558            result = RES_OK;
3559            freeItemType( ptypes );
3560        }
3561            RETURN_LONG( result );
3562    }
3563    
3564    ZEND_FUNCTION(xnp_get_index_id_by_item_id)
3565    {
3566            result_t result;
3567            long sid;
3568            itemid_t iid;
3569            zval *zxids;
3570    
3571            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
3572              &sid, &iid, &zxids) == FAILURE) {
3573                    return;
3574            }
3575    
3576        const indexid_t *pindexids;
3577        int indexidLen;
3578        result = getIndexIDByItemID( (sessionid_t)sid, iid, &pindexids, &indexidLen );
3579        if ( RES_OK == result ){
3580            indexidsToZval( pindexids, indexidLen, &zxids );
3581            freeIndexID( pindexids );
3582        }
3583            RETURN_LONG(result);
3584    }
3585    
3586    ZEND_FUNCTION(xnp_get_own_public_item_id)
3587    {
3588            long sid;
3589            userid_t uid;
3590            zval* ziids;
3591                    
3592          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
3593            &uname, &unameLen, &passwd, &passwdLen) == FAILURE) {                                    &sid, &uid, &ziids) == FAILURE) {
3594                  return;                  return;
3595          }          }
3596                    
3597          //ここでログイン          const itemid_t *piids;
3598            int iidsLen;
3599            result_t result = getOwnPublicItemID( (sessionid_t)sid, uid, &piids, &iidsLen );
3600            if ( RES_OK == result ){
3601                    itemidsToZval( piids, iidsLen, &ziids );
3602                    freeItemID( piids );
3603            }
3604                    
3605            RETURN_LONG( result );
3606    }
3607    
3608    ZEND_FUNCTION(xnp_zip_create)
3609    {
3610            zval* zzipfile;
3611            zval* zfiles;
3612            result_t result = RES_ERROR;
3613            
3614            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za",
3615                                                              &zzipfile, &zfiles) == FAILURE) {
3616                    return;
3617