aboutsummaryrefslogtreecommitdiffstats
path: root/ncpd
diff options
context:
space:
mode:
authorFritz Elfert <felfert@to.com>2002-07-14 19:08:08 +0000
committerFritz Elfert <felfert@to.com>2002-07-14 19:08:08 +0000
commit28e01b8c6a137a9e98d95689be3d3d72be18d9d7 (patch)
treef011d3dba1f05cc8c08b582ba4b9568d3dfc94af /ncpd
parent838b2558b635d0ec27785e1280904fdea61bc935 (diff)
downloadplptools-28e01b8c6a137a9e98d95689be3d3d72be18d9d7.tar.gz
plptools-28e01b8c6a137a9e98d95689be3d3d72be18d9d7.tar.bz2
plptools-28e01b8c6a137a9e98d95689be3d3d72be18d9d7.zip
- Non-KDE stuff now builds correctly with gcc3
Diffstat (limited to 'ncpd')
-rw-r--r--ncpd/link.cc79
-rw-r--r--ncpd/link.h6
-rw-r--r--ncpd/linkchan.cc23
-rw-r--r--ncpd/main.cc35
-rw-r--r--ncpd/ncp.cc69
-rw-r--r--ncpd/ncp.h9
-rw-r--r--ncpd/packet.cc35
-rw-r--r--ncpd/socketchan.cc14
8 files changed, 148 insertions, 122 deletions
diff --git a/ncpd/link.cc b/ncpd/link.cc
index 453211f..76a8be4 100644
--- a/ncpd/link.cc
+++ b/ncpd/link.cc
@@ -50,6 +50,11 @@ extern "C" {
}
};
+using namespace std;
+
+extern ostream lout;
+extern ostream lerr;
+
ENUM_DEFINITION(Link::link_type, Link::LINK_TYPE_UNKNOWN) {
stringRep.add(Link::LINK_TYPE_UNKNOWN, N_("Unknown"));
stringRep.add(Link::LINK_TYPE_SIBO, N_("SIBO"));
@@ -169,7 +174,7 @@ sendAck(int seq)
return;
bufferStore tmp;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: >> ack seq=" << seq << endl;
+ lout << "Link: >> ack seq=" << seq << endl;
if (seq > 7) {
int hseq = seq >> 3;
int lseq = (seq & 7) | 8;
@@ -187,7 +192,7 @@ sendReqCon()
return;
bufferStore tmp;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: >> con seq=4" << endl;
+ lout << "Link: >> con seq=4" << endl;
tmp.addByte(0x24);
tmp.addDWord(conMagic);
ackWaitQueueElement e;
@@ -208,7 +213,7 @@ sendReqReq()
return;
bufferStore tmp;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: >> con seq=1" << endl;
+ lout << "Link: >> con seq=1" << endl;
tmp.addByte(0x21);
ackWaitQueueElement e;
e.seq = 0; // expected response is Ack with seq=0 or ReqCon
@@ -228,7 +233,7 @@ sendReq()
return;
bufferStore tmp;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: >> con seq=1" << endl;
+ lout << "Link: >> con seq=1" << endl;
tmp.addByte(0x20);
// No Ack expected for this, so no new entry in ackWaitQueue
p->send(tmp);
@@ -259,11 +264,11 @@ receive(bufferStore buff)
case 0x30:
// Normal data
if (verbose & LNK_DEBUG_LOG) {
- cout << "Link: << dat seq=" << seq ;
+ lout << "Link: << dat seq=" << seq ;
if (verbose & LNK_DEBUG_DUMP)
- cout << " " << buff << endl;
+ lout << " " << buff << endl;
else
- cout << " len=" << buff.getLen() << endl;
+ lout << " len=" << buff.getLen() << endl;
}
sendAck((rxSequence+1) & seqMask);
@@ -278,14 +283,14 @@ receive(bufferStore buff)
// XOFF
xoff[buff.getByte(1)] = true;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: got XOFF for channel "
+ lout << "Link: got XOFF for channel "
<< buff.getByte(1) << endl;
break;
case 2:
// XON
xoff[buff.getByte(1)] = false;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: got XON for channel "
+ lout << "Link: got XON for channel "
<< buff.getByte(1) << endl;
// Transmit packets on hold queue
transmitHoldQueue(buff.getByte(1));
@@ -298,7 +303,7 @@ receive(bufferStore buff)
} else {
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: DUP\n";
+ lout << "Link: DUP\n";
}
break;
@@ -314,10 +319,10 @@ receive(bufferStore buff)
refstamp = i->stamp;
ackWaitQueue.erase(i);
if (verbose & LNK_DEBUG_LOG) {
- cout << "Link: << ack seq=" << seq ;
+ lout << "Link: << ack seq=" << seq ;
if (verbose & LNK_DEBUG_DUMP)
- cout << " " << buff;
- cout << endl;
+ lout << " " << buff;
+ lout << endl;
}
break;
}
@@ -336,7 +341,7 @@ receive(bufferStore buff)
purgeAllQueues();
p->setEpoc(false);
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: 1-linkType set to " << linkType << endl;
+ lout << "Link: 1-linkType set to " << linkType << endl;
}
// Older packets implicitely ack'ed
multiAck(refstamp);
@@ -357,7 +362,7 @@ receive(bufferStore buff)
if (i->txcount-- == 0) {
// timeout, remove packet
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: >> TRANSMIT timeout seq=" <<
+ lout << "Link: >> TRANSMIT timeout seq=" <<
i->seq << endl;
ackWaitQueue.erase(i);
i--;
@@ -365,7 +370,7 @@ receive(bufferStore buff)
// retransmit it
i->stamp = now;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: >> RETRANSMIT seq=" << i->seq
+ lout << "Link: >> RETRANSMIT seq=" << i->seq
<< endl;
p->send(i->data);
}
@@ -373,10 +378,10 @@ receive(bufferStore buff)
}
pthread_mutex_unlock(&queueMutex);
if ((verbose & LNK_DEBUG_LOG) && (!nextFound)) {
- cout << "Link: << UNMATCHED ack seq=" << seq;
+ lout << "Link: << UNMATCHED ack seq=" << seq;
if (verbose & LNK_DEBUG_DUMP)
- cout << " " << buff;
- cout << endl;
+ lout << " " << buff;
+ lout << endl;
}
}
break;
@@ -392,7 +397,7 @@ receive(bufferStore buff)
ackWaitQueue.erase(i);
linkType = LINK_TYPE_EPOC;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: 2-linkType set to " << linkType << endl;
+ lout << "Link: 2-linkType set to " << linkType << endl;
conFound = true;
failed = false;
// EPOC can handle extended sequence numbers
@@ -401,10 +406,10 @@ receive(bufferStore buff)
maxOutstanding = 8;
p->setEpoc(true);
if (verbose & LNK_DEBUG_LOG) {
- cout << "Link: << con seq=" << seq ;
+ lout << "Link: << con seq=" << seq ;
if (verbose & LNK_DEBUG_DUMP)
- cout << " " << buff;
- cout << endl;
+ lout << " " << buff;
+ lout << endl;
}
break;
}
@@ -416,16 +421,16 @@ receive(bufferStore buff)
sendAck(rxSequence);
} else {
if (verbose & LNK_DEBUG_LOG) {
- cout << "Link: << req seq=" << seq;
+ lout << "Link: << req seq=" << seq;
if (verbose & LNK_DEBUG_DUMP)
- cout << " " << buff;
- cout << endl;
+ lout << " " << buff;
+ lout << endl;
}
rxSequence = txSequence = 0;
if (seq > 0) {
linkType = LINK_TYPE_EPOC;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: 3-linkType set to " << linkType << endl;
+ lout << "Link: 3-linkType set to " << linkType << endl;
// EPOC can handle extended sequence numbers
seqMask = 0x7ff;
// EPOC can handle up to 8 unacknowledged packets
@@ -440,7 +445,7 @@ receive(bufferStore buff)
seqMask = 7;
maxOutstanding = 1;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: 4-linkType set to " << linkType << endl;
+ lout << "Link: 4-linkType set to " << linkType << endl;
rxSequence = 0;
txSequence = 1; // Our ReqReq was seq 0
purgeAllQueues();
@@ -453,12 +458,12 @@ receive(bufferStore buff)
case 0x10:
// Disconnect
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: << DISC" << endl;
+ lout << "Link: << DISC" << endl;
failed = true;
break;
default:
- cerr << "Link: FATAL: Unknown packet type " << type << endl;
+ lerr << "Link: FATAL: Unknown packet type " << type << endl;
}
}
@@ -531,15 +536,15 @@ transmit(bufferStore buf)
// Request for new link
e.txcount = 4;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: >> req seq=" << e.seq << endl;
+ lout << "Link: >> req seq=" << e.seq << endl;
buf.prependByte(0x20 + e.seq);
} else {
e.txcount = 8;
if (verbose & LNK_DEBUG_LOG) {
- cout << "Link: >> dat seq=" << e.seq;
+ lout << "Link: >> dat seq=" << e.seq;
if (verbose & LNK_DEBUG_DUMP)
- cout << " " << buf;
- cout << endl;
+ lout << " " << buf;
+ lout << endl;
}
if (e.seq > 7) {
int hseq = e.seq >> 3;
@@ -615,7 +620,7 @@ retransmit()
if (i->txcount-- == 0) {
// timeout, remove packet
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: >> TRANSMIT timeout seq=" << i->seq << endl;
+ lout << "Link: >> TRANSMIT timeout seq=" << i->seq << endl;
ackWaitQueue.erase(i);
failed = true;
i--;
@@ -623,7 +628,7 @@ retransmit()
// retransmit it
i->stamp = now;
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: >> RETRANSMIT seq=" << i->seq << endl;
+ lout << "Link: >> RETRANSMIT seq=" << i->seq << endl;
p->send(i->data);
}
}
@@ -648,7 +653,7 @@ hasFailed()
bool lfailed = p->linkFailed();
if (failed || lfailed) {
if (verbose & LNK_DEBUG_LOG)
- cout << "Link: hasFailed: " << failed << ", " << lfailed << endl;
+ lout << "Link: hasFailed: " << failed << ", " << lfailed << endl;
}
failed |= lfailed;
return failed;
diff --git a/ncpd/link.h b/ncpd/link.h
index 25cd280..e8b2386 100644
--- a/ncpd/link.h
+++ b/ncpd/link.h
@@ -193,9 +193,9 @@ private:
bool failed;
Enum<link_type> linkType;
- vector<ackWaitQueueElement> ackWaitQueue;
- vector<bufferStore> holdQueue;
- vector<bufferStore> waitQueue;
+ std::vector<ackWaitQueueElement> ackWaitQueue;
+ std::vector<bufferStore> holdQueue;
+ std::vector<bufferStore> waitQueue;
bool xoff[256];
};
diff --git a/ncpd/linkchan.cc b/ncpd/linkchan.cc
index 2d9a67e..9a45158 100644
--- a/ncpd/linkchan.cc
+++ b/ncpd/linkchan.cc
@@ -32,6 +32,9 @@
using namespace std;
+extern ostream lout;
+extern ostream lerr;
+
linkChan::linkChan(ncp * _ncpController, int _ncpChannel):channel(_ncpController)
{
registerSer = 0x1234;
@@ -45,11 +48,11 @@ ncpDataCallback(bufferStore & a)
{
int len = a.getLen();
if (verbose & LINKCHAN_DEBUG_LOG) {
- cout << "linkchan: << msg ";
+ lout << "linkchan: << msg ";
if (verbose & LINKCHAN_DEBUG_DUMP)
- cout << a << endl;
+ lout << a << endl;
else
- cout << len << endl;
+ lout << len << endl;
}
if ((len >= 5) && (a.getByte(0) == 1)) {
@@ -63,16 +66,16 @@ ncpDataCallback(bufferStore & a)
strncpy(srvName, a.getString(7), 17);
if (verbose & LINKCHAN_DEBUG_LOG)
- cout << "linkchan: received registerAck: ser=0x" << hex << setw(4)
- << setfill(0) << ser << " res=" << res << " srvName=\""
+ lout << "linkchan: received registerAck: ser=0x" << hex << setw(4)
+ << setfill('0') << ser << " res=" << res << " srvName=\""
<< srvName << "\"" << endl;
while (!registerStack.empty()) {
se = registerStack.pop();
if (se.getWord(0) == ser) {
if (verbose & LINKCHAN_DEBUG_LOG)
- cout << "linkchan: found ser=0x" << hex << setw(4) <<
- setfill(0) << se.getWord(0) <<
+ lout << "linkchan: found ser=0x" << hex << setw(4) <<
+ setfill('0') << se.getWord(0) <<
" on stack -> callBack to waiting chan" << endl;
if (strlen(srvName) < 4)
strcat(srvName, ".*");
@@ -83,7 +86,7 @@ ncpDataCallback(bufferStore & a)
registerStack = newStack;
return;
}
- cerr << "linkchan: unknown message " << a.getByte(0) << endl;
+ lerr << "linkchan: unknown message " << a.getByte(0) << endl;
}
char *linkChan::
@@ -96,14 +99,14 @@ void linkChan::
ncpConnectAck()
{
if (verbose & LINKCHAN_DEBUG_LOG)
- cout << "linkchan: << cack" << endl;
+ lout << "linkchan: << cack" << endl;
}
void linkChan::
ncpConnectTerminate()
{
if (verbose & LINKCHAN_DEBUG_LOG)
- cout << "linkchan: << ctrm" << endl;
+ lout << "linkchan: << ctrm" << endl;
terminateWhenAsked();
}
diff --git a/ncpd/main.cc b/ncpd/main.cc
index a1b7dc5..6e63088 100644
--- a/ncpd/main.cc
+++ b/ncpd/main.cc
@@ -47,7 +47,9 @@
#include "packet.h"
#include "log.h"
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
#include <getopt.h>
using namespace std;
@@ -64,10 +66,15 @@ static int numScp = 0;
static socketChan *scp[257]; // MAX_CHANNELS_PSION + 1
+logbuf dlog(LOG_DEBUG, STDOUT_FILENO);
+logbuf elog(LOG_ERR, STDERR_FILENO);
+ostream lout(&dlog);
+ostream lerr(&elog);
+
static RETSIGTYPE
term_handler(int)
{
- cout << "Got SIGTERM" << endl;
+ lout << "Got SIGTERM" << endl;
signal(SIGTERM, term_handler);
active = false;
};
@@ -75,7 +82,7 @@ term_handler(int)
static RETSIGTYPE
int_handler(int)
{
- cout << "Got SIGINT" << endl;
+ lout << "Got SIGINT" << endl;
signal(SIGINT, int_handler);
active = false;
};
@@ -92,7 +99,7 @@ checkForNewSocketConnection()
next->setWatch(&iow);
// New connect
if (verbose)
- cout << "New socket connection from " << peer << endl;
+ lout << "New socket connection from " << peer << endl;
if ((numScp >= theNCP->maxLinks()) || (!theNCP->gotLinkChannel())) {
bufferStore a;
@@ -105,7 +112,7 @@ checkForNewSocketConnection()
next->sendBufferStore(a);
next->closeSocket();
if (verbose)
- cout << "rejected" << endl;
+ lout << "rejected" << endl;
} else
scp[numScp++] = new socketChan(next, theNCP);
}
@@ -230,7 +237,7 @@ link_thread(void *arg)
}
iow.watch(5, 0);
if (verbose)
- cout << "ncp: restarting\n";
+ lout << "ncp: restarting\n";
theNCP->reset();
}
}
@@ -250,6 +257,8 @@ main(int argc, char **argv)
unsigned short nverbose = 0;
struct servent *se = getservbyname("psion", "tcp");
+ dlog.setOn(false);
+ elog.setOn(false);
endservent();
if (se != 0L)
sockNum = ntohs(se->s_port);
@@ -340,13 +349,9 @@ main(int argc, char **argv)
<< strerror(errno) << endl;
else {
if (dofork || autoexit) {
- logbuf dlog(LOG_DEBUG);
- logbuf elog(LOG_ERR);
- ostream lout(&dlog);
- ostream lerr(&elog);
- cout = lout;
- cerr = lerr;
openlog("ncpd", LOG_CONS|LOG_PID, LOG_DAEMON);
+ dlog.setOn(true);
+ elog.setOn(true);
syslog(LOG_INFO,
"daemon started. Listening at %s:%d, "
"using device %s\n", host, sockNum, serialDevice);
@@ -365,17 +370,17 @@ main(int argc, char **argv)
memset(scp, 0, sizeof(scp));
theNCP = new ncp(serialDevice, baudRate, nverbose);
if (!theNCP) {
- cerr << "Could not create NCP object" << endl;
+ lerr << "Could not create NCP object" << endl;
exit(-1);
}
pthread_t thr_a, thr_b;
if (pthread_create(&thr_a, NULL, link_thread, NULL) != 0) {
- cerr << "Could not create Link thread" << endl;
+ lerr << "Could not create Link thread" << endl;
exit(-1);
}
if (pthread_create(&thr_a, NULL,
pollSocketConnections, NULL) != 0) {
- cerr << "Could not create Socket thread" << endl;
+ lerr << "Could not create Socket thread" << endl;
exit(-1);
}
while (active)
@@ -388,7 +393,7 @@ main(int argc, char **argv)
skt.closeSocket();
break;
case -1:
- cerr << "fork: " << strerror(errno) << endl;
+ lerr << "fork: " << strerror(errno) << endl;
break;
default:
exit(0);
diff --git a/ncpd/ncp.cc b/ncpd/ncp.cc
index 1780826..aff7867 100644
--- a/ncpd/ncp.cc
+++ b/ncpd/ncp.cc
@@ -40,6 +40,11 @@
#define MAX_CHANNELS_SIBO 8
#define NCP_SENDLEN 250
+using namespace std;
+
+extern ostream lout;
+extern ostream lerr;
+
ncp::ncp(const char *fname, int baud, unsigned short _verbose)
{
channelPtr = new channel*[MAX_CHANNELS_PSION + 1];
@@ -133,19 +138,19 @@ receive(bufferStore s) {
int allData = s.getByte(1);
s.discardFirstBytes(2);
if (!isValidChannel(channel)) {
- cerr << "ncp: Got message for unknown channel\n";
+ lerr << "ncp: Got message for unknown channel\n";
} else {
messageList[channel].addBuff(s);
if (allData == LAST_MESS) {
channelPtr[channel]->ncpDataCallback(messageList[channel]);
messageList[channel].init();
} else if (allData != NOT_LAST_MESS) {
- cerr << "ncp: bizarre third byte!\n";
+ lerr << "ncp: bizarre third byte!\n";
}
}
}
} else
- cerr << "Got null message\n";
+ lerr << "Got null message\n";
}
void ncp::
@@ -158,7 +163,7 @@ controlChannel(int chan, enum interControllerMessageType t, bufferStore & comman
open.addByte(t);
open.addBuff(command);
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: >> " << ctrlMsgName(t) << " " << chan << endl;
+ lout << "ncp: >> " << ctrlMsgName(t) << " " << chan << endl;
l->send(open);
}
@@ -169,7 +174,7 @@ findPcServer(const char *name)
vector<PcServer>::iterator i;
for (i = pcServers.begin(); i != pcServers.end(); i++)
if (i->getName() == name)
- return i;
+ return i->self();
}
return NULL;
}
@@ -184,7 +189,7 @@ unregisterPcServer(PcServer *server) {
if (server) {
vector<PcServer>::iterator i;
for (i = pcServers.begin(); i != pcServers.end(); i++)
- if (i == server) {
+ if (i->self() == server) {
pcServers.erase(i);
return;
}
@@ -199,7 +204,7 @@ decodeControlMessage(bufferStore & buff)
interControllerMessageType imt = (interControllerMessageType)buff.getByte(1);
buff.discardFirstBytes(2);
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: << " << ctrlMsgName(imt) << " " << remoteChan;
+ lout << "ncp: << " << ctrlMsgName(imt) << " " << remoteChan;
bufferStore b;
int localChan;
@@ -208,8 +213,8 @@ decodeControlMessage(bufferStore & buff)
case NCON_MSG_CONNECT_TO_SERVER:
if (verbose & NCP_DEBUG_LOG) {
if (verbose & NCP_DEBUG_DUMP)
- cout << " [" << buff << "]";
- cout << endl;
+ lout << " [" << buff << "]";
+ lout << endl;
}
failed = false;
@@ -224,11 +229,11 @@ decodeControlMessage(bufferStore & buff)
b.addByte(0);
controlChannel(localChan, NCON_MSG_CONNECT_RESPONSE, b);
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: Link UP" << endl;
+ lout << "ncp: Link UP" << endl;
// Create linkchan if it does not yet exist
if (!lChan) {
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: new passive linkChan" << endl;
+ lout << "ncp: new passive linkChan" << endl;
channelPtr[localChan] =
lChan = new linkChan(this, localChan);
lChan->setVerbose(verbose);
@@ -249,19 +254,19 @@ decodeControlMessage(bufferStore & buff)
if (ok) {
b.addByte(rfsv::E_PSI_GEN_NONE);
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: ACCEPT client connect" << endl;
+ lout << "ncp: ACCEPT client connect" << endl;
} else {
localChan = 0;
b.addByte(rfsv::E_PSI_FILE_NXIST);
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: REJECT client connect" << endl;
+ lout << "ncp: REJECT client connect" << endl;
}
controlChannel(localChan, NCON_MSG_CONNECT_RESPONSE, b);
// Create linkchan if it does not yet exist
if (!lChan) {
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: new active linkChan" << endl;
+ lout << "ncp: new active linkChan" << endl;
channelPtr[localChan] =
lChan = new linkChan(this, -1);
lChan->setVerbose(verbose);
@@ -277,20 +282,20 @@ decodeControlMessage(bufferStore & buff)
failed = false;
forChan = buff.getByte(0);
if (verbose & NCP_DEBUG_LOG)
- cout << " ch=" << forChan << " stat=";
+ lout << " ch=" << forChan << " stat=";
if (buff.getByte(1) == 0) {
if (verbose & NCP_DEBUG_LOG)
- cout << "OK" << endl;
+ lout << "OK" << endl;
if (isValidChannel(forChan)) {
remoteChanList[forChan] = remoteChan;
channelPtr[forChan]->ncpConnectAck();
} else {
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: message for unknown channel" << endl;
+ lout << "ncp: message for unknown channel" << endl;
}
} else {
if (verbose & NCP_DEBUG_LOG)
- cout << "Unknown " << (int) buff.getByte(1) << endl;
+ lout << "Unknown " << (int) buff.getByte(1) << endl;
if (isValidChannel(forChan))
channelPtr[forChan]->ncpConnectNak();
}
@@ -313,8 +318,8 @@ decodeControlMessage(bufferStore & buff)
protocolVersion = ver;
if (verbose & NCP_DEBUG_LOG) {
if (verbose & NCP_DEBUG_DUMP)
- cout << " [" << buff << "]";
- cout << endl;
+ lout << " [" << buff << "]";
+ lout << endl;
}
// Fake NCP version 2 for a Series 3 (behave like PsiWin 1.1)
if (ver == PV_SERIES_3) {
@@ -330,14 +335,14 @@ decodeControlMessage(bufferStore & buff)
b.addDWord(time(NULL));
controlChannel(0, NCON_MSG_NCP_INFO, b);
} else {
- cout << "ALERT!!!! Unexpected Protocol Version!! (No Series 5/3?)!" << endl;
+ lout << "ALERT!!!! Unexpected Protocol Version!! (No Series 5/3?)!" << endl;
failed = true;
}
break;
case NCON_MSG_CHANNEL_DISCONNECT:
if (verbose & NCP_DEBUG_LOG)
- cout << " ch=" << (int) buff.getByte(0) << endl;
+ lout << " ch=" << (int) buff.getByte(0) << endl;
disconnect(buff.getByte(0));
l->purgeQueue(remoteChan);
break;
@@ -349,8 +354,8 @@ decodeControlMessage(bufferStore & buff)
default:
if (verbose & NCP_DEBUG_LOG) {
if (verbose & NCP_DEBUG_DUMP)
- cout << " [" << buff << "]";
- cout << endl;
+ lout << " [" << buff << "]";
+ lout << endl;
}
}
@@ -362,7 +367,7 @@ getFirstUnusedChan()
for (int cNum = 1; cNum < maxLinks(); cNum++) {
if (channelPtr[cNum] == NULL) {
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: getFirstUnusedChan=" << cNum << endl;
+ lout << "ncp: getFirstUnusedChan=" << cNum << endl;
channelPtr[cNum] = (channel *)0xdeadbeef;
return cNum;
}
@@ -380,7 +385,7 @@ void ncp::
RegisterAck(int chan, const char *name)
{
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: RegisterAck: chan=" << chan << endl;
+ lout << "ncp: RegisterAck: chan=" << chan << endl;
for (int cNum = 1; cNum < maxLinks(); cNum++) {
channel *ch = channelPtr[cNum];
if (isValidChannel(cNum) && ch->getNcpChannel() == chan) {
@@ -389,7 +394,7 @@ RegisterAck(int chan, const char *name)
return;
}
}
- cerr << "ncp: RegisterAck: no channel to deliver" << endl;
+ lerr << "ncp: RegisterAck: no channel to deliver" << endl;
}
void ncp::
@@ -404,9 +409,9 @@ Register(channel * ch)
ch->setNcpChannel(cNum);
lChan->Register(ch);
} else
- cerr << "ncp: Out of channels in register" << endl;
+ lerr << "ncp: Out of channels in register" << endl;
} else
- cerr << "ncp: Register without established lChan" << endl;
+ lerr << "ncp: Register without established lChan" << endl;
}
int ncp::
@@ -464,12 +469,12 @@ void ncp::
disconnect(int channel)
{
if (!isValidChannel(channel)) {
- cerr << "ncp: Ignored disconnect for unknown channel #" << channel << endl;
+ lerr << "ncp: Ignored disconnect for unknown channel #" << channel << endl;
return;
}
channelPtr[channel]->terminateWhenAsked();
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: disconnect: channel=" << channel << endl;
+ lout << "ncp: disconnect: channel=" << channel << endl;
channelPtr[channel] = NULL;
bufferStore b;
b.addByte(remoteChanList[channel]);
@@ -488,7 +493,7 @@ hasFailed()
bool lfailed = l->hasFailed();
if (failed || lfailed) {
if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: hasFailed: " << failed << ", " << lfailed << endl;
+ lout << "ncp: hasFailed: " << failed << ", " << lfailed << endl;
}
failed |= lfailed;
if (failed) {
diff --git a/ncpd/ncp.h b/ncpd/ncp.h
index 5a6a1ba..fba51e5 100644
--- a/ncpd/ncp.h
+++ b/ncpd/ncp.h
@@ -46,12 +46,13 @@ class channel;
*/
class PcServer {
public:
- PcServer(ppsocket *, string _name) { name = _name; }
+ PcServer(ppsocket *, std::string _name) { name = _name; }
~PcServer() {}
bool clientConnect(int, int) { return false; }
- string getName() { return name; }
+ std::string getName() { return name; }
+ PcServer *self() { return this; }
private:
- string name;
+ std::string name;
};
class ncp {
@@ -111,7 +112,7 @@ private:
short int protocolVersion;
linkChan *lChan;
int maxChannels;
- vector<PcServer> pcServers;
+ std::vector<PcServer> pcServers;
};
#endif
diff --git a/ncpd/packet.cc b/ncpd/packet.cc
index 57b83c7..841dc54 100644
--- a/ncpd/packet.cc
+++ b/ncpd/packet.cc
@@ -149,6 +149,11 @@ static const int baud_table[] = {
};
#define BAUD_TABLE_SIZE (sizeof(baud_table) / sizeof(int))
+using namespace std;
+
+extern ostream lout;
+extern ostream lerr;
+
packet::
packet(const char *fname, int _baud, Link *_link, unsigned short _verbose)
{
@@ -227,7 +232,7 @@ void packet::
internalReset()
{
if (verbose & PKT_DEBUG_LOG)
- cout << "resetting serial connection" << endl;
+ lout << "resetting serial connection" << endl;
if (fd != -1) {
ser_exit(fd);
fd = -1;
@@ -249,7 +254,7 @@ internalReset()
fd = init_serial(devname, realBaud, 0);
if (verbose & PKT_DEBUG_LOG)
- cout << "serial connection set to " << dec << realBaud
+ lout << "serial connection set to " << dec << realBaud
<< " baud, fd=" << fd << endl;
if (fd != -1) {
lastFatal = false;
@@ -292,12 +297,12 @@ send(bufferStore &b)
long len = b.getLen();
if (verbose & PKT_DEBUG_LOG) {
- cout << "packet: >> ";
+ lout << "packet: >> ";
if (verbose & PKT_DEBUG_DUMP)
- cout << b;
+ lout << b;
else
- cout << " len=" << dec << len;
- cout << endl;
+ lout << " len=" << dec << len;
+ lout << endl;
}
for (int i = 0; i < len; i++) {
@@ -432,15 +437,15 @@ findSync()
inCRCstate = 0;
if (receivedCRC != crcIn) {
if (verbose & PKT_DEBUG_LOG)
- cout << "packet: BAD CRC" << endl;
+ lout << "packet: BAD CRC" << endl;
} else {
if (verbose & PKT_DEBUG_LOG) {
- cout << "packet: << ";
+ lout << "packet: << ";
if (verbose & PKT_DEBUG_DUMP)
- cout << rcv;
+ lout << rcv;
else
- cout << "len=" << dec << rcv.getLen();
- cout << endl;
+ lout << "len=" << dec << rcv.getLen();
+ lout << endl;
}
theLINK->receive(rcv);
}
@@ -481,7 +486,7 @@ linkFailed()
lastFatal = true;
if ((serialStatus == -1) || (arg != serialStatus)) {
if (verbose & PKT_DEBUG_HANDSHAKE)
- cout << "packet: < DTR:" << ((arg & TIOCM_DTR)?1:0)
+ lout << "packet: < DTR:" << ((arg & TIOCM_DTR)?1:0)
<< " RTS:" << ((arg & TIOCM_RTS)?1:0)
<< " DCD:" << ((arg & TIOCM_CAR)?1:0)
<< " DSR:" << ((arg & TIOCM_DSR)?1:0)
@@ -492,7 +497,7 @@ linkFailed()
if (res < 0)
lastFatal = true;
if (verbose & PKT_DEBUG_HANDSHAKE)
- cout << "packet: > DTR:" << ((arg & TIOCM_DTR)?1:0)
+ lout << "packet: > DTR:" << ((arg & TIOCM_DTR)?1:0)
<< " RTS:" << ((arg & TIOCM_RTS)?1:0)
<< " DCD:" << ((arg & TIOCM_CAR)?1:0)
<< " DSR:" << ((arg & TIOCM_DSR)?1:0)
@@ -505,9 +510,9 @@ linkFailed()
failed = true;
}
if ((verbose & PKT_DEBUG_LOG) && lastFatal)
- cout << "packet: linkFATAL\n";
+ lout << "packet: linkFATAL\n";
if ((verbose & PKT_DEBUG_LOG) && failed)
- cout << "packet: linkFAILED\n";
+ lout << "packet: linkFAILED\n";
return (lastFatal || failed);
}
diff --git a/ncpd/socketchan.cc b/ncpd/socketchan.cc
index 371befd..d0b22bf 100644
--- a/ncpd/socketchan.cc
+++ b/ncpd/socketchan.cc
@@ -34,6 +34,8 @@
#include <ppsocket.h>
#include <rfsv.h>
+extern std::ostream lerr;
+
socketChan:: socketChan(ppsocket * _skt, ncp * _ncpController):
channel(_ncpController)
{
@@ -58,7 +60,7 @@ ncpDataCallback(bufferStore & a)
if (registerName != 0) {
skt->sendBufferStore(a);
} else
- cerr << "socketchan: Connect without name!!!\n";
+ lerr << "socketchan: Connect without name!!!\n";
}
char *socketChan::
@@ -88,7 +90,7 @@ ncpCommand(bufferStore & a)
a.addStringT("Series 5");
break;
default:
- cerr << "ncpd: protocol version not known" << endl;
+ lerr << "ncpd: protocol version not known" << endl;
a.addStringT("Unknown!");
break;
}
@@ -132,7 +134,7 @@ ncpCommand(bufferStore & a)
ok = true;
}
if (!ok) {
- cerr << "socketChan:: received unknown NCP command (" << a << ")" << endl;
+ lerr << "socketChan:: received unknown NCP command (" << a << ")" << endl;
a.init();
a.addByte(rfsv::E_PSI_GEN_NSUP);
skt->sendBufferStore(a);
@@ -209,7 +211,7 @@ socketPoll()
if (memchr(a.getString(), 0, a.getLen()) == 0) {
// Not 0 terminated, -> invalid
- cerr << "ncpd: command " << a << " unrecognized."
+ lerr << "ncpd: command " << a << " unrecognized."
<< endl;
return;
}
@@ -223,7 +225,7 @@ socketPoll()
// NCP$INFO.*
if (a.getLen() > 8 && !strncmp(a.getString(), "NCP$", 4)) {
if (!ncpCommand(a))
- cerr << "ncpd: command " << a << " unrecognized."
+ lerr << "ncpd: command " << a << " unrecognized."
<< endl;
return;
}
@@ -255,7 +257,7 @@ socketPoll()
} else if (res == 1) {
if (a.getLen() > 8 && !strncmp(a.getString(), "NCP$", 4)) {
if (!ncpCommand(a))
- cerr << "ncpd: command " << a << " unrecognized."
+ lerr << "ncpd: command " << a << " unrecognized."
<< endl;
return;
}