Yadis discovery now passes Accept: application/xrds+xml
[citadel.git] / citadel / modules / openid / serv_openid_rp.c
index 39af689e475a8396cd1114d71e9cee2ae59bf881..576bc22b612c2ef0af0e1754eff3c57d051a881a 100644 (file)
@@ -589,7 +589,7 @@ int fetch_http(StrBuf *url, StrBuf **target_buf)
 {
        StrBuf *ReplyBuf;
        CURL *curl;
-       CURLcode res;
+       CURLcode result;
        char *effective_url = NULL;
        char errmsg[1024] = "";
 
@@ -598,18 +598,15 @@ int fetch_http(StrBuf *url, StrBuf **target_buf)
        if (ReplyBuf == 0) return(-1);
 
        curl = ctdl_openid_curl_easy_init(errmsg);
-       if (!curl) {
-               syslog(LOG_ALERT, "Unable to initialize libcurl.");
-               return(-1);
-       }
+       if (!curl) return(-1);
 
        curl_easy_setopt(curl, CURLOPT_URL, ChrPtr(url));
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, ReplyBuf);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback);
 
-       res = curl_easy_perform(curl);
-       if (res) {
-               syslog(LOG_DEBUG, "libcurl error %d: %s", res, errmsg);
+       result = curl_easy_perform(curl);
+       if (result) {
+               syslog(LOG_DEBUG, "libcurl error %d: %s", result, errmsg);
        }
        curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url);
        StrBufPlain(url, effective_url, -1);
@@ -670,7 +667,6 @@ void xrds_xml_end(void *data, const char *supplied_el) {
 void xrds_xml_chardata(void *data, const XML_Char *s, int len) {
        struct xrds *xrds = (struct xrds *) data;
        
-       syslog(LOG_DEBUG, "%2d xrds_xml_chardata()", xrds->nesting_level);
        /* StrBufAppendBufPlain (xrds->CData, s, len, 0); */
 }
 
@@ -702,24 +698,47 @@ int parse_xrds_document(StrBuf *ReplyBuf) {
 
 
 /*
- * Attempt to perform YADIS discovery.
+ * Attempt to perform Yadis discovery.
  * If successful, returns nonzero and fills the session's claimed ID blah FIXME this comment
- * If YADIS fails, returns 0 and does nothing else.
+ * If Yadis fails, returns 0 and does nothing else.
  */
 int perform_yadis_discovery(StrBuf *YadisURL) {
        int docbytes = (-1);
        StrBuf *ReplyBuf = NULL;
        int r;
+       CURL *curl;
+       CURLcode result;
+       char errmsg[1024] = "";
+       struct curl_slist *my_headers = NULL;
+       /*char *effective_url = NULL;*/
 
        if (YadisURL == NULL) return(0);
        if (StrLength(YadisURL) == 0) return(0);
 
+       ReplyBuf = NewStrBuf ();
+       if (ReplyBuf == 0) return(0);
 
+       curl = ctdl_openid_curl_easy_init(errmsg);
+       if (!curl) return(0);
 
+       curl_easy_setopt(curl, CURLOPT_URL, ChrPtr(YadisURL));
+       curl_easy_setopt(curl, CURLOPT_WRITEDATA, ReplyBuf);
+       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback);
 
+       my_headers = curl_slist_append(my_headers, "Accept:");  /* disable the default Accept: header */
+       my_headers = curl_slist_append(my_headers, "Accept: application/xrds+xml");
+       curl_easy_setopt(curl, CURLOPT_HTTPHEADER, my_headers);
 
+       result = curl_easy_perform(curl);
+       if (result) {
+               syslog(LOG_DEBUG, "libcurl error %d: %s", result, errmsg);
+       }
+       /*curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url);
+       StrBufPlain(YadisURL, effective_url, -1);*/
+       curl_slist_free_all(my_headers);
+       curl_easy_cleanup(curl);
 
-       docbytes = fetch_http(YadisURL, &ReplyBuf);
+       docbytes = StrLength(ReplyBuf);
        if (docbytes < 0) {
                return(0);
        }
@@ -798,7 +817,7 @@ void cmd_oids(char *argbuf) {
         * So we're not even going to bother attempting this mode.
         */
 
-       /* Second we attempt YADIS.
+       /* Second we attempt Yadis.
         * Google uses this so we'd better do our best to implement it.
         */
        int yadis_succeeded = perform_yadis_discovery(oiddata->claimed_id);