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