aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs59
1 files changed, 4 insertions, 55 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs
index 6fc3ea3..d08f830 100644
--- a/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs
@@ -40,7 +40,6 @@ using System.Xml;
40 40
41namespace OpenSim.ApplicationPlugins.Rest.Inventory 41namespace OpenSim.ApplicationPlugins.Rest.Inventory
42{ 42{
43
44 /// <summary> 43 /// <summary>
45 /// This class represents the current REST request. It 44 /// This class represents the current REST request. It
46 /// encapsulates the request/response state and takes care 45 /// encapsulates the request/response state and takes care
@@ -66,7 +65,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
66 65
67 internal class RequestData 66 internal class RequestData
68 { 67 {
69
70 // HTTP Server interface data 68 // HTTP Server interface data
71 69
72 internal OSHttpRequest request = null; 70 internal OSHttpRequest request = null;
@@ -170,7 +168,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
170 168
171 internal RequestData(OSHttpRequest p_request, OSHttpResponse p_response, string p_qprefix) 169 internal RequestData(OSHttpRequest p_request, OSHttpResponse p_response, string p_qprefix)
172 { 170 {
173
174 request = p_request; 171 request = p_request;
175 response = p_response; 172 response = p_response;
176 qprefix = p_qprefix; 173 qprefix = p_qprefix;
@@ -187,7 +184,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
187 initUrl(); 184 initUrl();
188 185
189 initParameters(p_qprefix.Length); 186 initParameters(p_qprefix.Length);
190
191 } 187 }
192 188
193 // Just for convenience... 189 // Just for convenience...
@@ -212,7 +208,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
212 208
213 return authenticated; 209 return authenticated;
214 } 210 }
215 else return true; 211 else
212 return true;
216 } 213 }
217 } 214 }
218 215
@@ -229,7 +226,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
229 226
230 private void authenticate() 227 private void authenticate()
231 { 228 {
232
233 string authdata = request.Headers.Get("Authorization"); 229 string authdata = request.Headers.Get("Authorization");
234 string reqscheme = String.Empty; 230 string reqscheme = String.Empty;
235 231
@@ -291,7 +287,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
291 Rest.Log.DebugFormat("{0} Challenge reason: Authentication failed", MsgId); 287 Rest.Log.DebugFormat("{0} Challenge reason: Authentication failed", MsgId);
292 DoChallenge(); 288 DoChallenge();
293 } 289 }
294
295 } 290 }
296 291
297 /// <summary> 292 /// <summary>
@@ -315,7 +310,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
315 310
316 private void DoBasic(string authdata) 311 private void DoBasic(string authdata)
317 { 312 {
318
319 string response = null; 313 string response = null;
320 314
321 MatchCollection matches = basicParms.Matches(authdata); 315 MatchCollection matches = basicParms.Matches(authdata);
@@ -346,7 +340,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
346 // Validate against user database 340 // Validate against user database
347 authenticated = Validate(userName,userPass); 341 authenticated = Validate(userName,userPass);
348 } 342 }
349
350 } 343 }
351 344
352 /// <summary> 345 /// <summary>
@@ -357,7 +350,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
357 350
358 private void DoDigest(string authdata) 351 private void DoDigest(string authdata)
359 { 352 {
360
361 string response = null; 353 string response = null;
362 354
363 MatchCollection matches = digestParm1.Matches(authdata); 355 MatchCollection matches = digestParm1.Matches(authdata);
@@ -390,12 +382,10 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
390 382
391 if (authparms.TryGetValue("response", out response)) 383 if (authparms.TryGetValue("response", out response))
392 { 384 {
393
394 string temp = null; 385 string temp = null;
395 386
396 do 387 do
397 { 388 {
398
399 string nck = null; 389 string nck = null;
400 string ncl = null; 390 string ncl = null;
401 391
@@ -448,7 +438,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
448 438
449 if (authparms.TryGetValue("qop", out temp)) 439 if (authparms.TryGetValue("qop", out temp))
450 { 440 {
451
452 qop = temp.ToLower(); // replace with actual value used 441 qop = temp.ToLower(); // replace with actual value used
453 442
454 // if QOP was specified then 443 // if QOP was specified then
@@ -485,11 +474,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
485 { 474 {
486 lock (cntable) cntable.Add(nonce, nck); 475 lock (cntable) cntable.Add(nonce, nck);
487 } 476 }
488
489 } 477 }
490 else 478 else
491 { 479 {
492
493 qop = String.Empty; 480 qop = String.Empty;
494 481
495 // if QOP was not specified then 482 // if QOP was not specified then
@@ -509,12 +496,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
509 // Validate the supplied userid/password info 496 // Validate the supplied userid/password info
510 497
511 authenticated = ValidateDigest(userName, nonce, cnonce, nck, authPrefix, response); 498 authenticated = ValidateDigest(userName, nonce, cnonce, nck, authPrefix, response);
512
513 } 499 }
514 while (false); 500 while (false);
515
516 } 501 }
517
518 } 502 }
519 503
520 // Indicate that authentication is required 504 // Indicate that authentication is required
@@ -523,7 +507,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
523 string opaque, string stale, string alg, 507 string opaque, string stale, string alg,
524 string qop, string auth) 508 string qop, string auth)
525 { 509 {
526
527 sbuilder.Length = 0; 510 sbuilder.Length = 0;
528 511
529 if (scheme == null || scheme == Rest.AS_BASIC) 512 if (scheme == null || scheme == Rest.AS_BASIC)
@@ -544,7 +527,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
544 527
545 if (scheme == null || scheme == Rest.AS_DIGEST) 528 if (scheme == null || scheme == Rest.AS_DIGEST)
546 { 529 {
547
548 sbuilder.Append(Rest.AS_DIGEST); 530 sbuilder.Append(Rest.AS_DIGEST);
549 sbuilder.Append(" "); 531 sbuilder.Append(" ");
550 532
@@ -617,9 +599,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
617 sbuilder.Append(Rest.CS_DQUOTE); 599 sbuilder.Append(Rest.CS_DQUOTE);
618 600
619 AddHeader(Rest.HttpHeaderWWWAuthenticate,sbuilder.ToString()); 601 AddHeader(Rest.HttpHeaderWWWAuthenticate,sbuilder.ToString());
620
621 } 602 }
622
623 } 603 }
624 604
625 /// <summary> 605 /// <summary>
@@ -631,7 +611,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
631 611
632 private bool Validate(string user, string pass) 612 private bool Validate(string user, string pass)
633 { 613 {
634
635 Rest.Log.DebugFormat("{0} Simple User Validation", MsgId); 614 Rest.Log.DebugFormat("{0} Simple User Validation", MsgId);
636 615
637 // Both values are required 616 // Both values are required
@@ -643,7 +622,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
643 user = user.Trim(); 622 user = user.Trim();
644 623
645 return vetPassword(user, pass); 624 return vetPassword(user, pass);
646
647 } 625 }
648 626
649 /// <summary> 627 /// <summary>
@@ -658,7 +636,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
658 636
659 private string getPassword(string user) 637 private string getPassword(string user)
660 { 638 {
661
662 int x; 639 int x;
663 string first; 640 string first;
664 string last; 641 string last;
@@ -690,7 +667,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
690 Rest.Log.DebugFormat("{0} Normal User {1}", MsgId, user); 667 Rest.Log.DebugFormat("{0} Normal User {1}", MsgId, user);
691 return udata.PasswordHash; 668 return udata.PasswordHash;
692 } 669 }
693
694 } 670 }
695 671
696 /// <summary> 672 /// <summary>
@@ -704,7 +680,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
704 680
705 private bool vetPassword(string user, string pass) 681 private bool vetPassword(string user, string pass)
706 { 682 {
707
708 int x; 683 int x;
709 string HA1; 684 string HA1;
710 string first; 685 string first;
@@ -734,13 +709,11 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
734 HA1 = HashToString(String.Format("{0}:{1}",HA1,udata.PasswordSalt)); 709 HA1 = HashToString(String.Format("{0}:{1}",HA1,udata.PasswordSalt));
735 710
736 return (0 == sc.Compare(HA1, udata.PasswordHash)); 711 return (0 == sc.Compare(HA1, udata.PasswordHash));
737
738 } 712 }
739 713
740 // Validate the request-digest 714 // Validate the request-digest
741 private bool ValidateDigest(string user, string nonce, string cnonce, string nck, string uri, string response) 715 private bool ValidateDigest(string user, string nonce, string cnonce, string nck, string uri, string response)
742 { 716 {
743
744 string patt = null; 717 string patt = null;
745 string payl = String.Empty; 718 string payl = String.Empty;
746 string KDS = null; 719 string KDS = null;
@@ -798,12 +771,10 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
798 // Compare the generated sequence with the original 771 // Compare the generated sequence with the original
799 772
800 return (0 == sc.Compare(KDS, response)); 773 return (0 == sc.Compare(KDS, response));
801
802 } 774 }
803 775
804 private string HashToString(string pattern) 776 private string HashToString(string pattern)
805 { 777 {
806
807 Rest.Log.DebugFormat("{0} Generate <{1}>", MsgId, pattern); 778 Rest.Log.DebugFormat("{0} Generate <{1}>", MsgId, pattern);
808 779
809 byte[] hash = md5hash.ComputeHash(encoding.GetBytes(pattern)); 780 byte[] hash = md5hash.ComputeHash(encoding.GetBytes(pattern));
@@ -818,7 +789,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
818 Rest.Log.DebugFormat("{0} Hash = <{1}>", MsgId, sbuilder.ToString()); 789 Rest.Log.DebugFormat("{0} Hash = <{1}>", MsgId, sbuilder.ToString());
819 790
820 return sbuilder.ToString(); 791 return sbuilder.ToString();
821
822 } 792 }
823 793
824 internal void Complete() 794 internal void Complete()
@@ -829,7 +799,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
829 799
830 internal void Redirect(string Url, bool temp) 800 internal void Redirect(string Url, bool temp)
831 { 801 {
832
833 redirectLocation = Url; 802 redirectLocation = Url;
834 803
835 if (temp) 804 if (temp)
@@ -844,7 +813,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
844 } 813 }
845 814
846 Fail(statusCode, statusDescription, true); 815 Fail(statusCode, statusDescription, true);
847
848 } 816 }
849 817
850 // Fail for an arbitrary reason. Just a failure with 818 // Fail for an arbitrary reason. Just a failure with
@@ -867,7 +835,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
867 835
868 internal void Fail(int code, string message, bool reset) 836 internal void Fail(int code, string message, bool reset)
869 { 837 {
870
871 statusCode = code; 838 statusCode = code;
872 statusDescription = message; 839 statusDescription = message;
873 840
@@ -907,7 +874,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
907 re.httppath = path; 874 re.httppath = path;
908 875
909 throw re; 876 throw re;
910
911 } 877 }
912 878
913 // Reject this request 879 // Reject this request
@@ -924,19 +890,16 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
924 890
925 internal virtual bool Respond(string reason) 891 internal virtual bool Respond(string reason)
926 { 892 {
927
928 Rest.Log.DebugFormat("{0} Respond ENTRY, handled = {1}, reason = {2}", MsgId, handled, reason); 893 Rest.Log.DebugFormat("{0} Respond ENTRY, handled = {1}, reason = {2}", MsgId, handled, reason);
929 894
930 if (!handled) 895 if (!handled)
931 { 896 {
932
933 Rest.Log.DebugFormat("{0} Generating Response", MsgId); 897 Rest.Log.DebugFormat("{0} Generating Response", MsgId);
934 Rest.Log.DebugFormat("{0} Method is {1}", MsgId, method); 898 Rest.Log.DebugFormat("{0} Method is {1}", MsgId, method);
935 899
936 // A Head request can NOT have a body! 900 // A Head request can NOT have a body!
937 if (method != Rest.HEAD) 901 if (method != Rest.HEAD)
938 { 902 {
939
940 Rest.Log.DebugFormat("{0} Response is not abbreviated", MsgId); 903 Rest.Log.DebugFormat("{0} Response is not abbreviated", MsgId);
941 904
942 // If the writer is non-null then we know that an XML 905 // If the writer is non-null then we know that an XML
@@ -993,7 +956,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
993 956
994 response.SendChunked = chunked; 957 response.SendChunked = chunked;
995 response.KeepAlive = keepAlive; 958 response.KeepAlive = keepAlive;
996
997 } 959 }
998 960
999 // Set the status code & description. If nothing has been stored, 961 // Set the status code & description. If nothing has been stored,
@@ -1054,13 +1016,11 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1054 1016
1055 Rest.Log.DebugFormat("{0} Closing output stream", MsgId); 1017 Rest.Log.DebugFormat("{0} Closing output stream", MsgId);
1056 response.OutputStream.Close(); 1018 response.OutputStream.Close();
1057
1058 } 1019 }
1059 1020
1060 Rest.Log.DebugFormat("{0} Respond EXIT, handled = {1}, reason = {2}", MsgId, handled, reason); 1021 Rest.Log.DebugFormat("{0} Respond EXIT, handled = {1}, reason = {2}", MsgId, handled, reason);
1061 1022
1062 return handled; 1023 return handled;
1063
1064 } 1024 }
1065 1025
1066 // Add a header to the table. We need to allow 1026 // Add a header to the table. We need to allow
@@ -1122,7 +1082,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1122 1082
1123 private void initUrl() 1083 private void initUrl()
1124 { 1084 {
1125
1126 uri = request.Url; 1085 uri = request.Url;
1127 1086
1128 if (query == null) 1087 if (query == null)
@@ -1137,7 +1096,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1137 { 1096 {
1138 path = uri.AbsolutePath; 1097 path = uri.AbsolutePath;
1139 if (path.EndsWith(Rest.UrlPathSeparator)) 1098 if (path.EndsWith(Rest.UrlPathSeparator))
1140 path = path.Substring(0,path.Length-1); 1099 path = path.Substring(0, path.Length-1);
1141 } 1100 }
1142 1101
1143 // If we succeeded in getting a path, perform any 1102 // If we succeeded in getting a path, perform any
@@ -1149,7 +1108,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1149 { 1108 {
1150 // Handle "+". Not a standard substitution, but 1109 // Handle "+". Not a standard substitution, but
1151 // common enough... 1110 // common enough...
1152 path = path.Replace(Rest.C_PLUS,Rest.C_SPACE); 1111 path = path.Replace(Rest.C_PLUS, Rest.C_SPACE);
1153 } 1112 }
1154 pathNodes = path.Split(Rest.CA_PATHSEP); 1113 pathNodes = path.Split(Rest.CA_PATHSEP);
1155 } 1114 }
@@ -1167,12 +1126,10 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1167 1126
1168 hostname = uri.Host; 1127 hostname = uri.Host;
1169 port = uri.Port; 1128 port = uri.Port;
1170
1171 } 1129 }
1172 1130
1173 internal int initParameters(int prfxlen) 1131 internal int initParameters(int prfxlen)
1174 { 1132 {
1175
1176 if (prfxlen < path.Length-1) 1133 if (prfxlen < path.Length-1)
1177 { 1134 {
1178 parameters = path.Substring(prfxlen+1).Split(Rest.CA_PATHSEP); 1135 parameters = path.Substring(prfxlen+1).Split(Rest.CA_PATHSEP);
@@ -1194,7 +1151,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1194 } 1151 }
1195 1152
1196 return parameters.Length; 1153 return parameters.Length;
1197
1198 } 1154 }
1199 1155
1200 internal string[] PathNodes 1156 internal string[] PathNodes
@@ -1211,7 +1167,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1211 1167
1212 internal string BuildUrl(int first, int last) 1168 internal string BuildUrl(int first, int last)
1213 { 1169 {
1214
1215 if (pathNodes == null) 1170 if (pathNodes == null)
1216 { 1171 {
1217 initUrl(); 1172 initUrl();
@@ -1252,7 +1207,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1252 } 1207 }
1253 1208
1254 return sbuilder.ToString(); 1209 return sbuilder.ToString();
1255
1256 } 1210 }
1257 1211
1258 // Setup the XML writer for output 1212 // Setup the XML writer for output
@@ -1272,7 +1226,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1272 1226
1273 internal void initXmlReader() 1227 internal void initXmlReader()
1274 { 1228 {
1275
1276 XmlReaderSettings settings = new XmlReaderSettings(); 1229 XmlReaderSettings settings = new XmlReaderSettings();
1277 1230
1278 settings.ConformanceLevel = ConformanceLevel.Fragment; 1231 settings.ConformanceLevel = ConformanceLevel.Fragment;
@@ -1282,14 +1235,12 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1282 settings.ValidationType = ValidationType.None; 1235 settings.ValidationType = ValidationType.None;
1283 1236
1284 reader = XmlReader.Create(request.InputStream,settings); 1237 reader = XmlReader.Create(request.InputStream,settings);
1285
1286 } 1238 }
1287 1239
1288 private void Flush() 1240 private void Flush()
1289 { 1241 {
1290 byte[] dbuffer = new byte[8192]; 1242 byte[] dbuffer = new byte[8192];
1291 while (request.InputStream.Read(dbuffer,0,dbuffer.Length) != 0); 1243 while (request.InputStream.Read(dbuffer,0,dbuffer.Length) != 0);
1292 return;
1293 } 1244 }
1294 1245
1295 // This allows us to make errors a bit more apparent in REST 1246 // This allows us to make errors a bit more apparent in REST
@@ -1301,7 +1252,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1301 1252
1302 internal void SendHtml(string title, string text) 1253 internal void SendHtml(string title, string text)
1303 { 1254 {
1304
1305 AddHeader(Rest.HttpHeaderContentType, "text/html"); 1255 AddHeader(Rest.HttpHeaderContentType, "text/html");
1306 sbuilder.Length = 0; 1256 sbuilder.Length = 0;
1307 1257
@@ -1321,7 +1271,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
1321 sbuilder.Append("</html>"); 1271 sbuilder.Append("</html>");
1322 1272
1323 html = sbuilder.ToString(); 1273 html = sbuilder.ToString();
1324
1325 } 1274 }
1326 } 1275 }
1327} 1276}