2013-07-07 10:28:15 +08:00
|
|
|
/* Messenger.c
|
2013-07-26 09:45:56 +08:00
|
|
|
*
|
|
|
|
* An implementation of a simple text chat only messenger on the tox network core.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Tox project All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Tox.
|
|
|
|
*
|
|
|
|
* Tox is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tox is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
2013-07-27 20:43:36 +08:00
|
|
|
*
|
2013-07-26 09:45:56 +08:00
|
|
|
*/
|
2013-07-07 10:28:15 +08:00
|
|
|
|
|
|
|
#include "Messenger.h"
|
2013-07-19 01:56:50 +08:00
|
|
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
2013-07-27 20:43:36 +08:00
|
|
|
|
2013-07-27 11:07:25 +08:00
|
|
|
typedef struct {
|
2013-07-07 10:28:15 +08:00
|
|
|
uint8_t client_id[CLIENT_ID_SIZE];
|
2013-07-09 08:50:25 +08:00
|
|
|
int crypt_connection_id;
|
2013-08-03 03:57:53 +08:00
|
|
|
uint64_t friend_request_id; /* id of the friend request corresponding to the current friend request to the current friend. */
|
2013-07-20 11:00:10 +08:00
|
|
|
uint8_t status; /* 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. */
|
|
|
|
uint8_t info[MAX_DATA_SIZE]; /* the data that is sent during the friend requests we do */
|
2013-07-18 23:47:27 +08:00
|
|
|
uint8_t name[MAX_NAME_LENGTH];
|
2013-07-20 11:00:10 +08:00
|
|
|
uint8_t name_sent; /* 0 if we didn't send our name to this friend 1 if we have. */
|
2013-07-19 01:56:50 +08:00
|
|
|
uint8_t *userstatus;
|
|
|
|
uint16_t userstatus_length;
|
|
|
|
uint8_t userstatus_sent;
|
2013-08-06 03:30:07 +08:00
|
|
|
USERSTATUS_KIND userstatus_kind;
|
2013-07-20 11:00:10 +08:00
|
|
|
uint16_t info_size; /* length of the info */
|
2013-07-27 11:07:25 +08:00
|
|
|
} Friend;
|
2013-07-17 07:02:44 +08:00
|
|
|
|
|
|
|
uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
|
|
|
|
|
2013-07-18 23:47:27 +08:00
|
|
|
static uint8_t self_name[MAX_NAME_LENGTH];
|
2013-07-28 09:08:06 +08:00
|
|
|
static uint16_t self_name_length;
|
|
|
|
|
2013-07-19 01:56:50 +08:00
|
|
|
static uint8_t *self_userstatus;
|
|
|
|
static uint16_t self_userstatus_len;
|
2013-08-06 03:30:07 +08:00
|
|
|
static USERSTATUS_KIND self_userstatus_kind;
|
2013-07-17 07:02:44 +08:00
|
|
|
|
2013-07-07 10:28:15 +08:00
|
|
|
#define MAX_NUM_FRIENDS 256
|
|
|
|
|
2013-07-13 04:27:19 +08:00
|
|
|
static Friend friendlist[MAX_NUM_FRIENDS];
|
2013-07-09 08:50:25 +08:00
|
|
|
|
2013-07-13 04:27:19 +08:00
|
|
|
static uint32_t numfriends;
|
2013-07-27 20:43:36 +08:00
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* 1 if we are online
|
|
|
|
0 if we are offline
|
|
|
|
static uint8_t online; */
|
2013-07-17 07:02:44 +08:00
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* return the friend id associated to that public key.
|
|
|
|
return -1 if no such friend */
|
2013-07-27 11:07:25 +08:00
|
|
|
int getfriend_id(uint8_t *client_id)
|
2013-07-10 08:25:52 +08:00
|
|
|
{
|
|
|
|
uint32_t i;
|
2013-07-27 06:17:24 +08:00
|
|
|
|
2013-07-27 11:07:25 +08:00
|
|
|
for (i = 0; i < numfriends; ++i) {
|
|
|
|
if (friendlist[i].status > 0)
|
|
|
|
if (memcmp(client_id, friendlist[i].client_id, crypto_box_PUBLICKEYBYTES) == 0)
|
2013-07-10 08:25:52 +08:00
|
|
|
return i;
|
2013-07-27 11:07:25 +08:00
|
|
|
}
|
2013-07-27 06:17:24 +08:00
|
|
|
|
2013-07-10 08:25:52 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* copies the public key associated to that friend id into client_id buffer.
|
|
|
|
make sure that client_id is of size CLIENT_ID_SIZE.
|
|
|
|
return 0 if success
|
|
|
|
return -1 if failure. */
|
2013-07-27 11:07:25 +08:00
|
|
|
int getclient_id(int friend_id, uint8_t *client_id)
|
2013-07-14 05:44:43 +08:00
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friend_id >= numfriends || friend_id < 0)
|
2013-07-14 05:44:43 +08:00
|
|
|
return -1;
|
|
|
|
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friendlist[friend_id].status > 0) {
|
2013-07-14 05:44:43 +08:00
|
|
|
memcpy(client_id, friendlist[friend_id].client_id, CLIENT_ID_SIZE);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-27 06:17:24 +08:00
|
|
|
|
2013-07-14 05:44:43 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-08-02 03:27:08 +08:00
|
|
|
/*
|
|
|
|
* add a friend
|
|
|
|
* set the data that will be sent along with friend request
|
|
|
|
* client_id is the client id of the friend
|
|
|
|
* data is the data and length is the length
|
|
|
|
* returns the friend number if success
|
2013-08-03 00:35:34 +08:00
|
|
|
* return FA_TOOLONG if message length is too long
|
|
|
|
* return FAERR_NOMESSAGE if no message (message length must be >= 1 byte)
|
|
|
|
* return FAERR_OWNKEY if user's own key
|
|
|
|
* return FAERR_ALREADYSENT if friend request already sent or already a friend
|
2013-08-06 03:30:07 +08:00
|
|
|
* return FAERR_UNKNOWN for unknown error
|
2013-08-02 03:27:08 +08:00
|
|
|
*/
|
2013-07-27 11:07:25 +08:00
|
|
|
int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
|
2013-07-07 10:28:15 +08:00
|
|
|
{
|
2013-08-06 03:30:07 +08:00
|
|
|
if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES
|
|
|
|
- crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
|
2013-08-01 09:42:28 +08:00
|
|
|
+ crypto_box_ZEROBYTES))
|
2013-08-03 00:33:11 +08:00
|
|
|
return FAERR_TOOLONG;
|
2013-08-02 03:27:08 +08:00
|
|
|
if (length < 1)
|
2013-08-03 00:33:11 +08:00
|
|
|
return FAERR_NOMESSAGE;
|
2013-08-02 03:27:08 +08:00
|
|
|
if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0)
|
2013-08-03 00:33:11 +08:00
|
|
|
return FAERR_OWNKEY;
|
2013-08-02 03:27:08 +08:00
|
|
|
if (getfriend_id(client_id) != -1)
|
2013-08-03 00:33:11 +08:00
|
|
|
return FAERR_ALREADYSENT;
|
2013-08-02 03:27:08 +08:00
|
|
|
|
2013-07-10 08:25:52 +08:00
|
|
|
uint32_t i;
|
2013-08-05 23:22:47 +08:00
|
|
|
for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
|
2013-08-03 00:33:11 +08:00
|
|
|
if(friendlist[i].status == NOFRIEND) {
|
2013-07-10 08:25:52 +08:00
|
|
|
DHT_addfriend(client_id);
|
2013-08-03 00:33:11 +08:00
|
|
|
friendlist[i].status = FRIEND_ADDED;
|
2013-07-17 07:02:44 +08:00
|
|
|
friendlist[i].crypt_connection_id = -1;
|
2013-07-10 08:25:52 +08:00
|
|
|
friendlist[i].friend_request_id = -1;
|
|
|
|
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
|
2013-07-19 01:56:50 +08:00
|
|
|
friendlist[i].userstatus = calloc(1, 1);
|
|
|
|
friendlist[i].userstatus_length = 1;
|
2013-08-06 03:30:07 +08:00
|
|
|
friendlist[i].userstatus_kind = USERSTATUS_KIND_OFFLINE;
|
2013-07-11 05:31:58 +08:00
|
|
|
memcpy(friendlist[i].info, data, length);
|
|
|
|
friendlist[i].info_size = length;
|
2013-07-27 20:43:36 +08:00
|
|
|
|
2013-07-20 00:18:29 +08:00
|
|
|
++numfriends;
|
2013-07-10 08:25:52 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2013-08-03 00:35:34 +08:00
|
|
|
return FAERR_UNKNOWN;
|
2013-07-07 10:28:15 +08:00
|
|
|
}
|
|
|
|
|
2013-07-10 01:20:48 +08:00
|
|
|
int m_addfriend_norequest(uint8_t * client_id)
|
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (getfriend_id(client_id) != -1)
|
2013-07-10 08:25:52 +08:00
|
|
|
return -1;
|
|
|
|
uint32_t i;
|
2013-08-05 23:22:47 +08:00
|
|
|
for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
|
2013-08-03 00:33:11 +08:00
|
|
|
if(friendlist[i].status == NOFRIEND) {
|
2013-07-10 08:25:52 +08:00
|
|
|
DHT_addfriend(client_id);
|
2013-08-03 00:33:11 +08:00
|
|
|
friendlist[i].status = FRIEND_REQUESTED;
|
2013-07-17 07:02:44 +08:00
|
|
|
friendlist[i].crypt_connection_id = -1;
|
2013-07-10 08:25:52 +08:00
|
|
|
friendlist[i].friend_request_id = -1;
|
|
|
|
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
|
2013-07-19 01:56:50 +08:00
|
|
|
friendlist[i].userstatus = calloc(1, 1);
|
|
|
|
friendlist[i].userstatus_length = 1;
|
2013-07-10 08:25:52 +08:00
|
|
|
numfriends++;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
2013-07-10 01:20:48 +08:00
|
|
|
}
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* remove a friend
|
|
|
|
return 0 if success
|
|
|
|
return -1 if failure */
|
2013-07-07 10:28:15 +08:00
|
|
|
int m_delfriend(int friendnumber)
|
2013-07-10 08:25:52 +08:00
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friendnumber >= numfriends || friendnumber < 0)
|
2013-07-10 08:25:52 +08:00
|
|
|
return -1;
|
|
|
|
|
2013-07-09 08:50:25 +08:00
|
|
|
DHT_delfriend(friendlist[friendnumber].client_id);
|
2013-07-14 23:52:32 +08:00
|
|
|
crypto_kill(friendlist[friendnumber].crypt_connection_id);
|
2013-07-19 01:56:50 +08:00
|
|
|
free(friendlist[friendnumber].userstatus);
|
2013-07-10 08:25:52 +08:00
|
|
|
memset(&friendlist[friendnumber], 0, sizeof(Friend));
|
|
|
|
uint32_t i;
|
2013-08-01 06:01:59 +08:00
|
|
|
|
2013-07-27 11:07:25 +08:00
|
|
|
for (i = numfriends; i != 0; --i) {
|
2013-08-03 00:33:11 +08:00
|
|
|
if (friendlist[i-1].status != NOFRIEND)
|
2013-07-10 08:25:52 +08:00
|
|
|
break;
|
2013-07-27 11:07:25 +08:00
|
|
|
}
|
2013-07-10 08:25:52 +08:00
|
|
|
numfriends = i;
|
2013-08-01 06:01:59 +08:00
|
|
|
|
2013-07-10 08:25:52 +08:00
|
|
|
return 0;
|
2013-07-09 08:50:25 +08:00
|
|
|
}
|
|
|
|
|
2013-08-03 00:35:34 +08:00
|
|
|
/* return FRIEND_ONLINE if friend is online
|
|
|
|
return FRIEND_CONFIRMED if friend is confirmed
|
|
|
|
return FRIEND_REQUESTED if the friend request was sent
|
|
|
|
return FRIEND_ADDED if the friend was added
|
|
|
|
return NOFRIEND if there is no friend with that number */
|
2013-07-09 08:50:25 +08:00
|
|
|
int m_friendstatus(int friendnumber)
|
2013-07-07 10:28:15 +08:00
|
|
|
{
|
2013-07-31 07:38:05 +08:00
|
|
|
if (friendnumber < 0 || friendnumber >= numfriends)
|
2013-08-03 00:33:11 +08:00
|
|
|
return NOFRIEND;
|
2013-07-09 08:50:25 +08:00
|
|
|
return friendlist[friendnumber].status;
|
2013-07-07 10:28:15 +08:00
|
|
|
}
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* send a text chat message to an online friend
|
|
|
|
return 1 if packet was successfully put into the send queue
|
|
|
|
return 0 if it was not */
|
2013-07-27 11:07:25 +08:00
|
|
|
int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length)
|
2013-07-07 10:28:15 +08:00
|
|
|
{
|
2013-07-31 07:38:05 +08:00
|
|
|
if (friendnumber < 0 || friendnumber >= numfriends)
|
2013-07-10 01:20:48 +08:00
|
|
|
return 0;
|
2013-08-03 00:33:11 +08:00
|
|
|
if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != FRIEND_ONLINE)
|
2013-07-27 20:43:36 +08:00
|
|
|
/* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */
|
2013-07-19 01:56:50 +08:00
|
|
|
return 0;
|
2013-07-09 08:50:25 +08:00
|
|
|
uint8_t temp[MAX_DATA_SIZE];
|
2013-07-19 04:58:03 +08:00
|
|
|
temp[0] = PACKET_ID_MESSAGE;
|
2013-07-09 08:50:25 +08:00
|
|
|
memcpy(temp + 1, message, length);
|
|
|
|
return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1);
|
2013-07-07 10:28:15 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 03:30:07 +08:00
|
|
|
/* send a name packet to friendnumber
|
2013-07-28 09:08:06 +08:00
|
|
|
length is the length with the NULL terminator*/
|
|
|
|
static int m_sendname(int friendnumber, uint8_t * name, uint16_t length)
|
2013-07-18 23:47:27 +08:00
|
|
|
{
|
2013-07-28 09:08:06 +08:00
|
|
|
if(length > MAX_NAME_LENGTH || length == 0)
|
|
|
|
return 0;
|
2013-07-18 23:47:27 +08:00
|
|
|
uint8_t temp[MAX_NAME_LENGTH + 1];
|
2013-07-28 09:08:06 +08:00
|
|
|
memcpy(temp + 1, name, length);
|
2013-07-19 04:58:03 +08:00
|
|
|
temp[0] = PACKET_ID_NICKNAME;
|
2013-07-28 09:08:06 +08:00
|
|
|
return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1);
|
2013-07-18 23:47:27 +08:00
|
|
|
}
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* set the name of a friend
|
|
|
|
return 0 if success
|
|
|
|
return -1 if failure */
|
2013-07-18 23:47:27 +08:00
|
|
|
static int setfriendname(int friendnumber, uint8_t * name)
|
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friendnumber >= numfriends || friendnumber < 0)
|
2013-07-18 23:47:27 +08:00
|
|
|
return -1;
|
|
|
|
memcpy(friendlist[friendnumber].name, name, MAX_NAME_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* Set our nickname
|
|
|
|
name must be a string of maximum MAX_NAME_LENGTH length.
|
2013-07-28 09:08:06 +08:00
|
|
|
length must be at least 1 byte
|
|
|
|
length is the length of name with the NULL terminator
|
2013-07-20 11:00:10 +08:00
|
|
|
return 0 if success
|
|
|
|
return -1 if failure */
|
2013-07-18 23:47:27 +08:00
|
|
|
int setname(uint8_t * name, uint16_t length)
|
|
|
|
{
|
2013-07-28 09:08:06 +08:00
|
|
|
if (length > MAX_NAME_LENGTH || length == 0)
|
2013-07-18 23:47:27 +08:00
|
|
|
return -1;
|
|
|
|
memcpy(self_name, name, length);
|
2013-07-28 09:08:06 +08:00
|
|
|
self_name_length = length;
|
2013-07-18 23:47:27 +08:00
|
|
|
uint32_t i;
|
2013-07-27 11:07:25 +08:00
|
|
|
for (i = 0; i < numfriends; ++i)
|
2013-07-18 23:47:27 +08:00
|
|
|
friendlist[i].name_sent = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-31 02:30:33 +08:00
|
|
|
/* get our nickname
|
2013-08-06 03:30:07 +08:00
|
|
|
put it in name
|
2013-07-31 02:32:18 +08:00
|
|
|
name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
|
2013-07-31 02:30:33 +08:00
|
|
|
return the length of the name */
|
|
|
|
uint16_t getself_name(uint8_t *name)
|
2013-07-30 23:09:09 +08:00
|
|
|
{
|
2013-07-31 02:30:33 +08:00
|
|
|
memcpy(name, self_name, self_name_length);
|
|
|
|
return self_name_length;
|
2013-08-06 03:30:07 +08:00
|
|
|
}
|
2013-07-30 23:09:09 +08:00
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* get name of friendnumber
|
|
|
|
put it in name
|
|
|
|
name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
|
|
|
|
return 0 if success
|
|
|
|
return -1 if failure */
|
2013-07-18 23:47:27 +08:00
|
|
|
int getname(int friendnumber, uint8_t * name)
|
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friendnumber >= numfriends || friendnumber < 0)
|
2013-07-18 23:47:27 +08:00
|
|
|
return -1;
|
|
|
|
memcpy(name, friendlist[friendnumber].name, MAX_NAME_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-07 10:28:15 +08:00
|
|
|
|
2013-08-06 03:30:07 +08:00
|
|
|
int m_set_userstatus(USERSTATUS_KIND kind, uint8_t *status, uint16_t length)
|
2013-07-19 01:56:50 +08:00
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (length > MAX_USERSTATUS_LENGTH)
|
2013-07-19 01:56:50 +08:00
|
|
|
return -1;
|
2013-08-06 03:30:07 +08:00
|
|
|
if (kind != USERSTATUS_KIND_RETAIN) {
|
|
|
|
self_userstatus_kind = kind;
|
|
|
|
}
|
2013-07-19 01:56:50 +08:00
|
|
|
uint8_t *newstatus = calloc(length, 1);
|
|
|
|
memcpy(newstatus, status, length);
|
|
|
|
free(self_userstatus);
|
|
|
|
self_userstatus = newstatus;
|
|
|
|
self_userstatus_len = length;
|
|
|
|
|
|
|
|
uint32_t i;
|
2013-07-27 11:07:25 +08:00
|
|
|
for (i = 0; i < numfriends; ++i)
|
2013-07-19 01:56:50 +08:00
|
|
|
friendlist[i].userstatus_sent = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-06 03:30:07 +08:00
|
|
|
int m_set_userstatus_kind(USERSTATUS_KIND kind) {
|
|
|
|
if (kind >= USERSTATUS_KIND_INVALID) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (kind == USERSTATUS_KIND_RETAIN) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
self_userstatus_kind = kind;
|
|
|
|
uint32_t i;
|
|
|
|
for (i = 0; i < numfriends; ++i)
|
|
|
|
friendlist[i].userstatus_sent = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* return the size of friendnumber's user status
|
|
|
|
guaranteed to be at most MAX_USERSTATUS_LENGTH */
|
2013-07-19 01:56:50 +08:00
|
|
|
int m_get_userstatus_size(int friendnumber)
|
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friendnumber >= numfriends || friendnumber < 0)
|
2013-07-19 01:56:50 +08:00
|
|
|
return -1;
|
|
|
|
return friendlist[friendnumber].userstatus_length;
|
|
|
|
}
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* 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 */
|
2013-07-19 01:56:50 +08:00
|
|
|
int m_copy_userstatus(int friendnumber, uint8_t * buf, uint32_t maxlen)
|
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friendnumber >= numfriends || friendnumber < 0)
|
2013-07-19 01:56:50 +08:00
|
|
|
return -1;
|
2013-07-19 02:13:29 +08:00
|
|
|
memset(buf, 0, maxlen);
|
2013-07-19 01:56:50 +08:00
|
|
|
memcpy(buf, friendlist[friendnumber].userstatus, MIN(maxlen, MAX_USERSTATUS_LENGTH) - 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-06 03:30:07 +08:00
|
|
|
int m_copy_self_userstatus(uint8_t * buf, uint32_t maxlen)
|
|
|
|
{
|
|
|
|
memset(buf, 0, maxlen);
|
|
|
|
memcpy(buf, self_userstatus, MIN(maxlen, MAX_USERSTATUS_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;
|
|
|
|
}
|
|
|
|
|
2013-07-19 01:56:50 +08:00
|
|
|
static int send_userstatus(int friendnumber, uint8_t * status, uint16_t length)
|
|
|
|
{
|
2013-08-06 03:30:07 +08:00
|
|
|
uint8_t *thepacket = malloc(length + 2);
|
|
|
|
memcpy(thepacket + 2, status, length);
|
2013-07-19 04:58:03 +08:00
|
|
|
thepacket[0] = PACKET_ID_USERSTATUS;
|
2013-08-06 03:30:07 +08:00
|
|
|
thepacket[1] = self_userstatus_kind;
|
2013-07-19 02:13:29 +08:00
|
|
|
int written = write_cryptpacket(friendlist[friendnumber].crypt_connection_id, thepacket, length + 1);
|
|
|
|
free(thepacket);
|
|
|
|
return written;
|
2013-07-19 01:56:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int set_friend_userstatus(int friendnumber, uint8_t * status, uint16_t length)
|
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friendnumber >= numfriends || friendnumber < 0)
|
2013-07-19 01:56:50 +08:00
|
|
|
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;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-26 16:02:17 +08:00
|
|
|
|
2013-08-06 03:30:07 +08:00
|
|
|
static void set_friend_userstatus_kind(int friendnumber, USERSTATUS_KIND k)
|
|
|
|
{
|
|
|
|
friendlist[friendnumber].userstatus_kind = k;
|
|
|
|
}
|
|
|
|
|
2013-07-27 06:17:24 +08:00
|
|
|
/* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t);
|
|
|
|
static uint8_t friend_request_isset = 0; */
|
2013-07-20 11:00:10 +08:00
|
|
|
/* set the function that will be executed when a friend request is received. */
|
2013-07-10 01:20:48 +08:00
|
|
|
void m_callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t))
|
2013-07-07 10:28:15 +08:00
|
|
|
{
|
2013-07-23 02:52:42 +08:00
|
|
|
callback_friendrequest(function);
|
2013-07-09 08:50:25 +08:00
|
|
|
}
|
|
|
|
|
2013-07-13 04:27:19 +08:00
|
|
|
static void (*friend_message)(int, uint8_t *, uint16_t);
|
2013-07-20 10:40:23 +08:00
|
|
|
static uint8_t friend_message_isset = 0;
|
2013-07-09 08:50:25 +08:00
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* set the function that will be executed when a message from a friend is received. */
|
2013-07-10 01:20:48 +08:00
|
|
|
void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t))
|
2013-07-09 08:50:25 +08:00
|
|
|
{
|
|
|
|
friend_message = function;
|
2013-07-20 10:40:23 +08:00
|
|
|
friend_message_isset = 1;
|
2013-07-07 10:28:15 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 01:56:50 +08:00
|
|
|
static void (*friend_namechange)(int, uint8_t *, uint16_t);
|
2013-07-20 10:40:23 +08:00
|
|
|
static uint8_t friend_namechange_isset = 0;
|
2013-07-19 01:56:50 +08:00
|
|
|
void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t))
|
|
|
|
{
|
|
|
|
friend_namechange = function;
|
2013-07-20 10:40:23 +08:00
|
|
|
friend_namechange_isset = 1;
|
2013-07-19 01:56:50 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 03:30:07 +08:00
|
|
|
static void (*friend_statuschange)(int, USERSTATUS_KIND, uint8_t *, uint16_t);
|
2013-07-20 10:40:23 +08:00
|
|
|
static uint8_t friend_statuschange_isset = 0;
|
2013-08-06 03:30:07 +08:00
|
|
|
void m_callback_userstatus(void (*function)(int, USERSTATUS_KIND, uint8_t *, uint16_t))
|
2013-07-19 01:56:50 +08:00
|
|
|
{
|
|
|
|
friend_statuschange = function;
|
2013-07-20 10:40:23 +08:00
|
|
|
friend_statuschange_isset = 1;
|
2013-07-19 01:56:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-07 10:28:15 +08:00
|
|
|
#define PORT 33445
|
2013-07-20 11:00:10 +08:00
|
|
|
/* run this at startup */
|
2013-08-05 21:57:17 +08:00
|
|
|
int initMessenger(void)
|
2013-07-07 10:28:15 +08:00
|
|
|
{
|
|
|
|
new_keys();
|
2013-08-06 03:30:07 +08:00
|
|
|
m_set_userstatus(USERSTATUS_KIND_ONLINE, (uint8_t*)"Online", sizeof("Online"));
|
2013-07-09 08:50:25 +08:00
|
|
|
initNetCrypto();
|
2013-07-07 10:28:15 +08:00
|
|
|
IP ip;
|
|
|
|
ip.i = 0;
|
2013-07-24 07:32:50 +08:00
|
|
|
|
|
|
|
if(init_networking(ip,PORT) == -1)
|
2013-07-26 09:00:31 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
2013-07-07 10:28:15 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 11:07:25 +08:00
|
|
|
//TODO: make this function not suck.
|
2013-08-05 21:57:17 +08:00
|
|
|
static void doFriends(void)
|
2013-07-27 20:43:36 +08:00
|
|
|
{
|
|
|
|
/* TODO: add incoming connections and some other stuff. */
|
2013-07-09 08:50:25 +08:00
|
|
|
uint32_t i;
|
|
|
|
int len;
|
|
|
|
uint8_t temp[MAX_DATA_SIZE];
|
2013-07-27 11:07:25 +08:00
|
|
|
for (i = 0; i < numfriends; ++i) {
|
2013-08-03 00:33:11 +08:00
|
|
|
if (friendlist[i].status == FRIEND_ADDED) {
|
2013-07-23 02:52:42 +08:00
|
|
|
int fr = send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size);
|
2013-07-27 11:07:25 +08:00
|
|
|
if (fr == 0) /* TODO: This needs to be fixed so that it sends the friend requests a couple of times in case of packet loss */
|
2013-08-03 00:33:11 +08:00
|
|
|
friendlist[i].status = FRIEND_REQUESTED;
|
2013-07-27 11:07:25 +08:00
|
|
|
else if (fr > 0)
|
2013-08-03 00:33:11 +08:00
|
|
|
friendlist[i].status = FRIEND_REQUESTED;
|
2013-07-09 08:50:25 +08:00
|
|
|
}
|
2013-08-03 00:33:11 +08:00
|
|
|
if (friendlist[i].status == FRIEND_REQUESTED || friendlist[i].status == FRIEND_CONFIRMED) { /* friend is not online */
|
|
|
|
if (friendlist[i].status == FRIEND_REQUESTED) {
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friendlist[i].friend_request_id + 10 < unix_time()) { /*I know this is hackish but it should work.*/
|
2013-07-23 05:02:32 +08:00
|
|
|
send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size);
|
|
|
|
friendlist[i].friend_request_id = unix_time();
|
|
|
|
}
|
|
|
|
}
|
2013-07-09 08:50:25 +08:00
|
|
|
IP_Port friendip = DHT_getfriendip(friendlist[i].client_id);
|
2013-07-27 11:07:25 +08:00
|
|
|
switch (is_cryptoconnected(friendlist[i].crypt_connection_id)) {
|
2013-07-27 20:43:36 +08:00
|
|
|
case 0:
|
|
|
|
if (friendip.ip.i > 1)
|
|
|
|
friendlist[i].crypt_connection_id = crypto_connect(friendlist[i].client_id, friendip);
|
|
|
|
break;
|
|
|
|
case 3: /* Connection is established */
|
2013-08-03 00:33:11 +08:00
|
|
|
friendlist[i].status = FRIEND_ONLINE;
|
2013-07-27 20:43:36 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
crypto_kill(friendlist[i].crypt_connection_id);
|
|
|
|
friendlist[i].crypt_connection_id = -1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-07-10 01:20:48 +08:00
|
|
|
}
|
2013-07-09 08:50:25 +08:00
|
|
|
}
|
2013-08-03 00:33:11 +08:00
|
|
|
while (friendlist[i].status == FRIEND_ONLINE) { /* friend is online */
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friendlist[i].name_sent == 0) {
|
2013-07-28 09:08:06 +08:00
|
|
|
if (m_sendname(i, self_name, self_name_length))
|
2013-07-18 23:47:27 +08:00
|
|
|
friendlist[i].name_sent = 1;
|
2013-07-27 11:07:25 +08:00
|
|
|
}
|
|
|
|
if (friendlist[i].userstatus_sent == 0) {
|
|
|
|
if (send_userstatus(i, self_userstatus, self_userstatus_len))
|
2013-07-19 01:56:50 +08:00
|
|
|
friendlist[i].userstatus_sent = 1;
|
2013-07-27 11:07:25 +08:00
|
|
|
}
|
2013-07-09 08:50:25 +08:00
|
|
|
len = read_cryptpacket(friendlist[i].crypt_connection_id, temp);
|
2013-07-27 11:07:25 +08:00
|
|
|
if (len > 0) {
|
|
|
|
switch (temp[0]) {
|
2013-07-27 20:43:36 +08:00
|
|
|
case PACKET_ID_NICKNAME: {
|
2013-07-28 09:08:06 +08:00
|
|
|
if (len >= MAX_NAME_LENGTH + 1 || len == 1)
|
2013-07-19 01:56:50 +08:00
|
|
|
break;
|
2013-07-27 20:43:36 +08:00
|
|
|
if(friend_namechange_isset)
|
2013-07-28 09:08:06 +08:00
|
|
|
friend_namechange(i, temp + 1, len - 1);
|
|
|
|
memcpy(friendlist[i].name, temp + 1, len - 1);
|
|
|
|
friendlist[i].name[len - 2] = 0; /* make sure the NULL terminator is present. */
|
2013-07-27 20:43:36 +08:00
|
|
|
break;
|
2013-07-19 01:56:50 +08:00
|
|
|
}
|
2013-07-27 20:43:36 +08:00
|
|
|
case PACKET_ID_USERSTATUS: {
|
2013-08-06 03:30:07 +08:00
|
|
|
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]);
|
2013-07-27 20:43:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PACKET_ID_MESSAGE: {
|
|
|
|
if (friend_message_isset)
|
|
|
|
(*friend_message)(i, temp + 1, len - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (is_cryptoconnected(friendlist[i].crypt_connection_id) == 4) { /* if the connection timed out, kill it */
|
|
|
|
crypto_kill(friendlist[i].crypt_connection_id);
|
|
|
|
friendlist[i].crypt_connection_id = -1;
|
2013-08-03 00:33:11 +08:00
|
|
|
friendlist[i].status = FRIEND_CONFIRMED;
|
2013-07-27 20:43:36 +08:00
|
|
|
}
|
|
|
|
break;
|
2013-07-09 08:50:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-05 21:57:17 +08:00
|
|
|
static void doInbound(void)
|
2013-07-10 01:20:48 +08:00
|
|
|
{
|
|
|
|
uint8_t secret_nonce[crypto_box_NONCEBYTES];
|
|
|
|
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
|
|
|
|
uint8_t session_key[crypto_box_PUBLICKEYBYTES];
|
|
|
|
int inconnection = crypto_inbound(public_key, secret_nonce, session_key);
|
2013-07-27 11:07:25 +08:00
|
|
|
if (inconnection != -1) {
|
2013-07-10 01:20:48 +08:00
|
|
|
int friend_id = getfriend_id(public_key);
|
2013-07-27 11:07:25 +08:00
|
|
|
if (friend_id != -1) {
|
2013-07-27 20:43:36 +08:00
|
|
|
crypto_kill(friendlist[friend_id].crypt_connection_id);
|
|
|
|
friendlist[friend_id].crypt_connection_id =
|
|
|
|
accept_crypto_inbound(inconnection, public_key, secret_nonce, session_key);
|
|
|
|
|
2013-08-03 00:33:11 +08:00
|
|
|
friendlist[friend_id].status = FRIEND_CONFIRMED;
|
2013-07-10 01:20:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 22:24:56 +08:00
|
|
|
/*Interval in seconds between LAN discovery packet sending*/
|
|
|
|
#define LAN_DISCOVERY_INTERVAL 60
|
|
|
|
|
2013-08-03 03:57:53 +08:00
|
|
|
static uint64_t last_LANdiscovery;
|
2013-07-26 22:24:56 +08:00
|
|
|
|
|
|
|
/*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/
|
2013-08-05 21:57:17 +08:00
|
|
|
static void LANdiscovery(void)
|
2013-07-26 22:24:56 +08:00
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) {
|
2013-07-26 22:24:56 +08:00
|
|
|
send_LANdiscovery(htons(PORT));
|
|
|
|
last_LANdiscovery = unix_time();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* the main loop that needs to be run at least 200 times per second. */
|
2013-08-05 21:57:17 +08:00
|
|
|
void doMessenger(void)
|
2013-07-07 10:28:15 +08:00
|
|
|
{
|
|
|
|
IP_Port ip_port;
|
|
|
|
uint8_t data[MAX_UDP_PACKET_SIZE];
|
|
|
|
uint32_t length;
|
2013-07-27 11:07:25 +08:00
|
|
|
while (receivepacket(&ip_port, data, &length) != -1) {
|
2013-07-14 23:40:42 +08:00
|
|
|
#ifdef DEBUG
|
2013-07-20 11:00:10 +08:00
|
|
|
/* if(rand() % 3 != 1) //simulate packet loss */
|
|
|
|
/* { */
|
2013-07-27 20:43:36 +08:00
|
|
|
if (DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port) &&
|
|
|
|
friendreq_handlepacket(data, length, ip_port) && LANdiscovery_handlepacket(data, length, ip_port))
|
2013-07-20 11:00:10 +08:00
|
|
|
/* if packet is discarded */
|
2013-07-14 23:40:42 +08:00
|
|
|
printf("Received unhandled packet with length: %u\n", length);
|
2013-07-07 10:28:15 +08:00
|
|
|
else
|
2013-07-14 23:40:42 +08:00
|
|
|
printf("Received handled packet with length: %u\n", length);
|
2013-07-20 11:00:10 +08:00
|
|
|
/* } */
|
2013-07-18 00:07:19 +08:00
|
|
|
printf("Status: %u %u %u\n",friendlist[0].status ,is_cryptoconnected(friendlist[0].crypt_connection_id), friendlist[0].crypt_connection_id);
|
2013-07-14 23:40:42 +08:00
|
|
|
#else
|
|
|
|
DHT_handlepacket(data, length, ip_port);
|
|
|
|
LosslessUDP_handlepacket(data, length, ip_port);
|
2013-07-23 02:52:42 +08:00
|
|
|
friendreq_handlepacket(data, length, ip_port);
|
2013-07-26 22:24:56 +08:00
|
|
|
LANdiscovery_handlepacket(data, length, ip_port);
|
2013-07-14 23:40:42 +08:00
|
|
|
#endif
|
|
|
|
|
2013-07-07 10:28:15 +08:00
|
|
|
}
|
|
|
|
doDHT();
|
|
|
|
doLossless_UDP();
|
|
|
|
doNetCrypto();
|
2013-07-10 01:20:48 +08:00
|
|
|
doInbound();
|
2013-07-09 08:50:25 +08:00
|
|
|
doFriends();
|
2013-07-26 22:24:56 +08:00
|
|
|
LANdiscovery();
|
2013-07-09 08:50:25 +08:00
|
|
|
}
|
2013-07-17 07:02:44 +08:00
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* returns the size of the messenger data (for saving) */
|
2013-08-05 21:57:17 +08:00
|
|
|
uint32_t Messenger_size(void)
|
2013-07-18 00:07:19 +08:00
|
|
|
{
|
|
|
|
return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES
|
2013-07-27 20:43:36 +08:00
|
|
|
+ sizeof(uint32_t) + DHT_size() + sizeof(uint32_t) + sizeof(Friend) * numfriends;
|
2013-07-18 00:07:19 +08:00
|
|
|
}
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* save the messenger in data of size Messenger_size() */
|
2013-07-27 11:07:25 +08:00
|
|
|
void Messenger_save(uint8_t *data)
|
2013-07-18 00:07:19 +08:00
|
|
|
{
|
|
|
|
save_keys(data);
|
|
|
|
data += crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
|
|
|
|
uint32_t size = DHT_size();
|
|
|
|
memcpy(data, &size, sizeof(size));
|
|
|
|
data += sizeof(size);
|
|
|
|
DHT_save(data);
|
|
|
|
data += size;
|
|
|
|
size = sizeof(Friend) * numfriends;
|
|
|
|
memcpy(data, &size, sizeof(size));
|
|
|
|
data += sizeof(size);
|
|
|
|
memcpy(data, friendlist, sizeof(Friend) * numfriends);
|
|
|
|
}
|
|
|
|
|
2013-07-20 11:00:10 +08:00
|
|
|
/* load the messenger from data of size length. */
|
2013-07-18 00:07:19 +08:00
|
|
|
int Messenger_load(uint8_t * data, uint32_t length)
|
|
|
|
{
|
2013-07-27 11:07:25 +08:00
|
|
|
if (length == ~0)
|
2013-07-18 00:07:19 +08:00
|
|
|
return -1;
|
2013-07-27 11:07:25 +08:00
|
|
|
if (length < crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t) * 2)
|
2013-07-18 00:07:19 +08:00
|
|
|
return -1;
|
|
|
|
length -= crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t) * 2;
|
|
|
|
load_keys(data);
|
|
|
|
data += crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
|
|
|
|
uint32_t size;
|
|
|
|
memcpy(&size, data, sizeof(size));
|
|
|
|
data += sizeof(size);
|
2013-07-27 20:43:36 +08:00
|
|
|
|
2013-07-27 11:07:25 +08:00
|
|
|
if (length < size)
|
2013-07-18 00:07:19 +08:00
|
|
|
return -1;
|
|
|
|
length -= size;
|
2013-07-27 11:07:25 +08:00
|
|
|
if (DHT_load(data, size) == -1)
|
2013-07-18 00:07:19 +08:00
|
|
|
return -1;
|
|
|
|
data += size;
|
|
|
|
memcpy(&size, data, sizeof(size));
|
|
|
|
data += sizeof(size);
|
2013-07-27 11:07:25 +08:00
|
|
|
if (length != size || length % sizeof(Friend) != 0)
|
2013-07-18 00:07:19 +08:00
|
|
|
return -1;
|
2013-07-27 20:43:36 +08:00
|
|
|
|
2013-07-18 00:07:19 +08:00
|
|
|
Friend * temp = malloc(size);
|
|
|
|
memcpy(temp, data, size);
|
2013-07-27 20:43:36 +08:00
|
|
|
|
2013-07-18 00:07:19 +08:00
|
|
|
uint16_t num = size / sizeof(Friend);
|
2013-07-27 20:43:36 +08:00
|
|
|
|
2013-07-18 00:07:19 +08:00
|
|
|
uint32_t i;
|
2013-07-27 11:07:25 +08:00
|
|
|
for (i = 0; i < num; ++i) {
|
|
|
|
if(temp[i].status != 0) {
|
2013-07-19 05:10:26 +08:00
|
|
|
int fnum = m_addfriend_norequest(temp[i].client_id);
|
|
|
|
setfriendname(fnum, temp[i].name);
|
2013-07-20 11:00:10 +08:00
|
|
|
/* set_friend_userstatus(fnum, temp[i].userstatus, temp[i].userstatus_length); */
|
2013-07-19 05:10:26 +08:00
|
|
|
}
|
2013-07-18 00:07:19 +08:00
|
|
|
}
|
|
|
|
free(temp);
|
|
|
|
return 0;
|
|
|
|
}
|