protected void Run() {
while(_running) {
HttpListenerContext context = null;
try {
context = _listener.GetContext();
} catch(Exception e) {
Console.WriteLine(e);
ProtocolLog.WriteIf(SocialLog.SVPNLog,
String.Format("SVPN Exception: {0}", e));
}
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
string responseString;
response.ContentType = "text/xml";
if (request.RawUrl.StartsWith("/state.xml?")) {
string getData = request.RawUrl.Substring(11);
try {
responseString = Process(SocialUtils.DecodeUrl(getData));
} catch (Exception e) {
responseString = e.Message;
}
}
else if (request.RawUrl == "/state.xml") {
StreamReader reader = new StreamReader(request.InputStream,
request.ContentEncoding);
string postData = reader.ReadToEnd();
request.InputStream.Close();
reader.Close();
try {
responseString = Process(SocialUtils.DecodeUrl(postData));
} catch (Exception e) {
responseString = e.Message;
}
}
else if (request.RawUrl == "/socialvpn.js") {
using (StreamReader text = new StreamReader("socialvpn.js")) {
responseString = text.ReadToEnd();
}
response.ContentType = "text/javascript";
}
else if (request.RawUrl == "/socialvpn.css") {
using (StreamReader text = new StreamReader("socialvpn.css")) {
responseString = text.ReadToEnd();
}
response.ContentType = "text/css";
}
else if (request.RawUrl == "/socialdns.js") {
using (StreamReader text = new StreamReader("socialdns.js")) {
responseString = text.ReadToEnd();
}
response.ContentType = "text/javascript";
}
else if (request.RawUrl == "/socialdns.css") {
using (StreamReader text = new StreamReader("socialdns.css")) {
responseString = text.ReadToEnd();
}
response.ContentType = "text/css";
}
else if (request.RawUrl == "/jquery-ui.css") {
using (StreamReader text = new StreamReader("jquery-ui.css")) {
responseString = text.ReadToEnd();
}
response.ContentType = "text/css";
}
else if (request.RawUrl == "/jquery.js") {
using (StreamReader text = new StreamReader("jquery.js")) {
responseString = text.ReadToEnd();
}
response.ContentType = "text/javascript";
}
else if (request.RawUrl == "/jquery-ui.js") {
using (StreamReader text = new StreamReader("jquery-ui.js")) {
responseString = text.ReadToEnd();
}
response.ContentType = "text/javascript";
}
else if (request.RawUrl == "/sdns") {
using (StreamReader text = new StreamReader("socialdns.html")) {
responseString = text.ReadToEnd();
}
response.ContentType = "text/html";
}
else {
using (StreamReader text = new StreamReader("socialvpn.html")) {
responseString = text.ReadToEnd();
}
response.ContentType = "text/html";
}
if(responseString.StartsWith("<html>")) {
response.ContentType = "text.html";
}
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
response.AddHeader("Cache-Control", "No-cache");
System.IO.Stream output = response.OutputStream;
try {
output.Write(buffer, 0, buffer.Length);
output.Close();
} catch (Exception e) {
Console.WriteLine(e);
ProtocolLog.WriteIf(SocialLog.SVPNLog,
String.Format("SVPN Exception: {0}", e));
}
}
}
}