ffi-tox 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,6 +39,7 @@
39
39
  #include "../core/network.h"
40
40
  #define STRING_LENGTH 256
41
41
  #define HISTORY 50
42
+ #define PUB_KEY_BYTES 32
42
43
 
43
44
  void new_lines(char *line);
44
45
  void line_eval(char lines[HISTORY][STRING_LENGTH], char *line);
@@ -27,7 +27,7 @@
27
27
  #include <process.h>
28
28
 
29
29
  uint8_t pending_requests[256][CLIENT_ID_SIZE];
30
- uint8_t num_requests;
30
+ uint8_t num_requests = 0;
31
31
 
32
32
  char line[STRING_LENGTH];
33
33
  char users_id[200];
@@ -77,25 +77,25 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
77
77
  printf(msg);
78
78
  }
79
79
 
80
- void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
80
+ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
81
+ {
81
82
  char name[MAX_NAME_LENGTH];
82
83
  getname(friendnumber, (uint8_t*)name);
83
84
  char msg[100+length+strlen(name)+1];
84
- sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n", friendnumber, name, string);
85
+ sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string);
85
86
  printf(msg);
86
87
  }
87
88
 
88
89
  void load_key()
89
90
  {
90
91
  FILE *data_file = NULL;
91
-
92
- if ((data_file = fopen("data", "r"))) {
92
+ data_file = fopen("data","r");
93
+ if (data_file) {
93
94
  fseek(data_file, 0, SEEK_END);
94
95
  int size = ftell(data_file);
95
96
  fseek(data_file, 0, SEEK_SET);
96
97
  uint8_t data[size];
97
-
98
- if(fread(data, sizeof(uint8_t), size, data_file) != size) {
98
+ if (fread(data, sizeof(uint8_t), size, data_file) != size) {
99
99
  printf("\n[i] Could not read the data file. Exiting.");
100
100
  exit(1);
101
101
  }
@@ -107,115 +107,144 @@ void load_key()
107
107
  Messenger_save(data);
108
108
  data_file = fopen("data", "w");
109
109
 
110
- if(fwrite(data, sizeof(uint8_t), size, data_file) != size) {
110
+ if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
111
111
  printf("\n[i] Could not write data to file. Exiting.");
112
112
  exit(1);
113
113
  }
114
114
  }
115
-
116
115
  fclose(data_file);
117
116
  }
118
117
 
119
118
  void line_eval(char* line)
120
119
  {
121
120
  if(line[0] == '/') {
121
+ char inpt_command = line[1];
122
122
  /* Add friend */
123
- if(line[1] == 'f') {
123
+ if(inpt_command == 'f') {
124
124
  int i;
125
125
  char temp_id[128];
126
- for (i=0; i<128; i++)
126
+ for (i = 0; i < 128; i++)
127
127
  temp_id[i] = line[i+3];
128
128
  int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
129
- char numstring[100];
130
- sprintf(numstring, "\n[i] added friend %d\n\n", num);
131
- printf(numstring);
129
+ if (num >= 0) {
130
+ char numstring[100];
131
+ sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
132
+ printf(numstring);
133
+ }
134
+ else if (num == -1)
135
+ printf("\nWrong key size\n\n");
136
+ else if (num == -2)
137
+ printf("\nYou can't add yourself\n\n");
138
+ else if (num == -3)
139
+ printf("\nYou already have this person added\n\n");
140
+ else if (num == -4)
141
+ printf("\nUndefined error when adding friend");
132
142
  }
133
143
 
134
- else if (line[1] == 'r') {
144
+ else if (inpt_command == 'r') {
135
145
  do_header();
136
146
  printf("\n\n");
137
147
  }
138
148
 
139
- else if (line[1] == 'l') {
140
- printf("\n[i] Friend List | Total: %d\n\n", getnumfriends());
141
-
149
+ else if (inpt_command == 'l') {
150
+ int activefriends = 0;
142
151
  int i;
143
152
 
144
- for (i=0; i < getnumfriends(); i++) {
153
+ for (i = 0; i <= getnumfriends(); i++)
154
+ {
155
+ if (m_friendstatus(i) == 4)
156
+ activefriends++;
157
+ }
158
+
159
+ printf("\n[i] Friend List | Total: %d\n\n", activefriends);
160
+
161
+ for (i = 0; i <= getnumfriends(); i++) {
145
162
  char name[MAX_NAME_LENGTH];
146
163
  getname(i, (uint8_t*)name);
147
- printf("[%d] %s\n\n", i, (uint8_t*)name);
164
+ if (m_friendstatus(i) == 4)
165
+ printf("[%d] %s\n\n", i, (uint8_t*)name);
148
166
  }
149
167
  }
150
168
 
151
- else if (line[1] == 'd') {
169
+ else if (inpt_command == 'd') {
152
170
  size_t len = strlen(line);
153
171
  char numstring[len-3];
154
172
  int i;
155
- for (i=0; i<len; i++) {
173
+ for (i = 0; i < len; i++) {
156
174
  if (line[i+3] != ' ') {
157
175
  numstring[i] = line[i+3];
158
176
  }
159
177
  }
160
178
  int num = atoi(numstring);
161
179
  m_delfriend(num);
180
+ printf("\n\n");
162
181
  }
163
182
  /* Send message to friend */
164
- else if (line[1] == 'm') {
165
- int i;
183
+ else if (inpt_command == 'm') {
166
184
  size_t len = strlen(line);
167
185
  char numstring[len-3];
168
186
  char message[len-3];
169
- for (i=0; i<len; i++) {
187
+ int i;
188
+ for (i = 0; i < len; i++) {
170
189
  if (line[i+3] != ' ') {
171
190
  numstring[i] = line[i+3];
172
191
  } else {
173
192
  int j;
174
- for (j=i+1; j<len; j++)
193
+ for (j = (i+1); j < len; j++)
175
194
  message[j-i-1] = line[j+3];
176
195
  break;
177
196
  }
178
197
  }
179
198
  int num = atoi(numstring);
180
199
  if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
181
- printf("\n[i] could not send message: %s\n", message);
200
+ printf("\n[i] could not send message (they may be offline): %s\n", message);
182
201
  } else {
183
202
  //simply for aesthetics
184
203
  printf("\n");
185
204
  }
186
205
  }
187
206
 
188
- else if (line[1] == 'n') {
207
+ else if (inpt_command == 'n') {
189
208
  uint8_t name[MAX_NAME_LENGTH];
190
209
  int i = 0;
191
210
  size_t len = strlen(line);
192
- for (i=3; i<len; i++) {
211
+ for (i = 3; i < len; i++) {
193
212
  if (line[i] == 0 || line[i] == '\n') break;
194
- name[i - 3] = line[i];
213
+ name[i-3] = line[i];
195
214
  }
196
- name[i - 3] = 0;
215
+ name[i-3] = 0;
197
216
  setname(name, i);
198
217
  char numstring[100];
199
218
  sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
200
219
  printf(numstring);
220
+
221
+ FILE *name_file = NULL;
222
+ name_file = fopen("namefile.txt", "w");
223
+ fprintf(name_file, "%s", (char*)name);
224
+ fclose(name_file);
201
225
  }
202
226
 
203
- else if (line[1] == 's') {
227
+ else if (inpt_command == 's') {
204
228
  uint8_t status[MAX_USERSTATUS_LENGTH];
205
229
  int i = 0;
206
230
  size_t len = strlen(line);
207
- for (i=3; i<len; i++) {
231
+ for (i = 3; i < len; i++) {
208
232
  if (line[i] == 0 || line[i] == '\n') break;
209
- status[i - 3] = line[i];
233
+ status[i-3] = line[i];
210
234
  }
211
- status[i - 3] = 0;
235
+ status[i-3] = 0;
212
236
  m_set_userstatus(status, strlen((char*)status));
213
237
  char numstring[100];
214
238
  sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
215
239
  printf(numstring);
240
+
241
+ FILE* status_file = NULL;
242
+ status_file = fopen("statusfile.txt", "w");
243
+ fprintf(status_file, "%s", (char*)status);
244
+ fclose(status_file);
216
245
  }
217
246
 
218
- else if (line[1] == 'a') {
247
+ else if (inpt_command == 'a') {
219
248
  uint8_t numf = atoi(line + 3);
220
249
  char numchar[100];
221
250
  sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf);
@@ -225,12 +254,12 @@ void line_eval(char* line)
225
254
  printf(numchar);
226
255
  }
227
256
  /* EXIT */
228
- else if (line[1] == 'q') {
257
+ else if (inpt_command == 'q') {
258
+ uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline";
259
+ m_set_userstatus(status, strlen((char*)status));
229
260
  exit(EXIT_SUCCESS);
230
261
  }
231
- }
232
-
233
- else {
262
+ } else {
234
263
  //nothing atm
235
264
  }
236
265
  }
@@ -250,47 +279,74 @@ int main(int argc, char *argv[])
250
279
  printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
251
280
  exit(0);
252
281
  }
253
-
254
282
  if (initMessenger() == -1) {
255
283
  printf("initMessenger failed");
256
284
  exit(0);
257
285
  }
258
-
259
286
  if (argc > 4) {
260
287
  if(strncmp(argv[4], "nokey", 6) < 0) {
261
288
  }
262
289
  } else {
263
290
  load_key();
264
291
  }
265
-
292
+
293
+ int nameloaded = 0;
294
+ int statusloaded = 0;
295
+
296
+ FILE* name_file = NULL;
297
+ name_file = fopen("namefile.txt", "r");
298
+ if(name_file) {
299
+ uint8_t name[MAX_NAME_LENGTH];
300
+ while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) {
301
+ sscanf(line, "%s", (char*)name);
302
+ }
303
+ setname(name, strlen((char*)name)+1);
304
+ nameloaded = 1;
305
+ printf("%s\n", name);
306
+ }
307
+ fclose(name_file);
308
+
309
+ FILE* status_file = NULL;
310
+ status_file = fopen("statusfile.txt", "r");
311
+ if(status_file) {
312
+ uint8_t status[MAX_USERSTATUS_LENGTH];
313
+ while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) {
314
+ sscanf(line, "%s", (char*)status);
315
+ }
316
+ m_set_userstatus(status, strlen((char*)status)+1);
317
+ statusloaded = 1;
318
+ printf("%s\n", status);
319
+ }
320
+ fclose(status_file);
321
+
266
322
  m_callback_friendrequest(print_request);
267
323
  m_callback_friendmessage(print_message);
268
324
  m_callback_namechange(print_nickchange);
269
325
  m_callback_userstatus(print_statuschange);
270
-
271
- char idstring1[32][5];
272
- char idstring2[32][5];
273
- uint32_t i;
274
- for(i = 0; i < 32; i++)
326
+ char idstring1[PUB_KEY_BYTES][5];
327
+ char idstring2[PUB_KEY_BYTES][5];
328
+ int i;
329
+ for(i = 0; i < PUB_KEY_BYTES; i++)
275
330
  {
276
- if(self_public_key[i] < 16)
331
+ if(self_public_key[i] < (PUB_KEY_BYTES/2))
277
332
  strcpy(idstring1[i],"0");
278
333
  else
279
334
  strcpy(idstring1[i], "");
280
335
  sprintf(idstring2[i], "%hhX",self_public_key[i]);
281
336
  }
282
337
  strcpy(users_id,"[i] your ID: ");
283
- for (i=0; i<32; i++) {
284
- strcat(users_id,idstring1[i]);
285
- strcat(users_id,idstring2[i]);
338
+ int j;
339
+ for (j = 0; j < PUB_KEY_BYTES; j++) {
340
+ strcat(users_id,idstring1[j]);
341
+ strcat(users_id,idstring2[j]);
286
342
  }
287
343
 
288
344
  do_header();
289
-
345
+
290
346
  IP_Port bootstrap_ip_port;
291
347
  bootstrap_ip_port.port = htons(atoi(argv[2]));
292
348
  int resolved_address = resolve_addr(argv[1]);
293
- if (resolved_address != -1)
349
+ if (resolved_address != 0)
294
350
  bootstrap_ip_port.ip.i = resolved_address;
295
351
  else
296
352
  exit(1);
@@ -302,6 +358,16 @@ int main(int argc, char *argv[])
302
358
 
303
359
  _beginthread(get_input, 0, NULL);
304
360
 
361
+ if (nameloaded == 1) {
362
+ printf("\nNickname automatically loaded");
363
+ printf("\n---------------------------------");
364
+ }
365
+
366
+ if (statusloaded == 1) {
367
+ printf("\nStatus automatically loaded");
368
+ printf("\n---------------------------------");
369
+ }
370
+
305
371
  while(1) {
306
372
  if (on == 1 && DHT_isconnected() == -1) {
307
373
  printf("\n---------------------------------");
@@ -309,15 +375,13 @@ int main(int argc, char *argv[])
309
375
  printf("\n---------------------------------\n\n");
310
376
  on = 0;
311
377
  }
312
-
313
378
  if (on == 0 && DHT_isconnected()) {
314
379
  printf("\n[i] Connected to DHT");
315
380
  printf("\n---------------------------------\n\n");
316
381
  on = 1;
317
382
  }
318
-
319
383
  doMessenger();
384
+ Sleep(1);
320
385
  }
321
-
322
386
  return 0;
323
- }
387
+ }
@@ -27,5 +27,14 @@
27
27
  #include "../core/network.h"
28
28
 
29
29
  #define STRING_LENGTH 256
30
+ #define PUB_KEY_BYTES 32
31
+
32
+ void do_header();
33
+ void print_message(int friendnumber, uint8_t * string, uint16_t length);
34
+ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length);
35
+ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length);
36
+ void load_key();
37
+ void line_eval(char* line);
38
+ void get_input();
30
39
 
31
40
  #endif
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-tox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tristan Rice
@@ -14,33 +13,29 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ffi
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.9.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.9.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: ffi-swig-generator
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.3.2
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.3.2
46
41
  description: Ruby FFI bindings to Tox
@@ -53,65 +48,70 @@ files:
53
48
  - lib/ffi-tox.rb
54
49
  - lib/ffi-tox/libtox.rb
55
50
  - interfaces/libtox.i
56
- - ProjectTox-Core/CMakeLists.txt
57
51
  - ProjectTox-Core/COPYING
52
+ - ProjectTox-Core/CMakeLists.txt
58
53
  - ProjectTox-Core/INSTALL.md
59
54
  - ProjectTox-Core/README.md
60
55
  - ProjectTox-Core/core/DHT.c
61
56
  - ProjectTox-Core/core/DHT.h
62
57
  - ProjectTox-Core/core/LAN_discovery.c
63
58
  - ProjectTox-Core/core/LAN_discovery.h
64
- - ProjectTox-Core/core/Lossless_UDP.c
65
59
  - ProjectTox-Core/core/Lossless_UDP.h
60
+ - ProjectTox-Core/core/friend_requests.c
61
+ - ProjectTox-Core/core/net_crypto.h
62
+ - ProjectTox-Core/core/CMakeLists.txt
63
+ - ProjectTox-Core/core/Lossless_UDP.c
66
64
  - ProjectTox-Core/core/Messenger.c
67
65
  - ProjectTox-Core/core/Messenger.h
68
- - ProjectTox-Core/core/friend_requests.c
69
66
  - ProjectTox-Core/core/friend_requests.h
70
67
  - ProjectTox-Core/core/net_crypto.c
71
- - ProjectTox-Core/core/net_crypto.h
72
68
  - ProjectTox-Core/core/network.c
73
69
  - ProjectTox-Core/core/network.h
74
- - ProjectTox-Core/core/CMakeLists.txt
75
70
  - ProjectTox-Core/other/CMakeLists.txt
76
71
  - ProjectTox-Core/other/DHT_bootstrap.c
72
+ - ProjectTox-Core/testing/DHT_sendfiletest.c
73
+ - ProjectTox-Core/testing/Messenger_test.c
74
+ - ProjectTox-Core/testing/misc_tools.c
75
+ - ProjectTox-Core/testing/rect.py
77
76
  - ProjectTox-Core/testing/CMakeLists.txt
78
77
  - ProjectTox-Core/testing/DHT_cryptosendfiletest.c
79
- - ProjectTox-Core/testing/DHT_sendfiletest.c
80
78
  - ProjectTox-Core/testing/DHT_test.c
81
79
  - ProjectTox-Core/testing/Lossless_UDP_testclient.c
82
80
  - ProjectTox-Core/testing/Lossless_UDP_testserver.c
83
- - ProjectTox-Core/testing/Messenger_test.c
84
- - ProjectTox-Core/testing/misc_tools.c
85
81
  - ProjectTox-Core/testing/misc_tools.h
86
82
  - ProjectTox-Core/testing/nTox.c
87
83
  - ProjectTox-Core/testing/nTox.h
88
84
  - ProjectTox-Core/testing/nTox_win32.c
89
85
  - ProjectTox-Core/testing/nTox_win32.h
90
- - ProjectTox-Core/testing/rect.py
86
+ - ProjectTox-Core/cmake/FindLIBCONFIG.cmake
87
+ - ProjectTox-Core/cmake/FindNaCl.cmake
88
+ - ProjectTox-Core/cmake/FindSODIUM.cmake
89
+ - ProjectTox-Core/docs/commands.md
90
+ - ProjectTox-Core/docs/start_guide.de.md
91
+ - ProjectTox-Core/docs/start_guide.md
91
92
  - ext/ffi-tox/extconf.rb
92
93
  homepage: http://github.com/d4l3k/ffi-tox
93
94
  licenses:
94
95
  - Simplified BSD
96
+ metadata: {}
95
97
  post_install_message:
96
98
  rdoc_options: []
97
99
  require_paths:
98
100
  - lib
99
101
  required_ruby_version: !ruby/object:Gem::Requirement
100
- none: false
101
102
  requirements:
102
- - - ! '>='
103
+ - - '>='
103
104
  - !ruby/object:Gem::Version
104
105
  version: '0'
105
106
  required_rubygems_version: !ruby/object:Gem::Requirement
106
- none: false
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 1.8.24
113
+ rubygems_version: 2.0.3
114
114
  signing_key:
115
- specification_version: 3
115
+ specification_version: 4
116
116
  summary: Tox bindings
117
117
  test_files: []