42 #include "private/qdeclarativexmlhttprequest_p.h" 45 #include "private/qdeclarativeengine_p.h" 46 #include "private/qdeclarativerefcount_p.h" 47 #include "private/qdeclarativeengine_p.h" 48 #include "private/qdeclarativeexpression_p.h" 51 #include <QtCore/qobject.h> 52 #include <QtScript/qscriptvalue.h> 53 #include <QtScript/qscriptcontext.h> 54 #include <QtScript/qscriptengine.h> 55 #include <QtNetwork/qnetworkreply.h> 56 #include <QtCore/qtextcodec.h> 57 #include <QtCore/qxmlstream.h> 58 #include <QtCore/qstack.h> 59 #include <QtCore/qdebug.h> 61 #include <QtCore/QStringBuilder> 63 #ifndef QT_NO_XMLSTREAMREADER 67 #define INDEX_SIZE_ERR 1 68 #define DOMSTRING_SIZE_ERR 2 69 #define HIERARCHY_REQUEST_ERR 3 70 #define WRONG_DOCUMENT_ERR 4 71 #define INVALID_CHARACTER_ERR 5 72 #define NO_DATA_ALLOWED_ERR 6 73 #define NO_MODIFICATION_ALLOWED_ERR 7 74 #define NOT_FOUND_ERR 8 75 #define NOT_SUPPORTED_ERR 9 76 #define INUSE_ATTRIBUTE_ERR 10 77 #define INVALID_STATE_ERR 11 79 #define INVALID_MODIFICATION_ERR 13 80 #define NAMESPACE_ERR 14 81 #define INVALID_ACCESS_ERR 15 82 #define VALIDATION_ERR 16 83 #define TYPE_MISMATCH_ERR 17 85 #define THROW_DOM(error, desc) \ 87 QScriptValue errorValue = context->throwError(QLatin1String(desc)); \ 88 errorValue.setProperty(QLatin1String("code"), error); \ 92 #define THROW_SYNTAX(desc) \ 93 return context->throwError(QScriptContext::SyntaxError, QLatin1String(desc)); 94 #define THROW_REFERENCE(desc) \ 95 return context->throwError(QScriptContext::ReferenceError, QLatin1String(desc)); 97 #define D(arg) (arg)->release() 98 #define A(arg) (arg)->addref() 153 if (root)
delete root;
349 switch (node.
d->
type) {
487 switch (data->
type) {
639 while (!reader.
atEnd()) {
663 document->
root = node;
706 if (!document || reader.
hasError()) {
707 if (document)
D(document);
856 if (!(flags & HandlesReadAccess))
870 return HandlesReadAccess;
872 for (
int ii = 0; ii < map.
list->
count(); ++ii) {
875 return HandlesReadAccess;
891 if (!(flags & HandlesReadAccess))
904 return HandlesReadAccess;
918 return Node::create(engine, static_cast<DocumentImpl *>(document.
d)->root);
926 return QScriptValue(static_cast<DocumentImpl *>(document.
d)->isStandalone);
934 return QScriptValue(static_cast<DocumentImpl *>(document.
d)->version);
942 return QScriptValue(static_cast<DocumentImpl *>(document.
d)->encoding);
950 Opened = 1, HeadersReceived = 2,
951 Loading = 3, Done = 4 };
956 bool sendFlag()
const;
957 bool errorFlag()
const;
959 int replyStatus()
const;
960 QString replyStatusText()
const;
972 bool receivedXml()
const;
974 void downloadProgress(
qint64);
979 void requestFromUrl(
const QUrl &url);
993 void fillHeadersList();
999 #ifndef QT_NO_TEXTCODEC 1002 void readEncoding();
1013 void destroyNetwork();
1020 : m_state(Unsent), m_errorFlag(false), m_sendFlag(false),
1021 m_redirectCount(0), m_gotXml(false), m_textCodec(0), m_network(0), m_nam(manager)
1083 if (header.
first == utfname)
1109 if (pair.first ==
"set-cookie" ||
1110 pair.first ==
"set-cookie2")
1127 if (charsetIdx == -1) {
1135 if (semiColon == -1) {
1136 n = str.
length() - charsetIdx;
1138 n = semiColon - charsetIdx;
1204 if (cbv.
isError())
return cbv;
1267 #define XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION 15 1329 if (header.
first ==
"content-type") {
1330 int separatorIdx = header.
second.indexOf(
';');
1331 if (separatorIdx == -1) {
1335 int charsetIdx = header.
second.indexOf(
"charset=");
1336 if (charsetIdx != -1) {
1338 separatorIdx = header.
second.indexOf(
';', charsetIdx);
1339 m_charset = header.
second.mid(charsetIdx, separatorIdx >= 0 ? separatorIdx : header.
second.length());
1356 #ifndef QT_NO_TEXTCODEC 1370 if (!codec &&
m_mime ==
"text/html")
1385 #ifndef QT_NO_TEXTCODEC 1469 return request->
open(&dataObject, method, url);
1537 return request->
send(&dataObject, data);
1547 return request->
abort(&dataObject);
1748 #endif // QT_NO_XMLSTREAMREADER 1750 #include <qdeclarativexmlhttprequest.moc>
The QVariant class acts like a union for the most common Qt data types.
QTextCodec * findTextCodec() const
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
#define THROW_REFERENCE(desc)
The QScriptContext class represents a Qt Script function invocation.
virtual QueryFlags queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id)
Queries this script class for how access to the property with the given name of the given object shou...
QString toString() const
Returns a copy of the string reference as a QString object.
void setUrl(const QUrl &url)
Sets the URL this network request is referring to to be url.
#define INVALID_ACCESS_ERR
static QScriptValue prototype(QScriptEngine *)
static QScriptValue qmlxmlhttprequest_getAllResponseHeaders(QScriptContext *context, QScriptEngine *engine)
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue's property with the given name, using the given mode to resolv...
static QScriptValue nextSibling(QScriptContext *context, QScriptEngine *engine)
QByteArray m_responseEntityBody
static QScriptValue create(QScriptEngine *, NodeImpl *)
T qscriptvalue_cast(const QScriptValue &)
static QScriptValue prototype(QScriptEngine *)
#define QT_END_NAMESPACE
This macro expands to.
bool isCalledAsConstructor() const
Returns true if the function was called as a constructor (e.g.
static QScriptValue qmlxmlhttprequest_new(QScriptContext *context, QScriptEngine *engine)
QNetworkReply * head(const QNetworkRequest &request)
Posts a request to obtain the network headers for request and returns a new QNetworkReply object whic...
bool hasRawHeader(const QByteArray &headerName) const
Returns true if the raw header headerName is present in this network request.
static QScriptValue isElementContentWhitespace(QScriptContext *context, QScriptEngine *engine)
NodeListClass(QScriptEngine *engine)
static QScriptValue prototype(QScriptEngine *)
The QScriptClass class provides an interface for defining custom behavior of (a class of) Qt Script o...
static QScriptValue xmlStandalone(QScriptContext *context, QScriptEngine *engine)
static QScriptValue qmlxmlhttprequest_statusText(QScriptContext *context, QScriptEngine *engine)
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
QNetworkReply * put(const QNetworkRequest &request, QIODevice *data)
Uploads the contents of data to the destination request and returnes a new QNetworkReply object that ...
QByteArray & append(char c)
Appends the character ch to this byte array.
QScriptClass * namedNodeMapClass
const QByteArray & rawResponseBody() const
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
QByteArray rawHeader(const QByteArray &headerName) const
Returns the raw form of header headerName.
static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, QScriptEngine *engine)
static QByteArray headerName(QNetworkRequest::KnownHeaders header)
bool isCDATA() const
Returns true if the reader reports characters that stem from a CDATA section; otherwise returns false...
DEFINE_BOOL_CONFIG_OPTION(xhrDump, QML_XHR_DUMP)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
QDeclarativeXMLHttpRequest(QNetworkAccessManager *manager)
QString & replace(int i, int len, QChar after)
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
The QByteArray class provides an array of bytes.
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
int length() const
Returns the number of characters in this string.
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context, QScriptEngine *engine)
HeadersList m_headersList
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QNetworkReply * deleteResource(const QNetworkRequest &request)
Sends a request to delete the resource identified by the URL of request.
QStringRef value() const
Returns the attribute's value.
QScriptValue globalObject() const
Returns this engine's Global Object.
static QTextCodec * codecForHtml(const QByteArray &ba)
Tries to detect the encoding of the provided snippet of HTML in the given byte array, ba, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a QTextCodec instance that is capable of decoding the html to unicode.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
NetworkError
Indicates all possible error conditions found during the processing of the request.
static QScriptValue name(QScriptContext *context, QScriptEngine *engine)
void requestFromUrl(const QUrl &url)
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QByteArray toLower() const
Returns a lowercase copy of the byte array.
void error(QNetworkReply::NetworkError)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QStack class is a template class that provides a stack.
QStringRef name() const
Returns the local name of a StartElement, EndElement, or an EntityReference.
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
QDeclarativeGuard< QNetworkReply > m_network
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
bool atEnd() const
Returns true if the reader has read until the end of the XML document, or if an error() has occurred ...
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
quint32 readyState() const
The QObject class is the base class of all Qt objects.
QList< HeaderPair > HeadersList
static QScriptValue nodeName(QScriptContext *context, QScriptEngine *engine)
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
#define XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION
static QScriptValue prototype(QScriptEngine *)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
static QDeclarativeScriptEngine * get(QScriptEngine *e)
QNetworkAccessManager * m_nam
The QScriptString class acts as a handle to "interned" strings in a QScriptEngine.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
void printError(const QScriptValue &)
T pop()
Removes the top item from the stack and returns it.
The QXmlStreamAttribute class represents a single XML attribute.
QList< NodeImpl * > attributes
static QScriptValue nodeValue(QScriptContext *context, QScriptEngine *engine)
QStringRef namespaceUri() const
Returns the namespaceUri of a StartElement or EndElement.
void append(const T &t)
Inserts value at the end of the list.
The QScriptEngine class provides an environment for evaluating Qt Script code.
static QScriptValue attributes(QScriptContext *context, QScriptEngine *engine)
QFuture< void > map(Sequence &sequence, MapFunction function)
#define QT_BEGIN_NAMESPACE
This macro expands to.
void qt_add_qmlxmlhttprequest(QScriptEngine *engine)
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
static QScriptValue qmlxmlhttprequest_status(QScriptContext *context, QScriptEngine *engine)
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
static QScriptValue documentElement(QScriptContext *context, QScriptEngine *engine)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QScriptValue childNodes(QScriptContext *context, QScriptEngine *engine)
static QScriptValue qmlxmlhttprequest_setRequestHeader(QScriptContext *context, QScriptEngine *engine)
QNetworkAccessManager * networkAccessManager()
#define INUSE_ATTRIBUTE_ERR
bool hasError() const
Returns true if an error has occurred, otherwise false.
const T & at(int i) const
Returns the item at index position i in the list.
QScriptEngine * engine() const
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the...
static QScriptValue ownerElement(QScriptContext *context, QScriptEngine *engine)
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
void append(const T &t)
Inserts value at the end of the vector.
void addHeader(const QString &, const QString &)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
static QTextCodec * codec(MYSQL *mysql)
QScriptValue newObject()
Creates a QtScript object of class Object.
QList< NodeImpl * > * list
#define NO_MODIFICATION_ALLOWED_ERR
static QScriptValue xmlVersion(QScriptContext *context, QScriptEngine *engine)
QList< QByteArray > rawHeaderList() const
Returns a list of headers fields that were sent by the remote server, in the order that they were sen...
The QDeclarativeError class encapsulates a QML error.
static QScriptValue qmlxmlhttprequest_responseText(QScriptContext *context, QScriptEngine *engine)
void setScriptClass(QScriptClass *scriptClass)
Sets the custom script class of this script object to scriptClass.
static QScriptValue length(QScriptContext *context, QScriptEngine *engine)
void clear()
Removes all items from the list.
static QScriptValue prototype(QScriptEngine *)
QStringRef name() const
Returns the attribute's local name.
The State element defines configurations of objects and properties.
virtual QScriptValue property(const QScriptValue &object, const QScriptString &name, uint id)
Returns the value of the property with the given name of the given object.
#define NO_DATA_ALLOWED_ERR
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
bool toBoolean() const
Use toBool() instead.
void setHeader(KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers...
static QScriptValue parentNode(QScriptContext *context, QScriptEngine *engine)
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
The QNetworkAccessManager class allows the application to send network requests and receive replies...
QStringRef documentEncoding() const
If the state() is StartDocument , this function returns the encoding string as specified in the XML d...
void setFragment(const QString &fragment)
Sets the fragment of the URL to fragment.
static QScriptValue previousSibling(QScriptContext *context, QScriptEngine *engine)
QScriptClass * nodeListClass
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
static QScriptValue qmlxmlhttprequest_abort(QScriptContext *context, QScriptEngine *)
QPair< QByteArray, QByteArray > HeaderPair
QScriptValue newQObject(QObject *object, ValueOwnership ownership=QtOwnership, const QObjectWrapOptions &options=0)
Creates a QtScript object that wraps the given QObject object, using the given ownership.
QUrl resolvedUrl(QScriptContext *context, const QUrl &url)
TokenType readNext()
Reads the next token and returns its type.
QList< NodeImpl * > children
T & first()
Returns a reference to the first item in the list.
bool isNull() const
Returns true if this string is null; otherwise returns false.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
static QByteArray prototype(const QList< QByteArray > ¶meterTypes, const QList< QByteArray > ¶meterNames, bool *ok)
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
QScriptValue data() const
Returns the internal data of this QScriptValue object.
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
Sets the header headerName to be of value headerValue.
QString header(const QString &name)
QString scheme() const
Returns the scheme of the URL.
virtual ~QDeclarativeXMLHttpRequest()
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue's property with the given name to the given value.
QString & append(QChar c)
static QScriptValue firstChild(QScriptContext *context, QScriptEngine *engine)
#define NOT_SUPPORTED_ERR
NamedNodeMapClass(QScriptEngine *engine)
#define INVALID_STATE_ERR
void setPrototype(const QScriptValue &prototype)
If this QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to...
QStringRef documentVersion() const
If the state() is StartDocument , this function returns the version string as specified in the XML de...
QByteArray rawHeader(const QByteArray &headerName) const
Returns the raw contents of the header headerName as sent by the remote server.
static QScriptValue lastChild(QScriptContext *context, QScriptEngine *engine)
QScriptValue dispatchCallback(QScriptValue *me)
void downloadProgress(qint64)
#define THROW_DOM(error, desc)
static QScriptValue wholeText(QScriptContext *context, QScriptEngine *engine)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
QScriptValue open(QScriptValue *me, const QString &, const QUrl &)
T & last()
Returns a reference to the last item in the list.
static QScriptValue create(QScriptEngine *, NodeImpl *)
static QScriptValue nodeType(QScriptContext *context, QScriptEngine *engine)
QScriptValue abort(QScriptValue *me)
uint toUInt(bool *ok=0, int base=10) const
Returns the string converted to an unsigned int using base base, which is 10 by default and must be b...
QScriptValue send(QScriptValue *me, const QByteArray &)
#define TYPE_MISMATCH_ERR
virtual QScriptValue property(const QScriptValue &object, const QScriptString &name, uint id)
Returns the value of the property with the given name of the given object.
static QScriptValue qmlxmlhttprequest_readyState(QScriptContext *context, QScriptEngine *engine)
static QTextCodec * codecForName(const QByteArray &name)
Searches all installed QTextCodec objects and returns the one which best matches name; the match is c...
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
static QScriptValue xmlEncoding(QScriptContext *context, QScriptEngine *engine)
virtual QueryFlags queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id)
Queries this script class for how access to the property with the given name of the given object shou...
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
static QScriptValue length(QScriptContext *context, QScriptEngine *engine)
static void exceptionToError(QScriptEngine *, QDeclarativeError &)
QNetworkRequest m_request
static QScriptValue prototype(QScriptEngine *)
static QTextCodec * codecForUtfText(const QByteArray &ba)
Tries to detect the encoding of the provided snippet ba by using the BOM (Byte Order Mark) and return...
static QScriptValue prototype(QScriptEngine *)
QNetworkReply * post(const QNetworkRequest &request, QIODevice *data)
Sends an HTTP POST request to the destination specified by request and returns a new QNetworkReply ob...
static QScriptValue create(QScriptEngine *, NodeImpl *, QList< NodeImpl *> *)
static QScriptValue qmlxmlhttprequest_send(QScriptContext *context, QScriptEngine *)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
static QScriptValue length(QScriptContext *context, QScriptEngine *engine)
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
static QScriptValue prototype(QScriptEngine *)
The QXmlStreamReader class provides a fast parser for reading well-formed XML via a simple streaming ...
static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScriptEngine *engine)
static QScriptValue value(QScriptContext *context, QScriptEngine *engine)
QUrl url() const
Returns the URL of the content downloaded or uploaded.
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngine *engine)
The QTextCodec class provides conversions between text encodings.
QStringRef text() const
Returns the text of Characters , Comment , DTD , or EntityReference.
bool isStandaloneDocument() const
Returns true if this document has been declared standalone in the XML declaration; otherwise returns ...
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
QScriptValue thisObject() const
Returns the `this' object associated with this QScriptContext.
#define INVALID_CHARACTER_ERR
#define HIERARCHY_REQUEST_ERR
void warning(const QDeclarativeError &)
QString toString() const
Returns the string that this QScriptString represents, or a null string if this QScriptString is not ...
void setUserName(const QString &userName)
Sets the URL's user name to userName.
#define qPrintable(string)
The QScriptValue class acts as a container for the Qt Script data types.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this' object in the function call...
void deleteLater()
Schedules this object for deletion.
QScriptValue argument(int index) const
Returns the function argument at the given index.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QXmlStreamAttributes attributes() const
Returns the attributes of a StartElement.
void setPassword(const QString &password)
Sets the URL's password to password.
void clear()
Clears the contents of the byte array and makes it empty.
QScriptValue newVariant(const QVariant &value)
Creates a QtScript object holding the given variant value.
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
static bool isNull(const QVariant::Private *d)
int open(const char *, int,...)
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
The QList class is a template class that provides lists.
#define WRONG_DOCUMENT_ERR
The Text item allows you to add formatted text to a scene.
T & top()
Returns a reference to the stack's top item.
#define DOMSTRING_SIZE_ERR
static QScriptValue prototype(QScriptEngine *)
QString replyStatusText() const
static QScriptValue load(QScriptEngine *engine, const QByteArray &data)
#define INVALID_MODIFICATION_ERR
QStringRef namespaceUri() const
Returns the attribute's resolved namespaceUri, or an empty string reference if the attribute does not...