refactor(methods): remove useless include

This commit is contained in:
2026-03-17 00:51:04 +01:00
parent 417b4f9239
commit 6c30a42872
2 changed files with 13 additions and 8 deletions
-1
View File
@@ -2,7 +2,6 @@
#define TGBOT_METHODS_H #define TGBOT_METHODS_H
#include "types.h" #include "types.h"
#include <json-c/json.h>
/* Retrieve update */ /* Retrieve update */
int tgbot_get_update(tgbot_s *bot, tgbot_update_s *update, Callback cbq_handler); int tgbot_get_update(tgbot_s *bot, tgbot_update_s *update, Callback cbq_handler);
+13 -7
View File
@@ -10,7 +10,7 @@
#define opt_size(arr) (sizeof(arr) / sizeof(arr[0])) #define opt_size(arr) (sizeof(arr) / sizeof(arr[0]))
static size_t write_callback(void *ptr, size_t size, size_t nmemb, char *userdata) { static size_t write_callback(const void *ptr, size_t size, size_t nmemb, char *userdata) {
size_t real_size = size * nmemb; size_t real_size = size * nmemb;
struct memory_buffer *mem = (struct memory_buffer *)userdata; struct memory_buffer *mem = (struct memory_buffer *)userdata;
@@ -53,8 +53,12 @@ static int tgbot_request(const char *url, struct memory_buffer **mb, json_object
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)write_callback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, *mb); curl_easy_setopt(curl, CURLOPT_WRITEDATA, *mb);
} else { } else {
struct memory_buffer *mb_f = malloc(sizeof *mb_f);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, discard_callback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, discard_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL); curl_easy_setopt(curl, CURLOPT_WRITEDATA, mb_f);
if (mb_f) {
free(mb_f);
}
} }
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
@@ -163,11 +167,13 @@ int tgbot_get_me(const tgbot_s *bot, tgbot_me_s *me) {
char url[URL_LEN]; char url[URL_LEN];
snprintf(url, sizeof(url), "%sgetMe", bot->api); snprintf(url, sizeof(url), "%sgetMe", bot->api);
struct memory_buffer *mb; struct memory_buffer *mb = {0};
int ret = tgbot_request(url, &mb, NULL); int ret = tgbot_request(url, &mb, NULL);
if (ret != 0) { if (ret != 0) {
free(mb->data); if (mb) {
free(mb); free(mb->data);
free(mb);
}
return -1; return -1;
} }
@@ -196,12 +202,12 @@ int tgbot_get_me(const tgbot_s *bot, tgbot_me_s *me) {
} }
int tgbot_send_message(const tgbot_s *bot, int64_t chat_id, const char *text, const char *parse_mode, int tgbot_send_message(const tgbot_s *bot, int64_t chat_id, const char *text, const char *parse_mode,
tgbot_inlinekeyboard_s *keyboard) { tgbot_inlinekeyboard_s *reply_markup) {
tgbot_option_s options[4] = { tgbot_option_s options[4] = {
{"chat_id", &chat_id, tgbot_opt_int64}, {"chat_id", &chat_id, tgbot_opt_int64},
{"text", (void *)text, tgbot_opt_string}, {"text", (void *)text, tgbot_opt_string},
{"parse_mode", (void *)parse_mode, tgbot_opt_string}, {"parse_mode", (void *)parse_mode, tgbot_opt_string},
{"reply_markup", keyboard, tgbot_opt_inlinekeyboard}, {"reply_markup", reply_markup, tgbot_opt_inlinekeyboard},
}; };
return tgbot_execute_method(bot, "sendMessage", options, opt_size(options)); return tgbot_execute_method(bot, "sendMessage", options, opt_size(options));