Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
add test_chat.c
Browse files Browse the repository at this point in the history
  • Loading branch information
h4child committed Mar 31, 2018
1 parent 227e708 commit e05ab66
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 26 deletions.
3 changes: 1 addition & 2 deletions examples/inline_bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main (int argc, char **argv) {
if(!inbot)
return -1;

Framebot *updates = get_updates(inbot, NULL, 0, 100, 0, NULL);
Framebot *updates = get_updates(inbot, NULL, 0, 100, 0, "inline_query");
Update *queries = NULL;

long int last_update = 0;
Expand All @@ -41,7 +41,6 @@ int main (int argc, char **argv) {
queries = queries->next;
}
}
custom_sleep(3000);
get_updates(inbot, updates, last_update, 100, 0, NULL);
}

Expand Down
4 changes: 2 additions & 2 deletions include/framebot/framebot.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ int send_chat_action(Bot * bot, char * chat_id, char * action);
int send_chat_action_chat(Bot * bot, long int chat_id, char * action);

/* getUserProfilePhotos */
UserProfilePhotos * get_user_profile_photos(Bot * bot, char * dir, char *user_id,
UserProfilePhotos * get_user_profile_photos(Bot * bot, char *user_id,
long offset, long limit);
UserProfilePhotos * get_user_profile_photos_chat(Bot * bot, char * dir, long user_id,
UserProfilePhotos * get_user_profile_photos_chat(Bot * bot, long user_id,
long offset, long limit);

/* getFile */
Expand Down
6 changes: 3 additions & 3 deletions src/framebot.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ int file_download(Bot * bot, File * ofile, char *path){
* getUserProfilePhotos
* https://core.telegram.org/bots/api#getuserprofilephotos
*/
UserProfilePhotos * get_user_profile_photos(Bot * bot, char * dir, char *user_id,
UserProfilePhotos * get_user_profile_photos(Bot * bot, char *user_id,
long offset, long limit) {
UserProfilePhotos * oupp;
refjson *s_json;
Expand All @@ -842,14 +842,14 @@ UserProfilePhotos * get_user_profile_photos(Bot * bot, char * dir, char *user_id
return oupp;
}

UserProfilePhotos * get_user_profile_photos_chat (Bot * bot, char * dir, long user_id,
UserProfilePhotos * get_user_profile_photos_chat (Bot * bot, long user_id,
long offset, long limit) {
UserProfilePhotos * oupp;
char *cuser_id;

cuser_id = api_ltoa(user_id);

oupp = get_user_profile_photos(bot, dir, cuser_id, offset, limit);
oupp = get_user_profile_photos(bot, cuser_id, offset, limit);

free(cuser_id);

Expand Down
16 changes: 8 additions & 8 deletions src/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1279,25 +1279,25 @@ UserProfilePhotos * user_profile_photos_parse(json_t * json){
return NULL;

json_t *total_count, *photos, *array_photos;
size_t _length, i, length_, x;
size_t length_i, i, length_x, x;

total_count = json_object_get(json, "total_count");

PhotoSize ** ophotos = NULL, *_temp = NULL;
photos = json_object_get(json, "photos");
_length = json_array_size(photos);
length_i = json_array_size(photos);

/* Array of Array PhotoSize */
ophotos = (PhotoSize **) calloc(1, _length * sizeof(PhotoSize));
if (_length > 0) {
for (i = 0; i < _length; i++) {
if (length_i > 0) {
ophotos = (PhotoSize **) calloc(length_i, sizeof(PhotoSize));
for (i = 0; i < length_i; i++) {
array_photos = json_array_get(photos, i);
length_ = json_array_size(array_photos);
length_x = json_array_size(array_photos);

if(length_ > 0){
if(length_x > 0){
ophotos[i] = photo_size_parse(json_array_get(array_photos, 0));

for(x = 1; x < length_; x++){
for(x = 1; x < length_x; x++){
_temp = photo_size_parse(json_array_get(array_photos, x));
if(_temp)
photo_size_add(ophotos[i], _temp);
Expand Down
22 changes: 12 additions & 10 deletions src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ Error *get_error(){
void user_add(User *origin, User *next){
User *o = origin;

while(o){
while(o->next){
o = o->next;
}

o = next;
o->next = next;
}

void user_free(User *usr){
Expand Down Expand Up @@ -256,19 +256,23 @@ void audio_free(Audio *audio){
** https://core.telegram.org/bots/api#photosize
**/
void photo_size_free(PhotoSize *photoSize){
if(photoSize->file_id)
free(photoSize->file_id);
if(photoSize != NULL){
if(photoSize->file_id)
free(photoSize->file_id);

free(photoSize);
}

free(photoSize);
photoSize = NULL;
}


void photo_size_add(PhotoSize *root, PhotoSize *newps){
PhotoSize *aux = root;

while(aux->next)
while(aux->next){
aux = aux->next;
}

aux->next = newps;
}
Expand Down Expand Up @@ -1317,23 +1321,21 @@ UserProfilePhotos *user_profile_photos(long int total_count, PhotoSize ** photos
}

void user_profile_photos_free(UserProfilePhotos *oupp){
size_t i;
size_t i, m = 0;

PhotoSize *photo, *upp_n;

if(oupp->photos){
for(i = 0; i < oupp->total_count; i++){
photo = oupp->photos[i];
upp_n = photo;

while(photo){
upp_n = photo->next;
photo_size_free(photo);
photo = upp_n;
}

photo_size_free(oupp->photos[i]);
}
free(oupp->photos);
}

free(oupp);
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include_directories (${PROJECT_SOURCE_DIR}/../include)

add_definitions("-g")

add_executable(methods_chat test_chat.c)
add_executable(update test_update.c)
add_executable(file test_file.c)
add_executable(userprofilephotos test_userprofilephotos.c)
Expand All @@ -26,6 +27,7 @@ add_executable(sendvideonote test_sendvideonote.c)
add_executable(sendmessage test_sendmessage.c)

if (CMAKE_SYSTEM_NAME STREQUAL Linux)
target_link_libraries(methods_chat jansson libcurl.so framebot)
target_link_libraries(update jansson libcurl.so framebot)
target_link_libraries(file jansson libcurl.so framebot)
target_link_libraries(userprofilephotos jansson libcurl.so framebot)
Expand All @@ -39,6 +41,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL Linux)
endif (CMAKE_SYSTEM_NAME STREQUAL Linux)

if (WIN32)
target_link_libraries(methods_chat jansson libcurl_a framebot)
target_link_libraries(update jansson libcurl_a framebot)
target_link_libraries(file jansson libcurl_a framebot)
target_link_libraries(userprofilephotos jansson libcurl_a framebot)
Expand Down

0 comments on commit e05ab66

Please sign in to comment.