mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 16:58:30 +00:00
Make more major improvements to redbean
- POSIX regular expressions for Lua - Improved protocol parsing and encoding - Additional APIs for ZIP storage retrieval - Fix st_mode issue on NT for regular files - Generalized APIs for URL and Host handling - Worked out the kinks in resource resolution - Allow for custom error pages like /404.html
This commit is contained in:
parent
26ac6871da
commit
4effa23528
74 changed files with 3710 additions and 14246 deletions
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/x/x.h"
|
||||
#include "net/http/escape.h"
|
||||
#include "net/http/url.h"
|
||||
|
||||
/**
|
||||
* Escapes URL component using generic table.
|
||||
|
@ -26,29 +27,22 @@
|
|||
* Always using UTF-8 is a good idea.
|
||||
*
|
||||
* @param size if -1 implies strlen
|
||||
* @see EscapeUrlParam
|
||||
* @see EscapeUrlFragment
|
||||
* @see EscapeUrlPathSegment
|
||||
* @see kEscapeAuthority
|
||||
* @see kEscapeIpLiteral
|
||||
* @see kEscapePath
|
||||
* @see kEscapePathSegment
|
||||
* @see kEscapeParam
|
||||
* @see kEscapeFragment
|
||||
*/
|
||||
struct EscapeResult EscapeUrl(const char *data, size_t size,
|
||||
const char xlat[hasatleast 256]) {
|
||||
int c;
|
||||
char *p;
|
||||
size_t i;
|
||||
struct UrlView v;
|
||||
struct EscapeResult r;
|
||||
if (size == -1) size = data ? strlen(data) : 0;
|
||||
p = r.data = xmalloc(size * 6 + 1);
|
||||
for (i = 0; i < size; ++i) {
|
||||
if (!xlat[(c = data[i] & 0xff)]) {
|
||||
*p++ = c;
|
||||
} else {
|
||||
p[0] = '%';
|
||||
p[1] = "0123456789ABCDEF"[(c & 0xF0) >> 4];
|
||||
p[2] = "0123456789ABCDEF"[(c & 0x0F) >> 0];
|
||||
p += 3;
|
||||
}
|
||||
}
|
||||
r.size = p - r.data;
|
||||
v.p = data;
|
||||
v.n = size;
|
||||
r.data = xmalloc(size * 6 + 1);
|
||||
r.size = EscapeUrlView(r.data, &v, xlat) - r.data;
|
||||
r.data = xrealloc(r.data, r.size + 1);
|
||||
r.data[r.size] = '\0';
|
||||
return r;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue