shutdown();
}
- void init() {
- try {
- if (!m_id.empty()) {
- string threadid("[");
- threadid += m_id + ']';
- logging::NDC::push(threadid);
- }
- background_load();
- startup();
- }
- catch (...) {
- startup();
- if (!m_id.empty()) {
- logging::NDC::pop();
- }
- throw;
- }
-
- if (!m_id.empty()) {
- logging::NDC::pop();
- }
- }
+ void init();
const char* getId() const {
return m_id.c_str();
}
- void outputStatus(ostream& os) const {
- os << "<MetadataProvider";
-
- if (getId() && *getId()) {
- os << " id='" << getId() << "'";
- }
-
- if (!m_source.empty()) {
- os << " source='" << m_source << "'";
- }
-
- if (m_lastUpdate > 0) {
- DateTime ts(m_lastUpdate);
- ts.parseDateTime();
- auto_ptr_char timestamp(ts.getFormattedString());
- os << " lastUpdate='" << timestamp.get() << "'";
- }
-
- if (!m_local && m_reloadInterval > 0) {
- os << " reloadInterval='" << m_reloadInterval << "'";
- }
-
- os << "/>";
- }
+ void outputStatus(ostream& os) const;
const XMLObject* getMetadata() const {
return m_object.get();
static const XMLCh dropDOM[] = UNICODE_LITERAL_7(d,r,o,p,D,O,M);
static const XMLCh minRefreshDelay[] = UNICODE_LITERAL_15(m,i,n,R,e,f,r,e,s,h,D,e,l,a,y);
static const XMLCh refreshDelayFactor[] = UNICODE_LITERAL_18(r,e,f,r,e,s,h,D,e,l,a,y,F,a,c,t,o,r);
+
+ // TODO: need to move this into xmltooling as a utility function
+ static void xml_encode(ostream& os, const char* start)
+ {
+ size_t pos;
+ while (start && *start) {
+ pos = strcspn(start, "\"<>&");
+ if (pos > 0) {
+ os.write(start,pos);
+ start += pos;
+ }
+ else {
+ switch (*start) {
+ case '"': os << """; break;
+ case '<': os << "<"; break;
+ case '>': os << ">"; break;
+ case '&': os << "&"; break;
+ default: os << *start;
+ }
+ start++;
+ }
+ }
+ }
};
};
XMLMetadataProvider::XMLMetadataProvider(const DOMElement* e)
: MetadataProvider(e), AbstractMetadataProvider(e), DiscoverableMetadataProvider(e),
- ReloadableXMLFile(e, Category::getInstance(SAML_LOGCAT".MetadataProvider.XML"), false),
+ ReloadableXMLFile(e, Category::getInstance(SAML_LOGCAT ".MetadataProvider.XML"), false),
m_discoveryFeed(XMLHelper::getAttrBool(e, true, discoveryFeed)),
m_dropDOM(XMLHelper::getAttrBool(e, true, dropDOM)),
m_refreshDelayFactor(0.75), m_backoffFactor(1),
}
}
+void XMLMetadataProvider::init()
+{
+ try {
+ if (!m_id.empty()) {
+ string threadid("[");
+ threadid += m_id + ']';
+ logging::NDC::push(threadid);
+ }
+ background_load();
+ startup();
+ }
+ catch (...) {
+ startup();
+ if (!m_id.empty()) {
+ logging::NDC::pop();
+ }
+ throw;
+ }
+
+ if (!m_id.empty()) {
+ logging::NDC::pop();
+ }
+}
+
pair<bool,DOMElement*> XMLMetadataProvider::load(bool backup)
{
if (!backup) {
SchemaValidators.validate(xmlObject.get());
}
catch (std::exception& ex) {
- m_log.error("metadata intance failed manual validation checking: %s", ex.what());
+ m_log.error("metadata instance failed manual validation checking: %s", ex.what());
throw MetadataException("Metadata instance failed manual validation checking.");
}
return load(true);
throw;
}
- catch (std::exception&) {
+ catch (std::exception& ex) {
if (!m_local) {
m_reloadInterval = m_minRefreshDelay * m_backoffFactor++;
if (m_reloadInterval > m_maxRefreshDelay)
m_reloadInterval = m_maxRefreshDelay;
m_log.warn("adjusted reload interval to %u seconds", m_reloadInterval);
- if (!m_loaded && !m_backing.empty())
+ if (!m_loaded && !m_backing.empty()) {
+ m_log.warn("trying backup file, exception loading remote resource: %s", ex.what());
return load(true);
+ }
}
throw;
}
}
indexEntity(dynamic_cast<EntityDescriptor*>(m_object.get()), validUntil);
}
+
+void XMLMetadataProvider::outputStatus(ostream& os) const
+{
+ os << "<MetadataProvider";
+
+ if (getId() && *getId()) {
+ os << " id='"; xml_encode(os, getId()); os << "'";
+ }
+
+ if (!m_source.empty()) {
+ os << " source='"; xml_encode(os, m_source.c_str()); os << "'";
+ }
+
+ if (m_lastUpdate > 0) {
+ DateTime ts(m_lastUpdate);
+ ts.parseDateTime();
+ auto_ptr_char timestamp(ts.getFormattedString());
+ os << " lastUpdate='" << timestamp.get() << "'";
+ }
+
+ if (!m_local && m_reloadInterval > 0) {
+ os << " reloadInterval='" << m_reloadInterval << "'";
+ }
+
+ os << "/>";
+}