~ubuntu-branches/ubuntu/karmic/lire/karmic

« back to all changes in this revision

Viewing changes to www/lib/Lire/DlfAnalysers/UserAgentCategoriser.pm

  • Committer: Bazaar Package Importer
  • Author(s): Wolfgang Sourdeau
  • Date: 2005-04-25 23:10:41 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050425231041-8h3y0jyvmj0pe05o
Tags: 2:2.0.1-4
debian/control: build-depend an depend on libdbd-sqlite2-perl (>=
2:0.33-4) instead of libdbd-sqlite-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2002,2004 Stichting LogReport Foundation logreport@logreport.org
 
2
 
 
3
# This file is part of Lire.
 
4
 
 
5
# Lire is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
 
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
 
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program (see COPYING); if not, check with
 
17
# http://www.gnu.org/copyleft/gpl.html or write to the Free Software
 
18
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 
19
 
 
20
# Author:
 
21
#   Francis J. Lacoste <flacoste@logreport.org>
 
22
 
 
23
package Lire::DlfAnalysers::UserAgentCategoriser;
 
24
 
 
25
use strict;
 
26
 
 
27
use base qw/Lire::DlfCategoriser/;
 
28
 
 
29
use Lire::WWW::UserAgent;
 
30
 
 
31
sub new {
 
32
    return bless {}, shift;
 
33
}
 
34
 
 
35
sub name {
 
36
    return "www-user_agent";
 
37
}
 
38
 
 
39
sub title {
 
40
    return "UserAgent DlfAnalyser";
 
41
}
 
42
 
 
43
sub description {
 
44
    return '<para>This categoriser extracts browser, os and language information from the <structfield>useragent</structfield> field.</para>';
 
45
}
 
46
 
 
47
sub src_schema {
 
48
    return "www";
 
49
}
 
50
 
 
51
sub dst_schema {
 
52
    return "www-user_agent";
 
53
}
 
54
 
 
55
sub initialise {
 
56
    my ( $self, $config ) = @_;
 
57
 
 
58
    $self->{'analyser'} =
 
59
      new Lire::WWW::UserAgent( 'os_default' => 'LIRE_UNDEF',
 
60
                                'language_default' => 'LIRE_UNDEF',
 
61
                                'browser_default' => 'LIRE_UNDEF',
 
62
                              );
 
63
    return;
 
64
}
 
65
 
 
66
sub categorise {
 
67
    my ( $self, $dlf ) = @_;
 
68
 
 
69
    return unless defined $dlf->{'useragent'};
 
70
    $self->{'analyser'}->setUserAgent( $dlf->{ 'useragent'} );
 
71
 
 
72
    $dlf->{'os'} = $self->{'analyser'}->getOS();
 
73
    $dlf->{'lang'} = $self->{'analyser'}->getLanguage();
 
74
    $dlf->{'browser'} = $self->{'analyser'}->getBrowser();
 
75
 
 
76
    foreach my $field ( qw/os lang browser/ ) {
 
77
        $dlf->{$field} = undef if $dlf->{$field} eq 'LIRE_UNDEF';
 
78
    }
 
79
 
 
80
    return;
 
81
}
 
82
 
 
83
# keep perl happy
 
84
1;