httpResponse($torrentLists->delete($params[1], $_GET["reason"])); break; case validateRoute('POST', 'torrent-lists/\\d+/votes'): $torrentLists = new TorrentLists($db, $user); $response = $torrentLists->vote($params[1]); httpResponse($response); break; case validateRoute('GET', 'torrent-list-bookmarks'): $bookmarks = new TorrentListBookmarks($db, $user); httpResponse($bookmarks->query(null)); break; case validateRoute('POST', 'torrent-list-bookmarks'): $bookmarks = new TorrentListBookmarks($db, $user); httpResponse($bookmarks->create($postdata)); break; case validateRoute('DELETE', 'torrent-list-bookmarks/\\d+'): $bookmarks = new TorrentListBookmarks($db, $user); httpResponse($bookmarks->delete((int) $params[1])); break; } httpResponseError(404, 'Resource not found'); } catch (Exception $e) { /* Don't expose SQL errors, log them. */ if ($e instanceof PDOException) { $errorString = $e->getMessage() . $e->getFile() . $e->getLine(); $sqlerrors = new SqlErrors($db, $user); $sqlerrors->create($errorString); httpResponseError(500, L::get("SERVER_ERROR")); } else { httpResponseError($e->getCode(), $e->getMessage()); }
$reseed = new ReseedRequests($db, $user, $torrent, $mailbox, $logs); $reseed->create($postdata); httpResponse(); break; case validateRoute('GET', 'nonscene'): $adminlogs = new AdminLogs($db, $user); $nonscene = new Nonscene($db, $user, $adminlogs); httpResponse($nonscene->query()); break; case validateRoute('POST', 'nonscene'): $adminlogs = new AdminLogs($db, $user); $nonscene = new Nonscene($db, $user, $adminlogs); $nonscene->create($postdata); httpResponse(); break; case validateRoute('DELETE', 'nonscene/\\d+'): $adminlogs = new AdminLogs($db, $user); $nonscene = new Nonscene($db, $user, $adminlogs); $nonscene->delete($params[1]); httpResponse(); break; } httpResponseError(404, 'Resource not found'); } catch (Exception $e) { /* Don't expose SQL errors, log them. */ if ($e instanceof PDOException) { $errorString = $e->getMessage() . $e->getFile() . $e->getLine(); $sqlerrors = new SqlErrors($db, $user); $sqlerrors->create($errorString); httpResponseError(500, "Ett serverfel har inträffat. Händelsen har loggats."); } else {
function loadMethodsFromXML($xmlParser) { $methods = array(); $xmlMethods = XmlParserUtils::getChildren($xmlParser->document, XML_METHOD); foreach ($xmlMethods as $xmlMethod) { $name = XmlParserUtils::existAttribute($xmlMethod, XML_METHOD_NAME) ? $xmlMethod->tagAttrs[XML_METHOD_NAME] : null; if (empty($name)) { throw new MashapeException(EXCEPTION_METHOD_EMPTY_NAME, EXCEPTION_XML_CODE); } else { if (existMethod($methods, $name)) { throw new MashapeException(sprintf(EXCEPTION_METHOD_DUPLICATE_NAME, $name), EXCEPTION_XML_CODE); } } $http = XmlParserUtils::existAttribute($xmlMethod, XML_METHOD_HTTP) ? $xmlMethod->tagAttrs[XML_METHOD_HTTP] : null; if (empty($http)) { throw new MashapeException(EXCEPTION_METHOD_EMPTY_HTTP, EXCEPTION_XML_CODE); } else { $http = strtolower($http); if ($http != "get" && $http != "post" && $http != "put" && $http != "delete") { throw new MashapeException(sprintf(EXCEPTION_METHOD_INVALID_HTTP, $http), EXCEPTION_XML_CODE); } } $route = XmlParserUtils::existAttribute($xmlMethod, XML_METHOD_ROUTE) ? $xmlMethod->tagAttrs[XML_METHOD_ROUTE] : null; if (!empty($route)) { if (!validateRoute($route)) { throw new MashapeException(sprintf(EXCEPTION_METHOD_INVALID_ROUTE, $route), EXCEPTION_XML_CODE); } else { if (existRoute($methods, $route, $http)) { throw new MashapeException(sprintf(EXCEPTION_METHOD_DUPLICATE_ROUTE, $route), EXCEPTION_XML_CODE); } } } // Get the result $resultsNode = XmlParserUtils::getChildren($xmlMethod, "result"); //$xmlMethod->result; $resultNode = null; if (count($resultsNode) > 1) { throw new MashapeException(sprintf(EXCEPTION_RESULT_MULTIPLE, $name), EXCEPTION_XML_CODE); } elseif (count($resultsNode) == 1) { $resultNode = $resultsNode[0]; } // else { // throw new MashapeException(sprintf(EXCEPTION_RESULT_MISSING, $name), EXCEPTION_XML_CODE); // } $object = null; $array = null; $resultName = null; if ($resultNode != null) { $array = XmlParserUtils::existAttribute($resultNode, XML_RESULT_ARRAY) ? $resultNode->tagAttrs[XML_RESULT_ARRAY] : null; if ($array != null && strtolower($array) == "true") { $array = true; } else { $array = false; } $type = XmlParserUtils::existAttribute($resultNode, XML_RESULT_TYPE) ? $resultNode->tagAttrs[XML_RESULT_TYPE] : null; if (strtolower($type == "simple")) { $resultName = XmlParserUtils::existAttribute($resultNode, XML_RESULT_NAME) ? $resultNode->tagAttrs[XML_RESULT_NAME] : null; if (empty($resultName)) { throw new MashapeException(sprintf(EXCEPTION_RESULT_EMPTY_NAME_SIMPLE, $name), EXCEPTION_XML_CODE); } } else { if (strtolower($type == "complex")) { $object = XmlParserUtils::existAttribute($resultNode, XML_RESULT_NAME) ? $resultNode->tagAttrs[XML_RESULT_NAME] : null; if (empty($object)) { throw new MashapeException(sprintf(EXCEPTION_RESULT_EMPTY_NAME_OBJECT, $name), EXCEPTION_XML_CODE); } } else { if (empty($type)) { throw new MashapeException(sprintf(EXCEPTION_RESULT_EMPTY_TYPE, $name), EXCEPTION_XML_CODE); } else { throw new MashapeException(sprintf(EXCEPTION_RESULT_INVALID_TYPE, $type, $name), EXCEPTION_XML_CODE); } } } } $method = new RESTMethod(); $method->setName($name); $method->setObject($object); $method->setResult($resultName); $method->setArray($array); $method->setHttp($http); $method->setRoute($route); //Save method array_push($methods, $method); } return $methods; }