Skip to content

Commit 27f3ea5

Browse files
committed
Bump version to 6.3.0 and fix bugs after refactoring
Signed-off-by: Elmurod Talipov <elmurod.talipov@gmail.com>
1 parent 7a6dd8a commit 27f3ea5

4 files changed

Lines changed: 56 additions & 59 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
66
SET(EXEC_PREFIX "${PREFIX}/bin")
77
SET(INCLUDEDIR "${PREFIX}/include/${PROJECT_NAME}")
88
SET(LIBDIR "${PREFIX}/lib")
9-
SET(VERSION 4.7.1)
9+
SET(VERSION 6.3.0)
1010

1111
SET(CMAKE_MACOSX_RPATH 1)
1212

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: 41 additions & 38 deletions
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
{
@@ -1131,15 +1134,15 @@ static const char *telebot_core_get_media_type(const char *filename)
11311134
}
11321135

11331136
telebot_core_response_t
1134-
telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_id, char *media_paths[], int count,
1137+
telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_id, char *media_paths[], int path_count,
11351138
bool disable_notification, int reply_to_message_id)
11361139
{
11371140
CHECK_ARG_NULL(media_paths);
1138-
CHECK_ARG_CONDITION(count <= 0, "Invalid media path count, should be greater than 0");
1139-
CHECK_ARG_CONDITION(count > 10, "Invalid media path count, should be less than or equal to 10")
1141+
CHECK_ARG_CONDITION(path_count <= 0, "Invalid media path count, should be greater than 0");
1142+
CHECK_ARG_CONDITION(path_count > 10, "Invalid media path count, should be less than or equal to 10")
11401143

11411144
// Validate all media paths are non-NULL
1142-
for (int i = 0; i < count; ++i)
1145+
for (int i = 0; i < path_count; ++i)
11431146
{
11441147
if (media_paths[i] == NULL)
11451148
{
@@ -1157,7 +1160,7 @@ telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_
11571160
}
11581161

11591162
// Allocate memory for filenames
1160-
char **filenames = calloc(count, sizeof(char *));
1163+
char **filenames = calloc(path_count, sizeof(char *));
11611164
if (filenames == NULL)
11621165
{
11631166
json_object_put(media_array);
@@ -1166,10 +1169,10 @@ telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_
11661169
}
11671170

11681171
// Determine media types for validation
1169-
const char **media_types = calloc(count, sizeof(char *));
1172+
const char **media_types = calloc(path_count, sizeof(char *));
11701173
if (media_types == NULL)
11711174
{
1172-
for (int i = 0; i < count; i++)
1175+
for (int i = 0; i < path_count; i++)
11731176
{
11741177
free(filenames[i]);
11751178
}
@@ -1180,7 +1183,7 @@ telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_
11801183
;
11811184
}
11821185

1183-
for (int i = 0; i < count; ++i)
1186+
for (int i = 0; i < path_count; ++i)
11841187
{
11851188
// Extract filename from path using basename
11861189
const char *filename = basename(media_paths[i]);
@@ -1209,7 +1212,7 @@ telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_
12091212
// Validate media group composition
12101213
// Count unique types in the group
12111214
int photo_count = 0, video_count = 0, audio_count = 0, document_count = 0;
1212-
for (int i = 0; i < count; i++)
1215+
for (int i = 0; i < path_count; i++)
12131216
{
12141217
if (strcmp(media_types[i], "photo") == 0)
12151218
photo_count++;
@@ -1226,7 +1229,7 @@ telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_
12261229
// 2. Mixed photo and video only
12271230
bool valid_combination = false;
12281231

1229-
if (photo_count == count || video_count == count || audio_count == count || document_count == count)
1232+
if (photo_count == path_count || video_count == path_count || audio_count == path_count || document_count == path_count)
12301233
{
12311234
// All same type - valid
12321235
valid_combination = true;
@@ -1240,7 +1243,7 @@ telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_
12401243
if (!valid_combination)
12411244
{
12421245
// Free allocated resources
1243-
for (int i = 0; i < count; i++)
1246+
for (int i = 0; i < path_count; i++)
12441247
{
12451248
free(filenames[i]);
12461249
}
@@ -1252,7 +1255,7 @@ telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_
12521255
}
12531256

12541257
// Create JSON objects for media array
1255-
for (int i = 0; i < count; ++i)
1258+
for (int i = 0; i < path_count; ++i)
12561259
{
12571260
struct json_object *item = json_object_new_object();
12581261
json_object_object_add(item, "type", json_object_new_string(media_types[i]));
@@ -1271,7 +1274,7 @@ telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_
12711274
if (media_json_str == NULL)
12721275
{
12731276
// Free allocated filenames
1274-
for (int i = 0; i < count; i++)
1277+
for (int i = 0; i < path_count; i++)
12751278
{
12761279
free(filenames[i]);
12771280
}
@@ -1283,49 +1286,49 @@ telebot_core_send_media_group(telebot_core_handler_t core_h, long long int chat_
12831286

12841287
// Prepare MIME parts
12851288
telebot_core_mime_t mimes[20]; // max: chat_id + media + disable_notif + reply_id + 10 files
1286-
int index = 0;
1289+
int count = 0;
12871290

12881291
// chat_id
1289-
mimes[index].name = "chat_id";
1290-
mimes[index].type = TELEBOT_MIME_TYPE_LONG_LONG_INT;
1291-
mimes[index].data.lld = chat_id;
1292-
++index;
1292+
mimes[count].name = "chat_id";
1293+
mimes[count].type = TELEBOT_MIME_TYPE_LONG_LONG_INT;
1294+
mimes[count].data.lld = chat_id;
1295+
count++;
12931296

12941297
// media (JSON string)
1295-
mimes[index].name = "media";
1296-
mimes[index].type = TELEBOT_MIME_TYPE_STRING;
1297-
mimes[index].data.s = media_json_str;
1298-
++index;
1298+
mimes[count].name = "media";
1299+
mimes[count].type = TELEBOT_MIME_TYPE_STRING;
1300+
mimes[count].data.s = media_json_str;
1301+
count++;
12991302

13001303
// disable_notification
1301-
mimes[index].name = "disable_notification";
1302-
mimes[index].type = TELEBOT_MIME_TYPE_STRING;
1303-
mimes[index].data.s = disable_notification ? "true" : "false";
1304-
++index;
1304+
mimes[count].name = "disable_notification";
1305+
mimes[count].type = TELEBOT_MIME_TYPE_STRING;
1306+
mimes[count].data.s = disable_notification ? "true" : "false";
1307+
count++;
13051308

13061309
// reply_to_message_id (optional)
13071310
if (reply_to_message_id > 0)
13081311
{
1309-
mimes[index].name = "reply_to_message_id";
1310-
mimes[index].type = TELEBOT_MIME_TYPE_INT;
1311-
mimes[index].data.d = reply_to_message_id;
1312-
++index;
1312+
mimes[count].name = "reply_to_message_id";
1313+
mimes[count].type = TELEBOT_MIME_TYPE_INT;
1314+
mimes[count].data.d = reply_to_message_id;
1315+
count++;
13131316
}
13141317

13151318
// Attach actual photo files using the correct names
1316-
for (int i = 0; i < count; ++i)
1319+
for (int i = 0; i < path_count; ++i)
13171320
{
1318-
mimes[index].name = filenames[i]; // Use actual filename instead of generated name
1319-
mimes[index].type = TELEBOT_MIME_TYPE_FILE;
1320-
mimes[index].data.s = media_paths[i];
1321-
++index;
1321+
mimes[count].name = filenames[i]; // Use actual filename instead of generated name
1322+
mimes[count].type = TELEBOT_MIME_TYPE_FILE;
1323+
mimes[count].data.s = media_paths[i];
1324+
count++;
13221325
}
13231326

13241327
// Perform request
1325-
telebot_core_response_t response = telebot_core_curl_perform(core_h, TELEBOT_METHOD_SEND_MEDIA_GROUP, mimes, index);
1328+
telebot_core_response_t response = telebot_core_curl_perform(core_h, TELEBOT_METHOD_SEND_MEDIA_GROUP, mimes, count);
13261329

13271330
// Clean up allocated filenames
1328-
for (int i = 0; i < count; i++)
1331+
for (int i = 0; i < path_count; i++)
13291332
{
13301333
free(filenames[i]);
13311334
}

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)