Skip to content

Commit

Permalink
Change return type of rhizome_fill_manifest()
Browse files Browse the repository at this point in the history
To help improve diagnostic feedback through APIs
  • Loading branch information
quixotique committed Mar 16, 2015
1 parent 016bb32 commit 4d5cded
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
6 changes: 3 additions & 3 deletions meshms.c
Expand Up @@ -69,8 +69,8 @@ static enum meshms_status get_my_conversation_bundle(const sid_t *my_sidp, rhizo
if (m->haveSecret == NEW_BUNDLE_ID) {
rhizome_manifest_set_service(m, RHIZOME_SERVICE_FILE);
rhizome_manifest_set_name(m, "");
if (rhizome_fill_manifest(m, NULL, my_sidp) == -1)
return WHY("Invalid manifest");
if (rhizome_fill_manifest(m, NULL, my_sidp) != NULL)
return WHY("Invalid conversation manifest");
if (config.debug.meshms) {
char secret[RHIZOME_BUNDLE_KEY_STRLEN + 1];
rhizome_bytes_to_hex_upper(m->cryptoSignSecret, secret, RHIZOME_BUNDLE_KEY_BYTES);
Expand Down Expand Up @@ -205,7 +205,7 @@ static int create_ply(const sid_t *my_sid, struct meshms_conversations *conv, rh
rhizome_manifest_set_recipient(m, &conv->them);
rhizome_manifest_set_filesize(m, 0);
rhizome_manifest_set_tail(m, 0);
if (rhizome_fill_manifest(m, NULL, my_sid))
if (rhizome_fill_manifest(m, NULL, my_sid) != NULL)
return -1;
assert(m->haveSecret);
assert(m->payloadEncryption == PAYLOAD_ENCRYPTED);
Expand Down
2 changes: 1 addition & 1 deletion rhizome.h
Expand Up @@ -429,7 +429,7 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key);
int rhizome_bundle_import_files(rhizome_manifest *m, rhizome_manifest **m_out, const char *manifest_path, const char *filepath);

int rhizome_manifest_set_name_from_path(rhizome_manifest *m, const char *filepath);
int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t *authorSidp);
const char * rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t *authorSidp);

int rhizome_apply_bundle_secret(rhizome_manifest *, const rhizome_bk_t *);
int rhizome_manifest_add_bundle_key(rhizome_manifest *);
Expand Down
21 changes: 15 additions & 6 deletions rhizome_bundle.c
Expand Up @@ -1476,9 +1476,14 @@ int rhizome_manifest_set_name_from_path(rhizome_manifest *m, const char *filepat
* - use the given author SID, or the 'sender' if present, as the author
* - create an ID if there is none, otherwise authenticate the existing one
* - if service is file, then use the payload file's basename for "name"
*
* Return NULL if successful, otherwise a pointer to a static text string describing the reason for
* the failure.
*/
int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t *authorSidp)
const char * rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t *authorSidp)
{
const char *reason = NULL;

/* Set version of manifest from current time if not already set. */
if (m->version == 0)
rhizome_manifest_set_version(m, gettime_ms());
Expand Down Expand Up @@ -1507,8 +1512,10 @@ int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t
}
if (config.debug.rhizome)
DEBUG("creating new bundle");
if (rhizome_manifest_createid(m) == -1)
return WHY("Could not bind manifest to an ID");
if (rhizome_manifest_createid(m) == -1) {
WHY(reason = "Could not bind manifest to an ID");
return reason;
}
// fall through to set the BK field...
case NEW_BUNDLE_ID:
valid_haveSecret = 1;
Expand All @@ -1533,8 +1540,10 @@ int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t

/* Service field must already be set.
*/
if (m->service == NULL)
return WHYF("missing 'service'");
if (m->service == NULL) {
WHYF(reason = "Missing 'service' field");
return reason;
}
if (config.debug.rhizome)
DEBUGF("manifest service=%s", m->service);

Expand Down Expand Up @@ -1571,7 +1580,7 @@ int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t
rhizome_manifest_set_crypt(m, PAYLOAD_ENCRYPTED);
}

return 0;
return NULL;
}

/* Work out the authorship status of the bundle without performing any cryptographic checks.
Expand Down
5 changes: 3 additions & 2 deletions rhizome_direct_http.c
Expand Up @@ -249,10 +249,11 @@ static int rhizome_direct_addfile_end(struct http_request *hr)
if (m->service == NULL)
rhizome_manifest_set_service(m, RHIZOME_SERVICE_FILE);
const sid_t *author = is_sid_t_any(config.rhizome.api.addfile.default_author) ? NULL : &config.rhizome.api.addfile.default_author;
if (rhizome_fill_manifest(m, r->u.direct_import.data_file_name, author)) {
const char *reason = rhizome_fill_manifest(m, r->u.direct_import.data_file_name, author);
if (reason) {
rhizome_manifest_free(m);
rhizome_direct_clear_temporary_files(r);
http_request_simple_response(&r->http, 500, "Internal Error: Could not fill manifest");
http_request_simple_response(&r->http, 500, alloca_sprintf(-1, "Internal Error: %s", reason));
return 0;
}
rhizome_manifest_set_crypt(m, PAYLOAD_CLEAR);
Expand Down
5 changes: 3 additions & 2 deletions rhizome_restful.c
Expand Up @@ -560,8 +560,9 @@ static int insert_mime_part_end(struct http_request *hr)
}
if (r->manifest->service == NULL)
rhizome_manifest_set_service(r->manifest, RHIZOME_SERVICE_FILE);
if (rhizome_fill_manifest(r->manifest, NULL, r->u.insert.received_author ? &r->u.insert.author: NULL) == -1) {
WHY("rhizome_fill_manifest() failed");
const char *reason = rhizome_fill_manifest(r->manifest, NULL, r->u.insert.received_author ? &r->u.insert.author: NULL);
if (reason != NULL) {
http_request_simple_response(&r->http, 500, alloca_sprintf(-1, "Internal error: %s", reason));
return 500;
}
assert(r->manifest != NULL);
Expand Down

0 comments on commit 4d5cded

Please sign in to comment.