#!/usr/bin/perl # # faceClient # CGI interface between local voiceServer and Java face # applets/applications. # Copyright (C) 2002 Brian Rudy (brudyNO@SPAMpraecogito.com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # ## Revision History # # 0.03 9-20-2002 # Quick update for mod_perl support. # # 0.02 5-21-2002 # Updated to support cue 'stack' in voiceServer 0.03 # # 0.01 # First working version (polling mode) # # Requires # URI::Escape # IPC::Shareable # CGI::Request #use strict; use IPC::Shareable; use CGI::Request; use Apache::Constants ':common'; # Debugging stuff $IPC::Shareable::Debug = 1; # Simple interface: (combines SendHeaders, new and import_names) #my $req = GetRequest($pkg); # Full Interface: # We only need to output info, so this isn't required. my $req = new CGI::Request; # fetch and parse request my $faceglue = 'facedata'; my %options = ( 'key' => 'face', 'create' => 0, 'exclusive' => 0, 'mode' => 0644, 'destroy' => 0, ); # Print out a content-type for HTTP/1.0 compatibility #print "Content-type: text/html\n\n"; tie(@faceinfo, IPC::Shareable, $faceglue, { %options }) or die "$$: tie failed $!\n"; # sanitize input request from applet $OK_CHARS='0-9'; $reqstring = $req->param('give'); $reqstring =~ s/[^$OK_CHARS]/ /go; if ($req->param('give') eq 'finger') { oldway(); } else { if (($reqstring >= 0) && ($reqstring <= 9999999999)) { newway(); } } # faceServer has shut down #print "Shutdown\n"; exit; sub oldway { print $faceinfo[$#faceinfo]{stringfinger} . "\n"; } sub newway { if ($faceinfo[$#faceinfo]{timestamp} ne $reqstring) { if ($reqstring == 0) { # Client just initialized, give them the last cue on the stack. print $faceinfo[$#faceinfo]{timestamp} . " " . $faceinfo[$#faceinfo]{stringfinger} . " " . $faceinfo[$#faceinfo]{emotion} . "\n"; exit; } for $cueindex (0 .. $#faceinfo) { if ($faceinfo[$cueindex]{timestamp} eq $reqstring) { print $faceinfo[$cueindex + 1]{timestamp} . " " . $faceinfo[$cueindex + 1]{stringfinger} . " " . $faceinfo[$cueindex + 1]{emotion} . "\n"; exit; } } # just in case we don't have the timestamp requested print $faceinfo[$#faceinfo]{timestamp} . " " . $faceinfo[$#faceinfo]{stringfinger} . " " . $faceinfo[$#faceinfo]{emotion} . "\n"; } else { # the client is up to date print "0\n"; } }