From patchwork Mon Mar 5 09:44:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 881369 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23b; helo=mail-wm0-x23b.google.com; envelope-from=swupdate+bncbcxploxj6ikrb6nc6tkakgqevx3aoli@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="ELmAhu16"; dkim-atps=neutral Received: from mail-wm0-x23b.google.com (mail-wm0-x23b.google.com [IPv6:2a00:1450:400c:c09::23b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zvw3c5BnLz9sZX for ; Mon, 5 Mar 2018 20:44:28 +1100 (AEDT) Received: by mail-wm0-x23b.google.com with SMTP id e127sf3848874wmg.7 for ; Mon, 05 Mar 2018 01:44:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1520243065; cv=pass; d=google.com; s=arc-20160816; b=ouaCk8hj+jF5GVJ2/cUQX0vn27LW7Pot3R2sqDqgKo3ixooYaI8Nh+taBYR3/0LOXQ kmwBEWCxdwZLDRBpH6lGZJIyO4JEg2Q1xAsTMgOzJccFs8P3TsPkiB5myINEfsn3oBpr ZZZE5ATs2l9WeJuIzEM0KuEQhjv7QzDyFk/7n4yJAMulye5k5MX6M+ZRvY9aDx+6EiKp OH69GTlZo0eGZvq6pJni4mcxGlNL6PyRqkEhr1jBKt8vy+mTivd6eE6Eghl6lK+AkEB3 AAN7G0AstkHKVB+yLNMrxpLpwGtGAjnyG78cWEylQZWkDxFr5WIc9IsKnRs0yLeE38gC IRPA== 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:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=vWKN6JTucvtUEnbZfojt86qQXn7no73NFXfsX2E6CMY=; b=nzQnpY/+C62H4y0ASUaOsx6LIpAtEB3CupJBR1TWQ2slaw+b2MDN4zrfUF90vyy0JK Gpo0oigpbhjW6z/h6WOGF0Gc0gh3DTEl/BDA5HiQ6TrPVX08bvVTR+qzFLjuR+ujmP5S hlGw35Cu4wPirwxObWGFzSy2Rj11GhKqa0WvdhEDLT/FYJ3vR3jtj2mxu248XFN/TWOb jS284rbWGSQLCVSeB0u8b1Z1+RjLTGFzVs+LmIJKXWVG36C442g6RdbZbWOrsrX9OzeO 6fn4m/EHymKNJjtzQB+SQyQ9mJg6cIKr3TlU8cs3COIeuW3eGp7JRIAv/cwPhT7/kf8v r2WA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=vWKN6JTucvtUEnbZfojt86qQXn7no73NFXfsX2E6CMY=; b=ELmAhu16KZmPbyBejF9xxKbX8Tpds8qcGqt1TFhfK4Gb7SElPhO8PgApQ/SzyH+jPJ UKkiTaGtcod8uXob7FlG5SYXDNBa11pCVp+IZyOAOt3m9oqGW2n3s++sSWjEVVr8ST3H nm8u0fcVhj+xlUXe6pDsxdfDCU3LKnkz00F4kGZNQu9CI3XERjryTS9c67HjbnoT7+oy OpjdHbjpjxlHRGARIenfwcIt4UVUfL06ilApx7WVHUbFenkeqe5/lp9DNBuQOyjzxqQm ig8bvR9Jiz/psAdU7pNgJ+rfWOCbvA2a1U18KxVCvyc6vPE1a6tet1f4JFUrnAecftFW IsMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=vWKN6JTucvtUEnbZfojt86qQXn7no73NFXfsX2E6CMY=; b=NmA4gy9EA35EnJwcIhW/J0Ff59lDVX1Ea1/NJLNo65ek0txuKsWkG+Pr6pCN14VwU+ AGcUOQNTn3h1q4BjQeqMzPH1wa8Inp8HwoYPtMgFy5nD8QpC/V0A87Y8OMrU3rliYF9Y kwzflgeoZM1gVws1T5WT8RhBNqatEyPKYL5fSpfxqtDJ+NI+DOAh2UL+hGjoiUaIoa+J 7ZhU7EhHTqR1iYKhbaPwUEJJnLgCj/r4P1/KFcvfxGQl7TvVcLXginuTRnbRe3QQnsPx aeK8GHBs+6BMRO1XhF+PZllVCiHvjIh65cawjcfO/Nu0zdAt2XN6wagWuEgxXqlR3Cq4 rfeA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AElRT7FdMKdeC3ghLdJ5ygR4lLxAbegwjhyLO392o5HCAi1Mk38IkM17 hLkFHZWjfIyrfkt0zkeucXE= X-Google-Smtp-Source: AG47ELvyYZYz3nl8DlWL/GC32uIGkXiR9fwbD7B0vpDEUDu87AXI7RLsPTnxec3K5pksunOn59hrDw== X-Received: by 10.28.239.14 with SMTP id n14mr129120wmh.1.1520243065501; Mon, 05 Mar 2018 01:44:25 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.47.77 with SMTP id v74ls1370634wmv.6.gmail; Mon, 05 Mar 2018 01:44:24 -0800 (PST) X-Received: by 10.28.178.80 with SMTP id b77mr962123wmf.5.1520243064638; Mon, 05 Mar 2018 01:44:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520243064; cv=none; d=google.com; s=arc-20160816; b=sHpLA/dVoJNuDzntX44G+ngeXVPLty28DE2tu7usN6GinVrbhYv9Q29D3j/a9X2oHj YAMV4HDICU4kSfB7ZwMrWuAWBAm9zLECu00V1amvr9lI4mFMTEgn2WwnRlUkvK5zDGcz VJONZkGT5sv0ztn3OPYO8edGpJyZSfFcDWuQ4rkqNFKW8va7ORKbKH11Dj8BVCQ/pzBk HYPXff9UgUOvxdmhjUsaOo8LDRNAK3e02O0p0xZb/sIH8ox0hlHUJ2x2cWD1rMCst0+6 ZO3Y/v8ALTZ+gdDAXO5r56SL5jMW6nm7iEs4dSX74QszrN3mWm2VVG5W3meuO9VEe+GV Vovg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=D7jJEAAt6sby/v5vFAja1KZNF+oKgQ+wBy1ZjKcPu5k=; b=LPmcghCG6wdQxjiunCXQrg0ko4TkIVPjIo7SpLG6wdbGv9xd48gDy99TEqw0V4JH8T XTPAIXy+rUOU9ng2voktKN+B/VrVsVuEOlCjQh7v+eSU+MRXzFBllUdhikdjG5dnk0I5 PErGMldyrK1iKBGk2U0FQ2iP5nSBkByNoH2mXDBPUNq409bY+YnYvFR7vueV6vXbxQcx 8gW+OcmS4csJ68GOEuyP6PwP665ozOr91eGu+MsoJfEGHG0cmIQW8cuoaOmoK5Ll3w0w b6GYEX7upa5rRMCNfX3c+RL7ulsR31yrhGoWtk3ysrES9nrbUrOGjOE/feoI4F0K3Y8L 4mog== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id a138si231377wmd.0.2018.03.05.01.44.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 01:44:24 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3zvw3X2wVWz1qtH6; Mon, 5 Mar 2018 10:44:24 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3zvw3X2ckrz1sQwq; Mon, 5 Mar 2018 10:44:24 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id NNpseWb9likp; Mon, 5 Mar 2018 10:44:23 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Mon, 5 Mar 2018 10:44:23 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 1DFDA4540580; Mon, 5 Mar 2018 10:44:23 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oRshTkQZyx73; Mon, 5 Mar 2018 10:44:21 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id CD6BC4540378; Mon, 5 Mar 2018 10:44:20 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic , Sami Hartikainen Subject: [swupdate] [PATCH 1/2] mongoose: split upload_handler Date: Mon, 5 Mar 2018 10:44:17 +0100 Message-Id: <1520243058-10526-1-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de 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: , To make code more readable, split upload_handler into two function for v1 and v2 API. Signed-off-by: Stefano Babic CC: Sami Hartikainen --- mongoose/mongoose_interface.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c index 60914d3..423a2dc 100644 --- a/mongoose/mongoose_interface.c +++ b/mongoose/mongoose_interface.c @@ -112,20 +112,16 @@ static size_t snescape(char *dst, size_t n, const char *src) } #endif -static void upload_handler(struct mg_connection *nc, int ev, void *p) -{ - struct mg_http_multipart_part *mp; - struct file_upload_state *fus; #if defined(CONFIG_MONGOOSE_WEB_API_V1) +static void upload_handler_v1(struct mg_connection *nc, int ev, void *p) +{ struct mg_str *filename, *data; struct http_message *hm; size_t length; char buf[16]; int fd; -#endif switch (ev) { -#if defined(CONFIG_MONGOOSE_WEB_API_V1) case MG_EV_HTTP_REQUEST: hm = (struct http_message *) p; @@ -159,9 +155,20 @@ static void upload_handler(struct mg_connection *nc, int ev, void *p) mg_send(nc, "\r\n", 2); mg_printf(nc, "Ok, %.*s - %d bytes.\r\n", (int) filename->len, filename->p, (int) length); nc->flags |= MG_F_SEND_AND_CLOSE; - break; + default: + upload_handler(nc, ev, p); + break; + } +} #endif + +static void upload_handler(struct mg_connection *nc, int ev, void *p) +{ + struct mg_http_multipart_part *mp; + struct file_upload_state *fus; + + switch (ev) { case MG_EV_HTTP_PART_BEGIN: mp = (struct mg_http_multipart_part *) p; @@ -610,18 +617,16 @@ int start_mongoose(const char *cfgfname, int argc, char *argv[]) exit(EXIT_FAILURE); } + mg_set_protocol_http_websocket(nc); + mg_register_http_endpoint(nc, "/upload", MG_CB(upload_handler, NULL)); #if defined(CONFIG_MONGOOSE_WEB_API_V1) - mg_register_http_endpoint(nc, "/handle_post_request", MG_CB(upload_handler, NULL)); + mg_register_http_endpoint(nc, "/handle_post_request", MG_CB(upload_handler_v1, NULL)); mg_register_http_endpoint(nc, "/getstatus.json", MG_CB(recovery_status, NULL)); mg_register_http_endpoint(nc, "/rebootTarget", MG_CB(reboot_target, NULL)); mg_register_http_endpoint(nc, "/postUpdateCommand", MG_CB(post_update_cmd, NULL)); -#elif defined(CONFIG_MONGOOSE_WEB_API_V2) - mg_register_http_endpoint(nc, "/restart", restart_handler); #endif - mg_register_http_endpoint(nc, "/upload", MG_CB(upload_handler, NULL)); - mg_set_protocol_http_websocket(nc); - #if defined(CONFIG_MONGOOSE_WEB_API_V2) + mg_register_http_endpoint(nc, "/restart", restart_handler); mg_start_thread(broadcast_message_thread, &mgr); mg_start_thread(broadcast_progress_thread, &mgr); #endif