X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-si%2Fmodules%2FGosaPackages.pm;h=d5a0a6b4b1f4f8abdef8c2a278e15df2c1948ba0;hb=54c3f50d1005ca05082fa3efe2a37caa12cb50d5;hp=747f93a955da077c1e4ec95ad8a529a3fb3b0115;hpb=49eb1ed27268cfe00ebf84de42762f16d8b64393;p=gosa.git diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 747f93a95..d5a0a6b4b 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -264,7 +264,7 @@ sub process_incoming_msg { my @msg_l; my @out_msg_l; - &main::daemon_log("DEBUG: GosaPackages: receive '$header'", 8); + &main::daemon_log("DEBUG: GosaPackages: msg to process '$header'", 7); if ($header =~ /^job_/) { @msg_l = &process_job_msg($msg, $msg_hash, $session_id); @@ -303,38 +303,36 @@ sub process_incoming_msg { sub process_gosa_msg { my ($msg, $msg_hash, $session_id) = @_ ; my $out_msg; - my @out_msg_l; + my @out_msg_l = ('nohandler'); my $header = @{$msg_hash->{'header'}}[0]; $header =~ s/gosa_//; - # decide wether msg is a core function or a event handler - if ( $header eq 'query_jobdb') { - @out_msg_l = &query_jobdb - } elsif ($header eq 'delete_jobdb_entry') { - @out_msg_l = &delete_jobdb_entry - } elsif ($header eq 'clear_jobdb') { - @out_msg_l = &clear_jobdb - } elsif ($header eq 'update_status_jobdb_entry' ) { - @out_msg_l = &update_status_jobdb_entry - } elsif ($header eq 'count_jobdb' ) { - @out_msg_l = &count_jobdb - } else { - # msg could not be assigned to core function - # maybe it is an eventa - if( exists $event_hash->{$header} ) { - # a event exists with the header as name - &main::daemon_log("found event '$header' at event-module '".$event_hash->{$header}."'", 5); - no strict 'refs'; - @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); - } + if( exists $event_hash->{$header} ) { + # a event exists with the header as name + &main::daemon_log("INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); + no strict 'refs'; + @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); + } + + # if incoming 'gosa_'-msg is scheduled from job_queue, than it contains xml-tag 'jobdb_id' + # after procesing this msg, set status of this job in job_queue to done + if ($msg =~ /(\d+)<\/jobdb_id>/) { + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='done' ". + "WHERE id='$1'"; + &main::daemon_log("DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("INFO: set job '$1' to status processed", 5); } # if delivery not possible raise error and return - if( not @out_msg_l ) { - &main::daemon_log("ERROR: GosaPackages: no event handler or core function defined for $header", 1); - } elsif( 0 == @out_msg_l) { - &main::daemon_log("ERROR: GosaPackages got not answer from event_handler $header", 1); + if( not defined $out_msg_l[0] ) { + &main::daemon_log("WARNING: GosaPackages got no answer from event handler '$header'", 3); + @out_msg_l = (); + } elsif( $out_msg_l[0] eq 'nohandler') { + &main::daemon_log("ERROR: GosaPackages: no event handler or core function defined for '$header'", 1); + @out_msg_l = (); } return @out_msg_l; @@ -359,6 +357,8 @@ sub process_job_msg { my $macaddress; if( exists $msg_hash->{'macaddress'} ) { $macaddress = @{$msg_hash->{'macaddress'}}[0]; + } elsif (@{$msg_hash->{'target'}}[0] =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ) { + $macaddress = $1; } else { $error ++; $out_msg = "". @@ -366,7 +366,7 @@ sub process_job_msg { "$server_address". "GOSA". "1". - "no mac address specified". + "no mac address specified, neither in target-tag nor in macaddres-tag". ""; } @@ -400,142 +400,6 @@ sub process_job_msg { return @out_msg_l; } - - -## CORE FUNCTIONS ############################################################ - -sub query_jobdb { - my ($msg) = @_; - my $msg_hash = &transform_msg2hash($msg); - my $target = @{$msg_hash->{'target'}}[0]; - my $source = @{$msg_hash->{'source'}}[0]; - - # prepare query sql statement - my $select= &get_select_statement($msg, $msg_hash); - my $table= $main::job_queue_tn; - my $where= &get_where_statement($msg, $msg_hash); - my $limit= &get_limit_statement($msg, $msg_hash); - my $orderby= &get_orderby_statement($msg, $msg_hash); - my $sql_statement= "SELECT $select FROM $table $where $orderby $limit"; - - # execute db query - my $res_hash = $main::job_db->select_dbentry($sql_statement); - my $out_xml = &db_res2si_msg($res_hash, "query_jobdb", $target, $source); - - my @out_msg_l = ( $out_xml ); - return @out_msg_l; -} - - -sub count_jobdb { - my ($msg)= @_; - my $out_xml= "error"; - - # prepare query sql statement - my $table= $main::job_queue_tn; - my $sql_statement= "SELECT * FROM $table "; - - # execute db query - my $res_hash = $main::job_db->select_dbentry($sql_statement); - - my $count = keys(%{$res_hash}); - $out_xml= "
answer
$server_addressGOSA$count
"; - my @out_msg_l = ( $out_xml ); - return @out_msg_l; -} - - -sub delete_jobdb_entry { - my ($msg) = @_ ; - my $msg_hash = &transform_msg2hash($msg); - - # prepare query sql statement - my $table= $main::job_queue_tn; - my $where= &get_where_statement($msg, $msg_hash); - my $sql_statement = "DELETE FROM $table $where"; - - # execute db query - my $db_res = $main::job_db->del_dbentry($sql_statement); - - my $res; - if( $db_res > 0 ) { - $res = 0 ; - } else { - $res = 1; - } - - # prepare xml answer - my $out_xml = "
answer
$server_addressGOSA$res
"; - my @out_msg_l = ( $out_xml ); - return @out_msg_l; - -} - - -sub clear_jobdb { - my ($msg) = @_ ; - my $msg_hash = &transform_msg2hash($msg); - my $error= 0; - my $out_xml= "1"; - - my $table= $main::job_queue_tn; - - my $sql_statement = "DELETE FROM $table"; - my $db_res = $main::job_db->del_dbentry($sql_statement); - if( not $db_res > 0 ) { $error++; }; - - if( $error == 0 ) { - $out_xml = "
answer
$server_addressGOSA0
"; - } - my @out_msg_l = ( $out_xml ); - return @out_msg_l; -} - - -sub update_status_jobdb_entry { - my ($msg) = @_ ; - my $msg_hash = &transform_msg2hash($msg); - my $error= 0; - my $out_xml= "
answer
$server_addressGOSA1
"; - - my @len_hash = keys %{$msg_hash}; - if( 0 == @len_hash) { $error++; }; - - # prepare query sql statement - if( $error == 0) { - my $table= $main::job_queue_tn; - my $where= &get_where_statement($msg, $msg_hash); - my $update= &get_update_statement($msg, $msg_hash); - - # conditions - # no timestamp update if status eq waiting - my $res_hash = $main::job_db->select_dbentry("SELECT * FROM $table $where AND status='processing' "); - if( (0 != keys(%$res_hash)) && ($update =~ /timestamp/i) ) { - $error ++; - $out_xml = "1there is no timestamp update allowed while status is 'processing'"; - } - - if( $error == 0 ) { - my $sql_statement = "UPDATE $table $update $where"; - # execute db query - my $db_res = $main::job_db->update_dbentry($sql_statement); - - # check success of db update - if( not $db_res > 0 ) { $error++; }; - - } - } - - if( $error == 0) { - $out_xml = "0"; - } - - my $out_msg = sprintf("
answer
%sGOSA%s
", $server_address, $out_xml); - my @out_msg_l = ( $out_msg ); - return @out_msg_l; -} - - 1;