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); 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) : connected(false), doInput(true), doOutput(false), url(Url)
{ {
__sock = NULL; __sock = NULL;
@@ -130,9 +130,9 @@ void HttpURLConnection::setDoOutput(bool doOutput)
void HttpURLConnection::connect() void HttpURLConnection::connect()
{ {
if (!connected) { if (!connected) {
int port = url.getPort(); int port = url.Port();
if (port < 0) { if (port < 0) {
const char *protocol = url.getProtocol(); const char *protocol = url.Protocol();
if (!stricmp(protocol, "http")) { if (!stricmp(protocol, "http")) {
port = DEFAULT_PORT; port = DEFAULT_PORT;
} else if (!stricmp(protocol, "ipp")) { } else if (!stricmp(protocol, "ipp")) {
@@ -141,7 +141,7 @@ void HttpURLConnection::connect()
port = DEFAULT_PORT; port = DEFAULT_PORT;
} }
} }
__sock = new Socket(url.getHost(), port); __sock = new Socket(url.Host(), port);
if (__sock->fail()) { if (__sock->fail()) {
__error_msg = __sock->getLastError(); __error_msg = __sock->getLastError();
} else { } else {
@@ -213,9 +213,9 @@ void HttpURLConnection::action()
void HttpURLConnection::setRequest() void HttpURLConnection::setRequest()
{ {
if (connected) { if (connected) {
setRequestProperty("Host", url.getHost()); setRequestProperty("Host", url.Host());
ostream &os = getOutputStream(); 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++) { for (Fields::iterator it = __request->begin(); it != __request->end(); it++) {
os << (*it).key << ": " << (*it).value << '\r' << '\n'; os << (*it).key << ": " << (*it).value << '\r' << '\n';
} }
@@ -287,7 +287,7 @@ void HttpURLConnection::getResponse()
{ {
const char *p = getHeaderField("Location"); const char *p = getHeaderField("Location");
if (p) { if (p) {
URL trueUrl(p); BUrl trueUrl(p);
url = trueUrl; url = trueUrl;
delete __response; delete __response;
__response = NULL; __response = NULL;
@@ -9,7 +9,7 @@
#include <list> #include <list>
#include <string> #include <string>
#include "URL.h" #include <Url.h>
using namespace std; using namespace std;
@@ -76,7 +76,7 @@ typedef list<Field> Fields;
class HttpURLConnection { class HttpURLConnection {
public: public:
HttpURLConnection(const URL &url); HttpURLConnection(const BUrl &url);
virtual ~HttpURLConnection(); virtual ~HttpURLConnection();
virtual void connect(); virtual void connect();
@@ -92,7 +92,7 @@ public:
long getDate(); long getDate();
const char *getHeaderField(int n); const char *getHeaderField(int n);
const char *getHeaderField(const char *); const char *getHeaderField(const char *);
const URL &getURL() const; const BUrl &getURL() const;
HTTP_RESPONSECODE getResponseCode(); HTTP_RESPONSECODE getResponseCode();
const char *getResponseMessage(); const char *getResponseMessage();
@@ -111,7 +111,7 @@ protected:
bool connected; bool connected;
bool doInput; bool doInput;
bool doOutput; bool doOutput;
URL url; BUrl url;
virtual void action(); virtual void action();
virtual void setRequest(); virtual void setRequest();
@@ -4,14 +4,14 @@
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <Alert.h>
#include <Button.h> #include <Button.h>
#include <Directory.h>
#include <Rect.h> #include <Rect.h>
#include <TextControl.h> #include <TextControl.h>
#include <View.h> #include <View.h>
#include <Directory.h> #include <Url.h>
#include <Alert.h>
#include "URL.h"
#include "IppContent.h" #include "IppContent.h"
#include "IppURLConnection.h" #include "IppURLConnection.h"
#include "IppSetupDlg.h" #include "IppSetupDlg.h"
@@ -114,7 +114,7 @@ bool IppSetupView::UpdateViewData()
request->setURI("printer-uri", url->Text()); request->setURI("printer-uri", url->Text());
request->setDelimiter(IPP_END_OF_ATTRIBUTES_TAG); request->setDelimiter(IPP_END_OF_ATTRIBUTES_TAG);
IppURLConnection conn(URL(url->Text())); IppURLConnection conn(BUrl(url->Text()));
conn.setIppRequest(request); conn.setIppRequest(request);
conn.setRequestProperty("Connection", "close"); conn.setRequestProperty("Connection", "close");
@@ -3,8 +3,9 @@
#include <Alert.h> #include <Alert.h>
#include <DataIO.h> #include <DataIO.h>
#include <Message.h>
#include <Directory.h> #include <Directory.h>
#include <Message.h>
#include <Url.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h> #include <stdio.h>
@@ -12,7 +13,6 @@
#include <strings.h> #include <strings.h>
#include <unistd.h> #include <unistd.h>
#include "URL.h"
#include "IppContent.h" #include "IppContent.h"
#include "IppURLConnection.h" #include "IppURLConnection.h"
#include "IppSetupDlg.h" #include "IppSetupDlg.h"
@@ -97,7 +97,7 @@ IppTransport::~IppTransport()
__fs.seekg(0, ios::beg); __fs.seekg(0, ios::beg);
request->setRawData(__fs, fssize); request->setRawData(__fs, fssize);
URL url(__url); BUrl url(__url);
IppURLConnection conn(url); IppURLConnection conn(url);
conn.setIppRequest(request); conn.setIppRequest(request);
conn.setRequestProperty("Connection", "close"); conn.setRequestProperty("Connection", "close");
@@ -21,7 +21,7 @@ char *itoa(int i, char *buf, int unit)
#include "IppURLConnection.h" #include "IppURLConnection.h"
#include "IppContent.h" #include "IppContent.h"
IppURLConnection::IppURLConnection(const URL &Url) IppURLConnection::IppURLConnection(const BUrl &Url)
: HttpURLConnection(Url) : HttpURLConnection(Url)
{ {
__ippRequest = NULL; __ippRequest = NULL;
@@ -10,7 +10,7 @@ class IppContent;
class IppURLConnection : public HttpURLConnection { class IppURLConnection : public HttpURLConnection {
public: public:
IppURLConnection(const URL &url); IppURLConnection(const BUrl &url);
~IppURLConnection(); ~IppURLConnection();
void setIppRequest(IppContent *); void setIppRequest(IppContent *);
-1
View File
@@ -13,7 +13,6 @@ Addon IPP :
HttpURLConnection.cpp HttpURLConnection.cpp
IppContent.cpp IppContent.cpp
IppURLConnection.cpp IppURLConnection.cpp
URL.cpp
Socket.o Socket.o
SocketStream.o SocketStream.o
DbgMsg.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