interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / server / repos.om
| 1 | note forged server/repos.om: the allow-list helpers and per-repo metadata (description from the identity |
| 2 | note document, last commit) that both repository sources use: server/radsrc.om (RIDS.md and Radicle |
| 3 | note storage, the default build) and store/repos.om (the native store, the store-reading build). A |
| 4 | note source fills fan / fanm / faid / fabr with fnmput, fbrput and its own key, and calls fmeta. |
| 5 | note ficut: stored data behind this response was longer than the buffer it was read into, and the code |
| 6 | note that follows would have treated the cut copy as the whole (a list with entries missing, an empty |
| 7 | note list, a 404 for something that exists). fincut sets it and fobtr, so fsend (server/main.om) throws |
| 8 | note the response away and sends the whole 500 of fovfl with the words of tfmicut (server/pages.om). |
| 9 | note Kinds 3 and 4 (a file, a command) do not read it: a handler returns before it starts one. |
| 10 | global ficut ulong 1 |
| 11 | fn fincut to void |
| 12 | put ficut 0 1 |
| 13 | put fobtr 0 1 |
| 14 | end |
| 15 | text tfshow "show" |
| 16 | text tfidref "refs/rad/id:embeds/radicle.json" |
| 17 | text tfdkey "\"description\":\"" |
| 18 | text tflog "log" |
| 19 | text tfm1 "-1" |
| 20 | text tflcfmt "--format=%H %ct %cs %h %s" |
| 21 | note falsh / falsl / falct: full sha (40 hex, or length 0) and committer time (epoch s) of the last |
| 22 | note commit of repo i, for the JSON form (server/json.om); falc keeps "%cs %h %s" for the HTML pages. |
| 23 | global falsh uchar 10240 |
| 24 | global falsl ulong 256 |
| 25 | global falct ulong 256 |
| 26 | text tfrh "refs/heads/" |
| 27 | text tfrns "refs/namespaces/" |
| 28 | text tfrnsh "/refs/heads/" |
| 29 | fn fleol p ulong ln ulong to ulong |
| 30 | j = p |
| 31 | while lt j ln bound 16777216 |
| 32 | if eq get fxo j 10 |
| 33 | ret j |
| 34 | end |
| 35 | j = add j 1 |
| 36 | end |
| 37 | ret ln |
| 38 | end |
| 39 | fn flnext p ulong ln ulong to ulong |
| 40 | e = fleol p ln |
| 41 | if lt e ln |
| 42 | ret add e 1 |
| 43 | end |
| 44 | ret ln |
| 45 | end |
| 46 | fn ftrs a ulong b ulong to ulong |
| 47 | j = a |
| 48 | while lt j b bound 16777216 |
| 49 | if ne get fxo j 32 |
| 50 | ret j |
| 51 | end |
| 52 | j = add j 1 |
| 53 | end |
| 54 | ret b |
| 55 | end |
| 56 | fn ftre a ulong b ulong to ulong |
| 57 | j = b |
| 58 | while gt j a bound 16777216 |
| 59 | if ne get fxo sub j 1 32 |
| 60 | ret j |
| 61 | end |
| 62 | j = sub j 1 |
| 63 | end |
| 64 | ret a |
| 65 | end |
| 66 | fn fnmok c uchar to bool |
| 67 | if fisaln c |
| 68 | ret true |
| 69 | end |
| 70 | ret or or eq c 46 eq c 45 eq c 95 |
| 71 | end |
| 72 | fn fbrok c uchar to bool |
| 73 | if fnmok c |
| 74 | ret true |
| 75 | end |
| 76 | ret eq c 47 |
| 77 | end |
| 78 | fn fnmcur k ulong to ulong |
| 79 | if eq k 0 |
| 80 | ret 0 |
| 81 | end |
| 82 | ret add get fano sub k 1 get fanl sub k 1 |
| 83 | end |
| 84 | fn fidcur k ulong to ulong |
| 85 | if eq k 0 |
| 86 | ret 0 |
| 87 | end |
| 88 | ret add get faio sub k 1 get fail sub k 1 |
| 89 | end |
| 90 | fn fbrcur k ulong to ulong |
| 91 | if eq k 0 |
| 92 | ret 0 |
| 93 | end |
| 94 | ret add get fabo sub k 1 get fabl sub k 1 |
| 95 | end |
| 96 | fn fnmput k ulong a ulong b ulong to bool |
| 97 | s = ftrs a b |
| 98 | t = ftre s b |
| 99 | n = sub t s |
| 100 | if or eq n 0 gt n 100 |
| 101 | ret false |
| 102 | end |
| 103 | cur = fnmcur k |
| 104 | if gt add cur n len fanm |
| 105 | ret false |
| 106 | end |
| 107 | put fano k cur |
| 108 | put fanl k n |
| 109 | for i ulong n bound 128 |
| 110 | c = get fxo add s i |
| 111 | if not fnmok c |
| 112 | ret false |
| 113 | end |
| 114 | put fanm add cur i c |
| 115 | end |
| 116 | ret true |
| 117 | end |
| 118 | fn fbrput k ulong a ulong b ulong to bool |
| 119 | s = ftrs a b |
| 120 | t = ftre s b |
| 121 | n = sub t s |
| 122 | if or eq n 0 gt n 60 |
| 123 | ret false |
| 124 | end |
| 125 | cur = fbrcur k |
| 126 | if gt add cur n len fabr |
| 127 | ret false |
| 128 | end |
| 129 | put fabo k cur |
| 130 | put fabl k n |
| 131 | for i ulong n bound 64 |
| 132 | c = get fxo add s i |
| 133 | if not fbrok c |
| 134 | ret false |
| 135 | end |
| 136 | put fabr add cur i c |
| 137 | end |
| 138 | ret true |
| 139 | end |
| 140 | note fdeny: withdrawn or never-public repositories, refused even when a RIDS.md row lists them |
| 141 | note (by RID without "rad:" or by name); checked before the storage test, independent of the table |
| 142 | text tfdnr1 "z2ft64NFLsKzWttCXw6NWNbRQLggQ" |
| 143 | text tfdnn1 "omega-pearl" |
| 144 | text tfdnn2 "aien-crypto" |
| 145 | fn fdideq k ulong t view uchar * to bool |
| 146 | if ne get fail k len t |
| 147 | ret false |
| 148 | end |
| 149 | for i ulong len t bound 64 |
| 150 | if ne fridbyte k i get t i |
| 151 | ret false |
| 152 | end |
| 153 | end |
| 154 | ret true |
| 155 | end |
| 156 | fn fdnmeq k ulong t view uchar * to bool |
| 157 | if ne get fanl k len t |
| 158 | ret false |
| 159 | end |
| 160 | for i ulong len t bound 64 |
| 161 | if ne frnbyte k i get t i |
| 162 | ret false |
| 163 | end |
| 164 | end |
| 165 | ret true |
| 166 | end |
| 167 | fn fdeny k ulong to bool |
| 168 | if fdideq k tfdnr1 |
| 169 | ret true |
| 170 | end |
| 171 | if fdnmeq k tfdnn1 |
| 172 | ret true |
| 173 | end |
| 174 | ret fdnmeq k tfdnn2 |
| 175 | end |
| 176 | fn fmove w ulong i ulong to void |
| 177 | if eq w i |
| 178 | ret |
| 179 | end |
| 180 | put fano w get fano i |
| 181 | put fanl w get fanl i |
| 182 | put faio w get faio i |
| 183 | put fail w get fail i |
| 184 | put fabo w get fabo i |
| 185 | put fabl w get fabl i |
| 186 | end |
| 187 | note ---- per-repo metadata: description (identity doc) and last commit |
| 188 | fn fdcur i ulong to ulong |
| 189 | if eq i 0 |
| 190 | ret 0 |
| 191 | end |
| 192 | ret add get fado sub i 1 get fadl sub i 1 |
| 193 | end |
| 194 | fn flccur i ulong to ulong |
| 195 | if eq i 0 |
| 196 | ret 0 |
| 197 | end |
| 198 | ret add get falco sub i 1 get falcl sub i 1 |
| 199 | end |
| 200 | fn fmeta i ulong to void |
| 201 | put fado i fdcur i |
| 202 | put fadl i 0 |
| 203 | put falco i flccur i |
| 204 | put falcl i 0 |
| 205 | put falsl i 0 |
| 206 | put falct i 0 |
| 207 | fkgiti i |
| 208 | fka tfshow |
| 209 | fka tfidref |
| 210 | st = fexec 5000000000 |
| 211 | if eq st 0 |
| 212 | fdescget i |
| 213 | end |
| 214 | flcget i |
| 215 | end |
| 216 | fn fdkey s ulong ln ulong to bool |
| 217 | if gt add s len tfdkey ln |
| 218 | ret false |
| 219 | end |
| 220 | for k ulong len tfdkey bound 32 |
| 221 | if ne get fxo add s k get tfdkey k |
| 222 | ret false |
| 223 | end |
| 224 | end |
| 225 | ret true |
| 226 | end |
| 227 | fn fdescget i ulong to void |
| 228 | ln = get fxol 0 |
| 229 | s = ulong 0 |
| 230 | while lt s ln bound 16777216 |
| 231 | if fdkey s ln |
| 232 | fdcopy i add s len tfdkey ln |
| 233 | ret |
| 234 | end |
| 235 | s = add s 1 |
| 236 | end |
| 237 | end |
| 238 | fn fdcopy i ulong a ulong ln ulong to void |
| 239 | o = get fado i |
| 240 | n = ulong 0 |
| 241 | j = a |
| 242 | while lt j ln bound 100000 |
| 243 | c = get fxo j |
| 244 | if eq c 34 |
| 245 | break |
| 246 | end |
| 247 | if ge add o n len fadesc |
| 248 | break |
| 249 | end |
| 250 | if ge n 1000 |
| 251 | break |
| 252 | end |
| 253 | if eq c 92 |
| 254 | j = add j 1 |
| 255 | if ge j ln |
| 256 | break |
| 257 | end |
| 258 | c = fdunesc get fxo j |
| 259 | end |
| 260 | put fadesc add o n c |
| 261 | n = add n 1 |
| 262 | j = add j 1 |
| 263 | end |
| 264 | put fadl i n |
| 265 | fdclean i |
| 266 | end |
| 267 | fn fdunesc c uchar to uchar |
| 268 | if or eq c 110 eq c 116 |
| 269 | ret uchar 32 |
| 270 | end |
| 271 | ret c |
| 272 | end |
| 273 | fn flcarg i ulong ns ulong to void |
| 274 | fkgiti i |
| 275 | fka tflog |
| 276 | fka tfm1 |
| 277 | fka tflcfmt |
| 278 | fkopen |
| 279 | if eq ns 1 |
| 280 | fkt tfrns |
| 281 | fkt tfnid |
| 282 | fkt tfrnsh |
| 283 | else |
| 284 | fkt tfrh |
| 285 | end |
| 286 | o = get fabo i |
| 287 | for k ulong get fabl i bound 64 |
| 288 | fkc get fabr add o k |
| 289 | end |
| 290 | end |
| 291 | fn flcget i ulong to void |
| 292 | flcarg i 0 |
| 293 | st = fexec 5000000000 |
| 294 | if ne st 0 |
| 295 | flcarg i 1 |
| 296 | st = fexec 5000000000 |
| 297 | end |
| 298 | if ne st 0 |
| 299 | ret |
| 300 | end |
| 301 | a = flcsha i |
| 302 | o = get falco i |
| 303 | n = ulong 0 |
| 304 | m = hmin sub get fxol 0 a 1024 |
| 305 | for j ulong m bound 1024 |
| 306 | c = get fxo add a j |
| 307 | if eq c 10 |
| 308 | break |
| 309 | end |
| 310 | if ge n 1000 |
| 311 | break |
| 312 | end |
| 313 | if ge add o n len falc |
| 314 | break |
| 315 | end |
| 316 | put falc add o n c |
| 317 | n = add n 1 |
| 318 | end |
| 319 | put falcl i n |
| 320 | end |
| 321 | note flcsha: fxo starts "<40 hex sha> <epoch> %cs %h %s". Stores the sha in falsh / falsl and the |
| 322 | note committer time in falct for repo i, and returns the offset of "%cs"; returns 0 (whole line kept, |
| 323 | note falsl 0) when the prefix is not exactly that shape. |
| 324 | fn flcishx c uchar to bool |
| 325 | if fisdig c |
| 326 | ret true |
| 327 | end |
| 328 | ret and ge c 97 le c 102 |
| 329 | end |
| 330 | fn flcsha i ulong to ulong |
| 331 | ln = get fxol 0 |
| 332 | if lt ln 43 |
| 333 | ret 0 |
| 334 | end |
| 335 | for k ulong 40 |
| 336 | if not flcishx get fxo k |
| 337 | ret 0 |
| 338 | end |
| 339 | end |
| 340 | if ne get fxo 40 32 |
| 341 | ret 0 |
| 342 | end |
| 343 | t = ulong 0 |
| 344 | p = ulong 41 |
| 345 | for it ulong 20 |
| 346 | if ge p ln |
| 347 | break |
| 348 | end |
| 349 | c = get fxo p |
| 350 | if not fisdig c |
| 351 | break |
| 352 | end |
| 353 | t = add mul t 10 ulong sub c 48 |
| 354 | p = add p 1 |
| 355 | end |
| 356 | if or eq p 41 ge p ln |
| 357 | ret 0 |
| 358 | end |
| 359 | if ne get fxo p 32 |
| 360 | ret 0 |
| 361 | end |
| 362 | o = mul i 40 |
| 363 | for k ulong 40 |
| 364 | put falsh add o k get fxo k |
| 365 | end |
| 366 | put falsl i 40 |
| 367 | put falct i t |
| 368 | ret add p 1 |
| 369 | end |