X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Futil%2FPathResolver.cpp;h=4ca48ec41b1c56db8c9565f9f529a7d16a2ccdbd;hb=24f6c0a5e8a13de058a15d1404fbbabb852db824;hp=c0f2c1117f6e14494dd43872f681810847d88e67;hpb=bd026f07e729e66127b3efd48aee443fba815af3;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/util/PathResolver.cpp b/xmltooling/util/PathResolver.cpp index c0f2c11..4ca48ec 100644 --- a/xmltooling/util/PathResolver.cpp +++ b/xmltooling/util/PathResolver.cpp @@ -1,17 +1,21 @@ -/* - * Copyright 2001-2009 Internet2 +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. * - * 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 + * UCAID licenses this file to you 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 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** @@ -34,6 +38,7 @@ PathResolver::PathResolver() : m_defaultPackage(PACKAGE_NAME), m_defaultPrefix(" setXMLDir("/usr/share/xml"); setRunDir("/var/run"); setCfgDir("/etc"); + setCacheDir("/var/cache"); } PathResolver::~PathResolver() @@ -75,9 +80,16 @@ void PathResolver::setCfgDir(const char* dir) m_cfg = dir; } +void PathResolver::setCacheDir(const char* dir) +{ + m_cache = dir; +} + bool PathResolver::isAbsolute(const char* s) const { switch (*s) { + case 0: + return false; case '/': case '\\': return true; @@ -89,6 +101,16 @@ bool PathResolver::isAbsolute(const char* s) const const string& PathResolver::resolve(string& s, file_type_t filetype, const char* pkgname, const char* prefix) const { +#ifdef WIN32 + // Check for possible environment variable(s). + if (s.find('%') != string::npos) { + char expbuf[MAX_PATH + 2]; + DWORD cnt = ExpandEnvironmentStrings(s.c_str(), expbuf, sizeof(expbuf)); + if (cnt != 0 && cnt <= sizeof(expbuf)) + s = expbuf; + } +#endif + if (!isAbsolute(s.c_str())) { switch (filetype) { case XMLTOOLING_LIB_FILE: @@ -133,6 +155,16 @@ const string& PathResolver::resolve(string& s, file_type_t filetype, const char* } break; + case XMLTOOLING_CACHE_FILE: + s = m_cache + '/' + (pkgname ? pkgname : m_defaultPackage) + '/' + s; + if (!isAbsolute(m_cache.c_str())) { + if (prefix || m_defaultPrefix != "/usr") + s = string(prefix ? prefix : m_defaultPrefix) + '/' + s; + else + s = string("/") + s; + } + break; + default: throw XMLToolingException("Unknown file type to resolve."); }