createrepo_c library  0.2.1
C library for metadata manipulation
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
misc.h
1 /* createrepo_c - Library of routines for manipulation with repodata
2  * Copyright (C) 2012 Tomas Mlcoch
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17  * USA.
18  */
19 
20 #ifndef __C_CREATEREPOLIB_MISC_H__
21 #define __C_CREATEREPOLIB_MISC_H__
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include <glib.h>
28 #include <string.h>
29 #include <curl/curl.h>
30 #include "compression_wrapper.h"
31 
39 #define CR_UNUSED(x) (void)(x)
40 
43 #define CR_STATICSTRLEN(s) (sizeof(s)/sizeof(s[0]))
44 
49 const char *cr_flag_to_str(gint64 flags);
50 
53 struct cr_EVR {
54  char *epoch;
55  char *version;
56  char *release;
57 };
58 
61 struct cr_NVREA {
62  char *name;
63  char *version;
64  char *release;
65  char *epoch;
66  char *arch;
67 };
68 
72 struct cr_Version {
73  long version;
74  long release;
75  long patch;
76  char *suffix;
77 };
78 
79 
88 struct cr_EVR cr_str_to_evr(const char *string, GStringChunk *chunk);
89 
95 static inline int cr_is_primary(const char *filename) {
96  if (!strncmp(filename, "/etc/", 5))
97  return 1;
98  if (!strcmp(filename, "/usr/lib/sendmail"))
99  return 1;
100  if (strstr(filename, "bin/"))
101  return 1;
102  return 0;
103 };
104 
108  unsigned int start;
109  unsigned int end;
110 };
111 
117 struct cr_HeaderRangeStruct cr_get_header_byte_range(const char *filename,
118  GError **err);
119 
125 char *cr_get_filename(const char *filepath);
126 
135 int cr_download(CURL *handle,
136  const char *url,
137  const char *destination,
138  GError **err);
139 
146 int cr_copy_file(const char *src,
147  const char *dst,
148  GError **err);
149 
159 #define cr_compress_file(SRC, DST, COMTYPE, ERR) \
160  cr_compress_file_with_stat(SRC, DST, COMTYPE, NULL, ERR)
161 
172 int cr_compress_file_with_stat(const char *src,
173  const char *dst,
174  cr_CompressionType comtype,
175  cr_ContentStat *stat,
176  GError **err);
177 
184 int cr_better_copy_file(const char *src,
185  const char *dst,
186  GError **err);
187 
193 int cr_remove_dir(const char *path, GError **err);
194 
199 char *cr_normalize_dir_path(const char *path);
200 
205 struct cr_Version cr_str_to_version(const char *str);
206 
213 int cr_cmp_version_str(const char* str1, const char *str2);
214 
221 void cr_null_log_fn(const gchar *log_domain,
222  GLogLevelFlags log_level,
223  const gchar *message,
224  gpointer user_data);
225 
232 void cr_log_fn(const gchar *log_domain,
233  GLogLevelFlags log_level,
234  const gchar *message,
235  gpointer user_data);
236 
244 void cr_slist_free_full(GSList *list, GDestroyNotify free_f);
245 
250 struct cr_NVREA *cr_split_rpm_filename(const char *filename);
251 
255 void cr_nvrea_free(struct cr_NVREA *nvrea);
256 
262 #define cr_cmp_nvrea(A, B) (cr_cmp_evr((A)->epoch, (A)->version, (A)->release,\
263  (B)->epoch, (B)->version, (B)->release))
264 
274 int cr_cmp_evr(const char *e1, const char *v1, const char *r1,
275  const char *e2, const char *v2, const char *r2);
276 
277 
283 static inline gchar *
284 cr_safe_string_chunk_insert(GStringChunk *chunk, const char *str)
285 {
286  if (!str) return NULL;
287  return g_string_chunk_insert(chunk, str);
288 }
289 
296 static inline gchar *
297 cr_safe_string_chunk_insert_null(GStringChunk *chunk, const char *str)
298 {
299  if (!str || *str == '\0') return NULL;
300  return g_string_chunk_insert(chunk, str);
301 }
302 
303 
309 static inline gchar *
310 cr_safe_string_chunk_insert_const(GStringChunk *chunk, const char *str)
311 {
312  if (!str) return NULL;
313  return g_string_chunk_insert_const(chunk, str);
314 }
315 
318 #ifdef __cplusplus
319 }
320 #endif
321 
322 #endif /* __C_CREATEREPOLIB_MISC_H__ */