mirror of
https://github.com/kakwa/uts-server
synced 2024-12-04 23:15:54 +01:00
begin implementing the http part
This commit is contained in:
parent
44a28dde81
commit
ba1e79e848
@ -0,0 +1 @@
|
||||
int http_server_start();
|
@ -7,6 +7,7 @@
|
||||
#include <argp.h>
|
||||
#include <sys/syslog.h>
|
||||
#include "utils.h"
|
||||
#include "rfc3161.h"
|
||||
|
||||
const char *argp_program_version = UTS_VERSION;
|
||||
|
||||
@ -68,6 +69,7 @@ int main(int argc, char **argv)
|
||||
while (1)
|
||||
{
|
||||
//TODO: Insert daemon code here.
|
||||
http_server_start();
|
||||
syslog (LOG_NOTICE, "First daemon started.");
|
||||
sleep (5);
|
||||
break;
|
||||
|
@ -7,4 +7,38 @@
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/ts.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <asyncd/asyncd.h>
|
||||
|
||||
int ts_http_respond(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 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 http_server_start() {
|
||||
//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", ts_http_respond, NULL);
|
||||
ad_server_register_hook(server, http_default_handler, NULL);
|
||||
return ad_server_start(server);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user