test_case::shared_ptr
test_case_set::get_tc_from_csv(const std::string& csv_line, const csv_map& cols)
{
    unsigned test_case_num = 0;
    u_int32_t num_msgs = 0;
    std::size_t min_data_size = 0;
    std::size_t max_data_size = 0;
    bool auto_deq = false;
    std::size_t min_xid_size = 0;
    std::size_t max_xid_size = 0;
    test_case::transient_t transient = test_case::JTT_TRANSIENT;
    test_case::external_t external = test_case::JDL_INTERNAL;
    std::string comment;

    csv_tok t(csv_line);
    unsigned col_num = 0;
    for (csv_tok_citr t_itr = t.begin(); t_itr != t.end(); ++t_itr, ++col_num)
    {
        const std::string& tok = *t_itr;
        csv_map_citr m_citr = cols.find(col_num);
        if (m_citr != cols.end())
        {
            switch (m_citr->second)
            {
                case CSV_TC_NUM:
                    if (!tok.size() || tok[0] < '0' || tok[0] > '9')
                        return test_case::shared_ptr();
                    test_case_num = unsigned(std::atol(tok.c_str()));
                    break;
                case CSV_TC_NUM_MSGS: num_msgs = u_int32_t(std::atol(tok.c_str())); break;
                case CSV_TC_MIN_DATA_SIZE: min_data_size = std::size_t(std::atol(tok.c_str())); break;
                case CSV_TC_MAX_DATA_SIZE: max_data_size = std::size_t(std::atol(tok.c_str())); break;
                case CSV_TC_AUTO_DEQ:
                    if (tok == "TRUE" || tok == "1")
                        auto_deq = true;
                    break;
                case CSV_TC_MIN_XID_SIZE: min_xid_size = std::size_t(std::atol(tok.c_str())); break;
                case CSV_TC_MAX_XID_SIZE: max_xid_size = std::size_t(std::atol(tok.c_str())); break;
                case CSV_TC_TRANSIENT:
                    if (tok == "TRUE" || tok == "1")
                        transient = test_case::JTT_PERSISTNET;
                    else if (tok == "RANDOM" || tok == "-1")
                        transient = test_case::JTT_RANDOM;
                    break;
                case CSV_TC_EXTERNAL:
                    if (tok == "TRUE" || tok == "1")
                        external = test_case::JDL_EXTERNAL;
                    else if (tok == "RANDOM" || tok == "-1")
                       external  = test_case::JDL_RANDOM;
                    break;
                case CSV_TC_COMMENT: comment = *t_itr; break;
            }
        }
    }
    if (col_num)
        return test_case::shared_ptr(new test_case(test_case_num, num_msgs, min_data_size,
                max_data_size, auto_deq, min_xid_size, max_xid_size, transient, external, comment));
    else
        return test_case::shared_ptr();
}
Esempio n. 2
0
    to_xdr_t::to_xdr_t (u_int32_t i) 
    {
      if (i > u_int32_t (INT32_MAX)) {
	_x.set_typ (AMYSQL_TYPE_UINT64);
	*_x.amysql_uint64 = i;
      } else {
	_x.set_typ (AMYSQL_TYPE_INT);
	*_x.amysql_int = i;
      }
    }
Esempio n. 3
0
void cryptfiles::cryptFile( const char * s,const char * d,const char * k,unsigned long l,bool encrypt )
{
	using function_t = std::function< int( int ) > ;

	function_t foo = [ this ]( int e ){ emit progressUpdate( e ) ; return 0 ; } ;

	auto f = reinterpret_cast< void * >( &foo ) ;

	auto u = []( int e,void * f )
	{
		auto function = reinterpret_cast< function_t * >( f ) ;

		return ( *function )( e ) ;
	} ;

	auto r = Task::await( [ & ]{

		auto r = u_int32_t( l ) ;

		if( encrypt ){

			return lxqt_wallet_create_encrypted_file( k,r,s,d,u,f ) ;
		}else{
			return lxqt_wallet_create_decrypted_file( k,r,s,d,u,f ) ;
		}
	} ) ;

	if( r == lxqt_wallet_wrong_password ){

		this->taskFinished( cryptfiles::wrongKey ) ;

	}else if( r == lxqt_wallet_no_error ){

		if( m_ui->progressBar->value() == 100 ){

			utility::changePathOwner( d ) ;

			if( encrypt ){

				this->taskFinished( cryptfiles::encryptSuccess ) ;
			}else{
				this->taskFinished( cryptfiles::decryptSuccess ) ;
			}
		}else{
			this->taskFinished( cryptfiles::quit ) ;
		}
	}else{
		/*
		 * we shouldnt get here and we return a bogus return value for lack of better
		 * alternative
		 */
		this->taskFinished( cryptfiles::openMapperReadFail ) ;
	}
}
Esempio n. 4
0
int 
main (int argc, char *argv[])
{
  setprogname (argv[0]);
  if (argc != 2)
    usage ();
  str s = file2str (argv[1]);

  if (!s)
    fatal << "cannot open file: " << argv[1];

  u_int niter = 10;
  u_int osz = 0;
  u_int32_t tot = 0;
  mstr *outbuf = NULL;

  u_int slen = s.len ();
  u_int out_avail = u_int ((slen / 1000) * 1001) + 16;

  for (u_int i = 0; i < niter; i++) {

    if (outbuf)
      delete outbuf;
    outbuf = New mstr (out_avail);

    warn << "+ starting compression\n";
    startt ();
    osz = go (s, outbuf, out_avail); 
    u_int t = stopt ();
    warn << "- ending compression (time=" << t << ")\n";
    tot += t;
    
  }

  outbuf->setlen (osz);

  //
  // write out the buffer once, just to make sure we were getting reasonable
  // data output (and not some bullshit)
  //
  u_int i = 0;
  do {
    int rc = write (1, outbuf->cstr () + i, min<u_int> (2048, osz - i));
    if (rc < 0)
      panic ("write error!\n");
    i += rc;
  } while (i < osz);

  u_int64_t bw = osz / 1024;
  bw *= 1000000;
  bw /= tot;
  bw *= niter;


  warn ("Input: %d bytes\n"
	"Output: %d bytes\n"
	"Iterations: %d\n"
	"Usecs Total: %d\n"
	"Compression ratio * 1000: %d\n"
	"Throughput (kB/sec): %d\n",
	slen, osz, niter, tot, osz * 1000 / slen, u_int32_t (bw));

}
Esempio n. 5
0
void netflow_format_flow(struct store_flow_complete* flow, char* buf, size_t len,
    int utc_flag, u_int32_t display_mask, int hostorder) {
    char tmp[256];
    u_int32_t fields;
    u_int64_t (*fmt_ntoh64)(u_int64_t) = netflow_swp_ntoh64;
    u_int32_t (*fmt_ntoh32)(u_int32_t) = netflow_swp_ntoh32;
    u_int16_t (*fmt_ntoh16)(u_int16_t) = netflow_swp_ntoh16;

    if (hostorder) {
        fmt_ntoh64 = netflow_swp_fake64;
        fmt_ntoh32 = netflow_swp_fake32;
        fmt_ntoh16 = netflow_swp_fake16;
    }

    *buf = '\0';

    fields = fmt_ntoh32(flow->hdr.fields) & display_mask;

    strlcat(buf, "FLOW ", len);

    if (SHASFIELD(TAG)) {
        snprintf(tmp, sizeof(tmp), "tag %u ", fmt_ntoh32(flow->tag.tag));
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(RECV_TIME)) {
        snprintf(tmp, sizeof(tmp), "recv_time %s.%05d ",
            iso_time(fmt_ntoh32(flow->recv_time.recv_sec), utc_flag),
            fmt_ntoh32(flow->recv_time.recv_usec));
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(PROTO_FLAGS_TOS)) {
        snprintf(tmp, sizeof(tmp), "proto %d ", flow->pft.protocol);
        strlcat(buf, tmp, len);
        snprintf(tmp, sizeof(tmp), "tcpflags %02x ",
            flow->pft.tcp_flags);
        strlcat(buf, tmp, len);
        snprintf(tmp, sizeof(tmp), "tos %02x " , flow->pft.tos);
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(AGENT_ADDR4) || SHASFIELD(AGENT_ADDR6)) {
        snprintf(tmp, sizeof(tmp), "agent [%s] ",
            addr_ntop_buf(&flow->agent_addr));
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(SRC_ADDR4) || SHASFIELD(SRC_ADDR6)) {
        snprintf(tmp, sizeof(tmp), "src [%s]",
            addr_ntop_buf(&flow->src_addr));
        strlcat(buf, tmp, len);
        if (SHASFIELD(SRCDST_PORT)) {
            snprintf(tmp, sizeof(tmp), ":%d",
                fmt_ntoh16(flow->ports.src_port));
            strlcat(buf, tmp, len);
        }
        strlcat(buf, " ", len);
    }
    if (SHASFIELD(DST_ADDR4) || SHASFIELD(DST_ADDR6)) {
        snprintf(tmp, sizeof(tmp), "dst [%s]",
            addr_ntop_buf(&flow->dst_addr));
        strlcat(buf, tmp, len);
        if (SHASFIELD(SRCDST_PORT)) {
            snprintf(tmp, sizeof(tmp), ":%d",
                fmt_ntoh16(flow->ports.dst_port));
            strlcat(buf, tmp, len);
        }
        strlcat(buf, " ", len);
    }
    if (SHASFIELD(GATEWAY_ADDR4) || SHASFIELD(GATEWAY_ADDR6)) {
        snprintf(tmp, sizeof(tmp), "gateway [%s] ",
            addr_ntop_buf(&flow->gateway_addr));
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(PACKETS)) {
        snprintf(tmp, sizeof(tmp), "packets %lu ",
            fmt_ntoh64(flow->packets.flow_packets));
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(OCTETS)) {
        snprintf(tmp, sizeof(tmp), "octets %lu ",
            fmt_ntoh64(flow->octets.flow_octets));
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(IF_INDICES)) {
        snprintf(tmp, sizeof(tmp), "in_if %d out_if %d ",
            fmt_ntoh32(flow->ifndx.if_index_in),
            fmt_ntoh32(flow->ifndx.if_index_out));
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(AGENT_INFO)) {
        snprintf(tmp, sizeof(tmp), "sys_uptime_ms %s.%03u ",
            interval_time(fmt_ntoh32(flow->ainfo.sys_uptime_ms) / 1000),
            fmt_ntoh32(flow->ainfo.sys_uptime_ms) % 1000);
        strlcat(buf, tmp, len);
        snprintf(tmp, sizeof(tmp), "time_sec %s ",
            iso_time(fmt_ntoh32(flow->ainfo.time_sec), utc_flag));
        strlcat(buf, tmp, len);
        snprintf(tmp, sizeof(tmp), "time_nanosec %lu netflow ver %u ",
            (u_long)fmt_ntoh32(flow->ainfo.time_nanosec),
            fmt_ntoh16(flow->ainfo.netflow_version));
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(FLOW_TIMES)) {
        snprintf(tmp, sizeof(tmp), "flow_start %s.%03u ",
            interval_time(fmt_ntoh32(flow->ftimes.flow_start) / 1000),
            fmt_ntoh32(flow->ftimes.flow_start) % 1000);
        strlcat(buf, tmp, len);
        snprintf(tmp, sizeof(tmp), "flow_finish %s.%03u ",
            interval_time(fmt_ntoh32(flow->ftimes.flow_finish) / 1000),
            fmt_ntoh32(flow->ftimes.flow_finish) % 1000);
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(AS_INFO)) {
        snprintf(tmp, sizeof(tmp), "src_AS %u src_masklen %u ",
            fmt_ntoh32(flow->asinf.src_as), flow->asinf.src_mask);
        strlcat(buf, tmp, len);
        snprintf(tmp, sizeof(tmp), "dst_AS %u dst_masklen %u ",
            fmt_ntoh32(flow->asinf.dst_as), flow->asinf.dst_mask);
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(FLOW_ENGINE_INFO)) {
        snprintf(tmp, sizeof(tmp),
            "engine_type %u engine_id %u seq %lu source %lu ",
            fmt_ntoh16(flow->finf.engine_type), 
            fmt_ntoh16(flow->finf.engine_id),
            (u_long)fmt_ntoh32(flow->finf.flow_sequence), 
            (u_long)fmt_ntoh32(flow->finf.source_id));
        strlcat(buf, tmp, len);
    }
    if (SHASFIELD(CRC32)) {
        snprintf(tmp, sizeof(tmp), "crc32 %08x ",
            fmt_ntoh32(flow->crc32.crc32));
        strlcat(buf, tmp, len);
    }
}