1 /*-
2 * Copyright (c) 2011-2013 Baptiste Daroussin <bapt@FreeBSD.org>
3 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
4 * Copyright (c) 2013 Matthew Seaman <matthew@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in this position and unchanged.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <assert.h>
30
31 #include "pkg.h"
32 #include "private/event.h"
33 #include "private/pkg.h"
34
35 /*
36 * Dep
37 */
38 void
pkg_dep_free(struct pkg_dep * d)39 pkg_dep_free(struct pkg_dep *d)
40 {
41 if (d == NULL)
42 return;
43
44 free(d->origin);
45 free(d->name);
46 free(d->version);
47 free(d->uid);
48 free(d);
49 }
50
51 const char *
pkg_dep_get(struct pkg_dep const * const d,const pkg_dep_attr attr)52 pkg_dep_get(struct pkg_dep const * const d, const pkg_dep_attr attr)
53 {
54 assert(d != NULL);
55
56 switch (attr) {
57 case PKG_DEP_NAME:
58 return (d->name);
59 break;
60 case PKG_DEP_ORIGIN:
61 return (d->origin);
62 break;
63 case PKG_DEP_VERSION:
64 return (d->version);
65 break;
66 default:
67 return (NULL);
68 break;
69 }
70 }
71
72 bool
pkg_dep_is_locked(struct pkg_dep const * const d)73 pkg_dep_is_locked(struct pkg_dep const * const d)
74 {
75 assert(d != NULL);
76
77 return d->locked;
78 }
79
80 /*
81 * File
82 */
83 void
pkg_file_free(struct pkg_file * file)84 pkg_file_free(struct pkg_file *file)
85 {
86 free(file->sum);
87 free(file);
88 }
89
90 /*
91 * Script
92 */
93
94 const char *
pkg_script_get(struct pkg const * const p,pkg_script i)95 pkg_script_get(struct pkg const * const p, pkg_script i)
96 {
97 if (p->scripts[i] == NULL)
98 return (NULL);
99
100 fflush(p->scripts[i]->fp);
101 return (p->scripts[i]->buf);
102 }
103
104 /*
105 * Option
106 */
107 void
pkg_option_free(struct pkg_option * option)108 pkg_option_free(struct pkg_option *option)
109 {
110 if (option == NULL)
111 return;
112
113 free(option->key);
114 free(option->value);
115 free(option->default_value);
116 free(option->description);
117 free(option);
118 }
119
120 /*
121 * Conflicts
122 */
123 void
pkg_conflict_free(struct pkg_conflict * c)124 pkg_conflict_free(struct pkg_conflict *c)
125 {
126 if (c == NULL)
127 return;
128
129 free(c->uid);
130 free(c->digest);
131 free(c);
132 }
133
134 /*
135 * Config files
136 */
137 void
pkg_config_file_free(struct pkg_config_file * c)138 pkg_config_file_free(struct pkg_config_file *c)
139 {
140 if (c == NULL)
141 return;
142
143 free(c->content);
144 free(c);
145 }
146
147
148 /*
149 * kv
150 */
151
152 struct pkg_kv *
pkg_kv_new(const char * key,const char * val)153 pkg_kv_new(const char *key, const char *val)
154 {
155 struct pkg_kv *c;
156
157 c = xcalloc(1, sizeof(struct pkg_kv));
158 c->key = xstrdup(key);
159 c->value = xstrdup(val);
160
161 return (c);
162 }
163
164 void
pkg_kv_free(struct pkg_kv * c)165 pkg_kv_free(struct pkg_kv *c)
166 {
167 if (c == NULL)
168 return;
169
170 free(c->key);
171 free(c->value);
172 free(c);
173 }
174