summaryrefslogtreecommitdiffabout
path: root/include/opkele
authorMichael Krelin <hacker@klever.net>2008-03-03 15:57:15 (UTC)
committer Michael Krelin <hacker@klever.net>2008-03-03 15:57:15 (UTC)
commitc28479399ef0fedeb6bf14ec665bb4c427654356 (patch) (unidiff)
treeff1dfe84a54f717772bdb6233a5cbfedb57788d1 /include/opkele
parent0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be (diff)
downloadlibopkele-c28479399ef0fedeb6bf14ec665bb4c427654356.zip
libopkele-c28479399ef0fedeb6bf14ec665bb4c427654356.tar.gz
libopkele-c28479399ef0fedeb6bf14ec665bb4c427654356.tar.bz2
introduced base_message class as a base for basic_openid_message
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'include/opkele') (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/types.h42
1 files changed, 28 insertions, 14 deletions
diff --git a/include/opkele/types.h b/include/opkele/types.h
index ffb9afb..64f165c 100644
--- a/include/opkele/types.h
+++ b/include/opkele/types.h
@@ -73,144 +73,158 @@ namespace opkele {
73 */ 73 */
74 class association_t { 74 class association_t {
75 public: 75 public:
76 76
77 virtual ~association_t() { } 77 virtual ~association_t() { }
78 78
79 /** 79 /**
80 * retrieve the server with which association was established. 80 * retrieve the server with which association was established.
81 * @return server name 81 * @return server name
82 */ 82 */
83 virtual string server() const = 0; 83 virtual string server() const = 0;
84 /** 84 /**
85 * retrieve the association handle. 85 * retrieve the association handle.
86 * @return handle 86 * @return handle
87 */ 87 */
88 virtual string handle() const = 0; 88 virtual string handle() const = 0;
89 /** 89 /**
90 * retrieve the association type. 90 * retrieve the association type.
91 * @return association type 91 * @return association type
92 */ 92 */
93 virtual string assoc_type() const = 0; 93 virtual string assoc_type() const = 0;
94 /** 94 /**
95 * retrieve the association secret. 95 * retrieve the association secret.
96 * @return association secret 96 * @return association secret
97 */ 97 */
98 virtual secret_t secret() const = 0; 98 virtual secret_t secret() const = 0;
99 /** 99 /**
100 * retrieve the number of seconds the association expires in. 100 * retrieve the number of seconds the association expires in.
101 * @return seconds till expiration 101 * @return seconds till expiration
102 */ 102 */
103 virtual int expires_in() const = 0; 103 virtual int expires_in() const = 0;
104 /** 104 /**
105 * check whether the association is stateless. 105 * check whether the association is stateless.
106 * @return true if stateless 106 * @return true if stateless
107 */ 107 */
108 virtual bool stateless() const = 0; 108 virtual bool stateless() const = 0;
109 /** 109 /**
110 * check whether the association is expired. 110 * check whether the association is expired.
111 * @return true if expired 111 * @return true if expired
112 */ 112 */
113 virtual bool is_expired() const = 0; 113 virtual bool is_expired() const = 0;
114 }; 114 };
115 115
116 /** 116 /**
117 * the shared_ptr<> for association_t object type 117 * the shared_ptr<> for association_t object type
118 */ 118 */
119 typedef tr1mem::shared_ptr<association_t> assoc_t; 119 typedef tr1mem::shared_ptr<association_t> assoc_t;
120 120
121 class basic_openid_message { 121 class basic_message {
122 public: 122 public:
123 typedef list<string> fields_t; 123 typedef list<string> fields_t;
124 typedef util::forward_iterator_proxy< 124 typedef util::forward_iterator_proxy<
125 string,const string&,const string* 125 string,const string&,const string*
126 > fields_iterator; 126 > fields_iterator;
127 127
128 basic_openid_message() { } 128 basic_message() { }
129 virtual ~basic_openid_message() { } 129 virtual ~basic_message() { }
130 basic_openid_message(const basic_openid_message& x); 130 basic_message(const basic_message& x);
131 void copy_to(basic_openid_message& x) const; 131 void copy_to(basic_message& x) const;
132 void append_to(basic_openid_message& x) const; 132 void append_to(basic_message& x) const;
133 133
134 virtual bool has_field(const string& n) const = 0; 134 virtual bool has_field(const string& n) const = 0;
135 virtual const string& get_field(const string& n) const = 0; 135 virtual const string& get_field(const string& n) const = 0;
136 136
137 virtual bool has_ns(const string& uri) const;
138 virtual string get_ns(const string& uri) const;
139
140 virtual fields_iterator fields_begin() const = 0; 137 virtual fields_iterator fields_begin() const = 0;
141 virtual fields_iterator fields_end() const = 0; 138 virtual fields_iterator fields_end() const = 0;
142 139
143 virtual string append_query(const string& url,const char *pfx="openid.") const; 140 virtual string append_query(const string& url,const char *pfx=0) const;
144 virtual string query_string(const char *pfx="openid.") const; 141 virtual string query_string(const char *pfx=0) const;
145
146 142
147 virtual void reset_fields(); 143 virtual void reset_fields();
148 virtual void set_field(const string& n,const string& v); 144 virtual void set_field(const string& n,const string& v);
149 virtual void reset_field(const string& n); 145 virtual void reset_field(const string& n);
150 146
147 };
148
149 class basic_openid_message : public basic_message {
150 public:
151 typedef list<string> fields_t;
152 typedef util::forward_iterator_proxy<
153 string,const string&,const string*
154 > fields_iterator;
155
156 basic_openid_message() { }
157 basic_openid_message(const basic_openid_message& x);
158
159 virtual bool has_ns(const string& uri) const;
160 virtual string get_ns(const string& uri) const;
161
162 virtual string append_query(const string& url,const char *pfx="openid.") const {
163 return basic_message::append_query(url,pfx); }
164 virtual string query_string(const char *pfx="openid.") const {
165 return basic_message::query_string(pfx); }
166
151 virtual void from_keyvalues(const string& kv); 167 virtual void from_keyvalues(const string& kv);
152 virtual void to_keyvalues(ostream& o) const; 168 virtual void to_keyvalues(ostream& o) const;
153 169
154 virtual void to_htmlhiddens(ostream& o,const char* pfx=0) const; 170 virtual void to_htmlhiddens(ostream& o,const char* pfx=0) const;
155 171
156 void add_to_signed(const string& fields); 172 void add_to_signed(const string& fields);
157 string find_ns(const string& uri,const char *pfx) const; 173 string find_ns(const string& uri,const char *pfx) const;
158 string allocate_ns(const string& uri,const char *pfx); 174 string allocate_ns(const string& uri,const char *pfx);
159 }; 175 };
160 176
161 class openid_message_t : public basic_openid_message, public map<string,string> { 177 class openid_message_t : public basic_openid_message, public map<string,string> {
162 public: 178 public:
163 openid_message_t() { } 179 openid_message_t() { }
164 openid_message_t(const basic_openid_message& x) 180 openid_message_t(const basic_openid_message& x)
165 : basic_openid_message(x) { } 181 : basic_openid_message(x) { }
166 182
167 void copy_to(basic_openid_message& x) const;
168
169 bool has_field(const string& n) const; 183 bool has_field(const string& n) const;
170 const string& get_field(const string& n) const; 184 const string& get_field(const string& n) const;
171 virtual fields_iterator fields_begin() const; 185 virtual fields_iterator fields_begin() const;
172 virtual fields_iterator fields_end() const; 186 virtual fields_iterator fields_end() const;
173 187
174 void reset_fields(); 188 void reset_fields();
175 void set_field(const string& n,const string& v); 189 void set_field(const string& n,const string& v);
176 void reset_field(const string& n); 190 void reset_field(const string& n);
177 }; 191 };
178 192
179 /** 193 /**
180 * request/response parameters map 194 * request/response parameters map
181 */ 195 */
182 class params_t : public openid_message_t { 196 class params_t : public openid_message_t {
183 public: 197 public:
184 198
185 /** 199 /**
186 * check whether the parameter is present. 200 * check whether the parameter is present.
187 * @param n the parameter name 201 * @param n the parameter name
188 * @return true if yes 202 * @return true if yes
189 */ 203 */
190 bool has_param(const string& n) const { 204 bool has_param(const string& n) const {
191 return has_field(n); } 205 return has_field(n); }
192 /** 206 /**
193 * retrieve the parameter (const version) 207 * retrieve the parameter (const version)
194 * @param n the parameter name 208 * @param n the parameter name
195 * @return the parameter value 209 * @return the parameter value
196 * @throw failed_lookup if there is no such parameter 210 * @throw failed_lookup if there is no such parameter
197 */ 211 */
198 const string& get_param(const string& n) const { 212 const string& get_param(const string& n) const {
199 return get_field(n); } 213 return get_field(n); }
200 214
201 /** 215 /**
202 * parse the OpenID key/value data. 216 * parse the OpenID key/value data.
203 * @param kv the OpenID key/value data 217 * @param kv the OpenID key/value data
204 */ 218 */
205 void parse_keyvalues(const string& kv) { 219 void parse_keyvalues(const string& kv) {
206 from_keyvalues(kv); } 220 from_keyvalues(kv); }
207 221
208 string append_query(const string& url,const char *prefix="openid.") const; 222 string append_query(const string& url,const char *prefix="openid.") const;
209 223
210 }; 224 };
211 225
212 struct openid_endpoint_t { 226 struct openid_endpoint_t {
213 string uri; 227 string uri;
214 string claimed_id; 228 string claimed_id;
215 string local_id; 229 string local_id;
216 230