Example #1
0
    DnsResponse(const DnsHeader& head) : data(head.data),
                                         start(data-sizeof(struct dns_header) + sizeof(struct udp)),
                                         availableBytes(head.dnsPayloadLength),
                                         lastAliasOffset(0)
    {
        // std::cout << "DNS USEFUL DATA LEN: " << availableBytes << "\n";

        for (int i=0; i < head.questionNumber; i++)
        {
            ptrdiff_t offset = data - start;

            uint8_t* new_data = NULL;
    
            // fill the cache

            cachedNames[offset] = getQueryName(data, &new_data);

			// std::cout << "[DnsResponse] Query name: " << cachedNames[offset] << "\n";

            lastAliasOffset = offset;
 
            data = new_data + 4;

            availableBytes -= 4; // read qtype and qclass
        }

        
        // std::cout << "Read questions, available bytes: " << availableBytes << "\n";

        
        for (int i=0; i < head.answerRecordNumber; i++)
        {
            parseRecord();
        }

        // std::cout << "Read answers, available bytes: " << availableBytes << "\n";

        for (int i=0; i < head.authRecordNumber; i++)
        {
            parseRecord();

            // std::cout << "ReadING auth, available bytes: " << availableBytes << "\n";
        }

        for (int i=0; i < head.additionalRecordNumber; i++)
        {
            parseRecord();
        }

        // std::cout << "End of parsing, availableBytes: " << availableBytes << "\n";
    }
Example #2
0
static void parseTypes (tokenInfo * const token)
{
	tokenInfo *const name = newToken ();
	const vhdlKind kind = isKeyword (token, KEYWORD_TYPE) ?
		VHDLTAG_TYPE : VHDLTAG_SUBTYPE;
	Assert (isKeyword (token, KEYWORD_TYPE) ||
		isKeyword (token, KEYWORD_SUBTYPE));
	readToken (name);
	readToken (token);
	if (isKeyword (token, KEYWORD_IS))
	{
		readToken (token);	/* type */
		if (isKeyword (token, KEYWORD_RECORD))
		{
			makeVhdlTag (name, kind);
			/*TODO: make tags of the record's names */
			parseRecord (token);
		}
		else
		{
			makeVhdlTag (name, kind);
		}
	}
	deleteToken (name);
}
Example #3
0
static void parseType (tokenInfo *const token)
{
    tokenInfo *const name = newToken ();
    readToken (name);
    if (isType (name, TOKEN_IDENTIFIER))
    {
	readToken (token);
	if (isKeyword (token, KEYWORD_is))
	{
	    readToken (token);
	    switch (token->keyword)
	    {
		case KEYWORD_record:
		    makeSqlTag (name, SQLTAG_RECORD);
		    parseRecord (token);
		    break;

		case KEYWORD_table:
		    makeSqlTag (name, SQLTAG_TABLE);
		    break;

		case KEYWORD_ref:
		    readToken (token);
		    if (isKeyword (token, KEYWORD_cursor))
			makeSqlTag (name, SQLTAG_CURSOR);
		    break;

		default: break;
	    }
	}
    }
    deleteToken (name);
}
Record* parseRecords(char* file_name, int MAX_CHARS_PER_LINE){
    int numRecords = countLines(file_name);
    int currentPos = 0;
    Record* records = (Record *) malloc(numRecords * sizeof(Record));
    //char current_line[MAX_CHARS_PER_LINE];
    FILE* fp_read;

    if (!(fp_read= fopen ( file_name , "r" )))  {
        printf ("Could not open file \"%s\" for reading \n", file_name);
        return records;
    }
    Record* temp = parseRecord(fp_read, MAX_CHARS_PER_LINE);
    while (temp != NULL){
        records[currentPos] = *temp;
        currentPos+=1;
        temp = parseRecord(fp_read, MAX_CHARS_PER_LINE);
    }
    fclose(fp_read);

    return records;
}
Example #5
0
void MemDbLoader::parseTable(const QDomElement & elemSource)
{
    _tableName = elemSource.attribute("name");
    _columnNames.clear();

    QDomNodeList nlist = elemSource.childNodes();
    for(int i = 0; i < nlist.count(); i++ ) {
        QDomElement it = nlist.item(i).toElement();
        if(it.tagName()=="columns") {
            parseColumns(it);
        }
        else if(it.tagName()=="record") {
            parseRecord(it);
        }
    }
}
Example #6
0
static void parseTable (tokenInfo *const token)
{
    tokenInfo *const name = newToken ();
    readToken (name);
    readToken (token);
    if (isType (token, TOKEN_OPEN_PAREN))
    {
	if (isType (name, TOKEN_IDENTIFIER))
	{
	    makeSqlTag (name, SQLTAG_TABLE);
	    parseRecord (token);
	}
    }
    findToken (token, TOKEN_SEMICOLON);
    deleteToken (name);
}
void UnwrappedLineParser::parseStructuralElement() {
  assert(!FormatTok->Tok.is(tok::l_brace));
  switch (FormatTok->Tok.getKind()) {
  case tok::at:
    nextToken();
    if (FormatTok->Tok.is(tok::l_brace)) {
      parseBracedList();
      break;
    }
    switch (FormatTok->Tok.getObjCKeywordID()) {
    case tok::objc_public:
    case tok::objc_protected:
    case tok::objc_package:
    case tok::objc_private:
      return parseAccessSpecifier();
    case tok::objc_interface:
    case tok::objc_implementation:
      return parseObjCInterfaceOrImplementation();
    case tok::objc_protocol:
      return parseObjCProtocol();
    case tok::objc_end:
      return; // Handled by the caller.
    case tok::objc_optional:
    case tok::objc_required:
      nextToken();
      addUnwrappedLine();
      return;
    default:
      break;
    }
    break;
  case tok::kw_namespace:
    parseNamespace();
    return;
  case tok::kw_inline:
    nextToken();
    if (FormatTok->Tok.is(tok::kw_namespace)) {
      parseNamespace();
      return;
    }
    break;
  case tok::kw_public:
  case tok::kw_protected:
  case tok::kw_private:
    parseAccessSpecifier();
    return;
  case tok::kw_if:
    parseIfThenElse();
    return;
  case tok::kw_for:
  case tok::kw_while:
    parseForOrWhileLoop();
    return;
  case tok::kw_do:
    parseDoWhile();
    return;
  case tok::kw_switch:
    parseSwitch();
    return;
  case tok::kw_default:
    nextToken();
    parseLabel();
    return;
  case tok::kw_case:
    parseCaseLabel();
    return;
  case tok::kw_try:
    parseTryCatch();
    return;
  case tok::kw_extern:
    nextToken();
    if (FormatTok->Tok.is(tok::string_literal)) {
      nextToken();
      if (FormatTok->Tok.is(tok::l_brace)) {
        parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
        addUnwrappedLine();
        return;
      }
    }
    break;
  case tok::identifier:
    if (FormatTok->IsForEachMacro) {
      parseForOrWhileLoop();
      return;
    }
    // In all other cases, parse the declaration.
    break;
  default:
    break;
  }
  do {
    switch (FormatTok->Tok.getKind()) {
    case tok::at:
      nextToken();
      if (FormatTok->Tok.is(tok::l_brace))
        parseBracedList();
      break;
    case tok::kw_enum:
      parseEnum();
      break;
    case tok::kw_typedef:
      nextToken();
      // FIXME: Use the IdentifierTable instead.
      if (FormatTok->TokenText == "NS_ENUM")
        parseEnum();
      break;
    case tok::kw_struct:
    case tok::kw_union:
    case tok::kw_class:
      parseRecord();
      // A record declaration or definition is always the start of a structural
      // element.
      break;
    case tok::semi:
      nextToken();
      addUnwrappedLine();
      return;
    case tok::r_brace:
      addUnwrappedLine();
      return;
    case tok::l_paren:
      parseParens();
      break;
    case tok::caret:
      nextToken();
      if (FormatTok->Tok.isAnyIdentifier() ||
          FormatTok->isSimpleTypeSpecifier())
        nextToken();
      if (FormatTok->is(tok::l_paren))
        parseParens();
      if (FormatTok->is(tok::l_brace))
        parseChildBlock();
      break;
    case tok::l_brace:
      if (!tryToParseBracedList()) {
        // A block outside of parentheses must be the last part of a
        // structural element.
        // FIXME: Figure out cases where this is not true, and add projections
        // for them (the one we know is missing are lambdas).
        if (Style.BreakBeforeBraces != FormatStyle::BS_Attach)
          addUnwrappedLine();
        FormatTok->Type = TT_FunctionLBrace;
        parseBlock(/*MustBeDeclaration=*/false);
        addUnwrappedLine();
        return;
      }
      // Otherwise this was a braced init list, and the structural
      // element continues.
      break;
    case tok::kw_try:
      // We arrive here when parsing function-try blocks.
      parseTryCatch();
      return;
    case tok::identifier: {
      StringRef Text = FormatTok->TokenText;
      if (Style.Language == FormatStyle::LK_JavaScript && Text == "function") {
        tryToParseJSFunction();
        break;
      }
      nextToken();
      if (Line->Tokens.size() == 1) {
        if (FormatTok->Tok.is(tok::colon)) {
          parseLabel();
          return;
        }
        // Recognize function-like macro usages without trailing semicolon.
        if (FormatTok->Tok.is(tok::l_paren)) {
          parseParens();
          if (FormatTok->NewlinesBefore > 0 &&
              tokenCanStartNewLine(FormatTok->Tok) && Text == Text.upper()) {
            addUnwrappedLine();
            return;
          }
        } else if (FormatTok->HasUnescapedNewline && Text.size() >= 5 &&
                   Text == Text.upper()) {
          // Recognize free-standing macros like Q_OBJECT.
          addUnwrappedLine();
          return;
        }
      }
      break;
    }
    case tok::equal:
      nextToken();
      if (FormatTok->Tok.is(tok::l_brace)) {
        parseBracedList();
      }
      break;
    case tok::l_square:
      parseSquare();
      break;
    default:
      nextToken();
      break;
    }
  } while (!eof());
}
Example #8
0
		const  char *parseRecord(QVariant &res, const  char *s, int *maxLength)
		{
			return reinterpret_cast<const char *>(parseRecord(res,
															  reinterpret_cast<const uchar *>(s),
															  maxLength));
		}
Example #9
0
RecordPtr Common::parseRecord(const std::string& json)
{
  return parseRecord(toJSON(json));
}