Code Review
/
src
/
app-framework-binder.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
improves websockets
[src/app-framework-binder.git]
/
src
/
afb-websock.c
diff --git
a/src/afb-websock.c
b/src/afb-websock.c
index
dab4aa0
..
1f80071
100644
(file)
--- a/
src/afb-websock.c
+++ b/
src/afb-websock.c
@@
-27,15
+27,9
@@
#include <json.h>
#include <openssl/sha.h>
#include <json.h>
#include <openssl/sha.h>
-/*
-#include <openssl/bio.h>
-#include <openssl/evp.h>
-*/
#include "websock.h"
#include "websock.h"
-#include "local-def.h"
-
#include "afb-req-itf.h"
#include "afb-method.h"
#include "afb-hreq.h"
#include "afb-req-itf.h"
#include "afb-method.h"
#include "afb-hreq.h"
@@
-176,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_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
};
struct afb_wsreq
@@
-220,41
+215,50
@@
static const struct afb_req_itf wsreq_itf = {
struct afb_websock *afb_websock_create(struct afb_hreq *hreq)
{
struct afb_websock *afb_websock_create(struct afb_hreq *hreq)
{
+ int fd;
struct afb_websock *result;
struct afb_websock *result;
+ fd = MHD_get_connection_info(hreq->connection,
+ MHD_CONNECTION_INFO_CONNECTION_FD)->connect_fd;
+ fd = dup(fd);
+ if (fd < 0)
+ return NULL;
+
result = malloc(sizeof * result);
if (result == NULL)
goto error;
result->connection = hreq->connection;
result = malloc(sizeof * result);
if (result == NULL)
goto error;
result->connection = hreq->connection;
- result->fd = MHD_get_connection_info(hreq->connection,
- MHD_CONNECTION_INFO_CONNECTION_FD)->connect_fd;
+ result->fd = fd;
result->context = ctxClientGet(afb_hreq_context(hreq));
if (result->context == NULL)
goto error2;
result->tokener = json_tokener_new();
if (result->tokener == NULL)
result->context = ctxClientGet(afb_hreq_context(hreq));
if (result->context == NULL)
goto error2;
result->tokener = json_tokener_new();
if (result->tokener == NULL)
- goto error
2
;
+ goto error
3
;
- result->ws = websock_create(&aws_itf, result);
+ result->ws = websock_create
_v13
(&aws_itf, result);
if (result->ws == NULL)
if (result->ws == NULL)
- goto error
3
;
+ goto error
4
;
result->up = upoll_open(result->fd, result);
if (result->up == NULL)
result->up = upoll_open(result->fd, result);
if (result->up == NULL)
- goto error
4
;
+ goto error
5
;
upoll_on_readable(result->up, (void*)aws_on_readable);
upoll_on_hangup(result->up, (void*)aws_disconnect);
return result;
upoll_on_readable(result->up, (void*)aws_on_readable);
upoll_on_hangup(result->up, (void*)aws_disconnect);
return result;
-error
4
:
+error
5
:
websock_destroy(result->ws);
websock_destroy(result->ws);
-error
3
:
+error
4
:
json_tokener_free(result->tokener);
json_tokener_free(result->tokener);
+error3:
+ ctxClientPut(result->context);
error2:
free(result);
error:
error2:
free(result);
error:
+ close(fd);
return NULL;
}
return NULL;
}
@@
-300,7
+304,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;
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;
struct json_object *type, *id, *name, *req, *token;
struct afb_wsreq *wsreq;
const char *api, *verb;
@@
-346,7
+350,7
@@
static int aws_handle_json(struct afb_websock *aws, struct json_object *obj)
goto error;
verb = &api[lenapi+1];
for (lenverb = 0 ; verb[lenverb] && verb[lenverb] != '/' ; lenverb++);
goto error;
verb = &api[lenapi+1];
for (lenverb = 0 ; verb[lenverb] && verb[lenverb] != '/' ; lenverb++);
- if (!lenverb ||
!
verb[lenverb])
+ if (!lenverb || verb[lenverb])
goto error;
/* allocates the request data */
goto error;
/* allocates the request data */
@@
-366,9
+370,7
@@
static int aws_handle_json(struct afb_websock *aws, struct json_object *obj)
r.data = wsreq;
r.itf = &wsreq_itf;
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:
return 1;
error:
@@
-404,7
+406,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;
static struct afb_arg wsreq_get(struct afb_wsreq *wsreq, const char *name)
{
struct afb_arg arg;
@@
-413,12
+414,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);
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;
} else {
arg.name = NULL;
arg.value = NULL;
+ arg.size = 0;
}
}
- arg.size = 0;
- arg.is_file = 0;
+ arg.path = NULL;
return arg;
}
return arg;
}
@@
-429,7
+431,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;
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));
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));
@@
-502,6
+504,7
@@
static void wsreq_reply(struct afb_wsreq *wsreq, int retcode, const char *status
/* emits the reply */
message = json_object_to_json_string(reply);
websock_text(wsreq->aws->ws, message, strlen(message));
/* emits the reply */
message = json_object_to_json_string(reply);
websock_text(wsreq->aws->ws, message, strlen(message));
+ json_object_put(reply);
/* TODO eliminates the wsreq */
}
/* TODO eliminates the wsreq */
}