X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Futil%2FPathResolver.cpp;h=f6e3ec70b8c52152ba9474194b7e34a3de46b24c;hb=4fd97a9fce699269ef44adf0ff64985742cd8d10;hp=95a1eeabffb7e683786c95de5f142c625a5ddc9a;hpb=3df97d0f7aec907ff3726e36bf65c4ccbfc3cfd5;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/util/PathResolver.cpp b/xmltooling/util/PathResolver.cpp index 95a1eea..f6e3ec7 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,6 +80,11 @@ 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) { @@ -91,6 +101,20 @@ 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) { + // This is an ugly workaround for Windows XP, which doesn't support the APPDATA variable. + if (!getenv("APPDATA") && s.find("%APPDATA%") != string::npos) { + s.replace(s.find("%APPDATA%"), 9, "%ALLUSERSPROFILE%\\Application Data"); + } + 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: @@ -135,6 +159,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."); }