Found in "gnokii-working" directory, some November-patches version
[gnokii.git] / smsd / sms-sendsms
diff --git a/smsd/sms-sendsms b/smsd/sms-sendsms
new file mode 100755 (executable)
index 0000000..ee41076
--- /dev/null
@@ -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) : <STDIN>);
+$text="" if !defined($text);
+die "Message too long" if !$opt_longtext && !$opt_longudh && 160<length($text);
+
+my($hexencode)=!$opt_fromfile; #filenames are not hexencoded
+my($hextext);
+if ($hexencode) {
+       $hextext="";
+       $hextext.=sprintf("%02X",ord($1)) while ($text=~s/^(.)//s);
+       }
+else {
+       $hextext=$text;
+       }
+
+die "Excessive arguments: @ARGV" if @ARGV;
+
+$pg_conn=Pg::connectdb($opt_db);
+die $pg_conn->errorMessage() 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();