1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
///////////////////////////////////////////////////////////////
//
// File: HtCookieInFileJar.cc - Definition of class 'HtCookieInFileJar'
//
// Author: Gabriele Bartolini <angusgb@users.sf.net>
// Started: Mon Jan 27 14:38:42 CET 2003
//
// Class which allows a cookie file to be imported in memory
// for ht://Check and ht://Dig applications.
//
// The cookie file format is a text file, as proposed by Netscape,
// and each line contains a name-value pair for a cookie.
// Fields within a single line are separated by the 'tab' character;
// Here is the format for a line, as taken from http://www.cookiecentral.com/faq/#3.5:
//
// domain - The domain that created AND that can read the variable.
// flag - A TRUE/FALSE value indicating if all machines within a given domain
// can access the variable. This value is set automatically by the browser,
// depending on the value you set for domain.
// path - The path within the domain that the variable is valid for.
// secure - A TRUE/FALSE value indicating if a secure connection with the
// domain is needed to access the variable.
// expiration - The UNIX time that the variable will expire on. UNIX time is
// defined as the number of seconds since Jan 1, 1970 00:00:00 GMT.
// name - The name of the variable.
// value - The value of the variable.
//
//
///////////////////////////////////////////////////////////////
//
// Part of the ht://Check <http://htcheck.sourceforge.net/>
// Copyright (c) 1999-2004 Comune di Prato, Italia
//
// Part of the ht://Dig package <http://www.htdig.org/>
// Copyright (c) 1999-2004 The ht://Dig Group
// For copyright details, see the file COPYING in your distribution
// or the GNU Library General Public License (LGPL) version 2 or later
// <http://www.gnu.org/copyleft/lgpl.html>
//
///////////////////////////////////////////////////////////////
// $Id: HtCookieInFileJar.cc,v 1.5 2004/05/28 13:15:23 lha Exp $
///////////////////////////////////////////////////////////////
#ifndef __HtCookieInFileJar_H
#include "HtCookieInFileJar.h"
#endif
#include <stdio.h>
#define MAX_COOKIE_LINE 16384
// Costruttore (default constructor)
HtCookieInFileJar::HtCookieInFileJar(const String& fn, int& result)
: _filename(fn)
{
result = Load();
}
// Costruttore di copia (copy constructor)
HtCookieInFileJar::HtCookieInFileJar(const HtCookieInFileJar& rhs)
{
}
// Distruttore
HtCookieInFileJar::~HtCookieInFileJar()
{
}
// Operatore di assegnamento (assignment operator)
HtCookieInFileJar& HtCookieInFileJar::operator=(const HtCookieInFileJar& rhs)
{
if (this == &rhs)
return *this;
// Code for attributes copy
return *this; // ritorna se stesso
}
// Loads the contents of a cookies file into memory
int HtCookieInFileJar::Load()
{
FILE *f = fopen((const char *)_filename, "r");
if (f == NULL)
return -1;
char buf[MAX_COOKIE_LINE];
while(fgets(buf, MAX_COOKIE_LINE, f))
{
if (*buf && *buf != '#' && (strlen(buf) > 10)) // 10 is an indicative value
{
HtCookie *Cookie = new HtCookie(buf);
// Interface to the insert method
// If the cookie is not valid or has not been added, we'd better delete it
if (!Cookie->GetName().length()
|| !AddCookieForHost (Cookie, Cookie->GetSrcURL()))
{
if (debug > 2)
cout << "Discarded cookie line: " << buf;
delete Cookie;
}
}
}
return 0;
}
// Outputs a summary of the cookies that have been imported
ostream &HtCookieInFileJar::ShowSummary(ostream &out)
{
char * key;
int num_cookies = 0; // Global number of cookies
cookieDict->Start_Get();
out << endl << "Cookies that have been correctly imported from: " << _filename << endl;
while ((key = cookieDict->Get_Next()))
{
List * list;
HtCookie * cookie;
list = (List *)cookieDict->Find(key);
list->Start_Get();
while ((cookie = (HtCookie *)list->Get_Next()))
{
++num_cookies;
out << " " << num_cookies << ". " << cookie->GetName()
<< ": " << cookie->GetValue() << " (Domain: " << cookie->GetDomain();
if (debug > 1)
{
out << " - Path: " << cookie->GetPath();
if (cookie->GetExpires())
out << " - Expires: " << cookie->GetExpires()->GetRFC850();
}
out << ")" << endl;
}
// Global number of cookies
}
return out;
}
///////////////////////////////////////////////////////////////
|