#! /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();