author | Michael Krelin <hacker@klever.net> | 2007-09-11 22:44:51 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-09-11 22:44:51 (UTC) |
commit | 429c48d3d08e6c2f6c385d8975f7b5bf5e67acf3 (patch) (unidiff) | |
tree | 7f314d7f129a60325bf21723ad261570d36220cd | |
parent | 2c6565f363527142928062afe3d3101fdbb3c550 (diff) | |
download | libopkele-429c48d3d08e6c2f6c385d8975f7b5bf5e67acf3.zip libopkele-429c48d3d08e6c2f6c385d8975f7b5bf5e67acf3.tar.gz libopkele-429c48d3d08e6c2f6c385d8975f7b5bf5e67acf3.tar.bz2 |
added support for crappy libpcre c++ bindings
Added optional support for crappy google's c++ bindings. The bindings are
ridiculously googley, so I think, taking into account the amount of pcre
involved, I'll soon drop requirement for any bindings and will use libpcre
directly.
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | acinclude.m4 | 6 | ||||
-rw-r--r-- | configure.ac | 49 | ||||
-rw-r--r-- | lib/consumer.cc | 53 |
3 files changed, 92 insertions, 16 deletions
diff --git a/acinclude.m4 b/acinclude.m4 index 349d3cf..532f978 100644 --- a/acinclude.m4 +++ b/acinclude.m4 | |||
@@ -86,4 +86,4 @@ dnl PCRE_VERSION PCRE_CFLAGS PCRE_LIBS | |||
86 | dnl PCRE_LIBS_POSIX PCRE_CFLAGS_POSIX | 86 | dnl PCRE_LIBS_POSIX PCRE_CFLAGS_POSIX |
87 | dnl AM_CONDITIONAL: HAVE_PCRE | ||
88 | dnl AC_DEFINE: HAVE_PCRE PCRE_VERSION | 87 | dnl AC_DEFINE: HAVE_PCRE PCRE_VERSION |
88 | dnl env: HAVE_PCRE=yes|no | ||
89 | AC_DEFUN([AC_WITH_PCRE],[ | 89 | AC_DEFUN([AC_WITH_PCRE],[ |
@@ -144,3 +144,2 @@ AC_DEFUN([AC_WITH_PCRE],[ | |||
144 | fi | 144 | fi |
145 | AM_CONDITIONAL([HAVE_PCRE],[test "${HAVE_PCRE}" = "yes"]) | ||
146 | ]) | 145 | ]) |
@@ -151,4 +150,4 @@ dnl AC_SUBST: PCREPP_CONFIG PCREPP_PREFIX PCREPP_EXEC_PREFIX | |||
151 | dnl PCREPP_VERSION PCREPP_CFLAGS PCREPP_LIBS | 150 | dnl PCREPP_VERSION PCREPP_CFLAGS PCREPP_LIBS |
152 | dnl AM_CONDITIONAL: HAVE_PCREPP | ||
153 | dnl AC_DEFINE: HAVE_PCREPP PCREPP_VERSION | 151 | dnl AC_DEFINE: HAVE_PCREPP PCREPP_VERSION |
152 | dnl env: HAVE_PCREPP=yes|no | ||
154 | AC_DEFUN([AC_WITH_PCREPP],[ | 153 | AC_DEFUN([AC_WITH_PCREPP],[ |
@@ -209,3 +208,2 @@ AC_DEFUN([AC_WITH_PCREPP],[ | |||
209 | fi | 208 | fi |
210 | AM_CONDITIONAL([HAVE_PCREPP],[test "${HAVE_PCREPP}" = "yes"]) | ||
211 | ]) | 209 | ]) |
diff --git a/configure.ac b/configure.ac index 2094273..00c6bc4 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -54,8 +54,13 @@ LIBCURL_CHECK_CONFIG(,,,[ | |||
54 | ]) | 54 | ]) |
55 | AC_WITH_PCRE([ | 55 | |
56 | AC_WITH_PCREPP(,[ | 56 | want_pcre_impl="" |
57 | AC_MSG_ERROR([no pcre++ library found. get one at http://www.daemon.de/PCRE]) | 57 | AC_ARG_WITH([pcre-bindings], |
58 | ]) | 58 | AC_HELP_STRING([--with-pcre-bindings=(pcrepp|none|libpcrecpp)],[Specify which pcre c++ bindings to use. 'pcrepp' stands for quite sensible library, found at http://www.daemon.de/PCRE/, 'libcrecpp' makes use of crappy bindings by google and 'none' disables internal implementation of OP discovery]), |
59 | ],[ | 59 | [ |
60 | AC_MSG_ERROR([no pcre library found. get one at http://www.pcre.org/]) | 60 | case "$withval" in |
61 | pcrepp) want_pcre_impl="pcrepp" ;; | ||
62 | libpcrecpp) want_pcre_impl="libpcrecpp" ;; | ||
63 | none) want_pcre_impl="none";; | ||
64 | *) AC_MSG_ERROR([I'm not sure I understand what do you want for a pcre c++ bindings]) ;; | ||
65 | esac | ||
61 | ] | 66 | ] |
@@ -63,2 +68,34 @@ AC_WITH_PCRE([ | |||
63 | 68 | ||
69 | found_pcre_impl="" | ||
70 | |||
71 | if test -z "$want_pcre_impl" -o "$want_pcre_impl" = "pcrepp" ; then | ||
72 | AC_WITH_PCRE([ | ||
73 | AC_WITH_PCREPP([ | ||
74 | found_pcre_impl=pcrepp | ||
75 | ]) | ||
76 | ],[ | ||
77 | AC_MSG_ERROR([no pcre library found. get one at http://www.pcre.org/]) | ||
78 | ] | ||
79 | ) | ||
80 | test "$want_pcre_impl,$found_pcre_impl" = "pcrepp," && AC_MSG_ERROR([no pcre++ library found. get one at http://www.daemon.de/PCRE]) | ||
81 | fi | ||
82 | |||
83 | if test "$found_pcre_impl,$want_pcre_impl" = "," -o "$want_pcre_impl" = "libpcrecpp" ; then | ||
84 | test -z "$want_pcre_impl" || AC_MSG_NOTICE([You want to use crappy libpcre c++ bindings]) | ||
85 | PKG_CHECK_MODULES([LIBPCRECPP],[libpcrecpp],[ | ||
86 | found_pcre_impl=libpcrecpp | ||
87 | CXXFLAGS="$CXXFLAGS $LIBPCRECPP_CFLAGS" | ||
88 | LIBS="$LIBS $LIBPCRECPP_LIBS" | ||
89 | ],[ | ||
90 | test -z "$want_pcre_impl" || AC_MSG_ERROR([no libpcre c++ bindings found. why would you want it if you don't have it installed?]) | ||
91 | ] | ||
92 | ) | ||
93 | fi | ||
94 | test "$want_pcre_impl,$found_pcre_impl" = "," && AC_MSG_ERROR([no pcre c++ bindings found, use --with-pcre-bindings=none to disable code that makes use of it]) | ||
95 | |||
96 | case "$found_pcre_impl" in | ||
97 | pcrepp) AC_DEFINE([USE_PCREPP],,[defined if pcre++ is to be used]) ;; | ||
98 | libpcrecpp) AC_DEFINE([USE_LIBPCRECPP],,[defined if crappy google bindings are to be used]) ;; | ||
99 | esac | ||
100 | |||
64 | curl_ssl_verify_host="true" | 101 | curl_ssl_verify_host="true" |
diff --git a/lib/consumer.cc b/lib/consumer.cc index 8f66688..299b3bc 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -9,3 +9,2 @@ | |||
9 | #include <curl/curl.h> | 9 | #include <curl/curl.h> |
10 | #include <pcre++.h> | ||
11 | 10 | ||
@@ -15,2 +14,10 @@ | |||
15 | 14 | ||
15 | #if defined(USE_LIBPCRECPP) | ||
16 | # include <pcrecpp.h> | ||
17 | #elif defined(USE_PCREPP) | ||
18 | # include <pcre++.h> | ||
19 | #else | ||
20 | /* internal implementation won't be built */ | ||
21 | #endif | ||
22 | |||
16 | namespace opkele { | 23 | namespace opkele { |
@@ -263,2 +270,3 @@ namespace opkele { | |||
263 | void consumer_t::retrieve_links(const string& url,string& server,string& delegate) { | 270 | void consumer_t::retrieve_links(const string& url,string& server,string& delegate) { |
271 | #if defined(USE_LIBPCRECPP) || defined(USE_PCREPP) | ||
264 | server.erase(); | 272 | server.erase(); |
@@ -280,7 +288,36 @@ namespace opkele { | |||
280 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r); | 288 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r); |
281 | pcrepp::Pcre bre("<body\\b",PCRE_CASELESS); | ||
282 | // strip out everything past body | 289 | // strip out everything past body |
290 | static const char *re_hdre = "<head[^>]*>", | ||
291 | *re_lre = "<link\\b([^>]+)>", | ||
292 | *re_rre = "\\brel=['\"]([^'\"]+)['\"]", | ||
293 | *re_hre = "\\bhref=['\"]([^'\"]+)['\"]"; | ||
294 | #if defined(USE_LIBPCRECPP) | ||
295 | static pcrecpp::RE_Options ro(PCRE_CASELESS|PCRE_DOTALL); | ||
296 | static pcrecpp::RE | ||
297 | bre("<body\\b.*",ro), hdre(re_hdre,ro), | ||
298 | lre(re_lre,ro), rre(re_rre), hre(re_hre,ro); | ||
299 | bre.Replace("",&html); | ||
300 | pcrecpp::StringPiece hpiece(html); | ||
301 | if(!hdre.FindAndConsume(&hpiece)) | ||
302 | throw bad_input(OPKELE_CP_ "failed to find head"); | ||
303 | string attrs; | ||
304 | while(lre.FindAndConsume(&hpiece,&attrs)) { | ||
305 | pcrecpp::StringPiece rel, href; | ||
306 | if(!(rre.PartialMatch(attrs,&rel) && hre.PartialMatch(attrs,&href))) | ||
307 | continue; | ||
308 | if(rel=="openid.server") { | ||
309 | href.CopyToString(&server); | ||
310 | if(!delegate.empty()) | ||
311 | break; | ||
312 | }else if(rel=="openid.delegate") { | ||
313 | href.CopyToString(&delegate); | ||
314 | if(!server.empty()) | ||
315 | break; | ||
316 | } | ||
317 | } | ||
318 | #elif defined(USE_PCREPP) | ||
319 | pcrepp::Pcre bre("<body\\b",PCRE_CASELESS); | ||
283 | if(bre.search(html)) | 320 | if(bre.search(html)) |
284 | html.erase(bre.get_match_start()); | 321 | html.erase(bre.get_match_start()); |
285 | pcrepp::Pcre hdre("<head[^>]*>",PCRE_CASELESS); | 322 | pcrepp::Pcre hdre(re_hdre,PCRE_CASELESS); |
286 | if(!hdre.search(html)) | 323 | if(!hdre.search(html)) |
@@ -288,5 +325,3 @@ namespace opkele { | |||
288 | html.erase(0,hdre.get_match_end()+1); | 325 | html.erase(0,hdre.get_match_end()+1); |
289 | pcrepp::Pcre lre("<link\\b([^>]+)>",PCRE_CASELESS), | 326 | pcrepp::Pcre lre(re_lre,PCRE_CASELESS), rre(re_rre,PCRE_CASELESS), hre(re_hre,PCRE_CASELESS); |
290 | rre("\\brel=['\"]([^'\"]+)['\"]",PCRE_CASELESS), | ||
291 | hre("\\bhref=['\"]([^'\"]+)['\"]",PCRE_CASELESS); | ||
292 | while(lre.search(html)) { | 327 | while(lre.search(html)) { |
@@ -306,4 +341,10 @@ namespace opkele { | |||
306 | } | 341 | } |
342 | #else | ||
343 | #error "I must have gone crazy" | ||
344 | #endif | ||
307 | if(server.empty()) | 345 | if(server.empty()) |
308 | throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration"); | 346 | throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration"); |
347 | #else /* none of the RE bindings enabled */ | ||
348 | throw not_implemented(OPKELE_CP_ "No internal implementation of retrieve_links were provided at compile-time"); | ||
349 | #endif | ||
309 | } | 350 | } |