<commit_before><?php
/**
 * Push Notification Template service that allows registration for a push queue 
 *
 * @service pushNotificationTemplate
 * @package plugins.pushNotification
 * @subpackage api.services
 */
class PushNotificationTemplateService extends KalturaBaseService
{        
    private function doesParamExist($templateParam, $userParamsArray)
    {
        foreach ($userParamsArray as $userParam)
        {
            if ($templateParam->getKey() == $userParam->toObject()->getKey())
                return true;
        }
    }
    
    private function encode($msg)
    {
        // using a 128 Rijndael encyrption algorithm with Cipher-block chaining (CBC) as mode of AES encryption
        $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
        $secret = kConf::get("push_server_secret");
        $iv = kConf::get("push_server_secret_iv");
        
        mcrypt_generic_init($cipher, $secret, $iv);
        $cipherData = mcrypt_generic($cipher, $msg);
        mcrypt_generic_deinit($cipher);
        
        return bin2hex($cipherData);
    }
    
	/**
	 * Register to a queue from which event messages will be provided according to given template. Queue will be created if not already exists
	 * 
	 * @action register
	 * @actionAlias eventNotification_eventNotificationTemplate.register
	 * @param string $notificationTemplateSystemName Existing push notification template system name
	 * @param KalturaEventNotificationParameterArray $userParamsArray User params
	 * @return KalturaPushNotificationData
	 */
	function registerAction($notificationTemplateSystemName, $userParamsArray)
	{
	    // find the template, according to its system name, on both current partner and partner 0
	    $partnerId = $this->getPartnerId();
	    $partnersIds = array ( 
	        PartnerPeer::GLOBAL_PARTNER,
	        $partnerId,
	     );
	    $dbEventNotificationTemplate = EventNotificationTemplatePeer::retrieveBySystemName($notificationTemplateSystemName, null, $partnersIds);
	    if (!$dbEventNotificationTemplate)
	        throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_SYSTEM_NAME_NOT_FOUND, $notificationTemplateSystemName);
	    
	    // verify template is push typed
	    if (!$dbEventNotificationTemplate instanceof PushNotificationTemplate)
	        throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_WRONG_TYPE, $notificationTemplateSystemName, get_class($dbEventNotificationTemplate) );
	    
	    // Check all template needed params were actually given 
	    $missingParams = array();
	    $templateParams = $dbEventNotificationTemplate->getContentParameters();

	    foreach ($templateParams as $templateParam)
	    {
	        if (!$this->doesParamExist($templateParam,$userParamsArray))
	            array_push($missingParams, $templateParam->getKey());
	    }
	    
	    if ( $missingParams != null )
	        throw new KalturaAPIException(KalturaErrors::MISSING_MANDATORY_PARAMETER,  implode(",", $missingParams ));
	    
	    $queueKey = $dbEventNotificationTemplate->getQueueKey($userParamsArray->toObjectsArray(), $partnerId, null);
	    
	    // create queue if not exists 
	    if (!$dbEventNotificationTemplate->exists($queueKey))
	       $dbEventNotificationTemplate->create($queueKey);
	    
	    $result = new KalturaPushNotificationData();
	    $result->key = $queueKey;

	    // build the url to return
	    $protocol = infraRequestUtils::getProtocol();
	    $host = kConf::get("push_server_host");
	    $templateId = $dbEventNotificationTemplate->getId();
	    $secret = kConf::get("push_server_secret");
	    $token = base64_encode($partnerId . ":" . $this->encode($secret . ":" . time() ) );
	    $result->url = $protocol . "://" . $host ."/p/" . $partnerId ."/e/" . $templateId ."/t/" . $token;
	    
	    return $result;
	}
}<commit_msg>changed push server url in response to correspond socket io design<commit_after><?php
/**
 * Push Notification Template service that allows registration for a push queue 
 *
 * @service pushNotificationTemplate
 * @package plugins.pushNotification
 * @subpackage api.services
 */
class PushNotificationTemplateService extends KalturaBaseService
{        
    private function doesParamExist($templateParam, $userParamsArray)
    {
        foreach ($userParamsArray as $userParam)
        {
            if ($templateParam->getKey() == $userParam->toObject()->getKey())
                return true;
        }
    }
    
    private function encode($msg)
    {
        // using a 128 Rijndael encyrption algorithm with Cipher-block chaining (CBC) as mode of AES encryption
        $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
        $secret = kConf::get("push_server_secret");
        $iv = kConf::get("push_server_secret_iv");
        
        mcrypt_generic_init($cipher, $secret, $iv);
        $cipherData = mcrypt_generic($cipher, $msg);
        mcrypt_generic_deinit($cipher);
        
        return bin2hex($cipherData);
    }
    
	/**
	 * Register to a queue from which event messages will be provided according to given template. Queue will be created if not already exists
	 * 
	 * @action register
	 * @actionAlias eventNotification_eventNotificationTemplate.register
	 * @param string $notificationTemplateSystemName Existing push notification template system name
	 * @param KalturaEventNotificationParameterArray $userParamsArray User params
	 * @return KalturaPushNotificationData
	 */
	function registerAction($notificationTemplateSystemName, $userParamsArray)
	{
	    // find the template, according to its system name, on both current partner and partner 0
	    $partnerId = $this->getPartnerId();
	    $partnersIds = array ( 
	        PartnerPeer::GLOBAL_PARTNER,
	        $partnerId,
	     );
	    $dbEventNotificationTemplate = EventNotificationTemplatePeer::retrieveBySystemName($notificationTemplateSystemName, null, $partnersIds);
	    if (!$dbEventNotificationTemplate)
	        throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_SYSTEM_NAME_NOT_FOUND, $notificationTemplateSystemName);
	    
	    // verify template is push typed
	    if (!$dbEventNotificationTemplate instanceof PushNotificationTemplate)
	        throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_WRONG_TYPE, $notificationTemplateSystemName, get_class($dbEventNotificationTemplate) );
	    
	    // Check all template needed params were actually given 
	    $missingParams = array();
	    $templateParams = $dbEventNotificationTemplate->getContentParameters();

	    foreach ($templateParams as $templateParam)
	    {
	        if (!$this->doesParamExist($templateParam,$userParamsArray))
	            array_push($missingParams, $templateParam->getKey());
	    }
	    
	    if ( $missingParams != null )
	        throw new KalturaAPIException(KalturaErrors::MISSING_MANDATORY_PARAMETER,  implode(",", $missingParams ));
	    
	    $queueKey = $dbEventNotificationTemplate->getQueueKey($userParamsArray->toObjectsArray(), $partnerId, null);
	    
	    // create queue if not exists 
	    if (!$dbEventNotificationTemplate->exists($queueKey))
	       $dbEventNotificationTemplate->create($queueKey);
	    
	    $result = new KalturaPushNotificationData();
	    $result->key = $queueKey;

	    // build the url to return
	    $protocol = infraRequestUtils::getProtocol();
	    $host = kConf::get("push_server_host");
	    $templateId = $dbEventNotificationTemplate->getId();
	    $secret = kConf::get("push_server_secret");
	    $token = base64_encode($partnerId . ":" . $this->encode($secret . ":" . time() ) );
	    $result->url = $protocol . "://" . $host ."/?p=" . $partnerId ."&e=" . $templateId ."&x=" . $token;
	    
	    return $result;
	}
}
{'fraction_non_alphanumeric': 0.10442229038854806, 'fraction_numerical': 0.002556237218813906, 'mean_word_length': 3.68562874251497, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 33, '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': '5567362', 'n_tokens_mistral': 2216, 'n_tokens_neox': 2065, 'n_words': 476}