예제 #1
0
/*
	associate a buffer with a guid and a key
	the old buffer will be freeed automatically.
*/
F8RES_API __bool set_res_buf_ex(
	const f8_uuid * id,
	const void * buffer,
	int length,
	const char * key,
	__bool bForce
	)
{
	F8_RESOURCE * res;
	F8_RESITEM * item;

	res = _get_res(id);
	if(!res && bForce){
		create_resource(id);		
		res = _get_res(id);
	}
	if(!res){
		assert(0);
		return __false;
	}
	item = _get_item(res, key);
	if(!item){
		item = _new_item(res, key);
	}

	if(!item){
		return __false;
	}
	
	if(length == -1){
		length = strlen((const char*)buffer) + 1;
	}

	if(item->buffer == buffer){
		item->length = length;
		return __true;
	}

	if(item->buffer){
		__free__(item->buffer);
	}

	if(length){
		item->buffer = __malloc__(length);
		item->length = length;
		if(!item->buffer){
			return __false;
		}
		memcpy(item->buffer, buffer, length);
	}else{
		item->buffer = 0;
		item->length = 0;
	}

	return __true;
}
예제 #2
0
static void _free_items(ITEMMAP * imap)
{
	ITEMMAP::iterator it;

	it = imap->begin();
	while(it != imap->end()){
		if(it->second.buffer){
			__free__(it->second.buffer);
		}
		it->second.buffer = 0;
		it++;
	}
}
예제 #3
0
KPROXY_API void kproxy_uninit()
{
	uninit_blklib();
	uninit_network();
	
	if(proxy_adapter){
		on_offline(0, 0);
		delete_adapter(proxy_adapter);
		proxy_adapter = 0;
	}
	if(x_buffer){
		__free__(x_buffer);
		x_buffer = 0;
	}
	
	ex_uninit();
}
예제 #4
0
F8RES_API __bool del_res_item(
	const f8_uuid * id, 
	const char * key
	)
{
	F8_RESOURCE * res;
	ITEMMAP::iterator it;

	res = _get_res(id);
	if(!res){
		return __false;
	}
	it = res->pItems->find(key);
	if(it == res->pItems->end()){
		return __false;
	}
	if(it->second.buffer){
		__free__(it->second.buffer);
	}
	res->pItems->erase(it);

	return __true;
}
예제 #5
0
/*
	construct a resource object in memory from a stream
	the stream is composed of:
	1) a magic
	2) uuid
	3) item count
	4) array of items

	NOTE!! 
	1) On success, the resource item is not reference counted. 
	If the client won't addref on the loaded resource, then the 
	item is exposed to the garbage collector.
	More exactly, this proc won't addref on the resource when
	the resource already exists.
*/
static F8_RESOURCE * _load_res_stream(IF8Stream * str)
{
	__u16	magic;
	RESMAP::iterator it;
	__u32 itemcount;
	c_bstr_t cbstr;
	f8_uuid id;
	__int	length;
	void	* buffer;
	F8_RESOURCE * res;
	__bool ret;

	// DEBUG_PRINTF(("stream %08x\n", __vcall__(str, tell, (str))));
	
	if(!__vcall__(str, get, (str, &magic, sizeof(magic)))){
		return 0;
	}

	if(magic != F8_RES_MAGIC && magic != F8_RES_MAGIC_2){
		__vcall__(str, seek, (str, -sizeof(magic), SEEK_CUR));
		return 0;
	}

	if(!__vcall__(str, get, (str, &id, sizeof(id)))){
		return 0;
	}

	res = create_resource_bibibobo(&id, __false);
	if(!res){
		return 0;
	}
	
	/* the resource has not been loaded yet */
	if(!__vcall__(str, get, (str, &itemcount, sizeof(itemcount)))){
		return 0;
	}

	if(res->refcount){
		/* note if the resource is already present we silently
		eat the stream without modifing the in-memory version
		*/
		for(; itemcount; itemcount--){
			if(!__vcall__(str, get, (str, &cbstr.count, sizeof(cbstr.count)))){
				goto __failed;
			}
			__vcall__(str, seek, (str, cbstr.count, SEEK_CUR));
			if(!__vcall__(str, get, (str, &length, sizeof(length)))){
				goto __failed;
			}
			__vcall__(str, seek, (str, length, SEEK_CUR));
		}	
	}else{
		for(; itemcount; itemcount--){	
			if(!bstr_from_stream(&cbstr, str)){
				goto __failed;
			}

			if(!__vcall__(str, get, (str, &length, sizeof(length)))){
				goto __failed;
			}
			if(length){
				buffer = __malloc__(length);
				if(!buffer){
					goto __failed;
				}
				if(!__vcall__(str, get, (str, buffer, length))){
					goto __failed;
				}
			}else{
				buffer = 0;
			}
			
			ret = set_res_buf(&id, buffer, length, cbstr.buffer);
			__free__(buffer);
			c_free_bstr(&cbstr);
			if(!ret){
				goto __failed;
			}
		}
	}
	return res;	

__failed:
	/* the unload_resource will decrease the refcount */
	res->refcount++;
	unload_resource(&id);
	
	return 0;
}
예제 #6
0
void _free_()
{
        __free__();
}
예제 #7
0
파일: bstr.c 프로젝트: george-kuo/GoSysWare
LIBCOBJ_API void c_free_str(char * s)
{
	__free__(s);
}