• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 12595591960

03 Jan 2025 09:27AM UTC coverage: 62.774% (+2.5%) from 60.245%
12595591960

Pull #15008

github

web-flow
Merge c2a2749d3 into 788f396a7
Pull Request #15008: Do not follow CNAME records for ANY or CNAME queries

30393 of 78644 branches covered (38.65%)

Branch coverage included in aggregate %.

105822 of 138350 relevant lines covered (76.49%)

4613078.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.71
/ext/yahttp/yahttp/router.hpp
1
#pragma once
2
/* @file 
3
 * @brief Defines router class and support structures
4
 */
5
#if __cplusplus >= 201103L
6
#include <functional>
7
#include <tuple>
8
#define HAVE_CPP_FUNC_PTR
9
#define IGNORE std::ignore
10
namespace funcptr = std;
11
#else
12
#ifdef HAVE_BOOST
13
#include <boost/function.hpp>
14
#include <boost/tuple/tuple.hpp>
15
#define IGNORE boost::tuples::ignore
16
namespace funcptr = boost;
17
#define HAVE_CPP_FUNC_PTR
18
#else
19
#warning "You need to configure with boost or have C++11 capable compiler for router"
20
#endif
21
#endif
22

23
#ifdef HAVE_CPP_FUNC_PTR
24
#include <vector>
25
#include <utility>
26

27
namespace YaHTTP {
28
  enum RoutingResult {
29
    RouteFound = 1,
30
    RouteNotFound = 0,
31
    RouteNoMethod = -1,
32
  };
33

34
  typedef funcptr::function <void(Request* req, Response* resp)> THandlerFunction; //!< Handler function pointer 
35
  typedef funcptr::tuple<std::string, std::string, THandlerFunction, std::string> TRoute; //!< Route tuple (method, urlmask, handler, name)
36
  typedef std::vector<TRoute> TRouteList; //!< List of routes in order of evaluation
37
  typedef funcptr::tuple<int,int> TDelim;
38

39
  /*! Implements simple router.
40

41
This class implements a router for masked urls. The URL mask syntax is as of follows
42

43
/&lt;masked&gt;/url&lt;number&gt;/&lt;hi&gt;.&lt;format&gt;
44

45
You can use &lt;*param&gt; to denote that everything will be matched and consumed into the parameter, including slash (/). Use &lt;*&gt; to denote that URL 
46
is consumed but not stored. Note that only path is matched, scheme, host and url parameters are ignored. 
47
   */
48
  class Router {
49
  private:
50
    Router() {}; 
157✔
51
    static Router router; //<! Singleton instance of Router
52
  public:
53
    void map(const std::string& method, const std::string& url, THandlerFunction handler, const std::string& name); //<! Instance method for mapping urls
54
    RoutingResult route(Request *req, THandlerFunction& handler); //<! Instance method for performing routing
55
    void printRoutes(std::ostream &os); //<! Instance method for printing routes
56
    std::pair<std::string, std::string> urlFor(const std::string &name, const strstr_map_t& arguments); //<! Instance method for generating paths
57
    static bool match(const std::string& route, const URL& requrl, std::map<std::string, TDelim>& params); //<! Instance method for matching a route
58

59
/*! Map an URL.
60
If method is left empty, it will match any method. Name is also optional, but needed if you want to find it for making URLs
61
*/
62
    static void Map(const std::string& method, const std::string& url, THandlerFunction handler, const std::string& name = "") { router.map(method, url, std::move(handler), name); };
544✔
63
    static void Get(const std::string& url, THandlerFunction handler, const std::string& name = "") { router.map("GET", url, std::move(handler), name); }; //<! Helper for mapping GET
×
64
    static void Post(const std::string& url, THandlerFunction handler, const std::string& name = "") { router.map("POST", url, std::move(handler), name); }; //<! Helper for mapping POST
×
65
    static void Put(const std::string& url, THandlerFunction handler, const std::string& name = "") { router.map("PUT", url, std::move(handler), name); }; //<! Helper for mapping PUT
×
66
    static void Patch(const std::string& url, THandlerFunction handler, const std::string& name = "") { router.map("PATCH", url, std::move(handler), name); }; //<! Helper for mapping PATCH
×
67
    static void Delete(const std::string& url, THandlerFunction handler, const std::string& name = "") { router.map("DELETE", url, std::move(handler), name); }; //<! Helper for mapping DELETE
×
68
    static void Any(const std::string& url, THandlerFunction handler, const std::string& name = "") { router.map("", url, std::move(handler), name); }; //<! Helper for mapping any method
×
69

70
    static bool Match(const std::string& route, const URL& requrl, std::map<std::string, TDelim>& params) { return router.match(route, requrl, params); };
99✔
71
    static RoutingResult Route(Request *req, THandlerFunction& handler) { return router.route(req, handler); }; //<! Performs routing based on req->url.path, returns RouteFound if route is found and method matches, RouteNoMethod if route is seen but method did match, and RouteNotFound if not found.
143✔
72
    static void PrintRoutes(std::ostream &os) { router.printRoutes(os); }; //<! Prints all known routes to given output stream
×
73

74
    static std::pair<std::string, std::string> URLFor(const std::string &name, const strstr_map_t& arguments) { return router.urlFor(name,arguments); }; //<! Generates url from named route and arguments. Missing arguments are assumed empty
×
75
    static const TRouteList& GetRoutes() { return router.routes; } //<! Reference to route list
3✔
76
    static void Clear() { router.routes.clear(); } //<! Clear all routes
×
77

78
    TRouteList routes; //<! Instance variable for routes
79
  };
80
};
81
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc