예제 #1
0
파일: log.c 프로젝트: Mortal/claws
void log_status_skip(LogInstance instance, const gchar *format, ...)
{
	va_list args;
	gchar buf[BUFFSIZE + LOG_TIME_LEN];
	time_t t;
	LogText *logtext = g_new0(LogText, 1);
	struct tm buft;

	time(&t);
	strftime(buf, LOG_TIME_LEN + 1, "[%H:%M:%S] ", localtime_r(&t, &buft));

	va_start(args, format);
	g_vsnprintf(buf + LOG_TIME_LEN, BUFFSIZE, format, args);
	va_end(args);

	if (debug_get_mode()) g_message("%s", buf + LOG_TIME_LEN);

	logtext->instance = instance;
	logtext->text = g_strdup(buf + LOG_TIME_LEN);
	logtext->type = LOG_STATUS_SKIP;
	
	g_timeout_add(0, invoke_hook_cb, logtext);

	if (log_fp[instance] && prefs_common_enable_log_status()) {
		FWRITE(buf, 1, LOG_TIME_LEN, log_fp[instance])
		FPUTS("* SKIPPED: ", log_fp[instance])
		log_size[instance] += strlen("* SKIPPED: ");
		FPUTS(buf + LOG_TIME_LEN, log_fp[instance])
		log_size[instance] += strlen(buf);
		FFLUSH(log_fp[instance])
		rotate_log(instance);
	}
}
예제 #2
0
파일: log.c 프로젝트: aixoss/wget
void
logputs (enum log_options o, const char *s)
{
  FILE *fp;
  FILE *warcfp;

  check_redirect_output ();
  if (o == LOG_PROGRESS)
    fp = get_progress_fp ();
  else
    fp = get_log_fp ();

  if (fp == NULL)
    return;

  warcfp = get_warc_log_fp ();
  CHECK_VERBOSE (o);

  FPUTS (s, fp);
  if (warcfp != NULL)
    FPUTS (s, warcfp);
  if (save_context_p)
    saved_append (s);
  if (flush_log_p)
    logflush ();
  else
    needs_flushing = true;
}
int print_code(FILE * o, const PageTable & pt, const vaddr_t & rip)
{
    int len = 0;
    vaddr_t ip = rip - 15;
    uint8_t d;

    len += FPUTS("\t  ", o);

    try
    {
        for ( int i = 0; i < 32; ++i )
        {
            memory.read8_vaddr(pt, ip + i, d);
            if ( (ip + i) == rip )
                len += FPRINTF(o, " <%02"PRIx8">", d);
            else
                len += FPRINTF(o, " %02"PRIx8, d);
        }
    }
    catch ( const CommonError & e )
    {
        e.log();
    }

    len += FPUTS("\n", o);

    return len;
}
예제 #4
0
파일: log.c 프로젝트: DonCN/haiku
/* Dump saved lines to logfp. */
static void
log_dump_context (void)
{
  int num = log_line_current;
  FILE *fp = get_log_fp ();
  if (!fp)
    return;

  if (num == -1)
    return;
  if (trailing_line)
    ROT_ADVANCE (num);
  do
    {
      struct log_ln *ln = log_lines + num;
      if (ln->content)
        FPUTS (ln->content, fp);
      ROT_ADVANCE (num);
    }
  while (num != log_line_current);
  if (trailing_line)
    if (log_lines[log_line_current].content)
      FPUTS (log_lines[log_line_current].content, fp);
  fflush (fp);
}
int print_32bit_stack(FILE * o, const PageTable & pt, const vaddr_t & rsp,
                      const size_t count)
{
    int len = 0;
    const int WS = 4; // Word size in bytes
    const int WPL = 8; // Words per line
    const int mask = WS*WPL -1;

    uint32_t val;
    uint64_t sp = rsp;
    uint64_t end;
    uint64_t align;

    if ( rsp & (WS-1) )
        return len + FPUTS("\t  Stack pointer mis-aligned\n", o);

    if ( ! count )
        end = ((rsp | (PAGE_SIZE-1))+1);
    else
        end = rsp + count * WS;

    if ( ((rsp | sp | end) & 0xffffffff00000000ULL) )
    {
        len += FPRINTF(o, "%016"PRIx64" %016"PRIx64" %016"PRIx64"\n", rsp, sp, end);
        return len + FPUTS("\t Stack pointer out of range for 32bit "
                           "Virtual Address space\n", o);
    }

    align = (sp & mask)/WS;
    if ( align )
    {
        len += FPRINTF(o, "\n\t  %08"PRIx64":", sp & ~mask);
        while ( align-- )
            len += FPRINTF(o, " %8s", "");

    }

    try
    {
        for ( ; sp < end; sp += WS )
        {
            if ( !(sp & mask) )
                len += FPRINTF(o, "\n\t  %08"PRIx64":", sp);
            memory.read32_vaddr(pt, sp, val);
            len += FPRINTF(o, " %08"PRIx32, val);
        }
    }
    catch ( const CommonError & e )
    {
        e.log();
    }

    len += FPUTS("\n", o);
    return len;
}
예제 #6
0
simple_output &simple_output::simple_comment(const char *s)
{
  flush_last_word();
  if (col != 0)
    PUTC('\n', fp);
  FPUTS("<!-- ", fp);
  FPUTS(s, fp);
  FPUTS(" -->\n", fp);
  col = 0;
  return *this;
}
예제 #7
0
/* Write a header for the memo */
static int write_convert_header(FILE *p_outfile, char *p_memo_name)
{
  /* Write some header information and the filename */
  FPUTS("/* Don't change this file! It is auto-generated! */\n\n", p_outfile);
  FPUTS("#define FILENAME \"", p_outfile);
  FPUTS(p_memo_name, p_outfile);
  FPUTS("\"\n\n", p_outfile);

  /* Start of the data */
  FPUTS("char *pp_file_data[]={", p_outfile);

  return 0;
}
예제 #8
0
    int Payload::print_state(FILE * stream) const
    {
        int len = 0;

        len += FPRINTF(stream, "  Payload %s:\n", name);
        len += FPRINTF(stream, "    at address 0x%016"PRIx64"\n", payload_addr);
        len += FPRINTF(stream, "    state %d\n", state);
        len += FPRINTF(stream, "    rc %d\n", rc);
        if ( buildid )
        {
            len += FPRINTF(stream, "    buildid ");

            for ( unsigned int i = 0; i < buildid_len; i++ )
                len += FPRINTF(stream, "%02x", buildid[i]);

            len += FPUTS("\n", stream);
        }
        len += FPRINTF(stream, "    text [0x%016"PRIx64"-0x%016"PRIx64"]\n",
                       text_addr, text_end - 1);
        if ( rw_end > rw_addr )
            len += FPRINTF(stream, "    rw   [0x%016"PRIx64"-0x%016"PRIx64"]\n",
                           rw_addr, rw_end - 1);
        if ( ro_end > ro_addr )
            len += FPRINTF(stream, "    ro   [0x%016"PRIx64"-0x%016"PRIx64"]\n",
                           ro_addr, ro_end - 1);

        return len;
    }
int print_64bit_stack(FILE * o, const PageTable & pt, const vaddr_t & rsp,
                      const size_t count)
{
    int len = 0;
    const int WS = 8; // Word size in bytes
    const int WPL = 4; // Words per line
    const int mask = WS*WPL -1;

    uint64_t val;
    uint64_t sp = rsp;
    uint64_t end;
    uint64_t align;

    if ( rsp & (WS-1) )
        return len + FPUTS("\n\t  Stack pointer mis-aligned\n", o);

    if ( ! count )
        end = ((rsp | (PAGE_SIZE-1))+1);
    else
        end = rsp + count * WS;

    align = (sp & mask)/WS;
    if ( align )
    {
        len += FPRINTF(o, "\n\t  %016"PRIx64":", sp & ~mask);
        while ( align-- )
            len += FPRINTF(o, " %16s", "");
    }

    try
    {
        for ( ; sp < end; sp += WS )
        {
            if ( !(sp & mask) )
                len += FPRINTF(o, "\n\t  %016"PRIx64":", sp);
            memory.read64_vaddr(pt, sp, val);
            len += FPRINTF(o, " %016"PRIx64, val);
        }
    }
    catch ( const CommonError & e )
    {
        e.log();
    }

    len += FPUTS("\n", o);
    return len;
}
int SymbolTable::print_symbol32(FILE * o, const vaddr_t & addr, bool brackets) const
{
    int len = 0;

    if ( ! this->can_print )
        return 0;

    if ( ! this->is_text_symbol(addr) )
        return 0;

    SymbolTable::const_list_iter after
        = std::upper_bound(this->symbols.begin(), this->symbols.end(), addr, &SymbolTable::symcmp);

    if ( after == this->symbols.begin() ||
         after == this->symbols.end() )
        return 0;

    SymbolTable::const_list_iter before = after;
    before--;

    if ( (*before)->address <= addr && (*after)->address > addr )
    {
        len += FPUTS("\t ", o);
        if ( brackets )
            len += FPRINTF(o, "[%08"PRIx64"]", addr);
        else
            len += FPRINTF(o, " %08"PRIx64" ", addr);

        len += FPRINTF(o, " %s+%#"PRIx64"/%#"PRIx64,
                       (*before)->name,
                       addr - (*before)->address,
                       (*after)->address - (*before)->address );

        if ( ! std::strcmp((*before)->name, "hypercall_page") )
        {
            unsigned int nr = (unsigned int)((addr - (*before)->address)/32);
            len += FPRINTF(o, " (%d, %s)", nr, hypercall_name(nr));
        }

        len += FPUTS("\n", o);
    }
    else
        LOG_WARN("Strange resulting iterators printing symbol 0x%016"PRIx64"\n", addr);

    return len;
}
예제 #11
0
void simple_output::flush_last_word (void)
{
  int len=last_word.get_length();

  if (len > 0) {
    if (newlines) {
      if (col + len + 1 > max_line_length) {
	FPUTS("\n", fp);
	col = 0;
      } else {
	FPUTS(" ", fp);
	col++;
      }
      len += last_word.flush(fp);
    } else {
      FPUTS(" ", fp);
      col++;
      col += last_word.flush(fp);
    }
  }
}
예제 #12
0
/* Write a footer for the memo */
static int write_convert_footer(FILE *p_outfile, int nr_chunks)
{
  /* End of the outfile */
  FPUTS("};\n\n", p_outfile);
  /* Output the number of chunks */
  if (fprintf(p_outfile, "#define NR_CHUNKS %d\n", nr_chunks) <= 0)
    {
      fprintf(stderr, "convert_file(): error in fprintf\n");
      return -1;
    }


  return 0;
}
예제 #13
0
파일: log.c 프로젝트: DonCN/haiku
void
logputs (enum log_options o, const char *s)
{
  FILE *fp;

  check_redirect_output ();
  if ((fp = get_log_fp ()) == NULL)
    return;
  CHECK_VERBOSE (o);

  FPUTS (s, fp);
  if (save_context_p)
    saved_append (s);
  if (flush_log_p)
    logflush ();
  else
    needs_flushing = true;
}
static int
do_test (void)
{
  FILE *fp = tmpfile ();
  if (fp == NULL)
    {
      puts ("cannot open file");
      return 1;
    }

  FPUTS (L("7-11"), fp);
  rewind (fp);

  printf("setting errno to EINTR\n");
  errno = EINTR;

  printf("checking sscanf\n");

  int i, j, n;

  i = j = n = 0;
  FSCANF (fp, L(" %i - %i %n"), &i, &j, &n);
  printf ("found %i-%i (length=%i)\n", i, j, n);

  int result = 0;
  if (i != 7)
    {
      printf ("i is %d, expected 7\n", i);
      result = 1;
    }
  if (j != 11)
    {
      printf ("j is %d, expected 11\n", j);
      result = 1;
    }
  if (n != 4)
    {
      printf ("n is %d, expected 4\n", j);
      result = 1;
    }

  return result;
}
예제 #15
0
int word_list::flush (FILE *f)
{
  word *t;
  int   len=length;

  while (head != 0) {
    t = head;
    head = head->next;
    FPUTS(t->s, f);
    delete t;
  }
  head   = 0;
  tail   = 0;
  length = 0;
#if defined(DEBUGGING)
  fflush(f);   // just for testing
#endif
  return( len );
}
예제 #16
0
/* Convert a text file to C-source */
static int convert_file(FILE *p_infile, FILE *p_outfile, char *p_memo_name)
{
  static int first=1;
  static int line=0;
  static int chars=0;
  int nr_chunks=1;
  char buf[255];
  char *p;

  /* For each line in the infile */
  while( (p = fgets(buf, 255, p_infile)) )
    {
      /* Remove linefeeds from the input */
      while (strlen(p) >= 1 &&
	  (p[strlen(p)-1] == '\n' ||
	   p[strlen(p)-1] == '\r'))
	p[strlen(p)-1] = '\0';

      /* Do not indent the first chunk */
      if (first)
	{
	  FPUTS("\"", p_outfile);
	  first = 0;
	}
      else
	FPUTS("                      \"", p_outfile);

      FPUTS(p, p_outfile);
      chars += strlen(p);
      line++;

      /* Is this the last entry? */
      if (!feof(p_infile))
	{
	  /* Every 5th line starts a new chunk */
	  if (chars > 300)
	    {
	      FPUTS("\\r\",\n\n", p_outfile);
	      nr_chunks++;
	      chars = 0;
	    }
	  else
	    FPUTS("\\r\"\n", p_outfile);
	}
      else
	FPUTS("\"", p_outfile);
    }

  return nr_chunks;
}
예제 #17
0
    int VCPU::print_state(FILE * o) const
    {
        int len = 0;

        if ( ! this->is_online() )
            return len + FPUTS("\tVCPU Offline\n\n", o);

        if ( this->flags & CPU_PV_COMPAT )
            return len + this->print_state_compat(o);

        if ( this->flags & CPU_GP_REGS )
        {
            len += FPRINTF(o, "\tRIP:    %04x:[<%016"PRIx64">] Ring %d\n",
                           this->regs.cs, this->regs.rip, this->regs.cs & 0x3);
            len += FPRINTF(o, "\tRFLAGS: %016"PRIx64" ", this->regs.rflags);
            len += print_rflags(o, this->regs.rflags);
            len += FPUTS("\n\n", o);

            len += FPRINTF(o, "\trax: %016"PRIx64"   rbx: %016"PRIx64"   rcx: %016"PRIx64"\n",
                           this->regs.rax, this->regs.rbx, this->regs.rcx);
            len += FPRINTF(o, "\trdx: %016"PRIx64"   rsi: %016"PRIx64"   rdi: %016"PRIx64"\n",
                           this->regs.rdx, this->regs.rsi, this->regs.rdi);
            len += FPRINTF(o, "\trbp: %016"PRIx64"   rsp: %016"PRIx64"   r8:  %016"PRIx64"\n",
                           this->regs.rbp, this->regs.rsp, this->regs.r8);
            len += FPRINTF(o, "\tr9:  %016"PRIx64"   r10: %016"PRIx64"   r11: %016"PRIx64"\n",
                           this->regs.r9,  this->regs.r10, this->regs.r11);
            len += FPRINTF(o, "\tr12: %016"PRIx64"   r13: %016"PRIx64"   r14: %016"PRIx64"\n",
                           this->regs.r12, this->regs.r13, this->regs.r14);
            len += FPRINTF(o, "\tr15: %016"PRIx64"\n",
                           this->regs.r15);
        }

        if ( this->flags & CPU_CR_REGS )
        {
            len += FPUTS("\n", o);
            len += FPRINTF(o, "\tcr3: %016"PRIx64"\n", this->regs.cr3);
        }

        if ( this->flags & CPU_GP_REGS )
        {
            len += FPUTS("\n", o);

            if ( this->flags & CPU_SEG_REGS )
                len += FPRINTF(o, "\tds: %04"PRIx16"   es: %04"PRIx16"   "
                               "fs: %04"PRIx16"   gs: %04"PRIx16"   "
                               "ss: %04"PRIx16"   cs: %04"PRIx16"\n",
                               this->regs.ds, this->regs.es, this->regs.fs,
                               this->regs.gs, this->regs.ss, this->regs.cs);
            else
                len += FPRINTF(o, "\tss: %04"PRIx16"   cs: %04"PRIx16"\n",
                               this->regs.ss, this->regs.cs);
        }

        len += FPUTS("\n", o);

        len += FPRINTF(o, "\tPause Count: %"PRId32", Flags: 0x%"PRIx32" ",
                       this->pause_count, this->pause_flags);
        len += print_pause_flags(o, this->pause_flags);
        len += FPUTS("\n", o);

        switch ( this->runstate )
        {
        case RST_NONE:
            len += FPRINTF(o, "\tNot running:  Last run on PCPU%"PRIu32"\n", this->processor);
            break;
        case RST_RUNNING:
            len += FPRINTF(o, "\tCurrently running on PCPU%"PRIu32"\n", this->processor);
            break;
        case RST_CTX_SWITCH:
            len += FPUTS("\tBeing Context Switched:  State unreliable\n", o);
            break;
        default:
            len += FPUTS("\tUnknown runstate\n", o);
            break;
        }
        len += FPRINTF(o, "\tStruct vcpu at %016"PRIx64"\n", this->vcpu_ptr);

        len += FPUTS("\n", o);

        if ( this->flags & CPU_GP_REGS &&
             this->flags & CPU_CR_REGS &&
             ( this->paging_support == VCPU::PAGING_NONE ||
               this->paging_support == VCPU::PAGING_SHADOW )
            )
        {
            len += FPRINTF(o, "\tStack at %16"PRIx64":", this->regs.rsp);
            len += print_64bit_stack(o, *this->dompt, this->regs.rsp);

            len += FPUTS("\n\tCode:\n", o);
            len += print_code(o, *this->dompt, this->regs.rip);

            len += FPUTS("\n\tCall Trace:\n", o);
            if ( this->domid == 0 )
            {
                vaddr_t sp = this->regs.rsp;
                vaddr_t top = (this->regs.rsp | (PAGE_SIZE-1))+1;
                uint64_t val;

                len += host.dom0_symtab.print_symbol64(o, this->regs.rip, true);

                try
                {
                    while ( sp < top )
                    {
                        memory.read64_vaddr(*this->dompt, sp, val);
                        len += host.dom0_symtab.print_symbol64(o, val);
                        sp += 8;
                    }
                }
                catch ( const CommonError & e )
                {
                    e.log();
                }
            }
            else
                len += FPUTS("\t  No symbol table for domain\n", o);

            len += FPUTS("\n", o);
        }
        return len;
    }
예제 #18
0
void parse(char *country_input,
	   char *path_input,
	   char *domain_input,
	   char *ipaddress_input,
	   char *http_status_input,
	   char *referer_input,
	   char *bird,
	   char *db_path,
	   int minimum_field_count) {

	// GENERIC VARIABLES
	char *fields[MAX_FIELD_CNT];       // number of fields we expect in a single line
	int num_filters             = 0;   // total number of filters we detect from the command line
	int num_domain_filters      = 0;   // total number of domain filters
	int num_path_filters        = 0;   // total number of path filters
	int num_ipaddress_filters   = 0;   // total number of ipaddress filter
	int num_countries_filters   = 0;   // total number countries we want to restrict the filtering
	int num_http_status_filters = 0;   // total number of http status we want to restrict the filtering.
	int num_referer_filters     = 0;
	int required_hits           = 0;
	int bird_int                = 0;
	int i;

	int field_count_this_line=0;  // number of fields found in the current line

	char line[ LINE_BUF_SIZE ];
	char *ipaddr;
	char *url;
	char *http_status;
	char *referer;


	// DETERMINE NUMBER OF FILTERS
	if(params[DOMAIN_FILTER]){
		num_domain_filters = determine_num_obs(domain_input,comma_delimiter);
		required_hits+=1;
	}
	if(params[PATH_FILTER]){
		num_path_filters = determine_num_obs(path_input,comma_delimiter);
		required_hits+=1;
	}
	if(params[IP_FILTER]){
		num_ipaddress_filters = determine_num_obs(ipaddress_input, comma_delimiter);
		required_hits+=1;
	}
	if(params[GEO_FILTER]){
		if(country_input != NULL && strlen(country_input) >1){
			num_countries_filters = determine_num_obs(country_input, comma_delimiter);
			required_hits+=1;
		}
	}
	if(params[REFERER_FILTER]){
		num_referer_filters = determine_num_obs(referer_input, comma_delimiter);
		required_hits+=1;
	}
	if(params[HTTP_STATUS_FILTER]){
		if(http_status_input != NULL && strlen(http_status_input) >1){
			num_http_status_filters = determine_num_obs(http_status_input, comma_delimiter);
			required_hits+=1;
		}
	}

	num_filters = num_path_filters + num_domain_filters + num_ipaddress_filters
		+ num_countries_filters + num_http_status_filters + num_referer_filters;
	Filter filters[num_filters];

	// GEO_FILTER INITIALIZATION
	GeoIP *gi = NULL;    // initialize to suppress compiler warning
	char *countries[num_countries_filters];
	char *area;

	// FILTER INITIALIZATION
	if(params[DOMAIN_FILTER]){
		init_domains(filters, domain_input, comma_delimiter);
	} else {
		domain_input=NULL;
	}

	if(params[PATH_FILTER]){
		init_paths(filters, path_input, comma_delimiter);
	} else {
		path_input = NULL;
	}

	if(params[IP_FILTER]){
		init_ip_addresses(filters, ipaddress_input, comma_delimiter);
	} else {
		ipaddress_input = NULL;
	}

	if (params[REFERER_FILTER]){
		init_domains(filters, referer_input, comma_delimiter);
	} else {
		referer_input = NULL;
	}

	if( ! (params[GEO_FILTER] || (recode & GEO)) ) {
		country_input = NULL;
	} else {
		init_countries(countries, country_input, num_countries_filters, comma_delimiter);
		bird_int = init_bird_level(bird);
		/*
		 *  Before changing the type of cache, have a look at this benchmark:
		 *  http://www.maxmind.com/app/benchmark
		 *  and choose wisely.
		 */
		switch(bird_int){
		case COUNTRY:
			if(db_path!=NULL){
				db_country_path=db_path;
			}
			gi = GeoIP_open(db_country_path, GEOIP_MEMORY_CACHE);
			break;

		case REGION:
			if(db_path!=NULL){
				db_region_path=db_path;
			}
			gi = GeoIP_open(db_region_path, GEOIP_MEMORY_CACHE);
			break;

		case CITY:
			if(db_path!=NULL){
				db_city_path=db_path;
			}
			gi = GeoIP_open(db_city_path, GEOIP_MEMORY_CACHE);
			break;

		case LAT_LON:
			if(db_path!=NULL){
				db_city_path=db_path;
			}
			gi = GeoIP_open(db_city_path, GEOIP_MEMORY_CACHE);
			break;

		case EVERYTHING:
			if(db_path!=NULL){
				db_city_path=db_path;
			}
			gi = GeoIP_open(db_city_path, GEOIP_MEMORY_CACHE);
			break;
		}

		if (gi == NULL) {
			fprintf(stderr, "Error opening MaxMind Geo database.\n");
			fprintf(stderr, "Path used for country database:%s\n", db_country_path);
			fprintf(stderr, "Path used for region database:%s\n", db_region_path);
			fprintf(stderr, "Path used for city database:%s\n", db_city_path);
			exit(EXIT_FAILURE);
		} else {
			if(verbose_flag){
				char *db_info =GeoIP_database_info(gi);
				unsigned char db_edition = GeoIP_database_edition(gi);
				GeoIPDBTypes geodbtype = (GeoIPDBTypes)db_info;
				fprintf(stderr,"Maxmind database: %i; version: %i\n", db_edition, geodbtype);
			}
		}
	}

	if(params[HTTP_STATUS_FILTER]){
		init_http_status(filters, http_status_input, comma_delimiter);
	} else {
		http_status_input = NULL;
	}


	if (verbose_flag){
		fprintf(stderr, "num_path_filters:%d\tnum_domain_filters:%d"
			"\tnum_http_status_filters:%d\tip_address_count:%d"
			"\tcountries_count:%d\treferer_count:%d\n",
			num_path_filters, num_domain_filters, num_http_status_filters,
			num_ipaddress_filters, num_countries_filters, num_referer_filters);
	}


	// Now that we have initilaized all the filters,
	// do the actual filtering and conversion of the
	// incoming data.
	while ( true ) {
		int found =0;
		area = NULL;

		char *r;
		r=fgets(line, LINE_BUF_SIZE, stdin);
		if(!r) {
			break;
		}

		i = 0;
		char *p;
		do {
			fields[i] = r;
			//strsep(&r, ws_delimiter);
			p = strchr( r, *ws_delimiter );
			i++;
                        if ( NULL == p )
                                break;
                        *p = 0;
                        r = p + 1;
		} while (i < MAX_FIELD_CNT);

		if (i < minimum_field_count || i == MAX_FIELD_CNT){
			continue;    // ignore line since field count is outside expected range
		}


		// we found i fields in this line.
		field_count_this_line = i;

		ipaddr        = fields[4];
		http_status   = fields[5];
		url           = fields[8];
		referer       = fields[11];
		//ua            = fields[13]; // necessary for bot detection


		if (url != NULL) {

			if (params[DOMAIN_FILTER]){
				found += match_domain(url, filters, num_domain_filters,verbose_flag);
			}

			if (params[PATH_FILTER]){
				found += match_path(url, filters, num_path_filters,verbose_flag);
			}

			if (params[HTTP_STATUS_FILTER]){
				found += match_http_status(http_status, filters, num_http_status_filters,verbose_flag);
			}

			if (params[IP_FILTER]){
				found += match_ip_address(ipaddr, filters, num_ipaddress_filters,verbose_flag);
			}

			if (params[REFERER_FILTER]){
				found += match_domain(referer, filters, num_referer_filters,verbose_flag);
			}

			if (params[GEO_FILTER]){
				area = geo_lookup(gi, ipaddr, bird_int);
				found += geo_check(area, countries, num_countries_filters,verbose_flag);
				if (verbose_flag){
					fprintf(stderr, "IP address: %s was geocoded as: %s\n", ipaddr, area);
				}
			}
		}

		// required_hits will equal the number of filters
		// given.  These include ip, domain, path, status,
		// and country filtering.  If no filters were given,
		// then found will be 0 AND require_hits will be 0,
		// allowing the line to pass through.
		if (found >= required_hits) {
			// if we need to replace the IP addr
			// because recode is GEO or ANONYMIZE or both
			if (recode)
			{
				// geocode if we haven't already geocoded and
				// we'll be needing the geocoded string when
				// replacing the IP.
				if (area == NULL && (recode & GEO)) {
					area = geo_lookup(gi, ipaddr, bird_int);
				}

				// replace the ip address in fields.
				// if area is not null, it will be appended
				// to the ip address.  If (recode & ANONYMIZE) is
				// true, then the IP will be replaced.
				replace_ip_addr(fields, area, (recode & ANONYMIZE));
			}

			// print output to stdout
			for (i=0;i<field_count_this_line;++i){
				if (i!=0){
					FPUTS(ws_delimiter, stdout);
				}
				FPUTS(fields[i], stdout);
			}

		}

		if (verbose_flag) {
			fprintf(stderr, "ipaddr: '%s', url: '%s, status: %s'\n", ipaddr, url, http_status);
		}

	}
	free_memory(filters, path_input, domain_input,num_filters, gi, countries, num_countries_filters);
}
예제 #19
0
파일: log.c 프로젝트: DonCN/haiku
static bool
log_vprintf_internal (struct logvprintf_state *state, const char *fmt,
                      va_list args)
{
  char smallmsg[128];
  char *write_ptr = smallmsg;
  int available_size = sizeof (smallmsg);
  int numwritten;
  FILE *fp = get_log_fp ();

  if (!save_context_p)
    {
      /* In the simple case just call vfprintf(), to avoid needless
         allocation and games with vsnprintf(). */
      vfprintf (fp, fmt, args);
      goto flush;
    }

  if (state->allocated != 0)
    {
      write_ptr = state->bigmsg;
      available_size = state->allocated;
    }

  /* The GNU coding standards advise not to rely on the return value
     of sprintf().  However, vsnprintf() is a relatively new function
     missing from legacy systems.  Therefore I consider it safe to
     assume that its return value is meaningful.  On the systems where
     vsnprintf() is not available, we use the implementation from
     snprintf.c which does return the correct value.  */
  numwritten = vsnprintf (write_ptr, available_size, fmt, args);

  /* vsnprintf() will not step over the limit given by available_size.
     If it fails, it returns either -1 (older implementations) or the
     number of characters (not counting the terminating \0) that
     *would have* been written if there had been enough room (C99).
     In the former case, we double available_size and malloc to get a
     larger buffer, and try again.  In the latter case, we use the
     returned information to build a buffer of the correct size.  */

  if (numwritten == -1)
    {
      /* Writing failed, and we don't know the needed size.  Try
         again with doubled size. */
      int newsize = available_size << 1;
      state->bigmsg = xrealloc (state->bigmsg, newsize);
      state->allocated = newsize;
      return false;
    }
  else if (numwritten >= available_size)
    {
      /* Writing failed, but we know exactly how much space we
         need. */
      int newsize = numwritten + 1;
      state->bigmsg = xrealloc (state->bigmsg, newsize);
      state->allocated = newsize;
      return false;
    }

  /* Writing succeeded. */
  saved_append (write_ptr);
  FPUTS (write_ptr, fp);
  if (state->bigmsg)
    xfree (state->bigmsg);

 flush:
  if (flush_log_p)
    logflush ();
  else
    needs_flushing = true;

  return true;
}
예제 #20
0
    int VCPU::print_state_compat(FILE * o) const
    {
        int len = 0;

        if ( this->flags & CPU_GP_REGS )
        {
            len += FPRINTF(o, "\tEIP:    %04"PRIx16":[<%08"PRIx32">] Ring %d\n",
                           this->regs.cs, this->regs.eip, this->regs.cs & 0x3);
            len += FPRINTF(o, "\tEFLAGS: %08"PRIx32" ", this->regs.eflags);
            len += print_rflags(o, this->regs.rflags & -((uint32_t)1));
            len += FPUTS("\n", o);

            len += FPRINTF(o, "\teax: %08"PRIx32"   ebx: %08"PRIx32"   ",
                           this->regs.eax, this->regs.ebx);
            len += FPRINTF(o, "ecx: %08"PRIx32"   edx: %08"PRIx32"\n",
                           this->regs.ecx, this->regs.edx);
            len += FPRINTF(o, "\tesi: %08"PRIx32"   edi: %08"PRIx32"   ",
                           this->regs.esi, this->regs.edi);
            len += FPRINTF(o, "ebp: %08"PRIx32"   esp: %08"PRIx32"\n",
                           this->regs.ebp, this->regs.esp);
        }

        if ( this->flags & CPU_CR_REGS )
        {
            len += FPRINTF(o, "\tcr3: %016"PRIx64"\n", this->regs.cr3);
        }

        if ( this->flags & CPU_GP_REGS )
        {
            len += FPUTS("\n", o);

            if ( this->flags & CPU_SEG_REGS )
                len += FPRINTF(o, "\tds: %04"PRIx16"   es: %04"PRIx16"   "
                               "fs: %04"PRIx16"   gs: %04"PRIx16"   "
                               "ss: %04"PRIx16"   cs: %04"PRIx16"\n",
                               this->regs.ds, this->regs.es, this->regs.fs,
                               this->regs.gs, this->regs.ss, this->regs.cs);
            else
                len += FPRINTF(o, "\tss: %04"PRIx16"   cs: %04"PRIx16"\n",
                               this->regs.ss, this->regs.cs);
        }

        len += FPUTS("\n", o);

        len += FPRINTF(o, "\tPause Count: %"PRId32", Flags: 0x%"PRIx32" ",
                       this->pause_count, this->pause_flags);
        len += print_pause_flags(o, this->pause_flags);
        len += FPUTS("\n", o);

        switch ( this->runstate )
        {
        case RST_NONE:
            len += FPRINTF(o, "\tNot running:  Last run on PCPU%"PRIu32"\n", this->processor);
            break;
        case RST_RUNNING:
            len += FPRINTF(o, "\tCurrently running on PCPU%"PRIu32"\n", this->processor);
            break;
        case RST_CTX_SWITCH:
            len += FPUTS("\tBeing Context Switched:  State unreliable\n", o);
            break;
        default:
            len += FPUTS("\tUnknown runstate\n", o);
            break;
        }
        len += FPRINTF(o, "\tStruct vcpu at %016"PRIx64"\n", this->vcpu_ptr);

        len += FPUTS("\n", o);

        if ( this->flags & CPU_GP_REGS &&
             this->flags & CPU_CR_REGS )
        {
            len += FPRINTF(o, "\tStack at %08"PRIx32":", this->regs.esp);
            len += print_32bit_stack(o, *this->dompt, this->regs.rsp);

            len += FPUTS("\n\tCode:\n", o);
            len += print_code(o, *this->dompt, this->regs.rip);

            len += FPUTS("\n\tCall Trace:\n", o);
            if ( this->domid == 0 )
            {
                vaddr_t sp = this->regs.rsp;
                vaddr_t top = (this->regs.rsp | (PAGE_SIZE-1))+1;
                union { uint32_t val32; uint64_t val64; } val;
                val.val64 = 0;

                len += host.dom0_symtab.print_symbol32(o, this->regs.rip, true);

                try
                {
                    while ( sp < top )
                    {
                        memory.read32_vaddr(*this->dompt, sp, val.val32);
                        len += host.dom0_symtab.print_symbol32(o, val.val64);
                        sp += 4;
                    }
                }
                catch ( const CommonError & e )
                {
                    e.log();
                }
            }
            else
                len += FPUTS("\t  No symbol table for domain\n", o);

        }

        len += FPUTS("\n", o);
        return len;
    }
예제 #21
0
파일: scansbr.c 프로젝트: dscho/nmh
int
scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
      int unseen, char *folder, long size, int noisy)
{
    int i, compnum, encrypted, state;
    char *cp, *tmpbuf, *startbody, **nxtbuf;
    char *saved_c_text = NULL;
    struct comp *cptr;
    struct comp **savecomp;
    char *scnmsg = NULL;
    FILE *scnout = NULL;
    char name[NAMESZ];
    int bufsz;
    static int rlwidth, slwidth;
    static size_t scanl_size;

    /* first-time only initialization */
    if (!scanl) {
	if (width == 0) {
	    if ((width = sc_width ()) < WIDTH/2)
		width = WIDTH/2;
	    else if (width > MAXSCANL)
		width = MAXSCANL;
	}
	dat[3] = slwidth = width;
	/* Arbitrarily allocate 20 * slwidth to provide room for lots
	   of escape sequences. */
	scanl_size = SCAN_CHARWIDTH * (20 * slwidth + 2);
	scanl = (char *) mh_xmalloc (scanl_size);
	if (outnum)
	    umask(~m_gmprot());

	/* Compile format string */
	ncomps = fmt_compile (nfs, &fmt, 1) + 2;

	bodycomp = fmt_findcomp("body");
	datecomp = fmt_findcomp("date");
	cptr = fmt_findcomp("folder");
	if (cptr && folder)
	    cptr->c_text = getcpy(folder);
	if (fmt_addcompentry("encrypted")) {
		ncomps++;
	}
	cptr =  fmt_findcomp("dtimenow");
	if (cptr)
	    cptr->c_text = getcpy(dtimenow (0));

	/*
	 * In other programs I got rid of this complicated buffer switching,
	 * but since scan reads lots of messages at once and this complicated
	 * memory management, I decided to keep it; otherwise there was
	 * the potential for a lot of malloc() and free()s, and I could
	 * see the malloc() pool really getting fragmented.  Maybe it
	 * wouldn't be an issue in practice; perhaps this will get
	 * revisited someday.
	 *
	 * So, some notes for what's going on:
	 *
	 * nxtbuf is an array of pointers that contains malloc()'d buffers
	 * to hold our component text.  used_buf is an array of struct comp
	 * pointers that holds pointers to component structures we found while
	 * processing a message.
	 *
	 * We read in the message with m_getfld(), using "tmpbuf" as our
	 * input buffer.  tmpbuf is set at the start of message processing
	 * to the first buffer in our buffer pool (nxtbuf).
	 *
	 * Every time we find a component we care about, we set that component's
	 * text buffer to the current value of tmpbuf, and then switch tmpbuf
	 * to the next buffer in our pool.  We also add that component to
	 * our used_buf pool.
	 *
	 * When we're done, we go back and zero out all of the component
	 * text buffer pointers that we saved in used_buf.
	 *
	 * Note that this means c_text memory is NOT owned by the fmt_module
	 * and it's our responsibility to free it.
	 */

	nxtbuf = compbuffers = (char **) calloc((size_t) ncomps, sizeof(char *));
	if (nxtbuf == NULL)
	    adios (NULL, "unable to allocate component buffers");
	used_buf = (struct comp **) calloc((size_t) (ncomps+1),
	    sizeof(struct comp *));
	if (used_buf == NULL)
	    adios (NULL, "unable to allocate component buffer stack");
	used_buf += ncomps+1; *--used_buf = 0;
	rlwidth = bodycomp && (width > SBUFSIZ) ? width : SBUFSIZ;
	for (i = ncomps; i--; )
	    *nxtbuf++ = mh_xmalloc(rlwidth);
    }

    /*
     * each-message initialization
     */
    nxtbuf = compbuffers;
    savecomp = used_buf;
    tmpbuf = *nxtbuf++;
    startbody = NULL;
    dat[0] = innum ? innum : outnum;
    dat[1] = curflg;
    dat[4] = unseen;

    /*
     * Get the first field.  If the message is non-empty
     * and we're doing an "inc", open the output file.
     */
    bufsz = rlwidth;
    m_getfld_state_reset (&gstate);
    if ((state = m_getfld (&gstate, name, tmpbuf, &bufsz, inb)) == FILEEOF) {
	if (ferror(inb)) {
	    advise("read", "unable to"); /* "read error" */
	    return SCNFAT;
	} else {
	    return SCNEOF;
	}
    }

    if (outnum) {
	if (outnum > 0) {
	    scnmsg = m_name (outnum);
	    if (*scnmsg == '?')		/* msg num out of range */
		return SCNNUM;
	} else {
	    scnmsg = "/dev/null";
	}
	if ((scnout = fopen (scnmsg, "w")) == NULL)
	    adios (scnmsg, "unable to write");
    }

    /* scan - main loop */
    for (compnum = 1; ;
	bufsz = rlwidth, state = m_getfld (&gstate, name, tmpbuf, &bufsz, inb)) {
	switch (state) {
	    case FLD: 
	    case FLDPLUS: 
		compnum++;
		if (outnum) {
		    FPUTS (name);
		    if ( putc (':', scnout) == EOF) DIEWRERR();
		    FPUTS (tmpbuf);
		}
		/*
		 * if we're interested in this component, save a pointer
		 * to the component text, then start using our next free
		 * buffer as the component temp buffer (buffer switching
		 * saves an extra copy of the component text).
		 */
		if ((cptr = fmt_findcasecomp(name))) {
		    if (! cptr->c_text) {
			cptr->c_text = tmpbuf;
			for (cp = tmpbuf + strlen (tmpbuf) - 1; 
					cp >= tmpbuf; cp--)
			    if (isspace ((unsigned char) *cp))
				*cp = 0;
			    else
				break;
			*--savecomp = cptr;
			tmpbuf = *nxtbuf++;
		    }
		}

		while (state == FLDPLUS) {
		    bufsz = rlwidth;
		    state = m_getfld (&gstate, name, tmpbuf, &bufsz, inb);
		    if (outnum)
			FPUTS (tmpbuf);
		}
		break;

	    case BODY: 
		compnum = -1;
		/*
		 * A slight hack ... if we have less than rlwidth characters
		 * in the buffer, call m_getfld again.
		 */

		if ((i = strlen(tmpbuf)) < rlwidth) {
		    bufsz = rlwidth - i;
		    state = m_getfld (&gstate, name, tmpbuf + i, &bufsz, inb);
		}

		if (! outnum) {
		    state = FILEEOF; /* stop now if scan cmd */
		    if (bodycomp && startbody == NULL)
		    	startbody = tmpbuf;
		    goto finished;
		}
		if (putc ('\n', scnout) == EOF) DIEWRERR();
		FPUTS (tmpbuf);
		/*
                 * The previous code here used to call m_getfld() using
                 * pointers to the underlying output stdio buffers to
                 * avoid the extra copy.  Tests by Markus Schnalke show
                 * no noticable performance loss on larger mailboxes
                 * if we incur an extra copy, and messing around with
                 * internal stdio buffers is becoming more and more
                 * unportable as times go on.  So from now on just deal
                 * with the overhead of an extra copy.
		 *
		 * Subtle change - with the previous code tmpbuf wasn't
		 * used, so we could reuse it for the {body} component.
		 * Now since we're using tmpbuf as our read buffer we
		 * need to save the beginning of the body for later.
		 * See the above (and below) use of startbody.
		 */
body:;
		if (bodycomp && startbody == NULL) {
		    startbody = tmpbuf;
		    tmpbuf = *nxtbuf++;
		}

		while (state == BODY) {
		    bufsz = rlwidth;
		    state = m_getfld (&gstate, name, tmpbuf, &bufsz, inb);
		    FPUTS(tmpbuf);
		}
		goto finished;

	    case LENERR: 
	    case FMTERR: 
	    	if (innum)
		    fprintf (stderr, "??Format error (message %d) in ",
			     outnum ? outnum : innum);
		else
		    fprintf (stderr, "??Format error in ");

		fprintf (stderr, "component %d\n", compnum);

		if (outnum) {
		    FPUTS ("\n\nBAD MSG:\n");
		    FPUTS (name);
		    if (putc ('\n', scnout) == EOF) DIEWRERR();
		    state = BODY;
		    goto body;
		}
		/* fall through */

	    case FILEEOF:
		goto finished;

	    default: 
		adios (NULL, "getfld() returned %d", state);
	}
    }

    /*
     * format and output the scan line.
     */
finished:
    if (ferror(inb)) {
	advise("read", "unable to"); /* "read error" */
	return SCNFAT;
    }

    /* Save and restore buffer so we don't trash our dynamic pool! */
    if (bodycomp) {
	saved_c_text = bodycomp->c_text;
	bodycomp->c_text = startbody;
    }

    if (size)
	dat[2] = size;
    else if (outnum > 0)
    {
	dat[2] = ftell(scnout);
	if (dat[2] == EOF) DIEWRERR();
    }

    if ((datecomp && !datecomp->c_text) || (!size && !outnum)) {
	struct stat st;

	fstat (fileno(inb), &st);
	if (!size && !outnum)
	    dat[2] = st.st_size;
	if (datecomp) {
	    if (! datecomp->c_text) {
		if (datecomp->c_tws == NULL)
		    datecomp->c_tws = (struct tws *)
			calloc((size_t) 1, sizeof(*datecomp->c_tws));
		if (datecomp->c_tws == NULL)
		    adios (NULL, "unable to allocate tws buffer");
		*datecomp->c_tws = *dlocaltime ((time_t *) &st.st_mtime);
		datecomp->c_flags |= CF_DATEFAB|CF_TRUE;
	    } else {
		datecomp->c_flags &= ~CF_DATEFAB;
	    }
	}
    }

    fmt_scan (fmt, scanl, scanl_size, slwidth, dat, NULL);

    if (bodycomp)
	bodycomp->c_text = saved_c_text;

    if (noisy)
	fputs (scanl, stdout);

    cptr = fmt_findcomp ("encrypted");
    encrypted = cptr && cptr->c_text;

    /* return dynamically allocated buffers to pool */
    while ((cptr = *savecomp++)) {
	cptr->c_text = NULL;
    }

    if (outnum && (ferror(scnout) || fclose (scnout) == EOF))
	DIEWRERR();

    return (state != FILEEOF ? SCNERR : encrypted ? SCNENC : SCNMSG);
}
int dump_data(FILE * o, size_t ws, const PageTable & pt, const vaddr_t & start,
              const uint64_t & length)
{
    int len = 0;

    // Only support 32 and 64 bit dumps at the moment
    if ( ! ( ws == 4 || ws == 8 ) )
    {
        LOG_WARN("Unsupported word size '%zu' for dump_data()\n", ws);
        return 0;
    }

    // Verify that start + length does not overflow
    if ( ((-(uint64_t)1) - start) < length )
        return len + FPRINTF(o, "dump_data(): start (0x%016"PRIx64") and length "
                             "(0x%016"PRIx64") overflow the address space.\n",
                             start, length);


    for ( vaddr_t addr = start; addr < (start+length); addr += ws * 2 )
    {
        try
        {
            len += FPRINTF(o, "%04"PRIx64": ", addr - start);

            if ( ws == 4 )
            {
                union { uint32_t _32; unsigned char _8 [sizeof (uint32_t)]; } data[2];

                memory.read32_vaddr(pt, addr, data[0]._32);

                for ( size_t x = 0; x < sizeof data[0]._8; ++x )
                    len += FPRINTF(o, "%02x ", data[0]._8[x]);
                len += FPUTS(" ", o);

                memory.read32_vaddr(pt, addr+ws, data[1]._32);

                for ( size_t x = 0; x < sizeof data[1]._8; ++x )
                    len += FPRINTF(o, "%02x ", data[1]._8[x]);
                len += FPUTS(" ", o);

                len += FPRINTF(o, "0x%08"PRIx32" 0x%08"PRIx32"\n",
                               data[0]._32, data[1]._32);
            }
            else
            {
                union { uint64_t _64; unsigned char _8 [sizeof (uint64_t)]; } data[2];

                memory.read64_vaddr(pt, addr, data[0]._64);

                for ( size_t x = 0; x < sizeof data[0]._8; ++x )
                    len += FPRINTF(o, "%02x ", data[0]._8[x]);
                len += FPUTS(" ", o);

                memory.read64_vaddr(pt, addr+ws, data[1]._64);

                for ( size_t x = 0; x < sizeof data[1]._8; ++x )
                    len += FPRINTF(o, "%02x ", data[1]._8[x]);
                len += FPUTS(" ", o);

                len += FPRINTF(o, "0x%016"PRIx64" 0x%016"PRIx64"\n",
                               data[0]._64, data[1]._64);
            }
        }
        catch ( const CommonError & e )
        {
            e.log();
        }
    }

    return 0;
}
int print_console_ring(FILE * o, const PageTable & pt,
                       const vaddr_t & ring, const uint64_t & _length,
                       const uint64_t & producer, const uint64_t & consumer)
{
    int len = 0;
    int64_t prod = producer, cons = consumer, length = _length;
    ssize_t written;

    if ( _length > SSIZE_MAX )
        return len + FPRINTF(o, "Length(%"PRIu64") exceeds SSIZE_MAX(%zd)\n",
                             _length, (ssize_t)SSIZE_MAX);

    if ( (length & (length-1)) == 0 )
    {
        prod &= (length-1);
        cons &= (length-1);
    }

    if ( prod > length )
        return len + FPRINTF(o, "Producer index %"PRIu64" outside ring length %"PRIu64"\n",
                             prod, length);

    if ( cons > length )
        return len + FPRINTF(o, "Consumer index %"PRIu64" outside ring length %"PRIu64"\n",
                             cons, length);

    len += FPUTS("\n", o);

    try
    {
        if ( cons == 0 && prod == 0 )
        {
            LOG_DEBUG("Console ring: %"PRIu64" bytes at 0x%016"PRIx64"\n", length, ring);
            written = memory.write_block_vaddr_to_file(pt, ring, o, length);
            len += written;

            if ( written != length )
                LOG_INFO("Mismatch writing console ring to file. Written %zu bytes "
                         "of %"PRIu64"\n", written, length);
        }
        else
        {
            LOG_DEBUG("Console ring: %"PRIu64" bytes at 0x%016"PRIx64", prod %"PRId64", cons %"PRId64"\n",
                      length, ring, prod, cons);
            if ( cons >= prod )
            {
                written = memory.write_block_vaddr_to_file(pt, ring + cons,
                                                           o, length - cons);
                len += written;

                if ( (length - cons) != written )
                {
                    LOG_INFO("Mismatch writing console ring to file. Written %zu bytes "
                             "of %"PRIu64"\n", written, length - cons);
                }
                else
                {

                    written = memory.write_block_vaddr_to_file(pt, ring, o, prod);
                    len += written;

                    if ( prod != written )
                        LOG_INFO("Mismatch writing console ring to file. Written %zu bytes "
                                 "of %"PRIu64"\n", written, prod);
                }
            }
            else
            {
                written = memory.write_block_vaddr_to_file(pt, ring + cons, o, prod - cons);
                len += written;

                if ( (prod - cons) != written )
                    LOG_INFO("Mismatch writing console ring to file. Written %zu bytes "
                             "of %"PRIu64"\n", written, prod - cons );
            }
        }
    }
    catch ( const CommonError & e )
    {
        e.log();
    }

    len += FPUTS("\n", o);
    return len;
}