net: http: Provide destination address in http replies

net_app_ctx maintains multiple net contexts(net_ctx). But when http
api's wants to reply or send some data, its always choose the first
net_context in the array, which is not correct always.

net_app_get_net_pkt_with_dst() api will select proper context
based on destination address. So with the help of new api in
net_app, http can select proper context and send packets. To
achieve this, desination address is provided in http_recv_cb_t
and http_connect_cb_t callbacks. Also chaged relevant API's to
provide destination address in http message preparation methods.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This commit is contained in:
Ravi kumar Veeramally 2018-02-13 11:19:14 +02:00 committed by Carles Cufí
commit ebc81bdf8d
8 changed files with 133 additions and 73 deletions

View file

@ -72,41 +72,41 @@ int http_request(struct http_ctx *ctx, struct http_request *req, s32_t timeout,
ctx->pending = NULL;
}
ret = http_add_header(ctx, method, user_data);
ret = http_add_header(ctx, method, NULL, user_data);
if (ret < 0) {
goto out;
}
ret = http_add_header(ctx, " ", user_data);
ret = http_add_header(ctx, " ", NULL, user_data);
if (ret < 0) {
goto out;
}
ret = http_add_header(ctx, req->url, user_data);
ret = http_add_header(ctx, req->url, NULL, user_data);
if (ret < 0) {
goto out;
}
ret = http_add_header(ctx, req->protocol, user_data);
ret = http_add_header(ctx, req->protocol, NULL, user_data);
if (ret < 0) {
goto out;
}
ret = http_add_header(ctx, HTTP_CRLF, user_data);
ret = http_add_header(ctx, HTTP_CRLF, NULL, user_data);
if (ret < 0) {
goto out;
}
if (req->host) {
ret = http_add_header_field(ctx, HTTP_HOST, req->host,
user_data);
NULL, user_data);
if (ret < 0) {
goto out;
}
}
if (req->header_fields) {
ret = http_add_header(ctx, req->header_fields, user_data);
ret = http_add_header(ctx, req->header_fields, NULL, user_data);
if (ret < 0) {
goto out;
}
@ -115,7 +115,7 @@ int http_request(struct http_ctx *ctx, struct http_request *req, s32_t timeout,
if (req->content_type_value) {
ret = http_add_header_field(ctx, HTTP_CONTENT_TYPE,
req->content_type_value,
user_data);
NULL, user_data);
if (ret < 0) {
goto out;
}
@ -132,23 +132,25 @@ int http_request(struct http_ctx *ctx, struct http_request *req, s32_t timeout,
}
ret = http_add_header_field(ctx, HTTP_CONTENT_LEN,
content_len_str, user_data);
content_len_str,
NULL, user_data);
if (ret < 0) {
goto out;
}
ret = http_add_header(ctx, HTTP_CRLF, user_data);
ret = http_add_header(ctx, HTTP_CRLF, NULL, user_data);
if (ret < 0) {
goto out;
}
ret = http_prepare_and_send(ctx, req->payload,
req->payload_size, user_data);
req->payload_size,
NULL, user_data);
if (ret < 0) {
goto out;
}
} else {
ret = http_add_header(ctx, HTTP_EOF, user_data);
ret = http_add_header(ctx, HTTP_EOF, NULL, user_data);
if (ret < 0) {
goto out;
}
@ -606,8 +608,10 @@ static void http_connected(struct net_app_ctx *app_ctx,
return;
}
if (ctx->cb.connect) {
ctx->cb.connect(ctx, HTTP_CONNECTION, ctx->user_data);
if (ctx->cb.connect && app_ctx->default_ctx) {
ctx->cb.connect(ctx, HTTP_CONNECTION,
&app_ctx->default_ctx->remote,
ctx->user_data);
}
if (ctx->is_connected) {