update domo-iot
This commit is contained in:
72
src/main.c
Normal file
72
src/main.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/*!
|
||||
* main.c
|
||||
*
|
||||
* Copyright (c) 2015-2019, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* @Author: NADAL Jean-Baptiste
|
||||
* @Date: 08/11/2019
|
||||
*
|
||||
*/
|
||||
|
||||
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <asyncd/asyncd.h>
|
||||
|
||||
int my_http_get_handler(short event, ad_conn_t *conn, void *userdata)
|
||||
{
|
||||
if (event & AD_EVENT_READ)
|
||||
{
|
||||
if (ad_http_get_status(conn) == AD_HTTP_REQ_DONE)
|
||||
{
|
||||
ad_http_response(conn, 200, "text/html", "Hello World", 11);
|
||||
return ad_http_is_keepalive_request(conn) ? AD_DONE : AD_CLOSE;
|
||||
}
|
||||
}
|
||||
return AD_OK;
|
||||
}
|
||||
|
||||
int my_http_default_handler(short event, ad_conn_t *conn, void *userdata)
|
||||
{
|
||||
if (event & AD_EVENT_READ)
|
||||
{
|
||||
if (ad_http_get_status(conn) == AD_HTTP_REQ_DONE)
|
||||
{
|
||||
ad_http_response(conn, 501, "text/html", "Not implemented", 15);
|
||||
return AD_CLOSE; // Close connection.
|
||||
}
|
||||
}
|
||||
return AD_OK;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//SSL_load_error_strings();
|
||||
//SSL_library_init();
|
||||
ad_log_level(AD_LOG_DEBUG);
|
||||
ad_server_t *server = ad_server_new();
|
||||
ad_server_set_option(server, "server.port", "8888");
|
||||
//ad_server_set_ssl_ctx(server,
|
||||
// ad_server_ssl_ctx_create_simple("ssl.cert", "ssl.pkey"));
|
||||
ad_server_register_hook(server, ad_http_handler, NULL); // HTTP Parser is also a hook.
|
||||
ad_server_register_hook_on_method(server, "GET", my_http_get_handler, NULL);
|
||||
ad_server_register_hook(server, my_http_default_handler, NULL);
|
||||
return ad_server_start(server);
|
||||
}
|
||||
Reference in New Issue
Block a user