summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2021-03-18 18:19:25 +0100
committersijanec <anton@sijanec.eu>2021-03-18 18:19:25 +0100
commit19ae55a7b714e8f30ad2419e2a4a24a8c3d23bd9 (patch)
treecc628014c56f46577b721fba40e5ff5f4fd4293e
parentremoved network debugger (diff)
downloaddiscord.c-19ae55a7b714e8f30ad2419e2a4a24a8c3d23bd9.tar
discord.c-19ae55a7b714e8f30ad2419e2a4a24a8c3d23bd9.tar.gz
discord.c-19ae55a7b714e8f30ad2419e2a4a24a8c3d23bd9.tar.bz2
discord.c-19ae55a7b714e8f30ad2419e2a4a24a8c3d23bd9.tar.lz
discord.c-19ae55a7b714e8f30ad2419e2a4a24a8c3d23bd9.tar.xz
discord.c-19ae55a7b714e8f30ad2419e2a4a24a8c3d23bd9.tar.zst
discord.c-19ae55a7b714e8f30ad2419e2a4a24a8c3d23bd9.zip
-rw-r--r--Makefile21
-rw-r--r--README.md3
-rw-r--r--src/api.c18
-rw-r--r--src/i18n.h2
4 files changed, 29 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 1ea322b..f0511ae 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,20 @@
+DESTDIR=/
+
default:
- gcc -Wall -pedantic -g -Ilib -Isrc -I. -pthread $$(ncursesw6-config --cflags --libs) src/main.c -lcurl -lformw -lm -odiscord.c
-prepare:
- wget https://raw.githubusercontent.com/DaveGamble/cJSON/master/cJSON.c -O lib/cJSON.c
- wget https://raw.githubusercontent.com/DaveGamble/cJSON/master/cJSON.h -O lib/cJSON.h
+ gcc -Wall -pedantic -g -Isrc -I. -pthread $$(ncursesw6-config --cflags --libs) src/main.c -lcjson -lcurl -lformw -lm -odiscord.c
+
+install:
+ mkdir -p $(DESTDIR)/usr/bin/
+ cp discord.c $(DESTDIR)/usr/bin/
+
+distclean:
+ rm discord.c -f
+
clean:
- rm lib/cJSON.c lib/cJSON.h
+ rm discord.c -f
+
+prepare:
+ sudo apt install libncursesw6 libcurl4-openssl-dev libcjson-dev -y
+
valgrind:
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt --suppressions=/usr/lib/valgrind/ncurses.supp --suppressions=misc/openssl.supp ./discord.c
diff --git a/README.md b/README.md
index 295148c..4b626b2 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,8 @@ an alternative client for the discord messaging platform, written in the C progr
* GNU compiler collection
* GNU Make
* libcurl 7.17.0 or newer with HTTPS support
-* ncursesw 6
+* ncursesw6
+* libcjson-dev
## instructions
diff --git a/src/api.c b/src/api.c
index 3460edb..cd646dc 100644
--- a/src/api.c
+++ b/src/api.c
@@ -7,8 +7,7 @@
#include <i18n.h>
#include <string.h>
#include <lib.c>
-#include <cJSON.h>
-#include <cJSON.c>
+#include <cjson/cJSON.h>
#include <time.h>
#include <stdarg.h>
#include <printf.h>
@@ -496,14 +495,17 @@ int dc_fetch_channels (struct dc_guild * g) {
char * topic = cJSON_GetStringValue(cJSON_GetObjectItem(channel, "topic"));
char * name = cJSON_GetStringValue(cJSON_GetObjectItem(channel, "name"));
char * id = cJSON_GetStringValue(cJSON_GetObjectItem(channel, "id"));
- double type = cJSON_GetNumberValue(cJSON_GetObjectItem(channel, "type"));
- double slowmode = cJSON_GetNumberValue(cJSON_GetObjectItem(channel, "rate_limit_per_user"));
- if (!id || !name || type == NAN) {
- DC_CLIENT_ERROR(c, "!id || !name || type == NAN");
+ cJSON * type = cJSON_GetObjectItem(channel, "type");
+ cJSON * jsonslowmode = cJSON_GetObjectItem(channel, "rate_limit_per_user");
+ if (!cJSON_IsNumber(type) || !id || !name) {
+ DC_CLIENT_ERROR(c, "!cJSON_IsNumber(jsontype) || !id || !name");
continue;
}
- if (type != 0) /* if it's not a text channel (z. B. voice channel, category, ...) */
+ if (type->valueint != 0) /* if it's not a text channel (z. B. voice channel, category, ...) */
continue;
+ int slowmode = 0;
+ if (cJSON_IsNumber(jsonslowmode))
+ slowmode = jsonslowmode->valueint;
if (!topic)
topic = "";
unsigned long long int idull = strtoull(id, NULL, 10);
@@ -523,7 +525,7 @@ int dc_fetch_channels (struct dc_guild * g) {
g->channels[g->channels_sizeof-1]->guild = g;
g->channels[g->channels_sizeof-1]->messages = NULL;
g->channels[g->channels_sizeof-1]->messages_sizeof = 0;
- g->channels[g->channels_sizeof-1]->slowmode = slowmode != NAN ? slowmode : 0;
+ g->channels[g->channels_sizeof-1]->slowmode = slowmode;
}
if (DC_CUE(c, c->guilds_lock)) {rs = -8; goto rc;}
rc:
diff --git a/src/i18n.h b/src/i18n.h
index 955d810..53446b9 100644
--- a/src/i18n.h
+++ b/src/i18n.h
@@ -21,6 +21,6 @@
#define DC_I18N_HITRL "zmanjkalo dovoljenih zahtev na strežnik. API nit bo čakala " /* and then print seconds */
#define DC_I18N_UI_CNF "nepoznan ukaz"
#define DC_I18N_UI_NOT_JOINED "niste pridruženi v kanal. uporabite ukaz /pridruži"
-#define DC_I18N_CHANNEL_WILL_BE_REMOVED "kanal bo odstranjen iz lokalnega seznama kanalov"
+#define DC_I18N_CHANNEL_WILL_BE_REMOVED "kanal bo odstranjen z lokalnega seznama kanalov"
#define DC_I18N_UI_EMPTYMSG "ne moreš poslati praznega sporočila."
#define DC_I18N_UI_SLOWMODE "na tem kanalu po poslanem sporočilu novega ne smeš poslati %ds. počakaj še %ds in poskusi znova."