-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrest_assets_exist.php
More file actions
executable file
·139 lines (128 loc) · 2.47 KB
/
rest_assets_exist.php
File metadata and controls
executable file
·139 lines (128 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/******************************************************************************
* phpGridServer
*
* GNU LESSER GENERAL PUBLIC LICENSE
* Version 2.1, February 1999
*
*/
set_include_path(dirname($_SERVER["SCRIPT_FILENAME"]).PATH_SEPARATOR.get_include_path());
require_once("lib/services.php");
require_once("lib/xmltok.php");
if(function_exists("apache_request_headers"))
{
$headers = apache_request_headers();
if(isset($headers["X-SecondLife-Shard"]))
{
http_response_code("400");
exit;
}
}
function parseArrayOfString(&$input)
{
$assetids = array();
while($tok = xml_tokenize($input))
{
if($tok["type"]=="opening")
{
if($tok["name"]=="string")
{
$data = xml_parse_text($tok["name"], $input);
if(!$data)
{
throw new Exception();
}
$assetids[$data["text"]] = False;
}
else
{
throw new Exception();
}
}
else if($tok["type"]=="closing")
{
if($tok["name"]=="ArrayOfString")
{
return $assetids;
}
else
{
throw new Exception();
}
}
}
}
function parseAssetsExistRequest($input)
{
$encoding="utf-8";
while($tok = xml_tokenize($input))
{
if($tok["type"]=="processing")
{
if($tok["name"]=="xml")
{
if(isset($tok["attrs"]["encoding"]))
{
$encoding=$tok["attrs"]["encoding"];
}
}
}
else if($tok["type"]=="opening")
{
if($tok["name"] == "ArrayOfString")
{
return parseArrayOfString($input);
}
else
{
throw new Exception();
}
}
}
throw new Exception();
}
if(!isset($_SERVER["REQUEST_METHOD"]))
{
http_response_code("400");
}
else if($_SERVER["REQUEST_METHOD"]!="POST")
{
http_response_code("400");
}
else
{
$assetService = getService("RPC_Asset");
if(!$assetService)
{
http_response_code(500);
header("Content-Type: text/plain");
echo "Invalid asset service configuration";
trigger_error("Responded with 500: Invalid asset service configuration");
exit;
}
try
{
$assetidshash = parseAssetsExistRequest(file_get_contents("php://input"));
}
catch(Exception $e)
{
http_response_code("400");
exit;
}
$assetidshash = $assetService->existsMultiple($assetidshash);
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\"?>";
echo "<ArrayOfBoolean xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
foreach($assetidshash as $k => $v)
{
if($v)
{
echo "<boolean>true</boolean>";
}
else
{
echo "<boolean>false</boolean>";
}
}
echo "</ArrayOfBoolean>";
}