diff options
author | 2007-12-30 17:00:57 +0000 | |
---|---|---|
committer | 2007-12-30 17:00:57 +0000 | |
commit | 818aeed693588286d34eed62bebdfa8833f36c86 (patch) | |
tree | d05cf9aa2b95daeeb9ffef80f203e1bbe4eaa488 /server | |
parent | adding query for get_jobs from old server. (diff) | |
download | scire-818aeed693588286d34eed62bebdfa8833f36c86.tar.gz scire-818aeed693588286d34eed62bebdfa8833f36c86.tar.bz2 scire-818aeed693588286d34eed62bebdfa8833f36c86.zip |
add parse_command() and modify existing code to use it
svn path=/branches/new-fu/; revision=283
Diffstat (limited to 'server')
-rwxr-xr-x | server/scireserver.pl | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/server/scireserver.pl b/server/scireserver.pl index 6dd9a8c..2d5f11d 100755 --- a/server/scireserver.pl +++ b/server/scireserver.pl @@ -31,21 +31,23 @@ debug("Connecting to $connect_string"); # or die "Could not connect to database: $DBI::errstr"; while(<>) { - chomp( my $line = $_); - debug("DEBUG: line is: $line"); - if($line =~ /^QUIT$/) { + my ($command, @args) = parse_command($_); +# chomp( my $line = $_); +# debug("DEBUG: line is: $line"); + + if($command eq "QUIT") { print "OK\n"; exit; } - if ($line =~ /^REGISTER "(.+?)" "(.+)"$/) { - my ($mac,$ip) = ($1, $2); + if($command eq "REGISTER") { + my ($mac,$ip) = @args; register_client($mac, $ip); next; #End switch here. You can go no further. } - if($line =~ /^IDENTIFY (.+)$/) { - my $fingerprint = $1; + if($command eq "IDENTIFY") { + my $fingerprint = $args[0]; identify_client($fingerprint); next; #End switch here. You can go no further. } @@ -54,20 +56,20 @@ while(<>) { next; } - if ($line =~ /^GET_JOBS(.*)$/) { - my @existing_jobs = split(/ /,$1) if defined($1); + if ($command eq "GET_JOBS") { + my @existing_jobs = @args; get_jobs(@existing_jobs); - - } elsif ($line =~ /^GET_JOB (.+)$/) { - my $job = $1; + + } elsif ($command eq "GET_JOB") { + my $job = $args[0]; get_job($job); - } elsif ($line =~ /^SET_JOB_STATUS (.+?) "(.+)"$/) { - my ($jobid,$status) = ($1, $2); + } elsif ($command eq "SET_JOB_STATUS") { + my ($jobid,$status) = @args; set_job_status($jobid,$status); } else { - print "ERROR This command $line, is unknown. Please try again.\n"; + print "ERROR The command $command is unknown. Please try again.\n"; } } @@ -194,3 +196,14 @@ sub set_job_status { my ($jobid,$status) = @_; #Validate your inputs! } + +sub parse_command { + my $line = shift; + chomp $line; + my @parts = split / (?!(?:[^" ]|[^"] [^"])+")/, $line; + for(0..$#parts) { + $parts[$_] =~ s/(^"|"$)//g; + $parts[$_] =~ s/\\"/"/g; + } + return @parts; +} |