Commit Graph

3559 Commits

Author SHA1 Message Date
gardners
3743a08be1 attempt to fix building on openwrt 2015-12-26 17:13:16 +10:30
gardners
104c311b21 add missing OUT() to sync_send_response exit path if sqllite
statement preparation fails.
2015-12-26 15:44:22 +10:30
Jeremy Lakeman
84d133438a Clean up jni server test 2015-12-14 11:22:02 +10:30
Jeremy Lakeman
77162fbaec Improve config overflow message 2015-12-14 10:31:38 +10:30
Andrew Bettison
bd45186a6a Document REST POST /restful/rhizome/insert
Adds definitions for Rhizome concepts such as Bundle ID, Bundle Secret,
payload, etc. and a detailed step-by-step definition of the insertion
logic.
2015-12-07 22:39:19 +10:30
Andrew Bettison
3f8f0f6fc7 Improve Rhizome HTTP API diagnostics
Add RHIZOME_BUNDLE_STATUS_MANIFEST_TOO_BIG enum option to indicate
that the manifest exceeded 8 KiB in size.

Refactor rhizome_add_manifest() and rhizome_manifest_finalise()
to return 'struct rhizome_bundle_result' instead of 'enum
rhizome_bundle_status', so that that their detailed failure messages
can reach the HTTP API layer instead of just being logged.

Fix HTTP response status codes produced Rhizome direct HTTP requests
to be consistent with the Rhizome RESTful API.
2015-12-07 22:35:42 +10:30
Andrew Bettison
74735339aa Fix minor bug in Rhizome manifest parsing
Did not indicate failure if last line was missing a newline.
2015-12-07 22:35:42 +10:30
Andrew Bettison
2b40e5394d Define $LF in testdefs
Accompanies $CR and $HT to help write more readable test
scripts.
2015-12-07 22:35:42 +10:30
Andrew Bettison
1bd599f79d Add --omit option to 'tfw_createfile' utility
Allows generation of files that do not contain a specific set
of characters.
2015-12-07 22:35:42 +10:30
Andrew Bettison
61a4911934 Fix SEGV bug in rhizome_bundle_result_sprintf() 2015-12-07 22:33:43 +10:30
Andrew Bettison
cc26dd99e5 Cosmetic: rename variable 'result' to 'http_status'
For more consistency with standard terminology.
2015-12-07 11:25:40 +10:30
Andrew Bettison
aabb1c5547 Call rhizome_bundle_result_free() in meshms.c
Otherwise there may be a memory leak.
2015-12-07 11:25:40 +10:30
Andrew Bettison
39460947f1 Add 'rhizomeall' test script
Runs all Rhizome test cases.
2015-12-01 00:51:15 +10:30
Andrew Bettison
fd50a34fc8 Add minor safety check to a Rhizome test case
Ensure that two generated test files are different instead of just
assuming they are; makes the test logic more explicit.
2015-12-01 00:51:15 +10:30
Andrew Bettison
98ed0406c5 Refactor Rhizome result handling
- Introduce the new 'struct rhizome_bundle_result' that contains a
  rhizome_bundle_status enum value and an optional, nul-terminated
  string that provides an explanation of the cause of the status; add
  functions to construct, query, and free the struct

- Replace 'enum rhizome_add_result' with 'struct rhizome_bundle_result',
  removing an unnecessary level of enum interpretation

- Make rhizome_fill_manifest() return 'struct rhizome_bundle_result' and
  add logic to check that the supplied author SID is correct (previous
  behaviour was: if an incorrect author SID was supplied but the correct
  author could be found in the keyring, then the incorrect one was
  silently ignored)

- Simplify the response code in rhizome_restful.cc to take advantage of
  the new 'struct rhizome_bundle_result'; in particular, the mapping
  from 'enum rhizome_bundle_status' codes to HTTP status codes is now
  expressed in a single switch statement

- Fix some minor failures in test scripts revealed by the changes
2015-12-01 00:51:15 +10:30
Andrew Bettison
078bf5eb6b Improve HTTP responses
In 'struct http_response', rename the 'result_code' field to
'status_code' for consistency with the terminology used in the HTTP
specification, and add a 'reason' field, so that the phrase that
appears in the first response line can differ from the standard
"canned" phrases.
2015-12-01 00:51:15 +10:30
Andrew Bettison
17b0644277 Allow anonymous bundles to have a 'sender' field 2015-12-01 00:51:15 +10:30
Jeremy Lakeman
c3ca8770ea Squelch logging due to unacked packet timeout 2015-11-30 14:22:45 +10:30
Andrew Bettison
dae68c7524 Replace quick compilation fixes with proper fix
Proper fix does not use "#ifdef __clang__", instead detects the
compiler's supported attributes at ./configure time.
2015-11-23 15:12:00 +10:30
Andrew Bettison
e8e87b8a34 Fix broken clang and Android builds
Recent addition of the GCC __attribute__(alloc_size) to some functions
in mem.h broke the build when using Clang 3.5.  This commit introduces
configure-time checks for all GCC attributes used in the Serval source
code, and adapts accordingly.
2015-11-23 15:00:25 +10:30
Andrew Bettison
1d3a6abe61 Remove __attribute__(returns_nonnull) from emalloc() et al
Was added in error; in fact, emalloc() and its ilk can return NULL.
Also, Clang 3.5 and the Android GCC do not support this attribute.
2015-11-23 15:00:03 +10:30
Jeremy Lakeman
67c1f382d4 Quick fix to unbreak android build too 2015-11-23 11:14:57 +10:30
Jeremy Lakeman
f774d12686 Fix build for clang 2015-11-23 10:54:41 +10:30
Jeremy Lakeman
fd38ddb892 Attempt to recover from transient network errors 2015-11-23 09:48:51 +10:30
Andrew Bettison
bdb3b99143 Add some comments to clarify Rhizome enums 2015-11-17 00:42:06 +10:30
Andrew Bettison
0dd778bab5 Optimise strbuf_ncat()
Do not write nul unnecessarily.
2015-11-17 00:42:06 +10:30
Andrew Bettison
fc67b38fd2 Fix bug in strbuf_reset()
Could write a nul char into a zero-size buffer.
2015-11-17 00:42:06 +10:30
Andrew Bettison
23cd578595 Cosmetic improvements to strbuf.h 2015-11-17 00:42:06 +10:30
Andrew Bettison
8310d3cf19 Add strbuf_malloc() macro 2015-11-17 00:42:06 +10:30
Andrew Bettison
45b7d4f4c5 Under GCC, check strbuf_local() buffer limit
If strbuf_local(buf, len) is called with a buffer whose size can be
deduced at compile time, then this change will check that 'len' does not
exceed that size, causing an assertion failure at run time if it does.

The safety check makes use of the GCC extensions: __builtin_object_size()
and __attribute__((alloc_size(n)).  Under non-GCC compilers, the safety
check will not be performed.
2015-11-17 00:42:06 +10:30
Andrew Bettison
fdc6156ec7 Under GCC, enforce proper strbuf_local_buf() arg
Internally the strbuf_local_buf(x) macro uses sizeof(x) to determine
the size of the buffer, but this will give the wrong behaviour if x
is a pointer (char *x), not an array (char x[]).  With this change,
invoking it with a pointer will cause a compile error.

The safety check makes use of the GCC extensions: __builtin_object_size()
and __attribute__((alloc_size(n)).  Under non-GCC compilers, the safety
check will not be performed.
2015-11-17 00:42:06 +10:30
Jeremy Lakeman
2ddbb86cb5 Don't ask for explanation of SIDs with dead routing links 2015-11-16 14:09:35 +10:30
Jeremy Lakeman
a075a8edbc Retry socket binding when interfaces come up 2015-11-16 12:54:59 +10:30
Andrew Bettison
6b554442bc Optimise Rhizome author deduction
Test sender before trying all other identities in keyring.
2015-11-09 15:13:21 +10:30
Andrew Bettison
3c993f0273 Add fromhere=2 to Rhizome list output
Need a way for the client to distinguish between authenticated (certain)
and unauthenticated (likely) author SIDs in the context of a bundle list,
since the bundle list does not verify manifest signatures for performance
and battery life reasons.
2015-11-02 12:26:40 +10:30
Andrew Bettison
419364b5a9 Improve REST HTTP response status codes
List all the HTTP status codes in the REST API tech doc.

Only use 403 Forbidden for requests originating from a disallowed
origin (ie, not localhost).

- Return 400 for missing, unknown, duplicate and out-of-order form
  parts in POST requests.
- Return 415 Unsupported Media Type for unsupported form part
  Content-Disposition and Content-Type (including unsupported
  charset).
- Return 414 Request-URI Too Long for any buffer exhaustion while
  parsing request.
- Return 419 Authentication Timeout for missing crypto secret.
2015-11-02 12:26:40 +10:30
Andrew Bettison
e189bcf32a Add REST API technical document
Document some Keyring, Rhizome and MeshMS requests, many are still TBC.

Also fix doc/README.md's link to Cooee.md
2015-11-02 12:26:34 +10:30
Andrew Bettison
4564e955e3 Improve HTTP Origin response headers
Re-introduce "Origin: null" handling, because actually it is in the
spec.
2015-11-02 11:58:24 +10:30
Andrew Bettison
cee5241951 Make HTTP server return 405 if not POST or GET 2015-11-02 11:58:24 +10:30
Andrew Bettison
d9af2ffda4 Improve HTTP server diagnostics
Always log errors before responding with 500 Server Error.  Support more
status code "reason phrases".
2015-11-02 11:58:24 +10:30
Andrew Bettison
bbc7f8fbce Remove terminating semicolons from within macros
The ALARM_STRUCT() and DECLARE_TRIGGER() macros included terminating
semicolons, but their invocation should always be followed by a
semicolon, otherwise etags(1) gets confused, so their included semicolon
was redundant.
2015-11-02 10:11:41 +10:30
Andrew Bettison
a060642fdb Add strbuf_local_buf() macro 2015-11-02 10:11:41 +10:30
Andrew Bettison
27d98a29fa Reimplement strlcpy() using strncpy_nul() 2015-11-02 10:11:41 +10:30
Andrew Bettison
3ab7e04497 Add buf_strncpy_nul(), use in place of strlcpy() 2015-11-02 10:11:41 +10:30
Andrew Bettison
90e02141d1 Reimplement WHY() macro without comma operator
GCC 4.9 and later warn about unused values produced by the comma
operator.  Since the -Wno-unused-value option was removed from the
non-Android Makefile.in, it will not compile the WHY() macro and its
variants, with the -Wall option.

This commit removes the comma operator from the WHY() macro and its
variants, and replaces it with a new inline wrapper function.

This commit also removes the WHYNULL() macro and fixes the three places
it was used.
2015-10-26 15:58:52 +10:30
Jeremy Lakeman
0c275e67ef Clean up compilation warnings 2015-10-19 13:45:57 +10:30
Jeremy Lakeman
3049252c8a Poll netlink socket for interface changes on linux systems 2015-10-12 18:11:44 +10:30
Andrew Bettison
e770998372 Fix empty-string tests on char[]
Caused compiler errors, thanks to Jonas Höchst for reporting.
2015-10-01 07:05:17 +09:30
Andrew Bettison
404cc1476d Improve HTTP Origin header parsing
Parses the separate parts of the URI: scheme, hostname, port.
No longer supports "Origin: null", because that is not in the
spec.
2015-10-01 07:05:17 +09:30
Andrew Bettison
367d54f5f8 Add functions to parse uint16_t 2015-10-01 07:05:17 +09:30