12 my($pg_conn,$pg_result);
14 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);
21 $$ref=($$ref ? "'t'" : "'f'");
28 $$ref=(defined($$ref) ? "'$$ref'" : "NULL");
32 Getopt::Long::Configure("bundling");
36 die() if (!GetOptions(
38 "sendtext" ,\$opt_sendtext,
39 "sendringtone" ,\$opt_sendringtone,
40 "sendoplogo" ,\$opt_sendoplogo,
41 "sendcalleridlogo" ,\$opt_sendcalleridlogo,
42 "fromfile!" ,\$opt_fromfile,
43 "netcode=s" ,\$opt_netcode,
44 "longtext" ,\$opt_longtext,
45 "longudh" ,\$opt_longudh,
46 "udh!" ,\$opt_udhpresent,
47 "8|eightbit" ,\$opt_eightbit,
51 $type="ringtone" if $opt_sendringtone;
52 $type="oplogo" if $opt_sendoplogo;
53 $type="calleridlogo" if $opt_sendcalleridlogo;
54 $type="text" if !defined $type;
56 $opt_eightbit=1 if $type ne "text";
58 die "Argument conflict" if 0
59 || ($opt_longtext && $opt_longudh)
60 || (1 < defined($opt_sendtext)+defined($opt_sendringtone)+defined($opt_sendoplogo)+defined($opt_sendcalleridlogo))
61 || ($type ne "text") && $opt_udhpresent
64 die "Destination number required" if !@ARGV;
65 my($destination)=shift @ARGV;
68 die "Filename on commandline required" if $opt_fromfile && !@ARGV;
69 my($text)=($opt_fromfile ? shift(@ARGV) : <STDIN>);
70 $text="" if !defined($text);
71 die "Message too long" if !$opt_longtext && !$opt_longudh && 160<length($text);
73 my($hexencode)=!$opt_fromfile; #filenames are not hexencoded
77 $hextext.=sprintf("%02X",ord($1)) while ($text=~s/^(.)//s);
83 die "Excessive arguments: @ARGV" if @ARGV;
85 $pg_conn=Pg::connectdb($opt_db);
86 die $pg_conn->errorMessage() unless PGRES_CONNECTION_OK eq $pg_conn->status;
88 enbool(\$opt_fromfile);
89 ennull(\$opt_netcode);
90 enbool(\$opt_udhpresent);
91 $opt_longudh=!$opt_longtext;
92 enbool(\$opt_longudh);
93 enbool(\$opt_eightbit);
97 $pg_result=$pg_conn->exec(
98 "INSERT INTO outbox (number,text,hexencode,type,fromfile,netcode,udhpresent,longuseudh,eightbit,smsc)"
99 ." VALUES ('$destination','$hextext',$hexencode,'$type',$opt_fromfile,$opt_netcode,$opt_udhpresent,$opt_longudh,$opt_eightbit,$opt_smsc);");
100 die $pg_conn->errorMessage() unless PGRES_COMMAND_OK eq $pg_result->resultStatus();