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
@@ -1,11 +1,12 @@
// Sun, 18 Jun 2000 // Sun, 18 Jun 2000
// Y.Takagi // Y.Takagi
#include <Alert.h>
#include <DataIO.h> #include <DataIO.h>
#include <Message.h> #include <Message.h>
#include <Directory.h> #include <Directory.h>
#include <net/netdb.h>
#include <Alert.h> #include <pwd.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
@@ -56,10 +57,11 @@ IppTransport::IppTransport(BMessage *msg)
} }
dir.WriteAttr(IPP_JOB_ID, B_INT32_TYPE, 0, &__jobid, sizeof(__jobid)); dir.WriteAttr(IPP_JOB_ID, B_INT32_TYPE, 0, &__jobid, sizeof(__jobid));
getusername(__user, sizeof(__user)); struct passwd *pwd = getpwuid(geteuid());
if (__user[0] == '\0') { if (pwd != NULL && pwd->pw_name != NULL && pwd->pw_name[0])
strcpy(__user, pwd->pw_name);
else
strcpy(__user, "baron"); strcpy(__user, "baron");
}
sprintf(__file, "%s/%s@ipp.%ld", spool_path, __user, __jobid); sprintf(__file, "%s/%s@ipp.%ld", spool_path, __user, __jobid);
@@ -1,108 +1,112 @@
// Sun, 18 Jun 2000 // Sun, 18 Jun 2000
// Y.Takagi // Y.Takagi
#ifdef WIN32 #ifdef WIN32
#include <winsock.h> #include <winsock.h>
#include <ostream> #include <ostream>
#include <cstring> #include <cstring>
#else #else
#include <net/socket.h> #ifdef __HAIKU__
#include <ostream.h> # include <sys/socket.h>
#include <string.h> #else
#include <stdio.h> # include <net/socket.h>
char *itoa(int i, char *buf, int unit) #endif
{ #include <ostream.h>
sprintf(buf, "%d", i); #include <string.h>
return buf; #include <stdio.h>
} char *itoa(int i, char *buf, int unit)
#define stricmp strcasecmp {
#define strnicmp strncasecmp sprintf(buf, "%d", i);
#endif // WIN32 return buf;
}
#include <list> #define stricmp strcasecmp
#include "IppURLConnection.h" #define strnicmp strncasecmp
#include "IppContent.h" #endif // WIN32
IppURLConnection::IppURLConnection(const URL &Url) #include <list>
: HttpURLConnection(Url) #include "IppURLConnection.h"
{ #include "IppContent.h"
__ippRequest = NULL;
__ippResponse = new IppContent; IppURLConnection::IppURLConnection(const URL &Url)
setRequestMethod("POST"); : HttpURLConnection(Url)
setRequestProperty("Content-Type", "application/ipp"); {
setRequestProperty("Cache-Control", "no-cache"); __ippRequest = NULL;
setRequestProperty("Pragma", "no-cache"); __ippResponse = new IppContent;
} setRequestMethod("POST");
setRequestProperty("Content-Type", "application/ipp");
IppURLConnection::~IppURLConnection() setRequestProperty("Cache-Control", "no-cache");
{ setRequestProperty("Pragma", "no-cache");
if (__ippRequest) { }
delete __ippRequest;
} IppURLConnection::~IppURLConnection()
{
if (__ippResponse) { if (__ippRequest) {
delete __ippResponse; delete __ippRequest;
} }
}
if (__ippResponse) {
void IppURLConnection::setIppRequest(IppContent *obj) delete __ippResponse;
{ }
if (__ippRequest) { }
delete __ippRequest;
} void IppURLConnection::setIppRequest(IppContent *obj)
__ippRequest = obj; {
} if (__ippRequest) {
delete __ippRequest;
}
const IppContent *IppURLConnection::getIppResponse() const __ippRequest = obj;
{ }
return __ippResponse;
}
const IppContent *IppURLConnection::getIppResponse() const
void IppURLConnection::setRequest() {
{ return __ippResponse;
if (connected) { }
char buf[64];
itoa(__ippRequest->length(), buf, 10); void IppURLConnection::setRequest()
setRequestProperty("Content-Length", buf); {
HttpURLConnection::setRequest(); if (connected) {
} char buf[64];
} itoa(__ippRequest->length(), buf, 10);
setRequestProperty("Content-Length", buf);
void IppURLConnection::setContent() HttpURLConnection::setRequest();
{ }
if (connected && __ippRequest) { }
ostream &os = getOutputStream();
os << *__ippRequest; void IppURLConnection::setContent()
} {
} if (connected && __ippRequest) {
ostream &os = getOutputStream();
inline bool is_contenttype_ipp(const char *s) os << *__ippRequest;
{ }
return strnicmp(s, "application/ipp", 15) ? false : true; }
}
inline bool is_contenttype_ipp(const char *s)
void IppURLConnection::getContent() {
{ return strnicmp(s, "application/ipp", 15) ? false : true;
if (connected) { }
if (getResponseCode() == HTTP_OK && is_contenttype_ipp(getContentType())) {
istream &is = getInputStream(); void IppURLConnection::getContent()
is >> *__ippResponse; {
} else { if (connected) {
HttpURLConnection::getContent(); 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::printIppRequest(ostream &os)
ostream &IppURLConnection::printIppResponse(ostream &os) {
{ return __ippRequest->print(os);
if (getResponseCode() == HTTP_OK && is_contenttype_ipp(getContentType())) { }
return __ippResponse->print(os);
} ostream &IppURLConnection::printIppResponse(ostream &os)
return os; {
} if (getResponseCode() == HTTP_OK && is_contenttype_ipp(getContentType())) {
return __ippResponse->print(os);
}
return os;
}
@@ -1,11 +1,13 @@
// Sun, 18 Jun 2000 // Sun, 18 Jun 2000
// Y.Takagi // Y.Takagi
#include <Alert.h>
#include <DataIO.h> #include <DataIO.h>
#include <Message.h> #include <Message.h>
#include <Directory.h> #include <Directory.h>
#include <net/netdb.h>
#include <Alert.h> #include <netdb.h>
#include <pwd.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <iomanip> #include <iomanip>
@@ -33,6 +35,12 @@ LprTransport::LprTransport(BMessage *msg)
__jobid = 0; __jobid = 0;
__error = false; __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); DUMP_BMESSAGE(msg);
const char *spool_path = msg->FindString(SPOOL_PATH); 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)); 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); sprintf(__file, "%s/%s@ipp.%ld", spool_path, __user, __jobid);
__fs.open(__file, ios::in | ios::out | ios::binary | ios::trunc); __fs.open(__file, ios::in | ios::out | ios::binary | ios::trunc);
@@ -79,14 +82,6 @@ LprTransport::~LprTransport()
char hostname[128]; char hostname[128];
gethostname(hostname, sizeof(hostname)); 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; ostringstream cfname;
cfname << "cfA" << setw(3) << setfill('0') << __jobid << hostname; cfname << "cfA" << setw(3) << setfill('0') << __jobid << hostname;
@@ -95,7 +90,7 @@ LprTransport::~LprTransport()
ostringstream cf; ostringstream cf;
cf << 'H' << hostname << '\n'; cf << 'H' << hostname << '\n';
cf << 'P' << username << '\n'; cf << 'P' << __user << '\n';
cf << 'l' << dfname.str() << '\n'; cf << 'l' << dfname.str() << '\n';
cf << 'U' << dfname.str() << '\n'; cf << 'U' << dfname.str() << '\n';
+222 -217
View File
@@ -1,217 +1,222 @@
// Sun, 18 Jun 2000 // Sun, 18 Jun 2000
// Y.Takagi // Y.Takagi
#ifdef WIN32 #ifdef WIN32
#include <windows.h> # include <windows.h>
#include <winsock.h> # include <winsock.h>
#include <sstream> # include <sstream>
#else /* BeOS */ #else
#include <cerrno> # ifdef __HAIKU__
#include <net/socket.h> # include <sys/socket.h>
#include <net/netdb.h> # include <netdb.h>
#include "_sstream" # else
#endif # include <net/socket.h>
# include <net/netdb.h>
#include <iomanip> # endif
#include <algorithm> # include <errno.h>
#include "LpsClient.h" # include "_sstream"
#include "Socket.h" #endif
//#include "DbgMsg.h"
#include <iomanip>
#if (!__MWERKS__ || defined(WIN32)) #include <algorithm>
using namespace std; #include "LpsClient.h"
#else #include "Socket.h"
#define std //#include "DbgMsg.h"
#endif
#if (!__MWERKS__ || defined(WIN32))
#define LPS_SERVER_PORT 515 using namespace std;
#define LPS_CLIENT_PORT_S 721 #else
#define LPS_CLIENT_PORT_E 731 #define std
#endif
#define LPS_CHECK_QUEUE '\001'
#define LPS_PRINT_JOB '\002' #define LPS_SERVER_PORT 515
#define LPS_DISPLAY_SHORT_QUEUE '\003' #define LPS_CLIENT_PORT_S 721
#define LPS_DISPLAY_LONG_QUEUE '\004' #define LPS_CLIENT_PORT_E 731
#define LPS_REMOVE_JOB '\005'
#define LPS_END_TRANSFER '\000' #define LPS_CHECK_QUEUE '\001'
#define LPS_ABORT '\001' #define LPS_PRINT_JOB '\002'
#define LPS_RECEIVE_CONTROL_FILE '\002' #define LPS_DISPLAY_SHORT_QUEUE '\003'
#define LPS_RECEIVE_DATA_FILE '\003' #define LPS_DISPLAY_LONG_QUEUE '\004'
#define LPS_REMOVE_JOB '\005'
#define LPS_OK '\0' #define LPS_END_TRANSFER '\000'
#define LPS_ERROR '\1' #define LPS_ABORT '\001'
#define LPS_NO_SPOOL_SPACE '\2' #define LPS_RECEIVE_CONTROL_FILE '\002'
#define LPS_RECEIVE_DATA_FILE '\003'
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff #define LPS_OK '\0'
#endif #define LPS_ERROR '\1'
#define LPS_NO_SPOOL_SPACE '\2'
#ifdef WIN32
#define EADDRINUSE WSAEADDRINUSE #ifndef INADDR_NONE
#define ERRNO WSAGetLastError() #define INADDR_NONE 0xffffffff
#else #endif
#define ERRNO errno
#endif #ifdef WIN32
#define EADDRINUSE WSAEADDRINUSE
#define ERRNO WSAGetLastError()
LpsClient::LpsClient(const char *host) #else
: connected(false), __host(host), __sock(NULL) #define ERRNO errno
{ #endif
}
LpsClient::~LpsClient() LpsClient::LpsClient(const char *host)
{ : connected(false), __host(host), __sock(NULL)
close(); {
} }
void LpsClient::connect() throw(LPSException) LpsClient::~LpsClient()
{ {
// DBGMSG(("connect\n")); close();
}
for (int localPort = LPS_CLIENT_PORT_S ; localPort <= LPS_CLIENT_PORT_E ; localPort++) {
if (__sock) { void LpsClient::connect() throw(LPSException)
delete __sock; {
} // DBGMSG(("connect\n"));
__sock = new Socket(__host.c_str(), LPS_SERVER_PORT, localPort);
if (__sock->good()) { for (int localPort = LPS_CLIENT_PORT_S ; localPort <= LPS_CLIENT_PORT_E ; localPort++) {
__is = &__sock->getInputStream(); if (__sock) {
__os = &__sock->getOutputStream(); delete __sock;
connected = true; }
return; __sock = new Socket(__host.c_str(), LPS_SERVER_PORT, localPort);
} if (__sock->good()) {
} __is = &__sock->getInputStream();
__os = &__sock->getOutputStream();
throw(LPSException(__sock->getLastError())); connected = true;
} return;
}
void LpsClient::close() }
{
// DBGMSG(("close\n")); throw(LPSException(__sock->getLastError()));
}
connected = false;
if (__sock) { void LpsClient::close()
delete __sock; {
__sock = NULL; // DBGMSG(("close\n"));
}
} connected = false;
if (__sock) {
void LpsClient::receiveJob(const char *printer) throw(LPSException) delete __sock;
{ __sock = NULL;
// DBGMSG(("tell_receive_job\n")); }
}
if (connected) {
*__os << LPS_PRINT_JOB << printer << '\n' << flush; void LpsClient::receiveJob(const char *printer) throw(LPSException)
checkAck(); {
} // DBGMSG(("tell_receive_job\n"));
}
if (connected) {
void LpsClient::receiveControlFile(int size, const char *name) throw(LPSException) *__os << LPS_PRINT_JOB << printer << '\n' << flush;
{ checkAck();
// DBGMSG(("tell_receive_control_file\n")); }
}
if (connected) {
void LpsClient::receiveControlFile(int size, const char *name) throw(LPSException)
char cfname[32]; {
strncpy(cfname, name, sizeof(cfname)); // DBGMSG(("tell_receive_control_file\n"));
cfname[sizeof(cfname) - 1] = '\0';
if (connected) {
*__os << LPS_RECEIVE_CONTROL_FILE << size << ' ' << cfname << '\n' << flush;
char cfname[32];
checkAck(); strncpy(cfname, name, sizeof(cfname));
} cfname[sizeof(cfname) - 1] = '\0';
}
*__os << LPS_RECEIVE_CONTROL_FILE << size << ' ' << cfname << '\n' << flush;
void LpsClient::receiveDataFile(int size, const char *name) throw(LPSException)
{ checkAck();
// DBGMSG(("tell_receive_data_file\n")); }
}
if (connected) {
void LpsClient::receiveDataFile(int size, const char *name) throw(LPSException)
char dfname[32]; {
strncpy(dfname, name, sizeof(dfname)); // DBGMSG(("tell_receive_data_file\n"));
dfname[sizeof(dfname) - 1] = '\0';
if (connected) {
*__os << LPS_RECEIVE_DATA_FILE << size << ' ' << dfname << '\n' << flush;
char dfname[32];
checkAck(); strncpy(dfname, name, sizeof(dfname));
} dfname[sizeof(dfname) - 1] = '\0';
}
*__os << LPS_RECEIVE_DATA_FILE << size << ' ' << dfname << '\n' << flush;
void LpsClient::transferData(const char *buffer, int size) throw(LPSException)
{ checkAck();
// DBGMSG(("send: %d\n", size)); }
}
if (connected) {
void LpsClient::transferData(const char *buffer, int size) throw(LPSException)
if (size < 0) { {
size = strlen(buffer); // DBGMSG(("send: %d\n", size));
}
if (connected) {
if (!__os->write(buffer, size)) {
close(); if (size < 0) {
throw(LPSException("error talking to lpd server")); size = strlen(buffer);
} }
}
} if (!__os->write(buffer, size)) {
close();
void LpsClient::transferData(istream &is, int size) throw(LPSException) throw(LPSException("error talking to lpd server"));
{ }
// DBGMSG(("send: %d\n", size)); }
}
if (connected) {
void LpsClient::transferData(istream &is, int size) throw(LPSException)
if (size < 0) { {
is.seekg(0, ios::end); // DBGMSG(("send: %d\n", size));
size = is.tellg();
is.seekg(0, ios::beg); if (connected) {
}
if (size < 0) {
char c; is.seekg(0, ios::end);
while (is.get(c)) { size = is.tellg();
if (!__os->put(c)) { is.seekg(0, ios::beg);
close(); }
throw(LPSException("error reading file."));
return; 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; void LpsClient::endTransfer() throw(LPSException)
checkAck(); {
} // DBGMSG(("tell_end_transfer\n"));
}
if (connected) {
void LpsClient::checkAck() throw(LPSException) *__os << LPS_END_TRANSFER << flush;
{ checkAck();
// DBGMSG(("check_ack\n")); }
}
if (connected) {
void LpsClient::checkAck() throw(LPSException)
char c; {
// DBGMSG(("check_ack\n"));
if (!__is->get(c)) {
close(); if (connected) {
throw(LPSException("server not responding."));
return; char c;
}
if (!__is->get(c)) {
switch (c) { close();
case LPS_OK: throw(LPSException("server not responding."));
break; return;
case LPS_ERROR: }
close();
throw(LPSException("server error.")); switch (c) {
break; case LPS_OK:
case LPS_NO_SPOOL_SPACE: break;
close(); case LPS_ERROR:
throw(LPSException("not enough spool space on server.")); close();
break; throw(LPSException("server error."));
} break;
} case LPS_NO_SPOOL_SPACE:
} close();
throw(LPSException("not enough spool space on server."));
break;
}
}
}
+10 -7
View File
@@ -4,15 +4,18 @@
#ifdef WIN32 #ifdef WIN32
#include <winsock.h> #include <winsock.h>
#else #else
#include <net/socket.h> #ifdef __HAIKU__
#include <net/netdb.h> # include <sys/socket.h>
#ifdef HAVE_ARPA_INET #else
// inet_addr() is not defined in netdb.h anymore under BONE & later # include <net/socket.h>
#include <arpa/inet.h> #endif
#endif #include <netdb.h>
#include <arpa/inet.h>
#endif // WIN32 #endif // WIN32
#include <cstdio> #include <stdio.h>
#include <unistd.h>
#include "Socket.h" #include "Socket.h"
#include "SocketStream.h" #include "SocketStream.h"
@@ -1,127 +1,131 @@
// Sun, 18 Jun 2000 // Sun, 18 Jun 2000
// Y.Takagi // Y.Takagi
#ifndef WIN32 #ifndef WIN32
#include <net/socket.h> #ifdef __HAIKU__
# include <sys/socket.h>
#ifdef _DEBUG #else
#include <iostream> # include <net/socket.h>
#include <fstream> #endif
#endif
#ifdef _DEBUG
#include "Socket.h" #include <iostream>
#include "SocketStream.h" #include <fstream>
#endif
/*-----------------------------------------------------------------*/
#include "Socket.h"
socketstreambuf::socketstreambuf(Socket *sock, streamsize n) #include "SocketStream.h"
: streambuf(), __sock(sock), __alsize(n), __pu(NULL), __po(NULL)
{ /*-----------------------------------------------------------------*/
setg(0, 0, 0);
setp(0, 0); socketstreambuf::socketstreambuf(Socket *sock, streamsize n)
} : streambuf(), __sock(sock), __alsize(n), __pu(NULL), __po(NULL)
{
socketstreambuf::~socketstreambuf() setg(0, 0, 0);
{ setp(0, 0);
if (__pu) }
delete [] __pu;
if (__po) socketstreambuf::~socketstreambuf()
delete [] __po; {
} if (__pu)
delete [] __pu;
int socketstreambuf::underflow() if (__po)
{ delete [] __po;
// cout << "***** underflow" << endl; }
int bytes; int socketstreambuf::underflow()
{
if (__pu == NULL) { // cout << "***** underflow" << endl;
__pu = new char[__alsize];
} int bytes;
bytes = __sock->read(__pu, __alsize); if (__pu == NULL) {
if (bytes > 0) { __pu = new char[__alsize];
#ifdef _DEBUG }
ofstream ofs("recv.log", ios::binary | ios::app);
ofs.write(__pu, bytes); bytes = __sock->read(__pu, __alsize);
#endif if (bytes > 0) {
setg(__pu, __pu, __pu + bytes); #ifdef _DEBUG
return *gptr(); ofstream ofs("recv.log", ios::binary | ios::app);
} ofs.write(__pu, bytes);
#endif
return EOF; setg(__pu, __pu, __pu + bytes);
} return *gptr();
}
int socketstreambuf::overflow(int c)
{ return EOF;
// cout << "***** overflow" << endl; }
if (__po == NULL) { int socketstreambuf::overflow(int c)
__po = new char[__alsize]; {
setp(__po, __po + __alsize); // cout << "***** overflow" << endl;
} else if (sync() != 0) {
return EOF; if (__po == NULL) {
} __po = new char[__alsize];
return sputc(c); setp(__po, __po + __alsize);
} } else if (sync() != 0) {
return EOF;
int socketstreambuf::sync() }
{ return sputc(c);
// cout << "***** sync" << endl; }
if (__po) { int socketstreambuf::sync()
int length = pptr() - pbase(); {
if (length > 0) { // cout << "***** sync" << endl;
const char *buffer = pbase();
int bytes; if (__po) {
while (length > 0) { int length = pptr() - pbase();
bytes = __sock->write(buffer, length); if (length > 0) {
if (bytes <= 0) { const char *buffer = pbase();
return EOF; int bytes;
} while (length > 0) {
#ifdef _DEBUG bytes = __sock->write(buffer, length);
ofstream ofs("send.log", ios::binary | ios::app); if (bytes <= 0) {
ofs.write(buffer, bytes); return EOF;
#endif }
length -= bytes; #ifdef _DEBUG
buffer += bytes; ofstream ofs("send.log", ios::binary | ios::app);
} ofs.write(buffer, bytes);
pbump(pbase() - pptr()); #endif
} length -= bytes;
} buffer += bytes;
}
return 0; pbump(pbase() - pptr());
} }
}
/* -------------------------------------------------------------- */
return 0;
socketstreambase::socketstreambase(Socket *sock, streamsize n) }
: buf(sock, n)
{ /* -------------------------------------------------------------- */
ios::init(&this->buf);
} 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(Socket *sock, streamsize n)
isocketstream::~isocketstream() : socketstreambase(sock, n), istream(socketstreambase::rdbuf())
{ {
} }
/*-----------------------------------------------------------------*/ isocketstream::~isocketstream()
{
osocketstream::osocketstream(Socket *sock, streamsize n) }
: socketstreambase(sock, n), ostream(socketstreambase::rdbuf())
{ /*-----------------------------------------------------------------*/
}
osocketstream::osocketstream(Socket *sock, streamsize n)
osocketstream::~osocketstream() : socketstreambase(sock, n), ostream(socketstreambase::rdbuf())
{ {
flush(); }
}
osocketstream::~osocketstream()
#endif // !WIN32 {
flush();
}
#endif // !WIN32