summaryrefslogtreecommitdiffstats
path: root/lib/plugins/ReportUploader.cpp
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-08-24 13:07:44 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-08-24 13:07:44 +0200
commit5cc439c2c24859accf8a94d8a91879ad6d967ea4 (patch)
tree1915379ff53eeb579ed92d889b7e6d873df1144a /lib/plugins/ReportUploader.cpp
parentbe100446ebd3b1c8f6bb3ed450867c9dcbc625e8 (diff)
downloadabrt-5cc439c2c24859accf8a94d8a91879ad6d967ea4.tar.gz
abrt-5cc439c2c24859accf8a94d8a91879ad6d967ea4.tar.xz
abrt-5cc439c2c24859accf8a94d8a91879ad6d967ea4.zip
concat_path_file: make it a C function, not C++
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'lib/plugins/ReportUploader.cpp')
-rw-r--r--lib/plugins/ReportUploader.cpp57
1 files changed, 35 insertions, 22 deletions
diff --git a/lib/plugins/ReportUploader.cpp b/lib/plugins/ReportUploader.cpp
index eb01691c..7c31d516 100644
--- a/lib/plugins/ReportUploader.cpp
+++ b/lib/plugins/ReportUploader.cpp
@@ -101,7 +101,7 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
update_client(_("Sending archive %s to %s"), pFilename, pURL);
const char *base = (strrchr(pFilename, '/') ? : pFilename-1) + 1;
- string wholeURL = concat_path_file(pURL, base);
+ char *whole_url = concat_path_file(pURL, base);
int count = retry_count;
int result;
while (1)
@@ -109,6 +109,7 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
FILE* f = fopen(pFilename, "r");
if (!f)
{
+ free(whole_url);
throw CABRTException(EXCEP_PLUGIN, "Can't open archive file '%s'", pFilename);
}
struct stat buf;
@@ -117,7 +118,7 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* specify target */
- curl_easy_setopt(curl, CURLOPT_URL, wholeURL.c_str());
+ curl_easy_setopt(curl, CURLOPT_URL, whole_url);
curl_easy_setopt(curl, CURLOPT_READDATA, f);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)buf.st_size);
/* everything is done here; result 0 means success */
@@ -134,6 +135,7 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
/* retry the upload if not succesful, wait a bit before next try */
sleep(retry_delay);
}
+ free(whole_url);
if (count <= 0 && result != 0)
{
@@ -144,12 +146,15 @@ void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retr
static void write_str_to_file(const char *str, const char *path, const char *fname)
{
- string ofile_name = concat_path_file(path, fname);
- FILE *ofile = fopen(ofile_name.c_str(), "w");
+ char *ofile_name = concat_path_file(path, fname);
+ FILE *ofile = fopen(ofile_name, "w");
if (!ofile)
{
- throw CABRTException(EXCEP_PLUGIN, "Can't open '%s'", ofile_name.c_str());
+ CABRTException e(EXCEP_PLUGIN, "Can't open '%s'", ofile_name);
+ free(ofile_name);
+ throw e;
}
+ free(ofile_name);
fputs(str, ofile);
fclose(ofile);
}
@@ -212,11 +217,13 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
{
throw CABRTException(EXCEP_PLUGIN, "Can't mkdir a temporary directory in /tmp");
}
- string tmptar_name = concat_path_file(tmpdir_name, file_name.c_str());
- if (mkdir(tmptar_name.c_str(), 0700))
+ char *tmptar_name = concat_path_file(tmpdir_name, file_name.c_str());
+ if (mkdir(tmptar_name, 0700))
{
- throw CABRTException(EXCEP_PLUGIN, "Can't mkdir '%s'", tmptar_name.c_str());
+ CABRTException e(EXCEP_PLUGIN, "Can't mkdir '%s'", tmptar_name);
+ free(tmptar_name);
+ throw e;
}
// Copy each entry into the tarball root.
@@ -230,36 +237,39 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
const char *content = it->second[CD_CONTENT].c_str();
if (it->second[CD_TYPE] == CD_TXT)
{
- write_str_to_file(content, tmptar_name.c_str(), it->first.c_str());
+ write_str_to_file(content, tmptar_name, it->first.c_str());
}
else if (it->second[CD_TYPE] == CD_BIN)
{
- string ofile_name = concat_path_file(tmptar_name.c_str(), it->first.c_str());
- if (copy_file(content, ofile_name.c_str(), 0644) < 0)
+ char *ofile_name = concat_path_file(tmptar_name, it->first.c_str());
+ if (copy_file(content, ofile_name, 0644) < 0)
{
- throw CABRTException(EXCEP_PLUGIN,
+ CABRTException e(EXCEP_PLUGIN,
"Can't copy '%s' to '%s'",
- content,
- ofile_name.c_str()
+ content, ofile_name
);
+ free(tmptar_name);
+ free(ofile_name);
+ throw e;
}
+ free(ofile_name);
}
}
// add ticket_name and customer name to tarball
if (have_ticket_name)
{
- write_str_to_file(ticket_name.c_str(), tmptar_name.c_str(), "TICKET");
+ write_str_to_file(ticket_name.c_str(), tmptar_name, "TICKET");
}
if (customer_name != "")
{
- write_str_to_file(customer_name.c_str(), tmptar_name.c_str(), "CUSTOMER");
+ write_str_to_file(customer_name.c_str(), tmptar_name, "CUSTOMER");
}
// Create the compressed tarball
string outfile_basename = file_name + ".tar.gz";
- string outfile_name = concat_path_file(tmpdir_name, outfile_basename.c_str());
- string cmd = ssprintf("tar -C %s --create --gzip --file=%s %s", tmpdir_name, outfile_name.c_str(), file_name.c_str());
+ char *outfile_name = concat_path_file(tmpdir_name, outfile_basename.c_str());
+ string cmd = ssprintf("tar -C %s --create --gzip --file=%s %s", tmpdir_name, outfile_name, file_name.c_str());
RunCommand(cmd.c_str());
// encrypt if requested
@@ -270,9 +280,9 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
string infile_name = outfile_name;
outfile_basename += ".aes";
- outfile_name += ".aes";
+ outfile_name = append_to_malloced_string(outfile_name, ".aes");
- cmd = ssprintf("openssl aes-128-cbc -in %s -out %s -pass stdin", infile_name.c_str(), outfile_name.c_str());
+ cmd = ssprintf("openssl aes-128-cbc -in %s -out %s -pass stdin", infile_name.c_str(), outfile_name);
WriteCommand(cmd.c_str(), key.c_str());
}
@@ -284,11 +294,11 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
if (do_upload)
{
// FIXME: SendFile isn't working sometime (scp)
- SendFile(upload_url.c_str(), outfile_name.c_str(), retry_count, retry_delay);
+ SendFile(upload_url.c_str(), outfile_name, retry_count, retry_delay);
}
else
{
- cmd = ssprintf("cp %s /tmp/", outfile_name.c_str());
+ cmd = ssprintf("cp %s /tmp/", outfile_name);
RunCommand(cmd.c_str());
}
@@ -343,6 +353,9 @@ string CReportUploader::Report(const map_crash_data_t& pCrashData,
cmd = ssprintf("rm -rf %s", tmpdir_name);
RunCommand(cmd.c_str());
+ free(tmptar_name);
+ free(outfile_name);
+
return msg;
}