mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
discordlog: escape linebreaks in json string
This commit is contained in:
parent
f446bd243c
commit
06b95a4487
1 changed files with 17 additions and 2 deletions
|
@ -190,11 +190,26 @@ void lbrylog(const char *format, ...)
|
||||||
char message[YAAMP_SMALLBUFSIZE+1024];
|
char message[YAAMP_SMALLBUFSIZE+1024];
|
||||||
sprintf(message, "{\"username\":\"stratum\", \"content\":\"%s: %s\"}", buffer2, buffer);
|
sprintf(message, "{\"username\":\"stratum\", \"content\":\"%s: %s\"}", buffer2, buffer);
|
||||||
discordlog(message);
|
discordlog(message);
|
||||||
debuglog(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void discordlog(const char *message)
|
void discordlog(const char *message)
|
||||||
{
|
{
|
||||||
|
char stripped[YAAMP_SMALLBUFSIZE + 1024];
|
||||||
|
|
||||||
|
char *src = (char *)message;
|
||||||
|
char *dst = stripped;
|
||||||
|
|
||||||
|
while (*src && (dst - stripped < YAAMP_SMALLBUFSIZE + 1024 - 1)) {
|
||||||
|
if (*src == '\n') {
|
||||||
|
*dst++ = '\\';
|
||||||
|
*dst++ = 'n';
|
||||||
|
src++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*dst++ = *src++;
|
||||||
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
|
||||||
const char *WEBHOOK_URL = "https://discord.com/api/webhooks/1022124125340303461/htOuQOcax_A_whyya7eNz2odDqO45g3PWlTuVQwiLuz7d2peFpLa-pEpBakVKDX9I9s-";
|
const char *WEBHOOK_URL = "https://discord.com/api/webhooks/1022124125340303461/htOuQOcax_A_whyya7eNz2odDqO45g3PWlTuVQwiLuz7d2peFpLa-pEpBakVKDX9I9s-";
|
||||||
CURL *curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
if (!curl)
|
if (!curl)
|
||||||
|
@ -202,7 +217,7 @@ void discordlog(const char *message)
|
||||||
|
|
||||||
struct curl_slist *headers = curl_slist_append(NULL, "Content-Type: application/json");
|
struct curl_slist *headers = curl_slist_append(NULL, "Content-Type: application/json");
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, WEBHOOK_URL);
|
curl_easy_setopt(curl, CURLOPT_URL, WEBHOOK_URL);
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, message);
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, stripped);
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
|
|
||||||
/* Perform the request */
|
/* Perform the request */
|
||||||
|
|
Loading…
Add table
Reference in a new issue