Exemplo n.º 1
0
static void
test_routerlist_router_is_already_dir_fetching(void *arg)
{
  (void)arg;
  tor_addr_port_t test_ap, null_addr_ap, zero_port_ap;

  /* Setup */
  tor_addr_parse(&test_ap.addr, TEST_ADDR_STR);
  test_ap.port = TEST_DIR_PORT;
  tor_addr_make_null(&null_addr_ap.addr, AF_INET6);
  null_addr_ap.port = TEST_DIR_PORT;
  tor_addr_parse(&zero_port_ap.addr, TEST_ADDR_STR);
  zero_port_ap.port = 0;
  MOCK(connection_get_by_type_addr_port_purpose,
       mock_connection_get_by_type_addr_port_purpose);

  /* Test that we never get 1 from a NULL connection */
  mocked_connection = NULL;
  tt_assert(router_is_already_dir_fetching(&test_ap, 1, 1) == 0);
  tt_assert(router_is_already_dir_fetching(&test_ap, 1, 0) == 0);
  tt_assert(router_is_already_dir_fetching(&test_ap, 0, 1) == 0);
  /* We always expect 0 in these cases */
  tt_assert(router_is_already_dir_fetching(&test_ap, 0, 0) == 0);
  tt_assert(router_is_already_dir_fetching(NULL, 1, 1) == 0);
  tt_assert(router_is_already_dir_fetching(&null_addr_ap, 1, 1) == 0);
  tt_assert(router_is_already_dir_fetching(&zero_port_ap, 1, 1) == 0);

  /* Test that we get 1 with a connection in the appropriate circumstances */
  mocked_connection = connection_new(CONN_TYPE_DIR, AF_INET);
  tt_assert(router_is_already_dir_fetching(&test_ap, 1, 1) == 1);
  tt_assert(router_is_already_dir_fetching(&test_ap, 1, 0) == 1);
  tt_assert(router_is_already_dir_fetching(&test_ap, 0, 1) == 1);

  /* Test that we get 0 even with a connection in the appropriate
   * circumstances */
  tt_assert(router_is_already_dir_fetching(&test_ap, 0, 0) == 0);
  tt_assert(router_is_already_dir_fetching(NULL, 1, 1) == 0);
  tt_assert(router_is_already_dir_fetching(&null_addr_ap, 1, 1) == 0);
  tt_assert(router_is_already_dir_fetching(&zero_port_ap, 1, 1) == 0);

 done:
  /* If a connection is never set up, connection_free chokes on it. */
  if (mocked_connection) {
    buf_free(mocked_connection->inbuf);
    buf_free(mocked_connection->outbuf);
  }
  tor_free(mocked_connection);
  UNMOCK(connection_get_by_type_addr_port_purpose);
}
Exemplo n.º 2
0
void auth_generate_auth_hmac (SESSION * session, unsigned char *auth_hmac,
		unsigned int mac_len)
{
	(void)mac_len;
	struct buf* buf = buf_new();

	buf_append_data(buf, session->init_client_packet->ptr,
			session->init_client_packet->len);
	buf_append_data(buf,  session->init_server_packet->ptr,
			session->init_server_packet->len);
	buf_append_u8(buf, 0); /* random data length */
	buf_append_u8(buf, 0); /* unknown */
	buf_append_u16(buf, 8); /* puzzle solution length */
	buf_append_u32(buf, 0); /* unknown */
	/* <-- random data would go here */
	buf_append_data(buf, session->puzzle_solution, 8);

#ifdef DEBUG_LOGIN
	hexdump8x32 ("auth_generate_auth_hmac, HMAC message", buf->ptr,
			buf->len);
	hexdump8x32 ("auth_generate_auth_hmac, HMAC key", session->key_hmac,
			sizeof (session->key_hmac));
#endif

	sha1_hmac ( session->key_hmac, sizeof (session->key_hmac),
			buf->ptr, buf->len, auth_hmac);

#ifdef DEBUG_LOGIN
	hexdump8x32 ("auth_generate_auth_hmac, HMAC digest", auth_hmac,
			mac_len);
#endif

	buf_free(buf);
}
Exemplo n.º 3
0
EXPORTED void duplicate_mark(const duplicate_key_t *dkey, time_t mark, unsigned long uid)
{
    struct buf key = BUF_INITIALIZER;
    char data[100];
    int r;

    if (!duplicate_dbopen) return;

    r = make_key(&key, dkey);
    if (r) return;

    memcpy(data, &mark, sizeof(mark));
    memcpy(data + sizeof(mark), &uid, sizeof(uid));

    do {
	r = cyrusdb_store(dupdb, key.s, key.len,
		      data, sizeof(mark)+sizeof(uid), NULL);
    } while (r == CYRUSDB_AGAIN);

#if DEBUG
    syslog(LOG_DEBUG, "duplicate_mark: %-40s %-20s %-40s %ld %lu",
	   dkey->id, dkey->to, dkey->date, mark, uid);
#endif
    buf_free(&key);
}
Exemplo n.º 4
0
//-----------------------------------------------------------------------------
static void target_read(char *name)
{
    uint32_t flash_size = device->flash_size * device->n_planes;
    uint32_t size = flash_size;
    uint32_t addr = device->flash_start;
    uint32_t offs = 0;
    uint8_t *buf;

    buf = buf_alloc(flash_size);

    verbose("Reading...");

    while (size)
    {
        dap_read_block(addr, &buf[offs], device->page_size);

        addr += device->page_size;
        offs += device->page_size;
        size -= device->page_size;

        verbose(".");
    }

    save_file(name, buf, flash_size);

    buf_free(buf);

    verbose(" done.\n");
}
Exemplo n.º 5
0
static int
tac_mem ()
{
  Buf x;
  Line_ptr bol;
  char eol_byte = '\n';
  int fail;

  fail = buf_init_from_stdin (&x, eol_byte);
  if (fail)
    {
      buf_free (&x);
      return 1;
    }

  /* Special case the empty file.  */
  if (EMPTY (&x))
    return 0;

  /* Initially, point at one past the last byte of the file.  */
  bol.i = x.n_bufs - 1;
  bol.ptr = ONE_PAST_END (&x, bol.i);

  while (1)
    {
      Line_ptr new_bol;
      int found = find_bol (&x, &bol, &new_bol, eol_byte);
      if (!found)
	break;
      print_line (stdout, &x, &new_bol, &bol);
      bol = new_bol;
    }
  return 0;
}
Exemplo n.º 6
0
Arquivo: tnfa.c Projeto: berkus/moto
char* tnfa_toString(TNFA* tnfa){
	StringBuffer* sb = buf_createDefault();
	char* result;
	int i;
	IntEnumeration* ie;
	
	buf_printf(sb,"\nStart state s%d\nFinish state s%d",tnfa->start,tnfa->finish);
	for(i=0;i<tnfa->laststate;i++){
		if(ihtab_contains(tnfa->states,i)){
			TFATrans* t;
			buf_printf(sb,"\ns%d in: %d out: ",i,itoi_get(tnfa->inputOrder,i));
			t= ihtab_get(tnfa->states, i);
			while(t!=NULL){
				if (t->c==0)
					buf_printf(sb,"<s%d,'\\0',%d,%c> ",t->to,t->tag,t->priority);
				else
					buf_printf(sb,"<s%d,'%c',%d,%c> ",t->to,t->c,t->tag,t->priority);
				t=t->next;
			}
		}
	}

	buf_printf(sb,"\n#Tags = %d #Minimized = %d Minimized Tags ={",tnfa->tagcount,iset_size(tnfa->minimized));
	ie = iset_elements(tnfa->minimized);
	while(ienum_hasNext(ie)){
	   buf_printf(sb,"%d",ienum_next(ie));
	   if(ienum_hasNext(ie)) buf_putc(sb,',');
	}
	buf_putc(sb,'}');
	result= buf_toString(sb);
	buf_free(sb);
	return(result);
}
Exemplo n.º 7
0
static int osfy_image_callback(CHANNEL *ch, unsigned char *payload, unsigned short len) {
    struct image_ctx *image_ctx = (struct image_ctx *)ch->private;

    switch(ch->state) {
    case CHANNEL_DATA:
        buf_append_data(image_ctx->image->data, payload, len);
        break;

    case CHANNEL_ERROR:
        DSFYDEBUG("Got a channel ERROR, retrying within %d seconds\n", IMAGE_RETRY_TIMEOUT);
        buf_free(image_ctx->image->data);
        image_ctx->image->data = NULL;

        /* Reset timeout so the request can be retried */
        image_ctx->req->next_timeout = get_millisecs() + IMAGE_RETRY_TIMEOUT*1000;

        break;

    case CHANNEL_END:
        /* We simply assume we're always getting a JPEG image back */
        image_ctx->image->format = SP_IMAGE_FORMAT_JPEG;
        image_ctx->image->is_loaded = 1;
        image_ctx->image->error = SP_ERROR_OK;

        request_set_result(image_ctx->session, image_ctx->req, SP_ERROR_OK, image_ctx->image);

        free(image_ctx);
        break;

    default:
        break;
    }

    return 0;
}
Exemplo n.º 8
0
/* returns success or failure, and the keytype in *type. If we want
 * to restrict the type, type can contain a type to return */
int readhostkey(const char * filename, sign_key * hostkey, int *type) {

	int ret = DROPBEAR_FAILURE;
	buffer *buf;

	buf = buf_new(MAX_PRIVKEY_SIZE);

	if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) {
		goto out;
	}
	buf_setpos(buf, 0);

	addrandom(buf_getptr(buf, buf->len), buf->len);

	if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) {
		goto out;
	}

	ret = DROPBEAR_SUCCESS;
out:

	buf_burn(buf);
	buf_free(buf);
	return ret;
}
Exemplo n.º 9
0
void test_task ()
{
	buf_t *p;

	for (;;) {
		/* Check received data. */
		p = netif_input (&eth.netif);
		if (p) {
			if (memcmp (p->payload, data_pattern, packet_size) != 0)
				printf (&debug, "\npacket #%ld: data error\n",
					eth.netif.in_packets);
			buf_free (p);
			continue;
		}
		/* Send packets - make transmit queue full. */
		if (run_test_flag) {
			p = buf_alloc (&pool, packet_size, 16);
			if (p) {
				memcpy (p->payload, data_pattern, packet_size);
				netif_output (&eth.netif, p, 0, 0);
			}
		}
		k5600bg1_poll (&eth);
	}
}
Exemplo n.º 10
0
static void
test_proto_control0(void *arg)
{
  (void)arg;
  buf_t *buf = buf_new();

  /* The only remaining function for the v0 control protocol is the function
     that detects whether the user has stumbled across an old controller
     that's using it.  The format was:
        u16 length;
        u16 command;
        u8 body[length];
  */

  /* Empty buffer -- nothing to do. */
  tt_int_op(0, OP_EQ, peek_buf_has_control0_command(buf));
  /* 3 chars in buf -- can't tell */
  buf_add(buf, "AUT", 3);
  tt_int_op(0, OP_EQ, peek_buf_has_control0_command(buf));
  /* command in buf -- easy to tell */
  buf_add(buf, "HENTICATE ", 10);
  tt_int_op(0, OP_EQ, peek_buf_has_control0_command(buf));

  /* Control0 command header in buf: make sure we detect it. */
  buf_clear(buf);
  buf_add(buf, "\x09\x05" "\x00\x05" "blah", 8);
  tt_int_op(1, OP_EQ, peek_buf_has_control0_command(buf));

 done:
  buf_free(buf);
}
Exemplo n.º 11
0
static Xapian::Stopper *get_stopper()
{
    Xapian::Stopper *stopper = NULL;

    const char *swpath = config_getstring(IMAPOPT_SEARCH_STOPWORD_PATH);
    if (swpath) {
        // Set path to stopword file
        struct buf buf = BUF_INITIALIZER;
        buf_setcstr(&buf, swpath);
        // XXX doesn't play nice with WIN32 paths
        buf_appendcstr(&buf, "/english.list");

        // Open the stopword file
        errno = 0;
        std::ifstream inFile (buf_cstring(&buf));
        if (inFile.fail()) {
            syslog(LOG_ERR, "Xapian: could not open stopword file %s: %s",
                   buf_cstring(&buf), errno ? strerror(errno) : "unknown error");
            exit(1);
        }

        // Create the Xapian stopper
        stopper = new Xapian::SimpleStopper(
                std::istream_iterator<std::string>(inFile),
                std::istream_iterator<std::string>());

        // Clean up
        buf_free(&buf);
    }
    return stopper;
}
Exemplo n.º 12
0
Arquivo: gw-http.c Projeto: Voxar/spot
static int http_reply_need_auth (RESTSESSION * r)
{
	struct buf *b;
	int ret;
	char buf[256];

	b = buf_new();
	strcpy (buf, "HTTP/1.1 401\r\n");
	buf_append_data (b, buf, strlen (buf));
	strcpy (buf, "WWW-Authenticate: Basic realm=\"Spotify\"\r\n");
	buf_append_data (b, buf, strlen (buf));
	buf_append_data (b, content_type, strlen (content_type));
	buf_append_data (b, connection_close, strlen (connection_close));
	strcpy (buf, "Content-Length: 0\r\n");
	buf_append_data (b, buf, strlen (buf));
	buf_append_data (b, "\r\n", 2);

	ret = 0;
	if (send (r->socket, b->ptr, b->len, 0) != b->len)
		ret = -1;

	buf_free (b);
	http_cleanup (r);

	return ret;
}
Exemplo n.º 13
0
buf_t *
receive_hdlc (hdlc_t *c, buf_t *p)
{
	debug_printf ("serial: received %d bytes\n", p->tot_len);
	buf_free (p);
	return 0;
}
Exemplo n.º 14
0
static struct oc_text_buf *get_qs(char **str)
{
	struct oc_text_buf *res;
	int escaped = 0;
	char *p = *str;

	if (*p != '\"')
		return NULL;

	res = buf_alloc();

	while (*++p) {
		if (!escaped && *p == '\"') {
			*str = p+1;
			if (buf_error(res))
				break;
			return res;
		}
		if (escaped)
			escaped = 0;
		else if (*p == '\\')
			escaped = 1;
		buf_append_bytes(res, p, 1);
	}
	buf_free(res);
	return NULL;
}
Exemplo n.º 15
0
void emulator_clear(struct emulator *emu)
{
    mem_prog_clear(&emu->mem);
    buf_free(&emu->infd);
    free(emu->backup_text.data);
    free(emu->backup_data.data);
}
Exemplo n.º 16
0
/*
 * buf_load()
 *
 * Open the file specified by <path> and load all of its contents into a
 * buffer.
 * Returns the loaded buffer on success.
 */
BUF *
buf_load(const char *path, u_int flags)
{
	int fd;
	ssize_t ret;
	size_t len;
	u_char *bp;
	struct stat st;
	BUF *buf;

	if ((fd = open(path, O_RDONLY, 0600)) == -1) {
		warn("%s", path);
		return (NULL);
	}

	if (fstat(fd, &st) == -1)
		err(1, "%s", path);

	buf = buf_alloc((size_t)st.st_size, flags);
	for (bp = buf->cb_cur; ; bp += (size_t)ret) {
		len = SIZE_LEFT(buf);
		ret = read(fd, bp, len);
		if (ret == -1) {
			buf_free(buf);
			err(1, "buf_load");
		} else if (ret == 0)
			break;

		buf->cb_len += (size_t)ret;
	}

	(void)close(fd);

	return (buf);
}
Exemplo n.º 17
0
void
case_buf_len()
{
    struct buf *buf = buf("abcdef");
    assert(buf_len(buf) == 6);
    buf_free(buf);
}
Exemplo n.º 18
0
/* returns success or failure */
static int readhostkey(const char * filename, sign_key * hostkey, int type) {

	int ret = DROPBEAR_FAILURE;
	int i;
	buffer *buf;

	buf = buf_new(2000);

	if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) {
		goto out;
	}
	buf_setpos(buf, 0);
	if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) {
		goto out;
	}

	ret = DROPBEAR_SUCCESS;
out:
	if (ret == DROPBEAR_FAILURE) {
		for (i = 0; sshhostkey[i].name != NULL; i++) {
			if (sshhostkey[i].val == type) {
				sshhostkey[i].usable = 0;
				break;
			}
		}
		fprintf(stderr, "Failed reading '%s', disabling %s\n", filename,
				type == DROPBEAR_SIGNKEY_DSS ? "DSS" : "RSA");
	}

	buf_burn(buf);
	buf_free(buf);
	return ret;
}
Exemplo n.º 19
0
static BUF *
import_get_rcsdiff(struct cvs_file *cf, RCSNUM *rev)
{
	char *p1, *p2;
	BUF *b1, *b2;
	int fd1, fd2;

	b2 = buf_alloc(128);

	b1 = buf_load_fd(cf->fd);

	(void)xasprintf(&p1, "%s/diff1.XXXXXXXXXX", cvs_tmpdir);
	fd1 = buf_write_stmp(b1, p1, NULL);
	buf_free(b1);

	(void)xasprintf(&p2, "%s/diff2.XXXXXXXXXX", cvs_tmpdir);
	fd2 = rcs_rev_write_stmp(cf->file_rcs, rev, p2, RCS_KWEXP_NONE);

	diff_format = D_RCSDIFF;
	if (diffreg(p2, p1, fd2, fd1, b2, D_FORCEASCII) == D_ERROR)
		fatal("import_get_rcsdiff: failed to get RCS patch");

	close(fd1);
	close(fd2);

	(void)unlink(p1);
	(void)unlink(p2);

	xfree(p1);
	xfree(p2);

	return (b2);
}
Exemplo n.º 20
0
int pgp_rkeylist(REMAILER remailer[], int keyid[], int n)
     /* Step through all remailers and get keyid */
{
  BUFFER *userid;
  BUFFER *id;
  int i, err;

  userid = buf_new();
  id = buf_new();

  for (i = 1; i < n; i++) {
    buf_clear(userid);
    buf_setf(userid, "<%s>", remailer[i].addr);

    keyid[i]=0;
    if (remailer[i].flags.pgp) {
      buf_clear(id);
      err = pgpdb_getkey(PK_VERIFY, PGP_ANY, NULL, NULL, NULL, NULL, userid, NULL, id, NULL, NULL);
      if (id->length == 8) {
	/* printf("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
	   id->data[0], id->data[1], id->data[2], id->data[3], id->data[4], id->data[5], id->data[6], id->data[7], id->data[8], remailer[i].addr); */
	keyid[i] = (((((id->data[4] << 8) + id->data[5]) << 8) + id->data[6]) << 8) + id->data[7];
      }
    }
  }

  buf_free(userid);
  return (0);
}
Exemplo n.º 21
0
int read_and_exec(int socket) {
    struct buf_t* buf = buf_new(8049);
    int pos = buf_readuntil(socket, buf, '\n');
    if (pos == -2)
        return 0;
    char* buffer = buf->data;
    buffer[pos] = '\0';
    struct execargs_t* arguments[1024];
    int k = 0;
    while (1) {
        char delim;
        int argc = count_words(buffer, '|');
        if (argc == 0)
            break;
        char* argv[argc];
        int shift;
        int i = 0;
        for (i = 0; i < argc; i++) {
            delim = '|';
            argv[i] = get_word(buffer, &delim, &shift);
            buffer += shift;
        }
        arguments[k] = (struct execargs_t*) malloc(sizeof(struct execargs_t));
        *arguments[k] = new_args(argc, argv);
        shift = get_delim(buffer, '|');
        buffer+=shift;
        k++;
    }
    buf->size -= (buffer - (char*) buf->data + 1);
    runpiped(arguments, k, socket);
    buf_free(buf);
    return 0;
}
Exemplo n.º 22
0
/*
 * Check that the frame's dest addr is for us or a broadcast address. Otherwise
 * every frame sent by the simulator to us will trigger an interrupt. This
 * function will allow us to discard frames not meant for us.
 */
static bool drvr_check_addr(buffer_t *buf)
{
	buffer_t *tmp;
	mac_hdr_t hdr;
	U8 index;
	mac_pib_t *pib = mac_pib_get();

	BUF_ALLOC(tmp, TX);
	index = tmp->index;
	memcpy(tmp, buf, sizeof(buffer_t));
	tmp->index = index;
	mac_parse_hdr(tmp, &hdr);
	buf_free(tmp);


	if ((hdr.mac_frm_ctrl.frame_type == MAC_BEACON) ||
	    (hdr.mac_frm_ctrl.frame_type == MAC_ACK)) {
		return true;
	} else if (hdr.dest_addr.mode == SHORT_ADDR) {
		if ((hdr.dest_addr.short_addr == pib->short_addr) ||
		    (hdr.dest_addr.short_addr == MAC_BROADCAST_ADDR))
			return true;
	} else if (hdr.dest_addr.mode == LONG_ADDR) {
		if ((hdr.dest_addr.long_addr == pib->ext_addr))
			return true;
	}

	return false;
}
Exemplo n.º 23
0
//-----------------------------------------------------------------------------
static void target_cm7_read(char *name)
{
  uint32_t size = device->flash_size;
  uint32_t addr = device->flash_start;
  uint32_t offs = 0;
  uint8_t *buf;

  buf = buf_alloc(device->flash_size);

  verbose("Reading...");

  while (size)
  {
    for (uint32_t sector = 0; sector < device->page_size / SECTOR_SIZE; sector++)
    {
      dap_read_block(addr, &buf[offs], SECTOR_SIZE);
      addr += SECTOR_SIZE;
      offs += SECTOR_SIZE;
      size -= SECTOR_SIZE;
    }

    verbose(".");
  }

  save_file(name, buf, device->flash_size);

  buf_free(buf);

  verbose(" done.\n");
}
Exemplo n.º 24
0
/* This is the receive interrupt service routine for the sim driver */
void drvr_rx_isr()
{
	buffer_t *buf;

	if (rx_len > aMaxPHYPacketSize)
	{
		/*
		 * don't need to worry about buffer overflow attacks in
		 * the sim, but hey.. why not add a check just in case I
		 * try to hack myself.
		 */
		return;
	}

	BUF_ALLOC(buf, RX);

	/*
	 * copy data into the buffer starting from the back. it will be easier
	 * to forward in case we're not the final destination.
	 */
	buf->dptr = &buf->buf[aMaxPHYPacketSize - rx_len];
	buf->len = rx_len;

	/* void *memcpy(void *dest, const void *src, size_t n) */
	memcpy(buf->dptr, rx_buf, rx_len);

	if (drvr_check_addr(buf)) {
		DBG_PRINT("TEST_DRIVER: Rx Intterupt Received.\n");
		mac_queue_buf_insert(buf);

		rx_len = 0;
		process_poll(&drvr_process);
	} else
		buf_free(buf);
}
Exemplo n.º 25
0
static void auth_generate_auth_hmac(struct login_ctx *l) {
        struct buf* buf = buf_new();
	
	buf_append_data(buf, l->client_parameters->ptr,
                        l->client_parameters->len);
	buf_append_data(buf,  l->server_parameters->ptr,
                        l->server_parameters->len);
        buf_append_u8(buf, 0); /* random data length */
        buf_append_u8(buf, 0); /* unknown */
        buf_append_u16(buf, 8); /* puzzle solution length */
        buf_append_u32(buf, 0); /* unknown */
        /* <-- random data would go here */
        buf_append_data(buf, l->puzzle_solution, 8);

#ifdef DEBUG_LOGIN
	hexdump8x32 ("auth_generate_auth_hmac, HMAC message", buf->ptr,
		     buf->len);
	hexdump8x32 ("auth_generate_auth_hmac, HMAC key", l->key_hmac,
		     sizeof (l->key_hmac));
#endif

	sha1_hmac(l->key_hmac, sizeof(l->key_hmac),
		    buf->ptr, buf->len, l->auth_hmac);

#ifdef DEBUG_LOGIN
	hexdump8x32 ("auth_generate_auth_hmac, HMAC digest", l->auth_hmac,
		     sizeof(l->auth_hmac));
#endif

	buf_free(buf);
}
Exemplo n.º 26
0
static void act_cut (void) {
    fileoffset_t marktop, marksize;

    if (!marking || mark_point==cur_pos) {
	display_beep();
	strcpy (message, "Set mark first");
	return;
    }
    if (!insert_mode) {
	display_beep();
	strcpy (message, "Can't cut while not in Insert mode");
	return;
    }
    marktop = cur_pos;
    marksize = mark_point - cur_pos;
    if (marksize < 0) {
	marktop += marksize;
	marksize = -marksize;
    }
    if (cutbuffer)
	buf_free (cutbuffer);
    cutbuffer = buf_cut (filedata, marksize, marktop);
    file_size -= marksize;
    cur_pos = marktop;
    if (cur_pos < 0)
	cur_pos = 0;
    if (top_pos > cur_pos)
	top_pos = begline(cur_pos);
    edit_type = !!edit_type;
    modified = TRUE;
    marking = FALSE;
}
Exemplo n.º 27
0
static void
test_buffers_tls_read_mocked(void *arg)
{
  uint8_t *mem;
  buf_t *buf;
  (void)arg;

  mem = tor_malloc(64*1024);
  crypto_rand((char*)mem, 64*1024);
  tls_read_ptr = mem;
  n_remaining = 64*1024;

  MOCK(tor_tls_read, mock_tls_read);

  buf = buf_new();

  next_reply_val[0] = 1024;
  tt_int_op(128, ==, read_to_buf_tls(NULL, 128, buf));

  next_reply_val[0] = 5000;
  next_reply_val[1] = 5000;
  tt_int_op(6000, ==, read_to_buf_tls(NULL, 6000, buf));

 done:
  UNMOCK(tor_tls_read);
  tor_free(mem);
  buf_free(buf);
}
Exemplo n.º 28
0
/*
 * Should do the actual transmission of the packet. The packet is
 * contained in the pbuf that is passed to the function. This buf
 * might be chained.
 */
bool_t
slip_output (slip_t *u, buf_t *p, small_uint_t prio)
{
    debug_printf ("slip_output: transmit %d bytes\n", p->tot_len);
    mutex_lock (&u->transmitter);

    if (u->out) {
        /* Занято, ставим в очередь. */
        if (buf_queue_is_full (&u->outq)) {
            ++u->netif.out_discards;
            mutex_unlock (&u->transmitter);
            debug_printf ("slip_output: overflow\n");
            buf_free (p);
            return 0;
        }
        buf_queue_put (&u->outq, p);
    } else {
        u->out = p;
        u->outseg = p;
        u->out_first = u->outseg->payload;
        u->out_limit = u->outseg->payload + u->outseg->len;
        u->out_flag = 1;
        slip_transmit_start (u);
    }
    mutex_unlock (&u->transmitter);
    return 1;
}
Exemplo n.º 29
0
//-----------------------------------------------------------------------------
static void target_cm0p_read(char *name)
{
  uint32_t size = device->flash_size;
  uint32_t addr = device->flash_start;
  uint32_t offs = 0;
  uint8_t *buf;

  if (dap_read_word(DSU_CTRL_STATUS) & 0x00010000)
    error_exit("devices is locked, unable to read");

  buf = buf_alloc(device->flash_size);

  verbose("Reading...");

  while (size)
  {
    dap_read_block(addr, &buf[offs], device->row_size);

    addr += device->row_size;
    offs += device->row_size;
    size -= device->row_size;

    verbose(".");
  }

  save_file(name, buf, device->flash_size);

  buf_free(buf);

  verbose(" done.\n");
}
Exemplo n.º 30
0
/* Build and write one tick (one PAL frame or 1/50 s in standard vblank
 * timed mods) of audio data to the output device.
 */
static void bufdump(struct xmp_context *ctx, int i)
{
	uint8 *b;
	int j = 0;

	/* block until we have enough free space in the buffer */
	while (buf_free() < i)
		snooze(100000);

	b = (uint8 *)xmp_smix_buffer(ctx);

	while (i) {
        	if ((j = write_buffer(b, i)) > 0) {
			i -= j;
			b += j;
		} else
			break;
	}

	if (paused) {
		player->Start(); 
		player->SetHasData(true);
		paused = 0;
	}
}