Exemple #1
0
dynamic_page dynamic_new(const char* uri, PAGE_FUNCTION handler, page_attribute a)
{
	dynamic_page p;

	if( (p = malloc(sizeof *p)) != NULL) {
		p->handler = handler;
		p->attr = NULL;
		if( (p->uri = cstring_dup(uri)) == NULL) {
			free(p);
			p = NULL;
		}
		else if(a != NULL && (p->attr = attribute_dup(a)) == NULL) {
			cstring_free(p->uri);
			free(p);
			p = NULL;
		}
	}

	return p;
}
Exemple #2
0
/*bind home_dir and name node, i.e., one name node owns unique home dir*/
EC_BOOL chfsnp_mgr_bind(CHFSNP_MGR *chfsnp_mgr, const CSTRING *path, const UINT32 chfsnp_id)
{
    CSTRING *home_dir;
    CSTRING *home_dir_old;
    uint32_t home_dir_pos;

    ASSERT(cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr)) == CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr));
    if(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) <= chfsnp_id)
    {
        sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: max np num %u but chfsnp id %u overflow\n", CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr), chfsnp_id);
        return (EC_FALSE);
    }

    home_dir_pos = __chfsnp_mgr_get_np_id_of_path(chfsnp_mgr, (uint32_t)cstring_get_len(path), cstring_get_str(path));
    if(CHFSNP_ERR_ID != home_dir_pos)
    {
        home_dir = cvector_get_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), home_dir_pos);
        sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: some dir %s already bound to np %u, thus cannot accept binding %s\n", 
                            (char *)cstring_get_str(home_dir), home_dir_pos, (char *)cstring_get_str(path));
        return (EC_FALSE);
    }    

    home_dir = cstring_dup(path);
    if(NULL_PTR == home_dir)
    {
        sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: dup %s failed\n", (char *)cstring_get_str(path));
        return (EC_FALSE);
    }

    home_dir_old = (CSTRING *)cvector_set(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), chfsnp_id, (void *)home_dir);
    if(NULL_PTR != home_dir_old)
    {
        cstring_free(home_dir_old);
    }
    return (EC_TRUE);
}