View | Details | Raw Unified | Return to bug 247884 | Differences between
and this patch

Collapse All | Expand All

(-)www/gwsocket/Makefile (+69 lines)
Line 0 Link Here
1
# Created by: Daniel Morante <daniel@morante.net>
2
# $FreeBSD$
3
4
PORTNAME=	gwsocket
5
PORTVERSION=	0.3
6
CATEGORIES=	www
7
MASTER_SITES=	http://tar.gwsocket.io/
8
9
MAINTAINER=	daniel@morante.net
10
COMMENT=	RFC6455 compliant WebSocket Server
11
12
LICENSE=	MIT
13
LICENSE_FILE=	${WRKSRC}/COPYING
14
15
GNU_CONFIGURE=	yes
16
INSTALL_TARGET=	install-strip
17
USES=		alias compiler:c11 pkgconfig
18
USE_LDCONFIG=	yes
19
20
CFLAGS+=	-I${NCURSESINC} -I${LOCALBASE}/include
21
LDFLAGS+=	-L${NCURSESLIB} -L${LOCALBASE}/lib
22
23
PORTDOCS=	AUTHORS COPYING ChangeLog NEWS README
24
25
OPTIONS_DEFINE=	DOCS DEBUG OPENSSL EXAMPLES
26
OPTIONS_SUB=	yes
27
28
DEBUG_CONFIGURE_ON=	--enable-debug
29
30
OPENSSL_USES=           ssl
31
OPENSSL_CONFIGURE_ON=   --with-openssl=${OPENSSLBASE}
32
33
USE_RC_SUBR=	${PORTNAME}
34
35
USERS=	www
36
GROUPS=	www
37
38
DEFAULT_RUNDIR?=  /var/run/${PORTNAME}
39
DEFAULT_LOGDIR?=  /var/log/${PORTNAME}
40
41
SUB_FILES=	pkg-message
42
SUB_LIST+=	PORTNAME=${PORTNAME} \
43
			DEFAULT_USER=${USERS} \
44
			DEFAULT_GROUP=${GROUPS} \
45
			DEFAULT_RUNDIR=${DEFAULT_RUNDIR} \
46
			DEFAULT_LOGDIR=${DEFAULT_LOGDIR}
47
48
PLIST_SUB+=	PORTNAME=${PORTNAME} \
49
			DEFAULT_USER=${USERS} \
50
			DEFAULT_GROUP=${GROUPS} \
51
			DEFAULT_RUNDIR=${DEFAULT_RUNDIR} \
52
			DEFAULT_LOGDIR=${DEFAULT_LOGDIR}
53
54
do-install-DOCS-on:
55
	@${MKDIR} ${STAGEDIR}${DOCSDIR}
56
	${INSTALL_DATA} ${PORTDOCS:S,^,${WRKSRC}/,} ${STAGEDIR}${DOCSDIR}
57
58
post-install-EXAMPLES-on:
59
	@${MKDIR} ${STAGEDIR}${EXAMPLESDIR}
60
	${INSTALL_DATA} ${FILESDIR}/sample.html ${STAGEDIR}${EXAMPLESDIR}
61
62
post-install:
63
	@${MKDIR} ${STAGEDIR}${ETCDIR} \
64
		${STAGEDIR}${DEFAULT_RUNDIR} \
65
		${STAGEDIR}${DEFAULT_LOGDIR}
66
	${INSTALL_DATA} ${FILESDIR}/${PORTNAME}.conf \
67
		${STAGEDIR}${ETCDIR}/${PORTNAME}.conf.sample
68
69
.include <bsd.port.mk>
(-)www/gwsocket/distinfo (+3 lines)
Line 0 Link Here
1
TIMESTAMP = 1594149039
2
SHA256 (gwsocket-0.3.tar.gz) = b2a46bbbc99faaf2dd99095d81bc29128fe54298ba6f4f9203ec3d2e4cc4c528
3
SIZE (gwsocket-0.3.tar.gz) = 146851
(-)www/gwsocket/files/gwsocket.conf (+42 lines)
Line 0 Link Here
1
# This config file is evaluated by the rc script from the FreeBSD port of www/gwsocket.
2
# It is not related to gwsocket(1) itself.
3
# 
4
# Most options are set with "name=value" assignments.
5
6
# Specifies the port to bind. (-p --port)
7
#port=7890
8
9
# Specifies the path/file for the access log. (--access-log=<path/file>)
10
#access-log=/var/log/gwsocket/gwsocket-access.log
11
12
# Specifies the address to bind. (--addr=<addr>)
13
#addr=127.0.0.1
14
15
# Set the server to echo all received messages. (--echo-mode)
16
# Exclude, set to 'false' or 'no' to disable.  Set to 'true' or 'yes' to enable
17
#echo-mode=no
18
19
# Maximum size of a websocket frame. This includes received frames from the 
20
# client and messages through the named pipe. (--max-frame-size=<bytes>)
21
#max-frame-size=
22
23
# Ensure clients send the specified origin header upon the WebSocket 
24
# handshake. (--origin=<origin>)
25
#origin=
26
27
# Creates a named pipe (FIFO) that reads from on the given path/file. (--pipein=<path/file>)
28
#pipein=
29
30
# Creates a named pipe (FIFO) that writes to the given path/file. (--pipeout=<path/file>)
31
#pipeout=
32
33
# Parse messages using strict mode. See man page for more details. (--strict)
34
# Exclude, set to 'false' or 'no' to disable.  Set to 'true' or 'yes' to enable
35
#strict=no
36
37
# Path to TLS/SSL certificate. (--ssl-cert=<cert.crt>)
38
#ssl-cert=
39
40
# Path to TLS/SSL private key. (--ssl-key=<priv.key>)
41
#ssl-key=
42
(-)www/gwsocket/files/gwsocket.in (+138 lines)
Line 0 Link Here
1
#!/bin/sh
2
3
# $FreeBSD:$
4
#
5
# PROVIDE: %%PORTNAME%%
6
# REQUIRE: LOGIN
7
# KEYWORD: shutdown
8
9
# Add the following lines to /etc/rc.conf to enable %%PORTNAME%%
10
# %%PORTNAME%%_enable="YES"
11
#
12
# Add the following lines to /etc/rc.conf to enable multiple instances of %%PORTNAME%%
13
# %%PORTNAME%%_multi_enable="YES"
14
# An instance is created for each *.conf file found in the configration files directory
15
#
16
# %%PORTNAME%%_enable (bool):		Set to YES to enable %%PORTNAME%%
17
#					Default: NO
18
# %%PORTNAME%%_multi_enable (bool):	Set to YES to run multiple instances (%%PORTNAME%%_config is ignored)
19
#					Default: NO
20
# %%PORTNAME%%_conf_d (str):		%%PORTNAME%% configration files directory
21
#					Default: %%ETCDIR%%
22
# %%PORTNAME%%_config (str):		%%PORTNAME%% configration file (ignored when %%PORTNAME%%_multi_enable="YES")
23
#					Default: %%ETCDIR%%/%%PORTNAME%%.conf
24
# %%PORTNAME%%_user (str):		%%PORTNAME%% daemon user
25
#					Default: %%DEFAULT_USER%%
26
# %%PORTNAME%%_group (str):		%%PORTNAME%% daemon group
27
#					Default: %%DEFAULT_GROUP%%
28
# %%PORTNAME%%_logdir (str):		%%PORTNAME%% log directory
29
#					Default: %%DEFAULT_LOGDIR%%
30
# %%PORTNAME%%_piddir (str):		%%PORTNAME%% pid file directory
31
#					Default: %%DEFAULT_RUNDIR%%
32
33
. /etc/rc.subr
34
35
name="%%PORTNAME%%"
36
rcvar=%%PORTNAME%%_enable
37
load_rc_config $name
38
39
: ${%%PORTNAME%%_enable:="NO"}
40
: ${%%PORTNAME%%_multi_enable:="NO"}
41
: ${%%PORTNAME%%_user:="%%DEFAULT_USER%%"}
42
: ${%%PORTNAME%%_group:="%%DEFAULT_GROUP%%"}
43
: ${%%PORTNAME%%_conf_d:="%%ETCDIR%%"}
44
: ${%%PORTNAME%%_config:="${%%PORTNAME%%_conf_d%/}/${name}.conf"}
45
: ${%%PORTNAME%%_logdir:="%%DEFAULT_LOGDIR%%"}
46
: ${%%PORTNAME%%_piddir:="%%DEFAULT_RUNDIR%%"}
47
48
required_dirs="${%%PORTNAME%%_logdir} ${%%PORTNAME%%_piddir}"
49
required_files=${%%PORTNAME%%_config}
50
procname="%%PREFIX%%/bin/${name}"
51
procdesc="${name}"
52
pidfile="${%%PORTNAME%%_piddir%/}/${name}.pid"
53
logfile="${%%PORTNAME%%_logdir%/}/${name}.log"
54
command=/usr/sbin/daemon
55
start_precmd="%%PORTNAME%%_precmd"
56
57
%%PORTNAME%%_precmd()
58
{	
59
	# Loads the options declared in the configuration file into "$command_args".
60
	%%PORTNAME%%_conf_to_args ${%%PORTNAME%%_config}
61
}
62
63
%%PORTNAME%%_conf_to_args()
64
{
65
	local _line %%PORTNAME%%_config_param %%PORTNAME%%_config_value config_file_path=$1
66
	command_args="-f -t ${procdesc} -p ${pidfile} -o ${logfile} ${procname}"
67
68
	while read -r _line; do
69
		# Only proceed with lines which contain variable declaration.
70
		echo "${_line}" | grep -q -E \
71
        	-e "^[[:blank:]]*[[:alpha:]_-][[:alnum:]_-]{0,30}=" ||
72
			continue
73
74
		%%PORTNAME%%_config_param=${_line%%=*}
75
		%%PORTNAME%%_config_value=${_line#*=}
76
77
		# Properly handle flag type paramaters
78
		if %%PORTNAME%%_is_flag_param ${%%PORTNAME%%_config_param}; then
79
			if checkyesno %%PORTNAME%%_config_value; then
80
				command_args="$command_args --${%%PORTNAME%%_config_param}"
81
			fi
82
		elif [ -n "${%%PORTNAME%%_config_value}" ]; then
83
			command_args="$command_args --${%%PORTNAME%%_config_param}=${%%PORTNAME%%_config_value}"
84
		fi
85
	done < ${config_file_path}
86
}
87
88
%%PORTNAME%%_find_instances()
89
{
90
	local instance_config
91
	for instance_config in ${%%PORTNAME%%_conf_d%/}/*.conf; do
92
		[ -f "$instance_config" ] || break
93
		%%PORTNAME%%_instances="$%%PORTNAME%%_instances $(basename ${instance_config%.conf})";
94
	done
95
}
96
97
%%PORTNAME%%_is_flag_param()
98
{
99
	case $1 in
100
	'echo-mode' | 'strict' )
101
		return 0
102
		;;
103
	*)
104
		return 1
105
		;;
106
	esac
107
}
108
109
# Handles multi-instance feature
110
if [ $# -eq 2 ]; then
111
	# Performs action on single instance by name
112
	_instance=$2
113
	echo "===> Instance: ${_instance}"
114
115
	# Setup for the requested instance name
116
	%%PORTNAME%%_config="${%%PORTNAME%%_conf_d%/}/${_instance}.conf"
117
	procdesc="${name}_${_instance}"
118
	pidfile="${%%PORTNAME%%_piddir%/}/${_instance}.pid"
119
	logfile="${%%PORTNAME%%_logdir%/}/${_instance}.log"
120
	
121
	# The config file for the named instance must exist
122
	required_files="${%%PORTNAME%%_config}"
123
elif checkyesno %%PORTNAME%%_multi_enable; then
124
	# Compile list of all instances or given instances
125
	_swap=$*; shift; _instances=$*
126
	%%PORTNAME%%_find_instances
127
	_instances=${_instances:-${%%PORTNAME%%_instances}}
128
	set -- ${_swap}
129
130
	# Performs action on each instance
131
	for _instance in ${_instances}; do
132
		%%PREFIX%%/etc/rc.d/${name} $1 ${_instance}
133
	done	
134
	exit 0
135
fi
136
137
run_rc_command "$1"
138
(-)www/gwsocket/files/pkg-message.in (+26 lines)
Line 0 Link Here
1
[
2
{ type: install
3
  message: <<EOM
4
5
To run %%PORTNAME%% at startup, enable it in your /etc/rc.conf:
6
sysrc %%PORTNAME%%_enable="YES"
7
8
To start %%PORTNAME%%:
9
service %%PORTNAME%% start
10
11
To configure %%PORTNAME%% edit:
12
%%ETCDIR%%/%%PORTNAME%%.conf
13
14
A client example can be found at %%EXAMPLESDIR%%/sample.html
15
16
To run multiple instances of %%PORTNAME%%, enable it in your /etc/rc.conf:
17
sysrc %%PORTNAME%%_multi_enable="YES"
18
19
An instance will be created for each *.conf file found in:
20
%%ETCDIR%%
21
22
EOM
23
}
24
]
25
26
(-)www/gwsocket/files/sample.html (+43 lines)
Line 0 Link Here
1
<!DOCTYPE html>
2
<html lang="en">
3
<style>
4
pre {
5
    background: #EEE;
6
    border: 1px solid #CCC;
7
    padding: 10px;
8
}
9
#page-wrapper {
10
    border-top: 5px solid #69c773;
11
    margin: 1em auto;
12
    width: 950px;
13
}
14
</style>
15
<script>
16
window.onload = function() {
17
    function $(selector) {
18
        return document.querySelector(selector);
19
    }
20
    var socket = new WebSocket('ws://localhost:7890');
21
    socket.onopen = function(event) {
22
        $('#messages').innerHTML = 'Connected<br>';
23
    };
24
    socket.onmessage = function(event) {
25
        $('#messages').innerHTML += 'Received:<br>' + event.data + '<br>';
26
    };
27
    socket.onclose = function(event) {
28
        $('#messages').innerHTML = 'Disconnected ' + event.reason;
29
    };
30
    $('#submit').onclick = function(e) {
31
        socket.send($('input').value);
32
        $('#messages').innerHTML += 'Sent:<br>' + $('input').value + '<br>';
33
        $('input').value = '';
34
    };
35
};
36
</script>
37
38
<div id="page-wrapper">
39
    <pre id="messages">Connecting...</pre>
40
    <input id="message" required>
41
    <button id="submit">Send Message</button>
42
</div>
43
(-)www/gwsocket/pkg-descr (+4 lines)
Line 0 Link Here
1
gwsocket is a simple, standalone, language-agnostic, RFC6455 compliant
2
WebSocket Server, written in C.
3
4
WWW: https://gwsocket.io
(-)www/gwsocket/pkg-plist (+6 lines)
Line 0 Link Here
1
bin/%%PORTNAME%%
2
man/man1/%%PORTNAME%%.1.gz
3
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/sample.html
4
@sample %%ETCDIR%%/%%PORTNAME%%.conf.sample
5
@dir(%%DEFAULT_USER%%,%%DEFAULT_GROUP%%,) %%DEFAULT_LOGDIR%%
6
@dir(%%DEFAULT_USER%%,%%DEFAULT_GROUP%%,) %%DEFAULT_RUNDIR%%

Return to bug 247884