int memcache_stats (struct connection *c) {
  cmd_stats++;
  int len = copyexec_results_prepare_stats (c);
  write_out (&c->Out, stats_buff, len);
  write_out (&c->Out, "END\r\n", 5);
  return 0;
}
int memcache_stats (struct connection *c) {
  int len = isearch_prepare_stats ();
  int len2 = prepare_stats (c, stats_buff + len, STATS_BUFF_SIZE - len);
  write_out (&c->Out, stats_buff, len + len2);
  write_out (&c->Out, "END\r\n", 5);
  return 0;
}
Beispiel #3
0
static int
write_stage1(ig_data_t *install)
{
	ig_device_t	*device = &install->device;

	assert(install != NULL);

	if (write_out(device->part_fd, install->stage1_buf,
	    sizeof (install->stage1_buf), 0) != BC_SUCCESS) {
		(void) fprintf(stdout, WRITE_FAIL_PBOOT);
		perror("write");
		return (BC_ERROR);
	}

	/* Simulate "old" installgrub output. */
	(void) fprintf(stdout, WRITE_PBOOT, device->partition,
	    device->start_sector);

	if (write_mbr) {
		if (write_out(device->disk_fd, install->stage1_buf,
		    sizeof (install->stage1_buf), 0) != BC_SUCCESS) {
			(void) fprintf(stdout, WRITE_FAIL_BOOTSEC);
			perror("write");
			return (BC_ERROR);
		}
		/* Simulate "old" installgrub output. */
		(void) fprintf(stdout, WRITE_MBOOT);
	}

	return (BC_SUCCESS);
}
int memcache_stats (struct connection *c) {
  cmd_stats++;
  int stats_len = filesys_prepare_stats (c);
  write_out (&c->Out, value_buff, stats_len);
  write_out (&c->Out, "END\r\n", 5);
  return 0;
}
Beispiel #5
0
int accept_connection(int sockfd, struct sockaddr_storage* out_opt_client_addr)
{
    struct sockaddr_storage client_addr;
    struct sockaddr_storage* ptr_to_client_addr;
    socklen_t addr_size;
    int newfd;
    char str_ip[INET6_ADDRSTRLEN]; //should fit ipv4 too
    char str_port[MAXPORTLEN];
    
    addr_size = sizeof(struct sockaddr_storage);
    if (out_opt_client_addr)
        ptr_to_client_addr = out_opt_client_addr;
    else
        ptr_to_client_addr = &client_addr;
    
    newfd = accept(sockfd, (struct sockaddr*)ptr_to_client_addr, &addr_size);
    if (newfd == -1)
        write_out(PRINT_WARNING, "Unable to accept client connection: %s", strerror(errno));
    else
    {
        getnameinfo((struct sockaddr*)ptr_to_client_addr, sizeof(struct sockaddr_storage), str_ip, sizeof(str_ip), str_port, sizeof(str_port), NI_NUMERICHOST | NI_NUMERICSERV);
        write_out(PRINT_INFO, "Accepted connection from remote client %s on port %s", str_ip, str_port);
    }
    
    return newfd;
}
Beispiel #6
0
void display_row_transition(int factor) {
  write_out(row_transition_start);
  for(int i = 0; i < factor - 1; i++) {
    write_out(row_transition_piece);
  }
  write_out(row_transition_end);
}
Beispiel #7
0
  void Run() {
    int tot_len=0;
    bool valid=true;
    while(true) {
      file.seekg(file_position);
      int length = file.readsome(buf,MAXBUF);
      int i = length;
      // count a line if line don't ends with newline
      for(; i>0 && linecount>0; --i) {
	if(buf[i]=='\n') {
	  --linecount;
	}
      }
      ++i;
      tot_len+=(length-i);
      if(linecount==0){
	if(valid)
	  write_out(i, tot_len, valid);
	else 
	  write_out(file_size-tot_len, tot_len, valid);
	break;
      } else if(length>=file_size) {
	write_out(0,file_size, valid);
	break;
      }
      file_position-=MAXBUF;
      valid=false;
    }
  };
int main(int argc, char ** argv)
{
  double ** A, ** B, ** C;
  double ** control_matrix;
  long long mul_time;
  int a_dim1, a_dim2, b_dim1, b_dim2;
  struct timeval start_time;
  struct timeval stop_time;

  if ( argc != 5 ) {
    fprintf(stderr, "Usage: matmul-harness <A nrows> <A ncols> <B nrows> <B ncols>\n");
    exit(1);
  }
  else {
    a_dim1 = atoi(argv[1]);
    a_dim2 = atoi(argv[2]);
    b_dim1 = atoi(argv[3]);
    b_dim2 = atoi(argv[4]);
  }

  /* check the matrix sizes are compatible */
  if ( a_dim2 != b_dim1 ) {
    fprintf(stderr,
	    "FATAL number of columns of A (%d) does not match number of rows of B (%d)\n",
	    a_dim2, b_dim1);
    exit(1);
  }

  /* allocate the matrices */
  A = gen_random_matrix(a_dim1, a_dim2);
  B = gen_random_matrix(b_dim1, b_dim2);
  C = new_empty_matrix(a_dim1, b_dim2);
  control_matrix = new_empty_matrix(a_dim1, b_dim2);

  DEBUGGING(write_out(A, a_dim1, a_dim2));

  /* use a simple matmul routine to produce control result */
  matmul(A, B, control_matrix, a_dim1, a_dim2, b_dim2);

  /* record starting time */
  gettimeofday(&start_time, NULL);

  /* perform matrix multiplication */
  team_matmul(A, B, C, a_dim1, a_dim2, b_dim2);

  /* record finishing time */
  gettimeofday(&stop_time, NULL);
  mul_time = (stop_time.tv_sec - start_time.tv_sec) * 1000000L +
    (stop_time.tv_usec - start_time.tv_usec);
  printf("Matmul time: %lld microseconds\n", mul_time);

  DEBUGGING(write_out(C, a_dim1, b_dim2));

  /* now check that the team's matmul routine gives the same answer
     as the known working version */
  check_result(C, control_matrix, a_dim1, b_dim2);

  return 0;
}
Beispiel #9
0
static int
write_stage2(ig_data_t *install)
{
	ig_device_t		*device = &install->device;
	ig_stage2_t		*stage2 = &install->stage2;
	off_t			offset;

	assert(install != NULL);

	if (is_bootpar(device->type)) {
		/*
		 * stage2 is already on the filesystem, we only need to update
		 * the first two blocks (that we have modified during
		 * prepare_stage2())
		 */
		if (write_out(device->part_fd, stage2->file, SECTOR_SIZE,
		    stage2->pcfs_first_sectors[0] * SECTOR_SIZE)
		    != BC_SUCCESS ||
		    write_out(device->part_fd, stage2->file + SECTOR_SIZE,
		    SECTOR_SIZE, stage2->pcfs_first_sectors[1] * SECTOR_SIZE)
		    != BC_SUCCESS) {
			(void) fprintf(stderr, WRITE_FAIL_STAGE2);
			return (BC_ERROR);
		}
		(void) fprintf(stdout, WRITE_STAGE2_PCFS);
		return (BC_SUCCESS);
	}

	/*
	 * For disk, write stage2 starting at STAGE2_BLKOFF sector.
	 * Note that we use stage2->buf rather than stage2->file, because we
	 * may have extended information after the latter.
	 *
	 * If we're writing to an EFI-labeled disk where stage2 lives in the
	 * 3.5MB boot loader gap following the ZFS vdev labels, make sure the
	 * size of the buffer doesn't exceed the size of the gap.
	 */
	if (is_efi(device->type) && stage2->buf_size > STAGE2_MAXSIZE) {
		(void) fprintf(stderr, WRITE_FAIL_STAGE2);
		return (BC_ERROR);
	}

	offset = STAGE2_BLKOFF(device->type) * SECTOR_SIZE;

	if (write_out(device->part_fd, stage2->buf, stage2->buf_size,
	    offset) != BC_SUCCESS) {
		perror("write");
		return (BC_ERROR);
	}

	/* Simulate the "old" installgrub output. */
	(void) fprintf(stdout, WRITE_STAGE2_DISK, device->partition,
	    (stage2->buf_size / SECTOR_SIZE) + 1, STAGE2_BLKOFF(device->type),
	    stage2->first_sector);

	return (BC_SUCCESS);
}
int memcache_delete (struct connection *c, const char *key, int key_len) {
    int user_id, arg = 0;
    privacy_key_t privacy_key;

    if (verbosity > 0) {
        fprintf (stderr, "delete \"%s\"\n", key);
    }

    int res = -1;

    if (binlog_disabled == 2 || reverse_friends_mode) {
        write_out (&c->Out, "NOT_FOUND\r\n", 11);
        return 0;
    }

    switch (*key) {
    case 'u':
        if (sscanf (key, "user%d ", &user_id) == 1) {
            res = do_delete_user (user_id);
        }
        break;
    case 'f':
        if (sscanf (key, "friend_cat%d_%d ", &user_id, &arg) == 2) {
            res = do_delete_friend_category (user_id, arg);
        }
        if (sscanf (key, "friendreq%d_%d ", &user_id, &arg) == 2) {
            res = do_delete_friend_request (user_id, arg);
        }
        if (sscanf (key, "friend%d_%d ", &user_id, &arg) == 2) {
            res = do_delete_friend (user_id, arg);
        }
        break;
    case 'p':
        if (sscanf (key, "privacy%d_%n", &user_id, &arg) >= 1 && parse_privacy_key (key+arg, &privacy_key, 1) > 0) {
            res = do_delete_privacy (user_id, privacy_key);
        }
        break;
    case 'r':
        if (sscanf (key, "requests%d ", &user_id) == 1) {
            res = do_delete_all_friend_requests (user_id);
        }
        break;
    }

    if (res > 0) {
        write_out (&c->Out, "DELETED\r\n", 9);
    } else {
        write_out (&c->Out, "NOT_FOUND\r\n", 11);
    }

    return 0;
}
Beispiel #11
0
void show_board(Board* board) {
  reset_screen();
  int size = get_size(board);
  int factor = get_factor(board);
  for(int i = 0; i < size; i++) {
    display_space(get_space(board, i), i);
    if (is_row_transition(i, factor, size)) {
      display_row_transition(factor);
    }
    if (is_cell_transition(i, factor)) {
      write_out(cell_transition_message);
    }
  }
  write_out(end_board_message);
}
Beispiel #12
0
int kmain()
{
	fb_write_cell(0, 'A', FB_GREEN, FB_DARK_GRAY);
	char *hello = "Hello, World!";
	write_out(hello, 13);
	return 0xDEADBABE;
}
int rpcc_init_crypto (struct connection *c) {
  if (!(RPCC_DATA(c)->crypto_flags & 2)) {
    return rpcc_init_fake_crypto (c);
  }

  RPCC_DATA(c)->nonce_time = time (0);

  aes_generate_nonce (RPCC_DATA(c)->nonce);

  static struct rpc_nonce_packet buf;
  memset (&buf, 0, sizeof (buf));
  memcpy (buf.crypto_nonce, RPCC_DATA(c)->nonce, 16);
  buf.crypto_ts = RPCC_DATA(c)->nonce_time;
  buf.len = sizeof (buf);
  buf.seq_num = -2;
  buf.type = RPC_NONCE;
  buf.key_select = get_crypto_key_id ();
  buf.crypto_schema = RPC_CRYPTO_AES;
  buf.crc32 = compute_crc32 (&buf, sizeof (buf) - 4);

  write_out (&c->Out, &buf, sizeof (buf));

  assert ((RPCC_DATA(c)->crypto_flags & 14) == 2);
  RPCC_DATA(c)->crypto_flags |= 4;
 
  mark_all_processed (&c->Out);

  return 1;
}
static int rpcc_send_handshake_packet (struct connection *c) {
  struct rpcc_data *D = RPCC_DATA (c);
  static struct rpc_handshake_packet P;
  if (!PID.ip) {
    init_client_PID (c->our_ip);
    if (!PID.ip) {
      PID.ip = get_my_ipv4 ();
    }
  }
  memset (&P, 0, sizeof (P));
  P.len = sizeof (P);
  P.seq_num = -1;
  P.type = RPC_HANDSHAKE;
  P.flags = 0;
  if (!D->remote_pid.port) {
    D->remote_pid.ip = (c->remote_ip == 0x7f000001 ? 0 : c->remote_ip);
    D->remote_pid.port = c->remote_port;
  }
  memcpy (&P.sender_pid, &PID, sizeof (struct process_id));
  memcpy (&P.peer_pid, &D->remote_pid, sizeof (struct process_id));
  P.crc32 = compute_crc32 (&P, sizeof (P) - 4);
  write_out (&c->Out, &P, sizeof (P));
  RPCC_FUNC(c)->flush_packet (c);

  return 0;
}
Beispiel #15
0
int nbit_copy_through_nondestruct (netbuffer_t *XD, nb_iterator_t *I, int len) {
  netbuffer_t *H = I->head, *X = I->cur;
  int s, w = 0;
  char *p = I->cptr;

  assert (X->rptr <= p && p <= X->wptr);
  assert (!X->pptr || p <= X->pptr);

  while (len > 0) {
    s = (X->pptr ? X->pptr : X->wptr) - p;
    assert ((unsigned) s <= NET_BUFFER_SIZE);
    if (s > len) { s = len; }
    if (s > 0) {
      write_out (XD, p, s);
      w += s;
      p += s;
      len -= s;
    }
    if (!len || p != X->wptr || X->next == H) { 
      break; 
    }
    X = X->next;
    p = X->rptr;
  }
  return w;
}
int rpc_send_query (void *_R, struct connection *c) {
  int *R = _R;
  if (verbosity >= 4) {
    fprintf (stderr, "sending query... len = %d, op = %x\n", R[0], R[2]);
  }
  if (verbosity >= 6) {
    fprintf (stderr, "c = %p, server_check_ready = %d (cr_ok = %d)\n", c, server_check_ready (c), cr_ok);
  }
  assert (c && server_check_ready(c) == cr_ok);
  assert (R[0] <= MAX_PACKET_LEN && R[0] >= 16 && R[0] % 4 == 0);
  if (verbosity >= 10) {
    fprintf (stderr, "LINE %d:", __LINE__);
  }
  rpc_set_crc32 (R);
  if (verbosity >= 10) {
    fprintf (stderr, "LINE %d:", __LINE__);
  }
  write_out (&c->Out, R, R[0]);
  if (verbosity >= 10) {
    fprintf (stderr, "LINE %d:", __LINE__);
    fprintf (stderr, "%p %p %p\n", c->extra, RPCS_FUNC(c)->flush_packet, rpcc_flush_packet);
  }
  RPCS_FUNC(c)->flush_packet(c);
  if (verbosity >= 4) {
    fprintf (stderr, "message_sent\n");
  }
  return 0;
}
Beispiel #17
0
int copy_through_nondestruct (netbuffer_t *HD, netbuffer_t *H, int len) {
  netbuffer_t *X = H;
  int s, w = 0;
  char *rptr;
  if (X->wptr == X->rptr) {
    X = X->next;
  }
  rptr = X->rptr;
  while (len > 0) {
    s = (X->pptr ? X->pptr : X->wptr) - rptr;
    if (s > len) { s = len; }
    if (s > 0) {
      w += write_out (HD, rptr, s);
      rptr += s;
      len -= s;
    }
    if (rptr == X->wptr) {
      X = X->next;
      rptr = X->rptr;
      if (X == H) { break; }
    } else if (rptr == X->pptr) {
      break;
    }
  }
  return w;
}
Beispiel #18
0
int put_bio_data(int sockfd, BIO* rbio, MUTATOR mutate, void* state)
{
    int n;
    int mn;
    unsigned char buf[BUFFER_SIZE];
    unsigned char* mbuf;
    
    n = recv(sockfd, buf, BUFFER_SIZE, 0);
    if (n < 0)
    {
        write_out(PRINT_ERROR, "Socket recv error: %s", strerror(errno));
        return n;
    }
    
    if (n == 0)
        return n;
    
    if (mutate)
    {
        mbuf = mutate(state, buf, n, &mn);
    
        BIO_write(rbio, mbuf, mn);
    
        free(mbuf);
    }
    else
        BIO_write(rbio, buf, n);
    
    return n;
}
Beispiel #19
0
    void encode_silent_samples(int n_samples)
        {
        float **buffer;
        int i;

        /* generate a silent buffer */
        buffer = vorbis_analysis_buffer(&vd, n_samples);
        for (i = 0; i < vi.channels; i++)
            memset(buffer[i], 0, n_samples * sizeof (float));
        vorbis_analysis_wrote(&vd, n_samples);

        /* encode it */
        while (vorbis_analysis_blockout(&vd, &vb) == 1)
            {
            vorbis_analysis(&vb, NULL);
            vorbis_bitrate_addblock(&vb);
            while (vorbis_bitrate_flushpacket(&vd, &op))
                {
                ogg_stream_packetin(&os, &op);
                while (ogg_stream_pageout(&os, &og))
                    {
                    write_out(&og);
                    if (ogg_page_eos(&og))
                        break;
                    }
                }
            }
        }
Beispiel #20
0
int get_ssl_record(SSL* ssl, int sockfd, BIO* rbio, unsigned char* buf, unsigned int len)
{
    int n;
    int err;
    
    for (;;)
    {
        n = SSL_read(ssl, buf, len);
        if (n == 0)
            return -1;
        else if (n < 0)
        {
            err = SSL_get_error(ssl, n);
            if (err == SSL_ERROR_WANT_READ)
                if ((n = put_bio_data(sockfd, rbio, 0, 0)) <= 0)
                    return n;
                else;
            else
            {
                write_out(PRINT_ERROR, "TLS Error: %d", err);
                return -1;
            }
        }
        else
            return n;
    }
}
Beispiel #21
0
void print_ssl_error_stack(int level)
{
    unsigned long err_num;
    
    while ((err_num = ERR_get_error()))
        write_out(level, "%s", ERR_error_string(err_num, 0));
}
Beispiel #22
0
void btn2btn::process(struct mg_ev ev, output_slot* out) {
  struct input_event out_ev;
  memset(&out_ev, 0, sizeof(out_ev));
  out_ev.type = EV_KEY;
  out_ev.code = out_button;
  out_ev.value = ev.value;
  write_out(out_ev, out);
}
Beispiel #23
0
  void add_hash(chordID h) {
    hs.push_back(h);

    if(full()) {
      // write out indirect block
      write_out();
    }
  }
Beispiel #24
0
void write_device_callback(ToxAv* av, int32_t call_index, int16_t* data, int size, void* userdata)
{
    (void)userdata;
    if (call_index >= 0 && ASettins.calls[call_index].ttas) {
        ToxAvCSettings csettings = ASettins.cs;
        toxav_get_peer_csettings(av, call_index, 0, &csettings);
        write_out(ASettins.calls[call_index].out_idx, data, size, csettings.audio_channels);
    }
}
int friends_data_store (struct connection *c, int op, const char *key, int len, int flags, int expire, int bytes)
{
  int user_id = 0;
  struct keep_mc_store *Data = 0;

  //key[len] = 0;

  if (verbosity > 0) {
    fprintf (stderr, "mc_store: op=%d, key=\"%s\", flags=%d, expire=%d, bytes=%d, noreply=%d\n", op, key, flags, expire, bytes, 0);
  }

  if (bytes >= 0 && bytes < 1048576) {
    if (sscanf (key, "userlist%d", &user_id) == 1 && user_id < 0) {
      if (!c->Tmp) {
        c->Tmp = alloc_head_buffer();
        assert (c->Tmp);
      }
      Data = (struct keep_mc_store *) c->Tmp->start;
      Data->magic = FRIENDS_STORE_MAGIC;
      Data->list_id = user_id;
      Data->num = np_news_parse_list (userlist, MAX_USERLIST_NUM, 1, &c->In, bytes);
      advance_write_ptr (c->Tmp, sizeof (struct keep_mc_store));
      if (Data->num > 0 && user_id < 0) {
        write_out (c->Tmp, userlist, Data->num * 4);
      }
    } else {
      advance_skip_read_ptr (&c->In, bytes);
    }
  } else {
    advance_skip_read_ptr (&c->In, bytes);
  }

  if (!Data || Data->num <= 0 || user_id >= 0) {
    write_out (&c->Out, "NOT_STORED\r\n", 12);
    flush_output (c);
    free_tmp_buffers (c);
  } else {
    write_out (&c->Out, "STORED\r\n", 8);
    flush_output (c);
  }

  return bytes;
}
Beispiel #26
0
SSL* init_ssl_with_cipher(SSL_CTX* ssl_ctx, const char* cipher_name)
{
    SSL* ssl;
    
    ssl = SSL_new(ssl_ctx);
    if (!SSL_set_cipher_list(ssl, cipher_name))
    {
        write_out(PRINT_ERROR, "Unable to initialize SSL with %s.", cipher_name);
        write_raise_level();
        write_out(PRINT_ERROR, "Your version of OpenSSL may be outdated. Update OpenSSL and try again.");
        write_out(PRINT_ERROR, "If your version of OpenSSL is current, then %s cipher may have been disabled at compile time.", cipher_name);
        write_lower_level();
        if (ssl)
            SSL_free(ssl);
        return 0;
    }
    
    return ssl;
}
int memcache_incr (struct connection *c, int op, const char *key, int len, long long arg) {
    int user_id, friend_id;

    if (len >= 7 && !memcmp (key, "friend", 6) && !reverse_friends_mode) {
        int res = -1;
        if (binlog_disabled != 2 && sscanf (key, "friend%d_%d", &user_id, &friend_id) >= 2) {
            res = do_add_friend (user_id, friend_id, op ? 0 : arg, ~arg, 0);
        }
        if (res > 0) {
            write_out (&c->Out, stats_buff, sprintf(stats_buff, "%d\r\n", res));
        } else {
            write_out (&c->Out, "NOT_FOUND\r\n", 11);
        }
        return 0;
    }

    write_out (&c->Out, "NOT_FOUND\r\n", 11);
    return 0;
}
Beispiel #28
0
void write_device_callback(void *agent, int32_t call_index, const int16_t* PCM, uint16_t size, void* arg)
{
    (void)arg;
    (void)agent;

    if (call_index >= 0 && ASettins.calls[call_index].ttas) {
        ToxAvCSettings csettings = ASettins.cs;
        toxav_get_peer_csettings(ASettins.av, call_index, 0, &csettings);
        write_out(ASettins.calls[call_index].out_idx, PCM, size, csettings.audio_channels);
    }
}
Beispiel #29
0
void axis2btns::process(struct mg_ev ev, output_slot* out) {
  struct input_event out_ev;
  memset(&out_ev, 0, sizeof(out_ev));
  out_ev.type = EV_KEY;
  out_ev.code = neg_btn;
  out_ev.value = ev.value < -.5 * ABS_RANGE;
  if (out_ev.value != neg_cache) {
    write_out(out_ev, out);
    neg_cache = out_ev.value;
  }

  out_ev.type = EV_KEY;
  out_ev.code = pos_btn;
  out_ev.value = ev.value > .5 * ABS_RANGE;
  if (out_ev.value != pos_cache) {
    write_out(out_ev, out);
    pos_cache = out_ev.value;
  }

}
int main(int argc, char ** argv)
{
  struct complex ** A, ** B, ** C;
  struct complex ** control_matrix;
  long long control_time, mul_time;
  double speedup;
  int a_dim1, a_dim2, b_dim1, b_dim2, errs;
  struct timeval pre_time, start_time, stop_time;

  if ( argc != 5 ) {
    fprintf(stderr, "Usage: matmul-harness <A nrows> <A ncols> <B nrows> <B ncols>\n");
    exit(1);
  }
  else {
    a_dim1 = atoi(argv[1]);
    a_dim2 = atoi(argv[2]);
    b_dim1 = atoi(argv[3]);
    b_dim2 = atoi(argv[4]);
  }

  /* check the matrix sizes are compatible */
  if ( a_dim2 != b_dim1 ) {
    fprintf(stderr,
      "FATAL number of columns of A (%d) does not match number of rows of B (%d)\n",
      a_dim2, b_dim1);
    exit(1);
  }

  /* allocate the matrices */
  A = gen_random_matrix(a_dim1, a_dim2);
  B = gen_random_matrix(b_dim1, b_dim2);
  C = new_empty_matrix(a_dim1, b_dim2);
  control_matrix = new_empty_matrix(a_dim1, b_dim2);

  DEBUGGING( {
    printf("matrix A:\n");
    write_out(A, a_dim1, a_dim2);
    printf("\nmatrix B:\n");
    write_out(A, a_dim1, a_dim2);
    printf("\n");
  } )