diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/network.c | 43 | ||||
-rw-r--r-- | core/network.h | 10 | ||||
-rw-r--r-- | core/tox.h | 146 |
3 files changed, 86 insertions, 113 deletions
diff --git a/core/network.c b/core/network.c index 7880eae6..2bcf7d61 100644 --- a/core/network.c +++ b/core/network.c | |||
@@ -144,8 +144,9 @@ static void at_shutdown(void) | |||
144 | returns NULL if there are problems */ | 144 | returns NULL if there are problems */ |
145 | Networking_Core *new_networking(IP ip, uint16_t port) | 145 | Networking_Core *new_networking(IP ip, uint16_t port) |
146 | { | 146 | { |
147 | if(at_startup() != 0) | 147 | if (at_startup() != 0) |
148 | return NULL; | 148 | return NULL; |
149 | |||
149 | /* initialize our socket */ | 150 | /* initialize our socket */ |
150 | Networking_Core *temp = calloc(1, sizeof(Networking_Core)); | 151 | Networking_Core *temp = calloc(1, sizeof(Networking_Core)); |
151 | 152 | ||
@@ -215,43 +216,3 @@ void kill_networking(Networking_Core *net) | |||
215 | free(net); | 216 | free(net); |
216 | return; | 217 | return; |
217 | } | 218 | } |
218 | |||
219 | /* | ||
220 | resolve_addr(): | ||
221 | address should represent IPv4 or a hostname with A record | ||
222 | |||
223 | returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i | ||
224 | returns 0 on failure | ||
225 | |||
226 | TODO: Fix ipv6 support | ||
227 | */ | ||
228 | uint32_t resolve_addr(const char *address) | ||
229 | { | ||
230 | struct addrinfo *server = NULL; | ||
231 | struct addrinfo hints; | ||
232 | int rc; | ||
233 | uint32_t addr; | ||
234 | |||
235 | memset(&hints, 0, sizeof(hints)); | ||
236 | hints.ai_family = AF_INET; // IPv4 only right now. | ||
237 | hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses. | ||
238 | |||
239 | rc = getaddrinfo(address, "echo", &hints, &server); | ||
240 | |||
241 | // Lookup failed. | ||
242 | if (rc != 0) { | ||
243 | return 0; | ||
244 | } | ||
245 | |||
246 | // IPv4 records only.. | ||
247 | if (server->ai_family != AF_INET) { | ||
248 | freeaddrinfo(server); | ||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | |||
253 | addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr; | ||
254 | |||
255 | freeaddrinfo(server); | ||
256 | return addr; | ||
257 | } | ||
diff --git a/core/network.h b/core/network.h index 088bbb3b..3547f79b 100644 --- a/core/network.h +++ b/core/network.h | |||
@@ -151,16 +151,6 @@ Networking_Core *new_networking(IP ip, uint16_t port); | |||
151 | /* function to cleanup networking stuff(doesn't do much right now) */ | 151 | /* function to cleanup networking stuff(doesn't do much right now) */ |
152 | void kill_networking(Networking_Core *net); | 152 | void kill_networking(Networking_Core *net); |
153 | 153 | ||
154 | /* | ||
155 | resolve_addr(): | ||
156 | address should represent IPv4 or a hostname with A record | ||
157 | |||
158 | returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i | ||
159 | returns 0 on failure | ||
160 | |||
161 | TODO: Fix ipv6 support | ||
162 | */ | ||
163 | uint32_t resolve_addr(const char *address); | ||
164 | 154 | ||
165 | #ifdef __cplusplus | 155 | #ifdef __cplusplus |
166 | } | 156 | } |
@@ -24,34 +24,53 @@ | |||
24 | #ifndef TOX_H | 24 | #ifndef TOX_H |
25 | #define TOX_H | 25 | #define TOX_H |
26 | 26 | ||
27 | #include <stdint.h> | ||
27 | 28 | ||
28 | #ifdef __cplusplus | 29 | #ifdef __cplusplus |
29 | extern "C" { | 30 | extern "C" { |
30 | #endif | 31 | #endif |
31 | 32 | ||
32 | #define MAX_NAME_LENGTH 128 | 33 | #define TOX_MAX_NAME_LENGTH 128 |
33 | #define MAX_STATUSMESSAGE_LENGTH 128 | 34 | #define TOX_MAX_STATUSMESSAGE_LENGTH 128 |
35 | #define TOX_CLIENT_ID_SIZE 32 | ||
34 | 36 | ||
35 | #define FRIEND_ADDRESS_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + sizeof(uint16_t)) | 37 | #define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) |
38 | |||
39 | |||
40 | typedef union { | ||
41 | uint8_t c[4]; | ||
42 | uint16_t s[2]; | ||
43 | uint32_t i; | ||
44 | } IP; | ||
45 | |||
46 | typedef struct { | ||
47 | IP ip; | ||
48 | uint16_t port; | ||
49 | /* not used for anything right now */ | ||
50 | uint16_t padding; | ||
51 | } IP_Port; | ||
36 | 52 | ||
37 | /* status definitions */ | 53 | /* status definitions */ |
38 | #define FRIEND_ONLINE 4 | 54 | enum { |
39 | #define FRIEND_CONFIRMED 3 | 55 | TOX_NOFRIEND, |
40 | #define FRIEND_REQUESTED 2 | 56 | TOX_FRIEND_ADDED, |
41 | #define FRIEND_ADDED 1 | 57 | TOX_FRIEND_REQUESTED, |
42 | #define NOFRIEND 0 | 58 | TOX_FRIEND_CONFIRMED, |
59 | TOX_FRIEND_ONLINE, | ||
60 | }; | ||
43 | 61 | ||
44 | /* errors for m_addfriend | 62 | /* errors for m_addfriend |
45 | * FAERR - Friend Add Error */ | 63 | * FAERR - Friend Add Error */ |
46 | #define FAERR_TOOLONG -1 | 64 | enum { |
47 | #define FAERR_NOMESSAGE -2 | 65 | TOX_FAERR_TOOLONG = -1, |
48 | #define FAERR_OWNKEY -3 | 66 | TOX_FAERR_NOMESSAGE = -2, |
49 | #define FAERR_ALREADYSENT -4 | 67 | TOX_FAERR_OWNKEY = -3, |
50 | #define FAERR_UNKNOWN -5 | 68 | TOX_FAERR_ALREADYSENT = -4, |
51 | #define FAERR_BADCHECKSUM -6 | 69 | TOX_FAERR_UNKNOWN = -5, |
52 | #define FAERR_SETNEWNOSPAM -7 | 70 | TOX_FAERR_BADCHECKSUM = -6, |
53 | #define FAERR_NOMEM -8 | 71 | TOX_FAERR_SETNEWNOSPAM = -7, |
54 | 72 | TOX_FAERR_NOMEM = -8 | |
73 | }; | ||
55 | /* USERSTATUS | 74 | /* USERSTATUS |
56 | * Represents userstatuses someone can have. */ | 75 | * Represents userstatuses someone can have. */ |
57 | 76 | ||
@@ -63,12 +82,14 @@ typedef enum { | |||
63 | } | 82 | } |
64 | TOX_USERSTATUS; | 83 | TOX_USERSTATUS; |
65 | 84 | ||
85 | typedef void Tox; | ||
86 | |||
66 | /* | 87 | /* |
67 | * returns a FRIEND_ADDRESS_SIZE byte address to give to others. | 88 | * returns a FRIEND_ADDRESS_SIZE byte address to give to others. |
68 | * format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] | 89 | * format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] |
69 | * | 90 | * |
70 | */ | 91 | */ |
71 | void tox_getaddress(void *tox, uint8_t *address); | 92 | void tox_getaddress(Tox *tox, uint8_t *address); |
72 | 93 | ||
73 | /* | 94 | /* |
74 | * add a friend | 95 | * add a friend |
@@ -76,43 +97,43 @@ void tox_getaddress(void *tox, uint8_t *address); | |||
76 | * 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 | * 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. |
77 | * data is the data and length is the length | 98 | * data is the data and length is the length |
78 | * returns the friend number if success | 99 | * returns the friend number if success |
79 | * return -1 if message length is too long | 100 | * return FA_TOOLONG if message length is too long |
80 | * return -2 if no message (message length must be >= 1 byte) | 101 | * return FAERR_NOMESSAGE if no message (message length must be >= 1 byte) |
81 | * return -3 if user's own key | 102 | * return FAERR_OWNKEY if user's own key |
82 | * return -4 if friend request already sent or already a friend | 103 | * return FAERR_ALREADYSENT if friend request already sent or already a friend |
83 | * return -5 for unknown error | 104 | * return FAERR_UNKNOWN for unknown error |
84 | * return -6 if bad checksum in address | 105 | * return FAERR_BADCHECKSUM if bad checksum in address |
85 | * return -7 if the friend was already there but the nospam was different | 106 | * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different |
86 | * (the nospam for that friend was set to the new one) | 107 | * (the nospam for that friend was set to the new one) |
87 | * return -8 if increasing the friend list size fails | 108 | * return FAERR_NOMEM if increasing the friend list size fails |
88 | */ | 109 | */ |
89 | int tox_addfriend(void *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); |
90 | 111 | ||
91 | 112 | ||
92 | /* add a friend without sending a friendrequest. | 113 | /* add a friend without sending a friendrequest. |
93 | returns the friend number if success | 114 | returns the friend number if success |
94 | return -1 if failure. */ | 115 | return -1 if failure. */ |
95 | int tox_addfriend_norequest(void *tox, uint8_t *client_id); | 116 | int tox_addfriend_norequest(Tox *tox, uint8_t *client_id); |
96 | 117 | ||
97 | /* return the friend id associated to that client id. | 118 | /* return the friend id associated to that client id. |
98 | return -1 if no such friend */ | 119 | return -1 if no such friend */ |
99 | int tox_getfriend_id(void *tox, uint8_t *client_id); | 120 | int tox_getfriend_id(Tox *tox, uint8_t *client_id); |
100 | 121 | ||
101 | /* copies the public key associated to that friend id into client_id buffer. | 122 | /* copies the public key associated to that friend id into client_id buffer. |
102 | make sure that client_id is of size CLIENT_ID_SIZE. | 123 | make sure that client_id is of size CLIENT_ID_SIZE. |
103 | return 0 if success | 124 | return 0 if success |
104 | return -1 if failure */ | 125 | return -1 if failure */ |
105 | int tox_getclient_id(void *tox, int friend_id, uint8_t *client_id); | 126 | int tox_getclient_id(Tox *tox, int friend_id, uint8_t *client_id); |
106 | 127 | ||
107 | /* remove a friend */ | 128 | /* remove a friend */ |
108 | int tox_delfriend(void *tox, int friendnumber); | 129 | int tox_delfriend(Tox *tox, int friendnumber); |
109 | 130 | ||
110 | /* return 4 if friend is online | 131 | /* return 4 if friend is online |
111 | return 3 if friend is confirmed | 132 | return 3 if friend is confirmed |
112 | return 2 if the friend request was sent | 133 | return 2 if the friend request was sent |
113 | return 1 if the friend was added | 134 | return 1 if the friend was added |
114 | return 0 if there is no friend with that number */ | 135 | return 0 if there is no friend with that number */ |
115 | int tox_friendstatus(void *tox, int friendnumber); | 136 | int tox_friendstatus(Tox *tox, int friendnumber); |
116 | 137 | ||
117 | /* send a text chat message to an online friend | 138 | /* send a text chat message to an online friend |
118 | returns the message id if packet was successfully put into the send queue | 139 | returns the message id if packet was successfully put into the send queue |
@@ -121,13 +142,13 @@ int tox_friendstatus(void *tox, int friendnumber); | |||
121 | if one is received. | 142 | if one is received. |
122 | m_sendmessage_withid will send a message with the id of your choosing, | 143 | m_sendmessage_withid will send a message with the id of your choosing, |
123 | however we can generate an id for you by calling plain m_sendmessage. */ | 144 | however we can generate an id for you by calling plain m_sendmessage. */ |
124 | uint32_t tox_sendmessage(void *tox, int friendnumber, uint8_t *message, uint32_t length); | 145 | uint32_t tox_sendmessage(Tox *tox, int friendnumber, uint8_t *message, uint32_t length); |
125 | uint32_t tox_sendmessage_withid(void *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length); | 146 | uint32_t tox_sendmessage_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length); |
126 | 147 | ||
127 | /* send an action to an online friend | 148 | /* send an action to an online friend |
128 | returns 1 if packet was successfully put into the send queue | 149 | returns 1 if packet was successfully put into the send queue |
129 | return 0 if it was not */ | 150 | return 0 if it was not */ |
130 | int tox_sendaction(void *tox, int friendnumber, uint8_t *action, uint32_t length); | 151 | int tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length); |
131 | 152 | ||
132 | /* Set our nickname | 153 | /* Set our nickname |
133 | name must be a string of maximum MAX_NAME_LENGTH length. | 154 | name must be a string of maximum MAX_NAME_LENGTH length. |
@@ -135,7 +156,7 @@ int tox_sendaction(void *tox, int friendnumber, uint8_t *action, uint32_t length | |||
135 | length is the length of name with the NULL terminator | 156 | length is the length of name with the NULL terminator |
136 | return 0 if success | 157 | return 0 if success |
137 | return -1 if failure */ | 158 | return -1 if failure */ |
138 | int tox_setname(void *tox, uint8_t *name, uint16_t length); | 159 | int tox_setname(Tox *tox, uint8_t *name, uint16_t length); |
139 | 160 | ||
140 | /* | 161 | /* |
141 | Get your nickname. | 162 | Get your nickname. |
@@ -144,71 +165,71 @@ int tox_setname(void *tox, uint8_t *name, uint16_t length); | |||
144 | nlen The length of the string buffer. | 165 | nlen The length of the string buffer. |
145 | returns Return the length of the name, 0 on error. | 166 | returns Return the length of the name, 0 on error. |
146 | */ | 167 | */ |
147 | uint16_t tox_getselfname(void *tox, uint8_t *name, uint16_t nlen); | 168 | uint16_t tox_getselfname(Tox *tox, uint8_t *name, uint16_t nlen); |
148 | 169 | ||
149 | /* get name of friendnumber | 170 | /* get name of friendnumber |
150 | put it in name | 171 | put it in name |
151 | name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. | 172 | name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. |
152 | return 0 if success | 173 | return 0 if success |
153 | return -1 if failure */ | 174 | return -1 if failure */ |
154 | int tox_getname(void *tox, int friendnumber, uint8_t *name); | 175 | int tox_getname(Tox *tox, int friendnumber, uint8_t *name); |
155 | 176 | ||
156 | /* set our user status | 177 | /* set our user status |
157 | you are responsible for freeing status after | 178 | you are responsible for freeing status after |
158 | returns 0 on success, -1 on failure */ | 179 | returns 0 on success, -1 on failure */ |
159 | int tox_set_statusmessage(void *tox, uint8_t *status, uint16_t length); | 180 | int tox_set_statusmessage(Tox *tox, uint8_t *status, uint16_t length); |
160 | int tox_set_userstatus(void *tox, USERSTATUS status); | 181 | int tox_set_userstatus(Tox *tox, TOX_USERSTATUS status); |
161 | 182 | ||
162 | /* return the length of friendnumber's status message, | 183 | /* return the length of friendnumber's status message, |
163 | including null | 184 | including null |
164 | pass it into malloc */ | 185 | pass it into malloc */ |
165 | int tox_get_statusmessage_size(void *tox, int friendnumber); | 186 | int tox_get_statusmessage_size(Tox *tox, int friendnumber); |
166 | 187 | ||
167 | /* copy friendnumber's status message into buf, truncating if size is over maxlen | 188 | /* copy friendnumber's status message into buf, truncating if size is over maxlen |
168 | get the size you need to allocate from m_get_statusmessage_size | 189 | get the size you need to allocate from m_get_statusmessage_size |
169 | The self variant will copy our own status message. */ | 190 | The self variant will copy our own status message. */ |
170 | int tox_copy_statusmessage(void *tox, int friendnumber, uint8_t *buf, uint32_t maxlen); | 191 | int tox_copy_statusmessage(Tox *tox, int friendnumber, uint8_t *buf, uint32_t maxlen); |
171 | int tox_copy_self_statusmessage(void *tox, uint8_t *buf, uint32_t maxlen); | 192 | int tox_copy_self_statusmessage(Tox *tox, uint8_t *buf, uint32_t maxlen); |
172 | 193 | ||
173 | /* Return one of USERSTATUS values. | 194 | /* Return one of USERSTATUS values. |
174 | * Values unknown to your application should be represented as USERSTATUS_NONE. | 195 | * Values unknown to your application should be represented as USERSTATUS_NONE. |
175 | * As above, the self variant will return our own USERSTATUS. | 196 | * As above, the self variant will return our own USERSTATUS. |
176 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. */ | 197 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. */ |
177 | TOX_USERSTATUS tox_get_userstatus(void *tox, int friendnumber); | 198 | TOX_USERSTATUS tox_get_userstatus(Tox *tox, int friendnumber); |
178 | TOX_USERSTATUS tox_get_selfuserstatus(void *tox); | 199 | TOX_USERSTATUS tox_get_selfuserstatus(Tox *tox); |
179 | 200 | ||
180 | /* Sets whether we send read receipts for friendnumber. | 201 | /* Sets whether we send read receipts for friendnumber. |
181 | * This function is not lazy, and it will fail if yesno is not (0 or 1).*/ | 202 | * This function is not lazy, and it will fail if yesno is not (0 or 1).*/ |
182 | void tox_set_sends_receipts(void *tox, int friendnumber, int yesno); | 203 | void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno); |
183 | 204 | ||
184 | /* set the function that will be executed when a friend request is received. | 205 | /* set the function that will be executed when a friend request is received. |
185 | function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) */ | 206 | function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) */ |
186 | void tox_callback_friendrequest(void *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata); | 207 | void tox_callback_friendrequest(Tox *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata); |
187 | 208 | ||
188 | /* set the function that will be executed when a message from a friend is received. | 209 | /* set the function that will be executed when a message from a friend is received. |
189 | function format is: function(int friendnumber, uint8_t * message, uint32_t length) */ | 210 | function format is: function(int friendnumber, uint8_t * message, uint32_t length) */ |
190 | void tox_callback_friendmessage(void *tox, void (*function)(void *tox, int, uint8_t *, uint16_t, void *), | 211 | void tox_callback_friendmessage(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), |
191 | void *userdata); | 212 | void *userdata); |
192 | 213 | ||
193 | /* set the function that will be executed when an action from a friend is received. | 214 | /* set the function that will be executed when an action from a friend is received. |
194 | function format is: function(int friendnumber, uint8_t * action, uint32_t length) */ | 215 | function format is: function(int friendnumber, uint8_t * action, uint32_t length) */ |
195 | void tox_callback_action(void *tox, void (*function)(void *tox, int, uint8_t *, uint16_t, void *), void *userdata); | 216 | void tox_callback_action(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), void *userdata); |
196 | 217 | ||
197 | /* set the callback for name changes | 218 | /* set the callback for name changes |
198 | function(int friendnumber, uint8_t *newname, uint16_t length) | 219 | function(int friendnumber, uint8_t *newname, uint16_t length) |
199 | you are not responsible for freeing newname */ | 220 | you are not responsible for freeing newname */ |
200 | void tox_callback_namechange(void *tox, void (*function)(void *tox, int, uint8_t *, uint16_t, void *), | 221 | void tox_callback_namechange(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), |
201 | void *userdata); | 222 | void *userdata); |
202 | 223 | ||
203 | /* set the callback for status message changes | 224 | /* set the callback for status message changes |
204 | function(int friendnumber, uint8_t *newstatus, uint16_t length) | 225 | function(int friendnumber, uint8_t *newstatus, uint16_t length) |
205 | you are not responsible for freeing newstatus */ | 226 | you are not responsible for freeing newstatus */ |
206 | void tox_callback_statusmessage(void *tox, void (*function)(void *tox, int, uint8_t *, uint16_t, void *), | 227 | void tox_callback_statusmessage(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), |
207 | void *userdata); | 228 | void *userdata); |
208 | 229 | ||
209 | /* set the callback for status type changes | 230 | /* set the callback for status type changes |
210 | function(int friendnumber, USERSTATUS kind) */ | 231 | function(int friendnumber, USERSTATUS kind) */ |
211 | void tox_callback_userstatus(void *tox, void (*function)(void *tox, int, USERSTATUS, void *), void *userdata); | 232 | void tox_callback_userstatus(Tox *tox, void (*function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata); |
212 | 233 | ||
213 | /* set the callback for read receipts | 234 | /* set the callback for read receipts |
214 | function(int friendnumber, uint32_t receipt) | 235 | function(int friendnumber, uint32_t receipt) |
@@ -217,7 +238,7 @@ void tox_callback_userstatus(void *tox, void (*function)(void *tox, int, USERSTA | |||
217 | has been received on the other side. since core doesn't | 238 | has been received on the other side. since core doesn't |
218 | track ids for you, receipt may not correspond to any message | 239 | track ids for you, receipt may not correspond to any message |
219 | in that case, you should discard it. */ | 240 | in that case, you should discard it. */ |
220 | void tox_callback_read_receipt(void *tox, void (*function)(void *tox, int, uint32_t, void *), void *userdata); | 241 | void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_t, void *), void *userdata); |
221 | 242 | ||
222 | /* set the callback for connection status changes | 243 | /* set the callback for connection status changes |
223 | function(int friendnumber, uint8_t status) | 244 | function(int friendnumber, uint8_t status) |
@@ -227,38 +248,39 @@ void tox_callback_read_receipt(void *tox, void (*function)(void *tox, int, uint3 | |||
227 | note that this callback is not called when adding friends, thus the "after | 248 | note that this callback is not called when adding friends, thus the "after |
228 | being previously online" part. it's assumed that when adding friends, | 249 | being previously online" part. it's assumed that when adding friends, |
229 | their connection status is offline. */ | 250 | their connection status is offline. */ |
230 | void tox_callback_connectionstatus(void *tox, void (*function)(void *tox, int, uint8_t, void *), void *userdata); | 251 | void tox_callback_connectionstatus(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata); |
231 | 252 | ||
232 | /* Use this function to bootstrap the client | 253 | /* Use this function to bootstrap the client |
233 | Sends a get nodes request to the given node with ip port and public_key */ | 254 | Sends a get nodes request to the given node with ip port and public_key */ |
234 | void tox_bootstrap(void *tox, IP_Port ip_port, uint8_t *public_key); | 255 | void tox_bootstrap(Tox *tox, IP_Port ip_port, uint8_t *public_key); |
235 | 256 | ||
236 | /* returns 0 if we are not connected to the DHT | 257 | /* returns 0 if we are not connected to the DHT |
237 | returns 1 if we are */ | 258 | returns 1 if we are */ |
238 | int tox_isconnected(void *tox); | 259 | int tox_isconnected(Tox *tox); |
239 | 260 | ||
240 | /* run this at startup | 261 | /* run this at startup |
241 | * returns allocated instance of tox on success | 262 | * returns allocated instance of tox on success |
242 | * returns 0 if there are problems */ | 263 | * returns 0 if there are problems */ |
243 | void *tox_new(void); | 264 | Tox *tox_new(void); |
244 | 265 | ||
245 | /* run this before closing shop | 266 | /* run this before closing shop |
246 | * free all datastructures */ | 267 | * free all datastructures */ |
247 | void tox_kill(void *tox); | 268 | void tox_kill(Tox *tox); |
248 | 269 | ||
249 | /* the main loop that needs to be run at least 20 times per second */ | 270 | /* the main loop that needs to be run at least 20 times per second */ |
250 | void tox_do(void *tox); | 271 | void tox_do(Tox *tox); |
251 | 272 | ||
252 | /* SAVING AND LOADING FUNCTIONS: */ | 273 | /* SAVING AND LOADING FUNCTIONS: */ |
253 | 274 | ||
254 | /* returns the size of the messenger data (for saving) */ | 275 | /* returns the size of the messenger data (for saving) */ |
255 | uint32_t tox_size(void *tox); | 276 | uint32_t tox_size(Tox *tox); |
256 | 277 | ||
257 | /* save the messenger in data (must be allocated memory of size Messenger_size()) */ | 278 | /* save the messenger in data (must be allocated memory of size Messenger_size()) */ |
258 | void tox_save(void *tox, uint8_t *data); | 279 | void tox_save(Tox *tox, uint8_t *data); |
259 | 280 | ||
260 | /* load the messenger from data of size length */ | 281 | /* load the messenger from data of size length */ |
261 | int tox_load(void *tox, uint8_t *data, uint32_t length); | 282 | int tox_load(Tox *tox, uint8_t *data, uint32_t length); |
283 | |||
262 | 284 | ||
263 | #ifdef __cplusplus | 285 | #ifdef __cplusplus |
264 | } | 286 | } |