From 5e30711bfdb28085234a5ef6da4f4e44305ac3e4 Mon Sep 17 00:00:00 2001 From: Frank Schmirler Date: Thu, 2 Dec 2010 08:53:01 +0100 Subject: Snapshot 2007-03-20 --- server/connectionHTTP.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 server/connectionHTTP.c (limited to 'server/connectionHTTP.c') diff --git a/server/connectionHTTP.c b/server/connectionHTTP.c new file mode 100644 index 0000000..a526da9 --- /dev/null +++ b/server/connectionHTTP.c @@ -0,0 +1,200 @@ +/* + * $Id: connectionHTTP.c,v 1.10 2006/01/26 19:40:18 lordjaxom Exp $ + */ + +#include + +#include "server/connectionHTTP.h" +#include "server/setup.h" + +cConnectionHTTP::cConnectionHTTP(void): + cServerConnection("HTTP"), + m_Status(hsRequest), + m_LiveStreamer(NULL), + m_Channel(NULL), + m_Apid(0), + m_StreamType((eStreamType)StreamdevServerSetup.HTTPStreamType), + m_ListChannel(NULL) +{ + Dprintf("constructor hsRequest\n"); +} + +cConnectionHTTP::~cConnectionHTTP() +{ + delete m_LiveStreamer; +} + +bool cConnectionHTTP::Command(char *Cmd) +{ + Dprintf("command %s\n", Cmd); + switch (m_Status) { + case hsRequest: + Dprintf("Request\n"); + m_Request = Cmd; + m_Status = hsHeaders; + return true; + + case hsHeaders: + if (*Cmd == '\0') { + m_Status = hsBody; + return ProcessRequest(); + } + Dprintf("header\n"); + return true; + } + return false; // ??? shouldn't happen +} + +bool cConnectionHTTP::ProcessRequest(void) +{ + Dprintf("process\n"); + if (m_Request.substr(0, 4) == "GET " && CmdGET(m_Request.substr(4))) { + switch (m_Job) { + case hjListing: + return Respond("HTTP/1.0 200 OK") + && Respond("Content-Type: text/html") + && Respond("") + && Respond("VDR Channel Listing") + && Respond(""); + DeferClose(); + m_Status = hsFinished; + return; + } + + if (m_ListChannel->GroupSep()) + line = (std::string)"
  • --- " + m_ListChannel->Name() + "---
  • "; + else { + int index = 1; + line = (std::string)"
  • GetChannelID().ToString() + "\">" + + m_ListChannel->Name() + " "; + for (int i = 0; m_ListChannel->Apid(i) != 0; ++i, ++index) { + line += "GetChannelID().ToString() + "+" + + (const char*)itoa(index) + "\">(" + + m_ListChannel->Alang(i) + ") "; + } + for (int i = 0; m_ListChannel->Dpid(i) != 0; ++i, ++index) { + line += "GetChannelID().ToString() + "+" + + (const char*)itoa(index) + "\">(" + + m_ListChannel->Dlang(i) + ") "; + } + line += "
  • "; + } + if (!Respond(line.c_str())) + DeferClose(); + m_ListChannel = Channels.Next(m_ListChannel); + break; + + case hjTransfer: + Dprintf("streamer start\n"); + m_LiveStreamer->Start(this); + m_Status = hsFinished; + break; + } +} + +bool cConnectionHTTP::CmdGET(const std::string &Opts) +{ + const char *sp = Opts.c_str(), *ptr = sp, *ep; + const cChannel *chan; + int apid = 0, pos; + + ptr = skipspace(ptr); + while (*ptr == '/') + ++ptr; + + if (strncasecmp(ptr, "PS/", 3) == 0) { + m_StreamType = stPS; + ptr += 3; + } else if (strncasecmp(ptr, "PES/", 4) == 0) { + m_StreamType = stPES; + ptr += 4; + } else if (strncasecmp(ptr, "TS/", 3) == 0) { + m_StreamType = stTS; + ptr += 3; + } else if (strncasecmp(ptr, "ES/", 3) == 0) { + m_StreamType = stES; + ptr += 3; + } else if (strncasecmp(ptr, "Extern/", 3) == 0) { + m_StreamType = stExtern; + ptr += 7; + } + + while (*ptr == '/') + ++ptr; + for (ep = ptr + strlen(ptr); ep >= ptr && !isspace(*ep); --ep) + ; + + std::string filespec = Opts.substr(ptr - sp, ep - ptr); + Dprintf("substr: %s\n", filespec.c_str()); + + Dprintf("before channelfromstring\n"); + if (filespec == "" || filespec.substr(0, 12) == "channels.htm") { + m_ListChannel = Channels.First(); + m_Job = hjListing; + } else if ((chan = ChannelFromString(filespec.c_str(), &apid)) != NULL) { + m_Channel = chan; + m_Apid = apid; + Dprintf("Apid is %d\n", apid); + m_Job = hjTransfer; + } + Dprintf("after channelfromstring\n"); + return true; +} + -- cgit v1.2.3