[LON-CAPA-cvs] cvs: loncom / lond lonsql /lonnet/perl lonnet.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Wed, 08 Aug 2007 22:24:37 -0000
albertel Wed Aug 8 18:24:37 2007 EDT
Modified files:
/loncom/lonnet/perl lonnet.pm
/loncom lonsql lond
Log:
- moving inst dir queries into lonsql
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.903 loncom/lonnet/perl/lonnet.pm:1.904
--- loncom/lonnet/perl/lonnet.pm:1.903 Thu Aug 2 16:40:13 2007
+++ loncom/lonnet/perl/lonnet.pm Wed Aug 8 18:24:34 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.903 2007/08/02 20:40:13 albertel Exp $
+# $Id: lonnet.pm,v 1.904 2007/08/08 22:24:34 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -862,16 +862,28 @@
my %results;
my $homeserver = &domain($udom,'primary');
if ($homeserver ne '') {
- my $response=&reply("instdirsrch:$udom".':'.
- &escape($srch->{'srchby'}).':'.
- &escape($srch->{'srchterm'}).':'.
- $srch->{'srchtype'},$homeserver);
- if ($response ne 'refused') {
- my @matches = split(/&/,$response);
+ my $queryid=&reply("querysend:instdirsearch:".
+ &escape($srch->{'srchby'}).':'.
+ &escape($srch->{'srchterm'}).':'.
+ &escape($srch->{'srchtype'}),$homeserver);
+ my $host=&hostname($homeserver);
+ if ($queryid !~/^\Q$host\E\_/) {
+ &logthis('instituional directory search invalid queryid: '.$queryid.' for host: '.$homeserver.'in domain '.$udom);
+ return;
+ }
+ my $response = &get_query_reply($queryid);
+ my $maxtries = 5;
+ my $tries = 1;
+ while (($response=~/^timeout/) && ($tries < $maxtries)) {
+ $response = &get_query_reply($queryid);
+ $tries ++;
+ }
+
+ if (!&error($response) && $response ne 'refused') {
+ my @matches = split(/\n/,$response);
foreach my $match (@matches) {
my ($key,$value) = split(/=/,$match);
- my %userhash = &str2hash(&unescape($value));
- $results{&unescape($key).':'.$udom} = \%userhash;
+ $results{&unescape($key).':'.$udom} = &thaw_unescape($value);
}
}
}
@@ -4541,8 +4553,8 @@
sleep 2;
if (-e $replyfile.'.end') {
if (open(my $fh,$replyfile)) {
- $reply.=<$fh>;
- close($fh);
+ $reply = join('',<$fh>);
+ close($fh);
} else { return 'error: reply_file_error'; }
return &unescape($reply);
}
Index: loncom/lonsql
diff -u loncom/lonsql:1.83 loncom/lonsql:1.84
--- loncom/lonsql:1.83 Mon Jul 30 19:52:06 2007
+++ loncom/lonsql Wed Aug 8 18:24:36 2007
@@ -3,7 +3,7 @@
# The LearningOnline Network
# lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
#
-# $Id: lonsql,v 1.83 2007/07/30 23:52:06 albertel Exp $
+# $Id: lonsql,v 1.84 2007/08/08 22:24:36 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -387,7 +387,7 @@
print $client "$queryid\n";
#
# &logthis("QUERY: $query - $arg1 - $arg2 - $arg3 - $queryid");
- sleep 1;
+ # sleep 1;
#
my $result='';
#
@@ -492,6 +492,8 @@
'WARNING: Could not retrieve from database:'.
$sth->errstr().'</font>');
}
+ } elsif ($query eq 'instdirsearch') {
+ $result = &do_inst_dir_search($searchdomain,$arg1,$arg2,$arg3);
} elsif ($query eq 'prepare activity log') {
my ($cid,$domain) = map {&unescape($_);} ($arg1,$arg2);
&logthis('preparing activity log tables for '.$cid);
@@ -543,6 +545,30 @@
}
}
+sub do_inst_dir_search {
+ my ($domain,$srchby,$srchterm,$srchtype) = @_;
+ $srchby = &unescape($srchby);
+ $srchterm = &unescape($srchterm);
+ $srchtype = &unescape($srchtype);
+ my (%instusers,%instids,$result,$response);
+ eval {
+ local($SIG{__DIE__})='DEFAULT';
+ $result=&localenroll::get_userinfo($domain,undef,undef,\%instusers,
+ \%instids,undef,$srchby,$srchterm,
+ $srchtype);
+ };
+ if ($result eq 'ok') {
+ if (%instusers) {
+ foreach my $key (keys(%instusers)) {
+ my $usrstr = &Apache::lonnet::freeze_escape($instusers{$key});
+ $response .=&escape(&escape($key).'='.$usrstr).'&';
+ }
+ }
+ $response=~s/\&$//;
+ }
+ return $response;
+}
+
########################################################
########################################################
Index: loncom/lond
diff -u loncom/lond:1.377 loncom/lond:1.378
--- loncom/lond:1.377 Wed Aug 1 21:31:48 2007
+++ loncom/lond Wed Aug 8 18:24:36 2007
@@ -2,7 +2,7 @@
# The LearningOnline Network
# lond "LON Daemon" Server (port "LOND" 5663)
#
-# $Id: lond,v 1.377 2007/08/02 01:31:48 albertel Exp $
+# $Id: lond,v 1.378 2007/08/08 22:24:36 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -59,7 +59,7 @@
my $status='';
my $lastlog='';
-my $VERSION='$Revision: 1.377 $'; #' stupid emacs
+my $VERSION='$Revision: 1.378 $'; #' stupid emacs
my $remoteVERSION;
my $currenthostid="default";
my $currentdomainid;
@@ -4640,30 +4640,6 @@
}
®ister_handler("inst_usertypes", \&inst_usertypes_handler, 0, 1, 0);
-sub inst_dirsrch_handler {
- my ($cmd, $tail, $client) = @_;
- my ($domain,$srchby,$srchterm,$srchtype) = split(/:/, $tail);
- $srchby = &unescape($srchby);
- $srchterm = &unescape($srchterm);
- my $userinput = $cmd.":".$tail; # For logging purposes.
- my (%instusers,%instids,$result,$res);
- eval {
- local($SIG{__DIE__})='DEFAULT';
- $result=&localenroll::get_userinfo($domain,undef,undef,\%instusers,\%instids,undef,$srchby,$srchterm,$srchtype);
- };
- if ($result eq 'ok') {
- if (keys(%instusers) > 0) {
- foreach my $key (keys(%instusers)) {
- my $usrstr = &Apache::lonnet::hash2str(%{$instusers{$key}});
- $res.=&escape($key).'='.&escape($usrstr).'&';
- }
- }
- $res=~s/\&$//;
- }
- &Reply($client, "$res\n", $userinput);
-}
-®ister_handler("instdirsrch", \&inst_dirsrch_handler, 0, 1, 0);
-
# mkpath makes all directories for a file, expects an absolute path with a
# file or a trailing / if just a dir is passed
# returns 1 on success 0 on failure