-rw-r--r-- | include/opkele/discovery.h | 1 | ||||
-rw-r--r-- | lib/discovery.cc | 2 | ||||
-rw-r--r-- | test/idiscover.cc | 1 |
3 files changed, 4 insertions, 0 deletions
diff --git a/include/opkele/discovery.h b/include/opkele/discovery.h index 5d7129b..7865fb2 100644 --- a/include/opkele/discovery.h +++ b/include/opkele/discovery.h | |||
@@ -3,24 +3,25 @@ | |||
3 | 3 | ||
4 | #include <string> | 4 | #include <string> |
5 | #include <opkele/types.h> | 5 | #include <opkele/types.h> |
6 | 6 | ||
7 | namespace opkele { | 7 | namespace opkele { |
8 | using std::string; | 8 | using std::string; |
9 | 9 | ||
10 | struct idiscovery_t; | 10 | struct idiscovery_t; |
11 | 11 | ||
12 | void idiscover(idiscovery_t& result,const string& identity); | 12 | void idiscover(idiscovery_t& result,const string& identity); |
13 | 13 | ||
14 | struct idiscovery_t { | 14 | struct idiscovery_t { |
15 | bool xri_identity; | ||
15 | string normalized_id; | 16 | string normalized_id; |
16 | string canonicalized_id; | 17 | string canonicalized_id; |
17 | xrd::XRD_t xrd; | 18 | xrd::XRD_t xrd; |
18 | 19 | ||
19 | idiscovery_t(const string& i) { | 20 | idiscovery_t(const string& i) { |
20 | idiscover(*this,i); | 21 | idiscover(*this,i); |
21 | } | 22 | } |
22 | idiscovery_t(const char *i) { | 23 | idiscovery_t(const char *i) { |
23 | idiscover(*this,i); | 24 | idiscover(*this,i); |
24 | } | 25 | } |
25 | 26 | ||
26 | void clear() { | 27 | void clear() { |
diff --git a/lib/discovery.cc b/lib/discovery.cc index a35ce32..1f23ff1 100644 --- a/lib/discovery.cc +++ b/lib/discovery.cc | |||
@@ -86,35 +86,37 @@ namespace opkele { | |||
86 | string::size_type fsc = identity.find_first_not_of(whitespace); | 86 | string::size_type fsc = identity.find_first_not_of(whitespace); |
87 | if(fsc==string::npos) | 87 | if(fsc==string::npos) |
88 | throw bad_input(OPKELE_CP_ "whtiespace-only identity"); | 88 | throw bad_input(OPKELE_CP_ "whtiespace-only identity"); |
89 | string::size_type lsc = identity.find_last_not_of(whitespace); | 89 | string::size_type lsc = identity.find_last_not_of(whitespace); |
90 | assert(lsc!=string::npos); | 90 | assert(lsc!=string::npos); |
91 | if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1)) | 91 | if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1)) |
92 | fsc += sizeof("xri://")-1; | 92 | fsc += sizeof("xri://")-1; |
93 | if((fsc+1)>=lsc) | 93 | if((fsc+1)>=lsc) |
94 | throw bad_input(OPKELE_CP_ "not a character of importance in identity"); | 94 | throw bad_input(OPKELE_CP_ "not a character of importance in identity"); |
95 | string id(identity,fsc,lsc-fsc+1); | 95 | string id(identity,fsc,lsc-fsc+1); |
96 | if(strchr(i_leaders,id[0])) { | 96 | if(strchr(i_leaders,id[0])) { |
97 | result.normalized_id = id; | 97 | result.normalized_id = id; |
98 | result.xri_identity = true; | ||
98 | /* TODO: further canonicalize xri identity? Like folding case or whatever... */ | 99 | /* TODO: further canonicalize xri identity? Like folding case or whatever... */ |
99 | discover_at( | 100 | discover_at( |
100 | result, | 101 | result, |
101 | xri_proxy + util::url_encode(id)+ | 102 | xri_proxy + util::url_encode(id)+ |
102 | "?_xrd_r=application/xrd+xml;sep=false", xmode_xrd); | 103 | "?_xrd_r=application/xrd+xml;sep=false", xmode_xrd); |
103 | if(status_code!=100) | 104 | if(status_code!=100) |
104 | throw failed_xri_resolution(OPKELE_CP_ | 105 | throw failed_xri_resolution(OPKELE_CP_ |
105 | "XRI resolution failed with '"+status_string+"' message",status_code); | 106 | "XRI resolution failed with '"+status_string+"' message",status_code); |
106 | if(result.xrd.canonical_ids.empty()) | 107 | if(result.xrd.canonical_ids.empty()) |
107 | throw opkele::failed_discovery(OPKELE_CP_ "No CanonicalID for XRI identity found"); | 108 | throw opkele::failed_discovery(OPKELE_CP_ "No CanonicalID for XRI identity found"); |
108 | }else{ | 109 | }else{ |
110 | result.xri_identity = false; | ||
109 | if(id.find("://")==string::npos) | 111 | if(id.find("://")==string::npos) |
110 | id.insert(0,"http://"); | 112 | id.insert(0,"http://"); |
111 | string::size_type fp = id.find('#'); | 113 | string::size_type fp = id.find('#'); |
112 | if(fp!=string::npos) { | 114 | if(fp!=string::npos) { |
113 | string::size_type qp = id.find('?'); | 115 | string::size_type qp = id.find('?'); |
114 | if(qp==string::npos || qp<fp) | 116 | if(qp==string::npos || qp<fp) |
115 | id.erase(fp); | 117 | id.erase(fp); |
116 | else if(qp>fp) | 118 | else if(qp>fp) |
117 | id.erase(fp,qp-fp); | 119 | id.erase(fp,qp-fp); |
118 | } | 120 | } |
119 | result.normalized_id = util::rfc_3986_normalize_uri(id); | 121 | result.normalized_id = util::rfc_3986_normalize_uri(id); |
120 | discover_at(result,id,xmode_html|xmode_xrd); | 122 | discover_at(result,id,xmode_html|xmode_xrd); |
diff --git a/test/idiscover.cc b/test/idiscover.cc index 2abedc9..05cbcae 100644 --- a/test/idiscover.cc +++ b/test/idiscover.cc | |||
@@ -27,23 +27,24 @@ ostream& operator<<(ostream& o,const opkele::xrd::service_t s) { | |||
27 | 27 | ||
28 | int main(int argc,char **argv) { | 28 | int main(int argc,char **argv) { |
29 | try { | 29 | try { |
30 | if(argc<2) | 30 | if(argc<2) |
31 | throw opkele::exception(OPKELE_CP_ "Please, give me something to resolve"); | 31 | throw opkele::exception(OPKELE_CP_ "Please, give me something to resolve"); |
32 | for(int a=1;a<argc;++a) { | 32 | for(int a=1;a<argc;++a) { |
33 | opkele::idiscovery_t discovery(argv[a]); | 33 | opkele::idiscovery_t discovery(argv[a]); |
34 | clog | 34 | clog |
35 | << "===============================================================" << endl | 35 | << "===============================================================" << endl |
36 | << "User-supplied ID: " << argv[a] << endl | 36 | << "User-supplied ID: " << argv[a] << endl |
37 | << "Normalized ID: " << discovery.normalized_id << endl | 37 | << "Normalized ID: " << discovery.normalized_id << endl |
38 | << "Canonicalized ID: " << discovery.canonicalized_id << endl | 38 | << "Canonicalized ID: " << discovery.canonicalized_id << endl |
39 | << "The identity is " << (discovery.xri_identity?"":"not ") << "an i-name" << endl | ||
39 | << endl | 40 | << endl |
40 | << "CanonicalID: " << discovery.xrd.canonical_ids << endl | 41 | << "CanonicalID: " << discovery.xrd.canonical_ids << endl |
41 | << "LocalID: " << discovery.xrd.local_ids << endl | 42 | << "LocalID: " << discovery.xrd.local_ids << endl |
42 | << "Services: " << discovery.xrd.services << endl; | 43 | << "Services: " << discovery.xrd.services << endl; |
43 | } | 44 | } |
44 | }catch(exception& e) { | 45 | }catch(exception& e) { |
45 | cerr << "oops: " << e.what() << endl; | 46 | cerr << "oops: " << e.what() << endl; |
46 | _exit(1); | 47 | _exit(1); |
47 | } | 48 | } |
48 | _exit(0); | 49 | _exit(0); |
49 | } | 50 | } |