Update of /cvs/fresco/Fresco/Prague/src/Network
In directory purcel:/tmp/cvs-serv28781/Prague/src/Network
Modified Files:
Network.mk echo.cc ftp.cc protocol.cc smtp.cc url.cc
Log Message:
Fix up indention according to the coding style guide.
Index: Network.mk
===================================================================
RCS file: /cvs/fresco/Fresco/Prague/src/Network/Network.mk,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- Network.mk 25 Mar 2003 20:36:03 -0000 1.10
+++ Network.mk 31 Oct 2003 22:33:12 -0000 1.11
@@ -1,8 +1,8 @@
# $Id$
#
-# This source file is a part of the Berlin Project.
-# Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxxxxxxxxxxxxx>
-# http://www.berlin-consortium.org
+# This source file is a part of the Fresco Project.
+# Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxx>
+# http://www.fresco.org
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
@@ -19,36 +19,36 @@
# Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
# MA 02139, USA.
-NTW_SRC = protocol.cc echo.cc ftp.cc smtp.cc url.cc
+NTW_SRC = protocol.cc echo.cc ftp.cc smtp.cc url.cc
-NTW_DEP = $(patsubst %.cc, $(dpath)/%.d, $(NTW_SRC))
-NTW_OBJ = $(patsubst %.cc, $(opath)/%.o, $(NTW_SRC))
-NTW_GDB = $(patsubst %.cc, $(gpath)/%.o, $(NTW_SRC))
+NTW_DEP = $(patsubst %.cc, $(dpath)/%.d, $(NTW_SRC))
+NTW_OBJ = $(patsubst %.cc, $(opath)/%.o, $(NTW_SRC))
+NTW_GDB = $(patsubst %.cc, $(gpath)/%.o, $(NTW_SRC))
NTW_PRF = $(patsubst %.cc, $(ppath)/%.o, $(NTW_SRC))
-$(dpath)/%.d: Network/%.cc $(ipath)/Prague/Network/%.hh
- @echo making dependencies for $<
- if [ ! -d $(dpath) ]; then mkdir $(dpath); fi
- $(SHELL) -ec '$(CXX) $(DEPFLAGS) $(CPPFLAGS) $< \
- | sed "s/$*\\.o[ :]*/$(dpath)\/$*\\.d $(opath)\/$*\\.o
$(gpath)\/$*\\.o $(ppath)\/$*\\.o : /g" > $@'
-$(opath)/%.o: Network/%.cc
- $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(OPTFLAGS) $(SOFLAGS) -c $< -o
$@
-$(gpath)/%.o: Network/%.cc
- $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(GDBFLAGS) -c $< -o $@
-$(ppath)/%.o: Network/%.cc
- $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(OPTFLAGS) $(SOFLAGS)
$(PRFFLAGS) -c $< -o $@
+$(dpath)/%.d: Network/%.cc $(ipath)/Prague/Network/%.hh
+ @echo making dependencies for $<
+ if [ ! -d $(dpath) ]; then mkdir $(dpath); fi
+ $(SHELL) -ec '$(CXX) $(DEPFLAGS) $(CPPFLAGS) $< \
+ | sed "s/$*\\.o[ :]*/$(dpath)\/$*\\.d $(opath)\/$*\\.o
$(gpath)\/$*\\.o $(ppath)\/$*\\.o : /g" > $@'
+$(opath)/%.o: Network/%.cc
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(OPTFLAGS) $(SOFLAGS) -c $< -o $@
+$(gpath)/%.o: Network/%.cc
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(GDBFLAGS) -c $< -o $@
+$(ppath)/%.o: Network/%.cc
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(OPTFLAGS) $(SOFLAGS) $(PRFFLAGS) -c
$< -o $@
-clean: networkclean
+clean: networkclean
networkclean:
- rm -f Network/*~
- rm -f $(ipath)/Prague/Network/*~
+ rm -f Network/*~
+ rm -f $(ipath)/Prague/Network/*~
-ifneq ($(MAKECMDGOALS),config)
-ifneq ($(MAKECMDGOALS),clean)
-ifneq ($(MAKECMDGOALS),distclean)
-ifneq ($(MAKECMDGOALS),cvsclean)
+ifneq ($(MAKECMDGOALS),config)
+ifneq ($(MAKECMDGOALS),clean)
+ifneq ($(MAKECMDGOALS),distclean)
+ifneq ($(MAKECMDGOALS),cvsclean)
-include $(NTW_DEP)
endif
-endif
-endif
-endif
+endif
+endif
+endif
Index: echo.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Prague/src/Network/echo.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- echo.cc 25 Mar 2001 08:25:16 -0000 1.6
+++ echo.cc 31 Oct 2003 22:33:12 -0000 1.7
@@ -1,9 +1,9 @@
/*$Id$
*
- * This source file is a part of the Berlin Project.
+ * This source file is a part of the Fresco Project.
* Copyright (C) 1992-1996 Gnanasekaran Swaminathan <gs4t@xxxxxxxxxxxx>
- * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxxxxxxxxxxxxx>
- * http://www.berlin-consortium.org
+ * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxx>
+ * http://www.fresco.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -29,41 +29,40 @@
void echo::echobuf::serve_clients(int portno)
{
- if (protocol_name())
+ if (protocol_name())
{
- if (portno < 0) sockinetbuf::bind(sockinetaddr((unsigned long)
INADDR_ANY, "echo", protocol_name()));
- else if (portno <= 1024)
- {
- sockinetbuf::bind(sockinetaddr((unsigned long) INADDR_ANY, portno));
- sockinetaddr local = localaddr();
- std::cout << "Host: " << local.hostname() << '\n' << "Port: " <<
local.port() << std::endl;
- }
- else sockinetbuf::bind(sockinetaddr((unsigned long) INADDR_ANY, portno));
- // act as a server now
- listen(sockbuf::somaxconn);
- // commit suicide when we receive SIGTERM
- Fork::suicide_on_signal(Signal::terminate);
- for (;;)
- {
- sockinetbuf *socket = accept();
- Fork f (1, 1); // kill my children when I get terminated.
- if (f.child())
- {
- char buf [1024];
- int rcnt;
- while ((rcnt = socket->read(buf, 1024)) > 0)
- while (rcnt != 0)
- {
- int wcnt = socket->write(buf, rcnt);
- if (wcnt == -1) throw sockerr(errno);
- rcnt -= wcnt;
- }
- delete socket;
- sleep(300);
- exit (0);
- }
- else delete socket;
- }
+ if (portno < 0) sockinetbuf::bind(sockinetaddr((unsigned long)
INADDR_ANY, "echo", protocol_name()));
+ else if (portno <= 1024)
+ {
+ sockinetbuf::bind(sockinetaddr((unsigned long) INADDR_ANY,
portno));
+ sockinetaddr local = localaddr();
+ std::cout << "Host: " << local.hostname() << '\n' << "Port: " <<
local.port() << std::endl;
+ }
+ else sockinetbuf::bind(sockinetaddr((unsigned long) INADDR_ANY,
portno));
+ // act as a server now
+ listen(sockbuf::somaxconn);
+ // commit suicide when we receive SIGTERM
+ Fork::suicide_on_signal(Signal::terminate);
+ for (;;)
+ {
+ sockinetbuf *socket = accept();
+ Fork f (1, 1); // kill my children when I get terminated.
+ if (f.child())
+ {
+ char buf [1024];
+ int rcnt;
+ while ((rcnt = socket->read(buf, 1024)) > 0)
+ while (rcnt != 0)
+ {
+ int wcnt = socket->write(buf, rcnt);
+ if (wcnt == -1) throw sockerr(errno);
+ rcnt -= wcnt;
+ }
+ delete socket;
+ sleep(300);
+ exit (0);
+ }
+ else delete socket;
+ }
}
}
-
Index: ftp.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Prague/src/Network/ftp.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ftp.cc 2 Jun 2002 23:42:23 -0000 1.9
+++ ftp.cc 31 Oct 2003 22:33:12 -0000 1.10
@@ -1,9 +1,9 @@
/*$Id$
*
- * This source file is a part of the Berlin Project.
+ * This source file is a part of the Fresco Project.
* Copyright (C) 1992-1996 Gnanasekaran Swaminathan <gs4t@xxxxxxxxxxxx>
- * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxxxxxxxxxxxxx>
- * http://www.berlin-consortium.org
+ * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxx>
+ * http://www.fresco.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -31,36 +31,40 @@
#include <arpa/inet.h>
#if defined (__osf__) && defined (__DECCXX)
- extern "C" {
-# include <netdb.h>
- }
-#else
+extern "C"
+{
+# include <netdb.h>
+}
+#else
# include <netdb.h>
#endif
using namespace Prague;
-char reptype [][8] = {
- "A N",
- "A T",
- "A C",
- "E N",
- "E T",
- "E C",
- "I",
- "L "
+char reptype [][8] =
+{
+ "A N",
+ "A T",
+ "A C",
+ "E N",
+ "E T",
+ "E C",
+ "I",
+ "L "
};
-char filestru [][8] = {
- "F",
- "R",
- "P"
+char filestru [][8] =
+{
+ "F",
+ "R",
+ "P"
};
-char transmode [][8] = {
- "S",
- "B",
- "C"
+char transmode [][8] =
+{
+ "S",
+ "B",
+ "C"
};
// ftpdata waits on a port at the local machine.
@@ -69,231 +73,214 @@
// host if the istream i is set.
ftp::replycodea ftp::ftpbuf::ftpdata(int portno, std::istream *i, std::ostream
*o, const char *cmd, const char *arg)
{
- Trace trace("ftp::ftpbuf::ftpdata");
- sockinetbuf sb(sockbuf::sock_stream, 0);
- sb.bind_until_success(portno);
- useraddr(sb.localaddr());
-
- sb.listen(1);
+ Trace trace("ftp::ftpbuf::ftpdata");
+ sockinetbuf sb(sockbuf::sock_stream, 0);
+ sb.bind_until_success(portno);
+ useraddr(sb.localaddr());
- if (send_cmd(cmd, arg) >= ftp::rca_error) return ftp::rca_error;
- if (o)
+ sb.listen(1);
+
+ if (send_cmd(cmd, arg) >= ftp::rca_error) return ftp::rca_error;
+ if (o)
{
- sockinetbuf *c = sb.accept();
- // read data from c and put it in o
- char buf[1024];
- int rdsz;
- while ((rdsz = c->sys_read(buf, 1024)) != 0)
- o->write(buf, rdsz);
- delete c;
+ sockinetbuf *c = sb.accept();
+ // read data from c and put it in o
+ char buf[1024];
+ int rdsz;
+ while ((rdsz = c->sys_read(buf, 1024)) != 0)
+ o->write(buf, rdsz);
+ delete c;
}
- else if (i)
+ else if (i)
{
- sockinetbuf *c = sb.accept();
- // read data from i and send it to c
- char buf[1024];
- int rdsz;
- std::streambuf *rb = i->rdbuf();
- while ((rdsz = rb->sgetn(buf, 1024)) > 0)
- {
- int wrsz = c->sys_write(buf, rdsz);
- if (rdsz != wrsz) std::cerr << "write error\n";
- }
- delete c;
+ sockinetbuf *c = sb.accept();
+ // read data from i and send it to c
+ char buf[1024];
+ int rdsz;
+ std::streambuf *rb = i->rdbuf();
+ while ((rdsz = rb->sgetn(buf, 1024)) > 0)
+ {
+ int wrsz = c->sys_write(buf, rdsz);
+ if (rdsz != wrsz) std::cerr << "write error\n";
+ }
+ delete c;
}
- // Note: socketbuf object c must have been destructed by the time you reach
- // here.
- return get_response();
-}
+ // Note: socketbuf object c must have been destructed by the time you reach
+ // here.
+ return get_response();
+}
ftp::replycodea ftp::ftpbuf::get_response()
// get all the response that one can get and send all of them to o
{
- Trace trace("ftp::ftpbuf::get_response");
- // if o is 0, then we trash data.
- bool firstline = true;
- while (underflow() != EOF)
+ Trace trace("ftp::ftpbuf::get_response");
+ // if o is 0, then we trash data.
+ bool firstline = true;
+ while (underflow() != EOF)
{
- int n = in_avail();
- if (n < 5) continue;
- // data is of this form: 221 repsonse <CRLF> or 221-response <CRLF>
- char *q = gptr();
- char *p = q;
- // zap upto <CRLF>
- int i = 0;
- for (i = 2; i <= n; i++, p++)
- if (*p == '\r' && *(p+1) == '\n') break;
- if (_os) _os->write(q, i);
- gbump(i);
- if (firstline)
- {
- strncpy(_replycode, q, 3);
- _replycode[3] = ' ';
- if (q[3] == ' ') break;
- firstline = false;
- }
- else if (strncmp(q, _replycode, 4) == 0) break;
+ int n = in_avail();
+ if (n < 5) continue;
+ // data is of this form: 221 repsonse <CRLF> or 221-response <CRLF>
+ char *q = gptr();
+ char *p = q;
+ // zap upto <CRLF>
+ int i = 0;
+ for (i = 2; i <= n; i++, p++)
+ if (*p == '\r' && *(p+1) == '\n') break;
+ if (_os) _os->write(q, i);
+ gbump(i);
+ if (firstline)
+ {
+ strncpy(_replycode, q, 3);
+ _replycode[3] = ' ';
+ if (q[3] == ' ') break;
+ firstline = false;
+ }
+ else if (strncmp(q, _replycode, 4) == 0) break;
}
- return static_cast<replycodea>(_replycode[0]);
+ return static_cast<replycodea>(_replycode[0]);
}
ftp::replycodea ftp::ftpbuf::send_cmd(const char *cmd, const char *arg)
{
- Trace trace("ftp::ftpbuf::send_cmd");
- xsputn(cmd, std::strlen(cmd));
- if (arg)
+ Trace trace("ftp::ftpbuf::send_cmd");
+ xsputn(cmd, std::strlen(cmd));
+ if (arg)
{
- xsputn(" ", 1);
- xsputn(arg, std::strlen(arg));
+ xsputn(" ", 1);
+ xsputn(arg, std::strlen(arg));
}
- xsputn("\r\n", 2);
- sync();
- return get_response();
+ xsputn("\r\n", 2);
+ sync();
+ return get_response();
}
-ftp::ftpbuf::ftpbuf(std::ostream *out)
- : protocol::protocolbuf(protocol::tcp),
- _os(out)
+ftp::ftpbuf::ftpbuf(std::ostream *out) :
+ protocol::protocolbuf(protocol::tcp),
+ _os(out)
{
- _replycode[4] = 0;
+ _replycode[4] = 0;
}
-void ftp::ftpbuf::serve_clients(int portno)
+void ftp::ftpbuf::serve_clients(int portno) { }
// right now no server ftp class can be used as a server
-{}
ftp::replycodea ftp::ftpbuf::cd(const char *dir)
-{
- return send_cmd("CWD", dir);
-}
+{ return send_cmd("CWD", dir); }
ftp::replycodea ftp::ftpbuf::useraddr(const sockinetaddr &saa)
{
- sockinetaddr sa(saa);
- if (sa.sin_addr.s_addr == 0)
+ sockinetaddr sa(saa);
+ if (sa.sin_addr.s_addr == 0)
{
- // local host
- char hostname[64];
- if (::gethostname(hostname, 63) == -1) throw sockerr(EADDRNOTAVAIL);
- hostent *hp = gethostbyname(hostname);
- if (hp == 0) throw sockerr(EADDRNOTAVAIL);
- memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
+ // local host
+ char hostname[64];
+ if (::gethostname(hostname, 63) == -1) throw sockerr(EADDRNOTAVAIL);
+ hostent *hp = gethostbyname(hostname);
+ if (hp == 0) throw sockerr(EADDRNOTAVAIL);
+ memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
}
- struct in_addr ina = sa.sin_addr;
- int portno = ntohs(sa.sin_port);
- char *ina_p = inet_ntoa(ina);
- char addr[80];
-
- char *p = 0;
- strcpy(addr, ina_p);
- while ((p = strchr(addr, '.'))) *p = ',';
-
- int hi_portno = portno >> 8;
- int lo_portno = portno & 0xff;
-
- sprintf(addr + std::strlen(addr), ",%d,%d", hi_portno, lo_portno);
- return send_cmd("PORT", addr);
+ struct in_addr ina = sa.sin_addr;
+ int portno = ntohs(sa.sin_port);
+ char *ina_p = inet_ntoa(ina);
+ char addr[80];
+
+ char *p = 0;
+ strcpy(addr, ina_p);
+ while ((p = strchr(addr, '.'))) *p = ',';
+
+ int hi_portno = portno >> 8;
+ int lo_portno = portno & 0xff;
+
+ sprintf(addr + std::strlen(addr), ",%d,%d", hi_portno, lo_portno);
+ return send_cmd("PORT", addr);
}
ftp::replycodea ftp::ftpbuf::useraddr(const char *hostname, int portno)
-{
- return useraddr(sockinetaddr(hostname, portno));
-}
+{ return useraddr(sockinetaddr(hostname, portno)); }
ftp::replycodea ftp::ftpbuf::server_port(int portno)
{
- int hi_portno = portno >> 8;
- int lo_portno = portno & 0xff;
- char port [80];
- sprintf(port, "%d,%d", hi_portno, lo_portno);
- return send_cmd("PASV", port);
+ int hi_portno = portno >> 8;
+ int lo_portno = portno & 0xff;
+ char port [80];
+ sprintf(port, "%d,%d", hi_portno, lo_portno);
+ return send_cmd("PASV", port);
}
-
+
ftp::replycodea ftp::ftpbuf::rep_type(ftp::reptype rt)
-{
- return send_cmd("TYPE", ::reptype[int(rt)]);
-}
+{ return send_cmd("TYPE", ::reptype[int(rt)]); }
ftp::replycodea ftp::ftpbuf::file_stru(ftp::filestru fs)
-{
- return send_cmd("STRU", ::filestru[int(fs)]);
-}
+{ return send_cmd("STRU", ::filestru[int(fs)]); }
ftp::replycodea ftp::ftpbuf::trans_mode(ftp::transmode tm)
-{
- return send_cmd("STRU", ::transmode[int(tm)]);
-}
+{ return send_cmd("STRU", ::transmode[int(tm)]); }
ftp::replycodea ftp::ftpbuf::getfile(const char *rpath, const char *lpath)
{
- if (lpath == 0) lpath = rpath;
- if (rpath == 0) list();
- std::ofstream f(lpath);
- return ftpdata(10000, 0, &f, "RETR", rpath);
+ if (lpath == 0) lpath = rpath;
+ if (rpath == 0) list();
+ std::ofstream f(lpath);
+ return ftpdata(10000, 0, &f, "RETR", rpath);
}
ftp::replycodea ftp::ftpbuf::list(const char *rpath, bool justnames)
{
- if (justnames) return ftpdata(10000, 0, _os, "NLST", rpath);
- else return ftpdata(10000, 0, _os, "LIST", rpath);
+ if (justnames) return ftpdata(10000, 0, _os, "NLST", rpath);
+ else return ftpdata(10000, 0, _os, "LIST", rpath);
}
ftp::replycodea ftp::ftpbuf::putfile(const char *lpath, const char *rpath)
{
- if (rpath == 0) rpath = lpath;
- if (lpath == 0) return ftp::rca_error;
- std::ifstream f(lpath);
- return ftpdata(10000, &f, 0, "STOR", rpath);
+ if (rpath == 0) rpath = lpath;
+ if (lpath == 0) return ftp::rca_error;
+ std::ifstream f(lpath);
+ return ftpdata(10000, &f, 0, "STOR", rpath);
}
ftp::replycodea ftp::ftpbuf::putfile(const char *lpath)
{
- if (lpath == 0) return ftp::rca_error;
- std::ifstream f(lpath);
- return ftpdata(10000, &f, 0, "STOU", lpath);
+ if (lpath == 0) return ftp::rca_error;
+ std::ifstream f(lpath);
+ return ftpdata(10000, &f, 0, "STOU", lpath);
}
-
+
ftp::replycodea ftp::ftpbuf::append(const char *lpath, const char *rpath)
{
- if (lpath == 0) return ftp::rca_error;
- if (rpath == 0) rpath = lpath;
- std::ifstream f(lpath);
- return ftpdata(10000, &f, 0, "APPE", 0);
+ if (lpath == 0) return ftp::rca_error;
+ if (rpath == 0) rpath = lpath;
+ std::ifstream f(lpath);
+ return ftpdata(10000, &f, 0, "APPE", 0);
}
ftp::replycodea ftp::ftpbuf::allocate(int numbytes)
{
- char b[32];
- sprintf(b, "%d", numbytes);
- return send_cmd("ALLO", b);
+ char b[32];
+ sprintf(b, "%d", numbytes);
+ return send_cmd("ALLO", b);
}
ftp::replycodea ftp::ftpbuf::restart(int marker)
{
- char b[32];
- sprintf(b, "%d", marker);
- return send_cmd("REST", b);
+ char b[32];
+ sprintf(b, "%d", marker);
+ return send_cmd("REST", b);
}
ftp::replycodea ftp::ftpbuf::rename(const char *rpath, const char *newrpath)
{
- if (rpath == 0 || newrpath == 0) return ftp::rca_error;
- if (send_cmd("RNFR", rpath) >= ftp::rca_error) return rca_error;
- return send_cmd("RNTO", newrpath);
+ if (rpath == 0 || newrpath == 0) return ftp::rca_error;
+ if (send_cmd("RNFR", rpath) >= ftp::rca_error) return rca_error;
+ return send_cmd("RNTO", newrpath);
}
ftp::replycodea ftp::ftpbuf::rmfile(const char *rpath)
-{
- return send_cmd("DELE", rpath);
-}
+{ return send_cmd("DELE", rpath); }
ftp::replycodea ftp::ftpbuf::rmdir(const char *rpath)
-{
- return send_cmd("RMD", rpath);
-}
+{ return send_cmd("RMD", rpath); }
ftp::replycodea ftp::ftpbuf::mkdir (const char *rpath)
-{
- return send_cmd("MKD", rpath);
-}
+{ return send_cmd("MKD", rpath); }
Index: protocol.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Prague/src/Network/protocol.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- protocol.cc 25 Mar 2001 08:25:16 -0000 1.6
+++ protocol.cc 31 Oct 2003 22:33:12 -0000 1.7
@@ -1,9 +1,9 @@
/*$Id$
*
- * This source file is a part of the Berlin Project.
+ * This source file is a part of the Fresco Project.
* Copyright (C) 1992-1996 Gnanasekaran Swaminathan <gs4t@xxxxxxxxxxxx>
- * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxxxxxxxxxxxxx>
- * http://www.berlin-consortium.org
+ * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxx>
+ * http://www.fresco.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -28,33 +28,32 @@
const char *protocol::protocolbuf::protocol_name() const
{
- if (pn == protocol::tcp) return "tcp";
- if (pn == protocol::udp) return "udp";
- return 0;
+ if (pn == protocol::tcp) return "tcp";
+ if (pn == protocol::udp) return "udp";
+ return 0;
}
void protocol::protocolbuf::connect()
{
- if (pn == protocol::nil) throw sockerr(EPROTONOSUPPORT);
- sockinetbuf::connect(sockinetaddr(localaddr().hostname(), rfc_name(),
protocol_name()));
+ if (pn == protocol::nil) throw sockerr(EPROTONOSUPPORT);
+ sockinetbuf::connect(sockinetaddr(localaddr().hostname(), rfc_name(),
protocol_name()));
}
void protocol::protocolbuf::connect(unsigned long addr)
// addr is in host byte order
{
- if (pn == protocol::nil) throw sockerr(EPROTONOSUPPORT);
- sockinetbuf::connect (sockinetaddr(addr, rfc_name(), protocol_name()));
+ if (pn == protocol::nil) throw sockerr(EPROTONOSUPPORT);
+ sockinetbuf::connect (sockinetaddr(addr, rfc_name(), protocol_name()));
}
void protocol::protocolbuf::connect(const std::string &host)
{
- if (pn == protocol::nil) throw sockerr(EPROTONOSUPPORT);
- sockinetbuf::connect(sockinetaddr(host, rfc_name(), protocol_name()));
+ if (pn == protocol::nil) throw sockerr(EPROTONOSUPPORT);
+ sockinetbuf::connect(sockinetaddr(host, rfc_name(), protocol_name()));
}
void protocol::protocolbuf::connect(const std::string &host, int portno)
{
- if (pn == protocol::nil) throw sockerr(EPROTONOSUPPORT);
- sockinetbuf::connect(sockinetaddr(host, portno));
+ if (pn == protocol::nil) throw sockerr(EPROTONOSUPPORT);
+ sockinetbuf::connect(sockinetaddr(host, portno));
}
-
Index: smtp.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Prague/src/Network/smtp.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- smtp.cc 25 Mar 2001 08:25:16 -0000 1.5
+++ smtp.cc 31 Oct 2003 22:33:12 -0000 1.6
@@ -1,9 +1,9 @@
/*$Id$
*
- * This source file is a part of the Berlin Project.
+ * This source file is a part of the Fresco Project.
* Copyright (C) 1992-1996 Gnanasekaran Swaminathan <gs4t@xxxxxxxxxxxx>
- * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxxxxxxxxxxxxx>
- * http://www.berlin-consortium.org
+ * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxx>
+ * http://www.fresco.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -32,97 +32,93 @@
void smtp::smtpbuf::get_response()
// get all the response that one can get and send all of them to o
{
- // if o is 0, then we trash data.
- while (underflow() != EOF)
+ // if o is 0, then we trash data.
+ while (underflow() != EOF)
{
- int n = in_avail();
- if (n < 5) continue;
- // data is of this form: 221 repsonse <CRLF> or 221-response <CRLF>
- char* q = gptr ();
- char* p = q;
- // zap upto <CRLF>
- for (int i = 2; i <= n; i++, p++)
- if (*p == '\r' && *(p+1) == '\n')
- {
- if(_os) _os->write(q, i);
- gbump(i);
- break;
- }
- if (q[3] != '-') break;
+ int n = in_avail();
+ if (n < 5) continue;
+ // data is of this form: 221 repsonse <CRLF> or 221-response <CRLF>
+ char* q = gptr ();
+ char* p = q;
+ // zap upto <CRLF>
+ for (int i = 2; i <= n; i++, p++)
+ if (*p == '\r' && *(p+1) == '\n')
+ {
+ if(_os) _os->write(q, i);
+ gbump(i);
+ break;
+ }
+ if (q[3] != '-') break;
}
}
void smtp::smtpbuf::send_cmd(const std::string &cmd, const std::string &s,
const std::string &p)
{
- xsputn(cmd.c_str(), cmd.length());
- if (s.length()) xsputn(s.c_str(), s.length());
- if (p.length()) xsputn(p.c_str(), p.length());
- xsputn("\r\n", 2);
- sync();
- if (_os) get_response();
+ xsputn(cmd.c_str(), cmd.length());
+ if (s.length()) xsputn(s.c_str(), s.length());
+ if (p.length()) xsputn(p.c_str(), p.length());
+ xsputn("\r\n", 2);
+ sync();
+ if (_os) get_response();
}
void smtp::smtpbuf::helo()
{
- if (_os) get_response();
- send_cmd("HELO ", localaddr().hostname());
+ if (_os) get_response();
+ send_cmd("HELO ", localaddr().hostname());
}
void smtp::smtpbuf::mail(const std::string &from)
{
- if (from.length()) send_cmd("MAIL FROM:<", from, ">");
- else send_cmd("MAIL FROM:<>");
+ if (from.length()) send_cmd("MAIL FROM:<", from, ">");
+ else send_cmd("MAIL FROM:<>");
}
void smtp::smtpbuf::rcpt(const std::string &to)
-{
- if (to.length()) send_cmd("RCPT TO:<", to, ">");
-}
+{ if (to.length()) send_cmd("RCPT TO:<", to, ">"); }
void smtp::smtpbuf::help(const std::string &s)
-{
- send_cmd("HELP ", s);
-}
+{ send_cmd("HELP ", s); }
void smtp::smtpbuf::send_buf(const char *buf, int len)
{
- if (buf == 0 || len <= 0) return;
- // send line by line
- const unsigned char *p = (const unsigned char*) buf;
- if (*p == '.') sputc((unsigned int) '.');
- for (int i = 0; i < len; i++, p++)
+ if (buf == 0 || len <= 0) return;
+ // send line by line
+ const unsigned char *p = (const unsigned char*) buf;
+ if (*p == '.') sputc((unsigned int) '.');
+ for (int i = 0; i < len; i++, p++)
{
- if (*p == '\n')
- {
- sputc((unsigned int) '\r');
- sputc(*p);
- if(*(p+1) == '.') sputc((unsigned int) '.');
- }
- else sputc(*p);
+ if (*p == '\n')
+ {
+ sputc((unsigned int) '\r');
+ sputc(*p);
+ if(*(p+1) == '.') sputc((unsigned int) '.');
+ }
+ else sputc(*p);
}
}
void smtp::smtpbuf::data(const char *buf, int len)
{
- data ();
- send_buf(buf, len);
- xsputn("\r\n.\r\n", 5);
- sync();
- if (_os) get_response();
+ data ();
+ send_buf(buf, len);
+ xsputn("\r\n.\r\n", 5);
+ sync();
+ if (_os) get_response();
}
void smtp::smtpbuf::data(const std::string &filename)
{
- data ();
- int fd = 0;
- char buf [1024];
- int rcnt;
- if (filename.empty() || (fd = ::open(filename.c_str(), O_RDONLY )) == -1) fd
= 0;
+ data ();
+ int fd = 0;
+ char buf [1024];
+ int rcnt;
+ if (filename.empty() || (fd = ::open(filename.c_str(), O_RDONLY )) == -1)
fd = 0;
- while ((rcnt = ::read(fd, buf, 1024)) > 0) send_buf(buf, rcnt);
- xsputn("\r\n.\r\n", 5);
- sync();
- if (_os) get_response();
+ while ((rcnt = ::read(fd, buf, 1024)) > 0) send_buf(buf, rcnt);
+ xsputn("\r\n.\r\n", 5);
+ sync();
+ if (_os) get_response();
}
int smtp::get_response(char *buf, int len)
@@ -130,29 +126,26 @@
// return 1 if output continues after this line
// return 0 if output has terminated
{
- if (len < 8)
+ if (len < 8)
{
- getline(buf, len);
- return 0;
+ getline(buf, len);
+ return 0;
}
- buf[3] = 0;
- getline(buf, len);
- return buf[3] == '-';
+ buf[3] = 0;
+ getline(buf, len);
+ return buf[3] == '-';
}
-
+
std::ostream &operator << (std::ostream &os, smtp &s)
{
- char buf[1024];
- int cont = 1;
- while (cont)
+ char buf[1024];
+ int cont = 1;
+ while (cont)
{
- cont = s.get_response(buf, 1024);
- os << buf << std::endl;
+ cont = s.get_response(buf, 1024);
+ os << buf << std::endl;
}
- return os;
-}
-
-void smtp::smtpbuf::serve_clients(int portno)
-{
+ return os;
}
+void smtp::smtpbuf::serve_clients(int portno) { }
Index: url.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Prague/src/Network/url.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- url.cc 25 Mar 2001 08:25:16 -0000 1.4
+++ url.cc 31 Oct 2003 22:33:12 -0000 1.5
@@ -1,8 +1,8 @@
/*$Id$
*
- * This source file is a part of the Berlin Project.
- * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxxxxxxxxxxxxx>
- * http://www.berlin-consortium.org
+ * This source file is a part of the Fresco Project.
+ * Copyright (C) 1999 Stefan Seefeld <stefan@xxxxxxxxxx>
+ * http://www.fresco.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -27,278 +27,254 @@
void url::parse(const std::string &tt)
{
- std::string t(tt);
- /*
- * search for a fragment identifier.
- */
- int i = t.find('#');
- if (i >= 0)
+ std::string t(tt);
+ // search for a fragment identifier.
+ int i = t.find('#');
+ if (i >= 0)
{
- f = t.substr(i + 1);
- t.erase(i, t.length() - i);
+ f = t.substr(i + 1);
+ t.erase(i, t.length() - i);
}
- /*
- * search for a scheme
- */
- regex reg("^[a-zA-Z0-9\\+\\.\\-]+:");
- i = reg.search(t);
- if (i >= 0)
+ // search for a scheme
+ regex reg("^[a-zA-Z0-9\\+\\.\\-]+:");
+ i = reg.search(t);
+ if (i >= 0)
{
- int j = t.find(':');
- s = t.substr(0, j);
- t.erase(0, j + 1);
+ int j = t.find(':');
+ s = t.substr(0, j);
+ t.erase(0, j + 1);
}
- if (t[0] == '/' && t[1] == '/')
+ if (t[0] == '/' && t[1] == '/')
{
- /*
- * common internet scheme syntax
- */
- t.erase(0, 2);
- i = t.find('/');
- std::string nl;
- nl = t.substr(0, i);
- t.erase(0, i);
- if ((i = nl.find('@')) >= 0)
- {
- std::string login = nl.substr(0, i);
- nl.erase(0, i + 1);
- if ((i = login.find(':')) >= 0)
- {
- u = login.substr(0, i);
- pw = login.substr(login.length() - i);
- }
- else u = login;
- }
- if ((i = nl.find(':')) >= 0)
- {
- std::string portstr = nl.substr(i + 1);
- nl.erase(i, nl.length());
- po = atoi(portstr.c_str());
- }
- h = nl;
+ // common internet scheme syntax
+ t.erase(0, 2);
+ i = t.find('/');
+ std::string nl;
+ nl = t.substr(0, i);
+ t.erase(0, i);
+ if ((i = nl.find('@')) >= 0)
+ {
+ std::string login = nl.substr(0, i);
+ nl.erase(0, i + 1);
+ if ((i = login.find(':')) >= 0)
+ {
+ u = login.substr(0, i);
+ pw = login.substr(login.length() - i);
+ }
+ else u = login;
+ }
+ if ((i = nl.find(':')) >= 0)
+ {
+ std::string portstr = nl.substr(i + 1);
+ nl.erase(i, nl.length());
+ po = atoi(portstr.c_str());
+ }
+ h = nl;
}
- /*
- * search for a query.
- */
- if ((i = t.find('?')) >= 0)
+ // search for a query.
+ if ((i = t.find('?')) >= 0)
{
- q = t.substr(t.length() - i - 1);
- t.erase(i, t.length());
+ q = t.substr(t.length() - i - 1);
+ t.erase(i, t.length());
}
- /*
- * search for parameters.
- */
- if ((i = t.find(';')) >= 0)
+ // search for parameters.
+ if ((i = t.find(';')) >= 0)
{
- pa = t.substr(t.length() - i - 1);
- t.erase(i, t.length());
+ pa = t.substr(t.length() - i - 1);
+ t.erase(i, t.length());
}
- /*
- * the rest is the path.
- */
- p = t;
- if (s.length()) std::cout << "scheme\t:" << s << std::endl;
- if (u.length()) std::cout << "user\t:" << u << std::endl;
- if (pw.length()) std::cout << "password\t:" << pw << std::endl;
- if (h.length()) std::cout << "hostname\t:" << h << std::endl;
- if (po >= 0) std::cout << "port\t:" << po << std::endl;
- if (p.length()) std::cout << "path\t:" << p << std::endl;
- if (f.length()) std::cout << "fraction\t:" << f << std::endl;
- if (q.length()) std::cout << "query\t:" << q << std::endl;
- if (pa.length()) std::cout << "parameters\t:" << pa << std::endl;
+ // the rest is the path.
+ p = t;
+ if (s.length()) std::cout << "scheme\t:" << s << std::endl;
+ if (u.length()) std::cout << "user\t:" << u << std::endl;
+ if (pw.length()) std::cout << "password\t:" << pw << std::endl;
+ if (h.length()) std::cout << "hostname\t:" << h << std::endl;
+ if (po >= 0) std::cout << "port\t:" << po << std::endl;
+ if (p.length()) std::cout << "path\t:" << p << std::endl;
+ if (f.length()) std::cout << "fraction\t:" << f << std::endl;
+ if (q.length()) std::cout << "query\t:" << q << std::endl;
+ if (pa.length()) std::cout << "parameters\t:" << pa << std::endl;
}
-url::url(const std::string &t)
- : po(-1)
-{
- parse(t);
-}
+url::url(const std::string &t) : po(-1) { parse(t); }
-url::url(const url &absurl, const std::string &relurl)
- : po(-1)
+url::url(const url &absurl, const std::string &relurl) :
+ po(-1)
{
- parse(relurl);
-// if (method()) return;
-// method = absurl->method();
-// if (!hostname())
-// {
-// _user = absurl->user();
-// _password = absurl->password();
-// _hostname = absurl->hostname();
-// _port = absurl->port();
-// if (!path() || _path[0] != '/')
-// {
-// if (!path())
-// {
-// _path = absurl->path();
-// if (!parameters())
-// {
-// _parameters = absurl->parameters();
-// if (!query()) _query = absUrl->query();
-// }
-// }
-// else
-// {
-// // Step 6...
-// std::string newPath;
-// int idx1 = 0;
-// newPath = absurl->path();
-// if ((idx1 = newPath.findRev('/')) >= 0) newPath.truncate(idx1 +
1);
-// else newPath.truncate( 0 );
-// newPath += path();
-// idx1 = 0;
-// if (newPath[0] == '/') idx1++;
-// while (idx1 < int(newPath.length()))
-// {
-// if (newPath.mid(idx1, 2) == "./")
-// {
-// newPath.erase(idx1, 2);
-// //printf( "Url::Url() -- (1)path = '%s'\n", (const
char*)newPath );
-// }
-// else
-// {
-// idx1 = newPath.find('/', idx1 + 1);
-// if (idx1 < 0) idx1 = newPath.length();
-// else idx1++;
-// }
-// }
-// if (newPath.substr(2) == "/.")
-// {
-// newPath.truncate(newPath.length() - 1);
-// //printf( "Url::Url() -- (2)path = '%s'\n", (const
char*)newPath );
-// }
-// bool found = true;
-// while (found)
-// {
-// found = false;
-// idx1 = 0;
-// if (newPath.left(1) == '/') idx1++;
-// while (!found && (idx1 < int(newPath.length())))
-// {
-// int idx2 = newPath.find('/', idx1 + 1);
-// if (idx2 > idx1 && newPath.mid(idx1, 3) != "../" &&
newPath.mid(idx2, 4) == "/../")
-// {
-// found = true;
-// newPath.erase(idx1, idx2 - idx1 + 4);
-// //printf( "Url::Url() -- (3)path = '%s'\n", (const
char*)newPath );
-// }
-// else
-// {
-// if (idx2 < 0) idx1 = newPath.length();
-// else idx1 = idx2 + 1;
-// }
-// }
-// }
-// if (newPath.substr(3) == "/..")
-// {
-// idx1 = newPath.findRev('/', newPath.length() - 4) + 1;
-// if (newPath.mid(idx1, 3) != "../")
-// {
-// newPath.truncate(idx1);
-// //printf( "Url::Url() -- (4)path = '%s'\n", (const
char*)newPath );
-// }
-// }
-// path = newPath;
-// }
-// }
-// }
-}
+ parse(relurl);
+ // if (method()) return;
+ // method = absurl->method();
+ // if (!hostname())
+ // {
+ // _user = absurl->user();
+ // _password = absurl->password();
+ // _hostname = absurl->hostname();
+ // _port = absurl->port();
+ // if (!path() || _path[0] != '/')
+ // {
+ // if (!path())
+ // {
+ // _path = absurl->path();
+ // if (!parameters())
+ // {
+ // _parameters = absurl->parameters();
+ // if (!query()) _query = absUrl->query();
+ // }
+ // }
+ // else
+ // {
+ // // Step 6...
+ // std::string newPath;
+ // int idx1 = 0;
+ // newPath = absurl->path();
+ // if ((idx1 = newPath.findRev('/')) >= 0)
newPath.truncate(idx1 + 1);
+ // else newPath.truncate( 0 );
+ // newPath += path();
+ // idx1 = 0;
+ // if (newPath[0] == '/') idx1++;
+ // while (idx1 < int(newPath.length()))
+ // {
+ // if (newPath.mid(idx1, 2) == "./")
+ // {
+ // newPath.erase(idx1, 2);
+ // // printf( "Url::Url() -- (1)path = '%s'\n", (const
char*)newPath );
+ // }
+ // else
+ // {
+ // idx1 = newPath.find('/', idx1 + 1);
+ // if (idx1 < 0) idx1 = newPath.length();
+ // else idx1++;
+ // }
+ // }
+ // if (newPath.substr(2) == "/.")
+ // {
+ // newPath.truncate(newPath.length() - 1);
+ // // printf( "Url::Url() -- (2)path = '%s'\n", (const
char*)newPath );
+ // }
+ // bool found = true;
+ // while (found)
+ // {
+ // found = false;
+ // idx1 = 0;
+ // if (newPath.left(1) == '/') idx1++;
+ // while (!found && (idx1 < int(newPath.length())))
+ // {
+ // int idx2 = newPath.find('/', idx1 + 1);
+ // if (idx2 > idx1 && newPath.mid(idx1, 3) != "../" &&
newPath.mid(idx2, 4) == "/../")
+ // {
+ // found = true;
+ // newPath.erase(idx1, idx2 - idx1 + 4);
+ // // printf( "Url::Url() -- (3)path = '%s'\n",
(const char*)newPath );
+ // }
+ // else
+ // {
+ // if (idx2 < 0) idx1 = newPath.length();
+ // else idx1 = idx2 + 1;
+ // }
+ // }
+ // }
+ // if (newPath.substr(3) == "/..")
+ // {
+ // idx1 = newPath.findRev('/', newPath.length() - 4) + 1;
+ // if (newPath.mid(idx1, 3) != "../")
+ // {
+ // newPath.truncate(idx1);
+ // // printf( "Url::Url() -- (4)path = '%s'\n", (const
char*)newPath );
+ // }
+ // }
+ // path = newPath;
+ // }
+ // }
+ // }
+ }
-/*
- * @Method{}
- *
- * @Description{Return the fully qualified URL as a std::string}
- */
-// url::operator const std::string &() const
-// {
-// std::string tmp;
-// if (method())
-// {
-// tmp += method();
-// tmp += ":";
-// }
-// if (hostname())
-// {
-// tmp += "//";
-// if (user())
-// {
-// tmp += user();
-// if (password())
-// {
-// tmp += ":";
-// tmp += password();
-// }
-// tmp += "@";
-// }
-// tmp += hostname();
-// if (port() >= 0)
-// {
-// tmp += ":";
-// tmp += std::string().setNum(port());
-// }
-// if (path() && path()[0] != '/')
-// {
-// //printf( "Url::url() -- path() = '%s'\n", path() );
-// tmp += "/";
-// }
-// }
-// tmp += path();
-// if (parameters())
-// {
-// tmp += ";";
-// tmp += parameters();
-// }
-// if (query())
-// {
-// tmp += "?";
-// tmp += query();
-// }
-// if (fragment())
-// {
-// tmp += "#";
-// tmp += fragment();
-// }
-// return tmp;
-// }
+ //. @Method{}
+ //.
+ //. @Description{Return the fully qualified URL as a std::string}
+ // url::operator const std::string &() const
+ // {
+ // std::string tmp;
+ // if (method())
+ // {
+ // tmp += method();
+ // tmp += ":";
+ // }
+ // if (hostname())
+ // {
+ // tmp += "//";
+ // if (user())
+ // {
+ // tmp += user();
+ // if (password())
+ // {
+ // tmp += ":";
+ // tmp += password();
+ // }
+ // tmp += "@";
+ // }
+ // tmp += hostname();
+ // if (port() >= 0)
+ // {
+ // tmp += ":";
+ // tmp += std::string().setNum(port());
+ // }
+ // if (path() && path()[0] != '/')
+ // {
+ // // printf( "Url::url() -- path() = '%s'\n", path() );
+ // tmp += "/";
+ // }
+ // }
+ // tmp += path();
+ // if (parameters())
+ // {
+ // tmp += ";";
+ // tmp += parameters();
+ // }
+ // if (query())
+ // {
+ // tmp += "?";
+ // tmp += query();
+ // }
+ // if (fragment())
+ // {
+ // tmp += "#";
+ // tmp += fragment();
+ // }
+ // return tmp;
+ // }
void url::encode(std::string &s)
{
- unsigned int i;
- unsigned char c;
- std::string escaped;
- for (i = 0; i < s.length(); i++)
+ unsigned int i;
+ unsigned char c;
+ std::string escaped;
+ for (i = 0; i < s.length(); i++)
{
- c = s[i];
- if (c < 32 ||
- c > 126 ||
- isspace(c) ||
- strchr("<>\"#%{}|\\^~[]'`;/?:@=&", c))
- {
- // Escape the character.
-// escaped.sprintf("%%%02X", c);
-// s.replace( i, 1, escaped);
- i += 2;
- }
+ c = s[i];
+ if (c < 32 || c > 126 || isspace(c) ||
strchr("<>\"#%{}|\\^~[]'`;/?:@=&", c))
+ {
+ // Escape the character.
+ // escaped.sprintf("%%%02X", c);
+ // s.replace( i, 1, escaped);
+ i += 2;
+ }
}
}
void url::decode(std::string &s)
{
- unsigned int i;
- unsigned char c;
- std::string escaped;
- for (i = 0; i < s.length(); i++)
+ unsigned int i;
+ unsigned char c;
+ std::string escaped;
+ for (i = 0; i < s.length(); i++)
{
- c = s[i];
- if (c < 32 ||
- c > 126 ||
- isspace(c) ||
- strchr("<>\"#%{}|\\^~[]'`;/?:@=&", c))
- {
- // Escape the character.
-// escaped.sprintf("%%%02X", c);
-// s.replace( i, 1, escaped);
- i += 2;
- }
+ c = s[i];
+ if (c < 32 || c > 126 || isspace(c) ||
strchr("<>\"#%{}|\\^~[]'`;/?:@=&", c))
+ {
+ // Escape the character.
+ // escaped.sprintf("%%%02X", c);
+ // s.replace( i, 1, escaped);
+ i += 2;
+ }
}
}
|