From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CC6ADAC9A for ; Wed, 28 Jun 2023 12:06:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AE6C42112C for ; Wed, 28 Jun 2023 12:06:53 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 28 Jun 2023 12:06:53 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D6F3A40B11 for ; Wed, 28 Jun 2023 12:06:52 +0200 (CEST) Date: Wed, 28 Jun 2023 12:06:51 +0200 From: Stoiko Ivanov To: Mira Limbeck Cc: pmg-devel@lists.proxmox.com Message-ID: <20230628120651.21cff008@rosa.proxmox.com> In-Reply-To: <20230628085429.324086-1-m.limbeck@proxmox.com> References: <20230628085429.324086-1-m.limbeck@proxmox.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.24; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.096 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.rs] Subject: [pmg-devel] applied-series: [PATCH log-tracker 1/2] add compatibility with API/Tracking Center X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jun 2023 10:06:53 -0000 Thanks for addressing the issue so quickly and far cleaner than my RFC! Thanks also for the testing! quickly verified that it looks good on my test-system and applied with Dominik's R-b, T-b small nit I just realized after pushing - a mention of rfc3339/new syslogformat parsing in the commit subject or message would have been good. On Wed, 28 Jun 2023 10:54:28 +0200 Mira Limbeck wrote: > The API assumes the timestamps to be in the local timezone rather than > UTC. It then subtracts the timezone offset leading to wrong values when > timestamps are in UTC, but timezone is not. > > For compatibility, add the local timezone to those timestamps. > > Signed-off-by: Mira Limbeck > --- > src/main.rs | 43 ++++++++++++++++++++++++++++++++----------- > 1 file changed, 32 insertions(+), 11 deletions(-) > > diff --git a/src/main.rs b/src/main.rs > index e7bffd8..e55f17b 100644 > --- a/src/main.rs > +++ b/src/main.rs > @@ -1737,6 +1737,8 @@ struct Parser { > string_match: bool, > > lines: u64, > + > + timezone_offset: time_t, > } > > impl Parser { > @@ -1762,6 +1764,7 @@ impl Parser { > ctime: 0, > string_match: false, > lines: 0, > + timezone_offset: ltime.tm_gmtoff, > }) > } > > @@ -1836,7 +1839,12 @@ impl Parser { > let line = &buffer[0..size - 1]; > let complete_line = line; > > - let (time, line) = match parse_time(line, self.current_year, self.current_month) { > + let (time, line) = match parse_time( > + line, > + self.current_year, > + self.current_month, > + self.timezone_offset, > + ) { > Some(t) => t, > None => continue, > }; > @@ -1920,9 +1928,12 @@ impl Parser { > if size == 0 { > return count; > } > - if let Some((time, _)) = > - parse_time(&buffer[0..size], self.current_year, self.current_month) > - { > + if let Some((time, _)) = parse_time( > + &buffer[0..size], > + self.current_year, > + self.current_month, > + self.timezone_offset, > + ) { > // found the earliest file in the time frame > if time < self.options.start { > break; > @@ -1937,9 +1948,12 @@ impl Parser { > if size == 0 { > return count; > } > - if let Some((time, _)) = > - parse_time(&buffer[0..size], self.current_year, self.current_month) > - { > + if let Some((time, _)) = parse_time( > + &buffer[0..size], > + self.current_year, > + self.current_month, > + self.timezone_offset, > + ) { > if time < self.options.start { > break; > } > @@ -2235,11 +2249,17 @@ fn parse_number(data: &[u8], max_digits: usize) -> Option<(usize, &[u8])> { > } > > /// Parse time. Returns a tuple of (parsed_time, remaining_text) or None. > -fn parse_time(data: &'_ [u8], cur_year: i64, cur_month: i64) -> Option<(time_t, &'_ [u8])> { > - parse_time_with_year(data).or_else(|| parse_time_no_year(data, cur_year, cur_month)) > +fn parse_time( > + data: &'_ [u8], > + cur_year: i64, > + cur_month: i64, > + timezone_offset: time_t, > +) -> Option<(time_t, &'_ [u8])> { > + parse_time_with_year(data, timezone_offset) > + .or_else(|| parse_time_no_year(data, cur_year, cur_month)) > } > > -fn parse_time_with_year(data: &'_ [u8]) -> Option<(time_t, &'_ [u8])> { > +fn parse_time_with_year(data: &'_ [u8], timezone_offset: time_t) -> Option<(time_t, &'_ [u8])> { > let mut timestamp_buffer = [0u8; 25]; > > let count = data.iter().take_while(|b| **b != b' ').count(); > @@ -2266,7 +2286,8 @@ fn parse_time_with_year(data: &'_ [u8]) -> Option<(time_t, &'_ [u8])> { > match proxmox_time::parse_rfc3339(unsafe { > std::str::from_utf8_unchecked(×tamp_buffer[0..timestamp_len]) > }) { > - Ok(ltime) => Some((ltime, data)), > + // TODO handle timezone offset in old code path instead > + Ok(ltime) => Some((ltime + timezone_offset, data)), > Err(_err) => None, > } > }