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 0x01020304, or returns -1 for invalid inputs. See also FormatIp
for the inverse operation. for the inverse operation.
ProgramAddr(str) ProgramAddr(ip:int)
Configures the address on which to listen. Can be used multiple ProgramAddr(host:str)
times to set more than one address. 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) ProgramBrand(str)
Changes HTTP Server header, as well as the <h1> title on the / 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}; struct addrinfo hint = {AI_NUMERICSERV, AF_INET, SOCK_STREAM, IPPROTO_TCP};
host = luaL_checkstring(L, 1); host = luaL_checkstring(L, 1);
if ((ip = ParseIp(host, -1)) != -1) { if ((ip = ParseIp(host, -1)) != -1) {
lua_pushinteger(L, ntohl(ai->ai_addr4->sin_addr.s_addr)); lua_pushinteger(L, ip);
return 1; return 1;
} else if ((rc = getaddrinfo(host, "0", &hint, &ai)) == EAI_SUCCESS) { } else if ((rc = getaddrinfo(host, "0", &hint, &ai)) == EAI_SUCCESS) {
lua_pushinteger(L, ntohl(ai->ai_addr4->sin_addr.s_addr)); lua_pushinteger(L, ntohl(ai->ai_addr4->sin_addr.s_addr));

View file

@ -143,7 +143,7 @@ STATIC_YOINK("ShowCrashReportsEarly");
#define REDBEAN "redbean" #define REDBEAN "redbean"
#endif #endif
#define VERSION 0x020006 #define VERSION 0x020007
#define HEARTBEAT 5000 /*ms*/ #define HEARTBEAT 5000 /*ms*/
#define HASH_LOAD_FACTOR /* 1. / */ 4 #define HASH_LOAD_FACTOR /* 1. / */ 4
#define MONITOR_MICROS 150000 #define MONITOR_MICROS 150000
@ -764,25 +764,22 @@ static void ProgramSslTicketLifetime(long x) {
sslticketlifetime = 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) { static void ProgramAddr(const char *addr) {
uint32_t ip; ssize_t rc;
if (IsTiny()) { int64_t ip;
ip = ParseIp(addr, -1); if ((ip = ParseIp(addr, -1)) == -1) {
} else { if (!IsTiny()) {
ip = ResolveIp(addr); 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 = realloc(ips.p, ++ips.n * sizeof(*ips.p));
ips.p[ips.n - 1] = ip; ips.p[ips.n - 1] = ip;
@ -4647,14 +4644,22 @@ static int LuaProgramUniprocess(lua_State *L) {
return 1; return 1;
} }
static dontinline int LuaProgramString(lua_State *L, void P(const char *)) { static int LuaProgramAddr(lua_State *L) {
P(luaL_checkstring(L, 1)); 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; return 0;
} }
static int LuaProgramAddr(lua_State *L) { static dontinline int LuaProgramString(lua_State *L, void P(const char *)) {
OnlyCallFromInitLua(L, "ProgramAddr"); P(luaL_checkstring(L, 1));
return LuaProgramString(L, ProgramAddr); return 0;
} }
static int LuaProgramBrand(lua_State *L) { static int LuaProgramBrand(lua_State *L) {