mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 08:18:30 +00:00
Make major improvements to redbean and libraries
The most exciting improvement is dynamic pages will soon be able to use the executable itself as an object store. it required a heroic technique for overcoming ETXTBSY restrictions which lets us open the executable in read/write mode, which means (1) wa can restore the APE header, and (2) we can potentially containerize redbean extension code so that modules you download for your redbean online will only impact your redbean. Here's a list of breaking changes to redbean: - Remove /tool/net/ prefix from magic ZIP paths - GetHeader() now returns NIL if header is absent Here's a list of fixes and enhancements to redbean: - Support 64-bit ZIP archives - Record User-Agent header in logs - Add twelve error handlers to accept() - Display octal st_mode on listing page - Show ZIP file comments on listing page - Restore APE MZ header on redbean startup - Track request count on redbean index page - Report server uptime on redbean index page - Don't bind server socket using SO_REUSEPORT - Fix #151 where Lua LoadAsset() could free twice - Report rusage accounting when workers exit w/ -vv - Use ZIP iattr field as text/plain vs. binary hint - Add ParseUrl() API for parsing things like a.href - Add ParseParams() API for parsing HTTP POST bodies - Add IsAcceptablePath() API for checking dots, etc. - Add IsValidHttpToken() API for validating sane ASCII - Add IsAcceptableHostPort() for validating HOST[:PORT] - Send 400 response to HTTP/1.1 requests without a Host - Send 403 response if ZIP or file isn't other readable - Add virtual hosting that tries prepending Host to path - Route requests based on Host in Request-URI if present - Host routing will attempt to remove or add the www. prefix - Sign-extend UNIX timestamps and don't adjust FileTime zone Here's some of the improvements made to Cosmopolitan Libc: - Fix ape.S indentation - Improve consts.sh magnums - Write pretty good URL parser - Improve rusage accounting apis - Bring mremap() closer to working - Added ZIP APIs which will change - Check for overflow in reallocarray() - Remove overly fancy linkage in strerror() - Fix GDB attach on crash w/ OpenBSD msyscall() - Make sigqueue() portable to most UNIX distros - Make integer serialization macros more elegant - Bring back 34x tprecode8to16() performance boost - Make malloc() more resilient to absurdly large sizes
This commit is contained in:
parent
69c508729e
commit
bf03b2e64c
307 changed files with 4557 additions and 2581 deletions
74
libc/zip.h
74
libc/zip.h
|
@ -10,7 +10,7 @@
|
|||
|
||||
#define kZipAlign 2
|
||||
|
||||
#define kZipCosmopolitanVersion 20
|
||||
#define kZipCosmopolitanVersion kZipEra2001
|
||||
|
||||
#define kZipOsDos 0
|
||||
#define kZipOsAmiga 1
|
||||
|
@ -37,8 +37,8 @@
|
|||
#define kZipEra1993 20 /* PKZIP 2.0: deflate/subdir/etc. support */
|
||||
#define kZipEra2001 45 /* PKZIP 4.5: kZipExtraZip64 support */
|
||||
|
||||
#define kZipIattrBinary 0
|
||||
#define kZipIattrAscii 1
|
||||
#define kZipIattrBinary 0 /* first bit not set */
|
||||
#define kZipIattrText 1 /* first bit set */
|
||||
|
||||
#define kZipCompressionNone 0
|
||||
#define kZipCompressionDeflate 8
|
||||
|
@ -49,6 +49,9 @@
|
|||
#define kZipCdirHdrLinkableSize \
|
||||
ROUNDUP(kZipCfileHdrMinSize + PATH_MAX, kZipCdirAlign)
|
||||
|
||||
#define kZipCdir64HdrMagic 0x06064b50 /* PK♣♠ "PK\6\6" */
|
||||
#define kZipCdir64HdrMinSize 56
|
||||
|
||||
#define kZipCfileHdrMagic 0x02014b50 /* PK☺☻ "PK\1\2" */
|
||||
#define kZipCfileHdrMinSize 46
|
||||
#define kZipCfileOffsetGeneralflag 8
|
||||
|
@ -73,10 +76,12 @@
|
|||
|
||||
#define kZipGflagUtf8 0x800
|
||||
|
||||
#define kZipExtraHdrSize 4
|
||||
#define kZipExtraZip64 0x0001
|
||||
#define kZipExtraNtfs 0x000a
|
||||
#define kZipExtraExtendedTimestamp 0x5455
|
||||
#define kZipExtraHdrSize 4
|
||||
#define kZipExtraZip64 0x0001
|
||||
#define kZipExtraNtfs 0x000a
|
||||
#define kZipExtraUnix 0x000d
|
||||
#define kZipExtraExtendedTimestamp 0x5455
|
||||
#define kZipExtraInfoZipNewUnixExtra 0x7875
|
||||
|
||||
#define kZipCfileMagic "PK\001\002"
|
||||
|
||||
|
@ -91,15 +96,30 @@
|
|||
#define ZIP_CDIR_SIZE(P) READ32LE((P) + 12)
|
||||
#define ZIP_CDIR_OFFSET(P) READ32LE((P) + 16)
|
||||
#define ZIP_CDIR_COMMENTSIZE(P) READ16LE((P) + 20)
|
||||
#define ZIP_CDIR_COMMENT(P) (&(P)[22])
|
||||
#define ZIP_CDIR_COMMENT(P) ((P) + 22) /* recommend stopping at nul */
|
||||
#define ZIP_CDIR_HDRSIZE(P) (ZIP_CDIR_COMMENTSIZE(P) + kZipCdirHdrMinSize)
|
||||
|
||||
/* zip64 end of central directory record */
|
||||
#define ZIP_CDIR64_MAGIC(P) READ32LE(P)
|
||||
#define ZIP_CDIR64_HDRSIZE(P) (READ64LE((P) + 4) + 12)
|
||||
#define ZIP_CDIR64_VERSIONMADE(P) READ16LE((P) + 12)
|
||||
#define ZIP_CDIR64_VERSIONNEED(P) READ16LE((P) + 14)
|
||||
#define ZIP_CDIR64_DISK(P) READ32LE((P) + 16)
|
||||
#define ZIP_CDIR64_STARTINGDISK(P) READ32LE((P) + 20)
|
||||
#define ZIP_CDIR64_RECORDSONDISK(P) READ64LE((P) + 24)
|
||||
#define ZIP_CDIR64_RECORDS(P) READ64LE((P) + 32)
|
||||
#define ZIP_CDIR64_SIZE(P) READ64LE((P) + 40)
|
||||
#define ZIP_CDIR64_OFFSET(P) READ64LE((P) + 48)
|
||||
#define ZIP_CDIR64_COMMENTSIZE(P) \
|
||||
(ZIP_CDIR64_HDRSIZE(P) >= 56 ? ZIP_CDIR64_HDRSIZE(P) - 56 : 0)
|
||||
#define ZIP_CDIR64_COMMENT(P) ((P) + 56) /* recommend stopping at nul */
|
||||
|
||||
/* central directory file header */
|
||||
#define ZIP_CFILE_MAGIC(P) READ32LE(P)
|
||||
#define ZIP_CFILE_VERSIONMADE(P) ((P)[4])
|
||||
#define ZIP_CFILE_FILEATTRCOMPAT(P) ((P)[5])
|
||||
#define ZIP_CFILE_VERSIONNEED(P) ((P)[6])
|
||||
#define ZIP_CFILE_OSNEED(P) ((P)[7])
|
||||
#define ZIP_CFILE_VERSIONMADE(P) (255 & (P)[4])
|
||||
#define ZIP_CFILE_FILEATTRCOMPAT(P) (255 & (P)[5])
|
||||
#define ZIP_CFILE_VERSIONNEED(P) (255 & (P)[6])
|
||||
#define ZIP_CFILE_OSNEED(P) (255 & (P)[7])
|
||||
#define ZIP_CFILE_GENERALFLAG(P) READ16LE((P) + kZipCfileOffsetGeneralflag)
|
||||
#define ZIP_CFILE_COMPRESSIONMETHOD(P) \
|
||||
READ16LE((P) + kZipCfileOffsetCompressionmethod)
|
||||
|
@ -119,18 +139,19 @@
|
|||
#define ZIP_CFILE_EXTERNALATTRIBUTES(P) \
|
||||
READ32LE((P) + kZipCfileOffsetExternalattributes)
|
||||
#define ZIP_CFILE_OFFSET(P) READ32LE((P) + kZipCfileOffsetOffset)
|
||||
#define ZIP_CFILE_NAME(P) ((const char *)(&(P)[46])) /* not nul-terminated */
|
||||
#define ZIP_CFILE_EXTRA(P) (&(P)[46 + ZIP_CFILE_NAMESIZE(P)])
|
||||
#define ZIP_CFILE_COMMENT(P) \
|
||||
(&(P)[46 + ZIP_CFILE_NAMESIZE(P) + ZIP_CFILE_EXTRASIZE(P)])
|
||||
#define ZIP_CFILE_NAME(P) ((const char *)((P) + 46)) /* not nul-terminated */
|
||||
#define ZIP_CFILE_EXTRA(P) ((P) + 46 + ZIP_CFILE_NAMESIZE(P))
|
||||
#define ZIP_CFILE_COMMENT(P) \
|
||||
((const char *)((P) + 46 + ZIP_CFILE_NAMESIZE(P) + \
|
||||
ZIP_CFILE_EXTRASIZE(P))) /* recommend stopping at nul */
|
||||
#define ZIP_CFILE_HDRSIZE(P) \
|
||||
(ZIP_CFILE_NAMESIZE(P) + ZIP_CFILE_EXTRASIZE(P) + ZIP_CFILE_COMMENTSIZE(P) + \
|
||||
kZipCfileHdrMinSize)
|
||||
|
||||
/* local file header */
|
||||
#define ZIP_LFILE_MAGIC(P) READ32LE(P)
|
||||
#define ZIP_LFILE_VERSIONNEED(P) ((P)[4])
|
||||
#define ZIP_LFILE_OSNEED(P) ((P)[5])
|
||||
#define ZIP_LFILE_VERSIONNEED(P) (255 & (P)[4])
|
||||
#define ZIP_LFILE_OSNEED(P) (255 & (P)[5])
|
||||
#define ZIP_LFILE_GENERALFLAG(P) READ16LE((P) + kZipLfileOffsetGeneralflag)
|
||||
#define ZIP_LFILE_COMPRESSIONMETHOD(P) \
|
||||
READ16LE((P) + kZipLfileOffsetCompressionmethod)
|
||||
|
@ -145,8 +166,8 @@
|
|||
READ32LE((P) + kZipLfileOffsetUncompressedsize)
|
||||
#define ZIP_LFILE_NAMESIZE(P) READ16LE((P) + 26)
|
||||
#define ZIP_LFILE_EXTRASIZE(P) READ16LE((P) + 28)
|
||||
#define ZIP_LFILE_NAME(P) ((const char *)(&(P)[30]))
|
||||
#define ZIP_LFILE_EXTRA(P) (&(P)[30 + ZIP_LFILE_NAMESIZE(P)])
|
||||
#define ZIP_LFILE_NAME(P) ((const char *)((P) + 30))
|
||||
#define ZIP_LFILE_EXTRA(P) ((P) + 30 + ZIP_LFILE_NAMESIZE(P))
|
||||
#define ZIP_LFILE_HDRSIZE(P) \
|
||||
(ZIP_LFILE_NAMESIZE(P) + ZIP_LFILE_EXTRASIZE(P) + kZipLfileHdrMinSize)
|
||||
#define ZIP_LFILE_CONTENT(P) ((P) + ZIP_LFILE_HDRSIZE(P))
|
||||
|
@ -154,9 +175,20 @@
|
|||
|
||||
#define ZIP_EXTRA_HEADERID(P) READ16LE(P)
|
||||
#define ZIP_EXTRA_CONTENTSIZE(P) READ16LE((P) + 2)
|
||||
#define ZIP_EXTRA_CONTENT(P) (&(P)[4])
|
||||
#define ZIP_EXTRA_CONTENT(P) ((P) + 4)
|
||||
#define ZIP_EXTRA_SIZE(P) (ZIP_EXTRA_CONTENTSIZE(P) + kZipExtraHdrSize)
|
||||
|
||||
uint8_t *GetZipCdir(const uint8_t *, size_t);
|
||||
bool IsZipCdir32(const uint8_t *, size_t, size_t);
|
||||
bool IsZipCdir64(const uint8_t *, size_t, size_t);
|
||||
int GetZipCfileMode(const uint8_t *);
|
||||
uint64_t GetZipCdirOffset(const uint8_t *);
|
||||
uint64_t GetZipCdirRecords(const uint8_t *);
|
||||
uint64_t GetZipCfileUncompressedSize(const uint8_t *);
|
||||
uint64_t GetZipCfileCompressedSize(const uint8_t *);
|
||||
uint64_t GetZipCfileOffset(const uint8_t *);
|
||||
uint64_t GetZipLfileUncompressedSize(const uint8_t *);
|
||||
uint64_t GetZipLfileCompressedSize(const uint8_t *);
|
||||
uint8_t *zipfindcentraldir(const uint8_t *, size_t);
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue