Prevent E_NOTICE when game parameter is missing in queue cleanup
[stouyapi.git] / www / api / v1 / queued_downloads_delete.php
index 3861f93f060187d5bd563082aea65c64cabacd7c..a044053502ef49d6793275a273e1c231122d5f22 100644 (file)
@@ -12,15 +12,23 @@ $apiGameDir = __DIR__ . '/details-data/';
 require_once __DIR__ . '/../../../src/push-to-my-ouya-helpers.php';
 
 $ip = $_SERVER['REMOTE_ADDR'];
-if ($ip == '' || strpos($ip, ':') !== false) {
-    //empty or IPv6
+if ($ip == '') {
+    //empty ip
+    header('X-Fail-Reason: empty ip address');
     header('HTTP/1.0 204 No Content');
     exit(1);
 }
 $ip = mapIp($ip);
 
+if (!isset($_GET['game'])) {
+    header('HTTP/1.0 400 Bad Request');
+    header('Content-type: text/plain');
+    echo 'Game parameter missing' . "\n";
+    exit(1);
+}
+
 $game = $_GET['game'];
-$cleanGame = preg_replace('#[^a-zA-Z0-9.]#', '', $game);
+$cleanGame = preg_replace('#[^a-zA-Z0-9._]#', '', $game);
 if ($game != $cleanGame || $game == '') {
     header('HTTP/1.0 400 Bad Request');
     header('Content-type: text/plain');
@@ -32,6 +40,7 @@ try {
     $db = new SQLite3($dbFile, SQLITE3_OPEN_READWRITE);
 } catch (Exception $e) {
     //db file not found
+    header('X-Fail-Reason: database file not found');
     header('HTTP/1.0 204 No Content');
     exit(1);
 }