aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.GridServer/GridHttp.cs
diff options
context:
space:
mode:
authorgareth2007-04-02 00:48:25 +0000
committergareth2007-04-02 00:48:25 +0000
commite985e05a5ad7df4c5f01763dfe6b82cc1b37ab83 (patch)
tree7b07b8fae3ade588d11cdeeabf1f2479e80a8dff /OpenGridServices.GridServer/GridHttp.cs
parentMore refactoring (diff)
downloadopensim-SC_OLD-e985e05a5ad7df4c5f01763dfe6b82cc1b37ab83.zip
opensim-SC_OLD-e985e05a5ad7df4c5f01763dfe6b82cc1b37ab83.tar.gz
opensim-SC_OLD-e985e05a5ad7df4c5f01763dfe6b82cc1b37ab83.tar.bz2
opensim-SC_OLD-e985e05a5ad7df4c5f01763dfe6b82cc1b37ab83.tar.xz
Added new REST protocol (partially complete)
Made sim profiles load from DB Updated build files for grid server Added sim login
Diffstat (limited to 'OpenGridServices.GridServer/GridHttp.cs')
-rw-r--r--OpenGridServices.GridServer/GridHttp.cs152
1 files changed, 96 insertions, 56 deletions
diff --git a/OpenGridServices.GridServer/GridHttp.cs b/OpenGridServices.GridServer/GridHttp.cs
index c9cda61..33e1e71 100644
--- a/OpenGridServices.GridServer/GridHttp.cs
+++ b/OpenGridServices.GridServer/GridHttp.cs
@@ -56,8 +56,13 @@ namespace OpenGridServices.GridServer
56 MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Spawned main thread OK"); 56 MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Spawned main thread OK");
57 Listener = new HttpListener(); 57 Listener = new HttpListener();
58 58
59 Listener.Prefixes.Add("http://+:8001/gridserver/"); 59 Listener.Prefixes.Add("http://+:8001/sims/");
60 Listener.Prefixes.Add("http://+:8001/gods/");
61 Listener.Prefixes.Add("http://+:8001/highestuuid/");
62 Listener.Prefixes.Add("http://+:8001/uuidblocks/");
60 Listener.Start(); 63 Listener.Start();
64
65 MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Successfully bound to port 8001");
61 66
62 HttpListenerContext context; 67 HttpListenerContext context;
63 while(true) { 68 while(true) {
@@ -66,72 +71,105 @@ namespace OpenGridServices.GridServer
66 } 71 }
67 } 72 }
68 73
69 static string ParseXMLRPC(string requestBody) { 74 static string ParseXMLRPC(string requestBody, string referrer) {
70 try{ 75 try{
71 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); 76 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
72 77
73 Hashtable requestData = (Hashtable)request.Params[0]; 78 Hashtable requestData = (Hashtable)request.Params[0];
74 switch(request.MethodName) { 79 switch(request.MethodName) {
75 case "get_sim_info": 80 case "simulator_login":
76 ulong req_handle=(ulong)Convert.ToInt64(requestData["region_handle"]); 81 if(!(referrer=="simulator")) {
77 SimProfileBase TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle(req_handle); 82 XmlRpcResponse ErrorResp = new XmlRpcResponse();
78 string RecvKey=""; 83 Hashtable ErrorRespData = new Hashtable();
79 string caller=(string)requestData["caller"]; 84 ErrorRespData["error"]="Only simulators can login with this method";
80 switch(caller) { 85 ErrorResp.Value=ErrorRespData;
81 case "userserver": 86 return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8"));
82 RecvKey=OpenGrid_Main.thegrid.UserRecvKey; 87 }
83 break; 88
84 case "assetserver": 89 if(!((string)requestData["authkey"]==OpenGrid_Main.thegrid.SimRecvKey)) {
85 RecvKey=OpenGrid_Main.thegrid.AssetRecvKey; 90 XmlRpcResponse ErrorResp = new XmlRpcResponse();
86 break; 91 Hashtable ErrorRespData = new Hashtable();
87 } 92 ErrorRespData["error"]="invalid key";
88 if((TheSim!=null) && (string)requestData["authkey"]==RecvKey) { 93 ErrorResp.Value=ErrorRespData;
89 XmlRpcResponse SimInfoResp = new XmlRpcResponse(); 94 return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8"));
90 Hashtable SimInfoData = new Hashtable(); 95 }
91 SimInfoData["UUID"]=TheSim.UUID.ToString(); 96
92 SimInfoData["regionhandle"]=TheSim.regionhandle.ToString(); 97 SimProfileBase TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(new LLUUID((string)requestData["UUID"]));
93 SimInfoData["regionname"]=TheSim.regionname; 98 XmlRpcResponse SimLoginResp = new XmlRpcResponse();
94 SimInfoData["sim_ip"]=TheSim.sim_ip; 99 Hashtable SimLoginRespData = new Hashtable();
95 SimInfoData["sim_port"]=TheSim.sim_port.ToString(); 100
96 SimInfoData["caps_url"]=TheSim.caps_url; 101 ArrayList SimNeighboursData = new ArrayList();
97 SimInfoData["RegionLocX"]=TheSim.RegionLocX.ToString(); 102
98 SimInfoData["RegionLocY"]=TheSim.RegionLocY.ToString(); 103 SimProfileBase neighbour;
99 SimInfoData["sendkey"]=TheSim.sendkey; 104 Hashtable NeighbourBlock;
100 SimInfoData["recvkey"]=TheSim.recvkey; 105 for(int x=-1; x<2; x++) for(int y=-1; y<2; y++) {
101 SimInfoResp.Value=SimInfoData; 106 if(OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX+x)*256), (uint)(TheSim.RegionLocY+y)*256))!=null) {
102 return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(SimInfoResp),"utf-16","utf-8")); 107 neighbour=OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX+x)*256), (uint)(TheSim.RegionLocY+y)*256));
103 } else { 108 NeighbourBlock = new Hashtable();
104 XmlRpcResponse SimErrorResp = new XmlRpcResponse(); 109 NeighbourBlock["sim_ip"] = neighbour.sim_ip;
105 Hashtable SimErrorData = new Hashtable(); 110 NeighbourBlock["sim_port"] = neighbour.sim_port.ToString();
106 SimErrorData["error"]="sim not found"; 111 NeighbourBlock["region_locx"] = neighbour.RegionLocX.ToString();
107 SimErrorResp.Value=SimErrorData; 112 NeighbourBlock["region_locy"] = neighbour.RegionLocY.ToString();
108 return(XmlRpcResponseSerializer.Singleton.Serialize(SimErrorResp)); 113 NeighbourBlock["UUID"] = neighbour.UUID.ToString();
109 } 114 SimNeighboursData.Add(NeighbourBlock);
110 break; 115 }
111 } 116 }
117
118
119 SimLoginRespData["region_locx"]=TheSim.RegionLocX.ToString();
120 SimLoginRespData["region_locy"]=TheSim.RegionLocY.ToString();
121 SimLoginRespData["regionname"]=TheSim.regionname;
122 SimLoginRespData["estate_id"]="1";
123 SimLoginRespData["neighbours"]=SimNeighboursData;
124 SimLoginRespData["asset_url"]=OpenGrid_Main.thegrid.DefaultAssetServer;
125 SimLoginRespData["asset_sendkey"]=OpenGrid_Main.thegrid.AssetSendKey;
126 SimLoginRespData["asset_recvkey"]=OpenGrid_Main.thegrid.AssetRecvKey;
127 SimLoginRespData["user_url"]=OpenGrid_Main.thegrid.DefaultUserServer;
128 SimLoginRespData["user_sendkey"]=OpenGrid_Main.thegrid.UserSendKey;
129 SimLoginRespData["user_recvkey"]=OpenGrid_Main.thegrid.UserRecvKey;
130 SimLoginRespData["authkey"]=OpenGrid_Main.thegrid.SimSendKey;
131 SimLoginResp.Value=SimLoginRespData;
132 return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(SimLoginResp),"utf-16","utf-8"));
133 break;
134 }
112 } catch(Exception e) { 135 } catch(Exception e) {
113 Console.WriteLine(e.ToString()); 136 Console.WriteLine(e.ToString());
114 } 137 }
115 return ""; 138 return "";
116 } 139 }
117 140
118 static string ParseREST(string requestBody, string requestURL) { 141 static string ParseREST(string requestBody, string requestURL, string HTTPmethod) {
119 char[] splitter = {'/'}; 142 char[] splitter = {'/'};
120 string[] rest_params = requestURL.Split(splitter); 143 string[] rest_params = requestURL.Split(splitter);
121 string req_type = rest_params[1]; // First part of the URL is the type of request - 144 string req_type = rest_params[0]; // First part of the URL is the type of request -
122 switch(req_type) { 145 string respstring;
123 case "regions": 146 switch(req_type) {
124 ulong regionhandle = (ulong)Convert.ToInt64(rest_params[2]); // get usersessions/sessionid 147 case "sims":
125 switch(rest_params[3]) { 148 LLUUID UUID = new LLUUID((string)rest_params[1]);
126 case "neighbours": 149 SimProfileBase TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(UUID);
127 return OpenGrid_Main.thegrid._regionmanager.GetXMLNeighbours(regionhandle); 150 if(!(TheSim==null)) {
128 break; 151 switch(HTTPmethod) {
152 case "GET":
153 respstring="<authkey>" + OpenGrid_Main.thegrid.SimSendKey + "</authkey>";
154 respstring+="<sim>";
155 respstring+="<uuid>" + TheSim.UUID.ToString() + "</uuid>";
156 respstring+="<regionname>" + TheSim.regionname + "</regionname>";
157 respstring+="<sim_ip>" + TheSim.sim_ip + "</sim_ip>";
158 respstring+="<sim_port>" + TheSim.sim_port.ToString() + "</sim_port>";
159 respstring+="<region_locx>" + TheSim.RegionLocX.ToString() + "</region_locx>";
160 respstring+="<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>";
161 respstring+="<estate_id>1</estate_id>";
162 respstring+="</sim>";
163 break;
164 }
129 } 165 }
130 return "OK";
131 break; 166 break;
132 } 167 case "highestuuid":
168
169 break;
170 }
133 return ""; 171 return "";
134 172
135 } 173 }
136 174
137 175
@@ -152,18 +190,20 @@ namespace OpenGridServices.GridServer
152 body.Close(); 190 body.Close();
153 reader.Close(); 191 reader.Close();
154 192
193 // TODO: AUTHENTICATION!!!!!!!!! MUST ADD!!!!!!!!!! SCRIPT KIDDIES LOVE LACK OF IT!!!!!!!!!!
194
155 string responseString=""; 195 string responseString="";
156 switch(request.ContentType) { 196 switch(request.ContentType) {
157 case "text/xml": 197 case "text/xml":
158 // must be XML-RPC, so pass to the XML-RPC parser 198 // must be XML-RPC, so pass to the XML-RPC parser
159 199
160 responseString=ParseXMLRPC(requestBody); 200 responseString=ParseXMLRPC(requestBody,request.Headers["Referer"]);
161 response.AddHeader("Content-type","text/xml"); 201 response.AddHeader("Content-type","text/xml");
162 break; 202 break;
163 203
164 case null: 204 case null:
165 // must be REST or invalid crap, so pass to the REST parser 205 // must be REST or invalid crap, so pass to the REST parser
166 responseString=ParseREST(request.Url.OriginalString,requestBody); 206 responseString=ParseREST(request.Url.OriginalString,requestBody,request.HttpMethod);
167 break; 207 break;
168 } 208 }
169 209