:pserver:anonymous@intra.tektonica.com:/opt/cvs - gsmperl - Fri Dec 21 07:37 CET...
[gsmperl.git] / GSM / SMS / Transport / XmlRpc.pm
1 package GSM::SMS::Transport::XmlRpc;
2
3 #
4 # HTTP for Remote Serial modem 
5 #
6
7 use GSM::SMS::Transport::Transport;
8 @ISA = qw(GSM::SMS::Transport::Transport);
9
10 $VERSION = '0.1';
11
12 # All the parameters I need to run
13 my @config_vars = qw( 
14         name
15         match
16         spoolout
17                                         );
18
19 # Send a (PDU encoded) message  
20 sub send        {
21         my ($self, $msisdn, $pdu) = @_;
22
23         # print "send...";
24         $self->_add_to_spool( $msisdn, $pdu, $self->{cfg}->{"spoolout"} );
25         # print "\n";
26         return 0;
27 };
28
29 # Receive a PDU encoded message
30 #       $ is a ref to a PDU string
31 #       return
32 #       0 if PDU received
33 #       -1 if no message pending  
34 sub receive     {
35         my ($self, $pduref) = @_;
36
37         return -1;
38 };      
39  
40
41 # Close
42 sub close        {
43         my ($self) = @_;
44 }
45
46 # A ping command .. just return an informative string on success
47 sub ping {
48         my ($self) = @_;
49
50         return "Pong.. XmlRpc  transport ok";
51 }
52
53
54 # give out the needed config paramters
55 sub get_config_parameters {
56         my ($self) = @_;
57
58         return @config_vars;
59 }
60
61 # Do we have a valid route for this msisdn
62 sub has_valid_route {
63         my ($self, $msisdn) = @_;
64         
65         # print "route";
66
67         foreach my $route ( split /,/, $self->{cfg}->{"match"} ) {
68                 # print "($route)";
69                 return -1 if $msisdn =~ /$route/;
70         }
71         return 0;
72 }
73
74 #####################################################################
75 # transport specific
76 #####################################################################
77 sub _add_to_spool {
78         my ($self, $msisdn, $pdu, $dir) = @_;
79         local (*F);
80         
81         my $filename = $self->_create_spoolname($msisdn, $pdu);
82
83         # print ">".$dir."/".$filename."\n";
84         
85         open F, ">".$dir."/".$filename;
86         print F $pdu;
87         close F;
88 }
89
90
91 sub _remove_from_spool {
92         my ($self, $msisdn, $pdu, $dir) = @_;
93         
94         my $filename =  $self->_create_spoolname($msisdn, $pdu);
95         unlink( $dir."/".$filename );
96 }
97
98 sub _create_spoolname {
99         my ($self, $msisdn, $pdu) = @_;
100         
101         $msisdn =~ s/^\+//;
102         my $filename = $msisdn . "_" . $$ . time . substr($pdu,-32);
103         return $filename;
104 }
105
106 1;