Example #1
0
TIMESTAMP collector::commit(TIMESTAMP t0, TIMESTAMP t1)
{
	TIMESTAMP dt = (TIMESTAMP)get_interval();
	if ( dt==0 || ( t1==next_t && next_t!=TS_NEVER ) )
	{
		char buffer[4096];
		size_t eos = sprintf(buffer,"INSERT INTO `%s` (t", get_table());
		int n;
		for ( n=0 ; n<n_aggregates ; n++ )
			eos += sprintf(buffer+eos,",`%s`",names[n]);
		eos += sprintf(buffer+eos,") VALUES (from_unixtime(%lli)",gl_globalclock);
		for ( n=0 ; n<n_aggregates ; n++ )
			eos += sprintf(buffer+eos,",%g",list[n].get_value());
		sprintf(buffer+eos,"%s",")");

		if ( !db->query(buffer) )
			exception("unable to add data to '%s' - %s", get_table(), mysql_error(mysql));
		else
			gl_verbose("%s: sample added to '%s' ok", get_name(), get_table());

		// check limit
		if ( get_limit()>0 && db->get_last_index()>=get_limit() )
		{
			gl_verbose("%s: limit of %d records reached", get_name(), get_limit());
			next_t = TS_NEVER;
		}
		else
		{
			next_t = (dt==0 ? TS_NEVER : (TIMESTAMP)(t1/dt+1)*dt);
		}
		set_clock(t1);
	}
	return TS_NEVER;
}
Example #2
0
void test_db() {
  // Create a database with the default options.
  auto db = grnxx::open_db("");
  assert(db->num_tables() == 0);

  // Create a table named "Table_1".
  auto table = db->create_table("Table_1");
  assert(table->name() == "Table_1");
  assert(db->num_tables() == 1);
  assert(db->get_table(0) == table);

  assert(db->find_table("Table_1") == table);
  assert(!db->find_table("Table_X"));

  // The following create_table() must fail because "Table_1" already exists.
  try {
    db->create_table("Table_1");
    assert(false);
  } catch (...) {
  }

  // Create tables named "Table_2" and "Table_3".
  assert(db->create_table("Table_2"));
  assert(db->create_table("Table_3"));
  assert(db->num_tables() == 3);
  assert(db->get_table(0)->name() == "Table_1");
  assert(db->get_table(1)->name() == "Table_2");
  assert(db->get_table(2)->name() == "Table_3");

  // Remove "Table_2".
  db->remove_table("Table_2");
  assert(db->num_tables() == 2);
  assert(db->get_table(0)->name() == "Table_1");
  assert(db->get_table(1)->name() == "Table_3");

  // Recreate "Table_2".
  assert(db->create_table("Table_2"));

  // Move "Table_3" to the next to "Table_2".
  db->reorder_table("Table_3", "Table_2");
  assert(db->get_table(0)->name() == "Table_1");
  assert(db->get_table(1)->name() == "Table_2");
  assert(db->get_table(2)->name() == "Table_3");

  // Move "Table_3" to the head.
  db->reorder_table("Table_3", "");
  assert(db->get_table(0)->name() == "Table_3");
  assert(db->get_table(1)->name() == "Table_1");
  assert(db->get_table(2)->name() == "Table_2");

  // Move "Table_2" to the next to "Table_3".
  db->reorder_table("Table_2", "Table_3");
  assert(db->get_table(0)->name() == "Table_3");
  assert(db->get_table(1)->name() == "Table_2");
  assert(db->get_table(2)->name() == "Table_1");
}
Example #3
0
IEstimator* EstimatorsFactory::create(const std::string& classname)
{
    std::map<std::string, EstimatorsCreator*>::iterator i;
    i = get_table().find(classname);

    if(i != get_table().end())
        return i->second->create();
    else
        return (IEstimator*)NULL;
}
Example #4
0
/**
 * create -- creates a Berkeley DB file with tablename (tn), along with
 * 	 	the needed metadata.
 * 		requires the schema data to be already parsed '-L' option.
 */
int create(char* tn)
{
	DB* db;
	int rc;
	tbl_cache_p tbc = NULL;
	table_p tp = NULL;
	rc = 0;
	
	tbc = get_table(tn);
	if(!tbc)
	{	fprintf(stderr, "[create] Table %s is not supported.\n",tn);
		return 1;
	}
	
	tp  = tbc->dtp;
	db = get_db(tp);
	
	if(db)
	{
		printf("Created table %s\n",tn);
		rc = 0;
	}
	else
	{
		fprintf(stderr, "[create] Failed to create table %s\n",tn);
		rc = 1;
	}
	
	return rc;
}
Example #5
0
bool nas_acl_counter_t::push_create_obj_to_npu (npu_id_t npu_id,
                                                void* ndi_obj)
{
    ndi_obj_id_t ndi_cntr_id = 0;
    t_std_error rc = STD_ERR_OK;
    ndi_acl_counter_t ndi_counter = {0};

    ndi_counter.table_id = get_table().get_ndi_obj_id(npu_id);
    ndi_counter.enable_pkt_count = _enable_pkt_count;
    ndi_counter.enable_byte_count = _enable_byte_count;

    if ((rc = ndi_acl_counter_create (npu_id, &ndi_counter, &ndi_cntr_id))
            != STD_ERR_OK)
    {
        throw nas::base_exception {rc, __PRETTY_FUNCTION__,
                       std::string {"NDI Fail: counter Create Failed for NPU "}
                       + std::to_string (npu_id)};
    }
    // Cache the new counter ID generated by NDI
    _ndi_obj_ids[npu_id] = ndi_cntr_id;

    NAS_ACL_LOG_DETAIL ("Switch %d: Created ACL counter in NPU %d; NDI ID 0x%" PRIx64,
                        get_switch().id(), npu_id, ndi_cntr_id);

    return true;
}
Example #6
0
void build_action(vector_t *arguments) {
    load_t *loader = load_project_config();
    if (!loader) {
        printf("error: are you sure the current directory contains an Ark project?\n");
        return;
    }

    table_t *package = get_table(loader, "package");

    // check for a custom build method and use it if it
    // exists.
    char *build_method = get_string_contents("build", package);
    if (build_method) {
        // note we're using system calls, this isn't a good idea
        // at all, we're also just throwing in some random variable
        // that should probably be sanitized?
        // same applies for the one below
        exec_process(build_method);
        sdsfree(build_method);
    }
    else {
        exec_process("ark build src/*.ark");
    }

    destroy_loader(loader);
}
Example #7
0
//02 002
void config_encryption(const char *password, const char *method) {
    SSLeay_add_all_algorithms();
    sodium_init();
    _method = encryption_method_from_string(method);
    if (_method == ENCRYPTION_TABLE) {
        get_table((unsigned char *) password);
        cipher = CIPHER_TABLE;
    } else if (_method == ENCRYPTION_SALSA20 || _method == ENCRYPTION_CHACHA20) {
        cipher = CIPHER_SODIUM;
        _key_len = 32;
        unsigned char tmp[EVP_MAX_IV_LENGTH];;
        EVP_BytesToKey(EVP_aes_256_cfb(), EVP_md5(), NULL, (unsigned char *)password,
                                strlen(password), 1, _key, tmp);
        shadowsocks_key = _key;
    } else {
        cipher = CIPHER_OPENSSL;
        const char *name = shadowsocks_encryption_names[_method];
        if (_method == ENCRYPTION_RC4_MD5) {
            name = "RC4";
        }
        _cipher = EVP_get_cipherbyname(name);
        if (_cipher == NULL) {
//            assert(0);
            // TODO
            printf("_cipher is nil! \r\nThe %s doesn't supported!\r\n please chose anthor!",name);
        } else {
            unsigned char tmp[EVP_MAX_IV_LENGTH];
            _key_len = EVP_BytesToKey(_cipher, EVP_md5(), NULL, (unsigned char *)password,
                                      strlen(password), 1, _key, tmp);
            shadowsocks_key = _key;
        }

//        printf("%d\n", _key_len);
    }
}
Example #8
0
 int num_data_rows( HELEMENT he )
 {
   dom::element tbl = get_table(he);
   int n = fixed_rows(tbl);
   int total = tbl.children_count();
   return total - n;
 }
Example #9
0
static void drop_tbl ()
{
  char tbl_name[30];
  fscanf (in_s, " table %s;", tbl_name);
  trim_pending_semicolon (tbl_name);
  remove_table ( get_table(tbl_name) );
}
Example #10
0
    virtual BOOL on_mouse(HELEMENT he, HELEMENT target, UINT event_type, POINT pt, UINT mouseButtons, UINT keyboardStates )
    {
    
      if( event_type == MOUSE_WHEEL )
      {
        int dir = (int)mouseButtons;
        return on_scroll( he, target, dir < 0? SCROLL_STEP_PLUS : SCROLL_STEP_MINUS, 0, TRUE );
      }
    
      if( event_type != MOUSE_DOWN && event_type != MOUSE_DCLICK )
        return false;

      if(mouseButtons != MAIN_MOUSE_BUTTON) 
        return false;

      dom::element table = get_table(he);
      dom::element row = target_row(table, dom::element(target));

      if(row.is_valid()) // click on the row
      {
        if( (int)row.index() < (int)fixed_rows(table) )
        {
          // click on the header cell
          dom::element header_cell = target_header(row,target);
          if( header_cell.is_valid() )  
              on_column_click(table, header_cell);
          return true;
        }
        set_current_row(table, row, keyboardStates,  event_type == MOUSE_DCLICK);
      }
      return true; // as it is always ours then stop event bubbling
    }
Example #11
0
	bool Lua_table::valid()const
	{ 
		int const init_stack_top = initail_stack_size();
		bool result = get_table();
		restore_stack(init_stack_top);
		return result;
	}
Example #12
0
schema_p get_schema ( const char *name )
{
  tbl_p tbl = get_table ( name );
  if ( tbl == NULL)
    return NULL;
  else
    return tbl->sch;
}
Example #13
0
// ---------- begin of function ColorTable::patch_table --------//
void ColorTable::patch_table(BYTE from, WORD to)
{
	err_when(from >= table_size);
	for(int s = -abs_scale; s <= abs_scale; ++s)
	{
		get_table(s)[from] = to;
	}
}
void bit_vector_nearest_neighbor_base::set_row(
    const string& id,
    const common::sfv_t& sfv) {
  // TODO(beam2d): support nested algorithm, e.g. when used by lof and then
  // we cannot suppose that the first column is assigned
  // to bit_vector_nearest_neighbor_base.
  get_table()->add(id, owner(my_id_), hash(sfv));
}
Example #15
0
static void* resolve_symbol(const char* library, const char* symbol)
{
    const struct link_map* map = link_map_entry_for_library(library);

    if (!map)
    {
        return NULL;
    }

    const uint32_t* hashtab = get_table(map, DT_GNU_HASH);
    const Elf32_Sym* symtab = get_table(map, DT_SYMTAB);
    const char* strtab = get_table(map, DT_STRTAB);

    uint32_t nbuckets = hashtab[0];
    uint32_t symndx = hashtab[1];
    uint32_t maskwords = hashtab[2];
    // index 3 is used for a 'fast-reject-filter' we just ignore
    const uint32_t* buckets = &hashtab[4 + maskwords];
    const uint32_t* values = &hashtab[4 + maskwords + nbuckets];

    uint32_t hash = gnu_hash(symbol);

    uint32_t chain = buckets[hash % nbuckets];
    if (chain == 0)
    {
        fprintf(stderr, "hash of symbol %s in %s refers to empty chain\n", symbol, library);
        return NULL;
    }

    const Elf32_Sym* sym = &symtab[chain];
    const uint32_t* chain_ptr = &values[chain - symndx];
    do
    {
        if ((hash & ~1) == (*chain_ptr & ~1) && strcmp(symbol, strtab + sym->st_name) == 0)
        {
            return (void*)(map->l_addr + sym->st_value);
        }

        sym += 1;
        chain_ptr += 1;
    } while (sym->st_name & 1); // last bit is set for all but the last entry of the chain

    fprintf(stderr, "failed to resolve symbol %s in %s\n", symbol, library);
    return NULL;
}
Example #16
0
MyItr * Tables::get_itr( string t_name )
{
  Table * table = get_table ( t_name );

  if ( table )
    return table->get_itr();
  else
    return NULL;
}
Example #17
0
File: db.c Project: pandax381/NAT64
int sessiondb_delete_by_bib(struct bib_entry *bib)
{
	struct session_table *table = get_table(bib->l4_proto);
	if (!table)
		return -EINVAL;

	sessiontable_delete_by_bib(table, bib);
	return 0;
}
Example #18
0
File: db.c Project: pandax381/NAT64
int sessiondb_foreach(l4_protocol proto,
		int (*func)(struct session_entry *, void *), void *arg,
		struct ipv4_transport_addr *offset_remote,
		struct ipv4_transport_addr *offset_local)
{
	struct session_table *table = get_table(proto);
	return table ? sessiontable_foreach(table, func, arg, offset_remote,
			offset_local) : -EINVAL;
}
Example #19
0
euclid_lsh::euclid_lsh(
    const config& conf,
    jubatus::util::lang::shared_ptr<column_table> table,
    const std::string& id)
    : nearest_neighbor_base(table, id) {
  set_config(conf);

  vector<column_type> schema;
  fill_schema(schema);
  get_table()->init(schema);
}
Example #20
0
	void Lua_table::traverse(Lua_table::traverse_do_function do_)
	{
		if(! get_table() )return;
		int t(1);
		lua_pushnil(m_lua);  /* first key */
		while (lua_next(m_lua, t) != 0) 
		{
			(*do_)(m_lua);
			lua_pop(m_lua, 1);
		}
		lua_pop(m_lua, 1);
	}
Example #21
0
void fetch_action(vector_t *arguments) {
	load_t *project_config_loader = load_project_config();
	if (!project_config_loader) {
		printf("error: are you sure the current directory contains an Ark project?\n");
        return;
	}
    table_t *deps = get_table(project_config_loader, "dependencies");
    if (!deps) {
 		printf("error: [dependencies] was not found in the config file!\n");
 		return;
    }
    hashmap_iterate(deps->nodes, dependencies_iterate, false);
}
Example #22
0
void complete_field(std::string& field, parsed_query& p) {
        int once = 0;
        for(auto& table_name : p.tables) {
                auto table = get_table(table_name);
                if(table.is_field_present(field)) {
                        once += 1;
                }
        }
        if(once > 1) {
            throw "QueryError: Field " + field + " is ambiguous.";
        }
        if(once == 0) {
                throw "QueryError: Field " + field + " does not exist.";
        }
        for(auto& table_name : p.tables) {
                auto table = get_table(table_name);
                if(table.field_check(field)) {
                        if(field.find_last_of(".") != std::string::npos) continue;
                        field = table_name + "." + field;
                }
        }
}
Example #23
0
void LuaPlugin::deinit(PluginHost *h)
{
	Bot *b = (Bot*)h;

	lua_rawgeti(state, LUA_REGISTRYINDEX, plugin_ref);
	get_table(state, "deinit");

	if(lua_isnil(state, -1))
	{
		lua_pop(state, -1);
		throw CommandErrorException(_name, "did not provide plugin.deinit");
	}
}
Example #24
0
bool
BackupRestore::finalize_table(const TableS & table){
  bool ret= true;
  if (!m_restore && !m_restore_meta)
    return ret;
  if (!table.have_auto_inc())
    return ret;

  Uint64 max_val= table.get_max_auto_val();
  do
  {
    Uint64 auto_val = ~(Uint64)0;
    int r= m_ndb->readAutoIncrementValue(get_table(table.m_dictTable), auto_val);
    if (r == -1 && m_ndb->getNdbError().status == NdbError::TemporaryError)
    {
      NdbSleep_MilliSleep(50);
      continue; // retry
    }
    else if (r == -1 && m_ndb->getNdbError().code != 626)
    {
      ret= false;
    }
    else if ((r == -1 && m_ndb->getNdbError().code == 626) ||
             max_val+1 > auto_val || auto_val == ~(Uint64)0)
    {
      r= m_ndb->setAutoIncrementValue(get_table(table.m_dictTable),
                                      max_val+1, false);
      if (r == -1 &&
            m_ndb->getNdbError().status == NdbError::TemporaryError)
      {
        NdbSleep_MilliSleep(50);
        continue; // retry
      }
      ret = (r == 0);
    }
    return (ret);
  } while (1);
}
    virtual void get_rows_data( HELEMENT he )
    {
      dom::element tbl = get_table(he);

      DATA_ROWS_PARAMS drp;
      drp.firstRecord = first_row_idx;
      drp.totalRecords = num_rows;
      drp.firstRowIdx = fixed_rows(tbl);
      drp.lastRowIdx = tbl.children_count() - 1;

      dom::element self = he;
      self.send_event(ROWS_DATA_REQUEST, (UINT_PTR)&drp,tbl);

      first_row_idx = drp.firstRecord;
      num_rows      = drp.totalRecords;
    }
Example #26
0
void
mu_msg_header_view_set_message (MuMsgHeaderView *self, MuMsg *msg)
{
	g_return_if_fail (MU_IS_MSG_HEADER_VIEW(self));
	
	if (self->_priv->_table) {
		gtk_container_remove (GTK_CONTAINER(self), self->_priv->_table);
		self->_priv->_table = NULL;
	}

	if (msg) {
		self->_priv->_table = get_table (msg);
		gtk_box_pack_start (GTK_BOX(self), self->_priv->_table,
				    TRUE, TRUE, 0);
		gtk_widget_show_all (self->_priv->_table);
	}
}
Example #27
0
void config_encryption(const char *password, const char *method) {
    SSLeay_add_all_algorithms();
    _method = encryption_method_from_string(method);
    if (_method != EncryptionTable) {
    const char *name = encryption_names[_method];
    _cipher = EVP_get_cipherbyname(name);
    if (_cipher == NULL) {
//            assert(0);
        // TODO
    }
    unsigned char tmp[EVP_MAX_IV_LENGTH];
    _key_len = EVP_BytesToKey(_cipher, EVP_md5(), NULL, password,
            strlen(password), 1, _key, tmp);
    } else {
        get_table(password);
    }
}
Example #28
0
void LuaPlugin::init(PluginHost *h)
{
	Bot *b = (Bot*)h;

	lua_rawgeti(state, LUA_REGISTRYINDEX, plugin_ref);
	get_table(state, "init");

	push_bot(state, b);

	if(lua_isnil(state, -1))
	{
		lua_pop(state, -1);
		throw CommandErrorException(_name, "did not provide plugin.init");
	}

	safe_call(state, _name, 1, 0, 0);
}
    virtual BOOL on_scroll( HELEMENT he, HELEMENT target, SCROLL_EVENTS cmd, INT pos, BOOL isVertical ) 
    { 
      if(!isVertical)
        return FALSE; 

      int visible_rows = num_data_rows(he);
      int row = first_row_idx;

      switch( cmd )
      {
        case SCROLL_HOME:       row = 0; break;
        case SCROLL_END:        row = num_rows - visible_rows + 1; break;
        case SCROLL_STEP_PLUS:  row += 1; break;
        case SCROLL_STEP_MINUS: row -= 1; break;
        case SCROLL_PAGE_PLUS:  row += visible_rows; break;
        case SCROLL_PAGE_MINUS: row -= visible_rows; break;
        case SCROLL_POS:        row = pos; break;
        default: return FALSE; 
      }

      row = aux::limit(row, 0, num_rows - visible_rows + 1);
      
      if( row == first_row_idx ) return TRUE;

      first_row_idx = row;

      dom::element tbl = get_table(he);
      tbl.update(); // establish update 'umbrella'

      get_rows_data(he);

      dom::scrollbar sb = get_v_scrollbar(he);
      sb.set_values(first_row_idx, 0, num_rows, num_data_rows(he), 1);

      HTMLayoutUpdateWindow(tbl.get_element_hwnd(TRUE));
      
      return TRUE;

    }
    TEST_FIXTURE(table_service_test_base, ListTabled_SharedKeyLite)
    {
        const int TABLE_COUNT = 5;
        azure::storage::cloud_table tables[TABLE_COUNT];
        for (int i = 0; i < TABLE_COUNT; ++i)
        {
            tables[i] = get_table();
        }

        azure::storage::cloud_table_client client = get_table_client();
        client.set_authentication_scheme(azure::storage::authentication_scheme::shared_key_lite);

        utility::string_t prefix = object_name_prefix;
        azure::storage::table_request_options options;
        azure::storage::operation_context context;
        std::vector<azure::storage::cloud_table> results = list_all_tables(client, prefix, options, context);
        CHECK(results.size() >= TABLE_COUNT);

        for (int i = 0; i < TABLE_COUNT; ++i)
        {
            tables[i].delete_table();
        }
    }