summaryrefslogtreecommitdiff
path: root/core/Messenger.h
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-27 08:43:36 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-27 08:43:36 -0400
commit14b43651c10b596efc33e11739c22321c3dbc3bf (patch)
tree26310e5bb35b693d607076db57bf682387f4c7df /core/Messenger.h
parent1a6446266c9727e5c95e18d5e44157fd5a60900f (diff)
Ran the code through: astyle --style=linux
Diffstat (limited to 'core/Messenger.h')
-rw-r--r--core/Messenger.h216
1 files changed, 108 insertions, 108 deletions
diff --git a/core/Messenger.h b/core/Messenger.h
index 0e2606d9..3cdeeb93 100644
--- a/core/Messenger.h
+++ b/core/Messenger.h
@@ -3,7 +3,7 @@
3 * An implementation of a simple text chat only messenger on the tox network core. 3 * An implementation of a simple text chat only messenger on the tox network core.
4 * 4 *
5 * NOTE: All the text in the messages must be encoded using UTF-8 5 * NOTE: All the text in the messages must be encoded using UTF-8
6 * 6 *
7 * Copyright (C) 2013 Tox project All Rights Reserved. 7 * Copyright (C) 2013 Tox project All Rights Reserved.
8 * 8 *
9 * This file is part of Tox. 9 * This file is part of Tox.
@@ -20,8 +20,8 @@
20 * 20 *
21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 22 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
23 * 23 *
24 */ 24 */
25 25
26#ifndef MESSENGER_H 26#ifndef MESSENGER_H
27#define MESSENGER_H 27#define MESSENGER_H
@@ -42,111 +42,111 @@ extern "C" {
42#define PACKET_ID_USERSTATUS 49 42#define PACKET_ID_USERSTATUS 49
43#define PACKET_ID_MESSAGE 64 43#define PACKET_ID_MESSAGE 64
44 44
45/* don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased 45 /* don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased
46 to an absurdly large number later */ 46 to an absurdly large number later */
47 47
48/* add a friend 48 /* add a friend
49 set the data that will be sent along with friend request 49 set the data that will be sent along with friend request
50 client_id is the client id of the friend 50 client_id is the client id of the friend
51 data is the data and length is the length 51 data is the data and length is the length
52 returns the friend number if success 52 returns the friend number if success
53 return -1 if failure. */ 53 return -1 if failure. */
54int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length); 54 int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length);
55 55
56 56
57/* add a friend without sending a friendrequest. 57 /* add a friend without sending a friendrequest.
58 returns the friend number if success 58 returns the friend number if success
59 return -1 if failure. */ 59 return -1 if failure. */
60int m_addfriend_norequest(uint8_t *client_id); 60 int m_addfriend_norequest(uint8_t *client_id);
61 61
62/* return the friend id associated to that client id. 62 /* return the friend id associated to that client id.
63 return -1 if no such friend */ 63 return -1 if no such friend */
64int getfriend_id(uint8_t *client_id); 64 int getfriend_id(uint8_t *client_id);
65 65
66/* copies the public key associated to that friend id into client_id buffer. 66 /* copies the public key associated to that friend id into client_id buffer.
67 make sure that client_id is of size CLIENT_ID_SIZE. 67 make sure that client_id is of size CLIENT_ID_SIZE.
68 return 0 if success 68 return 0 if success
69 return -1 if failure */ 69 return -1 if failure */
70int getclient_id(int friend_id, uint8_t *client_id); 70 int getclient_id(int friend_id, uint8_t *client_id);
71 71
72/* remove a friend */ 72 /* remove a friend */
73int m_delfriend(int friendnumber); 73 int m_delfriend(int friendnumber);
74 74
75/* return 4 if friend is online 75 /* return 4 if friend is online
76 return 3 if friend is confirmed 76 return 3 if friend is confirmed
77 return 2 if the friend request was sent 77 return 2 if the friend request was sent
78 return 1 if the friend was added 78 return 1 if the friend was added
79 return 0 if there is no friend with that number */ 79 return 0 if there is no friend with that number */
80int m_friendstatus(int friendnumber); 80 int m_friendstatus(int friendnumber);
81 81
82/* send a text chat message to an online friend 82 /* send a text chat message to an online friend
83 returns 1 if packet was successfully put into the send queue 83 returns 1 if packet was successfully put into the send queue
84 return 0 if it was not */ 84 return 0 if it was not */
85int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length); 85 int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length);
86 86
87/* Set our nickname 87 /* Set our nickname
88 name must be a string of maximum MAX_NAME_LENGTH length. 88 name must be a string of maximum MAX_NAME_LENGTH length.
89 return 0 if success 89 return 0 if success
90 return -1 if failure */ 90 return -1 if failure */
91int setname(uint8_t *name, uint16_t length); 91 int setname(uint8_t *name, uint16_t length);
92 92
93/* get name of friendnumber 93 /* get name of friendnumber
94 put it in name 94 put it in name
95 name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. 95 name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
96 return 0 if success 96 return 0 if success
97 return -1 if failure */ 97 return -1 if failure */
98int getname(int friendnumber, uint8_t *name); 98 int getname(int friendnumber, uint8_t *name);
99 99
100/* set our user status 100 /* set our user status
101 you are responsible for freeing status after 101 you are responsible for freeing status after
102 returns 0 on success, -1 on failure */ 102 returns 0 on success, -1 on failure */
103int m_set_userstatus(uint8_t *status, uint16_t length); 103 int m_set_userstatus(uint8_t *status, uint16_t length);
104 104
105/* return the length of friendnumber's user status, 105 /* return the length of friendnumber's user status,
106 including null 106 including null
107 pass it into malloc */ 107 pass it into malloc */
108int m_get_userstatus_size(int friendnumber); 108 int m_get_userstatus_size(int friendnumber);
109 109
110/* copy friendnumber's userstatus into buf, truncating if size is over maxlen 110 /* copy friendnumber's userstatus into buf, truncating if size is over maxlen
111 get the size you need to allocate from m_get_userstatus_size */ 111 get the size you need to allocate from m_get_userstatus_size */
112int m_copy_userstatus(int friendnumber, uint8_t *buf, uint32_t maxlen); 112 int m_copy_userstatus(int friendnumber, uint8_t *buf, uint32_t maxlen);
113 113
114/* set the function that will be executed when a friend request is received. 114 /* set the function that will be executed when a friend request is received.
115 function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) */ 115 function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) */
116void m_callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t)); 116 void m_callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t));
117 117
118/* set the function that will be executed when a message from a friend is received. 118 /* set the function that will be executed when a message from a friend is received.
119 function format is: function(int friendnumber, uint8_t * message, uint32_t length) */ 119 function format is: function(int friendnumber, uint8_t * message, uint32_t length) */
120void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t)); 120 void m_callback_friendmessage(void (*function)(int, uint8_t *, uint16_t));
121 121
122/* set the callback for name changes 122 /* set the callback for name changes
123 function(int friendnumber, uint8_t *newname, uint16_t length) 123 function(int friendnumber, uint8_t *newname, uint16_t length)
124 you are not responsible for freeing newname */ 124 you are not responsible for freeing newname */
125void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t)); 125 void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t));
126 126
127/* set the callback for user status changes 127 /* set the callback for user status changes
128 function(int friendnumber, uint8_t *newstatus, uint16_t length) 128 function(int friendnumber, uint8_t *newstatus, uint16_t length)
129 you are not responsible for freeing newstatus */ 129 you are not responsible for freeing newstatus */
130void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t)); 130 void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t));
131 131
132/* run this at startup 132 /* run this at startup
133 returns 0 if no connection problems 133 returns 0 if no connection problems
134 returns -1 if there are problems */ 134 returns -1 if there are problems */
135int initMessenger(); 135 int initMessenger();
136 136
137/* the main loop that needs to be run at least 200 times per second */ 137 /* the main loop that needs to be run at least 200 times per second */
138void doMessenger(); 138 void doMessenger();
139 139
140/* SAVING AND LOADING FUNCTIONS: */ 140 /* SAVING AND LOADING FUNCTIONS: */
141 141
142/* returns the size of the messenger data (for saving) */ 142 /* returns the size of the messenger data (for saving) */
143uint32_t Messenger_size(); 143 uint32_t Messenger_size();
144 144
145/* save the messenger in data (must be allocated memory of size Messenger_size()) */ 145 /* save the messenger in data (must be allocated memory of size Messenger_size()) */
146void Messenger_save(uint8_t *data); 146 void Messenger_save(uint8_t *data);
147 147
148/* load the messenger from data of size length */ 148 /* load the messenger from data of size length */
149int Messenger_load(uint8_t *data, uint32_t length); 149 int Messenger_load(uint8_t *data, uint32_t length);
150 150
151#ifdef __cplusplus 151#ifdef __cplusplus
152} 152}