# HG changeset patch # User Adam Chlipala # Date 1293388086 18000 # Node ID b757dc2bd2f66aeb100674b6019f991df9dff439 # Parent c230e6da3ff63a3864131a1e232a97feb10aea5a Discovery returns a record diff -r c230e6da3ff6 -r b757dc2bd2f6 include/openid.h --- a/include/openid.h Sun Dec 26 13:10:36 2010 -0500 +++ b/include/openid.h Sun Dec 26 13:28:06 2010 -0500 @@ -1,4 +1,9 @@ #include +typedef struct uw_OpenidFfi_discovery *uw_OpenidFfi_discovery; + +uw_Basis_string uw_OpenidFfi_endpoint(uw_context, uw_OpenidFfi_discovery); +uw_Basis_string uw_OpenidFfi_localId(uw_context, uw_OpenidFfi_discovery); + uw_unit uw_OpenidFfi_init(uw_context); -uw_Basis_string uw_OpenidFfi_discover(uw_context, uw_Basis_string id); +uw_OpenidFfi_discovery *uw_OpenidFfi_discover(uw_context, uw_Basis_string id); diff -r c230e6da3ff6 -r b757dc2bd2f6 src/c/openid.c --- a/src/c/openid.c Sun Dec 26 13:10:36 2010 -0500 +++ b/src/c/openid.c Sun Dec 26 13:28:06 2010 -0500 @@ -6,6 +6,18 @@ #include +struct uw_OpenidFfi_discovery { + uw_Basis_string endpoint, localId; +}; + +uw_Basis_string uw_OpenidFfi_endpoint(uw_context ctx, uw_OpenidFfi_discovery d) { + return d->endpoint; +} + +uw_Basis_string uw_OpenidFfi_localId(uw_context ctx, uw_OpenidFfi_discovery d) { + return d->localId; +} + uw_unit uw_OpenidFfi_init(uw_context ctx) { curl_global_init(CURL_GLOBAL_ALL); @@ -26,7 +38,7 @@ typedef struct { uw_context ctx; - char *result; + uw_OpenidFfi_discovery d; } endpoint; static void XMLCALL startElement(void *userData, const XML_Char *name, const XML_Char **atts) { @@ -46,7 +58,7 @@ if (found) { for (attp = atts; *attp; attp += 2) { if (!strcmp(attp[0], "href")) { - ep->result = uw_strdup(ep->ctx, attp[1]); + ep->d->endpoint = uw_strdup(ep->ctx, attp[1]); return; } } @@ -71,13 +83,16 @@ return size * nmemb; } -uw_Basis_string uw_OpenidFfi_discover(uw_context ctx, uw_Basis_string id) { +uw_OpenidFfi_discovery *uw_OpenidFfi_discover(uw_context ctx, uw_Basis_string id) { char *s; CURL *c = curl(ctx); curl_data cd = {}; - endpoint ep = {ctx}; + uw_OpenidFfi_discovery dy = uw_malloc(ctx, sizeof(struct uw_OpenidFfi_discovery)); + endpoint ep = {ctx, dy}; CURLcode code; + dy->endpoint = dy->localId = NULL; + if (!strchr(id, ':')) { id = uw_Basis_strcat(ctx, "http://", id); if ((s = strchr(id, '#')) != NULL) @@ -101,8 +116,11 @@ code = curl_easy_perform(c); uw_pop_cleanup(ctx); - if (code) + if (code || !ep.d->endpoint) return NULL; - else - return ep.result; + else { + uw_OpenidFfi_discovery *dyp = malloc(sizeof(uw_OpenidFfi_discovery)); + *dyp = ep.d; + return dyp; + } } diff -r c230e6da3ff6 -r b757dc2bd2f6 src/ur/lib.urp --- a/src/ur/lib.urp Sun Dec 26 13:10:36 2010 -0500 +++ b/src/ur/lib.urp Sun Dec 26 13:28:06 2010 -0500 @@ -4,4 +4,5 @@ effectful OpenidFfi.init effectful OpenidFfi.discover +$/option openid diff -r c230e6da3ff6 -r b757dc2bd2f6 src/ur/openid.ur --- a/src/ur/openid.ur Sun Dec 26 13:10:36 2010 -0500 +++ b/src/ur/openid.ur Sun Dec 26 13:28:06 2010 -0500 @@ -1,3 +1,6 @@ task initialize = fn () => OpenidFfi.init -val discover = OpenidFfi.discover +fun discover s = + r <- OpenidFfi.discover s; + return (Option.mp (fn r => {Endpoint = OpenidFfi.endpoint r, + LocalId = OpenidFfi.localId r}) r) diff -r c230e6da3ff6 -r b757dc2bd2f6 src/ur/openid.urs --- a/src/ur/openid.urs Sun Dec 26 13:10:36 2010 -0500 +++ b/src/ur/openid.urs Sun Dec 26 13:28:06 2010 -0500 @@ -1,1 +1,1 @@ -val discover : string -> transaction (option string) +val discover : string -> transaction (option {Endpoint : string, LocalId : option string}) diff -r c230e6da3ff6 -r b757dc2bd2f6 src/ur/openidFfi.urs --- a/src/ur/openidFfi.urs Sun Dec 26 13:10:36 2010 -0500 +++ b/src/ur/openidFfi.urs Sun Dec 26 13:28:06 2010 -0500 @@ -1,2 +1,6 @@ val init : transaction {} -val discover : string -> transaction (option string) + +type discovery +val discover : string -> transaction (option discovery) +val endpoint : discovery -> string +val localId : discovery -> option string diff -r c230e6da3ff6 -r b757dc2bd2f6 tests/test.ur --- a/tests/test.ur Sun Dec 26 13:10:36 2010 -0500 +++ b/tests/test.ur Sun Dec 26 13:28:06 2010 -0500 @@ -1,8 +1,11 @@ fun discover r = - code <- Openid.discover r.Id; - return - Code: {[code]} - + dy <- Openid.discover r.Id; + case dy of + None => return No dice + | Some dy => return + Endpoint: {[dy.Endpoint]}
+ Local ID: {[dy.LocalId]}
+
fun main () = return