Mod aaa-12 添加web server插件接口

RCA:
SOL:
修改人:huangxin
检视人:huangxin
This commit is contained in:
huangxin 2019-10-09 16:21:50 +08:00
parent e43238ff4c
commit bd8083dfe9
4 changed files with 122 additions and 6 deletions

View File

@ -1,6 +1,6 @@
#var.log_root = "/home/cmhi/secogateway/libs/files/lighttpd/log"
var.server_root = "/usr/Product_usr/files/lighttpd"
var.server_root = "/mnt/e/wsl/webs"
#var.state_dir = "/home/cmhi/secogateway/libs/files/lighttpd"
#var.home_dir = "/home/cmhi/secogateway/libs/files/lighttpd"
#var.conf_dir = "/home/cmhi/secogateway/libs/files/lighttpd/config"

View File

@ -42,6 +42,7 @@
server.modules = (
"mod_portal",
"mod_usermagnet",
"mod_object",
# "mod_webm",
# "mod_access",
# "mod_alias",

View File

@ -419,6 +419,11 @@ mod_usermagnet_la_SOURCES = mod_usermagnet.c json.c user_hashtable.c user_auth.c
mod_usermagnet_la_LDFLAGS = -module -export-dynamic -avoid-version -L../../../../Platform/build/debug/
mod_usermagnet_la_LIBADD = $(common_libadd) -ldatabase-$(host_cpu)
lib_LTLIBRARIES += mod_object.la
mod_object_la_SOURCES = mod_object.c
mod_object_la_LDFLAGS = -module -export-dynamic -avoid-version -L../../../../Platform/build/debug/
mod_object_la_LIBADD = $(common_libadd)
hdr = server.h base64.h buffer.h burl.h network.h log.h http_kv.h keyvalue.h \
response.h request.h fastcgi.h chunk.h \
first.h settings.h http_chunk.h \

View File

@ -0,0 +1,110 @@
#include "first.h"
#include "base.h"
#include "log.h"
#include "buffer.h"
#include "http_header.h"
#include "sock_addr.h"
#include "plugin.h"
#include <stdlib.h>
#include <string.h>
#define OBJECT_PATH ("/object")
typedef struct {
unsigned short max_conns;
unsigned short silent;
buffer *location;
} plugin_config;
typedef struct {
PLUGIN_DATA;
plugin_config **config_storage;
plugin_config conf;
} plugin_data;
INIT_FUNC(mod_object_init)
{
plugin_data *p;
p = calloc(1, sizeof(*p));
return p;
}
FREE_FUNC(mod_object_free)
{
plugin_data *p = p_d;
UNUSED(srv);
if(!p) {
return HANDLER_GO_ON;
}
free(p);
return HANDLER_GO_ON;
}
SETDEFAULTS_FUNC(mod_object_set_defaults)
{
plugin_data *p = p_d;
UNUSED(p);
UNUSED(srv);
return HANDLER_GO_ON;
}
URIHANDLER_FUNC(mod_object_uri_handler)
{
plugin_data *p = p_d;
UNUSED(p);
log_error_write(srv, __FILE__, __LINE__, "s", "test");
if(buffer_is_empty(con->uri.path)) {
return HANDLER_GO_ON;
}
log_error_write(srv, __FILE__, __LINE__, "s", "test");
if(0 == strncmp(con->uri.path->ptr, OBJECT_PATH, strlen(OBJECT_PATH))) {
chunk *c;
chunkqueue *cq = con->request_content_queue;
buffer *result_info = buffer_init();
buffer *content_buffer = buffer_init();
log_error_write(srv, __FILE__, __LINE__, "ss", "path:", con->uri.path->ptr);
for(c = cq->first; c && content_buffer; c = c->next) {
size_t len = buffer_string_length(c->mem) - c->offset;
buffer_append_string_len(content_buffer, c->mem->ptr + c->offset, len);
}
log_error_write(srv, __FILE__, __LINE__, "ss", "Json:", content_buffer->ptr);
if(result_info) {
buffer_copy_string(result_info, "{\"message\" : \"OK\"}");
chunkqueue_append_buffer(con->write_queue, result_info);
buffer_free(result_info);
con->mode = DIRECT;
con->http_status = 200;
con->file_finished = 1;
}
return HANDLER_FINISHED;
}
log_error_write(srv, __FILE__, __LINE__, "s", "test");
return HANDLER_GO_ON;
}
int mod_object_plugin_init(plugin *p)
{
p->version = LIGHTTPD_VERSION_ID;
p->name = buffer_init_string("object");
p->init = mod_object_init;
p->set_defaults = mod_object_set_defaults;
p->handle_uri_clean = mod_object_uri_handler;
p->cleanup = mod_object_free;
p->data = NULL;
return 0;
}