/* * $Id: connectionHTTP.c,v 1.11 2007/04/16 11:01:02 schmirl 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; default: break; } 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; 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; }