File Coverage

blib/lib/WWW/SMS/SFR.pm
Criterion Covered Total %
statement 18 55 32.7
branch 0 8 0.0
condition 0 5 0.0
subroutine 6 8 75.0
pod 0 1 0.0
total 24 77 31.1


line stmt bran cond sub pod time code
1             #
2             # SFR.pm for WWW::SMS
3             #
4             # Copyright (C) 2001 Cedric Bouvier (cédric)
5             # Copyright (C) 2000,2001 Julien Gaulmin (julien23)
6             #
7             # This program is free software; you can redistribute it and/or modify
8             # it under the terms of the GNU General Public License as published by
9             # the Free Software Foundation; either version 2 of the License, or
10             # (at your option) any later version.
11             #
12             # This program is distributed in the hope that it will be useful,
13             # but WITHOUT ANY WARRANTY; without even the implied warranty of
14             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15             # GNU General Public License for more details.
16             #
17             # You should have received a copy of the GNU General Public License
18             # along with this program; if not, write to the Free Software
19             # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20             # USA or look at http://www.gnu.org/copyleft/gpl.html
21             #
22             # Contributors :
23             # - Cédric Bouvier (bwana147)
24             # - Julien Gaulmin (julien23)
25             #
26             # Change Log :
27             # - v1.1 (bwana147) : first version adapted from sms4nothing
28              
29             package WWW::SMS::SFR;
30 1     1   629 use strict;
  1         2  
  1         45  
31              
32 1     1   5 use Telephone::Number;
  1         2  
  1         24  
33 1     1   5 use vars qw/ @ISA @EXPORT @EXPORT_OK @PREFIXES $VERSION /;
  1         2  
  1         184  
34             require Exporter;
35             @ISA = qw(Exporter);
36             @EXPORT = qw();
37             @EXPORT_OK = qw(@PREFIXES _send MAXLENGTH);
38             @PREFIXES = (Telephone::Number->new('33', [
39             qw(60[39] 61\d 62[0-3] 655)
40             ], undef));
41              
42             $VERSION = '1.02';
43             sub MAXLENGTH () {640}
44 1     1   5 use constant LANGUAGE => 'FR';
  1         2  
  1         69  
45 1     1   5 use constant NETWORK => 'smsc1';
  1         2  
  1         38  
46 1     1   5 use constant VALIDITY_PERIOD => '72';
  1         2  
  1         707  
47              
48              
49             sub hnd_error {
50 0     0 0   $WWW::SMS::Error = "Failed at step $_[0] of module SFR.pm\n";
51 0           return 0;
52             }
53              
54             sub _send {
55 0     0     my $self = shift;
56              
57 0           require HTTP::Cookies;
58             #require Time::localtime;
59             #require Time::Local;
60 0           require Date::Manip;
61 0           require LWP::UserAgent;
62 0           require HTTP::Request;
63              
64 0           import Date::Manip qw/ ParseDate UnixDate /;
65              
66 0           my $step = 1;
67              
68 0           my $ua = LWP::UserAgent->new;
69 0   0       my $cookie_jar = HTTP::Cookies->new(
70             file => ($self->{cookie_jar} || "lwpcookie.txt"),
71             autosave => 1
72             );
73 0           $ua->agent('Mozilla/5.0');
74 0 0         $ua->proxy('http', $self->{proxy}) if ($self->{proxy});
75 0           $ua->cookie_jar($cookie_jar);
76              
77 0 0         $self->{smstext} = substr($self->{smstext}, 0, MAXLENGTH - 1)
78             if (length($self->{smstext})>MAXLENGTH);
79              
80             my (
81 0   0       $delivery_year,
82             $delivery_month,
83             $delivery_date,
84             $delivery_hour,
85             $delivery_min,
86             $delivery_time,
87             ) = UnixDate((ParseDate($self->{date}) || ParseDate('now')), qw/%Y %m %d %H %M %s/);
88              
89             # SFR compatible
90 0           $delivery_month--; # january is 0
91 0           $delivery_time .= '000'; # strange sfr epoch format
92              
93             # Create a GET request in order to get the javasession cookie from SFR
94 0           my $req = new HTTP::Request;
95 0           $req->method('GET');
96 0           $req->uri('http://195.115.48.10/servlet/ProxyFirst?' .
97             'redirect=SMS&LANGUAGE=FR&PAGE=launch');
98              
99             # Pass request from the user agent and get a response back
100 0           my $res = $ua->request($req);
101 0           $cookie_jar->add_cookie_header($req);
102              
103             # Check the outcome of the response
104 0 0         return &hnd_error($step) unless $res->is_success();
105 0           $step++;
106              
107             # Create a POST request to send the message
108 0           $req = new HTTP::Request;
109 0           $req->method('POST');
110 0           $req->uri('http://195.115.48.10/servlet/ProxySecond?redirect=SMS');
111 0           $req->referer('http://195.115.48.10/servlet/SMSServlet_KZ1OS9?' .
112             'redirect=SMS&LANGUAGE=FR&PAGE=launch');
113 0           $req->content_type('application/x-www-form-urlencoded');
114              
115 0           my %content = (
116             NOTIFICATION_FLAG => 'false',
117             LANGUAGE => LANGUAGE,
118             NETWORK => NETWORK,
119             DELIVERY_TIME => $delivery_time,
120             DELIVERY_DATE => $delivery_date,
121             DELIVERY_MONTH => $delivery_month,
122             DELIVERY_YEAR => $delivery_year,
123             DELIVERY_HOUR => $delivery_hour,
124             DELIVERY_MIN => $delivery_min,
125             SENDER => '',
126             NOTIFICATION_ADDRESS => '',
127             caracteres => length($self->{smstext}),
128             SHORT_MESSAGE => $self->{smstext},
129             VALIDITY_PERIOD => VALIDITY_PERIOD,
130             RECIPIENT => '0'.$self->{prefix}.$self->{telnum},
131             );
132 0           $req->content(join '&' => map { "$_=$content{$_}" } keys %content);
  0            
133              
134             # Pass request from the user agent and get a response back
135 0           $res = $ua->request($req);
136 0           $cookie_jar->add_cookie_header($req);
137              
138             # Check the outcome of the response
139 0 0         return &hnd_error($step) unless $res->is_success();
140 0           1;
141             }
142              
143             1;