-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathshared.h
151 lines (120 loc) · 4.24 KB
/
shared.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef WEBDAV_SHARED_H
#define WEBDAV_SHARED_H
#define _FILE_OFFSET_BITS 64
#include <sys/file.h>
#include <sys/socket.h>
#include <stdarg.h>
#define RAP_CONTROL_SOCKET 3
#define BUFFER_SIZE 40960
#define MAX_VARABLY_DEFINED_ARRAY 40960
typedef enum RapConstant {
RAP_REQUEST_AUTHENTICATE = 1,
// sent by startProcessingRequest to start processing an HTTP method
RAP_REQUEST_GET,
RAP_REQUEST_PUT,
RAP_REQUEST_PROPFIND,
RAP_REQUEST_PROPPATCH,
RAP_REQUEST_LOCK,
RAP_REQUEST_MKCOL,
RAP_REQUEST_MOVE,
RAP_REQUEST_COPY,
RAP_REQUEST_DELETE,
// sent by rap, processed by finishProcessingRequest
RAP_INTERIM_RESPOND_LOCK,
RAP_INTERIM_RESPOND_RELOCK,
// sent by finishProcessingRequest to complete processing a request
RAP_COMPLETE_REQUEST_LOCK,
// sent by rap once a request has completed - deliberately HTTP response codes
RAP_RESPOND_CONTINUE = 100,
RAP_RESPOND_OK = 200,
RAP_RESPOND_CREATED = 201,
RAP_RESPOND_OK_NO_CONTENT = 204,
RAP_RESPOND_MULTISTATUS = 207,
RAP_RESPOND_BAD_CLIENT_REQUEST = 400,
RAP_RESPOND_AUTH_FAILLED = 401,
RAP_RESPOND_ACCESS_DENIED = 403,
RAP_RESPOND_NOT_FOUND = 404,
RAP_RESPOND_CONFLICT = 409,
RAP_RESPOND_URI_TOO_LARGE = 414,
RAP_RESPOND_LOCKED = 423,
RAP_RESPOND_HEADER_TOO_LARGE = 431,
RAP_RESPOND_INTERNAL_ERROR = 500,
RAP_RESPOND_INSUFFICIENT_STORAGE = 507
} RapConstant;
// Auth Request
#define RAP_PARAM_AUTH_USER 0
#define RAP_PARAM_AUTH_PASSWORD 1
#define RAP_PARAM_AUTH_RHOST 2
// Generic Requet
#define RAP_PARAM_REQUEST_LOCK 0
#define RAP_PARAM_REQUEST_FILE 1
#define RAP_PARAM_REQUEST_DEPTH 2
#define RAP_PARAM_REQUEST_TARGET 2
// Generic Response
#define RAP_PARAM_RESPONSE_DATE 0
#define RAP_PARAM_RESPONSE_MIME 1
#define RAP_PARAM_RESPONSE_LOCATION 2
// Lock interim response
#define RAP_PARAM_LOCK_LOCATION 0
#define RAP_PARAM_LOCK_TYPE 1
#define RAP_PARAM_LOCK_TOKEN 1
#define RAP_PARAM_LOCK_TIMEOUT 2
// Error responses
#define RAP_PARAM_ERROR_LOCATION 0
#define RAP_PARAM_ERROR_REASON 1
#define RAP_PARAM_ERROR_DAV_REASON 2
#define PIPE_READ 0
#define PIPE_WRITE 1
#define PARENT_SOCKET 0
#define CHILD_SOCKET 1
#define LOCK_TOKEN_URN_PREFIX "urn:uuid:"
#define LOCK_TOKEN_PREFIX "<urn:uuid:"
#define LOCK_TOKEN_PREFIX_LENGTH (sizeof(LOCK_TOKEN_PREFIX) - 1)
#define LOCK_TOKEN_SUFFIX ">"
#define LOCK_TOKEN_LENGTH (LOCK_TOKEN_PREFIX_LENGTH + sizeof(LockToken) + sizeof(LOCK_TOKEN_SUFFIX))
typedef enum LockType {
LOCK_TYPE_NONE = 0,
LOCK_TYPE_SHARED = LOCK_SH,
LOCK_TYPE_EXCLUSIVE = LOCK_EX
} LockType;
typedef struct LockProvisions {
LockType source;
LockType target;
} LockProvisions;
/*
* #define QUOTE(name) #name
* #define STR(macro) QUOTE(macro)
*
*/
void * mallocSafe(size_t size);
void * reallocSafe(void * mem, size_t newSize);
//#define freeSafe(foo) /*stdLog("%p free(%s)", foo, QUOTE(foo) );*/ free(foo)
void freeSafe(void * mem);
char * copyString(const char * string);
size_t timeNow(char * buf, size_t bufSize);
size_t getWebDate(time_t rawtime, char * buf, size_t bufSize);
size_t getLocalDate(time_t rawtime, char * buf, size_t bufSize);
void stdLog(const char * str, ...);
void stdLogError(int errorNumber, const char * str, ...);
#define MAX_MESSAGE_PARAMS 3
#define INCOMING_BUFFER_SIZE 4096
typedef struct iovec MessageParam;
#define NULL_PARAM ( ( MessageParam ) { .iov_base = NULL, .iov_len = 0} )
typedef struct Message {
enum RapConstant mID;
int fd;
int paramCount;
MessageParam params[MAX_MESSAGE_PARAMS];
} Message;
ssize_t sendMessage(int sock, Message * message);
ssize_t recvMessage(int sock, Message * message, char * incomingBuffer, size_t incomingBufferSize);
ssize_t sendRecvMessage(int sock, Message * message, char * incomingBuffer, size_t incomingBufferSize);
#define makeMessageParam(primative,size) ((MessageParam) { .iov_base = (void *) primative, .iov_len = size })
#define toMessageParam(primative) makeMessageParam(&(primative), sizeof(primative))
#define messageParamTo(type,param) (*((type *) (param).iov_base))
char * messageParamToString(MessageParam * iovec);
MessageParam stringToMessageParam(const char * string);
#define messageParamSize(param) ((param).iov_len)
int lockToUser(const char * user, const char * chrootDir);
char * loadFileToBuffer(const char * file, size_t * size);
#endif