mirror of
https://github.com/CPunch/Laika.git
synced 2025-11-25 13:00:13 +00:00
lsocket.[ch]: refactored writeInt && readInt
- switched to laikaS_readu* && laikaS_writeu* - this gets rid of the ugly malloc() for platforms that don't support VLAs
This commit is contained in:
@@ -83,7 +83,7 @@ void laikaC_handleHandshakeRequest(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, v
|
||||
|
||||
/* queue response */
|
||||
laikaS_startOutPacket(peer, LAIKAPKT_HANDSHAKE_RES);
|
||||
laikaS_writeByte(&peer->sock, laikaS_isBigEndian());
|
||||
laikaS_writeByte(&peer->sock, laikaM_isBigEndian());
|
||||
laikaS_write(&peer->sock, peer->salt, LAIKA_HANDSHAKE_SALT_LEN);
|
||||
laikaS_endOutPacket(peer);
|
||||
|
||||
|
||||
@@ -65,8 +65,8 @@ void laikaC_handleAuthenticatedShellOpen(struct sLaika_peer *authPeer, LAIKAPKT_
|
||||
LAIKA_ERROR("laikaC_handleAuthenticatedShellOpen: Requested peer isn't a bot!\n");
|
||||
|
||||
/* read term size */
|
||||
laikaS_readInt(&authPeer->sock, &cols, sizeof(uint16_t));
|
||||
laikaS_readInt(&authPeer->sock, &rows, sizeof(uint16_t));
|
||||
cols = laikaS_readu16(&authPeer->sock);
|
||||
rows = laikaS_readu16(&authPeer->sock);
|
||||
|
||||
/* open shell */
|
||||
laikaC_openShell(peer, authPeer, cols, rows);
|
||||
@@ -80,7 +80,7 @@ void laikaC_handleAuthenticatedShellClose(struct sLaika_peer *authPeer, LAIKAPKT
|
||||
struct sLaika_shellInfo *shell;
|
||||
uint32_t id;
|
||||
|
||||
laikaS_readInt(&authPeer->sock, &id, sizeof(uint32_t));
|
||||
id = laikaS_readu32(&authPeer->sock);
|
||||
|
||||
/* ignore malformed packet */
|
||||
if (id >= LAIKA_MAX_SHELLS || (shell = pInfo->shells[id]) == NULL)
|
||||
@@ -102,7 +102,7 @@ void laikaC_handleAuthenticatedShellData(struct sLaika_peer *authPeer, LAIKAPKT_
|
||||
if (sz - sizeof(uint32_t) > LAIKA_SHELL_DATA_MAX_LENGTH)
|
||||
LAIKA_ERROR("laikaC_handleAuthenticatedShellData: Wrong data size!\n");
|
||||
|
||||
laikaS_readInt(&authPeer->sock, &id, sizeof(uint32_t));
|
||||
id = laikaS_readu32(&authPeer->sock);
|
||||
sz -= sizeof(uint32_t);
|
||||
|
||||
/* ignore malformed packet */
|
||||
@@ -116,7 +116,7 @@ void laikaC_handleAuthenticatedShellData(struct sLaika_peer *authPeer, LAIKAPKT_
|
||||
|
||||
/* forward to peer */
|
||||
laikaS_startVarPacket(peer, LAIKAPKT_SHELL_DATA);
|
||||
laikaS_writeInt(&peer->sock, &shell->botShellID, sizeof(uint32_t));
|
||||
laikaS_writeu32(&peer->sock, shell->botShellID);
|
||||
laikaS_write(&peer->sock, data, sz);
|
||||
laikaS_endVarPacket(peer);
|
||||
}
|
||||
|
||||
@@ -88,15 +88,15 @@ struct sLaika_shellInfo *laikaC_openShell(struct sLaika_peer *bot, struct sLaika
|
||||
|
||||
/* send SHELL_OPEN packets */
|
||||
laikaS_startOutPacket(bot, LAIKAPKT_SHELL_OPEN);
|
||||
laikaS_writeInt(&bot->sock, &shell->botShellID, sizeof(uint32_t));
|
||||
laikaS_writeInt(&bot->sock, &cols, sizeof(uint16_t));
|
||||
laikaS_writeInt(&bot->sock, &rows, sizeof(uint16_t));
|
||||
laikaS_writeu32(&bot->sock, shell->botShellID);
|
||||
laikaS_writeu16(&bot->sock, cols);
|
||||
laikaS_writeu16(&bot->sock, rows);
|
||||
laikaS_endOutPacket(bot);
|
||||
|
||||
laikaS_startOutPacket(auth, LAIKAPKT_SHELL_OPEN);
|
||||
laikaS_writeInt(&auth->sock, &shell->authShellID, sizeof(uint32_t));
|
||||
laikaS_writeInt(&auth->sock, &cols, sizeof(uint16_t));
|
||||
laikaS_writeInt(&auth->sock, &rows, sizeof(uint16_t));
|
||||
laikaS_writeu32(&auth->sock, shell->authShellID);
|
||||
laikaS_writeu16(&auth->sock, cols);
|
||||
laikaS_writeu16(&auth->sock, rows);
|
||||
laikaS_endOutPacket(auth);
|
||||
|
||||
return shell;
|
||||
@@ -106,11 +106,11 @@ void laikaC_closeShell(struct sLaika_shellInfo *shell)
|
||||
{
|
||||
/* send SHELL_CLOSE packets */
|
||||
laikaS_startOutPacket(shell->bot, LAIKAPKT_SHELL_CLOSE);
|
||||
laikaS_writeInt(&shell->bot->sock, &shell->botShellID, sizeof(uint32_t));
|
||||
laikaS_writeu32(&shell->bot->sock, shell->botShellID);
|
||||
laikaS_endOutPacket(shell->bot);
|
||||
|
||||
laikaS_startOutPacket(shell->auth, LAIKAPKT_SHELL_CLOSE);
|
||||
laikaS_writeInt(&shell->auth->sock, &shell->authShellID, sizeof(uint32_t));
|
||||
laikaS_writeu32(&shell->auth->sock, shell->authShellID);
|
||||
laikaS_endOutPacket(shell->auth);
|
||||
|
||||
/* unlink */
|
||||
@@ -175,7 +175,7 @@ void laikaC_handleShellClose(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *u
|
||||
struct sLaika_shellInfo *shell;
|
||||
uint32_t id;
|
||||
|
||||
laikaS_readInt(&peer->sock, &id, sizeof(uint32_t));
|
||||
id = laikaS_readu32(&peer->sock);
|
||||
|
||||
/* ignore packet if shell isn't open */
|
||||
if (id >= LAIKA_MAX_SHELLS || (shell = pInfo->shells[id]) == NULL)
|
||||
@@ -196,7 +196,7 @@ void laikaC_handleShellData(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uD
|
||||
if (sz > LAIKA_SHELL_DATA_MAX_LENGTH + sizeof(uint32_t))
|
||||
return;
|
||||
|
||||
laikaS_readInt(&peer->sock, &id, sizeof(uint32_t));
|
||||
id = laikaS_readu32(&peer->sock);
|
||||
|
||||
/* ignore packet if shell isn't open */
|
||||
if (id >= LAIKA_MAX_SHELLS || (shell = pInfo->shells[id]) == NULL)
|
||||
@@ -206,7 +206,7 @@ void laikaC_handleShellData(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uD
|
||||
|
||||
/* forward SHELL_DATA packet to auth */
|
||||
laikaS_startVarPacket(shell->auth, LAIKAPKT_SHELL_DATA);
|
||||
laikaS_writeInt(&shell->auth->sock, &shell->authShellID, sizeof(uint32_t));
|
||||
laikaS_writeu32(&shell->auth->sock, shell->authShellID);
|
||||
laikaS_write(&shell->auth->sock, buf, sz - sizeof(uint32_t));
|
||||
laikaS_endVarPacket(shell->auth);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user