void CgiParser::readMultipartData(WebRequest& request, const std::string type, ::int64_t len) { std::string boundary; if (!fishValue(type, boundary_e, boundary)) throw WException("Could not find a boundary for multipart data."); boundary = "--" + boundary; buflen_ = 0; left_ = len; spoolStream_ = 0; currentKey_.clear(); if (!parseBody(request, boundary)) return; for (;;) { if (!parseHead(request)) break; if (!parseBody(request,boundary)) break; } }
/** * Parse * Populate internal HTTPRequest variables by parsing the HTTP data * * @param True if successful. If false, sets parseErrorStr for reason of failure */ bool HTTPRequest::parse() { std::string initial = "", methodName = ""; // Get elements from the initial line: <method> <path> <version>\r\n methodName = getStrElement(); requestUri = getStrElement(); version = getLine(); // End of the line, pull till \r\n // Convert the name to the internal enumeration number method = methodStrToInt(methodName); if(method == -1) { parseErrorStr = "Invalid Method: " + methodName; return false; } // Validate the HTTP version. If there is a mismatch, discontinue parsing if(strcmp(version.c_str(), HTTP_VERSION) != 0) { parseErrorStr = "Supported HTTP version does not match"; return false; } // Parse and populate the headers map using the parseHeaders helper parseHeaders(); // Only POST and PUT can have Content (data after headers) if((method != POST) && (method != PUT)) return true; // Parse the body of the message if(!parseBody()) return false; return true; }
bool LparseParser::parseRule(int rt) { if (knownRuleType(rt)) { int bound = -1; bool weights = false; active_->setType(static_cast<Asp::RuleType>(rt)); if (rt == Asp::CHOICERULE || rt == Asp::DISJUNCTIVERULE) { int heads = input()->parseInt(1, INT_MAX, "Rule has too few heads"); for (int i = 0; i < heads; ++i) { active_->addHead(parseAtom()); } } else if (rt == Asp::OPTIMIZERULE) { weights = input()->parseInt(0, 0, "Minimize rule: 0 expected!") == 0; } else { active_->addHead(parseAtom()); weights = rt == Asp::WEIGHTRULE && check(input()->parseInt(bound, 0, INT_MAX), "Weightrule: Positive weight expected!"); } int lits = input()->parseInt(0, INT_MAX, "Number of body literals expected!"); int neg = input()->parseInt(0, lits, "Illegal negative body size!"); check(rt != Asp::CONSTRAINTRULE || input()->parseInt(bound, 0, INT_MAX), "Constraint rule: Positive bound expected!"); if (bound >= 0) { active_->setBound(bound); } return parseBody(static_cast<uint32>(lits), static_cast<uint32>(neg), weights) && addRule(*active_); } else if (rt >= 90 && rt < 93) { if (rt == 90) { return input()->parseInt(0, 0, "0 expected") == 0; } int a = input()->parseInt(1, INT_MAX, "atom id expected"); if (rt == 91) { builder_->freeze(a, input()->parseInt(0, 1, "0 or 1 expected") ? value_true : value_false); } else { builder_->unfreeze(a); } return true; } else { return parseRuleExtension(rt); } }
void *Parse_parse (int fd, int reqOnly) { http400 = generate400(); //getToken(fd, 1); modify ReqLine_t reqline; Http_t http = 0; if(reqOnly){ reqline = Parse_reqLine (fd); return reqline; } parseHeaders(fd); if (token.kind!=TOKEN_CRLF) parseError(fd); int num = parseBody(fd); reqline = gReqline; http = Http_new (HTTP_KIND_REQUEST , reqline , 0 , 0 , 0); if (DEBUG) Http_print (1, http); return http; }
/*! Constructor with the header \a header and the body \a body. */ THttpRequest::THttpRequest(const THttpRequestHeader &header, const QByteArray &body, const QHostAddress &clientAddress) : d(new THttpRequestData) { d->header = header; d->clientAddress = clientAddress; parseBody(body, header); }
void HTMLParser::parse(const char *szHTML, size_t nLen) { if(szHTML == NULL || nLen <= 0) return ; m_nContentLength = 0; m_nTitleLength = 0; if(m_pContentBuffer == NULL) { m_nContentBufferSize = nLen + 1; if (m_nContentBufferSize < CONTENTGROW_SIZE) m_nContentBufferSize = CONTENTGROW_SIZE; m_pContentBuffer = new char[m_nContentBufferSize]; } else if(m_nContentBufferSize < nLen + 1) { m_nContentBufferSize += CONTENTGROW_SIZE; if(m_nContentBufferSize < nLen + 1) m_nContentBufferSize = nLen + 1; delete[] m_pContentBuffer; m_pContentBuffer = new char[m_nContentBufferSize]; } register char* pCur = (char*)szHTML; char* pEnd = (char*)szHTML + nLen; parseBody(pCur, pEnd); m_pContentBuffer[m_nContentLength] = 0; }
const bool InPacket::parse( ) { if(bodyLength){ parseBody(); return true; }else return false; }
HtmlParser(const std::string &file_name) : _result(false) { std::string title; std::string body; Tree tr; html::ParserDom parser; parser.parse(getHtmlString(file_name)); tr = parser.getTree(); TreeIter it = tr.begin(); TreeIter end = tr.end(); _root_depth = tr.depth(it); while (it != end) { std::string shift = getShift(tr.depth(it)); if (not it->tagName().empty() && not it->isComment()) { if (it->isTag()) { if (it->tagName() == "head") { title = parseHead(tr, it); } if (it->tagName() == "body") { body = (b::format("<![CDATA[\n%s%s%s%s%s%s%s%s]]>") % shift % it->text() % "\n" % parseBody(tr, it) % shift % it->closingText() % "\n" % shift ).str(); } } } ++it; } b::format res = b::format( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<items>\n" " <snip1 type=\"contenttype\">\n" " <title type=\"field\">\n" " %s\n" " </title>\n" " <body type=\"field\">\n" " <value>\n" " %s\n" " </value>\n" " </body>\n" " </snip1>\n" "</items>\n" ) % title % body ; std::cout << res.str() << std::flush; _result = true; }
IndexedStructType::IndexedStructType(const string& body, int pack, int explicitAlign, bool isUnion, bool isArgStack) : RawType("", sizeof(DWORD) /* sizeof empty struct */) , m_pack(pack) , m_isUnion(isUnion) , m_explicitAlign(explicitAlign) , m_isArgStack(isArgStack) { parseBody(body); init(); }
CSSSheet *WordParseStyles(WordConverter *converter) { CSSSheet *styleSheet = CSSSheetNew(); CSSStyle *bodyStyle = CSSSheetLookupElement(styleSheet,"body",NULL,1,0); CSSPut(CSSStyleRule(bodyStyle),"counter-reset","h1 h2 h3 h4 h5 h6 figure table"); parseBody(converter,styleSheet); if (converter->package->styles == NULL) return styleSheet;; DFNode *root = converter->package->styles->root; if (root == NULL) return styleSheet; if (root->tag != WORD_STYLES) return styleSheet;; WordSheet *sheet = converter->styles; const char **allIdents = WordSheetCopyIdents(sheet); for (int i = 0; allIdents[i]; i++) { WordStyle *wordStyle = WordSheetStyleForIdent(sheet,allIdents[i]); if ((wordStyle->selector == NULL) || WordStyleIsProtected(wordStyle)) continue; CSSStyle *style = CSSSheetLookupSelector(styleSheet,wordStyle->selector,1,0); styleParse(wordStyle,converter,style); const char *defaultVal = DFGetAttribute(wordStyle->element,WORD_DEFAULT); if ((defaultVal != NULL) && Word_parseOnOff(defaultVal)) { StyleFamily family = WordStyleFamilyForSelector(style->selector); CSSSheetSetDefaultStyle(styleSheet,style,family); CSSSetDefault(CSSStyleRule(style),1); if (family == StyleFamilyParagraph) fixParagraphSpacing(style,wordStyle->element); } } free(allIdents); DFNode *docDefaults = DFChildWithTag(root,WORD_DOCDEFAULTS); DFNode *pPrDefault = DFChildWithTag(docDefaults,WORD_PPRDEFAULT); DFNode *pPr = DFChildWithTag(pPrDefault,WORD_PPR); if (pPr != NULL) { CSSStyle *body = CSSSheetLookupElement(styleSheet,"body",NULL,1,0); const char *styleId = NULL; WordGetPPr(pPr,CSSStyleRule(body),&styleId,converter->mainSection); } // Special case for figure style: set left and right margin to auto, if not already set CSSStyle *figure = CSSSheetLookupElement(styleSheet,"figure",NULL,0,0); if (figure != NULL) { if (CSSGet(CSSStyleRule(figure),"margin-left") == NULL) CSSPut(CSSStyleRule(figure),"margin-left","auto"); if (CSSGet(CSSStyleRule(figure),"margin-right") == NULL) CSSPut(CSSStyleRule(figure),"margin-right","auto"); } return styleSheet; }
bool MultipartParser::parse(const uint8_t *d, size_t l, const String &ct, bool files) { Reader r(ct.c_str(), ct.length()); if (!parseContentType(r)) { return false; } readFiles = files; data = Reader((const char *)d, l); origData = Reader((const char *)d, l); return parseBody(); }
bool parse(READ &read) { BinaryReader<READ> reader(read); // check header std::string line=reader.getString(30); if(line=="Vocaloid Motion Data file"){ version="1"; name=reader.getString(10); return parseBody(reader); } else if(line=="Vocaloid Motion Data 0002"){ version="2"; name=reader.getString(20); return parseBody(reader); } else{ //std::cout << "unknown header:" << line << std::endl; return false; } }
FunctionAST* Parser::handleFunctionDef() { PrototypeAST* proto = handleProtoDef(); currentFunc = proto; for (unsigned int i = 0; i < proto->args.size(); i++) currentFunc->associatedVars[proto->args[i]->GetName()] = proto->args[i]->GetType(); if (!proto) return 0; // parse body bool hadErr; std::vector<ExprAST*> body = parseBody(hadErr); if (hadErr) return 0; return new FunctionAST(proto, body); }
void RequestParser::parsePart(const Item& aItem, Part& aPart) { Item lHeaders; Item lBody; bool lHaveHeaders = getObject(aItem, "headers", false, lHeaders); if (lHaveHeaders) parseHeaders(lHeaders, aPart.theHeaders); getObject(aItem, "body", true, lBody); parseBody(lBody, aPart.theBody); }
bool Lvk::Clue::ScriptParser::parseRoot(QDomElement &root, Clue::Script &script) { if (root.childNodes().size() < 2) { m_errMsg = QObject::tr("Missing Header and/or Body"); return false; } QDomElement e0 = root.childNodes().item(0).toElement(); QDomElement e1 = root.childNodes().item(1).toElement(); return requireTagName("header", e0) && parseHeader(e0, script) && requireTagName("body", e1) && parseBody(e1, script); }
void RequestParser::parseRequest(const Item& aItem, Request& aRequest) { if (!getString(aItem, "method", false, aRequest.theMethod)) aRequest.theMethod = "GET"; else aRequest.theMethod = fn::upper_case(aRequest.theMethod); getString(aItem, "href", true, aRequest.theHref); Item lAuthentication; if ((aRequest.theAuthentication.theSendAuthentication = getObject(aItem, "authentication", false, lAuthentication))) parseAuthentication(lAuthentication, aRequest.theAuthentication); Item lOptions; if (getObject(aItem, "options", false, lOptions)) parseOptions(lOptions, aRequest.theOptions); // follow-redirect: take care of the default (if the user didn't provide one) if (aRequest.theMethod == "GET" || aRequest.theMethod == "HEAD" || aRequest.theMethod == "OPTIONS") { if (!aRequest.theOptions.theUserDefinedFollowRedirect) aRequest.theOptions.theFollowRedirect = true; } else { if (aRequest.theOptions.theFollowRedirect) { std::ostringstream lMsg; lMsg << "cannot follow redirect, request method: " << aRequest.theMethod; theThrower->raiseException("FOLLOW", lMsg.str()); } } Item lHeaders; bool lHaveHeaders = getObject(aItem, "headers", false, lHeaders); if (lHaveHeaders) parseHeaders(lHeaders, aRequest.theHeaders); Item lBody; Item lMultipart; aRequest.theHaveBody = getObject(aItem, "body", false, lBody); aRequest.theHaveMultiPart = getObject(aItem, "multipart", false, lMultipart); if (aRequest.theHaveBody && aRequest.theHaveMultiPart) theThrower->raiseException("REQUEST","The specified request is not valid. HTTP request cannot contain both body and multipart"); if (aRequest.theHaveBody) parseBody(lBody, aRequest.theBody); if (aRequest.theHaveMultiPart) parseMultipart(lMultipart, aRequest.theMultiPart); }
SipDialogEvent::SipDialogEvent(const char* bodyBytes) : mLock(OsBSem::Q_PRIORITY, OsBSem::FULL) { remove(0); append(DIALOG_EVENT_CONTENT_TYPE); if(bodyBytes) { bodyLength = strlen(bodyBytes); parseBody(bodyBytes); } mBody = bodyBytes; }
const bool EvaFTPacket::parse() { if(!m_Buffer) return false; int pos = 0; if(m_HasTags){ m_Tag = m_Buffer[0]; m_Tail = m_Buffer[m_BufferLength - 1]; pos++; } m_HeaderLength = parseHeader(m_Buffer + pos); if(m_HeaderLength == -1) return false; pos += m_HeaderLength; return parseBody(m_Buffer + pos, m_BufferLength - pos - (m_HasTags?1:0)); }
void *NclStructureParser::parseNcl( DOMElement *parentElement, void *objGrandParent) { void *parentObject = NULL; DOMNodeList *elementNodeList; int i, size; DOMNode *node; void *elementObject = NULL; parentObject = createNcl(parentElement, objGrandParent); if (parentObject == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); size = elementNodeList->getLength(); for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString(((DOMElement*)node)-> getTagName(), XMLString::transcode("head") )==0) { elementObject = parseHead((DOMElement*)node, parentObject);; if (elementObject != NULL) { addHeadToNcl(parentObject, elementObject); break; } } } for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString(((DOMElement*)node)-> getTagName(), XMLString::transcode("body") )==0) { elementObject = parseBody((DOMElement*)node, parentObject); if (elementObject != NULL) { posCompileBody((DOMElement*)node, elementObject); addBodyToNcl(parentObject, elementObject); break; } } } return parentObject; }
bool HttpResponse::parse(){ std::string statusstr; version = getStrElement(); statusstr = getStrElement(); determineStatusCode(); reason = getLine(); parseHeaders(); if(!parseBody()) return false; return true; }
void HttpResponseParser::parseMultipartBody(Item& aItem, const std::string& aBoundary) { std::istream& lStream = aItem.getStream(); std::string lLine; std::stringstream lBody; parseStartBoundary(lStream, aBoundary); while (lStream.good()) { parseHeaders(lStream); if (parseBody(lStream, aBoundary)) return; } }
bool PartHandler::parse( Stream* input, bool& isLast ) { TRACE( "Parsing...%s", "" ); // read the header and the body if ( ! parseHeader( input ) ) return false; // time to open the upload if ( ! startUpload() ) { return false; } bool v = parseBody( input, isLast ); closeUpload(); return v; }
static int parseDoc(Resolver * const me, char *docstr) { xmlDocPtr doc; xmlNodePtr cur; doc = xmlParseMemory(docstr, strlen(docstr)); if (doc == NULL ) { fprintf(stderr,"Document not parsed successfully. \n"); return -1; } cur = xmlDocGetRootElement(doc); if (cur == NULL) { fprintf(stderr,"empty document\n"); xmlFreeDoc(doc); return -1; } parseBody(me, cur); switch(me->CMTID) { case 0: break; case -1: fprintf(stderr,\ "document of the wrong type, gateway code check error"); break; case -9: fprintf(stderr,"document of the wrong type, root node != gateway"); break; default: fprintf(stderr,"unknow error!"); break; } xmlFreeDoc(doc); return 0; }
//处理读到body数据 void KAsyncFetchObject::handleReadBody(KHttpRequest *rq,int got) { assert(header); if (got<=0) { /////////[399] //assert(rq->send_ctx.body==NULL); /* 读body失败,对于未知长度,如果没有设置cache_no_length,则不缓存 */ lifeTime = -1; if (!TEST(rq->filter_flags,RF_CACHE_NO_LENGTH) || TEST(rq->ctx->obj->index.flags,(ANSW_CHUNKED|ANSW_HAS_CONTENT_LENGTH))) { SET(rq->ctx->obj->index.flags,FLAG_DEAD|OBJ_INDEX_UPDATE); } stage_rdata_end(rq,STREAM_WRITE_SUCCESS); return; } //解析body parseBody(rq,header,got); //解析完继续处理body数据 readBody(rq); }
EntityComponentTemplate *PhysicsEntityComponentFactory::createTemplate(TiXmlElement *xml) { // Create template PhysicsEntityComponentTemplate *tpl; tpl = new PhysicsEntityComponentTemplate(this); // Parse XML data // Bodies TiXmlNode *bodynode = xml->FirstChild("Body"); while (bodynode) { TiXmlElement *bodyelem = bodynode->ToElement(); if (!bodyelem) { bodynode = xml->IterateChildren("Body", bodynode); continue; } // Get body information PhysicsEntityComponentTemplate::BodyInfo info; if (parseBody(info, bodyelem)) { tpl->bodies.push_back(info); } bodynode = xml->IterateChildren("Body", bodynode); } // Character controllers for (TiXmlNode *charnode = xml->FirstChild("CharacterController"); charnode != 0; charnode = xml->IterateChildren("CharacterController", charnode)) { TiXmlElement *charelem = charnode->ToElement(); if (!charelem) continue; // Get character controller information PhysicsEntityComponentTemplate::CharacterInfo info; if (!charelem->Attribute("name")) continue; info.name = charelem->Attribute("name"); tpl->charcontrollers.push_back(info); } return tpl; }
bool Object::parse( ResourceManager *resMgr, Module *module, SSIZE_T &off, WORD objectInfoLen ) { // Need parse Object Info if (objectInfoLen && needObjectInfo()) { // Parse ObjectInfo if (!parseObjectInfo( module, off, objectInfoLen )) { printf( "[biop::Object] Warning, Cannot parse biop::ObjectInfo\n" ); return false; } } // Update offset to skip objectInfo off += objectInfoLen; // Read Service Context List Count BYTE serviceContextListCount; if (!module->readB( off, serviceContextListCount )) { printf( "[biop::Object] Warning, Cannot read bytes to parse ServiceContextList\n" ); return false; } // Parse Service Context List for (BYTE context=0; context<serviceContextListCount; context++) { if (!parseContext( module, off )) { printf( "[biop::Object] Warning, Cannot parse Service Context List: context=%d", context ); return false; } } // Skip body len DWORD bodyLen; if (!module->readDW( off, bodyLen )) { printf( "[biop::Object] Warning, Cannot parse body len" ); return false; } SSIZE_T old = off; off += bodyLen; // Parse body return parseBody( resMgr, module, old, bodyLen ); }
bool MultipartParser::parse(const uint8_t *d, size_t l, bool files) { data = Reader((const char *)d, l); origData = Reader((const char *)d, l); Reader str = readLine(); while (!str.empty()) { if (str.is("Content-Type:")) { str.offset("Content-Type:"_len); if (!parseContentType(str)) { return false; } } str = readLine(); } if (contentType.empty() || boundary.empty()) { return false; } readFiles = files; return parseBody(); }
ExprAST* Parser::handleForLoop() { lexer->NextToken(); // eat 'for' keyword if (lexer->token != '(') return Error("Expected '('"); lexer->NextToken(); // eat ( VariableDefAST* varDef = 0; ExprAST* varRef = 0; if (lexer->token == '[') varDef = handleVarDef(); if (lexer->token == Lexer::TOK_IDENTIFIER) varRef = parseExpression(); else return Error("Expected variable identifier"); if (lexer->token != ',') return Error("Expected ','"); lexer->NextToken(); // eat ',' ExprAST* untilCondition = parseExpression(); if (lexer->token != ',') return Error("Expected ','"); lexer->NextToken(); // eat ',' ExprAST* loopAction = parseExpression(); if (lexer->token != ')') return Error("Expected ')'"); lexer->NextToken(); // eat ')' bool hadErr; std::vector<ExprAST*> body = parseBody(hadErr); if (hadErr) return 0; return new ForLoopAST(varDef, varRef, untilCondition, loopAction, body); }
int InterpretCommand::execute(std::string arg) { std::cout << arg << std::endl; MethodState methodState; // TODO: Debug only; /* std::cout << arg << std::endl; */ bool status; try { status = parseBody(methodState, arg, "input"); if (!status) { std::cout << "Parsing failed for now reason!" << std::endl; return -1; } auto term = methodState.methodDeclaration->getBodyTerm(); std::cout << "parsed term: " << term->inspect() << std::endl; LexerTermBuilder builder; term->accept(&builder); auto astTerm = builder.getTerm(); std::cout << "built tree: " << astTerm->show() << std::endl; EvalTermVisitor evaluator(Context(mode->getClassTable())); astTerm->accept(evaluator); auto val = evaluator.getCalculatedValue(); std::cout << val->show() << std::endl; } catch (const pegtl::parse_error& e) { std::cout << "interpret: " << e.what() << std::endl; return -1; } /* std::cout << status << std::endl; */ return 0; }
Http_t Parse_parse (int fd) { http400 = generate400(); getToken(fd, 1); ReqLine_t reqline; Http_t http = 0; reqline = parseRequestLine (fd); parseHeaders(fd); if (token.kind!=TOKEN_CRLF) parseError(fd); parseBody(fd); http = Http_new (HTTP_KIND_REQUEST , reqline , 0 , 0 , 0); if (DEBUG) Http_print (1, http); return http; }