summaryrefslogtreecommitdiff
path: root/core/storage.c
blob: 0d7b80fbef9c18078bd85d2a7c72678521b910c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "../uwsgi.h"

/*

	Storage subsystem: filesystem-like abstraction

	struct uwsgi_storage_engine {
		char *name;
		uint16_t name_len;
		int64_t (*get)(char *, uint16_t, char *, uint64_t, uint64_t, uint64_t);
		int64_t (*set)(char *, uint16_t, char *, uint64_t, uint64_t, uint64_t);
	};

	struct uwsgi_storage {
		char *name;
		uint16_t name_len;
		struct uwsgi_storage_engine *engine;
	};



*/

struct uwsgi_storage* uwsgi_storage_by_name(char *name, uint16_t name_len) {
	if (!name_len) {
		name_len = strlen(name);
	}
	struct uwsgi_storage *s = uwsgi.virtualdisks;
	while(s) {
		if (!uwsgi_strncmp(s->name, s->name_len, name, name_len)) {
			return s;
		}
		s = s->next;
	}

	return NULL;
}

int64_t uwsgi_storage_get(struct uwsgi_storage *storage, char *key, uint16_t key_len, char *out_buf, uint64_t pos, uint64_t size, uint64_t flags) {
	if (!storage->get) return -1;
	return storage->get(key, key_len, out_buf, pos, size, flags);
}

int64_t uwsgi_storage_set(struct uwsgi_storage *storage, char *key, uint16_t key_len, char *in_buf, uint64_t pos, uint64_t size, uint64_t flags) {
	if (!storage->set) return -1;
	return storage->set(key, key_len, out_buf, pos, size, flags);
}