This commit is contained in:
Sean Qureshi 2013-08-08 03:07:41 -07:00
commit 4d0cce2f69
10 changed files with 172 additions and 157 deletions

View File

@ -65,7 +65,7 @@ void parent_confirm_message(int num, uint8_t *data, uint16_t length)
request_flags |= SECOND_FLAG;
}
void parent_confirm_status(int num, USERSTATUS_KIND status, uint8_t *data, uint16_t length)
void parent_confirm_status(int num, uint8_t *data, uint16_t length)
{
puts("OK");
request_flags |= FIRST_FLAG;
@ -110,7 +110,7 @@ void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length)
request_flags |= FIRST_FLAG;
}
void child_got_statuschange(int friend_num, USERSTATUS_KIND status, uint8_t *string, uint16_t length)
void child_got_statuschange(int friend_num, uint8_t *string, uint16_t length)
{
request_flags |= SECOND_FLAG;
}
@ -169,7 +169,7 @@ int main(int argc, char *argv[])
msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC);
m_callback_friendrequest(child_got_request);
m_callback_userstatus(child_got_statuschange);
m_callback_statusmessage(child_got_statuschange);
/* wait on the friend request */
while(!(request_flags & FIRST_FLAG))
@ -196,7 +196,7 @@ int main(int argc, char *argv[])
}
msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC);
m_callback_userstatus(parent_confirm_status);
m_callback_statusmessage(parent_confirm_status);
m_callback_friendmessage(parent_confirm_message);
/* hacky way to give the child time to set up */

View File

@ -62,16 +62,16 @@ END_TEST
START_TEST(test_m_get_userstatus_size)
{
int rc = 0;
ck_assert_msg((m_get_userstatus_size(-1) == -1),
"m_get_userstatus_size did NOT catch an argument of -1");
ck_assert_msg((m_get_userstatus_size(REALLY_BIG_NUMBER) == -1),
"m_get_userstatus_size did NOT catch the following argument: %d\n",
ck_assert_msg((m_get_statusmessage_size(-1) == -1),
"m_get_statusmessage_size did NOT catch an argument of -1");
ck_assert_msg((m_get_statusmessage_size(REALLY_BIG_NUMBER) == -1),
"m_get_statusmessage_size did NOT catch the following argument: %d\n",
REALLY_BIG_NUMBER);
rc = m_get_userstatus_size(friend_id_num);
rc = m_get_statusmessage_size(friend_id_num);
/* this WILL error if the original m_addfriend_norequest() failed */
ck_assert_msg((rc > 0 && rc <= MAX_USERSTATUS_LENGTH),
"m_get_userstatus_size is returning out of range values!\n"
ck_assert_msg((rc > 0 && rc <= MAX_STATUSMESSAGE_LENGTH),
"m_get_statusmessage_size is returning out of range values!\n"
"(this can be caused by the error of m_addfriend_norequest"
" in the beginning of the suite)\n");
}
@ -83,15 +83,13 @@ START_TEST(test_m_set_userstatus)
uint16_t good_length = strlen(status);
uint16_t bad_length = REALLY_BIG_NUMBER;
if(m_set_userstatus(USERSTATUS_KIND_ONLINE,
(uint8_t *)status, bad_length) != -1)
if(m_set_statusmessage((uint8_t *)status, bad_length) != -1)
ck_abort_msg("m_set_userstatus did NOT catch the following length: %d\n",
REALLY_BIG_NUMBER);
if((m_set_userstatus(USERSTATUS_KIND_RETAIN,
(uint8_t *)status, good_length)) != 0)
if((m_set_statusmessage((uint8_t *)status, good_length)) != 0)
ck_abort_msg("m_set_userstatus did NOT return 0 on the following length: %d\n"
"MAX_USERSTATUS_LENGTH: %d\n", good_length, MAX_USERSTATUS_LENGTH);
"MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH);
}
END_TEST

View File

@ -32,10 +32,11 @@ typedef struct {
uint8_t info[MAX_DATA_SIZE]; /* the data that is sent during the friend requests we do */
uint8_t name[MAX_NAME_LENGTH];
uint8_t name_sent; /* 0 if we didn't send our name to this friend 1 if we have. */
uint8_t *userstatus;
uint16_t userstatus_length;
uint8_t *statusmessage;
uint16_t statusmessage_length;
uint8_t statusmessage_sent;
USERSTATUS userstatus;
uint8_t userstatus_sent;
USERSTATUS_KIND userstatus_kind;
uint16_t info_size; /* length of the info */
uint32_t message_id; /* a semi-unique id used in read receipts */
uint8_t receives_read_receipts; /* shall we send read receipts to this person? */
@ -46,9 +47,9 @@ uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
static uint8_t self_name[MAX_NAME_LENGTH];
static uint16_t self_name_length;
static uint8_t *self_userstatus;
static uint16_t self_userstatus_len;
static USERSTATUS_KIND self_userstatus_kind;
static uint8_t *self_statusmessage;
static uint16_t self_statusmessage_len;
static USERSTATUS self_userstatus;
#define MAX_NUM_FRIENDS 256
@ -125,9 +126,9 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
friendlist[i].crypt_connection_id = -1;
friendlist[i].friend_request_id = -1;
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
friendlist[i].userstatus = calloc(1, 1);
friendlist[i].userstatus_length = 1;
friendlist[i].userstatus_kind = USERSTATUS_KIND_OFFLINE;
friendlist[i].statusmessage = calloc(1, 1);
friendlist[i].statusmessage_length = 1;
friendlist[i].userstatus = USERSTATUS_NONE;
memcpy(friendlist[i].info, data, length);
friendlist[i].info_size = length;
friendlist[i].message_id = 0;
@ -152,8 +153,9 @@ int m_addfriend_norequest(uint8_t * client_id)
friendlist[i].crypt_connection_id = -1;
friendlist[i].friend_request_id = -1;
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
friendlist[i].userstatus = calloc(1, 1);
friendlist[i].userstatus_length = 1;
friendlist[i].statusmessage = calloc(1, 1);
friendlist[i].statusmessage_length = 1;
friendlist[i].userstatus = USERSTATUS_NONE;
friendlist[i].message_id = 0;
friendlist[i].receives_read_receipts = 1; /* default: YES */
numfriends++;
@ -173,7 +175,7 @@ int m_delfriend(int friendnumber)
DHT_delfriend(friendlist[friendnumber].client_id);
crypto_kill(friendlist[friendnumber].crypt_connection_id);
free(friendlist[friendnumber].userstatus);
free(friendlist[friendnumber].statusmessage);
memset(&friendlist[friendnumber], 0, sizeof(Friend));
uint32_t i;
@ -290,33 +292,28 @@ int getname(int friendnumber, uint8_t * name)
return 0;
}
int m_set_userstatus(USERSTATUS_KIND kind, uint8_t *status, uint16_t length)
int m_set_statusmessage(uint8_t *status, uint16_t length)
{
if (length > MAX_USERSTATUS_LENGTH)
if (length > MAX_STATUSMESSAGE_LENGTH)
return -1;
if (kind != USERSTATUS_KIND_RETAIN) {
self_userstatus_kind = kind;
}
uint8_t *newstatus = calloc(length, 1);
memcpy(newstatus, status, length);
free(self_userstatus);
self_userstatus = newstatus;
self_userstatus_len = length;
free(self_statusmessage);
self_statusmessage = newstatus;
self_statusmessage_len = length;
uint32_t i;
for (i = 0; i < numfriends; ++i)
friendlist[i].userstatus_sent = 0;
friendlist[i].statusmessage_sent = 0;
return 0;
}
int m_set_userstatus_kind(USERSTATUS_KIND kind) {
if (kind >= USERSTATUS_KIND_INVALID) {
int m_set_userstatus(USERSTATUS status)
{
if (status >= USERSTATUS_INVALID) {
return -1;
}
if (kind == USERSTATUS_KIND_RETAIN) {
return 0;
}
self_userstatus_kind = kind;
self_userstatus = status;
uint32_t i;
for (i = 0; i < numfriends; ++i)
friendlist[i].userstatus_sent = 0;
@ -324,72 +321,83 @@ int m_set_userstatus_kind(USERSTATUS_KIND kind) {
}
/* return the size of friendnumber's user status
guaranteed to be at most MAX_USERSTATUS_LENGTH */
int m_get_userstatus_size(int friendnumber)
guaranteed to be at most MAX_STATUSMESSAGE_LENGTH */
int m_get_statusmessage_size(int friendnumber)
{
if (friendnumber >= numfriends || friendnumber < 0)
return -1;
return friendlist[friendnumber].userstatus_length;
return friendlist[friendnumber].statusmessage_length;
}
/* copy the user status of friendnumber into buf, truncating if needed to maxlen
bytes, use m_get_userstatus_size to find out how much you need to allocate */
int m_copy_userstatus(int friendnumber, uint8_t * buf, uint32_t maxlen)
bytes, use m_get_statusmessage_size to find out how much you need to allocate */
int m_copy_statusmessage(int friendnumber, uint8_t * buf, uint32_t maxlen)
{
if (friendnumber >= numfriends || friendnumber < 0)
return -1;
memset(buf, 0, maxlen);
memcpy(buf, friendlist[friendnumber].userstatus, MIN(maxlen, MAX_USERSTATUS_LENGTH) - 1);
memcpy(buf, friendlist[friendnumber].statusmessage, MIN(maxlen, MAX_STATUSMESSAGE_LENGTH) - 1);
return 0;
}
int m_copy_self_userstatus(uint8_t * buf, uint32_t maxlen)
int m_copy_self_statusmessage(uint8_t * buf, uint32_t maxlen)
{
memset(buf, 0, maxlen);
memcpy(buf, self_userstatus, MIN(maxlen, MAX_USERSTATUS_LENGTH) - 1);
memcpy(buf, self_statusmessage, MIN(maxlen, MAX_STATUSMESSAGE_LENGTH) - 1);
return 0;
}
USERSTATUS_KIND m_get_userstatus_kind(int friendnumber) {
if (friendnumber >= numfriends || friendnumber < 0)
return USERSTATUS_KIND_INVALID;
USERSTATUS_KIND uk = friendlist[friendnumber].userstatus_kind;
if (uk >= USERSTATUS_KIND_INVALID) {
uk = USERSTATUS_KIND_ONLINE;
}
return uk;
}
USERSTATUS_KIND m_get_self_userstatus_kind(void) {
return self_userstatus_kind;
}
static int send_userstatus(int friendnumber, uint8_t * status, uint16_t length)
USERSTATUS m_get_userstatus(int friendnumber)
{
uint8_t *thepacket = malloc(length + 2);
memcpy(thepacket + 2, status, length);
thepacket[0] = PACKET_ID_USERSTATUS;
thepacket[1] = self_userstatus_kind;
int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, length + 2);
if (friendnumber >= numfriends || friendnumber < 0)
return USERSTATUS_INVALID;
USERSTATUS status = friendlist[friendnumber].userstatus;
if (status >= USERSTATUS_INVALID) {
status = USERSTATUS_NONE;
}
return status;
}
USERSTATUS m_get_self_userstatus(void)
{
return self_userstatus;
}
static int send_statusmessage(int friendnumber, uint8_t * status, uint16_t length)
{
uint8_t *thepacket = malloc(length + 1);
memcpy(thepacket + 1, status, length);
thepacket[0] = PACKET_ID_STATUSMESSAGE;
int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, length + 1);
free(thepacket);
return written;
}
static int set_friend_userstatus(int friendnumber, uint8_t * status, uint16_t length)
static int send_userstatus(int friendnumber, USERSTATUS status)
{
uint8_t *thepacket = malloc(1 + 1);
memcpy(thepacket + 1, &status, 1);
thepacket[0] = PACKET_ID_USERSTATUS;
int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, 1 + 1);
free(thepacket);
return written;
}
static int set_friend_statusmessage(int friendnumber, uint8_t * status, uint16_t length)
{
if (friendnumber >= numfriends || friendnumber < 0)
return -1;
uint8_t *newstatus = calloc(length, 1);
memcpy(newstatus, status, length);
free(friendlist[friendnumber].userstatus);
friendlist[friendnumber].userstatus = newstatus;
friendlist[friendnumber].userstatus_length = length;
free(friendlist[friendnumber].statusmessage);
friendlist[friendnumber].statusmessage = newstatus;
friendlist[friendnumber].statusmessage_length = length;
return 0;
}
static void set_friend_userstatus_kind(int friendnumber, USERSTATUS_KIND k)
static void set_friend_userstatus(int friendnumber, USERSTATUS status)
{
friendlist[friendnumber].userstatus_kind = k;
friendlist[friendnumber].userstatus = status;
}
/* Sets whether we send read receipts for friendnumber. */
@ -428,12 +436,20 @@ void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t))
friend_namechange_isset = 1;
}
static void (*friend_statuschange)(int, USERSTATUS_KIND, uint8_t *, uint16_t);
static uint8_t friend_statuschange_isset = 0;
void m_callback_userstatus(void (*function)(int, USERSTATUS_KIND, uint8_t *, uint16_t))
static void (*friend_statusmessagechange)(int, uint8_t *, uint16_t);
static uint8_t friend_statusmessagechange_isset = 0;
void m_callback_statusmessage(void (*function)(int, uint8_t *, uint16_t))
{
friend_statuschange = function;
friend_statuschange_isset = 1;
friend_statusmessagechange = function;
friend_statusmessagechange_isset = 1;
}
static void (*friend_userstatuschange)(int, USERSTATUS);
static uint8_t friend_userstatuschange_isset = 0;
void m_callback_userstatus(void (*function)(int, USERSTATUS))
{
friend_userstatuschange = function;
friend_userstatuschange_isset = 1;
}
static void (*read_receipt)(int, uint32_t);
@ -449,7 +465,7 @@ void m_callback_read_receipt(void (*function)(int, uint32_t))
int initMessenger(void)
{
new_keys();
m_set_userstatus(USERSTATUS_KIND_ONLINE, (uint8_t*)"Online", sizeof("Online"));
m_set_statusmessage((uint8_t*)"Online", sizeof("Online"));
initNetCrypto();
IP ip;
ip.i = 0;
@ -504,8 +520,12 @@ static void doFriends(void)
if (m_sendname(i, self_name, self_name_length))
friendlist[i].name_sent = 1;
}
if (friendlist[i].statusmessage_sent == 0) {
if (send_statusmessage(i, self_statusmessage, self_statusmessage_len))
friendlist[i].statusmessage_sent = 1;
}
if (friendlist[i].userstatus_sent == 0) {
if (send_userstatus(i, self_userstatus, self_userstatus_len))
if (send_userstatus(i, self_userstatus))
friendlist[i].userstatus_sent = 1;
}
len = read_cryptpacket(friendlist[i].crypt_connection_id, temp);
@ -520,18 +540,24 @@ static void doFriends(void)
friendlist[i].name[len - 2] = 0; /* make sure the NULL terminator is present. */
break;
}
case PACKET_ID_STATUSMESSAGE: {
if (len < 2)
break;
uint8_t *status = calloc(MIN(len - 1, MAX_STATUSMESSAGE_LENGTH), 1);
memcpy(status, temp + 1, MIN(len - 1, MAX_STATUSMESSAGE_LENGTH));
if (friend_statusmessagechange_isset)
friend_statusmessagechange(i, status, MIN(len - 1, MAX_STATUSMESSAGE_LENGTH));
set_friend_statusmessage(i, status, MIN(len - 1, MAX_STATUSMESSAGE_LENGTH));
free(status);
break;
}
case PACKET_ID_USERSTATUS: {
if (len > 2) {
uint8_t *status = calloc(MIN(len - 2, MAX_USERSTATUS_LENGTH), 1);
memcpy(status, temp + 2, MIN(len - 2, MAX_USERSTATUS_LENGTH));
if (friend_statuschange_isset)
friend_statuschange(i, temp[1], status, MIN(len - 2, MAX_USERSTATUS_LENGTH));
set_friend_userstatus(i, status, MIN(len - 2, MAX_USERSTATUS_LENGTH));
free(status);
} else if (friend_statuschange_isset) {
friend_statuschange(i, temp[1], friendlist[i].userstatus, friendlist[i].userstatus_length);
}
set_friend_userstatus_kind(i, temp[1]);
if (len != 2)
break;
USERSTATUS status = temp[1];
if (friend_userstatuschange_isset)
friend_userstatuschange(i, status);
set_friend_userstatus(i, status);
break;
}
case PACKET_ID_MESSAGE: {
@ -694,7 +720,7 @@ int Messenger_load(uint8_t * data, uint32_t length)
if(temp[i].status != 0) {
int fnum = m_addfriend_norequest(temp[i].client_id);
setfriendname(fnum, temp[i].name);
/* set_friend_userstatus(fnum, temp[i].userstatus, temp[i].userstatus_length); */
/* set_friend_statusmessage(fnum, temp[i].statusmessage, temp[i].statusmessage_length); */
}
}
free(temp);

View File

@ -36,10 +36,11 @@ extern "C" {
#endif
#define MAX_NAME_LENGTH 128
#define MAX_USERSTATUS_LENGTH 128
#define MAX_STATUSMESSAGE_LENGTH 128
#define PACKET_ID_NICKNAME 48
#define PACKET_ID_USERSTATUS 49
#define PACKET_ID_STATUSMESSAGE 49
#define PACKET_ID_USERSTATUS 50
#define PACKET_ID_RECEIPT 65
#define PACKET_ID_MESSAGE 64
@ -58,24 +59,18 @@ extern "C" {
#define FAERR_ALREADYSENT -4
#define FAERR_UNKNOWN -5
/* don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased
/* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased
to an absurdly large number later */
/* USERSTATUS_KIND
* Represents the different kinds of userstatus
* someone can have.
* More on this later... */
/* USERSTATUS
* Represents userstatuses someone can have. */
typedef enum {
USERSTATUS_KIND_RETAIN = (uint8_t)0, /* This is a special value that must not be returned by
* m_get_userstatus_kind. You can pass it into m_set_userstatus
* to keep the current USERSTATUS_KIND. */
USERSTATUS_KIND_ONLINE, /* Recommended representation: Green. */
USERSTATUS_KIND_AWAY, /* Recommended representation: Orange, or yellow. */
USERSTATUS_KIND_BUSY, /* Recommended representation: Red. */
USERSTATUS_KIND_OFFLINE, /* Recommended representation: Grey, semi-transparent. */
USERSTATUS_KIND_INVALID,
} USERSTATUS_KIND;
USERSTATUS_NONE,
USERSTATUS_AWAY,
USERSTATUS_BUSY,
USERSTATUS_INVALID
} USERSTATUS;
/*
* add a friend
@ -150,26 +145,26 @@ int getname(int friendnumber, uint8_t *name);
/* set our user status
you are responsible for freeing status after
returns 0 on success, -1 on failure */
int m_set_userstatus(USERSTATUS_KIND kind, uint8_t *status, uint16_t length);
int m_set_userstatus_kind(USERSTATUS_KIND kind);
int m_set_statusmessage(uint8_t *status, uint16_t length);
int m_set_userstatus(USERSTATUS status);
/* return the length of friendnumber's user status,
/* return the length of friendnumber's status message,
including null
pass it into malloc */
int m_get_userstatus_size(int friendnumber);
int m_get_statusmessage_size(int friendnumber);
/* copy friendnumber's userstatus into buf, truncating if size is over maxlen
get the size you need to allocate from m_get_userstatus_size
The self variant will copy our own userstatus. */
int m_copy_userstatus(int friendnumber, uint8_t *buf, uint32_t maxlen);
int m_copy_self_userstatus(uint8_t *buf, uint32_t maxlen);
/* copy friendnumber's status message into buf, truncating if size is over maxlen
get the size you need to allocate from m_get_statusmessage_size
The self variant will copy our own status message. */
int m_copy_statusmessage(int friendnumber, uint8_t *buf, uint32_t maxlen);
int m_copy_self_statusmessage(uint8_t *buf, uint32_t maxlen);
/* Return one of USERSTATUS_KIND values, except USERSTATUS_KIND_RETAIN.
* Values unknown to your application should be represented as USERSTATUS_KIND_ONLINE.
* As above, the self variant will return our own USERSTATUS_KIND.
* If friendnumber is invalid, this shall return USERSTATUS_KIND_INVALID. */
USERSTATUS_KIND m_get_userstatus_kind(int friendnumber);
USERSTATUS_KIND m_get_self_userstatus_kind(void);
/* Return one of USERSTATUS values.
* Values unknown to your application should be represented as USERSTATUS_NONE.
* As above, the self variant will return our own USERSTATUS.
* If friendnumber is invalid, this shall return USERSTATUS_INVALID. */
USERSTATUS m_get_userstatus(int friendnumber);
USERSTATUS m_get_self_userstatus(void);
/* Sets whether we send read receipts for friendnumber.
* This function is not lazy, and it will fail if yesno is not (0 or 1).*/
@ -188,10 +183,10 @@ void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t));
you are not responsible for freeing newname */
void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t));
/* set the callback for user status changes
function(int friendnumber, USERSTATUS_KIND kind, uint8_t *newstatus, uint16_t length)
/* set the callback for status message changes
function(int friendnumber, uint8_t *newstatus, uint16_t length)
you are not responsible for freeing newstatus */
void m_callback_userstatus(void (*function)(int, USERSTATUS_KIND, uint8_t *, uint16_t));
void m_callback_statusmessage(void (*function)(int, uint8_t *, uint16_t));
/* set the callback for read receipts
function(int friendnumber, uint32_t receipt)

View File

@ -220,7 +220,7 @@ void line_eval(char *line)
print_friendlist();
}
else if (inpt_command == 's') {
uint8_t status[MAX_USERSTATUS_LENGTH];
uint8_t status[MAX_STATUSMESSAGE_LENGTH];
int i = 0;
size_t len = strlen(line);
for (i = 3; i < len; i++) {
@ -228,7 +228,7 @@ void line_eval(char *line)
status[i-3] = line[i];
}
status[i-3] = 0;
m_set_userstatus(USERSTATUS_KIND_ONLINE, status, strlen((char*)status) + 1);
m_set_statusmessage(status, strlen((char*)status) + 1);
char numstring[100];
sprintf(numstring, "[i] changed status to %s", (char*)status);
new_lines(numstring);
@ -364,7 +364,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
}
}
void print_statuschange(int friendnumber, USERSTATUS_KIND kind, uint8_t *string, uint16_t length)
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
{
char name[MAX_NAME_LENGTH];
if(getname(friendnumber, (uint8_t*)name) != -1) {
@ -464,7 +464,7 @@ int main(int argc, char *argv[])
m_callback_friendrequest(print_request);
m_callback_friendmessage(print_message);
m_callback_namechange(print_nickchange);
m_callback_userstatus(print_statuschange);
m_callback_statusmessage(print_statuschange);
initscr();
noecho();

View File

@ -86,7 +86,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
printf(msg);
}
void print_statuschange(int friendnumber,USERSTATUS_KIND kind, uint8_t *string, uint16_t length)
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
{
char name[MAX_NAME_LENGTH];
getname(friendnumber, (uint8_t*)name);
@ -263,7 +263,7 @@ void change_nickname()
void change_status(int savetofile)
{
uint8_t status[MAX_USERSTATUS_LENGTH];
uint8_t status[MAX_STATUSMESSAGE_LENGTH];
int i = 0;
size_t len = strlen(line);
@ -275,7 +275,7 @@ void change_status(int savetofile)
}
status[i-3] = 0;
m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status));
m_set_statusmessage(status, strlen((char*)status));
char numstring[100];
sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
printf(numstring);
@ -403,11 +403,11 @@ int main(int argc, char *argv[])
FILE* status_file = NULL;
status_file = fopen("statusfile.txt", "r");
if(status_file) {
uint8_t status[MAX_USERSTATUS_LENGTH];
while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) {
uint8_t status[MAX_STATUSMESSAGE_LENGTH];
while (fgets(line, MAX_STATUSMESSAGE_LENGTH, status_file) != NULL) {
sscanf(line, "%s", (char*)status);
}
m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status)+1);
m_set_statusmessage(status, strlen((char*)status)+1);
statusloaded = 1;
printf("%s\n", status);
fclose(status_file);
@ -416,7 +416,7 @@ int main(int argc, char *argv[])
m_callback_friendrequest(print_request);
m_callback_friendmessage(print_message);
m_callback_namechange(print_nickchange);
m_callback_userstatus(print_statuschange);
m_callback_statusmessae(print_statuschange);
char idstring1[PUB_KEY_BYTES][5];
char idstring2[PUB_KEY_BYTES][5];
int i;

View File

@ -32,7 +32,7 @@
void do_header();
void print_message(int friendnumber, uint8_t * string, uint16_t length);
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length);
void print_statuschange(int friendnumber,USERSTATUS_KIND kind, uint8_t *string, uint16_t length);
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length);
void load_key();
void add_friend();
void list_friends();

View File

@ -161,7 +161,7 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd)
return;
}
msg++;
m_set_userstatus(USERSTATUS_KIND_RETAIN, (uint8_t*) msg, strlen(msg)+1);
m_set_statusmessage((uint8_t*) msg, strlen(msg)+1);
wprintw(ctx->history, "Status set to: %s\n", msg);
}

View File

@ -20,7 +20,7 @@ extern int active_window;
typedef struct {
uint8_t name[MAX_NAME_LENGTH];
uint8_t status[MAX_USERSTATUS_LENGTH];
uint8_t status[MAX_STATUSMESSAGE_LENGTH];
int num;
int chatwin;
} friend_t;
@ -74,7 +74,7 @@ void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint16_t le
void friendlist_onStatusChange(ToxWindow *self, int num, uint8_t *str, uint16_t len)
{
if (len >= MAX_USERSTATUS_LENGTH || num >= num_friends)
if (len >= MAX_STATUSMESSAGE_LENGTH || num >= num_friends)
return;
memcpy((char*) &friends[num].status, (char*) str, len);

View File

@ -193,27 +193,22 @@ static void execute(ToxWindow *self, char *u_cmd)
return;
}
status++;
USERSTATUS_KIND status_kind;
USERSTATUS status_kind;
if (!strncmp(status, "online", strlen("online"))) {
status_kind = USERSTATUS_KIND_ONLINE;
status_kind = USERSTATUS_NONE;
status_text = "ONLINE";
}
else if (!strncmp(status, "away", strlen("away"))) {
status_kind = USERSTATUS_KIND_AWAY;
status_kind = USERSTATUS_AWAY;
status_text = "AWAY";
}
else if (!strncmp(status, "busy", strlen("busy"))) {
status_kind = USERSTATUS_KIND_BUSY;
status_kind = USERSTATUS_BUSY;
status_text = "BUSY";
}
else if (!strncmp(status, "offline", strlen("offline"))) {
status_kind = USERSTATUS_KIND_OFFLINE;
status_text = "OFFLINE";
}
else
{
wprintw(self->window, "Invalid status.\n");
@ -222,12 +217,13 @@ static void execute(ToxWindow *self, char *u_cmd)
msg = strchr(status, ' ');
if (msg == NULL) {
m_set_userstatus_kind(status_kind);
m_set_userstatus(status_kind);
wprintw(self->window, "Status set to: %s\n", status_text);
}
else {
msg++;
m_set_userstatus(status_kind, (uint8_t*) msg, strlen(msg)+1);
m_set_userstatus(status_kind);
m_set_statusmessage((uint8_t*) msg, strlen(msg)+1);
wprintw(self->window, "Status set to: %s, %s\n", status_text, msg);
}
}
@ -239,7 +235,7 @@ static void execute(ToxWindow *self, char *u_cmd)
return;
}
msg++;
m_set_userstatus(USERSTATUS_KIND_RETAIN, (uint8_t*) msg, strlen(msg)+1);
m_set_statusmessage((uint8_t*) msg, strlen(msg)+1);
wprintw(self->window, "Status set to: %s\n", msg);
}