summaryrefslogtreecommitdiffabout
path: root/lib/discovery.cc
Side-by-side diff
Diffstat (limited to 'lib/discovery.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/discovery.cc17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/discovery.cc b/lib/discovery.cc
index b7f2db6..5913ad4 100644
--- a/lib/discovery.cc
+++ b/lib/discovery.cc
@@ -1,37 +1,36 @@
#include <list>
#include <opkele/curl.h>
#include <opkele/expat.h>
#include <opkele/uris.h>
#include <opkele/discovery.h>
#include <opkele/exception.h>
#include <opkele/util.h>
#include <opkele/tidy.h>
+#include <opkele/data.h>
#include <opkele/debug.h>
#include "config.h"
#define XRDS_HEADER "X-XRDS-Location"
#define CT_HEADER "Content-Type"
namespace opkele {
using std::list;
using xrd::XRD_t;
using xrd::service_t;
/* TODO: the whole discovery thing needs cleanup and optimization due to
* many changes of concept. */
- static const char *whitespace = " \t\r\n";
- static const char *i_leaders = "=@+$!(";
static const size_t max_html = 16384;
static const struct service_type_t {
const char *uri;
const char *forceid;
} op_service_types[] = {
{ STURI_OPENID20_OP, IDURI_SELECT20 },
{ STURI_OPENID20, 0 },
{ STURI_OPENID11, 0 },
{ STURI_OPENID10, 0 }
};
enum {
@@ -119,36 +118,36 @@ namespace opkele {
idis.clear();
discover_at(idis,xrds_location,xmode_xrd);
}
idis.normalized_id = idis.canonicalized_id = yurl;
service_type_t st;
for(st.uri=*types;*types;st.uri=*(++types))
queue_endpoints(oi,idis,&st);
}
string discover(endpoint_discovery_iterator& oi,const string& identity) {
string rv;
idiscovery_t idis;
- string::size_type fsc = identity.find_first_not_of(whitespace);
+ string::size_type fsc = identity.find_first_not_of(data::_whitespace_chars);
if(fsc==string::npos)
throw bad_input(OPKELE_CP_ "whitespace-only identity");
- string::size_type lsc = identity.find_last_not_of(whitespace);
+ string::size_type lsc = identity.find_last_not_of(data::_whitespace_chars);
assert(lsc!=string::npos);
if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1))
fsc += sizeof("xri://")-1;
if((fsc+1)>=lsc)
throw bad_input(OPKELE_CP_ "not a character of importance in identity");
string id(identity,fsc,lsc-fsc+1);
idis.clear();
- if(strchr(i_leaders,id[0])) {
+ if(strchr(data::_iname_leaders,id[0])) {
/* TODO: further normalize xri identity? Like folding case
* or whatever... */
rv = id;
set<string> cids;
for(const struct service_type_t *st=op_service_types;
st<&op_service_types[sizeof(op_service_types)/sizeof(*op_service_types)];++st) {
idis.clear();
discover_at( idis,
xri_proxy + util::url_encode(id)+
"?_xrd_t="+util::url_encode(st->uri)+
"&_xrd_r=application/xrd%2Bxml"
";sep=true;refs=true",
@@ -486,31 +485,31 @@ namespace opkele {
if(heq)
xrds_location = l;
}else if(is_element(n,"link")) {
string rels;
string href;
for(;*a;a+=2) {
if( !strcasecmp(a[0],"rel") ) {
rels.assign(a[1]);
}else if( !strcasecmp(a[0],"href") ) {
const char *ns = a[1];
for(;*ns && isspace(*ns);++ns);
href.assign(ns);
- string::size_type lns=href.find_last_not_of(whitespace);
+ string::size_type lns=href.find_last_not_of(data::_whitespace_chars);
href.erase(lns+1);
}
}
- for(string::size_type ns=rels.find_first_not_of(whitespace);
- ns!=string::npos; ns=rels.find_first_not_of(whitespace,ns)) {
- string::size_type s = rels.find_first_of(whitespace,ns);
+ for(string::size_type ns=rels.find_first_not_of(data::_whitespace_chars);
+ ns!=string::npos; ns=rels.find_first_not_of(data::_whitespace_chars,ns)) {
+ string::size_type s = rels.find_first_of(data::_whitespace_chars,ns);
string rel;
if(s==string::npos) {
rel.assign(rels,ns,string::npos);
ns = string::npos;
}else{
rel.assign(rels,ns,s-ns);
ns = s;
}
if(rel=="openid.server")
html_openid1.uris.add(-1,xrd::uri_t(href));
else if(rel=="openid.delegate")
html_openid1.local_ids.add(-1,href);