Skip to content

Commit d062170

Browse files
committed
feature: implemented the 'ngx.crc32_short' and 'ngx.crc32_long' C FFI APIs.
1 parent 50dabbc commit d062170

File tree

1 file changed

+14
-44
lines changed

1 file changed

+14
-44
lines changed

src/ngx_http_lua_string.c

+14-44
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
static uintptr_t ngx_http_lua_ngx_escape_sql_str(u_char *dst, u_char *src,
3131
size_t size);
3232
static int ngx_http_lua_ngx_quote_sql_str(lua_State *L);
33-
static int ngx_http_lua_ngx_crc32_short(lua_State *L);
34-
static int ngx_http_lua_ngx_crc32_long(lua_State *L);
3533
static int ngx_http_lua_ngx_encode_args(lua_State *L);
3634
static int ngx_http_lua_ngx_decode_args(lua_State *L);
3735
#if (NGX_OPENSSL)
@@ -51,12 +49,6 @@ ngx_http_lua_inject_string_api(lua_State *L)
5149
lua_pushcfunction(L, ngx_http_lua_ngx_quote_sql_str);
5250
lua_setfield(L, -2, "quote_sql_str");
5351

54-
lua_pushcfunction(L, ngx_http_lua_ngx_crc32_short);
55-
lua_setfield(L, -2, "crc32_short");
56-
57-
lua_pushcfunction(L, ngx_http_lua_ngx_crc32_long);
58-
lua_setfield(L, -2, "crc32_long");
59-
6052
#if (NGX_OPENSSL)
6153
lua_pushcfunction(L, ngx_http_lua_ngx_hmac_sha1);
6254
lua_setfield(L, -2, "hmac_sha1");
@@ -256,42 +248,6 @@ ngx_http_lua_encode_base64(ngx_str_t *dst, ngx_str_t *src, int no_padding)
256248
}
257249

258250

259-
static int
260-
ngx_http_lua_ngx_crc32_short(lua_State *L)
261-
{
262-
u_char *p;
263-
size_t len;
264-
265-
if (lua_gettop(L) != 1) {
266-
return luaL_error(L, "expecting one argument, but got %d",
267-
lua_gettop(L));
268-
}
269-
270-
p = (u_char *) luaL_checklstring(L, 1, &len);
271-
272-
lua_pushnumber(L, (lua_Number) ngx_crc32_short(p, len));
273-
return 1;
274-
}
275-
276-
277-
static int
278-
ngx_http_lua_ngx_crc32_long(lua_State *L)
279-
{
280-
u_char *p;
281-
size_t len;
282-
283-
if (lua_gettop(L) != 1) {
284-
return luaL_error(L, "expecting one argument, but got %d",
285-
lua_gettop(L));
286-
}
287-
288-
p = (u_char *) luaL_checklstring(L, 1, &len);
289-
290-
lua_pushnumber(L, (lua_Number) ngx_crc32_long(p, len));
291-
return 1;
292-
}
293-
294-
295251
static int
296252
ngx_http_lua_ngx_encode_args(lua_State *L)
297253
{
@@ -414,6 +370,20 @@ ngx_http_lua_ffi_sha1_bin(const u_char *src, size_t len, u_char *dst)
414370
}
415371

416372

373+
unsigned int
374+
ngx_http_lua_ffi_crc32_short(const u_char *src, size_t len)
375+
{
376+
return ngx_crc32_short((u_char *) src, len);
377+
}
378+
379+
380+
unsigned int
381+
ngx_http_lua_ffi_crc32_long(const u_char *src, size_t len)
382+
{
383+
return ngx_crc32_long((u_char *) src, len);
384+
}
385+
386+
417387
size_t
418388
ngx_http_lua_ffi_encode_base64(const u_char *src, size_t slen, u_char *dst,
419389
int no_padding)

0 commit comments

Comments
 (0)