AMFWebService.pm untested

filter: Statementstmt 0.0% 0 / 108 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 181 CC 17 SCAR 52.6
CC
17
Cov
0%
handler
306.0
BEGIN
2.0
BEGIN
2.0
CRAP 193.4
1 #file:Apache2/AMFWebService.pm;
2 #--------------------------------
3  
4 #
5 # Created by Idel Fuschini
6 # Date: 01/08/10
7 # Site: http://www.apachemobilefilter.org
8 # Mail: idel.fuschini@gmail.com
9  
10 package Apache2::AMFWebService;
11
12 use strict;
13 use warnings;
14 use Apache2::AMFCommonLib ();
15
16 use Apache2::Filter ();
17 use Apache2::RequestIO ();
18 use APR::Table ();
19 use Cache::FileBackend;
20
21 use Apache2::Const -compile => qw(OK);
22
23 use constant BUFF_LEN => 1024;
24 use vars qw($VERSION);
25 $VERSION= "4.33";;;
26 #
27 # Define the global environment
28 #
29 my $CommonLib = new Apache2::AMFCommonLib ();
30 my $cachedirectorystore="notdefined";
31 my $cachedirective="no-cache";
32  
33 $CommonLib->printLog("---------------------------------------------------------------------------");
34 $CommonLib->printLog("AMFWebService Version $VERSION");
35
36 if ($ENV{RestMode}) {
37 } else {
38 $CommonLib->printLog("RestMode must be setted not exist. Please set the variable RestMode into httpd.conf");
39 }
40 if ($ENV{AMFWSCacheControl}) {
41 $cachedirective=$ENV{AMFWSCacheControl};
42 $CommonLib->printLog("AMFWSCacheControl is: $cachedirective");
43 } else {
44 $CommonLib->printLog("AMFWSCacheControl is not setted.");
45 }
46  
47 sub handler {
48 my $f = shift;
49 my $query_string=$f->args;
50 my $id;
51 my $ua;
52 my $capab;
53 my %ArrayQuery;
54 my %ArrayForSort;
55 my %ArrayPnotes;
56 my %ArrayCapability;
57 my $type="xml";
58 my $capabilityList="all";
59
60 if ($query_string) {
61 my @vars = split(/&/, $query_string);
62 foreach my $var (sort @vars){
63 if ($var) {
64 my ($v,$i) = split(/=/, $var);
65 $v =~ tr/+/ /;
66 $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
67 $i =~ tr/+/ /;
68 $i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
69 $i =~ s/<!--(.|\n)*-->//g;
70 $ArrayQuery{$v}=$i;
71 }
72 }
73 if ($ArrayQuery{type}) {
74 $type=$ArrayQuery{type};
75 }
76 if ($ArrayQuery{capabilityList}) {
77 my @capability = split(/,/, $ArrayQuery{capabilityList});
78 $capabilityList="no";
79 foreach my $var (sort @capability){
80 if ($var) {
81 $var=~ tr/[a-z]/[A-Z]/;
82 $ArrayCapability{$var}='ok';
83 }
84 }
85 }
86  
87 }
88
89 my $Hash=$f->subprocess_env();
90 my $html_page;
91 my $content_type="text/xml";
92 if ($type ne 'json' && $type ne 'xml') {
93 $type='xml';
94 }
95 if ($type eq 'json') {
96 $content_type="text/plain";
97 }
98 if ($type eq 'xml') {
99 $html_page='<?xml version="1.0" encoding="UTF-8"?><AMF_DEVICE_DETECTION>';
100 }
101 if ($type eq 'json') {
102 $html_page='{"AMF_DEVICE_DETECTION": {'."\n";
103 }
104 my $count=0;
105 while ( my ($key, $value) = each(%$Hash) ) {
106 if (substr($key,0,4) eq 'AMF_') {
107 $key=substr($key,4,length($key));
108 if ($count > 0) {
109 $html_page=$html_page.",\n";
110 $count=0;
111 }
112 if ($type eq 'xml' && ($capabilityList eq 'all' || ($ArrayCapability{$key}))) {
113 $html_page=$html_page."<$key>$value</$key>";
114 }
115 if ($type eq 'json' && ($capabilityList eq 'all' || ($ArrayCapability{$key}))) {
116 $html_page=$html_page." \"$key\":\"$value\"";
117 $count++;
118 }
119 }
120 }
121 if ($type eq 'xml') {
122 $html_page=$html_page.'</AMF_DEVICE_DETECTION>';
123 }
124 if ($type eq 'json') {
125 $html_page=substr($html_page,0,length($html_page)-2);
126 $html_page=$html_page."\n }\n}";
127 }
128 $f->headers_out->set("Last-Modified" => time());
129 if ($ENV{AMFWSCacheControl}) {
130 $f->err_headers_out->set('Cache-Control' => $cachedirective);
131 }
132 $f->content_type($content_type);
133 $f->print($html_page);
134 return Apache2::Const::OK;
135 }
136 1;
137  
138  
139 =head1 NAME
140  
141 Apache2::AMFWebService - This module give the result of Device Detection as WebService
142  
143 =head1 DESCRIPTION
144  
145 This module give the info as WebService
146  
147 =head1 AMF PROJECT SITE
148  
149 http://www.apachemobilefilter.org
150  
151 =head1 DOCUMENTATION
152  
153 http://wiki.apachemobilefilter.org
154  
155 Perl Module Documentation: http://wiki.apachemobilefilter.org/index.php/AMFWebService
156  
157 =head1 AUTHOR
158  
159 Idel Fuschini (idel.fuschini [at] gmail [dot] com)
160  
161 =head1 COPYRIGHT
162  
163 You may distribute under the terms of either the GNU General Public
164 License or the Artistic License, as specified in the Perl README file.
165  
166 =cut