omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / apps / interplane-forge / research / intake-route.om
| 1 | note Research intake adapter, composed only beside the open shelf. Its repository POST calls |
| 2 | note ohpost unchanged: the shelf's sign-in, CSRF, permission, write limits, queue and refusal paths. |
| 3 | note Research records only a request to index that repository after the shelf has accepted it. |
| 4 | note Zenodo requests use the same write precheck, per-key rate counter and disk-space measure. |
| 5 | text rqpath "/research/add/" |
| 6 | text rqdir "research/add/" |
| 7 | text rqqueue "queue" |
| 8 | text rqlk "queue.lock" |
| 9 | text rqtitle "Add your work" |
| 10 | text rqorc "orcid" |
| 11 | text rqdoi "doi" |
| 12 | text rqsync "sync" |
| 13 | text rqzpre "10.5281/zenodo." |
| 14 | text rqmsg "Give a repository ID, an ORCID iD or a Zenodo DOI. Links and files are not accepted here." |
| 15 | text rqwait "The request is queued. Public metadata will be listed with the key that asked. A repository appears only after the open shelf accepts it. Not verified." |
| 16 | text rqh "<section class=\"sl\"><h1>Add your work</h1><p>Bring a paper repository, sync public Zenodo records, or <a href=\"/research/doi\">get a DOI for your work</a>. <a href=\"/research/add\">Read the steps</a>.</p><p>A listing is not proof that a key belongs to an author. Public metadata and repository text are not verified. The operator can take a listing down by key or repository.</p>" |
| 17 | text rql "<p><a href=\"/login\">Sign in with your key</a> to add work.</p></section>" |
| 18 | text rqf1 "<h2>Bring a repository</h2><p>Bringing new projects is closed until Interplane's own store accepts them.</p>" |
| 19 | text rqf3 "<h2>Sync public records</h2><p>Give an ORCID iD, a Zenodo DOI, or both. A record is filed under an author only if that record carries the ORCID iD among its creators. This is a listing from public metadata by the key that asked, not an ORCID sign-in.</p><form method=\"post\" action=\"/research/add/\"><input type=\"hidden\" name=\"csrf\" value=\"" |
| 20 | text rqf4 "\"><input type=\"hidden\" name=\"action\" value=\"sync\"><label>ORCID iD <input name=\"orcid\" maxlength=\"19\" placeholder=\"0000-0000-0000-0000\"></label><label>Zenodo DOI <input name=\"doi\" maxlength=\"26\" placeholder=\"10.5281/zenodo.123456\"></label><button type=\"submit\">Sync records</button></form></section>" |
| 21 | global rqo uchar 20 |
| 22 | global rqol ulong 1 |
| 23 | global rqd uchar 40 |
| 24 | global rqdl ulong 1 |
| 25 | fn rqform to long |
| 26 | if not fget |
| 27 | ret 405 |
| 28 | end |
| 29 | put fkind 0 0 |
| 30 | fsetti rqtitle |
| 31 | fput rqh |
| 32 | if not ohdid |
| 33 | fput rql |
| 34 | ret 200 |
| 35 | end |
| 36 | fput rqf1 |
| 37 | fput rqf3 |
| 38 | socsrfout |
| 39 | fput rqf4 |
| 40 | ret 200 |
| 41 | end |
| 42 | note rqappend: P or Z, did, rid or ORCID, ORCID(empty) or DOI. Failed append is rolled back. |
| 43 | note Mutable intake state must not use rxfile, which pins immutable public generations. |
| 44 | fn rqfile name view uchar * to void |
| 45 | put ffilel 0 0 |
| 46 | for i ulong len tfdata bound 128 |
| 47 | ffilc get tfdata i |
| 48 | end |
| 49 | for i ulong len rqdir bound 64 |
| 50 | ffilc get rqdir i |
| 51 | end |
| 52 | for i ulong len name bound 16 |
| 53 | ffilc get name i |
| 54 | end |
| 55 | end |
| 56 | fn rqlock to long |
| 57 | rqfile rqlk |
| 58 | fd = fopen ffile 0 get ffilel 0 558145 384 |
| 59 | if lt fd 0 |
| 60 | ret -1 |
| 61 | end |
| 62 | r = flock int fd 6 |
| 63 | if ne r 0 |
| 64 | x = fclose int fd |
| 65 | ret -1 |
| 66 | end |
| 67 | ret fd |
| 68 | end |
| 69 | fn rqappend kind uchar to long |
| 70 | rm = ohroom 400 |
| 71 | if or eq rm 1 eq rm 3 |
| 72 | ret soerr 503 tomroom |
| 73 | end |
| 74 | rqfile rqqueue |
| 75 | put ffilel 0 sub get ffilel 0 len rqqueue |
| 76 | r = makedir ffile 0 get ffilel 0 448 |
| 77 | lf = rqlock |
| 78 | if lt lf 0 |
| 79 | ret soerr 503 tomsgq |
| 80 | end |
| 81 | rqfile rqqueue |
| 82 | fd = fopen ffile 0 get ffilel 0 558145 384 |
| 83 | if lt fd 0 |
| 84 | x = fclose int lf |
| 85 | ret soerr 503 tomsgq |
| 86 | end |
| 87 | sz = ohsize int fd |
| 88 | if or lt sz 0 gt sz 4193904 |
| 89 | x = fclose int fd |
| 90 | x = fclose int lf |
| 91 | ret soerr 503 tomsgq |
| 92 | end |
| 93 | b = new uchar 400 0 |
| 94 | n = ulong 0 |
| 95 | put b n kind |
| 96 | n = add n 1 |
| 97 | put b n 9 |
| 98 | n = add n 1 |
| 99 | for i ulong get godidl 0 bound 96 |
| 100 | put b n get godid i |
| 101 | n = add n 1 |
| 102 | end |
| 103 | put b n 9 |
| 104 | n = add n 1 |
| 105 | if eq kind 80 |
| 106 | for i ulong get goridl 0 bound 44 |
| 107 | put b n get gorid i |
| 108 | n = add n 1 |
| 109 | end |
| 110 | else |
| 111 | for i ulong get rqol 0 bound 19 |
| 112 | put b n get rqo i |
| 113 | n = add n 1 |
| 114 | end |
| 115 | end |
| 116 | put b n 9 |
| 117 | n = add n 1 |
| 118 | if eq kind 90 |
| 119 | for i ulong get rqdl 0 bound 40 |
| 120 | put b n get rqd i |
| 121 | n = add n 1 |
| 122 | end |
| 123 | end |
| 124 | put b n 10 |
| 125 | n = add n 1 |
| 126 | w = write int fd b 0 n |
| 127 | if ne w long n |
| 128 | if ge sz 0 |
| 129 | x = ftrunc int fd sz |
| 130 | end |
| 131 | x = fclose int fd |
| 132 | x = fclose int lf |
| 133 | ret soerr 503 tomsgq |
| 134 | end |
| 135 | x = fclose int fd |
| 136 | x = fclose int lf |
| 137 | ohused n |
| 138 | put fkind 0 0 |
| 139 | fsetti rqtitle |
| 140 | fput rqh |
| 141 | fput rqwait |
| 142 | fput toend |
| 143 | ret 200 |
| 144 | end |
| 145 | note Preflight before a shelf mutation. A later IO fault is reported as partial acceptance, not |
| 146 | note "nothing saved": the shelf retains the RID/key/note and the reply carries the retryable ID. |
| 147 | fn rqpre to long |
| 148 | rm = ohroom 400 |
| 149 | if or eq rm 1 eq rm 3 |
| 150 | ret soerr 503 tomroom |
| 151 | end |
| 152 | rqfile rqqueue |
| 153 | put ffilel 0 sub get ffilel 0 len rqqueue |
| 154 | r = makedir ffile 0 get ffilel 0 448 |
| 155 | lf = rqlock |
| 156 | if lt lf 0 |
| 157 | ret soerr 503 tomsgq |
| 158 | end |
| 159 | rqfile rqqueue |
| 160 | fd = fopen ffile 0 get ffilel 0 558145 384 |
| 161 | if lt fd 0 |
| 162 | x = fclose int lf |
| 163 | ret soerr 503 tomsgq |
| 164 | end |
| 165 | sz = ohsize int fd |
| 166 | x = fclose int fd |
| 167 | x = fclose int lf |
| 168 | if or lt sz 0 gt sz 4193904 |
| 169 | ret soerr 503 tomsgq |
| 170 | end |
| 171 | ret 0 |
| 172 | end |
| 173 | text rqpart "<section class=\"sl\"><h1>Shelf request accepted</h1><p>The shelf accepted this repository. Research indexing was not queued because storage changed after admission. The shelf retains the repository ID, the requesting key and the paper note. Retry the ID below at <a href=\"/research/add/\">Add your work</a>.</p><pre>" |
| 174 | text rqp2 "</pre><p>This is a partial acceptance, not a claim that nothing was saved. The shelf listing is not verified.</p></section>" |
| 175 | fn rqpartial to long |
| 176 | put fobl 0 0 |
| 177 | put fkind 0 0 |
| 178 | fsetti rqtitle |
| 179 | fput rqpart |
| 180 | for i ulong get goridl 0 bound 44 |
| 181 | fescc get gorid i |
| 182 | end |
| 183 | fput rqp2 |
| 184 | ret 202 |
| 185 | end |
| 186 | fn rqpost to long |
| 187 | if slffeq toact tobring |
| 188 | if ne get gscur 0 0 |
| 189 | if not socsrfok |
| 190 | ret soerr 403 tsmcsrf |
| 191 | end |
| 192 | p = rqpre |
| 193 | if ne p 0 |
| 194 | ret p |
| 195 | end |
| 196 | end |
| 197 | r = ohpost |
| 198 | if ne r 303 |
| 199 | ret r |
| 200 | end |
| 201 | note A signed-out ohpost redirects to login, not to the shelf. Do not queue that as a request. |
| 202 | if eq get gscur 0 0 |
| 203 | ret r |
| 204 | end |
| 205 | p = rqappend 80 |
| 206 | if ne p 200 |
| 207 | ret rqpartial |
| 208 | end |
| 209 | ret p |
| 210 | end |
| 211 | r = sowpre |
| 212 | if ne r 0 |
| 213 | ret r |
| 214 | end |
| 215 | soratev get gscur 0 get gsnow 0 |
| 216 | if not slformvalid |
| 217 | ret soerr 400 rqmsg |
| 218 | end |
| 219 | if ne slgetform tsfcsrf 32 |
| 220 | ret soerr 400 rqmsg |
| 221 | end |
| 222 | if not ohdid |
| 223 | ret 403 |
| 224 | end |
| 225 | if not slffeq toact rqsync |
| 226 | ret soerr 400 rqmsg |
| 227 | end |
| 228 | n = slgetform rqorc |
| 229 | if or lt n 0 gt n 19 |
| 230 | ret soerr 400 rqmsg |
| 231 | end |
| 232 | put rqol 0 ulong n |
| 233 | if gt n 0 |
| 234 | if ne n 19 |
| 235 | ret soerr 400 rqmsg |
| 236 | end |
| 237 | for i ulong 19 |
| 238 | c = get gcfv i |
| 239 | if or eq i 4 or eq i 9 eq i 14 |
| 240 | if ne c 45 |
| 241 | ret soerr 400 rqmsg |
| 242 | end |
| 243 | else |
| 244 | ok = and ge c 48 le c 57 |
| 245 | if and eq i 18 eq c 88 |
| 246 | ok = true |
| 247 | end |
| 248 | if not ok |
| 249 | ret soerr 400 rqmsg |
| 250 | end |
| 251 | end |
| 252 | put rqo i c |
| 253 | end |
| 254 | end |
| 255 | n = slgetform rqdoi |
| 256 | if or lt n 0 gt n 26 |
| 257 | ret soerr 400 rqmsg |
| 258 | end |
| 259 | put rqdl 0 ulong n |
| 260 | if gt n 0 |
| 261 | if le n long len rqzpre |
| 262 | ret soerr 400 rqmsg |
| 263 | end |
| 264 | for i ulong len rqzpre |
| 265 | if ne get gcfv i get rqzpre i |
| 266 | ret soerr 400 rqmsg |
| 267 | end |
| 268 | end |
| 269 | for i ulong sub ulong n len rqzpre bound 12 |
| 270 | c = get gcfv add len rqzpre i |
| 271 | if or lt c 48 gt c 57 |
| 272 | ret soerr 400 rqmsg |
| 273 | end |
| 274 | end |
| 275 | for i ulong ulong n bound 40 |
| 276 | put rqd i get gcfv i |
| 277 | end |
| 278 | end |
| 279 | if eq add get rqol 0 get rqdl 0 0 |
| 280 | ret soerr 400 rqmsg |
| 281 | end |
| 282 | ret rqappend 90 |
| 283 | end |
| 284 | fn rxint to long |
| 285 | if not fpeq rqpath |
| 286 | ret 0 |
| 287 | end |
| 288 | if eq get fmeth 0 3 |
| 289 | ret rqpost |
| 290 | end |
| 291 | ret rqform |
| 292 | end |