summaryrefslogtreecommitdiff
path: root/src/disfluid-cache-request.h
blob: 8d6310cd727ec3e12e6e79ae178b1ab2fd6dfd27 (about) (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
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
#ifndef DISFLUID_CACHE_REQUEST_INCLUDED
# define DISFLUID_CACHE_REQUEST_INCLUDED

struct disfluid_cache_request;

static inline int cache_request_init (struct disfluid_cache_request *request);

static inline
  void cache_request_clear (struct disfluid_cache_request *request);

static inline
  int cache_request_prepare (struct disfluid_cache_request *request,
			     const char *method, const char *host,
			     const char *path, const char *version);

static inline
  const char *cache_request_method (const struct disfluid_cache_request
				    *request);

static inline
  const char *cache_request_path (const struct disfluid_cache_request
				  *request);

static inline
  const char *cache_request_host (const struct disfluid_cache_request
				  *request);

static inline
  const char *cache_request_version (const struct disfluid_cache_request
				     *request);

struct disfluid_cache_request
{
  char *method;
  char *host;
  char *path;
  char *version;
};

static inline int
cache_request_init (struct disfluid_cache_request *request)
{
  request->method = NULL;
  request->host = NULL;
  request->path = NULL;
  request->version = NULL;
  return 0;
}

static inline void
cache_request_clear (struct disfluid_cache_request *request)
{
  free (request->method);
  free (request->host);
  free (request->path);
  free (request->version);
  request->method = NULL;
  request->host = NULL;
  request->path = NULL;
  request->version = NULL;
}

static inline int
cache_request_prepare (struct disfluid_cache_request *request,
		       const char *method, const char *host, const char *path,
		       const char *version)
{
  char *my_method = malloc (strlen (method) + 1);
  char *my_host = malloc (strlen (host) + 1);
  char *my_path = malloc (strlen (path) + 1);
  char *my_version = malloc (strlen (version) + 1);
  if (my_method && my_host && my_path && my_version)
    {
      strcpy (my_method, method);
      strcpy (my_host, host);
      strcpy (my_path, path);
      strcpy (my_version, version);
      free (request->method);
      free (request->host);
      free (request->path);
      free (request->version);
      request->method = my_method;
      request->host = my_host;
      request->path = my_path;
      request->version = my_version;
      return 0;
    }
  else
    {
      free (my_method);
      free (my_host);
      free (my_path);
      free (my_version);
      return 1;
    }
}

static inline const char *
cache_request_method (const struct disfluid_cache_request *request)
{
  return request->method;
}

static inline const char *
cache_request_path (const struct disfluid_cache_request *request)
{
  return request->path;
}

static inline const char *
cache_request_host (const struct disfluid_cache_request *request)
{
  return request->host;
}

static inline const char *
cache_request_version (const struct disfluid_cache_request *request)
{
  return request->version;
}

#endif /* DISFLUID_CACHE_REQUEST_INCLUDED */