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
|
/* tnt/dispatcher.h
* Copyright (C) 2003-2005 Tommi Maekitalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
* NON-INFRINGEMENT. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef TNT_DISPATCHER_H
#define TNT_DISPATCHER_H
#include <cxxtools/thread.h>
#include <tnt/urlmapper.h>
#include <vector>
#include <map>
#include "tnt/regex.h"
namespace tnt
{
// Dispatcher - one per host
class Dispatcher : public Urlmapper
{
public:
class CompidentType : public Compident
{
public:
typedef std::vector<std::string> args_type;
private:
std::string pathinfo;
args_type args;
bool pathinfo_set;
public:
CompidentType()
: pathinfo_set(false)
{ }
explicit CompidentType(const std::string& ident)
: Compident(ident),
pathinfo_set(false)
{ }
bool hasPathInfo() const
{ return pathinfo_set; }
void setPathInfo(const std::string& p)
{ pathinfo = p; pathinfo_set = true; }
void setArgs(const args_type& a)
{ args = a; }
const std::string& getPathInfo() const
{ return pathinfo; }
const args_type& getArgs() const
{ return args; }
args_type& getArgsRef()
{ return args; }
};
private:
typedef std::vector<std::pair<regex, CompidentType> > urlmap_type;
urlmap_type urlmap; // map url to soname/compname
mutable cxxtools::RWLock rwlock;
typedef std::map<std::pair<std::string, urlmap_type::const_iterator>,
CompidentType> urlMapCacheType;
mutable urlMapCacheType urlMapCache;
static urlMapCacheType::size_type maxUrlMapCache;
// don't make this public - it's not threadsafe:
CompidentType mapCompNext(const std::string& compUrl,
urlmap_type::const_iterator& pos) const;
public:
virtual ~Dispatcher() { }
void addUrlMapEntry(const std::string& url, const CompidentType& ci);
Compident mapComp(const std::string& compUrl) const;
static urlMapCacheType::size_type getMaxUrlMapCache()
{ return maxUrlMapCache; }
static void setMaxUrlMapCache(urlMapCacheType::size_type s)
{ maxUrlMapCache = s; }
friend class PosType;
class PosType
{
const Dispatcher& dis;
cxxtools::RdLock lock;
urlmap_type::const_iterator pos;
std::string url;
bool first;
public:
PosType(const Dispatcher& d, const std::string& u)
: dis(d),
lock(dis.rwlock),
pos(dis.urlmap.begin()),
url(u),
first(true)
{ }
CompidentType getNext();
};
};
}
#endif // TNT_DISPATCHER_H
|