File: storage.c

package info (click to toggle)
uwsgi 2.0.31-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,624 kB
  • sloc: ansic: 87,072; python: 7,010; cpp: 1,133; java: 708; perl: 678; sh: 585; ruby: 555; makefile: 148; xml: 130; cs: 121; objc: 37; php: 28; erlang: 20; javascript: 11
file content (47 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download | duplicates (9)
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);
}