Annotation of loncom/LondTransaction.pm, revision 1.9

1.1       foxr        1: #   This module defines and implements a class that represents
                      2: #   a connection to a lond daemon.
                      3: #
1.9     ! albertel    4: # $Id: LondTransaction.pm,v 1.8 2005/06/16 22:33:45 albertel Exp $
1.1       foxr        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
1.3       foxr       30: 
                     31: =head1 Synopsis
                     32: 
1.2       foxr       33:   LondTransaction objectifies the state of a transaction between lonc and
1.1       foxr       34:   lond (loncnew really).  
                     35: 
                     36: =cut
                     37: 
1.6       foxr       38: use strict;
                     39: 
1.3       foxr       40: package LondTransaction;
1.2       foxr       41: 
                     42: =pod
1.9     ! albertel   43: 
1.2       foxr       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: 
1.3       foxr       61: If the request is active,
1.2       foxr       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: 
1.3       foxr       87: =cut
                     88: 
                     89: =pod
                     90: 
1.2       foxr       91: =item new
                     92: 
                     93: Creates a new transaction object.
                     94: 
1.3       foxr       95: =cut
1.6       foxr       96: 
1.3       foxr       97: sub new {
1.7       foxr       98: 
                     99:     my ($class, $Transaction) = @_;
1.3       foxr      100: 
                    101:     
                    102:     my $self   = {request     => $Transaction,
                    103: 		  active      => 0,
                    104: 		  deferred    => 0};
                    105:     bless($self, $class);
1.5       foxr      106:     return $self;
1.3       foxr      107: }
1.9     ! albertel  108: 
1.3       foxr      109: =pod
                    110: 
1.2       foxr      111: =item Activate
                    112: 
                    113: Activates the transaction by assigning it to a LondConnection object
                    114: 
1.3       foxr      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
1.9     ! albertel  128: 
1.3       foxr      129: sub Activate {
1.7       foxr      130: 
                    131: 
                    132:     my ($self, $Connection) = @_;
                    133: 
1.3       foxr      134: 
                    135:     $self->{londSocket} = $Connection; # Store the connection object and
                    136:     $self->{active}     = 1;	       # Indicate it's active.
                    137: 
                    138: }
                    139: 
                    140: =pod
                    141: 
1.2       foxr      142: =item Retire
                    143: 
1.3       foxr      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
1.9     ! albertel  150: 
1.3       foxr      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
1.2       foxr      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: 
1.3       foxr      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
1.9     ! albertel  184: 
1.3       foxr      185: sub SetDeferred {
1.7       foxr      186: 
                    187: 
                    188:     my ($self, $File) = @_;
1.3       foxr      189: 
                    190:     $self->{deferred}      = 1;
1.5       foxr      191:     $self->{DeferredFile} = $File;
1.3       foxr      192: }
                    193: 
                    194: =pod
                    195: 
                    196: =item  SetClient
1.2       foxr      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: 
1.3       foxr      201: Parameters:
                    202: 
                    203: =over 3
                    204: 
                    205: =item Socket
                    206: 
                    207:   The socket open on the client.
                    208: 
                    209: =back
                    210: 
                    211: =cut
1.9     ! albertel  212: 
1.3       foxr      213: sub SetClient {
1.7       foxr      214: 
                    215:     my ($self, $Client) = @_;
1.3       foxr      216:     
                    217:     $self->{deferred}     = 0;
                    218:     $self->{clientSocket} = $Client; 
                    219: }
                    220: 
                    221: =pod
                    222: 
1.2       foxr      223: =head2  Selectors
                    224: 
                    225: 
                    226: =item isDeferred
                    227: 
                    228: Returns the state of the deferred member.
                    229: 
1.3       foxr      230: =cut
1.9     ! albertel  231: 
1.3       foxr      232: sub isDeferred {
                    233:     my $self   = shift;
                    234:     return $self->{deferred};
                    235: }
                    236: 
                    237: =pod
                    238: 
1.2       foxr      239: =item isActive
                    240: 
1.3       foxr      241: Returns the value of the active member.
                    242: 
                    243: =cut
1.9     ! albertel  244: 
1.3       foxr      245: sub isActive {
                    246:     my $self = shift;
                    247:     return $self->{active};
                    248: }
                    249: 
                    250: =pod
1.2       foxr      251: 
                    252: =item getClient
                    253: 
1.3       foxr      254: If not deferred returns the client socket, else returns undef.
                    255: 
                    256: =cut
1.9     ! albertel  257: 
1.3       foxr      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
1.2       foxr      269: 
                    270: =item getFile
                    271: 
                    272: If deferred, returns the name of the deferred queue file else
                    273: returns undef.
                    274: 
                    275: =cut
1.9     ! albertel  276: 
1.3       foxr      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
1.9     ! albertel  294: 
1.3       foxr      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
1.8       albertel  312: 
1.3       foxr      313: sub getRequest {
                    314:     my $self = shift;
                    315:     return $self->{request};
                    316: }
                    317: 
1.8       albertel  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: }
1.3       foxr      335: 
1.5       foxr      336: 1;

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