-rw-r--r-- | lib/consumer.cc | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc index 9f7530f..3c3b4f8 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -4,51 +4,33 @@ | |||
4 | #include <opkele/util.h> | 4 | #include <opkele/util.h> |
5 | #include <opkele/curl.h> | 5 | #include <opkele/curl.h> |
6 | #include <opkele/exception.h> | 6 | #include <opkele/exception.h> |
7 | #include <opkele/data.h> | 7 | #include <opkele/data.h> |
8 | #include <opkele/consumer.h> | 8 | #include <opkele/consumer.h> |
9 | #include <openssl/sha.h> | 9 | #include <openssl/sha.h> |
10 | #include <openssl/hmac.h> | 10 | #include <openssl/hmac.h> |
11 | #include <iostream> | 11 | #include <iostream> |
12 | 12 | ||
13 | #include "config.h" | 13 | #include "config.h" |
14 | 14 | ||
15 | #include <pcre.h> | 15 | #include <pcre.h> |
16 | 16 | ||
17 | namespace opkele { | 17 | namespace opkele { |
18 | using namespace std; | 18 | using namespace std; |
19 | using util::curl_t; | 19 | using util::curl_t; |
20 | 20 | using util::curl_pick_t; | |
21 | template<int lim> | ||
22 | class curl_fetch_string_t : public curl_t { | ||
23 | public: | ||
24 | curl_fetch_string_t(CURL *c) | ||
25 | : curl_t(c) { } | ||
26 | ~curl_fetch_string_t() throw() { } | ||
27 | |||
28 | string response; | ||
29 | |||
30 | size_t write(void *p,size_t size,size_t nmemb) { | ||
31 | size_t bytes = size*nmemb; | ||
32 | size_t get = min(lim-response.length(),bytes); | ||
33 | response.append((const char *)p,get); | ||
34 | return get; | ||
35 | } | ||
36 | }; | ||
37 | |||
38 | typedef curl_fetch_string_t<16384> curl_pick_t; | ||
39 | 21 | ||
40 | class pcre_matches_t { | 22 | class pcre_matches_t { |
41 | public: | 23 | public: |
42 | int *_ov; | 24 | int *_ov; |
43 | int _s; | 25 | int _s; |
44 | 26 | ||
45 | pcre_matches_t() : _ov(0), _s(0) { } | 27 | pcre_matches_t() : _ov(0), _s(0) { } |
46 | pcre_matches_t(int s) : _ov(0), _s(s) { | 28 | pcre_matches_t(int s) : _ov(0), _s(s) { |
47 | if(_s&1) ++_s; | 29 | if(_s&1) ++_s; |
48 | _s += _s>>1; | 30 | _s += _s>>1; |
49 | _ov = new int[_s]; | 31 | _ov = new int[_s]; |
50 | } | 32 | } |
51 | ~pcre_matches_t() throw() { if(_ov) delete[] _ov; } | 33 | ~pcre_matches_t() throw() { if(_ov) delete[] _ov; } |
52 | 34 | ||
53 | int begin(int i) const { return _ov[i<<1]; } | 35 | int begin(int i) const { return _ov[i<<1]; } |
54 | int end(int i) const { return _ov[(i<<1)+1]; } | 36 | int end(int i) const { return _ov[(i<<1)+1]; } |