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 ();
58 string ShibMLP::run (const string& is) const
62 const char* line = is.c_str();
63 const char* lastpos = line;
66 m_priv->log->info("Processing string");
69 // Search for SHIBMLP tags. These are of the form:
71 // Note that there MUST be white-space after "<shibmlp" but
72 // there does not need to be white space between the key and
75 while ((thispos = strstr(lastpos, "<")) != NULL) {
76 // save the string up to this token
77 res += is.substr(lastpos-line, thispos-lastpos);
79 // Make sure this token matches our token.
80 if (strnicmp (thispos, "<shibmlp ", 9)) {
82 lastpos = thispos + 1;
86 // Save this position off.
87 lastpos = thispos + 9; // strlen("<shibmlp ")
89 // search for the end-tag
90 if ((thispos = strstr(lastpos, "/>")) != NULL) {
91 string key = is.substr(lastpos-line, thispos-lastpos);
94 m_priv->log->debug("found key: \"%s\"", key.c_str());
96 map<string,string>::const_iterator i=m_map.find(key);
97 if (i == m_map.end()) {
98 static string s1 = "<!-- Unknown SHIBMLP key: ";
99 static string s2 = "/>";
100 res += s1 + key + s2;
101 m_priv->log->debug("key unknown");
104 m_priv->log->debug("key maps to \"%s\"", i->second.c_str());
107 lastpos = thispos + 2; // strlen("/>")
110 res += is.substr(lastpos-line);
115 string ShibMLP::run (istream& is) const
117 static string eol = "\r\n";
120 m_priv->log->info("processing stream");
122 while (getline(is, line))
128 void ShibMLP::insert (RPCError& e)
130 insert ("errorType", e.getType());
131 insert ("errorText", e.getText());
132 insert ("errorDesc", e.getDesc());
133 insert ("originErrorURL", e.getOriginErrorURL());
134 insert ("originContactName", e.getOriginContactName());
135 insert ("originContactEmail", e.getOriginContactEmail());