Skip to content

Commit

Permalink
Fixed flags and location setting in the logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Kalatozishvili committed Sep 16, 2024
1 parent a4c377c commit ffaa423
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 103 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

# Local files
.vscode/
57 changes: 0 additions & 57 deletions .vscode/settings.json

This file was deleted.

4 changes: 0 additions & 4 deletions examples/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ int main()
/* Greet users */
greet();

XASSERT(0, 0);

/* Initialize XLog with default parameters */
XLog_Init("example", XLOG_ALL, 0);
xlog_separator("[xutils]");
Expand Down Expand Up @@ -85,8 +83,6 @@ int main()
xlogd("just another debug message");
xlogt("just another trace message");

XLOG_ASSERT(XFALSE, 0, "Message from failed assert");

xlog_destroy();
return 0;
}
18 changes: 9 additions & 9 deletions src/crypt/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ XSTATUS XRSA_GenerateKeys(xrsa_ctx_t *pCtx, size_t nKeyLength, size_t nPubKeyExp
return XSTDERR;
}

nRetVal = RSA_generate_key_ex(pKeyPair, nKeyLength, pBigNum, NULL);
nRetVal = RSA_generate_key_ex(pKeyPair, (int)nKeyLength, pBigNum, NULL);
if (nRetVal != XSTDOK)
{
RSA_free(pKeyPair);
Expand Down Expand Up @@ -159,7 +159,7 @@ XSTATUS XRSA_GenerateKeys(xrsa_ctx_t *pCtx, size_t nKeyLength, size_t nPubKeyExp
return XSTDERR;
}

int nRead = BIO_read(pBioPriv, pCtx->pPrivateKey, pCtx->nPrivKeyLen);
int nRead = BIO_read(pBioPriv, pCtx->pPrivateKey, (int)pCtx->nPrivKeyLen);
if ((size_t)nRead != pCtx->nPrivKeyLen)
{
XRSA_Destroy(pCtx);
Expand All @@ -169,7 +169,7 @@ XSTATUS XRSA_GenerateKeys(xrsa_ctx_t *pCtx, size_t nKeyLength, size_t nPubKeyExp
return XSTDERR;
}

nRead = BIO_read(pBioPub, pCtx->pPublicKey, pCtx->nPubKeyLen);
nRead = BIO_read(pBioPub, pCtx->pPublicKey, (int)pCtx->nPubKeyLen);
if ((size_t)nRead != pCtx->nPubKeyLen)
{
XRSA_Destroy(pCtx);
Expand Down Expand Up @@ -201,7 +201,7 @@ uint8_t* XRSA_Crypt(xrsa_ctx_t *pCtx, const uint8_t *pData, size_t nLength, size
uint8_t *pOutput = malloc(nRSASize + 1);
XASSERT(pOutput, NULL);

int nOutLength = RSA_public_encrypt(nLength, pData, pOutput, pRSA, pCtx->nPadding);
int nOutLength = RSA_public_encrypt((int)nLength, pData, pOutput, pRSA, pCtx->nPadding);
XASSERT_FREE((nOutLength > 0 && nOutLength <= nRSASize), pOutput, NULL);

if (pOutLength) *pOutLength = (size_t)nOutLength;
Expand All @@ -222,7 +222,7 @@ uint8_t* XRSA_PrivCrypt(xrsa_ctx_t *pCtx, const uint8_t *pData, size_t nLength,
uint8_t *pOutput = malloc(nRSASize + 1);
XASSERT(pOutput, NULL);

int nOutLength = RSA_private_encrypt(nLength, pData, pOutput, pRSA, pCtx->nPadding);
int nOutLength = RSA_private_encrypt((int)nLength, pData, pOutput, pRSA, pCtx->nPadding);
XASSERT_FREE((nOutLength > 0 && nOutLength <= nRSASize), pOutput, NULL);

if (pOutLength) *pOutLength = (size_t)nOutLength;
Expand All @@ -243,7 +243,7 @@ uint8_t* XRSA_PubDecrypt(xrsa_ctx_t *pCtx, const uint8_t *pData, size_t nLength,
uint8_t *pOutput = malloc(nRSASize + 1);
XASSERT(pOutput, NULL);

int nOutLength = RSA_public_decrypt(nLength, pData, pOutput, pRSA, pCtx->nPadding);
int nOutLength = RSA_public_decrypt((int)nLength, pData, pOutput, pRSA, pCtx->nPadding);
XASSERT_FREE((nOutLength > 0 && nOutLength <= nRSASize), pOutput, NULL);

if (pOutLength) *pOutLength = (size_t)nOutLength;
Expand All @@ -261,7 +261,7 @@ uint8_t* XRSA_Decrypt(xrsa_ctx_t *pCtx, const uint8_t *pData, size_t nLength, si
uint8_t *pOutput = malloc(nLength + 1);
XASSERT(pOutput, NULL);

int nOutLength = RSA_private_decrypt(nLength, pData, pOutput, pRSA, pCtx->nPadding);
int nOutLength = RSA_private_decrypt((int)nLength, pData, pOutput, pRSA, pCtx->nPadding);
XASSERT_FREE((nOutLength > 0), pOutput, NULL);

if (pOutLength) *pOutLength = (size_t)nOutLength;
Expand All @@ -282,7 +282,7 @@ XSTATUS XRSA_LoadPrivKey(xrsa_ctx_t *pCtx)
XASSERT(pCtx->pKeyPair, XSTDERR);
}

BIO* pBIO = BIO_new_mem_buf((void*)pCtx->pPrivateKey, pCtx->nPrivKeyLen);
BIO* pBIO = BIO_new_mem_buf((void*)pCtx->pPrivateKey, (int)pCtx->nPrivKeyLen);
XASSERT(pBIO, XSTDERR);

RSA *pRSA = PEM_read_bio_RSAPrivateKey(pBIO, &pCtx->pKeyPair, NULL, NULL);
Expand All @@ -302,7 +302,7 @@ XSTATUS XRSA_LoadPubKey(xrsa_ctx_t *pCtx)
XASSERT(pCtx->pKeyPair, XSTDERR);
}

BIO* pBIO = BIO_new_mem_buf((void*)pCtx->pPublicKey, pCtx->nPubKeyLen);
BIO* pBIO = BIO_new_mem_buf((void*)pCtx->pPublicKey, (int)pCtx->nPubKeyLen);
XASSERT(pBIO, XSTDERR);

RSA *pRSA = PEM_read_bio_RSAPublicKey(pBIO, &pCtx->pKeyPair, NULL, NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/crypt/sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ XSTATUS XSHA1_Compute(uint8_t *pOutput, size_t nSize, const uint8_t *pInput, siz

xsha1_ctx_t xsha;
XSHA1_Init(&xsha);
XSHA1_Update(&xsha, pInput, nLength);
XSHA1_Update(&xsha, pInput, (uint32_t)nLength);
XSHA1_Final(&xsha, pOutput);

return XSTDOK;
Expand Down
4 changes: 2 additions & 2 deletions src/data/xbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int XByteBuffer_OwnData(xbyte_buffer_t *pBuffer, uint8_t *pData, size_t nSize)
XByteBuffer_Clear(pBuffer);
XByteBuffer_SetData(pBuffer, pData, nSize);
pBuffer->nSize = nSize;
return pBuffer->nSize;
return (int)pBuffer->nSize;
}

int XByteBuffer_Own(xbyte_buffer_t *pBuffer, xbyte_buffer_t *pSrc)
Expand All @@ -193,7 +193,7 @@ int XByteBuffer_Own(xbyte_buffer_t *pBuffer, xbyte_buffer_t *pSrc)
pSrc->pData = NULL;
pSrc->nSize = XSTDNON;
pSrc->nUsed = XSTDNON;
return pBuffer->nSize;
return (int)pBuffer->nSize;
}

int XByteBuffer_Add(xbyte_buffer_t *pBuffer, const uint8_t *pData, size_t nSize)
Expand Down
8 changes: 4 additions & 4 deletions src/data/xstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ size_t xstrnfill(char *pDst, size_t nSize, size_t nLength, char cFill)
char *xstrfill(size_t nLength, char cFill)
{
static char sRetVal[XSTR_MAX];
size_t nLen, i = 0;
xstrnul(sRetVal);
int i = 0;

int nLen = XSTD_MIN(nLength, sizeof(sRetVal) - 1);
nLen = XSTD_MIN(nLength, sizeof(sRetVal) - 1);
for (i = 0; i < nLen; i++) sRetVal[i] = ' ';

sRetVal[i] = '\0';
Expand Down Expand Up @@ -827,8 +827,8 @@ int xstrnrep(char *pDst, size_t nSize, const char *pOrig, const char *pRep, cons

xstrncpys(pOffset, nAvail, pWith, nWithLen);
pOrig += (size_t)nFirstPartLen + nRepLen;
nAvail -= nWithLen;
pOffset += nWithLen;
nAvail -= (int)nWithLen;
pOffset += (int)nWithLen;
if (nAvail <= 0) return XSTDNON;
}

Expand Down
6 changes: 3 additions & 3 deletions src/net/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int XAddr_GetIFCIP(const char *pIFace, char *pAddr, int nSize)
char *pIPAddr = inet_ntoa(((struct sockaddr_in *)&ifbuf.ifr_addr)->sin_addr);
return (pAddr != NULL) ? xstrncpyf(pAddr, nSize, "%s", pIPAddr) : XSTDERR;
#endif
return xstrncpyf(pAddr, nSize, "0.0.0.0");
return (int)xstrncpyf(pAddr, nSize, "0.0.0.0");
}

int XAddr_GetIFCMac(const char *pIFace, char *pAddr, int nSize)
Expand All @@ -242,7 +242,7 @@ int XAddr_GetIFCMac(const char *pIFace, char *pAddr, int nSize)
return xstrncpyf(pAddr, nSize, "%02x:%02x:%02x:%02x:%02x:%02x",
hwaddr[0],hwaddr[1],hwaddr[2],hwaddr[3],hwaddr[4],hwaddr[5]);
#endif
return xstrncpyf(pAddr, nSize, "0:0:0:0:0:0");
return (int)xstrncpyf(pAddr, nSize, "0:0:0:0:0:0");
}

int XAddr_GetMAC(char *pAddr, int nSize)
Expand Down Expand Up @@ -286,6 +286,6 @@ int XAddr_GetMAC(char *pAddr, int nSize)
close(sock);
return nLength;
#endif
return xstrncpyf(pAddr, nSize, "0:0:0:0:0:0");
return (int)xstrncpyf(pAddr, nSize, "0:0:0:0:0:0");
}

2 changes: 1 addition & 1 deletion src/net/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ xbyte_buffer_t* XAPI_GetTxBuff(xapi_data_t *pApiData)
XSTATUS XAPI_PutTxBuff(xapi_data_t *pApiData, xbyte_buffer_t *pBuffer)
{
XASSERT_RET((pApiData && pBuffer), XSTDINV);
XASSERT_RET(pBuffer->nUsed, pApiData->txBuffer.nUsed);
XASSERT_RET(pBuffer->nUsed, (XSTATUS)pApiData->txBuffer.nUsed);

XByteBuffer_AddBuff(&pApiData->txBuffer, pBuffer);
if (!pApiData->txBuffer.nUsed)
Expand Down
2 changes: 1 addition & 1 deletion src/net/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ xevent_status_t XEvents_Service(xevents_t *pEv, int nTimeoutMs)
if (nRet != XEVENTS_CONTINUE) break;
}
#else
for (i = 0; i < pEv->nEventCount; i++)
for (i = 0; i < (int)pEv->nEventCount; i++)
{
if (pEv->pEventArray[i].revents <= 0) continue;
else if (pEv->pEventArray[i].fd == XSOCK_INVALID) break;
Expand Down
14 changes: 7 additions & 7 deletions src/net/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void XSock_DeinitSSL(void)
int XSock_LastSSLError(char *pDst, size_t nSize)
{
if (pDst == NULL) return XSOCK_NONE;
int nLength = 0;
size_t nLength = 0;
pDst[0] = XSTR_NUL;

#ifdef XSOCK_USE_SSL
Expand All @@ -262,7 +262,7 @@ int XSock_LastSSLError(char *pDst, size_t nSize)
(void)nSize;
#endif

return nLength;
return (int)nLength;
}

int xclosesock(XSOCKET nFd)
Expand Down Expand Up @@ -588,7 +588,7 @@ int XSock_SSLWrite(xsock_t *pSock, const void *pData, size_t nLength)

while (nLeft > 0)
{
int nBytes = SSL_write(pSSL, &pBuff[nSent], nLeft);
int nBytes = SSL_write(pSSL, &pBuff[nSent], (int)nLeft);
if (nBytes <= 0)
{
int nError = SSL_get_error(pSSL, nBytes);
Expand Down Expand Up @@ -623,7 +623,7 @@ int XSock_SSLWrite(xsock_t *pSock, const void *pData, size_t nLength)
if (XSock_IsNB(pSock)) break;
}

return nSent;
return (int)nSent;
#else
pSock->eStatus = XSOCK_ERR_NOSSL;
XSock_Close(pSock);
Expand Down Expand Up @@ -826,7 +826,7 @@ XSOCKET XSock_Accept(xsock_t *pSock, xsock_t *pNewSock)
}

SSL_set_accept_state(pSSL);
SSL_set_fd(pSSL, pNewSock->nFD);
SSL_set_fd(pSSL, (int)pNewSock->nFD);

XSOCKET nFD = XSock_SetSSL(pNewSock, pSSL);
XASSERT((nFD != XSOCK_INVALID), XSOCK_INVALID);
Expand Down Expand Up @@ -1463,10 +1463,10 @@ XSOCKET XSock_InitSSLClient(xsock_t *pSock)
}

SSL_set_connect_state(pSSL);
SSL_set_fd(pSSL, pSock->nFD);
SSL_set_fd(pSSL, (int)pSock->nFD);

#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
long nOpts = SSL_get_options(pSSL);
long nOpts = (long)SSL_get_options(pSSL);
nOpts |= SSL_OP_IGNORE_UNEXPECTED_EOF;
SSL_set_options(pSSL, nOpts);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/net/ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ uint8_t* XWS_CreateFrame(const uint8_t *pPayload, size_t nLength, uint8_t nOpCod

if (nLength <= 125)
{
nLengthByte = nLength;
nLengthByte = (uint8_t)nLength;
}
else if (nLength <= 65535)
{
Expand Down
2 changes: 1 addition & 1 deletion src/sys/xcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int XCLI_GetInput(const char *pText, char *pInput, size_t nSize, xbool_t bCutNew
pInput[0] = XSTR_NUL;

if (pText != NULL) printf("%s", pText);
char *pRet = fgets(pInput, nSize, stdin);
char *pRet = fgets(pInput, (int)nSize, stdin);

XASSERT_RET((pRet != NULL), XSTDERR);
if (!xstrused(pInput)) return XSTDNON;
Expand Down
6 changes: 3 additions & 3 deletions src/sys/xfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ int XFile_ReadLine(xfile_t *pFile, char* pLine, size_t nSize, size_t nLineNum)
{
nRet = XFile_GetLine(pFile, pLine, nSize);
if (nRet <= 0) return XSTDERR;
if (++nLine == nLineNum) return nRet;
if (++nLine == nLineNum) return (int)nRet;
}

return XSTDERR;
Expand Down Expand Up @@ -611,10 +611,10 @@ long XPath_GetSize(const char *pPath)
if (XFile_Open(&srcFile, pPath, NULL, NULL) >= 0)
{
XFile_GetStats(&srcFile);
long nSize = srcFile.nSize;
size_t nSize = srcFile.nSize;

XFile_Close(&srcFile);
return nSize;
return (long)nSize;
}

return XSTDERR;
Expand Down
8 changes: 4 additions & 4 deletions src/sys/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static xbool_t XLog_OpenFile(xlog_file_t *pFile, const xlog_cfg_t *pCfg, const x
if (pFile->pHandle == NULL)
{
printf("<%s:%d> %s: [ERROR] Failed to open file: %s (%s)\n",
__FILE__, __LINE__, __func__, sFilePath, strerror(errno));
__FILE__, __LINE__, __func__, sFilePath, XSTRERR);

return XFALSE;
}
Expand Down Expand Up @@ -544,7 +544,7 @@ void XLog_FlagsSet(uint16_t nFlags)

uint16_t XLog_FlagsGet(void)
{
XASSERT_RET(XSTDNON, g_bInit);
XASSERT_RET(g_bInit, XSTDNON);
XSync_Lock(&g_xlog.lock);
uint16_t nFlags = g_xlog.config.nFlags;
XSync_Unlock(&g_xlog.lock);
Expand All @@ -553,7 +553,7 @@ uint16_t XLog_FlagsGet(void)

size_t XLog_PathSet(const char *pPath)
{
XASSERT_RET(XSTDNON, g_bInit);
XASSERT_RET(g_bInit, XSTDNON);
XSync_Lock(&g_xlog.lock);

xlog_file_t *pFile = &g_xlog.fileCtx;
Expand All @@ -569,7 +569,7 @@ size_t XLog_PathSet(const char *pPath)

size_t XLog_NameSet(const char *pName)
{
XASSERT_RET(XSTDNON, g_bInit);
XASSERT_RET(g_bInit, XSTDNON);
XSync_Lock(&g_xlog.lock);

xlog_file_t *pFile = &g_xlog.fileCtx;
Expand Down
Loading

0 comments on commit ffaa423

Please sign in to comment.