Branch data Line data Source code
1 : : /*-
2 : : * Copyright (c) 2011-2014 Baptiste Daroussin <bapt@FreeBSD.org>
3 : : * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
4 : : * All rights reserved.
5 : : *
6 : : * Redistribution and use in source and binary forms, with or without
7 : : * modification, are permitted provided that the following conditions
8 : : * are met:
9 : : * 1. Redistributions of source code must retain the above copyright
10 : : * notice, this list of conditions and the following disclaimer
11 : : * in this position and unchanged.
12 : : * 2. Redistributions in binary form must reproduce the above copyright
13 : : * notice, this list of conditions and the following disclaimer in the
14 : : * documentation and/or other materials provided with the distribution.
15 : : *
16 : : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17 : : * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 : : * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 : : * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20 : : * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 : : * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 : : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 : : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 : : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 : : * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 : : */
27 : :
28 : : #ifndef _PKG_UTIL_H
29 : : #define _PKG_UTIL_H
30 : :
31 : : #include <sys/types.h>
32 : : #include <sys/stat.h>
33 : : #include <sys/param.h>
34 : : #include <ucl.h>
35 : : #include <khash.h>
36 : : #include <pkg.h>
37 : : #include <xstring.h>
38 : :
39 : : #define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0)
40 : : #define RELATIVE_PATH(p) (p + (*p == '/' ? 1 : 0))
41 : :
42 : : #define ERROR_SQLITE(db, query) do { \
43 : : pkg_emit_error("sqlite error while executing %s in file %s:%d: %s", query, \
44 : : __FILE__, __LINE__, sqlite3_errmsg(db)); \
45 : : } while(0)
46 : :
47 : : #define ERROR_STMT_SQLITE(db, statement) do { \
48 : : pkg_emit_error("sqlite error while executing %s in file %s:%d: %s", sqlite3_expanded_sql(statement), \
49 : : __FILE__, __LINE__, sqlite3_errmsg(db)); \
50 : : } while (0)
51 : :
52 [ + + # # : 2906 : KHASH_MAP_INIT_INT(hardlinks, int)
- + + + #
# + + - +
- + + - -
+ + - - +
- + - + #
# ]
53 : : typedef khash_t(hardlinks) hardlinks_t;
54 : :
55 : : struct dns_srvinfo {
56 : : unsigned int type;
57 : : unsigned int class;
58 : : unsigned int ttl;
59 : : unsigned int priority;
60 : : unsigned int weight;
61 : : unsigned int port;
62 : : unsigned int finalweight;
63 : : char host[MAXHOSTNAMELEN];
64 : : struct dns_srvinfo *next;
65 : : };
66 : :
67 : : struct pkg_key;
68 : :
69 : : int32_t string_hash_func(const char *);
70 : :
71 : : int mkdirs(const char *path);
72 : : int file_to_buffer(const char *, char **, off_t *);
73 : : int file_to_bufferat(int, const char *, char **, off_t *);
74 : : int format_exec_cmd(char **, const char *, const char *, const char *, const char *,
75 : : int argc, char **argv, bool lua);
76 : : int is_dir(const char *);
77 : : int is_link(const char *);
78 : :
79 : : int rsa_new(struct pkg_key **, pkg_password_cb *, char *path);
80 : : void rsa_free(struct pkg_key *);
81 : : int rsa_sign(char *path, struct pkg_key *keyinfo, unsigned char **sigret,
82 : : unsigned int *siglen);
83 : : int rsa_verify(const char *key, unsigned char *sig, unsigned int sig_len, int fd);
84 : : int rsa_verify_cert(unsigned char *cert,
85 : : int certlen, unsigned char *sig, int sig_len, int fd);
86 : :
87 : : bool check_for_hardlink(hardlinks_t *hl, struct stat *st);
88 : : bool is_valid_abi(const char *arch, bool emit_error);
89 : : bool is_valid_os_version(struct pkg *pkg);
90 : :
91 : : struct dns_srvinfo *
92 : : dns_getsrvinfo(const char *zone);
93 : :
94 : : int set_nameserver(const char *nsname);
95 : : void set_blocking(int fd);
96 : : void set_nonblocking(int fd);
97 : :
98 : : int pkg_symlink_cksum(const char *path, const char *root, char *cksum);
99 : : int pkg_symlink_cksumat(int fd, const char *path, const char *root,
100 : : char *cksum);
101 : :
102 : : pid_t process_spawn_pipe(FILE *inout[2], const char *command);
103 : :
104 : : void *parse_mode(const char *str);
105 : : int *text_diff(char *a, char *b);
106 : : int merge_3way(char *pivot, char *v1, char *v2, xstring *out);
107 : : bool mkdirat_p(int fd, const char *path);
108 : : int get_socketpair(int *);
109 : : int checkflags(const char *mode, int *optr);
110 : : bool match_ucl_lists(const char *buffer, const ucl_object_t *globs, const ucl_object_t *regexes);
111 : : char *get_dirname(char *dir);
112 : : char *rtrimspace(char *buf);
113 : :
114 : : #endif
|