public ServiceMessage(HTTPPartialData HTTPData, StateServer Service)
: base(HTTPData)
{
service = Service;
//Get other information
timeout = null;
if (headers["TIMEOUT"] != null)
{
int v;
int.TryParse(headers["TIMEOUT"], out v);
timeout = v;
}
lockCookie = null;
if (headers["LOCKCOOKIE"] != null)
{
uint v;
uint.TryParse(headers["LOCKCOOKIE"], out v);
lockCookie = v;
}
int plainTextSize = -1;
bool encrypted = false;
if (headers["CONTENT-TYPE"] != null)
{
string[] directives = headers["CONTENT-TYPE"].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if(directives[0].Trim().ToUpperInvariant() == @"APPLICATION/X-ENCRYPTED") encrypted = true;
foreach (string directive in directives)
{
if (directive.Trim().ToUpperInvariant().StartsWith("PLAINTEXT-LENGTH"))
{
if (!int.TryParse(directive.Trim().Substring(16).Replace("=", string.Empty).Trim(), out plainTextSize))
{
isError = true;
}
}
}
if(encrypted && plainTextSize < 0) isError = true;
}
if (!isError)
{
if (socket.IsAuthenticated && service.Settings.EncryptPeerData)
{
if (body.Length > 0 )
{
if (!encrypted)
{
Diags.LogMessageUnprotectedError(this);
isError = true;
}
else
{
try
{
body = service.Authenticator.Unprotect(body, socket.SessionKey, plainTextSize);
}
catch (Exception ex)
{
Diags.LogMessageContentCipherError(this, ex);
isError = true;
}
}
}
}
else
{
if (encrypted)
{
Diags.LogMessageProtectedError(this);
isError = true;
}
}
}
}