summaryrefslogtreecommitdiff
path: root/cgi-bin
diff options
context:
space:
mode:
authorjules <jules@okfoc.us>2014-01-13 12:30:03 -0500
committerjules <jules@okfoc.us>2014-01-13 12:30:03 -0500
commit94e950d6c0d1930f8f30240cac9b10c56e26c4d9 (patch)
treea57b6fdec14d56abc01a3753ad22fc2a88791e85 /cgi-bin
parent9d37bced7dd4873f32f1374d2914e27bb984c422 (diff)
single json call
Diffstat (limited to 'cgi-bin')
-rwxr-xr-xcgi-bin/view40
1 files changed, 20 insertions, 20 deletions
diff --git a/cgi-bin/view b/cgi-bin/view
index 3994117..e4f4f2d 100755
--- a/cgi-bin/view
+++ b/cgi-bin/view
@@ -15,13 +15,25 @@ my $sql_passwd = "gTYgT&M6q";
sub not_specified_error{
-my $param = shift;
- print $json->pretty->encode ({ ERROR => sprintf("Function parameter %s not defined", $param ) });
+ my $param = shift;
+ my $callback = shift;
+ response({ ERROR => sprintf("Function parameter %s not defined", $param ) }, $callback);
exit(1);
}
+sub response{
+ my $res = $json->pretty->encode(shift);
+ my $callback = shift;
+ if (defined $callback){
+ print $callback + "(" + $res + ")";
+ }
+ else {
+ print $res;
+ }
+}
our $dbh = DBI->connect("DBI:mysql:$sql_dbname", $sql_username, $sql_passwd)
or die "Couldn't connect to database: " . DBI->errstr;
+
sub mysql_retrieve{
my ($statement, @args) = @_;
my $sth = $dbh->prepare($statement)
@@ -37,11 +49,11 @@ sub mysql_retrieve{
push(@rows, $data);
}
if ($sth->rows == 0) {
- return $json->pretty->encode ({ ERROR => "No ids matched `$data_id'.\n\n" });
+ return { ERROR => "No ids matched `$data_id'.\n\n" };
}
$sth->finish;
- return $json->pretty->encode({ SUCCESS => 1, data => \@rows });
+ return { SUCCESS => 1, data => \@rows };
}
sub main{
@@ -56,7 +68,7 @@ sub main{
my $callback = $params->{'callback'} || undef
unless(defined $params->{f}){
- not_specified_error("f");
+ not_specified_error("f", $callback);
}
my $res;
@@ -90,24 +102,12 @@ sub main{
when(/originals/){
$res = mysql_retrieve('select shaders.* from shader_ids cross join shaders on shader_ids.id = shaders.shader_id');
}
- default {
- if (defined $callback) {
- print $callback + "(";
- print $json->pretty->encode ({ ERROR => "Function parameter f improperly defined"});
- print ")";
- }
- else {
- print $json->pretty->encode ({ ERROR => "Function parameter f improperly defined"});
- }
+ default {
+ response({ ERROR => "Function parameter f improperly defined"}, $callback);
exit(1);
};
}
- if (defined $callback) {
- print $callback + "(" + $res + ")";
- }
- else {
- print $res;
- }
+ response($res, $callback);
}
main();
exit(0);