summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2008-04-06 09:31:10 (UTC)
committer Michael Krelin <hacker@klever.net>2008-04-06 09:31:10 (UTC)
commit752e484cd2fc239bc582a88fe7d62a225880ee3b (patch) (unidiff)
treead53fd61add881c5262b9cbc66c5db41e179a993
parentc56867c814a70505e27501c8f02768a594d8e42d (diff)
parent1e3ed01c149aaeed5a64aacff218a5486128fc92 (diff)
downloadlibopkele-752e484cd2fc239bc582a88fe7d62a225880ee3b.zip
libopkele-752e484cd2fc239bc582a88fe7d62a225880ee3b.tar.gz
libopkele-752e484cd2fc239bc582a88fe7d62a225880ee3b.tar.bz2
Merge commit '1e3ed01c149aaeed5a64aacff218a5486128fc92' into devel/openid20
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--configure.ac4
-rw-r--r--include/opkele/curl.h20
-rw-r--r--include/opkele/types.h39
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/curl.cc20
-rw-r--r--lib/fields.cc86
-rw-r--r--lib/message.cc (renamed from lib/openid_message.cc)84
-rw-r--r--libopkele.pc.in2
8 files changed, 157 insertions, 100 deletions
diff --git a/configure.ac b/configure.ac
index a49177f..0aa1272 100644
--- a/configure.ac
+++ b/configure.ac
@@ -178,6 +178,10 @@ PKG_CHECK_MODULES([KINGATE],[kingate-plaincgi],[have_kingate=true],[have_kingate
178AM_CONDITIONAL([HAVE_KINGATE],[$have_kingate]) 178AM_CONDITIONAL([HAVE_KINGATE],[$have_kingate])
179PKG_CHECK_MODULES([UUID],[uuid],[have_uuid=true],[have_uuid=false]) 179PKG_CHECK_MODULES([UUID],[uuid],[have_uuid=true],[have_uuid=false])
180AM_CONDITIONAL([HAVE_UUID],[$have_uuid]) 180AM_CONDITIONAL([HAVE_UUID],[$have_uuid])
181if $have_uuid ; then
182 AC_DEFINE([HAVE_LIBUUID],,[defined in presence of libuuid])
183 AC_SUBST([UUID_UUID],[uuid])
184fi
181 185
182curl_ssl_verify_host="true" 186curl_ssl_verify_host="true"
183AC_ARG_ENABLE([ssl-verify-host], 187AC_ARG_ENABLE([ssl-verify-host],
diff --git a/include/opkele/curl.h b/include/opkele/curl.h
index 5cf8e48..bcaf11d 100644
--- a/include/opkele/curl.h
+++ b/include/opkele/curl.h
@@ -12,6 +12,24 @@ namespace opkele {
12 12
13 namespace util { 13 namespace util {
14 14
15 class curl_slist_t {
16 public:
17 curl_slist *_s;
18
19 curl_slist_t() : _s(0) { }
20 curl_slist_t(curl_slist *s) : _s(s) { }
21 virtual ~curl_slist_t() throw();
22
23 curl_slist_t& operator=(curl_slist *s);
24
25 operator const curl_slist*(void) const { return _s; }
26 operator curl_slist*(void) { return _s; }
27
28 void append(const char *str);
29 void append(const string& str) {
30 append(str.c_str()); }
31 };
32
15 class curl_t { 33 class curl_t {
16 public: 34 public:
17 CURL *_c; 35 CURL *_c;
@@ -29,6 +47,8 @@ namespace opkele {
29 47
30 template<typename PT> 48 template<typename PT>
31 inline CURLcode easy_setopt(CURLoption o,PT p) { assert(_c); return curl_easy_setopt(_c,o,p); } 49 inline CURLcode easy_setopt(CURLoption o,PT p) { assert(_c); return curl_easy_setopt(_c,o,p); }
50 inline CURLcode easy_setopt(CURLoption o,const curl_slist_t& p) {
51 assert(_c); return curl_easy_setopt(_c,o,(const curl_slist*)p); }
32 CURLcode easy_perform() { assert(_c); return curl_easy_perform(_c); } 52 CURLcode easy_perform() { assert(_c); return curl_easy_perform(_c); }
33 template<typename IT> 53 template<typename IT>
34 inline CURLcode easy_getinfo(CURLINFO i,IT p) { assert(_c); return curl_easy_getinfo(_c,i,p); } 54 inline CURLcode easy_getinfo(CURLINFO i,IT p) { assert(_c); return curl_easy_getinfo(_c,i,p); }
diff --git a/include/opkele/types.h b/include/opkele/types.h
index ffb9afb..f63bf5d 100644
--- a/include/opkele/types.h
+++ b/include/opkele/types.h
@@ -118,36 +118,47 @@ namespace opkele {
118 */ 118 */
119 typedef tr1mem::shared_ptr<association_t> assoc_t; 119 typedef tr1mem::shared_ptr<association_t> assoc_t;
120 120
121 class basic_openid_message { 121 class basic_fields {
122 public: 122 public:
123 typedef list<string> fields_t;
124 typedef util::forward_iterator_proxy< 123 typedef util::forward_iterator_proxy<
125 string,const string&,const string* 124 string,const string&,const string*
126 > fields_iterator; 125 > fields_iterator;
127 126
128 basic_openid_message() { } 127 basic_fields() { }
129 virtual ~basic_openid_message() { } 128 virtual ~basic_fields() { }
130 basic_openid_message(const basic_openid_message& x); 129 basic_fields(const basic_fields& x);
131 void copy_to(basic_openid_message& x) const; 130 void copy_to(basic_fields& x) const;
132 void append_to(basic_openid_message& x) const; 131 void append_to(basic_fields& x) const;
133 132
134 virtual bool has_field(const string& n) const = 0; 133 virtual bool has_field(const string& n) const = 0;
135 virtual const string& get_field(const string& n) const = 0; 134 virtual const string& get_field(const string& n) const = 0;
136 135
137 virtual bool has_ns(const string& uri) const;
138 virtual string get_ns(const string& uri) const;
139
140 virtual fields_iterator fields_begin() const = 0; 136 virtual fields_iterator fields_begin() const = 0;
141 virtual fields_iterator fields_end() const = 0; 137 virtual fields_iterator fields_end() const = 0;
142 138
143 virtual string append_query(const string& url,const char *pfx="openid.") const; 139 virtual string append_query(const string& url,const char *pfx=0) const;
144 virtual string query_string(const char *pfx="openid.") const; 140 virtual string query_string(const char *pfx=0) const;
145
146 141
147 virtual void reset_fields(); 142 virtual void reset_fields();
148 virtual void set_field(const string& n,const string& v); 143 virtual void set_field(const string& n,const string& v);
149 virtual void reset_field(const string& n); 144 virtual void reset_field(const string& n);
150 145
146 };
147
148 class basic_openid_message : public basic_fields {
149 public:
150
151 basic_openid_message() { }
152 basic_openid_message(const basic_openid_message& x);
153
154 virtual bool has_ns(const string& uri) const;
155 virtual string get_ns(const string& uri) const;
156
157 virtual string append_query(const string& url,const char *pfx="openid.") const {
158 return basic_fields::append_query(url,pfx); }
159 virtual string query_string(const char *pfx="openid.") const {
160 return basic_fields::query_string(pfx); }
161
151 virtual void from_keyvalues(const string& kv); 162 virtual void from_keyvalues(const string& kv);
152 virtual void to_keyvalues(ostream& o) const; 163 virtual void to_keyvalues(ostream& o) const;
153 164
@@ -164,8 +175,6 @@ namespace opkele {
164 openid_message_t(const basic_openid_message& x) 175 openid_message_t(const basic_openid_message& x)
165 : basic_openid_message(x) { } 176 : basic_openid_message(x) { }
166 177
167 void copy_to(basic_openid_message& x) const;
168
169 bool has_field(const string& n) const; 178 bool has_field(const string& n) const;
170 const string& get_field(const string& n) const; 179 const string& get_field(const string& n) const;
171 virtual fields_iterator fields_begin() const; 180 virtual fields_iterator fields_begin() const;
diff --git a/lib/Makefile.am b/lib/Makefile.am
index e8bfbf5..20d15b8 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -28,7 +28,7 @@ libopkele_la_SOURCES = \
28 curl.cc expat.cc \ 28 curl.cc expat.cc \
29 discovery.cc \ 29 discovery.cc \
30 basic_rp.cc prequeue_rp.cc \ 30 basic_rp.cc prequeue_rp.cc \
31 openid_message.cc \ 31 fields.cc message.cc \
32 basic_op.cc verify_op.cc 32 basic_op.cc verify_op.cc
33libopkele_la_LDFLAGS = \ 33libopkele_la_LDFLAGS = \
34 -version-info 2:0:0 34 -version-info 2:0:0
diff --git a/lib/curl.cc b/lib/curl.cc
index 6172828..734e2ca 100644
--- a/lib/curl.cc
+++ b/lib/curl.cc
@@ -1,3 +1,4 @@
1#include <opkele/exception.h>
1#include <opkele/curl.h> 2#include <opkele/curl.h>
2 3
3#include "config.h" 4#include "config.h"
@@ -6,6 +7,25 @@ namespace opkele {
6 7
7 namespace util { 8 namespace util {
8 9
10 curl_slist_t::~curl_slist_t() throw() {
11 if(_s)
12 curl_slist_free_all(_s);
13 }
14
15 curl_slist_t& curl_slist_t::operator=(curl_slist *s) {
16 if(_s)
17 curl_slist_free_all(_s);
18 _s = s;
19 return *this;
20 }
21
22 void curl_slist_t::append(const char *str) {
23 curl_slist *s = curl_slist_append(_s,str);
24 if(!s)
25 throw opkele::exception(OPKELE_CP_ "failed to curl_slist_append()");
26 _s=s;
27 }
28
9 curl_t::~curl_t() throw() { 29 curl_t::~curl_t() throw() {
10 if(_c) 30 if(_c)
11 curl_easy_cleanup(_c); 31 curl_easy_cleanup(_c);
diff --git a/lib/fields.cc b/lib/fields.cc
new file mode 100644
index 0000000..d494098
--- a/dev/null
+++ b/lib/fields.cc
@@ -0,0 +1,86 @@
1#include <opkele/types.h>
2#include <opkele/exception.h>
3#include <opkele/util.h>
4
5namespace opkele {
6 using std::unary_function;
7
8 struct __om_copier : public unary_function<const string&,void> {
9 public:
10 const basic_fields& from;
11 basic_fields& to;
12
13 __om_copier(basic_fields& t,const basic_fields& f)
14 : from(f), to(t) { }
15
16 result_type operator()(argument_type f) {
17 to.set_field(f,from.get_field(f)); }
18 };
19
20 basic_fields::basic_fields(const basic_fields& x) {
21 x.copy_to(*this);
22 }
23 void basic_fields::copy_to(basic_fields& x) const {
24 x.reset_fields();
25 for_each(fields_begin(),fields_end(),
26 __om_copier(x,*this) );
27 }
28 void basic_fields::append_to(basic_fields& x) const {
29 for_each(fields_begin(),fields_end(),
30 __om_copier(x,*this) );
31 }
32
33 struct __om_query_builder : public unary_function<const string&,void> {
34 public:
35 const basic_fields& om;
36 bool first;
37 string& rv;
38 const char *pfx;
39
40 __om_query_builder(const char *p,string& r,const basic_fields& m)
41 : om(m), first(true), rv(r), pfx(p) {
42 for_each(om.fields_begin(),om.fields_end(),*this);
43 }
44 __om_query_builder(const char *p,string& r,const basic_fields& m,const string& u)
45 : om(m), first(true), rv(r), pfx(p) {
46 rv = u;
47 if(rv.find('?')==string::npos)
48 rv += '?';
49 else
50 first = false;
51 for_each(om.fields_begin(),om.fields_end(),*this);
52 }
53
54 result_type operator()(argument_type f) {
55 if(first)
56 first = false;
57 else
58 rv += '&';
59 if(pfx) rv += pfx;
60 rv+= f;
61 rv += '=';
62 rv += util::url_encode(om.get_field(f));
63 }
64 };
65
66 string basic_fields::append_query(const string& url,const char *pfx) const {
67 string rv;
68 return __om_query_builder(pfx,rv,*this,url).rv;
69 }
70 string basic_fields::query_string(const char *pfx) const {
71 string rv;
72 return __om_query_builder(pfx,rv,*this).rv;
73 }
74
75 void basic_fields::reset_fields() {
76 throw not_implemented(OPKELE_CP_ "reset_fields() not implemented");
77 }
78 void basic_fields::set_field(const string&,const string&) {
79 throw not_implemented(OPKELE_CP_ "set_field() not implemented");
80 }
81 void basic_fields::reset_field(const string&) {
82 throw not_implemented(OPKELE_CP_ "reset_field() not implemented");
83 }
84
85
86}
diff --git a/lib/openid_message.cc b/lib/message.cc
index e244f43..b2324b7 100644
--- a/lib/openid_message.cc
+++ b/lib/message.cc
@@ -10,30 +10,6 @@ namespace opkele {
10 using std::input_iterator_tag; 10 using std::input_iterator_tag;
11 using std::unary_function; 11 using std::unary_function;
12 12
13 struct __om_copier : public unary_function<const string&,void> {
14 public:
15 const basic_openid_message& from;
16 basic_openid_message& to;
17
18 __om_copier(basic_openid_message& t,const basic_openid_message& f)
19 : from(f), to(t) { }
20
21 result_type operator()(argument_type f) {
22 to.set_field(f,from.get_field(f)); }
23 };
24
25 basic_openid_message::basic_openid_message(const basic_openid_message& x) {
26 x.copy_to(*this);
27 }
28 void basic_openid_message::copy_to(basic_openid_message& x) const {
29 x.reset_fields();
30 for_each(fields_begin(),fields_end(),
31 __om_copier(x,*this) );
32 }
33 void basic_openid_message::append_to(basic_openid_message& x) const {
34 for_each(fields_begin(),fields_end(),
35 __om_copier(x,*this) );
36 }
37 13
38 struct __om_ns_finder : public unary_function<const string&,bool> { 14 struct __om_ns_finder : public unary_function<const string&,bool> {
39 public: 15 public:
@@ -65,58 +41,6 @@ namespace opkele {
65 return i->substr(3); 41 return i->substr(3);
66 } 42 }
67 43
68 struct __om_query_builder : public unary_function<const string&,void> {
69 public:
70 const basic_openid_message& om;
71 bool first;
72 string& rv;
73 const char *pfx;
74
75 __om_query_builder(const char *p,string& r,const basic_openid_message& m)
76 : om(m), first(true), rv(r), pfx(p) {
77 for_each(om.fields_begin(),om.fields_end(),*this);
78 }
79 __om_query_builder(const char *p,string& r,const basic_openid_message& m,const string& u)
80 : om(m), first(true), rv(r), pfx(p) {
81 rv = u;
82 if(rv.find('?')==string::npos)
83 rv += '?';
84 else
85 first = false;
86 for_each(om.fields_begin(),om.fields_end(),*this);
87 }
88
89 result_type operator()(argument_type f) {
90 if(first)
91 first = false;
92 else
93 rv += '&';
94 if(pfx) rv += pfx;
95 rv+= f;
96 rv += '=';
97 rv += util::url_encode(om.get_field(f));
98 }
99 };
100
101 string basic_openid_message::append_query(const string& url,const char *pfx) const {
102 string rv;
103 return __om_query_builder(pfx,rv,*this,url).rv;
104 }
105 string basic_openid_message::query_string(const char *pfx) const {
106 string rv;
107 return __om_query_builder(pfx,rv,*this).rv;
108 }
109
110 void basic_openid_message::reset_fields() {
111 throw not_implemented(OPKELE_CP_ "reset_fields() not implemented");
112 }
113 void basic_openid_message::set_field(const string&,const string&) {
114 throw not_implemented(OPKELE_CP_ "set_field() not implemented");
115 }
116 void basic_openid_message::reset_field(const string&) {
117 throw not_implemented(OPKELE_CP_ "reset_field() not implemented");
118 }
119
120 void basic_openid_message::from_keyvalues(const string& kv) { 44 void basic_openid_message::from_keyvalues(const string& kv) {
121 reset_fields(); 45 reset_fields();
122 string::size_type p = 0; 46 string::size_type p = 0;
@@ -129,7 +53,7 @@ namespace opkele {
129 if(nl==string::npos) 53 if(nl==string::npos)
130 throw bad_input(OPKELE_CP_ "malformed input"); 54 throw bad_input(OPKELE_CP_ "malformed input");
131 if(nl>co) 55 if(nl>co)
132 insert(value_type(kv.substr(p,co-p),kv.substr(co+1,nl-co-1))); 56 set_field(kv.substr(p,co-p),kv.substr(co+1,nl-co-1));
133 p = nl+1; 57 p = nl+1;
134#else /* POSTELS_LAW */ 58#else /* POSTELS_LAW */
135 string::size_type lb = kv.find_first_of("\r\n",co+1); 59 string::size_type lb = kv.find_first_of("\r\n",co+1);
@@ -240,12 +164,6 @@ namespace opkele {
240 return rv; 164 return rv;
241 } 165 }
242 166
243 void openid_message_t::copy_to(basic_openid_message& x) const {
244 x.reset_fields();
245 for(const_iterator i=begin();i!=end();++i)
246 x.set_field(i->first,i->second);
247 }
248
249 bool openid_message_t::has_field(const string& n) const { 167 bool openid_message_t::has_field(const string& n) const {
250 return find(n)!=end(); 168 return find(n)!=end();
251 } 169 }
diff --git a/libopkele.pc.in b/libopkele.pc.in
index 011f2fe..2720a6a 100644
--- a/libopkele.pc.in
+++ b/libopkele.pc.in
@@ -6,6 +6,6 @@ includedir=@includedir@
6Name: libopkele 6Name: libopkele
7Description: C++ implementation of OpenID protocol 7Description: C++ implementation of OpenID protocol
8Version: @VERSION@ 8Version: @VERSION@
9Requires: openssl libpcre @KONFORKA_KONFORKA@ 9Requires: openssl libpcre @KONFORKA_KONFORKA@ @UUID_UUID@
10Cflags: -I${includedir} @LIBCURL_CPPFLAGS@ @PCRE_CFLAGS@ @EXPAT_CFLAGS@ @TIDY_CFLAGS@ 10Cflags: -I${includedir} @LIBCURL_CPPFLAGS@ @PCRE_CFLAGS@ @EXPAT_CFLAGS@ @TIDY_CFLAGS@
11Libs: -L${libdir} -lopkele @LIBCURL@ @PCRE_LIBS@ @EXPAT_LIBS@ @TIDY_LIBS@ 11Libs: -L${libdir} -lopkele @LIBCURL@ @PCRE_LIBS@ @EXPAT_LIBS@ @TIDY_LIBS@