Skip to content

Commit

Permalink
http2d: Initial version
Browse files Browse the repository at this point in the history
New "http2d" module, providing an RFC 7540/9113 HTTP/2 server
implementation, based on "nghttp2" library (https://nghttp2.org/).
  • Loading branch information
liviuchircu authored and bogdan-iancu committed Apr 18, 2024
1 parent dc0d658 commit 4e69c8c
Show file tree
Hide file tree
Showing 4 changed files with 928 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/http2d/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# WARNING: do not run this directly, it should be run by the master Makefile

include ../../Makefile.defs
auto_gen=
NAME=http2d.so

#DEFS +=-I$(LOCALBASE)/include
LIBS +=-L$(LOCALBASE)/lib -lssl -lcrypto -levent -lnghttp2 -levent_openssl

include ../../Makefile.modules

112 changes: 112 additions & 0 deletions modules/http2d/http2d.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (C) 2024 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* opensips 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA
*/

#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>

#include "../../globals.h"
#include "../../sr_module.h"
#include "../../str.h"
#include "../../ut.h"
#include "../../mem/mem.h"

#include "server.h"

/* module functions */
static int mod_init();
static void mod_destroy(void);

unsigned int h2_port = 9111;
char *h2_ip;
str h2_tls_cert = STR_NULL;
str h2_tls_key = STR_NULL;


static const proc_export_t procs[] = {
{"HTTP2D", 0, 0, http2_server, 1, PROC_FLAG_INITCHILD },
{NULL, 0, 0, NULL, 0, 0}
};

/* Module parameters */
static const param_export_t params[] = {
{"port", INT_PARAM, &h2_port},
{"ip", STR_PARAM, &h2_ip},
{"tls_cert_file", STR_PARAM, &h2_tls_cert.s},
{"tls_key_file", STR_PARAM, &h2_tls_key.s},
{NULL, 0, NULL}
};

/* MI commands */
static const mi_export_t mi_cmds[] = {
{EMPTY_MI_EXPORT},
};

/* Module exports */
struct module_exports exports = {
"http2d", /* module name */
MOD_TYPE_DEFAULT, /* class of this module */
MODULE_VERSION,
DEFAULT_DLFLAGS, /* dlopen flags */
0, /* load function */
NULL, /* OpenSIPS module dependencies */
NULL, /* exported functions */
0, /* exported async functions */
params, /* exported parameters */
NULL, /* exported statistics */
mi_cmds, /* exported MI functions */
NULL, /* exported PV */
NULL, /* exported transformations */
procs, /* extra processes */
0, /* module pre-initialization function */
mod_init, /* module initialization function */
(response_function) NULL, /* response handling function */
(destroy_function) mod_destroy, /* destroy function */
NULL, /* per-child init function */
NULL /* reload confirm function */
};


static int mod_init(void)
{
if (!h2_tls_cert.s) {
LM_ERR("no TLS cert filepath provided (mandatory)\n");
return -1;
}

if (!h2_tls_key.s) {
LM_ERR("no TLS key filepath provided (mandatory)\n");
return -1;
}

if (!h2_ip)
h2_ip = "127.0.0.1";

h2_tls_cert.len = strlen(h2_tls_cert.s);
h2_tls_key.len = strlen(h2_tls_key.s);

return 0;
}


static void mod_destroy(void)
{
return;
}

0 comments on commit 4e69c8c

Please sign in to comment.