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.23 by aga, Sat Jan 15 00:39:16 2005 UTC revision 1.24 by youi, Sat Jan 22 09:24:21 2005 UTC
# Line 1  Line 1 
1  /*  /*
2          $Revision$          $Revision$
3          XNPAL: XooNiPs Platform Abstract Layer          XNPAL: XooNiPs Platform Abstract Layer
4            
5          zend_parse_parametersはphp4.1.0が必要          zend_parse_parametersはphp4.1.0が必要
6          .soファイルは外から見えない場所に置くべき。          .soファイルは外から見えない場所に置くべき。
7          C++では、extern "C"{}, BEGIN/END_EXTERN_C()が必要。          C++では、extern "C"{}, BEGIN/END_EXTERN_C()が必要。
# Line 14  Line 14 
14  #include "commonal.h"  #include "commonal.h"
15  #include "session.h"  #include "session.h"
16  #include "group.h"  #include "group.h"
17  #include "account.h"  #include "index.h"
18  #include "xnpal.h"  #include "xnpal.h"
19    #include "amazonbook.h"
20    
21  // for inet_aton  // for inet_aton
22  #include <sys/socket.h>  #include <sys/socket.h>
# Line 78  ZEND_FUNCTION(xnp_get_last_error_string Line 79  ZEND_FUNCTION(xnp_get_last_error_string
79    
80  ZEND_FUNCTION(xnp_test_criteria     );  ZEND_FUNCTION(xnp_test_criteria     );
81  ZEND_FUNCTION(xnp_test_uids         );  ZEND_FUNCTION(xnp_test_uids         );
82    
83    
84    ZEND_FUNCTION(xnp_get_item_permission      );
85    ZEND_FUNCTION(xnp_get_index_permission     );
86    ZEND_FUNCTION(xnp_get_certify_permission   );
87    
88    ZEND_FUNCTION(xnp_get_certify_state        );
89    ZEND_FUNCTION(xnp_set_certify_state        );
90    
91    ZEND_FUNCTION(xnp_insert_change_log        );
92    ZEND_FUNCTION(xnp_get_change_logs          );
93    
94    ZEND_FUNCTION(xnp_get_config_value         );
95    ZEND_FUNCTION(xnp_set_config_value         );
96    
97    ZEND_FUNCTION(xnp_dump_item_id             );
98    ZEND_FUNCTION(xnp_get_item_id_by_binder_id );
99    ZEND_FUNCTION(xnp_get_item_id_by_index_id  );
100    ZEND_FUNCTION(xnp_get_overlapped_items     );
101    
102    ZEND_FUNCTION(xnp_insert_item              );
103    ZEND_FUNCTION(xnp_update_item              );
104    ZEND_FUNCTION(xnp_delete_item              );
105    ZEND_FUNCTION(xnp_get_item                 );
106    ZEND_FUNCTION(xnp_get_items                );
107    
108    ZEND_FUNCTION(xnp_pubmed_complete          );
109    ZEND_FUNCTION(xnp_amazon_complete          );
110    
111    //ZEND_FUNCTION(xnp_uninitialize_db          );
112    
113    ZEND_FUNCTION(xnp_register_binder_item     );
114    ZEND_FUNCTION(xnp_unregister_binder_item   );
115    
116    ZEND_FUNCTION(xnp_register_item            );
117    ZEND_FUNCTION(xnp_unregister_item          );
118    
119  };  };
120  /* compiled function list so Zend knows what's in this module */  /* compiled function list so Zend knows what's in this module */
121  zend_function_entry xnpalmod_functions[] =  zend_function_entry xnpalmod_functions[] =
122  {  {
123      ZEND_FE(first_module         ,NULL)          ZEND_FE(first_module         ,NULL)
124      ZEND_FE(xnp_initialize_db     ,NULL)          ZEND_FE(xnp_initialize_db     ,NULL)
125      ZEND_FE(xnp_login_user        ,NULL)          ZEND_FE(xnp_login_user        ,NULL)
126      ZEND_FE(xnp_logout_user       ,NULL)          ZEND_FE(xnp_logout_user       ,NULL)
127      ZEND_FE(xnp_create_session    ,NULL)          ZEND_FE(xnp_create_session    ,NULL)
128      ZEND_FE(xnp_get_session       ,NULL)          ZEND_FE(xnp_get_session       ,NULL)
129      ZEND_FE(xnp_is_activated      ,NULL)          ZEND_FE(xnp_is_activated      ,NULL)
130      ZEND_FE(xnp_activate          ,NULL)          ZEND_FE(xnp_activate          ,NULL)
131      ZEND_FE(xnp_get_account_count ,NULL)          ZEND_FE(xnp_get_account_count ,NULL)
132      ZEND_FE(xnp_delete_account    ,NULL)          ZEND_FE(xnp_delete_account    ,NULL)
133      ZEND_FE(xnp_get_account       ,NULL)          ZEND_FE(xnp_get_account       ,NULL)
134      ZEND_FE(xnp_get_accounts      ,NULL)          ZEND_FE(xnp_get_accounts      ,NULL)
135      ZEND_FE(xnp_insert_account    ,NULL)          ZEND_FE(xnp_insert_account    ,NULL)
136      ZEND_FE(xnp_update_account    ,NULL)          ZEND_FE(xnp_update_account    ,NULL)
137      ZEND_FE(xnp_dump_uids         ,NULL)          ZEND_FE(xnp_dump_uids         ,NULL)
138      ZEND_FE(xnp_get_group_count   ,NULL)          ZEND_FE(xnp_get_group_count   ,NULL)
139      ZEND_FE(xnp_get_groups_by_uid ,NULL)          ZEND_FE(xnp_get_groups_by_uid ,NULL)
140      ZEND_FE(xnp_is_group_admin    ,NULL)          ZEND_FE(xnp_is_group_admin    ,NULL)
141      ZEND_FE(xnp_dump_gids         ,NULL)          ZEND_FE(xnp_dump_gids         ,NULL)
142      ZEND_FE(xnp_dump_group_admins ,NULL)          ZEND_FE(xnp_dump_group_admins ,NULL)
143      ZEND_FE(xnp_delete_member     ,NULL)          ZEND_FE(xnp_delete_member     ,NULL)
144      ZEND_FE(xnp_insert_member     ,NULL)          ZEND_FE(xnp_insert_member     ,NULL)
145      ZEND_FE(xnp_get_members       ,NULL)          ZEND_FE(xnp_get_members       ,NULL)
146      ZEND_FE(xnp_delete_group      ,NULL)          ZEND_FE(xnp_delete_group      ,NULL)
147      ZEND_FE(xnp_insert_group      ,NULL)          ZEND_FE(xnp_insert_group      ,NULL)
148      ZEND_FE(xnp_update_group      ,NULL)          ZEND_FE(xnp_update_group      ,NULL)
149      ZEND_FE(xnp_get_group         ,NULL)          ZEND_FE(xnp_get_group         ,NULL)
150      ZEND_FE(xnp_get_groups        ,NULL)          ZEND_FE(xnp_get_groups        ,NULL)
151      ZEND_FE(xnp_is_moderator      ,NULL)          ZEND_FE(xnp_is_moderator      ,NULL)
152      ZEND_FE(xnp_get_uid           ,NULL)          ZEND_FE(xnp_get_uid           ,NULL)
153    
154      ZEND_FE(xnp_get_all_indexes     ,NULL)          ZEND_FE(xnp_get_all_indexes     ,NULL)
155      ZEND_FE(xnp_get_indexes         ,NULL)          ZEND_FE(xnp_get_indexes         ,NULL)
156      ZEND_FE(xnp_insert_index        ,NULL)          ZEND_FE(xnp_insert_index        ,NULL)
157      ZEND_FE(xnp_update_index        ,NULL)          ZEND_FE(xnp_update_index        ,NULL)
158      ZEND_FE(xnp_delete_index        ,NULL)          ZEND_FE(xnp_delete_index        ,NULL)
159      ZEND_FE(xnp_get_index           ,NULL)          ZEND_FE(xnp_get_index           ,NULL)
160      ZEND_FE(xnp_is_index_readable   ,NULL)          ZEND_FE(xnp_is_index_readable   ,NULL)
161      ZEND_FE(xnp_is_index_writable   ,NULL)          ZEND_FE(xnp_is_index_writable   ,NULL)
162      ZEND_FE(xnp_swap_index_sort_number ,NULL)          ZEND_FE(xnp_swap_index_sort_number ,NULL)
163    
164      ZEND_FE(xnp_is_valid_session_id ,NULL)          ZEND_FE(xnp_is_valid_session_id ,NULL)
165      ZEND_FE(xnp_get_last_error_string ,NULL)          ZEND_FE(xnp_get_last_error_string ,NULL)
166      ZEND_FE(xnp_test_criteria     ,NULL)          ZEND_FE(xnp_test_criteria     ,NULL)
167      ZEND_FE(xnp_test_uids         ,NULL)          ZEND_FE(xnp_test_uids         ,NULL)
168      {NULL, NULL, NULL}  
169            ZEND_FE(xnp_get_item_permission      ,NULL)
170            ZEND_FE(xnp_get_index_permission     ,NULL)
171            ZEND_FE(xnp_get_certify_permission   ,NULL)
172    
173            ZEND_FE(xnp_get_certify_state        ,NULL)
174            ZEND_FE(xnp_set_certify_state        ,NULL)
175    
176            ZEND_FE(xnp_insert_change_log        ,NULL)
177            ZEND_FE(xnp_get_change_logs          ,NULL)
178    
179            ZEND_FE(xnp_get_config_value         ,NULL)
180            ZEND_FE(xnp_set_config_value         ,NULL)
181    
182            ZEND_FE(xnp_dump_item_id             ,NULL)
183            ZEND_FE(xnp_get_item_id_by_binder_id ,NULL)
184            ZEND_FE(xnp_get_item_id_by_index_id  ,NULL)
185            ZEND_FE(xnp_get_overlapped_items     ,NULL)
186    
187            ZEND_FE(xnp_insert_item              ,NULL)
188            ZEND_FE(xnp_update_item              ,NULL)
189            ZEND_FE(xnp_delete_item              ,NULL)
190            ZEND_FE(xnp_get_item                 ,NULL)
191            ZEND_FE(xnp_get_items                ,NULL)
192    
193            ZEND_FE(xnp_pubmed_complete          ,NULL)
194            ZEND_FE(xnp_amazon_complete          ,NULL)
195    
196    //    ZEND_FE(xnp_uninitialize_db          ,NULL)
197    
198            ZEND_FE(xnp_register_binder_item     ,NULL)
199            ZEND_FE(xnp_unregister_binder_item   ,NULL)
200    
201            ZEND_FE(xnp_register_item            ,NULL)
202            ZEND_FE(xnp_unregister_item          ,NULL)
203    
204            {NULL, NULL, NULL}
205  };  };
206    
207  /* compiled module information */  /* compiled module information */
208  zend_module_entry xnpalmod_module_entry =  zend_module_entry xnpalmod_module_entry =
209  {  {
210      STANDARD_MODULE_HEADER,          STANDARD_MODULE_HEADER,
211      "Visiome Platform Abstract Layer",          "Visiome Platform Abstract Layer",
212      xnpalmod_functions,          xnpalmod_functions,
213      NULL,          NULL,
214          PHP_MSHUTDOWN(xnpalmod),          PHP_MSHUTDOWN(xnpalmod),
215      NULL,          NULL,
216      NULL,          NULL,
217      NULL,          NULL,
218      NO_VERSION_YET,          NO_VERSION_YET,
219      STANDARD_MODULE_PROPERTIES          STANDARD_MODULE_PROPERTIES
220  };  };
221    
222  /* implement standard "stub" routine to introduce ourselves to Zend */  /* implement standard "stub" routine to introduce ourselves to Zend */
# Line 156  END_EXTERN_C() Line 230  END_EXTERN_C()
230  /* implement function that is meant to be made available to PHP */  /* implement function that is meant to be made available to PHP */
231  ZEND_FUNCTION(first_module)  ZEND_FUNCTION(first_module)
232  {  {
233      long parameter;          long parameter;
234  //      if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;  //      if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
235      if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &parameter) == FAILURE) {
236          return;                  return;
237      }          }
238          parameter++;          parameter++;
239      RETURN_LONG(parameter);          RETURN_LONG(parameter);
240  }  }
241  /** zvalからCの文字列を得る。  /** zvalからCの文字列を得る。
242    */    */
# Line 194  static void print_hash_key( int res, con Line 268  static void print_hash_key( int res, con
268    
269    
270  /** zval*からcriteria_tを生成するためのクラス。生成失敗ならgetResult()!=RES_OK <br>  /** zval*からcriteria_tを生成するためのクラス。生成失敗ならgetResult()!=RES_OK <br>
271      criteria :          criteria :
272      array( 'start'=>0, 'rows'=>10,          array( 'start'=>0, 'rows'=>10,
273         'orders'=>array(             'orders'=>array(
274          array('name'=>'id','order'=>'0'),                  array('name'=>'id','order'=>'0'),
275          array('name'=>'timestamp','name'=>'1'), ...)                  array('name'=>'timestamp','name'=>'1'), ...)
276      ); こんな形の連想配列          ); こんな形の連想配列
277    */    */
278  class zCriteria_t : public criteria {  class zCriteria_t : public criteria {
279  private:  private:
# Line 210  private: Line 284  private:
284          void setOrder( zval *pz ){          void setOrder( zval *pz ){
285                  char *column = 0;                  char *column = 0;
286                  order_t order = (order_t)0;                  order_t order = (order_t)0;
287                    
288                  HashPosition pos;                  HashPosition pos;
289                  zval **ppzTmp = 0;                  zval **ppzTmp = 0;
290                  int res2;                  int res2;
# Line 233  private: Line 307  private:
307  //                                      zend_printf( "order=%d<br>\n", order );  //                                      zend_printf( "order=%d<br>\n", order );
308                                  }                                  }
309                          }                          }
310                            
311                          zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);                          zend_hash_move_forward_ex(Z_ARRVAL_P(pz), &pos);
312                  }                  }
313                  if ( column ){                  if ( column ){
314                          orderby *o = new orderby( column, order );                          orderby *o = new orderby( column, order );
315                          addOrderBy( o );                          addOrderBy( o );
316                  }                  }
317                    
318                  result = RES_OK;                  result = RES_OK;
319          }          }
320            
321          // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)          // pz: array( array('column'=>'hoge','order'=>'1'), array('column'=>'huga','order'=>'2'), ...)
322          void setOrders( zval *pz ){          void setOrders( zval *pz ){
323                  HashPosition pos;                  HashPosition pos;
324                    
325                  zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);                  zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pz), &pos);
326                    
327                  zval **ppzTmp = 0;                  zval **ppzTmp = 0;
328                  int res2;                  int res2;
329                  while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {                  while ( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(pz), (void **)&ppzTmp, &pos)) == SUCCESS ) {
# Line 265  private: Line 339  private:
339                  }                  }
340                  result = RES_OK;                  result = RES_OK;
341          }          }
342            
343          void initialize( zval *pz ){          void initialize( zval *pz ){
344                  HashPosition pos;                  HashPosition pos;
345                  zval **ppzTmp = 0;                  zval **ppzTmp = 0;
# Line 308  public: Line 382  public:
382          zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }          zCriteria_t( zval *pz ) : criteria(){ initialize(pz); }
383          zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }          zCriteria_t( zval **ppz ) : criteria() { initialize(*ppz); }
384          result_t getResult(){ return result; };          result_t getResult(){ return result; };
385            
386          void dump(){          void dump(){
387                  zend_printf( "dumping zCriteria...<br>\n" );                  zend_printf( "dumping zCriteria...<br>\n" );
388                  zend_printf( "result=%d<br>\n", (int)result );                  zend_printf( "result=%d<br>\n", (int)result );
# Line 329  public: Line 403  public:
403    @return  成功ならtrue    @return  成功ならtrue
404   */   */
405  static bool hashGetLong( HashTable *ht, const char *key, long *val ){  static bool hashGetLong( HashTable *ht, const char *key, long *val ){
406      zval         **tmp;          zval         **tmp;
407      if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){          if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
408          convert_to_long_ex( tmp );                  convert_to_long_ex( tmp );
409          *val = Z_LVAL_PP(tmp);                  *val = Z_LVAL_PP(tmp);
410          return true;                  return true;
411      }          }
412      return false;          return false;
413  }  }
414    
415  /** 連想配列にアクセスして文字列を得る。  /** 連想配列にアクセスして文字列を得る。
# Line 345  static bool hashGetLong( HashTable *ht, Line 419  static bool hashGetLong( HashTable *ht,
419    @return  成功ならtrue    @return  成功ならtrue
420   */   */
421  static bool hashGetString( HashTable *ht, const char *key, char **val ){  static bool hashGetString( HashTable *ht, const char *key, char **val ){
422      zval         **tmp;          zval         **tmp;
423      if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){          if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
424          convert_to_string_ex( tmp );                  convert_to_string_ex( tmp );
425          *val = Z_STRVAL_PP(tmp);                  *val = Z_STRVAL_PP(tmp);
426          return true;                  return true;
427      }          }
428      return false;          return false;
429  }  }
430    
431  /** 連想配列にアクセスしてdouble値を得る。  /** 連想配列にアクセスしてdouble値を得る。
# Line 361  static bool hashGetString( HashTable *ht Line 435  static bool hashGetString( HashTable *ht
435    @return  成功ならtrue    @return  成功ならtrue
436   */   */
437  static bool hashGetDouble( HashTable *ht, const char *key, double *val ){  static bool hashGetDouble( HashTable *ht, const char *key, double *val ){
438      zval         **tmp;          zval         **tmp;
439      if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){          if( zend_hash_find( ht, (char *)key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
440          convert_to_double_ex( tmp );                  convert_to_double_ex( tmp );
441          *val = Z_DVAL_PP(tmp);                  *val = Z_DVAL_PP(tmp);
442          return true;                  return true;
443      }          }
444      return false;          return false;
445  }  }
446    
447  /** zval*からaccountを生成するためのクラス。 <br>  /** zval*からaccountを生成するためのクラス。 <br>
448      生成失敗ならgetResult()!=RES_OK <br>          生成失敗ならgetResult()!=RES_OK <br>
449    */    */
450  class zAccount_t : public account {  class zAccount_t : public account {
451  private:  private:
# Line 429  private: Line 503  private:
503          }          }
504  public:  public:
505          zAccount_t() : account(){ result = RES_ERROR; }          zAccount_t() : account(){ result = RES_ERROR; }
506        
507      /** コンストラクタ          /** コンストラクタ
508        @param pz  array( 'uid'=>1, 'uname'=>'root', ... ); こんな形の連想配列 */            @param pz  array( 'uid'=>1, 'uname'=>'root', ... ); こんな形の連想配列 */
509          zAccount_t( zval *pz ) : account(){ initialize(pz); }          zAccount_t( zval *pz ) : account(){ initialize(pz); }
510          zAccount_t( zval **ppz ) : account() { initialize(*ppz); }          zAccount_t( zval **ppz ) : account() { initialize(*ppz); }
511          result_t getResult(){ return result; };          result_t getResult(){ return result; };
# Line 440  public: Line 514  public:
514  class zIndex_t : public index {  class zIndex_t : public index {
515  private:  private:
516          result_t result;          result_t result;
517            
518          void initialize(zval *pz){          void initialize(zval *pz){
519                  HashTable *ht = Z_ARRVAL_P(pz);                  HashTable *ht = Z_ARRVAL_P(pz);
520                  long l;                  long l;
# Line 467  public: Line 541  public:
541          zIndex_t( zval *pz ) : index(){ initialize(pz); }          zIndex_t( zval *pz ) : index(){ initialize(pz); }
542          zIndex_t( zval **ppz ) : index() { initialize(*ppz); }          zIndex_t( zval **ppz ) : index() { initialize(*ppz); }
543          result_t getResult(){ return result; };          result_t getResult(){ return result; };
544            
545          void dump(){          void dump(){
546          }          }
547  };  };
548    
549  /** zval*から(userid_t *puid,int uidLen)を生成するためのクラス。 <br>  /** zval*から(userid_t *puid,int uidLen)を生成するためのクラス。 <br>
550      生成失敗ならgetResult()!=RES_OK <br>          生成失敗ならgetResult()!=RES_OK <br>
551    */    */
552  class zUIDs_t {  class zUIDs_t {
553  private:  private:
# Line 486  public: Line 560  public:
560                  len = 0;                  len = 0;
561                  result = RES_ERROR;                  result = RES_ERROR;
562          }          }
563            
564      /** コンストラクタ          /** コンストラクタ
565        @param pza  array( '1', '3', '4', '6', ... ); こんな形の配列 */            @param pza  array( '1', '3', '4', '6', ... ); こんな形の配列 */
566          zUIDs_t( zval *pza ){          zUIDs_t( zval *pza ){
567                  pUID = 0;                  pUID = 0;
568                  len = 0;                  len = 0;
569                  result = RES_ERROR;                  result = RES_ERROR;
570                    
571                  if ( Z_TYPE_P(pza) != IS_ARRAY ){                  if ( Z_TYPE_P(pza) != IS_ARRAY ){
572                          result = RES_ERROR;                          result = RES_ERROR;
573                  }                  }
# Line 511  public: Line 585  public:
585                                  HashPosition   pos;                                  HashPosition   pos;
586                                  int i = 0;                                  int i = 0;
587                                  pUID = new userid_t[len];                                  pUID = new userid_t[len];
588                                    
589                                  zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);                                  zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
590                                  while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {                                  while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
591                                          SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html 参照                                          SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html 参照
# Line 525  public: Line 599  public:
599                          }                          }
600                  }                  }
601          }          }
602            
603          ~zUIDs_t(){          ~zUIDs_t(){
604                  if ( pUID ) delete[] pUID;                  if ( pUID ) delete[] pUID;
605          }          }
# Line 533  public: Line 607  public:
607          userid_t *getPUID(){ return pUID; }          userid_t *getPUID(){ return pUID; }
608          int getLen(){ return len; }          int getLen(){ return len; }
609          void dump(){          void dump(){
610                  zend_printf( "dumping zUIDs...<br>\n" );          zend_printf( "dumping zUIDs...<br>\n" );
611                  zend_printf( "result=%d<br>\n", (int)result );                  zend_printf( "result=%d<br>\n", (int)result );
612                  zend_printf( "len=%d<br>\n", len );                  zend_printf( "len=%d<br>\n", len );
613                  for ( int i = 0; i < len; i++ ){                  for ( int i = 0; i < len; i++ ){
# Line 542  public: Line 616  public:
616          }          }
617  };  };
618    
619    /** zval*から(itemid_t *piid,int iidLen)を生成するためのクラス。 <br>
620            生成失敗ならgetResult()!=RES_OK <br>
621      */
622    class zIIDs_t {
623    private:
624            result_t result;
625            itemid_t *pIID;
626            int len;
627    public:
628            zIIDs_t(){
629                    pIID = 0;
630                    len = 0;
631                    result = RES_ERROR;
632            }
633    
634            /** コンストラクタ
635              @param pza  array( '1', '3', '4', '6', ... ); こんな形の配列 */
636            zIIDs_t( zval *pza ){
637                    pIID = 0;
638                    len = 0;
639                    result = RES_ERROR;
640    
641                    if ( Z_TYPE_P(pza) != IS_ARRAY ){
642                            result = RES_ERROR;
643                    }
644                    else {
645                            len = zend_hash_num_elements(Z_ARRVAL_P(pza));
646                            if(len == 0) {
647                                    pIID = new itemid_t[1];
648                                    result = RES_OK;
649                            }
650                            else {
651                                    /* php/ext/standard/string.c の implodeのあたりを参考に。
652                                       zend_hash_*のドキュメントってあるのだろうか?
653                                    */
654                                    zval         **tmp;
655                                    HashPosition   pos;
656                                    int i = 0;
657                                    pIID = new itemid_t[len];
658    
659                                    zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pza), &pos);
660                                    while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pza), (void **) &tmp, &pos) == SUCCESS ) {
661                                            SEPARATE_ZVAL(tmp); // zend.arguments.write-safety.html 参照
662                                            convert_to_long_ex(tmp);
663                                            if ( i < len )
664                                                    pIID[i++] = Z_LVAL_PP(tmp);
665                                            zend_hash_move_forward_ex(Z_ARRVAL_P(pza), &pos);
666                                    }
667                                    len = i;
668                                    result = RES_OK;
669                            }
670                    }
671            }
672    
673            ~zIIDs_t(){
674                    if ( pIID ) delete[] pIID;
675            }
676            result_t getResult(){ return result; }
677            itemid_t *getPIID(){ return pIID; }
678            int getLen(){ return len; }
679            void dump(){
680            zend_printf( "dumping zIIDs...<br>\n" );
681                    zend_printf( "result=%d<br>\n", (int)result );
682                    zend_printf( "len=%d<br>\n", len );
683                    for ( int i = 0; i < len; i++ ){
684                            zend_printf( "pIID[%d] = %d<br>\n", i, pIID[i] );
685                    }
686            }
687    };
688    
689    /**
690     *
691     * amazonbook_tの内容をPHPの配列に変換する
692     * @param pAmazonbook 変換元のamazonbook_t*
693     * @param z        変換結果を書き込む配列(初期化済みであること)
694     * @return RES_OK
695     *
696     */
697    result_t amazonbookToZval( const amazonbook_t *pAmazonbook, zval *z )
698    {
699            zend_hash_clean( z -> value.ht );
700            
701            add_assoc_string( z, "title", ( char* )pAmazonbook -> getTitle( ), 1 );
702            add_assoc_string( z, "author", ( char* )pAmazonbook -> getAuthor( ), 1 );
703            add_assoc_string( z, "publisher", ( char* )pAmazonbook -> getPublisher( ), 1 );
704            add_assoc_long( z, "year_of_publication", pAmazonbook -> getYearOfPublication( ) );
705            add_assoc_string( z, "isbn", ( char* )pAmazonbook -> getISBN( ), 1 );
706            add_assoc_string( z, "url", ( char* )pAmazonbook -> getURL( ), 1 );
707            
708            return RES_OK;
709    }
710    
711    /**
712     *
713     * pubmed_tの内容をPHPの配列に変換する
714     * @param pPubmed 変換元のpubmed_t*
715     * @param z        変換結果を書き込む配列(初期化済みであること)
716     * @return RES_OK
717     *
718     */
719    result_t pubmedToZval( const pubmed_t *pPubmed, zval *z )
720    {
721            zend_hash_clean( z -> value.ht );
722            
723            add_assoc_long( z, "pmid", pPubmed -> getID( ) );
724            add_assoc_string( z, "title", ( char* )pPubmed -> getTitle( ), 1 );
725            add_assoc_string( z, "author", ( char* )pPubmed -> getAuthor( ), 1 );
726            add_assoc_string( z, "journal", ( char* )pPubmed -> getJournal( ), 1 );
727            add_assoc_long( z, "year_of_publication", pPubmed -> getYearOfPublication( ) );
728            add_assoc_long( z, "volume", pPubmed -> getVolume( ) );
729            add_assoc_long( z, "number", pPubmed -> getNumber( ) );
730            add_assoc_string( z, "page", ( char* )pPubmed -> getPage( ), 1 );
731            add_assoc_string( z, "abstract", ( char* )pPubmed -> getAbstract( ), 1 );
732            
733            return RES_OK;
734    }
735    
736  /**  /**
737   *   *
738     * itemid_tの配列をPHPの配列に変換する
739     * @param piid 変換元のitemid_tの配列
740     * @param len  piidの配列の長さ
741     * @param ppz  変換結果を書き込む配列(初期化済みであること)
742     * @return RES_OK
743     *
744     */
745    result_t itemidsToZval( itemid_t *piid, int len, zval **ppz )
746    {
747            zend_hash_clean( Z_ARRVAL_PP(ppz) );
748    
749            // add GIDs
750            for ( int i = 0; i < len; i++ ){
751                    add_next_index_long(*ppz, (long)(piid[i]) );
752            }
753    
754            return RES_OK;
755    }
756    
757    /**
758     *
759   * uids_tの配列をPHPの配列に変換する   * uids_tの配列をPHPの配列に変換する
760   *   *
761   * @param pUID 変換元のuserid_tの配列   * @param pUID 変換元のuserid_tの配列
762   * @param len pUIDの配列の長さ   * @param len pUIDの配列の長さ
763   * @param pz 変換結果を書き込む配列(初期化済みであること)   * @param pz 変換結果を書き込む配列(初期化済みであること)
764   * @return RES_OK   * @return RES_OK
765   *   *
766   */   */
767  result_t uidsToZval( userid_t *pUID, int len, zval **ppz )  result_t uidsToZval( userid_t *pUID, int len, zval **ppz )
768  {  {
769      zend_hash_clean( Z_ARRVAL_PP(ppz) );          zend_hash_clean( Z_ARRVAL_PP(ppz) );
770            
771          // add UIDs          // add UIDs
772          for ( int i = 0; i < len; i++ ){          for ( int i = 0; i < len; i++ ){
773                  add_next_index_long(*ppz, (long)(pUID[i]) );                  add_next_index_long(*ppz, (long)(pUID[i]) );
774          }          }
775            
776          return RES_OK;          return RES_OK;
777  }  }
778    
779  /**  /**
780   *   *
781   * groupid_tの配列をPHPの配列に変換する   * groupid_tの配列をPHPの配列に変換する
# Line 574  result_t uidsToZval( userid_t *pUID, int Line 787  result_t uidsToZval( userid_t *pUID, int
787   */   */
788  result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )  result_t gidsToZval( groupid_t *pGID, int len, zval **ppz )
789  {  {
790      zend_hash_clean( Z_ARRVAL_PP(ppz) );          zend_hash_clean( Z_ARRVAL_PP(ppz) );
791            
792          // add GIDs          // add GIDs
793          for ( int i = 0; i < len; i++ ){          for ( int i = 0; i < len; i++ ){
794                  add_next_index_long(*ppz, (long)(pGID[i]) );                  add_next_index_long(*ppz, (long)(pGID[i]) );
795          }          }
796            
797            return RES_OK;
798    }
799    
800    /**
801     *
802     * changelog_tの内容をPHPの配列に変換する
803     * @param pChangelog 変換元のchangelog_t*
804     * @param z        変換結果を書き込む配列(初期化済みであること)
805     * @return RES_OK
806     *
807     */
808    result_t changelogToZval( const changelog_t *pChangelog, zval *z )
809    {
810            zend_hash_clean( z -> value.ht );
811    
812            add_assoc_long( z, "log_id", pChangelog -> getChangelogID( ) );
813            add_assoc_long( z, "item_id", pChangelog -> getItemID( ) );
814            add_assoc_long( z, "log_date", pChangelog -> getDate( ) );
815            add_assoc_string( z, "log", ( char* )pChangelog -> getLog( ), 1 );
816    
817          return RES_OK;          return RES_OK;
818  }  }
819    
820    /**
821     *
822     * item_tの内容をPHPの配列に変換する
823     * @param pItem 変換元のitem_t*
824     * @param z        変換結果を書き込む配列(初期化済みであること)
825     * @return RES_OK
826     *
827     */
828    result_t itemToZval( const item_t *pItem, zval *z )
829    {
830            zend_hash_clean( z -> value.ht );
831    
832            add_assoc_long( z, "item_id", pItem -> getItemID( ) );
833            add_assoc_long( z, "item_type_id", pItem -> getItemTypeID( ) );
834            add_assoc_long( z, "uid", pItem -> getContributorUID( ) );
835            add_assoc_string( z, "title", ( char* )pItem -> getTitle( ), 1 );
836            add_assoc_string( z, "keywords", ( char* )pItem -> getKeywords( ), 1 );
837            add_assoc_string( z, "description", ( char* )pItem -> getDescription( ), 1 );
838            add_assoc_string( z, "doi", ( char* )pItem -> getDOI( ), 1 );
839            add_assoc_long( z, "last_update_date", pItem -> getLastUpdateDate( ) );
840            add_assoc_long( z, "creation_date", pItem -> getCreationDate( ) );
841    
842            return RES_OK;
843    }
844    
845    
846    result_t itemsToZval( const item_t *pItems, int itemsLen, zval *z )
847    {
848            zend_hash_clean( z -> value.ht );
849            for( int i = 0; i < itemsLen; i++ ){
850                    zval *new_array;
851                    MAKE_STD_ZVAL(new_array);
852                    if(array_init(new_array) != SUCCESS){
853                            return RES_ERROR;
854                    }
855                    add_index_zval( z, i, new_array );
856                    itemToZval( &pItems[ i ], new_array );
857            }
858            return RES_OK;
859    }
860    
861    /**
862     *
863     * PHPの連想配列の内容をgroup_tに変換する
864     *
865     * @param z 変換元の連想配列
866     * @param pGroup 変換結果を書き込むグループ
867     * @return RES_OK
868     *
869     */
870    result_t zvalToItem( zval *z, item_t* pItem )
871    {
872            zval         **tmp;
873            HashPosition   pos;
874            int i = 0;
875            char* key = 0;
876    
877            key = "item_id";
878            if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
879                    convert_to_long_ex( tmp ) ;
880                    pItem -> setItemID( (*tmp) -> value.lval );
881            }
882            key = "item_type_id";
883            if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
884                    convert_to_long_ex( tmp ) ;
885                    pItem -> setItemTypeID( (*tmp) -> value.lval );
886            }
887            key = "uid";
888            if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
889                    convert_to_long_ex( tmp ) ;
890                    pItem -> setContributorUID( (*tmp) -> value.lval );
891            }
892            key = "title";
893            if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
894                    convert_to_string_ex( tmp ) ;
895                    pItem -> setTitle( (*tmp) -> value.str.val );
896            }
897            key = "keywords";
898            if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
899                    convert_to_string_ex( tmp ) ;
900                    pItem -> setKeywords( (*tmp) -> value.str.val );
901            }
902            key = "description";
903            if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
904                    convert_to_string_ex( tmp ) ;
905                    pItem -> setDescription( (*tmp) -> value.str.val );
906            }
907            key = "doi";
908            if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
909                    convert_to_string_ex( tmp ) ;
910                    pItem -> setDOI( (*tmp) -> value.str.val );
911            }
912            key = "last_update_date";
913            if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
914                    convert_to_long_ex( tmp ) ;
915                    pItem -> setLastUpdateDate( (*tmp) -> value.lval );
916            }
917            key = "creation_date";
918            if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
919                    convert_to_long_ex( tmp ) ;
920                    pItem -> setCreationDate( (*tmp) -> value.lval );
921            }
922            return RES_OK;
923    }
924    
925  /**  /**
926   *   *
# Line 595  result_t gidsToZval( groupid_t *pGID, in Line 932  result_t gidsToZval( groupid_t *pGID, in
932   */   */
933  result_t accountToZval( const account_t *pAccount, zval *z )  result_t accountToZval( const account_t *pAccount, zval *z )
934  {  {
935      zend_hash_clean( z -> value.ht );          zend_hash_clean( z -> value.ht );
936        
937      add_assoc_long( z, "uid", pAccount -> getUID( ) );          add_assoc_long( z, "uid", pAccount -> getUID( ) );
938      add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );          add_assoc_string( z, "uname", ( char* )pAccount -> getUname( ), 1 );
939      add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );          add_assoc_string( z, "name", ( char* )pAccount -> getName( ), 1 );
940      add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );          add_assoc_string( z, "email", ( char* )pAccount -> getEmail( ), 1 );
941      add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );          add_assoc_string( z, "url", ( char* )pAccount -> getURL( ), 1 );
942      add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );          add_assoc_string( z, "user_avatar", ( char* )pAccount -> getUserAvatar( ), 1 );
943      add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );          add_assoc_string( z, "user_icq", ( char* )pAccount -> getUserIcq( ), 1 );
944      add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );          add_assoc_string( z, "user_from", ( char* )pAccount -> getUserFrom( ), 1 );
945      add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );          add_assoc_string( z, "user_sig", ( char* )pAccount -> getUserSig( ), 1 );
946      add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );          add_assoc_string( z, "actkey", ( char* )pAccount -> getActkey( ), 1 );
947      add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );          add_assoc_string( z, "user_aim", ( char* )pAccount -> getUserAim( ), 1 );
948      add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );          add_assoc_string( z, "user_yim", ( char* )pAccount -> getUserYim( ), 1 );
949      add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );          add_assoc_string( z, "user_msnm", ( char* )pAccount -> getUserMsnm( ), 1 );
950      add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );          add_assoc_string( z, "pass", ( char* )pAccount -> getPass( ), 1 );
951      add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );          add_assoc_string( z, "theme", ( char* )pAccount -> getTheme( ), 1 );
952      add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );          add_assoc_string( z, "umode", ( char* )pAccount -> getUmode( ), 1 );
953      add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );          add_assoc_string( z, "user_occ", ( char* )pAccount -> getUserOcc( ), 1 );
954      add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );          add_assoc_string( z, "bio", ( char* )pAccount -> getBio( ), 1 );
955      add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );          add_assoc_string( z, "user_intrest", ( char* )pAccount -> getUserIntrest( ), 1 );
956      add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );          add_assoc_double( z, "timezone_offset", pAccount -> getTimezoneOffset( ) );
957      add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );          add_assoc_long( z, "attachsig", pAccount -> getAttachsig( ) );
958      add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );          add_assoc_long( z, "last_login", pAccount -> getLastLogin( ) );
959      add_assoc_long( z, "level", pAccount -> getLevel( ) );          add_assoc_long( z, "level", pAccount -> getLevel( ) );
960      add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );          add_assoc_long( z, "notify_method", pAccount -> getNotifyMethod( ) );
961      add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );          add_assoc_long( z, "notify_mode", pAccount -> getNotifyMode( ) );
962      add_assoc_long( z, "posts", pAccount -> getPosts( ) );          add_assoc_long( z, "posts", pAccount -> getPosts( ) );
963      add_assoc_long( z, "rank", pAccount -> getRank( ) );          add_assoc_long( z, "rank", pAccount -> getRank( ) );
964      add_assoc_long( z, "uorder", pAccount -> getUorder( ) );          add_assoc_long( z, "uorder", pAccount -> getUorder( ) );
965      add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );          add_assoc_long( z, "user_mailok", pAccount -> getUserMailok( ) );
966      add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );          add_assoc_long( z, "user_regdate", pAccount -> getUserRegdate( ) );
967      add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );          add_assoc_long( z, "user_viewemail", pAccount -> getUserViewemail( ) );
968        
969      add_assoc_long( z, "activate", pAccount -> getActivate( ) );          add_assoc_long( z, "activate", pAccount -> getActivate( ) );
970      add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );          add_assoc_string( z, "address", ( char* )pAccount -> getAddress( ), 1 );
971      add_assoc_string( z, "division", ( char* )pAccount -> getDivision( ), 1 );          add_assoc_string( z, "division", ( char* )pAccount -> getDivision( ), 1 );
972      add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );          add_assoc_string( z, "tel", ( char* )pAccount -> getTel( ), 1 );
973      add_assoc_string( z, "company_name", ( char* )pAccount -> getCompanyName( ), 1 );          add_assoc_string( z, "company_name", ( char* )pAccount -> getCompanyName( ), 1 );
974      add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );          add_assoc_string( z, "country", ( char* )pAccount -> getCountry( ), 1 );
975      add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );          add_assoc_string( z, "zipcode", ( char* )pAccount -> getZipcode( ), 1 );
976      add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );          add_assoc_string( z, "fax", ( char* )pAccount -> getFax( ), 1 );
977      add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );          add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
978      add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );          add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
979      add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );          add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
980      add_assoc_long( z, "private_index_id", pAccount -> getPrivateIndexID( ) );          add_assoc_long( z, "private_index_id", pAccount -> getPrivateIndexID( ) );
981          return RES_OK;          return RES_OK;
982  }  }
983    
984  /**  /**
985   *   *
986   * 複数のaccount_tの内容をPHPの配列の配列に変換する   * 複数のaccount_tの内容をPHPの配列の配列に変換する
# Line 652  result_t accountToZval( const account_t Line 990  result_t accountToZval( const account_t
990   * @return RES_OK   * @return RES_OK
991   *   *
992    z: こんな感じの配列になる。↓ <br>    z: こんな感じの配列になる。↓ <br>
993      array(          array(
994        array(            array(
995          'uid'=>100,                  'uid'=>100,
996          'activate'=>1,                  'activate'=>1,
997          'division'=>'foo',                  'division'=>'foo',
998          'tel'=>'123-456-789',                  'tel'=>'123-456-789',
999          ...                  ...
1000        ),            ),
1001        ...            ...
1002      )          )
1003   */   */
1004  result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )  result_t accountsToZval( const account_t *pAccounts, int accountsLen, zval *z )
1005  {  {
1006      zend_hash_clean( z -> value.ht );          zend_hash_clean( z -> value.ht );
1007      for( int i = 0; i < accountsLen; i++ ){          for( int i = 0; i < accountsLen; i++ ){
1008          zval *new_array;                  zval *new_array;
1009          MAKE_STD_ZVAL(new_array);                  MAKE_STD_ZVAL(new_array);
1010          if(array_init(new_array) != SUCCESS){                  if(array_init(new_array) != SUCCESS){
1011              return RES_ERROR;                          return RES_ERROR;
1012          }                  }
1013          add_index_zval( z, i, new_array );                  add_index_zval( z, i, new_array );
1014          accountToZval( &pAccounts[ i ], new_array );                  accountToZval( &pAccounts[ i ], new_array );
1015      }          }
1016          return RES_OK;          return RES_OK;
1017  }  }
1018    
# Line 687  result_t accountsToZval( const account_t Line 1025  result_t accountsToZval( const account_t
1025   * @return RES_OK   * @return RES_OK
1026   *   *
1027    z: こんな感じの配列になる。↓ <br>    z: こんな感じの配列になる。↓ <br>
1028      array(          array(
1029        array(            array(
1030          'gid'=>1,                  'gid'=>1,
1031          'gname'=>'foo group',                  'gname'=>'foo group',
1032          'gdesc'=>'group of foo'                  'gdesc'=>'group of foo'
1033        ),            ),
1034        ...            ...
1035      )          )
1036   */   */
1037  result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )  result_t groupsToZval( const group_t *pGroups, int groupsLen, zval *z )
1038  {  {
1039      zend_hash_clean( z -> value.ht );          zend_hash_clean( z -> value.ht );
1040      for( int i = 0; i < groupsLen; i++ ){          for( int i = 0; i < groupsLen; i++ ){
1041          zval *new_array;                  zval *new_array;
1042          MAKE_STD_ZVAL(new_array);                  MAKE_STD_ZVAL(new_array);
1043          if(array_init(new_array) != SUCCESS){                  if(array_init(new_array) != SUCCESS){
1044              return RES_ERROR;                          return RES_ERROR;
1045          }                  }
1046          add_index_zval( z, i, new_array );                  add_index_zval( z, i, new_array );
1047          add_assoc_long( new_array, "gid",  pGroups[ i ].getGID( ) );                  add_assoc_long( new_array, "gid",  pGroups[ i ].getGID( ) );
1048          add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );                  add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
1049          add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );                  add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
1050          add_assoc_long( new_array, "group_index_id",  pGroups[ i ].getGroupIndexID( ) );                  add_assoc_long( new_array, "group_index_id",  pGroups[ i ].getGroupIndexID( ) );
1051      }          }
1052          return RES_OK;          return RES_OK;
1053  }  }
1054    
1055  /**  /**
1056   *   *
1057   * group_tの内容をPHPの連想配列に変換する   * group_tの内容をPHPの連想配列に変換する
1058   *   *
1059   * @param pGroup 変換元のグループ情報   * @param pGroup 変換元のグループ情報
1060   * @param z 変換結果を書き込む連想配列(初期化済みであること)   * @param z 変換結果を書き込む連想配列(初期化済みであること)
1061   * @return RES_OK   * @return RES_OK
1062   *   *
1063   */   */
1064  result_t groupToZval( const group_t *pGroup, zval *z )  result_t groupToZval( const group_t *pGroup, zval *z )
1065  {  {
1066      zend_hash_clean( z -> value.ht );          zend_hash_clean( z -> value.ht );
1067      add_assoc_long( z, "gid",  pGroup -> getGID( ) );          add_assoc_long( z, "gid",  pGroup -> getGID( ) );
1068      add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );          add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
1069      add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );          add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
1070      add_assoc_long( z, "group_index_id",  pGroup -> getGroupIndexID( ) );          add_assoc_long( z, "group_index_id",  pGroup -> getGroupIndexID( ) );
1071          return RES_OK;          return RES_OK;
1072  }  }
1073    
1074  /**  /**
1075   *   *
1076   * PHPの連想配列の内容をgroup_tに変換する   * PHPの連想配列の内容をgroup_tに変換する
1077   *   *
1078   * @param z 変換元の連想配列   * @param z 変換元の連想配列
1079   * @param pGroup 変換結果を書き込むグループ   * @param pGroup 変換結果を書き込むグループ
1080   * @return RES_OK   * @return RES_OK
1081   *   *
1082   */   */
1083  result_t zvalToGroup( zval *z, group_t *pGroup )  result_t zvalToGroup( zval *z, group_t *pGroup )
1084  {  {
1085      zval         **tmp;          zval         **tmp;
1086      HashPosition   pos;          HashPosition   pos;
1087      int i = 0;          int i = 0;
1088      char* key = 0;          char* key = 0;
1089        
1090      key = "gid";          key = "gid";
1091      if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){          if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1092          convert_to_long_ex( tmp ) ;                  convert_to_long_ex( tmp ) ;
1093          pGroup -> setGID( (*tmp) -> value.lval );                  pGroup -> setGID( (*tmp) -> value.lval );
1094      }              }
1095      key = "gname";          key = "gname";
1096      if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){          if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1097          convert_to_string_ex( tmp ) ;                  convert_to_string_ex( tmp ) ;
1098          pGroup -> setGname( (*tmp) -> value.str.val );                  pGroup -> setGname( (*tmp) -> value.str.val );
1099      }              }
1100      key = "gdesc";          key = "gdesc";
1101      if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){          if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1102          convert_to_string_ex( tmp ) ;                  convert_to_string_ex( tmp ) ;
1103          pGroup -> setDesc( (*tmp) -> value.str.val );                  pGroup -> setDesc( (*tmp) -> value.str.val );
1104      }          }
1105      key = "group_index_id";          key = "group_index_id";
1106      if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){          if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
1107          convert_to_long_ex( tmp ) ;                  convert_to_long_ex( tmp ) ;
1108          pGroup -> setGroupIndexID( (*tmp) -> value.lval );                  pGroup -> setGroupIndexID( (*tmp) -> value.lval );
1109      }              }
1110          return RES_OK;          return RES_OK;
1111  }  }
1112    
1113  /**  /**
1114   *   *
1115   * session_tの内容をPHPの連想配列に変換する   * session_tの内容をPHPの連想配列に変換する
1116   *   *
1117   * @param pSession 変換元のsession_t   * @param pSession 変換元のsession_t
1118   * @param z 変換結果を書き込む連想配列(初期化済みであること)   * @param z 変換結果を書き込む連想配列(初期化済みであること)
1119   * @return RES_OK   * @return RES_OK
1120   *   *
1121   */   */
1122  result_t sessionToZval( const session_t *pSession, zval *z )  result_t sessionToZval( const session_t *pSession, zval *z )
1123  {  {
1124          string sessionID(unsignedIntToString(pSession->getSessionID()));          string sessionID(unsignedIntToString(pSession->getSessionID()));
1125          add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);          add_assoc_string(z, "session_id", (char *)sessionID.c_str(), 1);
1126            
1127          string date(unsignedIntToString((unsigned int)pSession->getDate()));          string date(unsignedIntToString((unsigned int)pSession->getDate()));
1128          add_assoc_string(z, "date", (char *)date.c_str(), 1);          add_assoc_string(z, "date", (char *)date.c_str(), 1);
1129            
1130          string userID(unsignedIntToString((unsigned int)pSession->getUID()));          string userID(unsignedIntToString((unsigned int)pSession->getUID()));
1131          add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);          add_assoc_string(z, "user_id", (char *)userID.c_str(), 1);
1132            
1133          return RES_OK;          return RES_OK;
1134  }  }
1135    
# Line 805  result_t sessionToZval( const session_t Line 1143  result_t sessionToZval( const session_t
1143   */   */
1144  result_t indexToZval( const index_t *pIndex, zval *z )  result_t indexToZval( const index_t *pIndex, zval *z )
1145  {  {
1146      zend_hash_clean( z -> value.ht );          zend_hash_clean( z -> value.ht );
1147        
1148      add_assoc_long( z, "item_id", pIndex -> getItemID( ) );          add_assoc_long( z, "item_id", pIndex -> getItemID( ) );
1149      add_assoc_long( z, "item_type_id", pIndex -> getItemTypeID( ) );          add_assoc_long( z, "item_type_id", pIndex -> getItemTypeID( ) );
1150      add_assoc_long( z, "contributor_uid", pIndex -> getContributorUID( ) );          add_assoc_long( z, "contributor_uid", pIndex -> getContributorUID( ) );
1151      add_assoc_string( z, "title", ( char* )pIndex -> getTitle( ), 1 );          add_assoc_string( z, "title", ( char* )pIndex -> getTitle( ), 1 );
1152      add_assoc_string( z, "keywords", ( char* )pIndex -> getKeywords( ), 1 );          add_assoc_string( z, "keywords", ( char* )pIndex -> getKeywords( ), 1 );
1153      add_assoc_string( z, "description", ( char* )pIndex -> getDescription( ), 1 );          add_assoc_string( z, "description", ( char* )pIndex -> getDescription( ), 1 );
1154      add_assoc_long( z, "last_update_date", pIndex -> getLastUpdateDate( ) );          add_assoc_long( z, "last_update_date", pIndex -> getLastUpdateDate( ) );
1155      add_assoc_long( z, "creation_date", pIndex-> getCreationDate( ) );          add_assoc_long( z, "creation_date", pIndex-> getCreationDate( ) );
1156      add_assoc_long( z, "parent_index_id", pIndex -> getParentIndexID( ) );          add_assoc_long( z, "parent_index_id", pIndex -> getParentIndexID( ) );
1157      add_assoc_long( z, "owner_uid", pIndex -> getOwnerUID( ) );          add_assoc_long( z, "owner_uid", pIndex -> getOwnerUID( ) );
1158      add_assoc_long( z, "owner_gid", pIndex -> getOwnerGID( ) );          add_assoc_long( z, "owner_gid", pIndex -> getOwnerGID( ) );
1159      add_assoc_long( z, "open_level", pIndex -> getOpenLevel( ) );          add_assoc_long( z, "open_level", pIndex -> getOpenLevel( ) );
1160      add_assoc_long( z, "sort_number", pIndex -> getSortNumber( ) );          add_assoc_long( z, "sort_number", pIndex -> getSortNumber( ) );
1161          return RES_OK;          return RES_OK;
1162  }  }
1163    
1164  result_t indexesToZval( const index_t *pIndexes, int indexesLen, zval *z )  result_t indexesToZval( const index_t *pIndexes, int indexesLen, zval *z )
1165  {  {
1166      zend_hash_clean( z -> value.ht );          zend_hash_clean( z -> value.ht );
1167      for( int i = 0; i < indexesLen; i++ ){          for( int i = 0; i < indexesLen; i++ ){
1168          zval *new_array;                  zval *new_array;
1169          MAKE_STD_ZVAL(new_array);                  MAKE_STD_ZVAL(new_array);
1170          if(array_init(new_array) != SUCCESS){                  if(array_init(new_array) != SUCCESS){
1171              return RES_ERROR;                          return RES_ERROR;
1172          }                  }
1173          add_index_zval( z, i, new_array );                  add_index_zval( z, i, new_array );
1174          indexToZval( &pIndexes[ i ], new_array );                  indexToZval( &pIndexes[ i ], new_array );
1175      }          }
1176          return RES_OK;          return RES_OK;
1177  }  }
1178    
# Line 842  result_t indexesToZval( const index_t *p Line 1180  result_t indexesToZval( const index_t *p
1180    
1181    
1182  /** 指定したグループの情報を得る<br>  /** 指定したグループの情報を得る<br>
1183      int xnp_get_group( int sid, int gid, array group );          int xnp_get_group( int sid, int gid, array group );
1184      @param sid    XNPのセッションID          @param sid    XNPのセッションID
1185      @param gid    XNP の group_id          @param gid    XNP の group_id
1186      @param group  結果を受け取る配列          @param group  結果を受け取る配列
1187      @return 0 success <br>          @return 0 success <br>
1188    */    */
1189  ZEND_FUNCTION(xnp_get_group)  ZEND_FUNCTION(xnp_get_group)
1190  {  {
1191          long sid, gid;          long sid, gid;
1192          zval *zgroup;          zval *zgroup;
1193            
1194          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1195                                &sid, &gid, &zgroup) == FAILURE) {                                                            &sid, &gid, &zgroup) == FAILURE) {
1196                  return;                  return;
1197          }          }
1198            
1199          const group_t *pgroup;          const group_t *pgroup;
1200          result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );          result_t result = getGroup( (sessionid_t)sid, (groupid_t)gid, &pgroup );
1201          if ( RES_OK == result ){          if ( RES_OK == result ){
1202                  groupToZval( pgroup, zgroup );                  groupToZval( pgroup, zgroup );
1203                  freeGroup( pgroup );                  freeGroup( pgroup );
1204          }          }
1205            
1206      RETURN_LONG(result);          RETURN_LONG(result);
1207  }  }
1208    
1209    
1210  /** 指定したグループ(複数)の情報を得る<br>  /** 指定したグループ(複数)の情報を得る<br>
1211      xnp_get_groups( int sid, array gids, array criteria, array groups );          xnp_get_groups( int sid, array gids, array criteria, array groups );
1212      @param sid      XNPのセッションID          @param sid      XNPのセッションID
1213      @param gids     XNP の group_id の配列          @param gids     XNP の group_id の配列
1214      @param criteria 条件          @param criteria 条件
1215      @param groups   結果を受け取る配列の配列          @param groups   結果を受け取る配列の配列
1216      @return 0 success <br>          @return 0 success <br>
1217    */    */
1218  ZEND_FUNCTION(xnp_get_groups)  ZEND_FUNCTION(xnp_get_groups)
1219  {  {
# Line 884  ZEND_FUNCTION(xnp_get_groups) Line 1222  ZEND_FUNCTION(xnp_get_groups)
1222          zval *zcriteria;          zval *zcriteria;
1223          zval *zgids;          zval *zgids;
1224          zval *zgroups;          zval *zgroups;
1225      zval **ppzTmp = 0;          zval **ppzTmp = 0;
1226      HashPosition pos;          HashPosition pos;
1227      int res2;          int res2;
1228      int gidsLen;          int gidsLen;
1229      const group_t* groups;          const group_t* groups;
1230      int groupsLen;          int groupsLen;
1231        
1232          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1233                                &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {                                                            &sid, &zgids, &zcriteria, &zgroups) == FAILURE) {
1234                  return;                  return;
1235          }          }
1236            
1237      //gidsにグループIDをコピーする          //gidsにグループIDをコピーする
1238      gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));          gidsLen = zend_hash_num_elements(Z_ARRVAL_P(zgids));
1239      groupid_t *gids = new groupid_t[ gidsLen ];          groupid_t *gids = new groupid_t[ gidsLen ];
1240      zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);          zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zgids), &pos);
1241      for( int i = 0; i < gidsLen; i++ ){          for( int i = 0; i < gidsLen; i++ ){
1242          if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){                  if( (res2=zend_hash_get_current_data_ex(Z_ARRVAL_P(zgids), (void **)&ppzTmp, &pos)) == SUCCESS ){
1243              SEPARATE_ZVAL(ppzTmp);                          SEPARATE_ZVAL(ppzTmp);
1244              convert_to_long_ex(ppzTmp);                          convert_to_long_ex(ppzTmp);
1245              gids[ i ] = Z_LVAL_PP(ppzTmp);                          gids[ i ] = Z_LVAL_PP(ppzTmp);
1246          }                  }
1247          zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);                  zend_hash_move_forward_ex(Z_ARRVAL_P(zgids), &pos);
1248      }          }
1249        
1250          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
1251          result = zcri.getResult();          result = zcri.getResult();
1252          if ( RES_OK == result ){          if ( RES_OK == result ){
1253          result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );                  result = getGroups( (sessionid_t)sid, gids, gidsLen, &zcri, &groups, &groupsLen );
1254          if ( RES_OK == result ){                  if ( RES_OK == result ){
1255              groupsToZval( groups, groupsLen, zgroups );                          groupsToZval( groups, groupsLen, zgroups );
1256              delete[] gids;                          delete[] gids;
1257              freeGroup( groups );                          freeGroup( groups );
1258          }                  }
1259      }          }
1260      RETURN_LONG(result);          RETURN_LONG(result);
1261  }  }
1262    
1263    
1264  /** 指定したユーザがモデレータかどうかを調べる<br>  /** 指定したユーザがモデレータかどうかを調べる<br>
1265      int xnp_is_moderator(int sid, int uid)          int xnp_is_moderator(int sid, int uid)
1266      @param sid      XNPのセッションID          @param sid      XNPのセッションID
1267      @param uid      xoops の uid (xoops_users.uid)          @param uid      xoops の uid (xoops_users.uid)
1268      @return true  モデレータである <br>          @return true  モデレータである <br>
1269    */    */
1270  ZEND_FUNCTION(xnp_is_moderator)  ZEND_FUNCTION(xnp_is_moderator)
1271  {  {
1272          long xnpSessionID;          long xnpSessionID;
1273          userid_t uid;          userid_t uid;
1274            
1275          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1276                                &xnpSessionID, &uid) == FAILURE) {                                                            &xnpSessionID, &uid) == FAILURE) {
1277                  return;                  return;
1278          }          }
1279            
1280          bool result = isModerator( (sessionid_t)xnpSessionID, uid );          bool result = isModerator( (sessionid_t)xnpSessionID, uid );
1281      RETURN_BOOL(result)          RETURN_BOOL(result)
1282  }  }
1283    
1284  /** ユーザ名からuidを調べる<br>  /** ユーザ名からuidを調べる<br>
1285      int xnp_get_uid(string uname,int &uid)          int xnp_get_uid(string uname,int &uid)
1286      @param sid      XNPのセッションID          @param sid      XNPのセッションID
1287      @param uname    xoops の uname (xoops_users.uname)          @param uname    xoops の uname (xoops_users.uname)
1288      @param uid      xoops の uid (xoops_users.uid) を受け取る変数          @param uid      xoops の uid (xoops_users.uid) を受け取る変数
1289      @return 0 success          @return 0 success
1290    */    */
1291  ZEND_FUNCTION(xnp_get_uid)  ZEND_FUNCTION(xnp_get_uid)
1292  {  {
# Line 956  ZEND_FUNCTION(xnp_get_uid) Line 1294  ZEND_FUNCTION(xnp_get_uid)
1294          int unameLen;          int unameLen;
1295          zval *zuid;          zval *zuid;
1296          userid_t uid;          userid_t uid;
1297        
1298          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
1299            &uname, &unameLen, &zuid) == FAILURE) {            &uname, &unameLen, &zuid) == FAILURE) {
1300                  return;                  return;
1301          }          }
1302            
1303          if (!PZVAL_IS_REF(zuid)) {          if (!PZVAL_IS_REF(zuid)) {
1304                  zend_error(E_WARNING, "2nd parameter wasn't passed by reference");                  zend_error(E_WARNING, "2nd parameter wasn't passed by reference");
1305                  RETURN_LONG(RES_PHP_NONREF);                  RETURN_LONG(RES_PHP_NONREF);
1306          }          }
1307            
1308          string strUname( uname, unameLen );          string strUname( uname, unameLen );
1309          result_t result = getUid( strUname.c_str(), &uid );          result_t result = getUid( strUname.c_str(), &uid );
1310          ZVAL_LONG(zuid, (long)uid);          ZVAL_LONG(zuid, (long)uid);
# Line 976  ZEND_FUNCTION(xnp_get_uid) Line 1314  ZEND_FUNCTION(xnp_get_uid)
1314  ZEND_FUNCTION(xnp_test_criteria)  ZEND_FUNCTION(xnp_test_criteria)
1315  {  {
1316          zval *z;          zval *z;
1317            
1318          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
1319            &z) == FAILURE) {            &z) == FAILURE) {
1320                  return;                  return;
1321          }          }
# Line 990  ZEND_FUNCTION(xnp_test_criteria) Line 1328  ZEND_FUNCTION(xnp_test_criteria)
1328  ZEND_FUNCTION(xnp_test_uids)  ZEND_FUNCTION(xnp_test_uids)
1329  {  {
1330          zval *z;          zval *z;
1331            
1332          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
1333            &z) == FAILURE) {            &z) == FAILURE) {
1334                  return;                  return;
1335          }          }
# Line 1004  ZEND_FUNCTION(xnp_test_uids) Line 1342  ZEND_FUNCTION(xnp_test_uids)
1342    
1343    
1344  /** DBに接続する。既に接続中の接続は閉じられる。<br>  /** DBに接続する。既に接続中の接続は閉じられる。<br>
1345      int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );          int initialize_db( string host[, string user[, string password[, string dbname[, string prefix]]]] );
1346      @param host      接続先。省略時はNULL          @param host      接続先。省略時はNULL
1347      @param user      DB接続時のユーザ名。省略時はNULL          @param user      DB接続時のユーザ名。省略時はNULL
1348      @param password  DB接続時のパスワード。省略時はNULL          @param password  DB接続時のパスワード。省略時はNULL
1349      @param dbname    DB接続時のDB名。省略時は""          @param dbname    DB接続時のDB名。省略時は""
1350      @param prefix    XOOPS DB のprefix。          @param prefix    XOOPS DB のprefix。
1351      @return 0 success <br>          @return 0 success <br>
1352    */    */
1353  ZEND_FUNCTION(xnp_initialize_db)  ZEND_FUNCTION(xnp_initialize_db)
1354  {  {
# Line 1032  ZEND_FUNCTION(xnp_initialize_db) Line 1370  ZEND_FUNCTION(xnp_initialize_db)
1370    
1371          if (argNum < 1) host = NULL;          if (argNum < 1) host = NULL;
1372          else            host = getZvalString( parameters[0] );          else            host = getZvalString( parameters[0] );
1373            
1374          if (argNum < 2) user = NULL;          if (argNum < 2) user = NULL;
1375          else            user = getZvalString( parameters[1] );          else            user = getZvalString( parameters[1] );
1376            
1377          if (argNum < 3) password = NULL;          if (argNum < 3) password = NULL;
1378          else            password = getZvalString( parameters[2] );          else            password = getZvalString( parameters[2] );
1379            
1380          if (argNum < 4) dbname = "";          if (argNum < 4) dbname = "";
1381          else            dbname = getZvalString( parameters[3] );          else            dbname = getZvalString( parameters[3] );
1382            
1383          if (argNum < 5) prefix = "";          if (argNum < 5) prefix = "";
1384          else            prefix = getZvalString( parameters[4] );          else            prefix = getZvalString( parameters[4] );
1385            
1386          result_t result = initializeDB( host, user, password, dbname, prefix );          result_t result = initializeDB( host, user, password, dbname, prefix );
1387            
1388          RETURN_LONG(result);          RETURN_LONG(result);
1389  }  }
1390    
1391  /** ログインする。<br>  /** ログインする。<br>
1392      int xnp_login_user(string uname, string password, int &session_id)          int xnp_login_user(string uname, string password, int &session_id)
1393      @param uname      ユーザ名(xoops_users.uname)          @param uname      ユーザ名(xoops_users.uname)
1394      @param password   パスワード(md5(password)=xoops_users.pass)          @param password   パスワード(md5(password)=xoops_users.pass)
1395      @return 0 success          @return 0 success
1396    */    */
1397  ZEND_FUNCTION(xnp_login_user)  ZEND_FUNCTION(xnp_login_user)
1398  {  {
# Line 1063  ZEND_FUNCTION(xnp_login_user) Line 1401  ZEND_FUNCTION(xnp_login_user)
1401          char *passwd;          char *passwd;
1402          int passwdLen;          int passwdLen;
1403          zval *zXNPSessionID;          zval *zXNPSessionID;
1404            
1405          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",
1406            &uname, &unameLen, &passwd, &passwdLen, &zXNPSessionID) == FAILURE) {            &uname, &unameLen, &passwd, &passwdLen, &zXNPSessionID) == FAILURE) {
1407                  return;                  return;
1408          }          }
1409            
1410          if (!PZVAL_IS_REF(zXNPSessionID)) {          if (!PZVAL_IS_REF(zXNPSessionID)) {
1411                  zend_error(E_WARNING, "3rd parameter wasn't passed by reference");                  zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1412                  RETURN_LONG(RES_PHP_NONREF);                  RETURN_LONG(RES_PHP_NONREF);
1413          }          }
1414            
1415          sessionid_t xnpSessionID;          sessionid_t xnpSessionID;
1416          result_t result = loginUser( uname, passwd, &xnpSessionID );          result_t result = loginUser( uname, passwd, &xnpSessionID );
1417          if ( result == RES_OK )          if ( result == RES_OK )
# Line 1082  ZEND_FUNCTION(xnp_login_user) Line 1420  ZEND_FUNCTION(xnp_login_user)
1420  }  }
1421    
1422  /** ログアウトする。<br>  /** ログアウトする。<br>
1423      void xnp_logout_user(int xnp_session_id)          void xnp_logout_user(int xnp_session_id)
1424      @param xnp_session_id  XNPのセッションID          @param xnp_session_id  XNPのセッションID
1425      @return なし          @return なし
1426    */    */
1427  ZEND_FUNCTION(xnp_logout_user)  ZEND_FUNCTION(xnp_logout_user)
1428  {  {
1429          long xnpSessionID;          long xnpSessionID;
1430            
1431          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &xnpSessionID) == FAILURE) {          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &xnpSessionID) == FAILURE) {
1432                  return;                  return;
1433          }          }
1434          logoutUser( (sessionid_t)xnpSessionID );          logoutUser( (sessionid_t)xnpSessionID );
1435            
1436      RETURN_NULL();          RETURN_NULL();
1437  }  }
1438    
1439  /** XNPのセッションID 作成<br>  /** XNPのセッションID 作成<br>
1440      int xnp_create_session( string xoops_sess_id, int uid, int &session )          int xnp_create_session( string xoops_sess_id, int uid, int &session )
1441      @param xoops_sess_id  xoopsのセッションID          @param xoops_sess_id  xoopsのセッションID
1442      @param uid  xoops の uid (xoops_users.uid)          @param uid  xoops の uid (xoops_users.uid)
1443      @param session  作成したXNPのsessionを受け取る変数          @param session  作成したXNPのsessionを受け取る変数
1444      @return 0 成功          @return 0 成功
1445    */    */
1446  ZEND_FUNCTION(xnp_create_session)  ZEND_FUNCTION(xnp_create_session)
1447  {  {
# Line 1111  ZEND_FUNCTION(xnp_create_session) Line 1449  ZEND_FUNCTION(xnp_create_session)
1449          int xoopsSessionIDLen;          int xoopsSessionIDLen;
1450          long uid;          long uid;
1451          zval *zXNPSessionID;          zval *zXNPSessionID;
1452            
1453          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz",
1454            &xoopsSessionID, &xoopsSessionIDLen, &uid, &zXNPSessionID) == FAILURE) {            &xoopsSessionID, &xoopsSessionIDLen, &uid, &zXNPSessionID) == FAILURE) {
1455                  return;                  return;
1456          }          }
1457            
1458          if (!PZVAL_IS_REF(zXNPSessionID)) {          if (!PZVAL_IS_REF(zXNPSessionID)) {
1459                  zend_error(E_WARNING, "3rd parameter wasn't passed by reference");                  zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1460                  RETURN_LONG(RES_PHP_NONREF);                  RETURN_LONG(RES_PHP_NONREF);
1461          }          }
1462            
1463          sessionid_t xnpSessionID = 0;          sessionid_t xnpSessionID = 0;
1464          result_t result = createSession( xoopsSessionID, (userid_t)uid, &xnpSessionID );          result_t result = createSession( xoopsSessionID, (userid_t)uid, &xnpSessionID );
1465          if ( result == RES_OK )          if ( result == RES_OK )
# Line 1130  ZEND_FUNCTION(xnp_create_session) Line 1468  ZEND_FUNCTION(xnp_create_session)
1468  }  }
1469    
1470  /** XNP の session の詳細情報を得る<br>  /** XNP の session の詳細情報を得る<br>
1471      int xnp_get_session( int xnp_session_id, array session_info )          int xnp_get_session( int xnp_session_id, array session_info )
1472      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1473      @param session_info  結果を受け取る配列          @param session_info  結果を受け取る配列
1474      @return 0 success          @return 0 success
1475    */    */
1476  ZEND_FUNCTION(xnp_get_session)  ZEND_FUNCTION(xnp_get_session)
1477  {  {
# Line 1149  ZEND_FUNCTION(xnp_get_session) Line 1487  ZEND_FUNCTION(xnp_get_session)
1487                  sessionToZval( session, sessionInfo );                  sessionToZval( session, sessionInfo );
1488                  freeSession( session );                  freeSession( session );
1489          }          }
1490            
1491          RETURN_LONG((long)result);          RETURN_LONG((long)result);
1492  }  }
1493    
1494  /** ユーザのactivate状態を取得する<br>  /** ユーザのactivate状態を取得する<br>
1495      bool xnp_is_activated( int xnp_session_id, int user_id )          bool xnp_is_activated( int xnp_session_id, int user_id )
1496      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1497      @param user_id  xoops_users.uid          @param user_id  xoops_users.uid
1498      @return 0 success          @return 0 success
1499    */    */
1500  ZEND_FUNCTION(xnp_is_activated)  ZEND_FUNCTION(xnp_is_activated)
1501  {  {
1502          long sid, uid;          long sid, uid;
1503            
1504          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sid, &uid) == FAILURE) {
1505                  return;                  return;
1506          }          }
1507            
1508          bool result = isActivated( (sessionid_t)sid, (userid_t)uid );          bool result = isActivated( (sessionid_t)sid, (userid_t)uid );
1509            
1510      RETURN_BOOL(result);          RETURN_BOOL(result);
1511  }  }
1512    
1513  /** activateする。<br>  /** activateする。<br>
1514      bool xnp_activate( int xnp_session_id, int user_id, bool activated )          bool xnp_activate( int xnp_session_id, int user_id, bool activated )
1515      @param xnp_session_id   xnp の session id          @param xnp_session_id   xnp の session id
1516      @param user_id   xoops_users.uid          @param user_id   xoops_users.uid
1517      @param activated  true:activate, false:inactivate          @param activated  true:activate, false:inactivate
1518      @return 0 success          @return 0 success
1519    */    */
1520  ZEND_FUNCTION(xnp_activate)  ZEND_FUNCTION(xnp_activate)
1521  {  {
1522          long sid, uid;          long sid, uid;
1523          bool activated;          bool activated;
1524            
1525          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llb",
1526            &sid, &uid, &activated) == FAILURE) {            &sid, &uid, &activated) == FAILURE) {
1527                  return;                  return;
1528          }          }
1529            
1530          result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );          result_t result = activate( (sessionid_t)sid, (userid_t)uid, activated );
1531            
1532      RETURN_LONG(result);          RETURN_LONG(result);
1533  }  }
1534    
1535  /** XNPのアカウント数を得る。<br>  /** XNPのアカウント数を得る。<br>
1536      int xnp_get_account_count( int xnp_session_id )          int xnp_get_account_count( int xnp_session_id )
1537      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1538      @return 0 success          @return 0 success
1539    */    */
1540  ZEND_FUNCTION(xnp_get_account_count)  ZEND_FUNCTION(xnp_get_account_count)
1541  {  {
1542          long sid;          long sid;
1543            
1544          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1545            &sid) == FAILURE) {            &sid) == FAILURE) {
1546                  return;                  return;
1547          }          }
1548            
1549          long count = getAccountCount( (sessionid_t)sid );          long count = getAccountCount( (sessionid_t)sid );
1550      RETURN_LONG(count);          RETURN_LONG(count);
1551  }  }
1552    
1553  /** アカウントを削除する。<br>  /** アカウントを削除する。<br>
1554      bool xnp_delete_account( int xnp_session_id, int user_id )          bool xnp_delete_account( int xnp_session_id, int user_id )
1555      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1556      @param user_id   xoops_users.uid          @param user_id   xoops_users.uid
1557      @return 0 success          @return 0 success
1558    */    */
1559  ZEND_FUNCTION(xnp_delete_account)  ZEND_FUNCTION(xnp_delete_account)
1560  {  {
1561          long sid, uid;          long sid, uid;
1562            
1563          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1564            &sid, &uid) == FAILURE) {            &sid, &uid) == FAILURE) {
1565                  return;                  return;
1566          }          }
1567            
1568          result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );          result_t result = deleteAccount( (sessionid_t)sid, (userid_t)uid );
1569            
1570      RETURN_LONG(result);          RETURN_LONG(result);
1571  }  }
1572    
1573  /** アカウント情報を得る。<br>  /** アカウント情報を得る。<br>
1574      int xnp_get_account( int xnp_session_id, int user_id, array account_info )          int xnp_get_account( int xnp_session_id, int user_id, array account_info )
1575      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1576      @param user_id   xoops_users.uid          @param user_id   xoops_users.uid
1577      @param account_info アカウント情報を受け取る連想配列          @param account_info アカウント情報を受け取る連想配列
1578      @return 0 success          @return 0 success
1579    */    */
1580  ZEND_FUNCTION(xnp_get_account)  ZEND_FUNCTION(xnp_get_account)
1581  {  {
1582          long sid, uid;          long sid, uid;
1583          zval *zaccount;          zval *zaccount;
1584            
1585          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1586            &sid, &uid, &zaccount) == FAILURE) {            &sid, &uid, &zaccount) == FAILURE) {
1587          fprintf( stderr, "error occured " );                  fprintf( stderr, "error occured " );
1588                  return;                  return;
1589          }          }
1590            
1591          const account_t *paccount;          const account_t *paccount;
1592          result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );          result_t result = getAccount( (sessionid_t)sid, (userid_t)uid, &paccount );
1593          if ( RES_OK == result ){          if ( RES_OK == result ){
1594                  accountToZval( paccount, zaccount );                  accountToZval( paccount, zaccount );
1595                  freeAccount( paccount );                  freeAccount( paccount );
1596          }          }
1597            
1598      RETURN_LONG(result);          RETURN_LONG(result);
1599  }  }
1600    
1601  /** 条件に一致するアカウントの情報を得る。<br>  /** 条件に一致するアカウントの情報を得る。<br>
1602      int xnp_get_accoutns( int sid, array uids, array criteria, array accounts );          int xnp_get_accoutns( int sid, array uids, array criteria, array accounts );
1603      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1604      @param user_id   xoops_users.uid          @param user_id   xoops_users.uid
1605      @param criteria  取得範囲・ソート順を表す配列          @param criteria  取得範囲・ソート順を表す配列
1606      @param account_info アカウント情報を受け取る連想配列          @param account_info アカウント情報を受け取る連想配列
1607      @return 0 success          @return 0 success
1608    */    */
1609  ZEND_FUNCTION(xnp_get_accounts)  ZEND_FUNCTION(xnp_get_accounts)
1610  {  {
# Line 1275  ZEND_FUNCTION(xnp_get_accounts) Line 1613  ZEND_FUNCTION(xnp_get_accounts)
1613          zval *zuids;          zval *zuids;
1614          zval *zcriteria;          zval *zcriteria;
1615          zval *zaccount;          zval *zaccount;
1616            
1617          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
1618            &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {            &sid, &zuids, &zcriteria, &zaccount) == FAILURE) {
1619                  return;                  return;
1620          }          }
1621            
1622          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
1623          result = zcri.getResult();          result = zcri.getResult();
1624          if ( RES_OK == result ){          if ( RES_OK == result ){
# Line 1289  ZEND_FUNCTION(xnp_get_accounts) Line 1627  ZEND_FUNCTION(xnp_get_accounts)
1627                  if ( RES_OK == result ){                  if ( RES_OK == result ){
1628                          const account_t *paccounts;                          const account_t *paccounts;
1629                          int accountLen;                          int accountLen;
1630                          result = getAccounts( (sessionid_t)sid,                          result = getAccounts( (sessionid_t)sid,
1631                                  zUIDs.getPUID(), zUIDs.getLen(),                                  zUIDs.getPUID(), zUIDs.getLen(),
1632                                  &zcri, &paccounts, &accountLen );                                  &zcri, &paccounts, &accountLen );
1633                          if ( RES_OK == result ){                          if ( RES_OK == result ){
# Line 1298  ZEND_FUNCTION(xnp_get_accounts) Line 1636  ZEND_FUNCTION(xnp_get_accounts)
1636                          }                          }
1637                  }                  }
1638          }          }
1639            
1640      RETURN_LONG(result);          RETURN_LONG(result);
1641  }  }
1642    
1643  /** アカウント情報を記録する。<br>  /** アカウント情報を記録する。<br>
1644      int xnp_insert_account( int sid, array account_info, int &user_id );          int xnp_insert_account( int sid, array account_info, int &user_id );
1645      @param xnp_session_id   xnp の session id          @param xnp_session_id   xnp の session id
1646      @param account_info 記録したいアカウントの情報          @param account_info 記録したいアカウントの情報
1647      @param user_id ユーザID(xoops_users.uid)を書き込むリファレンス          @param user_id ユーザID(xoops_users.uid)を書き込むリファレンス
1648      @return 0 success          @return 0 success
1649    */    */
1650  ZEND_FUNCTION(xnp_insert_account)  ZEND_FUNCTION(xnp_insert_account)
1651  {  {
# Line 1315  ZEND_FUNCTION(xnp_insert_account) Line 1653  ZEND_FUNCTION(xnp_insert_account)
1653          long sid;          long sid;
1654          zval *zaccount;          zval *zaccount;
1655          zval *zuid;          zval *zuid;
1656      userid_t uid;          userid_t uid;
1657            
1658          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1659            &sid, &zaccount, &zuid) == FAILURE) {            &sid, &zaccount, &zuid) == FAILURE) {
1660                  return;                  return;
1661          }          }
1662            
1663          zAccount_t zacc(zaccount);          zAccount_t zacc(zaccount);
1664          result = zacc.getResult();          result = zacc.getResult();
1665          if ( RES_OK == result ){          if ( RES_OK == result ){
1666                  result = insertAccount( (sessionid_t)sid, &zacc, &uid );                  result = insertAccount( (sessionid_t)sid, &zacc, &uid );
1667          }          }
1668      zuid -> type = IS_LONG;          zuid -> type = IS_LONG;
1669      zuid -> value.lval = uid;          zuid -> value.lval = uid;
1670      RETURN_LONG(result);          RETURN_LONG(result);
1671  }  }
1672    
1673  /** アカウント情報を更新する。<br>  /** アカウント情報を更新する。<br>
1674      int xnp_update_account( int sid, array account );          int xnp_update_account( int sid, array account );
1675      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1676      @param account_info 書き込むべきアカウント情報を表す連想配列          @param account_info 書き込むべきアカウント情報を表す連想配列
1677      @return 0 success          @return 0 success
1678    */    */
1679  ZEND_FUNCTION(xnp_update_account)  ZEND_FUNCTION(xnp_update_account)
1680  {  {
1681          result_t result;          result_t result;
1682          long sid;          long sid;
1683          zval *zaccount;          zval *zaccount;
1684            
1685          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1686            &sid, &zaccount) == FAILURE) {            &sid, &zaccount) == FAILURE) {
1687                  return;                  return;
1688          }          }
1689            
1690          zAccount_t zacc(zaccount);          zAccount_t zacc(zaccount);
1691          result = zacc.getResult();          result = zacc.getResult();
1692          if ( RES_OK == result ){          if ( RES_OK == result ){
1693                  result = updateAccount( (sessionid_t)sid, &zacc );                  result = updateAccount( (sessionid_t)sid, &zacc );
1694          }          }
1695            
1696      RETURN_LONG(result);          RETURN_LONG(result);
1697  }  }
1698    
1699  /** 条件に合うアカウントのuidの一覧を得る。<br>  /** 条件に合うアカウントのuidの一覧を得る。<br>
1700      int xnp_dump_uids( int xnp_session_id, array criteria, array uids );          int xnp_dump_uids( int xnp_session_id, array criteria, array uids );
1701      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1702      @param criteria  取得範囲・ソート順を表す配列          @param criteria  取得範囲・ソート順を表す配列
1703      @param uids uidを受け取る配列          @param uids uidを受け取る配列
1704      @return 0 success          @return 0 success
1705    */    */
1706  ZEND_FUNCTION(xnp_dump_uids)  ZEND_FUNCTION(xnp_dump_uids)
1707  {  {
# Line 1371  ZEND_FUNCTION(xnp_dump_uids) Line 1709  ZEND_FUNCTION(xnp_dump_uids)
1709          long sid;          long sid;
1710          zval *zcriteria;          zval *zcriteria;
1711          zval *zuids;          zval *zuids;
1712            
1713          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1714            &sid, &zcriteria, &zuids) == FAILURE) {            &sid, &zcriteria, &zuids) == FAILURE) {
1715                  return;                  return;
1716          }          }
1717            
1718          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
1719          result = zcri.getResult();          result = zcri.getResult();
1720          if ( RES_OK == result ){          if ( RES_OK == result ){
# Line 1388  ZEND_FUNCTION(xnp_dump_uids) Line 1726  ZEND_FUNCTION(xnp_dump_uids)
1726                          freeUID( puid );                          freeUID( puid );
1727                  }                  }
1728          }          }
1729            
1730      RETURN_LONG(result);          RETURN_LONG(result);
1731  }  }
1732    
1733  /** XNPのグループの数を得る<br>  /** XNPのグループの数を得る<br>
1734      int xnp_get_group_count( int xnp_session_id );          int xnp_get_group_count( int xnp_session_id );
1735      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1736      @return グループ数          @return グループ数
1737    */    */
1738  ZEND_FUNCTION(xnp_get_group_count)  ZEND_FUNCTION(xnp_get_group_count)
1739  {  {
1740          result_t result;          result_t result;
1741          long sid;          long sid;
1742            
1743          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
1744            &sid) == FAILURE) {            &sid) == FAILURE) {
1745                  return;                  return;
1746          }          }
1747            
1748          int count = getGroupCount( (sessionid_t)sid );          int count = getGroupCount( (sessionid_t)sid );
1749            
1750      RETURN_LONG(count);          RETURN_LONG(count);
1751  }  }
1752    
1753  /** uidで指定したユーザが属すグループで、かつ条件に一致するグループのgidを得る<br>  /** uidで指定したユーザが属すグループで、かつ条件に一致するグループのgidを得る<br>
1754      int xnp_get_group_by_uid( int xnp_session_id, int uid, array criteria, array gids );          int xnp_get_group_by_uid( int xnp_session_id, int uid, array criteria, array gids );
1755      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1756      @param user_id   xoops_users.uid          @param user_id   xoops_users.uid
1757      @param criteria  取得範囲・ソート順を表す配列          @param criteria  取得範囲・ソート順を表す配列
1758      @param gids gidを受け取る配列          @param gids gidを受け取る配列
1759      @return 0 success          @return 0 success
1760    */    */
1761  ZEND_FUNCTION(xnp_get_groups_by_uid)  ZEND_FUNCTION(xnp_get_groups_by_uid)
1762  {  {
# Line 1426  ZEND_FUNCTION(xnp_get_groups_by_uid) Line 1764  ZEND_FUNCTION(xnp_get_groups_by_uid)
1764          long sid, uid;          long sid, uid;
1765          zval *zcriteria;          zval *zcriteria;
1766          zval *zgids;          zval *zgids;
1767            
1768          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1769            &sid, &uid, &zcriteria, &zgids) == FAILURE) {            &sid, &uid, &zcriteria, &zgids) == FAILURE) {
1770                  return;                  return;
1771          }          }
1772            
1773          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
1774          result = zcri.getResult();          result = zcri.getResult();
1775          if ( RES_OK == result ){          if ( RES_OK == result ){
# Line 1443  ZEND_FUNCTION(xnp_get_groups_by_uid) Line 1781  ZEND_FUNCTION(xnp_get_groups_by_uid)
1781                          freeGID( pgids );                          freeGID( pgids );
1782                  }                  }
1783          }          }
1784            
1785      RETURN_LONG(result);          RETURN_LONG(result);
1786  }  }
1787    
1788    
1789    
1790  /** uidで指定したユーザがgidで指定したグループのグループ管理者かどうかを得る<br>  /** uidで指定したユーザがgidで指定したグループのグループ管理者かどうかを得る<br>
1791      int xnp_is_group_admin( int sid, int gid, int uid );          int xnp_is_group_admin( int sid, int gid, int uid );
1792      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1793      @param group_id  XNPのグループID          @param group_id  XNPのグループID
1794      @param user_id   xoops_users.uid          @param user_id   xoops_users.uid
1795      @return true: グループ管理者である。          @return true: グループ管理者である。
1796      @return false: グループ管理者でない。あるいはエラーである。          @return false: グループ管理者でない。あるいはエラーである。
1797    */    */
1798  ZEND_FUNCTION(xnp_is_group_admin)  ZEND_FUNCTION(xnp_is_group_admin)
1799  {  {
1800          result_t result;          result_t result;
1801          long sid, gid, uid;          long sid, gid, uid;
1802            
1803          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1804            &sid, &gid, &uid) == FAILURE) {            &sid, &gid, &uid) == FAILURE) {
1805                  return;                  return;
1806          }          }
1807            
1808          bool b  = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );          bool b  = isGroupAdmin( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1809            
1810      RETURN_BOOL(b);          RETURN_BOOL(b);
1811  }  }
1812    
1813  /** 条件に一致するグループのgidの一覧を得る。<br>  /** 条件に一致するグループのgidの一覧を得る。<br>
1814      int xnp_dump_gids( int sid, array criteria, array gids );          int xnp_dump_gids( int sid, array criteria, array gids );
1815      @param xnp_session_id   XNPのセッションID          @param xnp_session_id   XNPのセッションID
1816      @param criteria  取得範囲・ソート順を表す配列          @param criteria  取得範囲・ソート順を表す配列
1817      @param gids gidを受け取る配列          @param gids gidを受け取る配列
1818      @return 0 success          @return 0 success
1819    */    */
1820  ZEND_FUNCTION(xnp_dump_gids)  ZEND_FUNCTION(xnp_dump_gids)
1821  {  {
# Line 1485  ZEND_FUNCTION(xnp_dump_gids) Line 1823  ZEND_FUNCTION(xnp_dump_gids)
1823          long sid;          long sid;
1824          zval *zcriteria;          zval *zcriteria;
1825          zval *zgids;          zval *zgids;
1826            
1827          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1828            &sid, &zcriteria, &zgids) == FAILURE) {            &sid, &zcriteria, &zgids) == FAILURE) {
1829                  return;                  return;
1830          }          }
1831            
1832          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
1833          result = zcri.getResult();          result = zcri.getResult();
1834          if ( RES_OK == result ){          if ( RES_OK == result ){
# Line 1502  ZEND_FUNCTION(xnp_dump_gids) Line 1840  ZEND_FUNCTION(xnp_dump_gids)
1840                          freeGID( pgid );                          freeGID( pgid );
1841                  }                  }
1842          }          }
1843            
1844      RETURN_LONG(result);          RETURN_LONG(result);
1845  }  }
1846    
1847  /** gidで指定したグループの管理者で、かつ条件に一致するグループ管理者のuidの一覧を得る。<br>  /** gidで指定したグループの管理者で、かつ条件に一致するグループ管理者のuidの一覧を得る。<br>
1848      int xnp_dump_group_admins(int sid, int group_id, array criteria, array uids )          int xnp_dump_group_admins(int sid, int group_id, array criteria, array uids )
1849      @param sid      XNPのセッションID          @param sid      XNPのセッションID
1850      @param group_id XNPのグループID          @param group_id XNPのグループID
1851      @param criteria 条件          @param criteria 条件
1852      @param uids     uidの一覧を受け取る配列          @param uids     uidの一覧を受け取る配列
1853      @return 0 success          @return 0 success
1854    */    */
1855    
1856  ZEND_FUNCTION(xnp_dump_group_admins)  ZEND_FUNCTION(xnp_dump_group_admins)
# Line 1520  ZEND_FUNCTION(xnp_dump_group_admins) Line 1858  ZEND_FUNCTION(xnp_dump_group_admins)
1858          long sid, gid;          long sid, gid;
1859          zval *zcriteria;          zval *zcriteria;
1860          zval *zuids;          zval *zuids;
1861            
1862          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1863                                &sid, &gid, &zcriteria, &zuids) == FAILURE) {                                                            &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1864                  return;                  return;
1865          }          }
1866            
1867          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
1868          result_t result = zcri.getResult();          result_t result = zcri.getResult();
1869          if ( result == RES_OK ){          if ( result == RES_OK ){
# Line 1541  ZEND_FUNCTION(xnp_dump_group_admins) Line 1879  ZEND_FUNCTION(xnp_dump_group_admins)
1879  }  }
1880    
1881  /** グループからメンバーを削除する。<br>  /** グループからメンバーを削除する。<br>
1882      int xnp_delete_member(int sid, int group_id, int user_id )          int xnp_delete_member(int sid, int group_id, int user_id )
1883      @param sid      XNPのセッションID          @param sid      XNPのセッションID
1884      @param group_id XNPのグループID          @param group_id XNPのグループID
1885      @param user_id  ユーザID          @param user_id  ユーザID
1886      @return 0 success          @return 0 success
1887    */    */
1888    
1889  ZEND_FUNCTION(xnp_delete_member)  ZEND_FUNCTION(xnp_delete_member)
1890  {  {
1891          long sid, gid, uid;          long sid, gid, uid;
1892            
1893          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1894                                &sid, &gid, &uid) == FAILURE) {                                                            &sid, &gid, &uid) == FAILURE) {
1895                  return;                  return;
1896          }          }
1897            
1898          result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );          result_t result = deleteMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid );
1899          RETURN_LONG( result );          RETURN_LONG( result );
1900  }  }
1901    
1902  /** グループにメンバーを追加する<br>  /** グループにメンバーを追加する<br>
1903      int xnp_insert_member(int sid, int group_id, int user_id, bool admin )          int xnp_insert_member(int sid, int group_id, int user_id, bool admin )
1904      @param sid      XNPのセッションID          @param sid      XNPのセッションID
1905      @param group_id XNPのグループID          @param group_id XNPのグループID
1906      @param user_id  ユーザID          @param user_id  ユーザID
1907      @param admin    グループ管理者ならtrue          @param admin    グループ管理者ならtrue
1908      @return 0 success          @return 0 success
1909    */    */
1910    
1911  ZEND_FUNCTION(xnp_insert_member)  ZEND_FUNCTION(xnp_insert_member)
1912  {  {
1913          long sid, gid, uid;          long sid, gid, uid;
1914          zend_bool admin;          zend_bool admin;
1915            
1916          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllb",
1917                                &sid, &gid, &uid, &admin) == FAILURE) {                                                            &sid, &gid, &uid, &admin) == FAILURE) {
1918                  return;                  return;
1919          }          }
1920            
1921          result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );          result_t result = insertMember( (sessionid_t)sid, (groupid_t)gid, (userid_t)uid, (bool)admin );
1922          RETURN_LONG( result );          RETURN_LONG( result );
1923  }  }
1924    
1925  /** gidで指定したグループのメンバーのuidの一覧を得る<br>  /** gidで指定したグループのメンバーのuidの一覧を得る<br>
1926      int xnp_get_members(int sid, int group_id, array criteria, array uids )          int xnp_get_members(int sid, int group_id, array criteria, array uids )
1927      @param sid      XNPのセッションID          @param sid      XNPのセッションID
1928      @param group_id XNPのグループID          @param group_id XNPのグループID
1929      @param criteria 条件          @param criteria 条件
1930      @param uids     uidの一覧を受け取る配列          @param uids     uidの一覧を受け取る配列
1931      @return 0 success          @return 0 success
1932    */    */
1933    
1934  ZEND_FUNCTION(xnp_get_members)  ZEND_FUNCTION(xnp_get_members)
# Line 1598  ZEND_FUNCTION(xnp_get_members) Line 1936  ZEND_FUNCTION(xnp_get_members)
1936          long sid, gid;          long sid, gid;
1937          zval *zcriteria;          zval *zcriteria;
1938          zval *zuids;          zval *zuids;
1939            
1940          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1941                                &sid, &gid, &zcriteria, &zuids) == FAILURE) {                                                            &sid, &gid, &zcriteria, &zuids) == FAILURE) {
1942                  return;                  return;
1943          }          }
1944            
1945          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
1946          result_t result = zcri.getResult();          result_t result = zcri.getResult();
1947          if ( result == RES_OK ){          if ( result == RES_OK ){
# Line 1619  ZEND_FUNCTION(xnp_get_members) Line 1957  ZEND_FUNCTION(xnp_get_members)
1957  }  }
1958    
1959  /** グループ情報を変更する。<br>  /** グループ情報を変更する。<br>
1960      int xnp_update_group(int sid, array group )          int xnp_update_group(int sid, array group )
1961      @param sid      XNPのセッションID          @param sid      XNPのセッションID
1962      @param group    グループ情報の連想配列          @param group    グループ情報の連想配列
1963      @return 0 success          @return 0 success
1964    */    */
1965  ZEND_FUNCTION(xnp_update_group)  ZEND_FUNCTION(xnp_update_group)
1966  {  {
1967          long sid;          long sid;
1968          zval *zgroup;          zval *zgroup;
1969      group_t group;          group_t group;
1970            
1971          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1972                                &sid, &zgroup) == FAILURE) {                                                            &sid, &zgroup) == FAILURE) {
1973                  return;                  return;
1974          }          }
1975            
1976      zvalToGroup( zgroup, &group );          zvalToGroup( zgroup, &group );
1977      result_t result = updateGroup( sid, &group );          result_t result = updateGroup( sid, &group );
1978      RETURN_LONG( result );          RETURN_LONG( result );
1979  }  }
1980    
1981  /** グループ情報を追加する。<br>  /** グループ情報を追加する。<br>
1982      int xnp_insert_group( int sid, array group, int &gid )          int xnp_insert_group( int sid, array group, int &gid )
1983      @param sid      セッションID          @param sid      セッションID
1984      @param group    グループ情報の連想配列          @param group    グループ情報の連想配列
1985      @param gid      対応するグループIDを書き込むリファレンス          @param gid      対応するグループIDを書き込むリファレンス
1986      @return RES_OK          @return RES_OK
1987      @return RES_DB_NOT_INITIALIZED          @return RES_DB_NOT_INITIALIZED
1988      @return RES_NO_SUCH_SESSION          @return RES_NO_SUCH_SESSION
1989      @return RES_DB_QUERY_ERROR          @return RES_DB_QUERY_ERROR
1990  */  */
1991  ZEND_FUNCTION(xnp_insert_group)  ZEND_FUNCTION(xnp_insert_group)
1992  {  {
1993          long sid;          long sid;
1994          zval *zgroup;          zval *zgroup;
1995      zval *zgid;          zval *zgid;
1996      group_t group;          group_t group;
1997      groupid_t gid;          groupid_t gid;
1998            
1999          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2000                                &sid, &zgroup, &zgid ) == FAILURE) {                                                            &sid, &zgroup, &zgid ) == FAILURE) {
2001                  return;                  return;
2002          }          }
2003            
2004      zvalToGroup( zgroup, &group );          zvalToGroup( zgroup, &group );
2005      result_t result = insertGroup( sid, &group, &gid );          result_t result = insertGroup( sid, &group, &gid );
2006      zgid -> type = IS_LONG;          zgid -> type = IS_LONG;
2007      zgid -> value.lval = gid;          zgid -> value.lval = gid;
2008      RETURN_LONG( result );          RETURN_LONG( result );
2009  }  }
2010    
2011    
2012  /** グループ情報を削除する。<br>  /** グループ情報を削除する。<br>
2013      int xnp_delete_group( int sid, int gid )          int xnp_delete_group( int sid, int gid )
2014      @param sid      XNPのセッションID          @param sid      XNPのセッションID
2015      @param gid      削除したいグループのID          @param gid      削除したいグループのID
2016      @return RES_OK          @return RES_OK
2017      @return RES_DB_QUERY_ERROR          @return RES_DB_QUERY_ERROR
2018      @return RES_NO_SUCH_SESSION          @return RES_NO_SUCH_SESSION
2019      @return RES_DB_NOT_INITIALIZED          @return RES_DB_NOT_INITIALIZED
2020    */    */
2021  ZEND_FUNCTION(xnp_delete_group)  ZEND_FUNCTION(xnp_delete_group)
2022  {  {
2023          long sid;          long sid;
2024          long gid;          long gid;
2025            
2026          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2027                                &sid, &gid) == FAILURE) {                                                            &sid, &gid) == FAILURE) {
2028                  return;                  return;
2029          }          }
2030      RETURN_LONG( deleteGroup( sid, gid ) );          RETURN_LONG( deleteGroup( sid, gid ) );
2031  }  }
2032    
2033  /** グループの管理者を取得。<br>  /** グループの管理者を取得。<br>
2034      int xnp_dump_group_admins( int sid, int gid, array criteria, array uids )          int xnp_dump_group_admins( int sid, int gid, array criteria, array uids )
2035      @param sid      XNPのセッションID          @param sid      XNPのセッションID
2036      @param gid      XNPグループのID          @param gid      XNPグループのID
2037      @param criteria uidsに書き込むときのソート条件,範囲の指定          @param criteria uidsに書き込むときのソート条件,範囲の指定
2038      @param uids     管理者のUIDを書き込む配列          @param uids     管理者のUIDを書き込む配列
2039      @return RES_OK          @return RES_OK
2040      @return RES_DB_QUERY_ERROR          @return RES_DB_QUERY_ERROR
2041      @return RES_NO_SUCH_SESSION          @return RES_NO_SUCH_SESSION
2042      @return RES_DB_NOT_INITIALIZED          @return RES_DB_NOT_INITIALIZED
2043    */    */
2044  /*  /*
2045  ZEND_FUNCTION(xnp_dump_group_admins)  ZEND_FUNCTION(xnp_dump_group_admins)
# Line 1710  ZEND_FUNCTION(xnp_dump_group_admins) Line 2048  ZEND_FUNCTION(xnp_dump_group_admins)
2048          long gid;          long gid;
2049          zval *zcriteria;          zval *zcriteria;
2050          zval *zuids;          zval *zuids;
2051            
2052          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2053                                &sid, &gid, &zcriteria, &zuids) == FAILURE) {                                                            &sid, &gid, &zcriteria, &zuids) == FAILURE) {
2054                  return;                  return;
2055          }          }
2056          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
2057          result_t result = zcri.getResult();          result_t result = zcri.getResult();
2058          if ( RES_OK == result ){          if ( RES_OK == result ){
2059          userid_t* uids;                  userid_t* uids;
2060          int uidsLen;                  int uidsLen;
2061          result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );                  result_t result = dumpGroupAdmins( sid, gid, &zcri, &uids, &uidsLen );
2062          if( result != RES_OK ) RETURN_LONG( result );                  if( result != RES_OK ) RETURN_LONG( result );
2063          uidsToZval( uids, uidsLen, &zuids );                  uidsToZval( uids, uidsLen, &zuids );
2064          fprintf( stderr, "uidsLen=%d\n", uidsLen );                  fprintf( stderr, "uidsLen=%d\n", uidsLen );
2065          for( int i = 0; i < uidsLen; i++ ){                  for( int i = 0; i < uidsLen; i++ ){
2066              fprintf( stderr, "%d, \n", uids[ i ] );                          fprintf( stderr, "%d, \n", uids[ i ] );
2067          }                  }
2068          freeUID( uids );                  freeUID( uids );
2069          RETURN_LONG( result );                  RETURN_LONG( result );
2070      }          }
2071      RETURN_LONG( result );          RETURN_LONG( result );
2072  }  }
2073  */  */
2074    
# Line 1745  ZEND_FUNCTION(xnp_get_all_indexes) Line 2083  ZEND_FUNCTION(xnp_get_all_indexes)
2083          long sid;          long sid;
2084          zval *zcriteria;          zval *zcriteria;
2085          zval *zindexes;          zval *zindexes;
2086            
2087          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
2088                                &sid, &zcriteria, &zindexes) == FAILURE) {                                                            &sid, &zcriteria, &zindexes) == FAILURE) {
2089                  return;                  return;
2090          }          }
2091          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
# Line 1778  ZEND_FUNCTION(xnp_get_indexes) Line 2116  ZEND_FUNCTION(xnp_get_indexes)
2116          long parentXID;          long parentXID;
2117          zval *zcriteria;          zval *zcriteria;
2118          zval *zindexes;          zval *zindexes;
2119            
2120          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2121                                &sid, &parentXID, &zcriteria, &zindexes) == FAILURE) {                                                            &sid, &parentXID, &zcriteria, &zindexes) == FAILURE) {
2122                  return;                  return;
2123          }          }
2124          zCriteria_t zcri(zcriteria);          zCriteria_t zcri(zcriteria);
# Line 1810  ZEND_FUNCTION(xnp_insert_index) Line 2148  ZEND_FUNCTION(xnp_insert_index)
2148          long sid;          long sid;
2149          zval *zindex;          zval *zindex;
2150          zval *zIndexID;          zval *zIndexID;
2151            
2152          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2153                                &sid, &zindex, &zIndexID) == FAILURE) {                                                            &sid, &zindex, &zIndexID) == FAILURE) {
2154                  return;                  return;
2155          }          }
2156            
2157          if (!PZVAL_IS_REF(zIndexID)) {          if (!PZVAL_IS_REF(zIndexID)) {
2158                  zend_error(E_WARNING, "3rd parameter wasn't passed by reference");                  zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
2159                  RETURN_LONG(RES_PHP_NONREF);                  RETURN_LONG(RES_PHP_NONREF);
# Line 1838  ZEND_FUNCTION(xnp_update_index) Line 2176  ZEND_FUNCTION(xnp_update_index)
2176  {  {
2177          long sid;          long sid;
2178          zval *zindex;          zval *zindex;
2179            
2180          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
2181                                &sid, &zindex) == FAILURE) {                                                            &sid, &zindex) == FAILURE) {
2182                  return;                  return;
2183          }          }
2184          zIndex_t index(zindex);          zIndex_t index(zindex);
# Line 1861  ZEND_FUNCTION(xnp_delete_index) Line 2199  ZEND_FUNCTION(xnp_delete_index)
2199  {  {
2200          long sid;          long sid;
2201          long xid;          long xid;
2202            
2203          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2204                                &sid, &xid) == FAILURE) {                                                            &sid, &xid) == FAILURE) {
2205                  return;                  return;
2206          }          }
2207            
2208          result_t result = deleteIndex( sid, xid );          result_t result = deleteIndex( sid, xid );
2209          RETURN_LONG(result);          RETURN_LONG(result);
2210  }  }
# Line 1884  ZEND_FUNCTION(xnp_get_index) Line 2222  ZEND_FUNCTION(xnp_get_index)
2222          long sid;          long sid;
2223          long xid;          long xid;
2224          zval *zindex;          zval *zindex;
2225            
2226          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
2227                                &sid, &xid, &zindex) == FAILURE) {                                                            &sid, &xid, &zindex) == FAILURE) {
2228                  return;                  return;
2229          }          }
2230            
2231          const index_t *index;          const index_t *index;
2232          result_t result = getIndex( sid, xid, &index );          result_t result = getIndex( sid, xid, &index );
2233          if ( RES_OK == result ){          if ( RES_OK == result ){
# Line 1911  ZEND_FUNCTION(xnp_is_index_readable) Line 2249  ZEND_FUNCTION(xnp_is_index_readable)
2249  {  {
2250          long sid;          long sid;
2251          long xid;          long xid;
2252            
2253          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2254                                &sid, &xid) == FAILURE) {                                                            &sid, &xid) == FAILURE) {
2255                  return;                  return;
2256          }          }
2257          RETURN_BOOL(isIndexReadable(sid,xid));          RETURN_BOOL(isIndexReadable(sid,xid));
# Line 1930  ZEND_FUNCTION(xnp_is_index_writable) Line 2268  ZEND_FUNCTION(xnp_is_index_writable)
2268  {  {
2269          long sid;          long sid;
2270          long xid;          long xid;
2271            
2272          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2273                                &sid, &xid) == FAILURE) {                                                            &sid, &xid) == FAILURE) {
2274                  return;                  return;
2275          }          }
2276          RETURN_BOOL(isIndexWritable(sid,xid));          RETURN_BOOL(isIndexWritable(sid,xid));
# Line 1949  ZEND_FUNCTION(xnp_swap_index_sort_number Line 2287  ZEND_FUNCTION(xnp_swap_index_sort_number
2287  {  {
2288          long sid;          long sid;
2289          long xid1, xid2;          long xid1, xid2;
2290            
2291          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
2292                                &sid, &xid1, &xid2) == FAILURE) {                                                            &sid, &xid1, &xid2) == FAILURE) {
2293                  return;                  return;
2294          }          }
2295            
2296          result_t result = swapIndexSortNumber( sid, xid1, xid2 );          result_t result = swapIndexSortNumber( sid, xid1, xid2 );
2297          RETURN_LONG(result);          RETURN_LONG(result);
2298  }  }
# Line 1962  ZEND_FUNCTION(xnp_swap_index_sort_number Line 2300  ZEND_FUNCTION(xnp_swap_index_sort_number
2300    
2301    
2302  /** XNPのsession_idの正当性チェック<br>  /** XNPのsession_idの正当性チェック<br>
2303      bool xnp_is_valid_session_id( int xnp_session_id)          bool xnp_is_valid_session_id( int xnp_session_id)
2304      @return true 有効なXNPのsession_idである<br>          @return true 有効なXNPのsession_idである<br>
2305      @return false 無効なsession_idまたはエラー          @return false 無効なsession_idまたはエラー
2306    */    */
2307  ZEND_FUNCTION(xnp_is_valid_session_id)  ZEND_FUNCTION(xnp_is_valid_session_id)
2308  {  {
# Line 1972  ZEND_FUNCTION(xnp_is_valid_session_id) Line 2310  ZEND_FUNCTION(xnp_is_valid_session_id)
2310          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sid ) == FAILURE) {
2311                  return;                  return;
2312          }          }
2313            
2314          RETURN_BOOL(isValidSessionID((sessionid_t)sid));          RETURN_BOOL(isValidSessionID((sessionid_t)sid));
2315  }  }
2316    
2317  /** エラー文字列を得る<br>  /** エラー文字列を得る<br>
2318      string xnp_get_last_error_string()          string xnp_get_last_error_string()
2319      @return 0 success          @return 0 success
2320    */    */
2321  ZEND_FUNCTION(xnp_get_last_error_string)  ZEND_FUNCTION(xnp_get_last_error_string)
2322  {  {
2323          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "" ) == FAILURE) {
2324                  return;                  return;
2325          }          }
2326            
2327          string str( getLastErrorString() );          string str( getLastErrorString() );
2328          RETURN_STRING((char *)str.c_str(), 1);          RETURN_STRING((char *)str.c_str(), 1);
2329  }  }
2330    
2331    
2332    /**
2333     *
2334     * アイテムへのアクセス権限をチェックする
2335     *
2336     * @refer itemop_t
2337     * @param sid セッションID
2338     * @param iid チェック対象となるアイテムのID
2339     * @param op アクセスの種類
2340     * @return true 権限あり
2341     * @return false 権限なし
2342     *
2343     */
2344    ZEND_FUNCTION(xnp_get_item_permission)
2345    {
2346            RETURN_LONG( RES_ERROR );
2347    }
2348    
2349    
2350    /**
2351     *
2352     * インデックスへのアクセス権限をチェックする
2353     *
2354     * @refer indexop_t
2355     * @param sid セッションID
2356     * @param xid チェック対象となるインデックスのID
2357     * @param op アクセスの種類
2358     * @return true 権限あり
2359     * @return false 権限なし
2360     *
2361     */
2362    ZEND_FUNCTION(xnp_get_index_permission)
2363    {
2364            RETURN_LONG( RES_ERROR );
2365    }
2366    
2367    
2368    /**
2369     *
2370     * アイテムの承認状態を変更する権限の有無を調べます.
2371     * @refer certify_t
2372     * @param sid セッションID
2373     * @param xid 変更対象アイテムが登録されているインデックスのID
2374     * @param iid 変更対象アイテムのID
2375     * @param state 新しく変更したい承認状態
2376     * @return true 権限あり
2377     * @return false 権限なし
2378     *
2379     */
2380    ZEND_FUNCTION(xnp_get_certify_permission)
2381    {
2382            RETURN_LONG( RES_ERROR );
2383    }
2384    
2385    
2386    /**
2387     *
2388     * アイテムの承認状態を取得します.
2389     * @refer certify_t
2390     * @param sid セッションID
2391     * @param xid 対象アイテムが登録されているインデックスのID
2392     * @param iid 対象アイテムのID
2393     * @param state 承認状態を受け取る引数
2394     * @return RES_OK
2395     * @return RES_NO_WRITE_ACCESS_RIGHT
2396     *
2397     */
2398    ZEND_FUNCTION(xnp_get_certify_state)
2399    {
2400            long sid;
2401            indexid_t xid;
2402            itemid_t iid;
2403            zval *zstate;
2404            result_t result = RES_ERROR;
2405    
2406            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllz",
2407                                                              &sid, &xid, &iid, &zstate) == FAILURE) {
2408                    fprintf( stderr, "error occured " );
2409                    return;
2410            }
2411            certify_t st;
2412            result = getCertifyState( (sessionid_t)sid, xid, iid, &st );
2413            if ( RES_OK == result ){
2414                    zstate -> type = IS_LONG;
2415                    zstate -> value.lval = st;
2416            }
2417            RETURN_LONG( result );
2418    }
2419    
2420    
2421    /**
2422     *
2423     * アイテムの承認状態を変更します.
2424     * @refer certify_t
2425     * @param sid セッションID
2426     * @param xid 変更対象アイテムが登録されているインデックスのID
2427     * @param iid 変更対象アイテムのID
2428     * @param state 新しく変更したい承認状態
2429     * @return RES_OK
2430     * @return RES_NO_WRITE_ACCESS_RIGHT
2431     *
2432     */
2433    ZEND_FUNCTION(xnp_set_certify_state)
2434    {
2435            long sid;
2436            indexid_t xid;
2437            itemid_t iid;
2438            certify_t state;
2439            result_t result = RES_ERROR;
2440    
2441            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll",
2442                                                              &sid, &xid, &iid, &state) == FAILURE) {
2443                    fprintf( stderr, "error occured " );
2444                    return;
2445            }
2446            certify_t st;
2447            result = setCertifyState( (sessionid_t)sid, xid, iid, state );
2448            RETURN_LONG( result );
2449    }
2450    
2451    
2452    /**
2453     *
2454     * 変更履歴ログを記録する.
2455     *
2456     * @param sid セッションID
2457     * @param itemid 変更履歴を記録するアイテムのID
2458     * @param log ログ内容
2459     * @return RES_OK
2460     * @return RES_NO_SUCH_SESSION
2461     * @return RES_DB_QUERY_ERROR
2462     * @return RES_NO_WRITE_ACCESS_RIGHT
2463     * @return RES_DB_NOT_INITIALIZED
2464     * @return RES_ERROR
2465     *
2466     */
2467    ZEND_FUNCTION(xnp_insert_change_log)
2468    {
2469            long sid;
2470            itemid_t iid;
2471            zval *zlog;
2472            result_t result = RES_ERROR;
2473    
2474            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llz",
2475                                                              &sid, &iid, &zlog) == FAILURE) {
2476                    fprintf( stderr, "error occured " );
2477                    return;
2478            }
2479    
2480            result = insertChangeLog( sid, iid, getZvalString( &zlog ) );
2481            RETURN_LONG( result );
2482    }
2483    
2484    
2485    /**
2486     *
2487     * アイテムの変更履歴ログを取得する.
2488     *
2489     * @param sid セッションID
2490     * @param itemid 変更履歴を取得するアイテムのID
2491     * @param logs ログ内容を受け取るポインタ
2492     * @param logsLen logsに格納されたログの個数
2493     * @return RES_OK
2494     * @return RES_NO_SUCH_SESSION
2495     * @return RES_NO_READ_ACCESS_RIGHT
2496     * @return RES_DB_NOT_INITIALIZED
2497     * @return RES_ERROR
2498     *
2499     */
2500    ZEND_FUNCTION(xnp_get_change_logs)
2501    {
2502            result_t result;
2503            long sid;
2504            itemid_t iid;
2505            zval *zlogs;
2506    
2507            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
2508              &sid, &iid, &zlogs) == FAILURE) {
2509                    return;
2510            }
2511    
2512            const changelog_t *plogs;
2513            int logLen;
2514            result = getChangeLogs( (sessionid_t)sid, iid, &plogs, &logLen );
2515            if ( RES_OK == result ){
2516                    zend_hash_clean( zlogs -> value.ht );
2517                    for( int i = 0; i < logLen; i++ ){
2518                            zval *new_array;
2519                            MAKE_STD_ZVAL(new_array);
2520                            if(array_init(new_array) != SUCCESS){
2521                                    result = RES_ERROR;
2522                                    break;
2523                            }
2524                            add_index_zval( zlogs, i, new_array );
2525                            changelogToZval( &plogs[ i ], new_array );
2526                    }
2527                    freeChangeLog( plogs );
2528            }
2529            RETURN_LONG(result);
2530    }
2531    
2532    
2533    /**
2534     *
2535     * 設定名keyに対応する値をvauleに取得する.
2536     * valueの使用後はfreeStringで解放する.
2537     * @param key 設定キー名
2538     * @param value 設定値を受け取るポインタ
2539     *
2540     * @return RES_OK
2541     * @return RES_DB_QUERY_ERROR
2542     * @return RES_ERROR
2543     */
2544    ZEND_FUNCTION(xnp_get_config_value)
2545    {
2546            zval *zname;
2547            zval *zvalue;
2548            const char* name;
2549            char* value;
2550            result_t result = RES_ERROR;
2551    
2552            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",
2553                                                              &zname, &zvalue) == FAILURE) {
2554                    return;
2555            }
2556            result = getConfigValue( getZvalString( &zname ), &value );
2557            if( result == RES_OK ){
2558                    zvalue -> type = IS_STRING;
2559                    zvalue -> value.str.len = strlen(value);
2560                    zvalue -> value.str.val = estrdup(value);
2561                    freeString( value );
2562            }
2563            RETURN_LONG( result );
2564    }
2565    
2566    
2567    /**
2568     *
2569     * 設定名keyに値をvauleを設定する
2570     *
2571     * @param key 設定キー名
2572     * @param value 設定値
2573     *
2574     * @return RES_OK
2575     * @return RES_DB_QUERY_ERROR
2576     * @return RES_ERROR
2577     */
2578    ZEND_FUNCTION(xnp_set_config_value)
2579    {
2580            zval *zname;
2581            zval *zvalue;
2582            const char* name;
2583            char* value;
2584            result_t result = RES_ERROR;
2585    
2586            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",
2587                                                              &zname, &zvalue) == FAILURE) {
2588                    return;
2589            }
2590            result = setConfigValue( getZvalString( &zname ), getZvalString( &zvalue ) );
2591            RETURN_LONG( result );
2592    }
2593    
2594    
2595    /**
2596     *
2597     * アイテムIDの一覧取得.
2598     * アクセス可能なアイテムのIDを返す.
2599     *
2600     * int xnp_dump_item_id( int sid, array cri, array iids )
2601     * @param sid セッションID
2602     * @param cri 結果の範囲指定,ソート条件指定
2603     * @param iids 取得結果を受け取る配列
2604     * @return RES_OK
2605     * @return RES_DB_NOT_INITIALIZED
2606     * @return RES_NO_SUCH_SESSION
2607     * @return RES_DB_QUERY_ERROR
2608     *
2609     */
2610    ZEND_FUNCTION(xnp_dump_item_id)
2611    {
2612            long sid;
2613            zval *zcriteria;
2614            zval *ziids;
2615            result_t result = RES_ERROR;
2616    
2617            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
2618                                                              &sid, &zcriteria, &ziids) == FAILURE) {
2619                    fprintf( stderr, "error occured " );
2620                    return;
2621            }
2622    
2623            zCriteria_t zcri(zcriteria);
2624            result = zcri.getResult();
2625            if ( RES_OK == result ){
2626                    itemid_t *piids;
2627                    int iidsLen;
2628                    result = dumpItemID( (sessionid_t)sid, &zcri, &piids, &iidsLen );
2629                    if ( RES_OK == result ){
2630                            itemidsToZval( piids, iidsLen, &ziids );
2631                            freeItemID( piids );
2632                    }
2633            }
2634    
2635            RETURN_LONG( result );
2636    }
2637    
2638    
2639    /**
2640     *
2641     * バインダーに登録されたアイテムのIDを取得します.
2642     * @param sid セッションID
2643     * @param binderid 対象バインダーのID
2644     * @param cri 結果の範囲指定,ソート条件指定
2645     * @param iids 登録されたアイテムIDを受け取る引数
2646     * @param iidsLen iidsに格納された個数を受け取る引数
2647     * @return RES_OK
2648     * @return RES_DB_NOT_INITIALIZED
2649     * @return RES_NO_SUCH_SESSION
2650     * @return RES_DB_QUERY_ERROR
2651     * @return RES_ERROR
2652     *
2653     */
2654    ZEND_FUNCTION(xnp_get_item_id_by_binder_id)
2655    {
2656            result_t result;
2657            long sid;
2658            itemid_t iid;
2659            zval *zcriteria;
2660            zval *ziids;
2661    
2662            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2663              &sid, &iid, &zcriteria, &ziids) == FAILURE) {
2664                    return;
2665            }
2666    
2667            zCriteria_t zcri(zcriteria);
2668            result = zcri.getResult();
2669            if ( RES_OK == result ){
2670                    itemid_t *pitemids;
2671                    int itemidLen;
2672                    result = getItemIDByBinderID( (sessionid_t)sid, iid, &zcri, &pitemids, &itemidLen );
2673                    if ( RES_OK == result ){
2674                            itemidsToZval( pitemids, itemidLen, &ziids );
2675                            freeItemID( pitemids );
2676                    }
2677            }
2678            RETURN_LONG(result);
2679    }
2680    
2681    
2682    /**
2683     *
2684     * インデックスに登録されたアイテムのIDを取得します.
2685     * 権限が無くて読めないものは結果に含みません.
2686     * 未承認で読めないものも結果に含みません.
2687     *
2688     * @param sid セッションID
2689     * @param xid 対象インデックスのID
2690     * @param cri 結果の範囲指定,ソート条件指定
2691     * @param iids 登録されたアイテムIDを受け取る引数
2692     * @param iidsLen iidsに格納された個数を受け取る引数
2693     * @return RES_OK
2694     * @return RES_DB_NOT_INITIALIZED
2695     * @return RES_NO_SUCH_SESSION
2696     * @return RES_DB_QUERY_ERROR
2697     * @return RES_ERROR
2698     *
2699     */
2700    ZEND_FUNCTION(xnp_get_item_id_by_index_id)
2701    {
2702            result_t result;
2703            long sid;
2704            indexid_t xid;
2705            zval *zcriteria;
2706            zval *ziids;
2707    
2708            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
2709              &sid, &xid, &zcriteria, &ziids) == FAILURE) {
2710                    return;
2711            }
2712    
2713            zCriteria_t zcri(zcriteria);
2714            result = zcri.getResult();
2715            if ( RES_OK == result ){
2716                    itemid_t *pitemids;
2717                    int itemidLen;
2718                    result = getItemIDByIndexID( (sessionid_t)sid, xid, &zcri, &pitemids, &itemidLen );
2719                    if ( RES_OK == result ){
2720                            itemidsToZval( pitemids, itemidLen, &ziids );
2721                            freeItemID( pitemids );
2722                    }
2723            }
2724            RETURN_LONG(result);
2725    }
2726    
2727    
2728    ZEND_FUNCTION(xnp_get_overlapped_items)
2729    {
2730            RETURN_LONG( RES_ERROR );
2731    }
2732    
2733    /**
2734     *
2735     * アイテム(Basic Information)を登録する.
2736     * Platformユーザ以上の権限が必要.
2737     *
2738     * @param sid セッションID
2739     * @param item 登録したいアイテムの情報
2740     * @param itemid 登録したアイテムのIDを受け取る引数
2741     * @return RES_OK
2742     * @return RES_ERROR
2743     * @return RES_NO_SUCH_SESSION
2744     * @return RES_DB_QUERY_ERROR
2745     * @return RES_DB_NOT_INITIALIZED
2746     * @return RES_NO_WRITE_ACCESS_RIGHT
2747     *
2748     */
2749    ZEND_FUNCTION(xnp_insert_item)
2750    {
2751            long sid;
2752            zval *ziid;
2753            zval *zitem;
2754            item_t item;
2755            itemid_t iid;
2756            result_t result = RES_ERROR;
2757    
2758            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
2759                                                              &sid, &zitem, &ziid) == FAILURE) {
2760                    fprintf( stderr, "error occured " );
2761                    return;
2762            }
2763    
2764            zvalToItem( zitem, &item );
2765            result = insertItem( (sessionid_t)sid, &item, &iid );
2766            if ( RES_OK == result ){
2767                    ziid -> type = IS_LONG;
2768                    ziid -> value.lval = iid;
2769            }
2770            RETURN_LONG( result );
2771    }
2772    
2773    /**
2774     *
2775     * アイテム(Basic Information)を更新する.
2776     * Platformユーザ以上の権限が必要.
2777     * itemのitem_idを正しくセットすること.
2778     *
2779     * @param sid セッションID
2780     * @param item 更新したいアイテムの情報
2781     * @return RES_OK
2782     * @return RES_ERROR
2783     * @return RES_NO_SUCH_SESSION
2784     * @return RES_DB_QUERY_ERROR
2785     * @return RES_DB_NOT_INITIALIZED
2786     * @return RES_NO_WRITE_ACCESS_RIGHT
2787     */
2788    ZEND_FUNCTION(xnp_update_item)
2789    {
2790            long sid;
2791            zval *zitem;
2792            item_t item;
2793            itemid_t iid;
2794            result_t result = RES_ERROR;
2795    
2796            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
2797                                                              &sid, &zitem) == FAILURE) {
2798                    fprintf( stderr, "error occured " );
2799                    return;
2800            }
2801    
2802            zvalToItem( zitem, &item );
2803            result = updateItem( (sessionid_t)sid, &item );
2804            RETURN_LONG( result );
2805    }
2806    
2807    /**
2808     *
2809     * アイテム(Basic Information)を削除する.
2810     *
2811     * @param sid セッションID
2812     * @param item 削除したいアイテムの情報
2813     * @return RES_OK
2814     * @return RES_ERROR
2815     * @return RES_NO_SUCH_SESSION
2816     * @return RES_DB_QUERY_ERROR
2817     * @return RES_DB_NOT_INITIALIZED
2818     * @return RES_NO_WRITE_ACCESS_RIGHT
2819     */
2820    ZEND_FUNCTION(xnp_delete_item)
2821    {
2822            long sid;
2823            itemid_t iid;
2824            result_t result = RES_ERROR;
2825    
2826            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
2827                                                              &sid, &iid) == FAILURE) {
2828                    fprintf( stderr, "error occured " );
2829                    return;
2830            }
2831            result = deleteItem( (sessionid_t)sid, iid );
2832            RETURN_LONG( result );
2833    }
2834    
2835    
2836    /**
2837     *
2838     * アイテム情報取得.
2839     * 取得したアイテムは,使用後freeItemで解放する.
2840     *
2841     * @refer freeItem
2842     * @param sid セッションID
2843     * @param iid 取得したいアイテムのID
2844     * @param item 結果のアイテム情報を受け取る引数
2845     * @return RES_OK
2846     * @return RES_DB_NOT_INITIALIZED
2847     * @return RES_NO_SUCH_SESSION
2848     * @return RES_NO_SUCH_ITEM
2849     * @return RES_DB_QUERY_ERROR
2850     *
2851     */
2852    ZEND_FUNCTION(xnp_get_item)
2853    {
2854            long sid;
2855            long iid;
2856            zval *zitem;
2857            result_t result = RES_ERROR;
2858    
2859            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
2860                                                              &sid, &iid, &zitem) == FAILURE) {
2861                    fprintf( stderr, "error occured " );
2862                    return;
2863            }
2864    
2865            const item_t* pitem;
2866            result = getItem( (sessionid_t)sid, iid, &pitem );
2867            if ( RES_OK == result ){
2868                    itemToZval( pitem,  zitem );
2869                    freeItem( pitem );
2870            }
2871            RETURN_LONG( result );
2872    }
2873    
2874    
2875    /**
2876     *
2877     * アイテム情報取得.
2878     * 取得したアイテムは,使用後freeItemで解放する.
2879     *
2880     * @refer freeItem
2881     * @param sid セッションID
2882     * @param iids 取得したいアイテムのIDの配列
2883     * @param iidsLen iids配列の要素数
2884     * @param cri 結果の範囲指定,ソート条件指定
2885     * @param items 検索結果の配列のポインタを書き込む引数
2886     * @param itemsLen 検索結果の数(配列*itemsの要素数)
2887     * @return RES_OK
2888     * @return RES_DB_NOT_INITIALIZED
2889     * @return RES_NO_SUCH_SESSION
2890     * @return RES_DB_QUERY_ERROR
2891     *
2892     */
2893    ZEND_FUNCTION(xnp_get_items)
2894    {
2895            result_t result;
2896            long sid;
2897            zval *ziids;
2898            zval *zcriteria;
2899            zval *zitem;
2900    
2901            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laaa",
2902              &sid, &ziids, &zcriteria, &zitem) == FAILURE) {
2903                    return;
2904            }
2905    
2906            zCriteria_t zcri(zcriteria);
2907            result = zcri.getResult();
2908            if ( RES_OK == result ){
2909                    zIIDs_t zIIDs(ziids);
2910                    result = zIIDs.getResult();
2911                    if ( RES_OK == result ){
2912                            const item_t *pitems;
2913                            int itemLen;
2914                            result = getItems( (sessionid_t)sid,
2915                                                               zIIDs.getPIID(), zIIDs.getLen(),
2916                                                               &zcri, &pitems, &itemLen );
2917                            if ( RES_OK == result ){
2918                                    itemsToZval( pitems, itemLen, zitem );
2919                                    freeItem( pitems );
2920                            }
2921                    }
2922            }
2923    
2924            RETURN_LONG(result);
2925    }
2926    
2927    
2928    /**
2929     *
2930     *
2931     * @param pmid PUBMEDID
2932     * @param pubmed 結果を書き込むpubmed_tのポインタ引数
2933     *
2934     *
2935     *
2936     */
2937    ZEND_FUNCTION(xnp_pubmed_complete)
2938    {
2939            long pmid;
2940            zval *zpubmed;
2941            result_t result = RES_ERROR;
2942    
2943            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
2944                                                              &pmid, &zpubmed) == FAILURE) {
2945                    fprintf( stderr, "error occured " );
2946                    return;
2947            }
2948    
2949            const pubmed_t* ppubmed;
2950            result = pubmedComplete( pmid, &ppubmed );
2951            if ( RES_OK == result ){
2952                    pubmedToZval( ppubmed,  zpubmed );
2953                    freePubmed( ppubmed );
2954            }
2955            RETURN_LONG( result );
2956    }
2957    
2958    
2959    /**
2960     *
2961     *
2962     * @param isbn ISBN
2963     * @param amazonbook 結果を書き込むamazonbook_tのポインタ引数
2964     *
2965     *
2966     *
2967     */
2968    ZEND_FUNCTION(xnp_amazon_complete)
2969    {
2970            zval *zurl;
2971            zval *zamazonbook;
2972            result_t result = RES_ERROR;
2973    
2974            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za",
2975                                                              &zurl, &zamazonbook) == FAILURE) {
2976                    fprintf( stderr, "error occured " );
2977                    return;
2978            }
2979    
2980            const amazonbook_t* pamazonbook;
2981            result = amazonComplete( getZvalString( &zurl ) , &pamazonbook );
2982            if ( RES_OK == result ){
2983                    amazonbookToZval( pamazonbook,  zamazonbook );
2984                    //freeAmazonbook( pamazonbook );
2985            }
2986            RETURN_LONG( result );
2987    }
2988    
2989    
2990    //ZEND_FUNCTION(xnp_uninitialize_db)
2991    //{
2992    //    RETURN_LONG( RES_ERROR );
2993    //}
2994    
2995    
2996    /**
2997     *
2998     * バインダーにアイテムを追加する
2999     *
3000     * @param sid セッションID
3001     * @param binderid 処理対象のバインダーのID
3002     * @param iid バインダーに追加したいアイテムのID
3003     * @return RES_OK
3004     * @return RES_DB_QUERY_ERROR
3005     * @return RES_NO_SUCH_SESSION
3006     * @return RES_NO_WRITE_ACCESS_RIGHT
3007     * @return RES_ERROR
3008     *
3009     */
3010    ZEND_FUNCTION(xnp_register_binder_item)
3011    {
3012            result_t result = RES_ERROR;
3013            long sid;
3014            long bid;
3015            long iid;
3016    
3017            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3018              &sid, &bid, &iid) == FAILURE) {
3019                    return;
3020            }
3021    
3022            result = registerBinderItem( (sessionid_t)sid, bid, iid );
3023            RETURN_LONG(result);
3024    }
3025    
3026    
3027    /**
3028     *
3029     * バインダーからアイテムを削除する
3030     *
3031     * @param sid セッションID
3032     * @param binderid 処理対象のバインダーのID
3033     * @param iid バインダーから削除したいアイテムのID
3034     * @return RES_OK
3035     * @return RES_DB_QUERY_ERROR
3036     * @return RES_NO_SUCH_SESSION
3037     * @return RES_NO_WRITE_ACCESS_RIGHT
3038     * @return RES_ERROR
3039     *
3040     */
3041    ZEND_FUNCTION(xnp_unregister_binder_item)
3042    {
3043            result_t result = RES_ERROR;
3044            long sid;
3045            long bid;
3046            long iid;
3047    
3048            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3049              &sid, &bid, &iid) == FAILURE) {
3050                    return;
3051            }
3052    
3053            result = registerBinderItem( (sessionid_t)sid, bid, iid );
3054            RETURN_LONG(result);
3055    }
3056    
3057    
3058    /**
3059     *
3060     * インデックスにアイテムを追加する
3061     *
3062     * @param sid セッションID
3063     * @param xid 処理対象のインデックスのID
3064     * @param iid インデックスに追加したいアイテムのID
3065     * @return RES_OK
3066     * @return RES_DB_QUERY_ERROR
3067     * @return RES_NO_SUCH_SESSION
3068     * @return RES_NO_WRITE_ACCESS_RIGHT
3069     * @return RES_ERROR
3070     *
3071     */
3072    ZEND_FUNCTION(xnp_register_item)
3073    {
3074            result_t result = RES_ERROR;
3075            long sid;
3076            long xid;
3077            long iid;
3078    
3079            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3080              &sid, &xid, &iid) == FAILURE) {
3081                    return;
3082            }
3083    
3084            result = registerItem( (sessionid_t)sid, xid, iid );
3085            RETURN_LONG(result);
3086    }
3087    
3088    
3089    /**
3090     *
3091     * インデックスからアイテムを削除する
3092     *
3093     * @param sid セッションID
3094     * @param xid 処理対象のインデックスのID
3095     * @param iid インデックスから削除したいアイテムのID
3096     * @return RES_OK
3097     * @return RES_DB_QUERY_ERROR
3098     * @return RES_NO_SUCH_SESSION
3099     * @return RES_NO_WRITE_ACCESS_RIGHT
3100     * @return RES_ERROR
3101     *
3102     */
3103    ZEND_FUNCTION(xnp_unregister_item)
3104    {
3105            result_t result = RES_ERROR;
3106            long sid;
3107            long xid;
3108            long iid;
3109    
3110            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
3111              &sid, &xid, &iid) == FAILURE) {
3112                    return;
3113            }
3114    
3115            result = unregisterItem( (sessionid_t)sid, xid, iid );
3116            RETURN_LONG(result);
3117    }

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

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