<commit_before><?php
class Synology_Api extends Synology_Abstract{
	const API_SERVICE_NAME = 'API';
	const API_NAMESPACE = 'SYNO';
	
	private $_sid = null;
	private $_sessionName = 'default';
	
	/**
	 * Info API setup
	 * 
	 * @param string $address
	 * @param int $port
	 * @param string $protocol
	 * @param int $version
	 */
	public function __construct($address, $port = null, $protocol = null, $version = 1){
		parent::__construct(self::API_SERVICE_NAME, self::API_NAMESPACE, $address, $port, $protocol, $version);
	}
	
	/**
	 * Get a list of Service and Apis
	 * @return array
	 */
	public function getAvailableApi(){
		$services = array();
		foreach($this->_request('Info', 'query.cgi', 'query', array('query'=>'all')) as $key => $value){
			$keys = explode('.', $key);
			if(!array_key_exists($keys[0], $services)){
				$services[$keys[0]] = array();
			}
			
			
			if(!array_key_exists($keys[1], $services[$keys[0]])){
				$services[$keys[0]][$keys[1]] = array();
			}
			
			$services[$keys[0]][$keys[1]][$keys[2]] = $value;
		}
		return $services;
	}
	
	/**
	 * Connect to Synology
	 * 
	 * @param string $username
	 * @param string $password
	 * @param string $sessionName
	 * @return Synology_Api
	 */
	public function connect($username, $password, $sessionName = null){
		if(!empty($sessionName)){
			$this->_sessionName = $sessionName;
		}
		
		$this->log($this->_sessionName, 'Connect Session');
		$this->log($username, 'User');
		
		$options = array(
			'account'	=> $username,
			'passwd' 	=> <PASSWORD>,
			'session'	=> $this->_sessionName,
			'format' 	=> 'sid'
		);
		$data = $this->_request('Auth', 'auth.cgi', 'login', $options, 2);
		
		// save session name id
		$this->_sid = $data->sid;
		
		return $this;
	}
	
	/**
	 * Logout from Synology
	 * 
	 * @return Synology_Api
	 */
	public function disconnect(){
		$this->log($this->_sessionName, 'Disconnect Session');
		$this->_request('Auth', 'auth.cgi', 'logout', array('session' => $this->_sessionName));
		$this->_sid = null;<commit_msg>fix logout, by adding sid<commit_after><?php
class Synology_Api extends Synology_Abstract{
	const API_SERVICE_NAME = 'API';
	const API_NAMESPACE = 'SYNO';
	
	private $_sid = null;
	private $_sessionName = 'default';
	
	/**
	 * Info API setup
	 * 
	 * @param string $address
	 * @param int $port
	 * @param string $protocol
	 * @param int $version
	 */
	public function __construct($address, $port = null, $protocol = null, $version = 1){
		parent::__construct(self::API_SERVICE_NAME, self::API_NAMESPACE, $address, $port, $protocol, $version);
	}
	
	/**
	 * Get a list of Service and Apis
	 * @return array
	 */
	public function getAvailableApi(){
		$services = array();
		foreach($this->_request('Info', 'query.cgi', 'query', array('query'=>'all')) as $key => $value){
			$keys = explode('.', $key);
			if(!array_key_exists($keys[0], $services)){
				$services[$keys[0]] = array();
			}
			
			
			if(!array_key_exists($keys[1], $services[$keys[0]])){
				$services[$keys[0]][$keys[1]] = array();
			}
			
			$services[$keys[0]][$keys[1]][$keys[2]] = $value;
		}
		return $services;
	}
	
	/**
	 * Connect to Synology
	 * 
	 * @param string $username
	 * @param string $password
	 * @param string $sessionName
	 * @return Synology_Api
	 */
	public function connect($username, $password, $sessionName = null){
		if(!empty($sessionName)){
			$this->_sessionName = $sessionName;
		}
		
		$this->log($this->_sessionName, 'Connect Session');
		$this->log($username, 'User');
		
		$options = array(
			'account'	=> $username,
			'passwd' 	=> <PASSWORD>,
			'session'	=> $this->_sessionName,
			'format' 	=> 'sid'
		);
		$data = $this->_request('Auth', 'auth.cgi', 'login', $options, 2);
		
		// save session name id
		$this->_sid = $data->sid;
		
		return $this;
	}
	
	/**
	 * Logout from Synology
	 * 
	 * @return Synology_Api
	 */
	public function disconnect(){
		$this->log($this->_sessionName, 'Disconnect Session');
		$this->_request('Auth', 'auth.cgi', 'logout', array('_sid' => $this->_sid,'session' => $this->_sessionName));
		$this->_sid = null;
{'fraction_non_alphanumeric': 0.1932545544066962, 'fraction_numerical': 0.0054160512063023145, 'mean_word_length': 3.8951807228915665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2098618', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1350, 'n_words': 310}