diff options
author | mannol <eniz_vukovic@hotmail.com> | 2013-10-13 16:17:30 +0200 |
---|---|---|
committer | BtbN <btbn@btbn.de> | 2013-10-13 16:40:15 +0200 |
commit | 5bc25609041f135ad6b9d757295b665e2f84b955 (patch) | |
tree | 59006e5c5e3386df46c0376eb418c1a5e3a85b44 /toxcore | |
parent | da727875ac954b13ecb16521d255499511bb7424 (diff) |
tox A/V: integration of A/V code into tox
Also-by: Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Makefile.inc | 5 | ||||
-rw-r--r-- | toxcore/misc_tools.h | 57 | ||||
-rw-r--r-- | toxcore/network.c | 3 | ||||
-rw-r--r-- | toxcore/network.h | 2 | ||||
-rw-r--r-- | toxcore/util.c | 2 |
5 files changed, 65 insertions, 4 deletions
diff --git a/toxcore/Makefile.inc b/toxcore/Makefile.inc index 025f23c8..116a3e29 100644 --- a/toxcore/Makefile.inc +++ b/toxcore/Makefile.inc | |||
@@ -1,4 +1,4 @@ | |||
1 | lib_LTLIBRARIES = libtoxcore.la | 1 | lib_LTLIBRARIES += libtoxcore.la |
2 | 2 | ||
3 | libtoxcore_la_include_HEADERS = \ | 3 | libtoxcore_la_include_HEADERS = \ |
4 | ../toxcore/tox.h | 4 | ../toxcore/tox.h |
@@ -34,7 +34,8 @@ libtoxcore_la_CFLAGS = -I$(top_srcdir) \ | |||
34 | $(LIBSODIUM_CFLAGS) \ | 34 | $(LIBSODIUM_CFLAGS) \ |
35 | $(NACL_CFLAGS) | 35 | $(NACL_CFLAGS) |
36 | 36 | ||
37 | libtoxcore_la_LDFLAGS = $(EXTRA_LT_LDFLAGS) \ | 37 | libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ |
38 | $(EXTRA_LT_LDFLAGS) \ | ||
38 | $(LIBSODIUM_LDFLAGS) \ | 39 | $(LIBSODIUM_LDFLAGS) \ |
39 | $(NACL_LDFLAGS) \ | 40 | $(NACL_LDFLAGS) \ |
40 | $(WINSOCK2_LIBS) | 41 | $(WINSOCK2_LIBS) |
diff --git a/toxcore/misc_tools.h b/toxcore/misc_tools.h index 448c1cbd..5fd0cb7a 100644 --- a/toxcore/misc_tools.h +++ b/toxcore/misc_tools.h | |||
@@ -69,6 +69,63 @@ | |||
69 | * TODO: Update wiki. | 69 | * TODO: Update wiki. |
70 | **********************************************************/ | 70 | **********************************************************/ |
71 | 71 | ||
72 | /* Example usage | ||
73 | |||
74 | This sample program makes a new struct which contains a | ||
75 | character and a tox_list_t. It then prompts a user for | ||
76 | input until he enters q or e. It then adds each character | ||
77 | to the list, and uses a special for loop to print them. | ||
78 | It then removes all the 'z' characters, and prints the list | ||
79 | again. | ||
80 | |||
81 | //Notice that the data to be put in the list *contains* tox_list_t; | ||
82 | //usually, this is the other way around! | ||
83 | typedef struct tox_string { | ||
84 | char c; | ||
85 | tox_list_t tox_lst; //Notice that tox_lst is *NOT* a pointer. | ||
86 | } tox_string_t; | ||
87 | |||
88 | int main() | ||
89 | { | ||
90 | tox_list_t head; | ||
91 | tox_list_new(&head); //initialize head | ||
92 | |||
93 | //input a new character, until user enters q or e | ||
94 | char c = '\0'; | ||
95 | while (c != 'q' && c != 'e') { | ||
96 | scanf("%c", &c); | ||
97 | tox_string_t* tmp = malloc(sizeof(tox_string_t)); | ||
98 | tmp->c = c; | ||
99 | tox_list_add(&head, &tmp->tox_lst); //add it to the list | ||
100 | } | ||
101 | |||
102 | TOX_LIST_FOR_EACH() takes a struct tox_list and a name for a temporary pointer to use in the loop. | ||
103 | |||
104 | TOX_LIST_GET_VALUE() uses magic to return an instance of a structure that contains tox_list_t. | ||
105 | You have to give it a temporary tox_string_t, name of tox_list_t member inside our structure (tox_lst), | ||
106 | and the type of structure to return. | ||
107 | |||
108 | TOX_LIST_FOR_EACH(head, tmp) | ||
109 | printf("%c", TOX_LIST_GET_VALUE(*tmp, tox_lst, tox_string_t).c); | ||
110 | |||
111 | TOX_LIST_FOR_EACH(head, tmp) { | ||
112 | if (TOX_LIST_GET_VALUE(*tmp, tox_lst, tox_string_t).c == 'z') { | ||
113 | //If you delete tmp, you have to quit the loop, or it will go on infinitly. | ||
114 | //This will be fixed later on. | ||
115 | tox_list_remove(tmp); | ||
116 | break; | ||
117 | } | ||
118 | } | ||
119 | |||
120 | printf("\n"); | ||
121 | TOX_LIST_FOR_EACH(head, tmp) | ||
122 | printf("%c", TOX_LIST_GET_VALUE(*tmp, tox_lst, tox_string_t).c); | ||
123 | |||
124 | |||
125 | return 0; | ||
126 | } | ||
127 | */ | ||
128 | |||
72 | #define MEMBER_OFFSET(var_name_in_parent, parent_type) \ | 129 | #define MEMBER_OFFSET(var_name_in_parent, parent_type) \ |
73 | (&(((parent_type*)0)->var_name_in_parent)) | 130 | (&(((parent_type*)0)->var_name_in_parent)) |
74 | 131 | ||
diff --git a/toxcore/network.c b/toxcore/network.c index 38adc179..5d695b81 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -227,7 +227,7 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, uint8_t *data, uint32_t le | |||
227 | * Packet length is put into length. | 227 | * Packet length is put into length. |
228 | * Dump all empty packets. | 228 | * Dump all empty packets. |
229 | */ | 229 | */ |
230 | static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t *length) | 230 | int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t *length) |
231 | { | 231 | { |
232 | struct sockaddr_storage addr; | 232 | struct sockaddr_storage addr; |
233 | #ifdef WIN32 | 233 | #ifdef WIN32 |
@@ -667,6 +667,7 @@ void kill_networking(Networking_Core *net) | |||
667 | return; | 667 | return; |
668 | } | 668 | } |
669 | 669 | ||
670 | |||
670 | /* ip_equal | 671 | /* ip_equal |
671 | * compares two IPAny structures | 672 | * compares two IPAny structures |
672 | * unset means unequal | 673 | * unset means unequal |
diff --git a/toxcore/network.h b/toxcore/network.h index 8a0e20dc..0ce1f34d 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -285,4 +285,6 @@ Networking_Core *new_networking(IP ip, uint16_t port); | |||
285 | /* Function to cleanup networking stuff (doesn't do much right now). */ | 285 | /* Function to cleanup networking stuff (doesn't do much right now). */ |
286 | void kill_networking(Networking_Core *net); | 286 | void kill_networking(Networking_Core *net); |
287 | 287 | ||
288 | int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t *length); | ||
289 | |||
288 | #endif | 290 | #endif |
diff --git a/toxcore/util.c b/toxcore/util.c index e307bad6..8fc6806e 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -25,7 +25,7 @@ uint64_t random_64b() | |||
25 | { | 25 | { |
26 | uint64_t r; | 26 | uint64_t r; |
27 | 27 | ||
28 | // This is probably not random enough? | 28 | /* This is probably not random enough? */ |
29 | r = random_int(); | 29 | r = random_int(); |
30 | r <<= 32; | 30 | r <<= 32; |
31 | r |= random_int(); | 31 | r |= random_int(); |