interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / dl / tests / tmain.om

352 lines · 5802 bytes Raw Blame History
1note dl/tests/tmain.om: TEST-ONLY driver. One request per process, no socket:
2note dltest STORE ALLOWFILE METHOD PATH BASE INM QUERY [PATH2 ...] (INM and QUERY: - for none)
3note Extra PATHs are served by the same process after the first (state kept, as in the server).
4note STORE ends in /; ALLOWFILE has lines "<repo-name> <rid>". Sets the contract request globals the
5note way the server does (fridx, frid, fown, frepo, frest), calls dlroute, and prints the response:
6note METHOD BLOBF calls dlblobf (browse's large /raw/ entry point) on the PATH rest after the repo.
7note METHOD CLONE calls dlclone instead (PATH still selects the repo). Prints STATUS / KIND / CT / CD / ETAG / CC / LOC / FILE / TITLE lines, "--", then fob.
8global gtarg uchar 4096
9global gtargl ulong 1
10global gtal uchar 65536
11global gtall ulong 1
12text tthead "HEAD"
13text ttclone "CLONE"
14text ttblobf "BLOBF"
15text ttget "GET"
16text ttst "STATUS "
17text ttkind "KIND "
18text ttct "CT "
19text ttcd "CD "
20text ttet "ETAG "
21text ttcc "CC "
22text ttloc "LOC "
23text ttfile "FILE "
24text ttti "TITLE "
25text ttra "RETRY "
26text ttsep "--\n"
27text ttnl "\n"
28fn tout t view uchar * to void
29x = write 1 t 0 len t
30end
31fn toutn v ulong to void
32d = new uchar 20 0
33i = ulong 20
34x = v
35for it ulong 20
36i = sub i 1
37put d i uchar add rem x 10 48
38x = div x 10
39if eq x 0
40break
41end
42end
43w = write 1 d i sub 20 i
44end
45fn targ i ulong to bool
46put gtargl 0 0
47if ge i ulong argcnt
48ret false
49end
50n = argread i gtarg 0 4096
51if lt n 0
52ret false
53end
54put gtargl 0 ulong n
55ret true
56end
57fn targis t view uchar * to bool
58if ne get gtargl 0 len t
59ret false
60end
61for i ulong len t
62if ne get gtarg i get t i
63ret false
64end
65end
66ret true
67end
68fn tdash to bool
69ret and eq get gtargl 0 1 eq get gtarg 0 45
70end
71fn tloadal to bool
72fd = fopen gtarg 0 get gtargl 0 524288 0
73if lt fd 0
74ret false
75end
76r = read int fd gtal 0 65536
77x = fclose int fd
78if lt r 0
79ret false
80end
81put gtall 0 ulong r
82ret true
83end
84note tlfind scans for the repo name frepo and fills frid; returns the line index or 9999
85fn tlfind to ulong
86n = get gtall 0
87s = ulong 0
88k = ulong 0
89for i ulong n
90if eq get gtal i 10
91if tlmatch s i
92ret k
93end
94k = add k 1
95s = add i 1
96end
97end
98ret 9999
99end
100fn tlmatch s ulong e ulong to bool
101m = get frepol 0
102if le sub e s add m 1
103ret false
104end
105for i ulong m
106if ne get gtal add s i get frepo i
107ret false
108end
109end
110if ne get gtal add s m 32
111ret false
112end
113a = add add s m 1
114put fridl 0 sub e a
115for i ulong sub e a
116put frid i get gtal add a i
117end
118ret true
119end
120fn tcount to ulong
121k = ulong 0
122for i ulong get gtall 0
123if eq get gtal i 10
124k = add k 1
125end
126end
127ret k
128end
129note tsplit: fpath = /<owner>/<repo><rest>
130fn tsplit to void
131put fridx 0 9999
132n = get fpathl 0
133i = ulong 1
134for it ulong n
135if or ge i n eq get fpath i 47
136break
137end
138i = add i 1
139end
140if ge i n
141ret
142end
143put fownl 0 sub i 1
144for k ulong sub i 1
145put fown k get fpath add k 1
146end
147j = add i 1
148for it ulong n
149if or ge j n eq get fpath j 47
150break
151end
152j = add j 1
153end
154if or le j add i 1 gt sub sub j i 1 127
155ret
156end
157put frepol 0 sub sub j i 1
158for k ulong get frepol 0
159put frepo k get fpath add add i 1 k
160end
161put frestl 0 sub n j
162for k ulong sub n j
163put frest k get fpath add j k
164end
165if not tisowner
166ret
167end
168put fridx 0 tlfind
169end
170fn tisowner to bool
171if ne get fownl 0 len tfowner
172ret false
173end
174for i ulong len tfowner
175if ne get fown i get tfowner i
176ret false
177end
178end
179ret true
180end
181fn tcp1 to void
182n = get gtargl 0
183for i ulong n
184put gtstore i get gtarg i
185end
186put gtstl 0 n
187end
188fn tsetreq to bool
189put fmeth 0 0
190if targis ttget
191put fmeth 0 1
192end
193if targis tthead
194put fmeth 0 2
195end
196if targis ttclone
197put fmeth 0 9
198end
199if targis ttblobf
200put fmeth 0 8
201end
202if not targ 4
203ret false
204end
205n = get gtargl 0
206for i ulong n
207put fpath i get gtarg i
208end
209put fpathl 0 n
210if not targ 5
211ret false
212end
213n = get gtargl 0
214for i ulong n
215put fbase i get gtarg i
216end
217put fbasel 0 n
218ret tsetreq2
219end
220fn tsetreq2 to bool
221put finml 0 0
222if not targ 6
223ret false
224end
225if not tdash
226n = get gtargl 0
227for i ulong n
228put finm i get gtarg i
229end
230put finml 0 n
231end
232put fqsl 0 0
233if not targ 7
234ret false
235end
236if not tdash
237n = get gtargl 0
238for i ulong n
239put fqs i get gtarg i
240end
241put fqsl 0 n
242end
243ret true
244end
245fn tprint st long to void
246tout ttst
247toutn ulong st
248tout ttnl
249tout ttkind
250toutn get fkind 0
251tout ttnl
252x = write 1 ttct 0 len ttct
253x = write 1 fct 0 get fctl 0
254tout ttnl
255x = write 1 ttcd 0 len ttcd
256x = write 1 fcd 0 get fcdl 0
257tout ttnl
258x = write 1 ttet 0 len ttet
259x = write 1 fetag 0 get fetagl 0
260tout ttnl
261tprint2
262end
263fn tprint2 to void
264x = write 1 ttcc 0 len ttcc
265x = write 1 fcc 0 get fccl 0
266tout ttnl
267x = write 1 ttloc 0 len ttloc
268x = write 1 floc 0 get flocl 0
269tout ttnl
270x = write 1 ttfile 0 len ttfile
271x = write 1 ffile 0 get ffilel 0
272tout ttnl
273x = write 1 ttti 0 len ttti
274x = write 1 fti 0 get ftil 0
275tout ttnl
276tout ttra
277toutn get fretry 0
278tout ttnl
279tout ttsep
280x = write 1 fob 0 get fobl 0
281end
282fn main to int
283if not targ 1
284ret 2
285end
286tcp1
287if not targ 2
288ret 2
289end
290if not tloadal
291ret 3
292end
293put fan 0 tcount
294if not targ 3
295ret 2
296end
297if not tsetreq
298ret 2
299end
300tsplit
301put fkind 0 0
302st = long 0
303if eq get fmeth 0 9
304dlclone
305else
306st = tblobf
307end
308tprint st
309for k ulong 8
310if not targ add 8 k
311break
312end
313tnext
314end
315ret 0
316end
317note tblobf: METHOD BLOBF calls dlblobf on PATH's rest after the repo (/<owner>/<repo>/<blob id>)
318fn tblobf to long
319if ne get fmeth 0 8
320ret dlroute
321end
322n = get frestl 0
323if or lt n 1 gt n 64
324ret -9
325end
326b = new uchar 64 0
327for i ulong sub n 1
328put b i get frest add i 1
329end
330ret dlblobf view part b 0 sub n 1
331end
332note tnext: one more request on the PATH in gtarg, response fields cleared as the server does
333fn tnext to void
334n = get gtargl 0
335for i ulong n
336put fpath i get gtarg i
337end
338put fpathl 0 n
339put fkind 0 0
340put fctl 0 0
341put fcdl 0 0
342put fetagl 0 0
343put fccl 0 0
344put flocl 0 0
345put ffilel 0 0
346put ftil 0 0
347put fobl 0 0
348put fretry 0 0
349tsplit
350st = dlroute
351tprint st
352end