<commit_before><?php
/**
 * 
 * @package Scheduler
 * @subpackage Notifier
 * 
 */

class KAsyncNotifierSender
{
	const OK = 0; 
	const ERROR_RETRY = -1;
	const ERROR_NO_RETRY = -2;
	
	private static $curl;
	
	/**
	 * @param string $url
	 * @param array $params
	 */
	public static function createDebugHtml($url, $params)
	{
		$inputs = '';
		foreach($params as $param => $value)
			$inputs .= "<input name=\"$param\" value=\"$value\"/>";
		
		KalturaLog::debug('
		<html>
			<body>
				<form method="post" action="' . $url . '">
					' . $inputs . '
					<input type="submit" value="test"/>
				</form>
			</body>
		</html>
		'); 
	}
	
	/**
	 * @param string $url
	 * @param array $params
	 * @return array 
	 */
	public static function send($url, $params)
	{
		static $close_count = 0;
		
		KalturaLog::debug("send($url)"); 
		
		self::createDebugHtml($url, $params);
		
		// once every some time - close the connection and reconnect
		if($close_count > 50)
		{
			self::closeConnection();
			$close_count = 0;
		}
		
		$close_count ++;
		
		if(! self::$curl)
			self::$curl = curl_init();
		$ch = self::$curl;
		
		try
		{
			//TRACE ( "-- Hitting URL: $url" );
			$header = array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5", "Accept-Encoding: gzip,deflate", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Keep-Alive: 300", "Connection: keep-alive");
			
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params, null, "&"));
			
			// 			curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
			curl_setopt($ch, CURLOPT_URL, $url);
			
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_USERAGENT, '');
			curl_setopt($ch, CURLOPT_TIMEOUT, 10);
			//			curl_setopt($ch, CURLOPT_HEADER , true );
			

			//			curl_setopt($ch, CURLOPT_VERBOSE, true );
			//			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);		
			

			$result = curl_exec($ch);
			
			$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		}
		catch(Exception $ex)
		{
			self::closeConnection();
			KalturaLog::err('Sending notification failed with message: '.$ex->getMessage());
			throw $ex;
		}
		
		return array($params, $result, $http_code);
	}
	
	private static function closeConnection()
	{
		KalturaLog::debug("Closing connection");
		if(self::$curl != null)
			curl_close(self::$curl);
		self::$curl = null;
	}
<commit_msg>qnd: mantis 11963: this basically causes cURL to blindly accept any server certificate, without doing any verification as to which CA signed it, and whether or not that CA is trusted<commit_after><?php
/**
 * 
 * @package Scheduler
 * @subpackage Notifier
 * 
 */

class KAsyncNotifierSender
{
	const OK = 0; 
	const ERROR_RETRY = -1;
	const ERROR_NO_RETRY = -2;
	
	private static $curl;
	
	/**
	 * @param string $url
	 * @param array $params
	 */
	public static function createDebugHtml($url, $params)
	{
		$inputs = '';
		foreach($params as $param => $value)
			$inputs .= "<input name=\"$param\" value=\"$value\"/>";
		
		KalturaLog::debug('
		<html>
			<body>
				<form method="post" action="' . $url . '">
					' . $inputs . '
					<input type="submit" value="test"/>
				</form>
			</body>
		</html>
		'); 
	}
	
	/**
	 * @param string $url
	 * @param array $params
	 * @return array 
	 */
	public static function send($url, $params)
	{
		static $close_count = 0;
		
		KalturaLog::debug("send($url)"); 
		
		self::createDebugHtml($url, $params);
		
		// once every some time - close the connection and reconnect
		if($close_count > 50)
		{
			self::closeConnection();
			$close_count = 0;
		}
		
		$close_count ++;
		
		if(! self::$curl)
			self::$curl = curl_init();
		$ch = self::$curl;
		
		try
		{
			//TRACE ( "-- Hitting URL: $url" );
			$header = array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5", "Accept-Encoding: gzip,deflate", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", "Keep-Alive: 300", "Connection: keep-alive");
			
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params, null, "&"));
			
			// 			curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
			curl_setopt($ch, CURLOPT_URL, $url);
			
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_USERAGENT, '');
			curl_setopt($ch, CURLOPT_TIMEOUT, 10);
			
			//causes cURL to blindly accept any server certificate.use for https URLs
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
			//			curl_setopt($ch, CURLOPT_HEADER , true );
			

			//			curl_setopt($ch, CURLOPT_VERBOSE, true );
			//			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);		
			

			$result = curl_exec($ch);
			
			$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		}
		catch(Exception $ex)
		{
			self::closeConnection();
			KalturaLog::err('Sending notification failed with message: '.$ex->getMessage());
			throw $ex;
		}
		
		return array($params, $result, $http_code);
	}
	
	private static function closeConnection()
	{
		KalturaLog::debug("Closing connection");
		if(self::$curl != null)
			curl_close(self::$curl);
		self::$curl = null;
	}

{'fraction_non_alphanumeric': 0.1734338747099768, 'fraction_numerical': 0.012180974477958236, 'mean_word_length': 3.482668977469671, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '7145816', 'n_tokens_mistral': 2274, 'n_tokens_neox': 1858, 'n_words': 386}