From: Panu Matilainen Date: Fri, 26 Jun 2009 12:39:20 +0000 (+0300) Subject: Add base64 encode and decode extensions to the lua interface X-Git-Tag: tznext/4.11.0.1.tizen20130304~2914 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02f9f3fbdd5e0cc858ab46da9a11e04110f92462;p=tools%2Flibrpm-tizen.git Add base64 encode and decode extensions to the lua interface --- diff --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c index 133fa16..7f25655 100644 --- a/rpmio/rpmlua.c +++ b/rpmio/rpmlua.c @@ -16,6 +16,7 @@ #include #include #include "rpmio/rpmhook.h" +#include "rpmio/base64.h" #define _RPMLUA_INTERNAL #include "rpmio/rpmlua.h" @@ -568,6 +569,37 @@ void rpmluaInteractive(rpmlua _lua) /* ------------------------------------------------------------------ */ /* Lua API */ +static int rpm_b64encode(lua_State *L) +{ + const char *str = luaL_checkstring(L, 1); + size_t len = lua_strlen(L, 1); + int linelen = -1; + if (lua_gettop(L) == 2) + linelen = luaL_checkinteger(L, 2); + if (str && len) { + char *data = b64encode(str, len, linelen); + lua_pushstring(L, data); + free(data); + } + return 1; +} + +static int rpm_b64decode(lua_State *L) +{ + const char *str = luaL_checkstring(L, 1); + if (str) { + void *data = NULL; + size_t len = 0; + if (b64decode(str, &data, &len) == 0) { + lua_pushlstring(L, data, len); + } else { + lua_pushnil(L); + } + free(data); + } + return 1; +} + static int rpm_expand(lua_State *L) { const char *str = luaL_checkstring(L, 1); @@ -768,6 +800,8 @@ static int rpm_print (lua_State *L) } static const luaL_reg rpmlib[] = { + {"b64encode", rpm_b64encode}, + {"b64decode", rpm_b64decode}, {"expand", rpm_expand}, {"define", rpm_define}, {"register", rpm_register},