Пример #1
0
AMVoid			IAccountModel_RemoveAccount(IAccountModel *pAcntModel, const AMChar *szAcntId, AMBool bDelete)
{
	AIMAccount	*pAcntFind = AMNULL;
	AMInt32		rcSqlite = 0;
	sqlite3		*pDB = AMNULL;
	AMChar		*szErrMsg = AMNULL;
	AMChar	*	szSql = AMNULL;
	AMInt64		i64Rid = 0;

	AMAssert(0 != pAcntModel && AMNULL != szAcntId);

	pAcntFind = IAccountModel_findHistoryAcnt(pAcntModel, szAcntId);

	if(!pAcntFind)
		return;

	i64Rid = pAcntFind->_iRid;

	delete_List(&pAcntModel->listAcnt, pAcntFind, sizeof(AIMAccount));

	IAccountModel_MarkDirt(pAcntModel);

	szSql = sqlite3_mprintf(SQL_DELETE_ACNT, i64Rid);

	if(!szSql)
		return;	//malloc error

	rcSqlite = myADB_Open(IM_ACNT_DB, &pDB, AMFALSE);

	if(rcSqlite)
	{
		DPRINT("AMIMAcntModel: Can't open database: %s\n", sqlite3_errmsg(pDB));
		sqlite3_free(szSql);
		sqlite3_close(pDB);
		return;
	}

	rcSqlite = sqlite3_exec(pDB, szSql, 0, 0, &szErrMsg);

	sqlite3_free(szSql);

	if( rcSqlite != SQLITE_OK )
	{
		DPRINT("AMIMAcntModel: Can't DELETE!\n");
		sqlite3_free(szErrMsg);
		sqlite3_close(pDB);
		return;
	}

	sqlite3_close(pDB);

	IAccountModel_ClearDirt(pAcntModel);

	if(AMTRUE == bDelete)		//需要放到前面。 前面退出的情况,不应该影响删除数据的操作吧
	{
		//删除帐号数据库
	}
}
Пример #2
0
Файл: path.c Проект: kaiaie/bile
/** Removes "." and ".." from a path */
char *getCanonicalPath(const char *path){
	char   *prefix = NULL;
	char   *rest   = NULL;
	char   *tmp    = NULL;
	size_t offset  = 0;
	char   **src   = NULL;
	List   *dst    = NULL;
	size_t ii = 0;
	Buffer *buf    = NULL;
	char   *result = NULL;
	
	if (path != NULL && strlen(path) > 0) {
		tmp = strxreplace(astrcpy(path), '\\', '/');
		if (isDosPath(tmp) || isUncPath(tmp)) {
			if (isDosPath(tmp)) {
				prefix = getPathPart(tmp, PATH_DRIVE);
				offset = 0;
			}
			else if (isUncPath(tmp)) {
				prefix = getPathPart(tmp, PATH_HOST);
				offset = 2;
			}
			rest = astrcpy(strchr(&tmp[offset], '/'));
		}
		else {
			rest = astrcpy(tmp);
		}
		src = astrtok(rest, "/");
		dst = new_List();
		while (src[ii] != NULL) {
			if (strxequals(src[ii], "..")) {
				List_remove(dst, -1, false);
			}
			else if (!strxequals(src[ii], ".")) {
				List_append(dst, src[ii]);
			}
			ii++;
		}
		buf = new_Buffer(0);
		if (prefix != NULL) {
			Buffer_appendString(buf, prefix);
		}
		for (ii = 0; ii < List_length(dst); ++ii) {
			Buffer_appendString(buf, List_get(dst, ii));
			if (ii != (List_length(dst) - 1)) {
				Buffer_appendChar(buf, '/');
			}
		}
		result = astrcpy(buf->data);
		delete_Buffer(buf);
		delete_List(dst, false);
		astrtokfree(src);
		mu_free(prefix);
		mu_free(rest);
		mu_free(tmp);
	}
	return result;
}
Пример #3
0
void delete_Hash(Hash H){
	unsigned int i;
	assert(H);

	for (i = 0; i < H->length; ++i)
		delete_List(H->lists[i]);

	free(H->lists);
	free(H);
}
Пример #4
0
IMnetRetCode AIMAuthModule_onRspCheckCode(IMnetHandle hIMnetHandle, EventContent* pEventContent)
{
	IAIM *pIM = (IAIM *)IMnetGetReference(hIMnetHandle);
	AIMAuthModule *pAuthModule = AMNULL;
	ImRspCheckAuthCode *pCheckAuth = (ImRspCheckAuthCode *)pEventContent;
	AIMAuth *pAuthFind = AMNULL;
	AMChar *szImgData = AMNULL, *szSession = 0;
	AMInt32 iImgLen = 0, iRetCode = eAIM_RESULT_OK;
	AIM_RSP_CHECK_CODE rspCheckCode;

	AMAssert(pIM);
	pAuthModule = (AIMAuthModule *)pIM->hAuthModule;

	DPRINT("%s >>>>>> session: %s, retCode %d\n", __FUNCTION__, pCheckAuth->szSession, pCheckAuth->retCode);

	AMThreadMutexLock(&pAuthModule->mtxAuth);

	pAuthFind = _AIMAuthModule_findSession(pAuthModule, pCheckAuth->szSession);
	if(pAuthFind)
	{
		rspCheckCode.iAuthId = pAuthFind->iAuth;
		rspCheckCode.iRetCode = pCheckAuth->retCode;

		_AIMAuth_notify(pIM, OnRspCheckCode, &rspCheckCode);

		if(!pCheckAuth->retCode)
		{
			IMnetSendRawPacket(hIMnetHandle, pAuthFind->szRawPacket, pAuthFind->uiPacketLen);
			set_compare(List, &pAuthModule->lstAuth, _AIMAuth_cmpPtr);
			delete_List(&pAuthModule->lstAuth, pAuthFind, sizeof(AIMAuth));
		}
		else
		{
			AIM_NTF_NEED_AUTH ntfNeedAuth;

			ntfNeedAuth.iAuthId = pAuthFind->iAuth;

			ntfNeedAuth.iRetCode  = _AIMAuth_getAuthImg(&szSession, &ntfNeedAuth.pvData, &ntfNeedAuth.iDataLen);
			_AIMAuth_setSession(pAuthFind, szSession);
			
			_AIMAuth_notify(pIM, OnNtfNeedAuth, &ntfNeedAuth);
		}
	}
	else
	{
		iRetCode = eAIM_RESULT_NOT_READY;
	}

	AMThreadMutexUnlock(&pAuthModule->mtxAuth);

	return eIMnetSkip;
}
Пример #5
0
AMInt32	AIMAuthModule_cancelAuth(AMHandle hAuthModule, AMInt32 iAuthId)
{
	AIMAuthModule *pAuthModule = (AIMAuthModule *)hAuthModule;
	AIMAuth tmpAuth;
	AMInt32 iRetCode = eAIM_RESULT_OK;
	
	tmpAuth.iAuth = iAuthId;

	AMAssert(pAuthModule && iAuthId);

	AMThreadMutexLock(&pAuthModule->mtxAuth);

	set_compare(List, &pAuthModule->lstAuth, _AIMAuth_cmpId);
	delete_List(&pAuthModule->lstAuth, &tmpAuth, sizeof(AIMAuth));

	AMThreadMutexUnlock(&pAuthModule->mtxAuth);

	return iRetCode;
}
Пример #6
0
void delete_Stack(Stack s){
   delete_List((List)s);
}
Пример #7
0
AMVoid		IAccountModel_LoginOK(IAccountModel *pAcntModel, AIMAccount *pAcnt)
{
	AIMAccount *pAcntDup = 0;
	AMInt32	rcSqlite = 0;
	sqlite3	*pDB = AMNULL;
	AMChar	*szErrMsg = AMNULL;
	AMChar	*szSql = AMNULL;

	AMAssert(AMNULL != pAcntModel && AMNULL != pAcnt && AMNULL != pAcnt->szID);

	pAcntDup = IAccount_dup(pAcnt);

	IAccountModel_RemoveAccount(pAcntModel, pAcntDup->szID, AMFALSE);

	delete_List(&pAcntModel->listAcnt, pAcntDup, sizeof(AIMAccount));
	push_front_List(&pAcntModel->listAcnt, pAcntDup, sizeof(AIMAccount), DYNAMIC);

	IAccountModel_MarkDirt(pAcntModel);	
	
	rcSqlite = myADB_Open(IM_ACNT_DB, &pDB, AMFALSE);

	if(rcSqlite)
	{
		DPRINT("IAccountModel_LoginOK: Can't open database: %s\n", sqlite3_errmsg(pDB));
		sqlite3_close(pDB);
		return;
	}

	rcSqlite = sqlite3_exec(pDB, SQL_CREATE_ACNT_TABLE, 0, 0, &szErrMsg);

	if( rcSqlite != SQLITE_OK )
	{
		DPRINT("IAccountModel_Store: Can't \"CREATE TABLE _account(...);\": %s!\n", szErrMsg);
		sqlite3_close(pDB);
		sqlite3_free(szErrMsg);
		return;
	}

	szSql = sqlite3_mprintf(SQL_INSERT_ACNT, pAcntDup->szID, (pAcntDup->uiFlag&0x01)?pAcntDup->szToken:"0"
		, (pAcntDup->szPhoneNum?pAcntDup->szPhoneNum:"0"), pAcntDup->uiFlag, pAcntDup->ePresence
		, pAcntDup->iGroupStamp, pAcntDup->iContactStamp, pAcntDup->iBlackStamp, pAcntDup->iRevBlackStamp
		, pAcntDup->szSigXML?pAcntDup->szSigXML:"0");

	if(AMNULL != szSql)
	{
		rcSqlite = sqlite3_exec(pDB, "BEGIN TRANSACTION;", 0, 0, &szErrMsg);
		if(SQLITE_OK != rcSqlite)
		{
			DPRINT("IAccountModel_LoginOK.............: can not BEGIN TRANSACTION;, for: %s\n", szErrMsg);
			sqlite3_free(szErrMsg);
			sqlite3_free(szSql);
			sqlite3_close(pDB);
			return;
		}

		DPRINT("IAccountModel_LoginOK.....................%s\n", pAcntDup->szID?pAcntDup->szID:"0");

		rcSqlite = sqlite3_exec(pDB, szSql, 0, 0, &szErrMsg);
		
		sqlite3_free(szSql);

		if( rcSqlite != SQLITE_OK )
		{
			DPRINT("IAccountModel_LoginOK: Can't INSERT!\n");
			sqlite3_free(szErrMsg);
			sqlite3_close(pDB);
			return;
		}

		pAcntDup->_iRid = sqlite3_last_insert_rowid(pDB);
		pAcnt->_iRid = pAcntDup->_iRid;

		rcSqlite = sqlite3_exec(pDB, "COMMIT TRANSACTION;", 0, 0, &szErrMsg);

		if(SQLITE_OK != rcSqlite)
		{
			DPRINT("IASessionModel_StoreMsg.............: can not COMMIT TRANSACTION;, for: %s\n",szErrMsg);
			sqlite3_free(szErrMsg);
			sqlite3_close(pDB);
			return;
		}
	}

	sqlite3_close(pDB);

	IAccountModel_ClearDirt(pAcntModel);
}