public function exec() { if (function_exists('getallheaders')) { $headers = getallheaders(); } else { if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); } else { if (function_exists('nsapi_request_headers')) { $headers = nsapi_request_headers(); } } } if (isset($headers)) { // Gather available session information from the header $lsid = isset($headers['lsid']) ? $headers['lsid'] : FALSE; $sessionType = isset($headers['sessionType']) ? $headers['sessionType'] : FALSE; // Parse all the input $input = $this->input->post('s'); $statements = array(); $start = 0; while ($start < strlen($input)) { if ($start != 0) { $input = substr($input, $start); } $end = strpos($input, ';'); $level = hexdec(substr($input, 0, $end)); $input = substr($input, $end + 1); $end = strpos($input, ';'); $no = hexdec(substr($input, 0, $end)); $input = substr($input, $end + 1); $end = strpos($input, ';'); $nameLen = hexdec(substr($input, 0, $end)); $input = substr($input, $end + 1); $name = substr($input, 0, $nameLen); $input = substr($input, $nameLen + 1); $end = strpos($input, ';'); $personLen = hexdec(substr($input, 0, $end)); $input = substr($input, $end + 1); $person = substr($input, 0, $personLen); $input = substr($input, $personLen + 1); $end = strpos($input, ';'); $messageLen = hexdec(substr($input, 0, $end)); $input = substr($input, $end + 1); $message = substr($input, 0, $messageLen); $input = substr($input, $messageLen + 1); $end = strpos($input, ';'); $timeStamp = hexdec(substr($input, 0, $end)); $input = substr($input, $end + 1); $end = strpos($input, ';'); $parameterLen = hexdec(substr($input, 0, $end)); if ($parameterLen > 0) { $input = substr($input, $end + 1); $parameter = substr($input, 0, $parameterLen); $start = $parameterLen + 1; } else { $start = $end + 2; $parameter = ''; } // Put the statement in a acceptable array $statement = array('no' => $no, 'name' => $name, 'time_stamp' => $timeStamp, 'person' => $person, 'level' => $level, 'message' => $message, 'parameters' => $parameter); $statements[] = $statement; } // Store the statements $lsid = $this->log_model->store($lsid, $sessionType, $statements); // Return the used lsid so the next request can use it again (may start with error) if (substr($lsid, 0, 5) == 'ERROR') { show_error($lsid); } else { // Return the session id so the client can refer future statements to a session! exit($lsid); } } else { show_error('Server does not support headers, this feature is required for SL.'); } }
/** * Create a request object using the given configuration options. * * The configuration options array can contain the following: * * <dl> * <dt>uri</dt> <dd>The URI of the request</dd> * <dt>method</dt> <dd>The HTTP method of the request</dd> * <dt>data</dt> <dd>The body data of the request</dd> * <dt>accept</dt> <dd>An accept header</dd> * <dt>acceptLang</dt> <dd>An accept-language header</dd> * <dt>acceptEncoding</dt> <dd>An accept-encoding header</dd> * <dt>ifMatch</dt> <dd>An if-match header</dd> * <dt>ifNoneMatch</dt> <dd>An if-none-match header</dd> * <dt>mimetypes</dt> <dd>A map of file/URI extenstions to mimetypes, these * will be added to the default map of mimetypes</dd> * <dt>baseUri</dt> <dd>The base relative URI to use when dispatcher isn't * at the root of the domain. Do not put a trailing slash</dd> * <dt>404</dt> <dd>Class name to use when no resource is found</dd> * <dt>mounts</dt> <dd>an array of namespace to baseUri prefix mappings</dd> * </dl> * * @param mixed[] config Configuration options */ function __construct($config = array()) { // set defaults $config['uri'] = $this->getConfig($config, 'uri', 'REDIRECT_URL'); $config['baseUri'] = $this->getConfig($config, 'baseUri', ''); $config['accept'] = $this->getConfig($config, 'accept', 'HTTP_ACCEPT'); $config['acceptLang'] = $this->getConfig($config, 'acceptLang', 'HTTP_ACCEPT_LANGUAGE'); $config['acceptEncoding'] = $this->getConfig($config, 'acceptEncoding', 'HTTP_ACCEPT_ENCODING'); $config['ifMatch'] = $this->getConfig($config, 'ifMatch', 'HTTP_IF_MATCH'); $config['ifNoneMatch'] = $this->getConfig($config, 'ifNoneMatch', 'HTTP_IF_NONE_MATCH'); if (isset($config['mimetypes']) && is_array($config['mimetypes'])) { foreach ($config['mimetypes'] as $mimetype => $ext) { $this->mimetypes[$mimetype] = $ext; } } // set baseUri $this->baseUri = $config['baseUri']; // get request URI $parts = explode('/', $config['uri']); $lastPart = array_pop($parts); $this->uri = join('/', $parts); $parts = explode('.', $lastPart); $this->uri .= '/' . $parts[0]; if (substr($this->uri, -1, 1) == '/') { // remove trailing slash problem $this->uri = substr($this->uri, 0, -1); } array_shift($parts); foreach ($parts as $part) { if (array_search($part, $this->mimetypes)) { $this->accept[10][] = $part; $this->acceptLang[10][] = $part; } else { $this->uri .= "." . $part; } } // sort accept headers $accept = explode(',', strtolower($config['accept'])); foreach ($accept as $mimetype) { $parts = explode(';q=', $mimetype); if (isset($parts) && isset($parts[1]) && $parts[1]) { $num = $parts[1] * 10; } else { $num = 10; } if (array_key_exists($parts[0], $this->mimetypes)) { $this->accept[$num][] = $this->mimetypes[$parts[0]]; } } krsort($this->accept); // sort lang accept headers $accept = explode(',', strtolower($config['acceptLang'])); foreach ($accept as $mimetype) { $parts = explode(';q=', $mimetype); if (isset($parts) && isset($parts[1]) && $parts[1]) { $num = $parts[1] * 10; } else { $num = 10; } $this->acceptLang[$num][] = $parts[0]; } krsort($this->acceptLang); // get encoding accept headers if ($config['acceptEncoding']) { foreach (explode(',', $config['acceptEncoding']) as $key => $accept) { $this->acceptEncoding[$key] = trim($accept); } } // create negotiated URI lists from accept headers and request URI foreach ($this->accept as $typeOrder) { foreach ($typeOrder as $type) { if ($type) { foreach ($this->acceptLang as $langOrder) { foreach ($langOrder as $lang) { if ($lang && $lang != $type) { $this->negotiatedUris[] = $this->uri . '.' . $type . '.' . $lang; } } } $this->negotiatedUris[] = $this->uri . '.' . $type; $this->formatNegotiatedUris[] = $this->uri . '.' . $type; } } } foreach ($this->acceptLang as $langOrder) { foreach ($langOrder as $lang) { if ($lang) { $this->negotiatedUris[] = $this->uri . '.' . $lang; $this->languageNegotiatedUris[] = $this->uri . '.' . $lang; } } } $this->negotiatedUris[] = $this->uri; $this->formatNegotiatedUris[] = $this->uri; $this->languageNegotiatedUris[] = $this->uri; $this->negotiatedUris = array_values(array_unique($this->negotiatedUris)); $this->formatNegotiatedUris = array_values(array_unique($this->formatNegotiatedUris)); $this->languageNegotiatedUris = array_values(array_unique($this->languageNegotiatedUris)); // get HTTP method $this->method = strtoupper($this->getConfig($config, 'method', 'REQUEST_METHOD', $this->method)); // get HTTP request data $this->data = $this->getConfig($config, 'data', NULL, file_get_contents("php://input")); // get HTTP request type $raw_headers = array(); if (function_exists("apache_request_headers")) { $raw_headers = apache_request_headers(); } else { if (function_exists("nsapi_request_headers")) { $raw_headers = nsapi_request_headers(); } } foreach ($raw_headers as $k => $h) { switch (strtolower($k)) { case "content-type": $this->requestType = $h; break; case "x-authentication-token": $this->requestToken = $h; break; } } // get HTTP query string $this->queryString = $this->getConfig($config, NULL, 'QUERY_STRING'); // conditional requests if ($config['ifMatch']) { $ifMatch = explode(',', $config['ifMatch']); foreach ($ifMatch as $etag) { $this->ifMatch[] = trim($etag, '" '); } } if ($config['ifNoneMatch']) { $ifNoneMatch = explode(',', $config['ifNoneMatch']); foreach ($ifNoneMatch as $etag) { $this->ifNoneMatch[] = trim($etag, '" '); } } // 404 resource if (isset($config['404'])) { $this->noResource = $config['404']; } // mounts if (isset($config['mount']) && is_array($config['mount'])) { $this->mounts = $config['mount']; } // prime named resources for autoloading if (isset($config['autoload']) && is_array($config['autoload'])) { foreach ($config['autoload'] as $uri => $filename) { $parts = preg_split('|[/\\\\]|', $filename); $filename = join(DIRECTORY_SEPARATOR, $parts); $parts = explode('.', array_pop($parts)); $className = $parts[0]; if (file_exists($filename)) { $this->resources[$uri] = array('class' => $className, 'filename' => $filename, 'loaded' => FALSE); } } } // load definitions of already loaded resource classes foreach (get_declared_classes() as $className) { if (is_subclass_of($className, 'Resource')) { $resourceDetails = $this->getResourceClassDetails($className); preg_match_all('/@uri\\s+([^\\s]+)(?:\\s([0-9]+))?/', $resourceDetails['comment'], $annotations); if (isset($annotations[1])) { $uris = $annotations[1]; } else { $uris = array('/'); } foreach ($uris as $index => $uri) { if (substr($uri, -1, 1) == '/') { // remove trailing slash problem $uri = substr($uri, 0, -1); } $this->resources[$resourceDetails['mountPoint'] . $uri] = array('namespace' => $resourceDetails['namespaceName'], 'class' => $resourceDetails['className'], 'filename' => $resourceDetails['filename'], 'line' => $resourceDetails['line'], 'priority' => isset($annotations[2][$index]) && is_numeric($annotations[2][$index]) ? intval($annotations[2][$index]) : 0, 'loaded' => TRUE); } } } }
<?php $headers = nsapi_request_headers(); ini_set('nsapi.read_timeout');