From ada95ee2af5113c3f9a1c51780124310ac2fce77 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 25 Nov 2011 13:31:42 -0500 Subject: [PATCH] Begin separating YADIS handling from XRDS parsing --- citadel/modules/openid/serv_openid_rp.c | 67 ++++++++++++++++--------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/citadel/modules/openid/serv_openid_rp.c b/citadel/modules/openid/serv_openid_rp.c index 74fc0a5d9..aa1ba633e 100644 --- a/citadel/modules/openid/serv_openid_rp.c +++ b/citadel/modules/openid/serv_openid_rp.c @@ -601,32 +601,69 @@ int fetch_http(StrBuf *url, StrBuf **target_buf) struct xrds { - int foo; + int nesting_level; + int in_xrd; }; void xrds_xml_start(void *data, const char *supplied_el, const char **attr) { struct xrds *xrds = (struct xrds *) data; - syslog(LOG_DEBUG, "xrds_xml_start(%s) data=0x%x", supplied_el, (int)xrds); + ++xrds->nesting_level; + + if (!strcasecmp(supplied_el, "XRD")) { + ++xrds->in_xrd; + syslog(LOG_DEBUG, "*** XRD DOCUMENT BEGIN ***"); + } } void xrds_xml_end(void *data, const char *supplied_el) { struct xrds *xrds = (struct xrds *) data; - syslog(LOG_DEBUG, "xrds_xml_end(%s) data=0x%x", supplied_el, (int)xrds); + --xrds->nesting_level; + + if (!strcasecmp(supplied_el, "XRD")) { + --xrds->in_xrd; + syslog(LOG_DEBUG, "*** XRD DOCUMENT END ***"); + } } void xrds_xml_chardata(void *data, const XML_Char *s, int len) { struct xrds *xrds = (struct xrds *) data; - syslog(LOG_DEBUG, "xrds_xml_chardata() data=0x%x", (int)xrds); + syslog(LOG_DEBUG, "%2d xrds_xml_chardata()", xrds->nesting_level); /* StrBufAppendBufPlain (xrds->CData, s, len, 0); */ } +/* + * Parse an XRDS document. + * If OpenID stuff is discovered, populate FIXME something and return nonzero + * If nothing useful happened, return 0. + */ +int parse_xrds_document(StrBuf *ReplyBuf) { + struct xrds xrds; + + memset(&xrds, 0, sizeof (struct xrds)); + XML_Parser xp = XML_ParserCreate(NULL); + if (xp) { + XML_SetUserData(xp, &xrds); + XML_SetElementHandler(xp, xrds_xml_start, xrds_xml_end); + XML_SetCharacterDataHandler(xp, xrds_xml_chardata); + XML_Parse(xp, ChrPtr(ReplyBuf), StrLength(ReplyBuf), 0); + XML_Parse(xp, "", 0, 1); + XML_ParserFree(xp); + } + else { + syslog(LOG_ALERT, "Cannot create XML parser"); + } + + return(0); +} + + /* * Attempt to perform YADIS discovery. * If successful, returns nonzero and fills the session's claimed ID blah FIXME this comment @@ -635,9 +672,8 @@ void xrds_xml_chardata(void *data, const XML_Char *s, int len) { int perform_yadis_discovery(StrBuf *YadisURL) { int docbytes = (-1); StrBuf *ReplyBuf = NULL; - struct xrds xrds; + int r; - memset(&xrds, 0, sizeof (struct xrds)); docbytes = fetch_http(YadisURL, &ReplyBuf); if (docbytes < 0) { @@ -648,24 +684,9 @@ int perform_yadis_discovery(StrBuf *YadisURL) { return(0); } - /* If we get to this point, something was retrieved. - * Feed it to the XML parser to see if it's an XRDS document. - */ - XML_Parser xp = XML_ParserCreateNS(NULL, ':'); - if (xp) { - XML_SetUserData(xp, &xrds); - XML_SetElementHandler(xp, xrds_xml_start, xrds_xml_end); - XML_SetCharacterDataHandler(xp, xrds_xml_chardata); - XML_Parse(xp, ChrPtr(ReplyBuf), docbytes, 0); - XML_Parse(xp, "", 0, 1); - XML_ParserFree(xp); - } - else { - syslog(LOG_ALERT, "Cannot create XML parser"); - } - + r = parse_xrds_document(ReplyBuf); FreeStrBuf(&ReplyBuf); - return(0); + return(r); } -- 2.30.2