BOOL SObject::InitFromXml( pugi::xml_node xmlNode ) { if(!xmlNode) return FALSE; #ifdef _DEBUG { pugi::xml_writer_buff writer; xmlNode.print(writer,L"\t",pugi::format_default,pugi::encoding_utf16); m_strXml=SStringW(writer.buffer(),writer.size()); } #endif //设置当前对象的属性 //优先处理"class"属性 pugi::xml_attribute attrClass=xmlNode.attribute(L"class"); if(attrClass) { attrClass.set_userdata(1); //预处理过的属性,给属性增加一个userdata SetAttribute(attrClass.name(), attrClass.value(), TRUE); } for (pugi::xml_attribute attr = xmlNode.first_attribute(); attr; attr = attr.next_attribute()) { if(attr.get_userdata()) continue; //忽略已经被预处理的属性 SetAttribute(attr.name(), attr.value(), TRUE); } if(attrClass) { attrClass.set_userdata(0); } //调用初始化完成接口 OnInitFinished(xmlNode); return TRUE; }
std::string node_to_string(pugi::xml_node node) { xml_string_writer writer; node.print(writer); return writer.result; }
std::string PugiHelper::StartElementInString( const pugi::xml_node& node ) { std::stringstream ss; node.print(ss); std::string line; std::getline(ss, line); return line; }
LM_NAMESPACE_BEGIN std::string PugiHelper::ElementInString( const pugi::xml_node& node ) { std::stringstream ss; node.print(ss); return ss.str(); }
bool test_node(const pugi::xml_node& node, const pugi::char_t* contents, const pugi::char_t* indent, unsigned int flags) { xml_writer_string writer; node.print(writer, indent, flags, get_native_encoding()); return writer.as_string() == contents; }
std::basic_string<wchar_t> write_wide(pugi::xml_node node, unsigned int flags, pugi::xml_encoding encoding) { xml_writer_string writer; node.print(writer, STR("\t"), flags, encoding); return writer.as_wide(); }
std::string write_narrow(pugi::xml_node node, unsigned int flags, pugi::xml_encoding encoding) { xml_writer_string writer; node.print(writer, STR("\t"), flags, encoding); return writer.as_narrow(); }
tiny_string XMLNode::toString_priv(pugi::xml_node outputNode) { if(outputNode.type() == pugi::node_null) return ""; ostringstream buf; outputNode.print(buf); tiny_string ret = tiny_string(buf.str()); return ret; }
ProcessResult PresenceRouter::route(mtalk::talk::SessionPtr sessionPtr, const pugi::xml_node& node){ std::string toStr = node.attribute("to").value(); std::string fromStr = node.attribute("from").value(); JID to(toStr); JID from(fromStr); if(to.getEndpoint() == "muc.m.renren.com"){ long fromid = from.getUserId(); string sessionid = sessionPtr->getSessionId(); stringstream ss; node.print(ss,"\t",pugi::format_raw); string message=ss.str(); bool forward =MY_INSTANCE(ProxyRegister).getProxy<MucServiceProxy>("mucProxy")->forwardPresence(fromid,sessionid,message); //推给muc服务器 // 如果forward成功,返回ok,否则返回error if(forward){ ProcessResult result(ProcessResult::OK, "<success/>"); return result; }else { ProcessResult result(ProcessResult::ERROR, "forward muc fail"); return result; } } //单聊信息 if(to.getEndpoint() == "talk.sixin.com" || to.getEndpoint() == "renren.sixin.com" || to.getEndpoint() == "talk.m.renren.com" ||to.getEndpoint() ==""){ LOG_DEBUG("PresenceRoute::route presence message"); if(strcmp(node.attribute("type").value(), "unavailable") == 0 || strcmp(node.attribute("type").value(), "background") == 0|| strcmp(node.attribute("type").value(), "foreground") == 0){ return offlineHandlerPtr_->handler(sessionPtr, node); } stringstream os; node.print(os,"\t",pugi::format_raw); MY_INSTANCE(TalkServer).remotePush(from.getUserId(), to.getUserId(), os.str(), MessageType::ENTITY); ProcessResult result; return result; } else{ long fromid = from.getUserId(); long toid = to.getUserId(); stringstream ss; node.print(ss,"\t",pugi::format_raw); string message=ss.str(); string router=to.getRouter(); LOG_DEBUG("PrsenceRoute::route forward "<< to.getEndpoint()<<"presence msg = "<<message); router.append("ServiceProxy"); ProcessResult result; bool forward = 0; LOG_DEBUG("PresenceRoute::route forward "<< router<<"presence msg = "<<message); if(MY_INSTANCE(ProxyRegister).getProxy<RouterServiceProxy>(router).get()!=0){ LOG_DEBUG("PresenceRoute::get RouterServiceProxy and forward "<< router<<"presence msg = "<<message); forward = MY_INSTANCE(ProxyRegister).getProxy<RouterServiceProxy>(router)->forwardPresence(fromid,toid,message); } // 如果forward成功,返回ok,否则返回error string id = node.attribute("id").value(); string type=node.attribute("type").value(); if(forward){ result.setCode(ProcessResult::OK); stringstream ss; ss<<"<success id='"; ss<<id; ss << "' from='"; ss << from.toString(); ss << "' to='"; ss << to.toString(); ss<<"' type='"; ss<<type; ss<<"'/>"; result.setMsg(ss.str()); return result; }else { result.setCode(ProcessResult::ERROR); stringstream s; s<<"<error id='"; s<<id; s<<"'>fail to "; s<<to.getEndpoint(); s<<" error</error>"; result.setMsg(s.str()); result.setMsg("<error>talk internal error</error>"); return result; } } }