Example #1
0
/**
 * Call killVM(void *data, const char *name, const void * value) to each JVMs.<br>
 * prev = java_close_service()<br>
 * next = none.<br>
 *
 * @see java_close_service()
 */
void release_java_handler() {
    //iterate and kill all JavaVMs
    ci_dyn_array_iterate(environments, NULL, killVM);

    ci_dyn_array_destroy(environments);
    return;
}
Example #2
0
void *ldap_table_open(struct ci_lookup_table *table)
{
    int i;
    char *path;
    char tname[1024];
    struct ldap_table_data *ldapdata;
    ci_dyn_array_t *args = NULL;
    ci_array_item_t *arg = NULL;
    char *use_cache = "local";
    int cache_ttl = 60;
    size_t cache_size = 1*1024*1024;
    size_t cache_item_size = 2048;
    long int val;

    path = strdup(table->path);
    if (!path) {
        ci_debug_printf(1, "ldap_table_open: error allocating memory!\n");
        return NULL;
    }

    ldapdata = malloc(sizeof(struct ldap_table_data));
    if(!ldapdata) {
        free(path);
        ci_debug_printf(1, "ldap_table_open: error allocating memory (ldapdata)!\n");
        return NULL;
    }
    ldapdata->str = path;
    ldapdata->pool = NULL;
    ldapdata->base = NULL;
    ldapdata->server = NULL;
    ldapdata->port = 389;
    ldapdata->user = NULL;
    ldapdata->password = NULL;
    ldapdata->attrs = NULL;
    ldapdata->filter = NULL;
    ldapdata->name = NULL;

    if(!parse_ldap_str(ldapdata)) {
        free(ldapdata->str);
        free(ldapdata);
        ci_debug_printf(1, "ldap_table_open: parse path string error!\n");
        return NULL;
    }

    if (table->args) {
        if ((args = ci_parse_key_value_list(table->args, ','))) {
            for (i = 0; (arg = ci_dyn_array_get_item(args, i)) != NULL; ++i) {
                ci_debug_printf(5, "Table argument %s:%s\n", arg->name, (char *)arg->value);
                if(strcasecmp(arg->name, "name") == 0) {
                    ldapdata->name = strdup((char *)arg->value);
                } else if(strcasecmp(arg->name, "cache") == 0) {
                    if (strcasecmp((char *)arg->value, "no") == 0)
                        use_cache = NULL;
                    else
                        use_cache = (char *)arg->value;
                } else if (strcasecmp(arg->name, "cache-ttl") == 0) {
                    val = strtol((char *)arg->value, NULL, 10);
                    if (val > 0)
                        cache_ttl = val;
                    else
                        ci_debug_printf(1, "WARNING: wrong cache-ttl value: %ld, using default\n", val);
                } else if (strcasecmp(arg->name, "cache-size") == 0) {
                    val = ci_atol_ext((char *)arg->value, NULL);
                    if (val > 0)
                        cache_size = (size_t)val;
                    else
                        ci_debug_printf(1, "WARNING: wrong cache-size value: %ld, using default\n", val);
                } else if (strcasecmp(arg->name, "cache-item-size") == 0) {
                    val = ci_atol_ext((char *)arg->value, NULL);
                    if (val > 0)
                        cache_item_size = (size_t)val;
                    else
                        ci_debug_printf(1, "WARNING: wrong cache-item-size value: %ld, using default\n", val);
                }
            }
        }
    }

    ldapdata->pool = ldap_pool_create(ldapdata->server, ldapdata->port,
                                      ldapdata->user, ldapdata->password);
    if (use_cache) {
        snprintf(tname, sizeof(tname), "ldap:%s", ldapdata->name ? ldapdata->name : ldapdata->str);
        tname[sizeof(tname) - 1] = '\0';
        ldapdata->cache = ci_cache_build(tname, use_cache,
                                         cache_size, cache_item_size, cache_ttl,
                                         &ci_str_ops);
        if(!ldapdata->cache) {
            ci_debug_printf(1, "ldap_table_open: can not create cache! cache is disabled");
        }
    } else
        ldapdata->cache = NULL;

    table->data = ldapdata;

    /*Must released before exit, we have pointes pointing on args array items*/
    if (args)
        ci_dyn_array_destroy(args);
    return table->data;
}