diff --git a/.gitignore b/.gitignore
index 28b9956..203ebc1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,10 @@
!.gitignore
!.github
!.github/**/*
+!FrequenC.sln
+!FrequenC.vcxproj
+!FrequenC.vcxproj.filters
+!FrequenC.vcxproj.user
!API.md
!CLIENT_DEVELOPMENT.md
!CODE_OF_CONDUCT.md
diff --git a/FrequenC.sln b/FrequenC.sln
new file mode 100644
index 0000000..75bd37c
--- /dev/null
+++ b/FrequenC.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.8.34322.80
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FrequenC", "FrequenC.vcxproj", "{7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}.Debug|x64.ActiveCfg = Debug|x64
+ {7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}.Debug|x64.Build.0 = Debug|x64
+ {7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}.Debug|x86.ActiveCfg = Debug|Win32
+ {7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}.Debug|x86.Build.0 = Debug|Win32
+ {7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}.Release|x64.ActiveCfg = Release|x64
+ {7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}.Release|x64.Build.0 = Release|x64
+ {7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}.Release|x86.ActiveCfg = Release|Win32
+ {7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {6CEE4E46-96A0-49D0-BA78-B2B32AC1D76F}
+ EndGlobalSection
+EndGlobal
diff --git a/FrequenC.vcxproj b/FrequenC.vcxproj
new file mode 100644
index 0000000..f3318ef
--- /dev/null
+++ b/FrequenC.vcxproj
@@ -0,0 +1,201 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 17.0
+ {7CB47FA0-05FA-48DB-9C3D-1F2F026FCBA4}
+ Win32Proj
+ 10.0
+
+
+
+ Application
+ true
+ v143
+
+
+ Application
+ false
+ v143
+
+
+ Application
+ true
+ v143
+
+
+ Application
+ false
+ v143
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+ true
+
+
+ true
+
+
+ true
+
+
+
+ EnableAllWarnings
+ C:/Program Files (x86)/OpenSSL-Win32/include;external;include;sources
+ PCLL_SSL_LIBRARY=1;GITHUB_BRANCH="unknown";GITHUB_COMMIT_SHA="unknown";%(PreprocessorDefinitions)
+
+
+ true
+ Windows
+ wsock32.lib;Advapi32.lib;libssl.lib;libcrypto.lib
+ C:/Program Files (x86)/OpenSSL-Win32/lib/VC/x86/MTd;%(AdditionalLibraryDirectories)
+
+
+
+
+ Level3
+ C:/Program Files/OpenSSL-Win64/include;external;include;sources
+ PCLL_SSL_LIBRARY=1;GITHUB_BRANCH="unknown";GITHUB_COMMIT_SHA="unknown";%(PreprocessorDefinitions)
+
+
+ true
+ Windows
+ ws2_32.lib;wsock32.lib;Advapi32.lib;libssl.lib;libcrypto.lib
+ C:/Program Files/OpenSSL-Win64/lib/VC/x64/MTd;%(AdditionalLibraryDirectories)
+
+
+
+
+ EnableAllWarnings
+ C:/Program Files (x86)/OpenSSL-Win32/include;external;include;sources
+ PCLL_SSL_LIBRARY=1;GITHUB_BRANCH="unknown";GITHUB_COMMIT_SHA="unknown";%(PreprocessorDefinitions)
+
+
+ true
+ Windows
+ true
+ true
+ wsock32.lib;Advapi32.lib;libssl.lib;libcrypto.lib
+ C:/Program Files (x86)/OpenSSL-Win32/lib/VC/x86/MTd;%(AdditionalLibraryDirectories)
+
+
+
+
+ Level3
+ C:/Program Files/OpenSSL-Win64/include;external;include;sources
+ PCLL_SSL_LIBRARY=1;GITHUB_BRANCH="unknown";GITHUB_COMMIT_SHA="unknown";%(PreprocessorDefinitions)
+ AnySuitable
+ true
+ Speed
+ true
+ true
+ true
+
+
+ true
+ Windows
+ true
+ true
+ ws2_32.lib;wsock32.lib;Advapi32.lib;libssl.lib;libcrypto.lib
+ C:/Program Files/OpenSSL-Win64/lib/VC/x64/MTd;%(AdditionalLibraryDirectories)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
\ No newline at end of file
diff --git a/FrequenC.vcxproj.filters b/FrequenC.vcxproj.filters
new file mode 100644
index 0000000..c90f76a
--- /dev/null
+++ b/FrequenC.vcxproj.filters
@@ -0,0 +1,156 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+
+
+
+
\ No newline at end of file
diff --git a/FrequenC.vcxproj.user b/FrequenC.vcxproj.user
new file mode 100644
index 0000000..966b4ff
--- /dev/null
+++ b/FrequenC.vcxproj.user
@@ -0,0 +1,6 @@
+
+
+
+ true
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index cec5461..57487c6 100644
--- a/README.md
+++ b/README.md
@@ -15,10 +15,13 @@ The standalone audio-sending node written in C.
- [`OpenSSL`](https://www.openssl.org/) or [`WolfSSL`](https://www.wolfssl.com/)
+> [!NOTE]
+> For Windows, you must install [OpenSSL from slproweb.com](https://slproweb.com/products/Win32OpenSSL.html). Select the architecture that matches your machine's architecture.
+
## Installation
> [!IMPORTANT]
-> FrequenC as of now only supports Linux. Windows support is WIP and experimental.
+> For Windows, you can simply click build the project using Visual Studio. Make sure to install the dependencies first.
### 1. Clone the repository
diff --git a/external/base64.c b/external/base64.c
index be54408..e36016a 100644
--- a/external/base64.c
+++ b/external/base64.c
@@ -12,6 +12,7 @@
#include
#include
#include
+
#include "utils.h"
#include "base64.h"
diff --git a/external/csocket-client.c b/external/csocket-client.c
index 654120d..88539a9 100644
--- a/external/csocket-client.c
+++ b/external/csocket-client.c
@@ -76,7 +76,7 @@ int csocket_client_init(struct csocket_client *client, bool secure, char *hostna
return -1;
}
- ret = pcll_set_fd(&client->connection, client->socket);
+ ret = pcll_set_fd(&client->connection, (int)client->socket);
if (ret != PCLL_SUCCESS) {
_csocket_client_close(client);
@@ -107,7 +107,7 @@ int csocket_client_init(struct csocket_client *client, bool secure, char *hostna
return CSOCKET_CLIENT_SUCCESS;
}
-int csocket_client_send(struct csocket_client *client, char *data, size_t size) {
+int csocket_client_send(struct csocket_client *client, char *data, int size) {
if (client->secure) {
int ret = pcll_send(&client->connection, data, size);
if (ret == PCLL_ERROR) {
@@ -126,7 +126,7 @@ int csocket_client_send(struct csocket_client *client, char *data, size_t size)
return CSOCKET_CLIENT_SUCCESS;
}
-int csocket_client_recv(struct csocket_client *client, char *buffer, size_t size) {
+int csocket_client_recv(struct csocket_client *client, char *buffer, int size) {
if (client->secure) {
int recv_length = pcll_recv(&client->connection, buffer, size);
if (recv_length == PCLL_ERROR) {
diff --git a/external/csocket-client.h b/external/csocket-client.h
index 7fc1dee..26d6913 100644
--- a/external/csocket-client.h
+++ b/external/csocket-client.h
@@ -30,9 +30,9 @@ struct csocket_client {
int csocket_client_init(struct csocket_client *client, bool secure, char *hostname, int port);
-int csocket_client_send(struct csocket_client *client, char *data, size_t size);
+int csocket_client_send(struct csocket_client *client, char *data, int size);
-int csocket_client_recv(struct csocket_client *client, char *buffer, size_t size);
+int csocket_client_recv(struct csocket_client *client, char *buffer, int size);
void csocket_client_close(struct csocket_client *client);
diff --git a/external/csocket-server.c b/external/csocket-server.c
index 658692d..2815394 100644
--- a/external/csocket-server.c
+++ b/external/csocket-server.c
@@ -11,8 +11,6 @@
#include
#include
#include
- #include
- #include
#ifdef CSOCKET_SECURE
#include "pcll.h"
@@ -114,7 +112,7 @@ int csocket_server_accept(struct csocket_server server, struct csocket_server_cl
return 0;
}
-int csocket_server_send(struct csocket_server_client *client, char *data, size_t length) {
+int csocket_server_send(struct csocket_server_client *client, char *data, int length) {
#ifdef CSOCKET_SECURE
if (pcll_send(client->connection, data, length) < 0) {
perror("[csocket-server]: Failed to send data");
@@ -146,7 +144,7 @@ int csocket_close_client(struct csocket_server_client *client) {
return 0;
}
-int csocket_server_recv(struct csocket_server_client *client, char *buffer, size_t length) {
+int csocket_server_recv(struct csocket_server_client *client, char *buffer, int length) {
#ifdef CSOCKET_SECURE
int bytes = pcll_recv(client->connection, buffer, length);
if (bytes <= 0) {
@@ -187,8 +185,8 @@ unsigned int csocket_server_client_get_id(struct csocket_server_client *client)
return (unsigned int)client->socket;
}
-char *csocket_server_client_get_ip(struct csocket_server_client *client) {
- return inet_ntoa(client->address.sin_addr);
+const char *csocket_server_client_get_ip(struct csocket_server_client *client, char *ip) {
+ return inet_ntop(AF_INET, &client->address.sin_addr, ip, INET_ADDRSTRLEN);
}
unsigned int csocket_server_client_get_port(struct csocket_server_client *client) {
diff --git a/external/csocket-server.h b/external/csocket-server.h
index eac37f4..427513a 100644
--- a/external/csocket-server.h
+++ b/external/csocket-server.h
@@ -39,7 +39,11 @@ struct csocket_server {
};
struct csocket_server_client {
- int socket;
+ #ifdef _WIN32
+ SOCKET socket;
+ #else
+ int socket;
+ #endif
struct sockaddr_in address;
#ifdef CSOCKET_SECURE
SSL *ssl;
@@ -50,17 +54,17 @@ int csocket_server_init(struct csocket_server *server);
int csocket_server_accept(struct csocket_server server, struct csocket_server_client *client);
-int csocket_server_send(struct csocket_server_client *client, char *data, size_t length);
+int csocket_server_send(struct csocket_server_client *client, char *data, int length);
int csocket_close_client(struct csocket_server_client *client);
-int csocket_server_recv(struct csocket_server_client *client, char *buffer, size_t length);
+int csocket_server_recv(struct csocket_server_client *client, char *buffer, int length);
int csocket_server_close(struct csocket_server *server);
unsigned int csocket_server_client_get_id(struct csocket_server_client *client);
-char *csocket_server_client_get_ip(struct csocket_server_client *client);
+const char *csocket_server_client_get_ip(struct csocket_server_client *client, char *ip);
unsigned int csocket_server_client_get_port(struct csocket_server_client *client);
diff --git a/external/cthreads.c b/external/cthreads.c
index d4edbe5..988ff4c 100644
--- a/external/cthreads.c
+++ b/external/cthreads.c
@@ -131,7 +131,7 @@ unsigned long cthreads_thread_id(struct cthreads_thread thread) {
#endif
}
-void cthreads_thread_exit(void *code) {
+void cthreads_thread_exit(unsigned int code) {
#ifdef CTHREADS_DEBUG
printf("cthreads_thread_exit\n");
#endif
@@ -143,7 +143,7 @@ void cthreads_thread_exit(void *code) {
ExitThread((DWORD)(uintptr_t)code);
#endif
#else
- pthread_exit(code);
+ pthread_exit((void *)&code);
#endif
}
diff --git a/external/cthreads.h b/external/cthreads.h
index ec88f72..4c3d05b 100644
--- a/external/cthreads.h
+++ b/external/cthreads.h
@@ -225,7 +225,7 @@ unsigned long cthreads_thread_id(struct cthreads_thread thread);
*
* @param code Pointer to the thread exit code.
*/
-void cthreads_thread_exit(void *code);
+void cthreads_thread_exit(unsigned int code);
/**
* Cancels a thread.
diff --git a/external/jsmn-find.h b/external/jsmn-find.h
index 22aa211..8a5479d 100644
--- a/external/jsmn-find.h
+++ b/external/jsmn-find.h
@@ -394,7 +394,7 @@ jsmnf_find_path(const struct jsmnf_pair *head,
for (i = 0; i < depth; ++i) {
if (!iter) continue;
- found = jsmnf_find(iter, js, path[i], strlen(path[i]));
+ found = jsmnf_find(iter, js, path[i], (int)strlen(path[i]));
if (!found) break;
iter = found;
}
@@ -585,24 +585,24 @@ static unsigned
_jsmnf_utf8_encode(unsigned long value, char utf8_seq[4])
{
if (value <= 0x7F) {
- utf8_seq[0] = value;
+ utf8_seq[0] = (char)value;
return 1;
}
if (value <= 0x7FF) {
- utf8_seq[0] = (value >> 6) | 0xC0;
- utf8_seq[1] = (value & 0x3F) | 0x80;
+ utf8_seq[0] = (char)((value >> 6) | 0xC0);
+ utf8_seq[1] = (char)((value & 0x3F) | 0x80);
return 2;
}
if (value <= 0xFFFF) {
- utf8_seq[0] = (value >> 12) | 0xE0;
- utf8_seq[1] = ((value >> 6) & 0x3F) | 0x80;
- utf8_seq[2] = (value & 0x3F) | 0x80;
+ utf8_seq[0] = (char)((value >> 12) | 0xE0);
+ utf8_seq[1] = (char)(((value >> 6) & 0x3F) | 0x80);
+ utf8_seq[2] = (char)((value & 0x3F) | 0x80);
return 3;
}
- utf8_seq[0] = (value >> 18) | 0xF0;
- utf8_seq[1] = ((value >> 12) & 0x3F) | 0x80;
- utf8_seq[2] = ((value >> 6) & 0x3F) | 0x80;
- utf8_seq[3] = (value & 0x3F) | 0x80;
+ utf8_seq[0] = (char)((value >> 18) | 0xF0);
+ utf8_seq[1] = (char)(((value >> 12) & 0x3F) | 0x80);
+ utf8_seq[2] = (char)(((value >> 6) & 0x3F) | 0x80);
+ utf8_seq[3] = (char)((value & 0x3F) | 0x80);
return 4;
}
diff --git a/external/libtsrt.c b/external/libtsrt.c
index 534184c..097b55a 100644
--- a/external/libtsrt.c
+++ b/external/libtsrt.c
@@ -5,7 +5,6 @@
*/
#include // size_t, NULL
-#include
#include "libtstr.h"
diff --git a/external/pcll.c b/external/pcll.c
index e8bd9dc..2382fa0 100644
--- a/external/pcll.c
+++ b/external/pcll.c
@@ -98,9 +98,9 @@ int pcll_init_tls_server(struct pcll_server *server, char *cert, char *key) {
}
return PCLL_SUCCESS;
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
int pcll_init_ssl(struct pcll_connection *connection) {
@@ -146,9 +146,9 @@ int pcll_init_ssl(struct pcll_connection *connection) {
}
return PCLL_SUCCESS;
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
int pcll_init_only_ssl(struct pcll_connection *connection) {
@@ -172,9 +172,9 @@ int pcll_init_only_ssl(struct pcll_connection *connection) {
}
return PCLL_SUCCESS;
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
int pcll_set_fd(struct pcll_connection *connection, int fd) {
@@ -198,9 +198,9 @@ int pcll_set_fd(struct pcll_connection *connection, int fd) {
}
return PCLL_SUCCESS;
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
int pcll_set_safe_mode(struct pcll_connection *connection, char *hostname) {
@@ -234,9 +234,9 @@ int pcll_set_safe_mode(struct pcll_connection *connection, char *hostname) {
if (connection->ssl == NULL) return PCLL_ERROR;
return 0;
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
int pcll_connect(struct pcll_connection *connection) {
@@ -250,9 +250,9 @@ int pcll_connect(struct pcll_connection *connection) {
if (ret != WOLFSSL_SUCCESS) return ret;
return PCLL_SUCCESS;
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
int pcll_accept(struct pcll_connection *connection) {
@@ -276,9 +276,9 @@ int pcll_accept(struct pcll_connection *connection) {
}
return PCLL_SUCCESS;
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
int pcll_get_error(struct pcll_connection *connection, int error) {
@@ -286,9 +286,9 @@ int pcll_get_error(struct pcll_connection *connection, int error) {
return SSL_get_error(connection->ssl, error);
#elif PCLL_SSL_LIBRARY == PCLL_WOLFSSL
return wolfSSL_get_error(connection->ssl, error);
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
int pcll_send(struct pcll_connection *connection, char *data, int length) {
@@ -314,9 +314,9 @@ int pcll_send(struct pcll_connection *connection, char *data, int length) {
}
return PCLL_SUCCESS;
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
int pcll_recv(struct pcll_connection *connection, char *data, int length) {
@@ -342,9 +342,9 @@ int pcll_recv(struct pcll_connection *connection, char *data, int length) {
}
return recv_length;
+ #else
+ return PCLL_ERROR;
#endif
-
- return PCLL_ERROR;
}
void pcll_free(struct pcll_connection *connection) {
diff --git a/external/pdvoice.c b/external/pdvoice.c
index 43a01b4..d85e541 100644
--- a/external/pdvoice.c
+++ b/external/pdvoice.c
@@ -77,12 +77,21 @@ void _pdvoice_on_close(struct httpclient_response *client, struct frequenc_ws_fr
void *_pdvoice_udp(void *data) {
struct _pdvoice_udp_thread_data *thread_data = data;
- int udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
- if (udp_socket == -1) {
- printf("[pdvoice]: Failed to create UDP socket. Check your firewall.\n");
+ #ifdef _WIN32
+ SOCKET udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
+ if (udp_socket == INVALID_SOCKET) {
+ printf("[pdvoice]: Failed to create UDP socket. Check your firewall.\n");
- return NULL;
- }
+ return NULL;
+ }
+ #else
+ int udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
+ if (udp_socket == -1) {
+ printf("[pdvoice]: Failed to create UDP socket. Check your firewall.\n");
+
+ return NULL;
+ }
+ #endif
#ifdef _WIN32
BOOL enable = 1;
diff --git a/external/pjsonb.c b/external/pjsonb.c
index 673d4b9..8fc0773 100644
--- a/external/pjsonb.c
+++ b/external/pjsonb.c
@@ -48,7 +48,7 @@ void pjsonb_set_int(struct pjsonb *builder, const char *key, int value) {
return;
}
- int key_length = strlen(key);
+ size_t key_length = strlen(key);
builder->string = realloc(builder->string, builder->position + value_length + 4 + key_length + 1);
@@ -56,7 +56,7 @@ void pjsonb_set_int(struct pjsonb *builder, const char *key, int value) {
builder->position++;
memcpy(builder->string + builder->position, key, key_length);
- builder->position += key_length;
+ builder->position += (int)key_length;
memcpy(builder->string + builder->position, "\":", 2);
builder->position += 2;
@@ -69,6 +69,42 @@ void pjsonb_set_int(struct pjsonb *builder, const char *key, int value) {
builder->key_state = PJSONB_TO_CLOSE;
}
+void pjsonb_set_size_t(struct pjsonb *builder, const char *key, size_t value) {
+ int value_length = snprintf(NULL, 0, "%zu", value);
+
+ if (key == NULL) {
+ builder->string = realloc(builder->string, builder->position + value_length + 1);
+
+ builder->position += snprintf(builder->string + builder->position, value_length + 1, "%zu", value);
+
+ memcpy(builder->string + builder->position, ",", 1);
+
+ builder->key_state = PJSONB_TO_CLOSE;
+
+ return;
+ }
+
+ size_t key_length = strlen(key);
+
+ builder->string = realloc(builder->string, builder->position + value_length + 4 + key_length + 1);
+
+ builder->string[builder->position] = '"';
+ builder->position++;
+
+ memcpy(builder->string + builder->position, key, key_length);
+ builder->position += (int)key_length;
+
+ memcpy(builder->string + builder->position, "\":", 2);
+ builder->position += 2;
+
+ builder->position += snprintf(builder->string + builder->position, value_length + 1, "%zu", value);
+
+ memcpy(builder->string + builder->position, ",", 1);
+ builder->position++;
+
+ builder->key_state = PJSONB_TO_CLOSE;
+}
+
void pjsonb_set_float(struct pjsonb *builder, const char *key, float value) {
int value_length = snprintf(NULL, 0, "%f", value);
@@ -84,7 +120,7 @@ void pjsonb_set_float(struct pjsonb *builder, const char *key, float value) {
return;
}
- int key_length = strlen(key);
+ size_t key_length = strlen(key);
builder->string = realloc(builder->string, builder->position + value_length + 4 + key_length + 1);
@@ -92,7 +128,7 @@ void pjsonb_set_float(struct pjsonb *builder, const char *key, float value) {
builder->position++;
memcpy(builder->string + builder->position, key, key_length);
- builder->position += key_length;
+ builder->position += (int)key_length;
memcpy(builder->string + builder->position, "\":", 2);
builder->position += 2;
@@ -122,7 +158,7 @@ void pjsonb_set_bool(struct pjsonb *builder, const char *key, int value) {
return;
}
- int key_length = strlen(key);
+ size_t key_length = strlen(key);
builder->string = realloc(builder->string, builder->position + value_length + 4 + key_length + 1);
@@ -130,7 +166,7 @@ void pjsonb_set_bool(struct pjsonb *builder, const char *key, int value) {
builder->position++;
memcpy(builder->string + builder->position, key, key_length);
- builder->position += key_length;
+ builder->position += (int)key_length;
memcpy(builder->string + builder->position, "\":", 2);
builder->position += 2;
@@ -152,7 +188,7 @@ void pjsonb_set_string(struct pjsonb *builder, const char *key, const char *valu
builder->position++;
memcpy(builder->string + builder->position, value, value_length);
- builder->position += value_length;
+ builder->position += (int)value_length;
memcpy(builder->string + builder->position, "\",", 2);
builder->position += 2;
@@ -162,7 +198,7 @@ void pjsonb_set_string(struct pjsonb *builder, const char *key, const char *valu
return;
}
- int key_length = strlen(key);
+ size_t key_length = strlen(key);
builder->string = realloc(builder->string, builder->position + value_length + 6 + key_length + 1);
@@ -170,13 +206,13 @@ void pjsonb_set_string(struct pjsonb *builder, const char *key, const char *valu
builder->position++;
memcpy(builder->string + builder->position, key, key_length);
- builder->position += key_length;
+ builder->position += (int)key_length;
memcpy(builder->string + builder->position, "\":\"", 3);
builder->position += 3;
memcpy(builder->string + builder->position, value, value_length);
- builder->position += value_length;
+ builder->position += (int)value_length;
memcpy(builder->string + builder->position, "\",", 2);
builder->position += 2;
@@ -194,7 +230,7 @@ void pjsonb_enter_object(struct pjsonb *builder, const char *key) {
return;
}
- int key_length = strlen(key);
+ size_t key_length = strlen(key);
builder->string = realloc(builder->string, builder->position + 5 + key_length);
@@ -202,7 +238,7 @@ void pjsonb_enter_object(struct pjsonb *builder, const char *key) {
builder->position++;
memcpy(builder->string + builder->position, key, key_length);
- builder->position += key_length;
+ builder->position += (int)key_length;
memcpy(builder->string + builder->position, "\":{", 3);
builder->position += 3;
@@ -236,7 +272,7 @@ void pjsonb_enter_array(struct pjsonb *builder, const char *key) {
return;
}
- int key_length = strlen(key);
+ size_t key_length = strlen(key);
builder->string = realloc(builder->string, builder->position + 4 + key_length);
@@ -244,7 +280,7 @@ void pjsonb_enter_array(struct pjsonb *builder, const char *key) {
builder->position++;
memcpy(builder->string + builder->position, key, key_length);
- builder->position += key_length;
+ builder->position += (int)key_length;
memcpy(builder->string + builder->position, "\":[", 3);
builder->position += 3;
diff --git a/external/pjsonb.h b/external/pjsonb.h
index 02b84f4..6245286 100644
--- a/external/pjsonb.h
+++ b/external/pjsonb.h
@@ -33,6 +33,8 @@ void pjsonb_free(struct pjsonb *builder);
void pjsonb_set_int(struct pjsonb *builder, const char *key, int value);
+void pjsonb_set_size_t(struct pjsonb *builder, const char *key, size_t value);
+
void pjsonb_set_float(struct pjsonb *builder, const char *key, float value);
void pjsonb_set_bool(struct pjsonb *builder, const char *key, int value);
diff --git a/include/httpserver.h b/include/httpserver.h
index 780a0ed..fc71686 100644
--- a/include/httpserver.h
+++ b/include/httpserver.h
@@ -12,8 +12,8 @@ struct httpserver {
struct csocket_server server;
struct httpserver_client *sockets;
int *available_sockets;
- size_t sockets_capacity;
- size_t sockets_length;
+ int sockets_capacity;
+ int sockets_length;
void (*handler)(int, char*);
};
@@ -29,7 +29,7 @@ struct httpserver_response {
int headers_max_length;
struct httpserver_header *headers;
char *body;
- size_t body_length;
+ int body_length;
};
struct _httpserver_connection_data {
diff --git a/lib/httpclient.c b/lib/httpclient.c
index 1d4c6e9..24a7bcf 100644
--- a/lib/httpclient.c
+++ b/lib/httpclient.c
@@ -64,7 +64,7 @@ int httpclient_request(struct httpclient_request_params *request, struct httpcli
struct tstr_string http_request;
_httpclient_build_request(request, &http_request);
- int ret = csocket_client_send(&http_response->connection, http_request.string, http_request.length);
+ int ret = csocket_client_send(&http_response->connection, http_request.string, (int)http_request.length);
if (ret == CSOCKET_CLIENT_ERROR) {
csocket_client_close(&http_response->connection);
@@ -97,7 +97,7 @@ int httpclient_request(struct httpclient_request_params *request, struct httpcli
}
if (http_response->finished == 0) {
- int chunk_size_left = http_response->chunk_length - http_response->body_length;
+ int chunk_size_left = (int)((size_t)http_response->chunk_length - http_response->body_length);
read_chunk:
diff --git a/lib/httpserver.c b/lib/httpserver.c
index d6d6b29..1995e56 100644
--- a/lib/httpserver.c
+++ b/lib/httpserver.c
@@ -45,9 +45,9 @@ void httpserver_start_server(struct httpserver *server) {
}
void httpserver_stop_server(struct httpserver *server) {
- printf("[httpserver]: Stopping server with %zu sockets.\n", server->sockets_length);
+ printf("[httpserver]: Stopping server with %d sockets.\n", server->sockets_length);
- for (size_t i = 0; i < server->sockets_capacity; i++) {
+ for (int i = 0; i < server->sockets_capacity; i++) {
if (server->sockets[i].socket == -1) continue;
cthreads_thread_cancel(server->sockets[i].thread);
@@ -60,7 +60,7 @@ void httpserver_stop_server(struct httpserver *server) {
}
void _httpserver_add_available_socket(struct httpserver *server, int socket_index) {
- for (size_t i = 0; i < server->sockets_capacity; i++) {
+ for (int i = 0; i < server->sockets_capacity; i++) {
if (server->available_sockets[i] != 0) continue;
server->available_sockets[i] = socket_index + 1;
@@ -82,13 +82,13 @@ void httpserver_disconnect_client(struct httpserver *server, struct csocket_serv
}
int _httpserver_select_position(struct httpserver *server) {
- for (size_t i = 0; i < server->sockets_capacity; i++) {
+ for (int i = 0; i < server->sockets_capacity; i++) {
if (server->available_sockets[i] == 0) continue;
int socket_index = server->available_sockets[i] - 1;
server->available_sockets[i] = 0;
- printf("[httpserver]: Selected socket index: %d/%zu.\n", socket_index, server->sockets_capacity);
+ printf("[httpserver]: Selected socket index: %d/%d.\n", socket_index, server->sockets_capacity);
return socket_index;
}
@@ -97,7 +97,7 @@ int _httpserver_select_position(struct httpserver *server) {
server->sockets = realloc(server->sockets, server->sockets_capacity * sizeof(struct httpserver_client));
server->available_sockets = realloc(server->available_sockets, server->sockets_capacity * sizeof(int));
- for (size_t i = server->sockets_capacity / 2; i < server->sockets_capacity; i++) {
+ for (int i = server->sockets_capacity / 2; i < server->sockets_capacity; i++) {
server->sockets[i].thread = (struct cthreads_thread) { 0 };
server->sockets[i].thread_data = NULL;
server->sockets[i].socket = -1;
@@ -109,7 +109,7 @@ int _httpserver_select_position(struct httpserver *server) {
server->available_sockets[server->sockets_length] = 0;
- printf("[httpserver]: Reallocated sockets array and selected socket index: %zu/%zu.\n", server->sockets_length, server->sockets_capacity);
+ printf("[httpserver]: Reallocated sockets array and selected socket index: %d/%d.\n", server->sockets_length, server->sockets_capacity);
return server->sockets_length;
}
@@ -192,7 +192,8 @@ void httpserver_handle_request(struct httpserver *server, void (*callback)(struc
int socket_index = _httpserver_select_position(server);
server->sockets_length++;
- printf("[httpserver]: Connection accepted.\n - Socket: %d\n - Socket index: %d\n - IP: %s\n - Port: %d\n", socket, socket_index, csocket_server_client_get_ip(&client), csocket_server_client_get_port(&client));
+ char ip[16 + 1];
+ printf("[httpserver]: Connection accepted.\n - Socket: %d\n - Socket index: %d\n - IP: %s\n - Port: %d\n", socket, socket_index, csocket_server_client_get_ip(&client, ip), csocket_server_client_get_port(&client));
struct httpserver_client http_client = {
.thread = { 0 },
@@ -311,31 +312,31 @@ char *_httpserver_get_status_text(int status) {
return "Unknown";
}
-size_t _calculate_response_length(struct httpserver_response *response) {
- size_t length = 0;
+int _calculate_response_length(struct httpserver_response *response) {
+ int length = 0;
length += sizeof("HTTP/1.1 ");
length += 3;
- length += strlen(_httpserver_get_status_text(response->status));
+ length += (int)strlen(_httpserver_get_status_text(response->status));
length += 2;
for (int i = 0; i < response->headers_length; i++) {
- length += strlen(response->headers[i].key);
- length += strlen(response->headers[i].value);
+ length += (int)strlen(response->headers[i].key);
+ length += (int)strlen(response->headers[i].value);
length += 4;
}
length += 2;
if (response->body != NULL) {
- length += response->body_length;
+ length += (int)response->body_length;
}
return length;
}
void httpserver_send_response(struct httpserver_response *response) {
- size_t length = _calculate_response_length(response);
+ int length = _calculate_response_length(response);
char *response_string = frequenc_safe_malloc(length);
size_t response_position = 0;
@@ -358,7 +359,7 @@ void httpserver_send_response(struct httpserver_response *response) {
tstr_append(response_string, "\r\n", &response_position, 0);
if (response->body != NULL) {
- tstr_append(response_string, response->body, &response_position, response->body_length);
+ tstr_append(response_string, response->body, &response_position, (int)response->body_length);
}
csocket_server_send(response->client, response_string, length);
diff --git a/lib/main.c b/lib/main.c
index 8665d2e..c3b3d05 100644
--- a/lib/main.c
+++ b/lib/main.c
@@ -633,7 +633,7 @@ void callback(struct csocket_server_client *client, int socket_index, struct htt
struct tstr_string encoded_track = { 0 };
char payload_length[4];
frequenc_encode_track(&decoded_track, &encoded_track);
- frequenc_stringify_int(encoded_track.length, payload_length, sizeof(payload_length));
+ frequenc_stringify_int((int)encoded_track.length, payload_length, sizeof(payload_length));
struct httpserver_response response = {
.client = client,
@@ -650,7 +650,7 @@ void callback(struct csocket_server_client *client, int socket_index, struct htt
},
.headers_length = 2,
.body = encoded_track.string,
- .body_length = encoded_track.length
+ .body_length = (int)encoded_track.length
};
httpserver_send_response(&response);
@@ -685,7 +685,7 @@ void callback(struct csocket_server_client *client, int socket_index, struct htt
printf("[main]: Done loading tracks request: %s\n", identifier->value);
char payload_length[8 + 1];
- frequenc_stringify_int(result.length, payload_length, sizeof(payload_length));
+ frequenc_stringify_int((int)result.length, payload_length, sizeof(payload_length));
struct httpserver_response response = {
.client = client,
@@ -702,7 +702,7 @@ void callback(struct csocket_server_client *client, int socket_index, struct htt
},
.headers_length = 2,
.body = result.string,
- .body_length = result.length
+ .body_length = (int)result.length
};
httpserver_send_response(&response);
@@ -1259,3 +1259,11 @@ int main(void) {
httpserver_handle_request(&server, callback, ws_callback, disconnect_callback);
}
+
+#ifdef _WIN32
+ int APIENTRY WinMain(HINSTANCE h_instance, HINSTANCE h_prev_instance, LPSTR lp_cmd_line, int n_cmd_show) {
+ (void) h_instance; (void) h_prev_instance; (void) lp_cmd_line; (void) n_cmd_show;
+
+ return main();
+ }
+#endif
diff --git a/lib/track.c b/lib/track.c
index 83f500e..a13b314 100644
--- a/lib/track.c
+++ b/lib/track.c
@@ -53,7 +53,7 @@ void _read_utf(struct _decoder_class *decoder_class, struct tstr_string *result)
}
int frequenc_decode_track(struct frequenc_track_info *result, const struct tstr_string *track) {
- int output_length = b64_decoded_size(track->string, track->length) + 1;
+ size_t output_length = b64_decoded_size(track->string, (int)track->length);
unsigned char *output = frequenc_safe_malloc(output_length * sizeof(unsigned char));
memset(output, 0, output_length);
@@ -72,7 +72,7 @@ int frequenc_decode_track(struct frequenc_track_info *result, const struct tstr_
int buffer_length = _read_int(&buf) & ~(1 << 30);
if (buffer_length != output_length - 4 - 1) {
- printf("[track]: Failed to decode track.\n - Reason: Track binary length doesn't match track set length.\n - Expected: %d\n - Actual: %d\n", buffer_length, output_length - 4 - 1);
+ printf("[track]: Failed to decode track.\n - Reason: Track binary length doesn't match track set length.\n - Expected: %d\n - Actual: %zu\n", buffer_length, output_length - 4 - 1);
frequenc_unsafe_free(output);
@@ -110,7 +110,7 @@ int frequenc_decode_track(struct frequenc_track_info *result, const struct tstr_
_read_utf(&buf, &result->source_name);
if (buf.position != output_length - 1) {
- printf("[track]: Failed to decode track.\n - Reason: Track binary length doesn't match the end of the sequence of reads.\n - Expected: %d\n - Actual: %d\n", buf.position, output_length - 1);
+ printf("[track]: Failed to decode track.\n - Reason: Track binary length doesn't match the end of the sequence of reads.\n - Expected: %d\n - Actual: %zu\n", buf.position, output_length - 1);
frequenc_unsafe_free(output);
@@ -166,7 +166,7 @@ void _write_long(unsigned char *buffer, size_t *position, uint64_t value) {
}
void _write_utf(unsigned char *buffer, size_t *position, struct tstr_string value) {
- _write_unsigned_short(buffer, position, value.length);
+ _write_unsigned_short(buffer, position, (int)value.length);
memcpy(buffer + *position, value.string, value.length);
*position += value.length;
@@ -258,7 +258,7 @@ void frequenc_track_info_to_json(struct frequenc_track_info *track_info, struct
pjsonb_set_string(track_json, "title", track_info->title.string, track_info->title.length);
pjsonb_set_string(track_json, "author", track_info->author.string, track_info->author.length);
- pjsonb_set_int(track_json, "length", track_info->length);
+ pjsonb_set_size_t(track_json, "length", track_info->length);
pjsonb_set_string(track_json, "identifier", track_info->identifier.string, track_info->identifier.length);
pjsonb_set_bool(track_json, "is_stream", track_info->is_stream);
pjsonb_set_string(track_json, "uri", track_info->uri.string, track_info->uri.length);
@@ -276,7 +276,7 @@ void frequenc_partial_track_info_to_json(struct frequenc_track_info *track_info,
pjsonb_set_string(track_json, "title", track_info->title.string, track_info->title.length);
pjsonb_set_string(track_json, "author", track_info->author.string, track_info->author.length);
- pjsonb_set_int(track_json, "length", track_info->length);
+ pjsonb_set_size_t(track_json, "length", track_info->length);
pjsonb_set_string(track_json, "identifier", track_info->identifier.string, track_info->identifier.length);
pjsonb_set_bool(track_json, "is_stream", track_info->is_stream);
pjsonb_set_string(track_json, "uri", track_info->uri.string, track_info->uri.length);
diff --git a/lib/websocket.c b/lib/websocket.c
index 01b08c6..da75a2a 100644
--- a/lib/websocket.c
+++ b/lib/websocket.c
@@ -89,7 +89,7 @@ void frequenc_key_to_base64(char *key, char *output) {
SHA1C_CTX sha;
SHA1CInit(&sha);
- SHA1CUpdate(&sha, (const unsigned char *)key, strlen(key));
+ SHA1CUpdate(&sha, (const unsigned char *)key, (uint32_t)strlen(key));
SHA1CFinal((unsigned char *)results, &sha);
b64_encode((unsigned char *)results, output, sizeof(results));
@@ -114,7 +114,6 @@ void frequenc_set_ws_response_body(struct frequenc_ws_message *response, char *b
void frequenc_send_ws_response(struct frequenc_ws_message *response) {
size_t payload_start_index = 2;
- size_t payload_length = response->payload_length;
unsigned int mask[] = { 0, 0, 0, 0 };
@@ -127,32 +126,28 @@ void frequenc_send_ws_response(struct frequenc_ws_message *response) {
payload_start_index += 4;
- if (payload_length >= 65536) {
- payload_start_index += 8;
- payload_length = 127;
- } else if (payload_length > 125) {
- payload_start_index += 2;
- payload_length = 126;
- }
+ if (response->payload_length >= 65536) payload_start_index += 8;
+ else if (response->payload_length > 125) payload_start_index += 2;
unsigned char *buffer = frequenc_safe_malloc(payload_start_index + response->payload_length * sizeof(unsigned char));
buffer[0] = response->opcode | 128;
- buffer[1] = payload_length;
- if (payload_length == 126) {
- buffer[2] = response->payload_length >> 8;
- buffer[3] = response->payload_length & 0xFF;
- } else if (payload_length == 127) {
+ if (response->payload_length >= 65536) {
buffer[2] = buffer[3] = 0;
- buffer[4] = response->payload_length >> 56;
- buffer[5] = response->payload_length >> 48;
- buffer[6] = response->payload_length >> 40;
- buffer[7] = response->payload_length >> 32;
- buffer[8] = response->payload_length >> 24;
- buffer[9] = response->payload_length >> 16;
- buffer[10] = response->payload_length >> 8;
- buffer[11] = response->payload_length & 0xFF;
+ buffer[4] = (unsigned char)(response->payload_length >> 56);
+ buffer[5] = (unsigned char)(response->payload_length >> 48);
+ buffer[6] = (unsigned char)(response->payload_length >> 40);
+ buffer[7] = (unsigned char)(response->payload_length >> 32);
+ buffer[8] = (unsigned char)(response->payload_length >> 24);
+ buffer[9] = (unsigned char)(response->payload_length >> 16);
+ buffer[10] = (unsigned char)(response->payload_length >> 8);
+ buffer[11] = (unsigned char)(response->payload_length & 0xFF);
+ } else if (response->payload_length > 125) {
+ buffer[2] = (unsigned char)(response->payload_length >> 8);
+ buffer[3] = (unsigned char)(response->payload_length & 0xFF);
+ } else {
+ buffer[1] = (unsigned char)response->payload_length;
}
memcpy(buffer + payload_start_index, response->buffer, response->payload_length);
@@ -167,7 +162,13 @@ void frequenc_send_ws_response(struct frequenc_ws_message *response) {
buffer[payload_start_index + i] ^= mask[i & 3];
}
- csocket_server_send(response->client, (char *)buffer, payload_start_index + response->payload_length);
+ if (csocket_server_send(response->client, (char *)buffer, (int)(payload_start_index + response->payload_length)) == PCLL_ERROR) {
+ perror("[websocket]: Failed to send message");
+
+ frequenc_unsafe_free(buffer);
+
+ return;
+ }
frequenc_unsafe_free(buffer);
@@ -335,7 +336,6 @@ int frequenc_connect_ws_client(struct httpclient_request_params *request, struct
int frequenc_send_text_ws_client(struct httpclient_response *response, char *message, size_t message_length) {
int payload_start_index = 2;
- size_t payload_length = message_length;
unsigned int mask[] = { 0, 0, 0, 0 };
@@ -348,32 +348,28 @@ int frequenc_send_text_ws_client(struct httpclient_response *response, char *mes
payload_start_index += 4;
- if (payload_length >= 65536) {
- payload_start_index += 8;
- payload_length = 127;
- } else if (payload_length > 125) {
- payload_start_index += 2;
- payload_length = 126;
- }
+ if (message_length >= 65536) payload_start_index += 8;
+ else if (message_length > 125) payload_start_index += 2;
unsigned char *buffer = frequenc_safe_malloc(payload_start_index + message_length * sizeof(unsigned char));
buffer[0] = 1 | 128;
- buffer[1] = payload_length;
- if (payload_length == 126) {
- buffer[2] = message_length >> 8;
- buffer[3] = message_length & 0xFF;
- } else if (payload_length == 127) {
+ if (message_length >= 65536) {
buffer[2] = buffer[3] = 0;
- buffer[4] = message_length >> 56;
- buffer[5] = message_length >> 48;
- buffer[6] = message_length >> 40;
- buffer[7] = message_length >> 32;
- buffer[8] = message_length >> 24;
- buffer[9] = message_length >> 16;
- buffer[10] = message_length >> 8;
- buffer[11] = message_length & 0xFF;
+ buffer[4] = (unsigned char)(message_length >> 56);
+ buffer[5] = (unsigned char)(message_length >> 48);
+ buffer[6] = (unsigned char)(message_length >> 40);
+ buffer[7] = (unsigned char)(message_length >> 32);
+ buffer[8] = (unsigned char)(message_length >> 24);
+ buffer[9] = (unsigned char)(message_length >> 16);
+ buffer[10] = (unsigned char)(message_length >> 8);
+ buffer[11] = (unsigned char)(message_length & 0xFF);
+ } else if (message_length > 125) {
+ buffer[2] = (unsigned char)(message_length >> 8);
+ buffer[3] = (unsigned char)(message_length & 0xFF);
+ } else {
+ buffer[1] = (unsigned char)message_length;
}
memcpy(buffer + payload_start_index, message, message_length);
@@ -388,7 +384,7 @@ int frequenc_send_text_ws_client(struct httpclient_response *response, char *mes
buffer[payload_start_index + i] ^= mask[i & 3];
}
- if (csocket_client_send(&response->connection, (char *)buffer, payload_start_index + message_length) == PCLL_ERROR) {
+ if (csocket_client_send(&response->connection, (char *)buffer, (int)(payload_start_index + message_length)) == PCLL_ERROR) {
perror("[websocket]: Failed to send message");
frequenc_unsafe_free(buffer);