XMLAttribute::XMLAttribute(DDF& in) : Attribute(in) { DDF val = in.first().first(); while (val.string()) { m_values.push_back(val.string()); val = in.first().next(); } }
const vector<string>& ExtensibleAttribute::getSerializedValues() const { if (m_serialized.empty()) { const char* formatter = m_obj["_formatter"].string(); if (formatter) { string msg = formatter; DDF val = m_obj.first().first(); while (!val.isnull()) { static const char* legal="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_.[]"; m_serialized.push_back(string()); string& processed = m_serialized.back(); string::size_type i=0,start=0; while (start!=string::npos && start<msg.length() && (i=msg.find("$",start))!=string::npos) { if (i>start) processed += msg.substr(start,i-start); // append everything in between start=i+1; // move start to the beginning of the token name i=msg.find_first_not_of(legal,start); // find token delimiter if (i==start) { // append a non legal character processed+=msg[start++]; continue; } string tag = msg.substr(start,(i==string::npos) ? i : i-start); if (tag == "_string" && val.string()) { processed += val.string(); start=i; } else { DDF child = val.getmember(tag.c_str()); if (child.string()) processed += child.string(); else if (child.isstruct() && child["_string"].string()) processed += child["_string"].string(); start=i; } } if (start!=string::npos && start<msg.length()) processed += msg.substr(start,i); // append rest of string val = m_obj.first().next(); } } } return Attribute::getSerializedValues(); }
void Application::clearAttributeHeaders(SPRequest& request) const { if (SPConfig::getConfig().isEnabled(SPConfig::OutOfProcess)) { for (vector< pair<string,string> >::const_iterator i = m_unsetHeaders.begin(); i!=m_unsetHeaders.end(); ++i) request.clearHeader(i->first.c_str(), i->second.c_str()); return; } m_lock->rdlock(); if (m_unsetHeaders.empty()) { // No headers yet, so we have to request them from the remote half. m_lock->unlock(); m_lock->wrlock(); if (m_unsetHeaders.empty()) { SharedLock wrlock(m_lock, false); string addr=string(getId()) + "::getHeaders::Application"; DDF out,in = DDF(addr.c_str()); DDFJanitor jin(in),jout(out); out = getServiceProvider().getListenerService()->send(in); if (out.islist()) { DDF header = out.first(); while (header.isstring()) { m_unsetHeaders.push_back(pair<string,string>(header.name(),header.string())); header = out.next(); } } } else { m_lock->unlock(); } m_lock->rdlock(); } // Now holding read lock. SharedLock unsetLock(m_lock, false); for (vector< pair<string,string> >::const_iterator i = m_unsetHeaders.begin(); i!=m_unsetHeaders.end(); ++i) request.clearHeader(i->first.c_str(), i->second.c_str()); }
DDF SocketListener::send(const DDF& in) { #ifdef _DEBUG NDC ndc("send"); #endif log->debug("sending message (%s)", in.name() ? in.name() : "unnamed"); // Serialize data for transmission. ostringstream os; os << in; string ostr(os.str()); // Loop on the RPC in case we lost contact the first time through #ifdef WIN32 u_long len; #else uint32_t len; #endif int retry = 1; SocketListener::ShibSocket sock; while (retry >= 0) { sock = m_socketpool->get(); int outlen = ostr.length(); len = htonl(outlen); if (send(sock,(char*)&len,sizeof(len)) != sizeof(len) || send(sock,ostr.c_str(),outlen) != outlen) { log_error(); this->close(sock); if (retry) retry--; else throw ListenerException("Failure sending remoted message ($1).", params(1,in.name())); } else { // SUCCESS. retry = -1; } } log->debug("send completed, reading response message"); // Read the message. if (recv(sock,(char*)&len,sizeof(len)) != sizeof(len)) { log->error("error reading size of output message"); this->close(sock); throw ListenerException("Failure receiving response to remoted message ($1).", params(1,in.name())); } len = ntohl(len); char buf[16384]; int size_read; stringstream is; while (len && (size_read = recv(sock, buf, sizeof(buf))) > 0) { is.write(buf, size_read); len -= size_read; } if (len) { log->error("error reading output message from socket"); this->close(sock); throw ListenerException("Failure receiving response to remoted message ($1).", params(1,in.name())); } m_socketpool->put(sock); // Unmarshall data. DDF out; is >> out; // Check for exception to unmarshall and throw, otherwise return. if (out.isstring() && out.name() && !strcmp(out.name(),"exception")) { // Reconstitute exception object. DDFJanitor jout(out); XMLToolingException* except=NULL; try { except=XMLToolingException::fromString(out.string()); log->error("remoted message returned an error: %s", except->what()); } catch (XMLToolingException& e) { log->error("caught XMLToolingException while building the XMLToolingException: %s", e.what()); log->error("XML was: %s", out.string()); throw ListenerException("Remote call failed with an unparsable exception."); } auto_ptr<XMLToolingException> wrapper(except); wrapper->raise(); } return out; }
std::string getRemoteAddr() const { DDF s = m_input["client_addr"]; return s.string() ? s.string() : ""; }
std::string getRemoteUser() const { DDF s = m_input["remote_user"]; return s.string() ? s.string() : ""; }
std::string getContentType() const { DDF s = m_input["content_type"]; return s.string() ? s.string() : ""; }
std::string getHeader(const char* name) const { DDF s = m_input["headers"][name]; return s.string() ? s.string() : ""; }