some html parsing for link rel tags
authorArt Cancro <ajc@citadel.org>
Fri, 16 May 2008 15:00:02 +0000 (15:00 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 16 May 2008 15:00:02 +0000 (15:00 +0000)
webcit/auth.c
webcit/httpfetch.c

index 15c769d6110fcfcb4637e9af835a837505069fe1..620f9869e94b34e9ef6654b54894475d562a8e5b 100644 (file)
@@ -259,6 +259,37 @@ void do_login(void)
 }
 
 
+/*
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+<head>
+  <link rel="openid.server" href="http://uncensored.citadel.org/~ajc/MyID.config.php">
+  <link rel="openid.delegate" href="http://uncensored.citadel.org/~ajc/MyID.config.php">
+  <title>IGnatius T Foobar</title>
+</head>
+<body text="#00ff00" bgcolor="#000000" link="#ffff00">
+
+*/
+
+
+
+/* 
+ * Locate a <link> tag and, given its 'rel=' parameter, return its 'href' parameter
+ */
+void extract_link(char *target_buf, int target_size, char *rel, char *source_buf)
+{
+       char *ptr = source_buf;
+
+       while (ptr = bmstrcasestr(ptr, "<link"), ptr != NULL) {
+
+       lprintf(9, "Got something\n", ptr);             // FIXME
+
+       ++ptr;
+       }
+
+
+}
 
 
 /* 
@@ -279,11 +310,19 @@ void do_openid_login(void)
                return;
        }
        if (havebstr("login_action")) {
-
-               i = fetch_http(bstr("openid_url"), buf, sizeof buf);
-               lprintf(9, "fetched %d bytes (FIXME do something with it)\n", i);
-
-
+               i = fetch_http(bstr("openid_url"), buf, sizeof buf - 1);
+               buf[sizeof buf - 1] = 0;
+               if (i > 0) {
+                       char openid_server[1024];
+                       char openid_delegate[1024];
+                       
+                       extract_link(openid_server, sizeof openid_server, "openid.server", buf);
+                       extract_link(openid_delegate, sizeof openid_delegate, "openid.delegate", buf);
+
+                       lprintf(9, "  Server: %s\n", openid_server);
+                       lprintf(9, "Delegate: %s\n", openid_delegate);
+                       // FIXME finish this
+               }
        }
        if (WC->logged_in) {
                if (WC->need_regi) {
index aed837f7fe49cbf554da210d82d194e2d3c1f1cd..e4c48af7242e3e0150fa519db89c32cb30015ef2 100644 (file)
@@ -332,13 +332,11 @@ int fetch_http(char *url, char *target_buf, int maxbytes)
 
        /* First try curl */
        snprintf(cmd, sizeof cmd, "curl -L %s </dev/null 2>/dev/null", url);
-       lprintf(9, "%s\n", cmd);
        fp = popen(cmd, "r");
 
        /* Then try wget */
        if (!fp) {
                snprintf(cmd, sizeof cmd, "wget -q -O - %s </dev/null 2>/dev/null", url);
-               lprintf(9, "%s\n", cmd);
                fp = popen(cmd, "r");
        }
 
@@ -350,6 +348,7 @@ int fetch_http(char *url, char *target_buf, int maxbytes)
                        }
                }
                pclose(fp);
+               return bytes_received;
        }
 
        /* Fall back to the built-in mini handler */