root/HTTP-MobileAgent/trunk/lib/HTTP/MobileAgent/DoCoMo.pm

Revision 875 (checked in by miyagawa, 17 years ago)

version 0.09

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package HTTP::MobileAgent::DoCoMo;
2
3 use strict;
4 use vars qw($VERSION);
5 $VERSION = 0.09;
6
7 use base qw(HTTP::MobileAgent);
8
9 __PACKAGE__->make_accessors(
10     qw(version model status bandwidth
11        serial_number is_foma card_id comment)
12 );
13
14 use HTTP::MobileAgent::DoCoMoDisplayMap qw($DisplayMap);
15
16 # various preferences
17 use vars qw($DefaultCacheSize $HTMLVerMap $FOMAHTMLVersion);
18 $DefaultCacheSize = 5;
19
20 # http://www.nttdocomo.co.jp/p_s/imode/spec/useragent.html
21 $HTMLVerMap = [
22     # regex => version
23     qr/[DFNP]501i/ => '1.0',
24     qr/502i|821i|209i|691i|(F|N|P|KO)210i|^F671i$/ => '2.0',
25     qr/(D210i|SO210i)|503i|211i|SH251i|692i|200[12]|2101V/ => '3.0',
26     qr/504i|251i|^F671iS$|212i|2051|2102V/ => '4.0',
27     qr/eggy|P751v/ => '3.2',
28 ];
29
30 sub is_docomo { 1 }
31
32 sub parse {
33     my $self = shift;
34     my($main, $foma_or_comment) = split / /, $self->user_agent, 2;
35
36     if ($foma_or_comment && $foma_or_comment =~ s/^\((.*)\)$/$1/) {
37         # DoCoMo/1.0/P209is (Google CHTML Proxy/1.0)
38         $self->{comment} = $1;
39         $self->_parse_main($main);
40     } elsif ($foma_or_comment) {
41         # DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)
42         $self->{is_foma} = 1;
43         @{$self}{qw(name version)} = split m!/!, $main;
44         $self->_parse_foma($foma_or_comment);
45     } else {
46         # DoCoMo/1.0/R692i/c10
47         $self->_parse_main($main);
48     }
49 }
50
51 sub _parse_main {
52     my($self, $main) = @_;
53     my($name, $version, $model, $cache, @rest) = split m!/!, $main;
54     $self->{name}    = $name;
55     $self->{version} = $version;
56     $self->{model}   = $model;
57
58     if ($cache) {
59         $cache =~ s/^c// or return $self->no_match;
60         $self->{cache_size} = $cache;
61     }
62
63     for (@rest) {
64         /^ser(\w{11})$/ and do { $self->{serial_number} = $1; next };
65         /^(T[DBJ])$/   and do { $self->{status} = $1; next };
66         /^s(\d+)$/     and do { $self->{bandwidth} = $1; next };
67     }
68 }
69
70 sub _parse_foma {
71     my($self, $foma) = @_;
72
73     $foma =~ s/^([^\(]+)// or return $self->no_match;
74     $self->{model} = $1;
75     $self->{model} = 'SH2101V' if $1 eq 'MST_v_SH2101V'; # Huh?
76
77     if ($foma =~ s/^\((.*?)\)$//) {
78         my @options = split /;/, $1;
79         for (@options) {
80             /^c(\d+)$/      and $self->{cache_size} = $1, next;
81             /^ser(\w{15})$/ and $self->{serial_number} = $1, next;
82             /^icc(\w{20})$/ and $self->{card_id} = $1, next;
83             $self->no_match;
84         }
85     }
86 }
87
88 sub html_version {
89     my $self = shift;
90
91     my @map = @$HTMLVerMap;
92     while (my($re, $version) = splice(@map, 0, 2)) {
93         return $version if $self->model =~ /$re/;
94     }
95     return undef;
96 }
97
98 sub cache_size {
99     my $self = shift;
100     return $self->{cache_size} || $DefaultCacheSize;
101 }
102
103 sub series {
104     my $self = shift;
105     return 'FOMA' if $self->is_foma;
106
107     my $model = $self->model;
108     $model =~ /(\d{3}i)/;
109     return $1;
110 }
111
112 sub vendor {
113     my $self = shift;
114     my $model = $self->model;
115     $model =~ /^([A-Z]+)\d/;
116     return $1;
117 }
118
119 sub _make_display {
120     my $self = shift;
121     my $display = $DisplayMap->{$self->model};
122     return HTTP::MobileAgent::Display->new(%$display);
123 }
124
125 1;
126 __END__
127
128 =head1 NAME
129
130 HTTP::MobileAgent::DoCoMo - NTT DoCoMo implementation
131
132 =head1 SYNOPSIS
133
134   use HTTP::MobileAgent;
135
136   local $ENV{HTTP_USER_AGENT} = "DoCoMo/1.0/P502i/c10";
137   my $agent = HTTP::MobileAgent->new;
138
139   printf "Name: %s\n", $agent->name;                    # "DoCoMo"
140   printf "Ver: %s\n", $agent->version;                  # 1.0
141   printf "HTML ver: %s\n", $agent->html_version;        # 2.0
142   printf "Model: %s\n", $agent->model;                  # "P502i"
143   printf "Cache: %dk\n", $agent->cache_size;            # 10
144   print  "FOMA\n" if $agent->is_foma;                   # false
145   printf "Vendor: %s\n", $agent->vendor;                # 'P'
146   printf "Series: %s\n", $agent->series;                # "502i"
147
148   # only available with <form utn>
149   # e.g.) "DoCoMo/1.0/P503i/c10/serNMABH200331";
150   printf "Serial: %s\n", $agent->serial_number;         # "NMABH200331"
151
152   # e.g.) "DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)";
153   printf "Serial: %s\n", $agent->serial_number;         # "0123456789abcde"
154   printf "Card ID: %s\n", $agent->card_id;              # "01234567890123456789"
155
156   # e.g.) "DoCoMo/1.0/P502i (Google CHTML Proxy/1.0)
157   pritnf "Comment: %s\n", $agent->comment;              # "Google CHTML Proxy/1.0
158
159   # only available in eggy/M-stage
160   # e.g.) "DoCoMo/1.0/eggy/c300/s32/kPHS-K"
161   printf "Bandwidth: %dkbps\n", $agent->bandwidth;      # 32
162
163 =head1 DESCRIPTION
164
165 HTTP::MobileAgent::DoCoMo is a subclass of HTTP::MobileAgent, which
166 implements NTT docomo i-mode user agents.
167
168 =head1 METHODS
169
170 See L<HTTP::MobileAgent/"METHODS"> for common methods. Here are
171 HTTP::MobileAgent::DoCoMo specific methods.
172
173 =over 4
174
175 =item version
176
177   $version = $agent->version;
178
179 returns DoCoMo version number like "1.0".
180
181 =item html_version
182
183   $html_version = $agent->html_version;
184
185 returns supported HTML version like '3.0'. retuns undef if unknown.
186
187 =item model
188
189   $model = $agent->model;
190
191 returns name of the model like 'P502i'.
192
193 =item cache_size
194
195   $cache_size = $agent->cache_size;
196
197 returns cache size as killobytes unit. returns 5 if unknown.
198
199 =item is_foma
200
201   if ($agent->is_foma) { }
202
203 retuns whether it's FOMA or not.
204
205 =item vendor
206
207   $vendor = $agent->vendor;
208
209 returns vender code like 'SO' for Sony. returns undef if unknown.
210
211 =item series
212
213   $series = $agent->series;
214
215 returns series name like '502i'. returns undef if unknown.
216
217 =item serial_number
218
219   $serial_number = $agent->serial_number;
220
221 returns hardware unique serial number (15 digit in FOMA, 11 digit
222 otherwise alphanumeric). Only available with E<lt>form utnE<gt>
223 attribute. returns undef otherwise.
224
225 =item card_id
226
227   $card_id = $agent->card_id;
228
229 returns FOMA Card ID (20 digit alphanumeric). Only available in FOMA
230 with E<lt>form utnE<gt> attribute. returns undef otherwise.
231
232 =item comment
233
234   $comment = $agent->comment;
235
236 returns comment on user agent string like 'Google Proxy'. returns
237 undef otherwise.
238
239 =item bandwidth
240
241   $bandwidth = $agent->bandwidth;
242
243 returns bandwidth like 32 as killobytes unit. Only vailable in eggy,
244 returns undef otherwise.
245
246 =back
247
248 =head1 AUTHOR
249
250 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
251
252 This library is free software; you can redistribute it and/or modify
253 it under the same terms as Perl itself.
254
255 =head1 SEE ALSO
256
257 L<HTTP::MobileAgent>
258
259 http://www.nttdocomo.co.jp/p_s/imode/spec/useragent.html
260
261 http://www.nttdocomo.co.jp/p_s/imode/spec/ryouiki.html
262
263 http://www.nttdocomo.co.jp/p_s/imode/tag/utn.html
264
265 http://www.nttdocomo.co.jp/p_s/mstage/visual/contents/cnt_mpage.html
266
267
268 =cut
Note: See TracBrowser for help on using the browser.