Exemplo n.º 1
0
BOOL CFileVersionInfo::QueryStringValue( IN  LPCTSTR lpszItem,
										 OUT LPTSTR  lpszValue, 
										 IN  INT     nBuf ) const
{
	if( m_bValid  == FALSE || lpszItem == NULL )
		ASSERT_RETURN( FALSE );
	
	if( lpszValue != NULL && nBuf <= 0 )
		ASSERT_RETURN( FALSE );

	::ZeroMemory( lpszValue, nBuf * sizeof( TCHAR ) );

	TCHAR szSFI[ MAX_PATH ] = { 0 };
	::wsprintf( szSFI, _T( "\\StringFileInfo\\%04X%04X\\%s" ), 
		GetCurLID(), GetCurCP(), lpszItem );

	BOOL   bRes    = FALSE;
	UINT   uLen    = 0;
	LPTSTR lpszBuf = NULL;

	if( ::VerQueryValue( m_lpbyVIB, (LPTSTR)szSFI, (LPVOID*)&lpszBuf, &uLen ) )
	{
		if( lpszValue != NULL && nBuf > 0 )
			bRes = (BOOL)( ::lstrcpyn( lpszValue, lpszBuf, nBuf ) != NULL );
		else
			bRes = TRUE;
	}
	
	return ( bRes );
}
Exemplo n.º 2
0
int kdbus_test_sync_reply(struct kdbus_test_env *env)
{
	pthread_t thread;
	int ret;

	conn_a = kdbus_hello(env->buspath, 0, NULL, 0);
	conn_b = kdbus_hello(env->buspath, 0, NULL, 0);
	ASSERT_RETURN(conn_a && conn_b);

	pthread_create(&thread, NULL, run_thread, NULL);

	ret = kdbus_msg_send(conn_b, NULL, cookie,
			     KDBUS_MSG_FLAGS_EXPECT_REPLY |
			     KDBUS_MSG_FLAGS_SYNC_REPLY,
			     5000000000ULL, 0, conn_a->id);

	pthread_join(thread, NULL);
	ASSERT_RETURN(ret == 0);

	kdbus_printf("-- closing bus connections\n");
	kdbus_conn_free(conn_a);
	kdbus_conn_free(conn_b);

	return TEST_OK;
}
Exemplo n.º 3
0
	bool KBagManager::AddOneCell( const SC_BagAddResponse* pBAR )
	{
		ASSERT_RETURN(pBAR, false);
		int nBagID = pBAR->byteBagID;
		KBag* pBag = FindBag(nBagID);
		ASSERT_RETURN(pBag, false);
		
		KItem item;
		item.Clear();
		KMsgInputStream si(pBAR->GetItemBuffer(), pBAR->nItemBufferSize);
		if(!item.Unserilize(si))
		{
			return false;
		}
		if(!pBag->AddOneCell(pBAR->nPos, item))
		{
			return false;
		}
		
		pBag->NumChange(item.GetID(), item.GetStackNumber());

		// 通知界面
		int nBoxID = BagId2BoxID(nBagID);
		ASSERT_RETURN(-1 != nBoxID, false);
		KItemBlock* pIB = KItemBlock::Alloc();
		pIB->SetPos(nBoxID, pBAR->nPos);
		KBlockBoxManager::Instance()->PutBlock(nBoxID, pBAR->nPos, pIB);

		if (nBagID == enum_item_BagNormal)
		{
			KDynamicWorld::getSingleton().SendWorldMsg(LOGIC_WORLD_NORMAL_BAG_ITEM_CHANGE, item.GetID(), 0);
		}

		return true;
	}
Exemplo n.º 4
0
	bool KBagManager::IsValidCell( int nBoxId, int nPos ) const
	{
		int nBagId = BoxID2BagID(nBoxId);
		ASSERT_RETURN(nBagId >= enum_item_Bag_Start, false);
		const KBag* pBag = FindBag(nBagId);
		ASSERT_RETURN(pBag, false);
		return pBag->IsPosValid(nPos);
	}
Exemplo n.º 5
0
	int KBagManager::GetItemPosition(int nBoxId, DWORD dwItemID) const
	{
		int nBagId = BoxID2BagID(nBoxId);
		ASSERT_RETURN(nBagId >= enum_item_Bag_Start, -1);

		const KBag* pBag = FindBag(nBagId);
		ASSERT_RETURN(pBag, -1);
		return pBag->GetFirstPos(dwItemID);
	}
Exemplo n.º 6
0
	int KBagManager::GetItemCountByID( DWORD dwItemID ) const
	{
		ASSERT_RETURN(dwItemID > 0, 0);
		const KCreateInfo_ItemBase* pCIIB = GetItemCreateInfo(dwItemID);
		ASSERT_RETURN(pCIIB, 0);
		int nBag = GetBagTypeByItemType(pCIIB->GetItemType());
		ASSERT_RETURN(nBag >= 0, 0);
		return GetItemCountByID(nBag, dwItemID);
	}
Exemplo n.º 7
0
int kdbus_test_fd_passing(struct kdbus_test_env *env)
{
	struct kdbus_conn *conn_src, *conn_dst;
	const char *str = "stackenblocken";
	const struct kdbus_item *item;
	struct kdbus_msg *msg;
	unsigned int i;
	int fds[2];
	int ret;

	/* create two connections */
	conn_src = kdbus_hello(env->buspath, 0, NULL, 0);
	conn_dst = kdbus_hello(env->buspath, 0, NULL, 0);
	ASSERT_RETURN(conn_src && conn_dst);

	/*
	 * Try to ass the handle of a connection as message payload.
	 * This must fail.
	 */
	ret = send_fd(conn_src, conn_dst->id, conn_src->fd);
	ASSERT_RETURN(ret == -ELOOP);

	ret = send_fd(conn_src, conn_dst->id, conn_dst->fd);
	ASSERT_RETURN(ret == -ELOOP);

	ret = pipe(fds);
	ASSERT_RETURN(ret == 0);

	i = write(fds[1], str, strlen(str));
	ASSERT_RETURN(i == strlen(str));

	ret = send_fd(conn_src, conn_dst->id, fds[0]);
	ASSERT_RETURN(ret == 0);

	ret = kdbus_msg_recv(conn_dst, &msg);
	ASSERT_RETURN(ret == 0);

	KDBUS_ITEM_FOREACH(item, msg, items) {
		if (item->type == KDBUS_ITEM_FDS) {
			char tmp[14];
			int nfds = (item->size - KDBUS_ITEM_HEADER_SIZE) /
					sizeof(int);

			ASSERT_RETURN(nfds == 1);

			i = read(item->fds[0], tmp, sizeof(tmp));
			ASSERT_RETURN(i == sizeof(tmp));
			ASSERT_RETURN(memcmp(tmp, str, sizeof(tmp)) == 0);

			close(item->fds[0]);
			break;
		}
	}

	return TEST_OK;
}
Exemplo n.º 8
0
	bool KL2Map_Base::_InsertJointToBlock(const _Node_Lite * pNode)
	{	PERF_COUNTER(KL2Map_Base__InsertJointToBlock);

		ASSERT_RETURN(pNode, false);
		int_r bx(-1), by(-1);
		GetJointBlockPos(pNode->x, pNode->y, bx, by);
		ASSERT_RETURN(bx >= 0, false);
		ASSERT_RETURN(by >= 0, false);
		return m_L2MapByBlock[bx][by].insert_unique(pNode) > -1;
	}
Exemplo n.º 9
0
static int unpriv_test_custom_ep(const char *buspath)
{
	int ret, ep_fd1, ep_fd2;
	char *ep1, *ep2, *tmp1, *tmp2;

	tmp1 = strdup(buspath);
	tmp2 = strdup(buspath);
	ASSERT_RETURN(tmp1 && tmp2);

	ret = asprintf(&ep1, "%s/%u-%s", dirname(tmp1), getuid(), "apps1");
	ASSERT_RETURN(ret >= 0);

	ret = asprintf(&ep2, "%s/%u-%s", dirname(tmp2), getuid(), "apps2");
	ASSERT_RETURN(ret >= 0);

	free(tmp1);
	free(tmp2);

	/* endpoint only accessible to current uid */
	ep_fd1 = create_endpoint(buspath, getuid(), "apps1", 0);
	ASSERT_RETURN(ep_fd1 >= 0);

	/* endpoint world accessible */
	ep_fd2 = create_endpoint(buspath, getuid(), "apps2",
				  KDBUS_MAKE_ACCESS_WORLD);
	ASSERT_RETURN(ep_fd2 >= 0);

	ret = RUN_UNPRIVILEGED(UNPRIV_UID, UNPRIV_UID, ({
		int ep_fd;
		struct kdbus_conn *ep_conn;

		/*
		 * Make sure that we are not able to create custom
		 * endpoints
		 */
		ep_fd = create_endpoint(buspath, getuid(),
					"unpriv_costum_ep", 0);
		ASSERT_EXIT(ep_fd == -EPERM);

		/*
		 * Endpoint "apps1" only accessible to same users,
		 * that own the endpoint. Access denied by VFS
		 */
		ep_conn = kdbus_hello(ep1, 0, NULL, 0);
		ASSERT_EXIT(!ep_conn && errno == EACCES);

		/* Endpoint "apps2" world accessible */
		ep_conn = kdbus_hello(ep2, 0, NULL, 0);
		ASSERT_EXIT(ep_conn);

		kdbus_conn_free(ep_conn);

		_exit(EXIT_SUCCESS);
	}),
Exemplo n.º 10
0
	bool KBagManager::UpdateCellLock(const SC_BagCellUpdateLock* pBCUL)
	{
		ASSERT_RETURN(pBCUL, false);

		KCellBag* pCell = FindCell(pBCUL->byteBagID, pBCUL->nPos);
		ASSERT_RETURN(pCell, false);

		pCell->SetLock(pBCUL->nLockType);
		
		// TODO: 通知UI
		return true;
	}
Exemplo n.º 11
0
static int kdbus_match_kdbus_pids(struct kdbus_msg *msg,
				  const struct kdbus_pids *expected_pids)
{
	struct kdbus_item *item;

	item = kdbus_get_item(msg, KDBUS_ITEM_PIDS);
	ASSERT_RETURN(item);

	ASSERT_RETURN(memcmp(&item->pids, expected_pids,
			     sizeof(struct kdbus_pids)) == 0);

	return 0;
}
Exemplo n.º 12
0
	int KBagManager::GetFrequency( int nBoxId, int nPos ) const
	{
		int nBagId = BoxID2BagID(nBoxId);
		ASSERT_RETURN(nBagId >= enum_item_Bag_Start, 0);
		const KBag* pBag = FindBag(nBagId);
		ASSERT_RETURN(pBag, 0);
		const KCellBag* pCell = pBag->FindCell(nPos);
		if(NULL == pCell)
		{
			return 0;
		}
		const KItem& item = pCell->GetItem();
		return item.GetFrequency();
	}
Exemplo n.º 13
0
std::vector<std::wstring> NppInterface::GetOpenFilenames(ViewTarget viewTarget) const {
	int enumVal = -1;

	switch (viewTarget) {
	case ViewTarget::primary:
		enumVal = PRIMARY_VIEW;
		break;
	case ViewTarget::secondary:
		enumVal = SECOND_VIEW;
		break;
	case ViewTarget::both:
		enumVal = ALL_OPEN_FILES;
		break;
	}

	ASSERT_RETURN(enumVal >= 0, {});
	int count = SendMsgToNpp(NPPM_GETNBOPENFILES, 0, enumVal);

	wchar_t** paths;
	paths = new wchar_t *[count];
	for (int i = 0; i < count; ++i)
		paths[i] = new wchar_t[MAX_PATH];

	int msg = -1;
	switch (viewTarget) {
	case ViewTarget::primary:
		msg = NPPM_GETOPENFILENAMESPRIMARY;
		break;
	case ViewTarget::secondary:
		msg = NPPM_GETOPENFILENAMESSECOND;
		break;
	case ViewTarget::both:
		msg = NPPM_GETOPENFILENAMES;
		break;
	}

	ASSERT_RETURN(msg >= 0, {}); {
		auto ret = SendMsgToNpp(msg, reinterpret_cast<WPARAM>(paths), count);
		ASSERT_RETURN(ret == count, {});
	}

	std::vector<std::wstring> res;
	for (int i = 0; i < count; ++i) {
		res.push_back(paths[i]);
		delete[] paths[i];
	}
	delete[] paths;
	return res;
}
Exemplo n.º 14
0
	const KCreateInfo_ItemBase* KBagManager::GetOneItemCreateInfoBase( int nBagID, DWORD dwItemID )
	{
		const KBag* pBag = FindBag(nBagID);
		ASSERT_RETURN(pBag, NULL);

		int nPos = pBag->GetFirstPos(dwItemID);
		ASSERT_RETURN(nPos >= 0, NULL);
		
		const KCellBag* pCell = pBag->FindCell(nPos);
		ASSERT_RETURN(pCell, NULL);
		const KItem& item = pCell->GetItem();

		ASSERT_I(item.GetID() == dwItemID);
		return GetItemCreateInfo(dwItemID);
	}
Exemplo n.º 15
0
	bool KBagManager::_AddBagList(KBag* pAddBag)
	{
		ASSERT_RETURN(pAddBag, false);
		int nBagID = pAddBag->GetBagID();
		ASSERT_RETURN(nBagID >= 0, false);

		KBag* pFindBag = FindBag(nBagID);
		if(NULL == pFindBag)
		{
			m_listBag[nBagID] = pAddBag;
			return true;
		}

		return false;
	}
Exemplo n.º 16
0
	bool KStoreProduct::AddProductPrice(int nMoneyType, int nTParam1, int nTParam2)
	{
		ASSERT_RETURN(nMoneyType > enumPT_none && nMoneyType < enumPT_count, false);

		KStoreProductPrice price;
		price.nMoneyType = nMoneyType;
		price.nTParam1 = nTParam1;
		price.nTParam2 = nTParam2;
		int i = 0;
		for(i=0;i<sizeof(m_Prices)/sizeof(m_Prices[0]);i++)
		{
			if(enumPT_none == m_Prices[i].nMoneyType) break;
			if(m_Prices[i].nMoneyType == nMoneyType) return false;
		}

		if(i < PRICE_TYPE_MAX)
		{
			m_Prices[i].nMoneyType = nMoneyType;
			m_Prices[i].nTParam1 = nTParam1;
			m_Prices[i].nTParam2 = nTParam2;
			return true;
		}

		return false;
	}
void CGraphicWindowChildFrame::moveForward()
{
	ASSERT_RETURN( forwardTabCount() > 0 );
	int newTab = m_forwardTabList[forwardTabCount()];
	m_forwardTabList.remove(forwardTabCount());
	SetTab( newTab );
}
Exemplo n.º 18
0
	int KBagManager::GetCount(int nBagID, int nPos) const
	{
		const KCellBag* pCell = FindCell(nBagID, nPos);
		ASSERT_RETURN(pCell, 0);

		return pCell->GetItemStackNumber();
	}
Exemplo n.º 19
0
Arquivo: iptc.c Projeto: Limsik/e17
Enlil_IPTC_Job *
enlil_iptc_job_prepend(Enlil_Photo       *photo,
                       Enlil_IPTC_Done_Cb cb,
                       void              *data)
{
   ASSERT_RETURN(photo != NULL);
   Eina_List *l;
   Enlil_IPTC_Job *job;

   EINA_LIST_FOREACH(l_jobs, l, job)
     if(job->photo == photo)
       break;

   if(!job)
     {
        job = calloc(1, sizeof(Enlil_IPTC_Job));
        job->photo = photo;
        job->cb = cb;
        job->data = data;
     }
   else
     l_jobs = eina_list_remove(l_jobs, job);

   l_jobs = eina_list_prepend(l_jobs, job);

   _job_next();

   return job;
}
Exemplo n.º 20
0
	int KBagManager::GetItemCountByID(int nBagID, DWORD dwItemID) const
	{
		const KBag* pBag = FindBag(nBagID);
		ASSERT_RETURN(pBag, 0);
		
		return pBag->GetItemSize(dwItemID);
	}
Exemplo n.º 21
0
MemoryPool* initPool(size_t size, size_t increment)
{
	MemoryPool *pool;
	MemoryBlock *block;
	void *buffer;

	ASSERT_RETURN(size >= sizeof(MemoryPool)+sizeof(MemoryBlock), NULL);

	buffer=malloc(size+sizeof(*pool)+sizeof(*block));
	if (!buffer)
		return NULL;

	// Initialize first memory block
	block = (MemoryBlock*) ((size_t)buffer+sizeof(*pool));
	block->next = NULL;
	block->start=(void*)((size_t)block+sizeof(*block));
	block->pos=ALIGN_PTR(block->start, POOL_ALIGNMENT);
	block->end=block->start+size;

	// Initialize pool
	pool = (MemoryPool*) buffer;
	pool->lastAlloc = 0;
	pool->capacity = size;
	pool->increment = (increment) ? increment : (size_t)sysconf(_SC_PAGESIZE);
	pool->base=block;
	pool->cur=block;

	PRINT("Pool created, used size=%ld, capacity=%ld, increment size=%ld", (((size_t)(pool->cur->start)) - (size_t)pool), pool->capacity, pool->increment);

	return pool;
}
Exemplo n.º 22
0
Arquivo: tag.c Projeto: Limsik/e17
int
enlil_tag_photos_count_get(const Enlil_Tag *tag)
{
   ASSERT_RETURN(tag != NULL);

   return eina_list_count(tag->photos);
}
Exemplo n.º 23
0
bool SocketAddress::setIntern(Exception& ex,const string& hostAndPort,bool resolveHost) {
	ASSERT_RETURN(!hostAndPort.empty(),false);

	string host, port;
	auto it  = hostAndPort.begin();
	auto& end = hostAndPort.end();
	if (*it == '[') {
		++it;
		while (it != end && *it != ']')
			host += *it++;
		if (it == end) {
			ex.set(Exception::NETADDRESS,"Malformed IPv6 address ", hostAndPort);
			return false;
		}
		++it;
	} else {
		while (it != end && *it != ':')
			host += *it++;
	}
	if (it != end && *it == ':') {
		++it;
		while (it != end)
			port += *it++;
	}
	else {
		ex.set(Exception::NETADDRESS, "Missing port number in ", hostAndPort);
		return false;
	}
	return setIntern(ex,host, resolveService(ex,port),resolveHost);
}
Exemplo n.º 24
0
	const KBagQuest* KBagManager::FindQuestBag() const
	{
		const KBag* pBag = FindBag(enum_item_BagQuest);
		ASSERT_RETURN(pBag, NULL);
		const KBagQuest* pBagQuest = dynamic_cast<const KBagQuest*>(pBag);
		return pBagQuest;
	}
Exemplo n.º 25
0
BOOL CFileVersionInfo::GetCPName( IN  WORD	   wCP,
								  OUT LPCTSTR* ppszName )
{
	if( ppszName == NULL )
		ASSERT_RETURN( FALSE );

	BOOL bRes = TRUE;	
	*ppszName  = NULL;

	switch ( wCP )
	{
		case VI_CP_ASCII:	 *ppszName = _T( "7-bit ASCII" );				break;
		case VI_CP_JAPAN:	 *ppszName = _T( "Japan (Shift – JIS X-0208)" );break;
		case VI_CP_KOREA:	 *ppszName = _T( "Korea (Shift – KSC 5601)" );	break;
		case VI_CP_TAIWAN:	 *ppszName = _T( "Taiwan (Big5)" );				break;
		case VI_CP_UNICODE:	 *ppszName = _T( "Unicode" );					break;
		case VI_CP_LATIN2:	 *ppszName = _T( "Latin-2 (Eastern European)" );break;
		case VI_CP_CYRILLIC: *ppszName = _T( "Cyrillic" );					break;
		case VI_CP_MULTILNG: *ppszName = _T( "Multilingual" );				break;
		case VI_CP_GREEK:	 *ppszName = _T( "Greek" );						break;
		case VI_CP_TURKISH:	 *ppszName = _T( "Turkish" );					break;
		case VI_CP_HEBREW:	 *ppszName = _T( "Hebrew" );					break;
		case VI_CP_ARABIC:	 *ppszName = _T( "Arabic" );					break;		
		default:			 *ppszName = _T( "Unknown" ); bRes = FALSE;		break;
	}
	return bRes;
}
Exemplo n.º 26
0
	const KBagNormal* KBagManager::FindNormalBag() const
	{
		const KBag* pBag = FindBag(enum_item_BagNormal);
		ASSERT_RETURN(pBag, NULL);
		const KBagNormal* pBagNormal = dynamic_cast<const KBagNormal*>(pBag);
		return pBagNormal;
	}
Exemplo n.º 27
0
DWORD CFileVersionInfo::GetTransByIndex( IN UINT nIndex ) const
{
	if( m_bValid == FALSE || nIndex < 0 || nIndex > m_nTransCnt )
		ASSERT_RETURN( 0 );

	return m_lpdwTrans[ nIndex ];
}
int pthread_attr_setinheritsched(pthread_attr_t *attr, int h)
{
  ASSERT_RETURN(!attr,EINVAL);

  attr->schedinherited = h;
  return 0;
}
Exemplo n.º 29
0
/*
 * Return: TEST_OK, TEST_ERR or TEST_SKIP
 * we return TEST_OK only if the children return with the expected
 * 'expected_status' that is specified as an argument.
 */
static int kdbus_fork_test(const char *bus, const char *name,
			   struct kdbus_conn **conn_db, int expected_status)
{
	pid_t pid;
	int ret = 0;
	int status = 0;

	pid = fork();
	ASSERT_RETURN_VAL(pid >= 0, pid);

	if (pid == 0) {
		ret = prctl(PR_SET_PDEATHSIG, SIGKILL);
		ASSERT_EXIT(ret == 0);

		ret = drop_privileges(65534, 65534);
		ASSERT_EXIT(ret == 0);

		ret = kdbus_recv_in_threads(bus, name, conn_db);
		_exit(ret == expected_status ? EXIT_SUCCESS : EXIT_FAILURE);
	}

	ret = waitpid(pid, &status, 0);
	ASSERT_RETURN(ret >= 0);

	return (status == EXIT_SUCCESS) ? TEST_OK : TEST_ERR;
}
void CGraphicsRigidDiaphragmLoad::translate( const CRigidDiaphragmLoad* pRDL, float length )
{
	double dLoc[3];
	const CNode* pN = pRDL->location();
	ASSERT_RETURN( pN );
	
	dLoc[0] = m_loc[0] = pN->x();
	dLoc[1] = m_loc[1] = pN->y();
	dLoc[2] = m_loc[2] = pN->z();

	glMatrixMode( GL_MODELVIEW );
	//glPushMatrix();
	glTranslatef( (float)m_loc.x, (float)m_loc.y, (float)m_loc.z );

	if( !zero( pRDL->magnitude( DX ) ) ){
		//draw x dir arrow
	}
	else if( !zero( pRDL->magnitude( DY ) ) ){
		//draw y dir arrow
		glRotatef( 90.f, 0.f, 0.f, 1.f );
	}
	else if( !zero( pRDL->magnitude( DZ ) ) ){
		//draw z dir arrow
		glRotatef( -90.f, 0.f, 1.f, 0.f );
	}
	glTranslatef( length, 0.f, 0.f );
	//glGetDoublev( GL_MODELVIEW_MATRIX, m_mv );
	//glPopMatrix();

	return;
}