X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=lua%2Fuci.c;h=67e9418810d031f042582768fbc81d86215b1c4f;hp=bdac3f6f5c13dd9892f5315bf9d7659fc23dd9c0;hb=9d0c6014304f1dd2f1f7a57e2039520b0f330250;hpb=740ed93a529b0a8d9dc8a21f7d6fbac65295f4a3 diff --git a/lua/uci.c b/lua/uci.c index bdac3f6..67e9418 100644 --- a/lua/uci.c +++ b/lua/uci.c @@ -426,6 +426,56 @@ error: } static int +uci_lua_rename(lua_State *L) +{ + struct uci_context *ctx; + struct uci_ptr ptr; + int err = UCI_ERR_MEM; + char *s = NULL; + int nargs, offset = 0; + + ctx = find_context(L, &offset); + nargs = lua_gettop(L); + if (lookup_args(L, ctx, offset, &ptr, &s)) + goto error; + + switch(nargs - offset) { + case 1: + /* Format: uci.set("p.s.o=v") or uci.set("p.s=v") */ + break; + case 4: + /* Format: uci.set("p", "s", "o", "v") */ + ptr.value = luaL_checkstring(L, nargs); + break; + case 3: + /* Format: uci.set("p", "s", "v") */ + ptr.value = ptr.option; + ptr.option = NULL; + break; + default: + err = UCI_ERR_INVAL; + goto error; + } + + err = uci_lookup_ptr(ctx, &ptr, NULL, false); + if (err) + goto error; + + if (((ptr.s == NULL) && (ptr.option != NULL)) || (ptr.value == NULL)) { + err = UCI_ERR_INVAL; + goto error; + } + + err = uci_rename(ctx, &ptr); + if (err) + goto error; + +error: + return uci_push_status(L, ctx, false); +} + + +static int uci_lua_set(lua_State *L) { struct uci_context *ctx; @@ -762,6 +812,7 @@ static const luaL_Reg uci[] = { { "get_all", uci_lua_get_all }, { "add", uci_lua_add }, { "set", uci_lua_set }, + { "rename", uci_lua_rename }, { "save", uci_lua_save }, { "delete", uci_lua_delete }, { "commit", uci_lua_commit },