void refresh(void);
- const std::string& get (const std::string& header, const std::string& tag) const;
- const std::string& get (const char* header, const char* tag) const {
+ const std::string& get (const std::string& header, const std::string& tag);
+ const std::string& get (const char* header, const char* tag) {
std::string h = header, t = tag;
return get(h,t);
}
- const std::string& operator() (const std::string& header, const std::string& tag) const {
+ const std::string& operator() (const std::string& header, const std::string& tag) {
return get(header,tag);
}
- const std::string& operator() (const char* header, const char* tag) const {
+ const std::string& operator() (const char* header, const char* tag) {
std::string h = header, t = tag;
return get(h,t);
}
- bool exists(const std::string& header) const;
- bool exists(const std::string& header, const std::string& tag) const;
+ bool exists(const std::string& header);
+ bool exists(const std::string& header, const std::string& tag);
- bool exists(const char* header) const {
+ bool exists(const char* header) {
std::string s = header;
return exists(s);
}
- bool exists(const char* header, const char* tag) const {
+ bool exists(const char* header, const char* tag) {
std::string h = header, t = tag;
return exists(h,t);
}
// Special method to look for a tag in one header and maybe in the
// 'SHIBTARGET_GENERAL' header
bool get_tag(std::string& header, std::string& tag, bool try_general,
- std::string* result) const;
+ std::string* result);
bool get_tag(std::string& header, const char* tag, bool try_general,
- std::string* result) const {
+ std::string* result) {
std::string t = tag;
return get_tag (header,t,try_general,result);
}
bool get_tag(const char* header, const char* tag, bool try_general,
- std::string* result) const {
+ std::string* result) {
std::string h = header, t = tag;
return get_tag (h,t,try_general,result);
}
// Dump out the inifile to the output stream
- void dump(std::ostream& os) const;
+ void dump(std::ostream& os);
// Iterators
virtual const std::string* next() = 0;
};
- Iterator* header_iterator() const;
- Iterator* tag_iterator(const std::string& header) const;
+ Iterator* header_iterator();
+ Iterator* tag_iterator(const std::string& header);
private:
ShibINIPriv *m_priv;
#include <fstream>
#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
#include <log4cpp/Category.hh>
using namespace std;
map<string, map<string, string> > table;
string file;
bool cs;
+
+ unsigned long modtime;
};
ShibINIPriv::ShibINIPriv()
void ShibINI::refresh(void)
{
+ saml::NDC ndc("refresh");
+
+ // check if we need to refresh
+#ifdef _WIN32
+ struct _stat stat_buf;
+ if (_stat (m_priv->file.c_str(), &stat_buf) < 0)
+#else
+ struct stat stat_buf;
+ if (stat (m_priv->file.c_str(), &stat_buf) < 0)
+#endif
+ m_priv->log->error("stat failed: %s", m_priv->file.c_str());
+
+ if (m_priv->modtime == stat_buf.st_mtime)
+ return;
+
+ m_priv->modtime = stat_buf.st_mtime;
+
// clear the existing maps
m_priv->table.clear();
}
}
-const std::string& ShibINI::get (const string& header, const string& tag) const
+const std::string& ShibINI::get (const string& header, const string& tag)
{
+ refresh();
+
static string empty = "";
string h = header;
return i->second;
}
-bool ShibINI::exists(const std::string& header) const
+bool ShibINI::exists(const std::string& header)
{
+ refresh();
+
string h = header;
if (!m_priv->cs) to_lowercase (h);
return (m_priv->table.find(h) != m_priv->table.end());
}
-bool ShibINI::exists(const std::string& header, const std::string& tag) const
+bool ShibINI::exists(const std::string& header, const std::string& tag)
{
+ refresh();
+
string h = header;
string t = tag;
return (m_priv->table[h].find(t) != m_priv->table[h].end());
}
-bool ShibINI::get_tag (string& header, string& tag, bool try_general, string* result) const
+bool ShibINI::get_tag (string& header, string& tag, bool try_general, string* result)
{
if (!result) return false;
+ refresh();
+
if (exists (header, tag)) {
*result = get (header, tag);
return true;
}
-void ShibINI::dump (ostream& os) const
+void ShibINI::dump (ostream& os)
{
+ refresh();
+
os << "File: " << m_priv->file << "\n";
os << "Case-Sensitive: " << ( m_priv->cs ? "Yes\n" : "No\n" );
os << "File Entries:\n";
os << "END\n";
}
-ShibINI::Iterator* ShibINI::header_iterator() const
+ShibINI::Iterator* ShibINI::header_iterator()
{
+ refresh();
HeaderIterator* iter = new HeaderIterator(m_priv);
return (ShibINI::Iterator*) iter;
}
-ShibINI::Iterator* ShibINI::tag_iterator(const std::string& header) const
+ShibINI::Iterator* ShibINI::tag_iterator(const std::string& header)
{
+ refresh();
TagIterator* iter = new TagIterator(m_priv, header);
return (ShibINI::Iterator*) iter;
}