Skip to content

Commit

Permalink
CHANGE: replaced port/spec/port-id with port/spec/port
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Feb 8, 2022
1 parent c54b352 commit f66b9a6
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/boot/sysobj.reb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ standard: object [

port-spec-net: make port-spec-file [
host: none
port-id: 80
port: 80
]

port-spec-checksum: make port-spec-head [
Expand Down Expand Up @@ -491,7 +491,7 @@ view: object [
; user: ; User data

; host:
; port-id:
; port:
; user:
; pass:
; target:
Expand Down
3 changes: 2 additions & 1 deletion src/core/p-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2022 Rebol Open Source Contributors
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -133,7 +134,7 @@ enum Transport_Types {
case A_OPEN:

arg = Obj_Value(spec, STD_PORT_SPEC_NET_HOST);
val = Obj_Value(spec, STD_PORT_SPEC_NET_PORT_ID);
val = Obj_Value(spec, STD_PORT_SPEC_NET_PORT);

if (OS_DO_DEVICE(sock, RDC_OPEN)) Trap_Port(RE_CANNOT_OPEN, port, -12);
SET_OPEN(sock);
Expand Down
28 changes: 14 additions & 14 deletions src/mezz/prot-http.reb
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ do-request: func [
Accept: "*/*"
Accept-charset: "utf-8"
Accept-Encoding: "gzip,deflate"
Host: either not find [80 443] spec/port-id [
ajoin [spec/host #":" spec/port-id]
Host: either not find [80 443] spec/port [
ajoin [spec/host #":" spec/port]
][
form spec/host
]
Expand Down Expand Up @@ -508,22 +508,22 @@ do-redirect: func [port [port!] new-uri [url! string! file!] /local spec state h
do-request port
return true
]
new-uri: as url! ajoin [spec/scheme "://" spec/host #":" spec/port-id new-uri]
new-uri: as url! ajoin [spec/scheme "://" spec/host #":" spec/port new-uri]
]
new-uri: decode-url new-uri
spec/headers/host: new-uri/host

unless select new-uri 'port-id [
unless select new-uri 'port [
switch new-uri/scheme [
'https [append new-uri [port-id: 443]]
'http [append new-uri [port-id: 80 ]]
'https [append new-uri [port: 443]]
'http [append new-uri [port: 80 ]]
]
]
new-uri: construct/with new-uri port/scheme/spec
new-uri/method: spec/method
new-uri/ref: as url! ajoin either find [#[none] 80 443] new-uri/port-id [
new-uri/ref: as url! ajoin either find [#[none] 80 443] new-uri/port [
[new-uri/scheme "://" new-uri/host new-uri/path]
][ [new-uri/scheme "://" new-uri/host #":" new-uri/port-id new-uri/path]]
][ [new-uri/scheme "://" new-uri/host #":" new-uri/port new-uri/path]]

unless find [http https] new-uri/scheme [
return throw-http-error port {Redirect to a protocol different from HTTP or HTTPS not supported}
Expand Down Expand Up @@ -783,12 +783,12 @@ sys/make-scheme [
chunk: none
chunk-size: none
]
;? port/state/info
spec: port/spec
port/state/connection: conn: make port! compose [
scheme: (to lit-word! either port/spec/scheme = 'http ['tcp]['tls])
host: port/spec/host
port-id: port/spec/port-id
ref: as url! ajoin [scheme "://" host #":" port-id]
scheme: (to lit-word! either spec/scheme = 'http ['tcp]['tls])
host: spec/host
port: spec/port
ref: as url! ajoin [scheme "://" host #":" port]
]

conn/awake: :http-awake
Expand Down Expand Up @@ -877,6 +877,6 @@ sys/make-scheme/with [
name: 'https
title: "Secure HyperText Transport Protocol v1.1"
spec: make spec [
port-id: 443
port: 443
]
] 'http
23 changes: 12 additions & 11 deletions src/mezz/prot-mysql.reb
Original file line number Diff line number Diff line change
Expand Up @@ -1394,17 +1394,18 @@ mysql-driver: make object! [

open-tcp-port: func [
port [port!] "mysql port"
/local conn
/local conn spec
][
spec: port/spec
conn: make port![
scheme: 'tcp
host: port/spec/host
port-id: port/spec/port-id
ref: rejoin [tcp:// host ":" port-id port/spec/path]
user: port/spec/user
pass: port/spec/pass
path: port/spec/path
timeout: port/spec/timeout
host: spec/host
port: spec/port
ref: rejoin [tcp:// host ":" port spec/path]
user: spec/user
pass: spec/pass
path: spec/path
timeout: spec/timeout
]

conn/extra: make locals-class [
Expand Down Expand Up @@ -1486,7 +1487,7 @@ sys/make-scheme [

spec: make system/standard/port-spec-net [
path: %""
port-id: 3306
port: 3306
timeout: 120
user:
pass: none
Expand All @@ -1510,7 +1511,7 @@ sys/make-scheme [
spec: event/port/spec
spec/pass: none
spec/ref: rejoin [
mysql:// spec/user #"@" spec/host #":" spec/port-id spec/path
mysql:// spec/user #"@" spec/host #":" spec/port spec/path
]
sys/log/info 'MySQL ["Connected:^[[22m" spec/ref]
pl/handshaked?: true
Expand Down Expand Up @@ -1708,7 +1709,7 @@ send-sql: func [
]

throw-timeout: func[port [port!]] [
cause-error 'Access 'timeout to url! rejoin [port/spec/scheme "://" port/spec/host #":" port/spec/port-id]
cause-error 'Access 'timeout to url! rejoin [port/spec/scheme "://" port/spec/host #":" port/spec/port]
]

connect-sql: func [
Expand Down
14 changes: 6 additions & 8 deletions src/mezz/prot-tls.reb
Original file line number Diff line number Diff line change
Expand Up @@ -1811,23 +1811,21 @@ sys/make-scheme [
]
]

open: func [port [port!] /local conn][
open: func [port [port!] /local conn spec][
log-more "OPEN"
if port/state [return port]

if none? port/spec/host [TLS-error "Missing host address"]

spec: port/spec
port/state: make-TLS-ctx

port/state/connection: conn: make port! [
scheme: 'tcp
host: port/spec/host
port-id: port/spec/port-id
ref: rejoin [tcp:// host ":" port-id]
host: spec/host
port: spec/port
ref: rejoin [tcp:// host ":" port]
]

port/data: port/state/port-data

port/data: port/state/port-data
conn/awake: :TLS-awake
conn/extra: port
open conn
Expand Down
14 changes: 7 additions & 7 deletions src/mezz/prot-whois.reb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ append system/options/log [whois: 1]
sys/make-scheme [
name: 'whois
title: "WHOIS Protocol"
spec: make system/standard/port-spec-net [port-id: 43 timeout: 15 ]
spec: make system/standard/port-spec-net [port: 43 timeout: 15 ]
awake: func [event /local port parent] [
sys/log/debug 'WHOIS ["Awake:^[[22m" event/type]
port: event/port
Expand Down Expand Up @@ -58,7 +58,7 @@ sys/make-scheme [
actor: [
open: func [
port [port!]
/local conn
/local conn spec
] [
if all [
port/state
Expand All @@ -72,8 +72,8 @@ sys/make-scheme [
]
return port
]

if none? port/spec/host [ port/spec/host: "whois.iana.org" ]
spec: port/spec
if none? spec/host [ spec/host: "whois.iana.org" ]

port/state: object [
state: 'inited
Expand All @@ -83,9 +83,9 @@ sys/make-scheme [
]
port/state/connection: conn: make port! [
scheme: 'tcp
host: port/spec/host
port-id: port/spec/port-id
ref: rejoin [tcp:// host #":" port-id]
host: spec/host
port: spec/port
ref: rejoin [tcp:// host #":" port]
]
conn/extra: port
conn/awake: :awake
Expand Down
2 changes: 1 addition & 1 deletion src/mezz/sys-ports.reb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ make-port*: func [
; optional host [:port]
opt [
copy s1 any host-char
opt [#":" copy s2 digits (compose/into [port-id: (to integer! s2)] tail out)]
opt [#":" copy s2 digits (compose/into [port: (to integer! s2)] tail out)]
(unless empty? s1 [attempt [s1: to tuple! s1] emit host s1])
]
]
Expand Down
12 changes: 6 additions & 6 deletions src/modules/httpd.reb
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ sys/make-scheme [
Name: 'httpd

Actor: [
Open: func [port [port!]][
; probe port/spec
sys/log/info 'HTTPD ["Opening server at port:^[[22m" port/spec/port-id]
Open: func [port [port!] /local spec][
spec: port/spec
sys/log/info 'HTTPD ["Opening server at port:^[[22m" spec/port]
port/extra: make object! [
subport: open compose [
subport: open [
scheme: 'tcp
port-id: (port/spec/port-id)
port: spec/port
]
subport/awake: :port/scheme/awake-server
subport/extra: make object! [
Expand All @@ -225,7 +225,7 @@ sys/make-scheme [
]

Close: func [port [port!]][
sys/log/info 'HTTPD ["Closing server at port:^[[22m" port/spec/port-id]
sys/log/info 'HTTPD ["Closing server at port:^[[22m" port/spec/port]
close port/extra/subport
]

Expand Down
12 changes: 6 additions & 6 deletions src/modules/port-scanner.reb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ batch-size: 8000 ; higher batch size means higher CPU use!
timeout: 0:0:0.5 ; setting timeout too low may result in not resolved opened ports!

; actor:
on-awake: func [event /local port id] [
on-awake: func [event /local port number] [
port: event/port
;print [as-green "==TCP-event:" as-red event/type "port:" as-red port/spec/port-id]
;print [as-green "==TCP-event:" as-red event/type "port:" as-red port/spec/port]
switch/default event/type [
lookup [open port]
connect [
id: port/spec/port-id
print ["Open port found:" as-red id]
append found id
number: port/spec/port
print ["Open port found:" as-red number]
append found number
false
]
][true]
Expand Down Expand Up @@ -71,7 +71,7 @@ scan-ports: function [
port: make port! compose [
scheme: 'tcp
host: (ip)
port-id: (id)
port: (id)
awake: :on-awake
]
open port
Expand Down
8 changes: 4 additions & 4 deletions src/modules/spotify.reb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spotify: object [
client-id: none
client-secret: none
scope: ""
port-id: 8989
port: 8989
token: none
get: func [what [any-string!] ][request self 'GET what none]
put: func [what [any-string!] /with data][request self 'PUT what data]
Expand All @@ -44,14 +44,14 @@ authorize: function [
return none
]
unless string? ctx/client-id [ ctx/client-id: form ctx/client-id ]
unless integer? ctx/port-id [ ctx/port-id: 8989 ]
unless integer? ctx/port [ ctx/port: 8989 ]
unless string? ctx/scope [ ctx/scope: form ctx/scope ]

; url-encode spaces in scopes
parse ctx/scope [any [change some #[bitset! #{0064000080}] #"+" | skip]]

redirect-uri: rejoin [
"http%3A%2F%2Flocalhost:" ctx/port-id "%2Fspotify-callback%2F"
"http%3A%2F%2Flocalhost:" ctx/port "%2Fspotify-callback%2F"
]

unless ctx/client-secret [
Expand Down Expand Up @@ -81,7 +81,7 @@ authorize: function [
; Result from the server is returned as a redirect, so let's start simple server
; listening on specified port (limited to accept only local requests, as the redirect is
; going from the browser actually.. it automaticaly close itself once data are received
result: system/modules/httpd/http-server/config/actor ctx/port-id [
result: system/modules/httpd/http-server/config/actor ctx/port [
root: #[false] ; we are not serving any content!
keep-alive: #[false]
] [
Expand Down
4 changes: 2 additions & 2 deletions src/tests/units/port-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Rebol [
--assert url/user = "švéd"
--assert url/pass = "břéťa"
--assert url/host = "example.com"
--assert url/port-id = 8080
--assert url/port = 8080
--assert url/path = "/get?q=ščř"
--assert url/tag = "kovtička"
--test-- "decode-url http://host?query"
Expand All @@ -33,7 +33,7 @@ Rebol [
;@@ https://github.com/Oldes/Rebol-issues/issues/1275
url: decode-url tcp://:9000
--assert url/scheme = 'tcp
--assert url/port-id = 9000
--assert url/port = 9000

===end-group===

Expand Down

0 comments on commit f66b9a6

Please sign in to comment.