diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/network.c | 8 | ||||
-rw-r--r-- | toxcore/network.h | 14 | ||||
-rw-r--r-- | toxcore/tox.c | 88 | ||||
-rw-r--r-- | toxcore/tox.h | 79 |
4 files changed, 103 insertions, 86 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index 34775570..666846db 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -23,7 +23,7 @@ | |||
23 | 23 | ||
24 | #include "network.h" | 24 | #include "network.h" |
25 | 25 | ||
26 | /* return current UNIX time in microseconds (us). */ | 26 | /* return current UNIX time in microseconds (us). */ |
27 | uint64_t current_time(void) | 27 | uint64_t current_time(void) |
28 | { | 28 | { |
29 | uint64_t time; | 29 | uint64_t time; |
@@ -44,7 +44,7 @@ uint64_t current_time(void) | |||
44 | #endif | 44 | #endif |
45 | } | 45 | } |
46 | 46 | ||
47 | /* return a random number. | 47 | /* return a random number. |
48 | * NOTE: This function should probably not be used where cryptographic randomness is absolutely necessary. | 48 | * NOTE: This function should probably not be used where cryptographic randomness is absolutely necessary. |
49 | */ | 49 | */ |
50 | uint32_t random_int(void) | 50 | uint32_t random_int(void) |
@@ -145,8 +145,8 @@ static void at_shutdown(void) | |||
145 | * ip must be in network order EX: 127.0.0.1 = (7F000001). | 145 | * ip must be in network order EX: 127.0.0.1 = (7F000001). |
146 | * port is in host byte order (this means don't worry about it). | 146 | * port is in host byte order (this means don't worry about it). |
147 | * | 147 | * |
148 | * returns Networking_Core object if no problems | 148 | * return Networking_Core object if no problems |
149 | * returns NULL if there are problems. | 149 | * return NULL if there are problems. |
150 | */ | 150 | */ |
151 | Networking_Core *new_networking(IP ip, uint16_t port) | 151 | Networking_Core *new_networking(IP ip, uint16_t port) |
152 | { | 152 | { |
diff --git a/toxcore/network.h b/toxcore/network.h index 32850944..eb725d25 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -123,10 +123,10 @@ typedef struct { | |||
123 | int sock; | 123 | int sock; |
124 | } Networking_Core; | 124 | } Networking_Core; |
125 | 125 | ||
126 | /* return current time in milleseconds since the epoch. */ | 126 | /* return current time in milleseconds since the epoch. */ |
127 | uint64_t current_time(void); | 127 | uint64_t current_time(void); |
128 | 128 | ||
129 | /* return a random number. | 129 | /* return a random number. |
130 | * NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary. | 130 | * NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary. |
131 | */ | 131 | */ |
132 | uint32_t random_int(void); | 132 | uint32_t random_int(void); |
@@ -143,12 +143,12 @@ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handl | |||
143 | void networking_poll(Networking_Core *net); | 143 | void networking_poll(Networking_Core *net); |
144 | 144 | ||
145 | /* Initialize networking. | 145 | /* Initialize networking. |
146 | * bind to ip and port. | 146 | * bind to ip and port. |
147 | * ip must be in network order EX: 127.0.0.1 = (7F000001). | 147 | * ip must be in network order EX: 127.0.0.1 = (7F000001). |
148 | * port is in host byte order (this means don't worry about it). | 148 | * port is in host byte order (this means don't worry about it). |
149 | * | 149 | * |
150 | * returns 0 if no problems. | 150 | * return 0 if no problems. |
151 | * returns -1 if there were problems. | 151 | * return -1 if there were problems. |
152 | */ | 152 | */ |
153 | Networking_Core *new_networking(IP ip, uint16_t port); | 153 | Networking_Core *new_networking(IP ip, uint16_t port); |
154 | 154 | ||
diff --git a/toxcore/tox.c b/toxcore/tox.c index 494de478..23ca6572 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -38,16 +38,17 @@ void tox_getaddress(void *tox, uint8_t *address) | |||
38 | * Set the data that will be sent along with friend request. | 38 | * Set the data that will be sent along with friend request. |
39 | * address is the address of the friend (returned by getaddress of the friend you wish to add) it must be FRIEND_ADDRESS_SIZE bytes. TODO: add checksum. | 39 | * address is the address of the friend (returned by getaddress of the friend you wish to add) it must be FRIEND_ADDRESS_SIZE bytes. TODO: add checksum. |
40 | * data is the data and length is the length. | 40 | * data is the data and length is the length. |
41 | * returns the friend number if success. | 41 | * |
42 | * return FA_TOOLONG if message length is too long. | 42 | * return the friend number if success. |
43 | * return FAERR_NOMESSAGE if no message (message length must be >= 1 byte). | 43 | * return FA_TOOLONG if message length is too long. |
44 | * return FAERR_OWNKEY if user's own key. | 44 | * return FAERR_NOMESSAGE if no message (message length must be >= 1 byte). |
45 | * return FAERR_ALREADYSENT if friend request already sent or already a friend. | 45 | * return FAERR_OWNKEY if user's own key. |
46 | * return FAERR_UNKNOWN for unknown error. | 46 | * return FAERR_ALREADYSENT if friend request already sent or already a friend. |
47 | * return FAERR_BADCHECKSUM if bad checksum in address. | 47 | * return FAERR_UNKNOWN for unknown error. |
48 | * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different. | 48 | * return FAERR_BADCHECKSUM if bad checksum in address. |
49 | * (the nospam for that friend was set to the new one). | 49 | * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different. |
50 | * return FAERR_NOMEM if increasing the friend list size fails. | 50 | * (the nospam for that friend was set to the new one). |
51 | * return FAERR_NOMEM if increasing the friend list size fails. | ||
51 | */ | 52 | */ |
52 | int tox_addfriend(void *tox, uint8_t *address, uint8_t *data, uint16_t length) | 53 | int tox_addfriend(void *tox, uint8_t *address, uint8_t *data, uint16_t length) |
53 | { | 54 | { |
@@ -56,7 +57,8 @@ int tox_addfriend(void *tox, uint8_t *address, uint8_t *data, uint16_t length) | |||
56 | } | 57 | } |
57 | 58 | ||
58 | /* Add a friend without sending a friendrequest. | 59 | /* Add a friend without sending a friendrequest. |
59 | * returns the friend number if success. | 60 | * |
61 | * return the friend number if success. | ||
60 | * return -1 if failure. | 62 | * return -1 if failure. |
61 | */ | 63 | */ |
62 | int tox_addfriend_norequest(void *tox, uint8_t *client_id) | 64 | int tox_addfriend_norequest(void *tox, uint8_t *client_id) |
@@ -65,8 +67,8 @@ int tox_addfriend_norequest(void *tox, uint8_t *client_id) | |||
65 | return m_addfriend_norequest(m, client_id); | 67 | return m_addfriend_norequest(m, client_id); |
66 | } | 68 | } |
67 | 69 | ||
68 | /* return the friend id associated to that client id. | 70 | /* return the friend id associated to that client id. |
69 | * return -1 if no such friend. | 71 | * return -1 if no such friend. |
70 | */ | 72 | */ |
71 | int tox_getfriend_id(void *tox, uint8_t *client_id) | 73 | int tox_getfriend_id(void *tox, uint8_t *client_id) |
72 | { | 74 | { |
@@ -75,7 +77,8 @@ int tox_getfriend_id(void *tox, uint8_t *client_id) | |||
75 | } | 77 | } |
76 | 78 | ||
77 | /* Copies the public key associated to that friend id into client_id buffer. | 79 | /* Copies the public key associated to that friend id into client_id buffer. |
78 | * Make sure that client_id is of size CLIENT_ID_SIZE. | 80 | * Make sure that client_id is of size CLIENT_ID_SIZE. |
81 | * | ||
79 | * return 0 if success. | 82 | * return 0 if success. |
80 | * return -1 if failure. | 83 | * return -1 if failure. |
81 | */ | 84 | */ |
@@ -92,11 +95,11 @@ int tox_delfriend(void *tox, int friendnumber) | |||
92 | return m_delfriend(m, friendnumber); | 95 | return m_delfriend(m, friendnumber); |
93 | } | 96 | } |
94 | 97 | ||
95 | /* return 4 if friend is online. | 98 | /* return 4 if friend is online. |
96 | * return 3 if friend is confirmed. | 99 | * return 3 if friend is confirmed. |
97 | * return 2 if the friend request was sent. | 100 | * return 2 if the friend request was sent. |
98 | * return 1 if the friend was added. | 101 | * return 1 if the friend was added. |
99 | * return 0 if there is no friend with that number. | 102 | * return 0 if there is no friend with that number. |
100 | */ | 103 | */ |
101 | int tox_friendstatus(void *tox, int friendnumber) | 104 | int tox_friendstatus(void *tox, int friendnumber) |
102 | { | 105 | { |
@@ -105,7 +108,7 @@ int tox_friendstatus(void *tox, int friendnumber) | |||
105 | } | 108 | } |
106 | 109 | ||
107 | /* Send a text chat message to an online friend. | 110 | /* Send a text chat message to an online friend. |
108 | * returns the message id if packet was successfully put into the send queue. | 111 | * return the message id if packet was successfully put into the send queue. |
109 | * return 0 if it was not. | 112 | * return 0 if it was not. |
110 | * | 113 | * |
111 | * You will want to retain the return value, it will be passed to your read receipt callback | 114 | * You will want to retain the return value, it will be passed to your read receipt callback |
@@ -126,7 +129,7 @@ uint32_t tox_sendmessage_withid(void *tox, int friendnumber, uint32_t theid, uin | |||
126 | } | 129 | } |
127 | 130 | ||
128 | /* Send an action to an online friend. | 131 | /* Send an action to an online friend. |
129 | * returns 1 if packet was successfully put into the send queue. | 132 | * return 1 if packet was successfully put into the send queue. |
130 | * return 0 if it was not. | 133 | * return 0 if it was not. |
131 | */ | 134 | */ |
132 | int tox_sendaction(void *tox, int friendnumber, uint8_t *action, uint32_t length) | 135 | int tox_sendaction(void *tox, int friendnumber, uint8_t *action, uint32_t length) |
@@ -139,8 +142,9 @@ int tox_sendaction(void *tox, int friendnumber, uint8_t *action, uint32_t length | |||
139 | * name must be a string of maximum MAX_NAME_LENGTH length. | 142 | * name must be a string of maximum MAX_NAME_LENGTH length. |
140 | * length must be at least 1 byte. | 143 | * length must be at least 1 byte. |
141 | * length is the length of name with the NULL terminator. | 144 | * length is the length of name with the NULL terminator. |
142 | * return 0 if success. | 145 | * |
143 | * return -1 if failure. | 146 | * return 0 if success. |
147 | * return -1 if failure. | ||
144 | */ | 148 | */ |
145 | int tox_setname(void *tox, uint8_t *name, uint16_t length) | 149 | int tox_setname(void *tox, uint8_t *name, uint16_t length) |
146 | { | 150 | { |
@@ -152,8 +156,9 @@ int tox_setname(void *tox, uint8_t *name, uint16_t length) | |||
152 | * m - The messanger context to use. | 156 | * m - The messanger context to use. |
153 | * name - Pointer to a string for the name. | 157 | * name - Pointer to a string for the name. |
154 | * nlen - The length of the string buffer. | 158 | * nlen - The length of the string buffer. |
155 | * return length of the name. | 159 | * |
156 | * return 0 on error. | 160 | * return length of the name. |
161 | * return 0 on error. | ||
157 | */ | 162 | */ |
158 | uint16_t tox_getselfname(void *tox, uint8_t *name, uint16_t nlen) | 163 | uint16_t tox_getselfname(void *tox, uint8_t *name, uint16_t nlen) |
159 | { | 164 | { |
@@ -162,7 +167,8 @@ uint16_t tox_getselfname(void *tox, uint8_t *name, uint16_t nlen) | |||
162 | } | 167 | } |
163 | 168 | ||
164 | /* Get name of friendnumber and put it in name. | 169 | /* Get name of friendnumber and put it in name. |
165 | * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. | 170 | * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. |
171 | * | ||
166 | * return 0 if success. | 172 | * return 0 if success. |
167 | * return -1 if failure. | 173 | * return -1 if failure. |
168 | */ | 174 | */ |
@@ -172,9 +178,11 @@ int tox_getname(void *tox, int friendnumber, uint8_t *name) | |||
172 | return getname(m, friendnumber, name); | 178 | return getname(m, friendnumber, name); |
173 | } | 179 | } |
174 | 180 | ||
175 | /* set our user status | 181 | /* Set our user status; |
176 | you are responsible for freeing status after | 182 | * you are responsible for freeing status after. |
177 | returns 0 on success, -1 on failure */ | 183 | * |
184 | * return 0 on success, -1 on failure. | ||
185 | */ | ||
178 | int tox_set_statusmessage(void *tox, uint8_t *status, uint16_t length) | 186 | int tox_set_statusmessage(void *tox, uint8_t *status, uint16_t length) |
179 | { | 187 | { |
180 | Messenger *m = tox; | 188 | Messenger *m = tox; |
@@ -187,8 +195,8 @@ int tox_set_userstatus(void *tox, USERSTATUS status) | |||
187 | return m_set_userstatus(m, status); | 195 | return m_set_userstatus(m, status); |
188 | } | 196 | } |
189 | 197 | ||
190 | /* return the length of friendnumber's status message, including null. | 198 | /* return the length of friendnumber's status message, including null. |
191 | * Pass it into malloc. | 199 | * Pass it into malloc. |
192 | */ | 200 | */ |
193 | int tox_get_statusmessage_size(void *tox, int friendnumber) | 201 | int tox_get_statusmessage_size(void *tox, int friendnumber) |
194 | { | 202 | { |
@@ -197,8 +205,8 @@ int tox_get_statusmessage_size(void *tox, int friendnumber) | |||
197 | } | 205 | } |
198 | 206 | ||
199 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. | 207 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. |
200 | * Get the size you need to allocate from m_get_statusmessage_size. | 208 | * Get the size you need to allocate from m_get_statusmessage_size. |
201 | * The self variant will copy our own status message. | 209 | * The self variant will copy our own status message. |
202 | */ | 210 | */ |
203 | int tox_copy_statusmessage(void *tox, int friendnumber, uint8_t *buf, uint32_t maxlen) | 211 | int tox_copy_statusmessage(void *tox, int friendnumber, uint8_t *buf, uint32_t maxlen) |
204 | { | 212 | { |
@@ -317,6 +325,7 @@ void tox_callback_read_receipt(void *tox, void (*function)(Messenger *tox, int, | |||
317 | 325 | ||
318 | /* Set the callback for connection status changes. | 326 | /* Set the callback for connection status changes. |
319 | * function(int friendnumber, uint8_t status) | 327 | * function(int friendnumber, uint8_t status) |
328 | * | ||
320 | * Status: | 329 | * Status: |
321 | * 0 -- friend went offline after being previously online | 330 | * 0 -- friend went offline after being previously online |
322 | * 1 -- friend went online | 331 | * 1 -- friend went online |
@@ -332,7 +341,7 @@ void tox_callback_connectionstatus(void *tox, void (*function)(Messenger *tox, i | |||
332 | } | 341 | } |
333 | 342 | ||
334 | /* Use this function to bootstrap the client. | 343 | /* Use this function to bootstrap the client. |
335 | * Sends a get nodes request to the given node with ip port and public_key. | 344 | * Sends a get nodes request to the given node with ip port and public_key. |
336 | */ | 345 | */ |
337 | void tox_bootstrap(void *tox, IP_Port ip_port, uint8_t *public_key) | 346 | void tox_bootstrap(void *tox, IP_Port ip_port, uint8_t *public_key) |
338 | { | 347 | { |
@@ -340,8 +349,8 @@ void tox_bootstrap(void *tox, IP_Port ip_port, uint8_t *public_key) | |||
340 | DHT_bootstrap(m->dht, ip_port, public_key); | 349 | DHT_bootstrap(m->dht, ip_port, public_key); |
341 | } | 350 | } |
342 | 351 | ||
343 | /* returns 0 if we are not connected to the DHT. | 352 | /* return 0 if we are not connected to the DHT. |
344 | * returns 1 if we are. | 353 | * return 1 if we are. |
345 | */ | 354 | */ |
346 | int tox_isconnected(void *tox) | 355 | int tox_isconnected(void *tox) |
347 | { | 356 | { |
@@ -350,8 +359,9 @@ int tox_isconnected(void *tox) | |||
350 | } | 359 | } |
351 | 360 | ||
352 | /* Run this at startup. | 361 | /* Run this at startup. |
353 | * returns allocated instance of tox on success. | 362 | * |
354 | * returns 0 if there are problems. | 363 | * return allocated instance of tox on success. |
364 | * return 0 if there are problems. | ||
355 | */ | 365 | */ |
356 | void *tox_new(void) | 366 | void *tox_new(void) |
357 | { | 367 | { |
@@ -376,7 +386,7 @@ void tox_do(void *tox) | |||
376 | 386 | ||
377 | /* SAVING AND LOADING FUNCTIONS: */ | 387 | /* SAVING AND LOADING FUNCTIONS: */ |
378 | 388 | ||
379 | /* returns the size of the messenger data (for saving). */ | 389 | /* return size of the messenger data (for saving). */ |
380 | uint32_t tox_size(void *tox) | 390 | uint32_t tox_size(void *tox) |
381 | { | 391 | { |
382 | Messenger *m = tox; | 392 | Messenger *m = tox; |
diff --git a/toxcore/tox.h b/toxcore/tox.h index eabdf8ff..b17ca36f 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -86,7 +86,7 @@ TOX_USERSTATUS; | |||
86 | 86 | ||
87 | typedef void Tox; | 87 | typedef void Tox; |
88 | 88 | ||
89 | /* returns FRIEND_ADDRESS_SIZE byte address to give to others. | 89 | /* return FRIEND_ADDRESS_SIZE byte address to give to others. |
90 | * format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] | 90 | * format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] |
91 | */ | 91 | */ |
92 | void tox_getaddress(Tox *tox, uint8_t *address); | 92 | void tox_getaddress(Tox *tox, uint8_t *address); |
@@ -95,32 +95,33 @@ void tox_getaddress(Tox *tox, uint8_t *address); | |||
95 | * Set the data that will be sent along with friend request. | 95 | * Set the data that will be sent along with friend request. |
96 | * address is the address of the friend (returned by getaddress of the friend you wish to add) it must be FRIEND_ADDRESS_SIZE bytes. TODO: add checksum. | 96 | * address is the address of the friend (returned by getaddress of the friend you wish to add) it must be FRIEND_ADDRESS_SIZE bytes. TODO: add checksum. |
97 | * data is the data and length is the length. | 97 | * data is the data and length is the length. |
98 | * returns the friend number if success. | 98 | * |
99 | * return TOX_FA_TOOLONG if message length is too long. | 99 | * return the friend number if success. |
100 | * return TOX_FAERR_NOMESSAGE if no message (message length must be >= 1 byte). | 100 | * return TOX_FA_TOOLONG if message length is too long. |
101 | * return TOX_FAERR_OWNKEY if user's own key. | 101 | * return TOX_FAERR_NOMESSAGE if no message (message length must be >= 1 byte). |
102 | * return TOX_FAERR_ALREADYSENT if friend request already sent or already a friend. | 102 | * return TOX_FAERR_OWNKEY if user's own key. |
103 | * return TOX_FAERR_UNKNOWN for unknown error. | 103 | * return TOX_FAERR_ALREADYSENT if friend request already sent or already a friend. |
104 | * return TOX_FAERR_BADCHECKSUM if bad checksum in address. | 104 | * return TOX_FAERR_UNKNOWN for unknown error. |
105 | * return TOX_FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different. | 105 | * return TOX_FAERR_BADCHECKSUM if bad checksum in address. |
106 | * (the nospam for that friend was set to the new one). | 106 | * return TOX_FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different. |
107 | * return TOX_FAERR_NOMEM if increasing the friend list size fails. | 107 | * (the nospam for that friend was set to the new one). |
108 | * return TOX_FAERR_NOMEM if increasing the friend list size fails. | ||
108 | */ | 109 | */ |
109 | int tox_addfriend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length); | 110 | int tox_addfriend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length); |
110 | 111 | ||
111 | 112 | ||
112 | /* Add a friend without sending a friendrequest. | 113 | /* Add a friend without sending a friendrequest. |
113 | * returns the friend number if success. | 114 | * return the friend number if success. |
114 | * return -1 if failure. | 115 | * return -1 if failure. |
115 | */ | 116 | */ |
116 | int tox_addfriend_norequest(Tox *tox, uint8_t *client_id); | 117 | int tox_addfriend_norequest(Tox *tox, uint8_t *client_id); |
117 | 118 | ||
118 | /* return the friend id associated to that client id. | 119 | /* return the friend id associated to that client id. |
119 | return -1 if no such friend */ | 120 | return -1 if no such friend */ |
120 | int tox_getfriend_id(Tox *tox, uint8_t *client_id); | 121 | int tox_getfriend_id(Tox *tox, uint8_t *client_id); |
121 | 122 | ||
122 | /* Copies the public key associated to that friend id into client_id buffer. | 123 | /* Copies the public key associated to that friend id into client_id buffer. |
123 | * Make sure that client_id is of size CLIENT_ID_SIZE. | 124 | * Make sure that client_id is of size CLIENT_ID_SIZE. |
124 | * return 0 if success. | 125 | * return 0 if success. |
125 | * return -1 if failure. | 126 | * return -1 if failure. |
126 | */ | 127 | */ |
@@ -138,8 +139,9 @@ int tox_delfriend(Tox *tox, int friendnumber); | |||
138 | int tox_friendstatus(Tox *tox, int friendnumber); | 139 | int tox_friendstatus(Tox *tox, int friendnumber); |
139 | 140 | ||
140 | /* Send a text chat message to an online friend. | 141 | /* Send a text chat message to an online friend. |
141 | * returns the message id if packet was successfully put into the send queue. | 142 | * |
142 | * return 0 if it was not. | 143 | * return the message id if packet was successfully put into the send queue. |
144 | * return 0 if it was not. | ||
143 | * | 145 | * |
144 | * You will want to retain the return value, it will be passed to your read receipt callback | 146 | * You will want to retain the return value, it will be passed to your read receipt callback |
145 | * if one is received. | 147 | * if one is received. |
@@ -150,7 +152,8 @@ uint32_t tox_sendmessage(Tox *tox, int friendnumber, uint8_t *message, uint32_t | |||
150 | uint32_t tox_sendmessage_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length); | 152 | uint32_t tox_sendmessage_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length); |
151 | 153 | ||
152 | /* Send an action to an online friend. | 154 | /* Send an action to an online friend. |
153 | * returns 1 if packet was successfully put into the send queue. | 155 | * |
156 | * return 1 if packet was successfully put into the send queue. | ||
154 | * return 0 if it was not. | 157 | * return 0 if it was not. |
155 | */ | 158 | */ |
156 | int tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length); | 159 | int tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length); |
@@ -160,8 +163,8 @@ int tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length) | |||
160 | * length must be at least 1 byte. | 163 | * length must be at least 1 byte. |
161 | * length is the length of name with the NULL terminator. | 164 | * length is the length of name with the NULL terminator. |
162 | * | 165 | * |
163 | * return 0 if success. | 166 | * return 0 if success. |
164 | * return -1 if failure. | 167 | * return -1 if failure. |
165 | */ | 168 | */ |
166 | int tox_setname(Tox *tox, uint8_t *name, uint16_t length); | 169 | int tox_setname(Tox *tox, uint8_t *name, uint16_t length); |
167 | 170 | ||
@@ -171,12 +174,13 @@ int tox_setname(Tox *tox, uint8_t *name, uint16_t length); | |||
171 | * name - Pointer to a string for the name. | 174 | * name - Pointer to a string for the name. |
172 | * nlen - The length of the string buffer. | 175 | * nlen - The length of the string buffer. |
173 | * | 176 | * |
174 | * returns Return the length of the name, 0 on error. | 177 | * return length of name. |
178 | * return 0 on error. | ||
175 | */ | 179 | */ |
176 | uint16_t tox_getselfname(Tox *tox, uint8_t *name, uint16_t nlen); | 180 | uint16_t tox_getselfname(Tox *tox, uint8_t *name, uint16_t nlen); |
177 | 181 | ||
178 | /* Get name of friendnumber and put it in name. | 182 | /* Get name of friendnumber and put it in name. |
179 | * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. | 183 | * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. |
180 | * | 184 | * |
181 | * return 0 if success. | 185 | * return 0 if success. |
182 | * return -1 if failure. | 186 | * return -1 if failure. |
@@ -184,29 +188,30 @@ uint16_t tox_getselfname(Tox *tox, uint8_t *name, uint16_t nlen); | |||
184 | int tox_getname(Tox *tox, int friendnumber, uint8_t *name); | 188 | int tox_getname(Tox *tox, int friendnumber, uint8_t *name); |
185 | 189 | ||
186 | /* Set our user status. | 190 | /* Set our user status. |
187 | * You are responsible for freeing status after. | 191 | * You are responsible for freeing status after. |
192 | * | ||
188 | * returns 0 on success. | 193 | * returns 0 on success. |
189 | * returns -1 on failure. | 194 | * returns -1 on failure. |
190 | */ | 195 | */ |
191 | int tox_set_statusmessage(Tox *tox, uint8_t *status, uint16_t length); | 196 | int tox_set_statusmessage(Tox *tox, uint8_t *status, uint16_t length); |
192 | int tox_set_userstatus(Tox *tox, TOX_USERSTATUS status); | 197 | int tox_set_userstatus(Tox *tox, TOX_USERSTATUS status); |
193 | 198 | ||
194 | /* return the length of friendnumber's status message, including null. | 199 | /* return the length of friendnumber's status message, including null. |
195 | * Pass it into malloc | 200 | * Pass it into malloc |
196 | */ | 201 | */ |
197 | int tox_get_statusmessage_size(Tox *tox, int friendnumber); | 202 | int tox_get_statusmessage_size(Tox *tox, int friendnumber); |
198 | 203 | ||
199 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. | 204 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. |
200 | * Get the size you need to allocate from m_get_statusmessage_size. | 205 | * Get the size you need to allocate from m_get_statusmessage_size. |
201 | * The self variant will copy our own status message. | 206 | * The self variant will copy our own status message. |
202 | */ | 207 | */ |
203 | int tox_copy_statusmessage(Tox *tox, int friendnumber, uint8_t *buf, uint32_t maxlen); | 208 | int tox_copy_statusmessage(Tox *tox, int friendnumber, uint8_t *buf, uint32_t maxlen); |
204 | int tox_copy_self_statusmessage(Tox *tox, uint8_t *buf, uint32_t maxlen); | 209 | int tox_copy_self_statusmessage(Tox *tox, uint8_t *buf, uint32_t maxlen); |
205 | 210 | ||
206 | /* return one of USERSTATUS values. | 211 | /* return one of USERSTATUS values. |
207 | * Values unknown to your application should be represented as USERSTATUS_NONE. | 212 | * Values unknown to your application should be represented as USERSTATUS_NONE. |
208 | * As above, the self variant will return our own USERSTATUS. | 213 | * As above, the self variant will return our own USERSTATUS. |
209 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. | 214 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. |
210 | */ | 215 | */ |
211 | TOX_USERSTATUS tox_get_userstatus(Tox *tox, int friendnumber); | 216 | TOX_USERSTATUS tox_get_userstatus(Tox *tox, int friendnumber); |
212 | TOX_USERSTATUS tox_get_selfuserstatus(Tox *tox); | 217 | TOX_USERSTATUS tox_get_selfuserstatus(Tox *tox); |
@@ -264,6 +269,7 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_ | |||
264 | 269 | ||
265 | /* Set the callback for connection status changes. | 270 | /* Set the callback for connection status changes. |
266 | * function(int friendnumber, uint8_t status) | 271 | * function(int friendnumber, uint8_t status) |
272 | * | ||
267 | * Status: | 273 | * Status: |
268 | * 0 -- friend went offline after being previously online | 274 | * 0 -- friend went offline after being previously online |
269 | * 1 -- friend went online | 275 | * 1 -- friend went online |
@@ -275,18 +281,19 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_ | |||
275 | void tox_callback_connectionstatus(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata); | 281 | void tox_callback_connectionstatus(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata); |
276 | 282 | ||
277 | /* Use this function to bootstrap the client. | 283 | /* Use this function to bootstrap the client. |
278 | * Sends a get nodes request to the given node with ip port and public_key. | 284 | * Sends a get nodes request to the given node with ip port and public_key. |
279 | */ | 285 | */ |
280 | void tox_bootstrap(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key); | 286 | void tox_bootstrap(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key); |
281 | 287 | ||
282 | /* returns 0 if we are not connected to the DHT. | 288 | /* return 0 if we are not connected to the DHT. |
283 | * returns 1 if we are. | 289 | * return 1 if we are. |
284 | */ | 290 | */ |
285 | int tox_isconnected(Tox *tox); | 291 | int tox_isconnected(Tox *tox); |
286 | 292 | ||
287 | /* Run this at startup. | 293 | /* Run this at startup. |
288 | * returns allocated instance of tox on success. | 294 | * |
289 | * returns 0 if there are problems. | 295 | * return allocated instance of tox on success. |
296 | * return 0 if there are problems. | ||
290 | */ | 297 | */ |
291 | Tox *tox_new(void); | 298 | Tox *tox_new(void); |
292 | 299 | ||
@@ -299,7 +306,7 @@ void tox_do(Tox *tox); | |||
299 | 306 | ||
300 | /* SAVING AND LOADING FUNCTIONS: */ | 307 | /* SAVING AND LOADING FUNCTIONS: */ |
301 | 308 | ||
302 | /* returns the size of the messenger data (for saving). */ | 309 | /* return size of messenger data (for saving). */ |
303 | uint32_t tox_size(Tox *tox); | 310 | uint32_t tox_size(Tox *tox); |
304 | 311 | ||
305 | /* Save the messenger in data (must be allocated memory of size Messenger_size()). */ | 312 | /* Save the messenger in data (must be allocated memory of size Messenger_size()). */ |