diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-17 15:12:27 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-17 15:12:27 (GMT) |
commit | f668cb35d19ac92748ffe5d65952ada01ea0e214 (patch) | |
tree | 4d5d773d08715d7728f6cb5b75f940ed26ead4fb /rh-bin/musicgrid.cgi | |
parent | df18aa673e1dd90133b4d5b2381773b017fef729 (diff) |
implemented get command
Diffstat (limited to 'rh-bin/musicgrid.cgi')
-rwxr-xr-x | rh-bin/musicgrid.cgi | 90 |
1 files changed, 65 insertions, 25 deletions
diff --git a/rh-bin/musicgrid.cgi b/rh-bin/musicgrid.cgi index 1ec5313..aa823aa 100755 --- a/rh-bin/musicgrid.cgi +++ b/rh-bin/musicgrid.cgi @@ -25,6 +25,7 @@ use strict; use CGI; use POSIX; use XML::Quote; +use lib "../../rhrdlibs/lib/"; use RHRD::rddb; my $status = 'ERROR'; @@ -33,40 +34,79 @@ my $responsecode = 500; my @clocks = (); my $q = CGI->new; -my $username = $q->param('LOGIN_NAME'); -my $token = $q->param('PASSWORD'); -my $command = $q->param('PASSWORD'); +my $username = ""; #$q->param('LOGIN_NAME'); +my $token = ""; #$q->param('PASSWORD'); +my $cmd = "get"; #$q->param('COMMAND'); -if(!defined $command +sub get_clocks +{ + my ($ctx) = @_; -(my $ctx, $status, $errorstring) = RHRD::rddb::init(); -if(defined $ctx) { - my $result = 1; -# ($result, $status, $errorstring) = RHRD::rddb::check_token($ctx, $username, $token); - if($result == 1) { - # TODO: check if user is allowed to read/edit music pools - # TODO: dispatch command get,set - $responsecode = 200; - @clocks = RHRD::rddb::get_musicpools_clocks($ctx); - if(!defined $clocks[0] && defined $clocks[1]) { + @clocks = RHRD::rddb::get_musicpools_clocks($ctx); + if(!defined $clocks[0] && defined $clocks[1]) { + return 500, $clocks[1] . ": " . $clocks[2]; + } + + return 200, "OK"; +} + +sub set_clock +{ + my ($ctx) = @_; + + my $dow = $q->param('DOW'); + my $hour = $q->param('HOUR'); + my $shortname = $q->param('NAME'); + + if(!defined $dow) { + return 400 ,"mandatory field DOW is missing"; + } elsif(!defined $hour) { + return 400, "mandatory field HOUR is missing"; + } elsif(!defined $shortname) { + return 400, "mandatory field NAME is missing"; + } + + return 500, "not yet implemented"; +} + +if(!defined $username) { + $responsecode = 400; + $errorstring = "mandatory field LOGIN_NAME is missing"; +} elsif(!defined $token) { + $responsecode = 400; + $errorstring = "mandatory field PASSWORD is missing"; +} elsif(!defined $cmd) { + $responsecode = 400; + $errorstring = "mandatory field COMMAND is missing"; +} else { + (my $ctx, $status, $errorstring) = RHRD::rddb::init(); + if(defined $ctx) { + my $result = 1; # (my $result, $status, $errorstring) = RHRD::rddb::check_token($ctx, $username, $token); + if($result == 1) { + # TODO: check if user is allowed to read/edit music pools + if($cmd eq "get") { + ($responsecode, $errorstring) = get_clocks($ctx); + } + elsif($cmd eq "set") { + ($responsecode, $errorstring) = set_clock($ctx); + } + else { + $responsecode = 400; + $errorstring = "command '$cmd' is unknown"; + } + } elsif($result == 0) { + $responsecode = 401; + } else { $responsecode = 500; - $status = $clocks[1]; - $errorstring = $clocks[2]; } - } elsif($result == 0) { - $responsecode = 401; - } else { - $responsecode = 500; + RHRD::rddb::destroy($ctx); } - RHRD::rddb::destroy($ctx); } - print "Content-type: application/xml; charset=UTF-8\n"; print "Status: $responsecode\n\n"; -# TODO: dispatch command get,set -if($responsecode != 200) { +if($cmd eq "set" || $responsecode != 200) { print "<RDWebResult>\n"; print " <ResponseCode>" . xml_quote($responsecode) . "</ResponseCode>\n"; print " <ErrorString>" . xml_quote($errorstring) . "</ErrorString>\n"; @@ -75,7 +115,7 @@ if($responsecode != 200) { print "<grid>\n"; for my $href (@clocks) { print " <clock dow=\"" . xml_quote($href->{'DOW'}) . "\" hour=\"" . xml_quote($href->{'HOUR'}) . "\">\n"; - print " <name>" . xml_quote($href->{'NAME'}) . "</name>\n"; + print " <name>" . xml_quote($href->{'SHORTNAME'}) . "</name>\n"; print " <color>" . xml_quote($href->{'COLOR'}) . "</color>\n"; print " <title>" . xml_quote($href->{'TITLE'}) . "</title>\n"; print " </clock>\n"; |