Commit Graph

198 Commits

Author SHA1 Message Date
iphydf
6ae33c16cf
Add VLA compatibility macro for C89-ish compilers. 2017-01-28 20:49:12 +00:00
iphydf
8f96ca6d86
Update license headers and remove redundant file name comment.
"All rights reserved" was incorrect. The project was licensed under GPL3,
which means a lot of rights are licensed to everybody in the world, i.e.
not reserved to the "Tox Project".
2017-01-19 00:01:44 +00:00
iphydf
cf94537266
Enable all possible C compiler warning flags.
We disable the ones that fire, so we can use -Werror. We can then
investigate each warning individually and see whether to fix it or to
keep silencing it.
2016-11-06 01:32:10 +00:00
iphydf
1977d56caa
Remove return after no-return situation (and other cleanups).
Cleanups:
- Fix header guards to not use reserved names.
- Avoid name shadowing.
- Removed an unused variable found by avoiding name shadowing.
2016-09-30 19:06:44 +01:00
Jfreegman
dd2965a58f Make group callbacks stateless 2016-09-21 15:33:55 -04: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
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
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
77db27331e
Sort #includes in all source files. 2016-09-01 16:35:46 +01:00
iphydf
633da98ae6
Add braces to all if statements. 2016-08-31 20:04:16 +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
a5e35180c7
Make tox_callback_friend_name stateless.
See #27 and #40 for details.
2016-08-18 00:01:53 +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
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
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
irungentoo
d711362622
Merged normal message function and send action function into one
messaging function.

This removes code duplication and allows us to easily add new message
types to the api without having to add new functions.
2015-03-18 15:32:53 -04:00
Dubslow
2f65de6fd1
Move get_connection_status to self pseudonamespace, to contrast friend_get_connection_status 2015-03-18 14:18:36 -05:00
irungentoo
b9e747fd50
When friend goes offline all his file transfers get removed.
This is now documented in the API.

Ported programs in testing/ to this behaviour.
2015-03-18 14:39:52 -04:00
irungentoo
5b7cbc8956
Api changes.
receive to recv in file receive functions.

Added TOX_MAX_FILENAME_LENGTH define.
2015-03-18 12:54:00 -04:00
irungentoo
8286c2c22f
Save function renamed to tox_get_savedata() 2015-03-17 16:20:38 -04:00
irungentoo
24c70c9e84
Added and implemented file_id parameter to file tranfers.
file_id is a 32byte identifier that can be used by users to identify
file tranfers across core/client restarts in order to resume broken
file tranfers.

In avatar tranfers it corresponds to the hash of the avatar.

Added tox_file_get_file_id() function to api to obtain the file_id
of an ongoing file transfer.

If not set, core will generate a random one.
2015-03-17 13:44:48 -04:00
irungentoo
6cf7270638
Make nTox save on exit. 2015-03-14 10:05:39 -04:00
irungentoo
c3e07b73d3
Remove TOX_FILE_KIND typedef. 2015-03-13 15:38:44 -04:00
irungentoo
8e2957ec50
Merge branch 'newer_api' of https://github.com/dubslow/toxcore into new_api 2015-03-13 15:29:34 -04:00
Dubslow
64fefb6f43
revert to TOX_FILE_KIND 2015-03-13 12:34:14 -05:00
Dubslow
3bf259f69d Convert core code depending on the api 2015-03-12 18:23:14 -05:00
irungentoo
8dc2db2025
Added position parameter to tox_file_send_chunk().
This is done so that the function now has the same parameters as the
request chunk callback.
2015-03-12 15:17:34 -04:00
irungentoo
8e55d96381
Ported nTox to new file transfer api. 2015-03-10 18:49:06 -04:00
irungentoo
d83efd35dd
Ported some of the code in testing/ to the new api. 2015-02-24 20:29:01 -05:00
irungentoo
94ac524374
Group audio might work now but I have not tested anything yet. 2014-11-10 17:59:14 -05:00
irungentoo
8b35d194c0
Group chats are starting to work. 2014-09-26 13:25:52 -04:00
irungentoo
7557b92fc9
Modified tox_bootstrap_from_address() function.
PORT IS NO LONGER PASSED IN NETWORK BYTE ORDER.

Removed useless ipv6enabled parameter.
2014-08-14 19:01:21 -04:00
irungentoo
ef78169842
Added disabling of UDP and basic SOCKS5 proxy support to public API.
tox_new() now takes a Tox_Options struct as argument.

If a NULL pointer is passed to that struct, defaults are used.
2014-08-14 18:34:20 -04:00
irungentoo
c4f0650ae3
Fixed const related warnings. 2014-07-02 16:04:41 -04:00
Tux3 / Mlkj / !Lev.uXFMLA
3044bd8101 Fix CppCheck style errors
#if 0 the content of toxav/msi.c : int stringify_message(MSIMessage
*msg, char *dest)
This function has no effect and does not seem to be used for actively
waiting.

Fix various other style errors, reduce scope when possible, avoid
redundant writes, clarify operator priorities, etc.
2014-06-20 21:43:21 +02:00
irungentoo
07936960df
Astyle and fixes. 2014-06-10 18:35:55 -04:00
irungentoo
7a11c10429
Fixed some nTox bugs. 2014-06-08 09:21:37 -04:00
liuguangzhao
9aa28c10b8 fix nTox cmdline input slow problem. 2014-06-08 14:08:52 +00:00
irungentoo
1bad0b5eea
Fixed TOX_MAX_MESSAGE_LENGTH define.
Removed some useless code from toxcore.

Astyled core code with new version of astyle.
2014-06-01 18:55:52 -04:00
irungentoo
89bf08287d
Renamed tox_do_run_interval to tox_do_interval.
tox_do_interval now returns a time in ms based on how much action
is going on in net_crypto.
2014-05-30 23:01:17 -04:00
irungentoo
0e814904e4
Replaced tox_wait* functions with tox_do_run_interval().
Build system fixes.
2014-05-30 13:20:36 -04:00