Commit Graph

3847 Commits

Author SHA1 Message Date
iphydf
406d292107
Minor cleanups: header reordering, adding {}.
I hadn't done this for the "fun" code, yet. Also, we should include
system headers after our own headers.

"In general, a module should be implemented by one or more .cpp files.
Each of these .cpp files should include the header that defines their
interface first. This ensures that all of the dependences of the module
header have been properly added to the module header itself, and are not
implicit. System headers should be included after user headers for a
translation unit."
-- http://llvm.org/docs/CodingStandards.html#a-public-header-file-is-a-module
2016-09-09 19:30:50 +01:00
Jfreegman
769db9dd9a Separate IP_Port packing from pack_nodes() and unpack_nodes()
Allows us to pack IP_Port structs that are part of arbitrarily structured data.
2016-09-09 10:37:40 -04:00
iphydf
59075ba325
Use const for version numbers.
ApiDSL generates the lowercase function declarations for us and puts them in the
right namespace (TOX_, TOXAV_).
2016-09-09 10:05:12 +01:00
iphydf
3521898b0c
Fix potential null pointer dereference.
This used to not be an issue, but now that the logger is no longer
global, not all source locations may have access to it.
2016-09-08 20:21:12 +01:00
iphydf
54de13c1c7
Fix compilation for Windows.
- Mingw32 didn't read MSDN, so behaves badly despite lean and mean.
- Avoid alignment issues on windows with packed bitfields in the RTP header.
  This change makes the program ill-formed in C99, but I don't know the correct
  fix at the moment, and I don't want to keep the Windows build broken for too
  long.
2016-09-08 11:37:35 +01:00
iphydf
d5f9344847
Remove the packet mutation in toxav's bwcontroller.
1. This mutation is never observed outside the function.
2. If it were (it's not), it would be undefined behaviour, since the
   packet data goes out of scope a few instructions after the callback
   returns.
2016-09-08 11:10:25 +01:00
iphydf
254feb0acd
Add address sanitizer option to cmake file. 2016-09-08 10:13:40 +01:00
iphydf
ca1fe7ff7d
Fix memory leak on error paths in tox_new.
We didn't need to create the logger before all the validations. There is only
one error path where we need to free the logger.
2016-09-08 01:04:46 +01:00
iphydf
159dc3b6ab
Print a message about missing astyle in format-source. 2016-09-07 23:11:13 +01:00
Jfreegman
27a1626084
Comment intentional switch fallthroughs 2016-09-07 17:48:01 -04:00
Jfreegman
a35be20e6a Add debugging option to autotools configuration 2016-09-07 17:25:48 -04:00
iphydf
584debc7b6
Prevent <winsock.h> inclusion by <windows.h>. 2016-09-07 11:21:11 +01: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
4e6c86d1cb
Merge remote-tracking branch 'irungentoo/master' into merge-iru 2016-09-06 11:25:13 +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
irungentoo
e6af3a7825
Fixed bug. 2016-09-05 20:31:32 -04:00
iphydf
e7d3a1a665
Allocate sizeof(IP_ADAPTER_INFO) bytes instead of sizeof(T*).
https://msdn.microsoft.com/en-gb/library/windows/desktop/aa365917(v=vs.85).aspx
shows an example use of GetAdaptersInfo that does it this way.
2016-09-06 01:10:15 +01:00
iphydf
8121ace449
Make packet data a ptr-to-const.
Ensure that nobody inadvertly modifies the temporary packet data buffer.
2016-09-05 23:03:21 +01:00
iphydf
aa0e3974c5
Add TODO for @mannol. 2016-09-05 22:44:06 +01:00
isotoxin
2c989d992c Rearrange fields to decrease size of structure 2016-09-03 21:26:45 +03:00
iphydf
33edad8582
Add a short sleep before each tox_iterate in av test.
A race condition that happens on machines with heavily used network interfaces
causes tests to fail. Packets sent don't arrive on time. This sleep gives it 100
extra milliseconds. The real fix would be to wait for the event to occur and
then continue, but with a "once-loop" that is tox_iterate, it's not feasible at
this time.
2016-09-02 22:02:22 +01:00
iphydf
a759ddc7eb
Re-enable group chat tests.
They don't seem to be a lot less stable than the rest. Either way we regularly
need to restart builds to make timeouts go away.
2016-09-02 13:57:46 +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
579bdc126f
Remove useless casts.
These casts are either completely useless (casting T to T) or implicit (x = y).
2016-09-01 18:49:49 +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
45d1f9acb9
Match parameter names in declarations with their definitions.
The parameter names were taken from function definitions to update the names in
function declarations (prototypes).
2016-09-01 14:54:17 +01:00
iphydf
576f130615
Remove redundant return statements. 2016-08-31 23:51:39 +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
8595d47e10
Remove unused and bit-rotten friends_test. 2016-08-31 18:11:44 +01:00
iphydf
fa3b51266b
Add missing #includes to headers and rename tox_old to tox_group.
Also, no longer #include the group code into tox.c. Instead, compile it
separately in tox_group.c. This is a bit less surprising to someone looking
around the code. Having some implementations in a .h file is certainly a bit
surprising to a disciplined C programmer, especially when there is no technical
reason to do it.
2016-08-30 19:31:40 +01:00
iphydf
4692cea75e
Add getters/setters for options. 2016-08-29 23:15:39 +01:00
iphydf
74ecb0c460
Update tox.h with constant functions.
These are now generated by apidsl.
2016-08-29 14:07:17 +01:00
iphydf
8e0eeff79f
Expose constants as functions.
These functions simply return the constants. They are a stable ABI, so that if
constants change, the ABI of these functions won't. Code solely relying on these
functions will remain compatible with future values of those constants.

The functions are currently not exposed in tox.h, because this is pending a
change in apidsl to generate accessors for "const" values.
2016-08-28 20:05:07 +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
mannol
1f25fc0ae4 Fix plane size calculation in test 2016-08-26 22:47:19 +02:00
iphydf
a45356ce3e
Avoid large stack allocations on thread stacks.
OS X and Windows have small thread stacks by default. Allocating audio and video
frames (about 962KB total) on the stack overflows it.
2016-08-26 21:17:24 +01:00
iphydf
eb8a3e7a7c
Comment out useless TODO'd if block.
The condition is a potential use after free, because `connection_kill` before it
will delete the `conn` that is dereferenced.
2016-08-26 20:45:29 +01:00
iphydf
a3f9893e89
Initialise the id in assoc_test.
Once every new moon, the assoc_test would fail because the key is 0. It
can be anything but 0 to succeed, so I made it 1.
2016-08-26 15:24:43 +01:00
Gregory Mullen (grayhatter)
8c8532a984
Reduce the timeout on travis to something much more reasonable
10x timeouts forces travis to kill our build without offering anything helpful
2016-08-25 11:52:46 -07:00
iphydf
7075c3648a
Add cmake test for apidsl. 2016-08-24 09:41:40 +01:00
iphydf
503d198741
Replace uint with unsigned int in assoc.c.
uint is not a valid type on Windows. It's also not a valid type in C, but Linux
and OSX define it somewhere. We can't rely on its existence.
2016-08-22 16:01:08 +01:00
Gregory Mullen (grayhatter)
a6f2e9539b
Make Message received receipts stateless 2016-08-22 03:12:47 -07:00
Gregory Mullen (grayhatter)
3f0c101771
Make Friend User Status stateless 2016-08-22 02:10:18 -07:00
iphydf
b044cfbf15
Fix windows build.
The threading networking functions (on windows: winsock and friends) need to be
linked into the toxnetwork library, not the toxcore library, anymore. On Linux
and OSX, there is no winsock. On OSX, there is no need to link against threading
libraries, and on Linux, toxnetwork can have unresolved symbols when linking, so
this failure wasn't caught before.

Tested by building on the iphydf/windows-x86-qt5 docker image.
2016-08-21 14:21:57 +01:00
Zetok Zalbavar
4d83451da6
docs(INSTALL.md): update instructions for Gentoo 2016-08-20 19:44:50 +01:00