本文整理汇总了C#中OpenSource.UPnP.HTTPMessage类的典型用法代码示例。如果您正苦于以下问题:C# HTTPMessage类的具体用法?C# HTTPMessage怎么用?C# HTTPMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HTTPMessage类属于OpenSource.UPnP命名空间,在下文中一共展示了HTTPMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StateData
public StateData(HTTPMessage req, IPEndPoint d, object Tag, HeaderHandler HeaderCB)
{
this.Dest = d;
this.Request = req;
this.Tag = Tag;
this.HeaderCB = HeaderCB;
}
示例2: DelayedInvokeResponse
/// <summary>
/// This is used to complete an AsyncRequest in an AsyncFashion.
/// <para>
/// You must either assign all the Argument values, or return an exception with "e"
/// </para>
/// </summary>
/// <param name="id">ID</param>
/// <param name="RetArg">Return Argument</param>
/// <param name="OutArgs">Out Arguments</param>
/// <param name="e">Exception</param>
public void DelayedInvokeResponse(long id, object RetArg, UPnPArgument[] OutArgs, UPnPCustomException e)
{
UPnPDevice.InvokerInfoStruct iis = (UPnPDevice.InvokerInfoStruct)DelayedResponseTable[id];
HTTPMessage resp = new HTTPMessage();
if (e != null)
{
resp.StatusCode = 500;
resp.StatusData = "Internal";
resp.StringBuffer = ParentDevice.BuildErrorBody(e);
}
else
{
resp = ParentDevice.ParseInvokeResponse(iis.MethodName, iis.SOAPAction, this.ServiceURN, RetArg, OutArgs);
}
iis.WebSession.Send(resp);
iis.WebSession.StartReading();
lock (DelayedResponseTable)
{
DelayedResponseTable.Remove(id);
}
}
示例3: ParseByteArray
/// <summary>
/// Parses a Byte Array at a specific location, and builds a Packet.
/// </summary>
/// <param name="buffer">The Array of Bytes</param>
/// <param name="indx">The Start Index</param>
/// <param name="count">The number of Bytes to process</param>
/// <returns></returns>
public static HTTPMessage ParseByteArray(byte[] buffer, int indx, int count)
{
HTTPMessage TheMessage = new HTTPMessage();
UTF8Encoding UTF8 = new UTF8Encoding();
String TempData = UTF8.GetString(buffer,indx,count);
DText parser = new DText();
String TempString;
int idx = TempData.IndexOf("\r\n\r\n");
if (idx < 0) return null;
TempData = TempData.Substring(0,idx);
parser.ATTRMARK = "\r\n";
parser.MULTMARK = ":";
parser[0] = TempData;
string CurrentLine = parser[1];
DText HdrParser = new DText();
HdrParser.ATTRMARK = " ";
HdrParser.MULTMARK = "/";
HdrParser[0] = CurrentLine;
if (CurrentLine.ToUpper().StartsWith("HTTP/")==true)
{
TheMessage.ResponseCode = int.Parse(HdrParser[2]);
int s1 = CurrentLine.IndexOf(" ");
s1 = CurrentLine.IndexOf(" ",s1+1);
TheMessage.ResponseData = HTTPMessage.UnEscapeString(CurrentLine.Substring(s1));
try
{
TheMessage.Version = HdrParser[1,2];
}
catch(Exception)
{
TheMessage.Version = "0.9";
}
}
else
{
TheMessage.Directive = HdrParser[1];
TempString = CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1);
if (TempString.ToUpper().StartsWith("HTTP/")==false)
{
TheMessage.Version = "0.9";
TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(TempString);
}
else
{
TheMessage.Version = TempString.Substring(TempString.IndexOf("/")+1);
int fs = CurrentLine.IndexOf(" ") + 1;
TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(CurrentLine.Substring(
fs,
CurrentLine.Length-fs-TempString.Length-1));
}
}
String Tag="";
String TagData="";
for(int line=2;line<=parser.DCOUNT();++line)
{
if (Tag!="" && parser[line,1].StartsWith(" "))
{
TagData = parser[line,1].Substring(1);
}
else
{
Tag = parser[line,1];
TagData = "";
for(int i=2;i<=parser.DCOUNT(line);++i)
{
if (TagData=="")
{
TagData = parser[line,i];
}
else
{
TagData = TagData + parser.MULTMARK + parser[line,i];
}
}
}
TheMessage.AppendTag(Tag,TagData);
}
int cl=0;
if (TheMessage.HasTag("Content-Length"))
{
try
{
cl = int.Parse(TheMessage.GetTag("Content-Length"));
}
catch(Exception)
{
cl = -1;
}
//.........这里部分代码省略.........
示例4: OnPacketTraceChangedSink
private void OnPacketTraceChangedSink(IUPnPTestGroup sender, HTTPMessage packet)
{
this.BeginInvoke(new UpdatePacketTraceForCurrentTestHandler(UpdatePacketTraceForCurrentTest), new object[] { sender, packet });
}
示例5: SniffPacketSink
private void SniffPacketSink(HTTPSession sender, HTTPMessage MSG)
{
if (this.OnSniffPacket != null)
{
if (sender.StateObject == null)
{
OnSniffPacket(this, MSG, null);
return;
}
StateData sd = (StateData)sender.StateObject;
object Tag = sd.Tag;
OnSniffPacket(this, MSG, Tag);
}
}
示例6: HeaderSink
private void HeaderSink(HTTPSession sender, HTTPMessage header, Stream TheStream)
{
_Source = sender.Source;
StateData sd = null;
if (TheStream != null)
{
// This is the result of post-headers in a chunked document
sd = (StateData)sender.StateObject;
object Tag = sd.Tag;
if (sd.HeaderCB != null) sd.HeaderCB(this, sender, header, TheStream, Tag);
sender.StateObject = null;
KeepAliveTimer.Add(this.GetHashCode(), 10);
}
else
{
lock (TagQueue)
{
sd = (StateData)TagQueue.Dequeue();
}
sender.StateObject = sd;
object Tag = sd.Tag;
if (sd.HeaderCB != null)
{
sd.HeaderCB(this, sender, header, TheStream, Tag);
if (sender.UserStream != null && !sender.IsChunked)
{
// If I don't set this to null, this holds a strong reference, resulting in
// possible memory leaks
sender.StateObject = null;
}
}
}
}
示例7: NonPipelinedSniffPacketSink
private void NonPipelinedSniffPacketSink(HTTPRequest sender, HTTPMessage Response, object Tag)
{
if (OnSniffPacket != null)
OnSniffPacket(this, Response, Tag);
}
示例8: PipelineRequest
/// <summary>
/// Pipelines a request packet
/// </summary>
/// <param name="dest">Destination IPEndPoint</param>
/// <param name="MSG">HTTPMessage Packet</param>
/// <param name="Tag">State Data</param>
public void PipelineRequest(IPEndPoint dest, HTTPMessage MSG, object Tag)
{
ContinueRequest(dest, "", Tag, MSG);
}
示例9: HandleSendEvent
private void HandleSendEvent(HTTPRequest R, HTTPMessage M, object Tag)
{
R.Dispose();
SendEventTable.Remove(R);
}
示例10: HandleInvokeRequest
private void HandleInvokeRequest(HTTPRequest sender, HTTPMessage response, object Tag)
{
AsyncInvokeInfo state = (AsyncInvokeInfo)Tag;
if (response == null)
{
if (state.ErrorCB != null)
{
state.ErrorCB(this, state.MethodName, state.Args, new UPnPInvokeException(state.MethodName, state.Args, "Could not connect to device"), state.Tag);
}
else
{
if (OnInvokeError != null)
{
OnInvokeError(this, state.MethodName, state.Args, new UPnPInvokeException(state.MethodName, state.Args, "Could not connect to device"), state.Tag);
}
}
return;
}
if (response.StatusCode == 100)
{
// Ignore
return;
}
UPnPAction action = (UPnPAction)RemoteMethods[state.MethodName];
if (response.StatusCode != 200)
{
if ((OnInvokeError != null) || (state.ErrorCB != null))
{
if ((response.StatusCode == 500) && (response.BodyBuffer.Length > 0))
{
// Try to parse SOAP Encoded Error
UPnPCustomException ce = null;
try
{
ce = ParseErrorBody(response.StringBuffer);
OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error,
"UPnP Action <" + state.MethodName + "> Error [" + ce.ErrorCode.ToString() + "] " + ce.ErrorDescription);
}
catch
{
ce = null;
OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error,
"HTTP Fault invoking " + state.MethodName + " : " + response.StatusData);
}
if (state.ErrorCB != null)
{
state.ErrorCB(this, action.Name, state.Args, new UPnPInvokeException(state.MethodName, state.Args, response.StatusData, ce), state.Tag);
}
else
{
if (OnInvokeError != null)
{
OnInvokeError(this, action.Name, state.Args, new UPnPInvokeException(state.MethodName, state.Args, response.StatusData, ce), state.Tag);
}
}
}
else
{
if (state.ErrorCB != null)
{
state.ErrorCB(this, action.Name, state.Args, new UPnPInvokeException(state.MethodName, state.Args, response.StatusData), state.Tag);
}
else
{
if (OnInvokeError != null)
{
OnInvokeError(this, action.Name, state.Args, new UPnPInvokeException(state.MethodName, state.Args, response.StatusData), state.Tag);
}
}
}
}
return;
}
//Lets Parse the data we got back
//Now we can parse the XML Body
StringReader MyString = new StringReader(response.StringBuffer.Trim());
XmlTextReader XMLDoc = new XmlTextReader(MyString);
String MethodTag = "";
UPnPArgument VarArg;
ArrayList VarList = new ArrayList();
XMLDoc.Read();
XMLDoc.MoveToContent();
if (XMLDoc.LocalName == "Envelope")
{
XMLDoc.Read();
XMLDoc.MoveToContent();
if (XMLDoc.LocalName == "Body")
{
XMLDoc.Read();
XMLDoc.MoveToContent();
//.........这里部分代码省略.........
示例11: _SubscribeEvent
internal HTTPMessage _SubscribeEvent(out String SID, String CallbackURL, String Timeout)
{
SubscriberInfo sinfo = new SubscriberInfo();
sinfo.SID = GetNewSID();
sinfo.CallbackURL = CallbackURL;
sinfo.SEQ = 1;
int to = int.Parse(Timeout);
if (to == 0)
{
sinfo.Expires = -1;
}
else
{
sinfo.Expires = DateTime.Now.AddSeconds(to).Ticks;
}
SubscriberTable[sinfo.SID] = sinfo;
// Send an inital Event
//SSDP.ParseURL(CallbackURL,out WebIP, out WebPort, out Tag);
HTTPMessage Packet = new HTTPMessage();
Packet.Directive = "NOTIFY";
Packet.AddTag("Content-Type", "text/xml");
Packet.AddTag("NT", "upnp:event");
Packet.AddTag("NTS", "upnp:propchange");
Packet.AddTag("SID", sinfo.SID);
Packet.AddTag("SEQ", "0");
Packet.AddTag("CONNECTION", "close");
Packet.BodyBuffer = BuildEventXML();
SID = sinfo.SID;
SubscriptionAddedEvent.Fire(this); // Trigger event saying that a subscription was added
return (Packet);
}
示例12: SendEvents
internal void SendEvents(UPnPStateVariable V)
{
//IDictionaryEnumerator en = SubscriberTable.GetEnumerator();
SubscriberInfo sinfo;
HTTPMessage Packet;
Uri[] EventURLS;
ICollection en = SubscriberTable.Keys;
String[] KEYS = new String[en.Count];
HTTPRequest R;
en.CopyTo(KEYS, 0);
for (int keyid = 0; keyid < KEYS.Length; ++keyid)
{
object _tobj = SubscriberTable[KEYS[keyid]];
if (_tobj != null)
{
sinfo = (SubscriberInfo)_tobj;
if ((sinfo.Expires > DateTime.Now.Ticks) || (sinfo.Expires == -1))
{
EventURLS = ParseEventURL(sinfo.CallbackURL);
for (int x = 0; x < EventURLS.Length; ++x)
{
try
{
IPAddress dest = IPAddress.Parse(EventURLS[x].Host);
Packet = new HTTPMessage();
Packet.Directive = "NOTIFY";
Packet.AddTag("Content-Type", "text/xml");
Packet.AddTag("NT", "upnp:event");
Packet.AddTag("NTS", "upnp:propchange");
Packet.BodyBuffer = BuildEventXML(new UPnPStateVariable[1] { V });
Packet.DirectiveObj = HTTPMessage.UnEscapeString(EventURLS[x].PathAndQuery);
if (dest.AddressFamily == AddressFamily.InterNetwork) Packet.AddTag("Host", EventURLS[x].Host + ":" + EventURLS[x].Port.ToString());
if (dest.AddressFamily == AddressFamily.InterNetworkV6) Packet.AddTag("Host", "[" + RemoveIPv6Scope(EventURLS[x].Host) + "]:" + EventURLS[x].Port.ToString());
Packet.AddTag("SID", sinfo.SID);
Packet.AddTag("SEQ", sinfo.SEQ.ToString());
Packet.AddTag("CONNECTION", "close");
++sinfo.SEQ;
SubscriberTable[KEYS[keyid]] = sinfo;
//OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.SuccessAudit,Packet.StringBuffer);
R = new HTTPRequest();
SendEventTable[R] = R;
R.OnResponse += new HTTPRequest.RequestHandler(HandleSendEvent);
R.PipelineRequest(new IPEndPoint(IPAddress.Parse(EventURLS[x].Host), EventURLS[x].Port), Packet, null);
}
catch (Exception)
{
}
}
}
else
{
SubscriberTable.Remove(sinfo.SID);
}
}
}
}
示例13: UnSubscribe
/// <summary>
/// Unsubscribe to UPnPEvent
/// </summary>
/// <param name="cb"></param>
public void UnSubscribe(UPnPEventHandler cb)
{
bool processUnSubscribe = false;
lock (SubscribeLock)
{
--SubscribeCounter;
if (SubscribeCounter <= 0)
{
SubscribeCounter = 0;
processUnSubscribe = true;
}
if (cb == null)
{
processUnSubscribe = true;
OnUPnPEvent = null;
}
else
{
OnUPnPEvent -= cb;
}
}
if (processUnSubscribe == false) return;
HTTPMessage request = new HTTPMessage();
String WebIP;
int WebPort;
String Tag;
SSDP.ParseURL(this.__eventurl, out WebIP, out WebPort, out Tag);
IPEndPoint dest = new IPEndPoint(IPAddress.Parse(WebIP), WebPort);
request.Directive = "UNSUBSCRIBE";
request.DirectiveObj = Tag;
request.AddTag("Host", WebIP + ":" + WebPort.ToString()); // WebIP is already formatted for IPv6
request.AddTag("SID", CurrentSID);
HTTPRequest UR = new HTTPRequest();
SubscribeRequestTable[UR] = UR;
UR.OnResponse += new HTTPRequest.RequestHandler(HandleUnsubscribeResponse);
CurrentSID = "";
UR.PipelineRequest(dest, request, null);
}
示例14: Subscribe
/// <summary>
/// Subscribe to UPnPEvents
/// </summary>
/// <param name="Timeout">Subscription Cycle</param>
public void Subscribe(int Timeout, UPnPEventSubscribeHandler CB)
{
bool processSubscribe = false;
lock (SubscribeLock)
{
if (SubscribeCounter == 0) processSubscribe = true;
++SubscribeCounter;
//OnUPnPEvent += UPnPEventCallback;
}
if (processSubscribe == false)
{
// Already subscribed... Just trigger Events
foreach (UPnPStateVariable V in this.GetStateVariables()) V.InitialEvent();
if (CB != null) CB(this, true);
return;
}
foreach (UPnPStateVariable V in this.GetStateVariables())
{
if (V.SendEvent) V.CurrentValue = null;
}
CurrentTimeout = Timeout;
HTTPMessage request = new HTTPMessage();
String WebIP;
int WebPort;
String Tag;
String NT;
if (Timeout == 0)
{
NT = "Second-infinite";
}
else
{
NT = "Second-" + Timeout.ToString();
}
SSDP.ParseURL(this.__eventurl, out WebIP, out WebPort, out Tag);
IPEndPoint dest = new IPEndPoint(IPAddress.Parse(WebIP), WebPort);
IPAddress addr = IPAddress.Parse(WebIP);
request.Directive = "SUBSCRIBE";
request.DirectiveObj = Tag;
if (addr.AddressFamily == AddressFamily.InterNetwork)
{
request.AddTag("Host", WebIP + ":" + WebPort.ToString());
}
else if (addr.AddressFamily == AddressFamily.InterNetworkV6)
{
request.AddTag("Host", "[" + RemoveIPv6Scope(addr.ToString()) + "]:" + WebPort.ToString());
}
request.AddTag("Callback", "<" + this.EventCallbackURL + ">");
request.AddTag("NT", "upnp:event");
request.AddTag("Timeout", NT);
HTTPRequest SR = new HTTPRequest();
SubscribeRequestTable[SR] = SR;
SR.OnResponse += new HTTPRequest.RequestHandler(HandleSubscribeResponse);
SR.PipelineRequest(dest, request, CB);
}
示例15: InvokeAsync
/// <summary>
/// Invokes a method on this service with specific callbacks
/// </summary>
/// <param name="MethodName">Name of Method</param>
/// <param name="InVarArr">Array of UPnPArguments</param>
/// <param name="InvokeCallback">Callback for Success</param>
/// <param name="ErrorCallback">Callback for Failed</param>
/// <returns>Unique Handle identifier</returns>
public void InvokeAsync(String MethodName, UPnPArgument[] InVarArr,
object Tag,
UPnPService.UPnPServiceInvokeHandler InvokeCallback,
UPnPService.UPnPServiceInvokeErrorHandler ErrorCallback)
{
HTTPMessage request = new HTTPMessage();
if (InVarArr == null)
{
InVarArr = new UPnPArgument[0];
}
UPnPAction action = (UPnPAction)RemoteMethods[MethodName];
if (action == null)
{
throw (new UPnPInvokeException(MethodName, InVarArr, MethodName + " is not currently defined in this object"));
}
else
{
action.ValidateArgs(InVarArr);
}
String WebIP;
String sName;
int WebPort;
SSDP.ParseURL(__controlurl, out WebIP, out WebPort, out sName);
IPEndPoint dest = new IPEndPoint(IPAddress.Parse(WebIP), WebPort);
request.Directive = "POST";
request.DirectiveObj = sName;
request.AddTag("Host", WebIP + ":" + WebPort);
request.AddTag("Content-Type", "text/xml; charset=\"utf-8\"");
request.AddTag("SoapAction", "\"" + ServiceURN + "#" + MethodName + "\"");
MemoryStream mstream = new MemoryStream(4096);
XmlTextWriter W = new XmlTextWriter(mstream, System.Text.Encoding.UTF8);
W.Formatting = Formatting.Indented;
W.Indentation = 3;
W.WriteStartDocument();
String S = "http://schemas.xmlsoap.org/soap/envelope/";
W.WriteStartElement("s", "Envelope", S);
W.WriteAttributeString("s", "encodingStyle", S, "http://schemas.xmlsoap.org/soap/encoding/");
W.WriteStartElement("s", "Body", S);
W.WriteStartElement("u", MethodName, ServiceURN);
for (int ID = 0; ID < InVarArr.Length; ++ID)
{
if (action.GetArg(InVarArr[ID].Name).Direction == "in")
{
W.WriteElementString(InVarArr[ID].Name, UPnPService.SerializeObjectInstance(InVarArr[ID].DataValue));
}
}
W.WriteEndElement();
W.WriteEndElement();
W.WriteEndElement();
W.WriteEndDocument();
W.Flush();
byte[] wbuf = new Byte[mstream.Length - 3];
mstream.Seek(3, SeekOrigin.Begin);
mstream.Read(wbuf, 0, wbuf.Length);
W.Close();
request.BodyBuffer = wbuf;
AsyncInvokeInfo state = new AsyncInvokeInfo();
state.Args = InVarArr;
state.MethodName = MethodName;
state.Packet = request;
state.Tag = Tag;
state.InvokeCB = InvokeCallback;
state.ErrorCB = ErrorCallback;
InvocationPipeline.PipelineRequest(dest, request, state);
}