IPP: remove custom URL implemenation.

Use BUrl.

Change-Id: I40ce72fc34b2ba4f5980eee3cc81cba58c74a43a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2961
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Adrien Destugues
2020-06-28 21:37:30 +00:00
committed by waddlesplash
parent 35323f65d5
commit 33984e7b7d
9 changed files with 20 additions and 192 deletions
@@ -47,7 +47,7 @@ bool Field::operator == (const Field &o)
return (key == o.key) && (value == o.value);
}
HttpURLConnection::HttpURLConnection(const URL &Url)
HttpURLConnection::HttpURLConnection(const BUrl &Url)
: connected(false), doInput(true), doOutput(false), url(Url)
{
__sock = NULL;
@@ -130,9 +130,9 @@ void HttpURLConnection::setDoOutput(bool doOutput)
void HttpURLConnection::connect()
{
if (!connected) {
int port = url.getPort();
int port = url.Port();
if (port < 0) {
const char *protocol = url.getProtocol();
const char *protocol = url.Protocol();
if (!stricmp(protocol, "http")) {
port = DEFAULT_PORT;
} else if (!stricmp(protocol, "ipp")) {
@@ -141,7 +141,7 @@ void HttpURLConnection::connect()
port = DEFAULT_PORT;
}
}
__sock = new Socket(url.getHost(), port);
__sock = new Socket(url.Host(), port);
if (__sock->fail()) {
__error_msg = __sock->getLastError();
} else {
@@ -213,9 +213,9 @@ void HttpURLConnection::action()
void HttpURLConnection::setRequest()
{
if (connected) {
setRequestProperty("Host", url.getHost());
setRequestProperty("Host", url.Host());
ostream &os = getOutputStream();
os << __method << ' ' << url.getFile() << " HTTP/1.1" << '\r' << '\n';
os << __method << ' ' << url.Path() << " HTTP/1.1" << '\r' << '\n';
for (Fields::iterator it = __request->begin(); it != __request->end(); it++) {
os << (*it).key << ": " << (*it).value << '\r' << '\n';
}
@@ -287,7 +287,7 @@ void HttpURLConnection::getResponse()
{
const char *p = getHeaderField("Location");
if (p) {
URL trueUrl(p);
BUrl trueUrl(p);
url = trueUrl;
delete __response;
__response = NULL;
@@ -9,7 +9,7 @@
#include <list>
#include <string>
#include "URL.h"
#include <Url.h>
using namespace std;
@@ -76,7 +76,7 @@ typedef list<Field> Fields;
class HttpURLConnection {
public:
HttpURLConnection(const URL &url);
HttpURLConnection(const BUrl &url);
virtual ~HttpURLConnection();
virtual void connect();
@@ -92,7 +92,7 @@ public:
long getDate();
const char *getHeaderField(int n);
const char *getHeaderField(const char *);
const URL &getURL() const;
const BUrl &getURL() const;
HTTP_RESPONSECODE getResponseCode();
const char *getResponseMessage();
@@ -111,7 +111,7 @@ protected:
bool connected;
bool doInput;
bool doOutput;
URL url;
BUrl url;
virtual void action();
virtual void setRequest();
@@ -4,14 +4,14 @@
#include <string.h>
#include <strings.h>
#include <Alert.h>
#include <Button.h>
#include <Directory.h>
#include <Rect.h>
#include <TextControl.h>
#include <View.h>
#include <Directory.h>
#include <Alert.h>
#include <Url.h>
#include "URL.h"
#include "IppContent.h"
#include "IppURLConnection.h"
#include "IppSetupDlg.h"
@@ -114,7 +114,7 @@ bool IppSetupView::UpdateViewData()
request->setURI("printer-uri", url->Text());
request->setDelimiter(IPP_END_OF_ATTRIBUTES_TAG);
IppURLConnection conn(URL(url->Text()));
IppURLConnection conn(BUrl(url->Text()));
conn.setIppRequest(request);
conn.setRequestProperty("Connection", "close");
@@ -3,8 +3,9 @@
#include <Alert.h>
#include <DataIO.h>
#include <Message.h>
#include <Directory.h>
#include <Message.h>
#include <Url.h>
#include <pwd.h>
#include <stdio.h>
@@ -12,7 +13,6 @@
#include <strings.h>
#include <unistd.h>
#include "URL.h"
#include "IppContent.h"
#include "IppURLConnection.h"
#include "IppSetupDlg.h"
@@ -97,7 +97,7 @@ IppTransport::~IppTransport()
__fs.seekg(0, ios::beg);
request->setRawData(__fs, fssize);
URL url(__url);
BUrl url(__url);
IppURLConnection conn(url);
conn.setIppRequest(request);
conn.setRequestProperty("Connection", "close");
@@ -21,7 +21,7 @@ char *itoa(int i, char *buf, int unit)
#include "IppURLConnection.h"
#include "IppContent.h"
IppURLConnection::IppURLConnection(const URL &Url)
IppURLConnection::IppURLConnection(const BUrl &Url)
: HttpURLConnection(Url)
{
__ippRequest = NULL;
@@ -10,7 +10,7 @@ class IppContent;
class IppURLConnection : public HttpURLConnection {
public:
IppURLConnection(const URL &url);
IppURLConnection(const BUrl &url);
~IppURLConnection();
void setIppRequest(IppContent *);
-1
View File
@@ -13,7 +13,6 @@ Addon IPP :
HttpURLConnection.cpp
IppContent.cpp
IppURLConnection.cpp
URL.cpp
Socket.o
SocketStream.o
DbgMsg.o
-103
View File
@@ -1,103 +0,0 @@
// Sun, 18 Jun 2000
// Y.Takagi
#include <cstring>
#include <stdlib.h>
#include "URL.h"
URL::URL(const char *spec)
{
// __protocol = "http";
// __host = "localhost";
// __file = "/";
__port = -1;
if (spec) {
char *temp_spec = new char[strlen(spec) + 1];
strcpy(temp_spec, spec);
char *p1;
char *p2;
char *p3;
char *p4;
p1 = strstr(temp_spec, "//");
if (p1) {
*p1 = '\0';
p1 += 2;
__protocol = temp_spec;
} else {
p1 = temp_spec;
}
p3 = strstr(p1, "/");
if (p3) {
p4 = strstr(p3, "#");
if (p4) {
__ref = p4 + 1;
*p4 = '\0';
}
__file = p3;
*p3 = '\0';
} else {
__file = "/";
}
p2 = strstr(p1, ":");
if (p2) {
__port = atoi(p2 + 1);
*p2 = '\0';
}
__host = p1;
delete [] temp_spec;
}
// if (__port == -1) {
// if (__protocol == "http") {
// __port = 80;
// } else if (__protocol == "ipp") {
// __port = 631;
// }
// }
}
URL::URL(const char *protocol, const char *host, int port, const char *file)
{
__protocol = protocol;
__host = host;
__file = file;
__port = port;
}
URL::URL(const char *protocol, const char *host, const char *file)
{
__protocol = protocol;
__host = host;
__file = file;
}
URL::URL(const URL &url)
{
__protocol = url.__protocol;
__host = url.__host;
__file = url.__file;
__ref = url.__ref;
__port = url.__port;
}
URL &URL::operator = (const URL &url)
{
__protocol = url.__protocol;
__host = url.__host;
__file = url.__file;
__ref = url.__ref;
__port = url.__port;
return *this;
}
bool URL::operator == (const URL &url)
{
return (__protocol == url.__protocol) && (__host == url.__host) && (__file == url.__file) &&
(__ref == url.__ref) && (__port == url.__port);
}
-68
View File
@@ -1,68 +0,0 @@
// 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