summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2007-09-11 22:44:51 (UTC)
committer Michael Krelin <hacker@klever.net>2007-09-11 22:44:51 (UTC)
commit429c48d3d08e6c2f6c385d8975f7b5bf5e67acf3 (patch) (unidiff)
tree7f314d7f129a60325bf21723ad261570d36220cd
parent2c6565f363527142928062afe3d3101fdbb3c550 (diff)
downloadlibopkele-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>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--acinclude.m46
-rw-r--r--configure.ac49
-rw-r--r--lib/consumer.cc53
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
@@ -1,213 +1,211 @@
1dnl AC_WITH_PKGCONFIG([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) 1dnl AC_WITH_PKGCONFIG([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
2dnl Outputs: 2dnl Outputs:
3dnl AC_SUBST: PKGCONFIG_PKGCONFIG PKGCONFIG_DIR 3dnl AC_SUBST: PKGCONFIG_PKGCONFIG PKGCONFIG_DIR
4dnl AM_CONDTIONAL: HAVE_PKGCONFIG 4dnl AM_CONDTIONAL: HAVE_PKGCONFIG
5AC_DEFUN([AC_WITH_PKGCONFIG],[ 5AC_DEFUN([AC_WITH_PKGCONFIG],[
6 PKGCONFIG_PKGCONFIG="" 6 PKGCONFIG_PKGCONFIG=""
7 PKGCONFIG_DIR="" 7 PKGCONFIG_DIR=""
8 HAVE_PKGCONFIG="no" 8 HAVE_PKGCONFIG="no"
9 EXPLICIT_PKGCONFIGDIR="no" 9 EXPLICIT_PKGCONFIGDIR="no"
10 test -z "${WANT_PKGCONFIG}" && WANT_PKGCONFIG="" 10 test -z "${WANT_PKGCONFIG}" && WANT_PKGCONFIG=""
11 AC_PATH_PROG([PKGCONFIG_PKGCONFIG],[pkg-config],[false]) 11 AC_PATH_PROG([PKGCONFIG_PKGCONFIG],[pkg-config],[false])
12 if test "${PKGCONFIG_PKGCONFIG}" != "false" ; then 12 if test "${PKGCONFIG_PKGCONFIG}" != "false" ; then
13 AC_ARG_WITH([pkgconfigdir], 13 AC_ARG_WITH([pkgconfigdir],
14 AC_HELP_STRING([--with-pkgconfigdir=dir],[Specify pkgconfig directory]), 14 AC_HELP_STRING([--with-pkgconfigdir=dir],[Specify pkgconfig directory]),
15 [ 15 [
16 if test "${withval}" = "no" ; then 16 if test "${withval}" = "no" ; then
17 WANT_PKGCONFIG="no" 17 WANT_PKGCONFIG="no"
18 else 18 else
19 PKGCONFIG_DIR="${withval}" 19 PKGCONFIG_DIR="${withval}"
20 EXPLICIT_PKGCONFIGDIR="yes" 20 EXPLICIT_PKGCONFIGDIR="yes"
21 fi 21 fi
22 ],[ 22 ],[
23 AC_MSG_CHECKING([for pkgconfig directory]) 23 AC_MSG_CHECKING([for pkgconfig directory])
24 PKGCONFIG_DIR="`${PKGCONFIG_PKGCONFIG} --debug 2>&1 | grep '^Scanning'| head -n 1 | cut -d\' -f2-|cut -d\' -f1`" 24 PKGCONFIG_DIR="`${PKGCONFIG_PKGCONFIG} --debug 2>&1 | grep '^Scanning'| head -n 1 | cut -d\' -f2-|cut -d\' -f1`"
25 AC_MSG_RESULT([${PKGCONFIG_DIR}]) 25 AC_MSG_RESULT([${PKGCONFIG_DIR}])
26 ] 26 ]
27 ) 27 )
28 if test -d "${PKGCONFIG_DIR}" ; then 28 if test -d "${PKGCONFIG_DIR}" ; then
29 HAVE_PKGCONFIG=yes 29 HAVE_PKGCONFIG=yes
30 AC_SUBST([PKGCONFIG_PKGCONFIG]) 30 AC_SUBST([PKGCONFIG_PKGCONFIG])
31 AC_SUBST([PKGCONFIG_DIR]) 31 AC_SUBST([PKGCONFIG_DIR])
32 else 32 else
33 AC_MSG_NOTICE([unexistent pkgconfig directory: ${PKGCONFIG_DIR}]) 33 AC_MSG_NOTICE([unexistent pkgconfig directory: ${PKGCONFIG_DIR}])
34 if test "${EXPLICIT_PKGCONFIGDIR}" = "yes" ; then 34 if test "${EXPLICIT_PKGCONFIGDIR}" = "yes" ; then
35 HAVE_PKGCONFIG=yes 35 HAVE_PKGCONFIG=yes
36 AC_SUBST([PKGCONFIG_PKGCONFIG]) 36 AC_SUBST([PKGCONFIG_PKGCONFIG])
37 AC_SUBST([PKGCONFIG_DIR]) 37 AC_SUBST([PKGCONFIG_DIR])
38 else 38 else
39 ifelse([$2], , :, [$2]) 39 ifelse([$2], , :, [$2])
40 fi 40 fi
41 fi 41 fi
42 fi 42 fi
43 AM_CONDITIONAL([HAVE_PKGCONFIG],[test "${HAVE_PKGCONFIG}" = "yes"]) 43 AM_CONDITIONAL([HAVE_PKGCONFIG],[test "${HAVE_PKGCONFIG}" = "yes"])
44]) 44])
45 45
46dnl AC_WITH_DOXYGEN([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) 46dnl AC_WITH_DOXYGEN([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
47dnl Outputs: 47dnl Outputs:
48dnl AC_SUBST: DOXYGEN HAVE_DOXYGEN 48dnl AC_SUBST: DOXYGEN HAVE_DOXYGEN
49dnl AM_CONDTIONAL: HAVE_DOXYGEN 49dnl AM_CONDTIONAL: HAVE_DOXYGEN
50AC_DEFUN([AC_WITH_DOXYGEN],[ 50AC_DEFUN([AC_WITH_DOXYGEN],[
51 HAVE_DOXYGEN="no" 51 HAVE_DOXYGEN="no"
52 AC_PATH_PROG([DOXYGEN],[doxygen],[false]) 52 AC_PATH_PROG([DOXYGEN],[doxygen],[false])
53 if test "${DOXYGEN}" = "false" ; then 53 if test "${DOXYGEN}" = "false" ; then
54 ifelse([$2], , :, [$2]) 54 ifelse([$2], , :, [$2])
55 else 55 else
56 HAVE_DOXYGEN="yes" 56 HAVE_DOXYGEN="yes"
57 AC_SUBST([DOXYGEN]) 57 AC_SUBST([DOXYGEN])
58 $1 58 $1
59 fi 59 fi
60 AC_SUBST([HAVE_DOXYGEN]) 60 AC_SUBST([HAVE_DOXYGEN])
61 AM_CONDITIONAL([HAVE_DOXYGEN],[test "${HAVE_DOXYGEN}" = "yes"]) 61 AM_CONDITIONAL([HAVE_DOXYGEN],[test "${HAVE_DOXYGEN}" = "yes"])
62]) 62])
63 63
64dnl AC_WITH_DOT([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) 64dnl AC_WITH_DOT([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
65dnl Outputs: 65dnl Outputs:
66dnl AC_SUBST: DOT HAVE_DOT 66dnl AC_SUBST: DOT HAVE_DOT
67dnl AM_CONDITIONAL: HAVE_DOT 67dnl AM_CONDITIONAL: HAVE_DOT
68AC_DEFUN([AC_WITH_DOT],[ 68AC_DEFUN([AC_WITH_DOT],[
69 HAVE_DOT="no" 69 HAVE_DOT="no"
70 AC_PATH_PROG([DOT],[dot],[false]) 70 AC_PATH_PROG([DOT],[dot],[false])
71 if test "${DOT}" = "false" ; then 71 if test "${DOT}" = "false" ; then
72 ifelse([$2], , :, [$2]) 72 ifelse([$2], , :, [$2])
73 else 73 else
74 HAVE_DOT="yes" 74 HAVE_DOT="yes"
75 AC_SUBST([DOT]) 75 AC_SUBST([DOT])
76 $1 76 $1
77 fi 77 fi
78AC_SUBST([HAVE_DOT]) 78AC_SUBST([HAVE_DOT])
79 AM_CONDITIONAL([HAVE_DOT],[test "${HAVE_DOT}" = "yes"]) 79 AM_CONDITIONAL([HAVE_DOT],[test "${HAVE_DOT}" = "yes"])
80]) 80])
81 81
82dnl AC_WITH_PCRE([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) 82dnl AC_WITH_PCRE([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
83dnl Outputs: 83dnl Outputs:
84dnl AC_SUBST: PCRE_CONFIG PCRE_PREFIX PCRE_EXEC_PREFIX 84dnl AC_SUBST: PCRE_CONFIG PCRE_PREFIX PCRE_EXEC_PREFIX
85dnl PCRE_VERSION PCRE_CFLAGS PCRE_LIBS 85dnl PCRE_VERSION PCRE_CFLAGS PCRE_LIBS
86dnl PCRE_LIBS_POSIX PCRE_CFLAGS_POSIX 86dnl PCRE_LIBS_POSIX PCRE_CFLAGS_POSIX
87dnl AM_CONDITIONAL: HAVE_PCRE
88dnl AC_DEFINE: HAVE_PCRE PCRE_VERSION 87dnl AC_DEFINE: HAVE_PCRE PCRE_VERSION
88dnl env: HAVE_PCRE=yes|no
89AC_DEFUN([AC_WITH_PCRE],[ 89AC_DEFUN([AC_WITH_PCRE],[
90 HAVE_PCRE="no" 90 HAVE_PCRE="no"
91 PCRE_CONFIG="" 91 PCRE_CONFIG=""
92 PCRE_PREFIX="" 92 PCRE_PREFIX=""
93 PCRE_EXEC_PREFIX="" 93 PCRE_EXEC_PREFIX=""
94 PCRE_VERSION="" 94 PCRE_VERSION=""
95 PCRE_CFLAGS="" 95 PCRE_CFLAGS=""
96 PCRE_LIBS="" 96 PCRE_LIBS=""
97 PCRE_LOCATIONS="${PATH}:/usr/local/bin:/usr/bin" 97 PCRE_LOCATIONS="${PATH}:/usr/local/bin:/usr/bin"
98 test -z "$WANT_PCRE" && WANT_PCRE="" 98 test -z "$WANT_PCRE" && WANT_PCRE=""
99 AC_ARG_WITH([pcre], 99 AC_ARG_WITH([pcre],
100 AC_HELP_STRING([--with-pcre=location],[Look for pcre in specified locations]), 100 AC_HELP_STRING([--with-pcre=location],[Look for pcre in specified locations]),
101 [ 101 [
102 if test "${withval}" = "no" ; then 102 if test "${withval}" = "no" ; then
103 WANT_PCRE="no" 103 WANT_PCRE="no"
104 else 104 else
105 if test -x "${withval}" ; then 105 if test -x "${withval}" ; then
106 PCRE_CONFIG="${withval}" 106 PCRE_CONFIG="${withval}"
107 elif test -x "${withval}/pcre-config" ; then 107 elif test -x "${withval}/pcre-config" ; then
108 PCRE_CONFIG="${withval}/pcre-config" 108 PCRE_CONFIG="${withval}/pcre-config"
109 elif test -x "${withval}/bin/pcre-config" ; then 109 elif test -x "${withval}/bin/pcre-config" ; then
110 PCRE_CONFIG="${withval}/bin/pcre-config" 110 PCRE_CONFIG="${withval}/bin/pcre-config"
111 fi 111 fi
112 fi 112 fi
113 ] 113 ]
114 ) 114 )
115 if test "${WANT_PCRE}" = "no" ; then 115 if test "${WANT_PCRE}" = "no" ; then
116 ifelse([$2], , :, [$2]) 116 ifelse([$2], , :, [$2])
117 else 117 else
118 if test -z "${PCRE_CONFIG}" ; then 118 if test -z "${PCRE_CONFIG}" ; then
119 AC_PATH_PROG(PCRE_CONFIG,[pcre-config],false,[${PCRE_LOCATIONS}]) 119 AC_PATH_PROG(PCRE_CONFIG,[pcre-config],false,[${PCRE_LOCATIONS}])
120 if test "${PCRE_CONFIG}" = "false" ; then 120 if test "${PCRE_CONFIG}" = "false" ; then
121 ifelse([$2], , :, [$2]) 121 ifelse([$2], , :, [$2])
122 else 122 else
123 HAVE_PCRE="yes" 123 HAVE_PCRE="yes"
124 PCRE_PREFIX="`${PCRE_CONFIG} --prefix`" 124 PCRE_PREFIX="`${PCRE_CONFIG} --prefix`"
125 PCRE_EXEC_PREFIX="`${PCRE_CONFIG} --exec-prefix`" 125 PCRE_EXEC_PREFIX="`${PCRE_CONFIG} --exec-prefix`"
126 PCRE_VERSION="`${PCRE_CONFIG} --version`" 126 PCRE_VERSION="`${PCRE_CONFIG} --version`"
127 PCRE_CFLAGS="`${PCRE_CONFIG} --cflags`" 127 PCRE_CFLAGS="`${PCRE_CONFIG} --cflags`"
128 PCRE_LIBS="`${PCRE_CONFIG} --libs`" 128 PCRE_LIBS="`${PCRE_CONFIG} --libs`"
129 PCRE_CFLAGS_POSIX="`${PCRE_CONFIG} --cflags-posix`" 129 PCRE_CFLAGS_POSIX="`${PCRE_CONFIG} --cflags-posix`"
130 PCRE_LIBS_POSIX="`${PCRE_CONFIG} --libs-posix`" 130 PCRE_LIBS_POSIX="`${PCRE_CONFIG} --libs-posix`"
131 AC_SUBST([PCRE_CONFIG]) 131 AC_SUBST([PCRE_CONFIG])
132 AC_SUBST([PCRE_PREFIX]) 132 AC_SUBST([PCRE_PREFIX])
133 AC_SUBST([PCRE_EXEC_PREFIX]) 133 AC_SUBST([PCRE_EXEC_PREFIX])
134 AC_SUBST([PCRE_VERSION]) 134 AC_SUBST([PCRE_VERSION])
135 AC_SUBST([PCRE_CFLAGS]) 135 AC_SUBST([PCRE_CFLAGS])
136 AC_SUBST([PCRE_LIBS]) 136 AC_SUBST([PCRE_LIBS])
137 AC_SUBST([PCRE_CFLAGS_POSIX]) 137 AC_SUBST([PCRE_CFLAGS_POSIX])
138 AC_SUBST([PCRE_LIBS_POSIX]) 138 AC_SUBST([PCRE_LIBS_POSIX])
139 AC_DEFINE([HAVE_PCRE],,[pcre support]) 139 AC_DEFINE([HAVE_PCRE],,[pcre support])
140 AC_DEFINE_UNQUOTED([PCRE_VERSION],["${PCRE_VERSION}"],[pcre version]) 140 AC_DEFINE_UNQUOTED([PCRE_VERSION],["${PCRE_VERSION}"],[pcre version])
141 $1 141 $1
142 fi 142 fi
143 fi 143 fi
144 fi 144 fi
145 AM_CONDITIONAL([HAVE_PCRE],[test "${HAVE_PCRE}" = "yes"])
146]) 145])
147 146
148dnl AC_WITH_PCREPP([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) 147dnl AC_WITH_PCREPP([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
149dnl Outputs: 148dnl Outputs:
150dnl AC_SUBST: PCREPP_CONFIG PCREPP_PREFIX PCREPP_EXEC_PREFIX 149dnl AC_SUBST: PCREPP_CONFIG PCREPP_PREFIX PCREPP_EXEC_PREFIX
151dnl PCREPP_VERSION PCREPP_CFLAGS PCREPP_LIBS 150dnl PCREPP_VERSION PCREPP_CFLAGS PCREPP_LIBS
152dnl AM_CONDITIONAL: HAVE_PCREPP
153dnl AC_DEFINE: HAVE_PCREPP PCREPP_VERSION 151dnl AC_DEFINE: HAVE_PCREPP PCREPP_VERSION
152dnl env: HAVE_PCREPP=yes|no
154AC_DEFUN([AC_WITH_PCREPP],[ 153AC_DEFUN([AC_WITH_PCREPP],[
155 HAVE_PCREPP="no" 154 HAVE_PCREPP="no"
156 PCREPP_CONFIG="" 155 PCREPP_CONFIG=""
157 PCREPP_PREFIX="" 156 PCREPP_PREFIX=""
158 PCREPP_EXEC_PREFIX="" 157 PCREPP_EXEC_PREFIX=""
159 PCREPP_VERSION="" 158 PCREPP_VERSION=""
160 PCREPP_CFLAGS="" 159 PCREPP_CFLAGS=""
161 PCREPP_LIBS="" 160 PCREPP_LIBS=""
162 PCREPP_LOCATIONS="${PATH}:/usr/local/bin:/usr/bin" 161 PCREPP_LOCATIONS="${PATH}:/usr/local/bin:/usr/bin"
163 test -z "$WANT_PCREPP" && WANT_PCREPP="" 162 test -z "$WANT_PCREPP" && WANT_PCREPP=""
164 AC_ARG_WITH([pcrepp], 163 AC_ARG_WITH([pcrepp],
165 AC_HELP_STRING([--with-pcrepp=location],[Look for pcre++ in specified locations]), 164 AC_HELP_STRING([--with-pcrepp=location],[Look for pcre++ in specified locations]),
166 [ 165 [
167 if test "${withval}" = "no" ; then 166 if test "${withval}" = "no" ; then
168 WANT_PCREPP="no" 167 WANT_PCREPP="no"
169 else 168 else
170 if test -x "${withval}" ; then 169 if test -x "${withval}" ; then
171 PCREPP_CONFIG="${withval}" 170 PCREPP_CONFIG="${withval}"
172 elif test -x "${withval}/pcre++-config" ; then 171 elif test -x "${withval}/pcre++-config" ; then
173 PCREPP_CONFIG="${withval}/pcre++-config" 172 PCREPP_CONFIG="${withval}/pcre++-config"
174 elif test -x "${withval}/bin/pcre++-config" ; then 173 elif test -x "${withval}/bin/pcre++-config" ; then
175 PCREPP_CONFIG="${withval}/bin/pcre++-config" 174 PCREPP_CONFIG="${withval}/bin/pcre++-config"
176 fi 175 fi
177 fi 176 fi
178 ] 177 ]
179 ) 178 )
180 if test "${WANT_PCREPP}" = "no" ; then 179 if test "${WANT_PCREPP}" = "no" ; then
181 ifelse([$2], , :, [$2]) 180 ifelse([$2], , :, [$2])
182 else 181 else
183 if test "${HAVE_PCRE}" != "yes" ; then 182 if test "${HAVE_PCRE}" != "yes" ; then
184 ifelse([$2], , :, [$2]) 183 ifelse([$2], , :, [$2])
185 else 184 else
186 if test -z "${PCREPP_CONFIG}" ; then 185 if test -z "${PCREPP_CONFIG}" ; then
187 AC_PATH_PROG([PCREPP_CONFIG],[pcre++-config],false,[${PCREPP_LOCATIONS}]) 186 AC_PATH_PROG([PCREPP_CONFIG],[pcre++-config],false,[${PCREPP_LOCATIONS}])
188 if test "${PCREPP_CONFIG}" = "false" ; then 187 if test "${PCREPP_CONFIG}" = "false" ; then
189 ifelse([$2], , :, [$2]) 188 ifelse([$2], , :, [$2])
190 else 189 else
191 HAVE_PCREPP="yes" 190 HAVE_PCREPP="yes"
192 PCREPP_PREFIX="`${PCREPP_CONFIG} --prefix`" 191 PCREPP_PREFIX="`${PCREPP_CONFIG} --prefix`"
193 PCREPP_EXEC_PREFIX="`${PCREPP_CONFIG} --exec-prefix`" 192 PCREPP_EXEC_PREFIX="`${PCREPP_CONFIG} --exec-prefix`"
194 PCREPP_VERSION="`${PCREPP_CONFIG} --version`" 193 PCREPP_VERSION="`${PCREPP_CONFIG} --version`"
195 PCREPP_CFLAGS="`${PCREPP_CONFIG} --cflags` ${PCRE_CFLAGS}" 194 PCREPP_CFLAGS="`${PCREPP_CONFIG} --cflags` ${PCRE_CFLAGS}"
196 PCREPP_LIBS="`${PCREPP_CONFIG} --libs` ${PCRE_LIBS}" 195 PCREPP_LIBS="`${PCREPP_CONFIG} --libs` ${PCRE_LIBS}"
197 AC_SUBST([PCREPP_CONFIG]) 196 AC_SUBST([PCREPP_CONFIG])
198 AC_SUBST([PCREPP_PREFIX]) 197 AC_SUBST([PCREPP_PREFIX])
199 AC_SUBST([PCREPP_EXEC_PREFIX]) 198 AC_SUBST([PCREPP_EXEC_PREFIX])
200 AC_SUBST([PCREPP_VERSION]) 199 AC_SUBST([PCREPP_VERSION])
201 AC_SUBST([PCREPP_CFLAGS]) 200 AC_SUBST([PCREPP_CFLAGS])
202 AC_SUBST([PCREPP_LIBS]) 201 AC_SUBST([PCREPP_LIBS])
203 AC_DEFINE([HAVE_PCREPP],,[pcre++ support]) 202 AC_DEFINE([HAVE_PCREPP],,[pcre++ support])
204 AC_DEFINE_UNQUOTED([PCREPP_VERSION],["${PCREPP_VERSION}"],[pcre++ version]) 203 AC_DEFINE_UNQUOTED([PCREPP_VERSION],["${PCREPP_VERSION}"],[pcre++ version])
205 $1 204 $1
206 fi 205 fi
207 fi 206 fi
208 fi 207 fi
209 fi 208 fi
210 AM_CONDITIONAL([HAVE_PCREPP],[test "${HAVE_PCREPP}" = "yes"])
211]) 209])
212 210
213m4_include([acinclude.d/libcurl.m4]) 211m4_include([acinclude.d/libcurl.m4])
diff --git a/configure.ac b/configure.ac
index 2094273..00c6bc4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,95 +1,132 @@
1AC_INIT([libopkele], [0.3], [libopkele-bugs@klever.net]) 1AC_INIT([libopkele], [0.3], [libopkele-bugs@klever.net])
2AC_CONFIG_SRCDIR([include/opkele/opkele-config.h]) 2AC_CONFIG_SRCDIR([include/opkele/opkele-config.h])
3AC_CONFIG_HEADERS([config.h include/opkele/acconfig.h]) 3AC_CONFIG_HEADERS([config.h include/opkele/acconfig.h])
4AM_INIT_AUTOMAKE([dist-bzip2]) 4AM_INIT_AUTOMAKE([dist-bzip2])
5 5
6AC_PROG_INSTALL 6AC_PROG_INSTALL
7AC_PROG_CXX 7AC_PROG_CXX
8AC_PROG_CC 8AC_PROG_CC
9AC_PROG_LIBTOOL 9AC_PROG_LIBTOOL
10 10
11AC_HEADER_STDC 11AC_HEADER_STDC
12 12
13AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) 13AC_PATH_PROG([XSLTPROC],[xsltproc],[true])
14AC_WITH_PKGCONFIG 14AC_WITH_PKGCONFIG
15 15
16PKG_CHECK_MODULES([OPENSSL],[openssl],,[ 16PKG_CHECK_MODULES([OPENSSL],[openssl],,[
17 AC_MSG_ERROR([no openssl library found. get one from http://www.openssl.org/]) 17 AC_MSG_ERROR([no openssl library found. get one from http://www.openssl.org/])
18]) 18])
19 19
20WANT_KONFORKA="yes" 20WANT_KONFORKA="yes"
21AC_ARG_ENABLE([konforka], 21AC_ARG_ENABLE([konforka],
22 AC_HELP_STRING([--disable-konforka],[do not use konforka library (default: use if found)]), 22 AC_HELP_STRING([--disable-konforka],[do not use konforka library (default: use if found)]),
23 [ 23 [
24 test "${enableval}" = "no" && WANT_KONFORKA="no" 24 test "${enableval}" = "no" && WANT_KONFORKA="no"
25 ] 25 ]
26) 26)
27if test "${WANT_KONFORKA}" = "yes" ; then 27if test "${WANT_KONFORKA}" = "yes" ; then
28 PKG_CHECK_MODULES([KONFORKA],[konforka],[ 28 PKG_CHECK_MODULES([KONFORKA],[konforka],[
29 AC_SUBST([KONFORKA_CFLAGS]) 29 AC_SUBST([KONFORKA_CFLAGS])
30 AC_SUBST([KONFORKA_LIBS]) 30 AC_SUBST([KONFORKA_LIBS])
31 AC_DEFINE([HAVE_KONFORKA],,[defined in presence of konforka library]) 31 AC_DEFINE([HAVE_KONFORKA],,[defined in presence of konforka library])
32 AC_DEFINE([OPKELE_HAVE_KONFORKA],,[defined in presence of konforka library]) 32 AC_DEFINE([OPKELE_HAVE_KONFORKA],,[defined in presence of konforka library])
33 AC_SUBST([KONFORKA_KONFORKA],[konforka]) 33 AC_SUBST([KONFORKA_KONFORKA],[konforka])
34 ],[true]) 34 ],[true])
35fi 35fi
36 36
37WANT_DOXYGEN="yes" 37WANT_DOXYGEN="yes"
38AC_ARG_ENABLE([doxygen], 38AC_ARG_ENABLE([doxygen],
39 AC_HELP_STRING([--disable-doxygen],[do not generate documentation]), 39 AC_HELP_STRING([--disable-doxygen],[do not generate documentation]),
40 [ 40 [
41 test "${enableval}" = "no" && WANT_DOXYGEN="no" 41 test "${enableval}" = "no" && WANT_DOXYGEN="no"
42 ] 42 ]
43) 43)
44if test "${WANT_DOXYGEN}" = "yes" ; then 44if test "${WANT_DOXYGEN}" = "yes" ; then
45 AC_WITH_DOXYGEN 45 AC_WITH_DOXYGEN
46 AC_WITH_DOT 46 AC_WITH_DOT
47else 47else
48 AM_CONDITIONAL([HAVE_DOXYGEN],[false]) 48 AM_CONDITIONAL([HAVE_DOXYGEN],[false])
49 AM_CONDITIONAL([HAVE_DOT],[false]) 49 AM_CONDITIONAL([HAVE_DOT],[false])
50fi 50fi
51 51
52LIBCURL_CHECK_CONFIG(,,,[ 52LIBCURL_CHECK_CONFIG(,,,[
53 AC_MSG_ERROR([no required libcurl library. get one from http://curl.haxx.se/]) 53 AC_MSG_ERROR([no required libcurl library. get one from http://curl.haxx.se/])
54]) 54])
55AC_WITH_PCRE([ 55
56 AC_WITH_PCREPP(,[ 56want_pcre_impl=""
57 AC_MSG_ERROR([no pcre++ library found. get one at http://www.daemon.de/PCRE]) 57AC_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 ]
62) 67)
63 68
69found_pcre_impl=""
70
71if 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])
81fi
82
83if 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 )
93fi
94test "$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
96case "$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]) ;;
99esac
100
64curl_ssl_verify_host="true" 101curl_ssl_verify_host="true"
65AC_ARG_ENABLE([ssl-verify-host], 102AC_ARG_ENABLE([ssl-verify-host],
66 AC_HELP_STRING([--disable-ssl-verify-host],[disable cURL cert/host relationships verification]), 103 AC_HELP_STRING([--disable-ssl-verify-host],[disable cURL cert/host relationships verification]),
67 [ test "${enableval}" = "no" && curl_ssl_verify_host="false" ] 104 [ test "${enableval}" = "no" && curl_ssl_verify_host="false" ]
68) 105)
69${curl_ssl_verify_host} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYHOST],,[defined if cURL is not to verify cert/host]) 106${curl_ssl_verify_host} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYHOST],,[defined if cURL is not to verify cert/host])
70 107
71curl_ssl_verify_peer="true" 108curl_ssl_verify_peer="true"
72AC_ARG_ENABLE([ssl-verify-peer], 109AC_ARG_ENABLE([ssl-verify-peer],
73 AC_HELP_STRING([--disable-ssl-verify-peer],[disable cURL cert validity verification]), 110 AC_HELP_STRING([--disable-ssl-verify-peer],[disable cURL cert validity verification]),
74 [ test "${enableval}" = "no" && curl_ssl_verify_peer="false" ] 111 [ test "${enableval}" = "no" && curl_ssl_verify_peer="false" ]
75) 112)
76${curl_ssl_verify_peer} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYPEER],,[defined if cURL is not to verify cert validity]) 113${curl_ssl_verify_peer} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYPEER],,[defined if cURL is not to verify cert validity])
77 114
78postels_law=true 115postels_law=true
79AC_ARG_ENABLE([postels-law], 116AC_ARG_ENABLE([postels-law],
80 AC_HELP_STRING([--disable-postels-law],[Be strict, do not adhere to Postel's Law ("be conservative in what you do, be liberal in what you accept from others", RFC 793)]), 117 AC_HELP_STRING([--disable-postels-law],[Be strict, do not adhere to Postel's Law ("be conservative in what you do, be liberal in what you accept from others", RFC 793)]),
81 [ test "${enableval}" = "no" && postels_law=false ] 118 [ test "${enableval}" = "no" && postels_law=false ]
82) 119)
83$postels_law && AC_DEFINE([POSTELS_LAW],,[defined if we want to adhere to Postel's Law]) 120$postels_law && AC_DEFINE([POSTELS_LAW],,[defined if we want to adhere to Postel's Law])
84 121
85AC_DEFINE_UNQUOTED([OPKELE_SRC_DIR],["$PWD"],[source directory]) 122AC_DEFINE_UNQUOTED([OPKELE_SRC_DIR],["$PWD"],[source directory])
86 123
87AC_CONFIG_FILES([ 124AC_CONFIG_FILES([
88 Makefile 125 Makefile
89 libopkele.pc 126 libopkele.pc
90 Doxyfile 127 Doxyfile
91 include/Makefile 128 include/Makefile
92 lib/Makefile 129 lib/Makefile
93 test/Makefile 130 test/Makefile
94]) 131])
95AC_OUTPUT 132AC_OUTPUT
diff --git a/lib/consumer.cc b/lib/consumer.cc
index 8f66688..299b3bc 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -1,371 +1,412 @@
1#include <algorithm> 1#include <algorithm>
2#include <cassert> 2#include <cassert>
3#include <opkele/util.h> 3#include <opkele/util.h>
4#include <opkele/exception.h> 4#include <opkele/exception.h>
5#include <opkele/data.h> 5#include <opkele/data.h>
6#include <opkele/consumer.h> 6#include <opkele/consumer.h>
7#include <openssl/sha.h> 7#include <openssl/sha.h>
8#include <openssl/hmac.h> 8#include <openssl/hmac.h>
9#include <curl/curl.h> 9#include <curl/curl.h>
10#include <pcre++.h>
11 10
12#include <iostream> 11#include <iostream>
13 12
14#include "config.h" 13#include "config.h"
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
16namespace opkele { 23namespace opkele {
17 using namespace std; 24 using namespace std;
18 25
19 class curl_t { 26 class curl_t {
20 public: 27 public:
21 CURL *_c; 28 CURL *_c;
22 29
23 curl_t() : _c(0) { } 30 curl_t() : _c(0) { }
24 curl_t(CURL *c) : _c(c) { } 31 curl_t(CURL *c) : _c(c) { }
25 ~curl_t() throw() { if(_c) curl_easy_cleanup(_c); } 32 ~curl_t() throw() { if(_c) curl_easy_cleanup(_c); }
26 33
27 curl_t& operator=(CURL *c) { if(_c) curl_easy_cleanup(_c); _c=c; return *this; } 34 curl_t& operator=(CURL *c) { if(_c) curl_easy_cleanup(_c); _c=c; return *this; }
28 35
29 operator const CURL*(void) const { return _c; } 36 operator const CURL*(void) const { return _c; }
30 operator CURL*(void) { return _c; } 37 operator CURL*(void) { return _c; }
31 }; 38 };
32 39
33 static CURLcode curl_misc_sets(CURL* c) { 40 static CURLcode curl_misc_sets(CURL* c) {
34 CURLcode r; 41 CURLcode r;
35 (r=curl_easy_setopt(c,CURLOPT_FOLLOWLOCATION,1)) 42 (r=curl_easy_setopt(c,CURLOPT_FOLLOWLOCATION,1))
36 || (r=curl_easy_setopt(c,CURLOPT_MAXREDIRS,5)) 43 || (r=curl_easy_setopt(c,CURLOPT_MAXREDIRS,5))
37 || (r=curl_easy_setopt(c,CURLOPT_DNS_CACHE_TIMEOUT,120)) 44 || (r=curl_easy_setopt(c,CURLOPT_DNS_CACHE_TIMEOUT,120))
38 || (r=curl_easy_setopt(c,CURLOPT_DNS_USE_GLOBAL_CACHE,1)) 45 || (r=curl_easy_setopt(c,CURLOPT_DNS_USE_GLOBAL_CACHE,1))
39 || (r=curl_easy_setopt(c,CURLOPT_USERAGENT,PACKAGE_NAME"/"PACKAGE_VERSION)) 46 || (r=curl_easy_setopt(c,CURLOPT_USERAGENT,PACKAGE_NAME"/"PACKAGE_VERSION))
40 || (r=curl_easy_setopt(c,CURLOPT_TIMEOUT,20)) 47 || (r=curl_easy_setopt(c,CURLOPT_TIMEOUT,20))
41 #ifdefDISABLE_CURL_SSL_VERIFYHOST 48 #ifdefDISABLE_CURL_SSL_VERIFYHOST
42 || (r=curl_easy_setopt(c,CURLOPT_SSL_VERIFYHOST,0)) 49 || (r=curl_easy_setopt(c,CURLOPT_SSL_VERIFYHOST,0))
43#endif 50#endif
44 #ifdefDISABLE_CURL_SSL_VERIFYPEER 51 #ifdefDISABLE_CURL_SSL_VERIFYPEER
45 || (r=curl_easy_setopt(c,CURLOPT_SSL_VERIFYPEER,0)) 52 || (r=curl_easy_setopt(c,CURLOPT_SSL_VERIFYPEER,0))
46#endif 53#endif
47 ; 54 ;
48 return r; 55 return r;
49 } 56 }
50 57
51 static size_t _curl_tostring(void *ptr,size_t size,size_t nmemb,void *stream) { 58 static size_t _curl_tostring(void *ptr,size_t size,size_t nmemb,void *stream) {
52 string *str = (string*)stream; 59 string *str = (string*)stream;
53 size_t bytes = size*nmemb; 60 size_t bytes = size*nmemb;
54 size_t get = min(16384-str->length(),bytes); 61 size_t get = min(16384-str->length(),bytes);
55 str->append((const char*)ptr,get); 62 str->append((const char*)ptr,get);
56 return get; 63 return get;
57 } 64 }
58 65
59 assoc_t consumer_t::associate(const string& server) { 66 assoc_t consumer_t::associate(const string& server) {
60 util::dh_t dh = DH_new(); 67 util::dh_t dh = DH_new();
61 if(!dh) 68 if(!dh)
62 throw exception_openssl(OPKELE_CP_ "failed to DH_new()"); 69 throw exception_openssl(OPKELE_CP_ "failed to DH_new()");
63 dh->p = util::dec_to_bignum(data::_default_p); 70 dh->p = util::dec_to_bignum(data::_default_p);
64 dh->g = util::dec_to_bignum(data::_default_g); 71 dh->g = util::dec_to_bignum(data::_default_g);
65 if(!DH_generate_key(dh)) 72 if(!DH_generate_key(dh))
66 throw exception_openssl(OPKELE_CP_ "failed to DH_generate_key()"); 73 throw exception_openssl(OPKELE_CP_ "failed to DH_generate_key()");
67 string request = 74 string request =
68 "openid.mode=associate" 75 "openid.mode=associate"
69 "&openid.assoc_type=HMAC-SHA1" 76 "&openid.assoc_type=HMAC-SHA1"
70 "&openid.session_type=DH-SHA1" 77 "&openid.session_type=DH-SHA1"
71 "&openid.dh_consumer_public="; 78 "&openid.dh_consumer_public=";
72 request += util::url_encode(util::bignum_to_base64(dh->pub_key)); 79 request += util::url_encode(util::bignum_to_base64(dh->pub_key));
73 curl_t curl = curl_easy_init(); 80 curl_t curl = curl_easy_init();
74 if(!curl) 81 if(!curl)
75 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); 82 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()");
76 string response; 83 string response;
77 CURLcode r; 84 CURLcode r;
78 (r=curl_misc_sets(curl)) 85 (r=curl_misc_sets(curl))
79 || (r=curl_easy_setopt(curl,CURLOPT_URL,server.c_str())) 86 || (r=curl_easy_setopt(curl,CURLOPT_URL,server.c_str()))
80 || (r=curl_easy_setopt(curl,CURLOPT_POST,1)) 87 || (r=curl_easy_setopt(curl,CURLOPT_POST,1))
81 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDS,request.data())) 88 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDS,request.data()))
82 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,request.length())) 89 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,request.length()))
83 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring)) 90 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring))
84 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&response)) 91 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&response))
85 ; 92 ;
86 if(r) 93 if(r)
87 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r); 94 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r);
88 if(r=curl_easy_perform(curl)) 95 if(r=curl_easy_perform(curl))
89 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r); 96 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r);
90 params_t p; p.parse_keyvalues(response); 97 params_t p; p.parse_keyvalues(response);
91 if(p.has_param("assoc_type") && p.get_param("assoc_type")!="HMAC-SHA1") 98 if(p.has_param("assoc_type") && p.get_param("assoc_type")!="HMAC-SHA1")
92 throw bad_input(OPKELE_CP_ "unsupported assoc_type"); 99 throw bad_input(OPKELE_CP_ "unsupported assoc_type");
93 string st; 100 string st;
94 if(p.has_param("session_type")) st = p.get_param("session_type"); 101 if(p.has_param("session_type")) st = p.get_param("session_type");
95 if((!st.empty()) && st!="DH-SHA1") 102 if((!st.empty()) && st!="DH-SHA1")
96 throw bad_input(OPKELE_CP_ "unsupported session_type"); 103 throw bad_input(OPKELE_CP_ "unsupported session_type");
97 secret_t secret; 104 secret_t secret;
98 if(st.empty()) { 105 if(st.empty()) {
99 secret.from_base64(p.get_param("mac_key")); 106 secret.from_base64(p.get_param("mac_key"));
100 }else{ 107 }else{
101 util::bignum_t s_pub = util::base64_to_bignum(p.get_param("dh_server_public")); 108 util::bignum_t s_pub = util::base64_to_bignum(p.get_param("dh_server_public"));
102 vector<unsigned char> ck(DH_size(dh)+1); 109 vector<unsigned char> ck(DH_size(dh)+1);
103 unsigned char *ckptr = &(ck.front())+1; 110 unsigned char *ckptr = &(ck.front())+1;
104 int cklen = DH_compute_key(ckptr,s_pub,dh); 111 int cklen = DH_compute_key(ckptr,s_pub,dh);
105 if(cklen<0) 112 if(cklen<0)
106 throw exception_openssl(OPKELE_CP_ "failed to DH_compute_key()"); 113 throw exception_openssl(OPKELE_CP_ "failed to DH_compute_key()");
107 if(cklen && (*ckptr)&0x80) { 114 if(cklen && (*ckptr)&0x80) {
108 (*(--ckptr)) = 0; ++cklen; 115 (*(--ckptr)) = 0; ++cklen;
109 } 116 }
110 unsigned char key_sha1[SHA_DIGEST_LENGTH]; 117 unsigned char key_sha1[SHA_DIGEST_LENGTH];
111 SHA1(ckptr,cklen,key_sha1); 118 SHA1(ckptr,cklen,key_sha1);
112 secret.enxor_from_base64(key_sha1,p.get_param("enc_mac_key")); 119 secret.enxor_from_base64(key_sha1,p.get_param("enc_mac_key"));
113 } 120 }
114 int expires_in = 0; 121 int expires_in = 0;
115 if(p.has_param("expires_in")) { 122 if(p.has_param("expires_in")) {
116 expires_in = util::string_to_long(p.get_param("expires_in")); 123 expires_in = util::string_to_long(p.get_param("expires_in"));
117 }else if(p.has_param("issued") && p.has_param("expiry")) { 124 }else if(p.has_param("issued") && p.has_param("expiry")) {
118 expires_in = util::w3c_to_time(p.get_param("expiry"))-util::w3c_to_time(p.get_param("issued")); 125 expires_in = util::w3c_to_time(p.get_param("expiry"))-util::w3c_to_time(p.get_param("issued"));
119 }else 126 }else
120 throw bad_input(OPKELE_CP_ "no expiration information"); 127 throw bad_input(OPKELE_CP_ "no expiration information");
121 return store_assoc(server,p.get_param("assoc_handle"),secret,expires_in); 128 return store_assoc(server,p.get_param("assoc_handle"),secret,expires_in);
122 } 129 }
123 130
124 string consumer_t::checkid_immediate(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) { 131 string consumer_t::checkid_immediate(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) {
125 return checkid_(mode_checkid_immediate,identity,return_to,trust_root,ext); 132 return checkid_(mode_checkid_immediate,identity,return_to,trust_root,ext);
126 } 133 }
127 string consumer_t::checkid_setup(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) { 134 string consumer_t::checkid_setup(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) {
128 return checkid_(mode_checkid_setup,identity,return_to,trust_root,ext); 135 return checkid_(mode_checkid_setup,identity,return_to,trust_root,ext);
129 } 136 }
130 string consumer_t::checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root,extension_t *ext) { 137 string consumer_t::checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root,extension_t *ext) {
131 params_t p; 138 params_t p;
132 if(mode==mode_checkid_immediate) 139 if(mode==mode_checkid_immediate)
133 p["mode"]="checkid_immediate"; 140 p["mode"]="checkid_immediate";
134 else if(mode==mode_checkid_setup) 141 else if(mode==mode_checkid_setup)
135 p["mode"]="checkid_setup"; 142 p["mode"]="checkid_setup";
136 else 143 else
137 throw bad_input(OPKELE_CP_ "unknown checkid_* mode"); 144 throw bad_input(OPKELE_CP_ "unknown checkid_* mode");
138 string iurl = canonicalize(identity); 145 string iurl = canonicalize(identity);
139 string server, delegate; 146 string server, delegate;
140 retrieve_links(iurl,server,delegate); 147 retrieve_links(iurl,server,delegate);
141 p["identity"] = delegate.empty()?iurl:delegate; 148 p["identity"] = delegate.empty()?iurl:delegate;
142 if(!trust_root.empty()) 149 if(!trust_root.empty())
143 p["trust_root"] = trust_root; 150 p["trust_root"] = trust_root;
144 p["return_to"] = return_to; 151 p["return_to"] = return_to;
145 try { 152 try {
146 string ah = find_assoc(server)->handle(); 153 string ah = find_assoc(server)->handle();
147 p["assoc_handle"] = ah; 154 p["assoc_handle"] = ah;
148 }catch(failed_lookup& fl) { 155 }catch(failed_lookup& fl) {
149 string ah = associate(server)->handle(); 156 string ah = associate(server)->handle();
150 p["assoc_handle"] = ah; 157 p["assoc_handle"] = ah;
151 } 158 }
152 if(ext) ext->checkid_hook(p,identity); 159 if(ext) ext->checkid_hook(p,identity);
153 return p.append_query(server); 160 return p.append_query(server);
154 } 161 }
155 162
156 void consumer_t::id_res(const params_t& pin,const string& identity,extension_t *ext) { 163 void consumer_t::id_res(const params_t& pin,const string& identity,extension_t *ext) {
157 if(pin.has_param("openid.user_setup_url")) 164 if(pin.has_param("openid.user_setup_url"))
158 throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); 165 throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url"));
159 string server,delegate; 166 string server,delegate;
160 retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate); 167 retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate);
161 params_t ps; 168 params_t ps;
162 try { 169 try {
163 assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); 170 assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle"));
164 if(assoc->is_expired()) /* TODO: or should I throw some other exception to force programmer fix his implementation? */ 171 if(assoc->is_expired()) /* TODO: or should I throw some other exception to force programmer fix his implementation? */
165 throw failed_lookup(OPKELE_CP_ "retrieve_assoc() has returned expired handle"); 172 throw failed_lookup(OPKELE_CP_ "retrieve_assoc() has returned expired handle");
166 const string& sigenc = pin.get_param("openid.sig"); 173 const string& sigenc = pin.get_param("openid.sig");
167 vector<unsigned char> sig; 174 vector<unsigned char> sig;
168 util::decode_base64(sigenc,sig); 175 util::decode_base64(sigenc,sig);
169 const string& slist = pin.get_param("openid.signed"); 176 const string& slist = pin.get_param("openid.signed");
170 string kv; 177 string kv;
171 string::size_type p = 0; 178 string::size_type p = 0;
172 while(true) { 179 while(true) {
173 string::size_type co = slist.find(',',p); 180 string::size_type co = slist.find(',',p);
174 string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p); 181 string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p);
175 kv += f; 182 kv += f;
176 kv += ':'; 183 kv += ':';
177 f.insert(0,"openid."); 184 f.insert(0,"openid.");
178 kv += pin.get_param(f); 185 kv += pin.get_param(f);
179 kv += '\n'; 186 kv += '\n';
180 if(ext) ps[f.substr(sizeof("openid.")-1)] = pin.get_param(f); 187 if(ext) ps[f.substr(sizeof("openid.")-1)] = pin.get_param(f);
181 if(co==string::npos) 188 if(co==string::npos)
182 break; 189 break;
183 p = co+1; 190 p = co+1;
184 } 191 }
185 secret_t secret = assoc->secret(); 192 secret_t secret = assoc->secret();
186 unsigned int md_len = 0; 193 unsigned int md_len = 0;
187 unsigned char *md = HMAC( 194 unsigned char *md = HMAC(
188 EVP_sha1(), 195 EVP_sha1(),
189 &(secret.front()),secret.size(), 196 &(secret.front()),secret.size(),
190 (const unsigned char *)kv.data(),kv.length(), 197 (const unsigned char *)kv.data(),kv.length(),
191 0,&md_len); 198 0,&md_len);
192 if(sig.size()!=md_len || memcmp(&(sig.front()),md,md_len)) 199 if(sig.size()!=md_len || memcmp(&(sig.front()),md,md_len))
193 throw id_res_mismatch(OPKELE_CP_ "signature mismatch"); 200 throw id_res_mismatch(OPKELE_CP_ "signature mismatch");
194 }catch(failed_lookup& e) { /* XXX: more specific? */ 201 }catch(failed_lookup& e) { /* XXX: more specific? */
195 const string& slist = pin.get_param("openid.signed"); 202 const string& slist = pin.get_param("openid.signed");
196 string::size_type pp = 0; 203 string::size_type pp = 0;
197 params_t p; 204 params_t p;
198 while(true) { 205 while(true) {
199 string::size_type co = slist.find(',',pp); 206 string::size_type co = slist.find(',',pp);
200 string f = "openid."; 207 string f = "openid.";
201 f += (co==string::npos)?slist.substr(pp):slist.substr(pp,co-pp); 208 f += (co==string::npos)?slist.substr(pp):slist.substr(pp,co-pp);
202 p[f] = pin.get_param(f); 209 p[f] = pin.get_param(f);
203 if(co==string::npos) 210 if(co==string::npos)
204 break; 211 break;
205 pp = co+1; 212 pp = co+1;
206 } 213 }
207 p["openid.assoc_handle"] = pin.get_param("openid.assoc_handle"); 214 p["openid.assoc_handle"] = pin.get_param("openid.assoc_handle");
208 p["openid.sig"] = pin.get_param("openid.sig"); 215 p["openid.sig"] = pin.get_param("openid.sig");
209 p["openid.signed"] = pin.get_param("openid.signed"); 216 p["openid.signed"] = pin.get_param("openid.signed");
210 try { 217 try {
211 string ih = pin.get_param("openid.invalidate_handle"); 218 string ih = pin.get_param("openid.invalidate_handle");
212 p["openid.invalidate_handle"] = ih; 219 p["openid.invalidate_handle"] = ih;
213 }catch(failed_lookup& fl) { } 220 }catch(failed_lookup& fl) { }
214 try { 221 try {
215 check_authentication(server,p); 222 check_authentication(server,p);
216 }catch(failed_check_authentication& fca) { 223 }catch(failed_check_authentication& fca) {
217 throw id_res_failed(OPKELE_CP_ "failed to check_authentication()"); 224 throw id_res_failed(OPKELE_CP_ "failed to check_authentication()");
218 } 225 }
219 } 226 }
220 if(ext) ext->id_res_hook(pin,ps,identity); 227 if(ext) ext->id_res_hook(pin,ps,identity);
221 } 228 }
222 229
223 void consumer_t::check_authentication(const string& server,const params_t& p) { 230 void consumer_t::check_authentication(const string& server,const params_t& p) {
224 string request = "openid.mode=check_authentication"; 231 string request = "openid.mode=check_authentication";
225 for(params_t::const_iterator i=p.begin();i!=p.end();++i) { 232 for(params_t::const_iterator i=p.begin();i!=p.end();++i) {
226 if(i->first!="openid.mode") { 233 if(i->first!="openid.mode") {
227 request += '&'; 234 request += '&';
228 request += i->first; 235 request += i->first;
229 request += '='; 236 request += '=';
230 request += util::url_encode(i->second); 237 request += util::url_encode(i->second);
231 } 238 }
232 } 239 }
233 curl_t curl = curl_easy_init(); 240 curl_t curl = curl_easy_init();
234 if(!curl) 241 if(!curl)
235 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); 242 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()");
236 string response; 243 string response;
237 CURLcode r; 244 CURLcode r;
238 (r=curl_misc_sets(curl)) 245 (r=curl_misc_sets(curl))
239 || (r=curl_easy_setopt(curl,CURLOPT_URL,server.c_str())) 246 || (r=curl_easy_setopt(curl,CURLOPT_URL,server.c_str()))
240 || (r=curl_easy_setopt(curl,CURLOPT_POST,1)) 247 || (r=curl_easy_setopt(curl,CURLOPT_POST,1))
241 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDS,request.data())) 248 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDS,request.data()))
242 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,request.length())) 249 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,request.length()))
243 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring)) 250 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring))
244 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&response)) 251 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&response))
245 ; 252 ;
246 if(r) 253 if(r)
247 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r); 254 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r);
248 if(r=curl_easy_perform(curl)) 255 if(r=curl_easy_perform(curl))
249 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r); 256 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r);
250 params_t pp; pp.parse_keyvalues(response); 257 params_t pp; pp.parse_keyvalues(response);
251 if(pp.has_param("invalidate_handle")) 258 if(pp.has_param("invalidate_handle"))
252 invalidate_assoc(server,pp.get_param("invalidate_handle")); 259 invalidate_assoc(server,pp.get_param("invalidate_handle"));
253 if(pp.has_param("is_valid")) { 260 if(pp.has_param("is_valid")) {
254 if(pp.get_param("is_valid")=="true") 261 if(pp.get_param("is_valid")=="true")
255 return; 262 return;
256 }else if(pp.has_param("lifetime")) { 263 }else if(pp.has_param("lifetime")) {
257 if(util::string_to_long(pp.get_param("lifetime"))) 264 if(util::string_to_long(pp.get_param("lifetime")))
258 return; 265 return;
259 } 266 }
260 throw failed_check_authentication(OPKELE_CP_ "failed to verify response"); 267 throw failed_check_authentication(OPKELE_CP_ "failed to verify response");
261 } 268 }
262 269
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();
265 delegate.erase(); 273 delegate.erase();
266 curl_t curl = curl_easy_init(); 274 curl_t curl = curl_easy_init();
267 if(!curl) 275 if(!curl)
268 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); 276 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()");
269 string html; 277 string html;
270 CURLcode r; 278 CURLcode r;
271 (r=curl_misc_sets(curl)) 279 (r=curl_misc_sets(curl))
272 || (r=curl_easy_setopt(curl,CURLOPT_URL,url.c_str())) 280 || (r=curl_easy_setopt(curl,CURLOPT_URL,url.c_str()))
273 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring)) 281 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring))
274 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&html)) 282 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&html))
275 ; 283 ;
276 if(r) 284 if(r)
277 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r); 285 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r);
278 r = curl_easy_perform(curl); 286 r = curl_easy_perform(curl);
279 if(r && r!=CURLE_WRITE_ERROR) 287 if(r && r!=CURLE_WRITE_ERROR)
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))
287 throw bad_input(OPKELE_CP_ "failed to find head"); 324 throw bad_input(OPKELE_CP_ "failed to find head");
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)) {
293 string attrs = lre[0]; 328 string attrs = lre[0];
294 html.erase(0,lre.get_match_end()+1); 329 html.erase(0,lre.get_match_end()+1);
295 if(!(rre.search(attrs)&&hre.search(attrs))) 330 if(!(rre.search(attrs)&&hre.search(attrs)))
296 continue; 331 continue;
297 if(rre[0]=="openid.server") { 332 if(rre[0]=="openid.server") {
298 server = hre[0]; 333 server = hre[0];
299 if(!delegate.empty()) 334 if(!delegate.empty())
300 break; 335 break;
301 }else if(rre[0]=="openid.delegate") { 336 }else if(rre[0]=="openid.delegate") {
302 delegate = hre[0]; 337 delegate = hre[0];
303 if(!server.empty()) 338 if(!server.empty())
304 break; 339 break;
305 } 340 }
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 }
310 351
311 assoc_t consumer_t::find_assoc(const string& server) { 352 assoc_t consumer_t::find_assoc(const string& server) {
312 throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); 353 throw failed_lookup(OPKELE_CP_ "no find_assoc() provided");
313 } 354 }
314 355
315 string consumer_t::normalize(const string& url) { 356 string consumer_t::normalize(const string& url) {
316 string rv = url; 357 string rv = url;
317 // strip leading and trailing spaces 358 // strip leading and trailing spaces
318 string::size_type i = rv.find_first_not_of(" \t\r\n"); 359 string::size_type i = rv.find_first_not_of(" \t\r\n");
319 if(i==string::npos) 360 if(i==string::npos)
320 throw bad_input(OPKELE_CP_ "empty URL"); 361 throw bad_input(OPKELE_CP_ "empty URL");
321 if(i) 362 if(i)
322 rv.erase(0,i); 363 rv.erase(0,i);
323 i = rv.find_last_not_of(" \t\r\n"); 364 i = rv.find_last_not_of(" \t\r\n");
324 assert(i!=string::npos); 365 assert(i!=string::npos);
325 if(i<(rv.length()-1)) 366 if(i<(rv.length()-1))
326 rv.erase(i+1); 367 rv.erase(i+1);
327 // add missing http:// 368 // add missing http://
328 i = rv.find("://"); 369 i = rv.find("://");
329 if(i==string::npos) { // primitive. but do we need more? 370 if(i==string::npos) { // primitive. but do we need more?
330 rv.insert(0,"http://"); 371 rv.insert(0,"http://");
331 i = sizeof("http://")-1; 372 i = sizeof("http://")-1;
332 }else{ 373 }else{
333 i += sizeof("://")-1; 374 i += sizeof("://")-1;
334 } 375 }
335 string::size_type qm = rv.find('?',i); 376 string::size_type qm = rv.find('?',i);
336 string::size_type sl = rv.find('/',i); 377 string::size_type sl = rv.find('/',i);
337 if(qm!=string::npos) { 378 if(qm!=string::npos) {
338 if(sl==string::npos || sl>qm) 379 if(sl==string::npos || sl>qm)
339 rv.insert(qm,1,'/'); 380 rv.insert(qm,1,'/');
340 }else{ 381 }else{
341 if(sl==string::npos) 382 if(sl==string::npos)
342 rv += '/'; 383 rv += '/';
343 } 384 }
344 return rv; 385 return rv;
345 } 386 }
346 387
347 string consumer_t::canonicalize(const string& url) { 388 string consumer_t::canonicalize(const string& url) {
348 string rv = normalize(url); 389 string rv = normalize(url);
349 curl_t curl = curl_easy_init(); 390 curl_t curl = curl_easy_init();
350 if(!curl) 391 if(!curl)
351 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); 392 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()");
352 string html; 393 string html;
353 CURLcode r; 394 CURLcode r;
354 (r=curl_misc_sets(curl)) 395 (r=curl_misc_sets(curl))
355 || (r=curl_easy_setopt(curl,CURLOPT_URL,rv.c_str())) 396 || (r=curl_easy_setopt(curl,CURLOPT_URL,rv.c_str()))
356 || (r=curl_easy_setopt(curl,CURLOPT_NOBODY,1)) 397 || (r=curl_easy_setopt(curl,CURLOPT_NOBODY,1))
357 ; 398 ;
358 if(r) 399 if(r)
359 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r); 400 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r);
360 r = curl_easy_perform(curl); 401 r = curl_easy_perform(curl);
361 if(r) 402 if(r)
362 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r); 403 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r);
363 const char *eu = 0; 404 const char *eu = 0;
364 r = curl_easy_getinfo(curl,CURLINFO_EFFECTIVE_URL,&eu); 405 r = curl_easy_getinfo(curl,CURLINFO_EFFECTIVE_URL,&eu);
365 if(r) 406 if(r)
366 throw exception_curl(OPKELE_CP_ "failed to curl_easy_getinfo(..CURLINFO_EFFECTIVE_URL..)",r); 407 throw exception_curl(OPKELE_CP_ "failed to curl_easy_getinfo(..CURLINFO_EFFECTIVE_URL..)",r);
367 rv = eu; 408 rv = eu;
368 return normalize(rv); 409 return normalize(rv);
369 } 410 }
370 411
371} 412}