|
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Protocol
{
/// <summary>
/// Summary description for EchoProtocol.
/// </summary>
[ Guid("E00957BD-D0E1-4eb9-A025-7743FDC8B27B"), ComVisible(true), ClassInterface(ClassInterfaceType.None)]
[ AsyncProtocol(Name="echo", Description="Returns the URL of the protocol as HTML content.") ]
public class EchoProtocol : ProtocolBase, IInternetProtocol, IInternetProtocolRoot
{
#region IInternetProtocol Members
public void Start(string szURL, IInternetProtocolSink Sink, IInternetBindInfo pOIBindInfo, uint grfPI, uint dwReserved)
{
Debug.WriteLine("Start:" + szURL, "Info");
try
{
if (Sink is IServiceProvider)
{
Debug.WriteLine("ServiceProvider");
IServiceProvider Provider = (IServiceProvider)Sink;
object obj_Negotiate = new object();
Provider.QueryService(ref Guids.IID_IHttpNegotiate, ref Guids.IID_IHttpNegotiate, out obj_Negotiate);
IHttpNegotiate Negotiate = (IHttpNegotiate)obj_Negotiate;
string strNewHeaders;
Negotiate.BeginningTransaction(szURL, string.Empty, 0, out strNewHeaders);
Debug.WriteLine(strNewHeaders);
StreamWriter Writer = new StreamWriter(Stream);
int loc = szURL.IndexOf(':');
if (loc >= 0)
Writer.Write(string.Format("<HTML><BODY>{0}</BODY></HTML>", System.Web.HttpUtility.UrlDecode(szURL.Remove(0, loc+1))));
else
Writer.Write(string.Format("<HTML><BODY>{0}</BODY></HTML>", System.Web.HttpUtility.UrlDecode(szURL)));
Writer.Flush();
Stream.Position = 0;
string StrResponseHeaders = string.Format("HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length:{0}\r\n\r\n", Stream.Length);
string strNewResponseHeaders;
Negotiate.OnResponse(200, StrResponseHeaders, strNewHeaders, out strNewResponseHeaders);
Debug.WriteLine(strNewResponseHeaders);
}
Sink.ReportData(BSCF.BSCF_LASTDATANOTIFICATION, (uint)Stream.Length, (uint)Stream.Length);
Sink.ReportResult(0, 200, null);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
I co-founded Standard Beagle Studio, a software development consulting service in Austin Texas with my wife Cindy Brummer. We focus mostly on web projects, but have built some react native mobile apps, and even a windows screen saver or two.
I started my career back when ASP pages were state of the art, and IE3 was considered a web browser. I've worked with Microsoft technologies for most of that time, and have recently branched out into node, wordpress, and react native applications.
I'm a web developer, math and physics enthusiast, father of 2, and all around great guy. I live in Austin TX and love using technology to change people's lives for the better. When I manage scrape together some spare time, I build generative art at curvature of the mind.