diff options
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs')
-rw-r--r-- | OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs | 233 |
1 files changed, 150 insertions, 83 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs index e8c0ee8..fa22481 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/Rest.cs | |||
@@ -23,7 +23,7 @@ | |||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
@@ -38,9 +38,11 @@ using Nini.Config; | |||
38 | 38 | ||
39 | namespace OpenSim.ApplicationPlugins.Rest.Inventory | 39 | namespace OpenSim.ApplicationPlugins.Rest.Inventory |
40 | { | 40 | { |
41 | |||
41 | public class Rest | 42 | public class Rest |
42 | { | 43 | { |
43 | internal static readonly log4net.ILog Log = | 44 | |
45 | internal static readonly log4net.ILog Log = | ||
44 | log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | 47 | ||
46 | internal static bool DEBUG = Log.IsDebugEnabled; | 48 | internal static bool DEBUG = Log.IsDebugEnabled; |
@@ -53,7 +55,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
53 | /// RestHandler class during start-up. | 55 | /// RestHandler class during start-up. |
54 | /// </summary> | 56 | /// </summary> |
55 | 57 | ||
56 | internal static RestHandler Plugin = null; | 58 | internal static IRestHandler Plugin = null; |
57 | internal static OpenSimBase main = null; | 59 | internal static OpenSimBase main = null; |
58 | internal static CommunicationsManager Comms = null; | 60 | internal static CommunicationsManager Comms = null; |
59 | internal static IInventoryServices InventoryServices = null; | 61 | internal static IInventoryServices InventoryServices = null; |
@@ -66,10 +68,47 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
66 | internal static bool Secure = true; | 68 | internal static bool Secure = true; |
67 | internal static bool ExtendedEscape = true; | 69 | internal static bool ExtendedEscape = true; |
68 | internal static bool DumpAsset = false; | 70 | internal static bool DumpAsset = false; |
71 | internal static bool Fill = true; | ||
72 | internal static bool FlushEnabled = true; | ||
69 | internal static string Realm = "REST"; | 73 | internal static string Realm = "REST"; |
70 | internal static int CreationDate = (int) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
71 | internal static int DumpLineSize = 32; // Should be a multiple of 16 or (possibly) 4 | 74 | internal static int DumpLineSize = 32; // Should be a multiple of 16 or (possibly) 4 |
72 | 75 | ||
76 | /// <summary> | ||
77 | /// HTTP requires that status information be generated for PUT | ||
78 | /// and POST opertaions. This is in support of that. The | ||
79 | /// operation verb gets substituted into the first string, | ||
80 | /// and the completion code is inserted into the tail. The | ||
81 | /// strings are put here to encourage consistency. | ||
82 | /// </summary> | ||
83 | |||
84 | internal static string statusHead = "<html><body><title>{0} status</title><break>"; | ||
85 | internal static string statusTail = "</body></html>"; | ||
86 | |||
87 | internal static Dictionary<int,string> HttpStatusDesc; | ||
88 | |||
89 | static Rest() | ||
90 | { | ||
91 | HttpStatusDesc = new Dictionary<int,string>(); | ||
92 | if (HttpStatusCodeArray.Length != HttpStatusDescArray.Length) | ||
93 | { | ||
94 | Log.ErrorFormat("{0} HTTP Status Code and Description arrays do not match"); | ||
95 | throw new Exception("HTTP Status array discrepancy"); | ||
96 | } | ||
97 | |||
98 | // Repackage the data into something more tractable. The sparse | ||
99 | // nature of HTTP return codes makes an array a bad choice. | ||
100 | |||
101 | for (int i=0; i<HttpStatusCodeArray.Length; i++) | ||
102 | { | ||
103 | HttpStatusDesc.Add(HttpStatusCodeArray[i], HttpStatusDescArray[i]); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | internal static int CreationDate | ||
108 | { | ||
109 | get { return (int) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; } | ||
110 | } | ||
111 | |||
73 | internal static string MsgId | 112 | internal static string MsgId |
74 | { | 113 | { |
75 | get { return Plugin.MsgId; } | 114 | get { return Plugin.MsgId; } |
@@ -104,7 +143,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
104 | /// supported by all servers. See Respond | 143 | /// supported by all servers. See Respond |
105 | /// to see how these are handled. | 144 | /// to see how these are handled. |
106 | /// </summary> | 145 | /// </summary> |
107 | 146 | ||
108 | // REST AGENT 1.0 interpretations | 147 | // REST AGENT 1.0 interpretations |
109 | public const string GET = "get"; // information retrieval - server state unchanged | 148 | public const string GET = "get"; // information retrieval - server state unchanged |
110 | public const string HEAD = "head"; // same as get except only the headers are returned. | 149 | public const string HEAD = "head"; // same as get except only the headers are returned. |
@@ -136,7 +175,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
136 | public static readonly char C_PERIOD = '.'; | 175 | public static readonly char C_PERIOD = '.'; |
137 | public static readonly char C_COMMA = ','; | 176 | public static readonly char C_COMMA = ','; |
138 | public static readonly char C_DQUOTE = '"'; | 177 | public static readonly char C_DQUOTE = '"'; |
139 | 178 | ||
140 | public static readonly string CS_SPACE = " "; | 179 | public static readonly string CS_SPACE = " "; |
141 | public static readonly string CS_SLASH = "/"; | 180 | public static readonly string CS_SLASH = "/"; |
142 | public static readonly string CS_PATHSEP = "/"; | 181 | public static readonly string CS_PATHSEP = "/"; |
@@ -145,7 +184,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
145 | public static readonly string CS_PERIOD = "."; | 184 | public static readonly string CS_PERIOD = "."; |
146 | public static readonly string CS_COMMA = ","; | 185 | public static readonly string CS_COMMA = ","; |
147 | public static readonly string CS_DQUOTE = "\""; | 186 | public static readonly string CS_DQUOTE = "\""; |
148 | 187 | ||
149 | public static readonly char[] CA_SPACE = { C_SPACE }; | 188 | public static readonly char[] CA_SPACE = { C_SPACE }; |
150 | public static readonly char[] CA_SLASH = { C_SLASH }; | 189 | public static readonly char[] CA_SLASH = { C_SLASH }; |
151 | public static readonly char[] CA_PATHSEP = { C_PATHSEP }; | 190 | public static readonly char[] CA_PATHSEP = { C_PATHSEP }; |
@@ -203,53 +242,97 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
203 | public const int HttpStatusCodeGatewayTimeout = 504; | 242 | public const int HttpStatusCodeGatewayTimeout = 504; |
204 | public const int HttpStatusCodeHttpVersionError = 505; | 243 | public const int HttpStatusCodeHttpVersionError = 505; |
205 | 244 | ||
206 | // HTTP Status Descriptions (in status code order) | 245 | public static readonly int[] HttpStatusCodeArray = { |
246 | HttpStatusCodeContinue, | ||
247 | HttpStatusCodeSwitchingProtocols, | ||
248 | HttpStatusCodeOK, | ||
249 | HttpStatusCodeCreated, | ||
250 | HttpStatusCodeAccepted, | ||
251 | HttpStatusCodeNonAuthoritative, | ||
252 | HttpStatusCodeNoContent, | ||
253 | HttpStatusCodeResetContent, | ||
254 | HttpStatusCodePartialContent, | ||
255 | HttpStatusCodeMultipleChoices, | ||
256 | HttpStatusCodePermanentRedirect, | ||
257 | HttpStatusCodeFound, | ||
258 | HttpStatusCodeSeeOther, | ||
259 | HttpStatusCodeNotModified, | ||
260 | HttpStatusCodeUseProxy, | ||
261 | HttpStatusCodeReserved306, | ||
262 | HttpStatusCodeTemporaryRedirect, | ||
263 | HttpStatusCodeBadRequest, | ||
264 | HttpStatusCodeNotAuthorized, | ||
265 | HttpStatusCodePaymentRequired, | ||
266 | HttpStatusCodeForbidden, | ||
267 | HttpStatusCodeNotFound, | ||
268 | HttpStatusCodeMethodNotAllowed, | ||
269 | HttpStatusCodeNotAcceptable, | ||
270 | HttpStatusCodeProxyAuthenticate, | ||
271 | HttpStatusCodeTimeOut, | ||
272 | HttpStatusCodeConflict, | ||
273 | HttpStatusCodeGone, | ||
274 | HttpStatusCodeLengthRequired, | ||
275 | HttpStatusCodePreconditionFailed, | ||
276 | HttpStatusCodeEntityTooLarge, | ||
277 | HttpStatusCodeUriTooLarge, | ||
278 | HttpStatusCodeUnsupportedMedia, | ||
279 | HttpStatusCodeRangeNotSatsified, | ||
280 | HttpStatusCodeExpectationFailed, | ||
281 | HttpStatusCodeServerError, | ||
282 | HttpStatusCodeNotImplemented, | ||
283 | HttpStatusCodeBadGateway, | ||
284 | HttpStatusCodeServiceUnavailable, | ||
285 | HttpStatusCodeGatewayTimeout, | ||
286 | HttpStatusCodeHttpVersionError | ||
287 | }; | ||
207 | 288 | ||
208 | public const string HttpStatusDescContinue = "Continue Request"; // 100 | 289 | // HTTP Status Descriptions (in status code order) |
209 | public const string HttpStatusDescSwitchingProtocols = "Switching Protocols"; // 101 | 290 | // This array must be kept strictly consistent with respect |
210 | 291 | // to the status code array above. | |
211 | public const string HttpStatusDescOK = "OK"; | 292 | |
212 | public const string HttpStatusDescCreated = "CREATED"; | 293 | public static readonly string[] HttpStatusDescArray = { |
213 | public const string HttpStatusDescAccepted = "ACCEPTED"; | 294 | "Continue Request", |
214 | public const string HttpStatusDescNonAuthoritative = "NON-AUTHORITATIVE INFORMATION"; | 295 | "Switching Protocols", |
215 | public const string HttpStatusDescNoContent = "NO CONTENT"; | 296 | "OK", |
216 | public const string HttpStatusDescResetContent = "RESET CONTENT"; | 297 | "CREATED", |
217 | public const string HttpStatusDescPartialContent = "PARTIAL CONTENT"; | 298 | "ACCEPTED", |
218 | 299 | "NON-AUTHORITATIVE INFORMATION", | |
219 | public const string HttpStatusDescMultipleChoices = "MULTIPLE CHOICES"; | 300 | "NO CONTENT", |
220 | public const string HttpStatusDescPermanentRedirect = "PERMANENT REDIRECT"; | 301 | "RESET CONTENT", |
221 | public const string HttpStatusDescFound = "FOUND"; | 302 | "PARTIAL CONTENT", |
222 | public const string HttpStatusDescSeeOther = "SEE OTHER"; | 303 | "MULTIPLE CHOICES", |
223 | public const string HttpStatusDescNotModified = "NOT MODIFIED"; | 304 | "PERMANENT REDIRECT", |
224 | public const string HttpStatusDescUseProxy = "USE PROXY"; | 305 | "FOUND", |
225 | public const string HttpStatusDescReserved306 = "RESERVED CODE 306"; | 306 | "SEE OTHER", |
226 | public const string HttpStatusDescTemporaryRedirect = "TEMPORARY REDIRECT"; | 307 | "NOT MODIFIED", |
227 | 308 | "USE PROXY", | |
228 | public const string HttpStatusDescBadRequest = "BAD REQUEST"; | 309 | "RESERVED CODE 306", |
229 | public const string HttpStatusDescNotAuthorized = "NOT AUTHORIZED"; | 310 | "TEMPORARY REDIRECT", |
230 | public const string HttpStatusDescPaymentRequired = "PAYMENT REQUIRED"; | 311 | "BAD REQUEST", |
231 | public const string HttpStatusDescForbidden = "FORBIDDEN"; | 312 | "NOT AUTHORIZED", |
232 | public const string HttpStatusDescNotFound = "NOT FOUND"; | 313 | "PAYMENT REQUIRED", |
233 | public const string HttpStatusDescMethodNotAllowed = "METHOD NOT ALLOWED"; | 314 | "FORBIDDEN", |
234 | public const string HttpStatusDescNotAcceptable = "NOT ACCEPTABLE"; | 315 | "NOT FOUND", |
235 | public const string HttpStatusDescProxyAuthenticate = "PROXY AUTHENTICATION REQUIRED"; | 316 | "METHOD NOT ALLOWED", |
236 | public const string HttpStatusDescTimeOut = "TIMEOUT"; | 317 | "NOT ACCEPTABLE", |
237 | public const string HttpStatusDescConflict = "CONFLICT"; | 318 | "PROXY AUTHENTICATION REQUIRED", |
238 | public const string HttpStatusDescGone = "GONE"; | 319 | "TIMEOUT", |
239 | public const string HttpStatusDescLengthRequired = "LENGTH REQUIRED"; | 320 | "CONFLICT", |
240 | public const string HttpStatusDescPreconditionFailed = "PRECONDITION FAILED"; | 321 | "GONE", |
241 | public const string HttpStatusDescEntityTooLarge = "ENTITY TOO LARGE"; | 322 | "LENGTH REQUIRED", |
242 | public const string HttpStatusDescUriTooLarge = "URI TOO LARGE"; | 323 | "PRECONDITION FAILED", |
243 | public const string HttpStatusDescUnsupportedMedia = "UNSUPPORTED MEDIA"; | 324 | "ENTITY TOO LARGE", |
244 | public const string HttpStatusDescRangeNotSatisfied = "RANGE NOT SATISFIED"; | 325 | "URI TOO LARGE", |
245 | public const string HttpStatusDescExpectationFailed = "EXPECTATION FAILED"; | 326 | "UNSUPPORTED MEDIA", |
246 | 327 | "RANGE NOT SATISFIED", | |
247 | public const string HttpStatusDescServerError = "SERVER ERROR"; | 328 | "EXPECTATION FAILED", |
248 | public const string HttpStatusDescNotImplemented = "NOT IMPLEMENTED"; | 329 | "SERVER ERROR", |
249 | public const string HttpStatusDescBadGateway = "BAD GATEWAY"; | 330 | "NOT IMPLEMENTED", |
250 | public const string HttpStatusDescServiceUnavailable = "SERVICE UNAVAILABLE"; | 331 | "BAD GATEWAY", |
251 | public const string HttpStatusDescGatewayTimeout = "GATEWAY TIMEOUT"; | 332 | "SERVICE UNAVAILABLE", |
252 | public const string HttpStatusDescHttpVersionError = "HTTP VERSION NOT SUPPORTED"; | 333 | "GATEWAY TIMEOUT", |
334 | "HTTP VERSION NOT SUPPORTED" | ||
335 | }; | ||
253 | 336 | ||
254 | // HTTP Headers | 337 | // HTTP Headers |
255 | 338 | ||
@@ -309,7 +392,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
309 | public const string AS_DIGEST = "Digest"; | 392 | public const string AS_DIGEST = "Digest"; |
310 | 393 | ||
311 | /// Supported Digest algorithms | 394 | /// Supported Digest algorithms |
312 | 395 | ||
313 | public const string Digest_MD5 = "MD5"; // assumedd efault if omitted | 396 | public const string Digest_MD5 = "MD5"; // assumedd efault if omitted |
314 | public const string Digest_MD5Sess = "MD5-sess"; | 397 | public const string Digest_MD5Sess = "MD5-sess"; |
315 | 398 | ||
@@ -357,7 +440,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
357 | int val = 0; | 440 | int val = 0; |
358 | int sum = 0; | 441 | int sum = 0; |
359 | string tmp = null; | 442 | string tmp = null; |
360 | 443 | ||
361 | if (hex != null) | 444 | if (hex != null) |
362 | { | 445 | { |
363 | tmp = hex.ToLower(); | 446 | tmp = hex.ToLower(); |
@@ -372,40 +455,21 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
372 | } | 455 | } |
373 | 456 | ||
374 | return sum; | 457 | return sum; |
375 | } | ||
376 | |||
377 | public static string Int2Hex8(int val) | ||
378 | { | ||
379 | string res = String.Empty; | ||
380 | for (int i = 0; i < 8; i++) | ||
381 | { | ||
382 | res = (val % 16) + res; | ||
383 | val = val / 16; | ||
384 | } | ||
385 | return res; | ||
386 | } | ||
387 | |||
388 | public static string ToHex32(int val) | ||
389 | { | ||
390 | return String.Empty; | ||
391 | } | ||
392 | 458 | ||
393 | public static string ToHex32(string val) | ||
394 | { | ||
395 | return String.Empty; | ||
396 | } | 459 | } |
397 | 460 | ||
398 | // Nonce management | 461 | // Nonce management |
399 | 462 | ||
400 | public static string NonceGenerator() | 463 | public static string NonceGenerator() |
401 | { | 464 | { |
402 | return StringToBase64(Guid.NewGuid().ToString()); | 465 | return StringToBase64(CreationDate + Guid.NewGuid().ToString()); |
403 | } | 466 | } |
404 | 467 | ||
405 | // Dump he specified data stream; | 468 | // Dump he specified data stream; |
406 | 469 | ||
407 | public static void Dump(byte[] data) | 470 | public static void Dump(byte[] data) |
408 | { | 471 | { |
472 | |||
409 | char[] buffer = new char[Rest.DumpLineSize]; | 473 | char[] buffer = new char[Rest.DumpLineSize]; |
410 | int cc = 0; | 474 | int cc = 0; |
411 | 475 | ||
@@ -415,7 +479,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
415 | if (i % Rest.DumpLineSize == 0) Console.Write("\n{0}: ",i.ToString("d8")); | 479 | if (i % Rest.DumpLineSize == 0) Console.Write("\n{0}: ",i.ToString("d8")); |
416 | 480 | ||
417 | if (i % 4 == 0) Console.Write(" "); | 481 | if (i % 4 == 0) Console.Write(" "); |
418 | // if (i%16 == 0) Console.Write(" "); | ||
419 | 482 | ||
420 | Console.Write("{0}",data[i].ToString("x2")); | 483 | Console.Write("{0}",data[i].ToString("x2")); |
421 | 484 | ||
@@ -431,6 +494,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
431 | Console.Write(" |"+(new String(buffer))+"|"); | 494 | Console.Write(" |"+(new String(buffer))+"|"); |
432 | cc = 0; | 495 | cc = 0; |
433 | } | 496 | } |
497 | |||
434 | } | 498 | } |
435 | 499 | ||
436 | // Finish off any incomplete line | 500 | // Finish off any incomplete line |
@@ -440,30 +504,33 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
440 | for (int i = cc ; i < Rest.DumpLineSize; i++) | 504 | for (int i = cc ; i < Rest.DumpLineSize; i++) |
441 | { | 505 | { |
442 | if (i % 4 == 0) Console.Write(" "); | 506 | if (i % 4 == 0) Console.Write(" "); |
443 | // if (i%16 == 0) Console.Write(" "); | 507 | Console.Write(" "); |
444 | Console.Write(" "); | ||
445 | buffer[i % Rest.DumpLineSize] = ' '; | 508 | buffer[i % Rest.DumpLineSize] = ' '; |
446 | } | 509 | } |
447 | Console.WriteLine(" |"+(new String(buffer))+"|"); | 510 | Console.WriteLine(" |"+(new String(buffer))+"|"); |
448 | } | 511 | } |
449 | else | 512 | else |
450 | { | 513 | { |
451 | Console.Write("\n"); | 514 | Console.Write("\n"); |
452 | } | 515 | } |
516 | |||
453 | } | 517 | } |
454 | } | ||
455 | 518 | ||
519 | } | ||
520 | |||
456 | // Local exception type | 521 | // Local exception type |
457 | 522 | ||
458 | public class RestException : Exception | 523 | public class RestException : Exception |
459 | { | 524 | { |
525 | |||
460 | internal int statusCode; | 526 | internal int statusCode; |
461 | internal string statusDesc; | 527 | internal string statusDesc; |
462 | internal string httpmethod; | 528 | internal string httpmethod; |
463 | internal string httppath; | 529 | internal string httppath; |
464 | 530 | ||
465 | public RestException(string msg) : base(msg) | 531 | public RestException(string msg) : base(msg) |
466 | { | 532 | { |
467 | } | 533 | } |
468 | } | 534 | } |
535 | |||
469 | } | 536 | } |