Code

bugfix: bus - server - client communication
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 6 Feb 2008 15:04:04 +0000 (15:04 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 6 Feb 2008 15:04:04 +0000 (15:04 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8759 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-bus
gosa-si/gosa-si-client
gosa-si/gosa-si-server

index e69560e55e9d5f6965f59ca3f89663cdbdc50da5..f07bf9e6aae0701cc22a4ff827485b4afc9b09d7 100755 (executable)
@@ -108,7 +108,7 @@ sub daemon_log {
         chomp($msg);
         if($level && $verbose && $level <= $verbose){
             print LOG_HANDLE $msg."\n";
-            if(defined $foreground) { print $msg."\n" }
+            if(defined $foreground) { print STDERR $msg."\n" }
         }
     }
     close( LOG_HANDLE );
@@ -903,12 +903,18 @@ sub new_client {
     my $clients = $res->{1}->{clients};
 
     # if host has alread more clients, than just append
-    if( length($clients) != 0 ) {
-        $clients .= ",$new_client";
-    } else {
-        $clients = $new_client;
+    my @clients_l = split(',', $clients);
+    my @new_clients_l;
+    foreach my $act_client (@clients_l) {
+        if( $new_client eq $act_client ) {
+            # do nothing
+            next;
+        }
+        push(@new_clients_l, $act_client);
     }
-
+    push(@new_clients_l, $new_client);
+    $clients = join(",", @new_clients_l);
+    
     $sql_statement= "UPDATE bus_known_server SET clients='$clients' WHERE hostname='$source'";
     $bus_known_server_db->update_dbentry( $sql_statement );
     return;
index f89ef60b28e3a0aa9bfe97c984ad466f8e2f9137..fd36a5bbf7361f435f95a737af38c7558e6a31cd 100755 (executable)
@@ -1019,13 +1019,10 @@ sub server_input {
         }
         # postprocessing
         if( $answer =~ "<header>new_key</header>") {
-print STDERR "old key: $server_key\n";
             # set new key to global variable
             $answer =~ /<new_key>(\S*?)<\/new_key>/;
             my $new_key = $1;
             $server_key = $new_key;
-print STDERR "new key: $new_key\n";
-
         }
     }
 
index 777e5feee91739845c8e2f4a6ac725e2668ab4f0..a3764f4cdedf481179965270c7f6985acd88669c 100755 (executable)
@@ -744,72 +744,75 @@ sub client_input {
         # for each answer in answer list
         foreach my $answer ( @{$answer_l} ) {
 
+
+            
+
+
+            my $error = 0;
             # check answer if gosa-si envelope conform
-            if( $error == 0 ) {
-                my $answer_hash = $xml->XMLin($answer, ForceArray=>1);
-                $answer_header = @{$answer_hash->{'header'}}[0];
-                @answer_target_l = @{$answer_hash->{'target'}};
-                $answer_source = @{$answer_hash->{'source'}}[0];
-                if( !$answer_header ) {
-                    daemon_log('ERROR: module answer is not gosa-si envelope conform: no header', 1);
-                    daemon_log("\n$answer", 8);
-                    $error++;
-                }
-                if( 0 == length @answer_target_l ) {
-                    daemon_log('ERROR: module answer is not gosa-si envelope conform: no targets', 1);
-                    daemon_log("\n$answer", 8);
-                    $error++;
-                }
-                if( !$answer_source ) {
-                    daemon_log('ERROR: module answer is not gosa-si envelope conform: no source', 1);
-                    daemon_log("\n$answer", 8);
-                    $error++;
-                }
+            my $answer_hash = $xml->XMLin($answer, ForceArray=>1);
+            $answer_header = @{$answer_hash->{'header'}}[0];
+            @answer_target_l = @{$answer_hash->{'target'}};
+            $answer_source = @{$answer_hash->{'source'}}[0];
+            if( !$answer_header ) {
+                daemon_log('ERROR: module answer is not gosa-si envelope conform: no header', 1);
+                daemon_log("\n$answer", 8);
+                $error++;
+            }
+            if( 0 == length @answer_target_l ) {
+                daemon_log('ERROR: module answer is not gosa-si envelope conform: no targets', 1);
+                daemon_log("\n$answer", 8);
+                $error++;
+            }
+            if( !$answer_source ) {
+                daemon_log('ERROR: module answer is not gosa-si envelope conform: no source', 1);
+                daemon_log("\n$answer", 8);
+                $error++;
+            }
 
-                if( $error != 0 ) {
-                    next;
-                }
+            if( $error != 0 ) {
+                next;
+            }
 
-                # deliver msg to all targets 
-                foreach my $answer_target ( @answer_target_l ) {
-                    if( $answer_target eq "*" ) {
-                        # answer is for all clients
-                        my $sql_statement= "SELECT * FROM known_clients";
-                        my $query_res = $known_clients_db->select_dbentry( $sql_statement ); 
-                        while( my ($hit_num, $hit) = each %{ $query_res } ) {    
-                            my $host_name = $hit->{hostname};
-                            my $host_key = $hit->{hostkey};
-                            &send_msg_to_target($answer, $host_name, $host_key, $answer_header);
-                        }
+            # deliver msg to all targets 
+            foreach my $answer_target ( @answer_target_l ) {
+                if( $answer_target eq "*" ) {
+                    # answer is for all clients
+                    my $sql_statement= "SELECT * FROM known_clients";
+                    my $query_res = $known_clients_db->select_dbentry( $sql_statement ); 
+                    while( my ($hit_num, $hit) = each %{ $query_res } ) {    
+                        my $host_name = $hit->{hostname};
+                        my $host_key = $hit->{hostkey};
+                        &send_msg_to_target($answer, $host_name, $host_key, $answer_header);
                     }
-                    elsif( $answer_target eq "GOSA" ) {
-                        # answer is for GOSA and has to returned to connected client
-                        my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key);
-                        $client_answer = $gosa_answer;
-                    }
-                    elsif( $answer_target eq "KNOWN_SERVER" ) {
-                        # answer is for all server in known_server
-                        my $sql_statement= "SELECT * FROM known_server";
-                        my $query_res = $known_server_db->select_dbentry( $sql_statement ); 
-                        while( my ($hit_num, $hit) = each %{ $query_res } ) {    
-                            my $host_name = $hit->{hostname};
-                            my $host_key = $hit->{hostkey};
-                            $answer =~ s/KNOWN_SERVER/$host_name/g;
-                            &send_msg_to_target($answer, $host_name, $host_key, $answer_header);
-                        }
+                }
+                elsif( $answer_target eq "GOSA" ) {
+                    # answer is for GOSA and has to returned to connected client
+                    my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key);
+                    $client_answer = $gosa_answer;
+                }
+                elsif( $answer_target eq "KNOWN_SERVER" ) {
+                    # answer is for all server in known_server
+                    my $sql_statement= "SELECT * FROM known_server";
+                    my $query_res = $known_server_db->select_dbentry( $sql_statement ); 
+                    while( my ($hit_num, $hit) = each %{ $query_res } ) {    
+                        my $host_name = $hit->{hostname};
+                        my $host_key = $hit->{hostkey};
+                        $answer =~ s/KNOWN_SERVER/$host_name/g;
+                        &send_msg_to_target($answer, $host_name, $host_key, $answer_header);
                     }
-                    else {
-                        # answer is for one specific host
-                        # get encrypt_key
-                        my $encrypt_key = &get_encrypt_key($answer_target);
-                        if( !$encrypt_key ) {
-                            daemon_log("ERROR: no encrypt key found for answer target '$answer_target'", 1);
-                            daemon_log("\n$answer", 8);
-                            next;
-                        }
-                        # send_msg
-                        &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header);
+                }
+                else {
+                    # answer is for one specific host
+                    # get encrypt_key
+                    my $encrypt_key = &get_encrypt_key($answer_target);
+                    if( !$encrypt_key ) {
+                        daemon_log("ERROR: no encrypt key found for answer target '$answer_target'", 1);
+                        daemon_log("\n$answer", 8);
+                        next;
                     }
+                    # send_msg
+                    &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header);
                 }
             }
         }