2 package ZOOM::IRSpy::Utils;
10 use Exporter 'import';
11 our @EXPORT_OK = qw(utf8param
20 irspy_record2identifier
21 irspy_identifier2target
26 calc_reliability_string
27 calc_reliability_stats);
30 use XML::LibXML::XPathContext;
32 use Encode qw(is_utf8);
35 our $IRSPY_NS = 'http://indexdata.com/irspy/1.0';
37 # Under Apache 2/mod_perl 2, the ubiquitous $r is no longer and
38 # Apache::Request object, nor even an Apache2::Request, but an
39 # Apache2::RequestReq ... which, astonishingly, doesn't have the
40 # param() method. So if we're given one of these things, we need to
41 # make an Apache::Request out of, which at least isn't too hard.
42 # However *sigh* this may not be a cheap operation, so we keep a cache
43 # of already-made Request objects.
46 my %_paramsbyrequest; # Used for Apache2 only
48 my($r, $key, $value) = @_;
50 if ($r->isa('Apache2::RequestRec')) {
51 # Running under Apache2
52 if (defined $_apache2request{$r}) {
53 #warn "using existing Apache2::RequestReq for '$r'";
54 $r = $_apache2request{$r};
56 require Apache2::Request;
57 #warn "making new Apache2::RequestReq for '$r'";
58 $r = $_apache2request{$r} = new Apache2::Request($r);
63 return map { decode_utf8($_) } $r->param();
67 $raw = $_paramsbyrequest{$r}->{$key} if $r->isa('Apache2::Request');
68 $raw = $r->param($key) if !defined $raw;
71 # Argh! Simply writing through to the underlying method
72 # param() won't work in Apache2, where param() is readonly.
73 # So we have to keep a hash of additional values, which we
74 # consult (above) before the actual parameters. Ouch ouch.
75 if ($r->isa('Apache2::Request')) {
76 $_paramsbyrequest{$r}->{$key} = encode_utf8($value);
78 $r->param($key, encode_utf8($value));
82 return undef if !defined $raw;
83 my $cooked = decode_utf8($raw);
84 warn "converted '$raw' to '", $cooked, "'\n" if $cooked ne $raw;
88 # Utility functions follow, exported for use of web UI
89 sub utf8param_apache1 {
90 my($r, $key, $value) = @_;
91 die "utf8param() called with value '$value'" if defined $value;
93 my $raw = $r->param($key);
94 return undef if !defined $raw;
95 my $cooked = decode_utf8($raw);
96 warn "converted '$raw' to '", $cooked, "'\n" if $cooked ne $raw;
104 my($sec, $min, $hour, $mday, $mon, $year) = localtime($time);
105 return sprintf("%04d-%02d-%02dT%02d:%02d:%02d",
106 $year+1900, $mon+1, $mday, $hour, $min, $sec);
109 # strips whitespaces at start and ends of a field
119 # utf8param() with trim
121 my $result = utf8param(@_);
123 if (defined $result) {
124 $result = trimField($result);
130 # I can't -- just can't, can't, can't -- believe that this function
131 # isn't provided by one of the core XML modules. But the evidence all
132 # says that it's not: among other things, XML::Generator and
133 # Template::Plugin both roll their own. So I will do likewise. D'oh!
136 my($text, $fallback, $opts) = @_;
137 if (!defined $opts && ref $fallback) {
138 # The second and third arguments are both optional
142 $opts = {} if !defined $opts;
144 $text = $fallback if !defined $text;
146 confess "xml_encode(): text and fallback both undefined"
149 $text =~ s/&/&/g;
152 # Internet Explorer can't display ' (!) so don't create it
153 #$text =~ s/['']/'/g;
154 $text =~ s/[""]/"/g;
155 $text =~ s/ / /g if $opts->{nbsp};
161 # Quotes a term for use in a CQL query
165 $term =~ s/([""\\*?])/\\$1/g;
166 $term = qq["$term"] if $term =~ /[\s""\/]/;
171 # Makes a CQL query that finds a specified target. Arguments may be
172 # either an ID alone, or a (host, port, db) triple.
174 my($protocol, $host, $port, $db) = @_;
178 $id = irspy_make_identifier($protocol, $host, $port, $db);
183 return "rec.id=" . cql_quote($id);
187 # PRIVATE to irspy_namespace() and irspy_xpath_context()
189 e => 'http://explain.z3950.org/dtd/2.0/',
194 sub irspy_namespace {
198 confess "irspy_namespace(undef)" if !defined $prefix;
199 my $uri = $_namespaces{$prefix};
200 die "irspy_namespace(): no URI for namespace prefix '$prefix'"
207 sub irspy_xpath_context {
210 if (ref $record && $record->isa("ZOOM::Record")) {
211 $record = $record->render();
218 my $parser = new XML::LibXML();
219 my $doc = $parser->parse_string($record);
220 $root = $doc->getDocumentElement();
223 my $xc = XML::LibXML::XPathContext->new($root);
224 foreach my $prefix (keys %_namespaces) {
225 $xc->registerNs($prefix, $_namespaces{$prefix});
231 # Construct an opaque identifier from its components. Although it's
232 # trivial, this is needed in so many places that it really needs to be
235 # This is the converse of _parse_target_string() in IRSpy.pm, which
236 # should be renamed and moved into this package.
238 sub irspy_make_identifier {
239 my($protocol, $host, $port, $dbname) = @_;
241 die "irspy_make_identifier(" . join(", ", map { "'$_'" } @_).
242 "): wrong number of arguments" if @_ != 4;
244 die "irspy_make_identifier(): protocol undefined" if !defined $protocol;
245 die "irspy_make_identifier(): host undefined" if !defined $host;
246 die "irspy_make_identifier(): port undefined" if !defined $port;
247 die "irspy_make_identifier(): dbname undefined" if !defined $dbname;
249 return "$protocol:$host:$port/$dbname";
253 # Returns the opaque identifier of an IRSpy record based on the
254 # XPathContext'ed DOM object, as returned by irspy_xpath_context().
255 # This is doing the same thing as irspy_make_identifier() but from a
256 # record rather than a set of parameters.
258 sub irspy_record2identifier {
261 ### Must be kept the same as is used in ../../../zebra/*.xsl
262 return $xc->find("concat(e:serverInfo/\@protocol, ':',
263 e:serverInfo/e:host, ':',
264 e:serverInfo/e:port, '/',
265 e:serverInfo/e:database)");
269 # Transforms an IRSpy opqaue identifier, as returned from
270 # irspy_make_identifier() or irspy_record2identifier(), into a YAZ
271 # target-string suitable for feeding to ZOOM. Before we introduced
272 # the protocol element at the start of the identifier string, this was
273 # a null transform; now we have to be a bit cleverer.
275 sub irspy_identifier2target {
276 my $res = _irspy_identifier2target(@_);
277 #carp "converted ID '@_' to target '$res'";
281 sub _irspy_identifier2target {
284 confess "_irspy_identifier2target(): id is undefined"
287 my($protocol, $target) = ($id =~ /(.*?):(.*)/);
288 if (uc($protocol) eq "Z39.50" || uc($protocol) eq "TCP") {
289 return "tcp:$target";
290 } elsif (uc($protocol) eq "SRU") {
291 return "sru=get,http:$target";
292 } elsif (uc($protocol) eq "SRW") {
293 return "sru=srw,http:$target";
296 warn "_irspy_identifier2target($id): unrecognised protocol '$protocol'";
301 # Modifies the XML document for which $xc is an XPath context by
302 # inserting or replacing the values specified in the hash %$data. The
303 # keys are fieldnames, which are looked up in the register
304 # $fieldsByKey to determine, among other things, what their XPath is.
306 sub modify_xml_document {
307 my($xc, $fieldsByKey, $data) = @_;
310 foreach my $key (keys %$data) {
311 my $value = $data->{$key};
312 my $ref = $fieldsByKey->{$key} or die "no field '$key'";
313 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
314 #print "Considering $key='$value' ($xpath)<br/>\n";
315 my @nodes = $xc->findnodes($xpath);
317 warn scalar(@nodes), " nodes match '$xpath'" if @nodes > 1;
318 my $node = $nodes[0];
320 if ($node->isa("XML::LibXML::Attr")) {
321 if ($value ne $node->getValue()) {
322 $node->setValue($value);
324 #print "Attr $key: '", $node->getValue(), "' -> '$value' ($xpath)<br/>\n";
326 } elsif ($node->isa("XML::LibXML::Element")) {
327 # The contents could be any mixture of text and
328 # comments and maybe even other crud such as processing
329 # instructions. The simplest thing is just to throw it all
330 # away and start again, making a single Text node the
331 # canonical representation. But before we do that,
332 # we'll check whether the element is already
333 # canonical, to determine whether our change is a
336 my @children = $node->childNodes();
337 if (@children == 1) {
338 my $child = $node->firstChild();
339 if (ref $child && ref $child eq "XML::LibXML::Text") {
340 $old = $child->getData();
341 #print STDERR "child='$child', old=", _renderchars($old), "\n" if $key eq "title";
344 next if $value eq $old;
346 $node->removeChildNodes();
347 my $child = new XML::LibXML::Text($value);
348 $node->appendChild($child);
350 #print STDERR "Elem $key ($xpath): ", _renderchars($old), " -> '", _renderchars($value), "\n";
352 warn "unexpected node type $node";
356 next if !defined $value; # No need to create a new empty node
357 my($ppath, $selector) = $xpath =~ /(.*)\/(.*)/;
358 dom_add_node($xc, $ppath, $selector, $value, @addAfter);
359 #print "New $key ($xpath) = '$value'<br/>\n";
371 return "'" . $text . "'", " (", join(" ", map {ord($_)} split //, $text), "), is_utf8=" , is_utf8($text);
376 my($xc, $ppath, $selector, $value, @addAfter) = @_;
378 #print "Adding $selector='$value' at '$ppath' after (", join(", ", map { "'$_'" } @addAfter), ")<br/>\n";
379 my $node = find_or_make_node($xc, $ppath, 0);
380 die "couldn't find or make node '$node'" if !defined $node;
382 my $is_attr = ($selector =~ s/^@//);
383 my(undef, $prefix, $simpleSel) = $selector =~ /((.*?):)?(.*)/;
384 #warn "selector='$selector', prefix='$prefix', simpleSel='$simpleSel'";
386 if (defined $prefix) {
387 ### This seems to no-op (thank, DOM!) but I have have no
388 # idea, and it's not needed for IRSpy, so I am not going
390 $node->setAttributeNS(irspy_namespace($prefix),
393 $node->setAttribute($simpleSel, $value);
398 my $new = new XML::LibXML::Element($simpleSel);
399 $new->setNamespace(irspy_namespace($prefix), $prefix)
402 $new->appendText($value);
403 foreach my $predecessor (reverse @addAfter) {
404 my($child) = $xc->findnodes($predecessor, $node);
405 if (defined $child) {
406 $node->insertAfter($new, $child);
407 #warn "Added after '$predecessor'";
412 # Didn't find any of the nodes that are supposed to precede the
413 # new one, so we need to insert the new node as the first of the
414 # parent's children. However *sigh* there is no prependChild()
415 # analogous to appendChild(), so we have to go the long way round.
416 my @children = $node->childNodes();
418 $node->insertBefore($new, $children[0]);
419 #warn "Added new first child";
421 $node->appendChild($new);
422 #warn "Added new only child";
426 my $text = xml_encode(inheritance_tree($xc));
427 $text =~ s/\n/<br\/>$&/sg;
428 print "<pre>$text</pre>\n";
433 sub find_or_make_node {
434 my($xc, $path, $recursion_level) = @_;
436 die "deep recursion in find_or_make_node($path)"
437 if $recursion_level == 10;
438 $path = "." if $path eq "";
440 my @nodes = $xc->findnodes($path);
442 # Oh dear, the parent node doesn't exist. We could make it,
443 my(undef, $ppath, $element) = $path =~ /((.*)\/)?(.*)/;
444 $ppath = "" if !defined $ppath;
445 #warn "path='$path', ppath='$ppath', element='$element'";
446 #warn "no node '$path': making it";
447 my $parent = find_or_make_node($xc, $ppath, $recursion_level-1);
449 my(undef, $prefix, $nsElem) = $element =~ /((.*?):)?(.*)/;
450 #warn "element='$element', prefix='$prefix', nsElem='$nsElem'";
451 my $new = new XML::LibXML::Element($nsElem);
452 if (defined $prefix) {
453 #warn "setNamespace($prefix)";
454 $new->setNamespace(irspy_namespace($prefix), $prefix);
457 $parent->appendChild($new);
460 warn scalar(@nodes), " nodes match parent '$path'" if @nodes > 1;
465 sub inheritance_tree {
466 my($type, $level) = @_;
467 $level = 0 if !defined $level;
468 return "Woah! Too deep, man!\n" if $level > 20;
470 $type = ref $type if ref $type;
472 $text = "--> " if $level == 0;
473 $text .= ("\t" x $level) . "$type\n";
474 my @ISA = eval "\@${type}::ISA";
475 foreach my $superclass (@ISA) {
476 $text .= inheritance_tree($superclass, $level+1);
483 # This function is made available in xslt using the register_function call
485 my ($arg1, $arg2) = @_;
486 return "$arg1" cmp "$arg2";
490 ### It feels like this should be in YAZ, exported via ZOOM-Perl.
491 my %_bib1_access_point = (
492 1 => "Personal name",
493 2 => "Corporate name",
494 3 => "Conference name",
497 6 => "Title uniform",
500 9 => "LC card number",
501 10 => "BNB card no.",
503 12 => "Local number",
504 13 => "Dewey classification",
505 14 => "UDC classification",
506 15 => "Bliss classification",
507 16 => "LC call number",
508 17 => "NLM call number",
509 18 => "NAL call number",
510 19 => "MOS call number",
511 20 => "Local classification",
512 21 => "Subject heading",
513 22 => "Subject Rameau",
514 23 => "BDI index subject",
515 24 => "INSPEC subject",
516 25 => "MESH subject",
518 27 => "LC subject heading",
519 28 => "RVM subject heading",
520 29 => "Local subject index",
522 31 => "Date of publication",
523 32 => "Date of acquisition",
525 34 => "Title collective",
526 35 => "Title parallel",
528 37 => "Title added title page",
529 38 => "Title caption",
530 39 => "Title running",
532 41 => "Title other variant",
533 42 => "Title former",
534 43 => "Title abbreviated",
535 44 => "Title expanded",
536 45 => "Subject precis",
537 46 => "Subject rswk",
538 47 => "Subject subdivision",
539 48 => "No. nat'l biblio.",
540 49 => "No. legal deposit",
541 50 => "No. govt pub.",
542 51 => "No. music publisher",
544 53 => "Number local call",
545 54 => "Code--language",
546 55 => "Code--geographic area",
547 56 => "Code--institution",
548 57 => "Name and title *",
549 58 => "Name geographic",
550 59 => "Place publication",
552 61 => "Microform generation",
555 1000 => "Author-title",
556 1001 => "Record type",
559 1004 => "Author-name personal",
560 1005 => "Author-name corporate",
561 1006 => "Author-name conference",
562 1007 => "Identifier--standard",
563 1008 => "Subject--LC children's",
564 1009 => "Subject name -- personal",
565 1010 => "Body of text",
566 1011 => "Date/time added to db",
567 1012 => "Date/time last modified",
568 1013 => "Authority/format id",
569 1014 => "Concept-text",
570 1015 => "Concept-reference",
572 1017 => "Server-choice",
574 1019 => "Record-source",
577 1022 => "Geographic-class",
578 1023 => "Indexed-by",
581 1026 => "Related-periodical",
582 1027 => "Report-number",
583 1028 => "Stock-number",
584 1030 => "Thematic-number",
585 1031 => "Material-type",
588 1034 => "Content-type",
590 1036 => "Author-Title-Subject",
591 1032 => "Doc-id (semantic definition change)",
593 1038 => "Abstract-language",
594 1039 => "Application-kind",
595 1040 => "Classification",
596 1041 => "Classification-basic",
597 1042 => "Classification-local-record",
599 1044 => "Possessing-institution",
600 1045 => "Record-linking",
601 1046 => "Record-status",
603 1048 => "Control-number-GKD",
604 1049 => "Control-number-linking",
605 1050 => "Control-number-PND",
606 1051 => "Control-number-SWD",
607 1052 => "Control-number-ZDB",
608 1053 => "Country-publication (country of Publication)",
609 1054 => "Date-conference (meeting date)",
610 1055 => "Date-record-status",
611 1056 => "Dissertation-information",
612 1057 => "Meeting-organizer",
613 1058 => "Note-availability",
614 1059 => "Number-CAS-registry (CAS registry number)",
615 1060 => "Number-document (document number)",
616 1061 => "Number-local-accounting",
617 1062 => "Number-local-acquisition",
618 1063 => "Number-local-call-copy-specific",
619 1064 => "Number-of-reference (reference count)",
620 1065 => "Number-norm",
621 1066 => "Number-volume",
622 1067 => "Place-conference (meeting location)",
623 1068 => "Reference (references and footnotes)",
624 1069 => "Referenced-journal (reference work)",
625 1070 => "Section-code",
626 1071 => "Section-heading",
627 1072 => "Subject-GOO",
628 1073 => "Subject-name-conference",
629 1074 => "Subject-name-corporate",
630 1075 => "Subject-genre/form",
631 1076 => "Subject-name-geographical",
632 1077 => "Subject--chronological",
633 1078 => "Subject--title",
634 1079 => "Subject--topical",
635 1080 => "Subject-uncontrolled",
636 1081 => "Terminology-chemical (chemical name)",
637 1082 => "Title-translated",
638 1083 => "Year-of-beginning",
639 1084 => "Year-of-ending",
640 1085 => "Subject-AGROVOC",
641 1086 => "Subject-COMPASS",
642 1087 => "Subject-EPT",
643 1088 => "Subject-NAL",
644 1089 => "Classification-BCM",
645 1090 => "Classification-DB",
646 1091 => "Identifier-ISRC",
647 1092 => "Identifier-ISMN",
648 1093 => "Identifier-ISRN",
649 1094 => "Identifier-DOI",
650 1095 => "Code-language-original",
651 1096 => "Title-later",
653 1098 => "DC-Creator",
654 1099 => "DC-Subject",
655 1100 => "DC-Description",
656 1101 => "DC-Publisher",
658 1103 => "DC-ResourceType",
659 1104 => "DC-ResourceIdentifier",
660 1105 => "DC-Language",
661 1106 => "DC-OtherContributor",
664 1109 => "DC-Relation",
665 1110 => "DC-Coverage",
666 1111 => "DC-RightsManagement",
667 1112 => "Controlled Subject Index",
668 1113 => "Subject Thesaurus",
669 1114 => "Index Terms -- Controlled",
670 1115 => "Controlled Term",
671 1116 => "Spatial Domain",
672 1117 => "Bounding Coordinates",
673 1118 => "West Bounding Coordinate",
674 1119 => "East Bounding Coordinate",
675 1120 => "North Bounding Coordinate",
676 1121 => "South Bounding Coordinate",
678 1123 => "Place Keyword Thesaurus",
679 1124 => "Place Keyword",
680 1125 => "Time Period",
681 1126 => "Time Period Textual",
682 1127 => "Time Period Structured",
683 1128 => "Beginning Date",
684 1129 => "Ending Date",
685 1130 => "Availability",
686 1131 => "Distributor",
687 1132 => "Distributor Name",
688 1133 => "Distributor Organization",
689 1134 => "Distributor Street Address",
690 1135 => "Distributor City",
691 1136 => "Distributor State or Province",
692 1137 => "Distributor Zip or Postal Code",
693 1138 => "Distributor Country",
694 1139 => "Distributor Network Address",
695 1140 => "Distributor Hours of Service",
696 1141 => "Distributor Telephone",
697 1142 => "Distributor Fax",
698 1143 => "Resource Description",
699 1144 => "Order Process",
700 1145 => "Order Information",
702 1147 => "Cost Information",
703 1148 => "Technical Prerequisites",
704 1149 => "Available Time Period",
705 1150 => "Available Time Textual",
706 1151 => "Available Time Structured",
707 1152 => "Available Linkage",
708 1153 => "Linkage Type",
710 1155 => "Sources of Data",
711 1156 => "Methodology",
712 1157 => "Access Constraints",
713 1158 => "General Access Constraints",
714 1159 => "Originator Dissemination Control",
715 1160 => "Security Classification Control",
716 1161 => "Use Constraints",
717 1162 => "Point of Contact",
718 1163 => "Contact Name",
719 1164 => "Contact Organization",
720 1165 => "Contact Street Address",
721 1166 => "Contact City",
722 1167 => "Contact State or Province",
723 1168 => "Contact Zip or Postal Code",
724 1169 => "Contact Country",
725 1170 => "Contact Network Address",
726 1171 => "Contact Hours of Service",
727 1172 => "Contact Telephone",
728 1173 => "Contact Fax",
729 1174 => "Supplemental Information",
731 1176 => "Agency Program",
732 1177 => "Cross Reference",
733 1178 => "Cross Reference Title",
734 1179 => "Cross Reference Relationship",
735 1180 => "Cross Reference Linkage",
736 1181 => "Schedule Number",
737 1182 => "Original Control Identifier",
738 1183 => "Language of Record",
739 1184 => "Record Review Date",
741 1186 => "Performer-Individual",
742 1187 => "Performer-Group",
743 1188 => "Instrumentation",
744 1189 => "Instrumentation-Original",
745 1190 => "Instrumentation-Current",
746 1191 => "Arrangement",
747 1192 => "Arrangement-Original",
748 1193 => "Arrangement-Current",
749 1194 => "Musical Key-Original",
750 1195 => "Musical Key-Current",
751 1196 => "Date-Composition",
752 1197 => "Date-Recording",
753 1198 => "Place-Recording",
754 1199 => "Country-Recording",
755 1200 => "Number-ISWC",
756 1201 => "Number-Matrix",
757 1202 => "Number-Plate",
758 1203 => "Classification-McColvin",
760 1205 => "Number-Copies",
761 1206 => "Musical Theme",
762 1207 => "Instruments - total number",
763 1208 => "Instruments - distinct number",
764 1209 => "Identifier - URN",
765 1210 => "Sears Subject Heading",
766 1211 => "OCLC Number",
767 1212 => "Composition",
768 1213 => "Intellectual level",
772 1217 => "Nationality",
774 1219 => "Compression",
776 1221 => "Subject - occupation",
777 1222 => "Subject - function",
781 sub bib1_access_point {
784 return $_bib1_access_point{$ap} ||
785 "unknown BIB-1 attribute '$ap'";
790 my($rs, $which, $elementSetName) = @_;
792 # There is a slight race condition here on the element-set name,
793 # but it shouldn't be a problem as this is (currently) only called
794 # from parts of the program that run single-threaded.
795 my $old = $rs->option(elementSetName => $elementSetName);
796 my $rec = $rs->record($which);
797 $rs->option(elementSetName => $old);
799 return $rec->render();
803 sub calc_reliability_string {
806 my($nok, $nall, $percent) = calc_reliability_stats($xc);
807 return "[untested]" if $nall == 0;
808 return "$nok/$nall = " . $percent . "%";
812 sub calc_reliability_stats {
815 my @allpings = $xc->findnodes("i:status/i:probe");
816 my $nall = @allpings;
817 return (0, 0, 0) if $nall == 0;
818 my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
820 my $percent = int(100*$nok/$nall + 0.5);
821 return ($nok, $nall, $percent);
825 # validate_record( record, ( "port" => 1, "database" => 1, "country" => 0, ... ))
827 sub validate_record {
831 my %required = map { $_ => 1 } qw/port host database protocol/;
832 my %optional = map { $_ => 1 } qw/country type hosturl contact language/;
833 my %tests = ( %required, %args );
835 my $xc = irspy_xpath_context($rec);
837 my $protocol = $xc->findnodes("e:serverInfo/\@protocol") || "";
838 my $port = $xc->findnodes("e:serverInfo/e:port") || "";
839 my $host = $xc->findnodes("e:serverInfo/e:host") || "";
840 my $dbname = $xc->findnodes("e:serverInfo/e:database") || "";
842 my $id = irspy_make_identifier($protocol, $host, $port, $dbname);
844 if ($protocol =~ /\s+$/ || $dbname =~ /\s+$/) {
845 warn "xxx: $protocol:$host:$port:$dbname: whitespaces\n";
850 if ($tests{'protocol'}) {
851 push(@errors, 'protocol number is not valid') if $protocol !~ /^(z39\.50|sru|srw|tcp)$/;
854 if ($tests{'port'}) {
855 push(@errors, 'port number is not valid') if $port !~ /^\d+$/;
858 if ($tests{'host'}) {
859 push(@errors, 'host name is not valid') if $host !~ /^[0-9a-z]+[0-9a-z\.\-]*\.[0-9a-z]+$/i;
862 if ($tests{'database'}) {
863 push(@errors, 'database name is not valid') if $dbname =~ m,/,i;
864 push(@errors, 'database has trailing spaces') if $dbname ne trimField($dbname);
867 if ($tests{'hosturl'}) {
868 my $hosturl = $xc->findnodes("i:status/i:hostURL") || "";
869 push(@errors, 'This hosturl name is not valid') if $hosturl !~ /^\w+$/i;
872 return ( !$#errors, \@errors );