geoiprequest.cpp

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA  02110-1301, USA.
00020  ***************************************************************/
00021 
00022 /**
00023  * \file geoiprequest.cpp
00024  * \version $Id: geoiprequest.cpp 1238 2006-09-25 17:50:57Z edmanm $
00025  * \brief A formatted request for GeoIP information for one or more IPs
00026  */
00027 
00028 #include "geoiprequest.h"
00029 
00030 
00031 /** Creates an HTTP POST header for this request, based on the 
00032  * Host, Page, and content-length values. */
00033 QHttpRequestHeader
00034 GeoIpRequest::createHeader()
00035 {
00036   QHttpRequestHeader header("POST", _page, 1, 0);
00037   if (!_host.isEmpty()) {
00038     /* If a host was specified, put it in the HTTP header */
00039     header.setValue("Host", _host);
00040   }
00041   header.setValue("Connection", "close");
00042   header.setContentType("application/x-www-form-urlencoded");
00043   header.setContentLength(_request.length());
00044   return header;
00045 }
00046 
00047 /** Sets the list of IPs whose geo information we want to request. */
00048 void
00049 GeoIpRequest::setRequest(QList<QHostAddress> ips)
00050 {
00051   _request = "ip=";
00052   int ipcount = ips.size();
00053 
00054   /* Add each IP to a comma-delimited list. */
00055   for (int i = 0; i < ipcount; i++) {
00056     _request.append(ips.at(i).toString());
00057     if (i < ipcount-1) {
00058       _request.append(",");
00059     }
00060   }
00061 }
00062 
00063 /** Formats the request as an HTTP POST request. */
00064 QByteArray
00065 GeoIpRequest::request()
00066 {
00067   /* Create the header and append the request content. */
00068   QString request = createHeader().toString() + _request;
00069   return request.toAscii();
00070 }
00071 

Generated on Mon Oct 23 20:08:15 2006 for Vidalia by  doxygen 1.5.0