File:  [LON-CAPA] / loncom / LondTransaction.pm
Revision 1.9: download - view: text, annotated - select for diffs
Thu Jun 16 22:59:05 2005 UTC (18 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_X, version_2_8_99_1, version_2_8_99_0, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1, version_1_99_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, bz5969, bz2851, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, GCI_1, BZ5971-printing-apage, BZ5434-fox, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
- pod style docs want a blank line after =cut

    1: #   This module defines and implements a class that represents
    2: #   a connection to a lond daemon.
    3: #
    4: # $Id: LondTransaction.pm,v 1.9 2005/06/16 22:59:05 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: =pod
   30: 
   31: =head1 Synopsis
   32: 
   33:   LondTransaction objectifies the state of a transaction between lonc and
   34:   lond (loncnew really).  
   35: 
   36: =cut
   37: 
   38: use strict;
   39: 
   40: package LondTransaction;
   41: 
   42: =pod
   43: 
   44: =head1 Description
   45: 
   46: LondTransaction objects hold the state required to manage a 
   47: transaction between lonc and lond, from the loncnew point of view.
   48: The state consists of the following member data:
   49: 
   50: =item request
   51: 
   52: The text of the request to send to lond.
   53: 
   54: =item active
   55: 
   56: If zero, the request is not active and the londSocket item is not
   57: defined.
   58: 
   59: =item londSocket
   60: 
   61: If the request is active,
   62: this member contains the LondConnection object reference that
   63: this request is being processed on.
   64: 
   65: =item deferred
   66: 
   67: True if the request is a deferred (delayed) request.
   68: The member data below are either present or not depending on 
   69: whether or not deferred is true.
   70: 
   71: =item clientSocket
   72:    
   73: If deferred is false, this member data is defined and is the 
   74: handle to the socket that is connected to the apache child that
   75: has requested this transaction.
   76: 
   77: =item DeferredFile
   78: 
   79: If deferred is false, this member data is defined and is the name
   80: of the file that contains the deferred request.  When the transaction
   81: is retired, this file will be deleted.
   82: 
   83: =head1 Member Functions
   84: 
   85: =head2  Operational functions
   86: 
   87: =cut
   88: 
   89: =pod
   90: 
   91: =item new
   92: 
   93: Creates a new transaction object.
   94: 
   95: =cut
   96: 
   97: sub new {
   98: 
   99:     my ($class, $Transaction) = @_;
  100: 
  101:     
  102:     my $self   = {request     => $Transaction,
  103: 		  active      => 0,
  104: 		  deferred    => 0};
  105:     bless($self, $class);
  106:     return $self;
  107: }
  108: 
  109: =pod
  110: 
  111: =item Activate
  112: 
  113: Activates the transaction by assigning it to a LondConnection object
  114: 
  115: Parameters:
  116: 
  117: =over 3
  118: 
  119: =item  Connection
  120: 
  121: 
  122: Reference to the LondConnection object along which the transaction
  123: will be carried.
  124: 
  125: =back 
  126: 
  127: =cut
  128: 
  129: sub Activate {
  130: 
  131: 
  132:     my ($self, $Connection) = @_;
  133: 
  134: 
  135:     $self->{londSocket} = $Connection; # Store the connection object and
  136:     $self->{active}     = 1;	       # Indicate it's active.
  137: 
  138: }
  139: 
  140: =pod
  141: 
  142: =item Retire
  143: 
  144: 
  145: Retires a transaction after successful completion.  If the
  146: transaction is deferred, the deferred file is destroyed.
  147: Otherwise this is a noop.
  148: 
  149: =cut
  150: 
  151: sub Retire {
  152:     my $self     = shift;
  153: 
  154:     if($self->{deferred}) {
  155: 	unlink $self->{DeferredFile};
  156:     }
  157: 
  158:     #  Destroy my member data to release reference counts.
  159: 
  160:     delete $self->{londSocket};
  161:     delete $self->{clientSocket};
  162:     delete $self->{DeferredFile};
  163: 
  164: }
  165: 
  166: =pod
  167: 
  168: =item SetDeferred
  169: 
  170: Sets the state of a transaction to deferred, the deferred member
  171: is set true, clientSocket is undefined, and DeferredFile is set.
  172: 
  173: Parameters:
  174:  
  175: =over 3
  176: 
  177: =item File
  178: 
  179: Name of the file that holds the deferred transaction.
  180: 
  181: =back 
  182: 
  183: =cut
  184: 
  185: sub SetDeferred {
  186: 
  187: 
  188:     my ($self, $File) = @_;
  189: 
  190:     $self->{deferred}      = 1;
  191:     $self->{DeferredFile} = $File;
  192: }
  193: 
  194: =pod
  195: 
  196: =item  SetClient
  197: 
  198: Sets the state of a transaction to not deferred.  The deferred member
  199: is set false, clientSocket is set and DeferredFile is undefined.
  200: 
  201: Parameters:
  202: 
  203: =over 3
  204: 
  205: =item Socket
  206: 
  207:   The socket open on the client.
  208: 
  209: =back
  210: 
  211: =cut
  212: 
  213: sub SetClient {
  214: 
  215:     my ($self, $Client) = @_;
  216:     
  217:     $self->{deferred}     = 0;
  218:     $self->{clientSocket} = $Client; 
  219: }
  220: 
  221: =pod
  222: 
  223: =head2  Selectors
  224: 
  225: 
  226: =item isDeferred
  227: 
  228: Returns the state of the deferred member.
  229: 
  230: =cut
  231: 
  232: sub isDeferred {
  233:     my $self   = shift;
  234:     return $self->{deferred};
  235: }
  236: 
  237: =pod
  238: 
  239: =item isActive
  240: 
  241: Returns the value of the active member.
  242: 
  243: =cut
  244: 
  245: sub isActive {
  246:     my $self = shift;
  247:     return $self->{active};
  248: }
  249: 
  250: =pod
  251: 
  252: =item getClient
  253: 
  254: If not deferred returns the client socket, else returns undef.
  255: 
  256: =cut
  257: 
  258: sub getClient {
  259:     my $self = shift;
  260:     if($self->{deferred}) {
  261: 	return undef;
  262:     } else {
  263: 	return $self->{clientSocket};
  264:     }
  265: }
  266: 
  267: 
  268: =pod
  269: 
  270: =item getFile
  271: 
  272: If deferred, returns the name of the deferred queue file else
  273: returns undef.
  274: 
  275: =cut
  276: 
  277: sub getFile {
  278:     my $self = shift;
  279:     if($self->{deferred}) {
  280: 	return $self->{DeferredFile};
  281:     } else {
  282: 	return undef;
  283:     }
  284: }
  285: 
  286: 
  287: =pod
  288: 
  289: =item getServer
  290: 
  291:   If active returns the lond server socket else undef.
  292: 
  293: =cut
  294: 
  295: sub getServer {
  296:     my $self  = shift;
  297: 
  298:     if($self->{active}) {
  299: 	return $self->{londSocket};
  300:     } else {
  301: 	return undef;
  302:     }
  303: }
  304: 
  305: =pod
  306: 
  307: =item getRequest
  308: 
  309:   Returns the remaining request text.
  310: 
  311: =cut
  312: 
  313: sub getRequest {
  314:     my $self = shift;
  315:     return $self->{request};
  316: }
  317: 
  318: =pod
  319: 
  320: =item getLoggableRequest
  321: 
  322:    Use this top get what the request is when you don't want to spew
  323:    sensitive data into logs
  324: 
  325: =cut
  326: 
  327: sub getLoggableRequest {
  328:     my $self = shift;
  329:     my ($cmd,$subcmd)=split(':',$self->{request});
  330:     if ($cmd eq 'encrypt') {
  331: 	return "$cmd:$subcmd";
  332:     }
  333:     return $cmd;
  334: }
  335: 
  336: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>