Commit Graph

56 Commits

Author SHA1 Message Date
Michael Jones
66a85ef09e
Address clang-tidy warnings in db files (#1405)
The general approach here was:

- Always declare variables as close to where they are defined as
possible.
- Check for pre-conditions of functions before doing work (e.g. ensure
we can connect to the DB before doing a bunch of string formatting)
- Keep the scope of mutexes as reasonably small as practical.
- Use idiomatic C11, such as for-loops over the thing being iterated,
not while() loops over constants, or variables that aren't modified.
- Prefer if(fail){return} function-body after over `if(not fail){
function-body inside if} return;

Clang-tidy returns a clean bill of health, but while going through this
file i noticed a lot of things that raise questions.

Lack of checking column counts. Lack of handling the possibility of
multiple return values. Questionably handling of strings. Complete lack
of checking function inputs for invalid values (e.g. nullptr).

I'm not going to fix those, my organization doesn't USE the DB drivers,
so i have little interest in re-working the logic beyond addressing
clang-tidy warnings for my own sanity, but i did add TODO comments for
someone else to look at in the future.



Additional note: While the changes look very invasive.... they aren't.

I don't think there is a way to get github to ignore whitespace in the
filediff, but if someone were to compare the commit locally, they'll see
that almost all of the changes are just adjusting indentation.
2024-05-29 20:44:23 -07:00
Michael Jones
da332ed9e7
Add the InsertBraces command for clang-format to ensure that all conditionals always have braces (#1408)
- Why? Because code where conditionals lack braces is much harder to read, and prone to indentation confusion.
- How? Just added an extra flag to .clang-format and re-ran clang-format on all the files.

I also moved .clang-format up to the top level of the repo so that it can be applied to the fuzz targets as well.
2024-01-27 16:38:40 -08:00
Pavel Punsky
c062d5e2af
Simplify macOS detection macros (#1372) 2024-01-15 15:18:35 -08:00
Pavel Punsky
f8e9892d3e
Fix potential null passed to function expecting nonnull (#1373) 2024-01-15 15:13:32 -08:00
Gustavo Garcia
d9108a4b54
Add clang format rules and checks (#935)
I would like to get feedback on this and see if people is confortable
with these clang rules.

Right now is using the "llvm" style increasing the line length from 80
to 120 given that coturn is using long lines often.

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2022-11-06 22:05:17 +01:00
Kang Lin
40c99db6ba
Support Windows MSVC (#855)
The following changes have been made:
1. Replace deprecated functions with new standard functions
2. Add corresponding MSVC functions for non-standard functions 
3. Remove warnings about unsafe functions
4. CMAKE: modify find pack Libevent and openssl 
5. Modify include files
6. Use pthread4W
7. Modify socket in windows
8. Add CI - github action
8.1. msvc
8.2. mingw
10. The database:
9.1. sqlite, pgsql, hiredis, mongo  is test compiled.
9.2. mysql, isnot test compiled.
11. The applications、server can be compiled and run successfully! 
12. Add vcpkg manifest mode in cmake.
2022-10-28 19:32:23 -07:00
Pavel Punsky
af9bc12055
Sanitize DB connection string before printing to log (#1020)
Store sanitized version of DB connection string with password masked
(replace all chars with * which exposes its length)
Use sanitized version when logging connection string

Fixes #1017 and #272
2022-10-17 08:44:30 +02:00
Pavel Punsky
d9e74af75d
Cleanup unused include of header files (#1004)
Using clang-tidy to detect unused header files

Inspired by #855

Test Plan:
- Rebuild all on mac, review no warnings/errors
- Pass builds/docker build - review for no issues
2022-10-05 10:28:40 +02:00
Mészáros Mihály
a19bc7c464 Revert by hand merge PR825 in favor PR755 more simple solution 2021-09-22 13:32:34 +02:00
Mészáros Mihály
b5a597836b Merge branch 'master' into fix_sqlite_shutdown_race 2021-09-22 11:12:41 +02:00
Arne Georg Gisnås Gleditsch
8d66122d91 dbd_sqlite: Don't shutdown sqlite3 db during init
Ref https://www.sqlite.org/c3ref/initialize.html:

    The sqlite3_initialize() interface is threadsafe, but
    sqlite3_shutdown() is not.

We currently call `sqlite3_shutdown` from all threads as part of
`sqlite_init_multithreaded`, and this has been observed to have
adversarial effects during startup if many threads receive their first
inbound request at the same time. The apparent motivation behind
calling shutdown is to make the subsequent calls to `sqlite3_config`
succeed, since these ordinarily return SQLITE_MISUSE if called
multiple times. However, this function is also documented to not be
thread safe, so introduce a barrier that ensures we only initialize
once over all threads.
2021-09-20 16:33:25 +02:00
Serhii Charykov
0f7ff3ec4a Change sqlite_init_multithreaded return type to void
to satisfy pthread_once() interface because
previously return from sqlite_init_multithreaded
was not used
2021-04-26 23:47:11 +03:00
Serhii Charykov
2d12ad4f29 Refactor code 2021-04-26 23:34:24 +03:00
Serhii Charykov
34e18533cf Fix sqlite3_config call only once before using any other sqlite utilities 2021-04-26 22:19:16 +03:00
Serhii Charykov
0b709a05b7 Remove sqlite3_shutdown()
Because:
1. According to sqlite3 docs sqlite3_initialize() and sqlite3_shutdown() are not must to be invoked
2. sqlite3_initialize() is never called explicilty
3. sqlite3_shutdown() is not threadsafe and sqlite_init_multithreaded is not called holding a lock
4. According to docs all connections must be closed before invoking sqlite3_shutdown() but they are not (from the different threads).

Possible issue:
sqlite3_config must be called before sqlite3_initialize() or after sqlite3_shutdown() (and only once?)
2021-04-26 21:36:28 +03:00
Mészáros Mihály
50ebef7a3f Fix g++ 2 errors and many warnings
Resolves #661 #654
2021-01-05 21:47:50 +00:00
Mészáros Mihály
a409588eda Fix: sqlite disconnect function 2019-05-21 12:23:59 +02:00
Shu Muto
dac67ea046 Disconnect database gracefully
Coturn does not disconnect database properly when shutdown.
This behavior causes accumulation of sockets for database with TIME_WAIT.
Especially, `turnadmin` is recommended to manage userdb,
but use of `turnadmin` from other application or scripts
can run out of socket resource due to above problem.

This patch adds database disconnection when shutdown
for both of `turnserver` and `turnadmin`.

Fixes #366
2019-03-18 15:33:21 +09:00
Bradley T. Hughes
d2ee3ac291 Remove [su]{08,16,32,64}bits type defines
Do not overload the standard types with #defines, just use them
directly.
2019-03-08 09:08:30 +01:00
Bradley T. Hughes
043b102e38 Remove turn_strdup()
Do not overload strdup() from string.h
2019-03-07 08:00:08 +01:00
Bradley T. Hughes
b50fc77124 Remote turn_free()
Do not overload free() with a different API.
2019-03-07 07:58:12 +01:00
Bradley T. Hughes
fef016901e Remove turn_malloc()
Do not overload malloc() from stdlib.h
2019-03-06 23:38:20 +01:00
Bradley T. Hughes
ed91d4bc17 Remove turn_free_simple
Do not overload free() from stdlib.h
2019-03-06 23:34:25 +01:00
Oleg Moskalenko
dbc9dee42b working on multi-tenant server based upon oauth 2015-09-14 00:16:13 -07:00
mom040267
153b2d1d41 fixing a security hole 2015-06-28 05:37:28 +00:00
mom040267
6c2604620b SQLite support for CentOS/RedHat 5 2015-05-28 04:51:30 +00:00
mom040267
31b25414b4 working on oauth 2015-04-19 08:14:29 +00:00
mom040267
6dbee00b74 working on new third-party auth draft 2015-04-19 07:37:12 +00:00
mom040267
86f40b4bd9 working on third-party auth 2015-04-19 06:18:28 +00:00
mom040267
4424b3c92a --sha256, --sha384, --sha512 parameters retired. 2015-04-11 07:26:55 +00:00
mom040267
61239f9aa8 bandwidth limit is 64 bits now 2015-03-02 01:44:29 +00:00
mom040267
6a633fadc9 default sqlite database schema fixed 2015-02-22 07:14:00 +00:00
mom040267
11becb068c warnings fixed 2015-01-24 18:43:52 +00:00
mom040267
da0f380b18 cosmetics 2015-01-24 10:43:56 +00:00
mom040267
4e8b95bbb0 c++ compilation errors fixed 2015-01-24 08:21:32 +00:00
mom040267
7c2fc1b1b6 oauth timestamps added 2015-01-23 07:12:04 +00:00
mom040267
aefe2608d0 oauth keys page 2015-01-22 10:03:40 +00:00
mom040267
49c88a5576 start working on oauth 2015-01-21 18:43:47 +00:00
mom040267
01e1316c49 black/white lists page 2015-01-20 08:55:28 +00:00
mom040267
55d116f7fe origins admin page 2015-01-19 08:00:47 +00:00
mom040267
9bd8f29ac8 shared secrets admin page and fixes 2015-01-19 06:15:06 +00:00
mom040267
e3d9f5484c list users 2015-01-18 05:48:34 +00:00
mom040267
237b3baaa7 short-term credentials removed in the TURN server 2015-01-11 06:28:58 +00:00
mom040267
5cd0d33c31 1) working on https; 2) SSLv2 support removed. 2015-01-10 08:25:29 +00:00
mom040267
f17ce4fe83 new turn_admin table 2015-01-07 07:57:56 +00:00
mom040267
626a6b69d7 minor fixes 2014-12-21 10:48:53 +00:00
mom040267
ae71f2b7fd sqlite multithreading 2014-12-21 07:21:46 +00:00
mom040267
c3da54c292 multiple auth threads 2014-12-21 03:16:02 +00:00
mom040267
6b291a8238 multi-threaded DB connections. 2014-12-20 08:51:44 +00:00
mom040267
df7b770ebb minor fixes 2014-12-01 17:54:38 +00:00