diff --git a/lib/include/laika.h b/lib/include/laika.h index 7a6669c..9216b39 100644 --- a/lib/include/laika.h +++ b/lib/include/laika.h @@ -8,6 +8,8 @@ #include #include +#include "lconfig.h" + #define ARRAY_START 4 #ifdef DEBUG @@ -16,6 +18,4 @@ #define LAIKA_DEBUG(...) #endif -#include "lconfig.h" - #endif \ No newline at end of file diff --git a/lib/include/lconfig.h b/lib/include/lconfig.h index 6974500..78f833d 100644 --- a/lib/include/lconfig.h +++ b/lib/include/lconfig.h @@ -6,8 +6,8 @@ #define LAIKA_VERSION_MINOR 0 /* keys */ -#define LAIKA_PUBKEY "b507a9c8bc8f2c61ea019122311b64361d034ba2b6299a11628a2608ef7f4137" -#define LAIKA_PRIVKEY "4fefc9c4dba37f569432d091497b2c0e931ce78be945328e2ba57674969a3539" +#define LAIKA_PUBKEY "997d026d1c65deb6c30468525132be4ea44116d6f194c142347b67ee73d18814" +#define LAIKA_PRIVKEY "1dbd33962f1e170d1e745c6d3e19175049b5616822fac2fa3535d7477957a841" #endif diff --git a/lib/include/lconfig.h.in b/lib/include/lconfig.h.in index 0e2d095..3604c5e 100644 --- a/lib/include/lconfig.h.in +++ b/lib/include/lconfig.h.in @@ -9,5 +9,4 @@ #define LAIKA_PUBKEY "@LAIKA_PUBKEY@" #define LAIKA_PRIVKEY "@LAIKA_PRIVKEY@" - #endif \ No newline at end of file diff --git a/lib/include/lerror.h b/lib/include/lerror.h index 03a8300..53b0022 100644 --- a/lib/include/lerror.h +++ b/lib/include/lerror.h @@ -4,6 +4,8 @@ #include #include +#include "laika.h" + /* defines errorstack size */ #define LAIKA_MAXERRORS 32 diff --git a/lib/include/lmem.h b/lib/include/lmem.h index af13d70..41af48a 100644 --- a/lib/include/lmem.h +++ b/lib/include/lmem.h @@ -15,7 +15,7 @@ } /* moves array elements above indx down by numElem, removing numElem elements at indx */ -#define laikaM_rmvarray(type, buf, count, indx, numElem) { \ +#define laikaM_rmvarray(buf, count, indx, numElem) { \ int _i, _sz = ((count-indx)-numElem); \ for (_i = 0; _i < _sz; _i++) \ buf[indx+_i] = buf[indx+numElem+_i]; \ diff --git a/lib/src/lpolllist.c b/lib/src/lpolllist.c index e12647e..0b604f2 100644 --- a/lib/src/lpolllist.c +++ b/lib/src/lpolllist.c @@ -89,7 +89,7 @@ void laikaP_rmvSock(struct sLaika_pollList *pList, struct sLaika_socket *sock) { for (i = 0; i < pList->fdCount; i++) { if (pList->fds[i].fd == sock->sock) { /* remove from array */ - laikaM_rmvarray(PollFD, pList->fds, pList->fdCount, i, 1); + laikaM_rmvarray(pList->fds, pList->fdCount, i, 1); break; } } @@ -151,7 +151,6 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout, if (SOCKETERROR(nEvents)) LAIKA_ERROR("epoll_wait() failed!\n"); - *_nevents = nEvents; for (i = 0; i < nEvents; i++) { /* add event to revent array */ laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity); @@ -167,18 +166,17 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout, if (SOCKETERROR(nEvents)) LAIKA_ERROR("poll() failed!\n"); - *_nevents = nEvents; /* walk through the returned poll fds, if they have an event, add it to our revents array */ for (i = 0; i < pList->fdCount && nEvents > 0; i++) { PollFD pfd = pList->fds[i]; if (pList->fds[i].revents != 0) { /* grab socket from hashmap */ - struct sLaika_hashMapElem *_sock = hashmap_get(pList->sockets, &(tLaika_hashMapElem){.fd = (SOCKET)pfd.fd}); + tLaika_hashMapElem *elem = (tLaika_hashMapElem*)hashmap_get(pList->sockets, &(tLaika_hashMapElem){.fd = (SOCKET)pfd.fd}); /* insert event into revents array */ laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity); pList->revents[pList->reventCount++] = (struct sLaika_pollEvent){ - .sock = _sock->sock, + .sock = elem->sock, .pollIn = pfd.revents & POLLIN, .pollOut = pfd.revents & POLLOUT }; @@ -188,6 +186,8 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout, } #endif + *_nevents = pList->reventCount; + /* return revents array */ return pList->revents; } diff --git a/lib/src/lsocket.c b/lib/src/lsocket.c index c05811b..40cc55d 100644 --- a/lib/src/lsocket.c +++ b/lib/src/lsocket.c @@ -173,7 +173,7 @@ bool laikaS_setNonBlock(struct sLaika_socket *sock) { void laikaS_read(struct sLaika_socket *sock, void *buf, size_t sz) { memcpy(buf, sock->inBuf, sz); - laikaM_rmvarray(uint8_t, sock->inBuf, sock->inCount, 0, sz); + laikaM_rmvarray(sock->inBuf, sock->inCount, 0, sz); } void laikaS_write(struct sLaika_socket *sock, void *buf, size_t sz) { @@ -201,7 +201,7 @@ void laikaS_readENC(struct sLaika_socket *sock, void *buf, size_t sz, uint8_t *p if (crypto_box_seal_open(buf, sock->inBuf, LAIKAENC_SIZE(sz), pub, priv) != 0) LAIKA_ERROR("Failed to decrypt!\n"); - laikaM_rmvarray(uint8_t, sock->inBuf, sock->inCount, 0, LAIKAENC_SIZE(sz)); + laikaM_rmvarray(sock->inBuf, sock->inCount, 0, LAIKAENC_SIZE(sz)); } void laikaS_writeByte(struct sLaika_socket *sock, uint8_t data) { @@ -213,7 +213,7 @@ uint8_t laikaS_readByte(struct sLaika_socket *sock) { uint8_t tmp = *sock->inBuf; /* pop 1 byte */ - laikaM_rmvarray(uint8_t, sock->inBuf, sock->inCount, 0, 1); + laikaM_rmvarray(sock->inBuf, sock->inCount, 0, 1); return tmp; } @@ -310,7 +310,7 @@ RAWSOCKCODE laikaS_rawSend(struct sLaika_socket *sock, size_t sz, int *processed _rawWriteExit: /* trim sent data from outBuf */ - laikaM_rmvarray(uint8_t, sock->outBuf, sock->outCount, 0, sentBytes); + laikaM_rmvarray(sock->outBuf, sock->outCount, 0, sentBytes); *processed = sentBytes; return errCode;