using System;
using System.Text;
using System.Security;
namespace Intel.WebStorage
{
///
/// Provides basic access to the AMT's Web Storage
///
public interface IWebStorageConnection : IDisposable
{
#region Properties
///
/// The host name\IP of the machine to connect.
///
string Host { get; set; }
///
/// Gets or sets the user name.
///
string UserName { get; set; }
///
/// Gets or sets the password.
///
SecureString Password { get; set; }
///
/// Indicates whether to use secure connection (HTTP\HTTPS).
///
bool Secure { get; set; }
///
/// Indicates which authentication scheme to use with the AMT.
///
AuthenticationScheme Authentication { get; set; }
///
/// Connection options.
///
IWebStorageConnectionOptions Options { get; }
#endregion //Properties
#region Methods
///
/// Put a file in the root directory of AMT web storage.
/// Only index.htm and logon.htm can be saved in this location.
///
void Put(string filePath);
///
/// Put a file in the root directory of AMT web storage with specific HTTP headers fields for a file to be uploaded to the AMT.
/// Only index.htm and logon.htm can be saved in this location.
///
void Put(string filePath, Headers headers);
///
/// Put a file in the AMT's web storage.
///
/// .
/// .
/// .
/// .
void Put(string filePath, string directory, string subdirectory, string webUILinkName);
///
/// Put a file in the AMT's web storage with specific HTTP headers fields for a file to be uploaded to the AMT.
///
/// .
/// .
/// .
/// .
void Put(string filePath, string directory, string subdirectory, Headers headers);
///
/// Get a file from the AMT's web storage.
///
/// .
/// .
/// .
/// .
byte[] Get(string directory, string subdirectory, string fileName);
///
/// Get file content from the AMT's web storage.
///
///
///
///
/// File contnet
string GetFileContent(string directory, string subdirectory, string fileName);
///
/// Get the contents of a specific web storage directory.
///
/// .
/// .
/// .
/// .
string GetContent(string directory, string subdirectory);
///
/// Delete a file from the AMT's web storage.
///
/// .
/// .
/// .
/// .
void Delete(string directory, string subdirectory, string fileName);
#endregion //Methods
}
#region Structs
///
/// A struct that defines supported HTTP header fields for a file to be uploaded to the AMT.
/// This header fields will be included in the HTTP GET response header of the file.
///
public struct Headers
{
private const int MAX_HEADER_FIELD_LENGTH = 256;
private string _contentType;
private string _contentEncoding;
private string _contentDisposition;
private string _cacheControl;
private string _xFrameOptions;
private string _webUIlink;
///
/// The Content-Type of the file.
/// If this property is null or empty string the Content-Type field value in any HTTP GET response header will be: text/plain.
///
public string ContentType
{
get { return _contentType;}
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("Content-Type header field can contain up to 256 characters.");
_contentType = value;
}
}
///
/// The Content-Encoding of the file.
/// The Content-Encoding field will not be included in the response header of any HTTP GET command if this property is null or empty string.
///
public string ContentEncoding
{
get { return _contentEncoding; }
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("Content-Encoding header field can contain up to 256 characters.");
_contentEncoding = value;
}
}
///
/// The Content-Disposition of the file.
/// The Content-Disposition field will not be included in the response header of any HTTP GET command if this property is null or empty string.
///
public string ContentDisposition
{
get { return _contentDisposition; }
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("Content-Disposition header field can contain up to 256 characters.");
_contentDisposition = value;
}
}
///
/// The Cache-Control of the file.
/// The Cache-Control field will not be included in the response header of any HTTP GET command if this property is null or empty string.
///
public string CacheControl
{
get { return _cacheControl; }
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("Cache-Control header field can contain up to 256 characters.");
_cacheControl = value;
}
}
///
/// The X-Frame-Options header field value of the file.
/// The X-Frame-Options field will not be included in the response header of any HTTP GET command if this property is null or empty string.
///
public string XFrameOptions
{
get { return _xFrameOptions; }
set
{
if (!String.IsNullOrEmpty(value) && value.Length > MAX_HEADER_FIELD_LENGTH)
throw new WebStorageException("X-Frame-Options header field can contain up to 256 characters.");
_xFrameOptions = value;
}
}
///
/// The link name of the file that will be shown in the WebUI.
/// If empty or null - no new link name will be added to the file.
/// This parameter will not be passed in the HTTP response header.
///
public string Link
{
get { return _webUIlink; }
set { _webUIlink = value; }
}
public override string ToString()
{
StringBuilder str = new StringBuilder();
str.Append("");
//Headers
str.Append("");
if (!String.IsNullOrEmpty(ContentType))
str.Append("Content-Type:" + ContentType + "");
if (!String.IsNullOrEmpty(ContentEncoding))
str.Append("Content-Encoding:" + ContentEncoding + "");
if (!String.IsNullOrEmpty(ContentDisposition))
str.Append("Content-Disposition:" + ContentDisposition + "");
if (!String.IsNullOrEmpty(CacheControl))
str.Append("Cache-Control:" + CacheControl + "");
if (!String.IsNullOrEmpty(XFrameOptions))
str.Append("X-Frame-Options:" + XFrameOptions + "");
str.Append("");
//WebUI Link
if (!String.IsNullOrEmpty(Link))
{
str.Append("" + Link + "");
}
str.Append("");
return str.ToString();
}
public byte[] GetBytes()
{
string headerStr = ToString();
return Encoding.UTF8.GetBytes(headerStr);
}
}
#endregion //Structs
#region Enums
///
/// HTTP request method.
///
public enum HttpRequestMethod
{
PUT = 0,
GET,
DELETE
}
///
/// Authentication scheme.
///
public enum AuthenticationScheme
{
Digest = 0,
Kerberos
}
#endregion //Enums
}