don't use std::map.at(). It's not available in older libstdc++ version

Modified Files:
	CONTRIBUTORS HISTORY remux/extern.c server/connectionHTTP.c
This commit is contained in:
schmirl 2010-07-22 14:18:17 +00:00
parent c7d19619db
commit 0a860a1e3e
4 changed files with 141 additions and 11 deletions

View File

@ -160,3 +160,6 @@ Norman Thiel
vel_tins vel_tins
for reporting that externremux x264 uses value of ABR for VBR for reporting that externremux x264 uses value of ABR for VBR
Matthias Prill
for reporting a compiler error with older libstdc++ versions

View File

@ -1,6 +1,8 @@
VDR Plugin 'streamdev' Revision History VDR Plugin 'streamdev' Revision History
--------------------------------------- ---------------------------------------
- don't use std::map.at(). It's not available in older libstdc++ version
(reported by Matthias Prill)
- fixed extremux x264 using value of ABR for VBR (thanks to vel_tins@vdrportal) - fixed extremux x264 using value of ABR for VBR (thanks to vel_tins@vdrportal)
2010-07-20: Version 0.5.0b 2010-07-20: Version 0.5.0b

View File

@ -1,14 +1,19 @@
#include "remux/extern.h" #include "remux/extern.h"
#include "server/server.h" #include "server/server.h"
#include "server/connection.h"
#include "server/streamer.h" #include "server/streamer.h"
#include <vdr/channels.h>
#include <vdr/tools.h> #include <vdr/tools.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h>
namespace Streamdev { namespace Streamdev {
#define MAXENV 63
class cTSExt: public cThread { class cTSExt: public cThread {
private: private:
cRingBufferLinear *m_ResultBuffer; cRingBufferLinear *m_ResultBuffer;
@ -20,7 +25,7 @@ protected:
virtual void Action(void); virtual void Action(void);
public: public:
cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter); cTSExt(cRingBufferLinear *ResultBuffer, const cServerConnection *Connection, const cChannel *Channel, const int *Apids, const int *Dpids);
virtual ~cTSExt(); virtual ~cTSExt();
void Put(const uchar *Data, int Count); void Put(const uchar *Data, int Count);
@ -29,7 +34,7 @@ public:
} // namespace Streamdev } // namespace Streamdev
using namespace Streamdev; using namespace Streamdev;
cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter): cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, const cServerConnection *Connection, const cChannel *Channel, const int *Apids, const int *Dpids):
m_ResultBuffer(ResultBuffer), m_ResultBuffer(ResultBuffer),
m_Active(false), m_Active(false),
m_Process(-1), m_Process(-1),
@ -62,6 +67,118 @@ cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter):
if (m_Process == 0) { if (m_Process == 0) {
// child process // child process
char *env[MAXENV + 1];
int i = 0;
#define ADDENV(x...) if (asprintf(&env[i++], x) < 0) i--
// add channel ID, name and pids to environment
ADDENV("REMUX_CHANNEL_ID=%s", *Channel->GetChannelID().ToString());
ADDENV("REMUX_CHANNEL_NAME=%s", Channel->Name());
#if APIVERSNUM >= 10701
ADDENV("REMUX_VTYPE=%d", Channel->Vtype());
#endif
if (Channel->Vpid())
ADDENV("REMUX_VPID=%d", Channel->Vpid());
if (Channel->Ppid() != Channel->Vpid())
ADDENV("REMUX_PPID=%d", Channel->Ppid());
if (Channel->Tpid())
ADDENV("REMUX_TPID=%d", Channel->Tpid());
std::string buffer;
if (Apids && *Apids) {
for (const int *pid = Apids; *pid; pid++)
(buffer += (const char *) itoa(*pid)) += (*(pid + 1) ? " " : "");
ADDENV("REMUX_APID=%s", buffer.c_str());
buffer.clear();
for (const int *pid = Apids; *pid; pid++) {
int j;
for (j = 0; Channel->Apid(j) && Channel->Apid(j) != *pid; j++)
;
(buffer += Channel->Alang(j)) += (*(pid + 1) ? " " : "");
}
ADDENV("REMUX_ALANG=%s", buffer.c_str());
}
if (Dpids && *Dpids) {
buffer.clear();
for (const int *pid = Dpids; *pid; pid++)
(buffer += (const char *) itoa(*pid)) += (*(pid + 1) ? " " : "");
ADDENV("REMUX_DPID=%s", buffer.c_str());
buffer.clear();
for (const int *pid = Dpids; *pid; pid++) {
int j;
for (j = 0; Channel->Dpid(j) && Channel->Dpid(j) != *pid; j++)
;
(buffer += Channel->Dlang(j)) += (*(pid + 1) ? " " : "");
}
ADDENV("REMUX_DLANG=%s", buffer.c_str());
}
if (Channel->Spid(0)) {
buffer.clear();
for (const int *pid = Channel->Spids(); *pid; pid++)
(buffer += (const char *) itoa(*pid)) += (*(pid + 1) ? " " : "");
ADDENV("REMUX_SPID=%s", buffer.c_str());
buffer.clear();
for (int j = 0; Channel->Spid(j); j++)
(buffer += Channel->Slang(j)) += (Channel->Spid(j + 1) ? " " : "");
ADDENV("REMUX_SLANG=%s", buffer.c_str());
}
if (Connection) {
// add vars for a CGI like interface
// the following vars are not implemented:
// REMOTE_HOST, REMOTE_IDENT, REMOTE_USER
// CONTENT_TYPE, CONTENT_LENGTH,
// SCRIPT_NAME, PATH_TRANSLATED, GATEWAY_INTERFACE
ADDENV("REMOTE_ADDR=%s", Connection->RemoteIp().c_str());
ADDENV("SERVER_NAME=%s", Connection->LocalIp().c_str());
ADDENV("SERVER_PORT=%d", Connection->LocalPort());
ADDENV("SERVER_PROTOCOL=%s", Connection->Protocol());
ADDENV("SERVER_SOFTWARE=%s", VERSION);
for (tStrStrMap::const_iterator it = Connection->Headers().begin(); it != Connection->Headers().end(); it++) {
if (i >= MAXENV) {
esyslog("streamdev-server: Too many headers for externremux.sh");
break;
}
ADDENV("%s=%s", it->first.c_str(), it->second.c_str());
}
// look for section parameters: /path;param1=value1;param2=value2/
std::string::size_type begin, end;
const static std::string PATH_INFO("PATH_INFO");
tStrStrMap::const_iterator it_pathinfo = Connection->Headers().find(PATH_INFO);
const std::string& path = it_pathinfo == Connection->Headers().end() ? "/" : it_pathinfo->second;
begin = path.find(';', 0);
begin = path.find_first_not_of(';', begin);
end = path.find_first_of(";/", begin);
while (begin != std::string::npos && path[begin] != '/') {
std::string param = path.substr(begin, end - begin);
std::string::size_type e = param.find('=');
if (i >= MAXENV) {
esyslog("streamdev-server: Too many parameters for externremux.sh");
break;
}
else if (e > 0 && e != std::string::npos) {
ADDENV("REMUX_PARAM_%s", param.c_str());
}
else
esyslog("streamdev-server: Invalid externremux.sh parameter %s", param.c_str());
begin = path.find_first_not_of(';', end);
end = path.find_first_of(";/", begin);
}
}
env[i] = NULL;
dup2(inpipe[0], STDIN_FILENO); dup2(inpipe[0], STDIN_FILENO);
close(inpipe[1]); close(inpipe[1]);
dup2(outpipe[1], STDOUT_FILENO); dup2(outpipe[1], STDOUT_FILENO);
@ -71,9 +188,11 @@ cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter):
for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++) for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++)
close(i); //close all dup'ed filedescriptors close(i); //close all dup'ed filedescriptors
std::string cmd = std::string(opt_remux) + " " + Parameter; if (setpgid(0, 0) == -1)
if (execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL) == -1) { esyslog("streamdev-server: externremux setpgid failed: %m");
esyslog("streamdev-server: externremux script '%s' execution failed: %m", cmd.c_str());
if (execle("/bin/sh", "sh", "-c", opt_remux, NULL, env) == -1) {
esyslog("streamdev-server: externremux script '%s' execution failed: %m", opt_remux);
_exit(-1); _exit(-1);
} }
// should never be reached // should never be reached
@ -172,9 +291,9 @@ void cTSExt::Put(const uchar *Data, int Count)
} }
} }
cExternRemux::cExternRemux(int VPid, const int *APids, const int *Dpids, const int *SPids, std::string Parameter): cExternRemux::cExternRemux(const cServerConnection *Connection, const cChannel *Channel, const int *Apids, const int *Dpids):
m_ResultBuffer(new cRingBufferLinear(WRITERBUFSIZE, TS_SIZE * 2)), m_ResultBuffer(new cRingBufferLinear(WRITERBUFSIZE, TS_SIZE * 2)),
m_Remux(new cTSExt(m_ResultBuffer, Parameter)) m_Remux(new cTSExt(m_ResultBuffer, Connection, Channel, Apids, Dpids))
{ {
m_ResultBuffer->SetTimeouts(500, 100); m_ResultBuffer->SetTimeouts(500, 100);
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: connectionHTTP.c,v 1.19 2010/07/20 12:26:29 schmirl Exp $ * $Id: connectionHTTP.c,v 1.20 2010/07/22 14:18:18 schmirl Exp $
*/ */
#include <ctype.h> #include <ctype.h>
@ -140,7 +140,12 @@ bool cConnectionHTTP::ProcessRequest(void)
} }
} }
if (Headers().at(REQUEST_METHOD).compare("GET") == 0 && ProcessURI(Headers().at(PATH_INFO))) { tStrStrMap::const_iterator it_method = Headers().find(REQUEST_METHOD);
tStrStrMap::const_iterator it_pathinfo = Headers().find(PATH_INFO);
if (it_method == Headers().end() || it_pathinfo == Headers().end()) {
// should never happen
esyslog("streamdev-server connectionHTTP: Missing method or pathinfo");
} else if (it_method->second.compare("GET") == 0 && ProcessURI(it_pathinfo->second)) {
if (m_ChannelList) if (m_ChannelList)
return Respond("%s", true, m_ChannelList->HttpHeader().c_str()); return Respond("%s", true, m_ChannelList->HttpHeader().c_str());
else if (m_Channel != NULL) { else if (m_Channel != NULL) {
@ -176,7 +181,7 @@ bool cConnectionHTTP::ProcessRequest(void)
return Respond("HTTP/1.0 404 not found") return Respond("HTTP/1.0 404 not found")
&& Respond(""); && Respond("");
} }
} else if (Headers().at(REQUEST_METHOD).compare("HEAD") == 0 && ProcessURI(Headers().at(PATH_INFO))) { } else if (it_method->second.compare("HEAD") == 0 && ProcessURI(it_pathinfo->second)) {
DeferClose(); DeferClose();
if (m_ChannelList) if (m_ChannelList)
return Respond("%s", true, m_ChannelList->HttpHeader().c_str()); return Respond("%s", true, m_ChannelList->HttpHeader().c_str());
@ -249,7 +254,8 @@ cChannelList* cConnectionHTTP::ChannelListFromString(const std::string& Path, co
const static std::string QUERY_STRING("QUERY_STRING"); const static std::string QUERY_STRING("QUERY_STRING");
const static std::string HOST("HTTP_HOST"); const static std::string HOST("HTTP_HOST");
const std::string query = Headers().at(QUERY_STRING); tStrStrMap::const_iterator it_query = Headers().find(QUERY_STRING);
const std::string& query = it_query == Headers().end() ? "" : it_query->second;
std::string groupTarget; std::string groupTarget;
cChannelIterator *iterator = NULL; cChannelIterator *iterator = NULL;