From 0474bd1bce6df2f92e71d065b20a8fd4694945e4 Mon Sep 17 00:00:00 2001 From: rogo Date: Sat, 18 Apr 2020 15:03:43 +0200 Subject: [PATCH] reuse of http handler --- src/plugin.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index 97dce13..c6098ed 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -143,6 +143,7 @@ int ts3plugin_init() { printf("PLUGIN: App path: %s\nResources path: %s\nConfig path: %s\nPlugin path: %s\n", appPath, resourcesPath, configPath, pluginPath); curl_global_init(CURL_GLOBAL_ALL); + curl = curl_easy_init(); return 0; /* 0 = success, 1 = failure, -2 = failure but client will not show a "failed to load" warning */ /* -2 is a very special case and should only be used if a plugin displays a dialog (e.g. overlay) asking the user to disable @@ -155,6 +156,7 @@ void ts3plugin_shutdown() { /* Your plugin cleanup code here */ printf("PLUGIN: shutdown\n"); + curl_easy_cleanup(curl); curl_global_cleanup(); /* @@ -853,7 +855,7 @@ void ts3plugin_onTalkStatusChangeEvent(uint64 serverConnectionHandlerID, int sta char name[512]; if(ts3Functions.getClientDisplayName(serverConnectionHandlerID, clientID, name, 512) == ERROR_ok) { if (clientID == myClientID) { - curl = curl_easy_init(); + //curl = curl_easy_init(); if (curl) { if (status == STATUS_TALKING) { curl_easy_setopt(curl, CURLOPT_URL, LED_URL_SAVE); @@ -867,7 +869,7 @@ void ts3plugin_onTalkStatusChangeEvent(uint64 serverConnectionHandlerID, int sta res = curl_easy_perform(curl); } } - curl_easy_cleanup(curl); + //curl_easy_cleanup(curl); } } } @@ -937,22 +939,23 @@ int ts3plugin_onClientPokeEvent(uint64 serverConnectionHandlerID, anyID fromClie if(ffIgnored) { return 0; /* Client will block anyways, doesn't matter what we return */ } - curl = curl_easy_init(); + //curl = curl_easy_init(); - curl_easy_setopt(curl, CURLOPT_URL, LED_URL_POKE); - res = curl_easy_perform(curl); - Sleep(500); - res = curl_easy_perform(curl); - Sleep(500); - res = curl_easy_perform(curl); - Sleep(500); - res = curl_easy_perform(curl); - Sleep(500); - - curl_easy_setopt(curl, CURLOPT_URL, LED_URL_OFF); - res = curl_easy_perform(curl); - curl_easy_cleanup(curl); + if (curl) { + curl_easy_setopt(curl, CURLOPT_URL, LED_URL_POKE); + res = curl_easy_perform(curl); + Sleep(500); + res = curl_easy_perform(curl); + Sleep(500); + res = curl_easy_perform(curl); + Sleep(500); + res = curl_easy_perform(curl); + Sleep(500); + curl_easy_setopt(curl, CURLOPT_URL, LED_URL_OFF); + res = curl_easy_perform(curl); + //curl_easy_cleanup(curl); + } return 0; /* 0 = handle normally, 1 = client will ignore the poke */ }