diff src/c/openid.c @ 2:b757dc2bd2f6

Discovery returns a record
author Adam Chlipala <adam@chlipala.net>
date Sun, 26 Dec 2010 13:28:06 -0500
parents c230e6da3ff6
children f59083771ee2
line wrap: on
line diff
--- 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 <openid.h>
 
+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;
+  }
 }