summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-10-08 00:01:43 +0100
committerCarl Hetherington <cth@carlh.net>2015-10-09 13:45:00 +0100
commita513606c2129d9485e6f3cf25d9128602cc93999 (patch)
tree9de8ae84dc78abfb48a6a9535d2034f91a2c9566 /src/lib
parent7bb8edad8606a06815ed865cb0393e8b5cac768f (diff)
Remove use of fmemopen.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/emailer.cc31
-rw-r--r--src/lib/emailer.h7
2 files changed, 23 insertions, 15 deletions
diff --git a/src/lib/emailer.cc b/src/lib/emailer.cc
index 0193f3605..fd815b789 100644
--- a/src/lib/emailer.cc
+++ b/src/lib/emailer.cc
@@ -76,6 +76,12 @@ curl_data_shim (void* ptr, size_t size, size_t nmemb, void* userp)
return reinterpret_cast<Emailer*>(userp)->get_data (ptr, size, nmemb);
}
+static int
+curl_debug_shim (CURL* curl, curl_infotype type, char* data, size_t size, void* userp)
+{
+ return reinterpret_cast<Emailer*>(userp)->debug (curl, type, data, size);
+}
+
size_t
Emailer::get_data (void* ptr, size_t size, size_t nmemb)
{
@@ -206,10 +212,8 @@ Emailer::send (shared_ptr<Job> job)
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt (curl, CURLOPT_VERBOSE, 1L);
-
- _notes_buffer.reset (new char[65536]);
- FILE* notes = fmemopen (_notes_buffer.get(), 65536, "w");
- curl_easy_setopt (curl, CURLOPT_STDERR, notes);
+ curl_easy_setopt (curl, CURLOPT_DEBUGFUNCTION, curl_debug_shim);
+ curl_easy_setopt (curl, CURLOPT_DEBUGDATA, this);
curl_multi_add_handle (mcurl, curl);
@@ -247,7 +251,6 @@ Emailer::send (shared_ptr<Job> job)
CURLMcode mc = curl_multi_fdset (mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
if (mc != CURLM_OK) {
- fclose (notes);
throw KDMError (String::compose ("Failed to send KDM email to %1", _to));
}
@@ -270,7 +273,6 @@ Emailer::send (shared_ptr<Job> job)
mc = curl_multi_perform (mcurl, &still_running);
if (mc != CURLM_OK) {
- fclose (notes);
throw KDMError (String::compose ("Failed to send KDM email (%1)", curl_multi_strerror (mc)));
}
@@ -279,7 +281,6 @@ Emailer::send (shared_ptr<Job> job)
}
if ((time(0) - start) > 10) {
- fclose (notes);
throw KDMError (_("Failed to send KDM email (timed out)"));
}
}
@@ -288,7 +289,6 @@ Emailer::send (shared_ptr<Job> job)
do {
CURLMsg* m = curl_multi_info_read (mcurl, &messages);
if (m && m->data.result != CURLE_OK) {
- fclose (notes);
throw KDMError (String::compose ("Failed to send KDM email (%1)", curl_easy_strerror (m->data.result)));
}
} while (messages > 0);
@@ -302,8 +302,6 @@ Emailer::send (shared_ptr<Job> job)
curl_multi_cleanup (mcurl);
curl_easy_cleanup (curl);
curl_global_cleanup ();
-
- fclose (notes);
}
string
@@ -317,8 +315,15 @@ Emailer::address_list (list<string> addresses)
return o.substr (0, o.length() - 2);
}
-string
-Emailer::notes () const
+int
+Emailer::debug (CURL *, curl_infotype type, char* data, size_t size)
{
- return string (_notes_buffer.get());
+ if (type == CURLINFO_TEXT) {
+ _notes += string (data, size);
+ } else if (type == CURLINFO_HEADER_IN) {
+ _notes += "<- " + string (data, size);
+ } else if (type == CURLINFO_HEADER_OUT) {
+ _notes += "-> " + string (data, size);
+ }
+ return 0;
}
diff --git a/src/lib/emailer.h b/src/lib/emailer.h
index 9e6fca5b0..89993ca48 100644
--- a/src/lib/emailer.h
+++ b/src/lib/emailer.h
@@ -31,9 +31,12 @@ public:
void send (boost::shared_ptr<Job> job);
- std::string notes () const;
+ std::string notes () const {
+ return _notes;
+ }
size_t get_data (void* ptr, size_t size, size_t nmemb);
+ int debug (CURL* curl, curl_infotype type, char* data, size_t size);
private:
static std::string address_list (std::list<std::string> addresses);
@@ -54,5 +57,5 @@ private:
std::list<Attachment> _attachments;
std::string _email;
size_t _offset;
- boost::scoped_array<char> _notes_buffer;
+ std::string _notes;
};