Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.393 and 1.394

version 1.393, 2003/07/20 00:39:02 version 1.394, 2003/07/25 01:18:04
Line 4246  being set. Line 4246  being set.
   
 =back  =back
   
 =head1 INTRODUCTION  =head1 OVERVIEW
   
 This module provides subroutines which interact with the  lonnet provides subroutines which interact with the
 lonc/lond (TCP) network layer of LON-CAPA. And Can be used to ask about   lonc/lond (TCP) network layer of LON-CAPA. They can be used to ask
 - classes  about classes, users, and resources.
 - users   
 - resources  
   
 For many of these objects you can also use this to store data about  For many of these objects you can also use this to store data about
 them or modify them in various ways.  them or modify them in various ways.
   
 This is part of the LearningOnline Network with CAPA project  =head2 Symbs
 described at http://www.lon-capa.org.  
   
 =head1 RETURN MESSAGES  To identify a specific instance of a resource, LON-CAPA uses symbols
   or "symbs"X<symb>. These identifiers are built from the URL of the
   map, the resource number of the resource in the map, and the URL of
   the resource itself. The latter is somewhat redundant, but might help
   if maps change.
   
 =over 4  An example is
   
 =item *   msu/korte/parts/part1.sequence___19___msu/korte/tests/part12.problem
   
 con_lost : unable to contact remote host  The respective map entry is
   
 =item *   <resource id="19" src="/res/msu/korte/tests/part12.problem"
     title="Problem 2">
    </resource>
   
 con_delayed : unable to contact remote host, message will be delivered  Symbs are used by the random number generator, as well as to store and
 when the connection is brought back up  restore data specific to a certain instance of for example a problem.
   
 =item *  =head2 Storing And Retrieving Data
   
 con_failed : unable to contact remote host and unable to save message  X<store()>X<cstore()>X<restore()>Three of the most important functions
 for later delivery  in C<lonnet.pm> are C<&Apache::lonnet::cstore()>,
   C<&Apache::lonnet:restore()>, and C<&Apache::lonnet::store()>, which
   is is the non-critical message twin of cstore. These functions are for
   handlers to store a perl hash to a user's permanent data space in an
   easy manner, and to retrieve it again on another call. It is expected
   that a handler would use this once at the beginning to retrieve data,
   and then again once at the end to send only the new data back.
   
 =item *  The data is stored in the user's data directory on the user's
   homeserver under the ID of the course.
   
 error: : an error a occured, a description of the error follows the :  The hash that is returned by restore will have all of the previous
   value for all of the elements of the hash.
   
 =item *  Example:
   
    #creating a hash
    my %hash;
    $hash{'foo'}='bar';
   
    #storing it
    &Apache::lonnet::cstore(\%hash);
   
    #changing a value
    $hash{'foo'}='notbar';
   
    #adding a new value
    $hash{'bar'}='foo';
    &Apache::lonnet::cstore(\%hash);
   
    #retrieving the hash
    my %history=&Apache::lonnet::restore();
   
    #print the hash
    foreach my $key (sort(keys(%history))) {
      print("\%history{$key} = $history{$key}");
    }
   
   Will print out:
   
    %history{1:foo} = bar
    %history{1:keys} = foo:timestamp
    %history{1:timestamp} = 990455579
    %history{2:bar} = foo
    %history{2:foo} = notbar
    %history{2:keys} = foo:bar:timestamp
    %history{2:timestamp} = 990455580
    %history{bar} = foo
    %history{foo} = notbar
    %history{timestamp} = 990455580
    %history{version} = 2
   
   Note that the special hash entries C<keys>, C<version> and
   C<timestamp> were added to the hash. C<version> will be equal to the
   total number of versions of the data that have been stored. The
   C<timestamp> attribute will be the UNIX time the hash was
   stored. C<keys> is available in every historical section to list which
   keys were added or changed at a specific historical revision of a
   hash.
   
   B<Warning>: do not store the hash that restore returns directly. This
   will cause a mess since it will restore the historical keys as if the
   were new keys. I.E. 1:foo will become 1:1:foo etc.
   
   Calling convention:
   
    my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$uname,$home);
    &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$uname,$home);
   
   For more detailed information, see lonnet specific documentation.
   
 no_such_host : unable to fund a host associated with the user/domain  =head1 RETURN MESSAGES
   
   =over 4
   
   =item * B<con_lost>: unable to contact remote host
   
   =item * B<con_delayed>: unable to contact remote host, message will be delivered
   when the connection is brought back up
   
   =item * B<con_failed>: unable to contact remote host and unable to save message
   for later delivery
   
   =item * B<error:>: an error a occured, a description of the error follows the :
   
   =item * B<no_such_host>: unable to fund a host associated with the user/domain
 that was requested  that was requested
   
 =back  =back
Line 4295  that was requested Line 4375  that was requested
   
 =over 4  =over 4
   
 =item *  =item * 
   X<appenv()>
 appenv(%hash) : the value of %hash is written to the user envirnoment  B<appenv(%hash)>: the value of %hash is written to
 file, and will be restored for each access this user makes during this  the user envirnoment file, and will be restored for each access this
 session, also modifies the %ENV for the current process  user makes during this session, also modifies the %ENV for the current
   process
   
 =item *  =item *
   X<delenv()>
 delenv($regexp) : removes all items from the session environment file that matches the regular expression in $regexp. The values are also delted from the current processes %ENV.  B<delenv($regexp)>: removes all items from the session
   environment file that matches the regular expression in $regexp. The
   values are also delted from the current processes %ENV.
   
 =back  =back
   
Line 4312  delenv($regexp) : removes all items from Line 4395  delenv($regexp) : removes all items from
 =over 4  =over 4
   
 =item *  =item *
   X<queryauthenticate()>
 queryauthenticate($uname,$udom) : try to determine user's current  B<queryauthenticate($uname,$udom)>: try to determine user's current 
 authentication scheme  authentication scheme
   
 =item *  =item *
   X<authenticate()>
 authenticate($uname,$upass,$udom) : try to authenticate user from domain's lib  B<authenticate($uname,$upass,$udom)>: try to
 servers (first use the current one), $upass should be the users password  authenticate user from domain's lib servers (first use the current
   one). C<$upass> should be the users password.
   
 =item *  =item *
   X<homeserver()>
 homeserver($uname,$udom) : find the server which has the user's  B<homeserver($uname,$udom)>: find the server which has
 directory and files (there must be only one), this caches the answer,  the user's directory and files (there must be only one), this caches
 and also caches if there is a borken connection.  the answer, and also caches if there is a borken connection.
   
 =item *  =item *
   X<idget()>
 idget($udom,@ids) : find the usernames behind a list of IDs (IDs are a  B<idget($udom,@ids)>: find the usernames behind a list of IDs
 unique resource in a domain, there must be only 1 ID per username, and  (IDs are a unique resource in a domain, there must be only 1 ID per
 only 1 username per ID in a specific domain) (returns hash:  username, and only 1 username per ID in a specific domain) (returns
 id=>name,id=>name)  hash: id=>name,id=>name)
   
 =item *  =item *
   X<idrget()>
 idrget($udom,@unames) : find the IDs behind a list of usernames (returns hash:  B<idrget($udom,@unames)>: find the IDs behind a list of
 name=>id,name=>id)  usernames (returns hash: name=>id,name=>id)
   
 =item *  =item *
   X<idput()>
 idput($udom,%ids) : store away a list of names and associated IDs  B<idput($udom,%ids)>: store away a list of names and associated IDs
   
 =item *  =item *
   X<rolesinit()>
 rolesinit($udom,$username,$authhost) : get user privileges  B<rolesinit($udom,$username,$authhost)>: get user privileges
   
 =item *  =item *
   X<usection()>
 usection($udom,$uname,$cname) : finds the section of student in the  B<usection($udom,$uname,$cname)>: finds the section of student in the
 course $cname, return section name/number or '' for "not in course"  course $cname, return section name/number or '' for "not in course"
 and '-1' for "no section"  and '-1' for "no section"
   
 =item *  =item *
   X<userenvironment()>
 userenvironment($udom,$uname,@what) : gets the values of the keys  B<userenvironment($udom,$uname,@what)>: gets the values of the keys
 passed in @what from the requested user's environment, returns a hash  passed in @what from the requested user's environment, returns a hash
   
 =back  =back

Removed from v.1.393  
changed lines
  Added in v.1.394


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