Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to build http server #648

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ AC_ARG_WITH(mysql,
[MYSQL_CONFIG=$with_mysql],
[MYSQL_CONFIG="default_mysql_config"])

AC_ARG_ENABLE(httpserver, AC_HELP_STRING([--enable-httpserver], [enable httpserver]),
[compile_httpserver=$enableval],[compile_httpserver="yes"])

AM_CONDITIONAL([COMPILE_TOOLS], [test "${compile_tools}" = "yes"])
AM_CONDITIONAL([COMPILE_PYTHON], [test "${compile_python}" = "yes"])
AM_CONDITIONAL([COMPILE_FUSE], [test "${compile_fuse}" = "yes"])

AM_CONDITIONAL([WIN32], [test "$bwin32" = "true"])
AM_CONDITIONAL([MACOS], [test "$bmac" = "true"])
AM_CONDITIONAL([LINUX], [test "$blinux" = "true"])
Expand Down Expand Up @@ -260,6 +262,10 @@ if test "${compile_ldap}" = "yes"; then

fi

if test "${compile_httpserver}" = "yes"; then
AC_DEFINE([HAVE_EVHTP], [1], [Define to 1 if httpserver is enabled.])
fi

PKG_CHECK_MODULES(CURL, [libcurl >= $CURL_REQUIRED])
AC_SUBST(CURL_CFLAGS)
AC_SUBST(CURL_LIBS)
Expand Down
2 changes: 2 additions & 0 deletions server/access-file.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common.h"

#ifdef HAVE_EVHTP
#define DEBUG_FLAG SEAFILE_DEBUG_HTTP
#include "log.h"

Expand Down Expand Up @@ -1546,3 +1547,4 @@ access_file_init (evhtp_t *htp)

return 0;
}
#endif
2 changes: 2 additions & 0 deletions server/access-file.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef ACCESS_FILE_H
#define ACCESS_FILE_H

#ifdef HAVE_EVHTP
int
access_file_init (evhtp_t *htp);
#endif

#endif
13 changes: 11 additions & 2 deletions server/http-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include <event.h>
#endif

#ifdef HAVE_EVHTP
#include <evhtp.h>
#endif

#include <jwt.h>

Expand Down Expand Up @@ -61,8 +63,11 @@
#define FS_ID_LIST_TOKEN_LEN 36

struct _HttpServer {
#ifdef HAVE_EVHTP
evbase_t *evbase;
evhtp_t *evhtp;
event_t *reap_timer;
#endif
pthread_t thread_id;

GHashTable *token_cache;
Expand All @@ -74,8 +79,6 @@ struct _HttpServer {
GHashTable *vir_repo_info_cache;
pthread_mutex_t vir_repo_info_cache_lock;

event_t *reap_timer;

GThreadPool *compute_fs_obj_id_pool;

GHashTable *fs_obj_ids;
Expand Down Expand Up @@ -292,6 +295,7 @@ load_http_config (HttpServerStruct *htp_server, SeafileSession *session)
}
}

#ifdef HAVE_EVHTP
static int
validate_token (HttpServer *htp_server, evhtp_request_t *req,
const char *repo_id, char **username,
Expand Down Expand Up @@ -2872,6 +2876,7 @@ http_request_init (HttpServerStruct *server)
if (upload_file_init (priv->evhtp, server->http_temp_dir) < 0)
exit(-1);
}
#endif

static void
token_cache_value_free (gpointer data)
Expand Down Expand Up @@ -2963,6 +2968,7 @@ remove_expire_cache_cb (evutil_socket_t sock, short type, void *data)
static void *
http_server_run (void *arg)
{
#ifdef HAVE_EVHTP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么不能把整个 http-server.c 禁用呢?

HttpServerStruct *server = arg;
HttpServer *priv = server->priv;

Expand Down Expand Up @@ -2992,6 +2998,7 @@ http_server_run (void *arg)

event_base_loop (priv->evbase, 0);

#endif
return NULL;
}

Expand All @@ -3001,8 +3008,10 @@ seaf_http_server_new (struct _SeafileSession *session)
HttpServerStruct *server = g_new0 (HttpServerStruct, 1);
HttpServer *priv = g_new0 (HttpServer, 1);

#ifdef HAVE_EVHTP
priv->evbase = NULL;
priv->evhtp = NULL;
#endif

load_http_config (server, session);

Expand Down
2 changes: 2 additions & 0 deletions server/http-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ int
seaf_http_server_invalidate_tokens (HttpServerStruct *htp_server,
const GList *tokens);

#ifdef HAVE_EVHTP
void
send_statistic_msg (const char *repo_id, char *user, char *operation, guint64 bytes);
#endif

#endif
2 changes: 2 additions & 0 deletions server/upload-file.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common.h"

#ifdef HAVE_EVHTP
#define DEBUG_FLAG SEAFILE_DEBUG_HTTP
#include "log.h"

Expand Down Expand Up @@ -2697,3 +2698,4 @@ upload_file_init (evhtp_t *htp, const char *http_temp_dir)

return 0;
}
#endif
2 changes: 2 additions & 0 deletions server/upload-file.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef UPLOAD_FILE_H
#define UPLOAD_FILE_H

#ifdef HAVE_EVHTP
int
upload_file_init (evhtp_t *evhtp, const char *http_temp_dir);
#endif

#endif
Loading