X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-websock.c;h=d92c7b0059223a26304819ecb5d8fc4aef5deb47;hb=54b2652e94cfa7840dbebcba46edd5459e7c6e86;hp=cff995f28b7f7bfe493456eacfbf324025e275be;hpb=8d21ca2e3daf37d8afe7b678edb0aa2e47a468ef;p=src%2Fapp-framework-binder.git diff --git a/src/afb-websock.c b/src/afb-websock.c index cff995f2..d92c7b00 100644 --- a/src/afb-websock.c +++ b/src/afb-websock.c @@ -2,8 +2,6 @@ * Copyright 2016 IoT.bzh * Author: José Bollo * - * Inspired by the work of - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -30,7 +28,7 @@ #include "websock.h" -#include "local-def.h" +#include "afb-ws-json.h" #include "afb-req-itf.h" #include "afb-method.h" @@ -172,7 +170,8 @@ static struct websock_itf aws_itf = { .on_close = (void*)aws_on_close, .on_text = (void*)aws_on_content, .on_binary = (void*)aws_on_content, - .on_continue = (void*)aws_on_content + .on_continue = (void*)aws_on_content, + .on_extension = NULL }; struct afb_wsreq @@ -188,12 +187,12 @@ struct afb_wsreq struct afb_websock { int fd; + struct afb_wsreq *requests; struct MHD_Connection *connection; + struct AFB_clientCtx *context; struct websock *ws; struct upoll *up; - struct AFB_clientCtx *context; struct json_tokener *tokener; - struct afb_wsreq *requests; }; static struct afb_arg wsreq_get(struct afb_wsreq *wsreq, const char *name); @@ -215,6 +214,15 @@ static const struct afb_req_itf wsreq_itf = { }; struct afb_websock *afb_websock_create(struct afb_hreq *hreq) +{ + return (void*)afb_ws_json_create( + dup(MHD_get_connection_info(hreq->connection,MHD_CONNECTION_INFO_CONNECTION_FD)->connect_fd), + afb_hreq_context(hreq), + (void*)MHD_resume_connection, + hreq->connection); +} + +struct afb_websock *_afb_websock_create(struct afb_hreq *hreq) { int fd; struct afb_websock *result; @@ -229,31 +237,34 @@ struct afb_websock *afb_websock_create(struct afb_hreq *hreq) if (result == NULL) goto error; - result->connection = hreq->connection; result->fd = fd; + result->requests = NULL; + result->connection = hreq->connection; result->context = ctxClientGet(afb_hreq_context(hreq)); if (result->context == NULL) goto error2; result->tokener = json_tokener_new(); if (result->tokener == NULL) - goto error2; + goto error3; - result->ws = websock_create(&aws_itf, result); + result->ws = websock_create_v13(&aws_itf, result); if (result->ws == NULL) - goto error3; + goto error4; result->up = upoll_open(result->fd, result); if (result->up == NULL) - goto error4; + goto error5; upoll_on_readable(result->up, (void*)aws_on_readable); upoll_on_hangup(result->up, (void*)aws_disconnect); return result; -error4: +error5: websock_destroy(result->ws); -error3: +error4: json_tokener_free(result->tokener); +error3: + ctxClientPut(result->context); error2: free(result); error: @@ -303,7 +314,7 @@ static void aws_on_readable(struct afb_websock *ws) static int aws_handle_json(struct afb_websock *aws, struct json_object *obj) { struct afb_req r; - int count, num, rc; + int count, num; struct json_object *type, *id, *name, *req, *token; struct afb_wsreq *wsreq; const char *api, *verb; @@ -369,9 +380,7 @@ static int aws_handle_json(struct afb_websock *aws, struct json_object *obj) r.data = wsreq; r.itf = &wsreq_itf; - rc = afb_apis_handle(r, aws->context, api, lenapi, verb, lenverb); - if (rc == 0) - wsreq_fail(wsreq, "ail", "api not found"); + afb_apis_call(r, aws->context, api, lenapi, verb, lenverb); return 1; error: @@ -407,7 +416,6 @@ static void aws_on_content(struct afb_websock *ws, int last, size_t size) } } - static struct afb_arg wsreq_get(struct afb_wsreq *wsreq, const char *name) { struct afb_arg arg; @@ -416,12 +424,13 @@ static struct afb_arg wsreq_get(struct afb_wsreq *wsreq, const char *name) if (json_object_object_get_ex(wsreq->request, name, &value)) { arg.name = name; arg.value = json_object_get_string(value); + arg.size = strlen(arg.value); } else { arg.name = NULL; arg.value = NULL; + arg.size = 0; } - arg.size = 0; - arg.is_file = 0; + arg.path = NULL; return arg; } @@ -432,7 +441,7 @@ static void wsreq_iterate(struct afb_wsreq *wsreq, int (*iterator)(void *closure struct json_object_iterator end = json_object_iter_end(wsreq->request); arg.size = 0; - arg.is_file = 0; + arg.path = NULL; while(!json_object_iter_equal(&it, &end)) { arg.name = json_object_iter_peek_name(&it); arg.value = json_object_get_string(json_object_iter_peek_value(&it));