CStdString DomSerializer::DomNodeToString(DOMNode* node) { CStdString output; DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(XStr("LS").unicodeForm()); DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer(); DOMConfiguration * dc = theSerializer->getDomConfig(); // set user specified output encoding //dc->setEncoding(gOutputEncoding); dc->setParameter(XStr("format-pretty-print").unicodeForm(), true); XMLFormatTarget *myFormTarget; myFormTarget = new MemBufFormatTarget (); DOMLSOutput *outputStream = ((DOMImplementationLS*)impl)->createLSOutput(); outputStream->setByteStream(myFormTarget); theSerializer->write(node, outputStream); output = (char *)((MemBufFormatTarget*)myFormTarget)->getRawBuffer(); // Clean up delete theSerializer; // // Filter, formatTarget and error handler // are NOT owned by the serializer. delete myFormTarget; return output; }
void Parameter::getValueFromMessage(XStr &str) { if (name) // FIXME: Is CmiUInt8 a really named type?? if (type->isNamed() && (XStr(type->getBaseName()) != "CmiUInt8")) { str << " UserMessage *user_msg;\n"; str << " user_msg = (UserMessage *)m.argumentList[0];\n"; str << " " << type << "::unpack(&" << name << ", user_msg->buf);\n"; } else //str << " m >> " << name << ";\n"; str << " " << name << " = *(" << type << " *)m.argumentList[parameterNumber++]"<< ";\n"; }
void Parameter::addValueToMessage(XStr &str) { if (name) { // FIXME: Is CmiUInt8 a really named type?? if (type->isNamed() && (XStr(type->getBaseName()) != "CmiUInt8")) { str << " UserMessage *user_msg = new UserMessage(" << name << ".size());\n"; str << " " << type << "::pack(&" << name << ", user_msg->buf);\n"; str << " m | user_msg;\n"; } else { str << " m | " << name << ";\n"; } } }
OCMLInterpreter::OCMLInterpreter() { // Initialize the XML4C2 system. try { xercesc::XMLPlatformUtils::Initialize(); } catch(const xercesc::XMLException& toCatch) { char *pMsg = xercesc::XMLString::transcode(toCatch.getMessage()); std::cerr << "Error during Xerces-c Initialization.\n" << " Exception message:" << pMsg; xercesc::XMLString::release(&pMsg); throw; } impl_ = xercesc::DOMImplementationRegistry::getDOMImplementation(XStr("Core")); }
xercesc::DOMDocument* OCMLInterpreter::create_document(std::set<BON::Model>& root_models) { // create DOMDocument xercesc::DOMDocument* doc = impl_->createDocument(0, XStr("OCML"), 0); // Traverse the root models and ... for (std::set<BON::Model>::iterator iter = root_models.begin(); iter != root_models.end(); ++iter) { if (OCML_BON::Option_Category(*iter)) { // call xml_export functions of each Option_Category // and insert the returning node into the xml node xercesc::DOMNode* child = OCML_BON::Option_Category(*iter)->xml_export(doc); doc->getDocumentElement()->appendChild(child); } } return doc; }
int HttpServer::svc(void) { char buf[2048]; buf[2047] = '\0'; // security ACE_Time_Value timeout; timeout.sec(5); ssize_t size = peer().recv(buf, 2040, &timeout); if (size > 5) { try { int startUrlOffset = 5; // get rid of "GET /" from Http request, so skip 5 chars char* stopUrl = ACE_OS::strstr(buf+startUrlOffset, " HTTP"); // detect location of post-URL trailing stuff if(!stopUrl) { throw (CStdString("Malformed http request")); ; } *stopUrl = '\0'; // Remove post-URL trailing stuff CStdString url(buf+startUrlOffset); int queryOffset = url.Find("?"); if (queryOffset > 0) { // Strip beginning of URL in case the command is received as an URL "query" of the form: // http://hostname/service/command?type=ping url = url.Right(url.size() - queryOffset - 1); } CStdString className = UrlSerializer::FindClass(url); ObjectRef objRef = ObjectFactory::GetSingleton()->NewInstance(className); if (objRef.get()) { objRef->DeSerializeUrl(url); ObjectRef response = objRef->Process(); if(response.get() == NULL) { throw (CStdString("Command does not return a response:") + className); } else { DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XStr("Core").unicodeForm()); XERCES_CPP_NAMESPACE::DOMDocument* myDoc; myDoc = impl->createDocument( 0, // root element namespace URI. XStr("response").unicodeForm(), // root element name 0); // document type object (DTD). response->SerializeDom(myDoc); CStdString pingResponse = DomSerializer::DomNodeToString(myDoc); CStdString httpOk("HTTP/1.0 200 OK\r\nContent-type: text/xml\r\n\r\n"); peer().send(httpOk, httpOk.GetLength(), MSG_NOSIGNAL); peer().send(pingResponse, pingResponse.GetLength(), MSG_NOSIGNAL); myDoc->release(); } } else { throw (CStdString("Command not found:") + className); ; } } catch (CStdString &e) { CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nError\r\n"); error = error + e + "\r\n"; peer().send(error, error.GetLength(), MSG_NOSIGNAL); } catch(const XMLException& e) { CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nXML Error\r\n"); peer().send(error, error.GetLength(), MSG_NOSIGNAL); } } else { CStdString notFound("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nNot found\r\n"); peer().send(notFound, notFound.GetLength(), MSG_NOSIGNAL); } return 0; }