interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / community / 40route.om

226 lines · 4334 bytes Raw Blame History
1note community/40route.om -- /community/... routes. Pages and raw records are GET (and HEAD); only
2note /community/api takes a POST. A path that is not one of these is 404.
3
4text cmrt "/community"
5text cmrts "/community/"
6text cmrapi "/community/api"
7text cmrjoin "/community/join"
8text cmrled "/community/ledger"
9text cmrrfu "/community/refused"
10text cmralm "/community/alarms"
11text cmrdl "/community/dl/"
12text cmrpart "/community/part/"
13text cmrmsg "/community/msg/"
14text cmrkyp "/community/key/"
15text cmfjoin "dist/join.sh"
16text cmshct "text/x-shellscript; charset=utf-8"
17text cmoct "application/octet-stream"
18text cmatt "attachment"
19text cmcc5 "public, max-age=60"
20
21fn cm_prefix to bool
22if lt get fpathl 0 len cmrt
23ret false
24end
25for i ulong len cmrt
26if ne get fpath i get cmrt i
27ret false
28end
29end
30if eq get fpathl 0 len cmrt
31ret true
32end
33ret eq get fpath len cmrt 47
34end
35
36note cm_file: stream <root>rel (kind 3) with content type ct; 404 when it is absent
37fn cm_file rel view uchar * ct view uchar * to long
38put ffilel 0 0
39n = get cmgv cmrl
40for i ulong n bound 1024
41ffilc get cmroot i
42end
43for i ulong len rel bound 4096
44ffilc get rel i
45end
46put fobl 0 0
47put fkind 0 3
48fsetct ct
49ret 200
50end
51
52note cm_pfile: stream <read-only root>rel (dist/ files): what volunteers download
53fn cm_pfile rel view uchar * ct view uchar * to long
54put ffilel 0 0
55n = get cmgv cmprl
56for i ulong n bound 1024
57ffilc get cmproot i
58end
59for i ulong len rel bound 4096
60ffilc get rel i
61end
62put fobl 0 0
63put fkind 0 3
64fsetct ct
65ret 200
66end
67
68note cm_hexarg: the 64 hex characters after prefix t (the whole rest of the path) into id. The path
69note must start with t: "/community/msg/" and "/community/key/" have the same length.
70fn cm_hexarg t view uchar * id edit uchar * to bool
71if ne get fpathl 0 add len t 64
72ret false
73end
74if not fpre t
75ret false
76end
77for i ulong 64
78put id i get fpath add len t i
79end
80ret cm_ishex id
81end
82
83note cm_dlname: a file name of 1..100 bytes from A-Z a-z 0-9 . _ -, not starting with a dot
84fn cm_dlname s view uchar * to bool
85if or eq len s 0 gt len s 100
86ret false
87end
88if eq get s 0 46
89ret false
90end
91for i ulong len s bound 128
92c = get s i
93ok = or or and ge c 97 le c 122 and ge c 65 le c 90 and ge c 48 le c 57
94if not or or ok eq c 46 or eq c 95 eq c 45
95ret false
96end
97end
98ret true
99end
100
101fn cm_route to long
102id = new uchar 64 0
103if not cm_prefix
104ret 0
105end
106fsetcc cmnost
107if fpeq cmrapi
108ret cm_api
109end
110if not fget
111ret 405
112end
113if not cm_on
114ret 404
115end
116if or fpeq cmrt fpeq cmrts
117ret cm_index
118end
119if fpeq cmrjoin
120fsetcc cmcc5
121ret cm_pfile cmfjoin cmshct
122end
123if fpeq cmrled
124ret cm_file cmtled cmct
125end
126if fpeq cmrrfu
127ret cm_file cmtref cmct
128end
129if fpeq cmralm
130ret cm_file cmtalm cmct
131end
132r = cm_arch
133if ne r 0
134ret r
135end
136if fpre cmrdl
137ret cm_dl
138end
139if cm_hexarg cmrpart id
140ret cm_partpage id
141end
142if cm_hexarg cmrmsg id
143ret cm_raw cmtmsgs id
144end
145if cm_hexarg cmrkyp id
146ret cm_raw cmtkeys id
147end
148ret 404
149end
150
151text cmrtled "ledger."
152text cmrtref "refused."
153text cmrtalm "alarms."
154note cm_archok: "ledger.", "refused." or "alarms." followed by 1..20 digits (a set-aside log)
155fn cm_archok s view uchar * to bool
156p = ulong 0
157if gt len s len cmrtled
158if cm_eq part s 0 len cmrtled cmrtled
159p = len cmrtled
160end
161end
162if and eq p 0 gt len s len cmrtref
163if cm_eq part s 0 len cmrtref cmrtref
164p = len cmrtref
165end
166end
167if and eq p 0 gt len s len cmrtalm
168if cm_eq part s 0 len cmrtalm cmrtalm
169p = len cmrtalm
170end
171end
172if or eq p 0 gt sub len s p 20
173ret false
174end
175for i ulong sub len s p bound 32
176c = get s add p i
177if or lt c 48 gt c 57
178ret false
179end
180end
181ret true
182end
183
184note cm_arch: GET /community/<set-aside log>; 0 when the path is not one
185fn cm_arch to long
186nm = new uchar 64 0
187o = len cmrts
188if or le get fpathl 0 o gt sub get fpathl 0 o 60
189ret 0
190end
191n = sub get fpathl 0 o
192for i ulong n bound 64
193put nm i get fpath add o i
194end
195if not cm_archok part nm 0 n
196ret 0
197end
198ret cm_file part nm 0 n cmct
199end
200
201fn cm_raw dir view uchar * id view uchar * to long
202p = new uchar 128 0
203k = cm_cp p 0 dir
204k = cm_cp p k id
205ret cm_file part p 0 k cmct
206end
207
208fn cm_dl to long
209nm = new uchar 128 0
210p = new uchar 160 0
211o = len cmrdl
212n = sub get fpathl 0 o
213if or eq n 0 gt n 100
214ret 404
215end
216for i ulong n bound 128
217put nm i get fpath add o i
218end
219if not cm_dlname part nm 0 n
220ret 404
221end
222k = cm_cp p 0 cmtdist
223k = cm_cp p k part nm 0 n
224fsetcd cmatt
225ret cm_pfile part p 0 k cmoct
226end