static void _test_str(unit_state *state, int expected) { rcint *a = rcint_alloc(expected); return_unless(, a); rcstr *got = rc2str(a); return_unless(, got); rc_release(a); static char buffer[16]; snprintf(buffer, sizeof(buffer), "%d", expected); assert_eq_str(state, buffer, rcstr_str(got)); rc_release(got); }
static rpmRC rpmhkpReadKeys(const char ** keyids) { const char ** kip; rpmRC rc; int ec = 0; for (kip = keyids; *kip; kip++) { if (rpmIsVerbose()) fprintf(stderr, "=============== %s\n", *kip); rc = rpmhkpValidate(NULL, *kip); /* XXX 0 on success */ if (!rpmIsVerbose()) fprintf(stdout, "%-8s\t%s\n", rc2str(rc), *kip); if (rc) ec++; } return ec; }
void send_partial_error(const char *message, rc_ty rc) { char *reason = *msg_get_reason() ? strdup(msg_get_reason()) : NULL; msg_set_reason("%s: %s", message, reason ? reason : rc2str(rc)); free(reason); send_error_helper(',', 500, msg_get_reason()); }
void send_partial_error(const char *message, rc_ty rc) { msg_set_reason("%s: %s", message, rc2str(rc)); send_error_helper(',', 500, rc2str(rc)); }
static void create_or_extend_tempfile(const sx_hashfs_volume_t *vol, const char *filename, int extending) { const struct jparse_actions acts = { JPACTS_INT64( JPACT(cb_newfile_size, JPKEY("fileSize")), JPACT(cb_newfile_seq, JPKEY("extendSeq")) ), JPACTS_STRING( JPACT(cb_newfile_block, JPKEY("fileData"), JPANYITM), JPACT(cb_newfile_addmeta, JPKEY("fileMeta"), JPANYKEY) ), JPACTS_NULL( JPACT(cb_newfile_delmeta, JPKEY("fileMeta"), JPANYKEY) ) }; struct cb_newfile_ctx yctx; hash_presence_ctx_t ctx; const char *token; jparse_t *J; int len; rc_ty s; yctx.filesize = -1; yctx.seq = -1; yctx.rc = EINVAL; J = sxi_jparse_create(&acts, &yctx, 0); if(!J) { sx_hashfs_putfile_end(hashfs); quit_errmsg(503, "Cannot create JSON parser"); } while((len = get_body_chunk(hashbuf, sizeof(hashbuf))) > 0) if(sxi_jparse_digest(J, hashbuf, len)) break; if(len || sxi_jparse_done(J)) { send_error(rc2http(yctx.rc), sxi_jparse_geterr(J)); sx_hashfs_putfile_end(hashfs); sxi_jparse_destroy(J); return; } sxi_jparse_destroy(J); auth_complete(); quit_unless_authed(); s = sx_hashfs_putfile_gettoken(hashfs, user, yctx.filesize, yctx.seq, &token, hash_presence_callback, &ctx); if (s != OK) { sx_hashfs_putfile_end(hashfs); if(!*msg_get_reason()) msg_set_reason("Cannot obtain upload token: %s", rc2str(s)); quit_errmsg((s == ENOSPC) ? 413 : rc2http(s), msg_get_reason()); } CGI_PRINTF("Content-type: application/json\r\n\r\n{\"uploadToken\":"); json_send_qstring(extending ? path : token); CGI_PUTS(",\"uploadData\":{"); ctx.h = hashfs; ctx.comma = 0; while((s = sx_hashfs_putfile_getblock(hashfs)) == OK) { /* Nothing to do here, API does a little bit of work at a time by design * We can stick keepalives in here if we ever need to */ } sx_hashfs_putfile_end(hashfs); CGI_PUTS("}"); if(s != ITER_NO_MORE) { quit_itererr("Failed to send file blocks", s); } CGI_PUTS("}"); }