1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 21:43:02 +01:00

core api const-correctness update

This commit is contained in:
Jfreegman 2014-07-02 17:30:31 -04:00
parent 9696acc8bd
commit 10d0e99d72
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
10 changed files with 67 additions and 93 deletions

View File

@ -128,13 +128,11 @@ void kill_chat_window(ToxWindow *self, Tox *m)
free(statusbar);
}
static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t *msg, uint16_t len)
static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const uint8_t *msg, uint16_t len)
{
if (self->num != num)
return;
msg[len] = '\0';
ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH];
@ -176,14 +174,11 @@ static void chat_onTypingChange(ToxWindow *self, Tox *m, int32_t num, uint8_t is
friends[num].is_typing = is_typing;
}
static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, uint8_t *action, uint16_t len)
static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const uint8_t *action, uint16_t len)
{
if (self->num != num)
return;
action[len] = '\0';
ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH];
@ -200,14 +195,12 @@ static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, uint8_t *action,
alert_window(self, WINDOW_ALERT_1, true);
}
static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, uint8_t *nick, uint16_t len)
static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, const uint8_t *nick, uint16_t len)
{
if (self->num != num)
return;
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
nick[len] = '\0';
strcpy(self->name, nick);
snprintf(self->name, sizeof(self->name), "%s", nick);
}
static void chat_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
@ -219,22 +212,19 @@ static void chat_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t st
statusbar->status = status;
}
static void chat_onStatusMessageChange(ToxWindow *self, int32_t num, uint8_t *status, uint16_t len)
static void chat_onStatusMessageChange(ToxWindow *self, int32_t num, const uint8_t *status, uint16_t len)
{
if (self->num != num)
return;
StatusBar *statusbar = self->stb;
status[len] = '\0';
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", status);
len = strlen(statusbar->statusmsg);
statusbar->statusmsg_len = len;
statusbar->statusmsg[len] = '\0';
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
}
static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum,
uint64_t filesize, uint8_t *pathname, uint16_t path_len)
uint64_t filesize, const uint8_t *pathname, uint16_t path_len)
{
if (self->num != num)
return;
@ -242,9 +232,6 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
uint8_t msg[MAX_STR_SIZE * 2];
uint8_t *errmsg;
pathname[path_len] = '\0';
/* holds the filename appended to the user specified path */
uint8_t filename_path[MAX_STR_SIZE] = {0};
@ -328,7 +315,7 @@ static void chat_close_file_receiver(int32_t num, uint8_t filenum)
}
static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t receive_send,
uint8_t filenum, uint8_t control_type, uint8_t *data, uint16_t length)
uint8_t filenum, uint8_t control_type, const uint8_t *data, uint16_t length)
{
if (self->num != num)
return;
@ -378,7 +365,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
alert_window(self, WINDOW_ALERT_2, true);
}
static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, uint8_t *data,
static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, const uint8_t *data,
uint16_t length)
{
if (self->num != num)
@ -410,7 +397,7 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenu
}
}
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, uint8_t *group_pub_key)
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, const uint8_t *group_pub_key)
{
if (self->num != friendnumber)
return;
@ -804,12 +791,11 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
pthread_mutex_lock(&Winthread.lock);
uint16_t s_len = tox_get_status_message(m, self->num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
tox_get_status_message(m, self->num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
pthread_mutex_unlock(&Winthread.lock);
statusmsg[s_len] = '\0';
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
statusbar->statusmsg_len = s_len;
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
}
self->x = x2;

View File

@ -96,7 +96,7 @@ static void update_friend_last_online(int32_t num, uint64_t timestamp)
&friends[num].last_online.tm);
}
static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t *str, uint16_t len)
static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const uint8_t *str, uint16_t len)
{
if (num >= max_friends_index)
return;
@ -105,8 +105,6 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t *
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
} else {
str[len] = '\0';
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
int n_len = tox_get_name(m, num, nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
@ -135,16 +133,13 @@ static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int32_t num,
sort_friendlist_index();
}
static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, uint8_t *str, uint16_t len)
static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, const uint8_t *nick, uint16_t len)
{
if (len > TOX_MAX_NAME_LENGTH || num >= max_friends_index)
return;
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
str[len] = '\0';
strcpy(friends[num].name, str);
friends[num].namelength = len;
snprintf(friends[num].name, sizeof(friends[num].name), "%s", nick);
friends[num].namelength = strlen(friends[num].name);
sort_friendlist_index();
}
@ -156,16 +151,13 @@ static void friendlist_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint
friends[num].status = status;
}
static void friendlist_onStatusMessageChange(ToxWindow *self, int32_t num, uint8_t *str, uint16_t len)
static void friendlist_onStatusMessageChange(ToxWindow *self, int32_t num, const uint8_t *status, uint16_t len)
{
if (len > TOX_MAX_STATUSMESSAGE_LENGTH || num >= max_friends_index)
return;
str[len] = '\0';
snprintf(friends[num].statusmsg, sizeof(friends[num].statusmsg), "%s", str);
len = strlen(friends[num].statusmsg);
friends[num].statusmsg_len = len;
friends[num].statusmsg[len] = '\0';
snprintf(friends[num].statusmsg, sizeof(friends[num].statusmsg), "%s", status);
friends[num].statusmsg_len = strlen(friends[num].statusmsg);
}
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
@ -209,7 +201,7 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
}
static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum,
uint64_t filesize, uint8_t *filename, uint16_t filename_len)
uint64_t filesize, const uint8_t *filename, uint16_t filename_len)
{
if (num >= max_friends_index)
return;
@ -234,7 +226,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
}
}
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, uint8_t *group_pub_key)
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const uint8_t *group_pub_key)
{
if (num >= max_friends_index)
return;
@ -472,13 +464,11 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
pthread_mutex_lock(&Winthread.lock);
uint16_t s_len = tox_get_status_message(m, friends[f].num, statusmsg,
TOX_MAX_STATUSMESSAGE_LENGTH);
tox_get_status_message(m, friends[f].num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
pthread_mutex_unlock(&Winthread.lock);
friends[f].statusmsg_len = s_len;
friends[f].statusmsg[s_len] = '\0';
snprintf(friends[f].statusmsg, sizeof(friends[f].statusmsg), "%s", statusmsg);
friends[f].statusmsg_len = strlen(friends[f].statusmsg);
}
/* Truncate note if it doesn't fit on one line */

View File

@ -166,13 +166,11 @@ static void print_groupchat_help(ToxWindow *self)
}
static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int peernum,
uint8_t *msg, uint16_t len)
const uint8_t *msg, uint16_t len)
{
if (self->num != groupnum)
return;
msg[len] = '\0';
ChatContext *ctx = self->chatwin;
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
@ -208,14 +206,12 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
write_to_log(msg, nick, ctx->log, false);
}
static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int peernum, uint8_t *action,
static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int peernum, const uint8_t *action,
uint16_t len)
{
if (self->num != groupnum)
return;
action[len] = '\0';
ChatContext *ctx = self->chatwin;
/* check if message contains own name and alert appropriately */

View File

@ -121,7 +121,7 @@ static struct line_info *line_info_ret_queue(struct history *hst)
}
/* creates new line_info line and puts it in the queue */
void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *name2, uint8_t *msg,
void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *name2, const uint8_t *msg,
uint8_t type, uint8_t bold, uint8_t colour)
{
struct history *hst = self->chatwin->hst;

View File

@ -68,7 +68,7 @@ struct history {
};
/* creates new line_info line and puts it in the queue */
void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *name2, uint8_t *msg,
void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *name2, const uint8_t *msg,
uint8_t type, uint8_t bold, uint8_t colour);
/* Prints a section of history starting at line_start */

View File

@ -194,20 +194,23 @@ int valid_nick(uint8_t *nick)
}
/* gets base file name from path or original file name if no path is supplied */
void get_file_name(uint8_t *namebuf, uint8_t *pathname)
void get_file_name(uint8_t *namebuf, const uint8_t *pathname)
{
int idx = strlen(pathname) - 1;
while (idx >= 0 && pathname[idx] == '/')
pathname[idx--] = '\0';
uint8_t tmpname[MAX_STR_SIZE];
snprintf(tmpname, sizeof(tmpname), "%s", pathname);
uint8_t *filename = strrchr(pathname, '/');
while (idx >= 0 && pathname[idx] == '/')
tmpname[idx--] = '\0';
uint8_t *filename = strrchr(tmpname, '/');
if (filename != NULL) {
if (!strlen(++filename))
filename = pathname;
filename = tmpname;
} else {
filename = pathname;
filename = tmpname;
}
snprintf(namebuf, MAX_STR_SIZE, "%s", filename);

View File

@ -80,7 +80,7 @@ int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2);
int valid_nick(uint8_t *nick);
/* gets base file name from path or original file name if no path is supplied */
void get_file_name(uint8_t *namebuf, uint8_t *pathname);
void get_file_name(uint8_t *namebuf, const uint8_t *pathname);
/* converts str to all lowercase */
void str_to_lower(uint8_t *str);

View File

@ -77,21 +77,21 @@ int store_data(Tox *m, char *path);
void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata);
void on_connectionchange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata);
void on_message(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length, void *userdata);
void on_action(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length, void *userdata);
void on_nickchange(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length, void *userdata);
void on_message(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata);
void on_action(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata);
void on_nickchange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata);
void on_statuschange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata);
void on_statusmessagechange(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length, void *userdata);
void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata);
void on_friendadded(Tox *m, int32_t friendnumber, bool sort);
void on_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata);
void on_groupaction(Tox *m, int groupnumber, int peernumber, uint8_t *action, uint16_t length, void *userdata);
void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t *group_pub_key, void *userdata);
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, void *userdata);
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, uint16_t length, void *userdata);
void on_groupinvite(Tox *m, int32_t friendnumber, const uint8_t *group_pub_key, void *userdata);
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata);
void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *pathname,
void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *pathname,
uint16_t pathname_length, void *userdata);
void on_file_control(Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type,
uint8_t *data, uint16_t length, void *userdata);
void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata);
const uint8_t *data, uint16_t length, void *userdata);
void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *userdata);
void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata);
#endif /* #define _toxic_h */

View File

@ -73,7 +73,7 @@ void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *use
}
}
void on_message(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length, void *userdata)
void on_message(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata)
{
int i;
@ -83,7 +83,7 @@ void on_message(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length,
}
}
void on_action(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length, void *userdata)
void on_action(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata)
{
int i;
@ -93,7 +93,7 @@ void on_action(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length, v
}
}
void on_nickchange(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length, void *userdata)
void on_nickchange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata)
{
if (friendnumber < 0 || friendnumber > MAX_FRIENDS_NUM)
return;
@ -109,7 +109,7 @@ void on_nickchange(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t lengt
wprintw(prompt->window, "\nCould not store Tox data\n");
}
void on_statusmessagechange(Tox *m, int32_t friendnumber, uint8_t *string, uint16_t length, void *userdata)
void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata)
{
int i;
@ -142,7 +142,7 @@ void on_friendadded(Tox *m, int32_t friendnumber, bool sort)
wprintw(prompt->window, "\nCould not store Tox data\n");
}
void on_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length,
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length,
void *userdata)
{
int i;
@ -153,7 +153,7 @@ void on_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message,
}
}
void on_groupaction(Tox *m, int groupnumber, int peernumber, uint8_t *action, uint16_t length,
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, uint16_t length,
void *userdata)
{
int i;
@ -164,7 +164,7 @@ void on_groupaction(Tox *m, int groupnumber, int peernumber, uint8_t *action, ui
}
}
void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t *group_pub_key, void *userdata)
void on_groupinvite(Tox *m, int32_t friendnumber, const uint8_t *group_pub_key, void *userdata)
{
int i;
@ -185,7 +185,7 @@ void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t ch
}
void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize,
uint8_t *filename, uint16_t filename_length, void *userdata)
const uint8_t *filename, uint16_t filename_length, void *userdata)
{
int i;
@ -197,7 +197,7 @@ void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint6
}
void on_file_control (Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata)
{
int i;
@ -208,7 +208,7 @@ void on_file_control (Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_
}
}
void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length,
void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length,
void *userdata)
{
int i;
@ -330,7 +330,6 @@ void on_window_resize(void)
delwin(w->window);
w->window = newwin(y2, x2, 0, 0);
w->x = x2;
if (windows[i].is_friendlist)
continue;

View File

@ -80,18 +80,18 @@ struct ToxWindow {
void(*onFriendRequest)(ToxWindow *, Tox *, const uint8_t *, const uint8_t *, uint16_t);
void(*onFriendAdded)(ToxWindow *, Tox *, int32_t, bool);
void(*onConnectionChange)(ToxWindow *, Tox *, int32_t, uint8_t);
void(*onMessage)(ToxWindow *, Tox *, int32_t, uint8_t *, uint16_t);
void(*onNickChange)(ToxWindow *, Tox *, int32_t, uint8_t *, uint16_t);
void(*onMessage)(ToxWindow *, Tox *, int32_t, const uint8_t *, uint16_t);
void(*onNickChange)(ToxWindow *, Tox *, int32_t, const uint8_t *, uint16_t);
void(*onStatusChange)(ToxWindow *, Tox *, int32_t, uint8_t);
void(*onStatusMessageChange)(ToxWindow *, int32_t, uint8_t *, uint16_t);
void(*onAction)(ToxWindow *, Tox *, int32_t, uint8_t *, uint16_t);
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, uint8_t *, uint16_t);
void(*onGroupAction)(ToxWindow *, Tox *, int, int, uint8_t *, uint16_t);
void(*onGroupInvite)(ToxWindow *, Tox *, int32_t, uint8_t *);
void(*onStatusMessageChange)(ToxWindow *, int32_t, const uint8_t *, uint16_t);
void(*onAction)(ToxWindow *, Tox *, int32_t, const uint8_t *, uint16_t);
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, const uint8_t *, uint16_t);
void(*onGroupAction)(ToxWindow *, Tox *, int, int, const uint8_t *, uint16_t);
void(*onGroupInvite)(ToxWindow *, Tox *, int32_t, const uint8_t *);
void(*onGroupNamelistChange)(ToxWindow *, Tox *, int, int, uint8_t);
void(*onFileSendRequest)(ToxWindow *, Tox *, int32_t, uint8_t, uint64_t, uint8_t *, uint16_t);
void(*onFileControl)(ToxWindow *, Tox *, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *, uint16_t);
void(*onFileData)(ToxWindow *, Tox *, int32_t, uint8_t, uint8_t *, uint16_t);
void(*onFileSendRequest)(ToxWindow *, Tox *, int32_t, uint8_t, uint64_t, const uint8_t *, uint16_t);
void(*onFileControl)(ToxWindow *, Tox *, int32_t, uint8_t, uint8_t, uint8_t, const uint8_t *, uint16_t);
void(*onFileData)(ToxWindow *, Tox *, int32_t, uint8_t, const uint8_t *, uint16_t);
void(*onTypingChange)(ToxWindow *, Tox *, int32_t, uint8_t);
#ifdef _SUPPORT_AUDIO