diff options
author | Benoit Foucher <benoit@zeroc.com> | 2005-09-01 14:44:08 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2005-09-01 14:44:08 +0000 |
commit | a3fef020a305338363ec933dba834b475510c48e (patch) | |
tree | 7f782b5e3e3823fde01fe7004aaf3560e2fe3b23 /cpp/src/IceGrid/ServerI.cpp | |
parent | IceGrid Windows port. (diff) | |
download | ice-a3fef020a305338363ec933dba834b475510c48e.tar.bz2 ice-a3fef020a305338363ec933dba834b475510c48e.tar.xz ice-a3fef020a305338363ec933dba834b475510c48e.zip |
Added support for env variable substitution (Unix only for now).
Diffstat (limited to 'cpp/src/IceGrid/ServerI.cpp')
-rw-r--r-- | cpp/src/IceGrid/ServerI.cpp | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp index db592fcfe73..4ebac6eb1e4 100644 --- a/cpp/src/IceGrid/ServerI.cpp +++ b/cpp/src/IceGrid/ServerI.cpp @@ -65,6 +65,71 @@ private: const ServerIPtr _server; }; +struct EnvironmentEval : std::unary_function<string, string> +{ + string + operator()(const std::string& value) + { + string::size_type assignment = value.find("="); + if(assignment == string::npos || assignment >= value.size() - 1) + { + return value; + } + + string v = value.substr(assignment + 1); + assert(v.size()); + string::size_type beg = 0; + string::size_type end; +#ifdef _WIN32 +// char buf[32767]; +// while((beg = v.find("%", beg)) != string::npos && beg < v.size() - 1) +// { +// end = v.find("%"); +// if(end == string::npos) +// { +// return v; +// } +// string variable = v.substr(beg + 2, end - beg - 2); +// int ret = GetEnvironmentVariable(variable.c_str(), buf, sizeof(buf)); +// string valstr = ret > 0 ? string(buf) : ""; +// v.replace(beg, end - beg + 1, valstr); +// beg += strlen(value); +// } + return value; +#else + while((beg = v.find("$", beg)) != string::npos && beg < v.size() - 1) + { + string variable; + if(v[beg + 1] == '{') + { + end = v.find("}"); + if(end == string::npos) + { + return v; + } + variable = v.substr(beg + 2, end - beg - 2); + } + else + { + end = beg + 1; + while((isalnum(v[end]) || v[end] == '_') && end < v.size()) + { + ++end; + } + variable = v.substr(beg + 1, end - beg - 1); + --end; + } + + char* val = getenv(variable.c_str()); + string valstr = val ? string(val) : ""; + v.replace(beg, end - beg + 1, valstr); + beg += valstr.size(); + } +#endif + return value.substr(0, assignment) + "=" + v; + } +}; + } ServerI::ServerI(const NodeIPtr& node, const ServerPrx& proxy, const string& serversDir, const string& id, int wt) : @@ -479,7 +544,7 @@ ServerI::startInternal(ServerActivation act, const AMD_Server_startPtr& amdCB) options.push_back("--Ice.Config=" + _serverDir + "/config/config"); Ice::StringSeq envs; - copy(desc->envs.begin(), desc->envs.end(), back_inserter(envs)); + transform(desc->envs.begin(), desc->envs.end(), back_inserter(envs), EnvironmentEval()); string pwd = desc->pwd; if(pwd.empty()) |