Exemplo n.º 1
0
static void
handle_extra_feeds(noit_check_t *check,
                   int (*log_f)(noit_log_stream_t ls, noit_check_t *check)) {
  noit_log_stream_t ls;
  noit_skiplist_node *curr, *next;
  const char *feed_name;

  if(!check->feeds) return;
  curr = next = noit_skiplist_getlist(check->feeds);
  while(curr) {
    /* We advance next here (before we try to use curr).
     * We may need to remove the node we're looking at and that would
     * disturb the iterator, so advance in advance. */
    noit_skiplist_next(check->feeds, &next);
    feed_name = (char *)curr->data;
    ls = noit_log_stream_find(feed_name);
    if(!ls || log_f(ls, check)) {
      noit_check_transient_remove_feed(check, feed_name);
      /* noit_skiplisti_remove(check->feeds, curr, free); */
    }
    curr = next;
  }
  /* We're done... we may have destroyed the last feed.
   * that combined with transience means we should kill the check */
  /* noit_check_transient_remove_feed(check, NULL); */
}
Exemplo n.º 2
0
bool Channel::read_tile_or_closest_ancestor(TileIndex ti, TileIndex &ret_index, Tile &ret) const {
  Locker lock(*this);  // Lock self and hold lock until exiting this method
  ChannelInfo info;
  bool success = read_info(info);
  if (!success) {
    if (verbosity) log_f("read_tile_or_closest_ancestor: can't read info");
    return false;
  }
  TileIndex root = info.nonnegative_root_tile_index;

  if (ti.is_ancestor_of(root)) {
    ret_index = root;
  } else {
    if (ti != root && !root.is_ancestor_of(ti)) {
      // Tile isn't under root
      return false;
    }
    
    assert(tile_exists(root));
    ret_index = root;
    while (ret_index != ti) {
      TileIndex child = ti.start_time() < ret_index.left_child().end_time() ? ret_index.left_child() : ret_index.right_child();
      if (!tile_exists(child)) break;
      ret_index = child;
    }
  }
  // ret_index now holds closest ancestor to ti (or ti itself if it exists)  
    
  assert(read_tile(ret_index, ret));
  return true;
}
Exemplo n.º 3
0
// \brief Instantiate FilesystemKVS
// \param root Directory to use as root of store.  Should already exist
FilesystemKVS::FilesystemKVS(const char *root) : m_root(root) {
  if (m_root == "" || m_root[m_root.size()-1] == '/')
    throw std::runtime_error("store path " + std::string(root) + " shouldn't end with '/'");
  if (!filename_exists(root))
    throw std::runtime_error(std::string(root) + " does not exist");
  if (m_verbose) log_f("FilesystemKVS: opening %s", root);
}
Exemplo n.º 4
0
static void
ssh_auth_cb(obfsproxyssh_client_session_t *session)
{
	obfsproxyssh_t *state = session->client->state;
	int rval;

	rval = libssh2_userauth_publickey(session->ssh_session,
			bdata(session->user),
			get_rsa_public_key(session->privkey),
			get_rsa_public_key_len(session->privkey),
			sign_with_private_key,
			&session->privkey);
	if (LIBSSH2_ERROR_EAGAIN == rval)
		return;
	else if (0 != rval) {
		log_f(state, "SSH: Error: %s Failed to authenticate - %d",
				bdata(session->ssh_addr), rval);
		libssh2_session_free(session->ssh_session);
		session->ssh_session = NULL;
		session_free(session);
		return;
	}

	session->libssh2_cb = ssh_channel_cb;
	session->libssh2_cb(session);
}
Exemplo n.º 5
0
msg_t mission_thread(void* arg)
{
    (void)arg;
    state_t cur_state = STATE_PAD;
    state_t new_state;
    instance_data_t data;
    data.t_launch = data.t_last_ignition = data.t_last_burnout = 0;
    data.current_stage_position = STAGE;
    data.state = state_estimation_get_state();
    data.h_pad = data.state.h;
    log_f(CHAN_CAL_PAD, data.h_pad, 0.0f);
    log_s32(CHAN_SM_MISSION, cur_state, cur_state);

    chRegSetThreadName("Mission");

    while(1) {
        /* Run Kalman prediction step */
        data.state = state_estimation_get_state();

        /* Run state machine's current state function */
        new_state = run_state(cur_state, &data);

        /* Log changes in state */
        if(new_state != cur_state) {
            log_s32(CHAN_SM_MISSION,
                    (int32_t)cur_state, (int32_t)new_state);
            cur_state = new_state;
        }

        /* Tick the state machine about every millisecond */
        chThdSleepMilliseconds(1);
    }
}
Exemplo n.º 6
0
void auto_ban_ip(int site)
{

    char name [ MAX_STRING_LENGTH ];
    BAN_DATA *pban;

    int decA = ( site >> 24 ) & 0xFF;
    int decB = ( site >> 16 ) & 0xFF;
    int decC = ( site >>  8 ) & 0xFF;
    int decD = ( site       ) & 0xFF;

    if(decA == 127 && decB == 0 && decB == 0 && decD == 1)
    {
        return; /* Localhost is OK for right now */
    }

    sprintf(name,"%d.%d.%d.", decA, decB, decC);

    pban = new_ban();
    pban->name = str_dup(name);
    pban->level = 105;

    SET_BIT(pban->ban_flags,BAN_SUFFIX);
    SET_BIT(pban->ban_flags,BAN_PERMANENT);

    pban->next  = ban_list;
    ban_list    = pban;
    save_bans();
    log_f("%s has been automatically banned.\n\r",pban->name);

    return;
}
Exemplo n.º 7
0
static void
libssh2_trace_cb(LIBSSH2_SESSION *session, void *context, const char
	*data, size_t length)
{
	obfsproxyssh_t *state = context;

	log_f(state, "libssh2: %s", data);
}
Exemplo n.º 8
0
/// Lock key.  Do not call this directly;  instead, use KVSLocker to create a scoped lock.
/// \param key
///
/// Uses flock on file that contains value.
void *FilesystemKVS::lock(const std::string &key) {
  std::string path = value_key_to_path(key); 
  FILE *f = fopen(path.c_str(), "ab");
  if (!f) {
    make_parent_directories(path);
    f = fopen(path.c_str(), "a");
    if (!f) throw std::runtime_error("fopen " +  path);
  }
  int fd= fileno(f);
  if (m_verbose) log_f("FilesystemKVS::lock(%s) about to lock %s (fd=%d)", key.c_str(), path.c_str(), fd);
  if (-1 == flock(fd, LOCK_EX)) {
    fclose(f);
    throw std::runtime_error("flock " + path);
  }
  if (m_verbose) log_f("FilesystemKVS::lock(%s) locked %s (fd=%d)", key.c_str(), path.c_str(), fd);
  return (void*)f;
}
Exemplo n.º 9
0
/// Unlock key after it has been locked with lock.  Do not call this directly;  instead, use KVSLocker to create a scoped lock
/// \param key
void FilesystemKVS::unlock(void *lock) {
  FILE *f = (FILE*)lock;
  int fd = fileno(f);
  int ret = flock(fd, LOCK_UN);
  fclose(f);
  if (ret == -1) throw std::runtime_error("funlock");
  if (m_verbose) log_f("FilesystemKVS::unlock unlocked fd %d", fd);
}
Exemplo n.º 10
0
void Channel::write_tile(TileIndex ti, const Tile &tile) {
  std::string binary;
  tile.to_binary(binary);
  //assert(binary.size() <= m_max_tile_size);
  m_kvs.set(tile_key(ti), binary);
  total_tiles_written++;
  if (verbosity) log_f("Channel: write_tile %s %s: %s", 
                       descriptor().c_str(), ti.to_string().c_str(), tile.summary().c_str());
}
Exemplo n.º 11
0
bool Channel::read_tile(TileIndex ti, Tile &tile) const {
  std::string binary;
  if (!m_kvs.get(tile_key(ti), binary)) return false;
  total_tiles_read++;
  tile.from_binary(binary);
  if (verbosity) log_f("Channel: read_tile %s %s: %s", 
                       descriptor().c_str(), ti.to_string().c_str(), tile.summary().c_str());
  return true;
}
Exemplo n.º 12
0
StartOfFileRecord::StartOfFileRecord(const Source &source, const unsigned char *payload, int payload_len) {
  try {
    const unsigned char *ptr=payload;
    protocol_version = read_u16(ptr);
    time = TimeRecord(source, ptr);
    tick_period = read_u48(ptr);
    if (verbose) log_f("parse_bt_file: Parsing SOFR:  tick_period is %llu", tick_period);
    char *cptr = (char*) ptr, *end= (char*) payload+payload_len;
    if (end[-1] != 0) throw ParseError("At byte %d: DEVICE_PARAMS don't end with NUL", source.pos(end-1));
    while (cptr < end-1) {
      char *keyptr = cptr;
      cptr = strchr(cptr, '\t');
      if (!cptr) throw ParseError("At byte %d: DEVICE_PARAMS missing tab", source.pos(keyptr));
      std::string key(keyptr, cptr);
      cptr++; // skip tab
      char *valueptr = cptr;
      cptr = strchr(cptr, '\n');
      if (!cptr) throw ParseError("At byte %d: DEVICE_PARAMS missing newline", source.pos(valueptr));
      std::string value(valueptr, cptr);
      cptr++; // skip
      if (verbose) log_f("parse_bt_file:   '%s'='%s'", key.c_str(), value.c_str());
      device_params[key] = value;
    }
    
    if (!device_params.count("channel_specs")) {
      throw ParseError("No channel_specs field in DEVICE_PARAMS in START_OF_FILE record");
    }
    Json::Reader reader;
    if (!reader.parse(device_params["channel_specs"], channel_specs)) {
      throw ParseError("Failed to parse channel_specs JSON");
    }
    Json::Value::Members channel_names = channel_specs.getMemberNames();
    for (unsigned i = 0; i < channel_names.size(); i++) {
      std::string units = get_channel_units(channel_names[i]);
      double scale = get_channel_scale(channel_names[i]);
      if (verbose)
        log_f("parse_bt_file:   channel %d: '%s', units '%s', scale %g",
                i, channel_names[i].c_str(), units.c_str(), scale);
    }
  }
  catch (ParseError &e) {
    throw ParseError("In RTYPE_START_OF_FILE payload starting at byte %d: %s", source.pos(payload), e.what());
  }
}
Exemplo n.º 13
0
void TickToTime::receive_binrec(const RtcRecord &rtcr) {
  receive_short_ticks(rtcr.tick_count);
  if (verbose) {
    log_f("parse_bt_file: Current tick = %llu, tick period = %llu", m_current_tick, m_tick_period);
    log_f("parse_bt_file: Current tick = %llu, seconds = %g", m_current_tick, (m_current_tick * m_tick_period) / 1e12);
  }
  double new_zero_tick_time = rtcr.seconds_since_1970() - (m_current_tick * m_tick_period) / 1e12;
  if (m_zero_tick_time == 0) {
    if (verbose)
      log_f("parse_bt_file: RTC record: Setting zero_tick_time to %.9f", new_zero_tick_time);
  } else {
    if (verbose) {
      log_f("parse_bt_file: Won't change zero_tick_time by %.9f from %.9f to %.9f",
              new_zero_tick_time - m_zero_tick_time, m_zero_tick_time, new_zero_tick_time);
    }
    return;
  }
  m_zero_tick_time = new_zero_tick_time;
}
Exemplo n.º 14
0
static void
socks_relay_cb(struct bufferevent *bev, void *ptr)
{
	obfsproxyssh_client_session_t *session = ptr;
	obfsproxyssh_t *state = session->client->state;
	struct evbuffer *buf;
	unsigned char *p;
	size_t len;
	ssize_t rval;

	assert(session->socks_ev == bev);

	/*
	 * Note: This is not very efficient, but since libssh2 doesn't have
	 * scatter/gather I/O and libssh2 is most efficient when sending 1 SSH
	 * packet worth of data (32 KiB) at a time, I can't think of a better
	 * way to do this.
	 */

	buf = bufferevent_get_input(bev);
	len = evbuffer_get_length(buf);
	len = (len > OBFSPROXYSSH_CLIENT_WRITE_SZ) ?
		OBFSPROXYSSH_CLIENT_WRITE_SZ : len;
	p = evbuffer_pullup(buf, len);
	if (NULL == p) {
		log_f(state, "RELAY: Error: %s Failed to pullup (OOM?)",
				bdata(session->socks_addr));
		ssh_relay_event_cb(session->ssh_ev, BEV_EVENT_ERROR, session);
		return;
	}

	rval = libssh2_channel_write(session->ssh_channel, (char *) p, len);
	if (LIBSSH2_ERROR_EAGAIN == rval || 0 == rval)
		return;
	else if (rval < 0) {
		log_f(state, "RELAY: Error: %s Channel write failed (%d)",
				bdata(session->ssh_addr), rval);
		ssh_relay_event_cb(session->ssh_ev, BEV_EVENT_ERROR, session);
		return;
	} else
		evbuffer_drain(buf, rval);
}
Exemplo n.º 15
0
void SHOW_LOG(int level, const char *format, ...) {
    va_list arg;
    char buffer[200];
    int len;
    if (level <= THRESHOLD) {
        va_start(arg, format);
        len = vsprintf(buffer, format, arg);
        log_f(level, buffer, len);
        va_end(arg);
    }
}
Exemplo n.º 16
0
static int
ssh_client_profile_set(obfsproxyssh_client_session_t *session)
{
	obfsproxyssh_t *state = session->client->state;
	const obfsproxyssh_client_profile_t *profile = ssh_client_profile_current;
	int i, rval;

	assert(NULL != profile);

	rval = libssh2_banner_set(session->ssh_session, profile->banner);
	if (0 != rval) {
		log_f(state, "SSH: Error: %s Failed to set banner %d",
				bdata(session->ssh_addr), rval);
	}

	libssh2_session_flag(session->ssh_session, LIBSSH2_FLAG_COMPRESS,
			profile->enable_compression);

	/*
	 * Failure to set things to exactly what I specify should be a
	 * immediate and fatal error as the lists in the profiles are chosen
	 * carefully to match existing client(s) in the wild, but see the
	 * comments in ssh_client_profile_init().
	 */

	for (i = 0; i <= LIBSSH2_METHOD_LANG_SC; i++) {
		/* Trying to force a value to NULL, causes libssh2 to SIGSEGV */
		if (NULL == profile->kex_methods[i])
			continue;

		rval = libssh2_session_method_pref(session->ssh_session, i,
				profile->kex_methods[i]);
		if (0 != rval) {
			log_f(state, "SSH: Error: %s Failed to set prefered methods %d (%d)",
					bdata(session->ssh_addr), i, rval);
			return -1;
		}
	}

	return 0;
}
Exemplo n.º 17
0
/// Read channel metainformation from KVS
/// \param  info Returns metainformation, if read
/// \return true if channel exists in KVS and read successful;  false if channel does not exist in KVS
/// Channel exists if metainfo_key (.info) exists and is of non-zero size.  File may exist and be of zero size
/// if the channel is locked before it is created.
bool Channel::read_info(ChannelInfo &info) const {
  std::string info_str;
  if (m_kvs.get(metainfo_key(), info_str) && info_str != "") {
    assert(info_str.length() == sizeof(ChannelInfo));
    memcpy((void*)&info, (void*)info_str.c_str(), sizeof(info));
    assert(info.magic == ChannelInfo::MAGIC);
    if (verbosity) log_f("Channel: read_info %s: root tile=%s", descriptor().c_str(), info.nonnegative_root_tile_index.to_string().c_str());
    return true;
  } else {
    return false;
  }
}
Exemplo n.º 18
0
void write_bucket_to_file(int bucket_id, storage_ctx *ctx, int remain_in_mem) {
    char filename[50];
    sprintf(filename, ORAM_FILE_BUCKET_FORMAT, bucket_id);
    int fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR|S_IWUSR);
    write(fd, (void *)ctx->bucket_list[bucket_id], sizeof(oram_bucket));
    if (!remain_in_mem) {
        free(ctx->bucket_list[bucket_id]);
        ctx->bucket_list[bucket_id] = 0;
        ctx->mem_counter--;
    }
    close(fd);
    log_f("Write Bucket %d to file", bucket_id);
}
Exemplo n.º 19
0
/// \brief Get value
/// \param key
/// \param value if found, returns value in this parameter
/// \return Returns true if found, false if not
///
/// See FilesystemKVS class description for the mapping between datastore and filesystem.
bool FilesystemKVS::get(const std::string &key, std::string &value) const {
  std::string path = value_key_to_path(key);
  FILE *in = fopen(path.c_str(), "rb");
  if (!in) {
    if (m_verbose) log_f("FilesystemKVS::get(%s) found no file at %s, returning false", key.c_str(), path.c_str());
    return false;
  }
  struct stat statbuf;
  if (0 != fstat(fileno(in), &statbuf)) {
    fclose(in);
    throw std::runtime_error("fstat " + path);
  }
  value.resize(statbuf.st_size);
  if (statbuf.st_size) {
    if (1 != fread(&value[0], statbuf.st_size, 1, in)) {
      fclose(in);
      throw std::runtime_error("fread " + path);
    }
  }
  fclose(in);
  if (m_verbose) log_f("FilesystemKVS::get(%s) read %zd bytes from %s", key.c_str(), value.length(), path.c_str());
  return true;
}
Exemplo n.º 20
0
void Channel::read_data(std::vector<DataSample<double> > &data, double begin, double end) const {
  double time = begin;
  data.clear();

  Locker lock(*this);  // Lock self and hold lock until exiting this method

  ChannelInfo info;
  bool success = read_info(info);
  if (!success) {
    // Channel doesn't yet exist;  no data
    if (verbosity) log_f("read_data: can't read info");
    return;
  }
  bool first_tile = true;

  while (time < end) {
    TileIndex ti = find_lowest_child_overlapping_time(info.nonnegative_root_tile_index, time);
    if (ti.is_null()) {
      // No tiles; no more data
      if (verbosity) log_f("read_data: can't read tile");
      return;
    }

    Tile tile;
    assert(read_tile(ti, tile));
    unsigned i = 0;
    if (first_tile) {
      // Skip any samples before requested time
      for (; i < tile.double_samples.size() && tile.double_samples[i].time < begin; i++);
    }

    for (; i < tile.double_samples.size() && tile.double_samples[i].time < end; i++) {
      data.push_back(tile.double_samples[i]);
    }
    time = ti.end_time();
  }
}
Exemplo n.º 21
0
int mix_database::load()
{
	if (!td_list.empty() || !ra_list.empty() || !ts_list.empty())
		return 0;
	Cvirtual_binary f;
	if (f.load(xcc_dirs::get_data_dir() + "global mix database.dat") || f.size() < 16)
		return 1;
	const char* data = reinterpret_cast<const char*>(f.data());
	read_list(game_td, data);
	read_list(game_ra, data);
	read_list(game_ts, data);
	read_list(game_ra2, data);
	if (0)
	{
		ofstream log_f("c:\\log.txt");
		for (auto& i : ts_list)
			log_f << i.second.name << '\t' << i.second.description << endl;
	}
	return 0;
	char name[12] = "scg00ea.bin";
	const char char1[] = "bgjm";
	const char char2[] = "ew";
	const char char3[] = "abc";
	for (int i = 0; i < 2; i++)
	{
		if (i)
			strcpy(name + 8, "ini");
		for (int j = 0; j < 4; j++)
		{
			name[2] = char1[j];
			for (int k = 0; k < 100; k++)
			{
				memcpy(name + 3, nwzl(2, k).c_str(), 2);
				for (int l = 0; l < 2; l++)
				{
					name[5] = char2[l];
					for (int m = 0; m < 3; m++)
					{
						name[6] = char3[m];
						mix_database::add_name(game_td, name, "");
						mix_database::add_name(game_ra, name, "");
						mix_database::add_name(game_ts, name, "");
					}
				}
			}
		}
	}
	return 0;
}
Exemplo n.º 22
0
static void
client_error_cb(struct evconnlistener *lis, void *ptr)
{
	obfsproxyssh_client_t *client = ptr;
	obfsproxyssh_t *state = client->state;
	int err;

	assert(lis == client->listener);

	err = EVUTIL_SOCKET_ERROR();
	log_f(state, "SOCKS: Error: Error on listen socket (%d)", err);

	evconnlistener_free(lis);
	client->listener = NULL;
}
Exemplo n.º 23
0
int main(){
  vsip_init((void*)0);
  acos_f();
  asin_f();
  atan2_f();
  atan_f();
  cos_f();
  sin_f();
  sqrt_f();
  tan_f();
  ceil_f();
  exp_f();
  exp10_f();
  floor_f();
  fmod_f();
  hypot_f();
  log_f();
  log10_f();
  mag_f();
  max_f();
  min_f();
  pow_f();
  rsqrt_f();
  sinh_f();
  tanh_f();
  cosh_f();
  arg_f();
  cadd_f();
  cdiv_f();
  cexp_f();
  cjmul_f();
  cmul_f();
  clog_f();
  cmag_f();
  cmagsq_f();
  cmplx_f();
  cneg_f();
  conj_f();
  crecip_f();
  csqrt_f();
  csub_f(0);
  imag_f();
  real_f();
  polar_f();
  rect_f();
  vsip_finalize((void*)0);
  return 0;
}
Exemplo n.º 24
0
/// \brief Set key to value
/// \param key
/// \param value
void FilesystemKVS::set(const std::string &key, const std::string &value) {
  std::string path = value_key_to_path(key); 
  FILE *out = fopen(path.c_str(), "wb");
  if (!out) {
    make_parent_directories(path);
    out = fopen(path.c_str(), "wb");
    if (!out) throw std::runtime_error("fopen " +  path);
  }
  if (value.size()) {
    if (1 != fwrite(&value[0], value.size(), 1, out)) {
      fclose(out);
      throw std::runtime_error("fwrite " + path);
    }
  }
  if (m_verbose) log_f("FilesystemKVS::set(%s) wrote %zd bytes to %s", key.c_str(), value.length(), path.c_str());
  fclose(out);
}
Exemplo n.º 25
0
static void
ssh_channel_cb(obfsproxyssh_client_session_t *session)
{
	static const char socks_4_resp[] = {
		0x00,				/* VN */
		SOCKS_4_REQUEST_GRANTED,	/* CD */
		0x00, 0x00,			/* DSTPORT */
		0x00 ,0x00, 0x00, 0x00		/* DSTIP */
	};
	obfsproxyssh_t *state = session->client->state;

	session->ssh_channel =
		libssh2_channel_direct_tcpip(session->ssh_session,
				"127.0.0.1", session->orport);
	if (NULL == session->ssh_channel) {
		if (LIBSSH2_ERROR_EAGAIN ==
				libssh2_session_last_errno(session->ssh_session))
			return;
		else {
			log_f(state, "SSH: Error: %s Failed to initialize direct-tcp channel",
					bdata(session->ssh_addr));
			libssh2_session_free(session->ssh_session);
			session->ssh_session = NULL;
			session_free(session);
			return;
		}
	}

	/* Send the SOCKS 4 response */
	bufferevent_write(session->socks_ev, socks_4_resp,
			SOCKS_4_CONNECT_RESPONSE_LEN);

	/* Renable reading/writing on the buffer event */
	bufferevent_enable(session->socks_ev, EV_READ);
	bufferevent_setcb(session->socks_ev, socks_relay_cb, NULL,
			socks_event_cb, session);
	session->socks_is_valid = 1;

	/* Change the event callback to something that does channel cleanup */
	bufferevent_setcb(session->ssh_ev, ssh_read_cb, ssh_write_cb,
			ssh_relay_event_cb, session);

	session->libssh2_cb = ssh_relay_cb;
}
Exemplo n.º 26
0
void Channel::create_parent_tile_from_children(TileIndex parent_index, Tile &parent, Tile children[]) {
  // Subsample the children to create the parent
  // when do we want to show original values?
  // when do we want to do a real low-pass filter?
  // do we need to filter more than just the child tiles? e.g. gaussian beyond the tile border
  if (verbosity) log_f("Channel: creating parent %s from children %s, %s",
                       parent_index.to_string().c_str(),
                       parent_index.left_child().to_string().c_str(),
                       parent_index.right_child().to_string().c_str());

  combine_samples(BT_CHANNEL_DOUBLE_SAMPLES, parent_index, parent.double_samples, children[0].double_samples, children[1].double_samples);
  if (children[0].double_samples.size() + children[1].double_samples.size()) assert(parent.double_samples.size());

  combine_samples(BT_CHANNEL_STRING_SAMPLES, parent_index, parent.string_samples, children[0].string_samples, children[1].string_samples);
  if (children[0].string_samples.size() + children[1].string_samples.size()) assert(parent.string_samples.size());

  parent.ranges = children[0].ranges;
  parent.ranges.add(children[1].ranges);
}
Exemplo n.º 27
0
int main(int argc, char **argv)
{
  char **argptr = argv+1;

  if (!*argptr) usage();
  std::string storename = *argptr++;

  if (!*argptr) usage();
  int uid = atoi(*argptr++);
  if (uid <= 0) usage();
  set_log_prefix(string_printf("%d %d ", getpid(), uid));

  {
    std::string arglist;
    for (int i = 0; i < argc; i++) {
      if (i) arglist += " ";
      arglist += std::string("'")+argv[i]+"'";
    }
    log_f("export START: %s", arglist.c_str());
  }
  
  std::vector<std::string> channel_full_names;
  
  while (*argptr) {
    channel_full_names.push_back(*argptr++);
  }
  if (!channel_full_names.size()) usage();

  Range times = Range::all();

  FilesystemKVS store(storename.c_str());

  for (unsigned i = 0; i < channel_full_names.size(); i++) {
    std::string &channel_full_name = channel_full_names[i];
    if (i) printf("\f");
    printf("Time\t%s\n", channel_full_name.c_str());
    Channel ch(store, uid, channel_full_name);
    Channel::Locker locker(ch);
    ch.read_tiles_in_range(times, dump_samples, TileIndex::lowest_level());
  }
  return 0;
}
Exemplo n.º 28
0
PeriodicDataRecord::PeriodicDataRecord(const Source &source, const unsigned char *payload,
                                       int payload_len, const StartOfFileRecord *sofr)
  : start_of_file_record(sofr)
{
  try {
    const unsigned char *ptr=payload, *end=payload+payload_len;
    first_sample_short_tick = read_u32(ptr);
    sample_period = read_u32(ptr);
    number_of_samples = read_u32(ptr);
    
    char *cdef_begin = (char*)ptr;
    char *cdef_end;
    for (cdef_end = cdef_begin; cdef_end < (char*)end && *cdef_end; cdef_end++) {}
    if (cdef_end >= (char*)end) throw ParseError("At byte %d: DEVICE_PARAMS don't end with NUL", source.pos(end-1));
    
    char *cptr = (char*) cdef_begin;
    channel_signature = std::string(cdef_begin, cdef_end-1);
    
    while (cptr < cdef_end) {
      char *keyptr = cptr;
      cptr = strchr(cptr, '\t');
      if (!cptr) throw ParseError("At byte %d: DEVICE_PARAMS missing tab", source.pos(keyptr));
      std::string key(keyptr, cptr);
      cptr++; // skip tab
      char *valueptr = cptr;
      cptr = strchr(cptr, '\n');
      if (!cptr) throw ParseError("At byte %d: DEVICE_PARAMS missing newline", source.pos(valueptr));
      std::string value(valueptr, cptr);
      cptr++; // skip
      int nbits = atoi(value.c_str());
      if (verbose) log_f("parse_bt_file:  '%s'=%d", key.c_str(), nbits);
      channel_definitions.push_back(std::pair<std::string, int>(key, nbits));
    }
    
    ptr = (unsigned char*)cdef_end+1;
    data = std::vector<unsigned char>(ptr, end);
  }
  catch (ParseError &e) {
    throw ParseError("In RTYPE_START_OF_FILE payload starting at byte %d: %s", source.pos(payload), e.what());
  }
}
Exemplo n.º 29
0
static void
client_on_shutdown(obfsproxyssh_t *state, int arg)
{
	obfsproxyssh_client_t *client = state->ctxt;
	obfsproxyssh_client_session_t *session, *tmp;
	obfsproxyssh_client_args_t *p;

	if (NULL != client->listener) {
		log_f(state, "SOCKS: Stopped accepting new connections");
		evconnlistener_free(client->listener);
		client->listener = NULL;

		while(!LIST_EMPTY(&client->arg_cache)) {
			p = LIST_FIRST(&client->arg_cache);
			LIST_REMOVE(p, entries);
			bdestroy(p->addr);
			bdestroy(p->args);
			free(p);
		}
	}

	if (OBFSPROXYSSH_SHUTDOWN_LISTENER == arg)
		return;

	session = LIST_FIRST(&client->sessions);
	while (session != NULL) {
		tmp = LIST_NEXT(session, entries);
		bufferevent_disable(tmp->socks_ev, EV_READ);
		socks_event_cb(tmp->socks_ev, BEV_ERROR, tmp);
		session = tmp;
	}

	if (OBFSPROXYSSH_SHUTDOWN_SESSIONS == arg)
		return;

	libssh2_exit();

	free(client);
	state->ctxt = NULL;
	state->shutdown_fn = NULL;
}
Exemplo n.º 30
0
static void
socks_event_cb(struct bufferevent *bev, short what, void *ptr)
{
	obfsproxyssh_client_session_t *session = ptr;
	obfsproxyssh_t *state = session->client->state;

	assert(session->socks_ev == bev);

	if (0 == (what & (BEV_EVENT_EOF | BEV_EVENT_ERROR)))
		return;

	log_f(state, "SOCKS: %s Disconnect", bdata(session->socks_addr));

	session->socks_is_valid = 0;
	if (0 == session->ssh_is_valid)
		session_free(session);
	else {
		session->libssh2_cb = ssh_relay_teardown_cb;
		session->libssh2_cb(session);
	}
}