Logo Search packages:      
Sourcecode: jabberd2 version File versions  Download package

storage_t storage_new ( sm_t  sm  ) 

allocate a storage manager instance

Definition at line 100 of file storage.c.

References config_elem_st::attrs, sm_st::config, storage_st::drivers, config_elem_st::nvalues, storage_st::sm, st_SUCCESS, storage_add_type(), storage_st::types, and config_elem_st::values.

                               {
    storage_t st;
    int i, j;
    config_elem_t elem;
    char *type;
    st_ret_t ret;

    st = (storage_t) malloc(sizeof(struct storage_st));
    memset(st, 0, sizeof(struct storage_st));

    st->sm = sm;
    st->drivers = xhash_new(101);
    st->types = xhash_new(101);

    /* register types declared in the config file */
    elem = config_get(sm->config, "storage.driver");
    if(elem != NULL) {
        for(i = 0; i < elem->nvalues; i++) {
            type = j_attr((const char **) elem->attrs[i], "type"); 
            for(j = 0; st_driver_names[j] != NULL; j++) {
                if(strcmp(elem->values[i], st_driver_names[j]) == 0) {
                    if(type == NULL)
                        ret = storage_add_type(st, st_driver_names[j], NULL);
                    else
                        ret = storage_add_type(st, st_driver_names[j], type);
                    /* Initialisation of storage type failed */
                    if (ret != st_SUCCESS) {
                      free(st);
                      return NULL;
                    }
                }
            }
        }
    }

    return st;
}


Generated by  Doxygen 1.6.0   Back to index