Develop and Download Open Source Software

Browse CVS Repository

Diff of /xoonips/AL/commonal.cc

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

revision 1.44 by youi, Wed Jan 19 06:01:59 2005 UTC revision 1.45 by aga, Wed Jan 19 10:07:53 2005 UTC
# Line 2  Line 2 
2   *   *
3   * $Revision$   * $Revision$
4   * $Log$   * $Log$
5     * Revision 1.45  2005/01/19 10:07:53  aga
6     * ・ゲストユーザ向けの修正.
7     *
8   * Revision 1.44  2005/01/19 06:01:59  youi   * Revision 1.44  2005/01/19 06:01:59  youi
9   * 関数追加   * 関数追加
10   *  getConfigValue   *  getConfigValue
# Line 328  static bool isModeratorBySession( sessio Line 331  static bool isModeratorBySession( sessio
331      return false;      return false;
332  }  }
333    
334    
335    
336    
337  /** SQLを実行する。結果は捨てる。  /** SQLを実行する。結果は捨てる。
338    * @param sql sql    * @param sql sql
339    * @return result_t    * @return result_t
# Line 401  static result_t queryGetUnsignedInt( con Line 407  static result_t queryGetUnsignedInt( con
407      return ret;      return ret;
408  }  }
409    
 /** sidからuidを得る。  
   * @param sid session id  
   * @param uid uidを受け取る変数  
   * @return  
   */  
 static result_t sessionID2UID( sessionid_t sid, userid_t *uid ){  
     if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;  
       
     SQLRETURN sqlcode;  
     SQLHANDLE hstmt = NULL;      
       
     string sql = "SELECT uid FROM " + dbprefix + "_xnpaccount_session WHERE sid=" + unsignedIntToString(sid);  
     return queryGetUnsignedInt( "sessionID2UID", sql, (unsigned int*)uid );  
 }  
   
410  /**  /**
411   *   *
412   * 文字列コピー.   * 文字列コピー.
# Line 528  string addSlashes( const char *str ) Line 519  string addSlashes( const char *str )
519          return s;          return s;
520  }  }
521    
522    /** Xoops Module の設定を調べる
523      * @param module モジュールのdirname
524      * @param key    設定のkey
525      * @param value  設定を返す変数。
526      * @return
527      */
528    static result_t getXoopsModuleConfigValue( const char *module, const char *key, char **value ){
529        SQLRETURN sqlcode;
530        SQLHANDLE hstmt = NULL;
531        result_t result = RES_ERROR;
532        
533        if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
534            string sql = "SELECT conf_value "
535                " from " + dbprefix + "_config as tc, " + dbprefix  + "_modules as tm "
536                " where tm.mid=tc.conf_modid and tm.dirname = ? and tc.conf_name = ? ";
537            sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);
538            SQLINTEGER cbModule = SQL_NTS, cbKey = SQL_NTS;
539            SQLBindParameter(hstmt,  1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, strlen(module), 0, (SQLCHAR *)module, 0, &cbModule );
540            SQLBindParameter(hstmt,  2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, strlen(key),    0, (SQLCHAR *)key,    0, &cbKey );
541            if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), strlen( sql.c_str() ) ) ) == SQL_SUCCESS ){
542                if ( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
543                    string s = getResultCol( hstmt, 1 );
544                    *value = new char[s.length()+1];
545                    strcpy( *value, s.c_str() );
546                    result = RES_OK;
547                }
548                else if ( sqlcode == SQL_NO_DATA ){
549                    value = 0;
550                    result = RES_OK;
551                }
552                else {
553                    string s( "SQLFetch in getXoopsModuleConfig " );
554                    s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
555                    s += "sql=";
556                    s += sql;
557                    setLastErrorString( s.c_str( ) );
558                    result = RES_ERROR;
559                }
560            }else{
561                string s( "SQLExecDirect in getXoopsModuleConfig " );
562                s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
563                s += "sql=";
564                s += sql;
565                setLastErrorString( s.c_str( ) );
566                result = RES_DB_QUERY_ERROR;
567            }
568            SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
569        }
570        else {
571            setLastErrorString( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getXoopsModuleConfig " );
572            result = RES_ERROR;
573        }
574        return result;
575    }
576    
577    /** ゲストユーザがXooNiPsのPublicなアイテムを見ることができるかどうかを返す。
578      */
579    static bool isGuestEnabled(){
580        char *value = 0;
581        result_t result = getXoopsModuleConfigValue( "xnpaccount", "public_item_target_user", &value );
582        if ( result != RES_OK )
583            return false;
584        if ( value == 0 )
585            return false;
586        bool enabled = ( strcmp( value, "all" ) == 0 );
587        freeString( value );
588        return enabled;
589    }
590    
591    /** sidからuidを得る。
592      * @param sid session id
593      * @param uid uidを受け取る変数
594      * @return RES_OK  
595      *   sidは有効なsessionidである。この場合*uidには有効なuidが入る。
596      *   あるいは、公開アイテムを非XooNiPsユーザに公開 かつsidがsession::SID_GUEST(=0)である。この場合、*uidにはaccount::UID_GUEST(=0)が入る。
597      * @return その他            エラー
598      */
599    static result_t sessionID2UID( sessionid_t sid, userid_t *uid ){
600        if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
601        
602        SQLRETURN sqlcode;
603        SQLHANDLE hstmt = NULL;    
604        
605        if ( sid == session::SID_GUEST ){
606            if ( isGuestEnabled() ){
607                *uid = account::UID_GUEST;
608                return RES_OK;
609            }
610            return RES_NO_SUCH_SESSION;
611        }
612        else {
613            string sql = "SELECT uid FROM " + dbprefix + "_xnpaccount_session WHERE sid=" + unsignedIntToString(sid);
614            return queryGetUnsignedInt( "sessionID2UID", sql, uid );
615        }
616    }
617    
618    
619    
620  /**  /**
621   *   *
622   * gidの存在をチェック.   * gidの存在をチェック.
# Line 4083  result_t insertItemInternal( sessionid_t Line 4172  result_t insertItemInternal( sessionid_t
4172   *   *
4173   * @param cond SQLの条件式。省略時は0。 条件式内でtx(index), ti(item), tlink(group_user_link) が利用可能。   * @param cond SQLの条件式。省略時は0。 条件式内でtx(index), ti(item), tlink(group_user_link) が利用可能。
4174   * @param uid  このuidが読み込み権限を持つようなインデックスのみ取得する。   * @param uid  このuidが読み込み権限を持つようなインデックスのみ取得する。
                ただしuid==0なら、読み込み権限を無視する。  
4175   * @param indexes インデックスの一覧を返す変数   * @param indexes インデックスの一覧を返す変数
4176   * @param indexesLen indexesの配列長   * @param indexesLen indexesの配列長
4177   * @return RES_OK 成功   * @return RES_OK 成功
# Line 4102  static result_t getIndexesInternal( sess Line 4190  static result_t getIndexesInternal( sess
4190          cond = " 1 ";          cond = " 1 ";
4191            
4192      string accessRightCond = "1";      string accessRightCond = "1";
4193      if ( uid != 0 && !isModerator( sid, uid ) )      if ( !isModerator( sid, uid ) )
4194          accessRightCond =          accessRightCond =
4195              " (  tx.open_level=1 "              " (  tx.open_level=1 "
4196              " OR tx.open_level=2 AND tlink.uid is not NULL "              " OR tx.open_level=2 AND tlink.uid is not NULL "
# Line 4846  result_t updateIndexInternal( sessionid_ Line 4934  result_t updateIndexInternal( sessionid_
4934          int conflictIndexesLen;          int conflictIndexesLen;
4935          string criteriaString;          string criteriaString;
4936          string cond("tx.sort_number=" + unsignedIntToString(newIndex->getSortNumber()));          string cond("tx.sort_number=" + unsignedIntToString(newIndex->getSortNumber()));
4937          result = getIndexesInternal( sid, cond.c_str() , 0, &conflictIndexes, &conflictIndexesLen, criteriaString );          result = getIndexesInternal( sid, cond.c_str() , uid, &conflictIndexes, &conflictIndexesLen, criteriaString );
4938          if ( result == RES_OK ){          if ( result == RES_OK ){
4939              freeIndex( conflictIndexes );              freeIndex( conflictIndexes );
4940              if ( conflictIndexesLen != 0 ){              if ( conflictIndexesLen != 0 ){

Legend:
Removed from v.1.44  
changed lines
  Added in v.1.45

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