You are here

function _radioactivity_http_cb_process in Radioactivity 5

1 call to _radioactivity_http_cb_process()
radioactivity_http_cb in plugins/radioactivity_http.module

File

plugins/radioactivity_http.module, line 339

Code

function _radioactivity_http_cb_process($port) {
  $invocation = _radioactivity_http_cb_get_invocation($port);

  // check that the method is actually accessible
  if (!$invocation) {
    print 'Unknown method';
    return;
  }
  if (!$port['exposed_methods'][$invocation['method']]) {
    print 'Method not exposed';
    return;
  }

  // security check
  switch ($port['security_scheme']) {
    case 'none':

      // ok, no checks necessary
      break;
    case 'pkey-md5':

      // pkey + md5
      $expected_hash = _radioactivity_http_create_pkey_md5($invocation['method'], $invocation['params'], $port['private_key']);
      break;
    default:
      print 'Unknown security scheme';
  }
  if (isset($expected_hash)) {
    if ($expected_hash != $_GET['s']) {
      print 'Hash signature mismatch';
      return;
    }
  }

  // make the invocation
  $ret = call_user_func_array($invocation['method'], $invocation['params']);

  // return result
  switch ($port['return']) {
    case 'json':
      print json_encode($ret);
      break;
    case 'php-serialize':
      print serialize($ret);
      break;
    default:
      print 'Unknown return encoding: ' . $invocation['return'];
  }
}