2 * shib-mlp.cpp -- The ShibTarget Markup Language processor
4 * Created by: Derek Atkins <derek@ihtfp.com>
9 #include "shib-target.h"
12 #include <xercesc/util/XercesDefs.hpp>
14 #include <log4cpp/Category.hh>
17 using namespace shibtarget;
20 class shibtarget::ShibMLPPriv {
24 log4cpp::Category *log;
27 ShibMLPPriv::ShibMLPPriv()
29 string ctx = "shibtarget.ShibMLP";
30 log = &(log4cpp::Category::getInstance(ctx));
34 static void trimspace (string& s)
36 int end = s.size() - 1, start = 0;
38 // Trim stuff on right.
39 while (end > 0 && !isgraph(s[end])) end--;
41 // Trim stuff on left.
42 while (start < end && !isgraph(s[start])) start++;
45 s = s.substr(start, end - start + 1);
50 m_priv = new ShibMLPPriv ();
53 time_t now = time(NULL);
54 string now_s = ctime(&now);
55 insert ("now", now_s);
63 string ShibMLP::run (const string& is) const
67 const char* line = is.c_str();
68 const char* lastpos = line;
71 m_priv->log->info("Processing string");
74 // Search for SHIBMLP tags. These are of the form:
76 // Note that there MUST be white-space after "<shibmlp" but
77 // there does not need to be white space between the key and
80 while ((thispos = strstr(lastpos, "<")) != NULL) {
81 // save the string up to this token
82 res += is.substr(lastpos-line, thispos-lastpos);
84 // Make sure this token matches our token.
85 if (strnicmp (thispos, "<shibmlp ", 9)) {
87 lastpos = thispos + 1;
91 // Save this position off.
92 lastpos = thispos + 9; // strlen("<shibmlp ")
94 // search for the end-tag
95 if ((thispos = strstr(lastpos, "/>")) != NULL) {
96 string key = is.substr(lastpos-line, thispos-lastpos);
99 m_priv->log->debug("found key: \"%s\"", key.c_str());
101 map<string,string>::const_iterator i=m_map.find(key);
102 if (i == m_map.end()) {
103 static string s1 = "<!-- Unknown SHIBMLP key: ";
104 static string s2 = "/>";
105 res += s1 + key + s2;
106 m_priv->log->debug("key unknown");
109 m_priv->log->debug("key maps to \"%s\"", i->second.c_str());
112 lastpos = thispos + 2; // strlen("/>")
115 res += is.substr(lastpos-line);
120 string ShibMLP::run (istream& is) const
122 static string eol = "\r\n";
125 m_priv->log->info("processing stream");
127 while (getline(is, line))
133 void ShibMLP::insert (RPCError& e)
135 insert ("errorType", e.getType());
136 insert ("errorText", e.getText());
137 insert ("errorDesc", e.getDesc());
138 insert ("originErrorURL", e.getOriginErrorURL());
139 insert ("originContactName", e.getOriginContactName());
140 insert ("originContactEmail", e.getOriginContactEmail());
143 void ShibMLP::insert (const std::string& key, const std::string& value)
145 saml::NDC ndc("insert");
146 m_priv->log->debug("inserting %s -> %s", key.c_str(), value.c_str());