You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
264 lines
5.9 KiB
264 lines
5.9 KiB
13 years ago
|
// This is the SIP interface definition for TQHttp, TQHttpHeader,
|
||
|
// TQHttpRequestHeader and TQHttpResponseHeader.
|
||
13 years ago
|
//
|
||
|
// Copyright (c) 2007
|
||
|
// Riverbank Computing Limited <info@riverbankcomputing.co.uk>
|
||
|
//
|
||
13 years ago
|
// This file is part of PyTQt.
|
||
13 years ago
|
//
|
||
13 years ago
|
// This copy of PyTQt is free software; you can redistribute it and/or modify it
|
||
13 years ago
|
// under the terms of the GNU General Public License as published by the Free
|
||
|
// Software Foundation; either version 2, or (at your option) any later
|
||
|
// version.
|
||
|
//
|
||
13 years ago
|
// PyTQt is supplied in the hope that it will be useful, but WITHOUT ANY
|
||
13 years ago
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
|
// details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License along with
|
||
13 years ago
|
// PyTQt; see the file LICENSE. If not, write to the Free Software Foundation,
|
||
13 years ago
|
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
|
|
||
|
|
||
|
%ExportedDoc
|
||
13 years ago
|
<Sect2><Title>TQHttp (TQt v3+)</Title>
|
||
13 years ago
|
<FuncSynopsis>
|
||
13 years ago
|
<FuncDef>TQ_LONG <Function>readBlock</Function></FuncDef>
|
||
13 years ago
|
<ParamDef>char *<Parameter>data</Parameter></ParamDef>
|
||
13 years ago
|
<ParamDef>TQ_ULONG <Parameter>maxlen</Parameter></ParamDef>
|
||
13 years ago
|
</FuncSynopsis>
|
||
|
<Para>
|
||
|
This takes a single <Literal>maxlen</Literal> parameter. The
|
||
|
<Literal>data</Literal> is returned if there was no error, otherwise
|
||
|
<Literal>None</Literal> is returned.
|
||
|
</Para>
|
||
|
</Sect2>
|
||
|
|
||
13 years ago
|
<Sect2><Title>TQHttpHeader (TQt v3.1+)</Title>
|
||
13 years ago
|
<Para>
|
||
13 years ago
|
<Literal>TQHttpHeader</Literal> is fully implemented.
|
||
13 years ago
|
</Para>
|
||
|
</Sect2>
|
||
|
|
||
13 years ago
|
<Sect2><Title>TQHttpRequestHeader (TQt v3.1+)</Title>
|
||
13 years ago
|
<Para>
|
||
13 years ago
|
<Literal>TQHttpRequestHeader</Literal> is fully implemented.
|
||
13 years ago
|
</Para>
|
||
|
</Sect2>
|
||
|
|
||
13 years ago
|
<Sect2><Title>TQHttpResponseHeader (TQt v3.1+)</Title>
|
||
13 years ago
|
<Para>
|
||
13 years ago
|
<Literal>TQHttpResponseHeader</Literal> is fully implemented.
|
||
13 years ago
|
</Para>
|
||
|
</Sect2>
|
||
|
%End
|
||
|
|
||
|
|
||
13 years ago
|
%If (TQt_NETWORKPROTOCOL_HTTP)
|
||
13 years ago
|
|
||
13 years ago
|
class TQHttpHeader
|
||
13 years ago
|
{
|
||
|
%TypeHeaderCode
|
||
13 years ago
|
#include <tqhttp.h>
|
||
13 years ago
|
%End
|
||
|
|
||
|
public:
|
||
13 years ago
|
TQHttpHeader();
|
||
|
TQHttpHeader(const TQHttpHeader &);
|
||
|
TQHttpHeader(const TQString &);
|
||
|
virtual ~TQHttpHeader();
|
||
13 years ago
|
|
||
13 years ago
|
TQString value(const TQString &) const;
|
||
|
void setValue(const TQString &,const TQString &);
|
||
|
void removeValue(const TQString &);
|
||
13 years ago
|
|
||
13 years ago
|
TQStringList keys() const;
|
||
|
bool hasKey(const TQString &) const;
|
||
13 years ago
|
|
||
|
bool hasContentLength() const;
|
||
|
uint contentLength() const;
|
||
|
void setContentLength(int);
|
||
|
|
||
|
bool hasContentType() const;
|
||
13 years ago
|
TQString contentType() const;
|
||
|
void setContentType(const TQString &);
|
||
13 years ago
|
|
||
13 years ago
|
virtual TQString toString() const;
|
||
13 years ago
|
bool isValid() const;
|
||
|
|
||
|
virtual int majorVersion() const = 0;
|
||
|
virtual int minorVersion() const = 0;
|
||
|
|
||
|
protected:
|
||
13 years ago
|
virtual bool parseLine(const TQString &,int);
|
||
|
bool parse(const TQString &);
|
||
13 years ago
|
void setValid(bool);
|
||
|
};
|
||
|
|
||
|
|
||
13 years ago
|
class TQHttpResponseHeader : TQHttpHeader
|
||
13 years ago
|
{
|
||
|
%TypeHeaderCode
|
||
13 years ago
|
#include <tqhttp.h>
|
||
13 years ago
|
%End
|
||
|
|
||
|
public:
|
||
13 years ago
|
TQHttpResponseHeader();
|
||
|
TQHttpResponseHeader(const TQHttpResponseHeader &);
|
||
13 years ago
|
|
||
|
int statusCode() const;
|
||
13 years ago
|
TQString reasonPhrase() const;
|
||
13 years ago
|
|
||
|
int majorVersion() const;
|
||
|
int minorVersion() const;
|
||
|
|
||
13 years ago
|
TQString toString() const;
|
||
13 years ago
|
|
||
|
protected:
|
||
13 years ago
|
bool parseLine(const TQString &,int);
|
||
13 years ago
|
};
|
||
|
|
||
|
|
||
13 years ago
|
class TQHttpRequestHeader : TQHttpHeader
|
||
13 years ago
|
{
|
||
|
%TypeHeaderCode
|
||
13 years ago
|
#include <tqhttp.h>
|
||
13 years ago
|
%End
|
||
|
|
||
|
public:
|
||
13 years ago
|
TQHttpRequestHeader();
|
||
|
TQHttpRequestHeader(const TQString &,const TQString &,int = 1,int = 1);
|
||
|
TQHttpRequestHeader(const TQHttpRequestHeader &);
|
||
|
TQHttpRequestHeader(const TQString &);
|
||
13 years ago
|
|
||
13 years ago
|
void setRequest(const TQString &,const TQString &,int = 1,int = 1);
|
||
13 years ago
|
|
||
13 years ago
|
TQString method() const;
|
||
|
TQString path() const;
|
||
13 years ago
|
|
||
|
int majorVersion() const;
|
||
|
int minorVersion() const;
|
||
|
|
||
13 years ago
|
TQString toString() const;
|
||
13 years ago
|
|
||
|
protected:
|
||
13 years ago
|
bool parseLine(const TQString &,int);
|
||
13 years ago
|
};
|
||
|
|
||
|
|
||
13 years ago
|
class TQHttp : TQNetworkProtocol
|
||
13 years ago
|
{
|
||
|
%TypeHeaderCode
|
||
13 years ago
|
#include <tqhttp.h>
|
||
13 years ago
|
%End
|
||
|
|
||
|
public:
|
||
13 years ago
|
TQHttp();
|
||
|
TQHttp(TQObject * /TransferThis/,const char * = 0);
|
||
13 years ago
|
TQHttp(const TQString &,TQ_UINT16 = 80,TQObject * /TransferThis/ = 0,
|
||
13 years ago
|
const char * = 0);
|
||
13 years ago
|
virtual ~TQHttp();
|
||
13 years ago
|
|
||
|
int supportedOperations() const;
|
||
|
|
||
|
enum State {
|
||
|
Unconnected,
|
||
|
HostLookup,
|
||
|
Connecting,
|
||
|
Sending,
|
||
|
Reading,
|
||
|
Connected,
|
||
|
Closing
|
||
|
};
|
||
|
|
||
|
enum Error {
|
||
|
NoError,
|
||
|
UnknownError,
|
||
|
HostNotFound,
|
||
|
ConnectionRefused,
|
||
|
UnexpectedClose,
|
||
|
InvalidResponseHeader,
|
||
|
WrongContentLength,
|
||
|
Aborted
|
||
|
};
|
||
|
|
||
13 years ago
|
int setHost(const TQString &,TQ_UINT16 = 80);
|
||
13 years ago
|
|
||
13 years ago
|
int get(const TQString &,TQIODevice * = 0) /ReleaseGIL/;
|
||
|
int post(const TQString &,TQIODevice *,TQIODevice * = 0) /ReleaseGIL/;
|
||
|
int post(const TQString &,const TQByteArray &,
|
||
|
TQIODevice * = 0) /ReleaseGIL/;
|
||
|
int head(const TQString &) /ReleaseGIL/;
|
||
|
int request(const TQHttpRequestHeader &,TQIODevice * = 0,
|
||
|
TQIODevice * = 0) /ReleaseGIL/;
|
||
|
int request(const TQHttpRequestHeader &,const TQByteArray &,
|
||
|
TQIODevice * = 0) /ReleaseGIL/;
|
||
13 years ago
|
|
||
|
int closeConnection();
|
||
|
|
||
|
unsigned long bytesAvailable() const;
|
||
|
|
||
13 years ago
|
SIP_PYOBJECT readBlock(TQ_ULONG) /ReleaseGIL/ [TQ_LONG (char *,TQ_ULONG)];
|
||
13 years ago
|
%MethodCode
|
||
|
char *buf;
|
||
|
|
||
|
if ((buf = (char *)sipMalloc(a0)) == NULL)
|
||
|
sipIsErr = 1;
|
||
|
else
|
||
|
{
|
||
13 years ago
|
TQ_LONG actlen;
|
||
13 years ago
|
|
||
|
Py_BEGIN_ALLOW_THREADS
|
||
13 years ago
|
actlen = sipCpp -> TQHttp::readBlock(buf,a0);
|
||
13 years ago
|
Py_END_ALLOW_THREADS
|
||
|
|
||
|
if (actlen < 0)
|
||
|
{
|
||
|
Py_INCREF(Py_None);
|
||
|
sipRes = Py_None;
|
||
|
}
|
||
2 years ago
|
else if ((sipRes = PyBytes_FromStringAndSize(buf,actlen)) == NULL)
|
||
13 years ago
|
sipIsErr = 1;
|
||
|
|
||
12 years ago
|
sipFree((void *)buf);
|
||
13 years ago
|
}
|
||
|
%End
|
||
|
|
||
13 years ago
|
TQByteArray readAll() /ReleaseGIL/;
|
||
13 years ago
|
|
||
|
int currentId() const;
|
||
13 years ago
|
TQIODevice *currentSourceDevice() const;
|
||
|
TQIODevice *currentDestinationDevice() const;
|
||
|
TQHttpRequestHeader currentRequest() const;
|
||
13 years ago
|
bool hasPendingRequests() const;
|
||
|
void clearPendingRequests();
|
||
|
|
||
|
State state() const;
|
||
|
|
||
|
Error error() const;
|
||
13 years ago
|
TQString errorString() const;
|
||
13 years ago
|
|
||
|
public slots:
|
||
|
void abort();
|
||
|
|
||
|
signals:
|
||
|
void stateChanged(int);
|
||
13 years ago
|
void responseHeaderReceived(const TQHttpResponseHeader &);
|
||
|
void readyRead(const TQHttpResponseHeader &);
|
||
13 years ago
|
void dataSendProgress(int,int);
|
||
|
void dataReadProgress(int,int);
|
||
|
|
||
|
void requestStarted(int);
|
||
|
void requestFinished(int,bool);
|
||
|
void done(bool);
|
||
|
|
||
|
protected:
|
||
13 years ago
|
void operationGet(TQNetworkOperation *);
|
||
|
void operationPut(TQNetworkOperation *);
|
||
13 years ago
|
|
||
13 years ago
|
void timerEvent(TQTimerEvent *);
|
||
13 years ago
|
};
|
||
|
|
||
|
%End
|