luci-base: add hostport and ipaddrport validation types
[project/luci.git] / modules / luci-base / luasrc / cbi / datatypes.lua
index c5f4ec0..52f90af 100644 (file)
@@ -1,17 +1,5 @@
---[[
-
-LuCI - Configuration Bind Interface - Datatype Tests
-(c) 2010 Jo-Philipp Wich <xm@subsignal.org>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-        http://www.apache.org/licenses/LICENSE-2.0
-
-$Id$
-
-]]--
+-- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
+-- Licensed to the public under the Apache License 2.0.
 
 local fs = require "nixio.fs"
 local ip = require "luci.ip"
@@ -196,6 +184,16 @@ function network(val)
        return uciname(val) or host(val)
 end
 
+function hostport(val)
+       local h, p = val:match("^([^:]+):([^:]+)$")
+       return not not (h and p and host(h) and port(p))
+end
+
+function ipaddrport(val)
+       local h, p = val:match("^([^:]+):([^:]+)$")
+       return not not (h and p and ipaddr(h) and port(p))
+end
+
 function wpakey(val)
        if #val == 64 then
                return (val:match("^[a-fA-F0-9]+$") ~= nil)