Commit Graph

3445 Commits

Author SHA1 Message Date
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
Andrew Bettison
f73cd77185 Change arg of ctype functions from char to int
Consistent with functions defined in <ctype>; now all can be used
as a predicate function with the type int (*)(int).
2015-10-01 07:05:17 +09:30
Jeremy Lakeman
2fdd23e864 Do not add name and number to seeded keyring entry 2015-09-28 12:04:13 +09:30
Jeremy Lakeman
41d416977f Deprecate java command line api to keyring commands 2015-09-28 12:03:39 +09:30
Jeremy Lakeman
75df3bd4ec Format network addresses using posix API 2015-09-28 11:58:48 +09:30
Jeremy Lakeman
79e8a94792 Add route_link.h 2015-09-28 11:58:48 +09:30
Andrew Bettison
a276fc9d28 Remove Rhizome enabled test from Keyring REST API 2015-09-28 09:56:15 +09:30
Andrew Bettison
6123503c15 Improve Rhizome HTTP status codes
Also improve some reason phrases and test them
2015-09-21 18:43:24 +09:30
Andrew Bettison
96055e6b6c Fix test failure in HTTP POST /rhizome/import
Introduced in edc8aba
2015-09-21 18:43:24 +09:30
Andrew Bettison
3c18b7a3d9 Add missing header dependencies to Makefile 2015-09-21 12:45:03 +09:30
Andrew Bettison
487fe462b2 Add "extern" to some array decls in str.h 2015-09-21 12:30:36 +09:30
Andrew Bettison
7635e6b71b Add Keyring Java API (incomplete) with tests
keyringListIdentities()
keyringSetDidName()
2015-08-31 19:16:30 +09:30
Andrew Bettison
0e783c6b73 Fix malformed HTTP output of JSON fields 2015-08-31 19:16:30 +09:30
Andrew Bettison
714ea63190 Change JSON response of GET HTTP /restful/keyring/...
Return "sid", "did" and "name" fields inside their own "identity"
object
2015-08-31 19:16:30 +09:30
Andrew Bettison
e956749727 Move utility functions from 'rhizomejava' test to testdefs_java.sh 2015-08-31 19:16:30 +09:30