Commit Graph

662 Commits

Author SHA1 Message Date
iphydf 0d347c2b2e Minor cleanups: unused vars, unreachable code, static globals.
- All global variables should be static unless they have an explicit
  extern declaration in a header file.
- `to_compare` was not used in encryptsave and toxav tests.
- `break` in switch cases is not required directly after `return`,
  `goto`, or a noreturn function like `abort`.
2016-09-24 20:52:09 +01:00
Jfreegman dd2965a58f Make group callbacks stateless 2016-09-21 15:33:55 -04:00
iphydf 51d18236c8 Revert "Make ToxAV stateless"
This reverts commit 21f8db12c4.

It is currently broken. Incoming call callbacks are not invoked, and
instead the client goes offline immediately.
2016-09-19 21:53:40 +01:00
Jfreegman 8e43ca834c Complete old groupchat conversion to new API 2016-09-17 19:11:28 -04:00
iphydf c0397a0a46 ApiDSL'ing old group chats (now: conference). 2016-09-17 19:11:28 -04:00
Gregory Mullen (grayhatter) 21f8db12c4 Make ToxAV stateless 2016-09-17 14:05:51 -07:00
iphydf 80cc32a79d Use C99 %zu format conversion in printf for size_t.
size_t is unsigned long long on LLP64 and %lu prints unsigned long (32
bit), potentially causing problems.
2016-09-17 10:19:49 +01:00
iphydf 1494e474dd Ensure that all TODOs have an owner.
In the future, all TODOs added either need a bug number (TODO(#NN)) or a
person's github user name. By default, I made irungentoo the owner of
all toxcore TODOs, mannol the owner of toxav TODOs, and myself the owner
of API TODOs.
2016-09-16 12:06:02 +01:00
iphydf a8823830d3 Add some astyle options to make it do more.
It now enforces a bit more formatting. In particular, padding inside
parentheses is removed. I would like it to remove padding after unary
operators, but there seems to be no option for that.
2016-09-13 01:07:02 +01:00
michael bishop 05f474b4df make the majority of the callbacks stateless and add some status to a testcase 2016-09-10 01:09:37 -03:00
iphydf ad26560516 Improve static and const correctness.
- Any non-externally-visible declarations should be `static`.
- Casting away the `const` qualifier from pointers-to-const is
  dangerous. All but one instance of this are now correct. The one
  instance where we can't keep `const` is one where toxav code actually
  writes to a chunk of memory marked as `const`. This code also assumes
  4 byte alignment of data packets. I don't know whether that is a valid
  assumption, but it's likely unportable, and *not* obviously correct.
- Replaced empty parameter lists with `(void)` to avoid passing
  parameters to it. Empty parameter lists are old style declarations for
  unknown number and type of arguments.
- Commented out (as `#if DHT_HARDENING` block) the hardening code that
  was never executed.
- Minor style fix: don't use `default` in enum-switches unless the number
  of enumerators in the default case is very large. In this case, it was
  2, so we want to list them both explicitly to be warned about missing
  one if we add one in the future.
- Removed the only two function declarations from nTox.h and put them
  into nTox.c. They are not used outside and nTox is not a library.
2016-09-06 11:54:37 +01:00
iphydf 5b57ab6332 Improve C standard compliance.
- Don't cast between object and function pointers.
- Use standard compliant `__VA_ARGS__` in macros.
- Add explicit `__extension__` on unnamed union in struct (it's a GNU
  extension).
- Remove ; after function definitions.
- Replace `const T foo = 3;` for integral types `T` with `enum { foo = 3 };`.
  Folding integral constants like that as compile time constants is a GNU
  extension. Arrays allocated with `foo` as dimension are VLAs on strictly
  compliant C99 compilers.
- Replace empty initialiser list `{}` with zero-initialiser-list `{0}`.
  The former is a GNU extension meaning the latter.
- Cast `T*` (where `T != void`) to `void *` in format arguments. While any
  object pointer can be implicitly converted to and from `void *`, this
  conversion does not happen in variadic function calls.
- Replace arithmetic on `void *` with arithmetic on `char *`. The former
  is non-compliant.
- Replace non-`int`-derived types (like `uint16_t`, which is
  `short`-derived) in bit fields with `int`-derived types. Using any type
  other than `int` or `unsigned int` (or any of their aliases) in bit
  fields is a GNU extension.
2016-09-06 11:09:10 +01:00
Gregory Mullen (grayhatter) aad1e0ad3f Make friend requests stateless
Messenger is slightly twisty when it comes to sending connection status
callbacks It will very likely need at the very least a partial refactor to
clean it up a bit. Toxcore shouldn't need void *userdata as deep as is
currently does.

(amend 1) Because of the nature of toxcore connection callbacks, I decided to
change this commit from statelessness for connections changes to statelessness
for friend requests. It's simpler this was and doesn't include doing anything
foolish in the time between commits.

group fixup because grayhatter doesn't want to do it

"arguably correct" is not how you write security sensitive code

Clear a compiler warning about types within a function.
2016-09-06 02:22:04 -07:00
iphydf aa0e3974c5 Add TODO for @mannol. 2016-09-05 22:44:06 +01:00
iphydf a9fbdaf46b Do not use else after return.
http://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
2016-09-02 11:02:56 +01:00
iphydf 6f42eadc54 Replace pthread_yield with sched_yield.
The former is a non-standard glibc extension. On linux, it is implemented as a
call to sched_yield, so this change does nothing there. On OSX, pthread_yield
doesn't exist, and we already use sched_yield.
2016-09-02 09:55:00 +01:00
iphydf 77db27331e Sort #includes in all source files. 2016-09-01 16:35:46 +01:00
iphydf ad13518153 Add missing #include <pthread.h> to av_test.c.
It was an undefined function before.
2016-09-01 15:22:03 +01:00
iphydf 3a9300368d Add newlines because astyle wants them.
We'll revert this once we move to clang-format.
2016-08-31 20:54:20 +01:00
iphydf 633da98ae6 Add braces to all if statements. 2016-08-31 20:04:16 +01:00
iphydf 6356eb4e4f Enable build of av_test.
It has not been built in a while. We do want to keep this one working (or at
least compiling).
2016-08-31 20:02:41 +01:00
iphydf 13ae9e9a93 Move logging to a callback.
This removes the global logger (which by the way was deleted when the first tox
was killed, so other toxes would then stop logging). Various bits of the code
now carry a logger or pass it around. It's a bit less transparent now, but now
there is no need to have a global logger, and clients can decide what to log and
where.
2016-08-27 01:16:14 +01:00
Gregory Mullen (grayhatter) 1f94c96266 Make the friend message callback stateless 2016-08-20 11:07:49 -07:00
iphydf bdf5ac37b4 Make friend_status_message callback stateless.
See #40 for details.
2016-08-18 17:19:23 +01:00
iphydf 6935643f9a Fix some compiler warnings. 2016-08-18 17:10:15 +01:00
iphydf a5e35180c7 Make tox_callback_friend_name stateless.
See #27 and #40 for details.
2016-08-18 00:01:53 +01:00
iphydf db22522741 Add missing DHT_bootstrap to CMakeLists.txt.
- This PR also adds a DEBUG cmake option that enables -DTOX_DEBUG.
- We also remove `-Wall`, because there are too many warnings, and nobody really
  looks at them at the moment. We'll see about fixing them soon. We'll also want
  to enable `-Werror` at some point.
- Finally, this PR enables `-O3` to make sure toxcore still works correctly
  under heavy compiler optimisations.
2016-08-17 22:12:39 +01:00
iphydf dd8a568141 Make self_connection_status callback stateless.
**What are we doing?**

We are moving towards stateless callbacks. This means that when registering a
callback, you no longer pass a user data pointer. Instead, you pass a user data
pointer to tox_iterate. This pointer is threaded through the code, passed to
each callback. The callback can modify the data pointed at. An extra indirection
will be needed if the pointer itself can change.

**Why?**

Currently, callbacks are registered with a user data pointer. This means the
library has N pointers for N different callbacks. These pointers need to be
managed by the client code. Managing the lifetime of the pointee can be
difficult. In C++, it takes special effort to ensure that the lifetime of user
data extends at least beyond the lifetime of the Tox instance. For other
languages, the situation is much worse. Java and other garbage collected
languages may move objects in memory, so the pointers are not stable. Tox4j goes
through a lot of effort to make the Java/Scala user experience a pleasant one by
keeping a global array of Tox+userdata on the C++ side, and communicating via
protobufs. A Haskell FFI would have to do similarly complex tricks.

Stateless callbacks ensure that a user data pointer only needs to live during a
single function call. This means that the user code (or language runtime) can
move the data around at will, as long as it sets the new location in the
callback.

**How?**

We are doing this change one callback at a time. After each callback, we ensure
that everything still works as expected. This means the toxcore change will
require 15 Pull Requests.
2016-08-17 14:57:20 +01:00
Roman Proskuryakov ed3a794c9b fix: compare sensitive data with sodium_memcmp
fix: make increment_nonce & increment_nonce_number independent of user-controlled input
	fix: make crypto_core more stable agains null ptr dereference
2016-01-27 02:14:59 +03:00
irungentoo 6a494e2cbd Astyle. 2015-11-03 13:42:05 -05:00
Eniz Vukovic d6fdf16520 New Adaptive BR algorithm, cleanups and fixes 2015-10-10 23:54:23 +02:00
mannol c641b0fceb Updated with upstream 2015-08-09 12:39:21 +02:00
irungentoo 2ab3b14731 Merge branch 'dragonfly' of https://github.com/mneumann/toxcore 2015-08-08 21:38:23 -04:00
mannol 3c8cae72d0 Removed redundant function from video.[h|c] 2015-08-08 17:45:24 +02:00
irungentoo 6cb8ff4d65 Removed a useless define. 2015-08-07 20:53:53 -04:00
Michael Neumann caebc5303a Fix for DragonFlyBSD 2015-08-08 01:45:55 +02:00
mannol 657a57b406 Fixed memory leak during session cleanup and fixed naming. 2015-08-07 02:04:04 +02:00
irungentoo dfc154cc9e client_id -> public_key 2015-07-29 22:39:56 -04:00
mannol 2ecb71bb1e Renamed TOXAV_CALL_STATE to TOXAV_FRIEND_CALL_STATE 2015-06-27 17:28:07 +02:00
mannol a3132feddb Fixed sample size in callback and other stuff 2015-06-13 15:00:34 +02:00
mannol d694839d60 Rebased on master and removed alpha channel (again) 2015-06-05 22:14:37 +02:00
irungentoo 8e80ced6ce Move savedata to options struct.
Add a way to select the type of savedata (normal savedata, load a
secret key, potentially others?) to load.
2015-05-22 18:23:56 -04:00
mannol 3100042a2b Updated with master 2015-05-22 23:22:31 +02:00
irungentoo 782d68cdc3 Syncbot fixes. 2015-05-20 14:09:05 -04:00
mannol 73fbc22961 Fixed inconsistencies 2015-05-07 23:14:03 +02:00
mannol 9bba7a0434 Done 2015-04-29 01:01:25 +02:00
irungentoo b0983104d5 Renamed tox_file_send_control to tox_file_control.
Renamed tox_file_send_seek to tox_file_seek.
2015-03-21 08:58:54 -04:00
Dubslow d8da9bf709 callback_file_request_chunk -> callback_file_chunk_request
A couple of minor reasons, combined warrant a PR imo:
a) fileChunkRequested is a better signal name than fileRequestChunkReceived, and I don't want to break consistency by reordering words for just this signal
b) "request chunk" is parsed by English speakers as a verb-object combination,
   implying sending the request, not receiving, whereas "chunk requested" is
   parsed (more correctly) as an adjective-noun combo (in particular, request is
   a noun not a verb), and thus reads far more like "hey heads up we just got a request"

For instance some tests/testing code had some callbacks to *receive* chunk requests, and they were called "tox_file_request_chunk"... to receive a chunk, not request it. Now they're called "tox_file_chunk_request".

So yeah...
2015-03-19 08:38:27 -05:00
irungentoo e0bd6ef4e0 Renamed TOX_MESSAGE_TYPE_MESSAGE to TOX_MESSAGE_TYPE_NORMAL. 2015-03-18 17:14:57 -04:00
irungentoo 45cf8a744c Merge branch 'one_more_rename' of https://github.com/dubslow/toxcore into new_api 2015-03-18 16:15:36 -04:00