*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define _XOPEN_SOURCE 500
#define BUFFER_SIZE 4096
-const char *flag_to_string(gint64 flags)
+const char *
+flag_to_string(gint64 flags)
{
flags &= 0xf;
switch(flags) {
*
* In case chunk param is NULL:
* Returned structure had all strings malloced!!!
- * Be so kind and don't forget use free() for all its element, before end of structure lifecycle.
+ * Be so kind and don't forget use free() for all its element, before end of
+ * structure lifecycle.
*
* In case chunk is pointer to a GStringChunk:
* Returned structure had all string inserted in the passed chunk.
*
*/
-struct EVR string_to_version(const char *string, GStringChunk *chunk)
+struct EVR
+string_to_version(const char *string, GStringChunk *chunk)
{
struct EVR evr;
evr.epoch = NULL;
size_t release_len = strlen(ptr2+1);
if (release_len) {
if (chunk) {
- evr.release = g_string_chunk_insert_len(chunk, ptr2+1, release_len);
+ evr.release = g_string_chunk_insert_len(chunk, ptr2+1,
+ release_len);
} else {
evr.release = g_strndup(ptr2+1, release_len);
}
-inline int is_primary(const char *filename)
+inline int
+is_primary(const char *filename)
{
/*
This optimal piece of code cannot be used because of yum...
-char *compute_file_checksum(const char *filename, ChecksumType type)
+char *
+compute_file_checksum(const char *filename, ChecksumType type)
{
GChecksumType gchecksumtype;
FILE *fp = fopen(filename, "rb");
if (!fp) {
- g_critical(MODULE"%s: Cannot open %s (%s)", __func__, filename, strerror(errno));
+ g_critical(MODULE"%s: Cannot open %s (%s)", __func__, filename,
+ strerror(errno));
return NULL;
}
while (1) {
size_t input_len;
- input_len = fread((void *) buffer, sizeof(unsigned char), BUFFER_SIZE, fp);
+ input_len = fread((void *) buffer, sizeof(unsigned char),
+ BUFFER_SIZE, fp);
g_checksum_update(checksum, (const guchar *) buffer, input_len);
if (input_len < BUFFER_SIZE) {
break;
g_checksum_free(checksum);
if (!checksum_str) {
- g_critical(MODULE"%s: Cannot get checksum %s (low memory?)", __func__, filename);
+ g_critical(MODULE"%s: Cannot get checksum %s (low memory?)", __func__,
+ filename);
}
return checksum_str;
#define VAL_LEN 4 // Len of numeric values in rpm
-struct HeaderRangeStruct get_header_byte_range(const char *filename)
+struct HeaderRangeStruct
+get_header_byte_range(const char *filename)
{
/* Values readed by fread are 4 bytes long and stored as big-endian.
- * So there is htonl function to convert this big-endian number into host byte order.
+ * So there is htonl function to convert this big-endian number into host
+ * byte order.
*/
struct HeaderRangeStruct results;
FILE *fp = fopen(filename, "rb");
if (!fp) {
- g_debug(MODULE"%s: Cannot open file %s (%s)", __func__, filename, strerror(errno));
+ g_debug(MODULE"%s: Cannot open file %s (%s)", __func__, filename,
+ strerror(errno));
return results;
}
// Get header range
if (fseek(fp, 104, SEEK_SET) != 0) {
- g_debug(MODULE"%s: fseek fail on %s (%s)", __func__, filename, strerror(errno));
+ g_debug(MODULE"%s: fseek fail on %s (%s)", __func__, filename,
+ strerror(errno));
fclose(fp);
return results;
}
// Check sanity
if (hdrend < hdrstart) {
- g_debug(MODULE"%s: sanity check fail on %s (%d > %d))", __func__, filename, hdrstart, hdrend);
+ g_debug(MODULE"%s: sanity check fail on %s (%d > %d))", __func__,
+ filename, hdrstart, hdrend);
return results;
}
}
-const char *get_checksum_name_str(ChecksumType type)
+const char *
+get_checksum_name_str(ChecksumType type)
{
char *name = NULL;
}
-char *get_filename(const char *filepath)
+char *
+get_filename(const char *filepath)
{
char *filename = NULL;
}
-int copy_file(const char *src, const char *in_dst)
+int
+copy_file(const char *src, const char *in_dst)
{
size_t readed;
char buf[BUFFER_SIZE];
}
if ((orig = fopen(src, "r")) == NULL) {
- g_debug(MODULE"%s: Cannot open source file %s (%s)", __func__, src, strerror(errno));
+ g_debug(MODULE"%s: Cannot open source file %s (%s)", __func__, src,
+ strerror(errno));
return CR_COPY_ERR;
}
if ((new = fopen(dst, "w")) == NULL) {
- g_debug(MODULE"%s: Cannot open destination file %s (%s)", __func__, dst, strerror(errno));
+ g_debug(MODULE"%s: Cannot open destination file %s (%s)", __func__, dst,
+ strerror(errno));
fclose(orig);
return CR_COPY_ERR;
}
while ((readed = fread(buf, 1, BUFFER_SIZE, orig)) > 0) {
if (fwrite(buf, 1, readed, new) != readed) {
- g_debug(MODULE"%s: Error while copy %s -> %s (%s)", __func__, src, dst, strerror(errno));
+ g_debug(MODULE"%s: Error while copy %s -> %s (%s)", __func__, src,
+ dst, strerror(errno));
fclose(new);
fclose(orig);
return CR_COPY_ERR;
}
if (readed != BUFFER_SIZE && ferror(orig)) {
- g_debug(MODULE"%s: Error while copy %s -> %s (%s)", __func__, src, dst, strerror(errno));
+ g_debug(MODULE"%s: Error while copy %s -> %s (%s)", __func__, src,
+ dst, strerror(errno));
fclose(new);
fclose(orig);
return CR_COPY_ERR;
-int compress_file(const char *src, const char *in_dst, CompressionType compression)
+int
+compress_file(const char *src, const char *in_dst, CompressionType compression)
{
int readed;
char buf[BUFFER_SIZE];
}
if ((orig = fopen(src, "r")) == NULL) {
- g_debug(MODULE"%s: Cannot open source file %s (%s)", __func__, src, strerror(errno));
+ g_debug(MODULE"%s: Cannot open source file %s (%s)", __func__, src,
+ strerror(errno));
return CR_COPY_ERR;
}
}
if (readed != BUFFER_SIZE && ferror(orig)) {
- g_debug(MODULE"%s: Error while copy %s -> %s (%s)", __func__, src, dst, strerror(errno));
+ g_debug(MODULE"%s: Error while copy %s -> %s (%s)", __func__, src,
+ dst, strerror(errno));
cw_close(new);
fclose(orig);
return CR_COPY_ERR;
-void download(CURL *handle, const char *url, const char *in_dst, char **error)
+void
+download(CURL *handle, const char *url, const char *in_dst, char **error)
{
CURLcode rcode;
FILE *file = NULL;
// Set URL
if (curl_easy_setopt(handle, CURLOPT_URL, url) != CURLE_OK) {
- *error = g_strdup_printf(MODULE"%s: curl_easy_setopt(CURLOPT_URL) error", __func__);
+ *error = g_strdup_printf(MODULE"%s: curl_easy_setopt(CURLOPT_URL) error",
+ __func__);
fclose(file);
remove(dst);
g_free(dst);
// Set output file descriptor
if (curl_easy_setopt(handle, CURLOPT_WRITEDATA, file) != CURLE_OK) {
- *error = g_strdup_printf(MODULE"%s: curl_easy_setopt(CURLOPT_WRITEDATA) error", __func__);
+ *error = g_strdup_printf(MODULE
+ "%s: curl_easy_setopt(CURLOPT_WRITEDATA) error",
+ __func__);
fclose(file);
remove(dst);
g_free(dst);
rcode = curl_easy_perform(handle);
if (rcode != 0) {
- *error = g_strdup_printf(MODULE"%s: curl_easy_perform() error: %s", __func__, curl_easy_strerror(rcode));
+ *error = g_strdup_printf(MODULE"%s: curl_easy_perform() error: %s",
+ __func__, curl_easy_strerror(rcode));
fclose(file);
remove(dst);
g_free(dst);
-int better_copy_file(const char *src, const char *in_dst)
+int
+better_copy_file(const char *src, const char *in_dst)
{
if (!strstr(src, "://")) {
// Probably local path
download(handle, src, in_dst, &error);
curl_easy_cleanup(handle);
if (error) {
- g_debug(MODULE"%s: Error while downloading %s: %s", __func__, src, error);
+ g_debug(MODULE"%s: Error while downloading %s: %s", __func__, src,
+ error);
return CR_COPY_ERR;
}
}
-int remove_dir_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
+int
+remove_dir_cb(const char *fpath, const struct stat *sb, int typeflag,
+ struct FTW *ftwbuf)
{
UNUSED(sb);
UNUSED(typeflag);
}
-int remove_dir(const char *path)
+int
+remove_dir(const char *path)
{
return nftw(path, remove_dir_cb, 64, FTW_DEPTH | FTW_PHYS);
}
// Return path with exactly one trailing '/'
-char *normalize_dir_path(const char *path)
+char *
+normalize_dir_path(const char *path)
{
char *normalized = NULL;
}
-struct Version str_to_version(const char *str)
+struct Version
+str_to_version(const char *str)
{
char *endptr;
const char *ptr = str;
// 0 - versions are same
// 1 - first string is bigger version
// 2 - second string is bigger version
-int cmp_version_string(const char* str1, const char *str2)
+int
+cmp_version_string(const char* str1, const char *str2)
{
struct Version ver1, ver2;
return 0;
}
+
+
+void
+black_hole_log_function (const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data)
+{
+ UNUSED(log_domain);
+ UNUSED(log_level);
+ UNUSED(message);
+ UNUSED(user_data);
+ return;
+}
+
+
+void
+log_function (const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data)
+{
+ UNUSED(user_data);
+
+ if (log_domain)
+ printf("%s: ", log_domain);
+
+ switch(log_level) {
+ case G_LOG_LEVEL_ERROR:
+ printf("Error: %s\n", message);
+ break;
+ case G_LOG_LEVEL_CRITICAL:
+ printf("Critical: %s\n", message);
+ break;
+ case G_LOG_LEVEL_WARNING:
+ printf("Warning: %s\n", message);
+ break;
+ case G_LOG_LEVEL_DEBUG:
+ printf("- %s\n", message);
+ break;
+ default:
+ printf("> %s\n", message);
+ }
+
+ return;
+}
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __C_CREATEREPOLIB_MISC_H__
/** \ingroup misc
* Macro for supress compiler warning about unused param.
*/
-#define UNUSED(x) (void)(x) // Used to suppress compiler warning about unused param
+#define UNUSED(x) (void)(x) // Suppress compiler warning about unused param
/** \ingroup misc
* Convert flags from RPM header to a string representation.
/** \ingroup misc
* Convert epoch-version-release string into EVR structure.
- * If no GStringChunk passed, all non NULL items in returned structure are malloced and
- * in that case, you have to free all non-NULL element yourself.
+ * If no GStringChunk passed, all non NULL items in returned structure
+ * are malloced and in that case, you have to free all non-NULL element yourself.
* @param string NULL terminated n-v-r string
* @param chunk string chunk for store strings (optional, could be NULL)
* @return filled NVR
struct EVR string_to_version(const char *string, GStringChunk *chunk);
/** \ingroup misc
- * Check if the filename match pattern for primary files (files listed in primary.xml).
+ * Check if the filename match pattern for primary files (files listed
+ * in primary.xml).
* @param filename full path to file
* @return 1 if it is primary file, otherwise 0
*/
* Compute file checksum.
* @param filename filename
* @param type type of checksum
- * @return malloced null terminated string with checksum or NULL on error
+ * @return malloced null terminated string with checksum
+ * or NULL on error
*/
char *compute_file_checksum(const char *filename, ChecksumType type);
/** \ingroup misc
* Return checksum name.
* @param type checksum type
- * @return constant null terminated string with checksum name or NULL on error
+ * @return constant null terminated string with checksum name
+ * or NULL on error
*/
const char *get_checksum_name_str(ChecksumType type);
char *get_filename(const char *filepath);
/**@{*/
-#define CR_COPY_OK 0 /*!< Return value - Copy successfully finished */
-#define CR_COPY_ERR 1 /*!< Return value - Error while copy */
+#define CR_COPY_OK 0 /*!< Copy successfully finished */
+#define CR_COPY_ERR 1 /*!< Error while copy */
/**@}*/
/** \ingroup misc
* If *error == NULL then download was successfull.
* @param handle CURL handle
* @param url source url
- * @param destination destination (if destination is dir, filename from the url is used)
- * @param error pointer to string pointer for error message (mandatory argument!)
+ * @param destination destination (if destination is dir, filename from the
+ * url is used)
+ * @param error pointer to string pointer for error message
+ * (mandatory argument!)
*/
-void download(CURL *handle, const char *url, const char *destination, char **error);
+void download(CURL *handle, const char *url, const char *destination,
+ char **error);
/** \ingroup misc
* Copy file.
/** \ingroup misc
* Compress file.
* @param src source filename
- * @param dst destination (If dst is dir, filename of src + compression suffix is used.
+ * @param dst destination (If dst is dir, filename of src +
+ * compression suffix is used.
* If dst is NULL, src + compression suffix is used)
* @return CR_COPY_OK or CR_COPY_ERR on error
*/
/** \ingroup misc
* Compare two version string.
- * @param str1 First version string
- * @param str2 Second version string
- * @return 0 - versions are same, 1 - first string is bigger version, 2 - second string is bigger version
+ * @param str1 first version string
+ * @param str2 second version string
+ * @return 0 - versions are same, 1 - first string is bigger
+ * version, 2 - second string is bigger version
*/
int cmp_version_string(const char* str1, const char *str2);
+/** \ingroup misc
+ * Logging function with no output.
+ * @param log_domain logging domain
+ * @param log_level logging level
+ * @param message message
+ * @param user_data user data
+ */
+void black_hole_log_function (const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data);
+
+/** \ingroup misc
+ * Createrepo_c library standard logging function.
+ * @param log_domain logging domain
+ * @param log_level logging level
+ * @param message message
+ * @param user_data user data
+ */
+void log_function (const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data);
+
#endif /* __C_CREATEREPOLIB_MISC_H__ */