get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/812909/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 812909,
    "url": "http://patchwork.ozlabs.org/api/patches/812909/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170912152153.7729-8-brandon.carpenter@cypherpath.com/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api",
        "name": "QEMU Development",
        "link_name": "qemu-devel",
        "list_id": "qemu-devel.nongnu.org",
        "list_email": "qemu-devel@nongnu.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20170912152153.7729-8-brandon.carpenter@cypherpath.com>",
    "list_archive_url": null,
    "date": "2017-09-12T15:21:53",
    "name": "[v3,7/7] io: Attempt to send websocket close messages to client",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "4fa8e7981c5606ac79edcc14aa4d3c51983302ee",
    "submitter": {
        "id": 72031,
        "url": "http://patchwork.ozlabs.org/api/people/72031/?format=api",
        "name": "Brandon Carpenter",
        "email": "brandon.carpenter@cypherpath.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170912152153.7729-8-brandon.carpenter@cypherpath.com/mbox/",
    "series": [
        {
            "id": 2725,
            "url": "http://patchwork.ozlabs.org/api/series/2725/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2725",
            "date": "2017-09-12T15:21:48",
            "name": "Update websocket code to more fully support the RFC",
            "version": 3,
            "mbox": "http://patchwork.ozlabs.org/series/2725/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/812909/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/812909/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org",
        "Authentication-Results": [
            "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)",
            "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=cypherpath.com header.i=@cypherpath.com\n\theader.b=\"D+AS2JV3\"; dkim-atps=neutral"
        ],
        "Received": [
            "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xs7t9088pz9s7f\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 13 Sep 2017 01:26:08 +1000 (AEST)",
            "from localhost ([::1]:36510 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drn4g-0007Vg-Lo\n\tfor incoming@patchwork.ozlabs.org; Tue, 12 Sep 2017 11:26:06 -0400",
            "from eggs.gnu.org ([2001:4830:134:3::10]:40532)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <brandon.carpenter@cypherpath.com>)\n\tid 1drn18-0004mP-IO\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 11:22:29 -0400",
            "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <brandon.carpenter@cypherpath.com>)\n\tid 1drn17-00074I-Bn\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 11:22:26 -0400",
            "from mail-pg0-x230.google.com ([2607:f8b0:400e:c05::230]:37855)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <brandon.carpenter@cypherpath.com>)\n\tid 1drn17-00073q-44\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 11:22:25 -0400",
            "by mail-pg0-x230.google.com with SMTP id d8so21859635pgt.4\n\tfor <qemu-devel@nongnu.org>; Tue, 12 Sep 2017 08:22:25 -0700 (PDT)",
            "from servo.cypherpath.com (68-113-0-218.static.knwc.wa.charter.com.\n\t[68.113.0.218]) by smtp.gmail.com with ESMTPSA id\n\td18sm12753054pfk.11.2017.09.12.08.22.22\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tTue, 12 Sep 2017 08:22:23 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=cypherpath.com; s=google;\n\th=mime-version:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; bh=WgZWP+VIHu3GEE+meSJFmP4+gg340cZljkTTvvKN/oE=;\n\tb=D+AS2JV3Nh8AFd8QSsc2gkH4o3Jgc3EUnrhomdt0uh7V5PpioarVgGxmR5ATNUOepP\n\t5EXTOvRjQKDF9rQimTaKsEBNKd2FKboEOvXBRMcE82vdsbv+02wwc/pmfzH+/1Te3eTP\n\txbexPBqRHjSMjbhMOTjojyPxhv1o8rEg6xH3Y=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id\n\t:in-reply-to:references;\n\tbh=WgZWP+VIHu3GEE+meSJFmP4+gg340cZljkTTvvKN/oE=;\n\tb=HTGFct3s4Ib1c92XzjNUnJ82a2azPgdBs6C1e4CVOaLG1xR34fAHLKcINMrQQAAly3\n\trE5r0K1Gw2YtdsRsJDiqCkCmPXJtCOt37GMEuV7OqIcyJwHL+Rr+kDvLD0mYLlUlSgRR\n\tJNq9YYEnv1KPSfCirDk371atwSggQReWWDrKT0z1j1RQftnoIiItFy5q+cGKNN4x7C89\n\t/xmwLJDCITAfzrIaIy8g+ytFydu7rK28fxhBjKrx3lAtruSa5RAykHxo/IxA+IXM2ZPe\n\tA69EvIqoa6NEa+IK36hsWmDwMgnTxtrOD5KzT452J+PW2j0o7MS9btrFFMdLYmNXtG4W\n\tITgg==",
        "X-Gm-Message-State": "AHPjjUjMC6Oghy/OqzPB/Tzr094utxGiR+XCZpk5T3KzBe6GJNvyl5my\n\t5N99WjVxFKdLhveNEyfWNEwUei1MMoFBoEUazYZPbEFA6LuYUWlORzmJJh3C18KRh9MYSZsdw2v\n\tIxuVI",
        "MIME-Version": "1.0",
        "X-Google-Smtp-Source": "ADKCNb5Q7RHIjj2VCtLBqjIk1SNW2YMQnK7dc4kJ6s4RS30+PzTKKPHLMXJ6cbkH1LmBHG/WT2uEPQ==",
        "X-Received": "by 10.99.114.20 with SMTP id n20mr14991528pgc.448.1505229743860; \n\tTue, 12 Sep 2017 08:22:23 -0700 (PDT)",
        "From": "Brandon Carpenter <brandon.carpenter@cypherpath.com>",
        "To": "qemu-devel@nongnu.org",
        "Date": "Tue, 12 Sep 2017 08:21:53 -0700",
        "Message-Id": "<20170912152153.7729-8-brandon.carpenter@cypherpath.com>",
        "X-Mailer": "git-send-email 2.14.1",
        "In-Reply-To": "<20170912152153.7729-1-brandon.carpenter@cypherpath.com>",
        "References": "<20170912152153.7729-1-brandon.carpenter@cypherpath.com>",
        "Content-Type": "text/plain; charset=\"US-ASCII\"",
        "X-detected-operating-system": "by eggs.gnu.org: Genre and OS details not\n\trecognized.",
        "X-Received-From": "2607:f8b0:400e:c05::230",
        "Subject": "[Qemu-devel] [PATCH v3 7/7] io: Attempt to send websocket close\n\tmessages to client",
        "X-BeenThere": "qemu-devel@nongnu.org",
        "X-Mailman-Version": "2.1.21",
        "Precedence": "list",
        "List-Id": "<qemu-devel.nongnu.org>",
        "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel/>",
        "List-Post": "<mailto:qemu-devel@nongnu.org>",
        "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>",
        "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>",
        "Cc": "brandon.carpenter@cypherpath.com",
        "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org",
        "Sender": "\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"
    },
    "content": "Make a best effort attempt to close websocket connections according to\nthe RFC. Sends the close message, as room permits in the socket buffer,\nand immediately closes the socket.\n\nSigned-off-by: Brandon Carpenter <brandon.carpenter@cypherpath.com>\n---\n io/channel-websock.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 62 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/io/channel-websock.c b/io/channel-websock.c\nindex a29fee42d5..c50f8c6c50 100644\n--- a/io/channel-websock.c\n+++ b/io/channel-websock.c\n@@ -122,6 +122,15 @@ enum {\n     QIO_CHANNEL_WEBSOCK_OPCODE_PONG = 0xA\n };\n \n+enum {\n+    QIO_CHANNEL_WEBSOCK_STATUS_NORMAL = 1000,\n+    QIO_CHANNEL_WEBSOCK_STATUS_PROTOCOL_ERR = 1002,\n+    QIO_CHANNEL_WEBSOCK_STATUS_INVALID_DATA = 1003,\n+    QIO_CHANNEL_WEBSOCK_STATUS_POLICY = 1008,\n+    QIO_CHANNEL_WEBSOCK_STATUS_TOO_LARGE = 1009,\n+    QIO_CHANNEL_WEBSOCK_STATUS_SERVER_ERR = 1011,\n+};\n+\n static size_t\n qio_channel_websock_extract_headers(char *buffer,\n                                     QIOChannelWebsockHTTPHeader *hdrs,\n@@ -523,6 +532,26 @@ static void qio_channel_websock_encode(QIOChannelWebsock *ioc)\n }\n \n \n+static ssize_t qio_channel_websock_write_wire(QIOChannelWebsock *, Error **);\n+\n+\n+static void qio_channel_websock_write_close(QIOChannelWebsock *ioc,\n+                                              uint16_t code, const char *reason)\n+{\n+    buffer_reserve(&ioc->rawoutput, 2 + (reason ? strlen(reason) : 0));\n+    *(uint16_t *)(ioc->rawoutput.buffer + ioc->rawoutput.offset) = cpu_to_be16(code);\n+    ioc->rawoutput.offset += 2;\n+    if (reason) {\n+        buffer_append(&ioc->rawoutput, reason, strlen(reason));\n+    }\n+    qio_channel_websock_encode_buffer(&ioc->encoutput,\n+            QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE, &ioc->rawoutput);\n+    buffer_reset(&ioc->rawoutput);\n+    qio_channel_websock_write_wire(ioc, NULL);\n+    qio_channel_shutdown(ioc->master, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);\n+}\n+\n+\n static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,\n                                              Error **errp)\n {\n@@ -536,6 +565,8 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,\n         error_setg(errp,\n                    \"Decoding header but %zu bytes of payload remain\",\n                    ioc->payload_remain);\n+        qio_channel_websock_write_close(ioc,\n+                QIO_CHANNEL_WEBSOCK_STATUS_SERVER_ERR, \"internal server error\");\n         return -1;\n     }\n     if (ioc->encinput.offset < QIO_CHANNEL_WEBSOCK_HEADER_LEN_7_BIT) {\n@@ -568,19 +599,29 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,\n     if (!fin) {\n         if (opcode != QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {\n             error_setg(errp, \"only binary websocket frames may be fragmented\");\n+            qio_channel_websock_write_close(ioc,\n+                    QIO_CHANNEL_WEBSOCK_STATUS_POLICY ,\n+                    \"only binary frames may be fragmented\");\n             return -1;\n         }\n     } else {\n         if (opcode != QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME &&\n+                opcode != QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE &&\n                 opcode != QIO_CHANNEL_WEBSOCK_OPCODE_PING &&\n                 opcode != QIO_CHANNEL_WEBSOCK_OPCODE_PONG) {\n-            error_setg(errp, \"unsupported opcode: %#04x; only binary, ping, \"\n-                             \"and pong websocket frames are supported\", opcode);\n+            error_setg(errp, \"unsupported opcode: %#04x; only binary, close, \"\n+                       \"ping, and pong websocket frames are supported\", opcode);\n+            qio_channel_websock_write_close(ioc,\n+                    QIO_CHANNEL_WEBSOCK_STATUS_INVALID_DATA ,\n+                    \"only binary, close, ping, and pong frames are supported\");\n             return -1;\n         }\n     }\n     if (!has_mask) {\n         error_setg(errp, \"client websocket frames must be masked\");\n+        qio_channel_websock_write_close(ioc,\n+                QIO_CHANNEL_WEBSOCK_STATUS_PROTOCOL_ERR,\n+                \"client frames must be masked\");\n         return -1;\n     }\n \n@@ -590,6 +631,9 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,\n         ioc->mask = header->u.m;\n     } else if (opcode & QIO_CHANNEL_WEBSOCK_CONTROL_OPCODE_MASK) {\n         error_setg(errp, \"websocket control frame is too large\");\n+        qio_channel_websock_write_close(ioc,\n+                QIO_CHANNEL_WEBSOCK_STATUS_PROTOCOL_ERR,\n+                \"control frame is too large\");\n         return -1;\n     } else if (payload_len == QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_MAGIC_16_BIT &&\n                ioc->encinput.offset >= QIO_CHANNEL_WEBSOCK_HEADER_LEN_16_BIT) {\n@@ -607,7 +651,7 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,\n     }\n \n     buffer_advance(&ioc->encinput, header_size);\n-    return 1;\n+    return 0;\n }\n \n \n@@ -657,6 +701,21 @@ static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc,\n             buffer_reserve(&ioc->rawinput, payload_len);\n             buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len);\n         }\n+    } else if (ioc->opcode == QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE) {\n+        /* close frames are echoed back */\n+        error_setg(errp, \"websocket closed by peer\");\n+        if (payload_len) {\n+            /* echo client status */\n+            qio_channel_websock_encode_buffer(&ioc->encoutput,\n+                    QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE, &ioc->encinput);\n+            qio_channel_websock_write_wire(ioc, NULL);\n+            qio_channel_shutdown(ioc->master, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);\n+        } else {\n+            /* send our own status */\n+            qio_channel_websock_write_close(ioc,\n+                    QIO_CHANNEL_WEBSOCK_STATUS_NORMAL, \"peer requested close\");\n+        }\n+        return -1;\n     } else if (ioc->opcode == QIO_CHANNEL_WEBSOCK_OPCODE_PING) {\n         /* ping frames produce an immediate reply */\n         buffer_reset(&ioc->ping_reply);\n",
    "prefixes": [
        "v3",
        "7/7"
    ]
}