X-Git-Url: http://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=smsd%2Fsms-sendsms;fp=smsd%2Fsms-sendsms;h=ee4107608be3a7be60ec2c2cb5f49513bb4e56bc;hp=0000000000000000000000000000000000000000;hb=49dd905279a8e62936e3713510ab0fd738e20ecb;hpb=2f2703c9133032c12671ca5c77ae626b8fb178d4 diff --git a/smsd/sms-sendsms b/smsd/sms-sendsms new file mode 100755 index 0000000..ee41076 --- /dev/null +++ b/smsd/sms-sendsms @@ -0,0 +1,100 @@ +#! /usr/bin/perl +# +# $Id$ + +use strict; +use warnings; + +use Getopt::Long; +use Pg; + + +my($pg_conn,$pg_result); + +my($opt_db,$opt_sendtext,$opt_sendringtone,$opt_sendoplogo,$opt_sendcalleridlogo,$opt_fromfile,$opt_netcode,$opt_longtext,$opt_longudh,$opt_udhpresent,$opt_eightbit,$opt_smsc); + + +sub enbool +{ +my($ref)=@_; + + $$ref=($$ref ? "'t'" : "'f'"); +} + +sub ennull +{ +my($ref)=@_; + + $$ref=(defined($$ref) ? "'$$ref'" : "NULL"); +} + + +Getopt::Long::Configure("bundling"); + +$opt_db="dbname=sms"; + +die() if (!GetOptions( + "d|db" ,\$opt_db, + "sendtext" ,\$opt_sendtext, + "sendringtone" ,\$opt_sendringtone, + "sendoplogo" ,\$opt_sendoplogo, + "sendcalleridlogo" ,\$opt_sendcalleridlogo, + "fromfile!" ,\$opt_fromfile, + "netcode=s" ,\$opt_netcode, + "longtext" ,\$opt_longtext, + "longudh" ,\$opt_longudh, + "udh!" ,\$opt_udhpresent, + "8|eightbit" ,\$opt_eightbit, + "smsc=s" ,\$opt_smsc, + )); +my($type); +$type="ringtone" if $opt_sendringtone; +$type="oplogo" if $opt_sendoplogo; +$type="calleridlogo" if $opt_sendcalleridlogo; +$type="text" if !defined $type; + +$opt_eightbit=1 if $type ne "text"; + +die "Argument conflict" if 0 + || ($opt_longtext && $opt_longudh) + || (1 < defined($opt_sendtext)+defined($opt_sendringtone)+defined($opt_sendoplogo)+defined($opt_sendcalleridlogo)) + || ($type ne "text") && $opt_udhpresent + ; + +die "Destination number required" if !@ARGV; +my($destination)=shift @ARGV; + +undef $/; +die "Filename on commandline required" if $opt_fromfile && !@ARGV; +my($text)=($opt_fromfile ? shift(@ARGV) : ); +$text="" if !defined($text); +die "Message too long" if !$opt_longtext && !$opt_longudh && 160errorMessage() unless PGRES_CONNECTION_OK eq $pg_conn->status; + +enbool(\$opt_fromfile); +ennull(\$opt_netcode); +enbool(\$opt_udhpresent); +$opt_longudh=!$opt_longtext; +enbool(\$opt_longudh); +enbool(\$opt_eightbit); +ennull(\$opt_smsc); +enbool(\$hexencode); + +$pg_result=$pg_conn->exec( + "INSERT INTO outbox (number,text,hexencode,type,fromfile,netcode,udhpresent,longuseudh,eightbit,smsc)" + ." VALUES ('$destination','$hextext',$hexencode,'$type',$opt_fromfile,$opt_netcode,$opt_udhpresent,$opt_longudh,$opt_eightbit,$opt_smsc);"); +die $pg_conn->errorMessage() unless PGRES_COMMAND_OK eq $pg_result->resultStatus();