summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/expat.h6
-rw-r--r--lib/discovery.cc18
2 files changed, 16 insertions, 8 deletions
diff --git a/include/opkele/expat.h b/include/opkele/expat.h
index 60c41ac..97ed61a 100644
--- a/include/opkele/expat.h
+++ b/include/opkele/expat.h
@@ -14,26 +14,28 @@ namespace opkele {
14 14
15 expat_t() : _x(0) { } 15 expat_t() : _x(0) { }
16 expat_t(XML_Parser x) : _x(x) { } 16 expat_t(XML_Parser x) : _x(x) { }
17 virtual ~expat_t() throw(); 17 virtual ~expat_t() throw();
18 18
19 expat_t& operator=(XML_Parser x); 19 expat_t& operator=(XML_Parser x);
20 20
21 operator const XML_Parser(void) const { return _x; } 21 operator const XML_Parser(void) const { return _x; }
22 operator XML_Parser(void) { return _x; } 22 operator XML_Parser(void) { return _x; }
23 23
24 inline bool parse(const char *s,int len,bool final=false) { 24 inline bool parse(const char *s,int len,bool final=false) {
25 assert(_x); 25 assert(_x);
26 return XML_Parse(_x,s,len,final); 26 return XML_Parse(_x,s,len,final); }
27 } 27 enum XML_Status stop_parser(bool resumable=false) {
28 assert(_x);
29 return XML_StopParser(_x,resumable); }
28 30
29 virtual void start_element(const XML_Char *n,const XML_Char **a) { } 31 virtual void start_element(const XML_Char *n,const XML_Char **a) { }
30 virtual void end_element(const XML_Char *n) { } 32 virtual void end_element(const XML_Char *n) { }
31 void set_element_handler(); 33 void set_element_handler();
32 34
33 virtual void character_data(const XML_Char *s,int l) { } 35 virtual void character_data(const XML_Char *s,int l) { }
34 void set_character_data_handler(); 36 void set_character_data_handler();
35 37
36 virtual void processing_instruction(const XML_Char *t,const XML_Char *d) { } 38 virtual void processing_instruction(const XML_Char *t,const XML_Char *d) { }
37 void set_processing_instruction_handler(); 39 void set_processing_instruction_handler();
38 40
39 virtual void comment(const XML_Char *d) { } 41 virtual void comment(const XML_Char *d) { }
diff --git a/lib/discovery.cc b/lib/discovery.cc
index 81727c0..8729cfb 100644
--- a/lib/discovery.cc
+++ b/lib/discovery.cc
@@ -1,19 +1,20 @@
1#include <list> 1#include <list>
2#include <opkele/curl.h> 2#include <opkele/curl.h>
3#include <opkele/expat.h> 3#include <opkele/expat.h>
4#include <opkele/uris.h> 4#include <opkele/uris.h>
5#include <opkele/discovery.h> 5#include <opkele/discovery.h>
6#include <opkele/exception.h> 6#include <opkele/exception.h>
7#include <opkele/util.h> 7#include <opkele/util.h>
8#include <opkele/debug.h>
8 9
9#include "config.h" 10#include "config.h"
10 11
11#define XRDS_HEADER "X-XRDS-Location" 12#define XRDS_HEADER "X-XRDS-Location"
12#define CT_HEADER "Content-Type" 13#define CT_HEADER "Content-Type"
13 14
14namespace opkele { 15namespace opkele {
15 using std::list; 16 using std::list;
16 using xrd::XRD_t; 17 using xrd::XRD_t;
17 using xrd::service_t; 18 using xrd::service_t;
18 19
19 static const char *whitespace = " \t\r\n"; 20 static const char *whitespace = " \t\r\n";
@@ -166,25 +167,29 @@ namespace opkele {
166 x.services.add(-1,html_openid1); 167 x.services.add(-1,html_openid1);
167 } 168 }
168 if(!html_openid2.uris.empty()) { 169 if(!html_openid2.uris.empty()) {
169 html_openid2.types.insert(STURI_OPENID20); 170 html_openid2.types.insert(STURI_OPENID20);
170 x.services.add(-1,html_openid2); 171 x.services.add(-1,html_openid2);
171 } 172 }
172 } 173 }
173 174
174 size_t write(void *p,size_t s,size_t nm) { 175 size_t write(void *p,size_t s,size_t nm) {
175 if(skipping<0) return 0; 176 if(skipping<0) return 0;
176 /* TODO: limit total size */ 177 /* TODO: limit total size */
177 size_t bytes = s*nm; 178 size_t bytes = s*nm;
178 parse((const char *)p,bytes,false); 179 bool rp = parse((const char *)p,bytes,false);
180 if(!rp) {
181 skipping = -1;
182 bytes = 0;
183 }
179 return bytes; 184 return bytes;
180 } 185 }
181 size_t header(void *p,size_t s,size_t nm) { 186 size_t header(void *p,size_t s,size_t nm) {
182 size_t bytes = s*nm; 187 size_t bytes = s*nm;
183 const char *h = (const char*)p; 188 const char *h = (const char*)p;
184 const char *colon = (const char*)memchr(p,':',bytes); 189 const char *colon = (const char*)memchr(p,':',bytes);
185 const char *space = (const char*)memchr(p,' ',bytes); 190 const char *space = (const char*)memchr(p,' ',bytes);
186 if(space && ( (!colon) || space<colon ) ) { 191 if(space && ( (!colon) || space<colon ) ) {
187 xrds_location.clear(); http_content_type.clear(); 192 xrds_location.clear(); http_content_type.clear();
188 }else if(colon) { 193 }else if(colon) {
189 const char *hv = ++colon; 194 const char *hv = ++colon;
190 int hnl = colon-h; 195 int hnl = colon-h;
@@ -216,25 +221,25 @@ namespace opkele {
216 ++skipping; return; 221 ++skipping; return;
217 } 222 }
218 if(pt_stack.empty()) { 223 if(pt_stack.empty()) {
219 if(is_qelement(n,NSURI_XRDS "\tXRDS")) 224 if(is_qelement(n,NSURI_XRDS "\tXRDS"))
220 return; 225 return;
221 if(is_qelement(n,NSURI_XRD "\tXRD")) { 226 if(is_qelement(n,NSURI_XRD "\tXRD")) {
222 assert(xrd); 227 assert(xrd);
223 xrd->clear(); 228 xrd->clear();
224 pt_stack.push_back(n); 229 pt_stack.push_back(n);
225 }else if(xmode&xmode_html) { 230 }else if(xmode&xmode_html) {
226 html_start_element(n,a); 231 html_start_element(n,a);
227 }else{ 232 }else{
228 skipping = -1; 233 skipping = -1; stop_parser();
229 } 234 }
230 }else{ 235 }else{
231 int pt_s = pt_stack.size(); 236 int pt_s = pt_stack.size();
232 if(pt_s==1) { 237 if(pt_s==1) {
233 if(is_qelement(n,NSURI_XRD "\tCanonicalID")) { 238 if(is_qelement(n,NSURI_XRD "\tCanonicalID")) {
234 assert(xrd); 239 assert(xrd);
235 cdata = &(xrd->canonical_ids.add(element_priority(a),string())); 240 cdata = &(xrd->canonical_ids.add(element_priority(a),string()));
236 }else if(is_qelement(n,NSURI_XRD "\tLocalID")) { 241 }else if(is_qelement(n,NSURI_XRD "\tLocalID")) {
237 assert(xrd); 242 assert(xrd);
238 cdata = &(xrd->local_ids.add(element_priority(a),string())); 243 cdata = &(xrd->local_ids.add(element_priority(a),string()));
239 }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { 244 }else if(is_qelement(n,NSURI_XRD "\tProviderID")) {
240 assert(xrd); 245 assert(xrd);
@@ -301,32 +306,33 @@ namespace opkele {
301 xrd_service->types.insert(cdata_buf); 306 xrd_service->types.insert(cdata_buf);
302 }else if(is_qelement(n,NSURI_XRD "\tService")) { 307 }else if(is_qelement(n,NSURI_XRD "\tService")) {
303 assert(xrd); assert(xrd_service); 308 assert(xrd); assert(xrd_service);
304 assert(!pt_stack.empty()); 309 assert(!pt_stack.empty());
305 assert(pt_stack.back()==(NSURI_XRD "\tService")); 310 assert(pt_stack.back()==(NSURI_XRD "\tService"));
306 pt_stack.pop_back(); 311 pt_stack.pop_back();
307 xrd_service = 0; 312 xrd_service = 0;
308 }else if(is_qelement(n,NSURI_XRD "\tStatus")) { 313 }else if(is_qelement(n,NSURI_XRD "\tStatus")) {
309 assert(xrd); 314 assert(xrd);
310 if(is_qelement(pt_stack.back().c_str(),n)) { 315 if(is_qelement(pt_stack.back().c_str(),n)) {
311 assert(cdata==&status_string); 316 assert(cdata==&status_string);
312 pt_stack.pop_back(); 317 pt_stack.pop_back();
313 if(status_code!=100) 318 if(status_code!=100) {
314 skipping = -1; 319 skipping = -1; stop_parser();
320 }
315 } 321 }
316 }else if(is_qelement(n,NSURI_XRD "\tExpires")) { 322 }else if(is_qelement(n,NSURI_XRD "\tExpires")) {
317 assert(xrd); 323 assert(xrd);
318 xrd->expires = util::w3c_to_time(cdata_buf); 324 xrd->expires = util::w3c_to_time(cdata_buf);
319 }else if((xmode&xmode_html) && is_element(n,"head")) { 325 }else if((xmode&xmode_html) && is_element(n,"head")) {
320 skipping = -1; 326 skipping = -1; stop_parser();
321 } 327 }
322 cdata = 0; 328 cdata = 0;
323 } 329 }
324 void character_data(const XML_Char *s,int l) { 330 void character_data(const XML_Char *s,int l) {
325 if(skipping) return; 331 if(skipping) return;
326 if(cdata) cdata->append(s,l); 332 if(cdata) cdata->append(s,l);
327 } 333 }
328 334
329 void html_start_element(const XML_Char *n,const XML_Char **a) { 335 void html_start_element(const XML_Char *n,const XML_Char **a) {
330 if(is_element(n,"meta")) { 336 if(is_element(n,"meta")) {
331 bool heq = false; 337 bool heq = false;
332 string l; 338 string l;
@@ -365,24 +371,24 @@ namespace opkele {
365 ns = s; 371 ns = s;
366 } 372 }
367 if(rel=="openid.server") 373 if(rel=="openid.server")
368 html_openid1.uris.add(-1,href); 374 html_openid1.uris.add(-1,href);
369 else if(rel=="openid.delegate") 375 else if(rel=="openid.delegate")
370 html_openid1.local_ids.add(-1,href); 376 html_openid1.local_ids.add(-1,href);
371 else if(rel=="openid2.provider") 377 else if(rel=="openid2.provider")
372 html_openid2.uris.add(-1,href); 378 html_openid2.uris.add(-1,href);
373 else if(rel=="openid2.local_id") 379 else if(rel=="openid2.local_id")
374 html_openid2.local_ids.add(-1,href); 380 html_openid2.local_ids.add(-1,href);
375 } 381 }
376 }else if(is_element(n,"body")) { 382 }else if(is_element(n,"body")) {
377 skipping = -1; 383 skipping = -1; stop_parser();
378 } 384 }
379 } 385 }
380 386
381 }; 387 };
382 388
383 void idiscover(idiscovery_t& result,const string& identity) { 389 void idiscover(idiscovery_t& result,const string& identity) {
384 idigger_t idigger; 390 idigger_t idigger;
385 idigger.discover(result,identity); 391 idigger.discover(result,identity);
386 } 392 }
387 393
388} 394}