Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
/src/samples/http/server-https.c
/*
* This file is part of the Soletta (TM) Project
*
* Copyright (C) 2016 Intel Corporation. All rights reserved.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include "soletta.h"
#include "sol-http.h"
static struct sol_cert *cert, *key;
static struct sol_http_server *server;
static char *server_data;
static int
request_cb(void *data, struct sol_http_request *request)
{
int r;
struct sol_http_response response = {
.response_code = SOL_HTTP_STATUS_OK,
};
r = sol_http_server_send_response(request, &response);
return r;
}
static void
{
char **argv = sol_argv();
int port = 8080;
int c, opt_idx, argc = sol_argc();
static const struct option opts[] = {
{ "port", required_argument, NULL, 'p' },
{ "certificate", required_argument, NULL, 'c' },
{ "key", required_argument, NULL, 'k' },
{ "data", required_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
};
while ((c = getopt_long(argc, argv, "p:c:k:d:h", opts,
&opt_idx)) != -1) {
switch (c) {
case 'p':
port = atoi(optarg);
break;
case 'c':
if (!cert)
goto err;
break;
case 'k':
if (!key)
goto err;
break;
case 'd':
server_data = optarg;
break;
case 'h':
default:
fprintf(stderr,
"Usage:\n\t%s [-p <port >]\n"
"\t [-c <certificate to use>]\n"
"\t [-k <certificate key>]\n"
"\t [-d <data to serve>]\n",
argv[0]);
sol_quit_with_code(EXIT_SUCCESS);
return;
}
}
if (!server_data) {
fprintf(stderr, "ERROR: No data was given. Run with -h or --help for help\n");
goto err;
}
.port = port,
.security = {
.cert = cert,
.key = key,
}
});
if (!server) {
fprintf(stderr, "ERROR: Failed to create the server\n");
goto err;
}
request_cb, NULL) < 0) {
fprintf(stderr, "ERROR: Failed to register the handler\n");
goto err;
}
return;
err:
sol_quit_with_code(EXIT_FAILURE);
}
static void
{
if (server)
}