Пример #1
0
// internal helper function to process elements
void processXMLElement(XMLHandler& handler, xmlNode* node)
{
    // build attributes block for the element
    XMLAttributes attrs;

    xmlAttrPtr currAttr = node->properties;
    while (currAttr)
    {
        xmlChar* val = xmlGetProp(node, currAttr->name);
        attrs.add((utf8*)currAttr->name, (utf8*)val);
        xmlFree(val);
        currAttr = currAttr->next;
    }

    // element start processing
    handler.elementStart((utf8*)node->name, attrs);

    for (xmlNode* cur_node = node->children; cur_node; cur_node = cur_node->next)
    {
        switch(cur_node->type)
        {
        case XML_ELEMENT_NODE:
            processXMLElement(handler, cur_node);
            break;

        case XML_TEXT_NODE:
            if (cur_node->content != 0 && *cur_node->content!= '\0')
                handler.text((utf8*)cur_node->content);
            break;
        }
    }

    // element end processing
    handler.elementEnd((utf8*)node->name);
}
Пример #2
0
void ExpatParser::startElement(void* data, const char* element, const char** attr)
{
    XMLHandler* handler = static_cast<XMLHandler*>(data);
    XMLAttributes attrs;

    for(size_t i = 0 ; attr[i] ; i += 2)
        attrs.add((const encoded_char*)attr[i], (const encoded_char*)attr[i+1]);

    handler->elementStart((const encoded_char*)element, attrs);
}
Пример #3
0
void Option::printHelpTOC(XMLHandler &handler, const string &prefix) const {
  handler.startElement("li");

  XMLAttributes attrs;
  attrs["href"] = "#" + prefix + "option-" + getName();
  handler.startElement("a", attrs);
  handler.text(getName());
  handler.endElement("a");

  handler.endElement("li");
}
Пример #4
0
//-----------------------------------------------------------------------
static void XMLCALL expatEndElementHandler(void *userData, const XML_Char *name)
{
    MyUserData* myUserData = static_cast<MyUserData*>(userData);
    assert(myUserData);
    XMLHandler* handler = myUserData->handler;
    const UTFConverter& converter = myUserData->converter;
    assert(handler);
    assert(converter);
    std::string& s0 = myUserData->s0;

    s0 = name;
    handler->endElement(converter(s0, s0));
}
Пример #5
0
//-----------------------------------------------------------------------
static void XMLCALL expatCharacterDataHandler(void *userData, const XML_Char *s, int len)
{
    MyUserData* myUserData = static_cast<MyUserData*>(userData);
    assert(myUserData);
    XMLHandler* handler = myUserData->handler;
    const UTFConverter& converter = myUserData->converter;
    assert(handler);
    assert(converter);
    std::string& s0 = myUserData->s0;

    s0 = std::basic_string<XML_Char>(s, len);
    handler->characters(converter(s0, s0));
}
Пример #6
0
void Option::write(XMLHandler &handler, uint32_t flags) const {
  XMLAttributes attrs;

  string value = toString();
  if (isObscured() && !(flags & OBSCURED_FLAG))
    value = string(value.size(), '*');

  if (!isPlural()) attrs["v"] = value;

  handler.startElement(name, attrs);

  if (isPlural()) handler.text(value);

  handler.endElement(name);
}
Пример #7
0
			void judgeThread(){
				while(true){
					XMLHandler xmlh;
					if(rh->getNextXML(xmlh)){
						xml_node xmlnd=xmlh.child("judge");
						runid=atoi(xmlnd.child_value("runid"));
						jr.runid=runid;
						storepath=string(xmlnd.child_value("storepath"));
						fileprepath=string(xmlnd.child_value("fileprepath"));
						srcname=string(xmlnd.child_value("srcname"));
						string fullpath=storepath+fileprepath+srcname;
						#ifdef _DEBUG
						cout<<"dump the xml recved by judge thread"<<endl;
						xmlh.dump();
						cout<<"compile src file parameters:"<<endl;
						cout<<"fullpath "<<fullpath<<endl;
						cout<<"runnablepath"<<runnablepath+"a.out"<<endl;
						#endif
						jr.compilecode=dm->compile("g++","-lm -DONLINE_JUDGE",fullpath,runnablepath+"a.out");
						if(jr.compilecode==0){//succ
							dm->addRunnableLanucher(runnablepath+"a.out",inputpath+"1.in",runnablepath+"1.out");
							jr.outputpath=runnablepath+"1.out";
							dm->run();
							jr.usg=dm->getRet();
							jr.inputtype=1;
							//run NewJudger below
							if(jr.usg._re==0&&jr.usg._tle==0&&jr.usg._mle==0){
								jer=shared_ptr<NewJudger>(new NewJudger(3,runnablepath+"1.out"));
								jer->run();
							}
						}
						else jr.inputtype=0;
							
						XMLHandler xmlsend(getSendXML());
						#if _DEBUG
						cout<<"but final got send xml is "<<endl;
						xmlsend.dump();
						#endif
						jr.sendxmlpath=runnablepath+"ret"+to_string(runid)+".xml";
						xmlsend.saveFile(jr.sendxmlpath.c_str());
						rqh=shared_ptr<RequestHandler>(new RequestHandler());
						rqh->sendFile(jr.sendxmlpath.c_str(),posturl.c_str());
					}
					else{
						nanosleep(&t100m,&tres);
					}
				}
			}
Пример #8
0
//----------------------------------------------------------------------------//
void RapidXMLDocument::processElement(const rapidxml::xml_node<>* element)
{
    // build attributes block for the element
    XMLAttributes attrs;

    rapidxml::xml_attribute<>* currAttr = element->first_attribute(0);

    while (currAttr)
    {
        attrs.add((utf8*)currAttr->name(), (utf8*)currAttr->value());
        currAttr = currAttr->next_attribute();
    }

    // start element
    d_handler->elementStart((utf8*)element->name(), attrs);

    // do children
    rapidxml::xml_node<>* childNode = element->first_node();

    while (childNode)
    {
        switch (childNode->type())
        {
        case rapidxml::node_element:
            processElement(childNode);
            break;

        case rapidxml::node_data:
            if (childNode->value() != '\0')
                d_handler->text((utf8*)childNode->value());

            break;

            // Silently ignore unhandled node type
        };

        childNode = childNode->next_sibling();
    }


    // end element
    d_handler->elementEnd((utf8*)element->name());
}
Пример #9
0
			/*
			 **From  JudgeRet jr
			*/
			XMLHandler getSendXML(){
				XMLHandler xmlh;
				xml_node nd=xmlh.addChild("result",NULL);
				nd.append_child("runid").append_child(node_pcdata).set_value(to_string(jr.runid).c_str());
				nd.append_child("compilecode").append_child(node_pcdata).set_value(to_string(jr.compilecode).c_str());
				nd.append_child("inputtype").append_child(node_pcdata).set_value(to_string(jr.inputtype).c_str());
				nd.append_child("time").append_child(node_pcdata).set_value(to_string(jr.usg._timeUsage).c_str());
				nd.append_child("mem").append_child(node_pcdata).set_value(to_string(jr.usg._memUsage).c_str());
				nd.append_child("RE").append_child(node_pcdata).set_value(to_string(jr.usg._re).c_str());
				nd.append_child("TLE").append_child(node_pcdata).set_value(to_string(jr.usg._tle).c_str());
				nd.append_child("MLE").append_child(node_pcdata).set_value(to_string(jr.usg._mle).c_str());
				nd.append_child("outpath").append_child(node_pcdata).set_value((runnablepath+"1.out").c_str());
				JudgeInfo ji=jer->getRet();
				nd.append_child("judgercorrect").append_child(node_pcdata).set_value(to_string(ji.correct).c_str());
				nd.append_child("judgererrtype").append_child(node_pcdata).set_value(to_string(ji.err_type).c_str());
				#if _DEBUG
				cout<<"getSendXML ret"<<endl;
				xmlh.dump();
				#endif
				return xmlh;
			} 
Пример #10
0
static void XMLCALL expatStartElementHandler(void *userData, const XML_Char *name, const XML_Char **atts)
{
    MyUserData* myUserData = static_cast<MyUserData*>(userData);
    assert(myUserData);
    XMLHandler* handler = myUserData->handler;
    const UTFConverter& converter = myUserData->converter;
    assert(handler);
    assert(converter);
    std::string& s0 = myUserData->s0;
    std::string& s1 = myUserData->s1;

    XMLAttributes attributes;
    for (const XML_Char**p = atts; *p; p += 2)
    {
        assert(p[0] && p[1]);
        s0 = p[0];
        s1 = p[1];
        attributes.setValue(converter(s0, s0), converter(s1, s1));
    }

    s0 = name;
    handler->startElement(converter(s0, s0), attributes);
}
Пример #11
0
    void TinyXMLDocument::processElement(const TiXmlElement* element)
    {
        // build attributes block for the element
        XMLAttributes attrs;

        const TiXmlAttribute *currAttr = element->FirstAttribute();
        while (currAttr)
        {
            attrs.add((encoded_char*)currAttr->Name(), (encoded_char*)currAttr->Value());
            currAttr = currAttr->Next();
        }

        // start element
        d_handler->elementStart((encoded_char*)element->Value(), attrs);

        // do children
        const TiXmlNode* childNode = element->FirstChild();
        while (childNode)
        {
            switch(childNode->Type())
            {
            case TiXmlNode::CEGUI_TINYXML_ELEMENT:
                processElement(childNode->ToElement());
                break;
            case TiXmlNode::CEGUI_TINYXML_TEXT:
                if (childNode->ToText()->Value() != '\0')
                    d_handler->text((encoded_char*)childNode->ToText()->Value());
                break;

                // Silently ignore unhandled node type
            };
            childNode = childNode->NextSibling();
        }

        // end element
        d_handler->elementEnd((encoded_char*)element->Value());
    }
Пример #12
0
void Option::printHelp(XMLHandler &handler, const string &prefix) const {
  XMLAttributes attrs;

  attrs["class"] = "option";
  attrs["id"] = prefix + "option-" + getName();
  handler.startElement("div", attrs);

  // Name
  attrs.clear();
  attrs["class"] = "name";
  handler.startElement("span", attrs);
  handler.text(getName());
  handler.endElement("span");

  // Type
  attrs["class"] = "type";
  handler.startElement("span", attrs);
  handler.text(isOptional() ? "[" : "<");
  handler.text(getTypeString());

  // Default
  if (hasDefault()) {
    handler.text(" = ");

    bool isString = type == STRING_TYPE || type == STRINGS_TYPE;

    attrs["class"] = "default";
    handler.startElement("span", attrs);
    handler.text((isString ? "\"" : "") + getDefault() +
                 (isString ? "\"" : ""));
    handler.endElement("span");
  }

  handler.text(isOptional() ? "]" : ">");
  handler.endElement("span");

  // Help
  if (getHelp() != "") {
    attrs["class"] = "help";
    handler.startElement("div", attrs);
    string help = getHelp();
    vector<string> tokens;
    String::tokenize(help, tokens, "\t");
    handler.text(String::join(tokens, "  "));
    handler.text(" ");
    handler.endElement("div");
  }


  handler.endElement("div");
}
Пример #13
0
void ExpatParser::endElement(void* data, const char* element)
{
    XMLHandler* handler = static_cast<XMLHandler*>(data);
    handler->elementEnd((const encoded_char*)element);
}
Пример #14
0
void ExpatParser::characterData(void *data, const char *text, int len)
{
    XMLHandler* handler = static_cast<XMLHandler*>(data);
    String str((const encoded_char*)text, static_cast<String::size_type>(len));
    handler->text(str);
}
Пример #15
0
/**
  * Zpracuje a spravne zvoli akce podle doruceneho packetu
  */
void Thread::handleRequest()
{
    QByteArray rawdata = socket->readAll();

    Message message;
    ManipulateNet tool;
    PetriNet *petriNet = new PetriNet;
    XMLHandler xmlhandler;
    QList<PetriNet *> netList;

    xmlhandler.setMessage(&message);
    xmlhandler.setPetriNet(petriNet);
    xmlhandler.setNetList(&netList);
    xmlhandler.readMessage(QString(rawdata));
    Message resultMsg;
    XMLHandler resultXml;
    QString out;
    PetriNet *resultNet = new PetriNet;
    Simulate simulate;

    switch (message.command)
    {
    case Message::SLOGIN:
        break;
    case Message::CLOGIN:
        /* Pozadavek na prihlaseni uzivatele */
        if(!authenticate(message.user, message.password))
        {
            resultMsg.command = Message::WRONGLOGIN;
            resultXml.setMessage(&resultMsg);
        }
        else
        {
            resultMsg.command = Message::LOGGED;
            resultXml.setMessage(&resultMsg);
        }
        out = resultXml.writeMessage();
        rawdata = out.toUtf8();
        socket->write(rawdata);
        socket->flush();
        break;
    case Message::WRONGLOGIN:
        break;
    case Message::LOGGED:
        break;
    case Message::CLIST:
        /* Pozadavek na seznam siti */
        qDebug() << socketDescriptor << "Request for list of nets";
        tool.getNetList(this->getUsername(),&netList);
        if (tool.error)
        {
            /* Nastala chyba pri ukladani */
            resultMsg.command = Message::ERROR;
            resultMsg.errorText = "Error while getting list of nets";
        }
        else
        {
            resultMsg.command = Message::SLIST;
            resultXml.setNetList(&netList);
            resultXml.setMessage(&resultMsg);
        }
        resultXml.setMessage(&resultMsg);
        out = resultXml.writeMessage();
        rawdata = out.toUtf8();
        socket->write(rawdata);
        socket->flush();
        /* Dealokuju seznam siti */
        for (int i = 0; i < netList.size(); i++)
        {
            delete netList.at(i);
        }
        netList.clear();
        break;
    case Message::SLIST:
        break;
    case Message::SEND:
        break;
    case Message::ERROR:
        break;
    case Message::SAVE:
        /* Pozadavek na ulozeni site */
        qDebug() << socketDescriptor << "Request for save a net";
        tool.saveNet(petriNet->getName(),this->getUsername(),&xmlhandler);
        if (tool.error)
        {
            /* Nastala chyba pri ukladani */
            resultMsg.command = Message::ERROR;
            resultMsg.errorText = "Error while saving";
            writeLogSave(petriNet->getName(), "FAIL");
            resultXml.setMessage(&resultMsg);
            out = resultXml.writeMessage();
            rawdata = out.toUtf8();
            socket->write(rawdata);
            socket->flush();
        }
        else
        {
            writeLogSave(petriNet->getName(), "PASS");
        }

        break;
    case Message::LOAD:
        /* Pozadavek na nacteni site */
        qDebug() << socketDescriptor << "Request for load the net";

        tool.loadNet(petriNet->getName(),this->getUsername(),petriNet->getVersion(),petriNet);
        if (tool.error)
        {
            /* Nastala chyba pri cteni, sit neexistuje? */
            resultMsg.command = Message::ERROR;
            resultMsg.errorText = "Error while loading, perhaps the net does not exist";
            writeLogLoad(petriNet->getName(), "FAIL");
        }
        else
        {
            /* Sit byla uspesne otevrena */
            resultMsg.command = Message::SEND;
            resultXml.setPetriNet(petriNet);
            writeLogLoad(petriNet->getName(), "PASS");
        }

        /* At uz se stala chyba nebo ne, vse je treba zabalit a odeslat */
        resultXml.setMessage(&resultMsg);
        out = resultXml.writeMessage();
        rawdata = out.toUtf8();
        socket->write(rawdata);
        socket->flush();
        break;
    case Message::SIMULATE:
        /* Pozadavek na simulaci */
        qDebug() << socketDescriptor << "Request for the simulation";
        if (message.simulationSteps == 0)
        {
            simulate.simulateAll(petriNet);
        }
        else
        {
            if(!simulate.simulateStep(petriNet))
            {
                simulate.error = true;
            }
        }

        if (simulate.error)
        {
            /* Nastala chyba pri simulaci */
            resultMsg.command = Message::ERROR;
            resultMsg.errorText = "Error while simulation, perhaps there aren't any possible steps";
            writeLogSimulate(petriNet->getName(),petriNet->getVersion(),"FAIL");
        }
        else
        {
            /* Sit byla v poradku odsimulovana */
            resultMsg.command = Message::SEND;
            resultXml.setPetriNet(petriNet);
            writeLogSimulate(petriNet->getName(),petriNet->getVersion(),"PASS");
        }

        /* Zprava bude odeslana */
        resultXml.setMessage(&resultMsg);
        out = resultXml.writeMessage();
        rawdata = out.toUtf8();
        socket->write(rawdata);
        socket->flush();
        break;
    case Message::LOG:
        /* Klient zada o log */
        qDebug() << socketDescriptor << "Request for logs";
        resultMsg.user = getUsername();
        resultMsg.command = message.command;
        resultXml.setMessage(&resultMsg);
        out = resultXml.writeMessage();
        rawdata = out.toUtf8();
        socket->write(rawdata);
        socket->flush();
        break;
    }
    delete petriNet; // maže se opravdu vždycky?
    delete resultNet;
}