- 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
#
# $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.
# 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 \
\
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 \
\

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"
@ -8,7 +8,6 @@
#include "client/filter.h"
#include "tools/select.h"
#include "tools/string.h"
#include <vdr/channels.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>
@ -47,8 +47,6 @@ eOSState cStreamdevMenu::ProcessKey(eKeys Key) {
}
void cStreamdevMenu::SuspendServer(void) {
cTBString buffer;
if (ClientSocket.SuspendServer())
INFO(tr("Server is suspended"));
else
@ -1026,8 +1024,8 @@ eOSState cStreamdevMenuTimers::Summary(void) {
return osContinue;
cRemoteTimer *ti = CurrentTimer();
if (ti && !ti->Summary().IsNull())
return AddSubMenu(new cMenuText(tr("Summary"), ti->Summary()));
if (ti && ti->Summary() != "")
return AddSubMenu(new cMenuText(tr("Summary"), ti->Summary().c_str()));
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"
@ -34,13 +34,13 @@ cRemoteRecording::cRemoteRecording(const char *Text) {
*(ptr++) = '\0';
m_StartTime = timestr;
idx = -1;
while ((idx = m_StartTime.Find(' ', idx + 1)) != -1) m_StartTime[idx] = '\t';
Dprintf("m_Start: %s\n", (const char*)m_StartTime);
while ((idx = m_StartTime.find(' ', idx + 1)) != -1) m_StartTime[idx] = '\t';
Dprintf("m_Start: %s\n", m_StartTime.c_str());
if (*ptr == 0) return;
if (isspace(*ptr)) ++ptr;
if (*ptr == 0) return;
m_Name = ptr;
Dprintf("file: %s\n", (const char*)m_Name);
Dprintf("file: %s\n", m_Name.c_str());
m_IsValid = true;
}
@ -69,21 +69,20 @@ const char *cRemoteRecording::Title(char Delimiter, bool NewIndicator,
if (Level < 0 || Level == HierarchyLevels()) {
char *s;
const char *t;
if (Level > 0 && (t = strrchr(m_Name, '~')) != NULL)
const char *t;
if (Level > 0 && (t = strrchr(m_Name.c_str(), '~')) != NULL)
t++;
else
t = (const char*)m_Name;
t = m_Name.c_str();
asprintf(&m_TitleBuffer, "%s%c%c%s", (const char*)m_StartTime, New,
Delimiter, t);
asprintf(&m_TitleBuffer, "%s%c%c%s", m_StartTime.c_str(), New, Delimiter, t);
// let's not display a trailing '~':
stripspace(m_TitleBuffer);
s = &m_TitleBuffer[strlen(m_TitleBuffer) - 1];
if (*s == '~')
*s = 0;
} else if (Level < HierarchyLevels()) {
const char *s = m_Name;
const char *s = m_Name.c_str();
const char *p = s;
while (*++s) {
if (*s == '~') {
@ -104,7 +103,7 @@ const char *cRemoteRecording::Title(char Delimiter, bool NewIndicator,
int cRemoteRecording::HierarchyLevels(void)
{
const char *s = m_Name;
const char *s = m_Name.c_str();
int level = 0;
while (*++s) {
if (*s == '~') ++level;
@ -191,7 +190,7 @@ cRemoteTimer::cRemoteTimer(const char *Text) {
strncpy(m_File, tmpbuf, MaxFileName);
Dprintf("file: %s\n", m_File);
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;
}
@ -453,8 +452,8 @@ const char *cRemoteTimer::ToText(void) {
if (m_Buffer != NULL) free(m_Buffer);
strreplace(m_File, ':', '|');
if (!m_Summary.IsNull())
summary = strreplace(strdup(m_Summary), ':', '|');
if (m_Summary != "")
summary = strreplace(strdup(m_Summary.c_str()), ':', '|');
asprintf(&m_Buffer, "%d:%s:%s:%04d:%04d:%d:%d:%s:%s", m_Active,
(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
#define VDR_STREAMDEV_REMOTE_H
#include <vdr/config.h>
#include "tools/string.h"
#include <string>
#if VDRVERSNUM < 10300
class cEventInfo;
@ -18,13 +17,13 @@ class cChannel;
class cRemoteRecording: public cListObject {
private:
bool m_IsValid;
int m_Index;
bool m_IsNew;
char *m_TitleBuffer;
cTBString m_StartTime;
cTBString m_Name;
cTBString m_Summary;
bool m_IsValid;
int m_Index;
bool m_IsNew;
char *m_TitleBuffer;
std::string m_StartTime;
std::string m_Name;
std::string m_Summary;
public:
cRemoteRecording(const char *Text);
@ -37,10 +36,10 @@ public:
bool IsValid(void) const { return m_IsValid; }
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; }
const char *Name(void) const { return m_Name; }
const char *Summary(void) const { return m_Summary; }
const char *Name(void) const { return m_Name.c_str(); }
const char *Summary(void) const { return m_Summary.c_str(); }
const char *Title(char Delimiter, bool NewIndicator, int Level);
int HierarchyLevels(void);
};
@ -71,7 +70,7 @@ private:
int m_Lifetime;
char m_File[MaxFileName];
time_t m_FirstDay;
cTBString m_Summary;
std::string m_Summary;
char *m_Buffer;
const cChannel *m_Channel;
@ -116,7 +115,7 @@ public:
int Lifetime(void) const { return m_Lifetime; }
const char *File(void) const { return m_File; }
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 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>
@ -39,17 +39,17 @@ cTBSocket *cClientSocket::DataSocket(eSocketId Id) const {
return m_DataSockets[Id];
}
bool cClientSocket::Command(const cTBString &Command, uint Expected,
uint TimeoutMs) {
bool cClientSocket::Command(const std::string &Command, uint Expected, uint TimeoutMs)
{
errno = 0;
cTBString pkt = Command + "\015\012";
Dprintf("OUT: |%s|\n", (const char*)Command);
std::string pkt = Command + "\015\012";
Dprintf("OUT: |%s|\n", Command.c_str());
cTimeMs starttime;
if (!TimedWrite((const char*)pkt, pkt.Length(), TimeoutMs)) {
esyslog("Streamdev: Lost connection to %s:%d: %s",
(const char*)RemoteIp(), RemotePort(), strerror(errno));
if (!TimedWrite(pkt.c_str(), pkt.size(), TimeoutMs)) {
esyslog("Streamdev: Lost connection to %s:%d: %s", RemoteIp().c_str(), RemotePort(),
strerror(errno));
Close();
return false;
}
@ -63,34 +63,28 @@ bool cClientSocket::Command(const cTBString &Command, uint Expected,
return true;
}
bool cClientSocket::Expect(uint Expected, cTBString *Result, uint TimeoutMs) {
char *buffer;
bool cClientSocket::Expect(uint Expected, std::string *Result, uint TimeoutMs) {
char *endptr;
int bufcount;
bool res;
errno = 0;
buffer = new char[BUFSIZ + 1];
if ((bufcount = ReadUntil(buffer, BUFSIZ, "\012", TimeoutMs))
== -1) {
esyslog("Streamdev: Lost connection to %s:%d: %s",
(const char*)RemoteIp(), RemotePort(), strerror(errno));
if ((bufcount = ReadUntil(m_Buffer, sizeof(m_Buffer) - 1, "\012", TimeoutMs)) == -1) {
esyslog("Streamdev: Lost connection to %s:%d: %s", RemoteIp().c_str(), RemotePort(),
strerror(errno));
Close();
delete[] buffer;
return false;
}
if (buffer[bufcount - 1] == '\015')
if (m_Buffer[bufcount - 1] == '\015')
--bufcount;
buffer[bufcount] = '\0';
Dprintf("IN: |%s|\n", buffer);
m_Buffer[bufcount] = '\0';
Dprintf("IN: |%s|\n", m_Buffer);
if (Result != NULL)
*Result = buffer;
*Result = m_Buffer;
res = strtoul(buffer, &endptr, 10) == Expected;
delete[] buffer;
res = strtoul(m_Buffer, &endptr, 10) == Expected;
return res;
}
@ -125,73 +119,73 @@ bool cClientSocket::CheckConnection(void) {
if (!Expect(220)) {
if (errno == 0)
esyslog("ERROR: Streamdev: Didn't receive greeting from %s:%d",
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
Close();
return false;
}
if (!Command((cTBString)"CAPS TSPIDS", 220)) {
if (!Command("CAPS TSPIDS", 220)) {
if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't negotiate capabilities on %s:%d",
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
Close();
return false;
}
isyslog("Streamdev: Connected to server %s:%d using capabilities TSPIDS",
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
return true;
}
bool cClientSocket::ProvidesChannel(const cChannel *Channel, int Priority) {
cTBString buffer;
if (!CheckConnection()) return false;
CMD_LOCK;
if (!Command("PROV " + cTBString::Number(Priority) + " "
+ Channel->GetChannelID().ToString()))
std::string command = (std::string)"PROV " + (const char*)itoa(Priority) + " "
+ (const char*)Channel->GetChannelID().ToString();
if (!Command(command))
return false;
std::string 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",
(const char*)RemoteIp(), RemotePort(), Channel->Name());
RemoteIp().c_str(), RemotePort(), Channel->Name());
return false;
}
return true;
}
bool cClientSocket::CreateDataConnection(eSocketId Id) {
int idx;
cTBSocket listen(SOCK_STREAM);
cTBString buffer;
if (!CheckConnection()) return false;
if (m_DataSockets[Id] != NULL)
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",
strerror(errno));
return false;
}
buffer.Format("PORT %d %s,%d,%d", Id, (const char*)LocalIp(),
(listen.LocalPort() >> 8) & 0xff, listen.LocalPort() & 0xff);
idx = 5;
while ((idx = buffer.Find('.', idx + 1)) != -1)
buffer[idx] = ',';
std::string command = (std::string)"PORT " + (const char*)itoa(Id) + " "
+ LocalIp().c_str() + ","
+ (const char*)itoa((listen.LocalPort() >> 8) & 0xff) + ","
+ (const char*)itoa(listen.LocalPort() & 0xff);
size_t idx = 4;
while ((idx = command.find('.', idx + 1)) != (size_t)-1)
command[idx] = ',';
CMD_LOCK;
if (!Command(buffer, 220)) {
if (!Command(command, 220)) {
Dprintf("error: %m\n");
if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't establish data connection to %s:%d",
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
return false;
}
@ -204,7 +198,7 @@ bool cClientSocket::CreateDataConnection(eSocketId Id) {
m_DataSockets[Id] = new cTBSocket;
if (!m_DataSockets[Id]->Accept(listen)) {
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));
DELETENULL(m_DataSockets[Id]);
return false;
@ -218,10 +212,12 @@ bool cClientSocket::SetChannelDevice(const cChannel *Channel) {
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)
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 true;
@ -232,10 +228,11 @@ bool cClientSocket::SetPid(int Pid, bool On) {
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)
esyslog("Streamdev: Pid %d not available from %s:%d", Pid,
(const char*)LocalIp(), LocalPort());
esyslog("Streamdev: Pid %d not available from %s:%d", Pid, LocalIp().c_str(),
LocalPort());
return false;
}
return true;
@ -243,15 +240,16 @@ bool cClientSocket::SetPid(int Pid, bool On) {
#if VDRVERSNUM >= 10300
bool cClientSocket::SetFilter(ushort Pid, uchar Tid, uchar Mask, bool On) {
cTBString cmd;
if (!CheckConnection()) return false;
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)
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 true;
@ -264,7 +262,8 @@ bool cClientSocket::CloseDvr(void) {
CMD_LOCK;
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)
esyslog("ERROR: Streamdev: Couldn't cleanly close data connection");
return false;
@ -276,8 +275,8 @@ bool cClientSocket::CloseDvr(void) {
}
bool cClientSocket::SynchronizeEPG(void) {
cTBString buffer;
bool res;
std::string buffer;
bool result;
FILE *epgfd;
if (!CheckConnection()) return false;
@ -295,16 +294,16 @@ bool cClientSocket::SynchronizeEPG(void) {
return false;
}
while ((res = Expect(215, &buffer))) {
while ((result = Expect(215, &buffer))) {
if (buffer[3] == ' ') break;
fputs((const char*)buffer + 4, epgfd);
fputs(buffer.c_str() + 4, epgfd);
fputc('\n', epgfd);
}
if (!res) {
if (!result) {
if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch EPG data from %s:%d",
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
fclose(epgfd);
return false;
}
@ -333,14 +332,13 @@ bool cClientSocket::Quit(void) {
if (!(res = Command("QUIT", 221))) {
if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't quit command connection to %s:%d",
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
}
Close();
return res;
}
bool cClientSocket::LoadRecordings(cRemoteRecordings &Recordings) {
cTBString buffer;
bool res;
if (!CheckConnection()) return false;
@ -350,8 +348,9 @@ bool cClientSocket::LoadRecordings(cRemoteRecordings &Recordings) {
if (!Command("LSTR"))
return false;
std::string 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());
if (rec->IsValid())
Recordings.Add(rec);
@ -360,23 +359,24 @@ bool cClientSocket::LoadRecordings(cRemoteRecordings &Recordings) {
if (buffer[3] == ' ') break;
}
if (!res && buffer.Left(3) != "550") {
if (!res && buffer.substr(0, 3) != "550") {
if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch recordings from %s:%d",
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
return false;
}
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;
if (Expect(250, &buffer))
r->ParseInfo((const char*)buffer + 4);
else if (buffer.Left(3) != "550") {
r->ParseInfo(buffer.c_str() + 4);
else if (buffer.substr(0, 3) != "550") {
if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch details for recording from "
"%s:%d", (const char*)RemoteIp(), RemotePort());
esyslog("ERROR: Streamdev: Couldn't fetch details for recording from %s:%d",
RemoteIp().c_str(), RemotePort());
return false;
}
Dprintf("recording complete: %d\n", r->Index());
@ -388,11 +388,12 @@ bool cClientSocket::StartReplay(const char *Filename) {
if (!CheckConnection()) return false;
CMD_LOCK;
if (!Command((cTBString)"PLAY " + Filename, 220)) {
std::string command = (std::string)"PLAY " + Filename;
if (!Command(command, 220)) {
if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't replay \"%s\" from %s:%d",
Filename, (const char*)RemoteIp(), RemotePort());
Filename, RemoteIp().c_str(), RemotePort());
return false;
}
return true;
@ -404,7 +405,8 @@ bool cClientSocket::AbortReplay(void) {
CMD_LOCK;
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)
esyslog("ERROR: Streamdev: Couldn't cleanly close data connection");
return false;
@ -417,7 +419,6 @@ bool cClientSocket::AbortReplay(void) {
bool cClientSocket::DeleteRecording(cRemoteRecording *Recording) {
bool res;
cTBString buffer;
cRemoteRecording *rec = NULL;
if (!CheckConnection())
@ -428,19 +429,20 @@ bool cClientSocket::DeleteRecording(cRemoteRecording *Recording) {
if (!Command("LSTR"))
return false;
std::string buffer;
while ((res = Expect(250, &buffer))) {
if (rec == NULL) {
rec = new cRemoteRecording((const char*)buffer + 4);
rec = new cRemoteRecording(buffer.c_str() + 4);
if (!rec->IsValid() || rec->Index() != Recording->Index())
DELETENULL(rec);
}
if (buffer[3] == ' ') break;
}
if (!res && buffer.Left(3) != "550") {
if (!res && buffer.substr(0, 3) != "550") {
if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch recordings from %s:%d",
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
if (rec != NULL) delete rec;
return false;
}
@ -450,7 +452,8 @@ bool cClientSocket::DeleteRecording(cRemoteRecording *Recording) {
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..."));
return false;
}
@ -471,9 +474,6 @@ bool cClientSocket::SuspendServer(void) {
}
bool cClientSocket::LoadTimers(cRemoteTimers &Timers) {
cTBString buffer;
bool res;
if (!CheckConnection()) return false;
CMD_LOCK;
@ -481,39 +481,42 @@ bool cClientSocket::LoadTimers(cRemoteTimers &Timers) {
if (!Command("LSTT"))
return false;
bool res;
std::string 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());
if (timer->IsValid())
Timers.Add(timer);
if (buffer[3] == ' ') break;
}
if (!res && buffer.Left(3) != "550") {
if (!res && buffer.substr(0, 3) != "550") {
if (errno == 0)
esyslog("ERROR: Streamdev: Couldn't fetch recordings from %s:%d",
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
return false;
}
return res;
}
bool cClientSocket::SaveTimer(cRemoteTimer *Old, cRemoteTimer &New) {
cTBString buffer;
if (!CheckConnection()) return false;
CMD_LOCK;
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..."));
return false;
}
} 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;
std::string buffer;
if (!Expect(250, &buffer)) {
if (errno == 0)
ERROR(tr("Timers not in sync! Try again..."));
@ -522,7 +525,7 @@ bool cClientSocket::SaveTimer(cRemoteTimer *Old, cRemoteTimer &New) {
return false;
}
cRemoteTimer oldstate((const char*)buffer + 4);
cRemoteTimer oldstate(buffer.c_str() + 4);
if (oldstate != *Old) {
/*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());
@ -532,8 +535,10 @@ bool cClientSocket::SaveTimer(cRemoteTimer *Old, cRemoteTimer &New) {
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..."));
return false;
}
@ -542,16 +547,15 @@ bool cClientSocket::SaveTimer(cRemoteTimer *Old, cRemoteTimer &New) {
}
bool cClientSocket::DeleteTimer(cRemoteTimer *Timer) {
cTBString buffer;
if (!CheckConnection())
return false;
if (!CheckConnection()) return false;
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;
std::string buffer;
if (!Expect(250, &buffer)) {
if (errno == 0)
ERROR(tr("Timers not in sync! Try again..."));
@ -560,14 +564,14 @@ bool cClientSocket::DeleteTimer(cRemoteTimer *Timer) {
return false;
}
cRemoteTimer oldstate((const char*)buffer + 4);
cRemoteTimer oldstate(buffer.c_str() + 4);
if (oldstate != *Timer) {
ERROR(tr("Timers not in sync! Try again..."));
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..."));
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
@ -9,6 +9,8 @@
#include "common.h"
#include <string>
#define CMD_LOCK cMutexLock CmdLock((cMutex*)&m_Mutex)
class cRemoteRecordings;
@ -21,20 +23,20 @@ class cClientSocket: public cTBSocket {
private:
cTBSocket *m_DataSockets[si_Count];
cMutex m_Mutex;
char m_Buffer[BUFSIZ + 1]; // various uses
protected:
/* Send Command, and return true if the command results in Expected.
Returns false on failure, setting errno appropriately if it has been
a system failure. If Expected is zero, returns immediately after
sending the command. */
bool Command(const cTBString &Command, uint Expected = 0,
uint TimeoutMs = 1500);
bool Command(const std::string &Command, uint Expected = 0, uint TimeoutMs = 1500);
/* Fetch results from an ongoing Command called with Expected == 0. Returns
true if the response has the code Expected, returning an internal buffer
in the array pointer pointed to by Result. Returns false on 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:
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"
@ -38,7 +38,7 @@ cServerConnection *cServerComponent::CanAct(const cTBSelect &Select) {
cServerConnection *client = NewConnection();
if (client->Accept(m_Listen)) {
isyslog("Streamdev: Accepted new client (%s) %s:%d", m_Protocol,
(const char*)client->RemoteIp(), client->RemotePort());
client->RemoteIp().c_str(), client->RemotePort());
return client;
} else {
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"
@ -27,13 +27,13 @@ bool cServerConnection::CanAct(const cTBSelect &Select) {
int b;
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,
(const char*)RemoteIp(), RemotePort(), strerror(errno));
RemoteIp().c_str(), RemotePort(), strerror(errno));
return false;
}
if (b == 0) {
isyslog("Streamdev: Client (%s) %s:%d closed connection", m_Protocol,
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
return false;
}
@ -46,7 +46,7 @@ bool cServerConnection::CanAct(const cTBSelect &Select) {
int b;
if ((b = Write(m_WrBuf + m_WrOffs, m_WrBytes - m_WrOffs)) < 0) {
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;
}
@ -85,18 +85,18 @@ bool cServerConnection::ParseBuffer(void) {
return true;
}
bool cServerConnection::Respond(const char *Message) {
uint len = strlen(Message);
if (m_WrBytes + len + 2 > sizeof(m_WrBuf)) {
bool cServerConnection::Respond(const std::string &Message) {
if (m_WrBytes + Message.size() + 2 > sizeof(m_WrBuf)) {
esyslog("Streamdev: Output buffer overflow (%s) for %s:%d", m_Protocol,
(const char*)RemoteIp(), RemotePort());
RemoteIp().c_str(), RemotePort());
return false;
}
Dprintf("OUT: |%s|\n", Message);
memcpy(m_WrBuf + m_WrBytes, Message, len);
m_WrBuf[m_WrBytes + len] = '\015';
m_WrBuf[m_WrBytes + len + 1] = '\012';
m_WrBytes += len + 2;
Dprintf("OUT: |%s|\n", Message.c_str());
memcpy(m_WrBuf + m_WrBytes, Message.c_str(), Message.size());
m_WrBytes += Message.size();
m_WrBuf[m_WrBytes++] = '\015';
m_WrBuf[m_WrBytes++] = '\012';
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
@ -58,7 +58,7 @@ public:
/* 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 */
bool Respond(const char *Message);
bool Respond(const std::string &Message);
/* Will make the socket close after sending all queued output data */
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"
@ -63,7 +63,7 @@ bool cConnectionHTTP::Command(char *Cmd) {
|| m_Channel->Vpid() == 1 || m_Channel->Vpid() == 0x1FFF)) {
return Respond("HTTP/1.0 200 OK")
&& Respond("Content-Type: audio/mpeg")
&& Respond((cTBString)"icy-name: " + m_Channel->Name())
&& Respond((std::string)"icy-name: " + m_Channel->Name())
&& Respond("");
} else {
return Respond("HTTP/1.0 200 OK")
@ -86,20 +86,20 @@ bool cConnectionHTTP::Command(char *Cmd) {
void cConnectionHTTP::Flushed(void) {
if (m_Status == hsListing) {
cTBString line;
if (m_ListChannel == NULL) {
Respond("</ul></body></html>");
DeferClose();
return;
}
std::string line;
if (m_ListChannel->GroupSep())
line.Format("<li>--- %s ---</li>", m_ListChannel->Name());
line = (std::string)"<li>--- " + m_ListChannel->Name() + "---</li>";
else
line.Format("<li><a href=\"http://%s:%d/%s\">%s</a></li>",
(const char*)LocalIp(), StreamdevServerSetup.HTTPServerPort,
(const char*)m_ListChannel->GetChannelID().ToString(), m_ListChannel->Name());
line = (std::string)"<li><a href=\"http://" + LocalIp() + ":"
+ (const char*)itoa(StreamdevServerSetup.HTTPServerPort) + "/"
+ (const char*)m_ListChannel->GetChannelID().ToString() + "\">"
+ m_ListChannel->Name() + "</a></li>";
if (!Respond(line))
DeferClose();
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"
@ -82,13 +82,13 @@ bool cConnectionVTP::Command(char *Cmd) {
else if (strcasecmp(Cmd, "NEWT") == 0) return CmdNEWT(ep);
else if (strcasecmp(Cmd, "DELT") == 0) return CmdDELT(ep);
else
return Respond(500, (cTBString)"Unknown Command '" + Cmd + "'");
return Respond(500, (std::string)"Unknown Command '" + Cmd + "'");
}
bool cConnectionVTP::CmdCAPS(char *Opts) {
if (strcasecmp(Opts, "TSPIDS") == 0)
return Respond(220, (cTBString)"Capability \"" + Opts + "\" accepted");
return Respond(561, (cTBString)"Capability \"" + Opts + "\" not known");
return Respond(220, (std::string)"Capability \"" + Opts + "\" accepted");
return Respond(561, (std::string)"Capability \"" + Opts + "\" not known");
}
bool cConnectionVTP::CmdPROV(char *Opts) {
@ -102,7 +102,7 @@ bool cConnectionVTP::CmdPROV(char *Opts) {
Opts = skipspace(ep);
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
? Respond(220, "Channel available")
@ -120,7 +120,7 @@ bool cConnectionVTP::CmdPORT(char *Opts) {
return Respond(500, "Use: PORT Id Destination");
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);
n = 0;
@ -166,7 +166,7 @@ bool cConnectionVTP::CmdTUNE(char *Opts) {
cDevice *dev;
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)
return Respond(560, "Channel not available");
@ -191,8 +191,8 @@ bool cConnectionVTP::CmdADDP(char *Opts) {
return Respond(500, "Use: ADDP Pid");
return m_LiveStreamer && m_LiveStreamer->SetPid(pid, true)
? Respond(220, "Pid " + cTBString::Number(pid) + " available")
: Respond(560, "Pid " + cTBString::Number(pid) + " not available");
? Respond(220, (std::string)"Pid " + (const char*)itoa(pid) + " available")
: Respond(560, (std::string)"Pid " + (const char*)itoa(pid) + " not available");
}
bool cConnectionVTP::CmdDELP(char *Opts) {
@ -204,8 +204,8 @@ bool cConnectionVTP::CmdDELP(char *Opts) {
return Respond(500, "Use: DELP Pid");
return m_LiveStreamer && m_LiveStreamer->SetPid(pid, false)
? Respond(220, "Pid " + cTBString::Number(pid) + " stopped")
: Respond(560, "Pid " + cTBString::Number(pid) + " not transferring");
? Respond(220, (std::string)"Pid " + (const char*)itoa(pid) + " stopped")
: Respond(560, (std::string)"Pid " + (const char*)itoa(pid) + " not transferring");
}
bool cConnectionVTP::CmdADDF(char *Opts) {
@ -229,8 +229,8 @@ bool cConnectionVTP::CmdADDF(char *Opts) {
return Respond(500, "Use: ADDF Pid Tid Mask");
return m_LiveStreamer->SetFilter(pid, tid, mask, true)
? Respond(220, "Filter " + cTBString::Number(pid) + " transferring")
: Respond(560, "Filter " + cTBString::Number(pid) + " not available");
? Respond(220, (std::string)"Filter " + (const char*)itoa(pid) + " transferring")
: Respond(560, (std::string)"Filter " + (const char*)itoa(pid) + " not available");
#else
return Respond(500, "ADDF known but unimplemented with VDR < 1.3.0");
#endif
@ -257,8 +257,8 @@ bool cConnectionVTP::CmdDELF(char *Opts) {
return Respond(500, "Use: DELF Pid Tid Mask");
return m_LiveStreamer->SetFilter(pid, tid, mask, false)
? Respond(220, "Filter " + cTBString::Number(pid) + " stopped")
: Respond(560, "Filter " + cTBString::Number(pid) + " not transferring");
? Respond(220, (std::string)"Filter " + (const char*)itoa(pid) + " stopped")
: Respond(560, (std::string)"Filter " + (const char*)itoa(pid) + " not transferring");
#else
return Respond(500, "DELF known but unimplemented with VDR < 1.3.0");
#endif
@ -530,12 +530,12 @@ bool cConnectionVTP::CmdDELT(char *Option) {
EXIT_WRAPPER();
}
bool cConnectionVTP::Respond(int Code, const char *Message) {
cTBString pkt;
if (Code < 0)
pkt.Format("%03d-%s", -Code, Message);
else
pkt.Format("%03d %s", Code, Message);
return cServerConnection::Respond((const char*)pkt);
bool cConnectionVTP::Respond(int Code, const std::string &Message) {
char *buffer;
bool result;
asprintf(&buffer, "%03d%c%s", Code < 0 ? -Code : Code, Code < 0 ? '-' : ' ', Message.c_str());
result = cServerConnection::Respond(buffer);
free(buffer);
return result;
}

View File

@ -48,7 +48,7 @@ public:
bool CmdNEWT(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

View File

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

View File

@ -59,7 +59,7 @@ public:
virtual void Start(cTBSocket *Socket);
// Statistical purposes:
virtual cTBString Report(void);
virtual std::string Report(void);
};
#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"
@ -106,11 +106,11 @@ void cStreamdevServer::Action(void) {
if (m_Clients.Count() > StreamdevServerSetup.MaxClients) {
esyslog("Streamdev: Too many clients, rejecting %s:%d",
(const char*)client->RemoteIp(), client->RemotePort());
client->RemoteIp().c_str(), client->RemotePort());
client->Reject();
} else if (!StreamdevHosts.Acceptable(client->RemoteIpAddr())) {
esyslog("Streamdev: Client from %s:%d not allowed to connect",
(const char*)client->RemoteIp(), client->RemotePort());
client->RemoteIp().c_str(), client->RemotePort());
client->Reject();
} else
client->Welcome();
@ -122,7 +122,7 @@ void cStreamdevServer::Action(void) {
cServerConnection *next = m_Clients.Next(s);
if (!s->CanAct(select)) {
isyslog("Streamdev: Closing connection to %s:%d",
(const char*)s->RemoteIp(), s->RemotePort());
s->RemoteIp().c_str(), s->RemotePort());
s->Close();
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>
@ -16,10 +16,8 @@
#define VIDEOBUFSIZE MEGABYTE(4)
#define MAXBLOCKSIZE TS_SIZE*10
cStreamdevStreamer::cStreamdevStreamer(const char *Name)
#if VDRVERSNUM >= 10300
:cThread("Streamdev: " + (cTBString)Name)
#endif
cStreamdevStreamer::cStreamdevStreamer(const char *Name):
cThread(((std::string)"Streamdev: " + Name).c_str())
{
m_Active = false;
m_Receivers = 0;

View File

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

View File

@ -3,12 +3,12 @@
#include "tools/tools.h"
#include "tools/source.h"
#include "tools/string.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string>
/* cTBFile provides a cTBSource-derived interface for input and output on UNIX
files. */
@ -16,7 +16,7 @@
class cTBFile: public cTBSource {
private:
bool m_Anonymous;
cTBString m_Filename;
std::string m_Filename;
/* Unhide and forbid baseclass method */
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
Attribs, defaulting to rw-------. Returns true on success and false on
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);
/* 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
underlying filesystem. Returns true on success and false otherwise,
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
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).
Returns the exact size of the file in bytes. Returns -1 on error,
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 {

View File

@ -16,7 +16,7 @@ cTBSocket::~cTBSocket() {
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;
int socket;
@ -34,7 +34,7 @@ bool cTBSocket::Connect(const cTBString &Host, unsigned int Port) {
m_RemoteAddr.sin_family = AF_INET;
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,
sizeof(m_RemoteAddr)) == -1)
return false;
@ -50,7 +50,7 @@ bool cTBSocket::Connect(const cTBString &Host, unsigned int Port) {
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;
socklen_t len;
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_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))
== -1)
return false;

View File

@ -3,11 +3,11 @@
#include "tools/tools.h"
#include "tools/source.h"
#include "tools/string.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
/* cTBSocket provides a cTBSource-derived interface for input and output on
TCP/IPv4-sockets. */
@ -35,7 +35,7 @@ public:
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
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
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
connections may grow to. Returns true if the object is listening on
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
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
"0.0.0.0" for a listening socket listening to all interfaces. If the
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
the interface this socket is connected to on the remote side. If the
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 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,
uint TimeoutMs) {
char *offs;
int seqlen, ms;
size_t olen;
size_t len;
cTBSelect sel;
seqlen = strlen(Seq);
if ((offs = (char*)memmem(m_LineBuffer, m_LineBuffer.Length(), Seq, seqlen))){
olen = offs - m_LineBuffer;
if (olen >= Length) {
if ((len = m_LineBuffer.find(Seq)) != (size_t)-1) {
if (len > Length) {
errno = ENOBUFS;
return -1;
}
memcpy(Buffer, m_LineBuffer, olen);
m_LineBuffer = m_LineBuffer.Mid(olen + seqlen);
Dprintf("ReadUntil: Served from Linebuffer: %d, |%.*s|\n", olen, olen - 1,
memcpy(Buffer, m_LineBuffer.data(), len);
m_LineBuffer.erase(0, len + strlen(Seq));
Dprintf("ReadUntil: Served from Linebuffer: %d, |%.*s|\n", len, len - 1,
(char*)Buffer);
return olen;
return len;
}
cTimeMs starttime;
ms = TimeoutMs;
while (m_LineBuffer.Length() < BUFSIZ) {
int b;
while (m_LineBuffer.size() < BUFSIZ) {
sel.Clear();
sel.Add(m_Filed, false);
@ -118,25 +113,24 @@ ssize_t cTBSource::ReadUntil(void *Buffer, size_t Length, const char *Seq,
return -1;
if (sel.CanRead(m_Filed)) {
offs = m_LineBuffer.Buffer(BUFSIZ);
if ((b = Read(offs + m_LineBuffer.Length(), BUFSIZ
- m_LineBuffer.Length())) == -1)
return -1;
int b;
m_LineBuffer.Release(m_LineBuffer.Length() + b);
if ((offs = (char*)memmem(m_LineBuffer, m_LineBuffer.Length(), Seq,
seqlen))) {
olen = offs - m_LineBuffer;
if (olen >= Length) {
len = m_LineBuffer.size();
m_LineBuffer.resize(BUFSIZ);
if ((b = Read((char*)m_LineBuffer.data() + len, BUFSIZ - len)) == -1)
return -1;
m_LineBuffer.resize(len + b);
if ((len = m_LineBuffer.find(Seq)) != (size_t)-1) {
if (len > Length) {
errno = ENOBUFS;
return -1;
}
memcpy(Buffer, m_LineBuffer, olen);
m_LineBuffer = m_LineBuffer.Mid(olen + seqlen, m_LineBuffer.Length()
- olen - seqlen);
Dprintf("ReadUntil: Served after Read: %d, |%.*s|\n", olen, olen-1,
memcpy(Buffer, m_LineBuffer.data(), len);
m_LineBuffer.erase(0, len + strlen(Seq));
Dprintf("ReadUntil: Served from Linebuffer: %d, |%.*s|\n", len, len - 1,
(char*)Buffer);
return olen;
return len;
}
}
@ -148,46 +142,5 @@ ssize_t cTBSource::ReadUntil(void *Buffer, size_t Length, const char *Seq,
}
errno = ENOBUFS;
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
#include "tools/tools.h"
#include "tools/string.h"
#include <sys/types.h>
#include <string>
/* cTBSource provides an abstract interface for input and output. It can
be used to have common access to different types of UNIX-files. */
@ -16,7 +16,7 @@ private:
size_t m_BytesRead;
size_t m_BytesWritten;
cTBString m_LineBuffer;
std::string m_LineBuffer;
public:
cTBSource(void);