comparison src/c/openid.c @ 4:2d409aff8800

Received an OpenID authentication response, but haven't checked it yet
author Adam Chlipala <adam@chlipala.net>
date Sun, 26 Dec 2010 17:19:52 -0500
parents f59083771ee2
children 99496175078b
comparison
equal deleted inserted replaced
3:f59083771ee2 4:2d409aff8800
20 uw_Basis_string uw_OpenidFfi_localId(uw_context ctx, uw_OpenidFfi_discovery d) { 20 uw_Basis_string uw_OpenidFfi_localId(uw_context ctx, uw_OpenidFfi_discovery d) {
21 return d->localId; 21 return d->localId;
22 } 22 }
23 23
24 uw_unit uw_OpenidFfi_init(uw_context ctx) { 24 uw_unit uw_OpenidFfi_init(uw_context ctx) {
25
26
25 curl_global_init(CURL_GLOBAL_ALL); 27 curl_global_init(CURL_GLOBAL_ALL);
26 28
27 return uw_unit_v; 29 return uw_unit_v;
28 } 30 }
29 31
175 return size * nmemb; 177 return size * nmemb;
176 } 178 }
177 179
178 const char curl_failure[] = "error\0Error fetching URL"; 180 const char curl_failure[] = "error\0Error fetching URL";
179 181
180 uw_OpenidFfi_outputs uw_OpenidFfi_indirect(uw_context ctx, uw_Basis_string url, uw_OpenidFfi_inputs inps) { 182 uw_OpenidFfi_outputs uw_OpenidFfi_direct(uw_context ctx, uw_Basis_string url, uw_OpenidFfi_inputs inps) {
181 uw_buffer *buf = uw_malloc(ctx, sizeof(uw_buffer)); 183 uw_buffer *buf = uw_malloc(ctx, sizeof(uw_buffer));
182 CURL *c = curl(ctx); 184 CURL *c = curl(ctx);
183 CURLcode code; 185 CURLcode code;
184 186
185 uw_buffer_init(BUF_MAX, buf, BUF_INIT); 187 uw_buffer_init(BUF_MAX, buf, BUF_INIT);
223 } 225 }
224 } 226 }
225 227
226 return buf; 228 return buf;
227 } 229 }
230
231 static uw_Basis_string deurl(uw_context ctx, uw_Basis_string s) {
232 uw_Basis_string r = uw_malloc(ctx, strlen(s)), s2 = r;
233
234 for (; *s; ++s) {
235 if (s[0] == '%' && s[1] && s[2]) {
236 unsigned u;
237
238 sscanf(s+1, "%02x", &u);
239 *s2++ = u;
240 s += 2;
241 } else
242 *s2++ = *s;
243 }
244
245 *s2 = 0;
246 return r;
247 }
248
249 uw_OpenidFfi_outputs uw_OpenidFfi_indirect(uw_context ctx, uw_Basis_string fields) {
250 uw_OpenidFfi_outputs b = malloc(sizeof(uw_buffer));
251
252 uw_buffer_init(BUF_MAX, b, BUF_INIT);
253
254 while (*fields) {
255 char *equal = strchr(fields, '='), *and, *s;
256
257 if (!equal)
258 break;
259
260 *equal = 0;
261 s = deurl(ctx, fields);
262 uw_buffer_append(b, s, strlen(s));
263 uw_buffer_append(b, "", 1);
264
265 and = strchr(equal+1, '&');
266 if (and) {
267 *and = 0;
268 fields = and+1;
269 } else
270 fields = and = strchr(equal+1, 0);
271 s = deurl(ctx, equal+1);
272 uw_buffer_append(b, s, strlen(s));
273 uw_buffer_append(b, "", 1);
274 }
275
276 uw_buffer_append(b, "", 1);
277 return b;
278 }