From 3013a9dfbf0c8c980dd59183c38a702e8179ee13 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 21 Oct 2017 22:48:29 +0100 Subject: [PATCH] Inherit non-core connect class settings properly. Based partially on a patch by Attila. --- src/users.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/users.cpp b/src/users.cpp index c2ff9c5be..ead862b7d 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -1188,7 +1188,32 @@ ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask, cons Update(&parent); name = "unnamed"; type = t; - config = tag; + host = mask; + + // Connect classes can inherit from each other but this is problematic for modules which can't use + // ConnectClass::Update so we build a hybrid tag containing all of the values set on this class as + // well as the parent class. + ConfigItems* items = NULL; + config = ConfigTag::create(tag->tag, tag->src_name, tag->src_line, items); + + const ConfigItems& parentkeys = parent.config->getItems(); + for (ConfigItems::const_iterator piter = parentkeys.begin(); piter != parentkeys.end(); ++piter) + { + // The class name and parent name are not inherited + if (piter->first == "name" || piter->first == "parent") + continue; + + // Store the item in the config tag. If this item also + // exists in the child it will be overwritten. + (*items)[piter->first] = piter->second; + } + + const ConfigItems& childkeys = tag->getItems(); + for (ConfigItems::const_iterator citer = childkeys.begin(); citer != childkeys.end(); ++citer) + { + // This will overwrite the parent value if present. + (*items)[citer->first] = citer->second; + } } void ConnectClass::Update(const ConnectClass* src) -- 2.39.2