https://github.com/babelouest/ulfius/releases/latest
现在地址,安装后打开INSTALL.md 文件,查看需要安装的依赖库文件
apt install -y libmicrohttpd-dev libjansson-dev libcurl4-gnutls-dev libgnutls28-dev libgcrypt20-dev zlib1g-dev
安装zip压缩包,继续手动安装依赖库:
Last Orcania release: [https://github.com/babelouest/orcania/releases/latest/](https://github.com/babelouest/orcania/releases/latest/)
Last Yder release: [https://github.com/babelouest/yder/releases/latest/](https://github.com/babelouest/orcania/releases/latest/)
注:这两个使用apt命令安装的版本太久,所以需要安装最新版本从源代码安装。
在configure.ac 编写:
AC_CHECK_LIB([ulfius], [ulfius_init_instance], [], [AC_MSG_ERROR([ulfius library not found])])
if test "$ulfius_found" = "yes"; then
AC_DEFINE(HAVE_CRYPTO, 1, [Define when ulfius library is found])
LIBS = "$LIBS -lulfius"
编写代码启用https服务:
do_something() //http方法触发的回调函数
// 读取ssl文件函数
static char * read_file(const char * filename) {
char * buffer = NULL;
long length;
FILE * f;
if (filename != NULL) {
f = fopen (filename, "rb");
if (f) {
fseek (f, 0, SEEK_END);
length = ftell (f);
fseek (f, 0, SEEK_SET);
buffer = malloc ((size_t)(length + 1));
if (buffer != NULL) {
fread (buffer, 1, (size_t)length, f);
buffer[length] = '\0';
}
fclose (f);
}
return buffer;
} else {
return NULL;
}
}
int https_init()
{
struct _u_instance g_instance;
if (ulfius_init_instance(&g_instance, REST_PORT, NULL, NULL) != U_OK) {
return -1;
}// 初始化
ulfius_add_endpoint_by_val(&g_instance, "GET", "/start", NULL, 0, &do_something, NULL);
// 读取ssl密钥
char * key_pem = read_file("./ca.key"), * cert_pem = read_file("./ca.crt");
// 启动https服务
ret = ulfius_start_secure_framework(&g_instance, key_pem, cert_pem);
free(key_pem);
free(cert_pem);
}