-rw-r--r-- | lib/sreg.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/sreg.cc b/lib/sreg.cc index 08e66b7..60dc691 100644 --- a/lib/sreg.cc +++ b/lib/sreg.cc | |||
@@ -1,124 +1,124 @@ | |||
1 | #include <opkele/exception.h> | 1 | #include <opkele/exception.h> |
2 | #include <opkele/sreg.h> | 2 | #include <opkele/sreg.h> |
3 | #include <algorithm> | 3 | #include <algorithm> |
4 | 4 | ||
5 | namespace opkele { | 5 | namespace opkele { |
6 | using std::find; | 6 | using std::find; |
7 | 7 | ||
8 | static const struct _sreg_field { | 8 | static const struct _sreg_field { |
9 | const char *fieldname; | 9 | const char *fieldname; |
10 | sreg_t::fieldbit_t fieldbit; | 10 | sreg_t::fieldbit_t fieldbit; |
11 | }fields[] = { | 11 | }fields[] = { |
12 | { "nickname", sreg_t::field_nickname }, | 12 | { "nickname", sreg_t::field_nickname }, |
13 | { "email", sreg_t::field_email }, | 13 | { "email", sreg_t::field_email }, |
14 | { "fullname", sreg_t::field_fullname }, | 14 | { "fullname", sreg_t::field_fullname }, |
15 | { "dob", sreg_t::field_dob }, | 15 | { "dob", sreg_t::field_dob }, |
16 | { "gender", sreg_t::field_gender }, | 16 | { "gender", sreg_t::field_gender }, |
17 | { "postcode", sreg_t::field_postcode }, | 17 | { "postcode", sreg_t::field_postcode }, |
18 | { "country", sreg_t::field_country }, | 18 | { "country", sreg_t::field_country }, |
19 | { "language", sreg_t::field_language }, | 19 | { "language", sreg_t::field_language }, |
20 | { "timezone", sreg_t::field_timezone } | 20 | { "timezone", sreg_t::field_timezone } |
21 | }; | 21 | }; |
22 | # define fields_BEGINfields | 22 | # define fields_BEGINfields |
23 | # define fields_END &fields[sizeof(fields)/sizeof(*fields)] | 23 | # define fields_END &fields[sizeof(fields)/sizeof(*fields)] |
24 | typedef const struct _sreg_field *fields_iterator; | 24 | typedef const struct _sreg_field *fields_iterator; |
25 | 25 | ||
26 | bool operator==(const struct _sreg_field& fd,const string& fn) { | 26 | bool operator==(const struct _sreg_field& fd,const string& fn) { |
27 | return fd.fieldname==fn; | 27 | return fd.fieldname==fn; |
28 | } | 28 | } |
29 | 29 | ||
30 | void sreg_t::checkid_hook(params_t& p,const string& identity) { | 30 | void sreg_t::checkid_hook(params_t& p,const string& /* identity */) { |
31 | string fr, fo; | 31 | string fr, fo; |
32 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { | 32 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { |
33 | if(f->fieldbit&fields_required) { | 33 | if(f->fieldbit&fields_required) { |
34 | if(!fr.empty()) fr+=","; | 34 | if(!fr.empty()) fr+=","; |
35 | fr += f->fieldname; | 35 | fr += f->fieldname; |
36 | } | 36 | } |
37 | if(f->fieldbit&fields_optional) { | 37 | if(f->fieldbit&fields_optional) { |
38 | if(!fo.empty()) fo+=","; | 38 | if(!fo.empty()) fo+=","; |
39 | fo += f->fieldname; | 39 | fo += f->fieldname; |
40 | } | 40 | } |
41 | } | 41 | } |
42 | if(!fr.empty()) p["sreg.required"]=fr; | 42 | if(!fr.empty()) p["sreg.required"]=fr; |
43 | if(!fo.empty()) p["sreg.optional"]=fo; | 43 | if(!fo.empty()) p["sreg.optional"]=fo; |
44 | if(!policy_url.empty()) p["sreg.policy_url"]=policy_url; | 44 | if(!policy_url.empty()) p["sreg.policy_url"]=policy_url; |
45 | } | 45 | } |
46 | 46 | ||
47 | void sreg_t::id_res_hook(const params_t& p,const params_t& sp,const string& identity) { | 47 | void sreg_t::id_res_hook(const params_t& /* p */,const params_t& sp,const string& /* identity */) { |
48 | clear(); | 48 | clear(); |
49 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { | 49 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { |
50 | string fn = "sreg."; fn+=f->fieldname; | 50 | string fn = "sreg."; fn+=f->fieldname; |
51 | if(!sp.has_param(fn)) continue; | 51 | if(!sp.has_param(fn)) continue; |
52 | has_fields |= f->fieldbit; | 52 | has_fields |= f->fieldbit; |
53 | response[f->fieldbit]=sp.get_param(fn); | 53 | response[f->fieldbit]=sp.get_param(fn); |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | const string& sreg_t::get_field(fieldbit_t fb) const { | 57 | const string& sreg_t::get_field(fieldbit_t fb) const { |
58 | response_t::const_iterator i = response.find(fb); | 58 | response_t::const_iterator i = response.find(fb); |
59 | if(i==response.end()) | 59 | if(i==response.end()) |
60 | throw failed_lookup(OPKELE_CP_ "no field data available"); | 60 | throw failed_lookup(OPKELE_CP_ "no field data available"); |
61 | return i->second; | 61 | return i->second; |
62 | } | 62 | } |
63 | 63 | ||
64 | void sreg_t::set_field(fieldbit_t fb,const string& fv) { | 64 | void sreg_t::set_field(fieldbit_t fb,const string& fv) { |
65 | response[fb] = fv; | 65 | response[fb] = fv; |
66 | has_fields |= fb; | 66 | has_fields |= fb; |
67 | } | 67 | } |
68 | 68 | ||
69 | void sreg_t::reset_field(fieldbit_t fb) { | 69 | void sreg_t::reset_field(fieldbit_t fb) { |
70 | has_fields &= ~fb; | 70 | has_fields &= ~fb; |
71 | response.erase(fb); | 71 | response.erase(fb); |
72 | } | 72 | } |
73 | 73 | ||
74 | void sreg_t::clear() { | 74 | void sreg_t::clear() { |
75 | has_fields = 0; response.clear(); | 75 | has_fields = 0; response.clear(); |
76 | } | 76 | } |
77 | 77 | ||
78 | static long fields_list_to_bitmask(string& fl) { | 78 | static long fields_list_to_bitmask(string& fl) { |
79 | long rv = 0; | 79 | long rv = 0; |
80 | while(!fl.empty()) { | 80 | while(!fl.empty()) { |
81 | string::size_type co = fl.find(','); | 81 | string::size_type co = fl.find(','); |
82 | string fn; | 82 | string fn; |
83 | if(co==string::npos) { | 83 | if(co==string::npos) { |
84 | fn = fl; fl.erase(); | 84 | fn = fl; fl.erase(); |
85 | }else{ | 85 | }else{ |
86 | fn = fl.substr(0,co); fl.erase(0,co+1); | 86 | fn = fl.substr(0,co); fl.erase(0,co+1); |
87 | } | 87 | } |
88 | fields_iterator f = find(fields_BEGIN,fields_END,fn); | 88 | fields_iterator f = find(fields_BEGIN,fields_END,fn); |
89 | if(f!=fields_END) | 89 | if(f!=fields_END) |
90 | rv |= f->fieldbit; | 90 | rv |= f->fieldbit; |
91 | } | 91 | } |
92 | return rv; | 92 | return rv; |
93 | } | 93 | } |
94 | 94 | ||
95 | void sreg_t::checkid_hook(const params_t& pin,params_t& pout) { | 95 | void sreg_t::checkid_hook(const params_t& pin,params_t& pout) { |
96 | fields_optional = 0; fields_required = 0; policy_url.erase(); | 96 | fields_optional = 0; fields_required = 0; policy_url.erase(); |
97 | fields_response = 0; | 97 | fields_response = 0; |
98 | try { | 98 | try { |
99 | string fl = pin.get_param("openid.sreg.required"); | 99 | string fl = pin.get_param("openid.sreg.required"); |
100 | fields_required = fields_list_to_bitmask(fl); | 100 | fields_required = fields_list_to_bitmask(fl); |
101 | }catch(failed_lookup&) { } | 101 | }catch(failed_lookup&) { } |
102 | try { | 102 | try { |
103 | string fl = pin.get_param("openid.sreg.optional"); | 103 | string fl = pin.get_param("openid.sreg.optional"); |
104 | fields_optional = fields_list_to_bitmask(fl); | 104 | fields_optional = fields_list_to_bitmask(fl); |
105 | }catch(failed_lookup&) { } | 105 | }catch(failed_lookup&) { } |
106 | try { | 106 | try { |
107 | policy_url = pin.get_param("openid.sreg.policy_url"); | 107 | policy_url = pin.get_param("openid.sreg.policy_url"); |
108 | }catch(failed_lookup&) { } | 108 | }catch(failed_lookup&) { } |
109 | setup_response(pin,pout); | 109 | setup_response(pin,pout); |
110 | fields_response &= has_fields; | 110 | fields_response &= has_fields; |
111 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { | 111 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { |
112 | if(!(f->fieldbit&fields_response)) continue; | 112 | if(!(f->fieldbit&fields_response)) continue; |
113 | if(!pout["signed"].empty()) | 113 | if(!pout["signed"].empty()) |
114 | pout["signed"] +=','; | 114 | pout["signed"] +=','; |
115 | string pn = "sreg."; pn += f->fieldname; | 115 | string pn = "sreg."; pn += f->fieldname; |
116 | pout["signed"] += pn; | 116 | pout["signed"] += pn; |
117 | pout[pn] = get_field(f->fieldbit); | 117 | pout[pn] = get_field(f->fieldbit); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | void sreg_t::setup_response(const params_t& pin,params_t& pout) { | 121 | void sreg_t::setup_response(const params_t& /* pin */,params_t& /* pout */) { |
122 | fields_response = (fields_required|fields_optional)&has_fields; | 122 | fields_response = (fields_required|fields_optional)&has_fields; |
123 | } | 123 | } |
124 | } | 124 | } |