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