Debian Codegraph @

src/cfg_intake.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2017 Moritz Grimm <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:412:9`!
18 # include "config.h"cxx . . $ `<file>/src/config.h`/
19 #endif /* HAVE_CONFIG_H */
20
21 #include "compat.h"cxx . . $ `<file>/compat/compat.h`/
22
23 #include <sys/queue.h>
24
25 #include <string.h>
26
27 #include "cfg_private.h"cxx . . $ `<file>/src/cfg_private.h`/
28 #include "cfg_intake.h"cxx . . $ `<file>/src/cfg_intake.h`/
29 #include "xalloc.h"cxx . . $ `<file>/src/xalloc.h`/
30
31 struct cfg_intakecxx . . $ cfg_intake# {
32 TAILQ_ENTRYcxx . . $ `<external>/2546723208511035544/queue.h:382:9`!(cfg_intake) entrycxx . . $ cfg_intake#entry.;
33 char *namecxx . . $ cfg_intake#name.;
34 enum cfg_intake_typecxx . . $ cfg_intake_type# typecxx . . $ cfg_intake#type.;
35 char filenamecxx . . $ cfg_intake#filename.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!];
36 int shufflecxx . . $ cfg_intake#shuffle.;
37 int stream_oncecxx . . $ cfg_intake#stream_once.;
38 };
39
40 TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(cfg_intake_list, cfg_intake);
41
42 struct cfg_intake_listcxx . . $ cfg_intake_list# *
43 cfg_intake_list_createcxx . . $ cfg_intake_list_create(6d1209736ac34f33).(void)
44 {
45 struct cfg_intake_listcxx . . $ cfg_intake_list# *il;
46
47 il = xcalloccxx . . $ `src/xalloc.h:23:9`!(1UL, sizeof(*il));
48 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(il);
49
50 return (il);
51 }
52
53 void
54 cfg_intake_list_destroycxx . . $ cfg_intake_list_destroy(31419cc9a5f2e7fe).(cfg_intake_list_tcxx . . $ cfg_intake_list_t# *il_p)
55 {
56 struct cfg_intake_listcxx . . $ cfg_intake_list# *il = *il_p;
57 struct cfg_intakecxx . . $ cfg_intake# *i;
58
59 if (!il)
60 return;
61
62 while (NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! != (i = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(il))) {
63 TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(il, i, entry);
64 cfg_intake_destroycxx . . $ cfg_intake_destroy(6a9067edbc99ef0e).(&i);
65 }
66
67 xfreecxx . . $ `src/xalloc.h:26:9`!(il);
68 *il_p = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
69 }
70
71 unsigned int
72 cfg_intake_list_nentriescxx . . $ cfg_intake_list_nentries(de40473913f9f33f).(struct cfg_intake_listcxx . . $ cfg_intake_list# *il)
73 {
74 struct cfg_intakecxx . . $ cfg_intake# *i;
75 unsigned int n = 0;
76
77 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(i, il, entry) {
78 n++;
79 }
80
81 return (n);
82 }
83
84 struct cfg_intakecxx . . $ cfg_intake# *
85 cfg_intake_list_findcxx . . $ cfg_intake_list_find(4b9d0036e0282c96).(struct cfg_intake_listcxx . . $ cfg_intake_list# *il, const char *name)
86 {
87 struct cfg_intakecxx . . $ cfg_intake# *i;
88
89 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(i, il, entry) {
90 if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(i->namecxx . . $ cfg_intake#name., name))
91 return (i);
92 }
93
94 return (NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
95 }
96
97 struct cfg_intakecxx . . $ cfg_intake# *
98 cfg_intake_list_getcxx . . $ cfg_intake_list_get(4b9d0036e0282c96).(struct cfg_intake_listcxx . . $ cfg_intake_list# *il, const char *name)
99 {
100 struct cfg_intakecxx . . $ cfg_intake# *i;
101
102 i = cfg_intake_list_findcxx . . $ cfg_intake_list_find(4b9d0036e0282c96).(il, name);
103 if (i)
104 return (i);
105 i = cfg_intake_createcxx . . $ cfg_intake_create(1bb4ed2187fa89d7).(name);
106 if (!i)
107 return (NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
108
109 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(il, i, entry);
110
111 return (i);
112 }
113
114 void
115 cfg_intake_list_foreachcxx . . $ cfg_intake_list_foreach(2beadcdf627166c2).(struct cfg_intake_listcxx . . $ cfg_intake_list# *il,
116 void (*cb)(cfg_intake_tcxx . . $ cfg_intake_t#, void *), void *cb_arg)
117 {
118 struct cfg_intakecxx . . $ cfg_intake# *i;
119
120 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(i, il, entry) {
121 cb(i, cb_arg);
122 }
123 }
124
125 struct cfg_intakecxx . . $ cfg_intake# *
126 cfg_intake_createcxx . . $ cfg_intake_create(1bb4ed2187fa89d7).(const char *name)
127 {
128 struct cfg_intakecxx . . $ cfg_intake# *i;
129
130 if (!name || !name[0])
131 return (NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
132
133 i = xcalloccxx . . $ `src/xalloc.h:23:9`!(1UL, sizeof(*i));
134 i->namecxx . . $ cfg_intake#name. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(name);
135
136 return (i);
137 }
138
139 void
140 cfg_intake_destroycxx . . $ cfg_intake_destroy(6a9067edbc99ef0e).(struct cfg_intakecxx . . $ cfg_intake# **i_p)
141 {
142 struct cfg_intakecxx . . $ cfg_intake# *i = *i_p;
143
144 xfreecxx . . $ `src/xalloc.h:26:9`!(i->name);
145 xfreecxx . . $ `src/xalloc.h:26:9`!(i);
146 *i_p = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
147 }
148
149 int
150 cfg_intake_set_namecxx . . $ cfg_intake_set_name(29a71a406778a370).(struct cfg_intakecxx . . $ cfg_intake# *i, struct cfg_intake_listcxx . . $ cfg_intake_list# *il,
151 const char *name, const char **errstrp)
152 {
153 struct cfg_intakecxx . . $ cfg_intake# *i2;
154
155 if (!name || !name[0]) {
156 if (errstrp)
157 *errstrp = "empty";
158 return (-1);
159 }
160
161 i2 = cfg_intake_list_findcxx . . $ cfg_intake_list_find(4b9d0036e0282c96).(il, name);
162 if (i2 && i2 != i) {
163 if (errstrp)
164 *errstrp = "already exists";
165 return (-1);
166 }
167
168 SET_XSTRDUPcxx . . $ `src/cfg_private.h:71:9`!(i->name, name, errstrp);
169
170 return (0);
171 }
172
173 int
174 cfg_intake_set_typecxx . . $ cfg_intake_set_type(29a71a406778a370).(struct cfg_intakecxx . . $ cfg_intake# *i, struct cfg_intake_listcxx . . $ cfg_intake_list# *not_used,
175 const char *type, const char **errstrp)
176 {
177 (void)not_used;
178
179 if (!type || !type[0]) {
180 if (errstrp)
181 *errstrp = "empty";
182 return (-1);
183 }
184
185 if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).("autodetect", type))
186 i->typecxx . . $ cfg_intake#type. = CFG_INTAKE_AUTODETECTcxx . . $ CFG_INTAKE_AUTODETECT.;
187 else if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).("file", type))
188 i->typecxx . . $ cfg_intake#type. = CFG_INTAKE_FILEcxx . . $ CFG_INTAKE_FILE.;
189 else if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).("playlist", type))
190 i->typecxx . . $ cfg_intake#type. = CFG_INTAKE_PLAYLISTcxx . . $ CFG_INTAKE_PLAYLIST.;
191 else if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).("program", type))
192 i->typecxx . . $ cfg_intake#type. = CFG_INTAKE_PROGRAMcxx . . $ CFG_INTAKE_PROGRAM.;
193 else if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).("stdin", type))
194 i->typecxx . . $ cfg_intake#type. = CFG_INTAKE_STDINcxx . . $ CFG_INTAKE_STDIN.;
195 else {
196 if (errstrp)
197 *errstrp = "unsupported";
198 return (-1);
199 }
200 return (0);
201 }
202
203 int
204 cfg_intake_set_filenamecxx . . $ cfg_intake_set_filename(29a71a406778a370).(struct cfg_intakecxx . . $ cfg_intake# *i, struct cfg_intake_listcxx . . $ cfg_intake_list# *not_used,
205 const char *filename, const char **errstrp)
206 {
207 (void)not_used;
208 SET_STRLCPYcxx . . $ `src/cfg_private.h:57:9`!(i->filename, filename, errstrp);
209 return (0);
210 }
211
212 int
213 cfg_intake_set_shufflecxx . . $ cfg_intake_set_shuffle(29a71a406778a370).(struct cfg_intakecxx . . $ cfg_intake# *i, struct cfg_intake_listcxx . . $ cfg_intake_list# *not_used,
214 const char *shuffle, const char **errstrp)
215 {
216 (void)not_used;
217 SET_BOOLEANcxx . . $ `src/cfg_private.h:81:9`!(i->shuffle, shuffle, errstrp);
218 return (0);
219 }
220
221 int
222 cfg_intake_set_stream_oncecxx . . $ cfg_intake_set_stream_once(29a71a406778a370).(struct cfg_intakecxx . . $ cfg_intake# *i, struct cfg_intake_listcxx . . $ cfg_intake_list# *not_used,
223 const char *stream_once, const char **errstrp)
224 {
225 (void)not_used;
226 SET_BOOLEANcxx . . $ `src/cfg_private.h:81:9`!(i->stream_once, stream_once, errstrp);
227 return (0);
228 }
229
230 int
231 cfg_intake_validatecxx . . $ cfg_intake_validate(4f7d28fe13f0586b).(struct cfg_intakecxx . . $ cfg_intake# *i, const char **errstrp)
232 {
233 if (!cfg_intake_get_filenamecxx . . $ cfg_intake_get_filename(56a97a66344ba534).(i) &&
234 CFG_INTAKE_STDINcxx . . $ CFG_INTAKE_STDIN. != cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(i)) {
235 if (NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! != errstrp)
236 *errstrp = "intake filename missing";
237 return (-1);
238 }
239
240 return (0);
241 }
242
243 const char *
244 cfg_intake_get_namecxx . . $ cfg_intake_get_name(56a97a66344ba534).(struct cfg_intakecxx . . $ cfg_intake# *i)
245 {
246 return (i->namecxx . . $ cfg_intake#name.);
247 }
248
249 enum cfg_intake_typecxx . . $ cfg_intake_type#
250 cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(struct cfg_intakecxx . . $ cfg_intake# *i)
251 {
252 return (i->typecxx . . $ cfg_intake#type.);
253 }
254
255 const char *
256 cfg_intake_get_type_strcxx . . $ cfg_intake_get_type_str(56a97a66344ba534).(struct cfg_intakecxx . . $ cfg_intake# *i)
257 {
258 switch (i->typecxx . . $ cfg_intake#type.) {
259 case CFG_INTAKE_FILEcxx . . $ CFG_INTAKE_FILE.:
260 return ("file");
261 case CFG_INTAKE_PLAYLISTcxx . . $ CFG_INTAKE_PLAYLIST.:
262 return ("playlist");
263 case CFG_INTAKE_PROGRAMcxx . . $ CFG_INTAKE_PROGRAM.:
264 return ("program");
265 case CFG_INTAKE_STDINcxx . . $ CFG_INTAKE_STDIN.:
266 return ("stdin");
267 case CFG_INTAKE_AUTODETECTcxx . . $ CFG_INTAKE_AUTODETECT.:
268 default:
269 return ("autodetect");
270 }
271 }
272
273 const char *
274 cfg_intake_get_filenamecxx . . $ cfg_intake_get_filename(56a97a66344ba534).(struct cfg_intakecxx . . $ cfg_intake# *i)
275 {
276 return (i->filenamecxx . . $ cfg_intake#filename.[0] ? i->filenamecxx . . $ cfg_intake#filename. : NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
277 }
278
279 int
280 cfg_intake_get_shufflecxx . . $ cfg_intake_get_shuffle(2ab3bd772c3b65f).(struct cfg_intakecxx . . $ cfg_intake# *i)
281 {
282 return (i->shufflecxx . . $ cfg_intake#shuffle.);
283 }
284
285 int
286 cfg_intake_get_stream_oncecxx . . $ cfg_intake_get_stream_once(2ab3bd772c3b65f).(struct cfg_intakecxx . . $ cfg_intake# *i)
287 {
288 return (i->stream_oncecxx . . $ cfg_intake#stream_once.);
289 }