]> git.ipfire.org Git - people/ms/pakfire.git/blob - src/libpakfire/include/pakfire/util.h
digests: Split off into a new set of files
[people/ms/pakfire.git] / src / libpakfire / include / pakfire / util.h
1 /*#############################################################################
2 # #
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2013 Pakfire development team #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 #############################################################################*/
20
21 #ifndef PAKFIRE_UTIL_H
22 #define PAKFIRE_UTIL_H
23
24 #ifdef PAKFIRE_PRIVATE
25
26 #include <pwd.h>
27 #include <stdio.h>
28
29 #include <archive.h>
30
31 #include <pakfire/digest.h>
32 #include <pakfire/pakfire.h>
33
34 char* pakfire_unquote_in_place(char* s);
35
36 int pakfire_path_exists(const char* path);
37 time_t pakfire_path_age(const char* path);
38
39 const char* pakfire_basename(const char* path);
40 const char* pakfire_dirname(const char* path);
41
42 char* pakfire_remove_trailing_newline(char* str);
43
44 const char* pakfire_hostname(void);
45 const char* pakfire_get_home(struct pakfire* pakfire, uid_t uid);
46
47 int pakfire_read_file_into_buffer(FILE* f, char** buffer, size_t* len);
48
49 #define pakfire_hexlify(digest) __pakfire_hexlify(digest, sizeof(digest))
50 char* __pakfire_hexlify(const unsigned char* digest, const size_t length);
51 #define pakfire_unhexlify(dst, src) __pakfire_unhexlify(dst, sizeof(dst), src)
52 int __pakfire_unhexlify(unsigned char* dst, const size_t l, const char* src);
53
54 #define pakfire_path_join(dest, first, second) \
55 __pakfire_path_join(dest, sizeof(dest), first, second)
56 int __pakfire_path_join(char* dest, const size_t length,
57 const char* first, const char* second);
58 const char* pakfire_path_relpath(const char* root, const char* path);
59
60 // File stuff
61
62 int pakfire_file_write(struct pakfire* pakfire, const char* path,
63 uid_t owner, gid_t group, mode_t mode, const char* format, ...);
64
65 int pakfire_touch(const char* path, mode_t mode);
66 int pakfire_mkparentdir(const char* path, mode_t mode);
67 int pakfire_mkdir(const char* path, mode_t mode);
68 FILE* pakfire_mktemp(char* path);
69 char* pakfire_mkdtemp(char* path);
70 int pakfire_rmtree(const char* path, int flags);
71
72 char* pakfire_generate_uuid(void);
73
74 int pakfire_tty_is_noninteractive(void);
75
76 // Digests
77
78 size_t pakfire_digest_length(enum pakfire_digest_types digest);
79
80 // Archive Stuff
81
82 int pakfire_archive_copy_data(struct pakfire* pakfire,
83 struct archive* src, struct archive* dst);
84 int pakfire_archive_copy_data_from_file(struct pakfire* pakfire,
85 struct archive* archive, FILE* f);
86 int pakfire_archive_copy_data_to_buffer(struct pakfire* pakfire, struct archive* a,
87 struct archive_entry* entry, char** data, size_t* data_size);
88
89 // JSON Stuff
90
91 struct json_object* pakfire_json_parse_from_file(struct pakfire* pakfire, const char* path);
92 int pakfire_json_add_string(struct pakfire* pakfire,
93 struct json_object* json, const char* name, const char* value);
94 int pakfire_json_add_integer(struct pakfire* pakfire,
95 struct json_object* json, const char* name, int value);
96 int pakfire_json_add_string_array(struct pakfire* pakfire,
97 struct json_object* json, const char* name, char** array);
98
99 // Resource Limits
100
101 #define PAKFIRE_RLIMIT_NOFILE_MAX (512 * 1024)
102
103 int pakfire_rlimit_set(struct pakfire* pakfire, int limit);
104 int pakfire_rlimit_reset_nofile(struct pakfire* pakfire);
105
106 #endif
107
108 #endif /* PAKFIRE_UTIL_H */