Fix a theoretical memory leak in a cannot-realistically-happen situation in rfc2553_c...
[privoxy.git] / tools / uagen.pl
index d29ba90..b865320 100755 (executable)
@@ -3,7 +3,7 @@
 ##############################################################################################
 # uagen (http://www.fabiankeil.de/sourcecode/uagen/)
 #
-# $Id: uagen.pl,v 1.62 2009/12/23 17:20:19 fk Exp fk $
+# $Id: uagen.pl,v 1.10 2010/12/11 15:54:30 fabiankeil Exp $
 #
 # Generates a pseudo-random Firefox user agent and writes it into a Privoxy action file
 # and optionally into a Mozilla prefs file. For documentation see 'perldoc uagen(.pl)'.
@@ -56,9 +56,9 @@ use constant {
    # are too lazy to check, but want to change them anyway, take the values you
    # see in the "Help/About Mozilla Firefox" menu.
 
-   BROWSER_VERSION                   => "3.5.6",
-   BROWSER_REVISION                  => '1.9.1.6',
-   BROWSER_RELEASE_DATE              => '20091217',
+   BROWSER_VERSION                   => "3.6.15",
+   BROWSER_REVISION                  => '1.9.2.15',
+   BROWSER_RELEASE_DATE              => '20110305',
 };
 
 use constant LANGUAGES => qw(
@@ -94,12 +94,12 @@ sub generate_creation_time($) {
     die "release day in the future"
       if (  ( $year == $rel_year )
         and ( $mon  == $rel_mon )
-        and ( $mday  < $rel_day ) );    
+        and ( $mday  < $rel_day ) );
 
     my @c_time = (0, 0, 0, $rel_day, $rel_mon - 1, $rel_year - 1900, 0, 0, 0);
     my $c_seconds = &timelocal( @c_time );
 
-    $c_seconds = $now - (int rand ($now - $c_seconds)); 
+    $c_seconds = $now - (int rand ($now - $c_seconds));
     @c_time = localtime $c_seconds;
     ($sec, $min, $hour, $c_day, $c_mon, $c_year, $wday, $yday, $isdst) = @c_time;
     $c_mon  += 1;
@@ -232,10 +232,9 @@ sub log_to_file($) {
 
     return if $no_logging;
 
-    open( LOGFILE, ">>" . $logfile ) || die "Writing " . $logfile . " failed";
-    printf LOGFILE UAGEN_VERSION . " ($logtime) $message\n";
-    close(LOGFILE);
-
+    open(my $log_fd, ">>" . $logfile) || die "Writing " . $logfile . " failed";
+    printf $log_fd UAGEN_VERSION . " ($logtime) $message\n";
+    close($log_fd);
 }
 
 sub log_error($) {
@@ -260,14 +259,14 @@ sub write_action_file() {
     my $action_file_content = '';
 
     if ($action_injection){
-        open( ACTIONFILE, $action_file )
+        open(my $actionfile_fd, "<", $action_file)
             or log_error "Reading action file $action_file failed!";
-        while (<ACTIONFILE>) {
+        while (<$actionfile_fd>) {
             s@(hide-accept-language\{).*?(\})@$1$accept_language$2@;
             s@(hide-user-agent\{).*?(\})@$1$user_agent$2@;
            $action_file_content .= $_;
         }
-        close (ACTIONFILE);
+        close($actionfile_fd);
     } else {
        $action_file_content = "{";
        $action_file_content .= sprintf "+hide-accept-language{%s} \\\n",
@@ -275,10 +274,10 @@ sub write_action_file() {
         $action_file_content .= sprintf " +hide-user-agent{%s} \\\n}\n/\n",
             $user_agent;
     }
-    open( ACTIONFILE, ">" . $action_file )
+    open(my $actionfile_fd, ">" . $action_file)
       or log_error "Writing action file $action_file failed!";
-    print ACTIONFILE $action_file_content;
-    close(ACTIONFILE);
+    print $actionfile_fd $action_file_content;
+    close($actionfile_fd);
 
     return 0;
 }
@@ -289,16 +288,18 @@ sub write_prefs_file() {
     our $user_agent;
     our $accept_language;
     our $clean_prefs;
+
     my $prefs_file_content = '';
+    my $prefsfile_fd;
 
-    if (open( PREFSFILE, $mozilla_prefs_file )) {
+    if (open($prefsfile_fd, $mozilla_prefs_file)) {
 
-        while (<PREFSFILE>) {
+        while (<$prefsfile_fd>) {
             s@user_pref\(\"general.useragent.override\",.*\);\n?@@;
             s@user_pref\(\"intl.accept_languages\",.*\);\n?@@;
            $prefs_file_content .= $_;
         }
-        close (PREFSFILE);
+        close($prefsfile_fd);
     } else {
         log_error "Reading prefs file $mozilla_prefs_file failed. Creating a new file!";
     }
@@ -308,10 +309,10 @@ sub write_prefs_file() {
         sprintf("user_pref(\"intl.accept_languages\", \"%s\");\n", $accept_language)
         unless $clean_prefs;
 
-    open( PREFSFILE, ">" . $mozilla_prefs_file )
+    open($prefsfile_fd, ">" . $mozilla_prefs_file)
       or log_error "Writing prefs file $mozilla_prefs_file failed!";
-    print PREFSFILE $prefs_file_content;
-    close(PREFSFILE);
+    print $prefsfile_fd $prefs_file_content;
+    close($prefsfile_fd);
 
 }
 
@@ -526,7 +527,7 @@ B<--sleeping-time> I<minutes> Time to sleep. Only effective if used with B<--loo
 
 B<--silent> Don't print the generated User-Agent to the console.
 
-B<--version> Print version and exit.  
+B<--version> Print version and exit.
 
 The second dash is optional, options can be shortened, as long as there are
 no ambiguities.