1 /*------------------------------------------------------------------------------
2 Name: SessionName.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment:
6 ------------------------------------------------------------------------------*/
7
8 #ifndef XMLBLASTER_UTIL_SessionName_H
9 #define XMLBLASTER_UTIL_SessionName_H
10
11 #include <util/xmlBlasterDef.h>
12 #include <string>
13 #include <util/ReferenceCounterBase.h>
14 #include <util/ReferenceHolder.h>
15 #include <util/StringTrim.h>
16
17 namespace org { namespace xmlBlaster { namespace util {
18
19 class Dll_Export SessionName : public org::xmlBlaster::util::ReferenceCounterBase
20 {
21 private:
22 const std::string ME;
23 std::string sessionId_;
24 std::string clusterNodeId_;
25 std::string subjectId_;
26 long pubSessionId_;
27 org::xmlBlaster::util::Global& global_;
28 bool useSessionMarker_; // In future default to true, remove after Version 2.0
29
30 void copy(const SessionName& data);
31
32 void initialize(const std::string& absoluteName, const std::string& defaultUserName, long publicSessionId);
33
34 public:
35 /**
36 * When using this constructor you can let it assign the defaults by passing an empty std::string as the
37 * 'absoluteName' argument, or you force the SessionName to set the SessionName to what you specify in the
38 * 'absoluteName' argument.
39 * @param absoluteName the sessionId to assign to this SessionName. You can either pass an absolute name,
40 * or a relative name or an empty std::string.
41 */
42 SessionName(org::xmlBlaster::util::Global& global, const std::string& absoluteName="");
43
44 /**
45 * @defaultUserName is the name to use as a default for the user (the subjectId). It is stronger than the
46 * properties set but if an empty std::string is used, then the default name is taken from the 'user' property.
47 * This is just a default and as such it is weaker than the property 'session.name'. In other words, even
48 * if defaultUserName is not empty, it will be overwritten by eventual setting of the property 'session.name'.
49 *
50 * @publicSessionId is the public sessionId to be used. Note that this is just a suggestion, so if you
51 * have the 'session.name' property set, it will overwrite this. If the publicSessionId is '0', then it
52 * is omitted (the server will assign one for you).
53 */
54 SessionName(org::xmlBlaster::util::Global& global, const std::string& defaultUserName, long publicSessionId);
55 SessionName(const SessionName& data);
56 SessionName& operator =(const SessionName& data);
57
58 virtual ~SessionName();
59
60 /**
61 * Sets the absolute name. It checks if it really is an absolute name,
62 * i.e. if it contains the well known structure '/node/....' it parses it,
63 * otherwise it leaves it untouched (i.e. it will not parse it).
64 */
65
66 /**
67 * Sets the absolute name. Note that you can overwrite the nodeId here. It returns 'true' if the
68 * name was absolute, 'false' otherwise.
69 */
70 void setAbsoluteName(/*const std::string nodeId="",*/ const std::string& name);
71 std::string getRelativeName() const;
72 std::string getRelativeName(bool forceSessionMarker) const;
73 std::string getAbsoluteName() const;
74 std::string getClusterNodeId() const;
75 void setClusterNodeId(const std::string& clusterNodeId);
76 std::string getSubjectId() const;
77 void setSubjectId(const std::string& subjectId);
78 long getPubSessionId() const;
79 void setPubSessionId(const long pubSessionId);
80
81 // remove with version 2.0
82 bool useSessionMarker() const { return useSessionMarker_; }
83
84 std::string getSecretSessionId() const;
85 void setSecretSessionId(const std::string& sessionId);
86 std::string toXml(const std::string& extraOffset="") const;
87 };
88
89 typedef org::xmlBlaster::util::ReferenceHolder<SessionName> SessionNameRef;
90
91 }}} // namespaces
92
93 #endif
syntax highlighted by Code2HTML, v. 0.9.1