| 1 | /* |
| 2 | * ezstream - source client for Icecast with external en-/decoder support |
| 3 | * Copyright (C) 2003, 2004, 2005, 2006 Ed Zaleski <[email protected]> |
| 4 | * Copyright (C) 2007, 2009, 2015, 2017 Moritz Grimm <[email protected]> |
| 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 version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:412:9`! |
| 17 | # include "config.h"cxx . . $ `<file>/src/config.h`/ |
| 18 | #endif |
| 19 | |
| 20 | #include "compat.h"cxx . . $ `<file>/compat/compat.h`/ |
| 21 | |
| 22 | #include "ezstream.h"cxx . . $ `<file>/src/ezstream.h`/ |
| 23 | |
| 24 | #include <signal.h> |
| 25 | |
| 26 | #include "cfg.h"cxx . . $ `<file>/src/cfg.h`/ |
| 27 | #include "cmdline.h"cxx . . $ `<file>/src/cmdline.h`/ |
| 28 | #include "log.h"cxx . . $ `<file>/src/log.h`/ |
| 29 | #include "mdata.h"cxx . . $ `<file>/src/mdata.h`/ |
| 30 | #include "playlist.h"cxx . . $ `<file>/src/playlist.h`/ |
| 31 | #include "stream.h"cxx . . $ `<file>/src/stream.h`/ |
| 32 | #include "util.h"cxx . . $ `<file>/src/util.h`/ |
| 33 | #include "xalloc.h"cxx . . $ `<file>/src/xalloc.h`/ |
| 34 | |
| 35 | #define STREAM_DONEcxx . . $ `src/ezstream.c:35:9`! 0 |
| 36 | #define STREAM_CONTcxx . . $ `src/ezstream.c:36:9`! 1 |
| 37 | #define STREAM_SKIPcxx . . $ `src/ezstream.c:37:9`! 2 |
| 38 | #define STREAM_SERVERRcxx . . $ `src/ezstream.c:38:9`! 3 |
| 39 | #define STREAM_UPDMDATAcxx . . $ `src/ezstream.c:39:9`! 4 |
| 40 | |
| 41 | stream_tcxx . . $ stream_t# main_streamcxx . . $ main_stream.; |
| 42 | playlist_tcxx . . $ playlist_t# playlistcxx . . $ playlist.; |
| 43 | int playlistModecxx . . $ playlistMode.; |
| 44 | unsigned int resource_errorscxx . . $ resource_errors.; |
| 45 | |
| 46 | const int ezstream_signalscxx . . $ ezstream_signals.[] = { |
| 47 | SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!, SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!, SIGHUPcxx . . $ `<external>/11773118241360591791/signum-generic.h:56:9`!, SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!, SIGUSR2cxx . . $ `<external>/1457673850468744829/signum-arch.h:50:9`! |
| 48 | }; |
| 49 | |
| 50 | volatile sig_atomic_tcxx . . $ sig_atomic_t# rereadPlaylistcxx . . $ rereadPlaylist.; |
| 51 | volatile sig_atomic_tcxx . . $ sig_atomic_t# rereadPlaylist_notifycxx . . $ rereadPlaylist_notify.; |
| 52 | volatile sig_atomic_tcxx . . $ sig_atomic_t# skipTrackcxx . . $ skipTrack.; |
| 53 | volatile sig_atomic_tcxx . . $ sig_atomic_t# queryMetadatacxx . . $ queryMetadata.; |
| 54 | volatile sig_atomic_tcxx . . $ sig_atomic_t# quitcxx . . $ quit.; |
| 55 | |
| 56 | void sig_handlercxx . . $ sig_handler(d4f767463ce0a6b3).(int); |
| 57 | |
| 58 | static char * _build_reencode_cmdcxx . . $ _build_reencode_cmd(28e44a2798fbe905).(const char *, const char *, cfg_stream_tcxx . . $ cfg_stream_t#, |
| 59 | mdata_tcxx . . $ mdata_t#); |
| 60 | static FILEcxx . . $ FILE# * openResourcecxx . . $ openResource(24679f82c62a4fcb).(stream_tcxx . . $ stream_t#, const char *, int *, mdata_tcxx . . $ mdata_t# *, |
| 61 | int *, long *); |
| 62 | int reconnectcxx . . $ reconnect(e560f6a86f1dbfd1).(stream_tcxx . . $ stream_t#); |
| 63 | const char * getTimeStringcxx . . $ getTimeString(595caefabb192cea).(long); |
| 64 | int sendStreamcxx . . $ sendStream(f974962a2bce1cc).(stream_tcxx . . $ stream_t#, FILEcxx . . $ FILE# *, const char *, int, const char *, |
| 65 | struct timespeccxx . . $ timespec# *); |
| 66 | int streamFilecxx . . $ streamFile(ef58bb43cf5b9d8).(stream_tcxx . . $ stream_t#, const char *); |
| 67 | int streamPlaylistcxx . . $ streamPlaylist(e560f6a86f1dbfd1).(stream_tcxx . . $ stream_t#); |
| 68 | int ez_shutdowncxx . . $ ez_shutdown(7864480464b09eea).(int); |
| 69 | |
| 70 | void |
| 71 | sig_handlercxx . . $ sig_handler(d4f767463ce0a6b3).(int sig) |
| 72 | { |
| 73 | switch (sig) { |
| 74 | case SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!: |
| 75 | case SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!: |
| 76 | quitcxx . . $ quit. = 1; |
| 77 | break; |
| 78 | case SIGHUPcxx . . $ `<external>/11773118241360591791/signum-generic.h:56:9`!: |
| 79 | rereadPlaylistcxx . . $ rereadPlaylist. = 1; |
| 80 | rereadPlaylist_notifycxx . . $ rereadPlaylist_notify. = 1; |
| 81 | break; |
| 82 | case SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!: |
| 83 | skipTrackcxx . . $ skipTrack. = 1; |
| 84 | break; |
| 85 | case SIGUSR2cxx . . $ `<external>/1457673850468744829/signum-arch.h:50:9`!: |
| 86 | queryMetadatacxx . . $ queryMetadata. = 1; |
| 87 | break; |
| 88 | default: |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | static char * |
| 94 | _build_reencode_cmdcxx . . $ _build_reencode_cmd(28e44a2798fbe905).(const char *extension, const char *filename, |
| 95 | cfg_stream_tcxx . . $ cfg_stream_t# cfg_stream, mdata_tcxx . . $ mdata_t# md) |
| 96 | { |
| 97 | cfg_decoder_tcxx . . $ cfg_decoder_t# decoder; |
| 98 | cfg_encoder_tcxx . . $ cfg_encoder_t# encoder; |
| 99 | char *artist, *album, *title, *songinfo, *tmp; |
| 100 | char *filename_quoted; |
| 101 | char *custom_songinfo; |
| 102 | struct util_dictcxx . . $ util_dict# dicts[6]; |
| 103 | char *dec_str; |
| 104 | char *cmd_str; |
| 105 | size_t cmd_str_size; |
| 106 | |
| 107 | decoder = cfg_decoder_list_findextcxx . . $ cfg_decoder_list_findext(fa3ce1428af83150).(cfg_get_decoderscxx . . $ cfg_get_decoders(e15359236e44248b).(), extension); |
| 108 | if (!decoder) { |
| 109 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("cannot decode: %s: unsupported file extension %s", |
| 110 | filename, extension); |
| 111 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 112 | } |
| 113 | encoder = cfg_encoder_list_findcxx . . $ cfg_encoder_list_find(b613e7b3f606ecd3).(cfg_get_encoderscxx . . $ cfg_get_encoders(e957721effb49cb3).(), |
| 114 | cfg_stream_get_encodercxx . . $ cfg_stream_get_encoder(2200fed2ef732c87).(cfg_stream)); |
| 115 | if (!encoder) { |
| 116 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("cannot encode: %s: unknown encoder", |
| 117 | cfg_stream_get_encodercxx . . $ cfg_stream_get_encoder(2200fed2ef732c87).(cfg_stream)); |
| 118 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 119 | } |
| 120 | |
| 121 | tmp = util_utf82charcxx . . $ util_utf82char(a8b8e32347182212).(mdata_get_artistcxx . . $ mdata_get_artist(42a08b9e3d38b1e0).(md)); |
| 122 | artist = util_shellquotecxx . . $ util_shellquote(eabdfdef77619b3d).(tmp, 0); |
| 123 | xfreecxx . . $ `src/xalloc.h:26:9`!(tmp); |
| 124 | |
| 125 | tmp = util_utf82charcxx . . $ util_utf82char(a8b8e32347182212).(mdata_get_albumcxx . . $ mdata_get_album(42a08b9e3d38b1e0).(md)); |
| 126 | album = util_shellquotecxx . . $ util_shellquote(eabdfdef77619b3d).(tmp, 0); |
| 127 | xfreecxx . . $ `src/xalloc.h:26:9`!(tmp); |
| 128 | |
| 129 | tmp = util_utf82charcxx . . $ util_utf82char(a8b8e32347182212).(mdata_get_titlecxx . . $ mdata_get_title(42a08b9e3d38b1e0).(md)); |
| 130 | title = util_shellquotecxx . . $ util_shellquote(eabdfdef77619b3d).(tmp, 0); |
| 131 | xfreecxx . . $ `src/xalloc.h:26:9`!(tmp); |
| 132 | |
| 133 | tmp = util_utf82charcxx . . $ util_utf82char(a8b8e32347182212).(mdata_get_songinfocxx . . $ mdata_get_songinfo(42a08b9e3d38b1e0).(md)); |
| 134 | songinfo = util_shellquotecxx . . $ util_shellquote(eabdfdef77619b3d).(tmp, 0); |
| 135 | xfreecxx . . $ `src/xalloc.h:26:9`!(tmp); |
| 136 | |
| 137 | filename_quoted = util_shellquotecxx . . $ util_shellquote(eabdfdef77619b3d).(filename, 0); |
| 138 | |
| 139 | /* |
| 140 | * if (prog && format) |
| 141 | * metatoformat |
| 142 | * else |
| 143 | * if (!prog && title) |
| 144 | * emptymeta |
| 145 | * else |
| 146 | * replacemeta |
| 147 | */ |
| 148 | if (cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).() && |
| 149 | cfg_get_metadata_format_strcxx . . $ cfg_get_metadata_format_str(33a1f659e94feb42).()) { |
| 150 | char buf[BUFSIZcxx . . $ `<external>/232824719582829767/stdio.h:104:9`!]; |
| 151 | char *unquoted; |
| 152 | |
| 153 | mdata_strformatcxx . . $ mdata_strformat(2d1219fb966f86b0).(md, buf, sizeof(buf), |
| 154 | cfg_get_metadata_format_strcxx . . $ cfg_get_metadata_format_str(33a1f659e94feb42).()); |
| 155 | unquoted = util_utf82charcxx . . $ util_utf82char(a8b8e32347182212).(buf); |
| 156 | custom_songinfo = util_shellquotecxx . . $ util_shellquote(eabdfdef77619b3d).(unquoted, 0); |
| 157 | xfreecxx . . $ `src/xalloc.h:26:9`!(unquoted); |
| 158 | } else { |
| 159 | if (!cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).() && |
| 160 | strstrcxx . . $ `<external>/13506128340496143423/string.h:380:11`!(cfg_decoder_get_program(decoder), |
| 161 | PLACEHOLDER_TITLEcxx . . $ `src/cfg.h:23:9`!) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 162 | custom_songinfo = xstrdupcxx . . $ `src/xalloc.h:25:9`!(""); |
| 163 | } else { |
| 164 | custom_songinfo = xstrdupcxx . . $ `src/xalloc.h:25:9`!(songinfo); |
| 165 | } |
| 166 | } |
| 167 | xfreecxx . . $ `src/xalloc.h:26:9`!(songinfo); |
| 168 | |
| 169 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(dicts, 0, sizeof(dicts)); |
| 170 | dicts[0].fromcxx . . $ util_dict#from. = PLACEHOLDER_ARTISTcxx . . $ `src/cfg.h:21:9`!; |
| 171 | dicts[0].tocxx . . $ util_dict#to. = artist; |
| 172 | dicts[1].fromcxx . . $ util_dict#from. = PLACEHOLDER_ALBUMcxx . . $ `src/cfg.h:22:9`!; |
| 173 | dicts[1].tocxx . . $ util_dict#to. = album; |
| 174 | dicts[2].fromcxx . . $ util_dict#from. = PLACEHOLDER_TITLEcxx . . $ `src/cfg.h:23:9`!; |
| 175 | dicts[2].tocxx . . $ util_dict#to. = title; |
| 176 | dicts[3].fromcxx . . $ util_dict#from. = PLACEHOLDER_TRACKcxx . . $ `src/cfg.h:24:9`!; |
| 177 | dicts[3].tocxx . . $ util_dict#to. = filename_quoted; |
| 178 | dicts[4].fromcxx . . $ util_dict#from. = PLACEHOLDER_METADATAcxx . . $ `src/cfg.h:20:9`!; |
| 179 | dicts[4].tocxx . . $ util_dict#to. = custom_songinfo; |
| 180 | |
| 181 | if (!cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).() && |
| 182 | strstrcxx . . $ `<external>/13506128340496143423/string.h:380:11`!(cfg_encoder_get_program(encoder), |
| 183 | PLACEHOLDER_TITLEcxx . . $ `src/cfg.h:23:9`!) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 184 | xfreecxx . . $ `src/xalloc.h:26:9`!(custom_songinfo); |
| 185 | dicts[4].tocxx . . $ util_dict#to. = custom_songinfo = xstrdupcxx . . $ `src/xalloc.h:25:9`!(""); |
| 186 | } |
| 187 | |
| 188 | dec_str = util_expand_wordscxx . . $ util_expand_words(27058f725fae1c57).(cfg_decoder_get_programcxx . . $ cfg_decoder_get_program(91efd9e702af964e).(decoder), dicts); |
| 189 | cmd_str_size = strlencxx . . $ strlen(751346f8406fd082).(dec_str) + 1; |
| 190 | if (cfg_encoder_get_programcxx . . $ cfg_encoder_get_program(7eb039d546b1e15a).(encoder)) { |
| 191 | char *enc_str; |
| 192 | |
| 193 | enc_str = util_expand_wordscxx . . $ util_expand_words(27058f725fae1c57).(cfg_encoder_get_programcxx . . $ cfg_encoder_get_program(7eb039d546b1e15a).(encoder), |
| 194 | dicts); |
| 195 | cmd_str_size += strlencxx . . $ strlen(751346f8406fd082).(" | ") + strlencxx . . $ strlen(751346f8406fd082).(enc_str); |
| 196 | cmd_str = xcalloccxx . . $ `src/xalloc.h:23:9`!(cmd_str_size, sizeof(char)); |
| 197 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(cmd_str, cmd_str_size, "%s | %s", dec_str, enc_str); |
| 198 | xfreecxx . . $ `src/xalloc.h:26:9`!(enc_str); |
| 199 | xfreecxx . . $ `src/xalloc.h:26:9`!(dec_str); |
| 200 | } else { |
| 201 | cmd_str = xcalloccxx . . $ `src/xalloc.h:23:9`!(cmd_str_size, sizeof(char)); |
| 202 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(cmd_str, cmd_str_size, "%s", dec_str); |
| 203 | xfreecxx . . $ `src/xalloc.h:26:9`!(dec_str); |
| 204 | } |
| 205 | |
| 206 | xfreecxx . . $ `src/xalloc.h:26:9`!(artist); |
| 207 | xfreecxx . . $ `src/xalloc.h:26:9`!(album); |
| 208 | xfreecxx . . $ `src/xalloc.h:26:9`!(title); |
| 209 | xfreecxx . . $ `src/xalloc.h:26:9`!(filename_quoted); |
| 210 | xfreecxx . . $ `src/xalloc.h:26:9`!(custom_songinfo); |
| 211 | |
| 212 | return (cmd_str); |
| 213 | } |
| 214 | |
| 215 | static FILEcxx . . $ FILE# * |
| 216 | openResourcecxx . . $ openResource(24679f82c62a4fcb).(stream_tcxx . . $ stream_t# stream, const char *filename, int *popenFlag, |
| 217 | mdata_tcxx . . $ mdata_t# *md_p, int *isStdin, long *songLen) |
| 218 | { |
| 219 | FILEcxx . . $ FILE# *filep = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 220 | char extension[25]; |
| 221 | char *p = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 222 | char *pCommandString = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 223 | mdata_tcxx . . $ mdata_t# md; |
| 224 | cfg_stream_tcxx . . $ cfg_stream_t# cfg_stream = stream_get_cfg_streamcxx . . $ stream_get_cfg_stream(5d068d841fd5888b).(stream); |
| 225 | |
| 226 | if (md_p != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 227 | *md_p = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 228 | if (songLen != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 229 | *songLen = 0; |
| 230 | |
| 231 | if ((isStdin && *isStdin) || |
| 232 | strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(filename, "stdin") == 0) { |
| 233 | if (cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).()) { |
| 234 | md = mdata_createcxx . . $ mdata_create(bf1f2813200d3c0b).(); |
| 235 | |
| 236 | if (0 > mdata_run_programcxx . . $ mdata_run_program(65b6d78e09a82a4).(md, cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).()) || |
| 237 | 0 > stream_set_metadatacxx . . $ stream_set_metadata(b6629ca60a85dc43).(stream, md, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)) { |
| 238 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 239 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 240 | } |
| 241 | |
| 242 | if (md_p != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 243 | *md_p = md; |
| 244 | else |
| 245 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 246 | } |
| 247 | |
| 248 | if (isStdin != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 249 | *isStdin = 1; |
| 250 | filep = stdincxx . . $ `<external>/232824719582829767/stdio.h:157:9`!; |
| 251 | return (filep); |
| 252 | } |
| 253 | |
| 254 | if (isStdin != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 255 | *isStdin = 0; |
| 256 | |
| 257 | extension[0] = '\0'; |
| 258 | p = strrchrcxx . . $ `<external>/13506128340496143423/string.h:295:11`!(filename, '.'); |
| 259 | if (p != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 260 | strlcpycxx . . $ strlcpy(55abe9014c6d0e39).(extension, p, sizeof(extension)); |
| 261 | for (p = extension; *p != '\0'; p++) |
| 262 | *p = (char)tolowercxx . . $ `<external>/17904084882347303253/ctype.h:220:11`!((int)*p); |
| 263 | |
| 264 | if (strlencxx . . $ strlen(751346f8406fd082).(extension) == 0) { |
| 265 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: cannot determine file type", filename); |
| 266 | return (filep); |
| 267 | } |
| 268 | |
| 269 | md = mdata_createcxx . . $ mdata_create(bf1f2813200d3c0b).(); |
| 270 | if (cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).()) { |
| 271 | if (0 > mdata_run_programcxx . . $ mdata_run_program(65b6d78e09a82a4).(md, cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).())) |
| 272 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 273 | } else { |
| 274 | if (0 > mdata_parse_filecxx . . $ mdata_parse_file(65b6d78e09a82a4).(md, filename)) |
| 275 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 276 | } |
| 277 | if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == md) |
| 278 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 279 | if (songLen != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 280 | *songLen = mdata_get_lengthcxx . . $ mdata_get_length(cea3693af55ce6cb).(md); |
| 281 | |
| 282 | *popenFlag = 0; |
| 283 | if (cfg_stream_get_encodercxx . . $ cfg_stream_get_encoder(2200fed2ef732c87).(cfg_stream)) { |
| 284 | int stderr_fd = -1; |
| 285 | |
| 286 | pCommandString = _build_reencode_cmdcxx . . $ _build_reencode_cmd(28e44a2798fbe905).(extension, filename, |
| 287 | cfg_stream, md); |
| 288 | if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == pCommandString) { |
| 289 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 290 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 291 | } |
| 292 | if (md_p != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 293 | *md_p = md; |
| 294 | else |
| 295 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 296 | log_infocxx . . $ log_info(581fddd72a8db8fc).("running command: %s", pCommandString); |
| 297 | |
| 298 | if (cfg_get_program_quiet_stderrcxx . . $ cfg_get_program_quiet_stderr(b126dc7c1de90089).()) { |
| 299 | int fd; |
| 300 | |
| 301 | stderr_fd = dupcxx . . $ dup(7864480464b09eea).(filenocxx . . $ fileno(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!)); |
| 302 | if (0 > stderr_fd) { |
| 303 | log_alertcxx . . $ log_alert(581fddd72a8db8fc).("dup: %s", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 304 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 305 | } |
| 306 | if ((fd = opencxx . . $ open(e156e3aa1e5c4ad1).(_PATH_DEVNULLcxx . . $ `<external>/11492533085529128233/paths.h:45:9`!, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!, 0)) == -1) { |
| 307 | log_alertcxx . . $ log_alert(581fddd72a8db8fc).("%s: %s", _PATH_DEVNULLcxx . . $ `<external>/11492533085529128233/paths.h:45:9`!, |
| 308 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 309 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 310 | } |
| 311 | |
| 312 | dup2cxx . . $ dup2(9b79fb6aee4c0440).(fd, filenocxx . . $ fileno(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!)); |
| 313 | closecxx . . $ close(7864480464b09eea).(fd); |
| 314 | } |
| 315 | |
| 316 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 317 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 318 | if ((filep = popencxx . . $ popen(82ec0787cd37e0a3).(pCommandString, "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 319 | /* popen() does not set errno reliably ... */ |
| 320 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) |
| 321 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("execution error: %s: %s", |
| 322 | pCommandString, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 323 | else |
| 324 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("execution error: %s", |
| 325 | pCommandString); |
| 326 | } else { |
| 327 | *popenFlag = 1; |
| 328 | } |
| 329 | xfreecxx . . $ `src/xalloc.h:26:9`!(pCommandString); |
| 330 | |
| 331 | if (cfg_get_program_quiet_stderrcxx . . $ cfg_get_program_quiet_stderr(b126dc7c1de90089).()) |
| 332 | dup2cxx . . $ dup2(9b79fb6aee4c0440).(stderr_fd, filenocxx . . $ fileno(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!)); |
| 333 | |
| 334 | if (stderr_fd != -1) |
| 335 | closecxx . . $ close(7864480464b09eea).(stderr_fd); |
| 336 | |
| 337 | return (filep); |
| 338 | } |
| 339 | |
| 340 | if (md_p != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 341 | *md_p = md; |
| 342 | else |
| 343 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 344 | |
| 345 | if ((filep = fopencxx . . $ fopen(82ec0787cd37e0a3).(filename, "rb")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 346 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: %s", filename, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 347 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 348 | } |
| 349 | |
| 350 | return (filep); |
| 351 | } |
| 352 | |
| 353 | int |
| 354 | reconnectcxx . . $ reconnect(e560f6a86f1dbfd1).(stream_tcxx . . $ stream_t# stream) |
| 355 | { |
| 356 | unsigned int i; |
| 357 | cfg_server_tcxx . . $ cfg_server_t# cfg_server = stream_get_cfg_servercxx . . $ stream_get_cfg_server(c04f5d5f4c377bea).(stream); |
| 358 | |
| 359 | i = 0; |
| 360 | while (++i) { |
| 361 | if (cfg_server_get_reconnect_attemptscxx . . $ cfg_server_get_reconnect_attempts(50e7fa731851397f).(cfg_server) > 0) |
| 362 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("reconnect: %s: attempt #%u/%u ...", |
| 363 | cfg_server_get_hostnamecxx . . $ cfg_server_get_hostname(7a685941053ada3e).(cfg_server), i, |
| 364 | cfg_server_get_reconnect_attemptscxx . . $ cfg_server_get_reconnect_attempts(50e7fa731851397f).(cfg_server)); |
| 365 | else |
| 366 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("reconnect: %s: attempt #%u ...", |
| 367 | cfg_server_get_hostnamecxx . . $ cfg_server_get_hostname(7a685941053ada3e).(cfg_server), i); |
| 368 | |
| 369 | stream_disconnectcxx . . $ stream_disconnect(42ea99e01043689b).(stream); |
| 370 | if (0 == stream_connectcxx . . $ stream_connect(e560f6a86f1dbfd1).(stream)) { |
| 371 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("reconnect: %s: success", |
| 372 | cfg_server_get_hostnamecxx . . $ cfg_server_get_hostname(7a685941053ada3e).(cfg_server)); |
| 373 | return (0); |
| 374 | } |
| 375 | |
| 376 | if (cfg_server_get_reconnect_attemptscxx . . $ cfg_server_get_reconnect_attempts(50e7fa731851397f).(cfg_server) > 0 && |
| 377 | i >= cfg_server_get_reconnect_attemptscxx . . $ cfg_server_get_reconnect_attempts(50e7fa731851397f).(cfg_server)) |
| 378 | break; |
| 379 | |
| 380 | if (quitcxx . . $ quit.) |
| 381 | return (-1); |
| 382 | else |
| 383 | sleepcxx . . $ sleep(2141b656ce2cc063).(5); |
| 384 | }; |
| 385 | |
| 386 | log_warningcxx . . $ log_warning(581fddd72a8db8fc).("reconnect failed: giving up"); |
| 387 | |
| 388 | return (-1); |
| 389 | } |
| 390 | |
| 391 | const char * |
| 392 | getTimeStringcxx . . $ getTimeString(595caefabb192cea).(long seconds) |
| 393 | { |
| 394 | static char str[25]; |
| 395 | long secs, mins, hours; |
| 396 | |
| 397 | if (seconds < 0) |
| 398 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 399 | |
| 400 | secs = seconds; |
| 401 | hours = secs / 3600; |
| 402 | secs %= 3600; |
| 403 | mins = secs / 60; |
| 404 | secs %= 60; |
| 405 | |
| 406 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(str, sizeof(str), "%ldh%02ldm%02lds", hours, mins, secs); |
| 407 | return ((const char *)str); |
| 408 | } |
| 409 | |
| 410 | int |
| 411 | sendStreamcxx . . $ sendStream(f974962a2bce1cc).(stream_tcxx . . $ stream_t# stream, FILEcxx . . $ FILE# *filepstream, const char *fileName, |
| 412 | int isStdin, const char *songLenStr, struct timespeccxx . . $ timespec# *tv) |
| 413 | { |
| 414 | char buff[4096]; |
| 415 | size_t bytes_read, total, oldTotal; |
| 416 | int ret; |
| 417 | double kbps = -1.0; |
| 418 | struct timespeccxx . . $ timespec# timeStamp, *startTime = tv; |
| 419 | struct timespeccxx . . $ timespec# callTime, currentTime; |
| 420 | cfg_server_tcxx . . $ cfg_server_t# cfg_server = stream_get_cfg_servercxx . . $ stream_get_cfg_server(c04f5d5f4c377bea).(stream); |
| 421 | cfg_intake_tcxx . . $ cfg_intake_t# cfg_intake = stream_get_cfg_intakecxx . . $ stream_get_cfg_intake(b24beca3dc86be4b).(stream); |
| 422 | |
| 423 | clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, &callTime); |
| 424 | |
| 425 | timeStamp.tv_seccxx . . $ timespec#tv_sec. = startTime->tv_seccxx . . $ timespec#tv_sec.; |
| 426 | timeStamp.tv_nseccxx . . $ timespec#tv_nsec. = startTime->tv_nseccxx . . $ timespec#tv_nsec.; |
| 427 | |
| 428 | total = oldTotal = 0; |
| 429 | ret = STREAM_DONEcxx . . $ `src/ezstream.c:35:9`!; |
| 430 | while ((bytes_read = freadcxx . . $ fread(738fc8ac1d711e58).(buff, 1, sizeof(buff), filepstream)) > 0) { |
| 431 | if (!stream_get_connectedcxx . . $ stream_get_connected(e560f6a86f1dbfd1).(stream)) { |
| 432 | log_warningcxx . . $ log_warning(581fddd72a8db8fc).("%s: connection lost", |
| 433 | cfg_server_get_hostnamecxx . . $ cfg_server_get_hostname(7a685941053ada3e).(cfg_server)); |
| 434 | if (0 > reconnectcxx . . $ reconnect(e560f6a86f1dbfd1).(stream)) { |
| 435 | ret = STREAM_SERVERRcxx . . $ `src/ezstream.c:38:9`!; |
| 436 | break; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | stream_synccxx . . $ stream_sync(42ea99e01043689b).(stream); |
| 441 | |
| 442 | if (0 > stream_sendcxx . . $ stream_send(5edb09aac611db9a).(stream, buff, bytes_read)) { |
| 443 | if (0 > reconnectcxx . . $ reconnect(e560f6a86f1dbfd1).(stream)) |
| 444 | ret = STREAM_SERVERRcxx . . $ `src/ezstream.c:38:9`!; |
| 445 | break; |
| 446 | } |
| 447 | |
| 448 | if (quitcxx . . $ quit.) |
| 449 | break; |
| 450 | if (rereadPlaylist_notifycxx . . $ rereadPlaylist_notify.) { |
| 451 | rereadPlaylist_notifycxx . . $ rereadPlaylist_notify. = 0; |
| 452 | if (CFG_INTAKE_PLAYLISTcxx . . $ CFG_INTAKE_PLAYLIST. == cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(cfg_intake)) |
| 453 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("HUP signal received: playlist re-read scheduled"); |
| 454 | } |
| 455 | if (skipTrackcxx . . $ skipTrack.) { |
| 456 | skipTrackcxx . . $ skipTrack. = 0; |
| 457 | ret = STREAM_SKIPcxx . . $ `src/ezstream.c:37:9`!; |
| 458 | break; |
| 459 | } |
| 460 | |
| 461 | clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, ¤tTime); |
| 462 | |
| 463 | if (queryMetadatacxx . . $ queryMetadata. || |
| 464 | (0 <= cfg_get_metadata_refresh_intervalcxx . . $ cfg_get_metadata_refresh_interval(b126dc7c1de90089).() && |
| 465 | (currentTime.tv_seccxx . . $ timespec#tv_sec. - callTime.tv_seccxx . . $ timespec#tv_sec. >= |
| 466 | cfg_get_metadata_refresh_intervalcxx . . $ cfg_get_metadata_refresh_interval(b126dc7c1de90089).()))) { |
| 467 | queryMetadatacxx . . $ queryMetadata. = 0; |
| 468 | if (cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).()) { |
| 469 | ret = STREAM_UPDMDATAcxx . . $ `src/ezstream.c:39:9`!; |
| 470 | break; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | total += bytes_read; |
| 475 | if (cfg_get_program_rtstatus_outputcxx . . $ cfg_get_program_rtstatus_output(b126dc7c1de90089).()) { |
| 476 | double oldTime, newTime; |
| 477 | |
| 478 | if (!isStdin && playlistModecxx . . $ playlistMode.) { |
| 479 | if (CFG_INTAKE_PROGRAMcxx . . $ CFG_INTAKE_PROGRAM. == cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(cfg_intake)) { |
| 480 | char *tmp = xstrdupcxx . . $ `src/xalloc.h:25:9`!(cfg_intake_get_filename(cfg_intake)); |
| 481 | printfcxx . . $ printf(581fddd72a8db8fc).(" [%s]", basenamecxx . . $ basename(a8b8e32347182212).(tmp)); |
| 482 | xfreecxx . . $ `src/xalloc.h:26:9`!(tmp); |
| 483 | } else |
| 484 | printfcxx . . $ printf(581fddd72a8db8fc).(" [%4lu/%-4lu]", |
| 485 | playlist_get_positioncxx . . $ playlist_get_position(3834682fb383ec5a).(playlistcxx . . $ playlist.), |
| 486 | playlist_get_num_itemscxx . . $ playlist_get_num_items(3834682fb383ec5a).(playlistcxx . . $ playlist.)); |
| 487 | } |
| 488 | |
| 489 | oldTime = (double)timeStamp.tv_seccxx . . $ timespec#tv_sec. |
| 490 | + (double)timeStamp.tv_nseccxx . . $ timespec#tv_nsec. / 1000000000.0; |
| 491 | newTime = (double)currentTime.tv_seccxx . . $ timespec#tv_sec. |
| 492 | + (double)currentTime.tv_nseccxx . . $ timespec#tv_nsec. / 1000000000.0; |
| 493 | if (songLenStr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 494 | printfcxx . . $ printf(581fddd72a8db8fc).(" [ %s]", |
| 495 | getTimeStringcxx . . $ getTimeString(595caefabb192cea).(currentTime.tv_seccxx . . $ timespec#tv_sec. - |
| 496 | startTime->tv_seccxx . . $ timespec#tv_sec.)); |
| 497 | else |
| 498 | printfcxx . . $ printf(581fddd72a8db8fc).(" [ %s/%s]", |
| 499 | getTimeStringcxx . . $ getTimeString(595caefabb192cea).(currentTime.tv_seccxx . . $ timespec#tv_sec. - |
| 500 | startTime->tv_seccxx . . $ timespec#tv_sec.), |
| 501 | songLenStr); |
| 502 | if (newTime - oldTime >= 1.0) { |
| 503 | kbps = (((double)(total - oldTotal) |
| 504 | / (newTime - oldTime)) * 8.0) / 1000.0; |
| 505 | timeStamp.tv_seccxx . . $ timespec#tv_sec. = currentTime.tv_seccxx . . $ timespec#tv_sec.; |
| 506 | timeStamp.tv_nseccxx . . $ timespec#tv_nsec. = currentTime.tv_nseccxx . . $ timespec#tv_nsec.; |
| 507 | oldTotal = total; |
| 508 | } |
| 509 | if (kbps < 0) |
| 510 | printfcxx . . $ printf(581fddd72a8db8fc).(" "); |
| 511 | else |
| 512 | printfcxx . . $ printf(581fddd72a8db8fc).(" [%8.2f kbps]", kbps); |
| 513 | |
| 514 | printfcxx . . $ printf(581fddd72a8db8fc).(" \r"); |
| 515 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!); |
| 516 | } |
| 517 | } |
| 518 | if (ferrorcxx . . $ ferror(89bc1efcdac0ca22).(filepstream)) { |
| 519 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!) { |
| 520 | clearerrcxx . . $ clearerr(8d4262d45fc644ab).(filepstream); |
| 521 | ret = STREAM_CONTcxx . . $ `src/ezstream.c:36:9`!; |
| 522 | } else if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EBADFcxx . . $ `<external>/8987895939074593727/errno-base.h:13:9`! && isStdin) |
| 523 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("no (more) data available on standard input"); |
| 524 | else |
| 525 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("sendStream: %s: %s", fileName, |
| 526 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 527 | } |
| 528 | |
| 529 | return (ret); |
| 530 | } |
| 531 | |
| 532 | int |
| 533 | streamFilecxx . . $ streamFile(ef58bb43cf5b9d8).(stream_tcxx . . $ stream_t# stream, const char *fileName) |
| 534 | { |
| 535 | FILEcxx . . $ FILE# *filepstream = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 536 | int popenFlag = 0; |
| 537 | char *songLenStr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 538 | int ret, retval = 0; |
| 539 | long songLen; |
| 540 | mdata_tcxx . . $ mdata_t# md = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 541 | struct timespeccxx . . $ timespec# startTime; |
| 542 | cfg_stream_tcxx . . $ cfg_stream_t# cfg_stream = stream_get_cfg_streamcxx . . $ stream_get_cfg_stream(5d068d841fd5888b).(stream); |
| 543 | cfg_intake_tcxx . . $ cfg_intake_t# cfg_intake = stream_get_cfg_intakecxx . . $ stream_get_cfg_intake(b24beca3dc86be4b).(stream); |
| 544 | int isStdin = cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(cfg_intake) == CFG_INTAKE_STDINcxx . . $ CFG_INTAKE_STDIN.; |
| 545 | |
| 546 | if ((filepstream = openResourcecxx . . $ openResource(24679f82c62a4fcb).(stream, fileName, &popenFlag, &md, &isStdin, &songLen)) |
| 547 | == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 548 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 549 | if (++resource_errorscxx . . $ resource_errors. > 100) { |
| 550 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("too many errors; giving up"); |
| 551 | return (0); |
| 552 | } |
| 553 | /* Continue with next resource on failure: */ |
| 554 | return (1); |
| 555 | } |
| 556 | resource_errorscxx . . $ resource_errors. = 0; |
| 557 | |
| 558 | if (md != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 559 | const char *tmp; |
| 560 | char *metaData; |
| 561 | |
| 562 | tmp = mdata_get_songinfocxx . . $ mdata_get_songinfo(42a08b9e3d38b1e0).(md) ? |
| 563 | mdata_get_songinfocxx . . $ mdata_get_songinfo(42a08b9e3d38b1e0).(md) : mdata_get_namecxx . . $ mdata_get_name(42a08b9e3d38b1e0).(md); |
| 564 | metaData = util_utf82charcxx . . $ util_utf82char(a8b8e32347182212).(tmp); |
| 565 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("streaming: %s (%s)", metaData, |
| 566 | isStdin ? "stdin" : fileName); |
| 567 | xfreecxx . . $ `src/xalloc.h:26:9`!(metaData); |
| 568 | |
| 569 | /* MP3 streams are special, so set the metadata explicitly: */ |
| 570 | if (CFG_STREAM_MP3cxx . . $ CFG_STREAM_MP3. == cfg_stream_get_formatcxx . . $ cfg_stream_get_format(a1a4274431071f63).(cfg_stream)) |
| 571 | stream_set_metadatacxx . . $ stream_set_metadata(b6629ca60a85dc43).(stream, md, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 572 | |
| 573 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 574 | } else if (isStdin) |
| 575 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("streaming: standard input"); |
| 576 | |
| 577 | if (songLen > 0) |
| 578 | songLenStr = xstrdupcxx . . $ `src/xalloc.h:25:9`!(getTimeString(songLen)); |
| 579 | clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, &startTime); |
| 580 | do { |
| 581 | ret = sendStreamcxx . . $ sendStream(f974962a2bce1cc).(stream, filepstream, fileName, isStdin, |
| 582 | songLenStr, &startTime); |
| 583 | if (quitcxx . . $ quit.) |
| 584 | break; |
| 585 | if (ret != STREAM_DONEcxx . . $ `src/ezstream.c:35:9`!) { |
| 586 | if ((skipTrackcxx . . $ skipTrack. && rereadPlaylistcxx . . $ rereadPlaylist.) || |
| 587 | (skipTrackcxx . . $ skipTrack. && queryMetadatacxx . . $ queryMetadata.)) { |
| 588 | skipTrackcxx . . $ skipTrack. = 0; |
| 589 | ret = STREAM_CONTcxx . . $ `src/ezstream.c:36:9`!; |
| 590 | } |
| 591 | if (queryMetadatacxx . . $ queryMetadata. && rereadPlaylistcxx . . $ rereadPlaylist.) { |
| 592 | queryMetadatacxx . . $ queryMetadata. = 0; |
| 593 | ret = STREAM_CONTcxx . . $ `src/ezstream.c:36:9`!; |
| 594 | } |
| 595 | if (ret == STREAM_SKIPcxx . . $ `src/ezstream.c:37:9`! || skipTrackcxx . . $ skipTrack.) { |
| 596 | skipTrackcxx . . $ skipTrack. = 0; |
| 597 | if (!isStdin) |
| 598 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("USR1 signal received: skipping current track"); |
| 599 | retval = 1; |
| 600 | ret = STREAM_DONEcxx . . $ `src/ezstream.c:35:9`!; |
| 601 | } |
| 602 | if (ret == STREAM_UPDMDATAcxx . . $ `src/ezstream.c:39:9`! || queryMetadatacxx . . $ queryMetadata.) { |
| 603 | queryMetadatacxx . . $ queryMetadata. = 0; |
| 604 | if (cfg_get_metadata_no_updatescxx . . $ cfg_get_metadata_no_updates(b126dc7c1de90089).()) |
| 605 | continue; |
| 606 | if (cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).()) { |
| 607 | char *mdataStr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 608 | |
| 609 | log_infocxx . . $ log_info(581fddd72a8db8fc).("running metadata program: %s", |
| 610 | cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).()); |
| 611 | md = mdata_createcxx . . $ mdata_create(bf1f2813200d3c0b).(); |
| 612 | if (0 > mdata_run_programcxx . . $ mdata_run_program(65b6d78e09a82a4).(md, cfg_get_metadata_programcxx . . $ cfg_get_metadata_program(33a1f659e94feb42).()) || |
| 613 | 0 > stream_set_metadatacxx . . $ stream_set_metadata(b6629ca60a85dc43).(stream, md, &mdataStr)) { |
| 614 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 615 | retval = 0; |
| 616 | ret = STREAM_DONEcxx . . $ `src/ezstream.c:35:9`!; |
| 617 | continue; |
| 618 | } |
| 619 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(&md); |
| 620 | log_infocxx . . $ log_info(581fddd72a8db8fc).("new metadata: %s", mdataStr); |
| 621 | xfreecxx . . $ `src/xalloc.h:26:9`!(mdataStr); |
| 622 | } |
| 623 | } |
| 624 | if (ret == STREAM_SERVERRcxx . . $ `src/ezstream.c:38:9`!) { |
| 625 | retval = 0; |
| 626 | ret = STREAM_DONEcxx . . $ `src/ezstream.c:35:9`!; |
| 627 | } |
| 628 | } else |
| 629 | retval = 1; |
| 630 | } while (ret != STREAM_DONEcxx . . $ `src/ezstream.c:35:9`!); |
| 631 | |
| 632 | if (popenFlag) |
| 633 | pclosecxx . . $ pclose(89bc1efcdac0ca22).(filepstream); |
| 634 | else if (!isStdin) |
| 635 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(filepstream); |
| 636 | |
| 637 | if (songLenStr != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 638 | xfreecxx . . $ `src/xalloc.h:26:9`!(songLenStr); |
| 639 | |
| 640 | return (retval); |
| 641 | } |
| 642 | |
| 643 | int |
| 644 | streamPlaylistcxx . . $ streamPlaylist(e560f6a86f1dbfd1).(stream_tcxx . . $ stream_t# stream) |
| 645 | { |
| 646 | const char *song; |
| 647 | char lastSong[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 648 | cfg_intake_tcxx . . $ cfg_intake_t# cfg_intake = stream_get_cfg_intakecxx . . $ stream_get_cfg_intake(b24beca3dc86be4b).(stream); |
| 649 | |
| 650 | if (playlistcxx . . $ playlist. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 651 | switch (cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(cfg_intake)) { |
| 652 | case CFG_INTAKE_PROGRAMcxx . . $ CFG_INTAKE_PROGRAM.: |
| 653 | if ((playlistcxx . . $ playlist. = playlist_programcxx . . $ playlist_program(ea32118fbd7a0ccc).(cfg_intake_get_filenamecxx . . $ cfg_intake_get_filename(56a97a66344ba534).(cfg_intake))) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 654 | return (0); |
| 655 | break; |
| 656 | case CFG_INTAKE_STDINcxx . . $ CFG_INTAKE_STDIN.: |
| 657 | if ((playlistcxx . . $ playlist. = playlist_readcxx . . $ playlist_read(ea32118fbd7a0ccc).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 658 | return (0); |
| 659 | break; |
| 660 | default: |
| 661 | if ((playlistcxx . . $ playlist. = playlist_readcxx . . $ playlist_read(ea32118fbd7a0ccc).(cfg_intake_get_filenamecxx . . $ cfg_intake_get_filename(56a97a66344ba534).(cfg_intake))) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 662 | return (0); |
| 663 | if (playlist_get_num_itemscxx . . $ playlist_get_num_items(3834682fb383ec5a).(playlistcxx . . $ playlist.) == 0) |
| 664 | log_warningcxx . . $ log_warning(581fddd72a8db8fc).("%s: playlist empty", |
| 665 | cfg_intake_get_filenamecxx . . $ cfg_intake_get_filename(56a97a66344ba534).(cfg_intake)); |
| 666 | break; |
| 667 | } |
| 668 | } else { |
| 669 | /* |
| 670 | * XXX: This preserves traditional behavior, however, |
| 671 | * rereading the playlist after each walkthrough seems a |
| 672 | * bit more logical. |
| 673 | */ |
| 674 | playlist_rewindcxx . . $ playlist_rewind(fbb1db036548eb22).(playlistcxx . . $ playlist.); |
| 675 | } |
| 676 | |
| 677 | if (CFG_INTAKE_PROGRAMcxx . . $ CFG_INTAKE_PROGRAM. != cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(cfg_intake) && |
| 678 | cfg_intake_get_shufflecxx . . $ cfg_intake_get_shuffle(2ab3bd772c3b65f).(cfg_intake)) |
| 679 | playlist_shufflecxx . . $ playlist_shuffle(fbb1db036548eb22).(playlistcxx . . $ playlist.); |
| 680 | |
| 681 | while ((song = playlist_get_nextcxx . . $ playlist_get_next(4a6773dfaf0af90e).(playlistcxx . . $ playlist.)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 682 | strlcpycxx . . $ strlcpy(55abe9014c6d0e39).(lastSong, song, sizeof(lastSong)); |
| 683 | if (!streamFilecxx . . $ streamFile(ef58bb43cf5b9d8).(stream, song)) |
| 684 | return (0); |
| 685 | if (quitcxx . . $ quit.) |
| 686 | break; |
| 687 | if (rereadPlaylistcxx . . $ rereadPlaylist.) { |
| 688 | rereadPlaylistcxx . . $ rereadPlaylist. = rereadPlaylist_notifycxx . . $ rereadPlaylist_notify. = 0; |
| 689 | if (CFG_INTAKE_PROGRAMcxx . . $ CFG_INTAKE_PROGRAM. == cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(cfg_intake)) |
| 690 | continue; |
| 691 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("rereading playlist"); |
| 692 | if (!playlist_rereadcxx . . $ playlist_reread(47e6b14e38f59d9e).(&playlistcxx . . $ playlist.)) |
| 693 | return (0); |
| 694 | if (cfg_intake_get_shufflecxx . . $ cfg_intake_get_shuffle(2ab3bd772c3b65f).(cfg_intake)) |
| 695 | playlist_shufflecxx . . $ playlist_shuffle(fbb1db036548eb22).(playlistcxx . . $ playlist.); |
| 696 | else { |
| 697 | playlist_goto_entrycxx . . $ playlist_goto_entry(a782fde374a10b12).(playlistcxx . . $ playlist., lastSong); |
| 698 | playlist_skip_nextcxx . . $ playlist_skip_next(fbb1db036548eb22).(playlistcxx . . $ playlist.); |
| 699 | } |
| 700 | continue; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | return (1); |
| 705 | } |
| 706 | |
| 707 | int |
| 708 | ez_shutdowncxx . . $ ez_shutdown(7864480464b09eea).(int exitval) |
| 709 | { |
| 710 | if (main_streamcxx . . $ main_stream.) |
| 711 | stream_destroycxx . . $ stream_destroy(a819560812e4e895).(&main_streamcxx . . $ main_stream.); |
| 712 | |
| 713 | stream_exitcxx . . $ stream_exit(49f6e7a06ebc5aa8).(); |
| 714 | playlist_exitcxx . . $ playlist_exit(49f6e7a06ebc5aa8).(); |
| 715 | log_exitcxx . . $ log_exit(49f6e7a06ebc5aa8).(); |
| 716 | cfg_exitcxx . . $ cfg_exit(49f6e7a06ebc5aa8).(); |
| 717 | |
| 718 | return (exitval); |
| 719 | } |
| 720 | |
| 721 | int |
| 722 | maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) |
| 723 | { |
| 724 | int ret, cont; |
| 725 | const char *errstr; |
| 726 | extern char *optargcxx . . $ optarg.; |
| 727 | extern int optindcxx . . $ optind.; |
| 728 | struct sigactioncxx . . $ sigaction# act; |
| 729 | unsigned int i; |
| 730 | cfg_server_tcxx . . $ cfg_server_t# cfg_server; |
| 731 | cfg_stream_tcxx . . $ cfg_stream_t# cfg_stream; |
| 732 | cfg_intake_tcxx . . $ cfg_intake_t# cfg_intake; |
| 733 | |
| 734 | ret = 1; |
| 735 | if (0 > cfg_initcxx . . $ cfg_init(b126dc7c1de90089).() || |
| 736 | 0 > cmdline_parsecxx . . $ cmdline_parse(e4d6922c49795a40).(argc, argv, &ret) || |
| 737 | 0 > log_initcxx . . $ log_init(5c4306d8553b3696).(cfg_get_program_namecxx . . $ cfg_get_program_name(33a1f659e94feb42).()) || |
| 738 | 0 > playlist_initcxx . . $ playlist_init(b126dc7c1de90089).() || |
| 739 | 0 > cfg_file_reloadcxx . . $ cfg_file_reload(b126dc7c1de90089).() || |
| 740 | 0 > stream_initcxx . . $ stream_init(b126dc7c1de90089).()) |
| 741 | return (ez_shutdowncxx . . $ ez_shutdown(7864480464b09eea).(ret)); |
| 742 | |
| 743 | log_set_verbositycxx . . $ log_set_verbosity(cb2f890c2fdad230).(cfg_get_program_verbositycxx . . $ cfg_get_program_verbosity(db52760e79bf9054).()); |
| 744 | |
| 745 | if (0 > cfg_checkcxx . . $ cfg_check(15355eb6db2855df).(&errstr)) { |
| 746 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: %s", cfg_get_program_config_filecxx . . $ cfg_get_program_config_file(33a1f659e94feb42).(), errstr); |
| 747 | return (ez_shutdowncxx . . $ ez_shutdown(7864480464b09eea).(2)); |
| 748 | } |
| 749 | |
| 750 | main_streamcxx . . $ main_stream. = stream_createcxx . . $ stream_create(ed53485bf0dc7f57).(CFG_DEFAULTcxx . . $ `src/cfg.h:27:9`!); |
| 751 | if (0 > stream_configurecxx . . $ stream_configure(e560f6a86f1dbfd1).(main_streamcxx . . $ main_stream.)) { |
| 752 | stream_destroycxx . . $ stream_destroy(a819560812e4e895).(&main_streamcxx . . $ main_stream.); |
| 753 | return (ez_shutdowncxx . . $ ez_shutdown(7864480464b09eea).(1)); |
| 754 | } |
| 755 | cfg_server = stream_get_cfg_servercxx . . $ stream_get_cfg_server(c04f5d5f4c377bea).(main_streamcxx . . $ main_stream.); |
| 756 | cfg_stream = stream_get_cfg_streamcxx . . $ stream_get_cfg_stream(5d068d841fd5888b).(main_streamcxx . . $ main_stream.); |
| 757 | cfg_intake = stream_get_cfg_intakecxx . . $ stream_get_cfg_intake(b24beca3dc86be4b).(main_streamcxx . . $ main_stream.); |
| 758 | |
| 759 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&act, 0, sizeof(act)); |
| 760 | act.sa_handlercxx . . $ `<external>/16635209305659446502/sigaction.h:39:10`! = sig_handlercxx . . $ sig_handler(d4f767463ce0a6b3).; |
| 761 | #ifdef SA_RESTARTcxx . . $ `<external>/16635209305659446502/sigaction.h:64:10`! |
| 762 | act.sa_flagscxx . . $ sigaction#sa_flags. = SA_RESTARTcxx . . $ `<external>/16635209305659446502/sigaction.h:64:10`!; |
| 763 | #endif |
| 764 | for (i = 0; i < sizeof(ezstream_signalscxx . . $ ezstream_signals.) / sizeof(int); i++) { |
| 765 | if (sigactioncxx . . $ sigaction(53aba09fe16b06c7).(ezstream_signalscxx . . $ ezstream_signals.[i], &act, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) == -1) { |
| 766 | log_syserrcxx . . $ log_syserr(7edabc5ef8d007a9).(ERRORcxx . . $ ERROR., errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, "sigaction"); |
| 767 | stream_destroycxx . . $ stream_destroy(a819560812e4e895).(&main_streamcxx . . $ main_stream.); |
| 768 | return (ez_shutdowncxx . . $ ez_shutdown(7864480464b09eea).(1)); |
| 769 | } |
| 770 | } |
| 771 | /* |
| 772 | * Ignore SIGPIPE, which has been seen to give a long-running ezstream |
| 773 | * process trouble. EOF and/or EPIPE are also easier to handle. |
| 774 | */ |
| 775 | #ifndef SIG_IGNcxx . . $ `<external>/11773118241360591791/signum-generic.h:30:9`! |
| 776 | # define SIG_IGN (void (*)(int))1 |
| 777 | #endif /* !SIG_IGN */ |
| 778 | act.sa_handlercxx . . $ `<external>/16635209305659446502/sigaction.h:39:10`! = SIG_IGNcxx . . $ `<external>/11773118241360591791/signum-generic.h:30:9`!; |
| 779 | if (sigactioncxx . . $ sigaction(53aba09fe16b06c7).(SIGPIPEcxx . . $ `<external>/11773118241360591791/signum-generic.h:60:9`!, &act, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) == -1) { |
| 780 | log_syserrcxx . . $ log_syserr(7edabc5ef8d007a9).(ERRORcxx . . $ ERROR., errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, "sigaction"); |
| 781 | stream_destroycxx . . $ stream_destroy(a819560812e4e895).(&main_streamcxx . . $ main_stream.); |
| 782 | return (ez_shutdowncxx . . $ ez_shutdown(7864480464b09eea).(1)); |
| 783 | } |
| 784 | |
| 785 | if (0 > util_write_pid_filecxx . . $ util_write_pid_file(5c4306d8553b3696).(cfg_get_program_pid_filecxx . . $ cfg_get_program_pid_file(33a1f659e94feb42).())) |
| 786 | log_syserrcxx . . $ log_syserr(7edabc5ef8d007a9).(WARNINGcxx . . $ WARNING., errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, cfg_get_program_pid_filecxx . . $ cfg_get_program_pid_file(33a1f659e94feb42).()); |
| 787 | |
| 788 | if (0 > stream_connectcxx . . $ stream_connect(e560f6a86f1dbfd1).(main_streamcxx . . $ main_stream.)) { |
| 789 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("initial server connection failed"); |
| 790 | stream_destroycxx . . $ stream_destroy(a819560812e4e895).(&main_streamcxx . . $ main_stream.); |
| 791 | return (ez_shutdowncxx . . $ ez_shutdown(7864480464b09eea).(1)); |
| 792 | } |
| 793 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("connected: %s://%s:%u%s", |
| 794 | cfg_server_get_protocol_strcxx . . $ cfg_server_get_protocol_str(7a685941053ada3e).(cfg_server), |
| 795 | cfg_server_get_hostnamecxx . . $ cfg_server_get_hostname(7a685941053ada3e).(cfg_server), |
| 796 | cfg_server_get_portcxx . . $ cfg_server_get_port(50e7fa731851397f).(cfg_server), |
| 797 | cfg_stream_get_mountpointcxx . . $ cfg_stream_get_mountpoint(2200fed2ef732c87).(cfg_stream)); |
| 798 | |
| 799 | if (CFG_INTAKE_PROGRAMcxx . . $ CFG_INTAKE_PROGRAM. == cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(cfg_intake) || |
| 800 | CFG_INTAKE_PLAYLISTcxx . . $ CFG_INTAKE_PLAYLIST. == cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(cfg_intake) || |
| 801 | (CFG_INTAKE_AUTODETECTcxx . . $ CFG_INTAKE_AUTODETECT. == cfg_intake_get_typecxx . . $ cfg_intake_get_type(10f8593f8aa10422).(cfg_intake) && |
| 802 | (util_strrcasecmpcxx . . $ util_strrcasecmp(5ae29d726ae57f88).(cfg_intake_get_filenamecxx . . $ cfg_intake_get_filename(56a97a66344ba534).(cfg_intake), ".m3u") == 0 || |
| 803 | util_strrcasecmpcxx . . $ util_strrcasecmp(5ae29d726ae57f88).(cfg_intake_get_filenamecxx . . $ cfg_intake_get_filename(56a97a66344ba534).(cfg_intake), ".txt") == 0))) |
| 804 | playlistModecxx . . $ playlistMode. = 1; |
| 805 | else |
| 806 | playlistModecxx . . $ playlistMode. = 0; |
| 807 | |
| 808 | do { |
| 809 | if (playlistModecxx . . $ playlistMode.) { |
| 810 | cont = streamPlaylistcxx . . $ streamPlaylist(e560f6a86f1dbfd1).(main_streamcxx . . $ main_stream.); |
| 811 | } else { |
| 812 | cont = streamFilecxx . . $ streamFile(ef58bb43cf5b9d8).(main_streamcxx . . $ main_stream., |
| 813 | cfg_intake_get_filenamecxx . . $ cfg_intake_get_filename(56a97a66344ba534).(cfg_intake)); |
| 814 | } |
| 815 | if (quitcxx . . $ quit.) |
| 816 | break; |
| 817 | if (cfg_intake_get_stream_oncecxx . . $ cfg_intake_get_stream_once(2ab3bd772c3b65f).(cfg_intake)) |
| 818 | break; |
| 819 | } while (cont); |
| 820 | |
| 821 | stream_disconnectcxx . . $ stream_disconnect(42ea99e01043689b).(main_streamcxx . . $ main_stream.); |
| 822 | stream_destroycxx . . $ stream_destroy(a819560812e4e895).(&main_streamcxx . . $ main_stream.); |
| 823 | |
| 824 | if (quitcxx . . $ quit.) { |
| 825 | if (cfg_get_program_quiet_stderrcxx . . $ cfg_get_program_quiet_stderr(b126dc7c1de90089).() && |
| 826 | cfg_get_program_verbositycxx . . $ cfg_get_program_verbosity(db52760e79bf9054).()) |
| 827 | printfcxx . . $ printf(581fddd72a8db8fc).("\r"); |
| 828 | log_noticecxx . . $ log_notice(581fddd72a8db8fc).("INT or TERM signal received"); |
| 829 | } |
| 830 | |
| 831 | log_infocxx . . $ log_info(581fddd72a8db8fc).("exiting"); |
| 832 | |
| 833 | playlist_freecxx . . $ playlist_free(d6737836562b4329).(&playlistcxx . . $ playlist.); |
| 834 | |
| 835 | return (ez_shutdowncxx . . $ ez_shutdown(7864480464b09eea).(0)); |
| 836 | } |