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