void UltimateLyricsProvider::FetchInfo(INFO::InfoRequestData request)
{
    //Debug::debug() << name() << " fetch info ";

    const QTextCodec* codec = QTextCodec::codecForName(charset_.toAscii().constData());
    if (!codec) {
      qWarning() << "Invalid codec" << charset_;
      emit Finished(request);
      return;
    }

    //! Fill in fields in the URL
    //Debug::debug() << " ---- UltimateLyricsProvider::base url " << url_;

    lyrics_url_ = url_;
    ReplaceFields(request, &lyrics_url_);

    //Debug::debug() << " ---- UltimateLyricsProvider::complete url " << lyrics_url_;
    QUrl url(lyrics_url_);

    QObject *reply = HTTP()->get( url );
    m_requests[reply] = request;

    connect(reply, SIGNAL(data(QByteArray)), this, SLOT(LyricsFetched(QByteArray)));
    connect(reply, SIGNAL(error(QNetworkReply*)), this, SLOT(signalFinish()));
}
Exemple #2
0
void LastFmService::nowPlaying() 
{
    Debug::debug() << "  [LastFmService] now playing";
    if(!m_currentTrack) {
      Debug::debug() << "  [LastFmService] now playing : no current track ";
      return;
    }
    
    if(m_currentTrack->type() != TYPE_TRACK)
      return;
      
    QUrl url("http://ws.audioscrobbler.com/2.0/");

    QMap<QString, QString> params;
    params["method"] = "track.updateNowPlaying";
    params["track"]  = m_currentTrack->title;
    params["artist"] = m_currentTrack->artist;
    params["album"]  = m_currentTrack->album;
    params["trackNumber"] = QString::number(m_currentTrack->num) ;
    params["duration"] = QString::number(m_currentTrack->duration);

    params["api_key"] = LastFm::GLOBAL::api_key;
    params["sk"]      = LastFm::GLOBAL::session_key;

    LastFm::sign(params);
  
    QByteArray data = LastFm::paramToBytearray( params );
    
    /* post request */
    NetworkReply *reply = HTTP()->post(url, data);
    connect(reply, SIGNAL(finished(QNetworkReply*)), SLOT(slot_lastfm_response(QNetworkReply*)));
}   
Exemple #3
0
void LastFmService::love(MEDIA::TrackPtr track, bool love)
{
    Debug::debug() << "  [LastFmService] love";

    QUrl url("http://ws.audioscrobbler.com/2.0/");

    QMap<QString, QString> params;
    if(love)
      params["method"]      = "track.love";
    else
      params["method"]      = "track.unlove";
    params["artist"]      = track->artist;
    params["track"]       = track->title;
    params["api_key"]     = LastFm::GLOBAL::api_key;
    params["sk"]          = LastFm::GLOBAL::session_key;
    
    LastFm::sign(params);

    QByteArray data = LastFm::paramToBytearray( params );
    
    /* post request */
    NetworkReply *reply = HTTP()->post(url, data);
    connect(reply, SIGNAL(finished(QNetworkReply*)), SLOT(scrobbled(QNetworkReply*)));  
  
}
Exemple #4
0
int
Display::plot()
{
  DataGet obs;

  if (!obs) {
    return HTTP(std::cout).errorPage(obs.errmsg());
  }

  const bool qScript(cgi.qJavaScript()); // Is javascript support enabled?
  const bool qCanvas(!cgi.isSet("nc") || (cgi.get("nc") != "1")); // Canvas may be supported

  HTML html;
  html << html.header()
       << html.myStyle()
       << "<title>" << obs.title() << "</title>\n";
 
  if (qScript) {
    html << html.myScript();
  }

  html << "</head>\n<body>\n"
       << dateForm(obs);

  if (qScript && qCanvas) { // scripting in a browser that may support a canvas
    html << "<script>\n"
         << "plt(";
    obs.json(html);
    html << ");\n"
         << "</script>\n"
         << "<noscript>\n";
  }
  
  html << html.addOnStart()
       << "<img src='/kayaking2/cgi/png"
       << cgi.queryString(false)
       << "' alt='Plot goes here' width='800' height='600'>\n"
       << html.addOnEnd();

  if (qScript && qCanvas) {
    html << "</noscript>\n";
  }

  html << "</body>\n</html>\n";

  return HTTP(std::cout).htmlPage(3600, html);
}
bool Database::loadFromURL(std::string url){
    std::string page;
    if (HTTP().get(url, page)){
    
        //get the first line of the input as a token
        std::string delimiters = "\n";
        Tokenizer t(page, delimiters);
        std::string firstLine;
        t.getNextToken(firstLine);
    
        //specify schema
        Tokenizer sch(firstLine,",");
        std::string fName;
        std::vector <FieldDescriptor> vecDes;
        while (sch.getNextToken(fName)){
            FieldDescriptor fdtemp;
            
            if (fName[fName.size()-1]=='*'){
                fName=fName.substr(0,fName.size()-1);
                fdtemp.name=fName;
                fdtemp.index=it_indexed;
                vecDes.push_back(fdtemp);
            }
            
            else {
                fdtemp.name=fName;
                fdtemp.index=it_none;
                vecDes.push_back(fdtemp);
            }
        }
        
        specifySchema(vecDes);
        
        std::string temp2;
        while (t.getNextToken(temp2)){
            std::vector<std::string> line;
            std::string lines;
            Tokenizer t2(temp2,",");
            while (t2.getNextToken(lines)){
                line.push_back(lines);
            }
            addRow(line);
        }
        return true;
    }
    
    else return false;
    
    return false;
}
Exemple #6
0
void LastFmService::scrobble() 
{
    Debug::debug() << "  [LastFmService] scrobble ";
  
    if(!m_currentTrack) {
      Debug::debug() << "  [LastFmService] no current track ";
      return;
    }
    
    if (LastFm::GLOBAL::session_key.isEmpty()) {
        Debug::warning() <<  "Not authenticated to Last.fm";
        return;
    }
    
    m_playbackLength  += QDateTime::currentDateTime().toTime_t() - m_unpauseTime;
    //Debug::debug() << "  [LastFmService] scrobble track m_playbackLength" << m_playbackLength;
    //Debug::debug() << "  [LastFmService] scrobble track m_trackLength" << m_trackLength;

    /* The track must be played for at least half of it's duration or at least 4 minutes, whatever
       occurs first and must be longer then 30 seconds to be scrobbled */
    if (((m_playbackLength < m_currentTrack->duration / 2) && (m_playbackLength < 240)) || (m_currentTrack->duration < 30)) {
        Debug::debug() << "  [LastFmService] track " << m_currentTrack->title << "was not played long enough or is too short, not scrobbling";
        return;
    }  
    
    QUrl url("http://ws.audioscrobbler.com/2.0/");

    QMap<QString, QString> params;
    params["method"]      = "track.scrobble";
    params["timestamp"]   = QString::number(m_playbackStart);
    params["track"]       = m_currentTrack->title;
    params["artist"]      = m_currentTrack->artist;
    params["album"]       = m_currentTrack->album;
    params["trackNumber"] = QString::number(m_currentTrack->num);
    params["duration"]    = QString::number(m_currentTrack->duration);
    params["api_key"]     = LastFm::GLOBAL::api_key;
    params["sk"]          = LastFm::GLOBAL::session_key;

    LastFm::sign(params);

    QByteArray data = LastFm::paramToBytearray( params );
      
    /* post request */
    NetworkReply *reply = HTTP()->post(url, data);
    connect(reply, SIGNAL(finished(QNetworkReply*)), SLOT(slot_lastfm_response(QNetworkReply*)));
}
Exemple #7
0
void LastFmService::signIn(const QString& username, const QString& password)
{
    Debug::debug() << "  [LastFmService] Sign In request...username" << username << " password " << password;
    
    signOut();
    
    QUrl url("http://ws.audioscrobbler.com/2.0/");
    
    QMap<QString, QString> params;
    params["method"]    = "auth.getMobileSession";
    params["username"]  = username;
    params["authToken"] = LastFm::md5((username + LastFm::md5(password.toUtf8())).toUtf8());
    params["api_key"]   = LastFm::GLOBAL::api_key;
    LastFm::sign(params);

    LastFm::GLOBAL::auth_token =  LastFm::md5((username + LastFm::md5(password.toUtf8())).toUtf8());

    QByteArray array = LastFm::paramToBytearray( params );

    /* post request */
    NetworkReply *reply = HTTP()->post(url, array);
    connect(reply, SIGNAL(finished(QNetworkReply*)), SLOT(slot_sign_in_finished(QNetworkReply*)));
}
Exemple #8
0
int					/* O - 1 on success, 0 on error */
cupsdStartTLS(cupsd_client_t *con)	/* I - Client connection */
{
  OSStatus	error = 0;		/* Error code */
  SecTrustRef	peerTrust;		/* Peer certificates */


  cupsdLogMessage(CUPSD_LOG_DEBUG, "[Client %d] Encrypting connection.",
                  con->number);

  con->http->encryption = HTTP_ENCRYPTION_ALWAYS;

  con->http->tls_credentials = copy_cdsa_certificate(con);

  if (!con->http->tls_credentials)
  {
   /*
    * No keychain (yet), make a self-signed certificate...
    */

    if (make_certificate(con))
      con->http->tls_credentials = copy_cdsa_certificate(con);
  }

  if (!con->http->tls_credentials)
  {
    cupsdLogMessage(CUPSD_LOG_ERROR,
        	    "Could not find signing key in keychain \"%s\"",
		    ServerCertificate);
    error = errSSLBadConfiguration;
  }

  if (!error)
    con->http->tls = SSLCreateContext(kCFAllocatorDefault, kSSLServerSide,
                                     kSSLStreamType);

  if (!error)
    error = SSLSetIOFuncs(con->http->tls, _httpReadCDSA, _httpWriteCDSA);

  if (!error)
    error = SSLSetConnection(con->http->tls, HTTP(con));

  if (!error)
    error = SSLSetCertificate(con->http->tls, con->http->tls_credentials);

  if (!error)
  {
   /*
    * Perform SSL/TLS handshake
    */

    while ((error = SSLHandshake(con->http->tls)) == errSSLWouldBlock)
      usleep(1000);
  }

  if (error)
  {
    cupsdLogMessage(CUPSD_LOG_ERROR,
                    "Unable to encrypt connection from %s - %s (%d)",
                    con->http->hostname, cssmErrorString(error), (int)error);

    con->http->error  = error;
    con->http->status = HTTP_ERROR;

    if (con->http->tls)
    {
      CFRelease(con->http->tls);
      con->http->tls = NULL;
    }

    if (con->http->tls_credentials)
    {
      CFRelease(con->http->tls_credentials);
      con->http->tls_credentials = NULL;
    }

    return (0);
  }

  cupsdLogMessage(CUPSD_LOG_DEBUG, "Connection from %s now encrypted.",
                  con->http->hostname);

  if (!SSLCopyPeerTrust(con->http->tls, &peerTrust) && peerTrust)
  {
    cupsdLogMessage(CUPSD_LOG_DEBUG, "Received %d peer certificates.",
		    (int)SecTrustGetCertificateCount(peerTrust));
    CFRelease(peerTrust);
  }
  else
    cupsdLogMessage(CUPSD_LOG_DEBUG, "Received NO peer certificates.");

  return (1);
}
Exemple #9
0
CUPnPDevice::CUPnPDevice(std::string url)
{
	std::string result, head, body, charset, urlbase;
	std::string curl, eurl, name, mimetype, iurl, rcode;
	std::string::size_type pos;
	XMLTreeNode *root, *device, *service, *node, *snode, *icon;
	int width = 0;
	int height = 0;
	int depth = 0;
	bool servicefound = false;

	descurl = url;
	urlbase = url.substr(7);
	pos = urlbase.find("/");
	if (pos != std::string::npos)
		urlbase = url.substr(0,pos+7);
	else
		urlbase = url;

	result = HTTP(url);

	pos = result.find("\r\n\r\n");

	if (pos == std::string::npos)
		//throw std::runtime_error(std::string("no desc body"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no desc body\n");

	head = result.substr(0,pos);
	body = result.substr(pos+4);

	if (body == "")
		//throw std::runtime_error(std::string("desc body empty"));
		printf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: desc body empty\n");

	if (!check_response(head, charset, rcode))
		//throw std::runtime_error(std::string("protocol error"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: protocol error\n");

	if (rcode != "200")
		//throw std::runtime_error(std::string("description url returned ") + rcode);
		printf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: description url error\n");
	
	XMLTreeParser parser(charset.c_str());
	parser.Parse(body.c_str(), body.size(), 1);
	root = parser.RootNode();
	if (!root)
		//throw std::runtime_error(std::string("XML: no root node"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no root node\n");

	if (strcmp(root->GetType(),"root"))
		//throw std::runtime_error(std::string("XML: no root"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no root\n");

	for (node = root->GetChild(); node; node=node->GetNext())
	{
		if (!strcmp(node->GetType(),"URLBase"))
		{
			urlbase = std::string(node->GetData());
			if ((urlbase.length() > 0) && (urlbase[urlbase.length()-1] == '/'))
				urlbase.erase(urlbase.length()-1);
		}

	}

	node = root->GetChild();
	if (!node)
		//throw std::runtime_error(std::string("XML: no root child"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no root child\n");

	while (strcmp(node->GetType(),"device"))
	{
		node = node->GetNext();
		if (!node)
			//throw std::runtime_error(std::string("XML: no device"));
			dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no device\n");
	}
	device = node;

	for (node=device->GetChild(); node; node=node->GetNext())
	{
		if (!strcmp(node->GetType(),"deviceType"))
			devicetype = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"friendlyName"))
			friendlyname = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"manufacturer"))
			manufacturer = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"manufacturerURL"))
			manufacturerurl = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"modelDescription"))
			modeldescription = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"modelName"))
			modelname = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"modelNumber"))
			modelnumber = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"modelURL"))
			modelurl = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"serialNumber"))
			serialnumber = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"UDN"))
			udn = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"UPC"))
			upc = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"iconList"))
		{
			for (icon=node->GetChild(); icon; icon=icon->GetNext())
			{
				bool foundm = false;
				bool foundw = false;
				bool foundh = false;
				bool foundd = false;
				bool foundu = false;

				if (strcmp(icon->GetType(),"icon"))
					//throw std::runtime_error(std::string("XML: no icon"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no icon\n");
				
				for (snode=icon->GetChild(); snode; snode=snode->GetNext())
				{
					if (!strcmp(snode->GetType(),"mimetype"))
					{
						mimetype=std::string(snode->GetData()?snode->GetData():"");
						foundm = true;
					}
					if (!strcmp(snode->GetType(),"width"))
					{
						width=snode->GetData()?atoi(snode->GetData()):0;
						foundw = true;
					}
					if (!strcmp(snode->GetType(),"height"))
					{
						height=snode->GetData()?atoi(snode->GetData()):0;
						foundh = true;
					}
					if (!strcmp(snode->GetType(),"depth"))
					{
						depth=snode->GetData()?atoi(snode->GetData()):0;
						foundd = true;
					}
					if (!strcmp(snode->GetType(),"url"))
					{
						url=std::string(snode->GetData()?snode->GetData():"");
						foundu = true;
					}
				}
				if (!foundm)
					//throw std::runtime_error(std::string("XML: icon without mime"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without mime\n");
				if (!foundw)
					//throw std::runtime_error(std::string("XML: icon without width"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without width\n");
				if (!foundh)
					//throw std::runtime_error(std::string("XML: icon without height"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without height\n");
				if (!foundd)
					//throw std::runtime_error(std::string("XML: icon without depth"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without depth\n");
				if (!foundu)
					//throw std::runtime_error(std::string("XML: icon without url"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without url\n");
				
				UPnPIcon e = {mimetype, url, width, height, depth};
				icons.push_back(e);
			}
		}
		if (!strcmp(node->GetType(),"serviceList"))
		{
			servicefound = true;
			for (service=node->GetChild(); service; service=service->GetNext())
			{
				bool foundc = false;
				bool founde = false;
				bool foundn = false;

				if (strcmp(service->GetType(),"service"))
					//throw std::runtime_error(std::string("XML: no service"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no service\n");
				
				for (snode=service->GetChild(); snode; snode=snode->GetNext())
				{
					if (!strcmp(snode->GetType(),"serviceType"))
					{
						name=std::string(snode->GetData()?snode->GetData():"");
						foundn = true;
					}
					if (!strcmp(snode->GetType(),"eventSubURL"))
					{
						char *p;
						p = snode->GetData();
						if (!p)
							eurl=urlbase + "/";
						else if (p[0]=='/')
							eurl=urlbase + std::string(p);
						else
							eurl=urlbase + "/" + std::string(p);
						founde = true;
					}
					if (!strcmp(snode->GetType(),"controlURL"))
					{
						char *p;
						p = snode->GetData();
						if (!p)
							curl=urlbase + "/";
						else if (p[0]=='/')
							curl=urlbase + std::string(p);
						else
							curl=urlbase + "/" + std::string(p);
						foundc = true;
					}
				}
				if (!foundn)
					//throw std::runtime_error(std::string("XML: no service type"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no service type\n");
				if (!founde)
					//throw std::runtime_error(std::string("XML: no event url"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no service url\n");
				if (!foundc)
					//throw std::runtime_error(std::string("XML: no control url"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no control url\n");
				//try
				{
					services.push_back(CUPnPService(this, curl, eurl, name));
				}
				
				//catch (std::runtime_error error)
				//{
				//	std::cout << "error " << error.what() << "\n";
				//}
			}
		}
	}
	if (!servicefound)
		//throw std::runtime_error(std::string("XML: no service list"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no service list\n");
}
int					/* O - 1 on success, 0 on error */
cupsdStartTLS(cupsd_client_t *con)	/* I - Client connection */
{
  int		status;			/* Error code */
  gnutls_certificate_server_credentials *credentials;
					/* TLS credentials */


  cupsdLogMessage(CUPSD_LOG_DEBUG, "[Client %d] Encrypting connection.",
                  con->http.fd);

 /*
  * Verify that we have a certificate...
  */

  if (access(ServerKey, 0) || access(ServerCertificate, 0))
  {
   /*
    * Nope, make a self-signed certificate...
    */

    if (!make_certificate(con))
      return (0);
  }

 /*
  * Create the SSL object and perform the SSL handshake...
  */

  credentials = (gnutls_certificate_server_credentials *)
                    malloc(sizeof(gnutls_certificate_server_credentials));
  if (credentials == NULL)
  {
    cupsdLogMessage(CUPSD_LOG_ERROR,
                    "Unable to encrypt connection from %s - %s",
                    con->http.hostname, strerror(errno));

    return (0);
  }

  gnutls_certificate_allocate_credentials(credentials);
  gnutls_certificate_set_x509_key_file(*credentials, ServerCertificate,
				       ServerKey, GNUTLS_X509_FMT_PEM);

  gnutls_init(&con->http.tls, GNUTLS_SERVER);
  gnutls_set_default_priority(con->http.tls);

  gnutls_credentials_set(con->http.tls, GNUTLS_CRD_CERTIFICATE, *credentials);
  gnutls_transport_set_ptr(con->http.tls, (gnutls_transport_ptr)HTTP(con));
  gnutls_transport_set_pull_function(con->http.tls, _httpReadGNUTLS);
  gnutls_transport_set_push_function(con->http.tls, _httpWriteGNUTLS);

  while ((status = gnutls_handshake(con->http.tls)) != GNUTLS_E_SUCCESS)
  {
    if (gnutls_error_is_fatal(status))
    {
      cupsdLogMessage(CUPSD_LOG_ERROR,
                      "Unable to encrypt connection from %s - %s",
                      con->http.hostname, gnutls_strerror(status));

      gnutls_deinit(con->http.tls);
      gnutls_certificate_free_credentials(*credentials);
      con->http.tls = NULL;
      free(credentials);
      return (0);
    }
  }

  cupsdLogMessage(CUPSD_LOG_DEBUG, "Connection from %s now encrypted.",
                  con->http.hostname);

  con->http.tls_credentials = credentials;
  return (1);
}
int NeoflowHTTPCorrelator<RequestReaderType,
						  ResponseReaderType,
						  HTTPWriterType,
						  HTTPRequestWriterType,
						  HTTPResponseWriterType,
						  HTTPRequestRefWriterType,
						  HTTPResponseRefWriterType,
						  ConnectionHTTPRefWriterType>
::run() {
	HTTPRequest http_request;
	HTTPResponse http_response;
	IPv4Network network;
	ConnectionSearchHTTP connection_search_http;
	std::tr1::unordered_map<std::string, HTTP> http_map;
	uint8_t id_protocol;
	uint32_t id_src_ip;
	uint32_t id_dst_ip;
	uint16_t id_src_port;
	uint16_t id_dst_port;
	ConnectionSearchHTTP connectionSearchHTTP;
	ConnectionSearchHTTPRequest requestRow;
	ConnectionSearchHTTPResponse responseRow;
	ConnectionSearchHTTPRequestReference requestRef;
	ConnectionSearchHTTPResponseReference responseRef;
	ConnectionSearchConnectionHTTPReference connHTTPRef;
	ErrorStatus errorStatus;
	std::string httpFlowID;

	// fill up the http_map
	while ((errorStatus = _request_reader->read(http_request)) == E_SUCCESS) {
		// formulate the map key
		id_protocol = http_request.protocol();
		httpFlowID.assign(reinterpret_cast<char *>(&id_protocol),
						  sizeof(id_protocol));
		id_src_ip = http_request.raw_source_ip();
		httpFlowID.append(reinterpret_cast<char *>(&id_src_ip),
						  sizeof(id_src_ip));
		id_dst_ip = http_request.raw_destination_ip();
		httpFlowID.append(reinterpret_cast<char *>(&id_dst_ip),
						  sizeof(id_dst_ip));
		id_src_port = http_request.raw_source_port();
		httpFlowID.append(reinterpret_cast<char *>(&id_src_port),
						  sizeof(id_src_port));
		id_dst_port = http_request.raw_destination_port();
		httpFlowID.append(reinterpret_cast<char *>(&id_dst_port),
						  sizeof(id_dst_port));

		// check if there's an HTTP already in the map
		//      if not, create one
		std::tr1::unordered_map<std::string, HTTP>::iterator httpIt(http_map.find(httpFlowID));
		if (httpIt == http_map.end()) {
			httpIt = http_map.insert(std::make_pair(httpFlowID,
											  HTTP(id_protocol,
												   id_src_ip,
												   id_dst_ip,
												   id_src_port,
												   id_dst_port))).first;
		}

		// add this http_request to the HTTP in the map
		httpIt->second.add_request(http_request);
	}
	if (errorStatus != E_EOF) {
		_error = true;
		_errorMsg.assign("Reader: error reading http_request");
		return 1;
	}

	while ((errorStatus = _response_reader->read(http_response)) == E_SUCCESS) {
		// formulate the map key
		id_protocol = http_response.protocol();
		httpFlowID.assign(reinterpret_cast<char *>(&id_protocol),
						  sizeof(id_protocol));
		id_dst_ip = http_response.raw_destination_ip();
		httpFlowID.append(reinterpret_cast<char *>(&id_dst_ip),
						  sizeof(id_dst_ip));
		id_src_ip = http_response.raw_source_ip();
		httpFlowID.append(reinterpret_cast<char *>(&id_src_ip),
						  sizeof(id_src_ip));
		id_dst_port = http_response.raw_destination_port();
		httpFlowID.append(reinterpret_cast<char *>(&id_dst_port),
						  sizeof(id_dst_port));
		id_src_port = http_response.raw_source_port();
		httpFlowID.append(reinterpret_cast<char *>(&id_src_port),
						  sizeof(id_src_port));

		std::tr1::unordered_map<std::string, HTTP>::iterator httpIt(http_map.find(httpFlowID));
		if (httpIt != http_map.end()) {
			// add it
			httpIt->second.add_response(http_response);
		}
		httpIt = http_map.insert(make_pair(httpFlowID,
										  HTTP(id_protocol,
											   id_dst_ip,
											   id_src_ip,
											   id_dst_port,
											   id_src_port))).first;

		// add this http_response to the HTTP in the map
		httpIt->second.add_response(http_response);
	}
	if (errorStatus != E_EOF) {
		_error = true;
		_errorMsg.assign("Reader: error reading response");
		return 1;
	}

	// for each Connection
	for (std::set<ConnectionSearchConnection>::const_iterator i(_set->begin());
		 i != _set->end();
		 ++i)
	{
		// create the flowID
		id_protocol = i->protocol();
		httpFlowID.assign(reinterpret_cast<char *>(&id_protocol),
						  sizeof(id_protocol));
		id_dst_ip = i->raw_ip_a();
		httpFlowID.append(reinterpret_cast<char *>(&id_dst_ip),
						  sizeof(id_dst_ip));
		id_src_ip = i->raw_ip_b();
		httpFlowID.append(reinterpret_cast<char *>(&id_src_ip),
						  sizeof(id_src_ip));
		id_dst_port = i->raw_port_a();
		httpFlowID.append(reinterpret_cast<char *>(&id_dst_port),
						  sizeof(id_dst_port));
		id_src_port = i->raw_port_b();
		httpFlowID.append(reinterpret_cast<char *>(&id_src_port),
						  sizeof(id_src_port));
		// check for flow ID
		std::tr1::unordered_map<std::string, HTTP>::iterator httpIt(http_map.find(httpFlowID));
		if (httpIt == http_map.end()) {
			// if not found, create reverse flowID
			httpFlowID.assign(reinterpret_cast<char *>(&id_protocol),
							  sizeof(id_protocol));
			id_dst_ip = i->raw_ip_b();
			httpFlowID.append(reinterpret_cast<char *>(&id_dst_ip),
							  sizeof(id_dst_ip));
			id_src_ip = i->raw_ip_a();
			httpFlowID.append(reinterpret_cast<char *>(&id_src_ip),
							  sizeof(id_src_ip));
			id_dst_port = i->raw_port_b();
			httpFlowID.append(reinterpret_cast<char *>(&id_dst_port),
							  sizeof(id_dst_port));
			id_src_port = i->raw_port_a();
			httpFlowID.append(reinterpret_cast<char *>(&id_src_port),
							  sizeof(id_src_port));

			httpIt = http_map.find(httpFlowID);
			if (httpIt == http_map.end()) {
				continue;
			}
		}

		// found...write http and xref info
		connectionSearchHTTP.http_id(_http_id);
		connectionSearchHTTP.start_time(httpIt->second.start_time());
		connectionSearchHTTP.end_time(httpIt->second.end_time());
		connectionSearchHTTP.protocol(httpIt->second.protocol());
		connectionSearchHTTP.client_ip(httpIt->second.client_ip());
		connectionSearchHTTP.server_ip(httpIt->second.server_ip());
		connectionSearchHTTP.client_port(httpIt->second.client_port());
		connectionSearchHTTP.server_port(httpIt->second.server_port());

		_http_writer->write(connectionSearchHTTP);

		connHTTPRef.http_id(_http_id);
		connHTTPRef.connection_id(i->connection_id());

		_conn_http_ref_writer->write(connHTTPRef);

		// write the requests
		std::vector<HTTPRequest> requests(httpIt->second.requests());
		requestRef.http_id(_http_id);
		for (std::vector<HTTPRequest>::const_iterator req(requests.begin());
			 req != requests.end();
			 ++req)
		{
			requestRow.http_request_id(_http_request_id);
			requestRow.time(req->time());
			requestRow.protocol(req->protocol());
			requestRow.source_ip(req->source_ip());
			requestRow.destination_ip(req->destination_ip());
			requestRow.source_port(req->source_port());
			requestRow.destination_port(req->destination_port());
			requestRow.type(req->type());
			requestRow.uri(req->uri());
			requestRow.version(req->version());
			requestRow.host(req->host());
			requestRow.user_agent(req->user_agent());
			requestRow.referer(req->referer());

			_request_writer->write(requestRow);

			requestRef.http_request_id(_http_request_id);

			_request_ref_writer->write(requestRef);

			++_http_request_id;
		}

		// write the responses
		std::vector<HTTPResponse> responses(httpIt->second.responses());
		responseRef.http_id(_http_id);
		for (std::vector<HTTPResponse>::const_iterator res(responses.begin());
			 res != responses.end();
			 ++res)
		{
			responseRow.http_response_id(_http_response_id);
			responseRow.time(res->time());
			responseRow.protocol(res->protocol());
			responseRow.source_ip(res->source_ip());
			responseRow.destination_ip(res->destination_ip());
			responseRow.source_port(res->source_port());
			responseRow.destination_port(res->destination_port());
			responseRow.version(res->version());
			responseRow.status(res->status());
			responseRow.response(res->response());
			responseRow.reason(res->reason());
			responseRow.content_type(res->content_type());

			_response_writer->write(responseRow);

			responseRef.http_response_id(_http_response_id);

			_response_ref_writer->write(responseRef);

			++_http_response_id;
		}

		++_http_id;
	}

	return 0;
}