Renamed reworked UCI API to uci2 to allow a peaceful coexistence with the old one
Minor bugfixes
This commit is contained in:
parent
9d0c00590d
commit
d463d0b835
10 changed files with 36 additions and 37 deletions
|
@ -102,7 +102,6 @@ define Package/luci-core
|
||||||
$(call Package/luci/libtemplate)
|
$(call Package/luci/libtemplate)
|
||||||
DEPENDS:=+lua +luaposix +bitlib
|
DEPENDS:=+lua +luaposix +bitlib
|
||||||
TITLE:=LuCI core libraries
|
TITLE:=LuCI core libraries
|
||||||
SUBMENU:=!!! DISABLE Libraries -> libuci-lua !!! IT WILL BREAK LUCI !!!
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/luci-core/install
|
define Package/luci-core/install
|
||||||
|
@ -149,14 +148,14 @@ endef
|
||||||
|
|
||||||
define Package/luci-uci
|
define Package/luci-uci
|
||||||
$(call Package/luci/libtemplate)
|
$(call Package/luci/libtemplate)
|
||||||
DEPENDS+=+libuci @!PACKAGE_libuci-lua
|
DEPENDS+=+libuci
|
||||||
TITLE:=High-Level UCI API
|
TITLE:=High-Level UCI API
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/luci-uci/install
|
define Package/luci-uci/install
|
||||||
$(call Package/luci/install/template,$(1),libs/uci)
|
$(call Package/luci/install/template,$(1),libs/uci)
|
||||||
$(INSTALL_DIR) $(1)/usr/lib/lua
|
$(INSTALL_DIR) $(1)/usr/lib/lua
|
||||||
$(CP) $(PKG_BUILD_DIR)/contrib/uci/dist/usr/lib/lua/uci.so $(1)/usr/lib/lua
|
$(CP) $(PKG_BUILD_DIR)/contrib/uci/dist/usr/lib/lua/uci2.so $(1)/usr/lib/lua
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ compile: $(UCI_DIR)/.patched
|
||||||
$(MAKE) -C $(UCI_DIR) install DESTDIR=../dist prefix=/usr
|
$(MAKE) -C $(UCI_DIR) install DESTDIR=../dist prefix=/usr
|
||||||
$(MAKE) -C $(UCI_DIR)/lua CC=$(CC) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" OS="$(OS)"
|
$(MAKE) -C $(UCI_DIR)/lua CC=$(CC) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" OS="$(OS)"
|
||||||
$(MAKE) -C $(UCI_DIR)/lua install DESTDIR=../../dist luadir=$(LUA_LIBRARYDIR)
|
$(MAKE) -C $(UCI_DIR)/lua install DESTDIR=../../dist luadir=$(LUA_LIBRARYDIR)
|
||||||
|
mv dist$(LUA_LIBRARYDIR)/uci.so dist$(LUA_LIBRARYDIR)/uci2.so
|
||||||
|
|
||||||
compile-all: compile
|
compile-all: compile
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
Index: uci.git/lua/uci.c
|
Index: uci.git/lua/uci.c
|
||||||
===================================================================
|
===================================================================
|
||||||
--- uci.git.orig/lua/uci.c 2008-08-26 12:31:34.000000000 +0200
|
--- uci.git.orig/lua/uci.c 2008-08-26 12:31:34.000000000 +0200
|
||||||
+++ uci.git/lua/uci.c 2008-08-27 00:30:46.000000000 +0200
|
+++ uci.git/lua/uci.c 2008-08-27 10:27:29.000000000 +0200
|
||||||
@@ -25,6 +25,7 @@
|
@@ -24,7 +24,8 @@
|
||||||
|
#include <lauxlib.h>
|
||||||
#include <uci.h>
|
#include <uci.h>
|
||||||
|
|
||||||
#define MODNAME "uci"
|
-#define MODNAME "uci"
|
||||||
+#define CURSOR_META "uci.cursor.meta"
|
+#define MODNAME "uci2"
|
||||||
|
+#define CURSOR_META "uci2.cursor.meta"
|
||||||
//#define DEBUG 1
|
//#define DEBUG 1
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -286,7 +288,7 @@ Index: uci.git/lua/uci.c
|
||||||
if (!p)
|
if (!p)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -374,11 +429,12 @@
|
@@ -374,11 +429,11 @@
|
||||||
static int
|
static int
|
||||||
uci_lua_delete(lua_State *L)
|
uci_lua_delete(lua_State *L)
|
||||||
{
|
{
|
||||||
|
@ -294,13 +296,13 @@ Index: uci.git/lua/uci.c
|
||||||
struct uci_ptr ptr;
|
struct uci_ptr ptr;
|
||||||
char *s = NULL;
|
char *s = NULL;
|
||||||
int err = UCI_ERR_NOTFOUND;
|
int err = UCI_ERR_NOTFOUND;
|
||||||
|
-
|
||||||
- if (lookup_args(L, &ptr, &s))
|
- if (lookup_args(L, &ptr, &s))
|
||||||
+ if (lookup_args(L, ctx, &ptr, &s))
|
+ if (lookup_args(L, ctx, &ptr, &s))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
err = uci_delete(ctx, &ptr);
|
err = uci_delete(ctx, &ptr);
|
||||||
@@ -387,7 +443,7 @@
|
@@ -387,7 +442,7 @@
|
||||||
if (s)
|
if (s)
|
||||||
free(s);
|
free(s);
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -309,7 +311,7 @@ Index: uci.git/lua/uci.c
|
||||||
lua_pushboolean(L, (err == 0));
|
lua_pushboolean(L, (err == 0));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -395,6 +451,7 @@
|
@@ -395,6 +450,7 @@
|
||||||
static int
|
static int
|
||||||
uci_lua_set(lua_State *L)
|
uci_lua_set(lua_State *L)
|
||||||
{
|
{
|
||||||
|
@ -317,7 +319,7 @@ Index: uci.git/lua/uci.c
|
||||||
bool istable = false;
|
bool istable = false;
|
||||||
struct uci_ptr ptr;
|
struct uci_ptr ptr;
|
||||||
int err = UCI_ERR_MEM;
|
int err = UCI_ERR_MEM;
|
||||||
@@ -402,14 +459,14 @@
|
@@ -402,14 +458,14 @@
|
||||||
int i, nargs;
|
int i, nargs;
|
||||||
|
|
||||||
nargs = lua_gettop(L);
|
nargs = lua_gettop(L);
|
||||||
|
@ -335,7 +337,7 @@ Index: uci.git/lua/uci.c
|
||||||
/* Format: uci.set("p", "s", "o", "v") */
|
/* Format: uci.set("p", "s", "o", "v") */
|
||||||
if (lua_istable(L, nargs)) {
|
if (lua_istable(L, nargs)) {
|
||||||
if (lua_objlen(L, nargs) < 1)
|
if (lua_objlen(L, nargs) < 1)
|
||||||
@@ -422,7 +479,7 @@
|
@@ -422,7 +478,7 @@
|
||||||
ptr.value = luaL_checkstring(L, nargs);
|
ptr.value = luaL_checkstring(L, nargs);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -344,7 +346,7 @@ Index: uci.git/lua/uci.c
|
||||||
/* Format: uci.set("p", "s", "v") */
|
/* Format: uci.set("p", "s", "v") */
|
||||||
ptr.value = ptr.option;
|
ptr.value = ptr.option;
|
||||||
ptr.option = NULL;
|
ptr.option = NULL;
|
||||||
@@ -433,17 +490,23 @@
|
@@ -433,17 +489,23 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
err = uci_lookup_ptr(ctx, &ptr, NULL, false);
|
err = uci_lookup_ptr(ctx, &ptr, NULL, false);
|
||||||
|
@ -371,7 +373,7 @@ Index: uci.git/lua/uci.c
|
||||||
|
|
||||||
if (istable) {
|
if (istable) {
|
||||||
for (i = 2; i <= lua_objlen(L, nargs); i++) {
|
for (i = 2; i <= lua_objlen(L, nargs); i++) {
|
||||||
@@ -458,7 +521,7 @@
|
@@ -458,7 +520,7 @@
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -380,7 +382,7 @@ Index: uci.git/lua/uci.c
|
||||||
lua_pushboolean(L, (err == 0));
|
lua_pushboolean(L, (err == 0));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -472,6 +535,7 @@
|
@@ -472,6 +534,7 @@
|
||||||
static int
|
static int
|
||||||
uci_lua_package_cmd(lua_State *L, enum pkg_cmd cmd)
|
uci_lua_package_cmd(lua_State *L, enum pkg_cmd cmd)
|
||||||
{
|
{
|
||||||
|
@ -388,7 +390,7 @@ Index: uci.git/lua/uci.c
|
||||||
struct uci_element *e, *tmp;
|
struct uci_element *e, *tmp;
|
||||||
struct uci_ptr ptr;
|
struct uci_ptr ptr;
|
||||||
char *s = NULL;
|
char *s = NULL;
|
||||||
@@ -479,10 +543,10 @@
|
@@ -479,10 +542,10 @@
|
||||||
int nargs;
|
int nargs;
|
||||||
|
|
||||||
nargs = lua_gettop(L);
|
nargs = lua_gettop(L);
|
||||||
|
@ -401,7 +403,7 @@ Index: uci.git/lua/uci.c
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
uci_lookup_ptr(ctx, &ptr, NULL, false);
|
uci_lookup_ptr(ctx, &ptr, NULL, false);
|
||||||
@@ -562,16 +626,16 @@
|
@@ -562,16 +625,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -421,7 +423,7 @@ Index: uci.git/lua/uci.c
|
||||||
if (!p)
|
if (!p)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -596,6 +660,7 @@
|
@@ -596,6 +659,7 @@
|
||||||
static int
|
static int
|
||||||
uci_lua_changes(lua_State *L)
|
uci_lua_changes(lua_State *L)
|
||||||
{
|
{
|
||||||
|
@ -429,7 +431,7 @@ Index: uci.git/lua/uci.c
|
||||||
const char *package = NULL;
|
const char *package = NULL;
|
||||||
char **config = NULL;
|
char **config = NULL;
|
||||||
int nargs;
|
int nargs;
|
||||||
@@ -603,9 +668,9 @@
|
@@ -603,9 +667,9 @@
|
||||||
|
|
||||||
nargs = lua_gettop(L);
|
nargs = lua_gettop(L);
|
||||||
switch(nargs) {
|
switch(nargs) {
|
||||||
|
@ -441,7 +443,7 @@ Index: uci.git/lua/uci.c
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
luaL_error(L, "invalid argument count");
|
luaL_error(L, "invalid argument count");
|
||||||
@@ -613,13 +678,13 @@
|
@@ -613,13 +677,13 @@
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
if (package) {
|
if (package) {
|
||||||
|
@ -457,7 +459,7 @@ Index: uci.git/lua/uci.c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,29 +693,53 @@
|
@@ -628,29 +692,53 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -514,7 +516,7 @@ Index: uci.git/lua/uci.c
|
||||||
{ "load", uci_lua_load },
|
{ "load", uci_lua_load },
|
||||||
{ "unload", uci_lua_unload },
|
{ "unload", uci_lua_unload },
|
||||||
{ "get", uci_lua_get },
|
{ "get", uci_lua_get },
|
||||||
@@ -663,25 +752,33 @@
|
@@ -663,25 +751,33 @@
|
||||||
{ "revert", uci_lua_revert },
|
{ "revert", uci_lua_revert },
|
||||||
{ "changes", uci_lua_changes },
|
{ "changes", uci_lua_changes },
|
||||||
{ "foreach", uci_lua_foreach },
|
{ "foreach", uci_lua_foreach },
|
||||||
|
@ -527,7 +529,8 @@ Index: uci.git/lua/uci.c
|
||||||
|
|
||||||
-
|
-
|
||||||
int
|
int
|
||||||
luaopen_uci(lua_State *L)
|
-luaopen_uci(lua_State *L)
|
||||||
|
+luaopen_uci2(lua_State *L)
|
||||||
{
|
{
|
||||||
- ctx = uci_alloc_context();
|
- ctx = uci_alloc_context();
|
||||||
- if (!ctx)
|
- if (!ctx)
|
||||||
|
|
|
@ -29,10 +29,9 @@ module("luci.cbi", package.seeall)
|
||||||
require("luci.template")
|
require("luci.template")
|
||||||
require("luci.util")
|
require("luci.util")
|
||||||
require("luci.http")
|
require("luci.http")
|
||||||
require("luci.model.uci")
|
|
||||||
require("luci.uvl")
|
require("luci.uvl")
|
||||||
|
|
||||||
local uci = luci.model.uci
|
local uci = require("luci.model.uci")
|
||||||
local class = luci.util.class
|
local class = luci.util.class
|
||||||
local instanceof = luci.util.instanceof
|
local instanceof = luci.util.instanceof
|
||||||
|
|
||||||
|
|
|
@ -672,6 +672,7 @@ end
|
||||||
statusmsg = {
|
statusmsg = {
|
||||||
[200] = "OK",
|
[200] = "OK",
|
||||||
[301] = "Moved Permanently",
|
[301] = "Moved Permanently",
|
||||||
|
[302] = "Found",
|
||||||
[304] = "Not Modified",
|
[304] = "Not Modified",
|
||||||
[400] = "Bad Request",
|
[400] = "Bad Request",
|
||||||
[403] = "Forbidden",
|
[403] = "Forbidden",
|
||||||
|
|
|
@ -17,9 +17,9 @@ vhost = luci.httpd.server.VHost()
|
||||||
|
|
||||||
server:set_default_vhost(vhost)
|
server:set_default_vhost(vhost)
|
||||||
|
|
||||||
if pcall(require, "uci") and pcall(require, "luci.model.uci") then
|
if pcall(require, "uci2") and pcall(require, "luci.model.uci") then
|
||||||
luci.model.uci.cursor = function(config, ...)
|
luci.model.uci.cursor = function(config, save)
|
||||||
return uci.cursor(config or SYSROOT .. "/etc/config", ...)
|
return uci2.cursor(config or SYSROOT .. "/etc/config", save or SYSROOT .. "/tmp/.uci")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -93,9 +93,5 @@ function Luci.handle_get(self, request, sourcein, sinkerr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
headers["Expires"] = luci.http.protocol.date.to_http( os.time() )
|
|
||||||
headers["Date"] = headers["Expires"]
|
|
||||||
headers["Cache-Control"] = "no-cache"
|
|
||||||
|
|
||||||
return Response(status, headers), iter
|
return Response(status, headers), iter
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,7 @@ function init(path)
|
||||||
if (root ~= '/') then
|
if (root ~= '/') then
|
||||||
-- Entering dummy mode
|
-- Entering dummy mode
|
||||||
luci.model.uci.cursor = function(config, ...)
|
luci.model.uci.cursor = function(config, ...)
|
||||||
return uci.cursor(config or root .. "/etc/config", ...)
|
return uci2.cursor(config or root .. "/etc/config", ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
luci.sys.hostname = function() return "" end
|
luci.sys.hostname = function() return "" end
|
||||||
|
|
|
@ -23,7 +23,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
local uci = require "uci"
|
local uci = require "uci2"
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
local table = require "table"
|
local table = require "table"
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ end
|
||||||
function s.parse(self, ...)
|
function s.parse(self, ...)
|
||||||
TypedSection.parse(self, ...)
|
TypedSection.parse(self, ...)
|
||||||
if created then
|
if created then
|
||||||
|
m.uci:save("network")
|
||||||
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "network")
|
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "network")
|
||||||
.. "/" .. created)
|
.. "/" .. created)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue