#include "afb-hreq.h"
#include "afb-websock.h"
#include "afb-ws-json1.h"
+#include "afb-fdev.h"
/**************** WebSocket connection upgrade ****************************/
struct protodef
{
const char *name;
- void *(*create)(int fd, struct afb_apiset *apiset, struct afb_context *context, void (*cleanup)(void*), void *cleanup_closure);
+ void *(*create)(struct fdev *fdev, struct afb_apiset *apiset, struct afb_context *context, void (*cleanup)(void*), void *cleanup_closure);
};
static const struct protodef *search_proto(const struct protodef *protodefs, const char *protocols)
{
struct memo_websocket *memo = cls;
void *ws;
+ struct fdev *fdev;
- ws = memo->proto->create(sock, memo->apiset, &memo->hreq->xreq.context, close_websocket, urh);
- if (ws == NULL) {
+ fdev = afb_fdev_create(sock);
+ if (!fdev) {
/* TODO */
close_websocket(urh);
+ } else {
+ ws = memo->proto->create(fdev, memo->apiset, &memo->hreq->xreq.context, close_websocket, urh);
+ if (ws == NULL) {
+ /* TODO */
+ close_websocket(urh);
+ }
}
afb_hreq_unref(memo->hreq);
free(memo);
make_accept_value(key, acceptval);
MHD_add_response_header(response, sec_websocket_accept_s, acceptval);
MHD_add_response_header(response, sec_websocket_protocol_s, proto->name);
- MHD_add_response_header(response, MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_HEADER_UPGRADE);
MHD_add_response_header(response, MHD_HTTP_HEADER_UPGRADE, websocket_s);
MHD_queue_response(con, MHD_HTTP_SWITCHING_PROTOCOLS, response);
MHD_destroy_response(response);
}
static const struct protodef protodefs[] = {
- { "x-afb-ws-json1", afb_ws_json1_create },
+ { "x-afb-ws-json1", (void*)afb_ws_json1_create },
{ NULL, NULL }
};