summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore6
-rw-r--r--core/DHT.h2
-rw-r--r--core/Messenger.h4
-rw-r--r--core/network.h5
-rw-r--r--testing/toxic/CMakeLists.txt3
-rw-r--r--testing/toxic/chat.c6
-rw-r--r--testing/toxic/main.c7
-rw-r--r--testing/toxic/prompt.c20
-rw-r--r--testing/toxic/windows.h4
9 files changed, 39 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore
index 0e4e35ef..47cfd84a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,12 @@ install_manifest.txt
14testing/data 14testing/data
15*~ 15*~
16 16
17# Vim
18*.swp
19
20# Ctags
21tags
22
17# Object files 23# Object files
18*.o 24*.o
19 25
diff --git a/core/DHT.h b/core/DHT.h
index 2308abd8..cb5697ea 100644
--- a/core/DHT.h
+++ b/core/DHT.h
@@ -30,8 +30,6 @@
30extern "C" { 30extern "C" {
31#endif 31#endif
32 32
33/* Current time, unix format */
34#define unix_time() ((uint64_t)time(NULL))
35 33
36/* size of the client_id in bytes */ 34/* size of the client_id in bytes */
37#define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES 35#define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES
diff --git a/core/Messenger.h b/core/Messenger.h
index d2fa8945..3a9a56df 100644
--- a/core/Messenger.h
+++ b/core/Messenger.h
@@ -188,6 +188,10 @@ void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t));
188 you are not responsible for freeing newstatus */ 188 you are not responsible for freeing newstatus */
189void m_callback_statusmessage(void (*function)(int, uint8_t *, uint16_t)); 189void m_callback_statusmessage(void (*function)(int, uint8_t *, uint16_t));
190 190
191/* set the callback for status type changes
192 function(int friendnumber, USERSTATUS kind) */
193void m_callback_userstatus(void (*function)(int, USERSTATUS));
194
191/* set the callback for read receipts 195/* set the callback for read receipts
192 function(int friendnumber, uint32_t receipt) 196 function(int friendnumber, uint32_t receipt)
193 if you are keeping a record of returns from m_sendmessage, 197 if you are keeping a record of returns from m_sendmessage,
diff --git a/core/network.h b/core/network.h
index d246a9d1..d3c39333 100644
--- a/core/network.h
+++ b/core/network.h
@@ -66,6 +66,11 @@ extern "C" {
66 66
67#define MAX_UDP_PACKET_SIZE 65507 67#define MAX_UDP_PACKET_SIZE 65507
68 68
69
70/* Current time, unix format */
71#define unix_time() ((uint64_t)time(NULL))
72
73
69typedef union { 74typedef union {
70 uint8_t c[4]; 75 uint8_t c[4];
71 uint16_t s[2]; 76 uint16_t s[2];
diff --git a/testing/toxic/CMakeLists.txt b/testing/toxic/CMakeLists.txt
index f30d8e9e..38f02dc6 100644
--- a/testing/toxic/CMakeLists.txt
+++ b/testing/toxic/CMakeLists.txt
@@ -1,6 +1,9 @@
1cmake_minimum_required(VERSION 2.6.0) 1cmake_minimum_required(VERSION 2.6.0)
2project(toxic C) 2project(toxic C)
3 3
4execute_process(COMMAND git rev-list HEAD --count OUTPUT_VARIABLE COMMIT)
5SET(GCC_COVERAGE_COMPILE_FLAGS '-DTOXICVER="0.1.1_r${COMMIT}"')
6add_definitions(${GCC_COVERAGE_COMPILE_FLAGS})
4set(exe_name toxic) 7set(exe_name toxic)
5 8
6add_executable(${exe_name} 9add_executable(${exe_name}
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index 28c5de6c..56dfb050 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -16,7 +16,7 @@
16 16
17typedef struct { 17typedef struct {
18 int friendnum; 18 int friendnum;
19 char line[256]; 19 char line[MAX_STR_SIZE];
20 size_t pos; 20 size_t pos;
21 WINDOW* history; 21 WINDOW* history;
22 WINDOW* linewin; 22 WINDOW* linewin;
@@ -178,9 +178,9 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd)
178 } 178 }
179 179
180 else if (!strcmp(cmd, "/myid")) { 180 else if (!strcmp(cmd, "/myid")) {
181 char id[32*2 + 1] = {0}; 181 char id[KEY_SIZE_BYTES*2+1] = {0};
182 int i; 182 int i;
183 for (i = 0; i < 32; i++) { 183 for (i = 0; i < KEY_SIZE_BYTES; i++) {
184 char xx[3]; 184 char xx[3];
185 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); 185 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
186 strcat(id, xx); 186 strcat(id, xx);
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index b2310c80..7fa9e964 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -22,7 +22,10 @@ extern int add_req(uint8_t *public_key); // XXX
22 22
23/* Holds status of chat windows */ 23/* Holds status of chat windows */
24char WINDOW_STATUS[MAX_WINDOW_SLOTS]; 24char WINDOW_STATUS[MAX_WINDOW_SLOTS];
25#define TOXICVER "0.1.0" //Will be moved to a -D flag later 25
26#ifndef TOXICVER
27#define TOXICVER "NOVER" //Use the -D flag to set this
28#endif
26 29
27static ToxWindow windows[MAX_WINDOW_SLOTS]; 30static ToxWindow windows[MAX_WINDOW_SLOTS];
28static ToxWindow* prompt; 31static ToxWindow* prompt;
@@ -37,7 +40,7 @@ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length)
37 wprintw(prompt->window, "\nFriend request from:\n"); 40 wprintw(prompt->window, "\nFriend request from:\n");
38 41
39 int i; 42 int i;
40 for (i = 0; i < 32; ++i) { 43 for (i = 0; i < KEY_SIZE_BYTES; ++i) {
41 wprintw(prompt->window, "%02x", public_key[i] & 0xff); 44 wprintw(prompt->window, "%02x", public_key[i] & 0xff);
42 } 45 }
43 46
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index b3d6d229..eaa8d7bc 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -12,12 +12,12 @@
12 12
13#include "windows.h" 13#include "windows.h"
14 14
15uint8_t pending_requests[256][CLIENT_ID_SIZE]; // XXX 15uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX
16uint8_t num_requests=0; // XXX 16uint8_t num_requests=0; // XXX
17 17
18extern void on_friendadded(int friendnumber); 18extern void on_friendadded(int friendnumber);
19static void print_usage(ToxWindow *self); 19static void print_usage(ToxWindow *self);
20static char prompt_buf[256] = {0}; 20static char prompt_buf[MAX_STR_SIZE] = {0};
21static int prompt_buf_pos = 0; 21static int prompt_buf_pos = 0;
22 22
23// XXX: 23// XXX:
@@ -43,7 +43,7 @@ unsigned char *hex_string_to_bin(char hex_string[])
43static void execute(ToxWindow *self, char *u_cmd) 43static void execute(ToxWindow *self, char *u_cmd)
44{ 44{
45 int newlines = 0; 45 int newlines = 0;
46 char cmd[256] = {0}; 46 char cmd[MAX_STR_SIZE] = {0};
47 int i; 47 int i;
48 for (i = 0; i < strlen(prompt_buf); ++i) { 48 for (i = 0; i < strlen(prompt_buf); ++i) {
49 if (u_cmd[i] == '\n') 49 if (u_cmd[i] == '\n')
@@ -53,9 +53,9 @@ static void execute(ToxWindow *self, char *u_cmd)
53 } 53 }
54 54
55 int leading_spc = 0; 55 int leading_spc = 0;
56 for (i = 0; i < 256 && isspace(cmd[i]); ++i) 56 for (i = 0; i < MAX_STR_SIZE && isspace(cmd[i]); ++i)
57 leading_spc++; 57 leading_spc++;
58 memmove(cmd, cmd + leading_spc, 256 - leading_spc); 58 memmove(cmd, cmd + leading_spc, MAX_STR_SIZE - leading_spc);
59 59
60 int cmd_end = strlen(cmd); 60 int cmd_end = strlen(cmd);
61 while (cmd_end > 0 && cmd_end--) 61 while (cmd_end > 0 && cmd_end--)
@@ -121,7 +121,7 @@ static void execute(ToxWindow *self, char *u_cmd)
121 } 121 }
122 122
123 else if (!strncmp(cmd, "add ", strlen("add "))) { 123 else if (!strncmp(cmd, "add ", strlen("add "))) {
124 uint8_t id_bin[32]; 124 uint8_t id_bin[KEY_SIZE_BYTES];
125 char xx[3]; 125 char xx[3];
126 uint32_t x; 126 uint32_t x;
127 char *id = strchr(cmd, ' '); 127 char *id = strchr(cmd, ' ');
@@ -136,12 +136,12 @@ static void execute(ToxWindow *self, char *u_cmd)
136 msg++; 136 msg++;
137 } 137 }
138 else msg = ""; 138 else msg = "";
139 if (strlen(id) != 2*32) { 139 if (strlen(id) != 2*KEY_SIZE_BYTES) {
140 wprintw(self->window, "Invalid ID length.\n"); 140 wprintw(self->window, "Invalid ID length.\n");
141 return; 141 return;
142 } 142 }
143 int i; 143 int i;
144 for (i = 0; i < 32; ++i) { 144 for (i = 0; i < KEY_SIZE_BYTES; ++i) {
145 xx[0] = id[2*i]; 145 xx[0] = id[2*i];
146 xx[1] = id[2*i+1]; 146 xx[1] = id[2*i+1];
147 xx[2] = '\0'; 147 xx[2] = '\0';
@@ -240,9 +240,9 @@ static void execute(ToxWindow *self, char *u_cmd)
240 } 240 }
241 241
242 else if (!strcmp(cmd, "myid")) { 242 else if (!strcmp(cmd, "myid")) {
243 char id[32*2 + 1] = {0}; 243 char id[KEY_SIZE_BYTES*2 + 1] = {0};
244 size_t i; 244 size_t i;
245 for (i = 0; i < 32; ++i) { 245 for (i = 0; i < KEY_SIZE_BYTES; ++i) {
246 char xx[3]; 246 char xx[3];
247 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); 247 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
248 strcat(id, xx); 248 strcat(id, xx);
diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h
index cb45614d..287e534a 100644
--- a/testing/toxic/windows.h
+++ b/testing/toxic/windows.h
@@ -5,7 +5,9 @@
5#include <stdbool.h> 5#include <stdbool.h>
6#define TOXWINDOWS_MAX_NUM 32 6#define TOXWINDOWS_MAX_NUM 32
7#define MAX_FRIENDS_NUM 100 7#define MAX_FRIENDS_NUM 100
8 8#define MAX_STR_SIZE 256
9#define KEY_SIZE_BYTES 32
10
9/* number of permanent default windows */ 11/* number of permanent default windows */
10#define N_DEFAULT_WINS 2 12#define N_DEFAULT_WINS 2
11 13