Example #1
0
static int PUT_file(SLNRepoRef const repo, SLNSessionRef const session, HTTPConnectionRef const conn, HTTPMethod const method, strarg_t const URI, HTTPHeadersRef const headers) {
	// TODO: This is pretty much copy and pasted from above.
	if(HTTP_PUT != method) return -1;
	int len = 0;
	str_t algo[SLN_ALGO_SIZE];
	str_t hash[SLN_HASH_SIZE];
	algo[0] = '\0';
	hash[0] = '\0';
	sscanf(URI, "/sln/file/" SLN_ALGO_FMT "/" SLN_HASH_FMT "%n", algo, hash, &len);
	if(!algo[0] || !hash[0]) return -1;
	if('\0' != URI[len] && '?' != URI[len]) return -1;

	str_t *knownURI = SLNFormatURI(algo, hash);
	if(!knownURI) return 500;

	int rc = SLNSessionGetFileInfo(session, knownURI, NULL);
	if(DB_NOTFOUND == rc) {
		int status = accept_sub(session, knownURI, conn, headers);
		FREE(&knownURI);
		return status;
	}
	if(rc < 0) goto cleanup;

	rc = HTTPConnectionDrainMessage(conn);
	if(rc < 0) goto cleanup;

	created(knownURI, conn);

cleanup:
	FREE(&knownURI);
	if(UV_EACCES == rc) return 403;
	if(UV_ECONNABORTED == rc) return 400;
	if(rc < 0) return 500;
	return 0;
}
Example #2
0
static int POST_file(SLNRepoRef const repo, SLNSessionRef const session, HTTPConnectionRef const conn, HTTPMethod const method, strarg_t const URI, HTTPHeadersRef const headers) {
	if(HTTP_POST != method) return -1;
	int len = 0;
	sscanf(URI, "/sln/file%n", &len);
	if(!len) return -1;
	if('\0' != URI[len] && '?' != URI[len]) return -1;

	return accept_sub(session, NULL, conn, headers);
}
Example #3
0
static int POST_file(SLNRepoRef const repo, SLNSessionRef const session, HTTPConnectionRef const conn, HTTPMethod const method, strarg_t const URI, HTTPHeadersRef const headers) {
	if(HTTP_POST != method) return -1;
	if(0 != uripathcmp("/sln/file", URI, NULL)) return -1;

	return accept_sub(session, NULL, conn, headers);
}