From nobody Wed May 14 05:47:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525465780429479.6323457369789; Fri, 4 May 2018 13:29:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2ADA887633; Fri, 4 May 2018 20:29:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 81C2760930; Fri, 4 May 2018 20:29:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8B86E180BADA; Fri, 4 May 2018 20:29:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w44KLhAe013450 for ; Fri, 4 May 2018 16:21:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id B88FA20155E3; Fri, 4 May 2018 20:21:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B21ED20155E1 for ; Fri, 4 May 2018 20:21:41 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47D3C356C0 for ; Fri, 4 May 2018 20:21:40 +0000 (UTC) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w44KJvRI033871 for ; Fri, 4 May 2018 16:21:39 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hrtaghwm3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 04 May 2018 16:21:39 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 4 May 2018 14:21:39 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 4 May 2018 14:21:36 -0600 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w44KLatw11665836; Fri, 4 May 2018 13:21:36 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D0DE136043; Fri, 4 May 2018 14:21:36 -0600 (MDT) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP id 0081513603C; Fri, 4 May 2018 14:21:35 -0600 (MDT) From: Stefan Berger To: libvir-list@redhat.com Date: Fri, 4 May 2018 16:21:13 -0400 In-Reply-To: <1525465285-14102-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1525465285-14102-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18050420-0020-0000-0000-00000DDD26CD X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008970; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000258; SDB=6.01027522; UDB=6.00524878; IPR=6.00806655; MB=3.00020932; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-04 20:21:37 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18050420-0021-0000-0000-000061362745 Message-Id: <1525465285-14102-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-04_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805040185 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 04 May 2018 20:21:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 04 May 2018 20:21:40 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'stefanb@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.7 (RCVD_IN_DNSWL_LOW) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 02/14] util: Implement virStringFilterLines() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 04 May 2018 20:29:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Implement virStringFilterLines() that takes as an input a buffer with text and extracts each line that contains a given needle. The size of each re- turned line can be restricted and if it is restricted '...' will automa- tically be appended. Signed-off-by: Stefan Berger Reviewed-by: John Ferlan --- src/util/virstring.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virstring.h | 3 +++ 2 files changed, 65 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 15f367a..f1d91c7 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1499,3 +1499,65 @@ virStringParsePort(const char *str, =20 return 0; } + +/** + * virStringFilterLines: + * @input: input buffer with text + * @needle: the needle to search in each line + * @maxlinelen: maximum line length of each line in output buffer; + * 0 to not restrict + * + * Search for a given needle in each line of the input buffer and create + * an output buffer that contains only these line. + */ +char * +virStringFilterLines(char *input, const char *needle, size_t maxlinelen) +{ + char *sol =3D input; + char *eol; + char *buf =3D NULL; + size_t buflen =3D 1, llen; + const char *dots =3D "..."; + + while (*sol) { + eol =3D strchr(sol, '\n'); + if (eol) + *eol =3D 0; + + if (strstr(sol, needle)) { + size_t additional =3D 0; + + llen =3D strlen(sol); + if (maxlinelen && llen > maxlinelen) { + llen =3D maxlinelen; + additional =3D strlen(dots); + } + + if (VIR_REALLOC_N(buf, buflen + llen + additional + 1) < 0) { + VIR_FREE(buf); + if (*eol) + *eol =3D '\n'; + return NULL; + } + strncpy(&buf[buflen - 1], sol, llen); + buflen +=3D llen; + + if (additional) { + strncpy(&buf[buflen - 1], dots, additional); + buflen +=3D additional; + } + + strcpy(&buf[buflen - 1], "\n"); + buflen +=3D 1; + } + + if (eol) + *eol =3D '\n'; + else + break; + + sol =3D eol + 1; + } + + return buf; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index fa2ec1d..1fb9851 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -309,4 +309,7 @@ int virStringParsePort(const char *str, unsigned int *port) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; =20 +char *virStringFilterLines(char *input, const char *needle, size_t maxline= len) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + #endif /* __VIR_STRING_H__ */ --=20 2.5.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list