aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/BaseHttpServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers/BaseHttpServer.cs')
-rw-r--r--OpenSim/Framework/Servers/BaseHttpServer.cs184
1 files changed, 174 insertions, 10 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs
index b6776f2..da0ce79 100644
--- a/OpenSim/Framework/Servers/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/BaseHttpServer.cs
@@ -593,14 +593,26 @@ namespace OpenSim.Framework.Servers
593 case "text/xml": 593 case "text/xml":
594 case "application/xml": 594 case "application/xml":
595 default: 595 default:
596 // Point of note.. the DoWeHaveA methods check for an EXACT path
597 if (request.RawUrl.Contains("/CAPS/EQG"))
598 {
599 int i = 1;
600 }
596 if (DoWeHaveALLSDHandler(request.RawUrl)) 601 if (DoWeHaveALLSDHandler(request.RawUrl))
597 { 602 {
598 // Check if we have a LLSD handler here for the EXACT path.
599 HandleLLSDRequests(request, response); 603 HandleLLSDRequests(request, response);
604 return;
605 }
600 606
607 if (DoWeHaveAHTTPHandler(request.RawUrl))
608 {
609 HandleHTTPRequest(request, response);
601 return; 610 return;
602 } 611 }
612
613 // generic login request.
603 HandleXmlRpcRequests(request, response); 614 HandleXmlRpcRequests(request, response);
615
604 return; 616 return;
605 } 617 }
606 } 618 }
@@ -846,11 +858,21 @@ namespace OpenSim.Framework.Servers
846 { 858 {
847 llsdResponse = GenerateNoLLSDHandlerResponse(); 859 llsdResponse = GenerateNoLLSDHandlerResponse();
848 } 860 }
861 byte[] buffer = new byte[0];
862 if (llsdResponse.ToString() == "shutdown404!")
863 {
864 response.ContentType = "text/plain";
865 response.StatusCode = 404;
866 response.StatusDescription = "Not Found";
867 response.ProtocolVersion = "HTTP/1.0";
868 buffer = Encoding.UTF8.GetBytes("Not found");
869 }
870 else
871 {
872 response.ContentType = "application/llsd+xml";
849 873
850 response.ContentType = "application/llsd+xml"; 874 buffer = LLSDParser.SerializeXmlBytes(llsdResponse);
851 875 }
852 byte[] buffer = LLSDParser.SerializeXmlBytes(llsdResponse);
853
854 response.SendChunked = false; 876 response.SendChunked = false;
855 response.ContentLength64 = buffer.Length; 877 response.ContentLength64 = buffer.Length;
856 response.ContentEncoding = Encoding.UTF8; 878 response.ContentEncoding = Encoding.UTF8;
@@ -878,6 +900,11 @@ namespace OpenSim.Framework.Servers
878 } 900 }
879 } 901 }
880 902
903 /// <summary>
904 /// Checks if we have an Exact path in the LLSD handlers for the path provided
905 /// </summary>
906 /// <param name="path">URI of the request</param>
907 /// <returns>true if we have one, false if not</returns>
881 private bool DoWeHaveALLSDHandler(string path) 908 private bool DoWeHaveALLSDHandler(string path)
882 { 909 {
883 910
@@ -908,6 +935,59 @@ namespace OpenSim.Framework.Servers
908 } 935 }
909 936
910 // extra kicker to remove the default XMLRPC login case.. just in case.. 937 // extra kicker to remove the default XMLRPC login case.. just in case..
938 if (path != "/" && bestMatch == "/" && searchquery != "/")
939 return false;
940
941 if (path == "/")
942 return false;
943
944 if (String.IsNullOrEmpty(bestMatch))
945 {
946
947 return false;
948 }
949 else
950 {
951
952 return true;
953 }
954 }
955
956 /// <summary>
957 /// Checks if we have an Exact path in the HTTP handlers for the path provided
958 /// </summary>
959 /// <param name="path">URI of the request</param>
960 /// <returns>true if we have one, false if not</returns>
961 private bool DoWeHaveAHTTPHandler(string path)
962 {
963
964 string[] pathbase = path.Split('/');
965 string searchquery = "/";
966
967 if (pathbase.Length < 1)
968 return false;
969
970 for (int i = 1; i < pathbase.Length; i++)
971 {
972 searchquery += pathbase[i];
973 if (pathbase.Length - 1 != i)
974 searchquery += "/";
975 }
976
977 string bestMatch = null;
978
979 foreach (string pattern in m_HTTPHandlers.Keys)
980 {
981
982 if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length)
983 {
984
985 bestMatch = pattern;
986
987 }
988 }
989
990 // extra kicker to remove the default XMLRPC login case.. just in case..
911 if (path == "/") 991 if (path == "/")
912 return false; 992 return false;
913 993
@@ -1074,7 +1154,7 @@ namespace OpenSim.Framework.Servers
1074 Encoding encoding = Encoding.UTF8; 1154 Encoding encoding = Encoding.UTF8;
1075 StreamReader reader = new StreamReader(requestStream, encoding); 1155 StreamReader reader = new StreamReader(requestStream, encoding);
1076 1156
1077 //string requestBody = reader.ReadToEnd(); 1157 string requestBody = reader.ReadToEnd();
1078 // avoid warning for now 1158 // avoid warning for now
1079 reader.ReadToEnd(); 1159 reader.ReadToEnd();
1080 reader.Close(); 1160 reader.Close();
@@ -1087,6 +1167,10 @@ namespace OpenSim.Framework.Servers
1087 string[] querystringkeys = request.QueryString.AllKeys; 1167 string[] querystringkeys = request.QueryString.AllKeys;
1088 string[] rHeaders = request.Headers.AllKeys; 1168 string[] rHeaders = request.Headers.AllKeys;
1089 1169
1170 keysvals.Add("body", requestBody);
1171 keysvals.Add("uri", request.RawUrl);
1172 keysvals.Add("content-type", request.ContentType);
1173
1090 1174
1091 foreach (string queryname in querystringkeys) 1175 foreach (string queryname in querystringkeys)
1092 { 1176 {
@@ -1113,8 +1197,26 @@ namespace OpenSim.Framework.Servers
1113 bool foundHandler = TryGetHTTPHandler(method, out requestprocessor); 1197 bool foundHandler = TryGetHTTPHandler(method, out requestprocessor);
1114 if (foundHandler) 1198 if (foundHandler)
1115 { 1199 {
1116 Hashtable responsedata = requestprocessor(keysvals); 1200 Hashtable responsedata1 = requestprocessor(keysvals);
1117 DoHTTPGruntWork(responsedata,response); 1201 DoHTTPGruntWork(responsedata1,response);
1202
1203 //SendHTML500(response);
1204 }
1205 else
1206 {
1207 //m_log.Warn("[HTTP]: Handler Not Found");
1208 SendHTML404(response, host);
1209 }
1210 }
1211 else
1212 {
1213
1214 GenericHTTPMethod requestprocessor;
1215 bool foundHandler = TryGetHTTPHandlerPathBased(request.RawUrl, out requestprocessor);
1216 if (foundHandler)
1217 {
1218 Hashtable responsedata2 = requestprocessor(keysvals);
1219 DoHTTPGruntWork(responsedata2, response);
1118 1220
1119 //SendHTML500(response); 1221 //SendHTML500(response);
1120 } 1222 }
@@ -1124,10 +1226,67 @@ namespace OpenSim.Framework.Servers
1124 SendHTML404(response, host); 1226 SendHTML404(response, host);
1125 } 1227 }
1126 } 1228 }
1229 }
1230
1231 private bool TryGetHTTPHandlerPathBased(string path, out GenericHTTPMethod httpHandler)
1232 {
1233 httpHandler = null;
1234 // Pull out the first part of the path
1235 // splitting the path by '/' means we'll get the following return..
1236 // {0}/{1}/{2}
1237 // where {0} isn't something we really control 100%
1238
1239 string[] pathbase = path.Split('/');
1240 string searchquery = "/";
1241
1242 if (pathbase.Length < 1)
1243 return false;
1244
1245 for (int i = 1; i < pathbase.Length; i++)
1246 {
1247 searchquery += pathbase[i];
1248 if (pathbase.Length - 1 != i)
1249 searchquery += "/";
1250 }
1251
1252 // while the matching algorithm below doesn't require it, we're expecting a query in the form
1253 //
1254 // [] = optional
1255 // /resource/UUID/action[/action]
1256 //
1257 // now try to get the closest match to the reigstered path
1258 // at least for OGP, registered path would probably only consist of the /resource/
1259
1260 string bestMatch = null;
1261
1262 foreach (string pattern in m_HTTPHandlers.Keys)
1263 {
1264 if (searchquery.ToLower().StartsWith(pattern.ToLower()))
1265 {
1266 if (String.IsNullOrEmpty(bestMatch) || searchquery.Length > bestMatch.Length)
1267 {
1268 // You have to specifically register for '/' and to get it, you must specificaly request it
1269 //
1270 if (pattern == "/" && searchquery == "/" || pattern != "/")
1271 bestMatch = pattern;
1272 }
1273 }
1274 }
1275
1276
1277
1278 if (String.IsNullOrEmpty(bestMatch))
1279 {
1280 httpHandler = null;
1281 return false;
1282 }
1127 else 1283 else
1128 { 1284 {
1129 //m_log.Warn("[HTTP]: No Method specified"); 1285 if (bestMatch == "/" && searchquery != "/")
1130 SendHTML404(response, host); 1286 return false;
1287
1288 httpHandler = m_HTTPHandlers[bestMatch];
1289 return true;
1131 } 1290 }
1132 } 1291 }
1133 1292
@@ -1342,6 +1501,11 @@ namespace OpenSim.Framework.Servers
1342 1501
1343 public void RemoveHTTPHandler(string httpMethod, string path) 1502 public void RemoveHTTPHandler(string httpMethod, string path)
1344 { 1503 {
1504 if (httpMethod != null && httpMethod.Length == 0)
1505 {
1506 m_HTTPHandlers.Remove(path);
1507 return;
1508 }
1345 m_HTTPHandlers.Remove(GetHandlerKey(httpMethod, path)); 1509 m_HTTPHandlers.Remove(GetHandlerKey(httpMethod, path));
1346 } 1510 }
1347 1511