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

Commit

Permalink
replace strlen by fstrlen(macro)
Browse files Browse the repository at this point in the history
rename IF_STRING_NULL to STRING_NULL
deleted struct reply_markup
  • Loading branch information
h4child committed May 18, 2018
1 parent d234c97 commit d766466
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 93 deletions.
4 changes: 3 additions & 1 deletion include/framebot/framebot.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@
#define HEIGHT(p) (p > 0 ? api_ltoa(p) : NULL)
#define LENGTH(p) (p > 0 ? api_ltoa(p) : NULL)

#define IF_STRING_NULL(p) (p == NULL?"null":p)
#define fstrlen(p) (p == NULL ? 0 : strlen(p))

#define STRING_NULL(p) (p == NULL ? "null":p)

#define UPDATE_ID_LAST(x, y) (x->update_id > y->update_id ? x->update_id : y->update_id)

Expand Down
48 changes: 0 additions & 48 deletions include/framebot/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,55 +329,7 @@ typedef struct _callback_game{
char *inline_message_id;
} CallbackGame;

typedef struct _keyboard_button {
char *text;
bool request_contact:1;
bool request_location:1;
struct _keyboard_button *next;
} KeyboardButton;

typedef struct _inline_keyboard_button{
char *text;
char *url;
char *callback_data;
char *switch_nline_query;
char *switch_inline_query_current_chat;
CallbackGame *callback_game;
bool pay:1;
} InlineKeyboardButton;

typedef struct _inline_keyboard_markup{
int type;
InlineKeyboardButton ** inline_keyboard;
} InlineKeyboardMarkup;

typedef struct _reply_keyboard_markup {
int type;
KeyboardButton ** keyboard_button;
bool resize_keyboard;
bool one_time_keyboard;
bool selective:1;
} ReplyKeyboardMarkup;

typedef struct _reply_keyboard_remove{
int type;
bool remove_keyboard:1;
bool selective:1;
} ReplyKeyboardRemove;

typedef struct _force_reply{
int type;
bool force_reply:1;
bool selective:1;
} ForceReply;

typedef union _keyboard{
int type;
InlineKeyboardButton *inline_keyboard_markup;
ReplyKeyboardMarkup *reply_keyboard_markup;
ReplyKeyboardRemove *reply_keyboard_remove;
ForceReply *_force_reply;
} Keyboard;

//User functions
User *user(
Expand Down
34 changes: 0 additions & 34 deletions src/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,6 @@
#define STRINT 13


char *escape_string(char *str) {
CURL *curl = curl_easy_init();
if (curl) {
char *out = curl_easy_escape(curl, str, 0);
return out;
}
return NULL;
}

char *remove_newline(char *str){
size_t size_str;

size_str = strlen(str);

if(str[size_str - 1] == '\n')
str[size_str - 1] = '\0';

return str;
}

char *format (char *formats, ...) {

va_list params;
va_start(params, formats);

char *buffer = (char *)calloc(1, MAX_URL_SZ);

vsprintf(buffer, formats, params);

va_end(params);

return buffer;
}

char *vsformat (char *formats, va_list params) {
char *buffer = (char *) calloc(1, MAX_URL_SZ);

Expand Down
4 changes: 2 additions & 2 deletions src/framebot.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Framebot *get_updates (Bot *bot, Framebot *framebot, long int offset, long int l
Update *up = NULL;

s_json = generic_method_call(bot->token, API_GETUPDATES,
offset, limit, timeout, IF_STRING_NULL(allowed_updates) );
offset, limit, timeout, STRING_NULL(allowed_updates) );

if( !framebot ){
framebot = calloc(1, sizeof( Framebot ));
Expand Down Expand Up @@ -1885,7 +1885,7 @@ bool answer_inline_query( Bot *bot, char *inline_query_id, char *results, long i
refjson *s_json;

s_json = generic_method_call(bot->token, API_answerInlineQuery, inline_query_id, results,
cache_time, is_personal, IF_STRING_NULL(next_offset), IF_STRING_NULL(switch_pm_text), IF_STRING_NULL(switch_pm_parameter));
cache_time, is_personal, STRING_NULL(next_offset), STRING_NULL(switch_pm_text), STRING_NULL(switch_pm_parameter));

if(!s_json)
return -1;
Expand Down
8 changes: 4 additions & 4 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
char * alloc_string(const char * str){

if (str) {
char *nstr = (char *) malloc(strlen(str) + 1);
char *nstr = (char *) malloc(fstrlen(str) + 1);
strcpy(nstr, str);

return (char *) nstr;
return nstr;
}

return (char *) NULL;
return NULL;
}

char *realloc_string (char *base, char *str) {
if (!str)
return base;

char *tmp = (char *) realloc(base, strlen(base) + strlen(str) + 1);
char *tmp = (char *) realloc(base, fstrlen(base) + fstrlen(str) + 1);

if (tmp)
strcat(tmp, str);
Expand Down
8 changes: 4 additions & 4 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ size_t mem_write_callback(void *data, size_t size, size_t nmemb, void *userp) {
/* send data to telegram */
MemStore * call_method(const char *token, const char *method){
CURLcode res;
size_t url_size = API_URL_LEN + strlen( token ) + strlen( method ) + 2;
size_t url_size = API_URL_LEN + fstrlen( token ) + fstrlen( method ) + 2;
char * url = ( char * ) calloc(1, url_size );

strcpy( url, API_URL );
Expand Down Expand Up @@ -87,7 +87,7 @@ int call_method_download(const char * token, char * namefile, File *ofile){
if(!ofile)
return 0;

url_size = API_URL_FILE_LEN + strlen(token) + strlen(ofile->file_path) + 2;
url_size = API_URL_FILE_LEN + fstrlen(token) + fstrlen(ofile->file_path) + 2;
url = (char *)calloc(1, url_size);

strcpy(url, API_URL_FILE);
Expand Down Expand Up @@ -529,7 +529,7 @@ MemStore * call_method_upload(const char * token, IFile ifile){
char * url = NULL;

buff = mem_store();
url_size = API_URL_LEN + strlen(token) + strlen(method) + 2;
url_size = API_URL_LEN + fstrlen(token) + fstrlen(method) + 2;
url = calloc(1, url_size);

strcpy(url, API_URL);
Expand Down Expand Up @@ -567,7 +567,7 @@ MemStore * call_method_upload(const char * token, IFile ifile){
}

MemStore *call_method_wp(char *token, char *method, char *params) {
size_t len = strlen(method) + strlen(params) + 1;
size_t len = fstrlen(method) + fstrlen(params) + 1;
char *tmp = (char *)calloc(1, len);

MemStore *ms = call_method(token, tmp);
Expand Down

0 comments on commit d766466

Please sign in to comment.