コード例 #1
0
input_receiver *TaggedSection::new_subsection(data_input *iInput)
{
    //a complete tag other than an open tag means an error
    if ( !tag_compare(iInput->receive_input(), OPEN_TAG) &&
            is_whole_tag(iInput->receive_input()) )
        return 0 /*NULL*/;

    storage_section *Return = 0 /*NULL*/;

    //other than an open tag means a data section
    if (!tag_compare(iInput->receive_input(), OPEN_TAG))
    {
        this->add_child(Return = new TaggedData);
        return Return;
    }

    //otherwise, add a new subsection
    this->add_child( Return = new TaggedSection(iInput->receive_input()) );

    //clear the open tag from the buffer
    iInput->next_input();

    //return the last element added
    return Return;
}
コード例 #2
0
bool TaggedSection::is_close_tag(data_input *iInput) const
{
    //compare to main closing tag if the main section
    if (IsMainSection && !tag_compare(iInput->receive_input(), CLOSE_MAIN))
        return false;

    //compare to subsection closing tag if not the main section
    if (!IsMainSection && !tag_compare(iInput->receive_input(), CLOSE_TAG))
        return false;

    iInput->next_input();
    return true;
}
コード例 #3
0
ファイル: relaylib.c プロジェクト: bh0085/programming
static int
header_receive (int sock, int *icy_metadata)
{
    fd_set fds;
    struct timeval tv;
    int r;
    char buf[BUFSIZE+1];
    char *md;

    *icy_metadata = 0;
        
    while (1) {
	// use select to prevent deadlock on malformed http header
	// that lacks CRLF delimiter
	FD_ZERO(&fds);
        FD_SET(sock, &fds);
        tv.tv_sec = 2;
        tv.tv_usec = 0;
        r = select (sock + 1, &fds, NULL, NULL, &tv);
        if (r != 1) {
	    debug_printf ("header_receive: could not select\n");
	    break;
	}

	r = recv(sock, buf, BUFSIZE, 0);
	if (r <= 0) {
	    debug_printf ("header_receive: could not select\n");
	    break;
	}

	buf[r] = 0;
	md = strtok (buf, HTTP_HEADER_DELIM);
	while (md) {
	    debug_printf ("Got token: %s\n", md);

	    // Finished when we are at end of header: only CRLF will be there.
	    if ((md[0] == '\r') && (md[1] == 0)) {
		debug_printf ("End of header\n");
		return 0;
	    }
	
	    // Check for desired tag
	    if (tag_compare (md, ICY_METADATA_TAG) == 0) {
		for (md += strlen(ICY_METADATA_TAG); md[0] && (isdigit(md[0]) == 0); md++);
		
		if (md[0])
		    *icy_metadata = atoi(md);

		debug_printf ("client flag ICY-METADATA is %d\n", 
			      *icy_metadata);
	    }
	    
	    md = strtok (NULL, HTTP_HEADER_DELIM);
	}
    }

    return 1;
}
コード例 #4
0
ファイル: tokenize.cpp プロジェクト: scorpion007/uncrustify
/**
 * Parses a C++0x 'R' string. R"( xxx )" R"tag(  )tag" u8R"(x)" uR"(x)"
 * Newlines may be in the string.
 */
static bool parse_cr_string(tok_ctx& ctx, chunk_t& pc, int q_idx)
{
   int cnt;
   int tag_idx = ctx.c.idx + q_idx + 1;
   int tag_len = 0;

   ctx.save();

   /* Copy the prefix + " to the string */
   pc.str.clear();
   cnt = q_idx + 1;
   while (cnt--)
   {
      pc.str.append(ctx.get());
   }

   /* Add the tag and get the length of the tag */
   while (ctx.more() && (ctx.peek() != '('))
   {
      tag_len++;
      pc.str.append(ctx.get());
   }
   if (ctx.peek() != '(')
   {
      ctx.restore();
      return(false);
   }

   pc.type = CT_STRING;
   while (ctx.more())
   {
      if ((ctx.peek() == ')') &&
          (ctx.peek(tag_len + 1) == '"') &&
          tag_compare(ctx.data, tag_idx, ctx.c.idx + 1, tag_len))
      {
         cnt = tag_len + 2;   /* for the )" */
         while (cnt--)
         {
            pc.str.append(ctx.get());
         }
         parse_suffix(ctx, pc);
         return(true);
      }
      if (ctx.peek() == '\n')
      {
         pc.str.append(ctx.get());
         pc.nl_count++;
         pc.type = CT_STRING_MULTI;
      }
      else
      {
         pc.str.append(ctx.get());
      }
   }
   ctx.restore();
   return(false);
} // parse_cr_string
コード例 #5
0
bool TaggedSection::is_subsection(data_input *iInput) const
{
    //anything that isn't a close tag is a subsection
    return !tag_compare(iInput->receive_input(), CLOSE_TAG) &&
           iInput->receive_input().size();
}