Skip to content

Commit

Permalink
ruleset: naming convention
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <[email protected]>
  • Loading branch information
hexian000 committed Apr 16, 2024
1 parent 8b7473f commit 7afbca4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
44 changes: 22 additions & 22 deletions src/ruleset.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static int ruleset_loadfile_(lua_State *restrict L)
static int ruleset_invoke_(lua_State *restrict L)
{
struct reader_status rd = { .s = (struct stream *)lua_topointer(L, 1) };
if (lua_load(L, stream_reader, &rd, "=invoke", NULL)) {
if (lua_load(L, ruleset_reader, &rd, "=invoke", NULL)) {
return lua_error(L);
}
lua_call(L, 0, 0);
Expand All @@ -106,8 +106,8 @@ static int ruleset_rpcall_(lua_State *restrict L)
const void **result = (const void **)lua_topointer(L, 2);
size_t *resultlen = (size_t *)lua_topointer(L, 3);
lua_settop(L, 0);
lua_pushcfunction(L, api_marshal);
if (lua_load(L, stream_reader, &rd, "=rpc", NULL)) {
lua_pushcfunction(L, api_marshal_);
if (lua_load(L, ruleset_reader, &rd, "=rpc", NULL)) {
return lua_error(L);
}
/* stack: marshal f */
Expand Down Expand Up @@ -169,7 +169,7 @@ static int ruleset_update_(lua_State *restrict L)
struct reader_status rd = { .s = (struct stream *)lua_topointer(L, 2) };
lua_settop(L, 0);
if (modname == NULL) {
if (lua_load(L, stream_reader, &rd, "=ruleset", NULL)) {
if (lua_load(L, ruleset_reader, &rd, "=ruleset", NULL)) {
return lua_error(L);
}
lua_pushliteral(L, "ruleset");
Expand All @@ -184,7 +184,7 @@ static int ruleset_update_(lua_State *restrict L)
name[0] = '=';
memcpy(name + 1, modname, namelen);
name[1 + namelen] = '\0';
if (lua_load(L, stream_reader, &rd, name, NULL)) {
if (lua_load(L, ruleset_reader, &rd, name, NULL)) {
return lua_error(L);
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ static int ruleset_xpcall_(lua_State *restrict L)
}

/* neosocksd.invoke(code, addr, proxyN, ..., proxy1) */
static int api_invoke(lua_State *restrict L)
static int api_invoke_(lua_State *restrict L)
{
const int n = lua_gettop(L);
for (int i = 1; i <= MAX(2, n); i++) {
Expand All @@ -275,7 +275,7 @@ static int api_invoke(lua_State *restrict L)
}

/* neosocksd.resolve(host) */
static int api_resolve(lua_State *restrict L)
static int api_resolve_(lua_State *restrict L)
{
const char *name = luaL_checkstring(L, 1);
union sockaddr_max addr;
Expand All @@ -288,7 +288,7 @@ static int api_resolve(lua_State *restrict L)
}

/* neosocksd.parse_ipv4(ipv4) */
static int api_parse_ipv4(lua_State *restrict L)
static int api_parse_ipv4_(lua_State *restrict L)
{
const char *s = lua_tostring(L, 1);
if (s == NULL) {
Expand All @@ -304,7 +304,7 @@ static int api_parse_ipv4(lua_State *restrict L)
}

/* neosocksd.parse_ipv6(ipv6) */
static int api_parse_ipv6(lua_State *restrict L)
static int api_parse_ipv6_(lua_State *restrict L)
{
const char *s = lua_tostring(L, 1);
if (s == NULL) {
Expand Down Expand Up @@ -342,7 +342,7 @@ static void tick_cb(struct ev_loop *loop, struct ev_timer *watcher, int revents)
}

/* neosocksd.setinterval(interval) */
static int api_setinterval(lua_State *restrict L)
static int api_setinterval_(lua_State *restrict L)
{
luaL_checktype(L, 1, LUA_TNUMBER);
double interval = lua_tonumber(L, 1);
Expand All @@ -362,7 +362,7 @@ static int api_setinterval(lua_State *restrict L)
}

/* neosocksd.splithostport() */
static int api_splithostport(lua_State *restrict L)
static int api_splithostport_(lua_State *restrict L)
{
size_t len;
const char *s = luaL_checklstring(L, 1, &len);
Expand All @@ -386,7 +386,7 @@ static int api_splithostport(lua_State *restrict L)
}

/* neosocksd.stats() */
static int api_stats(lua_State *restrict L)
static int api_stats_(lua_State *restrict L)
{
struct server *restrict s = G.server;
if (s == NULL) {
Expand All @@ -410,7 +410,7 @@ static int api_stats(lua_State *restrict L)
}

/* neosocksd.now() */
static int api_now(lua_State *restrict L)
static int api_now_(lua_State *restrict L)
{
struct ruleset *restrict r = find_ruleset(L);
const ev_tstamp now = ev_now(r->loop);
Expand All @@ -420,17 +420,17 @@ static int api_now(lua_State *restrict L)

static int luaopen_neosocksd(lua_State *restrict L)
{
lua_pushcfunction(L, api_marshal);
lua_pushcfunction(L, api_marshal_);
lua_setglobal(L, "marshal");
const luaL_Reg apilib[] = {
{ "invoke", api_invoke },
{ "resolve", api_resolve },
{ "setinterval", api_setinterval },
{ "splithostport", api_splithostport },
{ "parse_ipv4", api_parse_ipv4 },
{ "parse_ipv6", api_parse_ipv6 },
{ "stats", api_stats },
{ "now", api_now },
{ "invoke", api_invoke_ },
{ "resolve", api_resolve_ },
{ "setinterval", api_setinterval_ },
{ "splithostport", api_splithostport_ },
{ "parse_ipv4", api_parse_ipv4_ },
{ "parse_ipv6", api_parse_ipv6_ },
{ "stats", api_stats_ },
{ "now", api_now_ },
{ NULL, NULL },
};
luaL_newlib(L, apilib);
Expand Down
2 changes: 1 addition & 1 deletion src/ruleset/await.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ await_invoke_k_(lua_State *restrict L, const int status, lua_KContext ctx)
.prefix = "return ",
.prefixlen = 7,
};
if (lua_load(L, stream_reader, &rd, "=unmarshal", NULL)) {
if (lua_load(L, ruleset_reader, &rd, "=unmarshal", NULL)) {
return lua_error(L);
}
lua_call(L, 0, LUA_MULTRET);
Expand Down
2 changes: 1 addition & 1 deletion src/ruleset/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int format_addr_(lua_State *restrict L)
return 1;
}

const char *stream_reader(lua_State *L, void *ud, size_t *restrict sz)
const char *ruleset_reader(lua_State *L, void *ud, size_t *restrict sz)
{
UNUSED(L);
struct reader_status *restrict rd = ud;
Expand Down
2 changes: 1 addition & 1 deletion src/ruleset/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct reader_status {
size_t prefixlen;
};

const char *stream_reader(lua_State *L, void *ud, size_t *sz);
const char *ruleset_reader(lua_State *L, void *ud, size_t *sz);

enum ruleset_functions {
FUNC_REQUEST = 1,
Expand Down
2 changes: 1 addition & 1 deletion src/ruleset/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static void marshal_value(
}

/* s = marshal(...) */
int api_marshal(lua_State *restrict L)
int api_marshal_(lua_State *restrict L)
{
const int n = lua_gettop(L);
/* open */
Expand Down
2 changes: 1 addition & 1 deletion src/ruleset/marshal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

#include "lua.h"

int api_marshal(lua_State *L);
int api_marshal_(lua_State *L);

#endif /* RULESET_MARSHAL_H */

0 comments on commit 7afbca4

Please sign in to comment.