std::string LLSLURL::getLoginString() const { std::stringstream unescaped_start; switch(mType) { case LOCATION: unescaped_start << "uri:" << mRegion << "&" << llround(mPosition[0]) << "&" << llround(mPosition[1]) << "&" << llround(mPosition[2]); break; case HOME_LOCATION: unescaped_start << "home"; break; case LAST_LOCATION: unescaped_start << "last"; break; default: LL_WARNS("AppInit") << "Unexpected SLURL type for login string" << (int)mType << LL_ENDL; break; } return xml_escape_string(unescaped_start.str()); }
std::string construct_start_string() { std::string start; LLSLURL start_slurl = LLStartUp::getStartSLURL(); switch(start_slurl.getType()) { case LLSLURL::LOCATION: { // a startup URL was specified LLVector3 position = start_slurl.getPosition(); std::string unescaped_start = STRINGIZE( "uri:" << start_slurl.getRegion() << "&" << position[VX] << "&" << position[VY] << "&" << position[VZ]); start = xml_escape_string(unescaped_start); break; } case LLSLURL::HOME_LOCATION: { start = "home"; break; } default: { start = "last"; } } return start; }
static void xml_parser_dump_node (const xml_node_t *node, int indent) { size_t l; xml_property_t *p; xml_node_t *n; printf ("%*s<%s ", indent, "", node->name); l = strlen (node->name); p = node->props; while (p) { char *value = xml_escape_string (p->value, XML_ESCAPE_SINGLE_QUOTE); printf ("%s='%s'", p->name, value); free (value); p = p->next; if (p) { printf ("\n%*s", indent+2+l, ""); } } printf (">\n"); n = node->child; while (n) { xml_parser_dump_node (n, indent+2); n = n->next; } printf ("%*s</%s>\n", indent, "", node->name); }
// virtual LLIOPipe::EStatus LLFilterSD2XMLRPCResponse::process_impl( const LLChannelDescriptors& channels, buffer_ptr_t& buffer, bool& eos, LLSD& context, LLPumpIO* pump) { LLFastTimer t(FTM_PROCESS_SD2XMLRPC_RESPONSE); PUMP_DEBUG; // This pipe does not work if it does not have everyting. This // could be addressed by making a stream parser for llsd which // handled partial information. if(!eos) { return STATUS_BREAK; } PUMP_DEBUG; // we have everyting in the buffer, so turn the structure data rpc // response into an xml rpc response. LLBufferStream stream(channels, buffer.get()); stream << XML_HEADER << XMLRPC_METHOD_RESPONSE_HEADER << std::flush; // Flush, or buffer->count() returns too much! LLSD sd; LLSDSerialize::fromNotation(sd, stream, buffer->count(channels.in())); PUMP_DEBUG; LLIOPipe::EStatus rv = STATUS_ERROR; if(sd.has("response")) { PUMP_DEBUG; // it is a normal response. pack it up and ship it out. stream.precision(DEFAULT_PRECISION); stream << XMLRPC_RESPONSE_HEADER; streamOut(stream, sd["response"]); stream << XMLRPC_RESPONSE_FOOTER << XMLRPC_METHOD_RESPONSE_FOOTER; rv = STATUS_DONE; } else if(sd.has("fault")) { PUMP_DEBUG; // it is a fault. stream << XMLRPC_FAULT_1 << sd["fault"]["code"].asInteger() << XMLRPC_FAULT_2 << xml_escape_string(sd["fault"]["description"].asString()) << XMLRPC_FAULT_3 << XMLRPC_METHOD_RESPONSE_FOOTER; rv = STATUS_DONE; } else { llwarns << "Unable to determine the type of LLSD response." << llendl; } PUMP_DEBUG; return rv; }
// virtual LLIOPipe::EStatus LLFilterSD2XMLRPCRequest::process_impl( const LLChannelDescriptors& channels, buffer_ptr_t& buffer, bool& eos, LLSD& context, LLPumpIO* pump) { LLFastTimer t(FTM_PROCESS_SD2XMLRPC_REQUEST); // This pipe does not work if it does not have everyting. This // could be addressed by making a stream parser for llsd which // handled partial information. PUMP_DEBUG; if(!eos) { llinfos << "!eos" << llendl; return STATUS_BREAK; } // See if we can parse it LLBufferStream stream(channels, buffer.get()); LLSD sd; LLSDSerialize::fromNotation(sd, stream, buffer->count(channels.in())); if(stream.fail()) { llinfos << "STREAM FAILURE reading structure data." << llendl; } PUMP_DEBUG; // We can get the method and parameters from either the member // function or passed in via the buffer. We prefer the buffer if // we found a parameter and a method, or fall back to using // mMethod and putting everyting in the buffer into the parameter. std::string method; LLSD param_sd; if(sd.has("method") && sd.has("parameter")) { method = sd["method"].asString(); param_sd = sd["parameter"]; } else { method = mMethod; param_sd = sd; } if(method.empty()) { llwarns << "SD -> XML Request no method found." << llendl; return STATUS_ERROR; } PUMP_DEBUG; // We have a method, and some kind of parameter, so package it up // and send it out. LLBufferStream ostream(channels, buffer.get()); ostream.precision(DEFAULT_PRECISION); if(ostream.fail()) { llinfos << "STREAM FAILURE setting precision" << llendl; } ostream << XML_HEADER << XMLRPC_REQUEST_HEADER_1 << xml_escape_string(method) << XMLRPC_REQUEST_HEADER_2; if(ostream.fail()) { llinfos << "STREAM FAILURE writing method headers" << llendl; } switch(param_sd.type()) { case LLSD::TypeMap: // If the params are a map, then we do not want to iterate // through them since the iterators returned will be map // ordered un-named values, which will lose the names, and // only stream the values, turning it into an array. ostream << "<param>"; streamOut(ostream, param_sd); ostream << "</param>"; break; case LLSD::TypeArray: { LLSD::array_iterator it = param_sd.beginArray(); LLSD::array_iterator end = param_sd.endArray(); for(; it != end; ++it) { ostream << "<param>"; streamOut(ostream, *it); ostream << "</param>"; } break; } default: ostream << "<param>"; streamOut(ostream, param_sd); ostream << "</param>"; break; } stream << XMLRPC_REQUEST_FOOTER << std::flush; return STATUS_DONE; }
void LLFilterSD2XMLRPC::streamOut(std::ostream& ostr, const LLSD& sd) { ostr << "<value>"; switch(sd.type()) { case LLSD::TypeMap: { #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(map) BEGIN" << llendl; #endif ostr << "<struct>"; if(ostr.fail()) { llinfos << "STREAM FAILURE writing struct" << llendl; } LLSD::map_const_iterator it = sd.beginMap(); LLSD::map_const_iterator end = sd.endMap(); for(; it != end; ++it) { ostr << "<member><name>" << xml_escape_string((*it).first) << "</name>"; streamOut(ostr, (*it).second); if(ostr.fail()) { llinfos << "STREAM FAILURE writing '" << (*it).first << "' with sd type " << (*it).second.type() << llendl; } ostr << "</member>"; } ostr << "</struct>"; #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(map) END" << llendl; #endif break; } case LLSD::TypeArray: { #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(array) BEGIN" << llendl; #endif ostr << "<array><data>"; LLSD::array_const_iterator it = sd.beginArray(); LLSD::array_const_iterator end = sd.endArray(); for(; it != end; ++it) { streamOut(ostr, *it); if(ostr.fail()) { llinfos << "STREAM FAILURE writing array element sd type " << (*it).type() << llendl; } } #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(array) END" << llendl; #endif ostr << "</data></array>"; break; } case LLSD::TypeUndefined: // treat undefined as a bool with a false value. case LLSD::TypeBoolean: #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(bool)" << llendl; #endif ostr << "<boolean>" << (sd.asBoolean() ? "1" : "0") << "</boolean>"; break; case LLSD::TypeInteger: #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(int)" << llendl; #endif ostr << "<i4>" << sd.asInteger() << "</i4>"; break; case LLSD::TypeReal: #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(real)" << llendl; #endif ostr << "<double>" << sd.asReal() << "</double>"; break; case LLSD::TypeString: #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(string)" << llendl; #endif ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>"; break; case LLSD::TypeUUID: #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(uuid)" << llendl; #endif // serialize it as a string ostr << "<string>" << sd.asString() << "</string>"; break; case LLSD::TypeURI: { #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(uri)" << llendl; #endif // serialize it as a string ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>"; break; } case LLSD::TypeBinary: { #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(binary)" << llendl; #endif // this is pretty inefficient, but we'll deal with that // problem when it becomes one. ostr << "<base64>"; LLSD::Binary buffer = sd.asBinary(); if(!buffer.empty()) { // *TODO: convert to LLBase64 int b64_buffer_length = apr_base64_encode_len(buffer.size()); char* b64_buffer = new char[b64_buffer_length]; b64_buffer_length = apr_base64_encode_binary( b64_buffer, &buffer[0], buffer.size()); ostr.write(b64_buffer, b64_buffer_length - 1); delete[] b64_buffer; } ostr << "</base64>"; break; } case LLSD::TypeDate: #if LL_SPEW_STREAM_OUT_DEBUGGING llinfos << "streamOut(date)" << llendl; #endif // no need to escape this since it will be alpha-numeric. ostr << "<dateTime.iso8601>" << sd.asString() << "</dateTime.iso8601>"; break; default: // unhandled type llwarns << "Unhandled structured data type: " << sd.type() << llendl; break; } ostr << "</value>"; }
char const * xml_escape_n (int n, char const *str) { return xml_escape_string (escape_bufs + n, str); }