Example #1
0
/*输出二维指针 print Two dimensional pointer*/
void print_tdp(char* prefix_s, char **p, int count)
{
	int i = 0;
	for (i = 0; i<count; i++) {
		print_p(prefix_s, p[i], DATA_STR);
	}
}
Example #2
0
/* Authentication (Client side) */
int auth_client(int fd, struct vtun_host *host, int * reason)
{
	char buf[VTUN_MESG_SIZE], chal[VTUN_CHAL_SIZE];
	int stage, success=0 ;
	
	stage = ST_INIT;
    *reason = D_NOREAD;
	while( readn_t(fd, buf, VTUN_MESG_SIZE, vtun.timeout) > 0 ){
        *reason = D_OTHER;
	   buf[sizeof(buf)-1]='\0';
	   switch( stage ){
		case ST_INIT:
            if (!strncmp(buf, "VTRUNKD", 7)) {
		      stage = ST_HOST;
		      print_p(fd,"HOST: %s\n",host->host);
		      continue;
	           }
               *reason = D_GREET;
		   break;	

	        case ST_HOST:
		   if( !strncmp(buf,"OK",2) && cs2cl(buf,chal)){
		      stage = ST_CHAL;
					
		      encrypt_chal(chal,host->passwd);
		      print_p(fd,"CHAL: %s\n", cl2cs(chal));

		      continue;
	   	   }
           *reason = D_CHAL;
		   break;	
	
	        case ST_CHAL:
		   if( !strncmp(buf,"OK",2) && cf2bf(buf,host) )
		      success = 1;
           else *reason = D_PWD;
		   break;
	   }
	   break;
	}

	return success;
}
Example #3
0
static void
print_html_geolocation (FILE * fp, GHolder * h, int process)
{
  char *data;
  float percent;
  int hits;
  int i;
  GSubList *sub_list;

  if (h->idx == 0)
    return;

  print_html_h2 (fp, GEOLO_HEAD, GEOLO_ID);
  print_p (fp, GEOLO_DESC);
  print_html_begin_table (fp);
  print_html_begin_thead (fp);

  fprintf (fp, "<tr>");
  fprintf (fp, "<th>Visitors</th>");
  fprintf (fp, "<th>%%</th>");
  fprintf (fp, "<th>");
  fprintf (fp, "Location");
  fprintf (fp, "<span class=\"r\" onclick=\"t(this)\">◀</span>");
  fprintf (fp, "</th>");
  fprintf (fp, "</tr>");

  print_html_end_thead (fp);
  print_html_begin_tbody (fp);

  for (i = 0; i < h->idx; i++) {
    hits = h->items[i].hits;
    data = h->items[i].data;
    percent = get_percentage (process, hits);
    percent = percent < 0 ? 0 : percent;

    print_html_begin_tr (fp, 0);
    fprintf (fp, "<td>%d</td>", hits);
    fprintf (fp, "<td>%4.2f%%</td>", percent);
    fprintf (fp, "<td>%s</td>", data);
    print_html_end_tr (fp);

    sub_list = h->items[i].sub_list;
    print_html_sub_geolocation (fp, sub_list, process);
  }
  print_html_end_tbody (fp);
  print_html_end_table (fp);
}
Example #4
0
int
main(int argc, char **argv)
{
	kstat_ctl_t	*kc;
	kstat_t		*ksp;
	kstat_named_t	*knp;
	struct vcpu	*vc;
	struct core	*core;
	struct pchip	*chip;
	struct link	**ins;
	char		*s;
	int		nspec;
	int		optc;
	int		opt_s = 0;
	int		opt_p = 0;
	int		opt_v = 0;
	int		ex = 0;

	cmdname = basename(argv[0]);


	(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define	TEXT_DOMAIN	"SYS_TEST"
#endif
	(void) textdomain(TEXT_DOMAIN);

	/* collect the kstats */
	if ((kc = kstat_open()) == NULL)
		die(_("kstat_open() failed"));

	if ((ksp = kstat_lookup(kc, "cpu_info", -1, NULL)) == NULL)
		die(_("kstat_lookup() failed"));

	for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {

		if (strcmp(ksp->ks_module, "cpu_info") != 0)
			continue;
		if (kstat_read(kc, ksp, NULL) == NULL)
			die(_("kstat_read() failed"));

		vc = find_link(&vcpus, ksp->ks_instance, &ins);
		if (vc == NULL) {
			vc = zalloc(sizeof (struct vcpu));
			vc->v_link.l_id = ksp->ks_instance;
			vc->v_link_core.l_id = ksp->ks_instance;
			vc->v_link_pchip.l_id = ksp->ks_instance;
			vc->v_link.l_ptr = vc;
			vc->v_link_core.l_ptr = vc;
			vc->v_link_pchip.l_ptr = vc;
			ins_link(ins, &vc->v_link);
		}

		if ((knp = kstat_data_lookup(ksp, "state")) != NULL) {
			vc->v_state = mystrdup(knp->value.c);
		} else {
			vc->v_state = "unknown";
		}

		if ((knp = kstat_data_lookup(ksp, "cpu_type")) != NULL) {
			vc->v_cpu_type = mystrdup(knp->value.c);
		}
		if ((knp = kstat_data_lookup(ksp, "fpu_type")) != NULL) {
			vc->v_fpu_type = mystrdup(knp->value.c);
		}

		if ((knp = kstat_data_lookup(ksp, "state_begin")) != NULL) {
			vc->v_state_begin = knp->value.l;
		}

		if ((knp = kstat_data_lookup(ksp, "clock_MHz")) != NULL) {
			vc->v_clock_mhz = knp->value.l;
		}

		if ((knp = kstat_data_lookup(ksp, "brand")) == NULL) {
			vc->v_brand = _("(unknown)");
		} else {
			vc->v_brand = mystrdup(knp->value.str.addr.ptr);
		}

		if ((knp = kstat_data_lookup(ksp, "socket_type")) == NULL) {
			vc->v_socket = "Unknown";
		} else {
			vc->v_socket = mystrdup(knp->value.str.addr.ptr);
		}

		if ((knp = kstat_data_lookup(ksp, "implementation")) == NULL) {
			vc->v_impl = _("(unknown)");
		} else {
			vc->v_impl = mystrdup(knp->value.str.addr.ptr);
		}
		/*
		 * Legacy code removed the chipid and cpuid fields... we
		 * do the same for compatibility.  Note that the original
		 * pattern is a bit strange, and we have to emulate this because
		 * on SPARC we *do* emit these.  The original pattern we are
		 * emulating is: $impl =~ s/(cpuid|chipid)\s*\w+\s+//;
		 */
		if ((s = strstr(vc->v_impl, "chipid")) != NULL) {
			char *x = s + strlen("chipid");
			while (isspace(*x))
				x++;
			if ((!isalnum(*x)) && (*x != '_'))
				goto nochipid;
			while (isalnum(*x) || (*x == '_'))
				x++;
			if (!isspace(*x))
				goto nochipid;
			while (isspace(*x))
				x++;
			(void) strcpy(s, x);
		}
nochipid:
		if ((s = strstr(vc->v_impl, "cpuid")) != NULL) {
			char *x = s + strlen("cpuid");
			while (isspace(*x))
				x++;
			if ((!isalnum(*x)) && (*x != '_'))
				goto nocpuid;
			while (isalnum(*x) || (*x == '_'))
				x++;
			if (!isspace(*x))
				goto nocpuid;
			while (isspace(*x))
				x++;
			(void) strcpy(s, x);
		}
nocpuid:

		if ((knp = kstat_data_lookup(ksp, "chip_id")) != NULL)
			vc->v_pchip_id = knp->value.l;
		chip = find_link(&pchips, vc->v_pchip_id, &ins);
		if (chip == NULL) {
			chip = zalloc(sizeof (struct pchip));
			chip->p_link.l_id = vc->v_pchip_id;
			chip->p_link.l_ptr = chip;
			ins_link(ins, &chip->p_link);
		}
		vc->v_pchip = chip;

		if ((knp = kstat_data_lookup(ksp, "core_id")) != NULL)
			vc->v_core_id = knp->value.l;
		core = find_link(&cores, vc->v_core_id, &ins);
		if (core == NULL) {
			core = zalloc(sizeof (struct core));
			core->c_link.l_id = vc->v_core_id;
			core->c_link.l_ptr = core;
			core->c_link_pchip.l_id = vc->v_core_id;
			core->c_link_pchip.l_ptr = core;
			core->c_pchip = chip;
			ins_link(ins, &core->c_link);
			chip->p_ncore++;
			(void) find_link(&chip->p_cores, core->c_link.l_id,
			    &ins);
			ins_link(ins, &core->c_link_pchip);
		}
		vc->v_core = core;



		/* now put other linkages in place */
		(void) find_link(&chip->p_vcpus, vc->v_link.l_id, &ins);
		ins_link(ins, &vc->v_link_pchip);
		chip->p_nvcpu++;

		(void) find_link(&core->c_vcpus, vc->v_link.l_id, &ins);
		ins_link(ins, &vc->v_link_core);
		core->c_nvcpu++;
	}

	(void) kstat_close(kc);

	nspec = 0;

	while ((optc = getopt(argc, argv, "pvs")) != EOF) {
		switch (optc) {
		case 's':
			opt_s = 1;
			break;
		case 'p':
			opt_p = 1;
			break;
		case 'v':
			opt_v = 1;
			break;
		default:
			usage(NULL);
		}
	}

	while (optind < argc) {
		long id;
		char *eptr;
		struct link *l;
		id = strtol(argv[optind], &eptr, 10);
		l = find_link(&vcpus, id, NULL);
		if ((*eptr != '\0') || (l == NULL)) {
			(void) fprintf(stderr,
			    _("%s: processor %s: Invalid argument\n"),
			    cmdname, argv[optind]);
			ex = 2;
		} else {
			((struct vcpu *)l->l_ptr)->v_doit = 1;
			((struct vcpu *)l->l_ptr)->v_pchip->p_doit = 1;
			((struct vcpu *)l->l_ptr)->v_core->c_doit = 1;
		}
		nspec++;
		optind++;
	}

	if (opt_s && opt_v) {
		usage(_("options -s and -v are mutually exclusive"));
	}
	if (opt_s && nspec != 1) {
		usage(_("must specify exactly one processor if -s used"));
	}
	if (opt_v && opt_p) {
		print_vp(nspec);
	} else if (opt_s && opt_p) {
		print_ps();
	} else if (opt_p) {
		print_p(nspec);
	} else if (opt_v) {
		print_v(nspec);
	} else if (opt_s) {
		print_s();
	} else {
		print_normal(nspec);
	}

	return (ex);
}
Example #5
0
/* Authentication (Server side) */
struct vtun_host * auth_server(int fd)
{
        char chal_req[VTUN_CHAL_SIZE], chal_res[VTUN_CHAL_SIZE];	
	char buf[VTUN_MESG_SIZE], *str1, *str2;
        struct vtun_host *h = NULL;
	char *host = NULL;
	int  stage;

        set_title("authentication");

	print_p(fd,"VTUN server ver %s\n",VTUN_VER);

	stage = ST_HOST;

	while( readn_t(fd, buf, VTUN_MESG_SIZE, vtun.timeout) > 0 ){
	   buf[sizeof(buf)-1]='\0';
	   strtok(buf,"\r\n");

	   if( !(str1=strtok(buf," :")) )
	      break;
	   if( !(str2=strtok(NULL," :")) )
	      break;

	   switch( stage ){
	     case ST_HOST:
	        if( !strcmp(str1,"HOST") ){
		   host = strdup(str2);

		   gen_chal(chal_req);
		   print_p(fd,"OK CHAL: %s\n", cl2cs(chal_req));

		   stage = ST_CHAL;
		   continue;
	        }
		break;
	     case ST_CHAL:
	        if( !strcmp(str1,"CHAL") ){
		   if( !cs2cl(str2,chal_res) )
		      break; 
		   
		   if( !(h = find_host(host)) )
		      break;

		   decrypt_chal(chal_res, h->passwd);   		
	
		   if( !memcmp(chal_req, chal_res, VTUN_CHAL_SIZE) ){
		      /* Auth successeful. */

		      /* Lock host */	
		      if( lock_host(h) < 0 ){
		         /* Multiple connections are denied */
		         h = NULL;
		         break;
		      }	
		      print_p(fd,"OK FLAGS: %s\n", bf2cf(h)); 
 		   } else
		      h = NULL;
	        }
		break;
 	   }
	   break;
	}

	if( host )
	   free(host);

	if( !h )
	   print_p(fd,"ERR\n");	

	return h;
}
int main(int argc, char **argv)
{

    int p_d[P_LENGTH] = {0};
    int decoded_fd;
    struct stat original_file_status;
    char * decoded_file;

    if(argc != 3)
    {
        printf("Usage : arithmetic_code <-e|-d> filepath\n");
        return 1;
    }
    char * original_file_name = argv[2];

    if(strcmp(argv[1], "-e") == 0)
    {

        char * original_file_name = argv[2];

        if( (decoded_fd = open(original_file_name, O_RDONLY))  == -1 )
        {
            printf("open %s failed\n", original_file_name);
            return 1;
        }

        if( (fstat(decoded_fd, &original_file_status)) == -1 )
        {
            printf("fstat %s failed\n", original_file_name);
            return 1;
        }

        get_probability_from_file(decoded_fd, p_d);
        if(lseek(decoded_fd, 0, SEEK_SET) == -1)
        {
        
            printf("lseek failed\n");
            return 1;
        }

        print_p(p_d, P_LENGTH);
        printf("\n");
        
        Code encode;
        Text text;

        encode.len = INIT_LENGTH;
        encode.fill_len = 0;
        encode.bit_len = 0;
        if( (encode.content = (char *)malloc(sizeof(char) * INIT_LENGTH)) == NULL )
        {
            printf("malloc memery failed\n");
            exit(1);
        }
        memset(encode.content, 0, INIT_LENGTH);

        int sum = 0;
        for(int i = 0; i < P_LENGTH; i++)
        {
            if(p_d[i] != 0)
            {
                encode.f_d[i] = sum;
                sum += p_d[i];
            }
            else
            {
                encode.f_d[i] = -1;
            }
        }
        encode.f_d[P_LENGTH] = sum;

        print_p(encode.f_d, P_LENGTH + 1);
        printf("\n");


        text.len = original_file_status.st_size;
        encode.text_len = text.len;
        text.read_len = 0;
        text.original_fd = decoded_fd;
        if( (text.content = (char *)malloc(sizeof(char) * (INIT_LENGTH + 1))) == NULL )
        {
            printf("text.content malloc memery failed\n");
            exit(1);
        }
        memset(text.content, 0, INIT_LENGTH);

        char * compress_file_name;
        int compress_file_name_len;
        compress_file_name_len = 
                strlen(original_file_name) + strlen(COMPRESS_SUFFIX) + 1;
        if( (compress_file_name = 
            (char *)malloc(sizeof(char) * (compress_file_name_len))) == NULL )
        {
            printf("text.compress_file_name malloc memery failed\n");
            exit(1);
        }
        memset(compress_file_name, 0, compress_file_name_len);
        strcat(compress_file_name, original_file_name);
        strcat(compress_file_name, COMPRESS_SUFFIX);
        if( (text.encode_fd = open(compress_file_name, O_WRONLY | O_CREAT | O_TRUNC))  == -1 )
        {
            printf("text.encode_fd open %s failed\n", argv[1]);
            return 1;
        }

    //-----------encode-text----------
    encode_text(&text, &encode);   
  }
  else if(strcmp(argv[1], "-d") == 0)
  {

    Code encode;
    char * compress_file_name;
    int encoded_fd;

    compress_file_name = argv[2];

    encode.len = 0;
    encode.fill_len = 0;
    encode.bit_len = 0;
    if( (encode.content = (char *)malloc(sizeof(char) * INIT_LENGTH)) == NULL )
    {
        printf("malloc memery failed\n");
        exit(1);
    }
    memset(encode.content, 0, INIT_LENGTH);

    if( (encoded_fd = open(compress_file_name, O_RDONLY))  == -1 )
    {
        printf("open %s failed\n", compress_file_name);
        return 1;
    }
//-----------decode-text-----------
    decode_text(&encode, encoded_fd);

  }
  else
  {
      printf("Usage : arithmetic_code <-e|-d> filepath\n");
  }


    return 0;
}
Example #7
0
static void
print_html_request_report (FILE * fp, GHolder * h, int process)
{
#ifdef TCB_BTREE
  TCBDB *ht = NULL;
#elif TCB_MEMHASH
  TCMDB *ht = NULL;
#else
  GHashTable *ht;
#endif

  char *data, *bandwidth, *usecs;
  const char *desc = REQUE_DESC;
  const char *head = REQUE_HEAD;
  const char *id = REQUE_ID;
  float percent;
  int hits;
  int i, until = 0;

  if (h->idx == 0)
    return;

  ht = get_ht_by_module (h->module);

  if (ht == ht_requests_static) {
    head = STATI_HEAD;
    id = STATI_ID;
    desc = STATI_DESC;
  } else if (ht == ht_not_found_requests) {
    head = FOUND_HEAD;
    id = FOUND_ID;
    desc = FOUND_DESC;
  }

  print_html_h2 (fp, head, id);
  print_p (fp, desc);
  print_html_begin_table (fp);
  print_html_begin_thead (fp);

  fprintf (fp, "<tr>");
  fprintf (fp, "<th>Hits</th>");
  fprintf (fp, "<th>%%</th>");
  fprintf (fp, "<th>Bandwidth</th>");
  if (conf.serve_usecs)
    fprintf (fp, "<th>Time&nbsp;served</th>");
  if (conf.append_protocol)
    fprintf (fp, "<th>Protocol</th>");
  if (conf.append_method)
    fprintf (fp, "<th>Method</th>");
  fprintf (fp, "<th>URL<span class=\"r\" onclick=\"t(this)\">◀</span>");
  fprintf (fp, "</th>");
  fprintf (fp, "</tr>");

  print_html_end_thead (fp);
  print_html_begin_tbody (fp);

  until = h->idx < MAX_CHOICES ? h->idx : MAX_CHOICES;
  for (i = 0; i < until; i++) {
    hits = h->items[i].hits;
    data = h->items[i].data;
    percent = get_percentage (process, hits);
    percent = percent < 0 ? 0 : percent;
    bandwidth = filesize_str (h->items[i].bw);

    print_html_begin_tr (fp, i > OUTPUT_N ? 1 : 0);

    /* hits */
    fprintf (fp, "<td>%d</td>", hits);
    /* percent */
    fprintf (fp, "<td>%4.2f%%</td>", percent);
    /* bandwidth */
    fprintf (fp, "<td>");
    clean_output (fp, bandwidth);
    fprintf (fp, "</td>");

    /* usecs */
    if (conf.serve_usecs) {
      usecs = usecs_to_str (h->items[i].usecs);
      fprintf (fp, "<td>");
      clean_output (fp, usecs);
      fprintf (fp, "</td>");
      free (usecs);
    }
    /* protocol */
    if (conf.append_protocol) {
      fprintf (fp, "<td>");
      clean_output (fp, h->items[i].protocol);
      fprintf (fp, "</td>");
    }
    /* method */
    if (conf.append_method) {
      fprintf (fp, "<td>");
      clean_output (fp, h->items[i].method);
      fprintf (fp, "</td>");
    }

    /* data */
    fprintf (fp, "<td>");
    clean_output (fp, data);
    fprintf (fp, "</td>");

    print_html_end_tr (fp);

    free (bandwidth);
  }

  print_html_end_tbody (fp);
  print_html_end_table (fp);
}
Example #8
0
static void
print_html_hosts (FILE * fp, GHolder * h, int process)
{
  GAgents *agents;

  char *data, *bandwidth, *usecs, *ag, *ptr_value, *host;
  float percent, l;
  int hits;
  int i, j, max, until = 0, delims = 0, colspan = 6;
  size_t alloc = 0;

#ifdef HAVE_LIBGEOIP
  const char *location = NULL;
  colspan++;
#endif

  if (h->idx == 0)
    return;

  print_html_h2 (fp, HOSTS_HEAD, HOSTS_ID);
  print_p (fp, HOSTS_DESC);
  print_html_begin_table (fp);
  print_html_begin_thead (fp);

  fprintf (fp, "<tr>");
  fprintf (fp, "<th></th>");
  fprintf (fp, "<th>Hits</th>");
  fprintf (fp, "<th>%%</th>");
  fprintf (fp, "<th>Bandwidth</th>");
  if (conf.serve_usecs) {
    colspan++;
    fprintf (fp, "<th>Time&nbsp;served</th>");
  }
  fprintf (fp, "<th>IP</th>");
#ifdef HAVE_LIBGEOIP
  fprintf (fp, "<th>Country</th>");
#endif
  if (conf.enable_html_resolver) {
    colspan++;
    fprintf (fp, "<th>Hostname</th>");
  }

  fprintf (fp, "<th style=\"width:100%%;text-align:right;\">");
  fprintf (fp, "<span class=\"r\" onclick=\"t(this)\">◀</span>");
  fprintf (fp, "</th>");
  fprintf (fp, "</tr>");

  print_html_end_thead (fp);
  print_html_begin_tbody (fp);

  until = h->idx < MAX_CHOICES ? h->idx : MAX_CHOICES;
  max = 0;
  for (i = 0; i < until; i++) {
    if (h->items[i].hits > max)
      max = h->items[i].hits;
  }

  for (i = 0; i < until; i++) {
    hits = h->items[i].hits;
    data = h->items[i].data;
    percent = get_percentage (process, hits);
    percent = percent < 0 ? 0 : percent;
    bandwidth = filesize_str (h->items[i].bw);
    l = get_percentage (max, hits);
    l = l < 1 ? 1 : l;

#ifdef HAVE_LIBTOKYOCABINET
    ag = tc_db_get_str (ht_hosts_agents, data);
#else
    ag = g_hash_table_lookup (ht_hosts_agents, data);
#endif

    print_html_begin_tr (fp, i > OUTPUT_N ? 1 : 0);
    fprintf (fp, "<td>");
    if (ag != NULL)
      fprintf (fp, "<span class=\"s\" onclick=\"a(this)\">▶</span>");
    else
      fprintf (fp, "<span class=\"s\">-</span>");
    fprintf (fp, "</td>");

    fprintf (fp, "<td>%d</td>", hits);
    fprintf (fp, "<td>%4.2f%%</td>", percent);

    fprintf (fp, "<td>");
    clean_output (fp, bandwidth);
    fprintf (fp, "</td>");

    /* usecs */
    if (conf.serve_usecs) {
      usecs = usecs_to_str (h->items[i].usecs);
      fprintf (fp, "<td>");
      clean_output (fp, usecs);
      fprintf (fp, "</td>");
      free (usecs);
    }

    fprintf (fp, "<td>%s</td>", data);

#ifdef HAVE_LIBGEOIP
    location = get_geoip_data (data);
    fprintf (fp, "<td style=\"white-space:nowrap;\">%s</td>", location);
#endif

    if (conf.enable_html_resolver) {
      host = reverse_ip (data);
      fprintf (fp, "<td style=\"white-space:nowrap;\">%s</td>", host);
      free (host);
    }

    fprintf (fp, "<td class=\"graph\">");
    fprintf (fp, "<div class=\"bar\" style=\"width:%f%%\"></div>", l);
    fprintf (fp, "</td>");
    print_html_end_tr (fp);

    /* render agents for each host */
    if (ag != NULL) {
      ptr_value = (char *) ag;

      delims = count_occurrences (ptr_value, '|');
      /* round-up + padding */
      alloc = ((strlen (ptr_value) + 300 - 1) / 300) + delims + 1;
      agents = xmalloc (alloc * sizeof (GAgents));
      memset (agents, 0, alloc * sizeof (GAgents));

      /* split agents into struct */
      split_agent_str (ptr_value, agents, 300);

      fprintf (fp, "<tr class=\"agent-hide\">\n");
      fprintf (fp, "<td colspan=\"%d\">\n", colspan);
      fprintf (fp, "<div>");
      fprintf (fp, "<table class=\"pure-table-striped\">");

      /* output agents from struct */
      for (j = 0; (j < 10) && (agents[j].agents != NULL); j++) {
        print_html_begin_tr (fp, 0);
        fprintf (fp, "<td>");
        clean_output (fp, agents[j].agents);
        fprintf (fp, "</td>");
        print_html_end_tr (fp);
      }

      fprintf (fp, "</table>\n");
      fprintf (fp, "</div>\n");
      fprintf (fp, "</td>\n");
      print_html_end_tr (fp);

      for (j = 0; (agents[j].agents != NULL); j++)
        free (agents[j].agents);
      free (agents);
#ifdef HAVE_LIBTOKYOCABINET
      if (ag)
        free (ag);
#endif
    }

    free (bandwidth);
  }

  print_html_end_tbody (fp);
  print_html_end_table (fp);
}
Example #9
0
static void
print_html_browser_os (FILE * fp, GHolder * h)
{
  char *data;
  const char *desc = OPERA_DESC;
  const char *head = OPERA_HEAD;
  const char *id = OPERA_ID;
  float percent, l;
  GSubList *sub_list;
  int hits, i, max, process = get_ht_size (ht_unique_visitors);

  if (h->idx == 0)
    return;

  if (h->module == BROWSERS) {
    head = BROWS_HEAD;
    id = BROWS_ID;
    desc = BROWS_DESC;
  }

  print_html_h2 (fp, head, id);
  print_p (fp, desc);
  print_html_begin_table (fp);
  print_html_begin_thead (fp);

  fprintf (fp, "<tr>");
  fprintf (fp, "<th>Visitors</th>");
  fprintf (fp, "<th>%%</th>");
  fprintf (fp, "<th>Name</th>");
  fprintf (fp, "<th style=\"width:100%%;text-align:right;\">");
  fprintf (fp, "<span class=\"r\" onclick=\"t(this)\">◀</span>");
  fprintf (fp, "</th>");
  fprintf (fp, "</tr>");

  print_html_end_thead (fp);
  print_html_begin_tbody (fp);

  max = 0;
  for (i = 0; i < h->idx; i++) {
    if (h->items[i].hits > max)
      max = h->items[i].hits;
  }

  for (i = 0; i < h->idx; i++) {
    hits = h->items[i].hits;
    data = h->items[i].data;
    percent = get_percentage (process, hits);
    percent = percent < 0 ? 0 : percent;

    l = get_percentage (max, hits);
    l = l < 1 ? 1 : l;

    print_html_begin_tr (fp, 0);
    fprintf (fp, "<td>%d</td>", hits);
    fprintf (fp, "<td>%4.2f%%</td>", percent);

    /* data */
    fprintf (fp, "<td>");
    clean_output (fp, data);
    fprintf (fp, "</td>");

    fprintf (fp, "<td class=\"graph\">");
    fprintf (fp, "<div class=\"bar\" style=\"width:%f%%\"></div>", l);
    fprintf (fp, "</td>");
    print_html_end_tr (fp);

    sub_list = h->items[i].sub_list;
    print_html_sub_browser_os (fp, sub_list, process);
  }

  print_html_end_tbody (fp);
  print_html_end_table (fp);
}
Example #10
0
static void
print_html_generic (FILE * fp, GHolder * h, int process)
{
  char *data;
  const char *desc = REFER_DESC;
  const char *head = REFER_HEAD;
  const char *id = REFER_ID;
  float percent;
  int hits, i, until = 0;

  if (h->idx == 0)
    return;

  if (h->module == NOT_FOUND) {
    head = FOUND_HEAD;
    id = FOUND_ID;
    desc = FOUND_DESC;
  } else if (h->module == REFERRING_SITES) {
    head = SITES_HEAD;
    id = SITES_ID;
    desc = SITES_DESC;
  } else if (h->module == KEYPHRASES) {
    head = KEYPH_HEAD;
    id = KEYPH_ID;
    desc = KEYPH_DESC;
  }

  print_html_h2 (fp, head, id);
  print_p (fp, desc);
  print_html_begin_table (fp);
  print_html_begin_thead (fp);

  fprintf (fp, "<tr>");
  fprintf (fp, "<th>Hits</th>");
  fprintf (fp, "<th>%%</th>");
  fprintf (fp, "<th>URL<span class=\"r\" onclick=\"t(this)\">◀</span></th>");
  fprintf (fp, "</tr>");

  print_html_end_thead (fp);
  print_html_begin_tbody (fp);

  until = h->idx < MAX_CHOICES ? h->idx : MAX_CHOICES;
  for (i = 0; i < until; i++) {
    hits = h->items[i].hits;
    data = h->items[i].data;
    percent = get_percentage (process, hits);
    percent = percent < 0 ? 0 : percent;

    print_html_begin_tr (fp, i > OUTPUT_N ? 1 : 0);

    fprintf (fp, "<td>%d</td>", hits);
    fprintf (fp, "<td>%4.2f%%</td>", percent);
    fprintf (fp, "<td>");
    clean_output (fp, data);
    fprintf (fp, "</td>");

    print_html_end_tr (fp);
  }

  print_html_end_tbody (fp);
  print_html_end_table (fp);
}
Example #11
0
static void
print_html_visitors_report (FILE * fp, GHolder * h)
{
  char *data, *bandwidth, buf[DATE_LEN];
  float percent, l;
  int hits, i, max, process = get_ht_size (ht_unique_visitors);

  /* make compiler happy */
  memset (buf, 0, sizeof (buf));

  print_html_h2 (fp, VISIT_HEAD, VISIT_ID);
  print_p (fp, VISIT_DESC);
  print_html_begin_table (fp);
  print_html_begin_thead (fp);

  fprintf (fp, "<tr>");
  fprintf (fp, "<th>Visitors</th>");
  fprintf (fp, "<th>%%</th>");
  fprintf (fp, "<th>Date</th>");
  fprintf (fp, "<th>Bandwidth</th>");
  fprintf (fp, "<th style=\"width:100%%;text-align:right;\">");
  fprintf (fp, "<span class=\"r\" onclick=\"t(this)\">◀</span>");
  fprintf (fp, "</th>");
  fprintf (fp, "</tr>");

  print_html_end_thead (fp);

  print_html_begin_tbody (fp);

  max = 0;
  for (i = 0; i < h->idx; i++) {
    if (h->items[i].hits > max)
      max = h->items[i].hits;
  }
  for (i = 0; i < h->idx; i++) {
    hits = h->items[i].hits;
    data = h->items[i].data;
    percent = get_percentage (process, hits);
    percent = percent < 0 ? 0 : percent;
    bandwidth = filesize_str (h->items[i].bw);

    l = get_percentage (max, hits);
    l = l < 1 ? 1 : l;

    print_html_begin_tr (fp, i > OUTPUT_N ? 1 : 0);

    /* hits */
    fprintf (fp, "<td>%d</td>", hits);
    if (hits == max)
      fprintf (fp, "<td class=\"max\">%4.2f%%</td>", percent);
    else
      fprintf (fp, "<td>%4.2f%%</td>", percent);

    /* date */
    convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN);
    fprintf (fp, "<td>%s</td>", buf);

    /* bandwidth */
    fprintf (fp, "<td>");
    clean_output (fp, bandwidth);
    fprintf (fp, "</td>");

    /* bars */
    fprintf (fp, "<td class=\"graph\">");
    fprintf (fp, "<div class=\"bar\" style=\"width:%f%%\"></div>", l);
    fprintf (fp, "</td>\n");

    print_html_end_tr (fp);

    free (bandwidth);
  }

  print_html_end_tbody (fp);
  print_html_end_table (fp);
}
void printMemoryProfile(unsigned long int delayMillis)                     // run over and over again
{
  print_p( PSTR("\n\n--------------------------------------------") );
  print_p( PSTR("\n\nget_free_memory() reports [") );
  Serial.print(get_free_memory());
  print_p( PSTR("] (bytes) which must be > 0 for no heap/stack collision") );
  

  // print_p( PSTR("\n\nSP should always be larger than HP or you'll be in big trouble!") );
  
  check_mem();

  print_p( PSTR("\nheapptr=[0x") ); Serial.print( (int) heapptr, HEX); print_p( PSTR("] (growing upward, ") ); Serial.print( (int) heapptr, DEC); print_p( PSTR(" decimal)") );
  
  print_p( PSTR("\nstackptr=[0x") ); Serial.print( (int) stackptr, HEX); print_p( PSTR("] (growing downward, ") ); Serial.print( (int) stackptr, DEC); print_p( PSTR(" decimal)") );
  
  print_p( PSTR("\ndiff=stackptr-heapptr, diff=[0x") );
  diff=stackptr-heapptr;
  Serial.print( (int) diff, HEX); print_p( PSTR("] (which is [") ); Serial.print( (int) diff, DEC); print_p( PSTR("] (bytes decimal)") );
  
  
  //---------------- Print memory profile -----------------
  print_p( PSTR("\n\n__data_start=[0x") ); Serial.print( (int) &__data_start, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) &__data_start, DEC); print_p( PSTR("] bytes decimal") );

  print_p( PSTR("\n__data_end=[0x") ); Serial.print((int) &__data_end, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) &__data_end, DEC); print_p( PSTR("] bytes decimal") );
  
  print_p( PSTR("\n__bss_start=[0x") ); Serial.print((int) & __bss_start, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) &__bss_start, DEC); print_p( PSTR("] bytes decimal") );

  print_p( PSTR("\n__bss_end=[0x") ); Serial.print( (int) &__bss_end, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) &__bss_end, DEC); print_p( PSTR("] bytes decimal") );

  print_p( PSTR("\n__heap_start=[0x") ); Serial.print( (int) &__heap_start, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) &__heap_start, DEC); print_p( PSTR("] bytes decimal") );

  print_p( PSTR("\n__malloc_heap_start=[0x") ); Serial.print( (int) __malloc_heap_start, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) __malloc_heap_start, DEC); print_p( PSTR("] bytes decimal") );

  print_p( PSTR("\n__malloc_margin=[0x") ); Serial.print( (int) &__malloc_margin, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) &__malloc_margin, DEC); print_p( PSTR("] bytes decimal") );

  print_p( PSTR("\n__brkval=[0x") ); Serial.print( (int) __brkval, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) __brkval, DEC); print_p( PSTR("] bytes decimal") );

  print_p( PSTR("\nSP=[0x") ); Serial.print( (int) SP, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) SP, DEC); print_p( PSTR("] bytes decimal") );

  print_p( PSTR("\nRAMEND=[0x") ); Serial.print( (int) RAMEND, HEX ); print_p( PSTR("] which is [") ); Serial.print( (int) RAMEND, DEC); print_p( PSTR("] bytes decimal") );

  summaries:
  ramSize   = (int) RAMEND       - (int) &__data_start;
  dataSize  = (int) &__data_end  - (int) &__data_start;
  bssSize   = (int) &__bss_end   - (int) &__bss_start;
  heapSize  = (int) __brkval     - (int) &__heap_start;
  stackSize = (int) RAMEND       - (int) SP;
  freeMem1  = (int) SP           - (int) __brkval;
  freeMem2  = ramSize - stackSize - heapSize - bssSize - dataSize;
  print_p( PSTR("\n--- section size summaries ---") );
  print_p( PSTR("\nram   size=[") ); Serial.print( ramSize, DEC ); print_p( PSTR("] bytes decimal") );
  print_p( PSTR("\n.data size=[") ); Serial.print( dataSize, DEC ); print_p( PSTR("] bytes decimal") );
  print_p( PSTR("\n.bss  size=[") ); Serial.print( bssSize, DEC ); print_p( PSTR("] bytes decimal") );
  print_p( PSTR("\nheap  size=[") ); Serial.print( heapSize, DEC ); print_p( PSTR("] bytes decimal") );
  print_p( PSTR("\nstack size=[") ); Serial.print( stackSize, DEC ); print_p( PSTR("] bytes decimal") );
  print_p( PSTR("\nfree size1=[") ); Serial.print( freeMem1, DEC ); print_p( PSTR("] bytes decimal") );
  print_p( PSTR("\nfree size2=[") ); Serial.print( freeMem2, DEC ); print_p( PSTR("] bytes decimal") );
  
  delay(delayMillis);
 
}