From patchwork Sat Jun 15 19:11:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Glembotzki X-Patchwork-Id: 1948198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=OETpa/W/; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=SXbZFJti; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::43f; helo=mail-wr1-x43f.google.com; envelope-from=swupdate+bncbdy5juxlviebb4osw6zqmgqe4swcxxi@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-wr1-x43f.google.com (mail-wr1-x43f.google.com [IPv6:2a00:1450:4864:20::43f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W1mFK578kz20Pb for ; Sun, 16 Jun 2024 05:20:21 +1000 (AEST) Received: by mail-wr1-x43f.google.com with SMTP id ffacd0b85a97d-35f251f1c23sf275919f8f.3 for ; Sat, 15 Jun 2024 12:20:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718479219; cv=pass; d=google.com; s=arc-20160816; b=p0htXoI/nu3nggeyyS9BtjgJu1Jnxewwo2X9Oue8ASxyvDX/ChzlXIeEM+SAnxvocq 0T1xYFHHi40vX18rS6AsVb/hXThQBMgzG0oX/4gUVWGpN1K5bjJH21ha6XV1khbzvAAw wXsP+MVN9mvlAbnUt9vv6MlQII/1QQ0NTtHauBldDlxgopiGV90DF2MAkqon1w9lGCrV 2ti7fOFeNVUybNENBTpNViiGucP+UyHQkh9Vm9PlpWAnMFNH+DVgDgdbQzlNf/Nq8nKk e1t2hABr1MQy/rIgTt+4oQv7EdeQh4orX2zXKOMDYUYB3F2hZjDlB+ky7lyzs/t6Wb/Q iXFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature :dkim-signature; bh=tbepqBBjfLAnEYu7yhhcokYd3QGtFdMuTUbVM5Nu1eg=; fh=4+iP71D8wM9HbCF0qgizbpQH5Bgu56A1666mWYct1dg=; b=W6sBd80ZEVWLbJEOA4H5zJNUmhN6G17Qz2Oe5HRfIgmDScpmIdI8CUKHJ2N5Kyc9Cw pFBtlgypFqw+ikFtDHNOm9IDmvS+Xg5VUhOpyw+RSwbkc4VOx/sY743QIne9UHGfGHE7 fgDCWeC8GmAgHFAIdN2irbEaBMr4S1xqwxHe0fN/cBnkxkcEBxndd/5OEzQcG/MJv3pr U0IVdYmfGAuUqgUFIkZ0D2Eac5l8OMMU/oBHczIpcvcH6wjiA9CoWHQlYOzGf9kb92rq wgtMXNvTDGe/Weud+brxd2EkZTDI6I1jY8Pdx3BJgDYJcjD+DAN8R0AnactSYZy4kOey Gtvw==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=em6Pn4lB; spf=pass (google.com: domain of m.glembo@gmail.com designates 2a00:1450:4864:20::630 as permitted sender) smtp.mailfrom=m.glembo@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1718479219; x=1719084019; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=tbepqBBjfLAnEYu7yhhcokYd3QGtFdMuTUbVM5Nu1eg=; b=OETpa/W/snXDuAMbQ8e+CsvTAANpPmgTVzZK05VEdVVotYhNqWvUe7HukCfv6l+6VE MGWYklV0zoK3R0n/xfp9rnzWfNDIZBFtagPA0AEEHweo/aQP9t6LKUuDoTNl5yt/8qkF igTXKwEWiiGDamZIckG2YBLv+a2+vyIIvwp9mw+vC8abHeJ2ydtFcRiWXxX6XGwW1h+Z cTdvNMpNyXi7jnEDFclHGcyxYBtez4I0soXoH/x7ycvDjhTOKUgb29iV2K7rJ1vaeo/4 vu5PRpjKtDsjeULyAdcNhQGr9OR9QIiuu2/OlX+ZkrAt1ssYADAAl73dSUDUSw0heDH2 UBZg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718479219; x=1719084019; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=tbepqBBjfLAnEYu7yhhcokYd3QGtFdMuTUbVM5Nu1eg=; b=SXbZFJtiy3TU8C2J8swkAwa81bApc0qZg4Ytfuozht2r9g7HqnOUs2KxaI7H962E4b e53rPULeO3zcrgiDmajUTCHujw4VfygmYUrdLPObxjJYa0EhheSbLdIojThL+5XQALdG 0/fjpJ5zbnjp8IcXdGXZLO0kwuRv6DqnvFykZteOp/h+PLr08lcXPzUW2J7XOxYJnImL BnXJrRBN51/TJv3/AeB9885fNFUzEEoKZ9mb2iObaGS0nGdTINCNWWAfI79GvsSgIkg9 Fch2C7aL7fSpB7Wg7HGxzTVdVmlmt4zvs/Ilnzl2v1FSNwjWFFBN0zkS1WLMiKkH2NtK YRSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718479219; x=1719084019; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=tbepqBBjfLAnEYu7yhhcokYd3QGtFdMuTUbVM5Nu1eg=; b=wYMe83LubXKD6Vz32WOPbi363rrz625mB1eqCLv4V3bdkO1LxQ09stEZtvkvVZ555+ kp3q+1Mi1bpobZFBn/ICH7g6utQNuRDDIldqX7ijx2C/78WbcqXIWnwhCK9qbRwJ9tLI U1yMRgo1NS0Cr8tzegThGSgUZtGFIsRDbap0faP2JB2bniYAQpE23v/58bEOqT7aRHUq ti1qcoZ0cK3/mzlwObCtgqrSdVtwLV5WukEBjFiRmdrtZa1l/nkJ8s1wiGmKMfTD5Nx5 g+6g9Q5K6iFUJ5yhc4oCz+qE1IVWaoeLKFseBa7jDEZQ13edkrbre9N5YnmsTMDn88Py wriw== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCVItH2aBK3Ak481Dbu6NAbpYSn7zgGVfQjTfe15kWRx3X384brnpLU/baLmtypMaU+qwxrkxUcmYJhT7ZBUd/GGi5Dgkf2+TzjpIrupPw== X-Gm-Message-State: AOJu0YxdVIUGHNwNU1EJ38Vyr3zujzG02da65tZoXqbP1BlqMx287CBB B60aMfuVSUjCF5XJ22Wg+uS8dsiuPJOZrPoBi/MOb1PQCcLxo791 X-Google-Smtp-Source: AGHT+IHISpcLoEqU5eLP2rg39Kom2bSAJyccGjBdISbGrL0WxuKQ2SPI7aR49KigMhRFZWWYN3K1Qw== X-Received: by 2002:a05:600c:3ba3:b0:422:78c:82f6 with SMTP id 5b1f17b1804b1-42304859b63mr45381855e9.3.1718479217942; Sat, 15 Jun 2024 12:20:17 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:600c:4f83:b0:421:7e41:1867 with SMTP id 5b1f17b1804b1-422b6dc6f7als12022465e9.0.-pod-prod-08-eu; Sat, 15 Jun 2024 12:20:15 -0700 (PDT) X-Received: by 2002:a7b:c8cb:0:b0:421:7c64:6f3d with SMTP id 5b1f17b1804b1-42304828f2amr66506965e9.16.1718479215051; Sat, 15 Jun 2024 12:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718479215; cv=none; d=google.com; s=arc-20160816; b=m53Lc0U6qdQmJaBkPdXHqa8mgeLrD45qDXNMHTQ3fm8iA09W1Khmz3CWqYYWhWX+aR c27pYmN0wtEpByU5POIoLYD7mmKc/YNR+jcD+NX+LqIUtqDYayaSYzyg8AEL5u4vYOYr SIRNHsXyQOBxpf6eG53OzzMMWbAwm2/xkfw3RkMv1VvbR+/ycWHaoRvErweE+nDo6mFT a8BeG06g1XKTZMMtNV1Ewz9bojrv+kWq8f6Xhhm1ma8+F5vbMQKiIY9Lc2BLJYiQHJvx fjH3xwWRpX25kPWdUY4m3iUVQWFLRPxBKLgDCH9CzNYw4S63IPYLGsZK5bDTMFoAeGF6 uNvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=sJ6UmDPhjUyBL5PpGALKMi6wsPtB4jLbjruHPVc1T5w=; fh=zydHuzCQWrku2OPQyZfraJZFcOpEXLQ/YBcu3QNiBd0=; b=Q7qnt05FmgF4vtmuMfJ+BNyOvYAf0dVXEDFtMzpVx/ciJto3gfDMt//smI2n+G29uD UkwT+NyJFgmttd0SSdpeSaLYs3YyAkA7Wtx6u70SxfsjFbAEWQ9ihqF0/BG148S1SwY7 3XqNYw8Oq/ygux6+SRlNAcFR+eouP1wpkBj7oHt9dY8EmJbyjkrB8WXgPJQDNsoS0hEz p8hONzrb8auRKpkAx2bEFxYKq+UO/Cu44xsMQqSvT0Luqt2Ryu/1rGS2Gx0I+Oqxr5YN Xob6bD0nTXtj+3BtmS0OcYzNeQDfVCoEMVV3jRVmHOlipSLnF7fVUIZxB8qSGalmgEd8 u9IA==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=em6Pn4lB; spf=pass (google.com: domain of m.glembo@gmail.com designates 2a00:1450:4864:20::630 as permitted sender) smtp.mailfrom=m.glembo@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com. [2a00:1450:4864:20::630]) by gmr-mx.google.com with ESMTPS id 5b1f17b1804b1-42284b090dfsi6260155e9.0.2024.06.15.12.20.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 15 Jun 2024 12:20:15 -0700 (PDT) Received-SPF: pass (google.com: domain of m.glembo@gmail.com designates 2a00:1450:4864:20::630 as permitted sender) client-ip=2a00:1450:4864:20::630; Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a6f04afcce1so410970266b.2 for ; Sat, 15 Jun 2024 12:20:15 -0700 (PDT) X-Received: by 2002:a17:906:d1cf:b0:a6f:4ba4:c389 with SMTP id a640c23a62f3a-a6f60d13b0fmr442526866b.16.1718479214226; Sat, 15 Jun 2024 12:20:14 -0700 (PDT) Received: from PC-2635.irisgmbh.local ([2a02:8108:96c0:76fc::80bb]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56db61e0sm327283766b.49.2024.06.15.12.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 12:20:13 -0700 (PDT) From: Michael Glembotzki To: swupdate@googlegroups.com Cc: Michael Glembotzki Subject: [swupdate] [PATCH 03/21] mongoose: Backport: bring mg_strdup() back from master Date: Sat, 15 Jun 2024 21:11:16 +0200 Message-ID: <20240615191941.40301-4-Michael.Glembotzki@iris-sensing.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240615191941.40301-1-Michael.Glembotzki@iris-sensing.com> References: <20240615191941.40301-1-Michael.Glembotzki@iris-sensing.com> MIME-Version: 1.0 X-Original-Sender: m.glembo@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=em6Pn4lB; spf=pass (google.com: domain of m.glembo@gmail.com designates 2a00:1450:4864:20::630 as permitted sender) smtp.mailfrom=m.glembo@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , mg_strdup was deprecated in 7.14, but was brought back in ab75bfa6. mongoose rev-id: ab75bfa6e70a6985becf1eed912f93ba668be363 Signed-off-by: Michael Glembotzki --- mongoose/mongoose.c | 20 ++++++++++++++++---- mongoose/mongoose.h | 5 +++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/mongoose/mongoose.c b/mongoose/mongoose.c index 1768bf70..44066893 100644 --- a/mongoose/mongoose.c +++ b/mongoose/mongoose.c @@ -6633,8 +6633,7 @@ void mg_rpc_add(struct mg_rpc **head, struct mg_str method, void (*fn)(struct mg_rpc_req *), void *fn_data) { struct mg_rpc *rpc = (struct mg_rpc *) calloc(1, sizeof(*rpc)); if (rpc != NULL) { - rpc->method.buf = mg_mprintf("%.*s", method.len, method.buf); - rpc->method.len = method.len; + rpc->method = mg_strdup(method); rpc->fn = fn; rpc->fn_data = fn_data; rpc->next = *head, *head = rpc; @@ -8048,6 +8047,20 @@ int mg_casecmp(const char *s1, const char *s2) { return diff; } +struct mg_str mg_strdup(const struct mg_str s) { + struct mg_str r = {NULL, 0}; + if (s.len > 0 && s.buf != NULL) { + char *sc = (char *) calloc(1, s.len + 1); + if (sc != NULL) { + memcpy(sc, s.buf, s.len); + sc[s.len] = '\0'; + r.buf = sc; + r.len = s.len; + } + } + return r; +} + int mg_strcmp(const struct mg_str str1, const struct mg_str str2) { size_t i = 0; while (i < str1.len && i < str2.len) { @@ -10605,8 +10618,7 @@ static int mg_parse_pem(const struct mg_str pem, const struct mg_str label, const char *c; struct mg_str caps[5]; if (!mg_match(pem, mg_str("#-----BEGIN #-----#-----END #-----#"), caps)) { - der->buf = mg_mprintf("%.*s", pem.len, pem.buf); - der->len = pem.len; + *der = mg_strdup(pem); return 0; } if (mg_strcmp(caps[1], label) != 0 || mg_strcmp(caps[3], label) != 0) { diff --git a/mongoose/mongoose.h b/mongoose/mongoose.h index b59e2b06..6b71240f 100644 --- a/mongoose/mongoose.h +++ b/mongoose/mongoose.h @@ -186,7 +186,7 @@ extern "C" { #define calloc(a, b) mg_calloc(a, b) #define free(a) vPortFree(a) #define malloc(a) pvPortMalloc(a) -#define strdup(s) mg_mprintf("%s", s) +#define strdup(s) ((char *) mg_strdup(mg_str(s)).buf) // Re-route calloc/free to the FreeRTOS's functions, don't use stdlib static inline void *mg_calloc(size_t cnt, size_t size) { @@ -288,7 +288,7 @@ extern uint32_t rt_time_get(void); #include "cmsis_os2.h" // keep this include #endif -#define strdup(s) mg_mprintf("%s", s) +#define strdup(s) ((char *) mg_strdup(mg_str(s)).buf) #if defined(__ARMCC_VERSION) #define mode_t size_t @@ -861,6 +861,7 @@ struct mg_str mg_str_n(const char *s, size_t n); int mg_casecmp(const char *s1, const char *s2); int mg_strcmp(const struct mg_str str1, const struct mg_str str2); int mg_strcasecmp(const struct mg_str str1, const struct mg_str str2); +struct mg_str mg_strdup(const struct mg_str s); bool mg_match(struct mg_str str, struct mg_str pattern, struct mg_str *caps); bool mg_span(struct mg_str s, struct mg_str *a, struct mg_str *b, char delim);