Librepo library  1.17.2
C library for downloading linux repository metadata and packages
Utility functions and macros

Macros

#define LR_CURL_VERSION_CHECK(major, minor, patch)
 

Functions

void lr_global_init (void)
 
void lr_log_librepo_summary (void)
 
void lr_out_of_memory (void)
 
void * lr_malloc (size_t len)
 
void * lr_malloc0 (size_t len)
 
void * lr_realloc (void *ptr, size_t len)
 
void lr_free (void *mem)
 
int lr_gettmpfile (void)
 
char * lr_gettmpdir (void)
 
char * lr_pathconcat (const char *str,...) G_GNUC_NULL_TERMINATED
 
int lr_remove_dir (const char *path)
 
int lr_copy_content (int source, int dest)
 
char * lr_prepend_url_protocol (const char *path)
 
gchar * lr_string_chunk_insert (GStringChunk *chunk, const gchar *string)
 
int lr_xml_parser_warning_logger (LrXmlParserWarningType type G_GNUC_UNUSED, char *msg, void *cbdata, GError **err G_GNUC_UNUSED) G_GNUC_UNUSED
 
gboolean lr_best_checksum (GSList *list, LrChecksumType *type, gchar **value)
 
gchar * lr_url_without_path (const char *url)
 
gchar ** lr_strv_dup (gchar **array)
 
gboolean lr_is_local_path (const gchar *path)
 
gboolean lr_key_file_save_to_file (GKeyFile *key_file, const gchar *filename, GError **error)
 
LrChecksumType lr_checksum_from_zck_hash (zck_hash zck_checksum_type)
 
zck_hash lr_zck_hash_from_lr_checksum (LrChecksumType checksum_type)
 
zckCtx * lr_zck_init_read_base (const char *checksum, LrChecksumType checksum_type, gint64 zck_header_size, int fd, GError **err)
 
gboolean lr_zck_valid_header_base (const char *checksum, LrChecksumType checksum_type, gint64 zck_header_size, int fd, GError **err)
 
zckCtx * lr_zck_init_read (LrDownloadTarget *target, char *filename, int fd, GError **err)
 
gboolean lr_zck_valid_header (LrDownloadTarget *target, char *filename, int fd, GError **err)
 
GSList * lr_get_recursive_files (char *path, char *extension, GError **err)
 

Detailed Description

Macro Definition Documentation

#define LR_CURL_VERSION_CHECK (   major,
  minor,
  patch 
)
Value:
(LIBCURL_VERSION_MAJOR > (major) || \
(LIBCURL_VERSION_MAJOR == (major) && LIBCURL_VERSION_MINOR > (minor)) || \
(LIBCURL_VERSION_MAJOR == (major) && LIBCURL_VERSION_MINOR == (minor) && \
LIBCURL_VERSION_PATCH >= (patch)))

Macro for curl version check.

Parameters
majorMajor version
minorMinor version
patchPatch version
Returns
True if current curl version is higher or equal

Definition at line 50 of file util.h.

Function Documentation

gboolean lr_best_checksum ( GSList *  list,
LrChecksumType type,
gchar **  value 
)

From the GSList of pointers to LrMetalinkHash objects, select the strongest one which librepo could calculate.

Parameters
listList of LrMetalinkHash*
typeVariable to store checksum type.
valueVariable to store pointer to value (pointer to original value from the list, NOT A COPY).
Returns
TRUE if usable checksum found, FALSE otherwise
LrChecksumType lr_checksum_from_zck_hash ( zck_hash  zck_checksum_type)

Get LrChecksumType that corresponds to zck_hash

Parameters
zck_checksum_typezck_hash value
Returns
checksum_type corresponding LrChecksumType value

Return value will be LR_CHECKSUM_UNKNOWN if zck_checksum_type isn't available as a LrChecksumType

int lr_copy_content ( int  source,
int  dest 
)

Copy content from source file descriptor to the dest file descriptor.

Parameters
sourceSource opened file descriptor
destDestination opened file descriptor
Returns
0 on succes, -1 on error
void lr_free ( void *  mem)

Free the memory block.

Parameters
memPointer to block of memory.
GSList* lr_get_recursive_files ( char *  path,
char *  extension,
GError **  err 
)

Recursively get list of all files in path that end with extension

Parameters
pathpath to search
extensionreturn files with this extension (including .)
errGError **
Returns
filelist GSList* of files that have extension

Return value will be NULL if no files match or there's an error. err will be set if there's an error

char* lr_gettmpdir ( void  )

Create temporary directory in /tmp directory.

Returns
Path to directory.
int lr_gettmpfile ( void  )

Create temporary librepo file in /tmp directory.

Returns
File descriptor.
void lr_global_init ( void  )

Initialize librepo library. This is called automatically to initialize librepo. You normally don't have to call this function manually.

gboolean lr_is_local_path ( const gchar *  path)

Check if string looks like a local path. (This function doesn't do realpath resolving and existence checking) If a path is empty, NULL or has protocol other then file:// specified then the path is considered as remote, otherwise TRUE is returned.

Parameters
pathA string path
Returns
TRUE if path string looks like a local path
gboolean lr_key_file_save_to_file ( GKeyFile *  key_file,
const gchar *  filename,
GError **  error 
)

Re-implementatio of g_key_file_save_to_file, because the function is available since 2.40 but we need to support older glib

Parameters
key_filekey file
filenamefilename
errorGError **
Returns
TRUE if successful, FALSE otherwise
void lr_log_librepo_summary ( void  )

Clean up librepo library. void lr_global_cleanup();Log a debug message with Librepo version and current time.

void* lr_malloc ( size_t  len)

Allocate len bytes of memory.

Parameters
lenNumber of bytes to be allocated.
Returns
Pointer to allocated memory.
void* lr_malloc0 ( size_t  len)

Allocate len bytes of memory. The allocated memory is set to zero.

Parameters
lenNumber of bytes to be allocated.
Returns
Pointer to allocated memory.
void lr_out_of_memory ( void  )

Print "Out of memory" message to stderr and abort program execution. This function is used when malloc call fails.

char* lr_pathconcat ( const char *  str,
  ... 
)

Concatenate all of given part of path. If last chunk is "" then separator will be appended to the result.

Parameters
strFirst part of the path.
...NULL terminated list of strings.
Returns
Concatenated path.
char* lr_prepend_url_protocol ( const char *  path)

If protocol is specified ("http://foo") return copy of path. If path is absolute ("/foo/bar/") return path with "file://" prefix. If path is relative ("bar/") return absolute path with "file://" prefix.

Parameters
path
Returns
url with protocol
void* lr_realloc ( void *  ptr,
size_t  len 
)

Change size of block memory pointed by ptr to the new len.

Parameters
ptrPointer to block of memory or NULL.
lenNew len of the block.
Returns
New pointer to the reallocated memory.
int lr_remove_dir ( const char *  path)

Recursively remove directory.

Parameters
pathPath to the directory.
Returns
0 on succes, -1 on error.
gchar* lr_string_chunk_insert ( GStringChunk *  chunk,
const gchar *  string 
)

Same as g_string_chunk_insert, but allows NULL as string. If the string is NULL, then returns NULL and do nothing.

Parameters
chunkString chunk
stringString or NULL
Returns
a pointer to the copy of string within the chunk
gchar** lr_strv_dup ( gchar **  array)

Create a copy of NULL-terminated array of strings. All strings in the copy are malloced - returned array must be freed by g_strfreev()

Parameters
arrayNULL-terminated array of strings or NULL
Returns
Copy of input array or NULL if input was NULL
gchar* lr_url_without_path ( const char *  url)

Return malloced string with host part of url (protocol prefix + hostname)

Parameters
urlURL
Returns
Malloced url without path, just protocol and hostname
int lr_xml_parser_warning_logger ( LrXmlParserWarningType type  G_GNUC_UNUSED,
char *  msg,
void *  cbdata,
GError **err  G_GNUC_UNUSED 
)

Warning callback to print warnings via GLib logger For more info take a look at LrXmlParserWarningCb

zck_hash lr_zck_hash_from_lr_checksum ( LrChecksumType  checksum_type)

Get zck_hash that corresponds to LrChecksumType

Parameters
checksum_typeLrChecksumType value
Returns
zck_checksum_type corresponding zck_hash value

Return value will be ZCK_HASH_UNKNOWN if checksum_type isn't available as a zck_hash

zckCtx* lr_zck_init_read ( LrDownloadTarget *  target,
char *  filename,
int  fd,
GError **  err 
)

Initialize zchunk file for reading while verifying header checksum

Parameters
checksumtarget containing checksum information
fdfile descriptor to read from
Returns
zck zchunk context opened for reading

Return value will be NULL if the header checksum doesn't match the provided checksum, is invalid, or if the header can't be read

zckCtx* lr_zck_init_read_base ( const char *  checksum,
LrChecksumType  checksum_type,
gint64  zck_header_size,
int  fd,
GError **  err 
)

Base function for initializing zchunk file for reading while verifying header checksum

Parameters
checksumheader checksum
checksum_typeheader checksum type
zck_header_sizeheader size
fdfile descriptor to read from
Returns
zck zchunk context opened for reading

Return value will be NULL if the header checksum doesn't match the provided checksum, is invalid, or if the header can't be read

gboolean lr_zck_valid_header ( LrDownloadTarget *  target,
char *  filename,
int  fd,
GError **  err 
)

Check whether zchunk file has valid header checksum

Parameters
checksumtarget containing checksum information
fdfile descriptor to read from
Returns
zck zchunk context opened for reading

Return value will be FALSE if the header checksum doesn't match the provided checksum, is invalid, or if the header can't be read

gboolean lr_zck_valid_header_base ( const char *  checksum,
LrChecksumType  checksum_type,
gint64  zck_header_size,
int  fd,
GError **  err 
)

Base function for checking whether zchunk file has valid header checksum

Parameters
checksumheader checksum
checksum_typeheader checksum type
zck_header_sizeheader size
fdfile descriptor to read from
Returns
zck zchunk context opened for reading

Return value will be FALSE if the header checksum doesn't match the provided checksum, is invalid, or if the header can't be read