Release redbean 2.0.7

This commit is contained in:
Justine Tunney 2022-06-23 17:59:35 -07:00
parent 4b9ee980a1
commit a9d77362f9
3 changed files with 41 additions and 28 deletions

View file

@ -1038,9 +1038,17 @@ FUNCTIONS
0x01020304, or returns -1 for invalid inputs. See also FormatIp
for the inverse operation.
ProgramAddr(str)
Configures the address on which to listen. Can be used multiple
times to set more than one address.
ProgramAddr(ip:int)
ProgramAddr(host:str)
Configures the address on which to listen. This can be called
multiple times to set more than one address. If an integer is
provided then it should be a word-encoded IPv4 address, such
as the ones returned by ResolveIp(). If a string is provided,
it will first be passed to ParseIp() to see if it's an IPv4
address. If it isn't, then a HOSTS.TXT lookup is performed,
with fallback to the system-configured DNS resolution service.
Please note that in MODE=tiny the HOSTS.TXT and DNS resolution
isn't included, and therefore an IP must be provided.
ProgramBrand(str)
Changes HTTP Server header, as well as the <h1> title on the /

View file

@ -390,7 +390,7 @@ int LuaResolveIp(lua_State *L) {
struct addrinfo hint = {AI_NUMERICSERV, AF_INET, SOCK_STREAM, IPPROTO_TCP};
host = luaL_checkstring(L, 1);
if ((ip = ParseIp(host, -1)) != -1) {
lua_pushinteger(L, ntohl(ai->ai_addr4->sin_addr.s_addr));
lua_pushinteger(L, ip);
return 1;
} else if ((rc = getaddrinfo(host, "0", &hint, &ai)) == EAI_SUCCESS) {
lua_pushinteger(L, ntohl(ai->ai_addr4->sin_addr.s_addr));

View file

@ -143,7 +143,7 @@ STATIC_YOINK("ShowCrashReportsEarly");
#define REDBEAN "redbean"
#endif
#define VERSION 0x020006
#define VERSION 0x020007
#define HEARTBEAT 5000 /*ms*/
#define HASH_LOAD_FACTOR /* 1. / */ 4
#define MONITOR_MICROS 150000
@ -764,25 +764,22 @@ static void ProgramSslTicketLifetime(long x) {
sslticketlifetime = x;
}
static uint32_t ResolveIp(const char *addr) {
ssize_t rc;
uint32_t ip;
struct addrinfo *ai = NULL;
struct addrinfo hint = {AI_NUMERICSERV, AF_INET, SOCK_STREAM, IPPROTO_TCP};
if ((rc = getaddrinfo(addr, "0", &hint, &ai)) != EAI_SUCCESS) {
DIEF("(cfg) error: bad addr: %s (EAI_%s)", addr, gai_strerror(rc));
}
ip = ntohl(ai->ai_addr4->sin_addr.s_addr);
freeaddrinfo(ai);
return ip;
}
static void ProgramAddr(const char *addr) {
uint32_t ip;
if (IsTiny()) {
ip = ParseIp(addr, -1);
} else {
ip = ResolveIp(addr);
ssize_t rc;
int64_t ip;
if ((ip = ParseIp(addr, -1)) == -1) {
if (!IsTiny()) {
struct addrinfo *ai = NULL;
struct addrinfo hint = {AI_NUMERICSERV, AF_INET, SOCK_STREAM,
IPPROTO_TCP};
if ((rc = getaddrinfo(addr, "0", &hint, &ai)) != EAI_SUCCESS) {
DIEF("(cfg) error: bad addr: %s (EAI_%s)", addr, gai_strerror(rc));
}
ip = ntohl(ai->ai_addr4->sin_addr.s_addr);
freeaddrinfo(ai);
} else {
DIEF("(cfg) error: ProgramAddr() needs an IP in MODE=tiny: %s", addr);
}
}
ips.p = realloc(ips.p, ++ips.n * sizeof(*ips.p));
ips.p[ips.n - 1] = ip;
@ -4647,14 +4644,22 @@ static int LuaProgramUniprocess(lua_State *L) {
return 1;
}
static dontinline int LuaProgramString(lua_State *L, void P(const char *)) {
P(luaL_checkstring(L, 1));
static int LuaProgramAddr(lua_State *L) {
uint32_t ip;
OnlyCallFromInitLua(L, "ProgramAddr");
if (lua_isinteger(L, 1)) {
ip = luaL_checkinteger(L, 1);
ips.p = realloc(ips.p, ++ips.n * sizeof(*ips.p));
ips.p[ips.n - 1] = ip;
} else {
ProgramAddr(luaL_checkstring(L, 1));
}
return 0;
}
static int LuaProgramAddr(lua_State *L) {
OnlyCallFromInitLua(L, "ProgramAddr");
return LuaProgramString(L, ProgramAddr);
static dontinline int LuaProgramString(lua_State *L, void P(const char *)) {
P(luaL_checkstring(L, 1));
return 0;
}
static int LuaProgramBrand(lua_State *L) {