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 websockets #2693

Merged
merged 5 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 10 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ JANSSON_REQUIRED=2.2.1
CURL_REQUIRED=7.17
ZLIB_REQUIRED=1.2.0
GNUTLS_REQUIRED=3.3.0
WS_REQUIRED=4.0.20

PKG_CHECK_MODULES(GLIB2, [glib-2.0 >= $GLIB_REQUIRED])
AC_SUBST(GLIB2_CFLAGS)
Expand Down Expand Up @@ -188,19 +189,22 @@ PKG_CHECK_MODULES(CURL, [libcurl >= $CURL_REQUIRED])
AC_SUBST(CURL_CFLAGS)
AC_SUBST(CURL_LIBS)

AC_ARG_ENABLE(ws, AC_HELP_STRING([--enable-ws], [enable build websockets]),
[compile_linux_ws=$enableval],[compile_linux_ws="yes"])
AM_CONDITIONAL([COMPILE_LINUX_WS], [test "${compile_linux_ws}" = "yes"])
if test "${compile_linux_ws}" = "yes"; then
PKG_CHECK_MODULES(WS, [libwebsockets >= $WS_REQUIRED])
AC_SUBST(WS_CFLAGS)
AC_SUBST(WS_LIBS)
fi

if test "$bwin32" != true; then
# do not check libevent_pthreads in win32
PKG_CHECK_MODULES(LIBEVENT_PTHREADS, [libevent_pthreads >= $LIBEVENT_PTHREADS_REQUIRED])
AC_SUBST(LIBEVENT_PTHREADS_CFLAGS)
AC_SUBST(LIBEVENT_PTHREADS_LIBS)
fi

if test "$blinux" != true; then
PKG_CHECK_MODULES(WS, [libwebsockets])
AC_SUBST(WS_CFLAGS)
AC_SUBST(WS_LIBS)
fi

AC_ARG_WITH([python3], [AS_HELP_STRING([--with-python3], [use python3])],
[with_python3="yes"],[])

Expand Down
10 changes: 9 additions & 1 deletion daemon/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ if MACOS
wt_monitor_src = wt-monitor.c wt-monitor-macos.c wt-monitor-structs.c
endif

if MACOS
ws_src = notif-mgr.c
else
if COMPILE_LINUX_WS
ws_src = notif-mgr.c
endif
endif
Copy link
Member

Choose a reason for hiding this comment

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

这里多了一个 endif?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里没多,在非MACOS的条件下,判断一下是否有COMPILE_LINUX_WS宏


common_src = \
job-mgr.c timer.c cevent.c \
http-tx-mgr.c \
Expand All @@ -79,7 +87,7 @@ common_src = \
filelock-mgr.c \
set-perm.c \
change-set.c \
notif-mgr.c
$(ws_src)


seaf_daemon_SOURCES = seaf-daemon.c $(common_src)
Expand Down
7 changes: 2 additions & 5 deletions daemon/notif-mgr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#if defined WIN32 || defined __APPLE__

#include "common.h"
#include <libwebsockets.h>
Expand Down Expand Up @@ -623,7 +622,7 @@ handle_folder_perm (json_t *content)
perm);
else if (g_strcmp0 (change_event, "del") == 0)
seaf_repo_manager_delete_folder_perm (seaf->repo_mgr, repo_id,
FOLDER_PERM_TYPE_USER,
FOLDER_PERM_TYPE_GROUP,
perm);
}
g_free (perm);
Expand Down Expand Up @@ -731,7 +730,7 @@ handle_messages (const char *msg, size_t len)

static const struct lws_protocols protocols[] = {
{ "notification.seafile.com", event_callback, 0, 0, 0, NULL, 0 },
LWS_PROTOCOL_LIST_TERM
{NULL, NULL, 0, 0, 0, NULL, 0}
};

static struct lws_context *
Expand Down Expand Up @@ -974,5 +973,3 @@ seaf_notif_manager_is_repo_subscribed (SeafNotifManager *mgr, SeafRepo *repo)
notif_server_unref (server);
return subscribed;
}

#endif
3 changes: 0 additions & 3 deletions daemon/notif-mgr.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#if defined WIN32 || defined __APPLE__

#ifndef NOTIF_MGR_H
#define NOTIF_MGR_H
Expand Down Expand Up @@ -31,5 +30,3 @@ gboolean
seaf_notif_manager_is_repo_subscribed (SeafNotifManager *mgr, SeafRepo *repo);

#endif

#endif
2 changes: 1 addition & 1 deletion daemon/repo-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6640,7 +6640,7 @@ seaf_repo_manager_del_repo (SeafRepoManager *mgr,

pthread_rwlock_unlock (&mgr->priv->lock);

#if defined WIN32 || defined __APPLE__
#if defined WIN32 || defined __APPLE__ || defined COMPILE_LINUX_WS
seaf_notif_manager_unsubscribe_repo (seaf->notif_mgr, repo);
#endif

Expand Down
2 changes: 1 addition & 1 deletion daemon/seafile-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ seafile_session_new(const char *seafile_dir,
if (!session->mq_mgr)
goto onerror;

#if defined WIN32 || defined __APPLE__
#if defined WIN32 || defined __APPLE__ || defined COMPILE_LINUX_WS
session->notif_mgr = seaf_notif_manager_new (session);
#endif

Expand Down
2 changes: 0 additions & 2 deletions daemon/seafile-session.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ struct _SeafileSession {

SeafFilelockManager *filelock_mgr;

#if defined WIN32 || defined __APPLE__
SeafNotifManager *notif_mgr;
#endif

/* Set after all components are up and running. */
gboolean started;
Expand Down
16 changes: 11 additions & 5 deletions daemon/sync-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,7 @@ http_notification_url (const char *url)
return ret;
}

#if defined WIN32 || defined __APPLE__ || defined COMPILE_LINUX_WS
// Returns TRUE if notification server is alive; otherwise FALSE.
// We only check notification server once.
static gboolean
Expand Down Expand Up @@ -1820,6 +1821,7 @@ check_notif_server (SeafSyncManager *mgr, SeafRepo *repo)
g_free (notif_url);
return FALSE;
}
#endif

gint
cmp_repos_by_sync_time (gconstpointer a, gconstpointer b, gpointer user_data)
Expand Down Expand Up @@ -2110,7 +2112,7 @@ check_folder_permissions_one_server_immediately (SeafSyncManager *mgr,
for (ptr = repos; ptr; ptr = ptr->next) {
repo = ptr->data;

#if defined WIN32 || defined __APPLE__
#if defined WIN32 || defined __APPLE__ || defined COMPILE_LINUX_WS
if (!force && seaf_notif_manager_is_repo_subscribed (seaf->notif_mgr, repo))
continue;
#endif
Expand Down Expand Up @@ -2254,7 +2256,7 @@ check_locked_files_one_server_immediately (SeafSyncManager *mgr,
for (ptr = repos; ptr; ptr = ptr->next) {
repo = ptr->data;

#if defined WIN32 || defined __APPLE__
#if defined WIN32 || defined __APPLE__ || defined COMPILE_LINUX_WS
if (!force && seaf_notif_manager_is_repo_subscribed (seaf->notif_mgr, repo))
continue;
#endif
Expand Down Expand Up @@ -2439,10 +2441,10 @@ periodic_sync_due (SeafRepo *repo)
return (now > (repo->last_sync_time + repo->sync_interval));
}

#if defined WIN32 || defined __APPLE__ || defined COMPILE_LINUX_WS
static int
check_and_subscribe_repo (SeafSyncManager *mgr, SeafRepo *repo)
{
#if defined WIN32 || defined __APPLE__
char *url = NULL;
HttpServerState *state = g_hash_table_lookup (mgr->http_server_states,
repo->server_url);
Expand Down Expand Up @@ -2483,10 +2485,10 @@ check_and_subscribe_repo (SeafSyncManager *mgr, SeafRepo *repo)
if (repo->jwt_token)
seaf_notif_manager_subscribe_repo (seaf->notif_mgr, repo);
}
#endif

return 0;
}
#endif

static int
auto_sync_pulse (void *vmanager)
Expand Down Expand Up @@ -2597,19 +2599,23 @@ auto_sync_pulse (void *vmanager)
if (repo->version > 0) {
/* For repo version > 0, only use http sync. */
if (check_http_protocol (manager, repo)) {
#if defined WIN32 || defined __APPLE__
#if defined WIN32 || defined __APPLE__ || defined COMPILE_LINUX_WS
if (check_notif_server (manager, repo)) {
seaf_notif_manager_connect_server (seaf->notif_mgr, repo->server_url, repo->use_fileserver_port);
}
#endif

if (repo->sync_interval == 0) {
sync_repo_v2 (manager, repo, FALSE);
#if defined WIN32 || defined __APPLE__ || defined COMPILE_LINUX_WS
check_and_subscribe_repo (manager, repo);
#endif
}
else if (periodic_sync_due (repo)) {
sync_repo_v2 (manager, repo, TRUE);
#if defined WIN32 || defined __APPLE__ || defined COMPILE_LINUX_WS
check_and_subscribe_repo (manager, repo);
#endif
}
}
} else {
Expand Down