- transfer

This commit is contained in:
lordjaxom 2005-02-08 17:22:35 +00:00
parent 0132230de0
commit b2b925d1a9
23 changed files with 253 additions and 301 deletions

View File

@ -1,7 +1,7 @@
# #
# Makefile for a Video Disk Recorder plugin # Makefile for a Video Disk Recorder plugin
# #
# $Id: Makefile,v 1.1 2004/12/30 22:43:58 lordjaxom Exp $ # $Id: Makefile,v 1.2 2005/02/08 17:22:35 lordjaxom Exp $
# The official name of this plugin. # The official name of this plugin.
# This name will be used in the '-P...' option of VDR to load the plugin. # This name will be used in the '-P...' option of VDR to load the plugin.
@ -49,7 +49,7 @@ DEFINES += -D_GNU_SOURCE
COMMONOBJS = common.o i18n.o \ COMMONOBJS = common.o i18n.o \
\ \
tools/file.o tools/source.o tools/select.o tools/shared.o tools/socket.o \ tools/file.o tools/source.o tools/select.o tools/shared.o tools/socket.o \
tools/string.o tools/tools.o tools/tools.o
CLIENTOBJS = $(PLUGIN)-client.o \ CLIENTOBJS = $(PLUGIN)-client.o \
\ \

View File

@ -1,5 +1,5 @@
/* /*
* $Id: device.c,v 1.4 2005/02/08 15:21:19 lordjaxom Exp $ * $Id: device.c,v 1.5 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include "client/device.h" #include "client/device.h"
@ -8,7 +8,6 @@
#include "client/filter.h" #include "client/filter.h"
#include "tools/select.h" #include "tools/select.h"
#include "tools/string.h"
#include <vdr/channels.h> #include <vdr/channels.h>
#include <vdr/ringbuffer.h> #include <vdr/ringbuffer.h>

View File

@ -1,5 +1,5 @@
/* /*
* $Id: menu.c,v 1.2 2005/02/08 14:09:27 lordjaxom Exp $ * $Id: menu.c,v 1.3 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include <vdr/menuitems.h> #include <vdr/menuitems.h>
@ -47,8 +47,6 @@ eOSState cStreamdevMenu::ProcessKey(eKeys Key) {
} }
void cStreamdevMenu::SuspendServer(void) { void cStreamdevMenu::SuspendServer(void) {
cTBString buffer;
if (ClientSocket.SuspendServer()) if (ClientSocket.SuspendServer())
INFO(tr("Server is suspended")); INFO(tr("Server is suspended"));
else else
@ -1026,8 +1024,8 @@ eOSState cStreamdevMenuTimers::Summary(void) {
return osContinue; return osContinue;
cRemoteTimer *ti = CurrentTimer(); cRemoteTimer *ti = CurrentTimer();
if (ti && !ti->Summary().IsNull()) if (ti && ti->Summary() != "")
return AddSubMenu(new cMenuText(tr("Summary"), ti->Summary())); return AddSubMenu(new cMenuText(tr("Summary"), ti->Summary().c_str()));
return osContinue; return osContinue;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: remote.c,v 1.2 2005/02/08 13:59:16 lordjaxom Exp $ * $Id: remote.c,v 1.3 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include "client/remote.h" #include "client/remote.h"
@ -34,13 +34,13 @@ cRemoteRecording::cRemoteRecording(const char *Text) {
*(ptr++) = '\0'; *(ptr++) = '\0';
m_StartTime = timestr; m_StartTime = timestr;
idx = -1; idx = -1;
while ((idx = m_StartTime.Find(' ', idx + 1)) != -1) m_StartTime[idx] = '\t'; while ((idx = m_StartTime.find(' ', idx + 1)) != -1) m_StartTime[idx] = '\t';
Dprintf("m_Start: %s\n", (const char*)m_StartTime); Dprintf("m_Start: %s\n", m_StartTime.c_str());
if (*ptr == 0) return; if (*ptr == 0) return;
if (isspace(*ptr)) ++ptr; if (isspace(*ptr)) ++ptr;
if (*ptr == 0) return; if (*ptr == 0) return;
m_Name = ptr; m_Name = ptr;
Dprintf("file: %s\n", (const char*)m_Name); Dprintf("file: %s\n", m_Name.c_str());
m_IsValid = true; m_IsValid = true;
} }
@ -69,21 +69,20 @@ const char *cRemoteRecording::Title(char Delimiter, bool NewIndicator,
if (Level < 0 || Level == HierarchyLevels()) { if (Level < 0 || Level == HierarchyLevels()) {
char *s; char *s;
const char *t; const char *t;
if (Level > 0 && (t = strrchr(m_Name, '~')) != NULL) if (Level > 0 && (t = strrchr(m_Name.c_str(), '~')) != NULL)
t++; t++;
else else
t = (const char*)m_Name; t = m_Name.c_str();
asprintf(&m_TitleBuffer, "%s%c%c%s", (const char*)m_StartTime, New, asprintf(&m_TitleBuffer, "%s%c%c%s", m_StartTime.c_str(), New, Delimiter, t);
Delimiter, t);
// let's not display a trailing '~': // let's not display a trailing '~':
stripspace(m_TitleBuffer); stripspace(m_TitleBuffer);
s = &m_TitleBuffer[strlen(m_TitleBuffer) - 1]; s = &m_TitleBuffer[strlen(m_TitleBuffer) - 1];
if (*s == '~') if (*s == '~')
*s = 0; *s = 0;
} else if (Level < HierarchyLevels()) { } else if (Level < HierarchyLevels()) {
const char *s = m_Name; const char *s = m_Name.c_str();
const char *p = s; const char *p = s;
while (*++s) { while (*++s) {
if (*s == '~') { if (*s == '~') {
@ -104,7 +103,7 @@ const char *cRemoteRecording::Title(char Delimiter, bool NewIndicator,
int cRemoteRecording::HierarchyLevels(void) int cRemoteRecording::HierarchyLevels(void)
{ {
const char *s = m_Name; const char *s = m_Name.c_str();
int level = 0; int level = 0;
while (*++s) { while (*++s) {
if (*s == '~') ++level; if (*s == '~') ++level;
@ -191,7 +190,7 @@ cRemoteTimer::cRemoteTimer(const char *Text) {
strncpy(m_File, tmpbuf, MaxFileName); strncpy(m_File, tmpbuf, MaxFileName);
Dprintf("file: %s\n", m_File); Dprintf("file: %s\n", m_File);
if (*ptr != '\0') m_Summary = ptr; if (*ptr != '\0') m_Summary = ptr;
Dprintf("summary: %s\n", (const char*)m_Summary); Dprintf("summary: %s\n", m_Summary.c_str());
m_IsValid = true; m_IsValid = true;
} }
@ -453,8 +452,8 @@ const char *cRemoteTimer::ToText(void) {
if (m_Buffer != NULL) free(m_Buffer); if (m_Buffer != NULL) free(m_Buffer);
strreplace(m_File, ':', '|'); strreplace(m_File, ':', '|');
if (!m_Summary.IsNull()) if (m_Summary != "")
summary = strreplace(strdup(m_Summary), ':', '|'); summary = strreplace(strdup(m_Summary.c_str()), ':', '|');
asprintf(&m_Buffer, "%d:%s:%s:%04d:%04d:%d:%d:%s:%s", m_Active, asprintf(&m_Buffer, "%d:%s:%s:%04d:%04d:%d:%d:%s:%s", m_Active,
(const char*)Channel()->GetChannelID().ToString(), PrintDay(m_Day, m_FirstDay), (const char*)Channel()->GetChannelID().ToString(), PrintDay(m_Day, m_FirstDay),

View File

@ -1,13 +1,12 @@
/* /*
* $Id: remote.h,v 1.1 2004/12/30 22:44:03 lordjaxom Exp $ * $Id: remote.h,v 1.2 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#ifndef VDR_STREAMDEV_REMOTE_H #ifndef VDR_STREAMDEV_REMOTE_H
#define VDR_STREAMDEV_REMOTE_H #define VDR_STREAMDEV_REMOTE_H
#include <vdr/config.h> #include <vdr/config.h>
#include <string>
#include "tools/string.h"
#if VDRVERSNUM < 10300 #if VDRVERSNUM < 10300
class cEventInfo; class cEventInfo;
@ -18,13 +17,13 @@ class cChannel;
class cRemoteRecording: public cListObject { class cRemoteRecording: public cListObject {
private: private:
bool m_IsValid; bool m_IsValid;
int m_Index; int m_Index;
bool m_IsNew; bool m_IsNew;
char *m_TitleBuffer; char *m_TitleBuffer;
cTBString m_StartTime; std::string m_StartTime;
cTBString m_Name; std::string m_Name;
cTBString m_Summary; std::string m_Summary;
public: public:
cRemoteRecording(const char *Text); cRemoteRecording(const char *Text);
@ -37,10 +36,10 @@ public:
bool IsValid(void) const { return m_IsValid; } bool IsValid(void) const { return m_IsValid; }
int Index(void) const { return m_Index; } int Index(void) const { return m_Index; }
const char *StartTime(void) const { return m_StartTime; } const char *StartTime(void) const { return m_StartTime.c_str(); }
bool IsNew(void) const { return m_IsNew; } bool IsNew(void) const { return m_IsNew; }
const char *Name(void) const { return m_Name; } const char *Name(void) const { return m_Name.c_str(); }
const char *Summary(void) const { return m_Summary; } const char *Summary(void) const { return m_Summary.c_str(); }
const char *Title(char Delimiter, bool NewIndicator, int Level); const char *Title(char Delimiter, bool NewIndicator, int Level);
int HierarchyLevels(void); int HierarchyLevels(void);
}; };
@ -71,7 +70,7 @@ private:
int m_Lifetime; int m_Lifetime;
char m_File[MaxFileName]; char m_File[MaxFileName];
time_t m_FirstDay; time_t m_FirstDay;
cTBString m_Summary; std::string m_Summary;
char *m_Buffer; char *m_Buffer;
const cChannel *m_Channel; const cChannel *m_Channel;
@ -116,7 +115,7 @@ public:
int Lifetime(void) const { return m_Lifetime; } int Lifetime(void) const { return m_Lifetime; }
const char *File(void) const { return m_File; } const char *File(void) const { return m_File; }
time_t FirstDay(void) const { return m_FirstDay; } time_t FirstDay(void) const { return m_FirstDay; }
const cTBString &Summary(void) const { return m_Summary; } const std::string &Summary(void) const { return m_Summary; }
const cChannel *Channel(void) const { return m_Channel; } const cChannel *Channel(void) const { return m_Channel; }
const char *ToText(void); const char *ToText(void);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: socket.c,v 1.3 2005/02/08 15:34:38 lordjaxom Exp $ * $Id: socket.c,v 1.4 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include <tools/select.h> #include <tools/select.h>
@ -39,17 +39,17 @@ cTBSocket *cClientSocket::DataSocket(eSocketId Id) const {
return m_DataSockets[Id]; return m_DataSockets[Id];
} }
bool cClientSocket::Command(const cTBString &Command, uint Expected, bool cClientSocket::Command(const std::string &Command, uint Expected, uint TimeoutMs)
uint TimeoutMs) { {
errno = 0; errno = 0;
cTBString pkt = Command + "\015\012"; std::string pkt = Command + "\015\012";
Dprintf("OUT: |%s|\n", (const char*)Command); Dprintf("OUT: |%s|\n", Command.c_str());
cTimeMs starttime; cTimeMs starttime;
if (!TimedWrite((const char*)pkt, pkt.Length(), TimeoutMs)) { if (!TimedWrite(pkt.c_str(), pkt.size(), TimeoutMs)) {
esyslog("Streamdev: Lost connection to %s:%d: %s", esyslog("Streamdev: Lost connection to %s:%d: %s", RemoteIp().c_str(), RemotePort(),
(const char*)RemoteIp(), RemotePort(), strerror(errno)); strerror(errno));
Close(); Close();
return false; return false;
} }
@ -63,34 +63,28 @@ bool cClientSocket::Command(const cTBString &Command, uint Expected,
return true; return true;
} }
bool cClientSocket::Expect(uint Expected, cTBString *Result, uint TimeoutMs) { bool cClientSocket::Expect(uint Expected, std::string *Result, uint TimeoutMs) {
char *buffer;
char *endptr; char *endptr;
int bufcount; int bufcount;
bool res; bool res;
errno = 0; errno = 0;
buffer = new char[BUFSIZ + 1]; if ((bufcount = ReadUntil(m_Buffer, sizeof(m_Buffer) - 1, "\012", TimeoutMs)) == -1) {
esyslog("Streamdev: Lost connection to %s:%d: %s", RemoteIp().c_str(), RemotePort(),
if ((bufcount = ReadUntil(buffer, BUFSIZ, "\012", TimeoutMs)) strerror(errno));
== -1) {
esyslog("Streamdev: Lost connection to %s:%d: %s",
(const char*)RemoteIp(), RemotePort(), strerror(errno));
Close(); Close();
delete[] buffer;
return false; return false;
} }
if (buffer[bufcount - 1] == '\015') if (m_Buffer[bufcount - 1] == '\015')
--bufcount; --bufcount;
buffer[bufcount] = '\0'; m_Buffer[bufcount] = '\0';
Dprintf("IN: |%s|\n", buffer); Dprintf("IN: |%s|\n", m_Buffer);
if (Result != NULL) if (Result != NULL)
*Result = buffer; *Result = m_Buffer;
res = strtoul(buffer, &endptr, 10) == Expected; res = strtoul(m_Buffer, &endptr, 10) == Expected;
delete[] buffer;
return res; return res;
} }
@ -125,73 +119,73 @@ bool cClientSocket::CheckConnection(void) {
if (!Expect(220)) { if (!Expect(220)) {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Didn't receive greeting from %s:%d", esyslog("ERROR: Streamdev: Didn't receive greeting from %s:%d",
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
Close(); Close();
return false; return false;
} }
if (!Command((cTBString)"CAPS TSPIDS", 220)) { if (!Command("CAPS TSPIDS", 220)) {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't negotiate capabilities on %s:%d", esyslog("ERROR: Streamdev: Couldn't negotiate capabilities on %s:%d",
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
Close(); Close();
return false; return false;
} }
isyslog("Streamdev: Connected to server %s:%d using capabilities TSPIDS", isyslog("Streamdev: Connected to server %s:%d using capabilities TSPIDS",
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
return true; return true;
} }
bool cClientSocket::ProvidesChannel(const cChannel *Channel, int Priority) { bool cClientSocket::ProvidesChannel(const cChannel *Channel, int Priority) {
cTBString buffer;
if (!CheckConnection()) return false; if (!CheckConnection()) return false;
CMD_LOCK; CMD_LOCK;
if (!Command("PROV " + cTBString::Number(Priority) + " " std::string command = (std::string)"PROV " + (const char*)itoa(Priority) + " "
+ Channel->GetChannelID().ToString())) + (const char*)Channel->GetChannelID().ToString();
if (!Command(command))
return false; return false;
std::string buffer;
if (!Expect(220, &buffer)) { if (!Expect(220, &buffer)) {
if (buffer.Left(3) != "560" && errno == 0) if (buffer.substr(0, 3) != "560" && errno == 0)
esyslog("ERROR: Streamdev: Couldn't check if %s:%d provides channel %s", esyslog("ERROR: Streamdev: Couldn't check if %s:%d provides channel %s",
(const char*)RemoteIp(), RemotePort(), Channel->Name()); RemoteIp().c_str(), RemotePort(), Channel->Name());
return false; return false;
} }
return true; return true;
} }
bool cClientSocket::CreateDataConnection(eSocketId Id) { bool cClientSocket::CreateDataConnection(eSocketId Id) {
int idx;
cTBSocket listen(SOCK_STREAM); cTBSocket listen(SOCK_STREAM);
cTBString buffer;
if (!CheckConnection()) return false; if (!CheckConnection()) return false;
if (m_DataSockets[Id] != NULL) if (m_DataSockets[Id] != NULL)
DELETENULL(m_DataSockets[Id]); DELETENULL(m_DataSockets[Id]);
if (!listen.Listen((const char*)LocalIp(), 0, 1)) { if (!listen.Listen(LocalIp(), 0, 1)) {
esyslog("ERROR: Streamdev: Couldn't create data connection: %s", esyslog("ERROR: Streamdev: Couldn't create data connection: %s",
strerror(errno)); strerror(errno));
return false; return false;
} }
buffer.Format("PORT %d %s,%d,%d", Id, (const char*)LocalIp(), std::string command = (std::string)"PORT " + (const char*)itoa(Id) + " "
(listen.LocalPort() >> 8) & 0xff, listen.LocalPort() & 0xff); + LocalIp().c_str() + ","
idx = 5; + (const char*)itoa((listen.LocalPort() >> 8) & 0xff) + ","
while ((idx = buffer.Find('.', idx + 1)) != -1) + (const char*)itoa(listen.LocalPort() & 0xff);
buffer[idx] = ','; size_t idx = 4;
while ((idx = command.find('.', idx + 1)) != (size_t)-1)
command[idx] = ',';
CMD_LOCK; CMD_LOCK;
if (!Command(buffer, 220)) { if (!Command(command, 220)) {
Dprintf("error: %m\n"); Dprintf("error: %m\n");
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't establish data connection to %s:%d", esyslog("ERROR: Streamdev: Couldn't establish data connection to %s:%d",
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
return false; return false;
} }
@ -204,7 +198,7 @@ bool cClientSocket::CreateDataConnection(eSocketId Id) {
m_DataSockets[Id] = new cTBSocket; m_DataSockets[Id] = new cTBSocket;
if (!m_DataSockets[Id]->Accept(listen)) { if (!m_DataSockets[Id]->Accept(listen)) {
esyslog("ERROR: Streamdev: Couldn't establish data connection to %s:%d%s%s", esyslog("ERROR: Streamdev: Couldn't establish data connection to %s:%d%s%s",
(const char*)RemoteIp(), RemotePort(), errno == 0 ? "" : ": ", RemoteIp().c_str(), RemotePort(), errno == 0 ? "" : ": ",
errno == 0 ? "" : strerror(errno)); errno == 0 ? "" : strerror(errno));
DELETENULL(m_DataSockets[Id]); DELETENULL(m_DataSockets[Id]);
return false; return false;
@ -218,10 +212,12 @@ bool cClientSocket::SetChannelDevice(const cChannel *Channel) {
CMD_LOCK; CMD_LOCK;
if (!Command((cTBString)"TUNE " + Channel->GetChannelID().ToString(), 220)) { std::string command = (std::string)"TUNE "
+ (const char*)Channel->GetChannelID().ToString();
if (!Command(command, 220)) {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't tune %s:%d to channel %s", esyslog("ERROR: Streamdev: Couldn't tune %s:%d to channel %s",
(const char*)RemoteIp(), RemotePort(), Channel->Name()); RemoteIp().c_str(), RemotePort(), Channel->Name());
return false; return false;
} }
return true; return true;
@ -232,10 +228,11 @@ bool cClientSocket::SetPid(int Pid, bool On) {
CMD_LOCK; CMD_LOCK;
if (!Command((On ? "ADDP " : "DELP ") + cTBString::Number(Pid), 220)) { std::string command = (std::string)(On ? "ADDP " : "DELP ") + (const char*)itoa(Pid);
if (!Command(command, 220)) {
if (errno == 0) if (errno == 0)
esyslog("Streamdev: Pid %d not available from %s:%d", Pid, esyslog("Streamdev: Pid %d not available from %s:%d", Pid, LocalIp().c_str(),
(const char*)LocalIp(), LocalPort()); LocalPort());
return false; return false;
} }
return true; return true;
@ -243,15 +240,16 @@ bool cClientSocket::SetPid(int Pid, bool On) {
#if VDRVERSNUM >= 10300 #if VDRVERSNUM >= 10300
bool cClientSocket::SetFilter(ushort Pid, uchar Tid, uchar Mask, bool On) { bool cClientSocket::SetFilter(ushort Pid, uchar Tid, uchar Mask, bool On) {
cTBString cmd;
if (!CheckConnection()) return false; if (!CheckConnection()) return false;
CMD_LOCK; CMD_LOCK;
cmd.Format("%s %hu %hhu %hhu", On ? "ADDF" : "DELF", Pid, Tid, Mask);
if (!Command(cmd, 220)) { std::string command = (std::string)(On ? "ADDF " : "DELF ") + (const char*)itoa(Pid)
+ " " + (const char*)itoa(Tid) + " " + (const char*)itoa(Mask);
if (!Command(command, 220)) {
if (errno == 0) if (errno == 0)
esyslog("Streamdev: Filter %hu, %hhu, %hhu not available from %s:%d", esyslog("Streamdev: Filter %hu, %hhu, %hhu not available from %s:%d",
Pid, Tid, Mask, (const char*)LocalIp(), LocalPort()); Pid, Tid, Mask, LocalIp().c_str(), LocalPort());
return false; return false;
} }
return true; return true;
@ -264,7 +262,8 @@ bool cClientSocket::CloseDvr(void) {
CMD_LOCK; CMD_LOCK;
if (m_DataSockets[siLive] != NULL) { if (m_DataSockets[siLive] != NULL) {
if (!Command("ABRT " + cTBString::Number(siLive), 220)) { std::string command = (std::string)"ABRT " + (const char*)itoa(siLive);
if (!Command(command, 220)) {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't cleanly close data connection"); esyslog("ERROR: Streamdev: Couldn't cleanly close data connection");
return false; return false;
@ -276,8 +275,8 @@ bool cClientSocket::CloseDvr(void) {
} }
bool cClientSocket::SynchronizeEPG(void) { bool cClientSocket::SynchronizeEPG(void) {
cTBString buffer; std::string buffer;
bool res; bool result;
FILE *epgfd; FILE *epgfd;
if (!CheckConnection()) return false; if (!CheckConnection()) return false;
@ -295,16 +294,16 @@ bool cClientSocket::SynchronizeEPG(void) {
return false; return false;
} }
while ((res = Expect(215, &buffer))) { while ((result = Expect(215, &buffer))) {
if (buffer[3] == ' ') break; if (buffer[3] == ' ') break;
fputs((const char*)buffer + 4, epgfd); fputs(buffer.c_str() + 4, epgfd);
fputc('\n', epgfd); fputc('\n', epgfd);
} }
if (!res) { if (!result) {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch EPG data from %s:%d", esyslog("ERROR: Streamdev: Couldn't fetch EPG data from %s:%d",
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
fclose(epgfd); fclose(epgfd);
return false; return false;
} }
@ -333,14 +332,13 @@ bool cClientSocket::Quit(void) {
if (!(res = Command("QUIT", 221))) { if (!(res = Command("QUIT", 221))) {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't quit command connection to %s:%d", esyslog("ERROR: Streamdev: Couldn't quit command connection to %s:%d",
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
} }
Close(); Close();
return res; return res;
} }
bool cClientSocket::LoadRecordings(cRemoteRecordings &Recordings) { bool cClientSocket::LoadRecordings(cRemoteRecordings &Recordings) {
cTBString buffer;
bool res; bool res;
if (!CheckConnection()) return false; if (!CheckConnection()) return false;
@ -350,8 +348,9 @@ bool cClientSocket::LoadRecordings(cRemoteRecordings &Recordings) {
if (!Command("LSTR")) if (!Command("LSTR"))
return false; return false;
std::string buffer;
while ((res = Expect(250, &buffer))) { while ((res = Expect(250, &buffer))) {
cRemoteRecording *rec = new cRemoteRecording((const char*)buffer + 4); cRemoteRecording *rec = new cRemoteRecording(buffer.c_str() + 4);
Dprintf("recording valid: %d\n", rec->IsValid()); Dprintf("recording valid: %d\n", rec->IsValid());
if (rec->IsValid()) if (rec->IsValid())
Recordings.Add(rec); Recordings.Add(rec);
@ -360,23 +359,24 @@ bool cClientSocket::LoadRecordings(cRemoteRecordings &Recordings) {
if (buffer[3] == ' ') break; if (buffer[3] == ' ') break;
} }
if (!res && buffer.Left(3) != "550") { if (!res && buffer.substr(0, 3) != "550") {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch recordings from %s:%d", esyslog("ERROR: Streamdev: Couldn't fetch recordings from %s:%d",
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
return false; return false;
} }
for (cRemoteRecording *r = Recordings.First(); r; r = Recordings.Next(r)) { for (cRemoteRecording *r = Recordings.First(); r; r = Recordings.Next(r)) {
if (!Command("LSTR " + cTBString::Number(r->Index()))) std::string command = (std::string)"LSTR " + (const char*)itoa(r->Index());
if (!Command(command))
return false; return false;
if (Expect(250, &buffer)) if (Expect(250, &buffer))
r->ParseInfo((const char*)buffer + 4); r->ParseInfo(buffer.c_str() + 4);
else if (buffer.Left(3) != "550") { else if (buffer.substr(0, 3) != "550") {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch details for recording from " esyslog("ERROR: Streamdev: Couldn't fetch details for recording from %s:%d",
"%s:%d", (const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
return false; return false;
} }
Dprintf("recording complete: %d\n", r->Index()); Dprintf("recording complete: %d\n", r->Index());
@ -388,11 +388,12 @@ bool cClientSocket::StartReplay(const char *Filename) {
if (!CheckConnection()) return false; if (!CheckConnection()) return false;
CMD_LOCK; CMD_LOCK;
if (!Command((cTBString)"PLAY " + Filename, 220)) { std::string command = (std::string)"PLAY " + Filename;
if (!Command(command, 220)) {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't replay \"%s\" from %s:%d", esyslog("ERROR: Streamdev: Couldn't replay \"%s\" from %s:%d",
Filename, (const char*)RemoteIp(), RemotePort()); Filename, RemoteIp().c_str(), RemotePort());
return false; return false;
} }
return true; return true;
@ -404,7 +405,8 @@ bool cClientSocket::AbortReplay(void) {
CMD_LOCK; CMD_LOCK;
if (m_DataSockets[siReplay] != NULL) { if (m_DataSockets[siReplay] != NULL) {
if (!Command("ABRT " + cTBString::Number(siReplay), 220)) { std::string command = (std::string)"ABRT " + (const char*)itoa(siReplay);
if (!Command(command, 220)) {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't cleanly close data connection"); esyslog("ERROR: Streamdev: Couldn't cleanly close data connection");
return false; return false;
@ -417,7 +419,6 @@ bool cClientSocket::AbortReplay(void) {
bool cClientSocket::DeleteRecording(cRemoteRecording *Recording) { bool cClientSocket::DeleteRecording(cRemoteRecording *Recording) {
bool res; bool res;
cTBString buffer;
cRemoteRecording *rec = NULL; cRemoteRecording *rec = NULL;
if (!CheckConnection()) if (!CheckConnection())
@ -428,19 +429,20 @@ bool cClientSocket::DeleteRecording(cRemoteRecording *Recording) {
if (!Command("LSTR")) if (!Command("LSTR"))
return false; return false;
std::string buffer;
while ((res = Expect(250, &buffer))) { while ((res = Expect(250, &buffer))) {
if (rec == NULL) { if (rec == NULL) {
rec = new cRemoteRecording((const char*)buffer + 4); rec = new cRemoteRecording(buffer.c_str() + 4);
if (!rec->IsValid() || rec->Index() != Recording->Index()) if (!rec->IsValid() || rec->Index() != Recording->Index())
DELETENULL(rec); DELETENULL(rec);
} }
if (buffer[3] == ' ') break; if (buffer[3] == ' ') break;
} }
if (!res && buffer.Left(3) != "550") { if (!res && buffer.substr(0, 3) != "550") {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch recordings from %s:%d", esyslog("ERROR: Streamdev: Couldn't fetch recordings from %s:%d",
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
if (rec != NULL) delete rec; if (rec != NULL) delete rec;
return false; return false;
} }
@ -450,7 +452,8 @@ bool cClientSocket::DeleteRecording(cRemoteRecording *Recording) {
return false; return false;
} }
if (!Command("DELR " + cTBString::Number(Recording->Index()), 250)) { std::string command = (std::string)"DELR " + (const char*)itoa(Recording->Index());
if (!Command(command, 250)) {
ERROR(tr("Couldn't delete recording! Try again...")); ERROR(tr("Couldn't delete recording! Try again..."));
return false; return false;
} }
@ -471,9 +474,6 @@ bool cClientSocket::SuspendServer(void) {
} }
bool cClientSocket::LoadTimers(cRemoteTimers &Timers) { bool cClientSocket::LoadTimers(cRemoteTimers &Timers) {
cTBString buffer;
bool res;
if (!CheckConnection()) return false; if (!CheckConnection()) return false;
CMD_LOCK; CMD_LOCK;
@ -481,39 +481,42 @@ bool cClientSocket::LoadTimers(cRemoteTimers &Timers) {
if (!Command("LSTT")) if (!Command("LSTT"))
return false; return false;
bool res;
std::string buffer;
while ((res = Expect(250, &buffer))) { while ((res = Expect(250, &buffer))) {
cRemoteTimer *timer = new cRemoteTimer((const char*)buffer + 4); cRemoteTimer *timer = new cRemoteTimer(buffer.c_str() + 4);
Dprintf("timer valid: %d\n", timer->IsValid()); Dprintf("timer valid: %d\n", timer->IsValid());
if (timer->IsValid()) if (timer->IsValid())
Timers.Add(timer); Timers.Add(timer);
if (buffer[3] == ' ') break; if (buffer[3] == ' ') break;
} }
if (!res && buffer.Left(3) != "550") { if (!res && buffer.substr(0, 3) != "550") {
if (errno == 0) if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch recordings from %s:%d", esyslog("ERROR: Streamdev: Couldn't fetch recordings from %s:%d",
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
return false; return false;
} }
return res; return res;
} }
bool cClientSocket::SaveTimer(cRemoteTimer *Old, cRemoteTimer &New) { bool cClientSocket::SaveTimer(cRemoteTimer *Old, cRemoteTimer &New) {
cTBString buffer;
if (!CheckConnection()) return false; if (!CheckConnection()) return false;
CMD_LOCK; CMD_LOCK;
if (New.Index() == -1) { // New timer if (New.Index() == -1) { // New timer
if (!Command((cTBString)"NEWT " + New.ToText(), 250)) { std::string command = (std::string)"NEWT " + (const char*)New.ToText();
if (!Command(command, 250)) {
ERROR(tr("Couldn't save timer! Try again...")); ERROR(tr("Couldn't save timer! Try again..."));
return false; return false;
} }
} else { // Modified timer } else { // Modified timer
if (!Command("LSTT " + cTBString::Number(New.Index()))) std::string command = (std::string)"LSTT " + (const char*)itoa(New.Index());
if (!Command(command))
return false; return false;
std::string buffer;
if (!Expect(250, &buffer)) { if (!Expect(250, &buffer)) {
if (errno == 0) if (errno == 0)
ERROR(tr("Timers not in sync! Try again...")); ERROR(tr("Timers not in sync! Try again..."));
@ -522,7 +525,7 @@ bool cClientSocket::SaveTimer(cRemoteTimer *Old, cRemoteTimer &New) {
return false; return false;
} }
cRemoteTimer oldstate((const char*)buffer + 4); cRemoteTimer oldstate(buffer.c_str() + 4);
if (oldstate != *Old) { if (oldstate != *Old) {
/*Dprintf("old timer: %d,%d,%d,%d,%d,%d,%s,%d,%s,%d\n", oldstate.m_Index, /*Dprintf("old timer: %d,%d,%d,%d,%d,%d,%s,%d,%s,%d\n", oldstate.m_Index,
oldstate.m_Active,oldstate.m_Day,oldstate.m_Start,oldstate.m_StartTime,oldstate.m_Priority,oldstate.m_File,oldstate.m_FirstDay,(const char*)oldstate.m_Summary,oldstate.m_Channel->Number()); oldstate.m_Active,oldstate.m_Day,oldstate.m_Start,oldstate.m_StartTime,oldstate.m_Priority,oldstate.m_File,oldstate.m_FirstDay,(const char*)oldstate.m_Summary,oldstate.m_Channel->Number());
@ -532,8 +535,10 @@ bool cClientSocket::SaveTimer(cRemoteTimer *Old, cRemoteTimer &New) {
return false; return false;
} }
if (!Command("MODT " + cTBString::Number(New.Index()) + " "
+ New.ToText(), 250)) { command = (std::string)"MODT " + (const char*)itoa(New.Index()) + " "
+ (const char*)New.ToText();
if (!Command(command, 250)) {
ERROR(tr("Couldn't save timer! Try again...")); ERROR(tr("Couldn't save timer! Try again..."));
return false; return false;
} }
@ -542,16 +547,15 @@ bool cClientSocket::SaveTimer(cRemoteTimer *Old, cRemoteTimer &New) {
} }
bool cClientSocket::DeleteTimer(cRemoteTimer *Timer) { bool cClientSocket::DeleteTimer(cRemoteTimer *Timer) {
cTBString buffer; if (!CheckConnection()) return false;
if (!CheckConnection())
return false;
CMD_LOCK; CMD_LOCK;
if (!Command("LSTT " + cTBString::Number(Timer->Index()))) std::string command = (std::string)"LSTT " + (const char*)itoa(Timer->Index());
if (!Command(command))
return false; return false;
std::string buffer;
if (!Expect(250, &buffer)) { if (!Expect(250, &buffer)) {
if (errno == 0) if (errno == 0)
ERROR(tr("Timers not in sync! Try again...")); ERROR(tr("Timers not in sync! Try again..."));
@ -560,14 +564,14 @@ bool cClientSocket::DeleteTimer(cRemoteTimer *Timer) {
return false; return false;
} }
cRemoteTimer oldstate((const char*)buffer + 4); cRemoteTimer oldstate(buffer.c_str() + 4);
if (oldstate != *Timer) { if (oldstate != *Timer) {
ERROR(tr("Timers not in sync! Try again...")); ERROR(tr("Timers not in sync! Try again..."));
return false; return false;
} }
if (!Command("DELT " + cTBString::Number(Timer->Index()), 250)) { command = (std::string)"DELT " + (const char*)itoa(Timer->Index());
if (!Command(command, 250)) {
ERROR(tr("Couldn't delete timer! Try again...")); ERROR(tr("Couldn't delete timer! Try again..."));
return false; return false;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: socket.h,v 1.2 2005/02/08 15:34:38 lordjaxom Exp $ * $Id: socket.h,v 1.3 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#ifndef VDR_STREAMDEV_CLIENT_CONNECTION_H #ifndef VDR_STREAMDEV_CLIENT_CONNECTION_H
@ -9,6 +9,8 @@
#include "common.h" #include "common.h"
#include <string>
#define CMD_LOCK cMutexLock CmdLock((cMutex*)&m_Mutex) #define CMD_LOCK cMutexLock CmdLock((cMutex*)&m_Mutex)
class cRemoteRecordings; class cRemoteRecordings;
@ -21,20 +23,20 @@ class cClientSocket: public cTBSocket {
private: private:
cTBSocket *m_DataSockets[si_Count]; cTBSocket *m_DataSockets[si_Count];
cMutex m_Mutex; cMutex m_Mutex;
char m_Buffer[BUFSIZ + 1]; // various uses
protected: protected:
/* Send Command, and return true if the command results in Expected. /* Send Command, and return true if the command results in Expected.
Returns false on failure, setting errno appropriately if it has been Returns false on failure, setting errno appropriately if it has been
a system failure. If Expected is zero, returns immediately after a system failure. If Expected is zero, returns immediately after
sending the command. */ sending the command. */
bool Command(const cTBString &Command, uint Expected = 0, bool Command(const std::string &Command, uint Expected = 0, uint TimeoutMs = 1500);
uint TimeoutMs = 1500);
/* Fetch results from an ongoing Command called with Expected == 0. Returns /* Fetch results from an ongoing Command called with Expected == 0. Returns
true if the response has the code Expected, returning an internal buffer true if the response has the code Expected, returning an internal buffer
in the array pointer pointed to by Result. Returns false on failure, in the array pointer pointed to by Result. Returns false on failure,
setting errno appropriately if it has been a system failure. */ setting errno appropriately if it has been a system failure. */
bool Expect(uint Expected, cTBString *Result = NULL, uint TimeoutMs = 1500); bool Expect(uint Expected, std::string *Result = NULL, uint TimeoutMs = 1500);
public: public:
cClientSocket(void); cClientSocket(void);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: component.c,v 1.1 2004/12/30 22:44:18 lordjaxom Exp $ * $Id: component.c,v 1.2 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include "server/component.h" #include "server/component.h"
@ -38,7 +38,7 @@ cServerConnection *cServerComponent::CanAct(const cTBSelect &Select) {
cServerConnection *client = NewConnection(); cServerConnection *client = NewConnection();
if (client->Accept(m_Listen)) { if (client->Accept(m_Listen)) {
isyslog("Streamdev: Accepted new client (%s) %s:%d", m_Protocol, isyslog("Streamdev: Accepted new client (%s) %s:%d", m_Protocol,
(const char*)client->RemoteIp(), client->RemotePort()); client->RemoteIp().c_str(), client->RemotePort());
return client; return client;
} else { } else {
esyslog("Streamdev: Couldn't accept (%s): %s", m_Protocol, esyslog("Streamdev: Couldn't accept (%s): %s", m_Protocol,

View File

@ -1,5 +1,5 @@
/* /*
* $Id: connection.c,v 1.1 2004/12/30 22:44:19 lordjaxom Exp $ * $Id: connection.c,v 1.2 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include "server/connection.h" #include "server/connection.h"
@ -27,13 +27,13 @@ bool cServerConnection::CanAct(const cTBSelect &Select) {
int b; int b;
if ((b = Read(m_RdBuf + m_RdBytes, sizeof(m_RdBuf) - m_RdBytes - 1)) < 0) { if ((b = Read(m_RdBuf + m_RdBytes, sizeof(m_RdBuf) - m_RdBytes - 1)) < 0) {
esyslog("Streamdev: Read from client (%s) %s:%d failed: %s", m_Protocol, esyslog("Streamdev: Read from client (%s) %s:%d failed: %s", m_Protocol,
(const char*)RemoteIp(), RemotePort(), strerror(errno)); RemoteIp().c_str(), RemotePort(), strerror(errno));
return false; return false;
} }
if (b == 0) { if (b == 0) {
isyslog("Streamdev: Client (%s) %s:%d closed connection", m_Protocol, isyslog("Streamdev: Client (%s) %s:%d closed connection", m_Protocol,
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
return false; return false;
} }
@ -46,7 +46,7 @@ bool cServerConnection::CanAct(const cTBSelect &Select) {
int b; int b;
if ((b = Write(m_WrBuf + m_WrOffs, m_WrBytes - m_WrOffs)) < 0) { if ((b = Write(m_WrBuf + m_WrOffs, m_WrBytes - m_WrOffs)) < 0) {
esyslog("Streamdev: Write to client (%s) %s:%d failed: %s", m_Protocol, esyslog("Streamdev: Write to client (%s) %s:%d failed: %s", m_Protocol,
(const char*)RemoteIp(), RemotePort(), strerror(errno)); RemoteIp().c_str(), RemotePort(), strerror(errno));
return false; return false;
} }
@ -85,18 +85,18 @@ bool cServerConnection::ParseBuffer(void) {
return true; return true;
} }
bool cServerConnection::Respond(const char *Message) { bool cServerConnection::Respond(const std::string &Message) {
uint len = strlen(Message); if (m_WrBytes + Message.size() + 2 > sizeof(m_WrBuf)) {
if (m_WrBytes + len + 2 > sizeof(m_WrBuf)) {
esyslog("Streamdev: Output buffer overflow (%s) for %s:%d", m_Protocol, esyslog("Streamdev: Output buffer overflow (%s) for %s:%d", m_Protocol,
(const char*)RemoteIp(), RemotePort()); RemoteIp().c_str(), RemotePort());
return false; return false;
} }
Dprintf("OUT: |%s|\n", Message); Dprintf("OUT: |%s|\n", Message.c_str());
memcpy(m_WrBuf + m_WrBytes, Message, len); memcpy(m_WrBuf + m_WrBytes, Message.c_str(), Message.size());
m_WrBuf[m_WrBytes + len] = '\015';
m_WrBuf[m_WrBytes + len + 1] = '\012'; m_WrBytes += Message.size();
m_WrBytes += len + 2; m_WrBuf[m_WrBytes++] = '\015';
m_WrBuf[m_WrBytes++] = '\012';
return true; return true;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: connection.h,v 1.1 2004/12/30 22:44:19 lordjaxom Exp $ * $Id: connection.h,v 1.2 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#ifndef VDR_STREAMDEV_SERVER_CONNECTION_H #ifndef VDR_STREAMDEV_SERVER_CONNECTION_H
@ -58,7 +58,7 @@ public:
/* Will put Message into the response queue, which will be sent in the next /* Will put Message into the response queue, which will be sent in the next
server cycle. Note that Message will be line-terminated by Respond */ server cycle. Note that Message will be line-terminated by Respond */
bool Respond(const char *Message); bool Respond(const std::string &Message);
/* Will make the socket close after sending all queued output data */ /* Will make the socket close after sending all queued output data */
void DeferClose(void) { m_DeferClose = true; } void DeferClose(void) { m_DeferClose = true; }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: connectionHTTP.c,v 1.3 2005/02/08 15:34:38 lordjaxom Exp $ * $Id: connectionHTTP.c,v 1.4 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include "server/connectionHTTP.h" #include "server/connectionHTTP.h"
@ -63,7 +63,7 @@ bool cConnectionHTTP::Command(char *Cmd) {
|| m_Channel->Vpid() == 1 || m_Channel->Vpid() == 0x1FFF)) { || m_Channel->Vpid() == 1 || m_Channel->Vpid() == 0x1FFF)) {
return Respond("HTTP/1.0 200 OK") return Respond("HTTP/1.0 200 OK")
&& Respond("Content-Type: audio/mpeg") && Respond("Content-Type: audio/mpeg")
&& Respond((cTBString)"icy-name: " + m_Channel->Name()) && Respond((std::string)"icy-name: " + m_Channel->Name())
&& Respond(""); && Respond("");
} else { } else {
return Respond("HTTP/1.0 200 OK") return Respond("HTTP/1.0 200 OK")
@ -86,20 +86,20 @@ bool cConnectionHTTP::Command(char *Cmd) {
void cConnectionHTTP::Flushed(void) { void cConnectionHTTP::Flushed(void) {
if (m_Status == hsListing) { if (m_Status == hsListing) {
cTBString line;
if (m_ListChannel == NULL) { if (m_ListChannel == NULL) {
Respond("</ul></body></html>"); Respond("</ul></body></html>");
DeferClose(); DeferClose();
return; return;
} }
std::string line;
if (m_ListChannel->GroupSep()) if (m_ListChannel->GroupSep())
line.Format("<li>--- %s ---</li>", m_ListChannel->Name()); line = (std::string)"<li>--- " + m_ListChannel->Name() + "---</li>";
else else
line.Format("<li><a href=\"http://%s:%d/%s\">%s</a></li>", line = (std::string)"<li><a href=\"http://" + LocalIp() + ":"
(const char*)LocalIp(), StreamdevServerSetup.HTTPServerPort, + (const char*)itoa(StreamdevServerSetup.HTTPServerPort) + "/"
(const char*)m_ListChannel->GetChannelID().ToString(), m_ListChannel->Name()); + (const char*)m_ListChannel->GetChannelID().ToString() + "\">"
+ m_ListChannel->Name() + "</a></li>";
if (!Respond(line)) if (!Respond(line))
DeferClose(); DeferClose();
m_ListChannel = Channels.Next(m_ListChannel); m_ListChannel = Channels.Next(m_ListChannel);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: connectionVTP.c,v 1.3 2005/02/08 15:34:38 lordjaxom Exp $ * $Id: connectionVTP.c,v 1.4 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include "server/connectionVTP.h" #include "server/connectionVTP.h"
@ -82,13 +82,13 @@ bool cConnectionVTP::Command(char *Cmd) {
else if (strcasecmp(Cmd, "NEWT") == 0) return CmdNEWT(ep); else if (strcasecmp(Cmd, "NEWT") == 0) return CmdNEWT(ep);
else if (strcasecmp(Cmd, "DELT") == 0) return CmdDELT(ep); else if (strcasecmp(Cmd, "DELT") == 0) return CmdDELT(ep);
else else
return Respond(500, (cTBString)"Unknown Command '" + Cmd + "'"); return Respond(500, (std::string)"Unknown Command '" + Cmd + "'");
} }
bool cConnectionVTP::CmdCAPS(char *Opts) { bool cConnectionVTP::CmdCAPS(char *Opts) {
if (strcasecmp(Opts, "TSPIDS") == 0) if (strcasecmp(Opts, "TSPIDS") == 0)
return Respond(220, (cTBString)"Capability \"" + Opts + "\" accepted"); return Respond(220, (std::string)"Capability \"" + Opts + "\" accepted");
return Respond(561, (cTBString)"Capability \"" + Opts + "\" not known"); return Respond(561, (std::string)"Capability \"" + Opts + "\" not known");
} }
bool cConnectionVTP::CmdPROV(char *Opts) { bool cConnectionVTP::CmdPROV(char *Opts) {
@ -102,7 +102,7 @@ bool cConnectionVTP::CmdPROV(char *Opts) {
Opts = skipspace(ep); Opts = skipspace(ep);
if ((chan = ChannelFromString(Opts)) == NULL) if ((chan = ChannelFromString(Opts)) == NULL)
return Respond(550, (cTBString)"Undefined channel \"" + Opts + "\""); return Respond(550, (std::string)"Undefined channel \"" + Opts + "\"");
return GetDevice(chan, prio) != NULL return GetDevice(chan, prio) != NULL
? Respond(220, "Channel available") ? Respond(220, "Channel available")
@ -120,7 +120,7 @@ bool cConnectionVTP::CmdPORT(char *Opts) {
return Respond(500, "Use: PORT Id Destination"); return Respond(500, "Use: PORT Id Destination");
if (id >= si_Count) if (id >= si_Count)
return Respond(501, "Wrong connection id " + cTBString::Number(id)); return Respond(501, (std::string)"Wrong connection id " + (const char*)itoa(id));
Opts = skipspace(ep); Opts = skipspace(ep);
n = 0; n = 0;
@ -166,7 +166,7 @@ bool cConnectionVTP::CmdTUNE(char *Opts) {
cDevice *dev; cDevice *dev;
if ((chan = ChannelFromString(Opts)) == NULL) if ((chan = ChannelFromString(Opts)) == NULL)
return Respond(550, (cTBString)"Undefined channel \"" + Opts + "\""); return Respond(550, (std::string)"Undefined channel \"" + Opts + "\"");
if ((dev = GetDevice(chan, 0)) == NULL) if ((dev = GetDevice(chan, 0)) == NULL)
return Respond(560, "Channel not available"); return Respond(560, "Channel not available");
@ -191,8 +191,8 @@ bool cConnectionVTP::CmdADDP(char *Opts) {
return Respond(500, "Use: ADDP Pid"); return Respond(500, "Use: ADDP Pid");
return m_LiveStreamer && m_LiveStreamer->SetPid(pid, true) return m_LiveStreamer && m_LiveStreamer->SetPid(pid, true)
? Respond(220, "Pid " + cTBString::Number(pid) + " available") ? Respond(220, (std::string)"Pid " + (const char*)itoa(pid) + " available")
: Respond(560, "Pid " + cTBString::Number(pid) + " not available"); : Respond(560, (std::string)"Pid " + (const char*)itoa(pid) + " not available");
} }
bool cConnectionVTP::CmdDELP(char *Opts) { bool cConnectionVTP::CmdDELP(char *Opts) {
@ -204,8 +204,8 @@ bool cConnectionVTP::CmdDELP(char *Opts) {
return Respond(500, "Use: DELP Pid"); return Respond(500, "Use: DELP Pid");
return m_LiveStreamer && m_LiveStreamer->SetPid(pid, false) return m_LiveStreamer && m_LiveStreamer->SetPid(pid, false)
? Respond(220, "Pid " + cTBString::Number(pid) + " stopped") ? Respond(220, (std::string)"Pid " + (const char*)itoa(pid) + " stopped")
: Respond(560, "Pid " + cTBString::Number(pid) + " not transferring"); : Respond(560, (std::string)"Pid " + (const char*)itoa(pid) + " not transferring");
} }
bool cConnectionVTP::CmdADDF(char *Opts) { bool cConnectionVTP::CmdADDF(char *Opts) {
@ -229,8 +229,8 @@ bool cConnectionVTP::CmdADDF(char *Opts) {
return Respond(500, "Use: ADDF Pid Tid Mask"); return Respond(500, "Use: ADDF Pid Tid Mask");
return m_LiveStreamer->SetFilter(pid, tid, mask, true) return m_LiveStreamer->SetFilter(pid, tid, mask, true)
? Respond(220, "Filter " + cTBString::Number(pid) + " transferring") ? Respond(220, (std::string)"Filter " + (const char*)itoa(pid) + " transferring")
: Respond(560, "Filter " + cTBString::Number(pid) + " not available"); : Respond(560, (std::string)"Filter " + (const char*)itoa(pid) + " not available");
#else #else
return Respond(500, "ADDF known but unimplemented with VDR < 1.3.0"); return Respond(500, "ADDF known but unimplemented with VDR < 1.3.0");
#endif #endif
@ -257,8 +257,8 @@ bool cConnectionVTP::CmdDELF(char *Opts) {
return Respond(500, "Use: DELF Pid Tid Mask"); return Respond(500, "Use: DELF Pid Tid Mask");
return m_LiveStreamer->SetFilter(pid, tid, mask, false) return m_LiveStreamer->SetFilter(pid, tid, mask, false)
? Respond(220, "Filter " + cTBString::Number(pid) + " stopped") ? Respond(220, (std::string)"Filter " + (const char*)itoa(pid) + " stopped")
: Respond(560, "Filter " + cTBString::Number(pid) + " not transferring"); : Respond(560, (std::string)"Filter " + (const char*)itoa(pid) + " not transferring");
#else #else
return Respond(500, "DELF known but unimplemented with VDR < 1.3.0"); return Respond(500, "DELF known but unimplemented with VDR < 1.3.0");
#endif #endif
@ -530,12 +530,12 @@ bool cConnectionVTP::CmdDELT(char *Option) {
EXIT_WRAPPER(); EXIT_WRAPPER();
} }
bool cConnectionVTP::Respond(int Code, const char *Message) { bool cConnectionVTP::Respond(int Code, const std::string &Message) {
cTBString pkt; char *buffer;
if (Code < 0) bool result;
pkt.Format("%03d-%s", -Code, Message); asprintf(&buffer, "%03d%c%s", Code < 0 ? -Code : Code, Code < 0 ? '-' : ' ', Message.c_str());
else result = cServerConnection::Respond(buffer);
pkt.Format("%03d %s", Code, Message); free(buffer);
return cServerConnection::Respond((const char*)pkt); return result;
} }

View File

@ -48,7 +48,7 @@ public:
bool CmdNEWT(char *Opts); bool CmdNEWT(char *Opts);
bool CmdDELT(char *Opts); bool CmdDELT(char *Opts);
bool Respond(int Code, const char *Message); bool Respond(int Code, const std::string &Message);
}; };
#endif // VDR_STREAMDEV_SERVERS_CONNECTIONVTP_H #endif // VDR_STREAMDEV_SERVERS_CONNECTIONVTP_H

View File

@ -155,8 +155,7 @@ bool cStreamdevLiveStreamer::SetFilter(u_short Pid, u_char Tid, u_char Mask,
#endif #endif
} }
uchar *cStreamdevLiveStreamer::Process(const uchar *Data, int &Count, uchar *cStreamdevLiveStreamer::Process(const uchar *Data, int &Count, int &Result) {
int &Result) {
uchar *remuxed = m_Remux != NULL ? m_Remux->Process(Data, Count, Result) uchar *remuxed = m_Remux != NULL ? m_Remux->Process(Data, Count, Result)
: cStreamdevStreamer::Process(Data, Count, Result); : cStreamdevStreamer::Process(Data, Count, Result);
if (remuxed) { if (remuxed) {
@ -186,18 +185,18 @@ uchar *cStreamdevLiveStreamer::Process(const uchar *Data, int &Count,
return NULL; return NULL;
} }
cTBString cStreamdevLiveStreamer::Report(void) { std::string cStreamdevLiveStreamer::Report(void) {
cTBString result; std::string result;
if (m_Device != NULL) if (m_Device != NULL)
result += "+- Device is " + cTBString::Number(m_Device->CardIndex()) + "\n"; result += (std::string)"+- Device is " + (const char*)itoa(m_Device->CardIndex()) + "\n";
if (m_Receiver != NULL) if (m_Receiver != NULL)
result += "+- Receiver is allocated\n"; result += "+- Receiver is allocated\n";
result += "+- Pids are "; result += "+- Pids are ";
for (int i = 0; i < MAXRECEIVEPIDS; ++i) for (int i = 0; i < MAXRECEIVEPIDS; ++i)
if (m_Pids[i] != 0) if (m_Pids[i] != 0)
result += cTBString::Number(m_Pids[i]) + ", "; result += (std::string)(const char*)itoa(m_Pids[i]) + ", ";
result += "\n"; result += "\n";
return result; return result;
} }

View File

@ -59,7 +59,7 @@ public:
virtual void Start(cTBSocket *Socket); virtual void Start(cTBSocket *Socket);
// Statistical purposes: // Statistical purposes:
virtual cTBString Report(void); virtual std::string Report(void);
}; };
#endif // VDR_STREAMDEV_LIVESTREAMER_H #endif // VDR_STREAMDEV_LIVESTREAMER_H

View File

@ -1,5 +1,5 @@
/* /*
* $Id: server.c,v 1.1 2004/12/30 22:44:20 lordjaxom Exp $ * $Id: server.c,v 1.2 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include "server/server.h" #include "server/server.h"
@ -106,11 +106,11 @@ void cStreamdevServer::Action(void) {
if (m_Clients.Count() > StreamdevServerSetup.MaxClients) { if (m_Clients.Count() > StreamdevServerSetup.MaxClients) {
esyslog("Streamdev: Too many clients, rejecting %s:%d", esyslog("Streamdev: Too many clients, rejecting %s:%d",
(const char*)client->RemoteIp(), client->RemotePort()); client->RemoteIp().c_str(), client->RemotePort());
client->Reject(); client->Reject();
} else if (!StreamdevHosts.Acceptable(client->RemoteIpAddr())) { } else if (!StreamdevHosts.Acceptable(client->RemoteIpAddr())) {
esyslog("Streamdev: Client from %s:%d not allowed to connect", esyslog("Streamdev: Client from %s:%d not allowed to connect",
(const char*)client->RemoteIp(), client->RemotePort()); client->RemoteIp().c_str(), client->RemotePort());
client->Reject(); client->Reject();
} else } else
client->Welcome(); client->Welcome();
@ -122,7 +122,7 @@ void cStreamdevServer::Action(void) {
cServerConnection *next = m_Clients.Next(s); cServerConnection *next = m_Clients.Next(s);
if (!s->CanAct(select)) { if (!s->CanAct(select)) {
isyslog("Streamdev: Closing connection to %s:%d", isyslog("Streamdev: Closing connection to %s:%d",
(const char*)s->RemoteIp(), s->RemotePort()); s->RemoteIp().c_str(), s->RemotePort());
s->Close(); s->Close();
m_Clients.Del(s); m_Clients.Del(s);
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: streamer.c,v 1.2 2005/02/08 13:59:16 lordjaxom Exp $ * $Id: streamer.c,v 1.3 2005/02/08 17:22:35 lordjaxom Exp $
*/ */
#include <vdr/ringbuffer.h> #include <vdr/ringbuffer.h>
@ -16,10 +16,8 @@
#define VIDEOBUFSIZE MEGABYTE(4) #define VIDEOBUFSIZE MEGABYTE(4)
#define MAXBLOCKSIZE TS_SIZE*10 #define MAXBLOCKSIZE TS_SIZE*10
cStreamdevStreamer::cStreamdevStreamer(const char *Name) cStreamdevStreamer::cStreamdevStreamer(const char *Name):
#if VDRVERSNUM >= 10300 cThread(((std::string)"Streamdev: " + Name).c_str())
:cThread("Streamdev: " + (cTBString)Name)
#endif
{ {
m_Active = false; m_Active = false;
m_Receivers = 0; m_Receivers = 0;

View File

@ -1,5 +1,6 @@
#include "tools/file.h" #include "tools/file.h"
#include <vdr/tools.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -13,12 +14,12 @@ cTBFile::~cTBFile() {
Close(); Close();
} }
bool cTBFile::Open(const cTBString &Filename, int Mode, mode_t Attribs) { bool cTBFile::Open(const std::string &Filename, int Mode, mode_t Attribs) {
int filed; int filed;
if (IsOpen()) Close(); if (IsOpen()) Close();
if ((filed = ::open(Filename, Mode, Attribs)) == -1) if ((filed = ::open(Filename.c_str(), Mode, Attribs)) == -1)
return false; return false;
if (!cTBSource::Open(filed)) if (!cTBSource::Open(filed))
@ -35,7 +36,7 @@ bool cTBFile::Open(uint Fileno) {
if (!cTBSource::Open(Fileno)) if (!cTBSource::Open(Fileno))
return false; return false;
m_Filename.Format("<&%d>", Fileno); m_Filename = (std::string)"<&" + (const char*)itoa(Fileno) + ">";
m_Anonymous = true; m_Anonymous = true;
return true; return true;
} }
@ -52,12 +53,12 @@ bool cTBFile::Close(void) {
if (!cTBSource::Close()) if (!cTBSource::Close())
ret = false; ret = false;
m_Filename.Clear(); m_Filename = "";
return ret; return ret;
} }
bool cTBFile::Unlink(void) const { bool cTBFile::Unlink(void) const {
if (m_Filename.IsNull()) if (m_Filename == "")
ERRNUL(ENOENT); ERRNUL(ENOENT);
if (!IsOpen()) if (!IsOpen())
@ -69,8 +70,8 @@ bool cTBFile::Unlink(void) const {
return cTBFile::Unlink(m_Filename); return cTBFile::Unlink(m_Filename);
} }
bool cTBFile::Unlink(const cTBString &Filename) { bool cTBFile::Unlink(const std::string &Filename) {
return (::unlink(Filename) != -1); return (::unlink(Filename.c_str()) != -1);
} }
ssize_t cTBFile::Size(void) const { ssize_t cTBFile::Size(void) const {
@ -85,10 +86,10 @@ ssize_t cTBFile::Size(void) const {
return buf.st_size; return buf.st_size;
} }
ssize_t cTBFile::Size(const cTBString &Filename) { ssize_t cTBFile::Size(const std::string &Filename) {
struct stat buf; struct stat buf;
if (stat(Filename, &buf) == -1) if (stat(Filename.c_str(), &buf) == -1)
return -1; return -1;
return buf.st_size; return buf.st_size;

View File

@ -3,12 +3,12 @@
#include "tools/tools.h" #include "tools/tools.h"
#include "tools/source.h" #include "tools/source.h"
#include "tools/string.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <string>
/* cTBFile provides a cTBSource-derived interface for input and output on UNIX /* cTBFile provides a cTBSource-derived interface for input and output on UNIX
files. */ files. */
@ -16,7 +16,7 @@
class cTBFile: public cTBSource { class cTBFile: public cTBSource {
private: private:
bool m_Anonymous; bool m_Anonymous;
cTBString m_Filename; std::string m_Filename;
/* Unhide and forbid baseclass method */ /* Unhide and forbid baseclass method */
virtual bool Open(int Fd, bool IsUnixFd = false) { return false; } virtual bool Open(int Fd, bool IsUnixFd = false) { return false; }
@ -51,7 +51,7 @@ public:
Mode. If the file is created, it receives the attributes given by Mode. If the file is created, it receives the attributes given by
Attribs, defaulting to rw-------. Returns true on success and false on Attribs, defaulting to rw-------. Returns true on success and false on
error, setting errno appropriately. */ error, setting errno appropriately. */
virtual bool Open(const cTBString &Filename, int Mode, virtual bool Open(const std::string &Filename, int Mode,
mode_t Attribs = S_IRUSR + S_IWUSR); mode_t Attribs = S_IRUSR + S_IWUSR);
/* Open() associates this file object with Fileno. Fileno must refer to a /* Open() associates this file object with Fileno. Fileno must refer to a
@ -74,7 +74,7 @@ public:
/* Unlink() unlinks (deletes) the file referred to by Filename from the /* Unlink() unlinks (deletes) the file referred to by Filename from the
underlying filesystem. Returns true on success and false otherwise, underlying filesystem. Returns true on success and false otherwise,
setting errno appropriately. */ setting errno appropriately. */
static bool Unlink(const cTBString &Filename); static bool Unlink(const std::string &Filename);
/* Size() returns the current size of the associated file. Returns the /* Size() returns the current size of the associated file. Returns the
exact size of the file in bytes. Returns -1 on error, setting errno to exact size of the file in bytes. Returns -1 on error, setting errno to
@ -85,7 +85,7 @@ public:
Symbolic links are followed (the size of the link-target is returned). Symbolic links are followed (the size of the link-target is returned).
Returns the exact size of the file in bytes. Returns -1 on error, Returns the exact size of the file in bytes. Returns -1 on error,
setting errno to an appropriate value. */ setting errno to an appropriate value. */
static ssize_t Size(const cTBString &Filename); static ssize_t Size(const std::string &Filename);
}; };
inline ssize_t cTBFile::SysRead(void *Buffer, size_t Length) const { inline ssize_t cTBFile::SysRead(void *Buffer, size_t Length) const {

View File

@ -16,7 +16,7 @@ cTBSocket::~cTBSocket() {
if (IsOpen()) Close(); if (IsOpen()) Close();
} }
bool cTBSocket::Connect(const cTBString &Host, unsigned int Port) { bool cTBSocket::Connect(const std::string &Host, unsigned int Port) {
socklen_t len; socklen_t len;
int socket; int socket;
@ -34,7 +34,7 @@ bool cTBSocket::Connect(const cTBString &Host, unsigned int Port) {
m_RemoteAddr.sin_family = AF_INET; m_RemoteAddr.sin_family = AF_INET;
m_RemoteAddr.sin_port = htons(Port); m_RemoteAddr.sin_port = htons(Port);
m_RemoteAddr.sin_addr.s_addr = inet_addr(Host); m_RemoteAddr.sin_addr.s_addr = inet_addr(Host.c_str());
if (::connect(socket, (struct sockaddr*)&m_RemoteAddr, if (::connect(socket, (struct sockaddr*)&m_RemoteAddr,
sizeof(m_RemoteAddr)) == -1) sizeof(m_RemoteAddr)) == -1)
return false; return false;
@ -50,7 +50,7 @@ bool cTBSocket::Connect(const cTBString &Host, unsigned int Port) {
return cTBSource::Open(socket); return cTBSource::Open(socket);
} }
bool cTBSocket::Listen(const char *Ip, unsigned int Port, int BackLog) { bool cTBSocket::Listen(const std::string &Ip, unsigned int Port, int BackLog) {
int val; int val;
socklen_t len; socklen_t len;
int socket; int socket;
@ -66,7 +66,7 @@ bool cTBSocket::Listen(const char *Ip, unsigned int Port, int BackLog) {
m_LocalAddr.sin_family = AF_INET; m_LocalAddr.sin_family = AF_INET;
m_LocalAddr.sin_port = htons(Port); m_LocalAddr.sin_port = htons(Port);
m_LocalAddr.sin_addr.s_addr = inet_addr(Ip); m_LocalAddr.sin_addr.s_addr = inet_addr(Ip.c_str());
if (::bind(socket, (struct sockaddr*)&m_LocalAddr, sizeof(m_LocalAddr)) if (::bind(socket, (struct sockaddr*)&m_LocalAddr, sizeof(m_LocalAddr))
== -1) == -1)
return false; return false;

View File

@ -3,11 +3,11 @@
#include "tools/tools.h" #include "tools/tools.h"
#include "tools/source.h" #include "tools/source.h"
#include "tools/string.h"
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <string>
/* cTBSocket provides a cTBSource-derived interface for input and output on /* cTBSocket provides a cTBSource-derived interface for input and output on
TCP/IPv4-sockets. */ TCP/IPv4-sockets. */
@ -35,7 +35,7 @@ public:
by Port of the target host given by Host in numbers-and-dots notation by Port of the target host given by Host in numbers-and-dots notation
(i.e. "212.43.45.21"). Returns true if the connection attempt was (i.e. "212.43.45.21"). Returns true if the connection attempt was
successful and false otherwise, setting errno appropriately. */ successful and false otherwise, setting errno appropriately. */
virtual bool Connect(const cTBString &Host, uint Port); virtual bool Connect(const std::string &Host, uint Port);
/* Shutdown() shuts down one or both ends of a socket. If called with How /* Shutdown() shuts down one or both ends of a socket. If called with How
set to SHUT_RD, further reads on this socket will be denied. If called set to SHUT_RD, further reads on this socket will be denied. If called
@ -54,7 +54,7 @@ public:
BackLog parameter defines the maximum length the queue of pending BackLog parameter defines the maximum length the queue of pending
connections may grow to. Returns true if the object is listening on connections may grow to. Returns true if the object is listening on
the specified port and false otherwise, setting errno appropriately. */ the specified port and false otherwise, setting errno appropriately. */
virtual bool Listen(const char *Ip, uint Port, int BackLog); virtual bool Listen(const std::string &Ip, uint Port, int BackLog);
/* Accept() returns a newly created cTBSocket, which is connected to the /* Accept() returns a newly created cTBSocket, which is connected to the
first connection request on the queue of pending connections of a first connection request on the queue of pending connections of a
@ -80,12 +80,12 @@ public:
the interface this socket is connected to locally. This can be the interface this socket is connected to locally. This can be
"0.0.0.0" for a listening socket listening to all interfaces. If the "0.0.0.0" for a listening socket listening to all interfaces. If the
socket is in its closed state, the result is undefined. */ socket is in its closed state, the result is undefined. */
cTBString LocalIp(void) const { return inet_ntoa(m_LocalAddr.sin_addr); } std::string LocalIp(void) const { return inet_ntoa(m_LocalAddr.sin_addr); }
/* RemoteIp() returns the internet address in numbers-and-dots notation of /* RemoteIp() returns the internet address in numbers-and-dots notation of
the interface this socket is connected to on the remote side. If the the interface this socket is connected to on the remote side. If the
socket is in its closed state, the result is undefined. */ socket is in its closed state, the result is undefined. */
cTBString RemoteIp(void) const { return inet_ntoa(m_RemoteAddr.sin_addr); } std::string RemoteIp(void) const { return inet_ntoa(m_RemoteAddr.sin_addr); }
in_addr_t LocalIpAddr(void) const { return m_LocalAddr.sin_addr.s_addr; } in_addr_t LocalIpAddr(void) const { return m_LocalAddr.sin_addr.s_addr; }
in_addr_t RemoteIpAddr(void) const { return m_RemoteAddr.sin_addr.s_addr; } in_addr_t RemoteIpAddr(void) const { return m_RemoteAddr.sin_addr.s_addr; }

View File

@ -87,30 +87,25 @@ bool cTBSource::TimedWrite(const void *Buffer, size_t Length, uint TimeoutMs) {
ssize_t cTBSource::ReadUntil(void *Buffer, size_t Length, const char *Seq, ssize_t cTBSource::ReadUntil(void *Buffer, size_t Length, const char *Seq,
uint TimeoutMs) { uint TimeoutMs) {
char *offs;
int seqlen, ms; int seqlen, ms;
size_t olen; size_t len;
cTBSelect sel; cTBSelect sel;
seqlen = strlen(Seq); if ((len = m_LineBuffer.find(Seq)) != (size_t)-1) {
if ((offs = (char*)memmem(m_LineBuffer, m_LineBuffer.Length(), Seq, seqlen))){ if (len > Length) {
olen = offs - m_LineBuffer;
if (olen >= Length) {
errno = ENOBUFS; errno = ENOBUFS;
return -1; return -1;
} }
memcpy(Buffer, m_LineBuffer, olen); memcpy(Buffer, m_LineBuffer.data(), len);
m_LineBuffer = m_LineBuffer.Mid(olen + seqlen); m_LineBuffer.erase(0, len + strlen(Seq));
Dprintf("ReadUntil: Served from Linebuffer: %d, |%.*s|\n", olen, olen - 1, Dprintf("ReadUntil: Served from Linebuffer: %d, |%.*s|\n", len, len - 1,
(char*)Buffer); (char*)Buffer);
return olen; return len;
} }
cTimeMs starttime; cTimeMs starttime;
ms = TimeoutMs; ms = TimeoutMs;
while (m_LineBuffer.Length() < BUFSIZ) { while (m_LineBuffer.size() < BUFSIZ) {
int b;
sel.Clear(); sel.Clear();
sel.Add(m_Filed, false); sel.Add(m_Filed, false);
@ -118,25 +113,24 @@ ssize_t cTBSource::ReadUntil(void *Buffer, size_t Length, const char *Seq,
return -1; return -1;
if (sel.CanRead(m_Filed)) { if (sel.CanRead(m_Filed)) {
offs = m_LineBuffer.Buffer(BUFSIZ); int b;
if ((b = Read(offs + m_LineBuffer.Length(), BUFSIZ
- m_LineBuffer.Length())) == -1)
return -1;
m_LineBuffer.Release(m_LineBuffer.Length() + b); len = m_LineBuffer.size();
if ((offs = (char*)memmem(m_LineBuffer, m_LineBuffer.Length(), Seq, m_LineBuffer.resize(BUFSIZ);
seqlen))) { if ((b = Read((char*)m_LineBuffer.data() + len, BUFSIZ - len)) == -1)
olen = offs - m_LineBuffer; return -1;
if (olen >= Length) { m_LineBuffer.resize(len + b);
if ((len = m_LineBuffer.find(Seq)) != (size_t)-1) {
if (len > Length) {
errno = ENOBUFS; errno = ENOBUFS;
return -1; return -1;
} }
memcpy(Buffer, m_LineBuffer, olen); memcpy(Buffer, m_LineBuffer.data(), len);
m_LineBuffer = m_LineBuffer.Mid(olen + seqlen, m_LineBuffer.Length() m_LineBuffer.erase(0, len + strlen(Seq));
- olen - seqlen); Dprintf("ReadUntil: Served from Linebuffer: %d, |%.*s|\n", len, len - 1,
Dprintf("ReadUntil: Served after Read: %d, |%.*s|\n", olen, olen-1,
(char*)Buffer); (char*)Buffer);
return olen; return len;
} }
} }
@ -148,46 +142,5 @@ ssize_t cTBSource::ReadUntil(void *Buffer, size_t Length, const char *Seq,
} }
errno = ENOBUFS; errno = ENOBUFS;
return -1; return -1;
/*
cTBSelect sel;
time_t st, et;
int ms, seqlen, offs;
seqlen = strlen(Seq);
st = time_ms();
ms = TimeoutMs;
offs = 0;
while (Length > 0) {
int b;
sel.Clear();
sel.Add(m_Filed, false);
if (sel.Select(ms) == -1)
return -1;
if (sel.CanRead(m_Filed)) {
if ((b = Read((char*)Buffer + offs, Length)) == -1)
return -1;
offs += b;
Length -= b;
if (memmem(Buffer, offs, Seq, seqlen) != NULL)
return offs;
}
et = time_ms();
ms -= et - st;
if (ms <= 0) {
errno = ETIMEDOUT;
return -1;
}
}
errno = ENOBUFS;
return -1;
*/
} }

View File

@ -2,9 +2,9 @@
#define TOOLBOX_SOURCE_H #define TOOLBOX_SOURCE_H
#include "tools/tools.h" #include "tools/tools.h"
#include "tools/string.h"
#include <sys/types.h> #include <sys/types.h>
#include <string>
/* cTBSource provides an abstract interface for input and output. It can /* cTBSource provides an abstract interface for input and output. It can
be used to have common access to different types of UNIX-files. */ be used to have common access to different types of UNIX-files. */
@ -16,7 +16,7 @@ private:
size_t m_BytesRead; size_t m_BytesRead;
size_t m_BytesWritten; size_t m_BytesWritten;
cTBString m_LineBuffer; std::string m_LineBuffer;
public: public:
cTBSource(void); cTBSource(void);