summaryrefslogtreecommitdiffabout
path: root/include
authorMichael Krelin <hacker@klever.net>2007-01-11 22:36:22 (UTC)
committer Michael Krelin <hacker@klever.net>2007-01-11 22:36:22 (UTC)
commit709e399023109847ff747b87dca371078fd95868 (patch) (unidiff)
treeb0f4ee058de83b1b59309e9d38d1612fb6fa7092 /include
parentf6011d4bdd5a78414fba54c0985817fa8d4283e6 (diff)
downloadlibopkele-709e399023109847ff747b87dca371078fd95868.zip
libopkele-709e399023109847ff747b87dca371078fd95868.tar.gz
libopkele-709e399023109847ff747b87dca371078fd95868.tar.bz2
Simple Registration extension
Diffstat (limited to 'include') (more/less context) (ignore whitespace changes)
-rw-r--r--include/Makefile.am3
-rw-r--r--include/opkele/sreg.h206
2 files changed, 208 insertions, 1 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 72931eb..4b9b02a 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,12 +1,13 @@
1nobase_include_HEADERS = \ 1nobase_include_HEADERS = \
2 opkele/acconfig.h \ 2 opkele/acconfig.h \
3 opkele/opkele-config.h \ 3 opkele/opkele-config.h \
4 opkele/types.h \ 4 opkele/types.h \
5 opkele/association.h \ 5 opkele/association.h \
6 opkele/exception.h \ 6 opkele/exception.h \
7 opkele/server.h \ 7 opkele/server.h \
8 opkele/consumer.h \ 8 opkele/consumer.h \
9 opkele/extension.h 9 opkele/extension.h \
10 opkele/sreg.h
10EXTRA_DIST = \ 11EXTRA_DIST = \
11 opkele/data.h \ 12 opkele/data.h \
12 opkele/util.h 13 opkele/util.h
diff --git a/include/opkele/sreg.h b/include/opkele/sreg.h
new file mode 100644
index 0000000..6713ef7
--- a/dev/null
+++ b/include/opkele/sreg.h
@@ -0,0 +1,206 @@
1#ifndef __OPKELE_SREG_H
2#define __OPKELE_SREG_H
3
4/**
5 * @file
6 * @brief Simple registration extension
7 */
8
9#include <opkele/extension.h>
10
11/**
12 * @brief the main opkele namespace
13 */
14namespace opkele {
15 using std::map;
16
17 /**
18 * OpenID simple registration extension implementation
19 * http://openid.net/specs/openid-simple-registration-extension-1_0.html
20 */
21 class sreg_t : public extension_t {
22 public:
23 /**
24 * sreg fields enumeration
25 */
26 enum fieldbit_t {
27 /**
28 * Any UTF-8 string that the End User wants to use as a nickname.
29 */
30 field_nickname = 1,
31 /**
32 * The email address of the End User as specified in section 3.4.1 of [RFC2822]
33 */
34 field_email = 2,
35 /**
36 * UTF-8 string free text representation of the End User's full name.
37 */
38 field_fullname = 4,
39 /**
40 * The End User's date of birth as YYYY-MM-DD. Any values whose
41 * representation uses fewer than the specified number of
42 * digits should be zero-padded. The length of this value MUST
43 * always be 10. If the End User user does not want to reveal
44 * any particular component of this value, it MUST be set to
45 * zero.
46 *
47 * For instance, if a End User wants to specify that his date
48 * of birth is in 1980, but not the month or day, the value
49 * returned SHALL be "1980-00-00".
50 */
51 field_dob = 8,
52 /**
53 * Alias to field_dob
54 */
55 field_birthdate = field_dob,
56 /**
57 * The End User's gender, "M" for male, "F" for female.
58 */
59 field_gender = 16,
60 /**
61 * Alias to field_gender
62 */
63 field_sex = field_gender,
64 /**
65 * UTF-8 string free text that SHOULD conform to the End User's
66 * country's postal system.
67 */
68 field_postcode = 32,
69 /**
70 * The End User's country of residence as specified by ISO3166
71 */
72 field_country = 64,
73 /**
74 * End User's preferred language as specified by ISO639
75 */
76 field_language = 128,
77 /**
78 * ASCII string from TimeZone database
79 *
80 * For example, "Europe/Paris" or "America/Los_Angeles".
81 */
82 field_timezone = 256,
83 /**
84 * All fields bits combined
85 */
86 fields_ALL = 511,
87 /**
88 * No fields
89 */
90 fields_NONE = 0
91 };
92 /**
93 * Bitmask for fields which, if absent from the response, will
94 * prevent the Consumer from completing the registration without
95 * End User interation.
96 */
97 long fields_required;
98 /**
99 * Bitmask for fields that will be used by the Consumer, but whose
100 * absence will not prevent the registration from completing.
101 */
102 long fields_optional;
103 /**
104 * A URL which the Consumer provides to give the End User a place
105 * to read about the how the profile data will be used. The
106 * Identity Provider SHOULD display this URL to the End User if it
107 * is given.
108 */
109 string policy_url;
110
111 /**
112 * Bitmask for fields present in response
113 */
114 long has_fields;
115 /**
116 * Container type for response fields values
117 */
118 typedef map<fieldbit_t,string> response_t;
119 /**
120 * Response contents
121 */
122 response_t response;
123
124 /**
125 * Fields bitmask to send in response
126 */
127 long fields_response;
128
129 /**
130 * Consumer constructor.
131 * @param fr required fields
132 * @see fields_required
133 * @param fo optional fields
134 * @see fields_optional
135 * @param pu policy url
136 * @see policy_url
137 */
138 sreg_t(long fr=fields_NONE,long fo=fields_NONE,const string& pu="")
139 : fields_required(fr), fields_optional(fo), policy_url(pu), has_fields(0) { }
140
141 /**
142 * Implementation of consumer's checkid hook
143 */
144 virtual void checkid_hook(params_t& p,const string& identity);
145 /**
146 * Implementation of consumer's id_res hook
147 */
148 virtual void id_res_hook(const params_t& p,const params_t& sp,const string& identity);
149 /**
150 * Implementation of server's checkid_hook
151 */
152 virtual void checkid_hook(const params_t& pin,params_t& pout);
153
154 /**
155 * Check and see if we have value for some particular field.
156 * @param fb field in question
157 * @see fieldbit_t
158 * @return true if the value is available
159 */
160 bool has_field(fieldbit_t fb) const { return has_fields&fb; }
161
162 /**
163 * Retrieve the value for a field.
164 * @param fb field in question
165 * @see fieldbit_t
166 * @return field value
167 * @throw failed_lookup if no data avaialble
168 */
169 const string& get_field(fieldbit_t fb) const;
170
171 /**
172 * Set the value for a field.
173 * @param fb field in question
174 * @see fieldbit_t
175 * @param fv field value
176 */
177 void set_field(fieldbit_t fb,const string& fv);
178
179 /**
180 * Remove the value for a field.
181 * @param fb field in question
182 * @see fieldbit_t
183 */
184 void reset_field(fieldbit_t fb);
185
186 /**
187 * Reset field data
188 */
189 void clear();
190
191 /**
192 * Function called after parsing sreg request to set up response
193 * fields. The default implementation tries to send as much fields
194 * as we have. The function is supposed to set the data and
195 * fields_response.
196 * @see fields_response
197 * @param pin input request parameters with "openid." prefix
198 * @param pout output request parameters without "openid." prefix.
199 * @see checkid_hook(const params_t&,params_t&)
200 */
201 virtual void setup_response(const params_t& pin,params_t& pout);
202
203 };
204}
205
206#endif /* __OPKELE_SREG_H */