Skip to content

Commit

Permalink
Merge branch '6.1' into 6.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	loader/build.xml
#	loader/pom.xml
  • Loading branch information
michaeloffner committed Jul 25, 2024
2 parents f3999c0 + 803a8c3 commit c845f85
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 98 deletions.
95 changes: 28 additions & 67 deletions core/src/main/java/lucee/runtime/config/ConfigAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1462,25 +1462,25 @@ else if (access >= SecurityManager.VALUE_1 && access <= SecurityManager.VALUE_10
if (!StringUtil.isEmpty(id)) el.setEL(KeyConstants._id, id);
else if (el.containsKey(KeyConstants._id)) el.removeEL(KeyConstants._id);

el.setEL("dsn", dsn);
el.setEL("username", username);
el.setEL("password", ConfigWebUtil.encrypt(password));
el.setEL(KeyConstants._dsn, dsn);
el.setEL(KeyConstants._username, username);
el.setEL(KeyConstants._password, ConfigWebUtil.encrypt(password));

el.setEL("host", host);
el.setEL(KeyConstants._host, host);
if (!StringUtil.isEmpty(timezone)) el.setEL(KeyConstants._timezone, timezone);
else if (el.containsKey(KeyConstants._timezone)) el.removeEL(KeyConstants._timezone);
el.setEL("database", database);
el.setEL("port", Caster.toString(port));
el.setEL("connectionLimit", Caster.toString(connectionLimit));
el.setEL("connectionTimeout", Caster.toString(idleTimeout));
el.setEL("liveTimeout", Caster.toString(liveTimeout));
el.setEL("metaCacheTimeout", Caster.toString(metaCacheTimeout));
el.setEL("blob", Caster.toString(blob));
el.setEL("clob", Caster.toString(clob));
el.setEL("allow", Caster.toString(allow));
el.setEL("validate", Caster.toString(validate));
el.setEL("storage", Caster.toString(storage));
el.setEL("custom", toStringURLStyle(custom));
el.setEL(KeyConstants._database, database);
el.setEL(KeyConstants._port, Caster.toString(port));
el.setEL(KeyConstants._connectionLimit, Caster.toString(connectionLimit));
el.setEL(KeyConstants._connectionTimeout, Caster.toString(idleTimeout));
el.setEL(KeyConstants._liveTimeout, Caster.toString(liveTimeout));
el.setEL(KeyConstants._metaCacheTimeout, Caster.toString(metaCacheTimeout));
el.setEL(KeyConstants._blob, Caster.toString(blob));
el.setEL(KeyConstants._clob, Caster.toString(clob));
el.setEL(KeyConstants._allow, Caster.toString(allow));
el.setEL(KeyConstants._validate, Caster.toString(validate));
el.setEL(KeyConstants._storage, Caster.toString(storage));
el.setEL(KeyConstants._custom, custom);

if (!StringUtil.isEmpty(dbdriver)) el.setEL("dbdriver", Caster.toString(dbdriver));

Expand Down Expand Up @@ -1540,7 +1540,7 @@ else if (access >= SecurityManager.VALUE_1 && access <= SecurityManager.VALUE_10
el.setEL("validate", Caster.toString(validate));
el.setEL("storage", Caster.toString(storage));
if (allow > -1) el.setEL("allow", Caster.toString(allow));
el.setEL("custom", toStringURLStyle(custom));
el.setEL("custom", custom);

if (!StringUtil.isEmpty(dbdriver)) el.setEL("dbdriver", Caster.toString(dbdriver));

Expand Down Expand Up @@ -1813,7 +1813,7 @@ void _updateGatewayEntry(String id, ClassDefinition cd, String componentPath, St
el.setEL("cfcPath", componentPath);
el.setEL("listenerCFCPath", listenerCfcPath);
el.setEL("startupMode", GatewayEntryImpl.toStartup(startupMode, "automatic"));
el.setEL("custom", toStringURLStyle(custom));
el.setEL("custom", custom);
el.setEL("readOnly", Caster.toString(readOnly));
return;
}
Expand All @@ -1826,7 +1826,7 @@ void _updateGatewayEntry(String id, ClassDefinition cd, String componentPath, St
el.setEL("listenerCFCPath", listenerCfcPath);
el.setEL("startupMode", GatewayEntryImpl.toStartup(startupMode, "automatic"));
setClass(el, null, "", cd);
el.setEL("custom", toStringURLStyle(custom));
el.setEL("custom", custom);
el.setEL("readOnly", Caster.toString(readOnly));
}

Expand Down Expand Up @@ -1976,7 +1976,7 @@ else if (_default == ConfigPro.CACHE_TYPE_WEBSERVICE) {
if (key.getString().equalsIgnoreCase(name)) {
Struct el = Caster.toStruct(conns.get(key, null), null);
setClass(el, null, "", cd);
el.setEL("custom", toStringURLStyle(custom));
el.setEL("custom", custom);
el.setEL("readOnly", Caster.toString(readOnly));
el.setEL("storage", Caster.toString(storage));
return;
Expand All @@ -1987,7 +1987,7 @@ else if (_default == ConfigPro.CACHE_TYPE_WEBSERVICE) {
Struct data = new StructImpl(Struct.TYPE_LINKED);
conns.setEL(name, data);
setClass(data, null, "", cd);
data.setEL("custom", toStringURLStyle(custom));
data.setEL("custom", custom);
data.setEL("readOnly", Caster.toString(readOnly));
data.setEL("storage", Caster.toString(storage));

Expand Down Expand Up @@ -2100,14 +2100,6 @@ public void _removeResourceProvider(String scheme) {
}

public void updateResourceProvider(String scheme, ClassDefinition cd, Struct arguments) throws PageException {
updateResourceProvider(scheme, cd, toStringCSSStyle(arguments));
}

public void _updateResourceProvider(String scheme, ClassDefinition cd, Struct arguments) throws PageException {
_updateResourceProvider(scheme, cd, toStringCSSStyle(arguments));
}

public void updateResourceProvider(String scheme, ClassDefinition cd, String arguments) throws PageException {
checkWriteAccess();
SecurityManager sm = config.getSecurityManager();
short access = sm.getAccess(SecurityManager.TYPE_FILE);
Expand All @@ -2117,7 +2109,7 @@ public void updateResourceProvider(String scheme, ClassDefinition cd, String arg
_updateResourceProvider(scheme, cd, arguments);
}

public void _updateResourceProvider(String scheme, ClassDefinition cd, String arguments) throws PageException {
public void _updateResourceProvider(String scheme, ClassDefinition cd, Struct arguments) throws PageException {

// check parameters
if (StringUtil.isEmpty(scheme)) throw new ExpressionException("scheme can't be an empty value");
Expand Down Expand Up @@ -2183,37 +2175,6 @@ private int getDatasourceLength(ConfigPro config) {
return len;
}

private static String toStringURLStyle(Struct sct) {
if (sct == null) return "";
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
StringBuilder rtn = new StringBuilder();
while (it.hasNext()) {
e = it.next();
if (rtn.length() > 0) rtn.append('&');
rtn.append(URLEncoder.encode(e.getKey().getString()));
rtn.append('=');
rtn.append(URLEncoder.encode(Caster.toString(e.getValue(), "")));
}
return rtn.toString();
}

private static String toStringCSSStyle(Struct sct) {
// Collection.Key[] keys = sct.keys();
StringBuilder rtn = new StringBuilder();
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;

while (it.hasNext()) {
e = it.next();
if (rtn.length() > 0) rtn.append(';');
rtn.append(encode(e.getKey().getString()));
rtn.append(':');
rtn.append(encode(Caster.toString(e.getValue(), "")));
}
return rtn.toString();
}

private static String encode(String str) {
try {
return URLEncodedFormat.invoke(str, "UTF-8", false);
Expand Down Expand Up @@ -4305,7 +4266,7 @@ private void _updateCacheHandler(String id, ClassDefinition cd) throws PageExcep
public void updateExecutionLog(ClassDefinition cd, Struct args, boolean enabled) throws PageException {
Struct el = _getRootElement("executionLog");
setClass(el, null, "", cd);
el.setEL("arguments", toStringCSSStyle(args));
el.setEL("arguments", args);
el.setEL("enabled", Caster.toString(enabled));
}

Expand Down Expand Up @@ -5614,7 +5575,7 @@ public void updateRemoteClientUsage(String code, String displayname) {
usage.setEL(code, displayname);

Struct extensions = _getRootElement("remoteClients");
extensions.setEL("usage", toStringURLStyle(usage));
extensions.setEL("usage", usage);

}

Expand All @@ -5630,7 +5591,7 @@ public void removeRemoteClientUsage(String code) {
usage.removeEL(KeyImpl.init(code));

Struct extensions = _getRootElement("remoteClients");
extensions.setEL("usage", toStringURLStyle(usage));
extensions.setEL("usage", usage);

}

Expand Down Expand Up @@ -5760,7 +5721,7 @@ public void updateDebugEntry(String type, String iprange, String label, String p
el.setEL("label", label);
el.setEL("path", path);
el.setEL("fullname", fullname);
el.setEL("custom", toStringURLStyle(custom));
el.setEL("custom", custom);
}

public void removeDebugEntry(String id) throws SecurityException {
Expand Down Expand Up @@ -5833,9 +5794,9 @@ public void updateLogSettings(String name, int level, ClassDefinition appenderCD

el.setEL("level", LogUtil.levelToString(level, ""));
setClass(el, null, "appender", appenderCD);
el.setEL("appenderArguments", toStringCSSStyle(appenderArgs));
el.setEL("appenderArguments", appenderArgs);
setClass(el, null, "layout", layoutCD);
el.setEL("layoutArguments", toStringCSSStyle(layoutArgs));
el.setEL("layoutArguments", layoutArgs);

if (el.containsKey("appender")) rem(el, "appender");
if (el.containsKey("layout")) rem(el, "layout");
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/config/ConfigFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ else if (old instanceof InputSource) {
else {
new ConverterException("inputing data is invalid, cannot cast [" + old.getClass().getName() + "] to a Resource or an InputSource");
}
Struct root = ConfigWebUtil.getAsStruct(reader.getData(), "cfLuceeConfiguration", "luceeConfiguration", "lucee-configuration");
Struct root = ConfigWebUtil.getAsStruct(reader.getData(), false, "cfLuceeConfiguration", "luceeConfiguration", "lucee-configuration");

//////////////////// charset ////////////////////
{
Expand Down Expand Up @@ -947,7 +947,7 @@ private static Struct _loadDocument(Resource res) throws IOException, PageExcept
// That step is not necessary anymore TODO remove
if (StringUtil.endsWithIgnoreCase(name, ".xml.cfm") || StringUtil.endsWithIgnoreCase(name, ".xml")) {
try {
return ConfigWebUtil.getAsStruct(new XMLConfigReader(res, true, new ReadRule(), new NameRule()).getData(), "cfLuceeConfiguration", "luceeConfiguration",
return ConfigWebUtil.getAsStruct(new XMLConfigReader(res, true, new ReadRule(), new NameRule()).getData(), false, "cfLuceeConfiguration", "luceeConfiguration",
"lucee-configuration");
}
catch (SAXException e) {
Expand Down
33 changes: 5 additions & 28 deletions core/src/main/java/lucee/runtime/config/ConfigWebFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
import lucee.runtime.tag.listener.TagListener;
import lucee.runtime.type.Array;
import lucee.runtime.type.Collection.Key;
import lucee.runtime.type.KeyImpl;
import lucee.runtime.type.Struct;
import lucee.runtime.type.StructImpl;
import lucee.runtime.type.UDF;
Expand Down Expand Up @@ -2419,7 +2418,7 @@ else if (!cd.isBundle()) {
Caster.toLongValue(getAttr(dataSource, "metaCacheTimeout"), 60000), toBoolean(getAttr(dataSource, "blob"), true),
toBoolean(getAttr(dataSource, "clob"), true), Caster.toIntValue(getAttr(dataSource, "allow"), DataSource.ALLOW_ALL),
toBoolean(getAttr(dataSource, "validate"), false), toBoolean(getAttr(dataSource, "storage"), false), getAttr(dataSource, "timezone"),
toStruct(getAttr(dataSource, "custom")), getAttr(dataSource, "dbdriver"), ParamSyntax.toParamSyntax(dataSource, ParamSyntax.DEFAULT),
ConfigWebUtil.getAsStruct(dataSource, true, "custom"), getAttr(dataSource, "dbdriver"), ParamSyntax.toParamSyntax(dataSource, ParamSyntax.DEFAULT),
toBoolean(getAttr(dataSource, "literalTimestampWithTSOffset"), false), toBoolean(getAttr(dataSource, "alwaysSetTimeout"), false),
toBoolean(getAttr(dataSource, "requestExclusive"), false), toBoolean(getAttr(dataSource, "alwaysResetConnections"), false)

Expand Down Expand Up @@ -2673,7 +2672,7 @@ else if (hasCS) {
}

{
Struct custom = toStruct(getAttr(data, "custom"));
Struct custom = ConfigWebUtil.getAsStruct(data, true, "custom");

// Workaround for old EHCache class definitions
if (cd.getClassName() != null && cd.getClassName().endsWith(".EHCacheLite")) {
Expand Down Expand Up @@ -2841,7 +2840,7 @@ private static void _loadGateway(ConfigServerImpl configServer, final ConfigImpl
id = e.getKey().getLowerString();

ge = new GatewayEntryImpl(id, getClassDefinition(eConnection, "", config.getIdentification()), getAttr(eConnection, "cfcPath"),
getAttr(eConnection, "listenerCFCPath"), getAttr(eConnection, "startupMode"), toStruct(getAttr(eConnection, "custom")),
getAttr(eConnection, "listenerCFCPath"), getAttr(eConnection, "startupMode"), ConfigWebUtil.getAsStruct(eConnection, true, "custom"),
Caster.toBooleanValue(getAttr(eConnection, "readOnly"), false));

if (!StringUtil.isEmpty(id)) {
Expand Down Expand Up @@ -2870,25 +2869,6 @@ else if (hasCS) {
}
}

private static Struct toStruct(String str) {

Struct sct = new StructImpl(StructImpl.TYPE_LINKED);
try {
String[] arr = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(str, '&'));

String[] item;
for (int i = 0; i < arr.length; i++) {
item = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(arr[i], '='));
if (item.length == 2) sct.setEL(KeyImpl.init(URLDecoder.decode(item[0], true).trim()), URLDecoder.decode(item[1], true));
else if (item.length == 1) sct.setEL(KeyImpl.init(URLDecoder.decode(item[0], true).trim()), "");
}
}
catch (PageException ee) {
}

return sct;
}

private static void setDatasource(ConfigImpl config, Map<String, DataSource> datasources, String datasourceName, ClassDefinition cd, String server, String databasename,
int port, String dsn, String user, String pass, TagListener listener, int connectionLimit, int idleTimeout, int liveTimeout, int minIdle, int maxIdle, int maxTotal,
long metaCacheTimeout, boolean blob, boolean clob, int allow, boolean validate, boolean storage, String timezone, Struct custom, String dbdriver, ParamSyntax ps,
Expand Down Expand Up @@ -3695,10 +3675,7 @@ private static void _loadRemoteClient(ConfigServerImpl configServer, ConfigImpl
Struct _clients = ConfigWebUtil.getAsStruct("remoteClients", root);

// usage
String strUsage = getAttr(_clients, "usage");
Struct sct;
if (!StringUtil.isEmpty(strUsage)) sct = toStruct(strUsage);// config.setRemoteClientUsage(toStruct(strUsage));
else sct = new StructImpl();
Struct sct = ConfigWebUtil.getAsStruct(_clients, true, "usage");// config.setRemoteClientUsage(toStruct(strUsage));
// TODO make this generic
if (configServer != null) {
String sync = Caster.toString(configServer.getRemoteClientUsage().get("synchronisation", ""), "");
Expand Down Expand Up @@ -4732,7 +4709,7 @@ private static void _loadDebug(ConfigServerImpl configServer, ConfigImpl config,
if (e == null) continue;
id = getAttr(e, "id");
list.put(id, new DebugEntry(id, getAttr(e, "type"), getAttr(e, "iprange"), getAttr(e, "label"), getAttr(e, "path"), getAttr(e, "fullname"),
toStruct(getAttr(e, "custom"))));
ConfigWebUtil.getAsStruct(e, true, "custom")));
}
catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
Expand Down
36 changes: 35 additions & 1 deletion core/src/main/java/lucee/runtime/config/ConfigWebUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import lucee.commons.io.res.util.ResourceUtil;
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.StringUtil;
import lucee.commons.net.URLDecoder;
import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
import lucee.runtime.Mapping;
Expand Down Expand Up @@ -80,6 +81,7 @@
import lucee.runtime.type.Struct;
import lucee.runtime.type.StructImpl;
import lucee.runtime.type.util.ArrayUtil;
import lucee.runtime.type.util.ListUtil;
import lucee.transformer.library.function.FunctionLib;
import lucee.transformer.library.tag.TagLib;

Expand Down Expand Up @@ -827,8 +829,10 @@ public static Array getAsArray(String parent, String child, Struct sct) {
return getAsArray(child, getAsStruct(parent, sct));
}

public static Struct getAsStruct(Struct input, String... names) {
public static Struct getAsStruct(Struct input, boolean allowCSSString, String... names) {
Struct sct = null;
if (input == null) return sct;

Object obj;
for (String name: names) {
obj = input.get(name, null);
Expand All @@ -837,6 +841,17 @@ public static Struct getAsStruct(Struct input, String... names) {
}
}

if (allowCSSString && sct == null) {
for (String name: names) {
obj = input.get(name, null);
if (obj instanceof CharSequence && !StringUtil.isEmpty(obj.toString(), true)) {
sct = toStruct(obj.toString().trim());
if (!sct.isEmpty()) break;
}
}

}

if (sct == null) {
sct = new StructImpl(Struct.TYPE_LINKED);
input.put(names[0], sct);
Expand All @@ -845,6 +860,25 @@ public static Struct getAsStruct(Struct input, String... names) {
return sct;
}

public static Struct toStruct(String str) {

Struct sct = new StructImpl(StructImpl.TYPE_LINKED);
try {
String[] arr = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(str, '&'));

String[] item;
for (int i = 0; i < arr.length; i++) {
item = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(arr[i], '='));
if (item.length == 2) sct.setEL(KeyImpl.init(URLDecoder.decode(item[0], true).trim()), URLDecoder.decode(item[1], true));
else if (item.length == 1) sct.setEL(KeyImpl.init(URLDecoder.decode(item[0], true).trim()), "");
}
}
catch (PageException ee) {
}

return sct;
}

// TODO
/**
* @deprecated use instead getAsStruct(Struct input, String... names)
Expand Down

0 comments on commit c845f85

Please sign in to comment.