示例#1
0
文件: log.c 项目: matthewtemple/h2010
/*
  TODO: test return codes
*/
char *format_entry(char *entry)
{
  assert(entry);
  char *formatted_entry;
  unsigned short line_end;
  char *entry_start;

  formatted_entry = NULL;
  entry_start = entry;

  line_end = find_line_end(entry_start, MAX_LINE_LENGTH);
  while (line_end > 0) {
    formatted_entry = h_core_string_append_n(formatted_entry,
        entry_start, line_end);
    formatted_entry = h_core_string_append_char(formatted_entry, '\n');
    entry_start += line_end;
    line_end = find_line_end(entry_start, MAX_LINE_LENGTH
        - (H_CORE_TIME_STRING_LENGTH + 1 + 1 + 4 + 1 + 3));
    if (line_end > 0) {
      formatted_entry = h_core_string_append
        (formatted_entry, "                         ");
    }
  }

  return formatted_entry;
}
示例#2
0
static char *FFMultiPartHeaderParam(const char *header, int hlen, const char *param)
{
    const char *line, *eol, *lineend, *hend, *c;
    char *ret;
    int len, host_len, param_len;

    line = header;
    len = hlen;
    hend = header + len;
    lineend = NULL;
    ret = NULL;
    param_len = strlen(param);
    while (lineend < hend) {
        lineend = find_line_end(line, line+len, &eol);
        if (lineend != line+len && (*eol == '\r' || *eol == '\n')) {
            if (strncasecmp(line, param, param_len) == 0) {
                c = line + param_len;
                while (*c == ' ' && c < lineend)
                    c++;
                host_len = eol - c;
                ret = xmalloc(host_len + 1);
                memcpy(ret, c, host_len);
                ret[host_len] = '\0';
                break;
            }
        }
        line = lineend;
        len = hend - lineend;
    }

    return ret;
}
示例#3
0
文件: lwan-config.c 项目: nining/lwan
bool config_read_line(config_t *conf, config_line_t *l)
{
    char *line, *line_end;

    if (conf->error_message)
        return false;

retry:
    if (!fgets(l->buffer, sizeof(l->buffer), conf->file))
        return false;

    if (conf->isolated.end > 0) {
        long curpos = ftell(conf->file);
        if (curpos < 0) {
            config_error(conf, "Could not obtain file position");
            return false;
        }
        if (curpos >= conf->isolated.end)
            return false;
    }
    conf->line++;

    line = remove_comments(l->buffer);
    line = remove_leading_spaces(line);
    line = remove_trailing_spaces(line);
    line_end = find_line_end(line);

    if (*line_end == '{') {
        if (!parse_section(line, l, line_end)) {
            config_error(conf, "Malformed section opening");
            return false;
        }
    } else if (*line == '\0') {
        goto retry;
    } else if (*line == '}' && line == line_end) {
        l->type = CONFIG_LINE_TYPE_SECTION_END;
    } else {
        char *equal = strchr(line, '=');
        if (equal) {
            if (!parse_line(line, l, equal)) {
                config_error(conf, "Malformed key=value line");
                return false;
            }
        } else {
            config_error(conf, "Expecting section or key=value");
            return false;
        }
    }

    return true;
}
示例#4
0
文件: file.c 项目: 8l/aoeui
static void scan(struct view *view)
{
	char *raw, scratch[8];
	position_t at;
	size_t bytes = view_raw(view, &raw, 0, getpagesize());
	size_t chop = bytes < view->bytes ? 8 : 0;
	size_t chlen, check;
	Unicode_t ch, lastch = 0;
	int crnl = 0, nl = 0;
	Boolean_t any_tab = default_tabs;
	int tabstop = default_tab_stop;

	/* Reset state */
	view->text->flags &= ~(TEXT_NO_UTF8 | TEXT_CRNL | TEXT_NO_TABS);
	view->text->tabstop = default_tab_stop;

	if (utf8_mode == UTF8_NO)
		view->text->flags |= TEXT_NO_UTF8;
	else if (utf8_mode == UTF8_AUTO)
		for (at = 0; at + chop < bytes; at += chlen) {
			chlen = utf8_length(raw + at, bytes - at);
			ch = utf8_unicode(raw + at, chlen);
			check = unicode_utf8(scratch, ch);
			if (chlen != check) {
				view->text->flags |= TEXT_NO_UTF8;
				break;
			}
		}

	for (at = 0; at + chop < bytes; lastch = ch)
		if ((ch = view_unicode(view, at, &at)) == '\n') {
			nl++;
			crnl += lastch == '\r';
		}
	if (nl && crnl == nl)
		view->text->flags |= TEXT_CRNL;

	for (at = 0; at + chop < bytes; at = find_line_end(view, at) + 1) {
		int spaces = 0;
		while ((ch = view_unicode(view, at, &at)) == ' ')
			spaces++;
		if (ch == '\t')
			any_tab = TRUE;
		if (spaces > 1 && spaces < tabstop)
			tabstop = spaces;
	}
	if (default_no_tabs || !any_tab) {
		view->text->flags |= TEXT_NO_TABS;
		view->text->tabstop = tabstop;
	}
}
static void
display_ping_and_tracert(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, socks_hash_entry_t *hash_info) {

/* Display the ping/trace_route conversation */


       	const guchar    *data, *dataend;
       	const guchar   *lineend, *eol;
       	int             linelen;

					/* handle the end command */
       	if ( pinfo->destport == TCP_PORT_SOCKS){
		col_append_str(pinfo->cinfo, COL_INFO, ", Terminate Request");

		if ( tree)
  			proto_tree_add_text(tree, tvb, offset, 1,
   				(hash_info->command  == PING_COMMAND) ?
				"Ping: End command" :
	   			"Traceroute: End command");
	}
       	else{ 		/* display the PING or Traceroute results */
		col_append_str(pinfo->cinfo, COL_INFO, ", Results");

		if ( tree){
			proto_tree_add_text(tree, tvb, offset, -1,
   				(hash_info->command  == PING_COMMAND) ?
   				"Ping Results:" :
   				"Traceroute Results");

  	      		data = tvb_get_ptr(tvb, offset, -1);
        		dataend = data + tvb_length_remaining(tvb, offset);

       	        	while (data < dataend) {

              			lineend = find_line_end(data, dataend, &eol);
                		linelen = (int)(lineend - data);

       		                proto_tree_add_text( tree, tvb, offset, linelen,
       		                	"%s", format_text(data, linelen));
               		        offset += linelen;
                       		data = lineend;
                       	}
		}
	}
}