show push popup over ouya logo
[stouyapi.git] / www / api / v1 / queued_downloads_delete.php
1 <?php
2 /**
3  * Delete a game from the "push to my OUYA" list
4  *
5  * Pushes are stored in the sqlite3 database in push-to-my-ouya.php
6  *
7  * @author Christian Weiske <cweiske@cweiske.de>
8  */
9 $dbFile     = __DIR__ . '/../../../data/push-to-my-ouya.sqlite3';
10 $apiGameDir = __DIR__ . '/details-data/';
11
12 require_once __DIR__ . '/../../../src/push-to-my-ouya-helpers.php';
13
14 $ip = $_SERVER['REMOTE_ADDR'];
15 if ($ip == '' || strpos($ip, ':') !== false) {
16     //empty or IPv6
17     header('HTTP/1.0 204 No Content');
18     exit(1);
19 }
20 $ip = mapIp($ip);
21
22 $game = $_GET['game'];
23 $cleanGame = preg_replace('#[^a-zA-Z0-9.]#', '', $game);
24 if ($game != $cleanGame || $game == '') {
25     header('HTTP/1.0 400 Bad Request');
26     header('Content-type: text/plain');
27     echo 'Invalid game' . "\n";
28     exit(1);
29 }
30
31 try {
32     $db = new SQLite3($dbFile, SQLITE3_OPEN_READWRITE);
33 } catch (Exception $e) {
34     //db file not found
35     header('HTTP/1.0 204 No Content');
36     exit(1);
37 }
38
39 $rowId = $db->querySingle(
40     'SELECT id FROM pushes'
41     . ' WHERE ip = \'' . SQLite3::escapeString($ip) . '\''
42     . ' AND game =\'' . SQLite3::escapeString($game) . '\''
43 );
44 if ($rowId === null) {
45     header('HTTP/1.0 404 Not Found');
46     header('Content-type: text/plain');
47     echo 'Game not queued' . "\n";
48     exit(1);
49 }
50
51 $db->exec('DELETE FROM pushes WHERE id = ' . intval($rowId));
52 header('HTTP/1.0 204 No Content');
53 ?>