SSPCPP-616 - clean up concatenated string literals
[shibboleth/cpp-sp.git] / shibsp / handler / impl / DiscoveryFeed.cpp
index 4fee1ef..f0f3514 100644 (file)
@@ -49,6 +49,7 @@ using namespace shibsp;
 #ifndef SHIBSP_LITE
 using namespace opensaml::saml2md;
 using namespace opensaml;
+using namespace boost;
 #endif
 using namespace xmltooling;
 using namespace std;
@@ -94,7 +95,7 @@ namespace shibsp {
         // A queue of feed files, linked to the last time of "access".
         // Each filename is also a cache tag.
         mutable queue< pair<string,time_t> > m_feedQueue;
-        Mutex* m_feedLock;
+        scoped_ptr<Mutex> m_feedLock;
 #endif
     };
 
@@ -110,10 +111,7 @@ namespace shibsp {
 };
 
 DiscoveryFeed::DiscoveryFeed(const DOMElement* e, const char* appId)
-    : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".DiscoveryFeed"), &g_Blocker), m_cacheToClient(false)
-#ifndef SHIBSP_LITE
-    , m_feedLock(nullptr)
-#endif
+    : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT ".DiscoveryFeed"), &g_Blocker), m_cacheToClient(false)
 {
     pair<bool,const char*> prop = getString("Location");
     if (!prop.first)
@@ -129,10 +127,10 @@ DiscoveryFeed::DiscoveryFeed(const DOMElement* e, const char* appId)
         prop = getString("dir");
         if (prop.first)
             m_dir = prop.second;
-        XMLToolingConfig::getConfig().getPathResolver()->resolve(m_dir, PathResolver::XMLTOOLING_RUN_FILE);
+        XMLToolingConfig::getConfig().getPathResolver()->resolve(m_dir, PathResolver::XMLTOOLING_CACHE_FILE);
         m_log.info("feed files will be cached in %s", m_dir.c_str());
 #ifndef SHIBSP_LITE
-        m_feedLock = Mutex::create();
+        m_feedLock.reset(Mutex::create());
 #endif
     }
 }
@@ -145,11 +143,10 @@ DiscoveryFeed::~DiscoveryFeed()
         // Anything left will be orphaned, but that shouldn't happen too often.
         time_t now = time(nullptr);
         while (!m_feedQueue.empty() && now - m_feedQueue.front().second > 120) {
-            string fname = m_dir + '/' + m_feedQueue.front().first;
+            string fname = m_dir + '/' + m_feedQueue.front().first + ".json";
             remove(fname.c_str());
             m_feedQueue.pop();
         }
-        delete m_feedLock;
     }
 #endif
 }
@@ -174,7 +171,7 @@ pair<bool,long> DiscoveryFeed::run(SPRequest& request, bool isHandler) const
                         string etag = '"' + s + '"';
                         request.setResponseHeader("ETag", etag.c_str());
                     }
-                    request.setContentType("application/json");
+                    request.setContentType("application/json; charset=UTF-8");
                     return make_pair(true, request.sendResponse(buf));
                 }
             }
@@ -200,7 +197,7 @@ pair<bool,long> DiscoveryFeed::run(SPRequest& request, bool isHandler) const
                 }
                 if (out["feed"].string()) {
                     istringstream buf(out["feed"].string());
-                    request.setContentType("application/json");
+                    request.setContentType("application/json; charset=UTF-8");
                     return make_pair(true, request.sendResponse(buf));
                 }
                 throw ConfigurationException("Discovery feed was empty.");
@@ -226,10 +223,10 @@ pair<bool,long> DiscoveryFeed::run(SPRequest& request, bool isHandler) const
             string etag = '"' + s + '"';
             request.setResponseHeader("ETag", etag.c_str());
         }
-        request.setContentType("application/json");
+        request.setContentType("application/json; charset=UTF-8");
         return make_pair(true, request.sendResponse(feed));
     }
-    catch (exception& ex) {
+    catch (std::exception& ex) {
         request.log(SPRequest::SPError, string("error while processing request:") + ex.what());
         istringstream msg("Discovery Request Failed");
         return make_pair(true, request.sendResponse(msg, HTTPResponse::XMLTOOLING_HTTP_STATUS_ERROR));
@@ -278,7 +275,7 @@ void DiscoveryFeed::feedToFile(const Application& application, string& cacheTag)
 #ifndef SHIBSP_LITE
     m_log.debug("processing discovery feed request");
 
-    DiscoverableMetadataProvider* m=dynamic_cast<DiscoverableMetadataProvider*>(application.getMetadataProvider(false));
+    DiscoverableMetadataProvider* m = dynamic_cast<DiscoverableMetadataProvider*>(application.getMetadataProvider(false));
     if (!m)
         m_log.warn("MetadataProvider missing or does not support discovery feed");
     Locker locker(m);
@@ -298,7 +295,7 @@ void DiscoveryFeed::feedToFile(const Application& application, string& cacheTag)
 
     // Clean up any old files.
     while (m_feedQueue.size() > 1 && (now - m_feedQueue.front().second > 120)) {
-        string fname = m_dir + '/' + m_feedQueue.front().first;
+        string fname = m_dir + '/' + m_feedQueue.front().first + ".json";
         remove(fname.c_str());
         m_feedQueue.pop();
     }
@@ -331,7 +328,7 @@ void DiscoveryFeed::feedToStream(const Application& application, string& cacheTa
 #ifndef SHIBSP_LITE
     m_log.debug("processing discovery feed request");
 
-    DiscoverableMetadataProvider* m=dynamic_cast<DiscoverableMetadataProvider*>(application.getMetadataProvider(false));
+    DiscoverableMetadataProvider* m = dynamic_cast<DiscoverableMetadataProvider*>(application.getMetadataProvider(false));
     if (!m)
         m_log.warn("MetadataProvider missing or does not support discovery feed");
     Locker locker(m);