1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-25 09:34:11 +00:00

New port: www/gwsocket Simple WebSocket Server

gwsocket is a simple, standalone, language-agnostic, RFC6455 compliant
WebSocket Server, written in C. It sits between your application and the
client's browser, giving fast bidirectional communication between these two
with ease and flexibility.

More info at: http://gwsocket.io.

PR:             247884
Submitted by:   Daniel Morante <daniel@morante.net>
This commit is contained in:
Tobias C. Berner 2020-08-15 05:30:41 +00:00
parent c7176e70a0
commit 40740c7d13
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=544909
9 changed files with 331 additions and 0 deletions

View File

@ -220,6 +220,7 @@
SUBDIR += gtkhtml4
SUBDIR += guacamole-client
SUBDIR += guile-www
SUBDIR += gwsocket
SUBDIR += h2o
SUBDIR += h2o-devel
SUBDIR += habari

66
www/gwsocket/Makefile Normal file
View File

@ -0,0 +1,66 @@
# Created by: Daniel Morante <daniel@morante.net>
# $FreeBSD$
PORTNAME= gwsocket
PORTVERSION= 0.3
CATEGORIES= www
MASTER_SITES= http://tar.gwsocket.io/
MAINTAINER= daniel@morante.net
COMMENT= RFC6455 compliant WebSocket Server
LICENSE= MIT
LICENSE_FILE= ${WRKSRC}/COPYING
USES= alias compiler:c11 pkgconfig
GNU_CONFIGURE= yes
PORTDOCS= AUTHORS COPYING ChangeLog NEWS README
OPTIONS_DEFINE= DOCS DEBUG OPENSSL EXAMPLES
OPTIONS_SUB= yes
DEBUG_CONFIGURE_ON= --enable-debug
OPENSSL_USES= ssl autoreconf
OPENSSL_PATCH_SITES= https://github.com/allinurl/${PORTNAME}/commit/
OPENSSL_PATCHFILES= 3d4e1d1585e5aa54e9500f58efede57feeed7d3d.patch:-p1 # https://github.com/allinurl/gwsocket/issues/28
OPENSSL_LIBS= -lcrypto
OPENSSL_CONFIGURE_WITH= openssl
USE_RC_SUBR= ${PORTNAME}
USERS= www
GROUPS= www
DEFAULT_RUNDIR?= /var/run/${PORTNAME}
DEFAULT_LOGDIR?= /var/log/${PORTNAME}
SUB_FILES= pkg-message
SUB_LIST+= PORTNAME=${PORTNAME} \
DEFAULT_USER=${USERS} \
DEFAULT_GROUP=${GROUPS} \
DEFAULT_RUNDIR=${DEFAULT_RUNDIR} \
DEFAULT_LOGDIR=${DEFAULT_LOGDIR}
PLIST_SUB+= DEFAULT_USER=${USERS} \
DEFAULT_GROUP=${GROUPS} \
DEFAULT_RUNDIR=${DEFAULT_RUNDIR} \
DEFAULT_LOGDIR=${DEFAULT_LOGDIR}
do-install-DOCS-on:
@${MKDIR} ${STAGEDIR}${DOCSDIR}
${INSTALL_DATA} ${PORTDOCS:S,^,${WRKSRC}/,} ${STAGEDIR}${DOCSDIR}
post-install-EXAMPLES-on:
@${MKDIR} ${STAGEDIR}${EXAMPLESDIR}
${INSTALL_DATA} ${FILESDIR}/sample.html ${STAGEDIR}${EXAMPLESDIR}
post-install:
@${MKDIR} ${STAGEDIR}${ETCDIR} \
${STAGEDIR}${DEFAULT_RUNDIR} \
${STAGEDIR}${DEFAULT_LOGDIR}
${INSTALL_DATA} ${FILESDIR}/${PORTNAME}.conf \
${STAGEDIR}${ETCDIR}/${PORTNAME}.conf.sample
.include <bsd.port.mk>

5
www/gwsocket/distinfo Normal file
View File

@ -0,0 +1,5 @@
TIMESTAMP = 1594435125
SHA256 (gwsocket-0.3.tar.gz) = b2a46bbbc99faaf2dd99095d81bc29128fe54298ba6f4f9203ec3d2e4cc4c528
SIZE (gwsocket-0.3.tar.gz) = 146851
SHA256 (3d4e1d1585e5aa54e9500f58efede57feeed7d3d.patch) = c9b34acbf596de86488aedb725be847c4478bb57eab62899d381c63966515235
SIZE (3d4e1d1585e5aa54e9500f58efede57feeed7d3d.patch) = 1518

View File

@ -0,0 +1,42 @@
# This config file is evaluated by the rc script from the FreeBSD port of www/gwsocket.
# It is not related to gwsocket(1) itself.
#
# Most options are set with "name=value" assignments.
# Specifies the port to bind. (-p --port)
#port=7890
# Specifies the path/file for the access log. (--access-log=<path/file>)
#access-log=/var/log/gwsocket/gwsocket-access.log
# Specifies the address to bind. (--addr=<addr>)
#addr=127.0.0.1
# Set the server to echo all received messages. (--echo-mode)
# Exclude, set to 'false' or 'no' to disable. Set to 'true' or 'yes' to enable
#echo-mode=no
# Maximum size of a websocket frame. This includes received frames from the
# client and messages through the named pipe. (--max-frame-size=<bytes>)
#max-frame-size=
# Ensure clients send the specified origin header upon the WebSocket
# handshake. (--origin=<origin>)
#origin=
# Creates a named pipe (FIFO) that reads from on the given path/file. (--pipein=<path/file>)
#pipein=
# Creates a named pipe (FIFO) that writes to the given path/file. (--pipeout=<path/file>)
#pipeout=
# Parse messages using strict mode. See man page for more details. (--strict)
# Exclude, set to 'false' or 'no' to disable. Set to 'true' or 'yes' to enable
#strict=no
# Path to TLS/SSL certificate. (--ssl-cert=<cert.crt>)
#ssl-cert=
# Path to TLS/SSL private key. (--ssl-key=<priv.key>)
#ssl-key=

View File

@ -0,0 +1,138 @@
#!/bin/sh
# $FreeBSD$
#
# PROVIDE: %%PORTNAME%%
# REQUIRE: LOGIN
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf to enable %%PORTNAME%%
# %%PORTNAME%%_enable="YES"
#
# Add the following lines to /etc/rc.conf to enable multiple instances of %%PORTNAME%%
# %%PORTNAME%%_multi_enable="YES"
# An instance is created for each *.conf file found in the configration files directory
#
# %%PORTNAME%%_enable (bool): Set to YES to enable %%PORTNAME%%
# Default: NO
# %%PORTNAME%%_multi_enable (bool): Set to YES to run multiple instances (%%PORTNAME%%_config is ignored)
# Default: NO
# %%PORTNAME%%_conf_d (str): %%PORTNAME%% configration files directory
# Default: %%ETCDIR%%
# %%PORTNAME%%_config (str): %%PORTNAME%% configration file (ignored when %%PORTNAME%%_multi_enable="YES")
# Default: %%ETCDIR%%/%%PORTNAME%%.conf
# %%PORTNAME%%_user (str): %%PORTNAME%% daemon user
# Default: %%DEFAULT_USER%%
# %%PORTNAME%%_group (str): %%PORTNAME%% daemon group
# Default: %%DEFAULT_GROUP%%
# %%PORTNAME%%_logdir (str): %%PORTNAME%% log directory
# Default: %%DEFAULT_LOGDIR%%
# %%PORTNAME%%_piddir (str): %%PORTNAME%% pid file directory
# Default: %%DEFAULT_RUNDIR%%
. /etc/rc.subr
name="%%PORTNAME%%"
rcvar=%%PORTNAME%%_enable
load_rc_config $name
: ${%%PORTNAME%%_enable:="NO"}
: ${%%PORTNAME%%_multi_enable:="NO"}
: ${%%PORTNAME%%_user:="%%DEFAULT_USER%%"}
: ${%%PORTNAME%%_group:="%%DEFAULT_GROUP%%"}
: ${%%PORTNAME%%_conf_d:="%%ETCDIR%%"}
: ${%%PORTNAME%%_config:="${%%PORTNAME%%_conf_d%/}/${name}.conf"}
: ${%%PORTNAME%%_logdir:="%%DEFAULT_LOGDIR%%"}
: ${%%PORTNAME%%_piddir:="%%DEFAULT_RUNDIR%%"}
required_dirs="${%%PORTNAME%%_logdir} ${%%PORTNAME%%_piddir}"
required_files=${%%PORTNAME%%_config}
procname="%%PREFIX%%/bin/${name}"
procdesc="${name}"
pidfile="${%%PORTNAME%%_piddir%/}/${name}.pid"
logfile="${%%PORTNAME%%_logdir%/}/${name}.log"
command=/usr/sbin/daemon
start_precmd="%%PORTNAME%%_precmd"
%%PORTNAME%%_precmd()
{
# Loads the options declared in the configuration file into "$command_args".
%%PORTNAME%%_conf_to_args ${%%PORTNAME%%_config}
}
%%PORTNAME%%_conf_to_args()
{
local _line %%PORTNAME%%_config_param %%PORTNAME%%_config_value config_file_path=$1
command_args="-f -t ${procdesc} -p ${pidfile} -o ${logfile} ${procname}"
while read -r _line; do
# Only proceed with lines which contain variable declaration.
echo "${_line}" | grep -q -E \
-e "^[[:blank:]]*[[:alpha:]_-][[:alnum:]_-]{0,30}=" ||
continue
%%PORTNAME%%_config_param=${_line%%=*}
%%PORTNAME%%_config_value=${_line#*=}
# Properly handle flag type paramaters
if %%PORTNAME%%_is_flag_param ${%%PORTNAME%%_config_param}; then
if checkyesno %%PORTNAME%%_config_value; then
command_args="$command_args --${%%PORTNAME%%_config_param}"
fi
elif [ -n "${%%PORTNAME%%_config_value}" ]; then
command_args="$command_args --${%%PORTNAME%%_config_param}=${%%PORTNAME%%_config_value}"
fi
done < ${config_file_path}
}
%%PORTNAME%%_find_instances()
{
local instance_config
for instance_config in ${%%PORTNAME%%_conf_d%/}/*.conf; do
[ -f "$instance_config" ] || break
%%PORTNAME%%_instances="$%%PORTNAME%%_instances $(basename ${instance_config%.conf})";
done
}
%%PORTNAME%%_is_flag_param()
{
case $1 in
'echo-mode' | 'strict' )
return 0
;;
*)
return 1
;;
esac
}
# Handles multi-instance feature
if [ $# -eq 2 ]; then
# Performs action on single instance by name
_instance=$2
echo "===> Instance: ${_instance}"
# Setup for the requested instance name
%%PORTNAME%%_config="${%%PORTNAME%%_conf_d%/}/${_instance}.conf"
procdesc="${name}_${_instance}"
pidfile="${%%PORTNAME%%_piddir%/}/${_instance}.pid"
logfile="${%%PORTNAME%%_logdir%/}/${_instance}.log"
# The config file for the named instance must exist
required_files="${%%PORTNAME%%_config}"
elif checkyesno %%PORTNAME%%_multi_enable; then
# Compile list of all instances or given instances
_swap=$*; shift; _instances=$*
%%PORTNAME%%_find_instances
_instances=${_instances:-${%%PORTNAME%%_instances}}
set -- ${_swap}
# Performs action on each instance
for _instance in ${_instances}; do
%%PREFIX%%/etc/rc.d/${name} $1 ${_instance}
done
exit 0
fi
run_rc_command "$1"

View File

@ -0,0 +1,26 @@
[
{ type: install
message: <<EOM
To run %%PORTNAME%% at startup, enable it in your /etc/rc.conf:
sysrc %%PORTNAME%%_enable="YES"
To start %%PORTNAME%%:
service %%PORTNAME%% start
To configure %%PORTNAME%% edit:
%%ETCDIR%%/%%PORTNAME%%.conf
A client example can be found at %%EXAMPLESDIR%%/sample.html
To run multiple instances of %%PORTNAME%%, enable it in your /etc/rc.conf:
sysrc %%PORTNAME%%_multi_enable="YES"
An instance will be created for each *.conf file found in:
%%ETCDIR%%
EOM
}
]

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<style>
pre {
background: #EEE;
border: 1px solid #CCC;
padding: 10px;
}
#page-wrapper {
border-top: 5px solid #69c773;
margin: 1em auto;
width: 950px;
}
</style>
<script>
window.onload = function() {
function $(selector) {
return document.querySelector(selector);
}
var socket = new WebSocket('ws://localhost:7890');
socket.onopen = function(event) {
$('#messages').innerHTML = 'Connected<br>';
};
socket.onmessage = function(event) {
$('#messages').innerHTML += 'Received:<br>' + event.data + '<br>';
};
socket.onclose = function(event) {
$('#messages').innerHTML = 'Disconnected ' + event.reason;
};
$('#submit').onclick = function(e) {
socket.send($('input').value);
$('#messages').innerHTML += 'Sent:<br>' + $('input').value + '<br>';
$('input').value = '';
};
};
</script>
<div id="page-wrapper">
<pre id="messages">Connecting...</pre>
<input id="message" required>
<button id="submit">Send Message</button>
</div>

4
www/gwsocket/pkg-descr Normal file
View File

@ -0,0 +1,4 @@
gwsocket is a simple, standalone, language-agnostic, RFC6455 compliant
WebSocket Server, written in C.
WWW: https://gwsocket.io

6
www/gwsocket/pkg-plist Normal file
View File

@ -0,0 +1,6 @@
bin/gwsocket
man/man1/gwsocket.1.gz
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/sample.html
@sample %%ETCDIR%%/gwsocket.conf.sample
@dir(%%DEFAULT_USER%%,%%DEFAULT_GROUP%%,) %%DEFAULT_LOGDIR%%
@dir(%%DEFAULT_USER%%,%%DEFAULT_GROUP%%,) %%DEFAULT_RUNDIR%%