GeoIpRequest.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "GeoIpRequest.h"
00018 #include "ZlibByteArray.h"
00019
00020 #include <QString>
00021 #include <QHostAddress>
00022 #include <QHttpRequestHeader>
00023
00024
00025
00026
00027 QHttpRequestHeader
00028 GeoIpRequest::createHeader() const
00029 {
00030 QHttpRequestHeader header("POST", _page, 1, 1);
00031
00032 if (!_host.isEmpty())
00033 header.setValue("Host", _host);
00034 header.setContentType("application/x-www-form-urlencoded");
00035 header.setContentLength(_request.length());
00036 header.setValue("Connection", "close");
00037
00038 if (ZlibByteArray::isZlibAvailable()) {
00039 QString acceptEncodings = "deflate, x-deflate";
00040 if (ZlibByteArray::isGzipSupported())
00041 acceptEncodings += ", gzip, x-gzip";
00042 header.setValue("Accept-Encoding", acceptEncodings);
00043 }
00044
00045 return header;
00046 }
00047
00048
00049 void
00050 GeoIpRequest::setRequest(const QList<QHostAddress> &ips)
00051 {
00052 _request = "format=long&ip=";
00053 int ipcount = ips.size();
00054
00055
00056 for (int i = 0; i < ipcount; i++) {
00057 _request.append(ips.at(i).toString());
00058 if (i < ipcount-1) {
00059 _request.append(",");
00060 }
00061 }
00062 _ips = ips;
00063 }
00064
00065
00066 QByteArray
00067 GeoIpRequest::request() const
00068 {
00069
00070 QString request = createHeader().toString() + _request;
00071 return request.toAscii();
00072 }
00073
00074
00075 bool
00076 GeoIpRequest::contains(const QHostAddress &ip) const
00077 {
00078 return _ips.contains(ip);
00079 }
00080