GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/webapi/uri_map.h Lines: 5 5 100.0 %
Date: 2018-10-07 00:43:30 Branches: 1 2 50.0 %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System
3
 */
4
5
#ifndef CVMFS_WEBAPI_URI_MAP_H_
6
#define CVMFS_WEBAPI_URI_MAP_H_
7
8
#include <stdint.h>
9
10
#include <string>
11
#include <vector>
12
13
#include "pathspec/pathspec.h"
14
15
class FastCgi;
16
17
/**
18
 * Captures the request path and the HTTP request method of an HTTP request,
19
 * which is enough information to route the request to a handler.
20
 */
21
class WebRequest {
22
 public:
23
  enum Verb {
24
    kGet,
25
    kPut,
26
    kPost,
27
    kDelete,
28
    kUnknown,
29
  };
30
31
  static WebRequest *CreateFromCgiHeaders(FastCgi *fcgi);
32
33
  Verb verb() const { return verb_; }
34
  std::string uri() const { return uri_; }
35
36
 private:
37
  WebRequest();
38
39
  Verb verb_;
40
  std::string uri_;
41
};
42
43
44
/**
45
 * Abstract base class for a request handler.  Requests are identified by a
46
 * 64bit id.  Every request translates into one OnRequest call and one or
47
 * multiple OnData calls.
48
 */
49
class UriHandler {
50
 public:
51
84
  explicit UriHandler(FastCgi *fcgi) : fcgi_(fcgi) { }
52
56
  virtual ~UriHandler() { }
53
  virtual void OnData(const uint64_t id,
54
                      unsigned char *buf, unsigned length) = 0;
55
56
 protected:
57
  FastCgi *fcgi_;
58
};
59
60
61
/**
62
 * Registeres handlers for URI path specifications and returns handler for
63
 * concrete requests.  Matching of requests is done in the order of
64
 * specification registration.
65
 */
66
84
class UriMap {
67
 public:
68
  void Register(const std::string &uri_spec, UriHandler *handler);
69
  UriHandler *Route(const std::string &uri);
70
71
 private:
72
812
  struct Match {
73
140
    Match(const Pathspec &s, UriHandler *h) : uri_spec(s), handler(h) { }
74
    Pathspec uri_spec;
75
    UriHandler *handler;
76
  };
77
78
  std::vector<Match> rules_;
79
};
80
81
#endif  // CVMFS_WEBAPI_URI_MAP_H_