+sub cgi_get_caller () {
+ my $caller= $ENV{'REMOTE_ADDR'};
+ $caller= 'LOCAL' unless defined $caller;
+
+ my $fwdf= $ENV{'HTTP_X_FORWARDED_FOR'};
+ if (defined $fwdf) {
+ $fwdf =~ s/\s//g;
+ $fwdf =~ s/[^0-9.,]/?/g;
+ $caller= "$fwdf";
+ }
+ return $caller;
+}
+
+sub set_ctype_utf8 () {
+ setlocale(LC_CTYPE, "en.UTF-8");
+}
+
+sub http_useragent_string_map ($$) {
+ my ($caller_lib_agent, $reason_style_or_caller) = @_;
+ $caller_lib_agent =~ y/A-Za-z/N-ZA-Mn-za-m/;
+ $caller_lib_agent =~ s/\s/_/g;
+ my $version= version_core();
+ return "yarrg/$version ($reason_style_or_caller)".
+ " $caller_lib_agent".
+ " (http://yarrg.chiark.net/intro)";
+}
+
+sub http_useragent ($) {
+ my ($who) = @_;
+ my $ua= LWP::UserAgent->new;
+ my $base= $ua->_agent();
+ $ua->agent(http_useragent_string_map($base, $who));
+ return $ua;
+}
+