[system] / trunk / webwork2 / lib / WebworkWebservice.pm Repository:
ViewVC logotype

View of /trunk/webwork2/lib/WebworkWebservice.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3072 - (download) (as text) (annotate)
Sat Jan 1 22:34:43 2005 UTC (8 years, 4 months ago) by gage
File size: 7948 byte(s)
Changes made to simplify the implementation of XMLRPC access to
the functionality of WeBWorK.

There is still a problem with making sure that the proper warning
mechanism is passed into the problem rendering compartment.
The proper permissions for creating directories also does not
get transmitted properly.

I would like to change the way that the defineEnvirVars subroutine is
passed into the Local.pm object.  I'd like to either pass the
environment as a hash or explicitly pass a reference to define
EnvirVars rather than inherit it from PG.  In particular I'd like
to be able to define environment variables directly in RenderProblem.pm
instead of faking it by defining fake problem objects.

    1 
    2 # FIXME need way to find the basic libraries and such.
    3 
    4 
    5 BEGIN {
    6     $main::VERSION = "2.1";
    7     my $webwork_directory = $ENV{WEBWORK_ROOT};
    8 
    9   eval "use lib '$webwork_directory/lib'"; die $@ if $@;
   10   eval "use WeBWorK::CourseEnvironment"; die $@ if $@;
   11   my $ce = new WeBWorK::CourseEnvironment({ webwork_dir => $webwork_directory });
   12   my $webwork_url = $ce->{webwork_url};
   13   my $pg_dir = $ce->{pg_dir};
   14 #   my $webwork_htdocs_url = $ce->{webwork_htdocs_url};
   15 #   my $webwork_htdocs_dir = $ce->{webwork_htdocs_dir};
   16 #   my $webwork_courses_url = $ce->{webwork_courses_url};
   17 #   my $webwork_courses_dir = $ce->{webwork_courses_dir};
   18   eval "use lib '$pg_dir/lib'"; die $@ if $@;
   19 
   20   $WebworkWebservice::WW_DIRECTORY = $webwork_directory;
   21   $WebworkWebservice::PG_DIRECTORY = $pg_dir;
   22   $WebworkWebservice::SeedCE       = $ce;
   23   $WebworkWebservice::HOST_NAME     = Apache->server->server_hostname;
   24   $WebworkWebservice::HOST_PORT     = Apache->server->port;
   25   #$WebworkWebservice::HOST_PATH    = Apache->server->path();
   26   $WebworkWebservice::PASSWORD      = 'geometry';
   27   $WebworkWebservice::COURSENAME    = 'daemon2_course'; # default course
   28 
   29 }
   30 use Apache;
   31 use WeBWorK::PG::Local;
   32 
   33 #use lib '/home/gage/webwork/webwork-modperl/lib';
   34 #use lib '/home/gage/webwork/pg/lib';
   35 
   36 
   37 #$Webservice::HOST_PATH = "http://$Webservice::HOST_NAME";
   38 #$Webservice::HOST_PATH .= ":$Webservice::HOST_PORT"
   39 #                 unless ($Webservice::HOST_PORT == 80 );
   40 
   41 # warn "webwork_directory = $WebworkWebservice::WW_DIRECTORY\n\t";
   42 # warn "pg_directory = $WebworkWebservice::PG_DIRECTORY\n\t";
   43 # warn "seedCE  = $WebworkWebservice::SeedCE\n\t";
   44 # warn "host name  = $WebworkWebservice::HOST_NAME\n\t";
   45 
   46 #FIXME  port is not being set!
   47 # warn "host port  = $Webservice::HOST_PORT\n\t";
   48 
   49 # #warn "host path  = $Webservice::HOST_PATH\n\t";
   50 # warn " password  $WebworkWebservice::PASSWORD\n\t";
   51 
   52 use strict;
   53 ###############################################################################
   54 
   55 package WebworkWebservice;
   56 
   57 sub pretty_print_rh {
   58     shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
   59   my $rh = shift;
   60   my $indent = shift || 0;
   61   my $out = "";
   62   my $type = ref($rh);
   63 
   64   if (defined($type) and $type) {
   65     $out .= " type = $type; ";
   66   } elsif ($rh == undef) {
   67     $out .= " type = UNDEFINED; ";
   68   }
   69   if ( ref($rh) =~/HASH/ or "$rh" =~/HASH/ ) {
   70       $out .= "{\n";
   71       $indent++;
   72     foreach my $key (sort keys %{$rh})  {
   73       $out .= "  "x$indent."$key => " . pretty_print_rh( $rh->{$key}, $indent ) . "\n";
   74     }
   75     $indent--;
   76     $out .= "\n"."  "x$indent."}\n";
   77 
   78   } elsif (ref($rh)  =~  /ARRAY/ or "$rh" =~/ARRAY/) {
   79       $out .= " ( ";
   80     foreach my $elem ( @{$rh} )  {
   81       $out .= pretty_print_rh($elem, $indent);
   82 
   83     }
   84     $out .=  " ) \n";
   85   } elsif ( ref($rh) =~ /SCALAR/ ) {
   86     $out .= "scalar reference ". ${$rh};
   87   } elsif ( ref($rh) =~/Base64/ ) {
   88     $out .= "base64 reference " .$$rh;
   89   } else {
   90     $out .=  $rh;
   91   }
   92 
   93   return $out." ";
   94 }
   95 
   96 
   97 use WebworkWebservice::RenderProblem;
   98 use WebworkWebservice::LibraryActions;
   99 use WebworkWebservice::MathTranslators;
  100 
  101 ###############################################################################
  102 package WebworkXMLRPC;
  103 use WebworkWebservice;
  104 use base qw(WebworkWebservice);
  105 
  106 
  107 
  108 #  respond to xmlrpc requests
  109 sub listLib {
  110     my $self = shift;
  111     my $in = shift;
  112     return( WebworkWebservice::LibraryActions::listLib($in) );
  113 }
  114 sub listLibraries {
  115     my $self = shift;
  116     my $in = shift;
  117     return( WebworkWebservice::LibraryActions::listLibraries($in) );
  118 }
  119 sub renderProblem {
  120     my $self = shift;
  121     my $in = shift;
  122     return( WebworkWebservice::RenderProblem::renderProblem($in) );
  123 }
  124 sub readFile {
  125     my $self = shift;
  126     my $in   = shift;
  127     return( WebworkWebservice::LibraryActions::readFile($in) );
  128 }
  129 sub tex2pdf {
  130     my $self = shift;
  131     my $in   = shift;
  132     return( WebworkWebservice::MathTranslators::tex2pdf($in) );
  133 }
  134 
  135 # -- SOAP::Lite -- guide.soaplite.com -- Copyright (C) 2001 Paul Kulchenko --
  136 # test responses
  137 
  138 sub hi {   shift if UNIVERSAL::isa($_[0] => __PACKAGE__); # grabs class reference
  139   return "hello, world";
  140 }
  141 sub hello2 { shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
  142   #print "Receiving request for hello world\n";
  143   return "Hello world2";
  144 }
  145 sub bye {shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
  146   return "goodbye, sad cruel world";
  147 }
  148 
  149 sub languages {shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
  150   return ["Perl", "C", "sh"];
  151 }
  152 
  153 sub echo_self {
  154   my $self = shift;
  155 }
  156 
  157 sub echo {
  158     return join("|",("begin ", WebworkWebservice::pretty_print_rh(\@_), " end") );
  159 }
  160 
  161 sub pretty_print_rh {
  162   WebworkWebservice::pretty_print_rh(@_);
  163 }
  164 
  165 
  166 sub tth {shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
  167   my $in = shift;
  168   my $tthpath = "/usr/local/bin/tth";
  169     # $tthpath -L -f5 -r 2>/dev/null " . $inputString;
  170     return $in;
  171 
  172 }
  173 
  174 
  175 
  176 
  177 package WWd;
  178 
  179 #use lib '/home/gage/webwork/xmlrpc/daemon';
  180 #use WebworkXMLRPC;
  181 
  182 
  183 
  184 
  185 ############utilities
  186 
  187 sub echo {
  188     return "WWd package ".join("|",("begin ", WebworkWebservice::pretty_print_rh(\@_), " end") );
  189 }
  190 
  191 sub listLib {
  192     shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
  193     my $in = shift;
  194     return( Webwork::listLib($in) );
  195 }
  196 sub renderProblem {
  197     shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
  198     my $in = shift;
  199     return( Filter::filterObject( Webwork::renderProblem($in) ) );
  200 }
  201 sub readFile {
  202     shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
  203     my $in = shift;
  204     return( Webwork::readFile($in) );
  205 }
  206 # sub hello {
  207 #   shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
  208 #   print "Receiving request for hello world\n";
  209 #   return "Hello world?";
  210 # }
  211 
  212 
  213 # sub tth {
  214 #   shift if UNIVERSAL::isa($_[0] => __PACKAGE__);
  215 #   my $in = shift;
  216 #   my $tthpath = "/usr/local/bin/tth";
  217 #     my $out;
  218 #     $inputString    = "<<END_OF_TTH_INPUT_STRING;\n\n\n" . $in . "\nEND_OF_TTH_INPUT_STRING\necho \"\" >/dev/null";
  219 #     #it's not clear why another command is needed.
  220 #
  221 #     if (-x $tthpath ) {
  222 #       my $tthcmd      = "$tthpath -L -f5 -r 2>/dev/null " . $inputString;
  223 #       if (open(TTH, "$tthcmd   |")) {
  224 #           local($/);
  225 #       $/ = undef;
  226 #       $out = <TTH>;
  227 #       $/ = "\n";
  228 #       close(TTH);
  229 #       }else {
  230 #           $out = "<BR>there has been an error in executing $tthcmd<BR>";
  231 #       }
  232 #   } else {
  233 #     $out = "<BR> Can't execute the program tth at |$tthpath|<BR>";
  234 #     }
  235 #
  236 #     #return "<!-- \r\n" . $in . "\r\n-->\r\n\r\n" . $out . "\r\n\r\n";
  237 #     return $out;
  238 #
  239 # }
  240 
  241 package Filter;
  242 
  243 
  244 
  245 
  246 
  247 
  248 
  249 
  250 
  251 
  252 sub is_hash_ref {
  253   my $in =shift;
  254   my $save_SIG_die_trap = $SIG{__DIE__};
  255     $SIG{__DIE__} = sub {CORE::die(@_) };
  256   my $out = eval{  %{   $in  }  };
  257   $out = ($@ eq '') ? 1 : 0;
  258   $@='';
  259   $SIG{__DIE__} = $save_SIG_die_trap;
  260   $out;
  261 }
  262 sub is_array_ref {
  263   my $in =shift;
  264   my $save_SIG_die_trap = $SIG{__DIE__};
  265     $SIG{__DIE__} = sub {CORE::die(@_) };
  266   my $out = eval{  @{   $in  }  };
  267   $out = ($@ eq '') ? 1 : 0;
  268   $@='';
  269   $SIG{__DIE__} = $save_SIG_die_trap;
  270   $out;
  271 }
  272 sub filterObject {
  273 
  274     my $is_hash = 0;
  275     my $is_array =0;
  276   my $obj = shift;
  277   #print "Enter filterObject ", ref($obj), "\n";
  278   my $type = ref($obj);
  279   unless ($type) {
  280     #print "leave filterObject with nothing\n";
  281     return($obj);
  282   }
  283 
  284 
  285   if ( is_hash_ref($obj)  ) {
  286       #print "enter hash ", %{$obj},"\n";
  287       my %obj_container= %{$obj};
  288     foreach my $key (keys %obj_container) {
  289       $obj_container{$key} = filterObject( $obj_container{$key} );
  290       #print $key, "  ",  ref($obj_container{$key}),"   ", $obj_container{$key}, "\n";
  291     }
  292     #print "leave filterObject with HASH\n";
  293     return( bless(\%obj_container,'HASH'));
  294   };
  295 
  296 
  297 
  298   if ( is_array_ref($obj)  ) {
  299     #print "enter array ( ", @{$obj}," )\n";
  300     my @obj_container= @{$obj};
  301     foreach my $i (0..$#obj_container) {
  302       $obj_container[$i] = filterObject( $obj_container[$i] );
  303       #print "\[$i\]  ",  ref($obj_container[$i]),"   ", $obj_container[$i], "\n";
  304     }
  305     #print "leave filterObject with ARRAY\n";
  306     return( bless(\@obj_container,'ARRAY'));
  307   };
  308 
  309 }
  310 
  311 
  312 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9