You are here

function kaltura_notification_handler in Kaltura 7.3

Same name and namespace in other branches
  1. 5 includes/kaltura.notification.inc \kaltura_notification_handler()
  2. 6.2 includes/kaltura.notification.inc \kaltura_notification_handler()
  3. 6 includes/kaltura.notification.inc \kaltura_notification_handler()
  4. 7.2 includes/kaltura.notification.inc \kaltura_notification_handler()

This is the callback function for the kaltura/notification_handler URL.

This function uses the KalturaNotificationClient class to normalize the received notifications. The mentioned class also validates the notification signature, to prevent malicious data injection.

Each notification is save in the notifications table, so in case of duplicate notification only the first notification will be handled.

This function also invokes the hook_notification_handler so other modules that want to act upon notification is received will be able to do so.

1 string reference to 'kaltura_notification_handler'
kaltura_menu in ./kaltura.module
Implements hook_menu().

File

includes/kaltura.notification.inc, line 21
Contains functions for handling all notifications from kaltura.

Code

function kaltura_notification_handler() {
  $admin_secret = variable_get('kaltura_admin_secret');

  // @todo Validate each needed parameter from $_POST. This is security issue.
  $params = $_POST;
  watchdog('kaltura NH', print_r($params, TRUE));
  unset($params['q']);
  $noti = new KalturaNotificationClient($params, $admin_secret);
  if ($noti->valid_signature === NULL) {
    watchdog('kaltura', 'notification params empty');
    return FALSE;
  }
  elseif ($noti->valid_signature === FALSE) {
    watchdog('kaltura', 'notification signature not valid');
    return FALSE;
  }
  else {
    watchdog('kaltura', 'hooray!!! notification signature valid');
  }

  // TODO: do we really need this echo?
  echo 'OK';
  foreach ($noti->data as $notification_data) {
    $times = kaltura_notification_received($notification_data['notification_id']);
    if (empty($times) || $notification_data['notification_type'] == 'test') {
      kaltura_notification_save($notification_data['notification_id'], $notification_data);
      kaltura_forward_notification($notification_data);
      kaltura_invoke('notification_handler', $notification_data);
    }
    else {
      watchdog('notification', 'This notification (' . $notification_data['notification_id'] . ') was already received');
    }
  }
}