diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-08-24 13:07:44 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-08-24 13:07:44 +0200 |
commit | 5cc439c2c24859accf8a94d8a91879ad6d967ea4 (patch) | |
tree | 1915379ff53eeb579ed92d889b7e6d873df1144a /lib/utils | |
parent | be100446ebd3b1c8f6bb3ed450867c9dcbc625e8 (diff) | |
download | abrt-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/utils')
-rw-r--r-- | lib/utils/DebugDump.cpp | 31 | ||||
-rw-r--r-- | lib/utils/Makefile.am | 2 | ||||
-rw-r--r-- | lib/utils/abrt_rh_support.cpp | 38 | ||||
-rw-r--r-- | lib/utils/append_to_malloced_string.c | 27 | ||||
-rw-r--r-- | lib/utils/concat_path_file.c | 25 | ||||
-rw-r--r-- | lib/utils/dirsize.cpp | 20 | ||||
-rw-r--r-- | lib/utils/hooklib.cpp | 4 |
7 files changed, 114 insertions, 33 deletions
diff --git a/lib/utils/DebugDump.cpp b/lib/utils/DebugDump.cpp index 9bc0ab73..6858fe36 100644 --- a/lib/utils/DebugDump.cpp +++ b/lib/utils/DebugDump.cpp @@ -109,8 +109,10 @@ bool CDebugDump::Open(const char *pDir) bool CDebugDump::Exist(const char* pPath) { - std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pPath); - return ExistFileDir(fullPath.c_str()); + char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pPath); + bool r = ExistFileDir(full_path); + free(full_path); + return r; } static bool GetAndSetLock(const char* pLockFile, const char* pPID) @@ -362,17 +364,19 @@ static bool DeleteFileDir(const char *pDir) { if (dot_or_dotdot(dent->d_name)) continue; - std::string fullPath = concat_path_file(pDir, dent->d_name); - if (unlink(fullPath.c_str()) == -1) + char *full_path = concat_path_file(pDir, dent->d_name); + if (unlink(full_path) == -1) { if (errno != EISDIR) { closedir(dir); - error_msg("Can't remove dir '%s'", fullPath.c_str()); + error_msg("Can't remove dir '%s'", full_path); + free(full_path); return false; } - DeleteFileDir(fullPath.c_str()); + DeleteFileDir(full_path); } + free(full_path); } closedir(dir); if (rmdir(pDir) == -1) @@ -459,8 +463,9 @@ void CDebugDump::LoadText(const char* pName, std::string& pData) if (!m_bOpened) error_msg_and_die("DebugDump is not opened"); - std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName); - LoadTextFile(fullPath.c_str(), pData); + char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pName); + LoadTextFile(full_path, pData); + free(full_path); } void CDebugDump::SaveText(const char* pName, const char* pData) @@ -468,16 +473,18 @@ void CDebugDump::SaveText(const char* pName, const char* pData) if (!m_bOpened) error_msg_and_die("DebugDump is not opened"); - std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName); - SaveBinaryFile(fullPath.c_str(), pData, strlen(pData), m_uid, m_gid); + char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pName); + SaveBinaryFile(full_path, pData, strlen(pData), m_uid, m_gid); + free(full_path); } void CDebugDump::SaveBinary(const char* pName, const char* pData, unsigned pSize) { if (!m_bOpened) error_msg_and_die("DebugDump is not opened"); - std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName); - SaveBinaryFile(fullPath.c_str(), pData, pSize, m_uid, m_gid); + char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pName); + SaveBinaryFile(full_path, pData, pSize, m_uid, m_gid); + free(full_path); } bool CDebugDump::InitGetNextFile() diff --git a/lib/utils/Makefile.am b/lib/utils/Makefile.am index 04211a7c..d182e1a0 100644 --- a/lib/utils/Makefile.am +++ b/lib/utils/Makefile.am @@ -11,6 +11,8 @@ AM_YFLAGS = --verbose libABRTUtils_la_SOURCES = \ xfuncs.c \ + concat_path_file.c \ + append_to_malloced_string.c \ encbase64.cpp \ read_write.c read_write.h \ logging.c logging.h \ diff --git a/lib/utils/abrt_rh_support.cpp b/lib/utils/abrt_rh_support.cpp index 7e804f9f..4a1d80f0 100644 --- a/lib/utils/abrt_rh_support.cpp +++ b/lib/utils/abrt_rh_support.cpp @@ -190,8 +190,9 @@ reportfile_add_binding_from_namedfile(reportfile_t* file, // <binding name=NAME fileName=FILENAME type=text/binary... internal_reportfile_start_binding(file, binding_name, isbinary, recorded_filename); // ... href=content/NAME> - string href_name = concat_path_file("content", binding_name); - xxmlTextWriterWriteAttribute(file->writer, "href", href_name.c_str()); + char *href_name = concat_path_file("content", binding_name); + xxmlTextWriterWriteAttribute(file->writer, "href", href_name); + free(href_name); } // @@ -222,7 +223,7 @@ reportfile_free(reportfile_t* file) char* post_signature(const char* baseURL, bool ssl_verify, const char* signature) { - string URL = concat_path_file(baseURL, "/signatures"); + char *URL = concat_path_file(baseURL, "/signatures"); abrt_post_state *state = new_abrt_post_state(0 + ABRT_POST_WANT_HEADERS @@ -230,7 +231,8 @@ post_signature(const char* baseURL, bool ssl_verify, const char* signature) + ABRT_POST_WANT_ERROR_MSG + (ssl_verify ? ABRT_POST_WANT_SSL_VERIFY : 0) ); - int http_resp_code = abrt_post_string(state, URL.c_str(), "application/xml", signature); + int http_resp_code = abrt_post_string(state, URL, "application/xml", signature); + free(URL); char *retval; const char *strata_msg; @@ -369,7 +371,7 @@ send_report_to_new_case(const char* baseURL, const char* component, const char* report_file_name) { - string case_url = concat_path_file(baseURL, "/cases"); + char *case_url = concat_path_file(baseURL, "/cases"); char *case_data = make_case_data(summary, description, "Red Hat Enterprise Linux", "6.0", @@ -390,14 +392,16 @@ send_report_to_new_case(const char* baseURL, ); case_state->username = username; case_state->password = password; - abrt_post_string(case_state, case_url.c_str(), "application/xml", case_data); + abrt_post_string(case_state, case_url, "application/xml", case_data); char *case_location = find_header_in_abrt_post_state(case_state, "Location:"); switch (case_state->http_resp_code) { case 305: /* "305 Use Proxy" */ - if (++redirect_count < 10 && case_location) { - case_url = case_location; + if (++redirect_count < 10 && case_location) + { + free(case_url); + case_url = xstrdup(case_location); free_abrt_post_state(case_state); goto redirect_case; } @@ -408,7 +412,7 @@ send_report_to_new_case(const char* baseURL, * instead of returning html-encoded body, we show short concise message, * and show offending URL (typos in which is a typical cause) */ retval = xasprintf("error in case creation, " - "HTTP code: 404 (Not found), URL:'%s'", case_url.c_str()); + "HTTP code: 404 (Not found), URL:'%s'", case_url); break; default: @@ -431,7 +435,7 @@ send_report_to_new_case(const char* baseURL, break; case 200: - case 201: + case 201: { if (!case_location) { /* Case Creation returned valid code, but no location */ retval = xasprintf("error in case creation: no Location URL, HTTP code: %d", @@ -439,7 +443,7 @@ send_report_to_new_case(const char* baseURL, break; } - string atch_url = concat_path_file(case_location, "/attachments"); + char *atch_url = concat_path_file(case_location, "/attachments"); abrt_post_state *atch_state; redirect_attach: atch_state = new_abrt_post_state(0 @@ -450,14 +454,16 @@ send_report_to_new_case(const char* baseURL, ); atch_state->username = username; atch_state->password = password; - abrt_post_file_as_form(atch_state, atch_url.c_str(), "application/binary", report_file_name); + abrt_post_file_as_form(atch_state, atch_url, "application/binary", report_file_name); char *atch_location = find_header_in_abrt_post_state(atch_state, "Location:"); switch (atch_state->http_resp_code) { case 305: /* "305 Use Proxy" */ - if (++redirect_count < 10 && atch_location) { - atch_url = atch_location; + if (++redirect_count < 10 && atch_location) + { + free(atch_url); + atch_url = xstrdup(atch_location); free_abrt_post_state(atch_state); goto redirect_attach; } @@ -503,11 +509,15 @@ send_report_to_new_case(const char* baseURL, //} retval = xasprintf("Case created: %s", /*body,*/ case_location); } /* switch (attach HTTP code) */ + free_abrt_post_state(atch_state); + free(atch_url); + } /* case 200/201 */ } /* switch (case HTTP code) */ free_abrt_post_state(case_state); free(allocated); + free(case_url); return retval; } diff --git a/lib/utils/append_to_malloced_string.c b/lib/utils/append_to_malloced_string.c new file mode 100644 index 00000000..430cef0b --- /dev/null +++ b/lib/utils/append_to_malloced_string.c @@ -0,0 +1,27 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include "abrtlib.h" + +char *append_to_malloced_string(char *mstr, const char *append) +{ + unsigned mlen = strlen(mstr); + mstr = (char*) xrealloc(mstr, mlen + strlen(append) + 1); + strcpy(mstr + mlen, append); + return mstr; +} diff --git a/lib/utils/concat_path_file.c b/lib/utils/concat_path_file.c new file mode 100644 index 00000000..4c946628 --- /dev/null +++ b/lib/utils/concat_path_file.c @@ -0,0 +1,25 @@ +/* + * Utility routines. + * + * Copyright (C) 2001 Erik Andersen + * + * Licensed under GPLv2 or later. + */ + +/* Concatenate path and filename to new allocated buffer. + * Add '/' only as needed (no duplicate // are produced). + * If path is NULL, it is assumed to be "/". + * filename should not be NULL. + */ + +#include "abrtlib.h" + +char *concat_path_file(const char *path, const char *filename) +{ + if (!path) + path = ""; + const char *end = path + strlen(path); + while (*filename == '/') + filename++; + return xasprintf("%s%s%s", path, (end != path && end[-1] != '/' ? "/" : ""), filename); +} diff --git a/lib/utils/dirsize.cpp b/lib/utils/dirsize.cpp index 739b6b73..79f429e3 100644 --- a/lib/utils/dirsize.cpp +++ b/lib/utils/dirsize.cpp @@ -33,17 +33,21 @@ double get_dirsize(const char *pPath) { if (dot_or_dotdot(ep->d_name)) continue; - string dname = concat_path_file(pPath, ep->d_name); - if (lstat(dname.c_str(), &statbuf) != 0) + char *dname = concat_path_file(pPath, ep->d_name); + if (lstat(dname, &statbuf) != 0) + { + free(dname); continue; + } if (S_ISDIR(statbuf.st_mode)) { - size += get_dirsize(dname.c_str()); + size += get_dirsize(dname); } else if (S_ISREG(statbuf.st_mode)) { size += statbuf.st_size; } + free(dname); } closedir(dp); return size; @@ -66,12 +70,15 @@ double get_dirsize_find_largest_dir( { if (dot_or_dotdot(ep->d_name)) continue; - string dname = concat_path_file(pPath, ep->d_name); - if (lstat(dname.c_str(), &statbuf) != 0) + char *dname = concat_path_file(pPath, ep->d_name); + if (lstat(dname, &statbuf) != 0) + { + free(dname); continue; + } if (S_ISDIR(statbuf.st_mode)) { - double sz = get_dirsize(dname.c_str()); + double sz = get_dirsize(dname); size += sz; if (worst_dir && (!excluded || strcmp(excluded, ep->d_name) != 0)) @@ -94,6 +101,7 @@ double get_dirsize_find_largest_dir( { size += statbuf.st_size; } + free(dname); } closedir(dp); return size; diff --git a/lib/utils/hooklib.cpp b/lib/utils/hooklib.cpp index 68970661..7c794ef5 100644 --- a/lib/utils/hooklib.cpp +++ b/lib/utils/hooklib.cpp @@ -127,7 +127,9 @@ void trim_debug_dumps(unsigned setting_MaxCrashReportsSize, const char *exclude_ if (dirsize / (1024*1024) < setting_MaxCrashReportsSize || worst_dir == "") break; log("size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, setting_MaxCrashReportsSize, worst_dir.c_str()); - delete_debug_dump_dir(concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()).c_str()); + char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()); + delete_debug_dump_dir(d); + free(d); worst_dir = ""; } } |