1 package GSM::SMS::Spool;
3 # implement spool functions
7 @EXPORT = qw(add_to_spool remove_from_spool create_spoolname read_from_spool);
11 my ($msisdn, $pdu, $dir) = @_;
14 my $filename = create_spoolname($msisdn, $pdu);
15 open F, ">".$dir."/".$filename;
21 sub remove_from_spool {
22 my ($file, $dir) = @_;
24 unlink( $dir."/".$file ) or die $!;
27 sub create_spoolname {
28 my ($msisdn, $pdu) = @_;
31 my $filename = $msisdn . "_" . $$ . time . substr($pdu,-32);
38 my ($file, $count, @arr);
39 # return array with $n==0:<all>:$n messages from spooldir
41 opendir(DIR, $dir) or croak "Could not read directory $dir ($!)";
42 while ( defined($file = readdir(DIR)) && ( ($n && $count<$n) || !$n) ) {
43 next if $file =~ /^\.\.?$/;
45 if ($file =~ /(.+?)_.+/) {
49 open F, $dir . "/" . $file;
54 $msg->{'msisdn'} = $msisdn;
55 $msg->{'pdu'} = $contents;
56 $msg->{'file'} = $file;
72 Implements a simple filesystem spool mechanism to temporarily store incoming and outgoing SMS messages.
76 =head2 add_to_spool( $msisdn, $pdu, $dir )
78 Add a message to the spool dir.
80 =head2 remove_from_spool( $file, $dir )
82 Remove a message from a spool dir.
84 =head2 create_spoolname( $msisdn, $dir )
86 Create the filename for a spool message. Internal function.
88 =head2 read_from_spool( $dir, $n )
90 Read n messages from the spool.
94 Johan Van den Brande <johan@vandenbrande.com>