Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp394545lqs; Tue, 5 Mar 2024 05:30:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU3CuiwK4YmTEJacsFepFsRjL7kOG6FL3hxJLYo2BC5LIAI2LxOiPJ/cnDwyf6M2YzjSghSz8NfzU+mSy8jwV/f+kiIrFLpugKgq8Ruig== X-Google-Smtp-Source: AGHT+IFSvP9fcWv14xdWvdCTNjK0iTNI8KIuocg2GV3L0+Z4nWUAgLIf8pDAguWPbNh+QNCkCkJS X-Received: by 2002:a05:6a00:4fce:b0:6e5:64cd:8f52 with SMTP id le14-20020a056a004fce00b006e564cd8f52mr15245734pfb.0.1709645410356; Tue, 05 Mar 2024 05:30:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709645410; cv=pass; d=google.com; s=arc-20160816; b=mEMHKkOOf6474YYCkO3lUi5p0UXjTt5GYUXnEODMSPTsS8a7GBDP6tyrDKd/XtT874 crgqvURUHZtFKgzmNsCugmyjL/sxQmR8aEb+yX9QrKWnds4KBeYwyrE38ISfdWwsy/Qb CMIE891bdZyD7+w5kiKAvmKPaY/wC/+wOB6EJLeOi/5XF3XPBhacFVj4NDUYxrXjXXFJ Bc/tX6v2zAbPVKYGace1e7D1R8TtoszFcNnKL3LVODk8YdGydn8+YRHUvsJ1Bu5/LHJj SSLJ00VYtSFpGCjBnvlD8JpcwWivm4yxWycohA1iqOok3u+oIyGdrGDKAIdt1Ga1W8z4 LrfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=oM/6F5z2fYXlwIh94EnOG8p4ZsVBItKx2EQBTXjGYvw=; fh=+1Udz8LsdqvxEUhwSl+pzs/+zW2GFZvOismtMWZ6snI=; b=BjV/hkqluoraLoCekyXK5XSn+ur175QkxJCzE2lSs4fi8zwdY6+lfD3VKVu6v8rQHQ 4Y/vdJdFfZGQu/68Im1CTq5KyVBuAOQT/EnLmtXogAppYYOtiCZtGqheTe4njtZ07OjB BKYjmrV1b8QFMEobHQ1Tjg9zU0j6/ml4/V6PmtIc0/XUeoIm6i39EycyqvsS0ILAUNeC fy+UXL8U0/jOR9GdDoTsuj+f1WFkMc5lok2vwrF4fYBLryNR14CXMdPl7RhjUkIqEVVs BM5xjsvRbuUQv8LWZhF6SFNP9njC6FgbMnn2z6xJ0RFgGcaAmanNlPrW9rtgf8T3fGr5 pBSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=IpdsbcIa; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-wireless+bounces-4379-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ea28-20020a056a004c1c00b006e6396391c1si1342116pfb.14.2024.03.05.05.30.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 05:30:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-4379-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=IpdsbcIa; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-wireless+bounces-4379-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0F873284CB4 for ; Tue, 5 Mar 2024 13:30:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0F5E85C5E; Tue, 5 Mar 2024 13:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="IpdsbcIa" X-Original-To: linux-wireless@vger.kernel.org Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F0B485920 for ; Tue, 5 Mar 2024 13:29:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709645400; cv=none; b=TBVHADE3bp2ZYGLeJyxqheDz5RfdR6uhzDfPmeNp0h4ZMW3yZotjEnAxVksTaX2C7uMDy7LpzGg/X0EvfOng0eQO4opKyUFFQo3rmMjkHfKIrm7kBm+gES/orT+t70vZsaEY1g/DY8/Tg7eAy+bw6bXugPHV+eeyFSvMNsheVuU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709645400; c=relaxed/simple; bh=RQq3gw9l2rvTVH2sYD6OTuNsWh+GiAYjPHJiMfUqsMU=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=PEh/uMSScRGa5uM0Tu4kQIgNFwHbFx0W7oeYIV9lDnQR1IGtWr2ILMmsPF8Wsi0ZbGLlZRNZktlTtg7iJJVozzzv/onnF3kdfdjFJDZbD/Y0MU4300GU1sOl89HpQIYehUDKDYVoT4a0Q4rq3jkBW8kAewJpB+Jln3OSC1FarzQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=IpdsbcIa; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=MIME-Version:Content-Transfer-Encoding: Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=oM/6F5z2fYXlwIh94EnOG8p4ZsVBItKx2EQBTXjGYvw=; t=1709645398; x=1710854998; b=IpdsbcIaA6aGUz6/QLjEnoCpdwTB2O+VcHB3MHitEQyn0Th GKRHge24ZEqhsSxcs8gRjsnSSeK0xEGlsk/9ADeWwqxNZKAeFv266w2GCjrh0/wiwOdPQboIYCPor glVHY0YXhK+fFWS/vB+w9O7uhMGfYeEm0ill29tFclPOpl849FOUcr/f+mQf2GuWrQ9JxQ8jfH89I rDAebb3krAEED3UOgO6ayAxnqSi6X6F4VVrCVihXUE1bJ2tlvazRiy6TNgz+TrG3phUaakKkD6LRW QEznOd8JxTRV7eHUgWWauDnRvAO611Wyp3RU2KQvDovnR8LXU2/k7/ZUGNNbJG+w==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1rhUrk-00000002ohe-0LoQ; Tue, 05 Mar 2024 14:29:56 +0100 Message-ID: <172b85b1166c2f026df396ee4dabc3cbb2c300f9.camel@sipsolutions.net> Subject: Re: [PATCH v5] Add JSON output options to 'iw' for scan results From: Johannes Berg To: Isaev Ruslan Cc: Nicolas Escande , linux-wireless@vger.kernel.org Date: Tue, 05 Mar 2024 14:29:55 +0100 In-Reply-To: References: <5c5be485dcfceb44fc731e47758d6be3.legale.legale@gmail.com> <12f91b008d6f2b4e6241794d2852c1c84fe6c12c.camel@sipsolutions.net> <37398c88130c487be656eed4e378d6b047a3d612.camel@sipsolutions.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.4 (3.50.4-1.fc39) Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-malware-bazaar: not-scanned On Tue, 2024-03-05 at 14:32 +0300, Isaev Ruslan wrote: >=20 > I think i could make a universal printf() like function with > additional args for json representation. >=20 > Something like this: > before: > printf("\t * Manufacturer: %.*s\n", sublen, data + 4); >=20 > after: > printf_json("\t * Manufacturer", "%.*s", sublen, data + 4); I think you meant printf_json("Manufacturer", "%.*s", sublen, data + 4); but yeah, that seems better? Not sure I'd call it print_json() over just print() or output() or so at that point. > void printf_json(const char* key, const char* fmt, ...) { > char buf[1024]; > va_list args; > va_start(args, format); >=20 > if (iw_json) { > vsnprintf(buf, sizeof(buf), format, args); > print_string(PRINT_JSON, key, "%s", buf); > } else { > printf("\t * %s: ", key); Guess we'd have to be careful about the indentation. Track the (JSON) object nesting level and apply it that way? johannes