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

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

version 0.10

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