-rw-r--r-- | include/opkele/curl.h | 24 | ||||
-rw-r--r-- | lib/consumer.cc | 20 |
2 files changed, 25 insertions, 19 deletions
diff --git a/include/opkele/curl.h b/include/opkele/curl.h index 8020b63..5cf8e48 100644 --- a/include/opkele/curl.h +++ b/include/opkele/curl.h | |||
@@ -2,9 +2,13 @@ | |||
2 | #define __OPKELE_CURL_H | 2 | #define __OPKELE_CURL_H |
3 | 3 | ||
4 | #include <cassert> | 4 | #include <cassert> |
5 | #include <string> | ||
6 | #include <algorithm> | ||
5 | #include <curl/curl.h> | 7 | #include <curl/curl.h> |
6 | 8 | ||
7 | namespace opkele { | 9 | namespace opkele { |
10 | using std::min; | ||
11 | using std::string; | ||
8 | 12 | ||
9 | namespace util { | 13 | namespace util { |
10 | 14 | ||
@@ -41,6 +45,26 @@ namespace opkele { | |||
41 | CURLcode set_header(); | 45 | CURLcode set_header(); |
42 | }; | 46 | }; |
43 | 47 | ||
48 | template<int lim> | ||
49 | class curl_fetch_string_t : public curl_t { | ||
50 | public: | ||
51 | curl_fetch_string_t(CURL *c) | ||
52 | : curl_t(c) { } | ||
53 | ~curl_fetch_string_t() throw() { } | ||
54 | |||
55 | string response; | ||
56 | |||
57 | size_t write(void *p,size_t size,size_t nmemb) { | ||
58 | size_t bytes = size*nmemb; | ||
59 | size_t get = min(lim-response.length(),bytes); | ||
60 | response.append((const char *)p,get); | ||
61 | return get; | ||
62 | } | ||
63 | }; | ||
64 | |||
65 | typedef curl_fetch_string_t<16384> curl_pick_t; | ||
66 | |||
67 | |||
44 | } | 68 | } |
45 | 69 | ||
46 | } | 70 | } |
diff --git a/lib/consumer.cc b/lib/consumer.cc index 9f7530f..3c3b4f8 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -17,25 +17,7 @@ | |||
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: |