From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
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) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 8B9949C60
 for <pmg-devel@lists.proxmox.com>; Mon, 26 Jun 2023 15:58:51 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 6E049297A9
 for <pmg-devel@lists.proxmox.com>; Mon, 26 Jun 2023 15:58:21 +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 <pmg-devel@lists.proxmox.com>; Mon, 26 Jun 2023 15:58:20 +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 A7B9E43D65;
 Mon, 26 Jun 2023 15:58:20 +0200 (CEST)
Message-ID: <608587cb-ee6a-4ddc-fbd6-29b90ea7abc4@proxmox.com>
Date: Mon, 26 Jun 2023 15:58:19 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Content-Language: en-US
To: Mira Limbeck <m.limbeck@proxmox.com>, pmg-devel@lists.proxmox.com
References: <20230626104142.519755-1-m.limbeck@proxmox.com>
From: Dominik Csapak <d.csapak@proxmox.com>
In-Reply-To: <20230626104142.519755-1-m.limbeck@proxmox.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.016 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 -
Subject: Re: [pmg-devel] [PATCH log-tracker 1/2] add support for bookworm
 syslog time format
X-BeenThere: pmg-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Mail Gateway development discussion
 <pmg-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pmg-devel/>
List-Post: <mailto:pmg-devel@lists.proxmox.com>
List-Help: <mailto:pmg-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 26 Jun 2023 13:58:51 -0000

One nit inline, but aside from that consider these two patches:

Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>

On 6/26/23 12:41, Mira Limbeck wrote:
> Adds `proxmox-time` as dependency to parse the timestamp
> 
> Since parse_rfc3339 can't handle microseconds, we try to remove the dot
> followed by 6 digits of microseconds before passing it to parse_rfc3339.
> 
> A fallback to the previous format is used when when it fails to parse
> the new format.
> 
> Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
> ---
>   Cargo.toml  |  1 +
>   src/main.rs | 36 ++++++++++++++++++++++++++++++++++++
>   2 files changed, 37 insertions(+)
> 
> diff --git a/Cargo.toml b/Cargo.toml
> index b484137..6d92253 100644
> --- a/Cargo.toml
> +++ b/Cargo.toml
> @@ -14,3 +14,4 @@ anyhow = "1"
>   clap = { version = "3.2.23", features = ["cargo"] }
>   flate2 = "1.0"
>   libc = "0.2"
> +proxmox-time = "1.1"
> diff --git a/src/main.rs b/src/main.rs
> index 20d8404..e7bffd8 100644
> --- a/src/main.rs
> +++ b/src/main.rs
> @@ -2236,6 +2236,42 @@ 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_with_year(data: &'_ [u8]) -> Option<(time_t, &'_ [u8])> {
> +    let mut timestamp_buffer = [0u8; 25];
> +
> +    let count = data.iter().take_while(|b| **b != b' ').count();

nit: wouldn't also a '.position(" ")' work?
could be a bit faster, since rust would not have to create another iterator?
(or maybe rust is smart enough to compile it out anyway?)

> +    if count != 27 && count != 32 {
> +        return None;
> +    }
> +    let (timestamp, data) = data.split_at(count);
> +    // remove whitespace
> +    let data = &data[1..];
> +
> +    // microseconds: .123456 -> 7 bytes
> +    let microseconds_idx = timestamp.iter().take_while(|b| **b != b'.').count();
> +
> +    // YYYY-MM-DDTHH:MM:SS
> +    let year_time = &timestamp[0..microseconds_idx];
> +    let year_time_len = year_time.len();
> +    // Z | +HH:MM | -HH:MM
> +    let timezone = &timestamp[microseconds_idx + 7..];
> +    let timezone_len = timezone.len();
> +    let timestamp_len = year_time_len + timezone_len;
> +    timestamp_buffer[0..year_time_len].copy_from_slice(year_time);
> +    timestamp_buffer[year_time_len..timestamp_len].copy_from_slice(timezone);
> +
> +    match proxmox_time::parse_rfc3339(unsafe {
> +        std::str::from_utf8_unchecked(&timestamp_buffer[0..timestamp_len])
> +    }) {
> +        Ok(ltime) => Some((ltime, data)),
> +        Err(_err) => None,
> +    }
> +}
> +
> +fn parse_time_no_year(data: &'_ [u8], cur_year: i64, cur_month: i64) -> Option<(time_t, &'_ [u8])> {
>       if data.len() < 15 {
>           return None;
>       }