From patchwork Mon Jan 11 14:20:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 24896 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AA88D44B187 for ; Mon, 11 Jan 2021 16:27:12 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9275368AB37; Mon, 11 Jan 2021 16:27:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4994068A94D for ; Mon, 11 Jan 2021 16:27:06 +0200 (EET) Received: by mail-lf1-f53.google.com with SMTP id o13so38045468lfr.3 for ; Mon, 11 Jan 2021 06:27:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=frV/QRaMRNSWrWS14BL+iylbUykADSteUjP70EuUYRY=; b=khxEV6ztWb+rrctEq43yzqogN2RYXfuDPsFXFHws8hKsLPwW7B4Yvm6BjgGD+meqRw fv29q2XljUTYiFPPl1IP/UdqHY3wnnLHqhmU7n5Q4aNxAsYMwlQcKuqPGLrUqrXNTgng vATCeosWq/MNvDGvqWknHc4soV8xqqbyqi3ErW3a+g7CxwyFLrqqUkths0cDnKyEUPS+ xTUJPOWcNQpdKA0VlenO5Nll/PrblFK15c4e5ZbnqIKNtKo8jazYmOhCgy08/GuyWRlb aqPdsK6rg2Fujda+/nUrICh/JUpCjPFXhQO4fW1ctSoMmmmL7bpHUQQZOQVE/W2tSf+t dbSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=frV/QRaMRNSWrWS14BL+iylbUykADSteUjP70EuUYRY=; b=KJZsjZvlXj5UrTp3+K43iToO3IlyHtFGGYSHBMDWpklwm3MxLJVMdeZkQaJgWDJb22 /ha3MrbZfuhHk5gFuGON3tBEpluve6A/8YRH2YJjIDK48wS4PItBH0/a5ofXRjCPgvJU gjicsXzPQ2999rSNiYdhC7squ4sklmxquVzk74vouyWYjlLZFBnVmRlijPUg7mkSeiWp ljgawZluV3NTti+5aqmAfNW7NCODDEKuZx7oZ4mkR+9GQWEGtThy3fpkQnxsp8EkfdYB zL8IraXkjRkSmeXyyzZgMezPQCGDja+rLBh+Y3xu/MCLSVPrHDNafvRURaP57BEWMoce umCw== X-Gm-Message-State: AOAM532N9yRLhnIw8Ik6gFre16dM5qXboq0pbV6xuspJDw9/baSztd88 f/md7KYkvtzfqkzbnvxy0iRIgCPgOu4= X-Google-Smtp-Source: ABdhPJy7kkSIQWJUm/8Wb3TZGK2HXYOOs683qXuw1n4sW8Cj9+GWynoxYZDa24jojmpmZ0o1wIphAw== X-Received: by 2002:a2e:bc0e:: with SMTP id b14mr1492520ljf.212.1610374825875; Mon, 11 Jan 2021 06:20:25 -0800 (PST) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id n20sm3113081lfh.133.2021.01.11.06.20.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jan 2021 06:20:25 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Jan 2021 16:20:19 +0200 Message-Id: <20210111142020.24303-3-jeebjp@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210111142020.24303-1-jeebjp@gmail.com> References: <20210111142020.24303-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/3] ffprobe: switch to av_bprint_escape for XML escaping X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jan Ekström Signed-off-by: Jan Ekström --- fftools/ffprobe.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 3453aa09ff..b1fccad65e 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -1672,24 +1672,6 @@ static av_cold int xml_init(WriterContext *wctx) return 0; } -static const char *xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx) -{ - const char *p; - - for (p = src; *p; p++) { - switch (*p) { - case '&' : av_bprintf(dst, "%s", "&"); break; - case '<' : av_bprintf(dst, "%s", "<"); break; - case '>' : av_bprintf(dst, "%s", ">"); break; - case '"' : av_bprintf(dst, "%s", """); break; - case '\'': av_bprintf(dst, "%s", "'"); break; - default: av_bprint_chars(dst, *p, 1); - } - } - - return dst->str; -} - #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ') static void xml_print_section_header(WriterContext *wctx) @@ -1761,14 +1743,19 @@ static void xml_print_str(WriterContext *wctx, const char *key, const char *valu if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) { XML_INDENT(); + av_bprint_escape(&buf, key, NULL, AV_ESCAPE_MODE_XML, 0); printf("<%s key=\"%s\"", - section->element_name, xml_escape_str(&buf, key, wctx)); + section->element_name, buf.str); av_bprint_clear(&buf); - printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx)); + + av_bprint_escape(&buf, value, NULL, AV_ESCAPE_MODE_XML, 0); + printf(" value=\"%s\"/>\n", buf.str); } else { if (wctx->nb_item[wctx->level]) printf(" "); - printf("%s=\"%s\"", key, xml_escape_str(&buf, value, wctx)); + + av_bprint_escape(&buf, value, NULL, AV_ESCAPE_MODE_XML, 0); + printf("%s=\"%s\"", key, buf.str); } av_bprint_finalize(&buf, NULL);