Blob
- Date:
- Message:
- implement `listen on' Listening by default on all the addresses is so bad I don't know why I haven't changed this before. Anyway. Add a `listen on $hostname port $port' syntax to the config file and deprecate the old "port" and "ipv6" global setting. Still try to honour them when no "listen on" directive is used for backward compatibily, but this will go away in the next next version hopefully. At the moment the `listen on' in server context don't filter the host, i.e. one can still reach a host from a address not specified in the corresponding `liste on', this will be added later.
- Actions:
- History | Blame | Raw File
1 ran_no=02 failed_no=03 failed=5 ge="./../ge"6 gg="./../gg"7 gmid="./../gmid"8 current_test=10 run_test() {11 ggflags=12 port=1096513 config_common=""14 hdr=15 body=16 dont_check_server_alive=no18 ran_no=$((ran_no + 1))20 current_test=$121 rm -f reg.conf23 if ! $1; then24 echo "$1 failed"25 failed="$failed $1"26 failed_no=$((failed_no + 1))27 return28 else29 echo "$1 passed"30 fi32 if [ "$dont_check_server_alive" != 'no' ]; then33 return34 fi36 if ! check; then37 echo "gmid crashed?"38 failed="$failed $1"39 failed_no=$((failed_no + 1))40 fi41 }43 tests_done() {44 ok=$((ran_no - failed_no))45 echo46 echo "tests: $ran_no / passed: $ok / failed: $failed_no"47 if [ "$failed" != "" ]; then48 echo49 echo "failed tests:$failed"50 exit 151 fi52 exit 053 }55 # usage: gen_config <global config> <server config>56 # generates a configuration file reg.conf57 gen_config() {58 cat <<EOF > reg.conf59 $config_common60 $161 server "localhost" {62 cert "$PWD/cert.pem"63 key "$PWD/key.pem"64 root "$PWD/testdata"65 listen on localhost port $port66 $267 }68 EOF69 if ! checkconf; then70 echo "failed to parse the config" >&271 return 172 fi73 }75 set_proxy() {76 cat <<EOF >>reg.conf77 server "localhost.local" {78 cert "$PWD/cert.pem"79 key "$PWD/key.pem"80 listen on localhost port $port81 proxy {82 relay-to localhost port $port83 $184 }85 }86 EOF88 if ! checkconf; then89 echo "failed to parse the config" >&290 return 191 fi92 }94 checkconf() {95 if ! $gmid -n -c reg.conf >/dev/null 2>&1; then96 $gmid -n -c reg.conf97 fi98 }100 # usage: setup_simple_test <global config> <server config>101 # generates a configuration file with `gen_config', validates it and102 # launches the daemon103 setup_simple_test() {104 gen_config "$1" "$2"105 run106 }108 # usage: get <path>109 # return the body of the request on stdout110 get() {111 $gg -T10 $ggflags "gemini://localhost:10965/$1" || true112 }114 # usage: head <path>115 # return the meta response line on stdout116 head() {117 $gg -T10 -d header $ggflags "gemini://localhost:10965/$1" || true118 }120 # usage: fetch <path>121 # fetches the header and the body. They're returned in $hdr and122 # $body.123 fetch() {124 if ! hdr="$(head $1)" || ! body="$(get $1)"; then125 return 1126 fi127 }129 # usage: fetch_hdr <path>130 # fetches the header into $hdr131 fetch_hdr() {132 hdr="$(head $1)"133 body=""134 }136 # usage: check_reply header body137 # checks that $hdr and $body are equal to the given strings138 check_reply() {139 if [ "$hdr" != "$1" ]; then140 echo "Header mismatch" >&2141 echo "wants : $1" >&2142 echo "got : $hdr" >&2143 return 1144 fi146 if [ "$body" != "$2" ]; then147 echo "Body mismatch" >&2148 echo "wants : $2" >&2149 echo "got : $body" >&2150 return 1151 fi152 }154 run() {155 if check; then156 kill -HUP "$(cat gmid.pid)"157 sleep 1158 return159 fi161 $gmid -P $PWD/gmid.pid -c reg.conf163 # give gmid time to bind the port, otherwise we end up164 # executing gg when gmid isn't ready yet.165 sleep 1166 }168 check() {169 if [ ! -f gmid.pid ]; then170 return 1171 fi173 pid="$(cat gmid.pid || true)"174 if [ "$pid" = "" ]; then175 return 1176 fi178 # remember: we're running under ``set -e''179 if ps $pid >/dev/null; then180 return 0181 fi183 return 1184 }186 count() {187 wc -l | xargs188 }190 quit() {191 pid="$(cat gmid.pid || true)"192 if [ "$pid" != "" ]; then193 kill $pid || true194 wait || true195 fi196 }198 onexit() {199 rm -f bigfile bigfile.sha200 quit201 }