/usr/share/tiarra/module/Client/Guess.pm is in tiarra 20100212-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | # -----------------------------------------------------------------------------
# $Id: Guess.pm 36552 2010-01-27 14:53:29Z drry $
# -----------------------------------------------------------------------------
# copyright (C) 2004 Topia <topia@clovery.jp>. all rights reserved.
package Client::Guess;
use strict;
use warnings;
use RunLoop;
use SelfLoader;
use Tiarra::SharedMixin;
# shorthand
our $re_ver = qr/[\d.][\d.a-zA-Z+-]+/;
our $re_tok = qr/\S+/;
sub _new {
# don't need instance present
return shift;
}
sub destruct {
map {
$_->remark('client-guess-cache', undef, 'delete');
} RunLoop->shared_loop->clients_list;
}
sub is_target {
my ($class_or_this, $type, $client) = @_;
my $this = $class_or_this->_this;
my $guess = $this->guess($client)->{type};
if (defined $guess) {
return $guess eq $type;
} else {
return undef;
}
}
sub guess {
my ($class_or_this, $client, $rehash) = @_;
my $this = $class_or_this->_this;
my $struct = $client->remark('client-guess-cache');
if (!$rehash && defined $struct && $struct->{completed}) {
return $struct;
} else {
$struct = {};
}
if (defined $client->remark('client-version')) {
if ($this->guess_ctcp_version($struct,
$client->remark('client-version'))) {
$struct->{completed} = 1;
}
}
if (defined $client->remark('client-type')) {
$struct->{type} = $client->remark('client-type');
}
if (scalar(keys(%{$struct}))) {
# cache
$client->remark('client-guess-cache', $struct);
}
return $struct;
}
sub guess_ctcp_version {
my ($class_or_this, $struct, $str) = @_;
my $this = $class_or_this->_this;
my $struct_set = sub {
my %stor;
# copy values
my $param;
$param = shift;
if (ref($param) eq 'ARRAY') {
$stor{keys} = [@$param];
} else {
$stor{keys} = [$param];
}
$stor{values} = [@_];
my ($key, $value);
while () {
($key, $value) = map {
if (scalar @{$stor{$_}}) {
shift @{$stor{$_}};
} else {
return $struct;
}
} qw(keys values);
$struct->{$key} = $value;
}
};
#$struct_set->('ctcp_version', $str);
my $func = 'version_guess_' . lc(substr($str,0,1));
if ($this->can($func)) {
if ($this->$func($str, $struct_set)) {
return 1;
}
}
if ($str =~ /^(Cotton|Unknown) Client/) {
$struct->{type} = 'cotton';
$struct->{exact_type} = lc($1);
} else {
return undef;
}
return 1;
}
no warnings 'redefine';
SelfLoader->load_stubs;
1;
__DATA__
sub version_guess_c {
my ($this, $str, $struct_set) = @_;
if ($str =~ /^CHOCOA ($re_ver) \(($re_tok)\)/) {
$struct_set->([qw(type ver plat)],
'chocoa', $1, $2);
} elsif ($str =~ m[^Conversation ($re_ver) for (MacOS X|.+?) (http://$re_tok)]) {
$struct_set->([qw(type ver plat url)],
'conversation', $1, $2, $3);
} else {
return undef;
}
return 1;
}
sub version_guess_t {
my ($this, $str, $struct_set) = @_;
if ($str =~ /^Tiarra:($re_tok):perl ($re_tok) on ($re_tok)/) {
$struct_set->([qw(type ver perl_ver perl_plat)],
'tiarra', $1, $2, $3);
} else {
return undef;
}
return 1;
}
sub version_guess_l {
my ($this, $str, $struct_set) = @_;
if ($str =~ /^LimeChat ($re_ver) \((.+?)\)/) {
$struct_set->([qw(type ver plat)], 'limechat', $1, $2);
} elsif ($str =~ /^Loqui version ($re_tok)/) {
$struct_set->([qw(type ver)], 'loqui', $1);
} elsif ($str =~ m{^Liece/($re_ver) :}) {
$struct_set->([qw(type ver)], 'liece', $1);
} else {
return undef;
}
return 1;
}
sub version_guess_m {
my ($this, $str, $struct_set) = @_;
if ($str =~ /^madoka ($re_ver) in perl ($re_ver):/) {
$struct_set->([qw(type ver perl_ver)], 'madoka', $1, $2);
} elsif ($str =~ /^Misuzilla Ircv \(($re_ver) version\) on (.NET CLR-$re_tok)/) {
$struct_set->([qw(type ver plat)], 'ircv', $1, $2);
} else {
return undef;
}
return 1;
}
sub version_guess_p {
my ($this, $str, $struct_set) = @_;
if ($str =~ /^plum ($re_ver) perl ($re_ver)\s*:?/) {
$struct_set->([qw(type ver perl_ver)], 'plum', $1, $2);
} else {
return undef;
}
return 1;
}
sub version_guess_r {
my ($this, $str, $struct_set) = @_;
if ($str =~ m{^Riece/($re_ver) ($re_tok)/($re_ver)}) {
$struct_set->([qw(type ver emacs_flavor emacs_ver)], 'riece', $1, $2, $3);
} else {
return undef;
}
return 1;
}
sub version_guess_w {
my ($this, $str, $struct_set) = @_;
if ($str =~ /^WoolChat Ver ($re_ver)/) {
$struct_set->([qw(type ver)], 'woolchat', $1);
} else {
return undef;
}
return 1;
}
sub version_guess_x {
my ($this, $str, $struct_set) = @_;
if ($str =~ m{^xchat ($re_ver) ($re_tok) ($re_tok) \[($re_tok)/($re_tok)\]}) {
$struct_set->([qw(type ver plat plat_ver arch cpu_speed)],
'xchat', $1, $2, $3, $4, $5);
} else {
return undef;
}
return 1;
}
|