| 1 | /* |
| 2 | * Copyright (c) 2015 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>:410:9`! |
| 18 | # include "config.h"cxx . . $ `<file>/src/config.h`/ |
| 19 | #endif /* HAVE_CONFIG_H */ |
| 20 | |
| 21 | #include <sys/queue.h> |
| 22 | |
| 23 | #include <string.h> |
| 24 | |
| 25 | #include "cfg_private.h"cxx . . $ `<file>/src/cfg_private.h`/ |
| 26 | #include "cfg_decoder.h"cxx . . $ `<file>/src/cfg_decoder.h`/ |
| 27 | #include "log.h"cxx . . $ `<file>/src/log.h`/ |
| 28 | #include "xalloc.h"cxx . . $ `<file>/src/xalloc.h`/ |
| 29 | |
| 30 | struct file_extcxx . . $ file_ext# { |
| 31 | TAILQ_ENTRYcxx . . $ `<external>/2546723208511035544/queue.h:382:9`!(file_ext) entrycxx . . $ file_ext#entry.; |
| 32 | char *extcxx . . $ file_ext#ext.; |
| 33 | }; |
| 34 | TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(file_ext_list, file_ext); |
| 35 | |
| 36 | struct cfg_decodercxx . . $ cfg_decoder# { |
| 37 | TAILQ_ENTRYcxx . . $ `<external>/2546723208511035544/queue.h:382:9`!(cfg_decoder) entrycxx . . $ cfg_decoder#entry.; |
| 38 | char *namecxx . . $ cfg_decoder#name.; |
| 39 | char *programcxx . . $ cfg_decoder#program.; |
| 40 | struct file_ext_listcxx . . $ file_ext_list# extscxx . . $ cfg_decoder#exts.; |
| 41 | }; |
| 42 | |
| 43 | TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(cfg_decoder_list, cfg_decoder); |
| 44 | |
| 45 | struct cfg_decoder_listcxx . . $ cfg_decoder_list# * |
| 46 | cfg_decoder_list_createcxx . . $ cfg_decoder_list_create(e15359236e44248b).(void) |
| 47 | { |
| 48 | struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl; |
| 49 | |
| 50 | dl = xcalloccxx . . $ `src/xalloc.h:23:9`!(1UL, sizeof(*dl)); |
| 51 | TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(dl); |
| 52 | |
| 53 | return (dl); |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | cfg_decoder_list_destroycxx . . $ cfg_decoder_list_destroy(f683c49a8e1aa5da).(struct cfg_decoder_listcxx . . $ cfg_decoder_list# **dl_p) |
| 58 | { |
| 59 | struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl = *dl_p; |
| 60 | struct cfg_decodercxx . . $ cfg_decoder# *d; |
| 61 | |
| 62 | if (!dl) |
| 63 | return; |
| 64 | |
| 65 | while (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! != (d = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(dl))) |
| 66 | cfg_decoder_list_removecxx . . $ cfg_decoder_list_remove(c04414ed9cb5b8c1).(dl, &d); |
| 67 | |
| 68 | xfreecxx . . $ `src/xalloc.h:26:9`!(dl); |
| 69 | *dl_p = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 70 | } |
| 71 | |
| 72 | unsigned int |
| 73 | cfg_decoder_list_nentriescxx . . $ cfg_decoder_list_nentries(8911930437a9d8fa).(struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl) |
| 74 | { |
| 75 | struct cfg_decodercxx . . $ cfg_decoder# *d; |
| 76 | unsigned int n = 0; |
| 77 | |
| 78 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(d, dl, entry) { |
| 79 | n++; |
| 80 | } |
| 81 | |
| 82 | return (n); |
| 83 | } |
| 84 | |
| 85 | struct cfg_decodercxx . . $ cfg_decoder# * |
| 86 | cfg_decoder_list_findcxx . . $ cfg_decoder_list_find(fa3ce1428af83150).(struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl, const char *name) |
| 87 | { |
| 88 | struct cfg_decodercxx . . $ cfg_decoder# *d; |
| 89 | |
| 90 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(d, dl, entry) { |
| 91 | if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(d->namecxx . . $ cfg_decoder#name., name)) |
| 92 | return (d); |
| 93 | } |
| 94 | |
| 95 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 96 | } |
| 97 | |
| 98 | struct cfg_decodercxx . . $ cfg_decoder# * |
| 99 | cfg_decoder_list_findextcxx . . $ cfg_decoder_list_findext(fa3ce1428af83150).(struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl, const char *ext) |
| 100 | { |
| 101 | struct cfg_decodercxx . . $ cfg_decoder# *d; |
| 102 | |
| 103 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(d, dl, entry) { |
| 104 | if (cfg_decoder_extsupportcxx . . $ cfg_decoder_extsupport(85762c1301d0f3c).(d, ext)) |
| 105 | return (d); |
| 106 | } |
| 107 | |
| 108 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | struct cfg_decodercxx . . $ cfg_decoder# * |
| 113 | cfg_decoder_list_getcxx . . $ cfg_decoder_list_get(fa3ce1428af83150).(struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl, const char *name) |
| 114 | { |
| 115 | struct cfg_decodercxx . . $ cfg_decoder# *d; |
| 116 | |
| 117 | d = cfg_decoder_list_findcxx . . $ cfg_decoder_list_find(fa3ce1428af83150).(dl, name); |
| 118 | if (d) |
| 119 | return (d); |
| 120 | d = cfg_decoder_createcxx . . $ cfg_decoder_create(d346db4af1b554c7).(name); |
| 121 | if (!d) |
| 122 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 123 | |
| 124 | TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(dl, d, entry); |
| 125 | |
| 126 | return (d); |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | cfg_decoder_list_removecxx . . $ cfg_decoder_list_remove(c04414ed9cb5b8c1).(struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl, struct cfg_decodercxx . . $ cfg_decoder# **d_p) |
| 131 | { |
| 132 | TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(dl, *d_p, entry); |
| 133 | cfg_decoder_destroycxx . . $ cfg_decoder_destroy(6c32b10b104ec8e2).(d_p); |
| 134 | } |
| 135 | |
| 136 | void |
| 137 | cfg_decoder_list_foreachcxx . . $ cfg_decoder_list_foreach(67a0558fbfe8df85).(struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl, |
| 138 | void (*cb)(cfg_decoder_tcxx . . $ cfg_decoder_t#, void *), void *cb_arg) |
| 139 | { |
| 140 | struct cfg_decodercxx . . $ cfg_decoder# *d; |
| 141 | |
| 142 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(d, dl, entry) { |
| 143 | cb(d, cb_arg); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | struct cfg_decodercxx . . $ cfg_decoder# * |
| 148 | cfg_decoder_createcxx . . $ cfg_decoder_create(d346db4af1b554c7).(const char *name) |
| 149 | { |
| 150 | struct cfg_decodercxx . . $ cfg_decoder# *d; |
| 151 | |
| 152 | if (!name || !name[0]) |
| 153 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 154 | |
| 155 | d = xcalloccxx . . $ `src/xalloc.h:23:9`!(1UL, sizeof(*d)); |
| 156 | d->namecxx . . $ cfg_decoder#name. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(name); |
| 157 | TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&d->exts); |
| 158 | |
| 159 | return (d); |
| 160 | } |
| 161 | |
| 162 | void |
| 163 | cfg_decoder_destroycxx . . $ cfg_decoder_destroy(6c32b10b104ec8e2).(struct cfg_decodercxx . . $ cfg_decoder# **d_p) |
| 164 | { |
| 165 | struct cfg_decodercxx . . $ cfg_decoder# *d = *d_p; |
| 166 | struct file_extcxx . . $ file_ext# *e; |
| 167 | |
| 168 | xfreecxx . . $ `src/xalloc.h:26:9`!(d->name); |
| 169 | xfreecxx . . $ `src/xalloc.h:26:9`!(d->program); |
| 170 | while (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! != (e = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&d->exts))) { |
| 171 | TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&d->exts, e, entry); |
| 172 | xfreecxx . . $ `src/xalloc.h:26:9`!(e->ext); |
| 173 | xfreecxx . . $ `src/xalloc.h:26:9`!(e); |
| 174 | } |
| 175 | xfreecxx . . $ `src/xalloc.h:26:9`!(d); |
| 176 | *d_p = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 177 | } |
| 178 | |
| 179 | int |
| 180 | cfg_decoder_set_namecxx . . $ cfg_decoder_set_name(1482a2e9031c2d61).(struct cfg_decodercxx . . $ cfg_decoder# *d, struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl, |
| 181 | const char *name, const char **errstrp) |
| 182 | { |
| 183 | struct cfg_decodercxx . . $ cfg_decoder# *d2; |
| 184 | |
| 185 | if (!name || !name[0]) { |
| 186 | if (errstrp) |
| 187 | *errstrp = "empty"; |
| 188 | return (-1); |
| 189 | } |
| 190 | |
| 191 | d2 = cfg_decoder_list_findcxx . . $ cfg_decoder_list_find(fa3ce1428af83150).(dl, name); |
| 192 | if (d2 && d2 != d) { |
| 193 | if (errstrp) |
| 194 | *errstrp = "already exists"; |
| 195 | return (-1); |
| 196 | } |
| 197 | |
| 198 | SET_XSTRDUPcxx . . $ `src/cfg_private.h:71:9`!(d->name, name, errstrp); |
| 199 | return (0); |
| 200 | } |
| 201 | |
| 202 | int |
| 203 | cfg_decoder_set_programcxx . . $ cfg_decoder_set_program(1482a2e9031c2d61).(struct cfg_decodercxx . . $ cfg_decoder# *d, |
| 204 | struct cfg_decoder_listcxx . . $ cfg_decoder_list# *not_used, const char *program, |
| 205 | const char **errstrp) |
| 206 | { |
| 207 | (void)not_used; |
| 208 | |
| 209 | if (!program || !program[0]) { |
| 210 | if (errstrp) |
| 211 | *errstrp = "empty"; |
| 212 | return (-1); |
| 213 | } |
| 214 | |
| 215 | xfreecxx . . $ `src/xalloc.h:26:9`!(d->program); |
| 216 | d->programcxx . . $ cfg_decoder#program. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(program); |
| 217 | |
| 218 | return (0); |
| 219 | } |
| 220 | |
| 221 | int |
| 222 | cfg_decoder_add_matchcxx . . $ cfg_decoder_add_match(1482a2e9031c2d61).(struct cfg_decodercxx . . $ cfg_decoder# *d, struct cfg_decoder_listcxx . . $ cfg_decoder_list# *dl, |
| 223 | const char *ext, const char **errstrp) |
| 224 | { |
| 225 | struct cfg_decodercxx . . $ cfg_decoder# *d2; |
| 226 | struct file_extcxx . . $ file_ext# *e, *e2; |
| 227 | |
| 228 | if (!ext || !ext[0]) { |
| 229 | if (errstrp) |
| 230 | *errstrp = "empty"; |
| 231 | return (-1); |
| 232 | } |
| 233 | |
| 234 | d2 = cfg_decoder_list_findextcxx . . $ cfg_decoder_list_findext(fa3ce1428af83150).(dl, ext); |
| 235 | e = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 236 | if (d2) { |
| 237 | e2 = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&d2->exts); |
| 238 | while (e2) { |
| 239 | if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(e2->extcxx . . $ file_ext#ext., ext)) { |
| 240 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("%s: relocating match from %s to %s", |
| 241 | ext, d2->namecxx . . $ cfg_decoder#name., d->namecxx . . $ cfg_decoder#name.); |
| 242 | TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&d2->exts, e2, entry); |
| 243 | e = e2; |
| 244 | break; |
| 245 | } |
| 246 | e2 = TAILQ_NEXTcxx . . $ `<external>/2546723208511035544/queue.h:459:9`!(e2, entry); |
| 247 | } |
| 248 | } |
| 249 | if (!e) { |
| 250 | e = xcalloccxx . . $ `src/xalloc.h:23:9`!(1UL, sizeof(*e)); |
| 251 | e->extcxx . . $ file_ext#ext. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(ext); |
| 252 | } |
| 253 | TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&d->exts, e, entry); |
| 254 | |
| 255 | return (0); |
| 256 | } |
| 257 | |
| 258 | int |
| 259 | cfg_decoder_validatecxx . . $ cfg_decoder_validate(11ea17061e373d7c).(struct cfg_decodercxx . . $ cfg_decoder# *d, const char **errstrp) |
| 260 | { |
| 261 | struct file_extcxx . . $ file_ext# *e; |
| 262 | unsigned int num_exts; |
| 263 | |
| 264 | if (!d->programcxx . . $ cfg_decoder#program.) { |
| 265 | if (errstrp) |
| 266 | *errstrp = "program not set"; |
| 267 | return (-1); |
| 268 | } |
| 269 | |
| 270 | num_exts = 0; |
| 271 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(e, &d->exts, entry) { |
| 272 | num_exts++; |
| 273 | } |
| 274 | if (!num_exts) { |
| 275 | if (errstrp) |
| 276 | *errstrp = "no file extensions registered"; |
| 277 | return (-1); |
| 278 | } |
| 279 | |
| 280 | CHECKPH_PROHIBITEDcxx . . $ `src/cfg_private.h:142:9`!(d->program, PLACEHOLDER_STRINGcxx . . $ `src/cfg.h:25:9`!); |
| 281 | CHECKPH_DUPLICATEcxx . . $ `src/cfg_private.h:150:9`!(d->program, PLACEHOLDER_TRACKcxx . . $ `src/cfg.h:24:9`!); |
| 282 | CHECKPH_DUPLICATEcxx . . $ `src/cfg_private.h:150:9`!(d->program, PLACEHOLDER_METADATAcxx . . $ `src/cfg.h:20:9`!); |
| 283 | CHECKPH_DUPLICATEcxx . . $ `src/cfg_private.h:150:9`!(d->program, PLACEHOLDER_ARTISTcxx . . $ `src/cfg.h:21:9`!); |
| 284 | CHECKPH_DUPLICATEcxx . . $ `src/cfg_private.h:150:9`!(d->program, PLACEHOLDER_TITLEcxx . . $ `src/cfg.h:23:9`!); |
| 285 | CHECKPH_REQUIREDcxx . . $ `src/cfg_private.h:162:9`!(d->program, PLACEHOLDER_TRACKcxx . . $ `src/cfg.h:24:9`!); |
| 286 | |
| 287 | return (0); |
| 288 | } |
| 289 | |
| 290 | int |
| 291 | cfg_decoder_extsupportcxx . . $ cfg_decoder_extsupport(85762c1301d0f3c).(struct cfg_decodercxx . . $ cfg_decoder# *d, const char *ext) |
| 292 | { |
| 293 | struct file_extcxx . . $ file_ext# *e; |
| 294 | |
| 295 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(e, &d->exts, entry) { |
| 296 | if (0 == strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(e->extcxx . . $ file_ext#ext., ext)) |
| 297 | return (1); |
| 298 | } |
| 299 | |
| 300 | return (0); |
| 301 | } |
| 302 | |
| 303 | void |
| 304 | cfg_decoder_ext_foreachcxx . . $ cfg_decoder_ext_foreach(e980ae9e2718d265).(struct cfg_decodercxx . . $ cfg_decoder# *d, |
| 305 | void (*cb)(const char *, void *), void *cb_arg) |
| 306 | { |
| 307 | struct file_extcxx . . $ file_ext# *e; |
| 308 | |
| 309 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(e, &d->exts, entry) { |
| 310 | cb(e->extcxx . . $ file_ext#ext., cb_arg); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | const char * |
| 315 | cfg_decoder_get_namecxx . . $ cfg_decoder_get_name(91efd9e702af964e).(struct cfg_decodercxx . . $ cfg_decoder# *d) |
| 316 | { |
| 317 | return (d->namecxx . . $ cfg_decoder#name.); |
| 318 | } |
| 319 | |
| 320 | const char * |
| 321 | cfg_decoder_get_programcxx . . $ cfg_decoder_get_program(91efd9e702af964e).(struct cfg_decodercxx . . $ cfg_decoder# *d) |
| 322 | { |
| 323 | return (d->programcxx . . $ cfg_decoder#program.); |
| 324 | } |