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.21 by youi, Wed Jan 12 11:39:52 2005 UTC revision 1.22 by aga, Fri Jan 14 10:37:17 2005 UTC
# Line 63  ZEND_FUNCTION(xnp_get_groups        ); Line 63  ZEND_FUNCTION(xnp_get_groups        );
63  ZEND_FUNCTION(xnp_is_moderator      );  ZEND_FUNCTION(xnp_is_moderator      );
64  ZEND_FUNCTION(xnp_get_uid           );  ZEND_FUNCTION(xnp_get_uid           );
65    
66    ZEND_FUNCTION(xnp_get_all_indexes     );
67    ZEND_FUNCTION(xnp_get_indexes         );
68    ZEND_FUNCTION(xnp_insert_index        );
69    ZEND_FUNCTION(xnp_update_index        );
70    ZEND_FUNCTION(xnp_delete_index        );
71    ZEND_FUNCTION(xnp_get_index           );
72    ZEND_FUNCTION(xnp_is_index_readable   );
73    ZEND_FUNCTION(xnp_is_index_writable   );
74    ZEND_FUNCTION(xnp_swap_index_sort_number );
75    
76  ZEND_FUNCTION(xnp_is_valid_session_id );  ZEND_FUNCTION(xnp_is_valid_session_id );
77  ZEND_FUNCTION(xnp_get_last_error_string );  ZEND_FUNCTION(xnp_get_last_error_string );
78    
# Line 102  zend_function_entry xnpalmod_functions[] Line 112  zend_function_entry xnpalmod_functions[]
112      ZEND_FE(xnp_get_groups        ,NULL)      ZEND_FE(xnp_get_groups        ,NULL)
113      ZEND_FE(xnp_is_moderator      ,NULL)      ZEND_FE(xnp_is_moderator      ,NULL)
114      ZEND_FE(xnp_get_uid           ,NULL)      ZEND_FE(xnp_get_uid           ,NULL)
115    
116        ZEND_FE(xnp_get_all_indexes     ,NULL)
117        ZEND_FE(xnp_get_indexes         ,NULL)
118        ZEND_FE(xnp_insert_index        ,NULL)
119        ZEND_FE(xnp_update_index        ,NULL)
120        ZEND_FE(xnp_delete_index        ,NULL)
121        ZEND_FE(xnp_get_index           ,NULL)
122        ZEND_FE(xnp_is_index_readable   ,NULL)
123        ZEND_FE(xnp_is_index_writable   ,NULL)
124        ZEND_FE(xnp_swap_index_sort_number ,NULL)
125    
126      ZEND_FE(xnp_is_valid_session_id ,NULL)      ZEND_FE(xnp_is_valid_session_id ,NULL)
127      ZEND_FE(xnp_get_last_error_string ,NULL)      ZEND_FE(xnp_get_last_error_string ,NULL)
128      ZEND_FE(xnp_test_criteria     ,NULL)      ZEND_FE(xnp_test_criteria     ,NULL)
# Line 402  private: Line 423  private:
423                  if ( hashGetString( ht, "base_url"          , &p ) ) setBaseURL          ( p );                  if ( hashGetString( ht, "base_url"          , &p ) ) setBaseURL          ( p );
424                  if ( hashGetLong  ( ht, "notice_mail"       , &l ) ) setNoticeMail       ( l );                  if ( hashGetLong  ( ht, "notice_mail"       , &l ) ) setNoticeMail       ( l );
425                  if ( hashGetLong  ( ht, "notice_mail_since" , &l ) ) setNoticeMailSince  ( l );                  if ( hashGetLong  ( ht, "notice_mail_since" , &l ) ) setNoticeMailSince  ( l );
426                    if ( hashGetLong  ( ht, "private_index_id " , &l ) ) setPrivateIndexID   ( l );
427    
428                  result = RES_OK;                  result = RES_OK;
429          }          }
# Line 415  public: Line 437  public:
437          result_t getResult(){ return result; };          result_t getResult(){ return result; };
438  };  };
439    
440    class zIndex_t : public index {
441    private:
442            result_t result;
443            
444            void initialize(zval *pz){
445                    HashTable *ht = Z_ARRVAL_P(pz);
446                    long l;
447                    char *p;
448                    double d;
449                    if ( hashGetLong  ( ht, "item_id"           , &l ) ) setItemID           ( l );
450                    if ( hashGetLong  ( ht, "item_type_id"      , &l ) ) setItemTypeID       ( l );
451                    if ( hashGetString( ht, "subtype"           , &p ) ) setSubtype          ( p );
452                    if ( hashGetLong  ( ht, "contributor_uid"   , &l ) ) setContributorUID   ( l );
453                    if ( hashGetString( ht, "title"             , &p ) ) setTitle            ( p );
454                    if ( hashGetString( ht, "keywords"          , &p ) ) setKeywords         ( p );
455                    if ( hashGetString( ht, "description"       , &p ) ) setDescription      ( p );
456                    if ( hashGetLong  ( ht, "last_update_date"  , &l ) ) setLastUpdateDate   ( l );
457                    if ( hashGetLong  ( ht, "creation_date"     , &l ) ) setCreationDate     ( l );
458                    if ( hashGetLong  ( ht, "parent_index_id"   , &l ) ) setParentIndexID    ( l );
459                    if ( hashGetLong  ( ht, "owner_uid"         , &l ) ) setOwnerUID         ( l );
460                    if ( hashGetLong  ( ht, "owner_gid"         , &l ) ) setOwnerGID         ( l );
461                    if ( hashGetLong  ( ht, "open_level"        , &l ) ) setOpenLevel        ( l );
462                    if ( hashGetLong  ( ht, "sort_number"       , &l ) ) setSortNumber       ( l );
463    
464                    result = RES_OK;
465            }
466    public:
467            zIndex_t() : index(){ result = RES_ERROR; }
468            zIndex_t( zval *pz ) : index(){ initialize(pz); }
469            zIndex_t( zval **ppz ) : index() { initialize(*ppz); }
470            result_t getResult(){ return result; };
471            
472            void dump(){
473            }
474    };
475    
476  /** zval*から(userid_t *puid,int uidLen)を生成するためのクラス。 <br>  /** zval*から(userid_t *puid,int uidLen)を生成するためのクラス。 <br>
477      生成失敗ならgetResult()!=RES_OK <br>      生成失敗ならgetResult()!=RES_OK <br>
478    */    */
# Line 583  result_t accountToZval( const account_t Line 641  result_t accountToZval( const account_t
641      add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );      add_assoc_string( z, "base_url", ( char* )pAccount -> getBaseURL( ), 1 );
642      add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );      add_assoc_long( z, "notice_mail", pAccount -> getNoticeMail( ) );
643      add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );      add_assoc_long( z, "notice_mail_since", pAccount -> getNoticeMailSince( ) );
644        add_assoc_long( z, "private_index_id", pAccount -> getPrivateIndexID( ) );
645          return RES_OK;          return RES_OK;
646  }  }
647  /**  /**
# Line 651  result_t groupsToZval( const group_t *pG Line 710  result_t groupsToZval( const group_t *pG
710          add_assoc_long( new_array, "gid",  pGroups[ i ].getGID( ) );          add_assoc_long( new_array, "gid",  pGroups[ i ].getGID( ) );
711          add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );          add_assoc_string( new_array, "gname", ( char* )pGroups[ i ].getGname( ), 1 );
712          add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );          add_assoc_string( new_array, "gdesc", ( char* )pGroups[ i ].getDesc( ), 1 );
713            add_assoc_long( new_array, "group_index_id",  pGroups[ i ].getGroupIndexID( ) );
714      }      }
715          return RES_OK;          return RES_OK;
716  }  }
# Line 670  result_t groupToZval( const group_t *pGr Line 730  result_t groupToZval( const group_t *pGr
730      add_assoc_long( z, "gid",  pGroup -> getGID( ) );      add_assoc_long( z, "gid",  pGroup -> getGID( ) );
731      add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );      add_assoc_string( z, "gname", ( char* )pGroup -> getGname( ), 1 );
732      add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );      add_assoc_string( z, "gdesc", ( char* )pGroup -> getDesc( ), 1 );
733        add_assoc_long( z, "group_index_id",  pGroup -> getGroupIndexID( ) );
734          return RES_OK;          return RES_OK;
735  }  }
736    
# Line 704  result_t zvalToGroup( zval *z, group_t * Line 765  result_t zvalToGroup( zval *z, group_t *
765          convert_to_string_ex( tmp ) ;          convert_to_string_ex( tmp ) ;
766          pGroup -> setDesc( (*tmp) -> value.str.val );          pGroup -> setDesc( (*tmp) -> value.str.val );
767      }      }
768        key = "group_index_id";
769        if( zend_hash_find( z -> value.ht, key, strlen( key ) + 1, ( void** )&tmp ) == SUCCESS ){
770            convert_to_long_ex( tmp ) ;
771            pGroup -> setGroupIndexID( (*tmp) -> value.lval );
772        }    
773          return RES_OK;          return RES_OK;
774  }  }
775    
# Line 730  result_t sessionToZval( const session_t Line 796  result_t sessionToZval( const session_t
796          return RES_OK;          return RES_OK;
797  }  }
798    
799    /**
800     *
801     * index_tの内容をPHPの配列に変換する
802     * @param pIndex 変換元のindex_t*
803     * @param z        変換結果を書き込む配列(初期化済みであること)
804     * @return RES_OK
805     *
806     */
807    result_t indexToZval( const index_t *pIndex, zval *z )
808    {
809        zend_hash_clean( z -> value.ht );
810        
811        add_assoc_long( z, "item_id", pIndex -> getItemID( ) );
812        add_assoc_long( z, "item_type_id", pIndex -> getItemTypeID( ) );
813        add_assoc_string( z, "subtype", ( char* )pIndex -> getSubtype( ), 1 );
814        add_assoc_long( z, "contributor_uid", pIndex -> getContributorUID( ) );
815        add_assoc_string( z, "title", ( char* )pIndex -> getTitle( ), 1 );
816        add_assoc_string( z, "keywords", ( char* )pIndex -> getKeywords( ), 1 );
817        add_assoc_string( z, "description", ( char* )pIndex -> getDescription( ), 1 );
818        add_assoc_long( z, "last_update_date", pIndex -> getLastUpdateDate( ) );
819        add_assoc_long( z, "creation_date", pIndex-> getCreationDate( ) );
820        add_assoc_long( z, "parent_index_id", pIndex -> getParentIndexID( ) );
821        add_assoc_long( z, "owner_uid", pIndex -> getOwnerUID( ) );
822        add_assoc_long( z, "owner_gid", pIndex -> getOwnerGID( ) );
823        add_assoc_long( z, "open_level", pIndex -> getOpenLevel( ) );
824        add_assoc_long( z, "sort_number", pIndex -> getSortNumber( ) );
825            return RES_OK;
826    }
827    
828    result_t indexesToZval( const index_t *pIndexes, int indexesLen, zval *z )
829    {
830        zend_hash_clean( z -> value.ht );
831        for( int i = 0; i < indexesLen; i++ ){
832            zval *new_array;
833            MAKE_STD_ZVAL(new_array);
834            if(array_init(new_array) != SUCCESS){
835                return RES_ERROR;
836            }
837            add_index_zval( z, i, new_array );
838            indexToZval( &pIndexes[ i ], new_array );
839        }
840            return RES_OK;
841    }
842    
843    
844    
845    
846  /** 指定したグループの情報を得る<br>  /** 指定したグループの情報を得る<br>
# Line 1624  ZEND_FUNCTION(xnp_dump_group_admins) Line 1735  ZEND_FUNCTION(xnp_dump_group_admins)
1735      RETURN_LONG( result );      RETURN_LONG( result );
1736  }  }
1737  */  */
1738        
1739    /** 全てのインデックスを得る<br>
1740     *   int xnp_get_all_indexes( int sid, array criteria, array indexes );
1741     * @param sid XNPのセッションID
1742     * @param cri 結果の範囲指定,ソート条件指定
1743     * @return RES_OK
1744     */
1745    ZEND_FUNCTION(xnp_get_all_indexes)
1746    {
1747            long sid;
1748            zval *zcriteria;
1749            zval *zindexes;
1750            
1751            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa",
1752                                  &sid, &zcriteria, &zindexes) == FAILURE) {
1753                    return;
1754            }
1755            zCriteria_t zcri(zcriteria);
1756            result_t result = zcri.getResult();
1757            if ( RES_OK == result ){
1758                    const index_t *indexes;
1759                    int indexesLen;
1760                    result = getAllIndexes( sid, &zcri, &indexes, &indexesLen );
1761                    if ( RES_OK == result ){
1762                            result = indexesToZval( indexes, indexesLen, zindexes );
1763                            freeIndex( indexes );
1764                    }
1765            }
1766            RETURN_LONG(result);
1767    }
1768    
1769    /** あるインデックスの全ての子インデックスを得る<br>
1770     *   int xnp_get_indexes( int sid, int parentXID, array criteria, array indexes );
1771     * @param sid XNPのセッションID
1772     * @param parentXID 親のindexID
1773     * @param cri 結果の範囲指定,ソート条件指定
1774     * @param indexes 結果を受け取る配列
1775     * @return RES_OK
1776     */
1777    ZEND_FUNCTION(xnp_get_indexes)
1778    {
1779            long sid;
1780            long parentXID;
1781            zval *zcriteria;
1782            zval *zindexes;
1783            
1784            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llaa",
1785                                  &sid, &parentXID, &zcriteria, &zindexes) == FAILURE) {
1786                    return;
1787            }
1788            zCriteria_t zcri(zcriteria);
1789            result_t result = zcri.getResult();
1790            if ( RES_OK == result ){
1791                    const index_t *indexes;
1792                    int indexesLen;
1793                    result = getIndexes( sid, parentXID, &zcri, &indexes, &indexesLen );
1794                    if ( RES_OK == result ){
1795                            result = indexesToZval( indexes, indexesLen, zindexes );
1796                            freeIndex( indexes );
1797                    }
1798            }
1799            RETURN_LONG(result);
1800    }
1801    
1802    
1803    /** インデックスを作成する<br>
1804     *   int xnp_insert_index( int sid, array index, int &indexID );
1805     * @param sid XNPのセッションID
1806     * @param index 作成するインデックス
1807     * @param indexID 作成されたインデックスのIDを受け取る変数
1808     * @return RES_OK
1809     */
1810    ZEND_FUNCTION(xnp_insert_index)
1811    {
1812            long sid;
1813            zval *zindex;
1814            zval *zIndexID;
1815            
1816            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laz",
1817                                  &sid, &zindex, &zIndexID) == FAILURE) {
1818                    return;
1819            }
1820            
1821            if (!PZVAL_IS_REF(zIndexID)) {
1822                    zend_error(E_WARNING, "3rd parameter wasn't passed by reference");
1823                    RETURN_LONG(RES_PHP_NONREF);
1824            }
1825            zIndex_t index( zindex );
1826            indexid_t xid;
1827            result_t result = insertIndex( sid, &index, &xid );
1828            if ( RES_OK == result )
1829                    ZVAL_LONG(zIndexID, (long)xid);
1830            RETURN_LONG(result);
1831    }
1832    
1833    /** インデックスを更新する<br>
1834     *   int xnp_update_index( int sid, array index );
1835     * @param sid XNPのセッションID
1836     * @param index 更新するインデックス
1837     * @return RES_OK
1838     */
1839    ZEND_FUNCTION(xnp_update_index)
1840    {
1841            long sid;
1842            zval *zindex;
1843            
1844            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la",
1845                                  &sid, &zindex) == FAILURE) {
1846                    return;
1847            }
1848            zIndex_t index(zindex);
1849            result_t result = index.getResult();
1850            if ( RES_OK == result ){
1851                    result = updateIndex( sid, &index );
1852            }
1853            RETURN_LONG(result);
1854    }
1855    
1856    /** インデックスを削除する<br>
1857     *   int xnp_delete_index( int sid, int indexID );
1858     * @param sid XNPのセッションID
1859     * @param indexID 削除するインデックス
1860     * @return RES_OK
1861     */
1862    ZEND_FUNCTION(xnp_delete_index)
1863    {
1864            long sid;
1865            long xid;
1866            
1867            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1868                                  &sid, &xid) == FAILURE) {
1869                    return;
1870            }
1871            
1872            result_t result = deleteIndex( sid, xid );
1873            RETURN_LONG(result);
1874    }
1875    
1876    
1877    /** インデックスを取得する<br>
1878     *   int xnp_get_index( int sid, int indexID, array index );
1879     * @param sid XNPのセッションID
1880     * @param indexID 取得するインデックスのID
1881     * @param index 取得結果を受け取る連想配列
1882     * @return RES_OK
1883     */
1884    ZEND_FUNCTION(xnp_get_index)
1885    {
1886            long sid;
1887            long xid;
1888            zval *zindex;
1889            
1890            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lla",
1891                                  &sid, &xid, &zindex) == FAILURE) {
1892                    return;
1893            }
1894            
1895            const index_t *index;
1896            result_t result = getIndex( sid, xid, &index );
1897            if ( RES_OK == result ){
1898                    result = indexToZval( index, zindex );
1899                    freeIndex( index );
1900            }
1901            RETURN_LONG(result);
1902    }
1903    
1904    
1905    
1906    /** インデックスが読み込み可能かどうかを調べる<br>
1907     *   int xnp_is_index_readable( int sid, int indexID );
1908     * @param sid XNPのセッションID
1909     * @param indexID 対象インデックスのID
1910     * @return true false
1911     */
1912    ZEND_FUNCTION(xnp_is_index_readable)
1913    {
1914            long sid;
1915            long xid;
1916            
1917            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1918                                  &sid, &xid) == FAILURE) {
1919                    return;
1920            }
1921            RETURN_BOOL(isIndexReadable(sid,xid));
1922    }
1923    
1924    
1925    /** インデックスが書き込み可能かどうかを調べる<br>
1926     *   int xnp_is_index_writable( int sid, int indexID );
1927     * @param sid XNPのセッションID
1928     * @param indexID 対象インデックスのID
1929     * @return true false
1930     */
1931    ZEND_FUNCTION(xnp_is_index_writable)
1932    {
1933            long sid;
1934            long xid;
1935            
1936            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
1937                                  &sid, &xid) == FAILURE) {
1938                    return;
1939            }
1940            RETURN_BOOL(isIndexWritable(sid,xid));
1941    }
1942    
1943    /** インデックスの順序を入れ替える<br>
1944     *   int xnp_swap_index_sort_number( int sid, int indexID1, int indexID2 );
1945     * @param sid XNPのセッションID
1946     * @param indexID1 対象インデックスのID
1947     * @param indexID2 対象インデックスのID
1948     * @return true false
1949     */
1950    ZEND_FUNCTION(xnp_swap_index_sort_number)
1951    {
1952            long sid;
1953            long xid1, xid2;
1954            
1955            if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
1956                                  &sid, &xid1, &xid2) == FAILURE) {
1957                    return;
1958            }
1959            
1960            result_t result = swapIndexSortNumber( sid, xid1, xid2 );
1961            RETURN_LONG(result);
1962    }
1963    
1964    
1965    
1966  /** XNPのsession_idの正当性チェック<br>  /** XNPのsession_idの正当性チェック<br>
1967      bool xnp_is_valid_session_id( int xnp_session_id)      bool xnp_is_valid_session_id( int xnp_session_id)
1968      @return true 有効なXNPのsession_idである<br>      @return true 有効なXNPのsession_idである<br>

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

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