Skip to content

Commit 22a7f4f

Browse files
committed
Fix bugs after refactoring
Signed-off-by: Elmurod Talipov <elmurod.talipov@gmail.com>
1 parent 7a6dd8a commit 22a7f4f

3 files changed

Lines changed: 18 additions & 21 deletions

File tree

include/telebot-core.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -478,17 +478,14 @@ telebot_core_response_t telebot_core_send_video_note(telebot_core_handler_t core
478478
* @param[in] count Number of photos in the array (2–10).
479479
* @param[in] disable_notification Sends the message silently. Users will receive a notification with no sound.
480480
* @param[in] reply_to_message_id If the message is a reply, ID of the original message.
481-
* @param[out] response Response data that contains the sent messages on success. It MUST be freed with #telebot_core_put_response().
482-
* @return on Success, TELEBOT_ERROR_NONE is returned, otherwise a negative error value.
481+
* @return #telebot_core_response_t response that contains the sent message,
482+
* which MUST be released with #telebot_core_put_response(), or null if allocation fails.
483+
* Response code should be checked with #teleobot_core_get_response_code(),
484+
* before getting data with #telebot_core_get_response_data().
483485
*/
484-
telebot_error_e telebot_core_send_media_group(
485-
telebot_core_handler_t *core_h,
486-
long long int chat_id,
487-
char *media_paths[],
488-
int count,
489-
bool disable_notification,
490-
int reply_to_message_id,
491-
telebot_core_response_t *response);
486+
telebot_core_response_t telebot_core_send_media_group(telebot_core_handler_t core_h,
487+
long long int chat_id, char *media_paths[], int count, bool disable_notification,
488+
int reply_to_message_id);
492489

493490
/**
494491
* @brief Send point on the map.

src/telebot-core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <stdio.h>
2424
#include <stdlib.h>
2525
#include <string.h>
26+
#include <json.h>
27+
#include <json_object.h>
2628
#include <telebot-common.h>
2729
#include <telebot-core.h>
2830
#include <telebot-private.h>
@@ -65,12 +67,13 @@ telebot_core_create(telebot_core_handler_t *core_h, const char *token)
6567

6668
*core_h = NULL;
6769

68-
telebot_core_handler_t _core_h = malloc(sizeof(telebot_core_handler_t));
70+
telebot_core_handler_t _core_h = malloc(sizeof(struct telebot_core_handler));
6971
if (_core_h == NULL)
7072
{
7173
ERR("Failed to allocate memory");
7274
return TELEBOT_ERROR_OUT_OF_MEMORY;
7375
}
76+
7477
_core_h->token = strdup(token);
7578
if (_core_h->token == NULL)
7679
{

src/telebot.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ static const char *telebot_update_type_str[TELEBOT_UPDATE_TYPE_MAX] = {
4949
"shipping_query",
5050
"pre_checkout_query",
5151
"poll",
52-
"poll_answer"
53-
};
52+
"poll_answer"};
5453

5554
static void telebot_put_user(telebot_user_t *user);
5655
static void telebot_put_chat_photo(telebot_chat_photo_t *photo);
@@ -619,17 +618,15 @@ telebot_error_e telebot_send_video_note(telebot_handler_t handle, long long int
619618
telebot_error_e telebot_send_media_group(telebot_handler_t handle, long long int chat_id, char *media_paths[],
620619
int count, bool disable_notification, int reply_to_message_id)
621620
{
622-
telebot_hdata_t *_handle = (telebot_hdata_t *)handle;
623-
if (_handle == NULL)
624-
return TELEBOT_ERROR_NOT_SUPPORTED;
621+
telebot_core_response_t response;
625622

626623
if ((media_paths == NULL) || (count < 2) || (count > 10))
627624
return TELEBOT_ERROR_INVALID_PARAMETER;
628625

629-
telebot_core_response_t response;
630-
telebot_error_e ret = telebot_core_send_media_group(_handle->core_h, chat_id, media_paths, count, disable_notification,
631-
reply_to_message_id, &response);
632-
telebot_core_put_response(&response);
626+
response = telebot_core_send_media_group(handle->core_h, chat_id, media_paths, count, disable_notification,
627+
reply_to_message_id);
628+
int ret = telebot_core_get_response_code(response);
629+
telebot_core_put_response(response);
633630
return ret;
634631
}
635632

@@ -1603,7 +1600,7 @@ telebot_error_e telebot_put_chat(telebot_chat_t *chat)
16031600
telebot_put_chat_photo(chat->photo);
16041601
TELEBOT_SAFE_FREE(chat->photo);
16051602

1606-
for (size_t index=0; index < chat->count_active_usernames; index++)
1603+
for (size_t index = 0; index < chat->count_active_usernames; index++)
16071604
TELEBOT_SAFE_FREE(chat->active_usernames[index]);
16081605
TELEBOT_SAFE_FREE(chat->active_usernames);
16091606
chat->count_active_usernames = 0;

0 commit comments

Comments
 (0)