summaryrefslogtreecommitdiffabout
path: root/lib/sreg.cc
Unidiff
Diffstat (limited to 'lib/sreg.cc') (more/less context) (show whitespace changes)
-rw-r--r--lib/sreg.cc6
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/sreg.cc b/lib/sreg.cc
index b40cd45..0bd4d2e 100644
--- a/lib/sreg.cc
+++ b/lib/sreg.cc
@@ -10,102 +10,100 @@ namespace opkele {
10 const char *fieldname; 10 const char *fieldname;
11 sreg_t::fieldbit_t fieldbit; 11 sreg_t::fieldbit_t fieldbit;
12 }fields[] = { 12 }fields[] = {
13 { "nickname", sreg_t::field_nickname }, 13 { "nickname", sreg_t::field_nickname },
14 { "email", sreg_t::field_email }, 14 { "email", sreg_t::field_email },
15 { "fullname", sreg_t::field_fullname }, 15 { "fullname", sreg_t::field_fullname },
16 { "dob", sreg_t::field_dob }, 16 { "dob", sreg_t::field_dob },
17 { "gender", sreg_t::field_gender }, 17 { "gender", sreg_t::field_gender },
18 { "postcode", sreg_t::field_postcode }, 18 { "postcode", sreg_t::field_postcode },
19 { "country", sreg_t::field_country }, 19 { "country", sreg_t::field_country },
20 { "language", sreg_t::field_language }, 20 { "language", sreg_t::field_language },
21 { "timezone", sreg_t::field_timezone } 21 { "timezone", sreg_t::field_timezone }
22 }; 22 };
23 # define fields_BEGINfields 23 # define fields_BEGINfields
24# define fields_END &fields[sizeof(fields)/sizeof(*fields)] 24# define fields_END &fields[sizeof(fields)/sizeof(*fields)]
25 typedef const struct _sreg_field *fields_iterator; 25 typedef const struct _sreg_field *fields_iterator;
26 26
27 bool operator==(const struct _sreg_field& fd,const string& fn) { 27 bool operator==(const struct _sreg_field& fd,const string& fn) {
28 return fd.fieldname==fn; 28 return fd.fieldname==fn;
29 } 29 }
30 30
31 void sreg_t::rp_checkid_hook(basic_openid_message& om) { 31 void sreg_t::rp_checkid_hook(basic_openid_message& om) {
32 string fr, fo; 32 string fr, fo;
33 for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { 33 for(fields_iterator f=fields_BEGIN;f<fields_END;++f) {
34 if(f->fieldbit&fields_required) { 34 if(f->fieldbit&fields_required) {
35 if(!fr.empty()) fr+=","; 35 if(!fr.empty()) fr+=",";
36 fr += f->fieldname; 36 fr += f->fieldname;
37 } 37 }
38 if(f->fieldbit&fields_optional) { 38 if(f->fieldbit&fields_optional) {
39 if(!fo.empty()) fo+=","; 39 if(!fo.empty()) fo+=",";
40 fo += f->fieldname; 40 fo += f->fieldname;
41 } 41 }
42 } 42 }
43 string pfx = om.allocate_ns(OIURI_SREG11,"sreg"); 43 string pfx = om.allocate_ns(OIURI_SREG11,"sreg");
44 if(!fr.empty()) om.set_field(pfx+".required",fr); 44 if(!fr.empty()) om.set_field(pfx+".required",fr);
45 if(!fo.empty()) om.set_field(pfx+".optional",fo); 45 if(!fo.empty()) om.set_field(pfx+".optional",fo);
46 if(!policy_url.empty()) om.set_field(pfx+".policy_url",policy_url); 46 if(!policy_url.empty()) om.set_field(pfx+".policy_url",policy_url);
47 } 47 }
48 48
49 void sreg_t::checkid_hook(basic_openid_message& om) { 49 void sreg_t::checkid_hook(basic_openid_message& om) {
50 rp_checkid_hook(om); } 50 rp_checkid_hook(om); }
51 51
52 void sreg_t::rp_id_res_hook(const basic_openid_message& om, 52 void sreg_t::rp_id_res_hook(const basic_openid_message& om,
53 const basic_openid_message& sp) { 53 const basic_openid_message& sp) {
54 clear(); 54 clear();
55 string pfx; 55 string pfx;
56 try { 56 try {
57 pfx = om.find_ns(OIURI_SREG11,"sreg"); 57 pfx = om.find_ns(OIURI_SREG11,"sreg");
58 }catch(failed_lookup& fl) { 58 }catch(failed_lookup&) {
59 try { 59 try {
60 pfx = om.find_ns(OIURI_SREG10,"sreg"); 60 pfx = om.find_ns(OIURI_SREG10,"sreg");
61 }catch(failed_lookup& fl) { 61 }catch(failed_lookup&) { return; }
62 return;
63 }
64 } 62 }
65 pfx += '.'; 63 pfx += '.';
66 for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { 64 for(fields_iterator f=fields_BEGIN;f<fields_END;++f) {
67 string fn = pfx; fn+=f->fieldname; 65 string fn = pfx; fn+=f->fieldname;
68 if(!sp.has_field(fn)) continue; 66 if(!sp.has_field(fn)) continue;
69 has_fields |= f->fieldbit; 67 has_fields |= f->fieldbit;
70 response[f->fieldbit]=sp.get_field(fn); 68 response[f->fieldbit]=sp.get_field(fn);
71 } 69 }
72 } 70 }
73 71
74 void sreg_t::id_res_hook(const basic_openid_message& om, 72 void sreg_t::id_res_hook(const basic_openid_message& om,
75 const basic_openid_message& sp) { 73 const basic_openid_message& sp) {
76 rp_id_res_hook(om,sp); } 74 rp_id_res_hook(om,sp); }
77 75
78 const string& sreg_t::get_field(fieldbit_t fb) const { 76 const string& sreg_t::get_field(fieldbit_t fb) const {
79 response_t::const_iterator i = response.find(fb); 77 response_t::const_iterator i = response.find(fb);
80 if(i==response.end()) 78 if(i==response.end())
81 throw failed_lookup(OPKELE_CP_ "no field data available"); 79 throw failed_lookup(OPKELE_CP_ "no field data available");
82 return i->second; 80 return i->second;
83 } 81 }
84 82
85 void sreg_t::set_field(fieldbit_t fb,const string& fv) { 83 void sreg_t::set_field(fieldbit_t fb,const string& fv) {
86 response[fb] = fv; 84 response[fb] = fv;
87 has_fields |= fb; 85 has_fields |= fb;
88 } 86 }
89 87
90 void sreg_t::reset_field(fieldbit_t fb) { 88 void sreg_t::reset_field(fieldbit_t fb) {
91 has_fields &= ~fb; 89 has_fields &= ~fb;
92 response.erase(fb); 90 response.erase(fb);
93 } 91 }
94 92
95 void sreg_t::clear() { 93 void sreg_t::clear() {
96 has_fields = 0; response.clear(); 94 has_fields = 0; response.clear();
97 } 95 }
98 96
99 static long fields_list_to_bitmask(string& fl) { 97 static long fields_list_to_bitmask(string& fl) {
100 long rv = 0; 98 long rv = 0;
101 while(!fl.empty()) { 99 while(!fl.empty()) {
102 string::size_type co = fl.find(','); 100 string::size_type co = fl.find(',');
103 string fn; 101 string fn;
104 if(co==string::npos) { 102 if(co==string::npos) {
105 fn = fl; fl.erase(); 103 fn = fl; fl.erase();
106 }else{ 104 }else{
107 fn = fl.substr(0,co); fl.erase(0,co+1); 105 fn = fl.substr(0,co); fl.erase(0,co+1);
108 } 106 }
109 fields_iterator f = find(fields_BEGIN,fields_END,fn); 107 fields_iterator f = find(fields_BEGIN,fields_END,fn);
110 if(f!=fields_END) 108 if(f!=fields_END)
111 rv |= f->fieldbit; 109 rv |= f->fieldbit;