aboutsummaryrefslogtreecommitdiff
path: root/include/response.h
blob: e4242a5f7b8d52f53b5f16a6efb2708ab795442c (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
48
49
50
#ifndef _RESPONSE_H_
#define _RESPONSE_H_

enum ResponseStatus {
  SUCCESS = 10,
  CONTENT_UNCHANGED = 11,

  PERMANENT_REDIRECT = 20,
  TEMPORARY_REDIRECT = 21,

  MALFORMED_REQUEST = 30,
  INVALID_REQUEST = 31,
  NOT_AVAILABLE = 32,

  INTERNAL_ERROR = 40,
  NOT_SUPPORTED = 41,
  SLOW_DOWN = 42,

  CLIENT_CERTIFICATE_REQUIRED = 50
};

struct mime_type {
  char *type;
  char *subtype;
};

struct response {
  enum ResponseStatus status;
  char *message;
  struct mime_type type;
  unsigned int length;
  char *hash;
  char *content;
};

/**
 * Parses a string into a `struct response`.
 */
int parse_response(struct response *res, char *s);

/**
 * Deallocates `struct response *res`.
 */
void free_response(struct response *res);

enum ResponseError {
  INVALID_STATUS = -1,
  UNKNOWN_KEY = -2,
};
#endif