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;
19 class shibtarget::ShibMLPPriv {
23 log4cpp::Category *log;
26 ShibMLPPriv::ShibMLPPriv()
28 string ctx = "shibtarget.ShibMLP";
29 log = &(log4cpp::Category::getInstance(ctx));
33 static void trimspace (string& s)
35 int end = s.size() - 1, start = 0;
37 // Trim stuff on right.
38 while (end > 0 && !isgraph(s[end])) end--;
40 // Trim stuff on left.
41 while (start < end && !isgraph(s[start])) start++;
44 s = s.substr(start, end - start + 1);
49 m_priv = new ShibMLPPriv ();
57 string ShibMLP::run (const string& is) const
61 const char* line = is.c_str();
62 const char* lastpos = line;
65 m_priv->log->info("Processing string");
68 // Search for SHIBMLP tags. These are of the form:
70 // Note that there MUST be white-space after "<shibmlp" but
71 // there does not need to be white space between the key and
74 while ((thispos = strstr(lastpos, "<")) != NULL) {
75 // save the string up to this token
76 res += is.substr(lastpos-line, thispos-lastpos);
78 // Make sure this token matches our token.
79 if (strnicmp (thispos, "<shibmlp ", 9)) {
81 lastpos = thispos + 1;
85 // Save this position off.
86 lastpos = thispos + 9; // strlen("<shibmlp ")
88 // search for the end-tag
89 if ((thispos = strstr(lastpos, "/>")) != NULL) {
90 string key = is.substr(lastpos-line, thispos-lastpos);
93 m_priv->log->debug("found key: \"%s\"", key.c_str());
95 map<string,string>::const_iterator i=m_map.find(key);
96 if (i == m_map.end()) {
97 static string s1 = "<!-- Unknown SHIBMLP key: ";
98 static string s2 = "/>";
100 m_priv->log->debug("key unknown");
103 m_priv->log->debug("key maps to \"%s\"", i->second.c_str());
106 lastpos = thispos + 2; // strlen("/>")
109 res += is.substr(lastpos-line);
114 string ShibMLP::run (istream& is) const
116 static string eol = "\r\n";
119 m_priv->log->info("processing stream");
121 while (getline(is, line))
127 void ShibMLP::insert (RPCError& e)
129 insert ("errorType", e.toString());
130 insert ("errorText", (e.m_except ? e.m_except->what() : e.error_msg));