blib/lib/Net/OmaDrm.pm untested

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 149 CC 13 SCAR 26.9
CC
13
Cov
0%
genCombinedDelivery
30.0
genForwardLock
20.0
new
12.0
CRAP 14.7
1 package Net::OmaDrm;
2  
3 use strict;
4 use warnings;
5 use diagnostics;
6  
7 #use MIME::Base64;
8  
9 # See the bottom of this file for the POD documentation. Search for the
10 # string '=head'.
11  
12 # You can run this file through either pod2man or pod2html to produce pretty
13 # documentation in manual or html file format (these utilities are part of the
14 # Perl 5 distribution).
15  
16 # Copyright (c) 2007 Christopherus Goo. All rights reserved.
17 # It may be used and modified freely, but I do request that this copyright
18 # notice remain attached to the file. You may modify this module as you
19 # wish, but if you redistribute a modified version, please attach a note
20 # listing the modifications you have made.
21  
22 # The most recent version and complete docs are available at:
23 # http://www.artofmobile.com/software/
24  
25 # April 2007. Singapore.
26  
27 $Net::OmaDrm::VERSION=0.1;
28  
29 =head1 NAME
30  
31 Net::OmaDrm - Perl Module to encapsulate OMA DRM format for a media type
32  
33 Open Mobile Alliance (OMA) is a standards body founded by telecommunication companies which develops open standards for the mobile phone industry. In order to ensure interoperability across all implementations for Digital Rights Management (DRM), the OMA provides DRM specifications so that content providers, operators and mobile phone manufacturers can easily integrate the DRM solution as smoothly as possible.
34  
35 This module supports the OMA DRM version 1.0 method of sending content to the handset. A device will declare the support for OMA-DRM by including one of the method which is provided by this module:
36  
37 > Forward-lock
38 * Content-Type
39 - application/vnd.oma.drm.message
40 > Combined delivery
41 * Content-Type
42 - application/vnd.oma.drm.message
43 - application/vnd.oma.drm.rights+xml
44 * o-ex:permission
45 - o-dd:display
46 - o-dd:play
47 * o-ex:constraint
48 - o-dd:count
49 - o-dd:interval
50  
51 A detailed document of OMA-DRM can be found at:
52 http://www.openmobilealliance.org/release_program/drm_v1_0.html
53
54 =head1 SYNOPSIS
55  
56 use Net::OmaDrm;
57  
58 my $mydrm = Net::OmaDrm->new($basepath);
59 my $content= $mydrm->genForwardLock($content_name,$content_type);
60  
61 =head1 DESCRIPTION
62  
63 This module will encapulate the media type to a multi-type content with OMA DRM standard.
64  
65 =head1 METHODS
66  
67 =over 4
68  
69 =item new
70  
71 This method is used to create the OmaDrm object.
72  
73 Usage:
74  
75 my $mydrm = Net::OmaDrm->new($basepath);
76  
77 The complete list of arguments is:
78  
79 $basepath : This is the base path for the content.
80  
81 =cut
82  
83 sub new {
84 my $class = shift || undef;
85 return undef if( !defined $class);
86  
87 my $basepath = shift || undef;
88 $basepath.='/' if ($basepath && !($basepath=~/\/$/));
89  
90 return bless { BASE_PATH => $basepath
91 }, $class;
92 }
93  
94 sub readfile {
95 my $class=shift;
96 my $filename=shift;
97 my $body;
98 my $basepath = $class->{BASE_PATH} || '';
99 $filename=$basepath.$filename;
100  
101 open WE, "$filename";
102 my $count=1;
103 my $partbody;
104 while ($count>0) {
105 $count = read WE, $partbody, 1;
106 $body.=$partbody if ($count>0);
107 }
108 close WE;
109 return $body;
110 }
111  
112 sub getHeader {
113 my $class=shift;
114 return "Content-Type: application/vnd.oma.drm.message; boundary=boundary-1\r\n\r\n";
115 }
116  
117 sub getContent {
118 my $class=shift;
119 my $parttype=shift;
120 my $encoding=shift;
121 my $parts=shift;
122  
123 my $body="--boundary-1\r\nContent-Type: $parttype\r\nContent-ID: <45678929547\@ArtOfMobile.bar>\r\n";
124 $body.="Content-Transfer-Encoding: $encoding\r\n\r\n$parts\r\n--boundary-1--\r\n";
125  
126 return $body;
127 }
128  
129 sub getRights {
130 my $class=shift;
131 my $interval=shift;
132 my $count=shift;
133  
134 my $constraint='';
135 $constraint.= "<o-ex:constraint><o-dd:count>$count</o-dd:count></o-ex:constraint>\n" if ($count);
136 $constraint.= "<o-ex:constraint><o-dd:interval>$interval</o-dd:interval></o-ex:constraint>\n" if ($interval);
137  
138 my $body="--boundary-1\r\nContent-Type: application/vnd.oma.drm.rights+xml\r\nContent-Transfer-Encoding: binary\r\n\r\n";
139 $body.=<<__CONTENT__RIGHT__;
140 <o-ex:rights xmlns:o-ex="http://odrl.net/1.1/ODRL-EX" xmlns:o-dd="http://odrl.net/1.1/ODRL-DD" >
141 <o-ex:context>
142 <o-dd:version>1.1</o-dd:version>
143 </o-ex:context>
144 <o-ex:agreement>
145 <o-ex:asset>
146 <o-ex:context>
147 <o-dd:uid>cid:45678929547\@ArtOfMobile.bar</o-dd:uid>
148 </o-ex:context>
149 </o-ex:asset>
150 <o-ex:permission>
151 <o-dd:play>
152 $constraint
153 </o-dd:play>
154 <o-dd:display>
155 $constraint
156 </o-dd:display>
157 </o-ex:permission>
158 </o-ex:agreement>
159 </o-ex:rights>
160  
161 __CONTENT__RIGHT__
162  
163 }
164  
165 =item genForwardLock
166  
167 This method will generate the Forward Lock DRM with an input Media Type.
168  
169 Usage:
170  
171 my $content= $mydrm->genForwardLock($content_name,$content_type);
172  
173 The complete list of arguments is:
174  
175 $content_name : File name of the content.
176 $content_type : Content Type.
177  
178 =cut
179  
180 sub genForwardLock {
181 my $class = shift || undef;
182 return undef if( !defined $class);
183 my $name = shift || undef;
184 return if (!defined $name);
185 my $parttype = shift || undef;
186 return if (!defined $parttype);
187  
188 return $class->genCombinedDelivery($name,$parttype,'','');
189 }
190  
191 =item genCombinedDelivery
192  
193 This method will generate multipart content with rights.
194  
195 Usage:
196  
197 my $content= $mydrm->genCombinedDelivery($content_name,$content_type,$interval,$count);
198  
199 Example:
200  
201 my $content= $mydrm->genCombinedDelivery("image.gif","image/gif",1,"");
202 my $content= $mydrm->genCombinedDelivery("image.gif","image/gif","","P30S");
203  
204 The complete list of arguments is:
205  
206 $content_name : File name of the content.
207 $content_type : Content Type.
208 $interval : Interval that the content can play.
209 $count : Number of time that the content can play.
210  
211 =cut
212  
213 sub genCombinedDelivery {
214 my $class = shift || undef;
215 return undef if( !defined $class);
216 my $name = shift || undef;
217 return if (!defined $name);
218 my $parttype = shift || undef;
219 return if (!defined $parttype);
220 my $interval = shift || undef;
221 my $count = shift || undef;
222  
223 my $body=$class->readfile($name);
224  
225 my $content=$class->getHeader;
226 $content.=$class->getRights($interval,$count) if ($interval || $count);
227 #$content.=$class->getContent($parttype,'Base64',encode_base64($body));
228 $content.=$class->getContent($parttype,'binary',$body);
229 return $content;
230 }
231  
232 =back 4
233  
234 =head1 AUTHOR
235  
236 Christopherus Goo <software@artofmobile.com>
237  
238 =head1 COPYRIGHT
239  
240 Copyright (c) 2007 Christopherus Goo. All rights reserved.
241 This software may be used and modified freely, but I do request that this
242 copyright notice remain attached to the file. You may modify this module
243 as you wish, but if you redistribute a modified version, please attach a
244 note listing the modifications you have made.
245  
246 This software or the author aren't related to OMA in any way.
247  
248 =cut
249  
250 1;
251  
252