Got rid of WIN32 related source code. Someone, please build.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19024 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
1781c9776e
commit
926f124731
@ -1,327 +1,323 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <minmax.h>
|
||||
#else
|
||||
#define stricmp strcasecmp
|
||||
#endif
|
||||
|
||||
#include "HttpURLConnection.h"
|
||||
#include "Socket.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define DEFAULT_PORT 80;
|
||||
|
||||
Field::Field(char *field)
|
||||
{
|
||||
char *p = strtok(field, ": \t\r\n");
|
||||
key = p ? p : "";
|
||||
p = strtok(NULL, " \t\r\n");
|
||||
value = p ? p : "";
|
||||
}
|
||||
|
||||
Field::Field(const char *k, const char *v)
|
||||
{
|
||||
key = k ? k : "";
|
||||
value = v ? v : "";
|
||||
}
|
||||
|
||||
Field::Field(const Field &o)
|
||||
{
|
||||
key = o.key;
|
||||
value = o.value;
|
||||
}
|
||||
|
||||
Field &Field::operator = (const Field &o)
|
||||
{
|
||||
key = o.key;
|
||||
value = o.value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Field::operator == (const Field &o)
|
||||
{
|
||||
return (key == o.key) && (value == o.value);
|
||||
}
|
||||
|
||||
HttpURLConnection::HttpURLConnection(const URL &Url)
|
||||
: connected(false), doInput(true), doOutput(false), url(Url)
|
||||
{
|
||||
__sock = NULL;
|
||||
__method = "GET";
|
||||
__request = NULL;
|
||||
__response = NULL;
|
||||
__response_code = HTTP_UNKNOWN;
|
||||
}
|
||||
|
||||
HttpURLConnection::~HttpURLConnection()
|
||||
{
|
||||
disconnect();
|
||||
|
||||
if (__sock) {
|
||||
delete __sock;
|
||||
}
|
||||
|
||||
if (__request) {
|
||||
delete __request;
|
||||
}
|
||||
|
||||
if (__response) {
|
||||
delete __response;
|
||||
}
|
||||
}
|
||||
|
||||
void HttpURLConnection::disconnect()
|
||||
{
|
||||
if (connected) {
|
||||
connected = false;
|
||||
__sock->close();
|
||||
}
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getRequestMethod() const
|
||||
{
|
||||
return __method.c_str();
|
||||
}
|
||||
|
||||
void HttpURLConnection::setRequestMethod(const char *method)
|
||||
{
|
||||
__method = method;
|
||||
}
|
||||
|
||||
void HttpURLConnection::setRequestProperty(const char *key, const char *value)
|
||||
{
|
||||
if (__request == NULL) {
|
||||
__request = new Fields;
|
||||
}
|
||||
__request->push_back(Field(key, value));
|
||||
}
|
||||
|
||||
istream &HttpURLConnection::getInputStream()
|
||||
{
|
||||
if (!connected) {
|
||||
connect();
|
||||
setRequest();
|
||||
}
|
||||
return __sock->getInputStream();
|
||||
}
|
||||
|
||||
ostream &HttpURLConnection::getOutputStream()
|
||||
{
|
||||
if (!connected) {
|
||||
connect();
|
||||
}
|
||||
return __sock->getOutputStream();
|
||||
}
|
||||
|
||||
void HttpURLConnection::setDoInput(bool doinput)
|
||||
{
|
||||
doinput = doinput;
|
||||
}
|
||||
|
||||
void HttpURLConnection::setDoOutput(bool dooutput)
|
||||
{
|
||||
dooutput = dooutput;
|
||||
}
|
||||
|
||||
void HttpURLConnection::connect()
|
||||
{
|
||||
if (!connected) {
|
||||
int port = url.getPort();
|
||||
if (port < 0) {
|
||||
const char *protocol = url.getProtocol();
|
||||
if (!stricmp(protocol, "http")) {
|
||||
port = DEFAULT_PORT;
|
||||
} else if (!stricmp(protocol, "ipp")) {
|
||||
port = 631;
|
||||
} else {
|
||||
port = DEFAULT_PORT;
|
||||
}
|
||||
}
|
||||
__sock = new Socket(url.getHost(), port);
|
||||
if (__sock->fail()) {
|
||||
__error_msg = __sock->getLastError();
|
||||
} else {
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getContentType()
|
||||
{
|
||||
return getHeaderField("Content-Type");
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getContentEncoding()
|
||||
{
|
||||
return getHeaderField("Content-Encoding");
|
||||
}
|
||||
|
||||
int HttpURLConnection::getContentLength()
|
||||
{
|
||||
const char *p = getHeaderField("Content-Length");
|
||||
return p ? atoi(p) : -1;
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getHeaderField(const char *s)
|
||||
{
|
||||
if (__response == NULL) {
|
||||
action();
|
||||
}
|
||||
if (__response) {
|
||||
for (Fields::iterator it = __response->begin(); it != __response->end(); it++) {
|
||||
if ((*it).key == s) {
|
||||
return (*it).value.c_str();
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HTTP_RESPONSECODE HttpURLConnection::getResponseCode()
|
||||
{
|
||||
if (__response == NULL) {
|
||||
action();
|
||||
}
|
||||
return __response_code;
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getResponseMessage()
|
||||
{
|
||||
if (__response == NULL) {
|
||||
action();
|
||||
}
|
||||
return __response_message.c_str();
|
||||
}
|
||||
|
||||
void HttpURLConnection::action()
|
||||
{
|
||||
if (!connected) {
|
||||
connect();
|
||||
}
|
||||
if (connected) {
|
||||
setRequest();
|
||||
}
|
||||
if (connected) {
|
||||
getResponse();
|
||||
}
|
||||
}
|
||||
|
||||
void HttpURLConnection::setRequest()
|
||||
{
|
||||
if (connected) {
|
||||
setRequestProperty("Host", url.getHost());
|
||||
ostream &os = getOutputStream();
|
||||
os << __method << ' ' << url.getFile() << " HTTP/1.1" << '\r' << '\n';
|
||||
for (Fields::iterator it = __request->begin(); it != __request->end(); it++) {
|
||||
os << (*it).key << ": " << (*it).value << '\r' << '\n';
|
||||
}
|
||||
os << '\r' << '\n';
|
||||
|
||||
setContent();
|
||||
|
||||
if (!doOutput) {
|
||||
os.flush();
|
||||
}
|
||||
|
||||
if (__response) {
|
||||
delete __response;
|
||||
__response = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HttpURLConnection::setContent()
|
||||
{
|
||||
}
|
||||
|
||||
void HttpURLConnection::getResponse()
|
||||
{
|
||||
if (connected) {
|
||||
|
||||
if (__response == NULL) {
|
||||
__response = new Fields;
|
||||
|
||||
istream &is = getInputStream();
|
||||
|
||||
char buffer[1024];
|
||||
|
||||
if (!is.getline(buffer, sizeof(buffer))) {
|
||||
__error_msg = __sock->getLastError();
|
||||
return;
|
||||
}
|
||||
buffer[is.gcount() - 2] = '\0';
|
||||
__response_message = buffer;
|
||||
strtok(buffer, " ");
|
||||
char *p = strtok(NULL, " ");
|
||||
__response_code = p ? (HTTP_RESPONSECODE)atoi(p) : HTTP_UNKNOWN;
|
||||
|
||||
while (is.getline(buffer, sizeof(buffer))) {
|
||||
if (buffer[0] == '\r') {
|
||||
break;
|
||||
}
|
||||
buffer[is.gcount() - 2] = '\0';
|
||||
__response->push_back(Field(buffer));
|
||||
}
|
||||
|
||||
int size = getContentLength();
|
||||
if (size > 0) {
|
||||
getContent();
|
||||
}
|
||||
|
||||
if (__response_code != HTTP_CONTINUE) {
|
||||
const char *s = getHeaderField("Connection");
|
||||
if (s == NULL) {
|
||||
connected = false;
|
||||
__error_msg = "cannot found \"Connection\" field";
|
||||
} else if (stricmp(s, "Keep-Alive")) {
|
||||
connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (__response_code) {
|
||||
case HTTP_MOVED_TEMP:
|
||||
{
|
||||
const char *p = getHeaderField("Location");
|
||||
if (p) {
|
||||
URL trueUrl(p);
|
||||
url = trueUrl;
|
||||
delete __response;
|
||||
__response = NULL;
|
||||
action();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HTTP_CONTINUE:
|
||||
delete __response;
|
||||
__response = NULL;
|
||||
getResponse();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HttpURLConnection::getContent()
|
||||
{
|
||||
const int maxBufSize = 1024;
|
||||
if (connected) {
|
||||
int size = getContentLength();
|
||||
if (size > 0) {
|
||||
istream &is = getInputStream();
|
||||
int bufsize = min(size, maxBufSize);
|
||||
char buf[maxBufSize];
|
||||
while (size > 0 && is.read(buf, bufsize)) {
|
||||
size -= bufsize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#define stricmp strcasecmp
|
||||
|
||||
#include "HttpURLConnection.h"
|
||||
#include "Socket.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define DEFAULT_PORT 80;
|
||||
|
||||
Field::Field(char *field)
|
||||
{
|
||||
char *p = strtok(field, ": \t\r\n");
|
||||
key = p ? p : "";
|
||||
p = strtok(NULL, " \t\r\n");
|
||||
value = p ? p : "";
|
||||
}
|
||||
|
||||
Field::Field(const char *k, const char *v)
|
||||
{
|
||||
key = k ? k : "";
|
||||
value = v ? v : "";
|
||||
}
|
||||
|
||||
Field::Field(const Field &o)
|
||||
{
|
||||
key = o.key;
|
||||
value = o.value;
|
||||
}
|
||||
|
||||
Field &Field::operator = (const Field &o)
|
||||
{
|
||||
key = o.key;
|
||||
value = o.value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Field::operator == (const Field &o)
|
||||
{
|
||||
return (key == o.key) && (value == o.value);
|
||||
}
|
||||
|
||||
HttpURLConnection::HttpURLConnection(const URL &Url)
|
||||
: connected(false), doInput(true), doOutput(false), url(Url)
|
||||
{
|
||||
__sock = NULL;
|
||||
__method = "GET";
|
||||
__request = NULL;
|
||||
__response = NULL;
|
||||
__response_code = HTTP_UNKNOWN;
|
||||
}
|
||||
|
||||
HttpURLConnection::~HttpURLConnection()
|
||||
{
|
||||
disconnect();
|
||||
|
||||
if (__sock) {
|
||||
delete __sock;
|
||||
}
|
||||
|
||||
if (__request) {
|
||||
delete __request;
|
||||
}
|
||||
|
||||
if (__response) {
|
||||
delete __response;
|
||||
}
|
||||
}
|
||||
|
||||
void HttpURLConnection::disconnect()
|
||||
{
|
||||
if (connected) {
|
||||
connected = false;
|
||||
__sock->close();
|
||||
}
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getRequestMethod() const
|
||||
{
|
||||
return __method.c_str();
|
||||
}
|
||||
|
||||
void HttpURLConnection::setRequestMethod(const char *method)
|
||||
{
|
||||
__method = method;
|
||||
}
|
||||
|
||||
void HttpURLConnection::setRequestProperty(const char *key, const char *value)
|
||||
{
|
||||
if (__request == NULL) {
|
||||
__request = new Fields;
|
||||
}
|
||||
__request->push_back(Field(key, value));
|
||||
}
|
||||
|
||||
istream &HttpURLConnection::getInputStream()
|
||||
{
|
||||
if (!connected) {
|
||||
connect();
|
||||
setRequest();
|
||||
}
|
||||
return __sock->getInputStream();
|
||||
}
|
||||
|
||||
ostream &HttpURLConnection::getOutputStream()
|
||||
{
|
||||
if (!connected) {
|
||||
connect();
|
||||
}
|
||||
return __sock->getOutputStream();
|
||||
}
|
||||
|
||||
void HttpURLConnection::setDoInput(bool doinput)
|
||||
{
|
||||
doinput = doinput;
|
||||
}
|
||||
|
||||
void HttpURLConnection::setDoOutput(bool dooutput)
|
||||
{
|
||||
dooutput = dooutput;
|
||||
}
|
||||
|
||||
void HttpURLConnection::connect()
|
||||
{
|
||||
if (!connected) {
|
||||
int port = url.getPort();
|
||||
if (port < 0) {
|
||||
const char *protocol = url.getProtocol();
|
||||
if (!stricmp(protocol, "http")) {
|
||||
port = DEFAULT_PORT;
|
||||
} else if (!stricmp(protocol, "ipp")) {
|
||||
port = 631;
|
||||
} else {
|
||||
port = DEFAULT_PORT;
|
||||
}
|
||||
}
|
||||
__sock = new Socket(url.getHost(), port);
|
||||
if (__sock->fail()) {
|
||||
__error_msg = __sock->getLastError();
|
||||
} else {
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getContentType()
|
||||
{
|
||||
return getHeaderField("Content-Type");
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getContentEncoding()
|
||||
{
|
||||
return getHeaderField("Content-Encoding");
|
||||
}
|
||||
|
||||
int HttpURLConnection::getContentLength()
|
||||
{
|
||||
const char *p = getHeaderField("Content-Length");
|
||||
return p ? atoi(p) : -1;
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getHeaderField(const char *s)
|
||||
{
|
||||
if (__response == NULL) {
|
||||
action();
|
||||
}
|
||||
if (__response) {
|
||||
for (Fields::iterator it = __response->begin(); it != __response->end(); it++) {
|
||||
if ((*it).key == s) {
|
||||
return (*it).value.c_str();
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HTTP_RESPONSECODE HttpURLConnection::getResponseCode()
|
||||
{
|
||||
if (__response == NULL) {
|
||||
action();
|
||||
}
|
||||
return __response_code;
|
||||
}
|
||||
|
||||
const char *HttpURLConnection::getResponseMessage()
|
||||
{
|
||||
if (__response == NULL) {
|
||||
action();
|
||||
}
|
||||
return __response_message.c_str();
|
||||
}
|
||||
|
||||
void HttpURLConnection::action()
|
||||
{
|
||||
if (!connected) {
|
||||
connect();
|
||||
}
|
||||
if (connected) {
|
||||
setRequest();
|
||||
}
|
||||
if (connected) {
|
||||
getResponse();
|
||||
}
|
||||
}
|
||||
|
||||
void HttpURLConnection::setRequest()
|
||||
{
|
||||
if (connected) {
|
||||
setRequestProperty("Host", url.getHost());
|
||||
ostream &os = getOutputStream();
|
||||
os << __method << ' ' << url.getFile() << " HTTP/1.1" << '\r' << '\n';
|
||||
for (Fields::iterator it = __request->begin(); it != __request->end(); it++) {
|
||||
os << (*it).key << ": " << (*it).value << '\r' << '\n';
|
||||
}
|
||||
os << '\r' << '\n';
|
||||
|
||||
setContent();
|
||||
|
||||
if (!doOutput) {
|
||||
os.flush();
|
||||
}
|
||||
|
||||
if (__response) {
|
||||
delete __response;
|
||||
__response = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HttpURLConnection::setContent()
|
||||
{
|
||||
}
|
||||
|
||||
void HttpURLConnection::getResponse()
|
||||
{
|
||||
if (connected) {
|
||||
|
||||
if (__response == NULL) {
|
||||
__response = new Fields;
|
||||
|
||||
istream &is = getInputStream();
|
||||
|
||||
char buffer[1024];
|
||||
|
||||
if (!is.getline(buffer, sizeof(buffer))) {
|
||||
__error_msg = __sock->getLastError();
|
||||
return;
|
||||
}
|
||||
buffer[is.gcount() - 2] = '\0';
|
||||
__response_message = buffer;
|
||||
strtok(buffer, " ");
|
||||
char *p = strtok(NULL, " ");
|
||||
__response_code = p ? (HTTP_RESPONSECODE)atoi(p) : HTTP_UNKNOWN;
|
||||
|
||||
while (is.getline(buffer, sizeof(buffer))) {
|
||||
if (buffer[0] == '\r') {
|
||||
break;
|
||||
}
|
||||
buffer[is.gcount() - 2] = '\0';
|
||||
__response->push_back(Field(buffer));
|
||||
}
|
||||
|
||||
int size = getContentLength();
|
||||
if (size > 0) {
|
||||
getContent();
|
||||
}
|
||||
|
||||
if (__response_code != HTTP_CONTINUE) {
|
||||
const char *s = getHeaderField("Connection");
|
||||
if (s == NULL) {
|
||||
connected = false;
|
||||
__error_msg = "cannot found \"Connection\" field";
|
||||
} else if (stricmp(s, "Keep-Alive")) {
|
||||
connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (__response_code) {
|
||||
case HTTP_MOVED_TEMP:
|
||||
{
|
||||
const char *p = getHeaderField("Location");
|
||||
if (p) {
|
||||
URL trueUrl(p);
|
||||
url = trueUrl;
|
||||
delete __response;
|
||||
__response = NULL;
|
||||
action();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HTTP_CONTINUE:
|
||||
delete __response;
|
||||
__response = NULL;
|
||||
getResponse();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HttpURLConnection::getContent()
|
||||
{
|
||||
const int maxBufSize = 1024;
|
||||
if (connected) {
|
||||
int size = getContentLength();
|
||||
if (size > 0) {
|
||||
istream &is = getInputStream();
|
||||
int bufsize = min(size, maxBufSize);
|
||||
char buf[maxBufSize];
|
||||
while (size > 0 && is.read(buf, bufsize)) {
|
||||
size -= bufsize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,148 +1,143 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __HttpURLConnection_H
|
||||
#define __HttpURLConnection_H
|
||||
|
||||
#ifdef WIN32
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#else
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
#endif
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "URL.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Socket;
|
||||
|
||||
enum HTTP_RESPONSECODE {
|
||||
HTTP_UNKNOWN = -1, //
|
||||
|
||||
HTTP_CONTINUE = 100, // Everything OK, keep going...
|
||||
HTTP_SWITCH_PROC = 101, // Switching Protocols
|
||||
|
||||
HTTP_OK = 200, // OPTIONS/GET/HEAD/POST/TRACE command was successful
|
||||
HTTP_CREATED, // PUT command was successful
|
||||
HTTP_ACCEPTED, // DELETE command was successful
|
||||
HTTP_NOT_AUTHORITATIVE, // Information isn't authoritative
|
||||
HTTP_NO_CONTENT, // Successful command, no new data
|
||||
HTTP_RESET, // Content was reset/recreated
|
||||
HTTP_PARTIAL, // Only a partial file was recieved/sent
|
||||
|
||||
HTTP_MULTI_CHOICE = 300, // Multiple files match request
|
||||
HTTP_MOVED_PERM, // Document has moved permanently
|
||||
HTTP_MOVED_TEMP, // Document has moved temporarily
|
||||
HTTP_SEE_OTHER, // See this other link...
|
||||
HTTP_NOT_MODIFIED, // File not modified
|
||||
HTTP_USE_PROXY, // Must use a proxy to access this URI
|
||||
|
||||
HTTP_BAD_REQUEST = 400, // Bad request
|
||||
HTTP_UNAUTHORIZED, // Unauthorized to access host
|
||||
HTTP_PAYMENT_REQUIRED, // Payment required
|
||||
HTTP_FORBIDDEN, // Forbidden to access this URI
|
||||
HTTP_NOT_FOUND, // URI was not found
|
||||
HTTP_BAD_METHOD, // Method is not allowed
|
||||
HTTP_NOT_ACCEPTABLE, // Not Acceptable
|
||||
HTTP_PROXY_AUTH, // Proxy Authentication is Required
|
||||
HTTP_REQUEST_TIMEOUT, // Request timed out
|
||||
HTTP_CONFLICT, // Request is self-conflicting
|
||||
HTTP_GONE, // Server has gone away
|
||||
HTTP_LENGTH_REQUIRED, // A content length or encoding is required
|
||||
HTTP_PRECON_FAILED, // Precondition failed
|
||||
HTTP_ENTITY_TOO_LARGE, // URI too long
|
||||
HTTP_REQ_TOO_LONG, // Request entity too large
|
||||
HTTP_UNSUPPORTED_TYPE, // The requested media type is unsupported
|
||||
|
||||
HTTP_SERVER_ERROR = 500, // Internal server error
|
||||
HTTP_INTERNAL_ERROR, // Feature not implemented
|
||||
HTTP_BAD_GATEWAY, // Bad gateway
|
||||
HTTP_UNAVAILABLE, // Service is unavailable
|
||||
HTTP_GATEWAY_TIMEOUT, // Gateway connection timed out
|
||||
HTTP_VERSION // HTTP version not supported
|
||||
};
|
||||
|
||||
struct Field {
|
||||
string key;
|
||||
string value;
|
||||
Field() {}
|
||||
Field(char *field);
|
||||
Field(const char *k, const char *v);
|
||||
Field(const Field &);
|
||||
Field &operator = (const Field &);
|
||||
bool operator == (const Field &);
|
||||
};
|
||||
|
||||
typedef list<Field> Fields;
|
||||
|
||||
class HttpURLConnection {
|
||||
public:
|
||||
HttpURLConnection(const URL &url);
|
||||
virtual ~HttpURLConnection();
|
||||
|
||||
virtual void connect();
|
||||
void disconnect();
|
||||
|
||||
void setRequestMethod(const char *method);
|
||||
const char *getRequestMethod() const;
|
||||
void setRequestProperty(const char *key, const char *value);
|
||||
|
||||
const char *getContentType();
|
||||
const char *getContentEncoding();
|
||||
int getContentLength();
|
||||
long getDate();
|
||||
const char *getHeaderField(int n);
|
||||
const char *getHeaderField(const char *);
|
||||
const URL &getURL() const;
|
||||
HTTP_RESPONSECODE getResponseCode();
|
||||
const char *getResponseMessage();
|
||||
|
||||
bool getDoInput() const;
|
||||
bool getDoOutput() const;
|
||||
void setDoInput(bool doinput);
|
||||
void setDoOutput(bool dooutput);
|
||||
|
||||
istream &getInputStream();
|
||||
ostream &getOutputStream();
|
||||
|
||||
const char *getLastError() const;
|
||||
void setLastError(const char *);
|
||||
|
||||
protected:
|
||||
bool connected;
|
||||
bool doInput;
|
||||
bool doOutput;
|
||||
URL url;
|
||||
|
||||
virtual void action();
|
||||
virtual void setRequest();
|
||||
virtual void setContent();
|
||||
virtual void getResponse();
|
||||
virtual void getContent();
|
||||
|
||||
private:
|
||||
Fields *__request;
|
||||
Fields *__response;
|
||||
Socket *__sock;
|
||||
string __method;
|
||||
string __response_message;
|
||||
HTTP_RESPONSECODE __response_code;
|
||||
string __error_msg;
|
||||
};
|
||||
|
||||
inline const char *HttpURLConnection::getLastError() const
|
||||
{
|
||||
return __error_msg.c_str();
|
||||
}
|
||||
|
||||
inline void HttpURLConnection::setLastError(const char *e)
|
||||
{
|
||||
__error_msg = e;
|
||||
}
|
||||
|
||||
#endif // __HttpURLConnection_H
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __HttpURLConnection_H
|
||||
#define __HttpURLConnection_H
|
||||
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "URL.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Socket;
|
||||
|
||||
enum HTTP_RESPONSECODE {
|
||||
HTTP_UNKNOWN = -1, //
|
||||
|
||||
HTTP_CONTINUE = 100, // Everything OK, keep going...
|
||||
HTTP_SWITCH_PROC = 101, // Switching Protocols
|
||||
|
||||
HTTP_OK = 200, // OPTIONS/GET/HEAD/POST/TRACE command was successful
|
||||
HTTP_CREATED, // PUT command was successful
|
||||
HTTP_ACCEPTED, // DELETE command was successful
|
||||
HTTP_NOT_AUTHORITATIVE, // Information isn't authoritative
|
||||
HTTP_NO_CONTENT, // Successful command, no new data
|
||||
HTTP_RESET, // Content was reset/recreated
|
||||
HTTP_PARTIAL, // Only a partial file was recieved/sent
|
||||
|
||||
HTTP_MULTI_CHOICE = 300, // Multiple files match request
|
||||
HTTP_MOVED_PERM, // Document has moved permanently
|
||||
HTTP_MOVED_TEMP, // Document has moved temporarily
|
||||
HTTP_SEE_OTHER, // See this other link...
|
||||
HTTP_NOT_MODIFIED, // File not modified
|
||||
HTTP_USE_PROXY, // Must use a proxy to access this URI
|
||||
|
||||
HTTP_BAD_REQUEST = 400, // Bad request
|
||||
HTTP_UNAUTHORIZED, // Unauthorized to access host
|
||||
HTTP_PAYMENT_REQUIRED, // Payment required
|
||||
HTTP_FORBIDDEN, // Forbidden to access this URI
|
||||
HTTP_NOT_FOUND, // URI was not found
|
||||
HTTP_BAD_METHOD, // Method is not allowed
|
||||
HTTP_NOT_ACCEPTABLE, // Not Acceptable
|
||||
HTTP_PROXY_AUTH, // Proxy Authentication is Required
|
||||
HTTP_REQUEST_TIMEOUT, // Request timed out
|
||||
HTTP_CONFLICT, // Request is self-conflicting
|
||||
HTTP_GONE, // Server has gone away
|
||||
HTTP_LENGTH_REQUIRED, // A content length or encoding is required
|
||||
HTTP_PRECON_FAILED, // Precondition failed
|
||||
HTTP_ENTITY_TOO_LARGE, // URI too long
|
||||
HTTP_REQ_TOO_LONG, // Request entity too large
|
||||
HTTP_UNSUPPORTED_TYPE, // The requested media type is unsupported
|
||||
|
||||
HTTP_SERVER_ERROR = 500, // Internal server error
|
||||
HTTP_INTERNAL_ERROR, // Feature not implemented
|
||||
HTTP_BAD_GATEWAY, // Bad gateway
|
||||
HTTP_UNAVAILABLE, // Service is unavailable
|
||||
HTTP_GATEWAY_TIMEOUT, // Gateway connection timed out
|
||||
HTTP_VERSION // HTTP version not supported
|
||||
};
|
||||
|
||||
struct Field {
|
||||
string key;
|
||||
string value;
|
||||
Field() {}
|
||||
Field(char *field);
|
||||
Field(const char *k, const char *v);
|
||||
Field(const Field &);
|
||||
Field &operator = (const Field &);
|
||||
bool operator == (const Field &);
|
||||
};
|
||||
|
||||
typedef list<Field> Fields;
|
||||
|
||||
class HttpURLConnection {
|
||||
public:
|
||||
HttpURLConnection(const URL &url);
|
||||
virtual ~HttpURLConnection();
|
||||
|
||||
virtual void connect();
|
||||
void disconnect();
|
||||
|
||||
void setRequestMethod(const char *method);
|
||||
const char *getRequestMethod() const;
|
||||
void setRequestProperty(const char *key, const char *value);
|
||||
|
||||
const char *getContentType();
|
||||
const char *getContentEncoding();
|
||||
int getContentLength();
|
||||
long getDate();
|
||||
const char *getHeaderField(int n);
|
||||
const char *getHeaderField(const char *);
|
||||
const URL &getURL() const;
|
||||
HTTP_RESPONSECODE getResponseCode();
|
||||
const char *getResponseMessage();
|
||||
|
||||
bool getDoInput() const;
|
||||
bool getDoOutput() const;
|
||||
void setDoInput(bool doinput);
|
||||
void setDoOutput(bool dooutput);
|
||||
|
||||
istream &getInputStream();
|
||||
ostream &getOutputStream();
|
||||
|
||||
const char *getLastError() const;
|
||||
void setLastError(const char *);
|
||||
|
||||
protected:
|
||||
bool connected;
|
||||
bool doInput;
|
||||
bool doOutput;
|
||||
URL url;
|
||||
|
||||
virtual void action();
|
||||
virtual void setRequest();
|
||||
virtual void setContent();
|
||||
virtual void getResponse();
|
||||
virtual void getContent();
|
||||
|
||||
private:
|
||||
Fields *__request;
|
||||
Fields *__response;
|
||||
Socket *__sock;
|
||||
string __method;
|
||||
string __response_message;
|
||||
HTTP_RESPONSECODE __response_code;
|
||||
string __error_msg;
|
||||
};
|
||||
|
||||
inline const char *HttpURLConnection::getLastError() const
|
||||
{
|
||||
return __error_msg.c_str();
|
||||
}
|
||||
|
||||
inline void HttpURLConnection::setLastError(const char *e)
|
||||
{
|
||||
__error_msg = e;
|
||||
}
|
||||
|
||||
#endif // __HttpURLConnection_H
|
||||
|
@ -1,9 +1,7 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifdef WIN32
|
||||
# include <winsock.h>
|
||||
#elif defined(__HAIKU__)
|
||||
#if defined(__HAIKU__)
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
#else
|
||||
|
@ -1,455 +1,450 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __IppContent_H
|
||||
#define __IppContent_H
|
||||
|
||||
#ifdef WIN32
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#else
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
#endif
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__ || defined(WIN32))
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
enum IPP_OPERATION_ID {
|
||||
|
||||
/* reserved, not used: 0x0000 */
|
||||
/* reserved, not used: 0x0001 */
|
||||
|
||||
IPP_PRINT_JOB = 0x0002, // printer operation
|
||||
IPP_PRINT_URI = 0x0003, // printer operation
|
||||
IPP_VALIDATE_JOB = 0x0004, // printer operation
|
||||
IPP_CREATE_JOB = 0x0005, // printer operation
|
||||
|
||||
IPP_SEND_DOCUMENT = 0x0006, // job operation
|
||||
IPP_SEND_URI = 0x0007, // job operation
|
||||
IPP_CANCEL_JOB = 0x0008, // job operation
|
||||
IPP_GET_JOB_ATTRIBUTES = 0x0009, // job operation
|
||||
|
||||
IPP_GET_JOBS = 0x000A, // printer operation
|
||||
IPP_GET_PRINTER_ATTRIBUTES = 0x000B // printer operation
|
||||
|
||||
/* reserved for future operations: 0x000C-0x3FFF */
|
||||
/* reserved for private extensions: 0x4000-0x8FFF */
|
||||
};
|
||||
|
||||
enum IPP_STATUS_CODE {
|
||||
|
||||
IPP_SUCCESSFUL_OK_S = 0x0000, // successful
|
||||
IPP_SUCCESSFUL_OK = 0x0000, // successful
|
||||
IPP_SUCCESSFUL_OK_IGNORED_OR_SUBSTITUTED_ATTRIBUTES = 0x0001, // successful
|
||||
IPP_SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES = 0x0002, // successful
|
||||
IPP_SUCCESSFUL_OK_E = 0x00FF, // successful
|
||||
|
||||
IPP_INFORMATIONAL_S = 0x0100, // informational
|
||||
IPP_INFORMATIONAL_E = 0x01FF, // informational
|
||||
|
||||
IPP_REDIRECTION_S = 0x0200, // redirection
|
||||
IPP_REDIRECTION_SE = 0x02FF, // redirection
|
||||
|
||||
IPP_CLIENT_ERROR_S = 0x0400, // client-error
|
||||
IPP_CLIENT_ERROR_BAD_REQUEST = 0x0400, // client-error
|
||||
IPP_CLIENT_ERROR_FORBIDDEN = 0x0401, // client-error
|
||||
IPP_CLIENT_ERROR_NOT_AUTHENTICATED = 0x0402, // client-error
|
||||
IPP_CLIENT_ERROR_NOT_AUTHORIZED = 0x0403, // client-error
|
||||
IPP_CLIENT_ERROR_NOT_POSSIBLE = 0x0404, // client-error
|
||||
IPP_CLIENT_ERROR_TIMEOUT = 0x0405, // client-error
|
||||
IPP_CLIENT_ERROR_NOT_FOUND = 0x0406, // client-error
|
||||
IPP_CLIENT_ERROR_GONE = 0x0407, // client-error
|
||||
IPP_CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE = 0x0408, // client-error
|
||||
IPP_CLIENT_ERROR_REQUEST_VALUE_TOO_LONG = 0x0409, // client-error
|
||||
IPP_CLIENT_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED = 0x040A, // client-error
|
||||
IPP_CLIENT_ERROR_ATTRIBUTES_OR_VALUES_NOT_SUPPORTED = 0x040B, // client-error
|
||||
IPP_CLIENT_ERROR_URI_SCHEME_NOT_SUPPORTED = 0x040C, // client-error
|
||||
IPP_CLIENT_ERROR_CHARSET_NOT_SUPPORTED = 0x040D, // client-error
|
||||
IPP_CLIENT_ERROR_CONFLICTING_ATTRIBUTES = 0x040E, // client-error
|
||||
IPP_CLIENT_ERROR_E = 0x04FF, // client-error
|
||||
|
||||
IPP_SERVER_ERROR_S = 0x0500, // server-error
|
||||
IPP_SERVER_ERROR_INTERNAL_ERROR = 0x0500, // server-error
|
||||
IPP_SERVER_ERROR_OPERATION_NOT_SUPPORTED = 0x0501, // server-error
|
||||
IPP_SERVER_ERROR_SERVICE_UNAVAILABLE = 0x0502, // server-error
|
||||
IPP_SERVER_ERROR_VERSION_NOT_SUPPORTED = 0x0503, // server-error
|
||||
IPP_SERVER_ERROR_DEVICE_ERROR = 0x0504, // server-error
|
||||
IPP_SERVER_ERROR_TEMPORARY_ERROR = 0x0505, // server-error
|
||||
IPP_SERVER_ERROR_NOT_ACCEPTING_JOBS = 0x0506, // server-error
|
||||
IPP_SERVER_ERROR_BUSY = 0x0507, // server-error
|
||||
IPP_SERVER_ERROR_JOB_CANCELED = 0x0508, // server-error
|
||||
IPP_SERVER_ERROR_E = 0x05FF // server-error
|
||||
};
|
||||
|
||||
enum IPP_TAG {
|
||||
/* reserved: 0x00 */
|
||||
IPP_OPERATION_ATTRIBUTES_TAG = 0x01,
|
||||
IPP_JOB_ATTRIBUTES_TAG = 0x02,
|
||||
IPP_END_OF_ATTRIBUTES_TAG = 0x03,
|
||||
IPP_PRINTER_ATTRIBUTES_TAG = 0x04,
|
||||
IPP_UNSUPPORTED_ATTRIBUTES_TAG = 0x05,
|
||||
/* reserved for future delimiters: 0x06-0x0e */
|
||||
/* reserved for future chunking-end-of-attributes-tag: 0x0F */
|
||||
|
||||
IPP_UNSUPPORTED = 0x10,
|
||||
/* reserved for future 'default': 0x11 */
|
||||
IPP_UNKNOWN = 0x12,
|
||||
IPP_NO_VALUE = 0x13,
|
||||
/* reserved for future "out-of-band" values: 0x14-0x1F */
|
||||
/* reserved: 0x20 */
|
||||
IPP_INTEGER = 0x21,
|
||||
IPP_BOOLEAN = 0x22,
|
||||
IPP_ENUM = 0x23,
|
||||
/* reserved for future integer types: 0x24-0x2F */
|
||||
IPP_STRING = 0x30,
|
||||
IPP_DATETIME = 0x31,
|
||||
IPP_RESOLUTION = 0x32,
|
||||
IPP_RANGE_OF_INTEGER = 0x33,
|
||||
/* reserved for collection (in the future): 0x34 */
|
||||
IPP_TEXT_WITH_LANGUAGE = 0x35,
|
||||
IPP_NAME_WITH_LANGUAGE = 0x36,
|
||||
/* reserved for future octetString types: 0x37-0x3F */
|
||||
/* reserved: 0x40 */
|
||||
IPP_TEXT_WITHOUT_LANGUAGE = 0x41,
|
||||
IPP_NAME_WITHOUT_LANGUAGE = 0x42,
|
||||
/* reserved: 0x43 */
|
||||
IPP_KEYWORD = 0x44,
|
||||
IPP_URI = 0x45,
|
||||
IPP_URISCHEME = 0x46,
|
||||
IPP_CHARSET = 0x47,
|
||||
IPP_NATURAL_LANGUAGE = 0x48,
|
||||
IPP_MIME_MEDIA_TYPE = 0x49
|
||||
/* reserved for future character string types: 0x4A-0x5F */
|
||||
};
|
||||
|
||||
enum IPP_RESOLUTION_UNITS {
|
||||
IPP_DOTS_PER_INCH = 3,
|
||||
IPP_DOTS_PER_CENTIMETER = 4
|
||||
};
|
||||
|
||||
enum IPP_FINISHINGS {
|
||||
IPP_NONE = 3,
|
||||
IPP_STAPLE = 4,
|
||||
IPP_PUNCH = 5,
|
||||
IPP_COVER = 6,
|
||||
IPP_BIND = 7
|
||||
};
|
||||
|
||||
enum IPP_ORIENTATION_REQUESTED {
|
||||
IPP_PORTRAIT = 3,
|
||||
IPP_LANDSCAPE = 4,
|
||||
IPP_REVERSE_LANDSCAPE = 5,
|
||||
IPP_REVERSE_PORTRAIT = 6
|
||||
};
|
||||
|
||||
enum IPP_PRINT_QUALITY {
|
||||
IPP_DRAFT = 3,
|
||||
IPP_NORMAL = 4,
|
||||
IPP_HIGH = 5
|
||||
};
|
||||
|
||||
enum IPP_JOB_STATE {
|
||||
IPP_JOB_STATE_PENDING = 3,
|
||||
IPP_JOB_STATE_PENDING_HELD = 4,
|
||||
IPP_JOB_STATE_PROCESSING = 5,
|
||||
IPP_JOB_STATE_PROCESSING_STOPPED= 6,
|
||||
IPP_JOB_STATE_CANCELED = 7,
|
||||
IPP_JOB_STATE_ABORTED = 8,
|
||||
IPP_JOB_STATE_COMPLETED = 9
|
||||
};
|
||||
|
||||
enum IPP_PRINTER_STATE {
|
||||
IPP_PRINTER_STATEIDLE = 3,
|
||||
IPP_PRINTER_STATEPROCESSING = 4,
|
||||
IPP_PRINTER_STATESTOPPED = 5
|
||||
};
|
||||
|
||||
|
||||
class IppAttribute {
|
||||
public:
|
||||
IppAttribute(IPP_TAG);
|
||||
virtual ~IppAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
IPP_TAG tag;
|
||||
};
|
||||
|
||||
class IppNamedAttribute : public IppAttribute {
|
||||
public:
|
||||
IppNamedAttribute(IPP_TAG t);
|
||||
IppNamedAttribute(IPP_TAG t, const char *n);
|
||||
virtual ~IppNamedAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
string name;
|
||||
friend istream& operator >> (istream &is, IppNamedAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppNamedAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
virtual ostream &print(ostream &) const;
|
||||
};
|
||||
|
||||
class IppNoValueAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppNoValueAttribute(IPP_TAG t);
|
||||
IppNoValueAttribute(IPP_TAG t, const char *n);
|
||||
virtual ~IppNoValueAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppNoValueAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppNoValueAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
};
|
||||
|
||||
class IppBooleanAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppBooleanAttribute(IPP_TAG t);
|
||||
IppBooleanAttribute(IPP_TAG t, const char *n, bool f);
|
||||
virtual ~IppBooleanAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppBooleanAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppBooleanAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
bool value;
|
||||
};
|
||||
|
||||
class IppIntegerAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppIntegerAttribute(IPP_TAG t);
|
||||
IppIntegerAttribute(IPP_TAG t, const char *n, int v);
|
||||
virtual ~IppIntegerAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppIntegerAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppIntegerAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
long value;
|
||||
};
|
||||
|
||||
class DATETIME {
|
||||
public:
|
||||
DATETIME();
|
||||
DATETIME(const DATETIME &);
|
||||
DATETIME & operator = (const DATETIME &);
|
||||
friend istream& operator >> (istream &is, DATETIME &attr);
|
||||
friend ostream& operator << (ostream &os, const DATETIME &attr);
|
||||
|
||||
unsigned char datetime[11];
|
||||
};
|
||||
|
||||
class IppDatetimeAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppDatetimeAttribute(IPP_TAG t);
|
||||
IppDatetimeAttribute(IPP_TAG t, const char *n, const DATETIME *dt);
|
||||
virtual ~IppDatetimeAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppDatetimeAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppDatetimeAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
DATETIME datetime;
|
||||
};
|
||||
|
||||
class IppStringAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppStringAttribute(IPP_TAG t);
|
||||
IppStringAttribute(IPP_TAG t, const char *s, const char *s1);
|
||||
virtual ~IppStringAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppStringAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppStringAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
string text;
|
||||
};
|
||||
|
||||
class IppDoubleStringAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppDoubleStringAttribute(IPP_TAG t);
|
||||
IppDoubleStringAttribute(IPP_TAG t, const char *n, const char *s1, const char *s2);
|
||||
virtual ~IppDoubleStringAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
friend istream& operator >> (istream &is, IppDoubleStringAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppDoubleStringAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
virtual ostream &print(ostream &) const;
|
||||
|
||||
string text1;
|
||||
string text2;
|
||||
};
|
||||
|
||||
class IppResolutionAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppResolutionAttribute(IPP_TAG t);
|
||||
IppResolutionAttribute(IPP_TAG t, const char *n, int, int, IPP_RESOLUTION_UNITS);
|
||||
virtual ~IppResolutionAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppResolutionAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppResolutionAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
int xres;
|
||||
int yres;
|
||||
IPP_RESOLUTION_UNITS resolution_units;
|
||||
};
|
||||
|
||||
class IppRangeOfIntegerAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppRangeOfIntegerAttribute(IPP_TAG t);
|
||||
IppRangeOfIntegerAttribute(IPP_TAG t, const char *n, int, int);
|
||||
virtual ~IppRangeOfIntegerAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppRangeOfIntegerAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppRangeOfIntegerAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
long lower;
|
||||
long upper;
|
||||
};
|
||||
|
||||
class IppContent {
|
||||
public:
|
||||
IppContent();
|
||||
~IppContent();
|
||||
int length() const;
|
||||
istream &input(istream &);
|
||||
ostream &output(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppContent &ic)
|
||||
{
|
||||
return ic.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppContent &ic)
|
||||
{
|
||||
return ic.output(os);
|
||||
}
|
||||
void setVersion(unsigned short);
|
||||
unsigned short getVersion() const;
|
||||
void setOperationId(IPP_OPERATION_ID);
|
||||
IPP_OPERATION_ID getOperationId() const;
|
||||
void setRequestId(unsigned long);
|
||||
unsigned long getRequestId() const;
|
||||
IPP_STATUS_CODE getStatusCode() const;
|
||||
const char *getStatusMessage() const;
|
||||
|
||||
void setDelimiter(IPP_TAG tag);
|
||||
void setInteger(const char *name, int value);
|
||||
void setBoolean(const char *name, bool value);
|
||||
void setString(const char *name, const char *value);
|
||||
void setDateTime(const char *name, const DATETIME *dt);
|
||||
void setResolution(const char *name, int x, int y, IPP_RESOLUTION_UNITS u);
|
||||
void setRangeOfInteger(const char *name, int lower, int upper);
|
||||
void setTextWithLanguage(const char *name, const char *s1, const char *s2);
|
||||
void setNameWithLanguage(const char *name, const char *s1, const char *s2);
|
||||
void setTextWithoutLanguage(const char *name, const char *value);
|
||||
void setNameWithoutLanguage(const char *name, const char *value);
|
||||
void setKeyword(const char *name, const char *value);
|
||||
void setURI(const char *name, const char *value);
|
||||
void setURIScheme(const char *name, const char *value);
|
||||
void setCharset(const char *name, const char *value);
|
||||
void setNaturalLanguage(const char *name, const char *value);
|
||||
void setMimeMediaType(const char *name, const char *value);
|
||||
|
||||
void setRawData(const char *file, int size = -1);
|
||||
void setRawData(istream &is, int size = -1);
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
bool operator !() const;
|
||||
bool good() const;
|
||||
bool fail() const;
|
||||
|
||||
private:
|
||||
list<IppAttribute *> attrs;
|
||||
unsigned short version;
|
||||
unsigned short operation_id;
|
||||
unsigned long request_id;
|
||||
string file_path;
|
||||
istream *is;
|
||||
int size;
|
||||
};
|
||||
|
||||
#endif // __IppContent_H
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __IppContent_H
|
||||
#define __IppContent_H
|
||||
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__)
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
enum IPP_OPERATION_ID {
|
||||
|
||||
/* reserved, not used: 0x0000 */
|
||||
/* reserved, not used: 0x0001 */
|
||||
|
||||
IPP_PRINT_JOB = 0x0002, // printer operation
|
||||
IPP_PRINT_URI = 0x0003, // printer operation
|
||||
IPP_VALIDATE_JOB = 0x0004, // printer operation
|
||||
IPP_CREATE_JOB = 0x0005, // printer operation
|
||||
|
||||
IPP_SEND_DOCUMENT = 0x0006, // job operation
|
||||
IPP_SEND_URI = 0x0007, // job operation
|
||||
IPP_CANCEL_JOB = 0x0008, // job operation
|
||||
IPP_GET_JOB_ATTRIBUTES = 0x0009, // job operation
|
||||
|
||||
IPP_GET_JOBS = 0x000A, // printer operation
|
||||
IPP_GET_PRINTER_ATTRIBUTES = 0x000B // printer operation
|
||||
|
||||
/* reserved for future operations: 0x000C-0x3FFF */
|
||||
/* reserved for private extensions: 0x4000-0x8FFF */
|
||||
};
|
||||
|
||||
enum IPP_STATUS_CODE {
|
||||
|
||||
IPP_SUCCESSFUL_OK_S = 0x0000, // successful
|
||||
IPP_SUCCESSFUL_OK = 0x0000, // successful
|
||||
IPP_SUCCESSFUL_OK_IGNORED_OR_SUBSTITUTED_ATTRIBUTES = 0x0001, // successful
|
||||
IPP_SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES = 0x0002, // successful
|
||||
IPP_SUCCESSFUL_OK_E = 0x00FF, // successful
|
||||
|
||||
IPP_INFORMATIONAL_S = 0x0100, // informational
|
||||
IPP_INFORMATIONAL_E = 0x01FF, // informational
|
||||
|
||||
IPP_REDIRECTION_S = 0x0200, // redirection
|
||||
IPP_REDIRECTION_SE = 0x02FF, // redirection
|
||||
|
||||
IPP_CLIENT_ERROR_S = 0x0400, // client-error
|
||||
IPP_CLIENT_ERROR_BAD_REQUEST = 0x0400, // client-error
|
||||
IPP_CLIENT_ERROR_FORBIDDEN = 0x0401, // client-error
|
||||
IPP_CLIENT_ERROR_NOT_AUTHENTICATED = 0x0402, // client-error
|
||||
IPP_CLIENT_ERROR_NOT_AUTHORIZED = 0x0403, // client-error
|
||||
IPP_CLIENT_ERROR_NOT_POSSIBLE = 0x0404, // client-error
|
||||
IPP_CLIENT_ERROR_TIMEOUT = 0x0405, // client-error
|
||||
IPP_CLIENT_ERROR_NOT_FOUND = 0x0406, // client-error
|
||||
IPP_CLIENT_ERROR_GONE = 0x0407, // client-error
|
||||
IPP_CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE = 0x0408, // client-error
|
||||
IPP_CLIENT_ERROR_REQUEST_VALUE_TOO_LONG = 0x0409, // client-error
|
||||
IPP_CLIENT_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED = 0x040A, // client-error
|
||||
IPP_CLIENT_ERROR_ATTRIBUTES_OR_VALUES_NOT_SUPPORTED = 0x040B, // client-error
|
||||
IPP_CLIENT_ERROR_URI_SCHEME_NOT_SUPPORTED = 0x040C, // client-error
|
||||
IPP_CLIENT_ERROR_CHARSET_NOT_SUPPORTED = 0x040D, // client-error
|
||||
IPP_CLIENT_ERROR_CONFLICTING_ATTRIBUTES = 0x040E, // client-error
|
||||
IPP_CLIENT_ERROR_E = 0x04FF, // client-error
|
||||
|
||||
IPP_SERVER_ERROR_S = 0x0500, // server-error
|
||||
IPP_SERVER_ERROR_INTERNAL_ERROR = 0x0500, // server-error
|
||||
IPP_SERVER_ERROR_OPERATION_NOT_SUPPORTED = 0x0501, // server-error
|
||||
IPP_SERVER_ERROR_SERVICE_UNAVAILABLE = 0x0502, // server-error
|
||||
IPP_SERVER_ERROR_VERSION_NOT_SUPPORTED = 0x0503, // server-error
|
||||
IPP_SERVER_ERROR_DEVICE_ERROR = 0x0504, // server-error
|
||||
IPP_SERVER_ERROR_TEMPORARY_ERROR = 0x0505, // server-error
|
||||
IPP_SERVER_ERROR_NOT_ACCEPTING_JOBS = 0x0506, // server-error
|
||||
IPP_SERVER_ERROR_BUSY = 0x0507, // server-error
|
||||
IPP_SERVER_ERROR_JOB_CANCELED = 0x0508, // server-error
|
||||
IPP_SERVER_ERROR_E = 0x05FF // server-error
|
||||
};
|
||||
|
||||
enum IPP_TAG {
|
||||
/* reserved: 0x00 */
|
||||
IPP_OPERATION_ATTRIBUTES_TAG = 0x01,
|
||||
IPP_JOB_ATTRIBUTES_TAG = 0x02,
|
||||
IPP_END_OF_ATTRIBUTES_TAG = 0x03,
|
||||
IPP_PRINTER_ATTRIBUTES_TAG = 0x04,
|
||||
IPP_UNSUPPORTED_ATTRIBUTES_TAG = 0x05,
|
||||
/* reserved for future delimiters: 0x06-0x0e */
|
||||
/* reserved for future chunking-end-of-attributes-tag: 0x0F */
|
||||
|
||||
IPP_UNSUPPORTED = 0x10,
|
||||
/* reserved for future 'default': 0x11 */
|
||||
IPP_UNKNOWN = 0x12,
|
||||
IPP_NO_VALUE = 0x13,
|
||||
/* reserved for future "out-of-band" values: 0x14-0x1F */
|
||||
/* reserved: 0x20 */
|
||||
IPP_INTEGER = 0x21,
|
||||
IPP_BOOLEAN = 0x22,
|
||||
IPP_ENUM = 0x23,
|
||||
/* reserved for future integer types: 0x24-0x2F */
|
||||
IPP_STRING = 0x30,
|
||||
IPP_DATETIME = 0x31,
|
||||
IPP_RESOLUTION = 0x32,
|
||||
IPP_RANGE_OF_INTEGER = 0x33,
|
||||
/* reserved for collection (in the future): 0x34 */
|
||||
IPP_TEXT_WITH_LANGUAGE = 0x35,
|
||||
IPP_NAME_WITH_LANGUAGE = 0x36,
|
||||
/* reserved for future octetString types: 0x37-0x3F */
|
||||
/* reserved: 0x40 */
|
||||
IPP_TEXT_WITHOUT_LANGUAGE = 0x41,
|
||||
IPP_NAME_WITHOUT_LANGUAGE = 0x42,
|
||||
/* reserved: 0x43 */
|
||||
IPP_KEYWORD = 0x44,
|
||||
IPP_URI = 0x45,
|
||||
IPP_URISCHEME = 0x46,
|
||||
IPP_CHARSET = 0x47,
|
||||
IPP_NATURAL_LANGUAGE = 0x48,
|
||||
IPP_MIME_MEDIA_TYPE = 0x49
|
||||
/* reserved for future character string types: 0x4A-0x5F */
|
||||
};
|
||||
|
||||
enum IPP_RESOLUTION_UNITS {
|
||||
IPP_DOTS_PER_INCH = 3,
|
||||
IPP_DOTS_PER_CENTIMETER = 4
|
||||
};
|
||||
|
||||
enum IPP_FINISHINGS {
|
||||
IPP_NONE = 3,
|
||||
IPP_STAPLE = 4,
|
||||
IPP_PUNCH = 5,
|
||||
IPP_COVER = 6,
|
||||
IPP_BIND = 7
|
||||
};
|
||||
|
||||
enum IPP_ORIENTATION_REQUESTED {
|
||||
IPP_PORTRAIT = 3,
|
||||
IPP_LANDSCAPE = 4,
|
||||
IPP_REVERSE_LANDSCAPE = 5,
|
||||
IPP_REVERSE_PORTRAIT = 6
|
||||
};
|
||||
|
||||
enum IPP_PRINT_QUALITY {
|
||||
IPP_DRAFT = 3,
|
||||
IPP_NORMAL = 4,
|
||||
IPP_HIGH = 5
|
||||
};
|
||||
|
||||
enum IPP_JOB_STATE {
|
||||
IPP_JOB_STATE_PENDING = 3,
|
||||
IPP_JOB_STATE_PENDING_HELD = 4,
|
||||
IPP_JOB_STATE_PROCESSING = 5,
|
||||
IPP_JOB_STATE_PROCESSING_STOPPED= 6,
|
||||
IPP_JOB_STATE_CANCELED = 7,
|
||||
IPP_JOB_STATE_ABORTED = 8,
|
||||
IPP_JOB_STATE_COMPLETED = 9
|
||||
};
|
||||
|
||||
enum IPP_PRINTER_STATE {
|
||||
IPP_PRINTER_STATEIDLE = 3,
|
||||
IPP_PRINTER_STATEPROCESSING = 4,
|
||||
IPP_PRINTER_STATESTOPPED = 5
|
||||
};
|
||||
|
||||
|
||||
class IppAttribute {
|
||||
public:
|
||||
IppAttribute(IPP_TAG);
|
||||
virtual ~IppAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
IPP_TAG tag;
|
||||
};
|
||||
|
||||
class IppNamedAttribute : public IppAttribute {
|
||||
public:
|
||||
IppNamedAttribute(IPP_TAG t);
|
||||
IppNamedAttribute(IPP_TAG t, const char *n);
|
||||
virtual ~IppNamedAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
string name;
|
||||
friend istream& operator >> (istream &is, IppNamedAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppNamedAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
virtual ostream &print(ostream &) const;
|
||||
};
|
||||
|
||||
class IppNoValueAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppNoValueAttribute(IPP_TAG t);
|
||||
IppNoValueAttribute(IPP_TAG t, const char *n);
|
||||
virtual ~IppNoValueAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppNoValueAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppNoValueAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
};
|
||||
|
||||
class IppBooleanAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppBooleanAttribute(IPP_TAG t);
|
||||
IppBooleanAttribute(IPP_TAG t, const char *n, bool f);
|
||||
virtual ~IppBooleanAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppBooleanAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppBooleanAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
bool value;
|
||||
};
|
||||
|
||||
class IppIntegerAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppIntegerAttribute(IPP_TAG t);
|
||||
IppIntegerAttribute(IPP_TAG t, const char *n, int v);
|
||||
virtual ~IppIntegerAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppIntegerAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppIntegerAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
long value;
|
||||
};
|
||||
|
||||
class DATETIME {
|
||||
public:
|
||||
DATETIME();
|
||||
DATETIME(const DATETIME &);
|
||||
DATETIME & operator = (const DATETIME &);
|
||||
friend istream& operator >> (istream &is, DATETIME &attr);
|
||||
friend ostream& operator << (ostream &os, const DATETIME &attr);
|
||||
|
||||
unsigned char datetime[11];
|
||||
};
|
||||
|
||||
class IppDatetimeAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppDatetimeAttribute(IPP_TAG t);
|
||||
IppDatetimeAttribute(IPP_TAG t, const char *n, const DATETIME *dt);
|
||||
virtual ~IppDatetimeAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppDatetimeAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppDatetimeAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
DATETIME datetime;
|
||||
};
|
||||
|
||||
class IppStringAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppStringAttribute(IPP_TAG t);
|
||||
IppStringAttribute(IPP_TAG t, const char *s, const char *s1);
|
||||
virtual ~IppStringAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppStringAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppStringAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
string text;
|
||||
};
|
||||
|
||||
class IppDoubleStringAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppDoubleStringAttribute(IPP_TAG t);
|
||||
IppDoubleStringAttribute(IPP_TAG t, const char *n, const char *s1, const char *s2);
|
||||
virtual ~IppDoubleStringAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
friend istream& operator >> (istream &is, IppDoubleStringAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppDoubleStringAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
virtual ostream &print(ostream &) const;
|
||||
|
||||
string text1;
|
||||
string text2;
|
||||
};
|
||||
|
||||
class IppResolutionAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppResolutionAttribute(IPP_TAG t);
|
||||
IppResolutionAttribute(IPP_TAG t, const char *n, int, int, IPP_RESOLUTION_UNITS);
|
||||
virtual ~IppResolutionAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppResolutionAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppResolutionAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
int xres;
|
||||
int yres;
|
||||
IPP_RESOLUTION_UNITS resolution_units;
|
||||
};
|
||||
|
||||
class IppRangeOfIntegerAttribute : public IppNamedAttribute {
|
||||
public:
|
||||
IppRangeOfIntegerAttribute(IPP_TAG t);
|
||||
IppRangeOfIntegerAttribute(IPP_TAG t, const char *n, int, int);
|
||||
virtual ~IppRangeOfIntegerAttribute() {}
|
||||
virtual int length() const;
|
||||
virtual istream &input(istream &is);
|
||||
virtual ostream &output(ostream &os) const;
|
||||
virtual ostream &print(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppRangeOfIntegerAttribute &attr)
|
||||
{
|
||||
return attr.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppRangeOfIntegerAttribute &attr)
|
||||
{
|
||||
return attr.output(os);
|
||||
}
|
||||
|
||||
long lower;
|
||||
long upper;
|
||||
};
|
||||
|
||||
class IppContent {
|
||||
public:
|
||||
IppContent();
|
||||
~IppContent();
|
||||
int length() const;
|
||||
istream &input(istream &);
|
||||
ostream &output(ostream &) const;
|
||||
friend istream& operator >> (istream &is, IppContent &ic)
|
||||
{
|
||||
return ic.input(is);
|
||||
}
|
||||
friend ostream& operator << (ostream &os, const IppContent &ic)
|
||||
{
|
||||
return ic.output(os);
|
||||
}
|
||||
void setVersion(unsigned short);
|
||||
unsigned short getVersion() const;
|
||||
void setOperationId(IPP_OPERATION_ID);
|
||||
IPP_OPERATION_ID getOperationId() const;
|
||||
void setRequestId(unsigned long);
|
||||
unsigned long getRequestId() const;
|
||||
IPP_STATUS_CODE getStatusCode() const;
|
||||
const char *getStatusMessage() const;
|
||||
|
||||
void setDelimiter(IPP_TAG tag);
|
||||
void setInteger(const char *name, int value);
|
||||
void setBoolean(const char *name, bool value);
|
||||
void setString(const char *name, const char *value);
|
||||
void setDateTime(const char *name, const DATETIME *dt);
|
||||
void setResolution(const char *name, int x, int y, IPP_RESOLUTION_UNITS u);
|
||||
void setRangeOfInteger(const char *name, int lower, int upper);
|
||||
void setTextWithLanguage(const char *name, const char *s1, const char *s2);
|
||||
void setNameWithLanguage(const char *name, const char *s1, const char *s2);
|
||||
void setTextWithoutLanguage(const char *name, const char *value);
|
||||
void setNameWithoutLanguage(const char *name, const char *value);
|
||||
void setKeyword(const char *name, const char *value);
|
||||
void setURI(const char *name, const char *value);
|
||||
void setURIScheme(const char *name, const char *value);
|
||||
void setCharset(const char *name, const char *value);
|
||||
void setNaturalLanguage(const char *name, const char *value);
|
||||
void setMimeMediaType(const char *name, const char *value);
|
||||
|
||||
void setRawData(const char *file, int size = -1);
|
||||
void setRawData(istream &is, int size = -1);
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
bool operator !() const;
|
||||
bool good() const;
|
||||
bool fail() const;
|
||||
|
||||
private:
|
||||
list<IppAttribute *> attrs;
|
||||
unsigned short version;
|
||||
unsigned short operation_id;
|
||||
unsigned long request_id;
|
||||
string file_path;
|
||||
istream *is;
|
||||
int size;
|
||||
};
|
||||
|
||||
#endif // __IppContent_H
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "IppDefs.h"
|
||||
#include "DbgMsg.h"
|
||||
|
||||
#if (!__MWERKS__ || defined(WIN32))
|
||||
#if (!__MWERKS__)
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
|
@ -1,47 +1,47 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __IppTransport_H
|
||||
#define __IppTransport_H
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <Message.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__ || defined(WIN32))
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class IppTransport : public BDataIO {
|
||||
public:
|
||||
IppTransport(BMessage *msg);
|
||||
virtual ~IppTransport();
|
||||
virtual ssize_t Read(void *buffer, size_t size);
|
||||
virtual ssize_t Write(const void *buffer, size_t size);
|
||||
|
||||
bool operator !() const;
|
||||
bool fail() const;
|
||||
|
||||
private:
|
||||
char __url[256];
|
||||
char __user[256];
|
||||
char __file[256];
|
||||
int32 __jobid;
|
||||
bool __error;
|
||||
fstream __fs;
|
||||
};
|
||||
|
||||
inline bool IppTransport::fail() const
|
||||
{
|
||||
return __error;
|
||||
}
|
||||
|
||||
inline bool IppTransport::operator !() const
|
||||
{
|
||||
return fail();
|
||||
}
|
||||
|
||||
#endif // __IppTransport_H
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __IppTransport_H
|
||||
#define __IppTransport_H
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <Message.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__)
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class IppTransport : public BDataIO {
|
||||
public:
|
||||
IppTransport(BMessage *msg);
|
||||
virtual ~IppTransport();
|
||||
virtual ssize_t Read(void *buffer, size_t size);
|
||||
virtual ssize_t Write(const void *buffer, size_t size);
|
||||
|
||||
bool operator !() const;
|
||||
bool fail() const;
|
||||
|
||||
private:
|
||||
char __url[256];
|
||||
char __user[256];
|
||||
char __file[256];
|
||||
int32 __jobid;
|
||||
bool __error;
|
||||
fstream __fs;
|
||||
};
|
||||
|
||||
inline bool IppTransport::fail() const
|
||||
{
|
||||
return __error;
|
||||
}
|
||||
|
||||
inline bool IppTransport::operator !() const
|
||||
{
|
||||
return fail();
|
||||
}
|
||||
|
||||
#endif // __IppTransport_H
|
||||
|
@ -1,11 +1,6 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
#include <ostream>
|
||||
#include <cstring>
|
||||
#else
|
||||
#ifdef __HAIKU__
|
||||
# include <sys/socket.h>
|
||||
#else
|
||||
@ -21,7 +16,6 @@ char *itoa(int i, char *buf, int unit)
|
||||
}
|
||||
#define stricmp strcasecmp
|
||||
#define strnicmp strncasecmp
|
||||
#endif // WIN32
|
||||
|
||||
#include <list>
|
||||
#include "IppURLConnection.h"
|
||||
|
@ -1,68 +1,68 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __URL_H
|
||||
#define __URL_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__ || defined(WIN32))
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class URL {
|
||||
public:
|
||||
URL(const char *spec);
|
||||
URL(const char *protocol, const char *host, int port, const char *file);
|
||||
URL(const char *protocol, const char *host, const char *file);
|
||||
// URL(URL &, const char *spec);
|
||||
|
||||
int getPort() const;
|
||||
const char *getProtocol() const;
|
||||
const char *getHost() const;
|
||||
const char *getFile() const;
|
||||
const char *getRef() const;
|
||||
|
||||
URL(const URL &);
|
||||
URL &operator = (const URL &);
|
||||
bool operator == (const URL &);
|
||||
|
||||
protected:
|
||||
// void set(const char *protocol, const char *host, int port, const char *file, const char *ref);
|
||||
|
||||
private:
|
||||
string __protocol;
|
||||
string __host;
|
||||
string __file;
|
||||
string __ref;
|
||||
int __port;
|
||||
};
|
||||
|
||||
inline int URL::getPort() const
|
||||
{
|
||||
return __port;
|
||||
}
|
||||
|
||||
inline const char *URL::getProtocol() const
|
||||
{
|
||||
return __protocol.c_str();
|
||||
}
|
||||
|
||||
inline const char *URL::getHost() const
|
||||
{
|
||||
return __host.c_str();
|
||||
}
|
||||
|
||||
inline const char *URL::getFile() const
|
||||
{
|
||||
return __file.c_str();
|
||||
}
|
||||
|
||||
inline const char *URL::getRef() const
|
||||
{
|
||||
return __ref.c_str();
|
||||
}
|
||||
|
||||
#endif // __URL_H
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __URL_H
|
||||
#define __URL_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__)
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class URL {
|
||||
public:
|
||||
URL(const char *spec);
|
||||
URL(const char *protocol, const char *host, int port, const char *file);
|
||||
URL(const char *protocol, const char *host, const char *file);
|
||||
// URL(URL &, const char *spec);
|
||||
|
||||
int getPort() const;
|
||||
const char *getProtocol() const;
|
||||
const char *getHost() const;
|
||||
const char *getFile() const;
|
||||
const char *getRef() const;
|
||||
|
||||
URL(const URL &);
|
||||
URL &operator = (const URL &);
|
||||
bool operator == (const URL &);
|
||||
|
||||
protected:
|
||||
// void set(const char *protocol, const char *host, int port, const char *file, const char *ref);
|
||||
|
||||
private:
|
||||
string __protocol;
|
||||
string __host;
|
||||
string __file;
|
||||
string __ref;
|
||||
int __port;
|
||||
};
|
||||
|
||||
inline int URL::getPort() const
|
||||
{
|
||||
return __port;
|
||||
}
|
||||
|
||||
inline const char *URL::getProtocol() const
|
||||
{
|
||||
return __protocol.c_str();
|
||||
}
|
||||
|
||||
inline const char *URL::getHost() const
|
||||
{
|
||||
return __host.c_str();
|
||||
}
|
||||
|
||||
inline const char *URL::getFile() const
|
||||
{
|
||||
return __file.c_str();
|
||||
}
|
||||
|
||||
inline const char *URL::getRef() const
|
||||
{
|
||||
return __ref.c_str();
|
||||
}
|
||||
|
||||
#endif // __URL_H
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "LprDefs.h"
|
||||
#include "DbgMsg.h"
|
||||
|
||||
#if (!__MWERKS__ || defined(WIN32))
|
||||
#if (!__MWERKS__)
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
|
@ -1,48 +1,48 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __LprTransport_H
|
||||
#define __LprTransport_H
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <Message.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__ || defined(WIN32))
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class LprTransport : public BDataIO {
|
||||
public:
|
||||
LprTransport(BMessage *msg);
|
||||
virtual ~LprTransport();
|
||||
virtual ssize_t Read(void *buffer, size_t size);
|
||||
virtual ssize_t Write(const void *buffer, size_t size);
|
||||
|
||||
bool operator !() const;
|
||||
bool fail() const;
|
||||
|
||||
private:
|
||||
char __server[256];
|
||||
char __queue[256];
|
||||
char __file[256];
|
||||
char __user[256];
|
||||
int32 __jobid;
|
||||
fstream __fs;
|
||||
bool __error;
|
||||
};
|
||||
|
||||
inline bool LprTransport::fail() const
|
||||
{
|
||||
return __error;
|
||||
}
|
||||
|
||||
inline bool LprTransport::operator !() const
|
||||
{
|
||||
return fail();
|
||||
}
|
||||
|
||||
#endif // __LprTransport_H
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __LprTransport_H
|
||||
#define __LprTransport_H
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <Message.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__)
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class LprTransport : public BDataIO {
|
||||
public:
|
||||
LprTransport(BMessage *msg);
|
||||
virtual ~LprTransport();
|
||||
virtual ssize_t Read(void *buffer, size_t size);
|
||||
virtual ssize_t Write(const void *buffer, size_t size);
|
||||
|
||||
bool operator !() const;
|
||||
bool fail() const;
|
||||
|
||||
private:
|
||||
char __server[256];
|
||||
char __queue[256];
|
||||
char __file[256];
|
||||
char __user[256];
|
||||
int32 __jobid;
|
||||
fstream __fs;
|
||||
bool __error;
|
||||
};
|
||||
|
||||
inline bool LprTransport::fail() const
|
||||
{
|
||||
return __error;
|
||||
}
|
||||
|
||||
inline bool LprTransport::operator !() const
|
||||
{
|
||||
return fail();
|
||||
}
|
||||
|
||||
#endif // __LprTransport_H
|
||||
|
@ -1,21 +1,15 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifdef WIN32
|
||||
# include <windows.h>
|
||||
# include <winsock.h>
|
||||
# include <sstream>
|
||||
#ifdef __HAIKU__
|
||||
# include <sys/socket.h>
|
||||
# include <netdb.h>
|
||||
#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"
|
||||
# include <net/socket.h>
|
||||
# include <net/netdb.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "_sstream"
|
||||
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
@ -23,7 +17,7 @@
|
||||
#include "Socket.h"
|
||||
//#include "DbgMsg.h"
|
||||
|
||||
#if (!__MWERKS__ || defined(WIN32))
|
||||
#if (!__MWERKS__)
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
@ -51,12 +45,7 @@ using namespace std;
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define EADDRINUSE WSAEADDRINUSE
|
||||
#define ERRNO WSAGetLastError()
|
||||
#else
|
||||
#define ERRNO errno
|
||||
#endif
|
||||
#define ERRNO errno
|
||||
|
||||
|
||||
LpsClient::LpsClient(const char *host)
|
||||
|
@ -1,56 +1,51 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __LPSCLIENT_H
|
||||
#define __LPSCLIENT_H
|
||||
|
||||
#ifdef WIN32
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#else
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
#endif
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__ || defined(WIN32))
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class Socket;
|
||||
|
||||
class LPSException {
|
||||
private:
|
||||
string str;
|
||||
public:
|
||||
LPSException(const string &what_arg) : str(what_arg) {}
|
||||
const char *what() const { return str.c_str(); }
|
||||
};
|
||||
|
||||
class LpsClient {
|
||||
public:
|
||||
LpsClient(const char *host);
|
||||
~LpsClient();
|
||||
void connect() throw(LPSException);
|
||||
void close();
|
||||
void receiveJob(const char *queue) throw(LPSException);
|
||||
void receiveControlFile(int cfsize, const char *cfname) throw(LPSException);
|
||||
void receiveDataFile(int dfsize, const char *dfname) throw(LPSException);
|
||||
void transferData(const char *buffer, int size = -1) throw(LPSException);
|
||||
void transferData(istream &is, int size = -1) throw(LPSException);
|
||||
void endTransfer() throw(LPSException);
|
||||
void checkAck() throw(LPSException);
|
||||
|
||||
protected:
|
||||
bool connected;
|
||||
|
||||
private:
|
||||
string __host;
|
||||
Socket *__sock;
|
||||
istream *__is;
|
||||
ostream *__os;
|
||||
};
|
||||
|
||||
#endif /* __LPSCLIENT_H */
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __LPSCLIENT_H
|
||||
#define __LPSCLIENT_H
|
||||
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__)
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class Socket;
|
||||
|
||||
class LPSException {
|
||||
private:
|
||||
string str;
|
||||
public:
|
||||
LPSException(const string &what_arg) : str(what_arg) {}
|
||||
const char *what() const { return str.c_str(); }
|
||||
};
|
||||
|
||||
class LpsClient {
|
||||
public:
|
||||
LpsClient(const char *host);
|
||||
~LpsClient();
|
||||
void connect() throw(LPSException);
|
||||
void close();
|
||||
void receiveJob(const char *queue) throw(LPSException);
|
||||
void receiveControlFile(int cfsize, const char *cfname) throw(LPSException);
|
||||
void receiveDataFile(int dfsize, const char *dfname) throw(LPSException);
|
||||
void transferData(const char *buffer, int size = -1) throw(LPSException);
|
||||
void transferData(istream &is, int size = -1) throw(LPSException);
|
||||
void endTransfer() throw(LPSException);
|
||||
void checkAck() throw(LPSException);
|
||||
|
||||
protected:
|
||||
bool connected;
|
||||
|
||||
private:
|
||||
string __host;
|
||||
Socket *__sock;
|
||||
istream *__is;
|
||||
ostream *__os;
|
||||
};
|
||||
|
||||
#endif /* __LPSCLIENT_H */
|
||||
|
@ -9,8 +9,7 @@ if $(BONE_COMPATIBLE) {
|
||||
Objects
|
||||
DbgMsg.cpp
|
||||
Socket.cpp
|
||||
SocketStream1.cpp
|
||||
SocketStream2.cpp
|
||||
SocketStream.cpp
|
||||
;
|
||||
|
||||
|
||||
|
@ -1,17 +1,13 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#ifdef __HAIKU__
|
||||
# include <sys/socket.h>
|
||||
#else
|
||||
# include <net/socket.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif // WIN32
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@ -23,29 +19,7 @@
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define EADDRINUSE WSAEADDRINUSE
|
||||
#define errno WSAGetLastError()
|
||||
#else
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
class WIN32SOCKET {
|
||||
public:
|
||||
WIN32SOCKET()
|
||||
{
|
||||
WSADATA winsockdata;
|
||||
WSAStartup(MAKEWORD(1,1), &winsockdata);
|
||||
}
|
||||
~WIN32SOCKET()
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
};
|
||||
|
||||
WIN32SOCKET win32socket;
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
Socket::Socket(const char *host, int port)
|
||||
: __sock(-1), __is(NULL), __os(NULL), __error(false)
|
||||
|
@ -1,68 +1,63 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __Socket_H
|
||||
#define __Socket_H
|
||||
|
||||
#ifdef WIN32
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#else
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
#endif // WIN32
|
||||
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__ || defined(WIN32))
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class Socket {
|
||||
public:
|
||||
Socket(const char *host, int port);
|
||||
Socket(const char *host, int port, int localPort);
|
||||
~Socket();
|
||||
|
||||
bool operator !() const;
|
||||
bool good() const;
|
||||
bool fail() const;
|
||||
|
||||
void close();
|
||||
int read(char *buffer, int size, int flags = 0);
|
||||
int write(const char *buffer, int size, int flags = 0);
|
||||
|
||||
istream &getInputStream();
|
||||
ostream &getOutputStream();
|
||||
|
||||
int getPort() const;
|
||||
const char *getLastError() const;
|
||||
|
||||
private:
|
||||
Socket(const Socket &);
|
||||
Socket &operator = (const Socket &);
|
||||
void open();
|
||||
|
||||
string __host;
|
||||
int __port;
|
||||
int __localPort;
|
||||
int __sock;
|
||||
istream *__is;
|
||||
ostream *__os;
|
||||
bool __error;
|
||||
char __error_msg[256];
|
||||
};
|
||||
|
||||
inline int Socket::getPort() const
|
||||
{
|
||||
return __port;
|
||||
}
|
||||
|
||||
inline const char *Socket::getLastError() const
|
||||
{
|
||||
return __error_msg;
|
||||
}
|
||||
|
||||
#endif // __Socket_H
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __Socket_H
|
||||
#define __Socket_H
|
||||
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#if (!__MWERKS__)
|
||||
using namespace std;
|
||||
#else
|
||||
#define std
|
||||
#endif
|
||||
|
||||
class Socket {
|
||||
public:
|
||||
Socket(const char *host, int port);
|
||||
Socket(const char *host, int port, int localPort);
|
||||
~Socket();
|
||||
|
||||
bool operator !() const;
|
||||
bool good() const;
|
||||
bool fail() const;
|
||||
|
||||
void close();
|
||||
int read(char *buffer, int size, int flags = 0);
|
||||
int write(const char *buffer, int size, int flags = 0);
|
||||
|
||||
istream &getInputStream();
|
||||
ostream &getOutputStream();
|
||||
|
||||
int getPort() const;
|
||||
const char *getLastError() const;
|
||||
|
||||
private:
|
||||
Socket(const Socket &);
|
||||
Socket &operator = (const Socket &);
|
||||
void open();
|
||||
|
||||
string __host;
|
||||
int __port;
|
||||
int __localPort;
|
||||
int __sock;
|
||||
istream *__is;
|
||||
ostream *__os;
|
||||
bool __error;
|
||||
char __error_msg[256];
|
||||
};
|
||||
|
||||
inline int Socket::getPort() const
|
||||
{
|
||||
return __port;
|
||||
}
|
||||
|
||||
inline const char *Socket::getLastError() const
|
||||
{
|
||||
return __error_msg;
|
||||
}
|
||||
|
||||
#endif // __Socket_H
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef WIN32
|
||||
#ifdef __HAIKU__
|
||||
# include <sys/socket.h>
|
||||
#else
|
||||
@ -127,5 +126,3 @@ osocketstream::~osocketstream()
|
||||
{
|
||||
flush();
|
||||
}
|
||||
|
||||
#endif // !WIN32
|
@ -1,8 +1,60 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifdef WIN32
|
||||
#include "SocketStream1.h"
|
||||
#else
|
||||
#include "SocketStream2.h"
|
||||
#endif
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __SocketStream_H
|
||||
#define __SocketStream_H
|
||||
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
#include <streambuf.h>
|
||||
|
||||
class Socket;
|
||||
|
||||
class socketstreambuf : public streambuf {
|
||||
public:
|
||||
explicit socketstreambuf(Socket *sock, streamsize n);
|
||||
~socketstreambuf();
|
||||
|
||||
protected:
|
||||
virtual int underflow();
|
||||
virtual int overflow(int);
|
||||
virtual int sync();
|
||||
|
||||
private:
|
||||
Socket *__sock;
|
||||
streamsize __alsize;
|
||||
char *__pu;
|
||||
char *__po;
|
||||
};
|
||||
|
||||
class socketstreambase : public virtual ios {
|
||||
public:
|
||||
socketstreambuf *rdbuf();
|
||||
|
||||
protected:
|
||||
socketstreambase(Socket *sock, streamsize n);
|
||||
~socketstreambase() {}
|
||||
|
||||
private:
|
||||
socketstreambuf buf;
|
||||
};
|
||||
|
||||
inline socketstreambuf *socketstreambase::rdbuf()
|
||||
{
|
||||
return &this->buf;
|
||||
}
|
||||
|
||||
class isocketstream : public socketstreambase, public istream {
|
||||
public:
|
||||
explicit isocketstream(Socket *sock, streamsize n = 4096);
|
||||
virtual ~isocketstream();
|
||||
};
|
||||
|
||||
|
||||
class osocketstream : public socketstreambase, public ostream {
|
||||
public:
|
||||
explicit osocketstream(Socket *sock, streamsize n = 4096);
|
||||
virtual ~osocketstream();
|
||||
};
|
||||
|
||||
#endif // __SocketStream_H
|
||||
|
@ -1,124 +0,0 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#include "Socket.h"
|
||||
#include "SocketStream.h"
|
||||
|
||||
namespace std {
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
|
||||
socketstreambuf::socketstreambuf(Socket *sock, streamsize n)
|
||||
: basic_streambuf<char_type, traits>(), __alsize(n), __sock(sock), __pu(NULL), __po(NULL)
|
||||
{
|
||||
setg(0, 0, 0);
|
||||
setp(0, 0);
|
||||
}
|
||||
|
||||
socketstreambuf::~socketstreambuf()
|
||||
{
|
||||
if (__pu)
|
||||
delete [] __pu;
|
||||
if (__po)
|
||||
delete [] __po;
|
||||
}
|
||||
|
||||
|
||||
socketstreambuf::int_type socketstreambuf::underflow()
|
||||
{
|
||||
// cout << "***** underflow" << endl;
|
||||
|
||||
if (__pu == NULL) {
|
||||
__pu = new char[__alsize];
|
||||
}
|
||||
|
||||
int 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 traits::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
return traits::eof();
|
||||
}
|
||||
|
||||
socketstreambuf::int_type socketstreambuf::overflow(socketstreambuf::int_type c)
|
||||
{
|
||||
// cout << "***** overflow" << endl;
|
||||
|
||||
if (__po == NULL) {
|
||||
__po = new char[__alsize];
|
||||
setp(__po, __po + __alsize);
|
||||
} else if (sync() != 0) {
|
||||
return traits::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;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
|
||||
isocketstream::isocketstream(Socket *sock, streamsize n)
|
||||
: basic_istream<char_type, traits>(&ssb_), ssb_(sock, n)
|
||||
{
|
||||
}
|
||||
|
||||
isocketstream::~isocketstream()
|
||||
{
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
|
||||
osocketstream::osocketstream(Socket *sock, streamsize n)
|
||||
: basic_ostream<char_type, traits>(&ssb_), ssb_(sock, n)
|
||||
{
|
||||
}
|
||||
|
||||
osocketstream::~osocketstream()
|
||||
{
|
||||
flush();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
|
||||
}
|
||||
|
||||
#endif // WIN32
|
@ -1,81 +0,0 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __SocketStream1_H
|
||||
#define __SocketStream1_H
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <streambuf>
|
||||
|
||||
class Socket;
|
||||
|
||||
namespace std {
|
||||
|
||||
class socketstreambuf : public basic_streambuf< char, char_traits<char> > {
|
||||
public:
|
||||
typedef char char_type;
|
||||
typedef char_traits<char> traits;
|
||||
typedef traits::int_type int_type;
|
||||
typedef traits::pos_type pos_type;
|
||||
typedef traits::off_type off_type;
|
||||
|
||||
explicit socketstreambuf(Socket *sock, streamsize n);
|
||||
virtual ~socketstreambuf();
|
||||
|
||||
protected:
|
||||
virtual int_type underflow();
|
||||
virtual int_type overflow(int_type c = traits::eof());
|
||||
virtual int sync();
|
||||
|
||||
private:
|
||||
Socket *__sock;
|
||||
streamsize __alsize;
|
||||
char *__pu;
|
||||
char *__po;
|
||||
};
|
||||
|
||||
class isocketstream : public basic_istream< char, char_traits<char> > {
|
||||
public:
|
||||
typedef char char_type;
|
||||
typedef char_traits<char> traits;
|
||||
typedef traits::int_type int_type;
|
||||
typedef traits::pos_type pos_type;
|
||||
typedef traits::off_type off_type;
|
||||
|
||||
explicit isocketstream(Socket *sock, streamsize n = 4096);
|
||||
virtual ~isocketstream();
|
||||
|
||||
socketstreambuf *rdbuf() const
|
||||
{
|
||||
return (socketstreambuf *)basic_ios<char_type, traits>::rdbuf();
|
||||
}
|
||||
|
||||
private:
|
||||
socketstreambuf ssb_;
|
||||
};
|
||||
|
||||
|
||||
class osocketstream : public basic_ostream< char, char_traits<char> > {
|
||||
public:
|
||||
typedef char char_type;
|
||||
typedef char_traits<char> traits;
|
||||
typedef traits::int_type int_type;
|
||||
typedef traits::pos_type pos_type;
|
||||
typedef traits::off_type off_type;
|
||||
|
||||
explicit osocketstream(Socket *sock, streamsize n = 4096);
|
||||
virtual ~osocketstream();
|
||||
|
||||
socketstreambuf *rdbuf() const
|
||||
{
|
||||
return (socketstreambuf *)basic_ios<char_type, traits>::rdbuf();
|
||||
}
|
||||
|
||||
private:
|
||||
socketstreambuf ssb_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __SocketStream1_H
|
@ -1,60 +0,0 @@
|
||||
// Sun, 18 Jun 2000
|
||||
// Y.Takagi
|
||||
|
||||
#ifndef __SocketStream2_H
|
||||
#define __SocketStream2_H
|
||||
|
||||
#include <istream.h>
|
||||
#include <ostream.h>
|
||||
#include <streambuf.h>
|
||||
|
||||
class Socket;
|
||||
|
||||
class socketstreambuf : public streambuf {
|
||||
public:
|
||||
explicit socketstreambuf(Socket *sock, streamsize n);
|
||||
~socketstreambuf();
|
||||
|
||||
protected:
|
||||
virtual int underflow();
|
||||
virtual int overflow(int);
|
||||
virtual int sync();
|
||||
|
||||
private:
|
||||
Socket *__sock;
|
||||
streamsize __alsize;
|
||||
char *__pu;
|
||||
char *__po;
|
||||
};
|
||||
|
||||
class socketstreambase : public virtual ios {
|
||||
public:
|
||||
socketstreambuf *rdbuf();
|
||||
|
||||
protected:
|
||||
socketstreambase(Socket *sock, streamsize n);
|
||||
~socketstreambase() {}
|
||||
|
||||
private:
|
||||
socketstreambuf buf;
|
||||
};
|
||||
|
||||
inline socketstreambuf *socketstreambase::rdbuf()
|
||||
{
|
||||
return &this->buf;
|
||||
}
|
||||
|
||||
class isocketstream : public socketstreambase, public istream {
|
||||
public:
|
||||
explicit isocketstream(Socket *sock, streamsize n = 4096);
|
||||
virtual ~isocketstream();
|
||||
};
|
||||
|
||||
|
||||
class osocketstream : public socketstreambase, public ostream {
|
||||
public:
|
||||
explicit osocketstream(Socket *sock, streamsize n = 4096);
|
||||
virtual ~osocketstream();
|
||||
};
|
||||
|
||||
#endif // __SocketStream2_H
|
Loading…
x
Reference in New Issue
Block a user