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