Mercurial > openid
comparison src/c/openid.c @ 42:1068de1623a5
Announce when provider only supports old OpenID version
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 12 Jun 2011 18:12:47 -0400 |
parents | a77f4cd1336d |
children | 00c8f43be8b7 |
comparison
equal
deleted
inserted
replaced
41:a77f4cd1336d | 42:1068de1623a5 |
---|---|
70 | 70 |
71 typedef struct { | 71 typedef struct { |
72 uw_context ctx; | 72 uw_context ctx; |
73 uw_OpenidFfi_discovery *d; | 73 uw_OpenidFfi_discovery *d; |
74 xrds_mode mode; | 74 xrds_mode mode; |
75 int cur_priority, max_priority; | 75 int cur_priority, max_priority, found_old_version; |
76 } endpoint; | 76 } endpoint; |
77 | 77 |
78 static void XMLCALL startElement(void *userData, const XML_Char *name, const XML_Char **atts) { | 78 static void XMLCALL startElement(void *userData, const XML_Char *name, const XML_Char **atts) { |
79 endpoint *ep = userData; | 79 endpoint *ep = userData; |
80 | 80 |
87 | 87 |
88 for (attp = atts; *attp; attp += 2) { | 88 for (attp = atts; *attp; attp += 2) { |
89 if (!strcmp(attp[0], "rel") && !strcmp(attp[1], "openid2.provider")) { | 89 if (!strcmp(attp[0], "rel") && !strcmp(attp[1], "openid2.provider")) { |
90 found = 1; | 90 found = 1; |
91 break; | 91 break; |
92 } else if (!strcmp(attp[0], "rel") && !strcmp(attp[1], "openid.server")) { | |
93 ep->found_old_version = 1; | |
94 return; | |
92 } | 95 } |
93 } | 96 } |
94 | 97 |
95 if (found) { | 98 if (found) { |
96 for (attp = atts; *attp; attp += 2) { | 99 for (attp = atts; *attp; attp += 2) { |
180 uw_OpenidFfi_discovery *uw_OpenidFfi_discover(uw_context ctx, uw_Basis_string id) { | 183 uw_OpenidFfi_discovery *uw_OpenidFfi_discover(uw_context ctx, uw_Basis_string id) { |
181 char *s; | 184 char *s; |
182 CURL *c = curl(ctx); | 185 CURL *c = curl(ctx); |
183 curl_discovery_data cd = {}; | 186 curl_discovery_data cd = {}; |
184 uw_OpenidFfi_discovery *dy = uw_malloc(ctx, sizeof(uw_OpenidFfi_discovery)); | 187 uw_OpenidFfi_discovery *dy = uw_malloc(ctx, sizeof(uw_OpenidFfi_discovery)); |
185 endpoint ep = {ctx, dy, NONE, 0, INT_MAX}; | 188 endpoint ep = {ctx, dy, NONE, 0, INT_MAX, 0}; |
186 CURLcode code; | 189 CURLcode code; |
187 struct curl_slist *headers = NULL; | 190 struct curl_slist *headers = NULL; |
188 | 191 |
189 dy->endpoint = dy->localId = NULL; | 192 dy->endpoint = dy->localId = NULL; |
190 | 193 |
220 | 223 |
221 if (code) { | 224 if (code) { |
222 uw_Basis_debug(ctx, "CURL error:"); | 225 uw_Basis_debug(ctx, "CURL error:"); |
223 uw_Basis_debug(ctx, (char*)curl_easy_strerror(code)); | 226 uw_Basis_debug(ctx, (char*)curl_easy_strerror(code)); |
224 } | 227 } |
225 else if (!dy->endpoint) | 228 else if (!dy->endpoint) { |
226 uw_Basis_debug(ctx, "Couldn't parse endpoint from page"); | 229 if (ep.found_old_version) |
230 uw_Basis_debug(ctx, "Provider doesn't support OpenID version 2.0 but does support an older version"); | |
231 else | |
232 uw_Basis_debug(ctx, "Couldn't parse endpoint from page"); | |
233 } | |
227 | 234 |
228 if (code || !dy->endpoint) | 235 if (code || !dy->endpoint) |
229 return NULL; | 236 return NULL; |
230 else | 237 else |
231 return dy; | 238 return dy; |