コード例 #1
0
ファイル: webserver-admin.c プロジェクト: Scypho/6lbr
static
PT_THREAD(generate_plugins(struct httpd_state *s))
{
  static sixlbr_plugin_info_t const *info;
  PSOCK_BEGIN(&s->sout);

  add("<h2>Plugins</h2>");
  add
    ("<table>"
     "<theader><tr class=\"row_first\"><td>Plugin ID</td><td>Description</td><td>Status</td><td>Version</td><td>Init</td><td>Status</td></tr></theader>"
     "<tbody>");
  SEND_STRING(&s->sout, buf);
  reset_buf();
  info = plugins_list_head();
  while(info != NULL) {
    add("<tr><td>%s</td><td>%s</td>", info->plugin->id, info->plugin->description);
    if(info->status == 0) {
      add("<td>Loaded</td><td>%s</td><td>%s</td><td>%s</td></tr>",
          info->plugin->version ? info->plugin->version() : "Unknown",
          info->init_status == 0 ? "Successful" : "Failed",
          info->plugin->status ? info->plugin->status() : "Unknown");
    } else {
      add("<td>Not loaded</td><td></td><td></td><td></td></tr>");
    }
    info = info->next;
    SEND_STRING(&s->sout, buf);
    reset_buf();
  }
  add("</tbody></table><br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();
  PSOCK_END(&s->sout);
}
コード例 #2
0
ファイル: get_next_line.c プロジェクト: abouvier/libft
static int	set_next_line(t_buffer *buf, char *newline, char **line)
{
	char	*s;
	t_list	*chunk;
	size_t	new_size;

	if (newline)
	{
		new_size = buf->CHUNK_SIZE - (newline - (char *)buf->CHUNK) - 1;
		if (!(s = ft_strnew(new_size - 1)))
			return (reset_buf(buf, NULL));
		ft_memcpy(s, newline + 1, new_size);
		buf->CHUNK_SIZE -= new_size + 1;
		buf->size -= new_size + 1;
	}
	if (!(*line = ft_strnew(buf->size)))
		return (reset_buf(buf, &s));
	build_line(buf, *line);
	if (newline)
	{
		if (!(chunk = ft_lstnew(s, new_size)))
			return (reset_buf(buf, &s));
		ft_lstadd(&buf->chunks, chunk);
		buf->size = new_size;
	}
	return (1);
}
コード例 #3
0
ファイル: webserver.c プロジェクト: TiagoLourenco/6lbr
/*---------------------------------------------------------------------------*/
static
PT_THREAD(generate_reboot(struct httpd_state *s))
{
#if BUF_USES_STACK
  char buf[BUF_SIZE];
#endif
  PSOCK_BEGIN(&s->sout);

  SEND_STRING(&s->sout, TOP);
  SEND_STRING(&s->sout,
              "<meta http-equiv=\"refresh\" content=\"2; url=/config.html\" />");
  SEND_STRING(&s->sout, BODY);
  reset_buf();
  add_div_home("Reboot");
  add("<div id=\"left_home\">");
  add("Restarting BR...<br />");
  add
    ("<a href=\"/config.html\">Click here if the page is not refreshing</a><br /><br />");
  add("</div>");
  SEND_STRING(&s->sout, buf);
  reset_buf();

  SEND_STRING(&s->sout, BOTTOM);

  process_post(&cetic_6lbr_process, 0, NULL);

  PSOCK_END(&s->sout);
}
コード例 #4
0
ファイル: wry.c プロジェクト: malleusinferni/wry
void del_buf(size_t i) {
    char save[BUFSIZ];
    if (buf.i < 1) return;
    strncpy(save, buf.s, i);
    save[i] = '\0';
    reset_buf(save);
}
コード例 #5
0
/* State function */
static int read_file(struct connection *conn)
{
	size_t bytes;

	bytes = conn->endp - conn->curp;
	if (bytes > 0) {
		if (!write_output(conn, bytes))
			return 1;
		conn->length -= bytes;
		if (conn->length <= 0) {
			if (verbose)
				printf("OK %s\n", conn->url);
			if (conn->regexp && !conn->matched)
				return do_process_html(conn);
			close_connection(conn);
			return 0;
		}
	} else {
		printf("Read file problems %zu for %s!\n", bytes, conn->url);
		return 1;
	}

	reset_buf(conn);
	return 0;
}
コード例 #6
0
ファイル: reader.c プロジェクト: qyqx/wisp
/* Turn string in buffer into string object. */
static object_t *parse_str (reader_t * r)
{
  size_t size = r->bufp - r->buf;
  char *str = xstrdup (r->buf);
  reset_buf (r);
  return c_str (str, size);
}
コード例 #7
0
/* State function */
static int read_file_gzip(struct connection *conn)
{
	size_t bytes;
	int rc;

	bytes = conn->endp - conn->curp;
	if (bytes <= 0) {
		printf("Read file problems %zu for %s!\n", bytes, conn->url);
		return 1;
	}

	rc = write_output_gzipped(conn, bytes);
	if (rc < 0)
		return 1;

	conn->length -= bytes;
	if (conn->length <= 0 || rc == Z_STREAM_END) {
		if (verbose)
			printf("OK %s\n", conn->url);
		if (conn->regexp && !conn->matched)
			return do_process_html(conn);
		close_connection(conn);
		return 0;
	}

	reset_buf(conn);
	return 0;
}
コード例 #8
0
void write_request(struct connection *conn)
{
	int n; /* must be signed. windows does not support ssize_t */

#ifdef WANT_SSL
	if (conn->ssl) {
		n = openssl_write(conn);
		/* openssl_write can return -EAGAIN if the SSL
		 * connection needs a read or write. */
		if (n == -EAGAIN)
			return;
	} else
#endif
		n = send(conn->poll->fd, conn->curp, conn->length,
			 MSG_NOSIGNAL);

	if (n == conn->length) {
		if (verbose > 2)
			printf("+ Sent request\n");
		conn->length = 0;

		/* reset for read */
		set_readable(conn);
		reset_buf(conn);
		NEXT_STATE(conn, read_reply);
	} else if (n > 0) {
		conn->length -= n;
		conn->curp += n;
	} else {
		printf("Write request error\n");
		fail_connection(conn);
	}
}
コード例 #9
0
ファイル: reactor.cpp プロジェクト: QEver/vosproj
boss::Socket::Socket()
:  _socket_fd(INVALID_SOCKET)
{
    _error_text[0] = '\0';

    reset_buf();
}
コード例 #10
0
ファイル: wry.c プロジェクト: malleusinferni/wry
void append_buf(char c) {
    if (c == '\n') {
        break_at(buf.i);
        reset_buf("");
    } else {
        insert_ch(c);
        if (buf.i > WRAP_SIZE) {
            char save[BUFSIZ] = "";
            if (buf.inword) {
                // TODO Handle words too long to wrap
                strncpy(save, buf.s + buf.wbeg, buf.i - buf.wbeg);
                buf.wc--;
            }
            break_at(buf.wbreak);
            reset_buf(save);
        }
    }
}
コード例 #11
0
ファイル: reader.c プロジェクト: qyqx/wisp
/* Remove top object from the sexp stack. */
static void reset (reader_t * r)
{
  r->done = 1;
  while (r->state != r->base)
    obj_destroy (pop (r));
  reset_buf (r);
  r->readbufp = r->readbuf;
  r->done = 0;
}
コード例 #12
0
ファイル: reader.c プロジェクト: qyqx/wisp
/* Turn string in buffer into atom object. */
static object_t *parse_atom (reader_t * r)
{
  char *str = r->buf;
  char *end;

  /* Detect integer */
  int i = strtol (str, &end, 10);
  (void) i;
  if (end != str && *end == '\0')
    {
      object_t *o = c_ints (str);
      reset_buf (r);
      return o;
    }

  /* Detect float */
  int d = strtod (str, &end);
  (void) d;
  if (end != str && *end == '\0')
    {
      object_t *o = c_floats (str);
      reset_buf (r);
      return o;
    }

  /* Might be a symbol then */
  char *p = r->buf;
  while (p <= r->bufp)
    {
      if (strchr (atom_chars, *p) == NULL)
	{
	  char *errstr = xstrdup ("invalid symbol character: X");
	  errstr[strlen (errstr) - 1] = *p;
	  read_error (r, errstr);
	  xfree (errstr);
	  return NIL;
	}
      p++;
    }
  object_t *o = c_sym (r->buf);
  reset_buf (r);
  return o;
}
コード例 #13
0
ファイル: webserver-admin.c プロジェクト: Scypho/6lbr
static
PT_THREAD(generate_admin(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sout);

  add("<h2>Administration</h2>");
#if CONTIKI_TARGET_NATIVE
  add("<h3>Logs</h3>");
  add("<form action=\"log\" method=\"get\">");
  add("<input type=\"submit\" value=\"Show log file\"/></form><br />");
  add("<form action=\"err\" method=\"get\">");
  add("<input type=\"submit\" value=\"Show error log file\"/></form><br />");
  add("<form action=\"clear-log\" method=\"get\">");
  add("<input type=\"submit\" value=\"Clear log file\"/></form><br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();
#endif
  add("<h3>Restart</h3>");
#if CONTIKI_TARGET_NATIVE
  add("<form action=\"reset-sr\" method=\"get\">");
  add("<input type=\"submit\" value=\"Reset slip-radio\"/></form><br />");
#endif
  add("<form action=\"restart\" method=\"get\">");
  add("<input type=\"submit\" value=\"Restart 6LBR\"/></form><br />");
#if CONTIKI_TARGET_NATIVE
  add("<form action=\"reboot\" method=\"get\">");
  add("<input type=\"submit\" value=\"Reboot 6LBR\"/></form><br />");
#endif
  SEND_STRING(&s->sout, buf);
  reset_buf();
#if CONTIKI_TARGET_NATIVE
  add("<form action=\"halt\" method=\"get\">");
  add("<input type=\"submit\" value=\"Halt 6LBR\"/></form><br />");
#endif
  add("<h3>Configuration</h3>");
  add("<form action=\"reset-config\" method=\"get\">");
  add("<input type=\"submit\" value=\"Reset NVM to factory default\"/></form><br />");

  SEND_STRING(&s->sout, buf);
  reset_buf();
  PSOCK_END(&s->sout);
}
コード例 #14
0
static char *get_buf(struct connection *conn)
{
	if (!conn->buf) {
		if (freelist) {
			conn->buf = freelist->buf;
			freelist = freelist->next;
			reset_buf(conn);
		} else
			conn->buf = malloc(BUFSIZE + 1);
	}
	return conn->buf;
}
コード例 #15
0
ファイル: webserver.c プロジェクト: TiagoLourenco/6lbr
/*---------------------------------------------------------------------------*/
static
PT_THREAD(generate_404(struct httpd_state *s))
{
#if BUF_USES_STACK
  char buf[BUF_SIZE];
#endif
  PSOCK_BEGIN(&s->sout);

  SEND_STRING(&s->sout, TOP);
  SEND_STRING(&s->sout, BODY);
  reset_buf();
  add_div_home("404");
  add("<div id=\"left_home\">");
  add("404 : Page not found<br />");
  add_div_footer();
  add("</div></div>");
  SEND_STRING(&s->sout, buf);
  reset_buf();

  SEND_STRING(&s->sout, BOTTOM);
  PSOCK_END(&s->sout);
}
コード例 #16
0
/* reads the status of the device */
static void read_status(struct denali_nand_info *denali)
{
	uint32_t cmd = 0x0;

	/* initialize the data buffer to store status */
	reset_buf(denali);

	cmd = ioread32(denali->flash_reg + WRITE_PROTECT);
	if (cmd)
		write_byte_to_buf(denali, NAND_STATUS_WP);
	else
		write_byte_to_buf(denali, 0);
}
コード例 #17
0
static
PT_THREAD(generate_sensors_prr(struct httpd_state *s))
{
  static int i;

  PSOCK_BEGIN(&s->sout);
  SEND_STRING(&s->sout, graph_top);
  add("['Sensor', 'IP', 'PRR Up', 'PRR Down'],");
  for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
    if(node_info_table[i].isused && node_info_table[i].messages_sent > 0 && node_info_table[i].replies_sent > 0) {
      float prr_up = 100.0 * (node_info_table[i].messages_sent - node_info_table[i].up_messages_lost)/node_info_table[i].messages_sent;
      float prr_down = 100.0 * (node_info_table[i].replies_sent - node_info_table[i].down_messages_lost)/node_info_table[i].replies_sent;
#if CETIC_NODE_CONFIG_HAS_NAME
      if (node_config_loaded) {
        node_config_t * node_config = node_config_find_by_ip(&node_info_table[i].ipaddr);
        add("[\"%s\",", node_config_get_name(node_config));
      } else
#endif
      {
        add("[\"");
        ipaddr_add(&node_info_table[i].ipaddr);
        add("\",");
      }
      add("\"");
      ipaddr_add(&node_info_table[i].ipaddr);
      add("\",%.1f,%.1f],", prr_up, prr_down);
      SEND_STRING(&s->sout, buf);
      reset_buf();
    }
  }
  add("]);var options={vAxis:{minValue: 0,maxValue: 100},legend:{position: \"none\"}};");
  SEND_STRING(&s->sout, buf);
  reset_buf();

  SEND_STRING(&s->sout,graph_2_column);
  SEND_STRING(&s->sout,graph_bottom);
  PSOCK_END(&s->sout);
}
コード例 #18
0
ファイル: get_next_line.c プロジェクト: abouvier/libft
int			get_next_line(int const fd, char **line)
{
	ssize_t			r;
	char			*n;
	char			*s;
	static t_buffer	buf;
	t_list			*chunk;

	r = 42;
	while (!buf.chunks
		|| (!(n = ft_memchr(buf.CHUNK, '\n', buf.CHUNK_SIZE)) && r))
	{
		if (!(s = ft_strnew(BUF_SIZE - 1))
			|| (r = read(fd, s, BUF_SIZE)) < 0
			|| !(chunk = ft_lstnew(s, r)))
			return (reset_buf(&buf, &s));
		ft_lstadd(&buf.chunks, chunk);
		buf.size += r;
	}
	if (buf.size)
		return (set_next_line(&buf, n, line));
	reset_buf(&buf, NULL);
	return (0);
}
コード例 #19
0
/* State function */
static int read_chunkblock(struct connection *conn)
{
	size_t bytes;

	bytes = conn->endp - conn->curp;
	if (bytes > (size_t)conn->length)
		bytes = conn->length;

	if (bytes > 0) {
		if (conn->zs) {
			if (write_output_gzipped(conn, bytes) < 0) {
				printf("Gzipped write error\n");
				return 1;
			}
		} else if (!write_output(conn, bytes))
			return 1;
	}

	conn->length -= bytes;
	if (conn->length <= 0) {
		if (verbose > 1)
			printf("Read block\n");
		conn->curp += bytes;
		conn->length = 0;
		conn->cstate = CS_START_CR;
		NEXT_STATE(conn, read_file_chunked);
		if (conn->endp > conn->curp)
			return read_file_chunked(conn);
		else if (conn->rlen == 0)
			reset_buf(conn);
		return 0;
	}

	reset_buf(conn);
	return 0;
}
コード例 #20
0
static
PT_THREAD(generate_sensors_traffic(struct httpd_state *s))
{
  static int i;

  PSOCK_BEGIN(&s->sout);
  SEND_STRING(&s->sout, graph_top);
  add("['Sensor', 'IP', 'Up', 'Down'],");
  for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
    if(node_info_table[i].isused) {
#if CETIC_NODE_CONFIG_HAS_NAME
      if (node_config_loaded) {
        node_config_t * node_config = node_config_find_by_ip(&node_info_table[i].ipaddr);
        add("[\"%s\",", node_config_get_name(node_config));
      } else
#endif
      {
        add("[\"");
        ipaddr_add(&node_info_table[i].ipaddr);
        add("\",");
      }
      add("\"");
      ipaddr_add(&node_info_table[i].ipaddr);
      add("\",%u,%u],", node_info_table[i].sent.size, node_info_table[i].recv.size);
      SEND_STRING(&s->sout, buf);
      reset_buf();
    }
  }
  add("]);var options={vAxis:{minValue: 0},legend:{position: \"none\"}};");
  SEND_STRING(&s->sout, buf);
  reset_buf();

  SEND_STRING(&s->sout,graph_2_column);
  SEND_STRING(&s->sout,graph_bottom);
  PSOCK_END(&s->sout);
}
コード例 #21
0
/*
 * NAME:	init_pw_area
 *
 * DESCRIPTION: Initialize pre-write area to all zeros.
 *
 * PARAMETERS:	minor_t	      mnum      - minor number identity of metadevice
 *		md_dev64_t dev_to_write - index of column to resync
 *		int   column_index      - index of column to resync
 *
 * RETURN:	1 if write error on resync device, otherwise 0
 *
 * LOCKS:	Expects Unit Reader Lock to be held across call.
 */
int
init_pw_area(
	mr_unit_t *un,
	md_dev64_t dev_to_write,
	diskaddr_t pwstart,
	uint_t	col
)
{
	buf_t	buf;
	caddr_t	databuffer;
	size_t	copysize;
	size_t	bsize;
	int	error = 0;
	int	i;

	ASSERT(un != NULL);
	ASSERT(un->un_column[col].un_devflags & MD_RAID_DEV_ISOPEN);

	bsize = un->un_iosize;
	copysize = dbtob(bsize);
	databuffer = kmem_zalloc(copysize, KM_SLEEP);
	init_buf(&buf, (B_BUSY | B_WRITE), copysize);

	for (i = 0; i < un->un_pwcnt; i++) {
		/* magic field is 0 for 4.0 compatability */
		RAID_FILLIN_RPW(databuffer, un, 0, 0,
				0, 0, 0,
				0, col, 0);
		buf.b_un.b_addr = (caddr_t)databuffer;
		buf.b_edev = md_dev64_to_dev(dev_to_write);
		buf.b_bcount = dbtob(bsize);
		buf.b_lblkno = pwstart + (i * un->un_iosize);

		/* write buf */
		(void) md_call_strategy(&buf, MD_STR_NOTTOP, NULL);

		if (biowait(&buf)) {
			error = 1;
			break;
		}
		reset_buf(&buf, (B_BUSY | B_WRITE), copysize);
	} /* for */

	destroy_buf(&buf);
	kmem_free(databuffer, copysize);

	return (error);
}
コード例 #22
0
static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col,
			   int page)
{
	struct denali_nand_info *denali = mtd_to_denali(mtd);
	uint32_t addr, id;
	int i;

	switch (cmd) {
	case NAND_CMD_PAGEPROG:
		break;
	case NAND_CMD_STATUS:
		read_status(denali);
		break;
	case NAND_CMD_READID:
	case NAND_CMD_PARAM:
		reset_buf(denali);
		/*sometimes ManufactureId read from register is not right
		 * e.g. some of Micron MT29F32G08QAA MLC NAND chips
		 * So here we send READID cmd to NAND insteand
		 * */
		addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
		index_addr(denali, (uint32_t)addr | 0, 0x90);
		index_addr(denali, (uint32_t)addr | 1, 0);
		for (i = 0; i < 5; i++) {
			index_addr_read_data(denali,
						(uint32_t)addr | 2,
						&id);
			write_byte_to_buf(denali, id);
		}
		break;
	case NAND_CMD_READ0:
	case NAND_CMD_SEQIN:
		denali->page = page;
		break;
	case NAND_CMD_RESET:
		reset_bank(denali);
		break;
	case NAND_CMD_READOOB:
		/* TODO: Read OOB data */
		break;
	default:
		printk(KERN_ERR ": unsupported command"
				" received 0x%x\n", cmd);
		break;
	}
}
コード例 #23
0
static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col,
			   int page)
{
	struct denali_nand_info *denali = mtd_to_denali(mtd);
	uint32_t addr, id;
	int i;

	switch (cmd) {
	case NAND_CMD_PAGEPROG:
		break;
	case NAND_CMD_STATUS:
		read_status(denali);
		break;
	case NAND_CMD_READID:
	case NAND_CMD_PARAM:
		reset_buf(denali);
		addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
		index_addr(denali, (uint32_t)addr | 0, 0x90);
		index_addr(denali, (uint32_t)addr | 1, 0);
		for (i = 0; i < 5; i++) {
			index_addr_read_data(denali,
						(uint32_t)addr | 2,
						&id);
			write_byte_to_buf(denali, id);
		}
		break;
	case NAND_CMD_READ0:
	case NAND_CMD_SEQIN:
		denali->page = page;
		break;
	case NAND_CMD_RESET:
		reset_bank(denali);
		break;
	case NAND_CMD_READOOB:
		
		break;
	default:
		printk(KERN_ERR ": unsupported command"
				" received 0x%x\n", cmd);
		break;
	}
}
コード例 #24
0
/* State function */
static int read_file_unsized(struct connection *conn)
{
	size_t bytes;

	bytes = conn->endp - conn->curp;
	if (bytes > 0) {
		if (!write_output(conn, bytes))
			return 1;
	} else {
		if (verbose)
			printf("OK %s\n", conn->url);
		if (conn->regexp && !conn->matched)
			return do_process_html(conn);
		close_connection(conn);
		return 0;
	}

	reset_buf(conn);
	return 0;
}
コード例 #25
0
ファイル: SNES_SPC_misc.cpp プロジェクト: yupferris/snes_spc
void SNES_SPC::reset_time_regs()
{
	cpu_error     = 0;
	echo_accessed = 0;
	spc_time      = 0;
	dsp_time      = 0;
	
	for ( int i = 0; i < timer_count; i++ )
	{
		Timer* t = &timers [i];
		t->next_time = 1;
		t->divider   = 0;
	}
	
	enable_rom( REGS [r_control] & 0x80 );
	timers_loaded();
	
	extra_clocks = 0;
	reset_buf();
}
コード例 #26
0
ファイル: SNES_SPC_misc.cpp プロジェクト: loveemu/snsf9x
void SNES_SPC::reset_time_regs()
{
	m.cpu_error     = 0;
	m.echo_accessed = 0;
	m.spc_time      = 0;
	m.dsp_time      = 0;
	#if SPC_LESS_ACCURATE
		m.dsp_time = clocks_per_sample + 1;
	#endif
	
	for ( int i = 0; i < timer_count; i++ )
	{
		Timer* t = &m.timers [i];
		t->next_time = 1;
		t->divider   = 0;
	}
	
	regs_loaded();
	
	m.extra_clocks = 0;
	reset_buf();
}
コード例 #27
0
ファイル: toxic_strings.c プロジェクト: Ansa89/toxic
/* copies history item at hst_pos to line. Sets pos and len to the len of the history item.
   hst_pos is decremented or incremented depending on key_dir.

   resets line if at end of history */
void fetch_hist_item(ChatContext *ctx, int key_dir)
{
    if (key_dir == KEY_UP) {
        if (--ctx->hst_pos < 0) {
            ctx->hst_pos = 0;
            sound_notify(NULL, notif_error, NT_ALWAYS, NULL);
        }
    } else {
        if (++ctx->hst_pos >= ctx->hst_tot) {
            ctx->hst_pos = ctx->hst_tot;
            reset_buf(ctx);
            return;
        }
    }

    const wchar_t *hst_line = ctx->ln_history[ctx->hst_pos];
    size_t h_len = wcslen(hst_line);

    wmemcpy(ctx->line, hst_line, h_len + 1);
    ctx->pos = h_len;
    ctx->len = h_len;
}
コード例 #28
0
ファイル: SNES_SPC_misc.cpp プロジェクト: loveemu/snsf9x
void SNES_SPC::set_output( sample_t* out, int size )
{
	require( (size & 1) == 0 ); // size must be even
	
	m.extra_clocks &= clocks_per_sample - 1;
	if ( out )
	{
		sample_t const* out_end = out + size;
		m.buf_begin = out;
		m.buf_end   = out_end;
		
		// Copy extra to output
		sample_t const* in = m.extra_buf;
		while ( in < m.extra_pos && out < out_end )
			*out++ = *in++;
		
		// Handle output being full already
		if ( out >= out_end )
		{
			// Have DSP write to remaining extra space
			out     = dsp.extra();
			out_end = &dsp.extra() [extra_size];
			
			// Copy any remaining extra samples as if DSP wrote them
			while ( in < m.extra_pos )
				*out++ = *in++;
			assert( out <= out_end );
		}
		
		dsp.set_output( out, out_end - out );
	}
	else
	{
		reset_buf();
	}
}
コード例 #29
0
ファイル: toxic_strings.c プロジェクト: Kuronogard/toxic
/* copies history item at hst_pos to buf. Sets pos and len to the len of the history item.
   hst_pos is decremented or incremented depending on key_dir.
   
   resets buffer if at end of history */
void fetch_hist_item(wchar_t *buf, size_t *pos, size_t *len, wchar_t (*hst)[MAX_STR_SIZE],
                     int hst_tot, int *hst_pos, int key_dir)
{
    if (key_dir == MOVE_UP) {
        if (--(*hst_pos) < 0) {
            *hst_pos = 0;
            beep();
        }
    } else {
        if (++(*hst_pos) >= hst_tot) {
            *hst_pos = hst_tot;
            reset_buf(buf, pos, len);
            return;
        }
    }

    const wchar_t *hst_line = hst[*hst_pos];
    size_t h_len = wcslen(hst_line);

    wmemcpy(buf, hst_line, h_len + 1);

    *pos = h_len;
    *len = h_len;
}
コード例 #30
0
ファイル: webserver-statistics.c プロジェクト: Ayesha-N/6lbr
static
PT_THREAD(generate_statistics(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sout);

  add("<h2>IP</h2>");
#if UIP_STATISTICS
  add("<h3>IP</h3>");
  SEND_STRING(&s->sout, buf);
  reset_buf();
  PRINT_UIP_STAT( ip.recv, "Received packets" );
  PRINT_UIP_STAT( ip.sent, "Sent packets" );
  PRINT_UIP_STAT( ip.forwarded, "forwarded packets" );
  PRINT_UIP_STAT( ip.drop, "Dropped packets" );
  SEND_STRING(&s->sout, buf);
  reset_buf();
  PRINT_UIP_STAT( ip.vhlerr, "Wrong IP version or header length" );
  PRINT_UIP_STAT( ip.fragerr, "Dropped IP fragments" );
  PRINT_UIP_STAT( ip.chkerr, "Checksum errors" );
  PRINT_UIP_STAT( ip.protoerr, "Unsupported protocol" );
  add("<br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();

  add("<h3>ICMP</h3>");
  PRINT_UIP_STAT( icmp.recv, "Received packets" );
  PRINT_UIP_STAT( icmp.sent, "Sent packets" );
  PRINT_UIP_STAT( icmp.drop, "Dropped packets" );
  PRINT_UIP_STAT( icmp.typeerr, "Unsupported type" );
  PRINT_UIP_STAT( ip.chkerr, "Checksum errors" );
  add("<br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();

#if UIP_TCP
  add("<h3>TCP</h3>");
  PRINT_UIP_STAT( tcp.recv, "Received packets" );
  PRINT_UIP_STAT( tcp.sent, "Sent packets" );
  PRINT_UIP_STAT( tcp.drop, "Dropped packets" );
  PRINT_UIP_STAT( tcp.chkerr, "Checksum errors" );
  SEND_STRING(&s->sout, buf);
  reset_buf();
  PRINT_UIP_STAT( tcp.ackerr, "Ack errors" );
  PRINT_UIP_STAT( tcp.rst, "Received RST" );
  PRINT_UIP_STAT( tcp.rexmit, "retransmitted segments" );
  PRINT_UIP_STAT( tcp.syndrop, "Dropped SYNs" );
  PRINT_UIP_STAT( tcp.synrst, "SYNs for closed ports" );
  add("<br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();
#endif
#if UIP_UDP
  add("<h3>UDP</h3>");
  PRINT_UIP_STAT( udp.recv, "Received packets" );
  PRINT_UIP_STAT( udp.sent, "Sent packets" );
  PRINT_UIP_STAT( udp.drop, "Dropped packets" );
  PRINT_UIP_STAT( udp.chkerr, "Checksum errors" );
  add("<br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();
#endif
  add("<h3>NDP</h3>");
  PRINT_UIP_STAT( nd6.recv, "Received packets" );
  PRINT_UIP_STAT( nd6.sent, "Sent packets" );
  PRINT_UIP_STAT( nd6.drop, "Dropped packets" );
  add("<br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();
#else
  add("<h3>IP statistics are deactivated</h3>");
#endif /* UIP_STATISTICS */
#if UIP_CONF_IPV6_RPL
  add("<h2>RPL</h2>");
#if RPL_CONF_STATS
  PRINT_RPL_STAT( mem_overflows, "Memory overflow");
  PRINT_RPL_STAT( local_repairs, "Local repairs");
  PRINT_RPL_STAT( global_repairs, "Global repairs");
  SEND_STRING(&s->sout, buf);
  reset_buf();
  PRINT_RPL_STAT( malformed_msgs, "Invalid packets");
  PRINT_RPL_STAT( resets, "DIO timer resets");
  PRINT_RPL_STAT( parent_switch, "Parent switch");
  SEND_STRING(&s->sout, buf);
  reset_buf();
  PRINT_RPL_STAT( forward_errors, "Forward errors");
  PRINT_RPL_STAT( loop_errors, "Loop errors");
  PRINT_RPL_STAT( loop_warnings, "Loop warnings");
  PRINT_RPL_STAT( root_repairs, "Root repairs");
  add("<br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();
#else
  add("<h3>RPL statistics are deactivated</h3>");
#endif
#endif /* UIP_CONF_IPV6_RPL */
#if CETIC_CSMA_STATS

  add("<h2>CSMA</h2>");
  add("Allocated packets : %d<br />", csma_allocated_packets());
  add("Allocated neighbors : %d<br />", csma_allocated_neighbors());
  add("Packet overflow : %d<br />", packet_overflow);
  add("Neighbor overflow : %d<br />", neighbor_overflow);
  add("<br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();
  add("Send packets : %d<br />", csma_sent_packets);
  add("Received packets : %d<br />", csma_received_packets);
  add("Not acked packets : %d<br />", csma_noack);
  add("Collisions : %d<br />", csma_collisions);
  add("Retransmissions : %d<br />", csma_retransmissions);
  add("Dropped packets : %d<br />", csma_dropped);
  add("Deferred packets : %d<br />", csma_deferred);
  add("<br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();
#endif
#if CETIC_6LBR_LLSEC_STATS
  if(nvm_data.security_layer == CETIC_6LBR_SECURITY_LAYER_NONCORESEC) {
    add("<h2>LLSEC</h2>");
    add("Invalid level : %d<br />", noncoresec_invalid_level);
    add("Non authentic frames : %d<br />", noncoresec_nonauthentic);
    add("Reboot detected : %d<br />", noncoresec_reboot);
    add("Replayed frames : %d<br />", noncoresec_replayed);
    add("<br />");
    SEND_STRING(&s->sout, buf);
    reset_buf();
  }
#endif
  add("<h2>RDC</h2>");
#if CONTIKI_TARGET_NATIVE
  add("Callback count : %d<br />", callback_count);
  add("Ack timeout : %d<br />", native_rdc_ack_timeout);
  add("Parse error : %d<br />", native_rdc_parse_error);
#endif
  add("<br />");
  SEND_STRING(&s->sout, buf);
  reset_buf();
#if CONTIKI_TARGET_NATIVE
  add("<h2>SLIP</h2>");
  add("Messages sent : %d<br />", slip_message_sent);
  add("Messages received : %d<br />", slip_message_received);
  add("Bytes sent : %d<br />", slip_sent);
  add("Bytes received : %d<br />", slip_received);
  add("<br />");
#endif
  SEND_STRING(&s->sout, buf);
  reset_buf();

  PSOCK_END(&s->sout);
}