Esempio n. 1
0
void
free_storage (void)
{
  GModule module;

  tc_db_close (ht_agent_keys, get_dbname (DB_AGENT_KEYS, -1));
  tc_db_close (ht_agent_vals, get_dbname (DB_AGENT_VALS, -1));
  tc_db_close (ht_general_stats, get_dbname (DB_GEN_STATS, -1));
  tc_db_close (ht_hostnames, get_dbname (DB_HOSTNAMES, -1));
  tc_db_close (ht_unique_keys, get_dbname (DB_UNIQUE_KEYS, -1));

  for (module = 0; module < TOTAL_MODULES; ++module) {
    free_tables (ht_storage[module].metrics, module);
  }
}
Esempio n. 2
0
/* Initialize Tokyo Cabinet storage tables */
void
init_storage (void)
{
  GModule module;

  ht_agent_keys = tc_adb_create (get_dbname (DB_AGENT_KEYS, -1));
  ht_agent_vals = tc_adb_create (get_dbname (DB_AGENT_VALS, -1));
  ht_general_stats = tc_adb_create (get_dbname (DB_GEN_STATS, -1));
  ht_hostnames = tc_adb_create (get_dbname (DB_HOSTNAMES, -1));
  ht_unique_keys = tc_adb_create (get_dbname (DB_UNIQUE_KEYS, -1));

  ht_storage = new_gstorage (TOTAL_MODULES);
  for (module = 0; module < TOTAL_MODULES; ++module) {
    init_tables (module);
  }
}
Esempio n. 3
0
/* Initialize map & metric hashes */
static void
init_tables (GModule module)
{
  GTCStorageMetric mtrc;
  int n = 0, i;

  /* *INDENT-OFF* */
  GTCStorageMetric metrics[] = {
    {MTRC_KEYMAP    , DB_KEYMAP    , NULL} ,
    {MTRC_ROOTMAP   , DB_ROOTMAP   , NULL} ,
    {MTRC_DATAMAP   , DB_DATAMAP   , NULL} ,
    {MTRC_UNIQMAP   , DB_UNIQMAP   , NULL} ,
    {MTRC_ROOT      , DB_ROOT      , NULL} ,
    {MTRC_HITS      , DB_HITS      , NULL} ,
    {MTRC_VISITORS  , DB_VISITORS  , NULL} ,
    {MTRC_BW        , DB_BW        , NULL} ,
    {MTRC_CUMTS     , DB_CUMTS     , NULL} ,
    {MTRC_MAXTS     , DB_MAXTS     , NULL} ,
    {MTRC_METHODS   , DB_METHODS   , NULL} ,
    {MTRC_PROTOCOLS , DB_PROTOCOLS , NULL} ,
    {MTRC_AGENTS    , DB_AGENTS    , NULL} ,
    {MTRC_METADATA  , DB_METADATA  , NULL} ,
  };
  /* *INDENT-ON* */

  n = ARRAY_SIZE (metrics);
  for (i = 0; i < n; i++) {
    mtrc = metrics[i];
#ifdef TCB_MEMHASH
    mtrc.store = tc_adb_create (get_dbname (mtrc.dbname, module));
#endif
#ifdef TCB_BTREE
    /* allow for duplicate keys */
    if (mtrc.metric == MTRC_AGENTS)
      mtrc.store = tc_bdb_create (DB_AGENTS, module);
    else
      mtrc.store = tc_adb_create (get_dbname (mtrc.dbname, module));
#endif
    tc_storage[module].metrics[i] = mtrc;
  }
}
Esempio n. 4
0
/* Initialize hash tables */
void
init_storage (void)
{
  GModule module;
  size_t idx = 0;

  /* Hashes used across the whole app (not per module) */
  ht_agent_keys = tc_adb_create (get_dbname (DB_AGENT_KEYS, -1));
  ht_agent_vals = tc_adb_create (get_dbname (DB_AGENT_VALS, -1));
  ht_general_stats = tc_adb_create (get_dbname (DB_GEN_STATS, -1));
  ht_hostnames = tc_adb_create (get_dbname (DB_HOSTNAMES, -1));
  ht_unique_keys = tc_adb_create (get_dbname (DB_UNIQUE_KEYS, -1));

  tc_storage = new_tcstorage (TOTAL_MODULES);

  FOREACH_MODULE (idx, module_list) {
    module = module_list[idx];

    tc_storage[module].module = module;
    init_tables (module);
  }
Esempio n. 5
0
static void
free_tables (GStorageMetrics * metrics, GModule module)
{
  /* Initialize metrics hash tables */
  tc_db_close (metrics->keymap, get_dbname (DB_KEYMAP, module));
  tc_db_close (metrics->datamap, get_dbname (DB_DATAMAP, module));
  tc_db_close (metrics->rootmap, get_dbname (DB_ROOTMAP, module));
  tc_db_close (metrics->uniqmap, get_dbname (DB_UNIQMAP, module));
  tc_db_close (metrics->hits, get_dbname (DB_HITS, module));
  tc_db_close (metrics->visitors, get_dbname (DB_VISITORS, module));
  tc_db_close (metrics->bw, get_dbname (DB_BW, module));
  tc_db_close (metrics->time_served, get_dbname (DB_AVGTS, module));
  tc_db_close (metrics->methods, get_dbname (DB_METHODS, module));
  tc_db_close (metrics->protocols, get_dbname (DB_PROTOCOLS, module));
#ifdef TCB_MEMHASH
  tc_db_close (metrics->agents, get_dbname (DB_AGENTS, module));
#endif
#ifdef TCB_BTREE
  tc_bdb_close (metrics->agents, get_dbname (DB_AGENTS, module));
#endif
}
Esempio n. 6
0
static void
init_tables (GModule module)
{
  ht_storage[module].module = module;
  ht_storage[module].metrics = new_ht_metrics ();

  /* Initialize metrics hash tables */
  ht_storage[module].metrics->keymap =
    tc_adb_create (get_dbname (DB_KEYMAP, module));
  ht_storage[module].metrics->datamap =
    tc_adb_create (get_dbname (DB_DATAMAP, module));
  ht_storage[module].metrics->rootmap =
    tc_adb_create (get_dbname (DB_ROOTMAP, module));
  ht_storage[module].metrics->uniqmap =
    tc_adb_create (get_dbname (DB_UNIQMAP, module));
  ht_storage[module].metrics->hits =
    tc_adb_create (get_dbname (DB_HITS, module));
  ht_storage[module].metrics->visitors =
    tc_adb_create (get_dbname (DB_VISITORS, module));
  ht_storage[module].metrics->bw = tc_adb_create (get_dbname (DB_BW, module));
  ht_storage[module].metrics->time_served =
    tc_adb_create (get_dbname (DB_AVGTS, module));
  ht_storage[module].metrics->methods =
    tc_adb_create (get_dbname (DB_METHODS, module));
  ht_storage[module].metrics->protocols =
    tc_adb_create (get_dbname (DB_PROTOCOLS, module));
#ifdef TCB_MEMHASH
  ht_storage[module].metrics->agents =
    tc_adb_create (get_dbname (DB_AGENTS, module));
#endif
#ifdef TCB_BTREE
  /* allow for duplicate keys */
  ht_storage[module].metrics->agents = tc_bdb_create (DB_AGENTS, module);
#endif
}
Esempio n. 7
0
int read_config(EP_CONTEXT *c, char *fn)
{
    FILE *fp;
    char line[1024], err[256], key[1024], val[1024], db[256], mydb[256],
        *p, *keyp;
    int res, len, n = 0;
    unsigned int i;

    /* if we're testing, configure with hardcoded test values */
    if (c->testing) {
        strcpy(c->code_table, "test_user_perl_source");
        strcpy(c->bootstrap_file, ""); /* will be filled in later */
        strcpy(c->debug_dir, "/tmp");
        strcpy(c->inc_path, "");
        strcpy(c->trusted_dir, ""); /* will be filled in later */
        c->use_namespace = 1;
        c->tainting = 1;
        c->package_subs = 0;
        c->max_code_size = 32768;
        c->max_sub_args = 32;
        c->ddl_format = EP_DDL_FORMAT_STANDARD;
        c->reparse_subs = 0;
        return(1);
    }
    if (!(fp = fopen(fn, "r"))) {
        return(0);
    }

    /* get our database name */
    res = get_dbname(c, mydb);
    if (res != OCI_SUCCESS && res != OCI_SUCCESS_WITH_INFO) {
        ora_exception(c, "get_dbname");
        fclose(fp);
        return(0);
    }

    while(fgets(line, 1024, fp)) {
        n++;
        /* ignore comments and blank lines */
        if (line[0] == '#' || line[0] == '\n') {
            continue;
        }

        /* parse away */
        if ((p = strpbrk(line, " \t"))) {
            len = p-line;
            strncpy(key, line, len);
            key[len] = '\0';
            strncpy(val, p+1, 1024-len-1);
            /* get rid of newline */
            if ((p = strchr(val, '\n'))) {
                *p = '\0';
            }
        }
        else {
            snprintf(err, 255, "Bad configuration line %d\n", n);
            ora_exception(c, err);
            fclose(fp);
            return(0);
        }

        /* parse out database name, if any */
        if (keyp = index(key, ':')) {
            strncpy(db, key, keyp-key);
            /* skip if line doesn't apply to our database */
            if (strncasecmp(db, mydb, strlen(mydb))) {
                continue;
            }
            strncpy(key, keyp+1, strlen(key));
        }

        if (!strcmp(key, "code_table")) {
            strncpy(c->code_table, val, 255);
            continue;
        }
        if (!strcmp(key, "bootstrap_file")) {
            strncpy(c->bootstrap_file, val, MAXPATHLEN-1);
            continue;
        }
        if (!strcmp(key, "debug_directory")) {
            strncpy(c->debug_dir, val, MAXPATHLEN-1);
            continue;
        }
        if (!strcmp(key, "inc_path")) {
            strncpy(c->inc_path, val, 4095);
            continue;
        }
        if (!strcmp(key, "trusted_code_directory")) {
            strncpy(c->trusted_dir, val, MAXPATHLEN-1);
            continue;
        }
        if (!strcmp(key, "enable_session_namespace")) {
            c->use_namespace = YESORNO(val);
            continue;
        }
        if (!strcmp(key, "enable_tainting")) {
            c->tainting = YESORNO(val);
            continue;
        }
        if (!strcmp(key, "enable_package_subs")) {
            c->package_subs = YESORNO(val);
            continue;
        }
        if (!strcmp(key, "reparse_subs")) {
            c->reparse_subs = YESORNO(val);
            continue;
        }
        if (!strcmp(key, "ddl_format")) {
            if (!strncmp(val, "standard", 8)) {
                c->ddl_format = EP_DDL_FORMAT_STANDARD;
            }
            else if (!strncmp(val, "package", 7)) {
                c->ddl_format = EP_DDL_FORMAT_PACKAGE;
            }
            else {
                ora_exception(c, "illegal DDL format");
                fclose(fp);
                return(0);
            }
            continue;
        }
        if (!strcmp(key, "max_code_size")) {
            i = atoi(val);
            if (i < 1 || i > 0xffffffff) {
                snprintf(err, 255, "Illegal value for max_code_size: '%s'\n", val);
                ora_exception(c, err);
                fclose(fp);
                return(0);
            }
            c->max_code_size = (int)i;
            continue;
        }
        if (!strcmp(key, "max_sub_args")) {
            i = atoi(val);
            if (i < 0 || i > 128) {
                snprintf(err, 255, "Illegal value for max_sub_args: '%s'\n", val);
                ora_exception(c, err);
                fclose(fp);
                return(0);
            }
            c->max_sub_args = i;
            continue;
        }
    }

    fclose(fp);

    return(1);
}