+struct memo_websocket {
+ const struct protodef *proto;
+ struct afb_hreq *hreq;
+ struct afb_apiset *apiset;
+};
+
+static void close_websocket(void *closure)
+{
+ struct MHD_UpgradeResponseHandle *urh = closure;
+ MHD_upgrade_action (urh, MHD_UPGRADE_ACTION_CLOSE);
+}
+
+static void upgrade_to_websocket(
+ void *cls,
+ struct MHD_Connection *connection,
+ void *con_cls,
+ const char *extra_in,
+ size_t extra_in_size,
+ MHD_socket sock,
+ struct MHD_UpgradeResponseHandle *urh)
+{
+ struct memo_websocket *memo = cls;
+ void *ws;
+
+ ws = memo->proto->create(sock, memo->apiset, &memo->hreq->xreq.context, close_websocket, urh);
+ if (ws == NULL) {
+ /* TODO */
+ close_websocket(urh);
+ }
+ afb_hreq_unref(memo->hreq);
+ free(memo);
+}
+
+static int check_websocket_upgrade(struct MHD_Connection *con, const struct protodef *protodefs, struct afb_hreq *hreq, struct afb_apiset *apiset)