Build fixes for Haiku - is this WIN32 stuff really needed, or can we get rid of it?

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19022 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-10-07 16:35:16 +00:00
parent d2ae268f24
commit 8c603fe7c6
7 changed files with 1557 additions and 1541 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,12 @@
// Sun, 18 Jun 2000
// Y.Takagi
#include <Alert.h>
#include <DataIO.h>
#include <Message.h>
#include <Directory.h>
#include <net/netdb.h>
#include <Alert.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
@ -56,10 +57,11 @@ IppTransport::IppTransport(BMessage *msg)
}
dir.WriteAttr(IPP_JOB_ID, B_INT32_TYPE, 0, &__jobid, sizeof(__jobid));
getusername(__user, sizeof(__user));
if (__user[0] == '\0') {
struct passwd *pwd = getpwuid(geteuid());
if (pwd != NULL && pwd->pw_name != NULL && pwd->pw_name[0])
strcpy(__user, pwd->pw_name);
else
strcpy(__user, "baron");
}
sprintf(__file, "%s/%s@ipp.%ld", spool_path, __user, __jobid);

View File

@ -1,108 +1,112 @@
// Sun, 18 Jun 2000
// Y.Takagi
#ifdef WIN32
#include <winsock.h>
#include <ostream>
#include <cstring>
#else
#include <net/socket.h>
#include <ostream.h>
#include <string.h>
#include <stdio.h>
char *itoa(int i, char *buf, int unit)
{
sprintf(buf, "%d", i);
return buf;
}
#define stricmp strcasecmp
#define strnicmp strncasecmp
#endif // WIN32
#include <list>
#include "IppURLConnection.h"
#include "IppContent.h"
IppURLConnection::IppURLConnection(const URL &Url)
: HttpURLConnection(Url)
{
__ippRequest = NULL;
__ippResponse = new IppContent;
setRequestMethod("POST");
setRequestProperty("Content-Type", "application/ipp");
setRequestProperty("Cache-Control", "no-cache");
setRequestProperty("Pragma", "no-cache");
}
IppURLConnection::~IppURLConnection()
{
if (__ippRequest) {
delete __ippRequest;
}
if (__ippResponse) {
delete __ippResponse;
}
}
void IppURLConnection::setIppRequest(IppContent *obj)
{
if (__ippRequest) {
delete __ippRequest;
}
__ippRequest = obj;
}
const IppContent *IppURLConnection::getIppResponse() const
{
return __ippResponse;
}
void IppURLConnection::setRequest()
{
if (connected) {
char buf[64];
itoa(__ippRequest->length(), buf, 10);
setRequestProperty("Content-Length", buf);
HttpURLConnection::setRequest();
}
}
void IppURLConnection::setContent()
{
if (connected && __ippRequest) {
ostream &os = getOutputStream();
os << *__ippRequest;
}
}
inline bool is_contenttype_ipp(const char *s)
{
return strnicmp(s, "application/ipp", 15) ? false : true;
}
void IppURLConnection::getContent()
{
if (connected) {
if (getResponseCode() == HTTP_OK && is_contenttype_ipp(getContentType())) {
istream &is = getInputStream();
is >> *__ippResponse;
} else {
HttpURLConnection::getContent();
}
}
}
ostream &IppURLConnection::printIppRequest(ostream &os)
{
return __ippRequest->print(os);
}
ostream &IppURLConnection::printIppResponse(ostream &os)
{
if (getResponseCode() == HTTP_OK && is_contenttype_ipp(getContentType())) {
return __ippResponse->print(os);
}
return os;
}
// Sun, 18 Jun 2000
// Y.Takagi
#ifdef WIN32
#include <winsock.h>
#include <ostream>
#include <cstring>
#else
#ifdef __HAIKU__
# include <sys/socket.h>
#else
# include <net/socket.h>
#endif
#include <ostream.h>
#include <string.h>
#include <stdio.h>
char *itoa(int i, char *buf, int unit)
{
sprintf(buf, "%d", i);
return buf;
}
#define stricmp strcasecmp
#define strnicmp strncasecmp
#endif // WIN32
#include <list>
#include "IppURLConnection.h"
#include "IppContent.h"
IppURLConnection::IppURLConnection(const URL &Url)
: HttpURLConnection(Url)
{
__ippRequest = NULL;
__ippResponse = new IppContent;
setRequestMethod("POST");
setRequestProperty("Content-Type", "application/ipp");
setRequestProperty("Cache-Control", "no-cache");
setRequestProperty("Pragma", "no-cache");
}
IppURLConnection::~IppURLConnection()
{
if (__ippRequest) {
delete __ippRequest;
}
if (__ippResponse) {
delete __ippResponse;
}
}
void IppURLConnection::setIppRequest(IppContent *obj)
{
if (__ippRequest) {
delete __ippRequest;
}
__ippRequest = obj;
}
const IppContent *IppURLConnection::getIppResponse() const
{
return __ippResponse;
}
void IppURLConnection::setRequest()
{
if (connected) {
char buf[64];
itoa(__ippRequest->length(), buf, 10);
setRequestProperty("Content-Length", buf);
HttpURLConnection::setRequest();
}
}
void IppURLConnection::setContent()
{
if (connected && __ippRequest) {
ostream &os = getOutputStream();
os << *__ippRequest;
}
}
inline bool is_contenttype_ipp(const char *s)
{
return strnicmp(s, "application/ipp", 15) ? false : true;
}
void IppURLConnection::getContent()
{
if (connected) {
if (getResponseCode() == HTTP_OK && is_contenttype_ipp(getContentType())) {
istream &is = getInputStream();
is >> *__ippResponse;
} else {
HttpURLConnection::getContent();
}
}
}
ostream &IppURLConnection::printIppRequest(ostream &os)
{
return __ippRequest->print(os);
}
ostream &IppURLConnection::printIppResponse(ostream &os)
{
if (getResponseCode() == HTTP_OK && is_contenttype_ipp(getContentType())) {
return __ippResponse->print(os);
}
return os;
}

View File

@ -1,11 +1,13 @@
// Sun, 18 Jun 2000
// Y.Takagi
#include <Alert.h>
#include <DataIO.h>
#include <Message.h>
#include <Directory.h>
#include <net/netdb.h>
#include <Alert.h>
#include <netdb.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
#include <iomanip>
@ -33,6 +35,12 @@ LprTransport::LprTransport(BMessage *msg)
__jobid = 0;
__error = false;
struct passwd *pwd = getpwuid(geteuid());
if (pwd != NULL && pwd->pw_name != NULL && pwd->pw_name[0])
strcpy(__user, pwd->pw_name);
else
strcpy(__user, "baron");
DUMP_BMESSAGE(msg);
const char *spool_path = msg->FindString(SPOOL_PATH);
@ -58,11 +66,6 @@ LprTransport::LprTransport(BMessage *msg)
}
dir.WriteAttr(LPR_JOB_ID, B_INT32_TYPE, 0, &__jobid, sizeof(__jobid));
getusername(__user, sizeof(__user));
if (__user[0] == '\0') {
strcpy(__user, "baron");
}
sprintf(__file, "%s/%s@ipp.%ld", spool_path, __user, __jobid);
__fs.open(__file, ios::in | ios::out | ios::binary | ios::trunc);
@ -79,14 +82,6 @@ LprTransport::~LprTransport()
char hostname[128];
gethostname(hostname, sizeof(hostname));
char username[128];
#ifdef WIN32
unsigned long length = sizeof(hostname);
GetUserName(username, &length);
#else
getusername(username, sizeof(username));
#endif
ostringstream cfname;
cfname << "cfA" << setw(3) << setfill('0') << __jobid << hostname;
@ -95,7 +90,7 @@ LprTransport::~LprTransport()
ostringstream cf;
cf << 'H' << hostname << '\n';
cf << 'P' << username << '\n';
cf << 'P' << __user << '\n';
cf << 'l' << dfname.str() << '\n';
cf << 'U' << dfname.str() << '\n';

View File

@ -1,217 +1,222 @@
// Sun, 18 Jun 2000
// Y.Takagi
#ifdef WIN32
#include <windows.h>
#include <winsock.h>
#include <sstream>
#else /* BeOS */
#include <cerrno>
#include <net/socket.h>
#include <net/netdb.h>
#include "_sstream"
#endif
#include <iomanip>
#include <algorithm>
#include "LpsClient.h"
#include "Socket.h"
//#include "DbgMsg.h"
#if (!__MWERKS__ || defined(WIN32))
using namespace std;
#else
#define std
#endif
#define LPS_SERVER_PORT 515
#define LPS_CLIENT_PORT_S 721
#define LPS_CLIENT_PORT_E 731
#define LPS_CHECK_QUEUE '\001'
#define LPS_PRINT_JOB '\002'
#define LPS_DISPLAY_SHORT_QUEUE '\003'
#define LPS_DISPLAY_LONG_QUEUE '\004'
#define LPS_REMOVE_JOB '\005'
#define LPS_END_TRANSFER '\000'
#define LPS_ABORT '\001'
#define LPS_RECEIVE_CONTROL_FILE '\002'
#define LPS_RECEIVE_DATA_FILE '\003'
#define LPS_OK '\0'
#define LPS_ERROR '\1'
#define LPS_NO_SPOOL_SPACE '\2'
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
#ifdef WIN32
#define EADDRINUSE WSAEADDRINUSE
#define ERRNO WSAGetLastError()
#else
#define ERRNO errno
#endif
LpsClient::LpsClient(const char *host)
: connected(false), __host(host), __sock(NULL)
{
}
LpsClient::~LpsClient()
{
close();
}
void LpsClient::connect() throw(LPSException)
{
// DBGMSG(("connect\n"));
for (int localPort = LPS_CLIENT_PORT_S ; localPort <= LPS_CLIENT_PORT_E ; localPort++) {
if (__sock) {
delete __sock;
}
__sock = new Socket(__host.c_str(), LPS_SERVER_PORT, localPort);
if (__sock->good()) {
__is = &__sock->getInputStream();
__os = &__sock->getOutputStream();
connected = true;
return;
}
}
throw(LPSException(__sock->getLastError()));
}
void LpsClient::close()
{
// DBGMSG(("close\n"));
connected = false;
if (__sock) {
delete __sock;
__sock = NULL;
}
}
void LpsClient::receiveJob(const char *printer) throw(LPSException)
{
// DBGMSG(("tell_receive_job\n"));
if (connected) {
*__os << LPS_PRINT_JOB << printer << '\n' << flush;
checkAck();
}
}
void LpsClient::receiveControlFile(int size, const char *name) throw(LPSException)
{
// DBGMSG(("tell_receive_control_file\n"));
if (connected) {
char cfname[32];
strncpy(cfname, name, sizeof(cfname));
cfname[sizeof(cfname) - 1] = '\0';
*__os << LPS_RECEIVE_CONTROL_FILE << size << ' ' << cfname << '\n' << flush;
checkAck();
}
}
void LpsClient::receiveDataFile(int size, const char *name) throw(LPSException)
{
// DBGMSG(("tell_receive_data_file\n"));
if (connected) {
char dfname[32];
strncpy(dfname, name, sizeof(dfname));
dfname[sizeof(dfname) - 1] = '\0';
*__os << LPS_RECEIVE_DATA_FILE << size << ' ' << dfname << '\n' << flush;
checkAck();
}
}
void LpsClient::transferData(const char *buffer, int size) throw(LPSException)
{
// DBGMSG(("send: %d\n", size));
if (connected) {
if (size < 0) {
size = strlen(buffer);
}
if (!__os->write(buffer, size)) {
close();
throw(LPSException("error talking to lpd server"));
}
}
}
void LpsClient::transferData(istream &is, int size) throw(LPSException)
{
// DBGMSG(("send: %d\n", size));
if (connected) {
if (size < 0) {
is.seekg(0, ios::end);
size = is.tellg();
is.seekg(0, ios::beg);
}
char c;
while (is.get(c)) {
if (!__os->put(c)) {
close();
throw(LPSException("error reading file."));
return;
}
}
}
}
void LpsClient::endTransfer() throw(LPSException)
{
// DBGMSG(("tell_end_transfer\n"));
if (connected) {
*__os << LPS_END_TRANSFER << flush;
checkAck();
}
}
void LpsClient::checkAck() throw(LPSException)
{
// DBGMSG(("check_ack\n"));
if (connected) {
char c;
if (!__is->get(c)) {
close();
throw(LPSException("server not responding."));
return;
}
switch (c) {
case LPS_OK:
break;
case LPS_ERROR:
close();
throw(LPSException("server error."));
break;
case LPS_NO_SPOOL_SPACE:
close();
throw(LPSException("not enough spool space on server."));
break;
}
}
}
// Sun, 18 Jun 2000
// Y.Takagi
#ifdef WIN32
# include <windows.h>
# include <winsock.h>
# include <sstream>
#else
# ifdef __HAIKU__
# include <sys/socket.h>
# include <netdb.h>
# else
# include <net/socket.h>
# include <net/netdb.h>
# endif
# include <errno.h>
# include "_sstream"
#endif
#include <iomanip>
#include <algorithm>
#include "LpsClient.h"
#include "Socket.h"
//#include "DbgMsg.h"
#if (!__MWERKS__ || defined(WIN32))
using namespace std;
#else
#define std
#endif
#define LPS_SERVER_PORT 515
#define LPS_CLIENT_PORT_S 721
#define LPS_CLIENT_PORT_E 731
#define LPS_CHECK_QUEUE '\001'
#define LPS_PRINT_JOB '\002'
#define LPS_DISPLAY_SHORT_QUEUE '\003'
#define LPS_DISPLAY_LONG_QUEUE '\004'
#define LPS_REMOVE_JOB '\005'
#define LPS_END_TRANSFER '\000'
#define LPS_ABORT '\001'
#define LPS_RECEIVE_CONTROL_FILE '\002'
#define LPS_RECEIVE_DATA_FILE '\003'
#define LPS_OK '\0'
#define LPS_ERROR '\1'
#define LPS_NO_SPOOL_SPACE '\2'
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
#ifdef WIN32
#define EADDRINUSE WSAEADDRINUSE
#define ERRNO WSAGetLastError()
#else
#define ERRNO errno
#endif
LpsClient::LpsClient(const char *host)
: connected(false), __host(host), __sock(NULL)
{
}
LpsClient::~LpsClient()
{
close();
}
void LpsClient::connect() throw(LPSException)
{
// DBGMSG(("connect\n"));
for (int localPort = LPS_CLIENT_PORT_S ; localPort <= LPS_CLIENT_PORT_E ; localPort++) {
if (__sock) {
delete __sock;
}
__sock = new Socket(__host.c_str(), LPS_SERVER_PORT, localPort);
if (__sock->good()) {
__is = &__sock->getInputStream();
__os = &__sock->getOutputStream();
connected = true;
return;
}
}
throw(LPSException(__sock->getLastError()));
}
void LpsClient::close()
{
// DBGMSG(("close\n"));
connected = false;
if (__sock) {
delete __sock;
__sock = NULL;
}
}
void LpsClient::receiveJob(const char *printer) throw(LPSException)
{
// DBGMSG(("tell_receive_job\n"));
if (connected) {
*__os << LPS_PRINT_JOB << printer << '\n' << flush;
checkAck();
}
}
void LpsClient::receiveControlFile(int size, const char *name) throw(LPSException)
{
// DBGMSG(("tell_receive_control_file\n"));
if (connected) {
char cfname[32];
strncpy(cfname, name, sizeof(cfname));
cfname[sizeof(cfname) - 1] = '\0';
*__os << LPS_RECEIVE_CONTROL_FILE << size << ' ' << cfname << '\n' << flush;
checkAck();
}
}
void LpsClient::receiveDataFile(int size, const char *name) throw(LPSException)
{
// DBGMSG(("tell_receive_data_file\n"));
if (connected) {
char dfname[32];
strncpy(dfname, name, sizeof(dfname));
dfname[sizeof(dfname) - 1] = '\0';
*__os << LPS_RECEIVE_DATA_FILE << size << ' ' << dfname << '\n' << flush;
checkAck();
}
}
void LpsClient::transferData(const char *buffer, int size) throw(LPSException)
{
// DBGMSG(("send: %d\n", size));
if (connected) {
if (size < 0) {
size = strlen(buffer);
}
if (!__os->write(buffer, size)) {
close();
throw(LPSException("error talking to lpd server"));
}
}
}
void LpsClient::transferData(istream &is, int size) throw(LPSException)
{
// DBGMSG(("send: %d\n", size));
if (connected) {
if (size < 0) {
is.seekg(0, ios::end);
size = is.tellg();
is.seekg(0, ios::beg);
}
char c;
while (is.get(c)) {
if (!__os->put(c)) {
close();
throw(LPSException("error reading file."));
return;
}
}
}
}
void LpsClient::endTransfer() throw(LPSException)
{
// DBGMSG(("tell_end_transfer\n"));
if (connected) {
*__os << LPS_END_TRANSFER << flush;
checkAck();
}
}
void LpsClient::checkAck() throw(LPSException)
{
// DBGMSG(("check_ack\n"));
if (connected) {
char c;
if (!__is->get(c)) {
close();
throw(LPSException("server not responding."));
return;
}
switch (c) {
case LPS_OK:
break;
case LPS_ERROR:
close();
throw(LPSException("server error."));
break;
case LPS_NO_SPOOL_SPACE:
close();
throw(LPSException("not enough spool space on server."));
break;
}
}
}

View File

@ -4,15 +4,18 @@
#ifdef WIN32
#include <winsock.h>
#else
#include <net/socket.h>
#include <net/netdb.h>
#ifdef HAVE_ARPA_INET
// inet_addr() is not defined in netdb.h anymore under BONE & later
#include <arpa/inet.h>
#endif
#ifdef __HAIKU__
# include <sys/socket.h>
#else
# include <net/socket.h>
#endif
#include <netdb.h>
#include <arpa/inet.h>
#endif // WIN32
#include <cstdio>
#include <stdio.h>
#include <unistd.h>
#include "Socket.h"
#include "SocketStream.h"

View File

@ -1,127 +1,131 @@
// Sun, 18 Jun 2000
// Y.Takagi
#ifndef WIN32
#include <net/socket.h>
#ifdef _DEBUG
#include <iostream>
#include <fstream>
#endif
#include "Socket.h"
#include "SocketStream.h"
/*-----------------------------------------------------------------*/
socketstreambuf::socketstreambuf(Socket *sock, streamsize n)
: streambuf(), __sock(sock), __alsize(n), __pu(NULL), __po(NULL)
{
setg(0, 0, 0);
setp(0, 0);
}
socketstreambuf::~socketstreambuf()
{
if (__pu)
delete [] __pu;
if (__po)
delete [] __po;
}
int socketstreambuf::underflow()
{
// cout << "***** underflow" << endl;
int bytes;
if (__pu == NULL) {
__pu = new char[__alsize];
}
bytes = __sock->read(__pu, __alsize);
if (bytes > 0) {
#ifdef _DEBUG
ofstream ofs("recv.log", ios::binary | ios::app);
ofs.write(__pu, bytes);
#endif
setg(__pu, __pu, __pu + bytes);
return *gptr();
}
return EOF;
}
int socketstreambuf::overflow(int c)
{
// cout << "***** overflow" << endl;
if (__po == NULL) {
__po = new char[__alsize];
setp(__po, __po + __alsize);
} else if (sync() != 0) {
return EOF;
}
return sputc(c);
}
int socketstreambuf::sync()
{
// cout << "***** sync" << endl;
if (__po) {
int length = pptr() - pbase();
if (length > 0) {
const char *buffer = pbase();
int bytes;
while (length > 0) {
bytes = __sock->write(buffer, length);
if (bytes <= 0) {
return EOF;
}
#ifdef _DEBUG
ofstream ofs("send.log", ios::binary | ios::app);
ofs.write(buffer, bytes);
#endif
length -= bytes;
buffer += bytes;
}
pbump(pbase() - pptr());
}
}
return 0;
}
/* -------------------------------------------------------------- */
socketstreambase::socketstreambase(Socket *sock, streamsize n)
: buf(sock, n)
{
ios::init(&this->buf);
}
/*-----------------------------------------------------------------*/
isocketstream::isocketstream(Socket *sock, streamsize n)
: socketstreambase(sock, n), istream(socketstreambase::rdbuf())
{
}
isocketstream::~isocketstream()
{
}
/*-----------------------------------------------------------------*/
osocketstream::osocketstream(Socket *sock, streamsize n)
: socketstreambase(sock, n), ostream(socketstreambase::rdbuf())
{
}
osocketstream::~osocketstream()
{
flush();
}
#endif // !WIN32
// Sun, 18 Jun 2000
// Y.Takagi
#ifndef WIN32
#ifdef __HAIKU__
# include <sys/socket.h>
#else
# include <net/socket.h>
#endif
#ifdef _DEBUG
#include <iostream>
#include <fstream>
#endif
#include "Socket.h"
#include "SocketStream.h"
/*-----------------------------------------------------------------*/
socketstreambuf::socketstreambuf(Socket *sock, streamsize n)
: streambuf(), __sock(sock), __alsize(n), __pu(NULL), __po(NULL)
{
setg(0, 0, 0);
setp(0, 0);
}
socketstreambuf::~socketstreambuf()
{
if (__pu)
delete [] __pu;
if (__po)
delete [] __po;
}
int socketstreambuf::underflow()
{
// cout << "***** underflow" << endl;
int bytes;
if (__pu == NULL) {
__pu = new char[__alsize];
}
bytes = __sock->read(__pu, __alsize);
if (bytes > 0) {
#ifdef _DEBUG
ofstream ofs("recv.log", ios::binary | ios::app);
ofs.write(__pu, bytes);
#endif
setg(__pu, __pu, __pu + bytes);
return *gptr();
}
return EOF;
}
int socketstreambuf::overflow(int c)
{
// cout << "***** overflow" << endl;
if (__po == NULL) {
__po = new char[__alsize];
setp(__po, __po + __alsize);
} else if (sync() != 0) {
return EOF;
}
return sputc(c);
}
int socketstreambuf::sync()
{
// cout << "***** sync" << endl;
if (__po) {
int length = pptr() - pbase();
if (length > 0) {
const char *buffer = pbase();
int bytes;
while (length > 0) {
bytes = __sock->write(buffer, length);
if (bytes <= 0) {
return EOF;
}
#ifdef _DEBUG
ofstream ofs("send.log", ios::binary | ios::app);
ofs.write(buffer, bytes);
#endif
length -= bytes;
buffer += bytes;
}
pbump(pbase() - pptr());
}
}
return 0;
}
/* -------------------------------------------------------------- */
socketstreambase::socketstreambase(Socket *sock, streamsize n)
: buf(sock, n)
{
ios::init(&this->buf);
}
/*-----------------------------------------------------------------*/
isocketstream::isocketstream(Socket *sock, streamsize n)
: socketstreambase(sock, n), istream(socketstreambase::rdbuf())
{
}
isocketstream::~isocketstream()
{
}
/*-----------------------------------------------------------------*/
osocketstream::osocketstream(Socket *sock, streamsize n)
: socketstreambase(sock, n), ostream(socketstreambase::rdbuf())
{
}
osocketstream::~osocketstream()
{
flush();
}
#endif // !WIN32