[Bio] / FigKernelPackages / ServerThing.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/ServerThing.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.61, Wed Jan 26 15:32:08 2011 UTC revision 1.70, Thu Mar 17 18:40:41 2011 UTC
# Line 55  Line 55 
55          if ($@) {          if ($@) {
56              SendError($@, "Could not start server.");              SendError($@, "Could not start server.");
57          } else {          } else {
58              # No error, so now we can process the request.              # No error, so now we can process the request. First, get the method list.
59                my $methods = $serverThing->methods();
60                # Store it in the object so we can use it to validate methods.
61                my %methodHash = map { $_ => 1 } @$methods;
62                $serverThing->{methods} = \%methodHash;
63              my $cgi;              my $cgi;
64              if (! defined $key) {              if (! defined $key) {
65                  # No tracing key, so presume we're a web service. Check for Fast CGI.                  # No tracing key, so presume we're a web service. Check for Fast CGI.
66                  if ($ENV{REQUEST_METHOD} eq '') {                  if ($ENV{REQUEST_METHOD} eq '') {
67                      # Count the number of requests.                      # Count the number of requests.
68                      my $requests = 0;                      my $requests = 0;
69                      Trace("Starting Fast CGI loop.") if T(3);                      # warn "Starting fast CGI loop.\n"; ##HACK Trace("Starting Fast CGI loop.") if T(3);
70                      # Loop through the fast CGI requests. If we have request throttling,                      # Loop through the fast CGI requests. If we have request throttling,
71                      # we exit after a maximum number of requests has been exceeded.                      # we exit after a maximum number of requests has been exceeded.
72                      require CGI::Fast;                      require CGI::Fast;
73                      while ((MAX_REQUESTS == 0 || ++$requests < MAX_REQUESTS) &&                      while ((MAX_REQUESTS == 0 || ++$requests < MAX_REQUESTS) &&
74                             ($cgi = new CGI::Fast())) {                             ($cgi = new CGI::Fast())) {
75                            my $function = $cgi->param('function') || "<non-functional>"; #HACK
76                            # warn "Function request is $function in task $$.\n"; ##HACK
77                          RunRequest($cgi, $serverThing);                          RunRequest($cgi, $serverThing);
78                          Trace("Request $requests complete in task $$.") if T(3);                          # warn "$requests requests complete in fast CGI task $$.\n"; ##HACK Trace("Request $requests complete in task $$.") if T(3);
79                      }                      }
80                      Trace("Terminating FastCGI task $$ after $requests requests.") if T(2);                      # warn "Terminating FastCGI task $$ after $requests requests.\n"; ##HACK Trace("Terminating FastCGI task $$ after $requests requests.") if T(2);
81                  } else {                  } else {
82                      # Here we have a normal web service (non-Fast).                      # Here we have a normal web service (non-Fast).
83                      my $cgi = CGI->new();                      my $cgi = CGI->new();
# Line 1031  Line 1037 
1037    
1038  =head3 RunRequest  =head3 RunRequest
1039    
1040      ServerThing::RunRequest($cgi, $serverName);      ServerThing::RunRequest($cgi, $serverThing, $docURL);
1041    
1042  Run a request from the specified server using the incoming CGI parameter  Run a request from the specified server using the incoming CGI parameter
1043  object for the parameters.  object for the parameters.
# Line 1083  Line 1089 
1089    
1090  Server object against which to run the request.  Server object against which to run the request.
1091    
1092    =item docURL
1093    
1094    URL to use for POD documentation requests.
1095    
1096  =back  =back
1097    
1098  =cut  =cut
# Line 1090  Line 1100 
1100  sub RunRequest {  sub RunRequest {
1101      # Get the parameters.      # Get the parameters.
1102      my ($cgi, $serverThing, $docURL) = @_;      my ($cgi, $serverThing, $docURL) = @_;
1103        # Make the CGI object available to the server.
1104        $serverThing->{cgi} = $cgi;
1105      # Determine the request type.      # Determine the request type.
1106      my $module = $cgi->param('pod');      my $module = $cgi->param('pod');
1107      if ($module) {      if ($module) {
# Line 1124  Line 1136 
1136          my $function = $cgi->param('function') || "";          my $function = $cgi->param('function') || "";
1137          Trace("Server function for task $$ is $function.") if T(3);          Trace("Server function for task $$ is $function.") if T(3);
1138          # Insure the function name is valid.          # Insure the function name is valid.
1139          Die("Invalid function name.")          if ($function ne "methods" && exists $serverThing->{methods} && ! $serverThing->{methods}{$function}) {
1140              if $function =~ /\W/;              SendError("Invalid function name.", "$function not found.")
1141            } else {
1142          # Determing the encoding scheme. The default is YAML.          # Determing the encoding scheme. The default is YAML.
1143          my $encoding = $cgi->param('encoding') || 'yaml';          my $encoding = $cgi->param('encoding') || 'yaml';
1144          # Optional callback for json encoded documents          # Optional callback for json encoded documents
# Line 1180  Line 1193 
1193                      print $cgi->header(-type => 'text/javascript');                      print $cgi->header(-type => 'text/javascript');
1194                  }                  }
1195                  # The nature of the output depends on the encoding type.                  # The nature of the output depends on the encoding type.
1196                        eval {
1197                  my $string;                  my $string;
1198                  if ($encoding eq 'yaml') {                  if ($encoding eq 'yaml') {
1199                      $string = YAML::Dump($document);                      $string = YAML::Dump($document);
# Line 1190  Line 1204 
1204                  }                  }
1205                  print $string;                  print $string;
1206                  MemTrace(length($string) . " bytes returned from $function by task $$.") if T(Memory => 3);                  MemTrace(length($string) . " bytes returned from $function by task $$.") if T(Memory => 3);
1207                        };
1208                        if ($@) {
1209                            SendError($@, "Error encoding result.");
1210                            Trace("Error encoding result: $@") if T(0);
1211                        }
1212              }              }
1213          }          }
1214          # Stop the timer.          # Stop the timer.
# Line 1197  Line 1216 
1216          Trace("Function $function executed in $duration seconds by task $$.") if T(2);          Trace("Function $function executed in $duration seconds by task $$.") if T(2);
1217      }      }
1218  }  }
1219    }
1220    
1221  =head3 CreateFile  =head3 CreateFile
1222    
# Line 1445  Line 1465 
1465  }  }
1466    
1467    
1468    =head3 Log
1469    
1470        Log($msg);
1471    
1472    Write a message to the log. This is a temporary hack until we can figure out how to get
1473    normal tracing and error logging working.
1474    
1475    =over 4
1476    
1477    =item msg
1478    
1479    Message to write. It will be appended to the C<servers.log> file in the FIG temporary directory.
1480    
1481    =back
1482    
1483    =cut
1484    
1485    sub Log {
1486        # Get the parameters.
1487        my ($msg) = @_;
1488        # Open the log file for appending.
1489        open(my $oh, ">>$FIG_Config::temp/servers.log") || Confess("Log error: $!");
1490        print $oh "$msg\n";
1491        close $oh;
1492    }
1493    
1494  1;  1;

Legend:
Removed from v.1.61  
changed lines
  Added in v.1.70

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3