codemirror-lang-liquidsoap 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (427) hide show
  1. package/dist/cli.js +8 -8
  2. package/dist/index.js +7 -7
  3. package/package.json +1 -1
  4. package/src/liquidsoap.grammar +10 -4
  5. package/src/parser.js +6 -6
  6. package/tests/liquidsoap/.codespellignore +1 -0
  7. package/tests/liquidsoap/.github/ISSUE_TEMPLATE/bug_report.yml +16 -0
  8. package/tests/liquidsoap/.github/docker/alpine.dockerfile +20 -0
  9. package/tests/liquidsoap/.github/docker/debian.dockerfile +55 -0
  10. package/tests/liquidsoap/.github/opam/{liquidsoap-core-windows.opam → liquidsoap-windows.opam} +8 -5
  11. package/tests/liquidsoap/.github/renovate.json +23 -0
  12. package/tests/liquidsoap/.github/scripts/add-local-opam-packages.sh +5 -3
  13. package/tests/liquidsoap/.github/scripts/build-apk.sh +10 -19
  14. package/tests/liquidsoap/.github/scripts/build-deb.sh +6 -15
  15. package/tests/liquidsoap/.github/scripts/build-details.sh +15 -4
  16. package/tests/liquidsoap/.github/scripts/build-posix.sh +11 -20
  17. package/tests/liquidsoap/.github/scripts/build-website.sh +1 -1
  18. package/tests/liquidsoap/.github/scripts/build-win32.sh +6 -2
  19. package/tests/liquidsoap/.github/scripts/push-docker.sh +13 -15
  20. package/tests/liquidsoap/.github/workflows/ci.yml +291 -185
  21. package/tests/liquidsoap/.ocamlformat +1 -1
  22. package/tests/liquidsoap/.pre-commit-config.yaml +2 -2
  23. package/tests/liquidsoap/CHANGES.md +112 -3
  24. package/tests/liquidsoap/README.md +10 -9
  25. package/tests/liquidsoap/ROADMAP.md +14 -8
  26. package/tests/liquidsoap/bin/liquidsoap-macos-instruments +7 -0
  27. package/tests/liquidsoap/doc/content/build.md +0 -1
  28. package/tests/liquidsoap/doc/content/faq.md +2 -4
  29. package/tests/liquidsoap/doc/content/icy_metadata.md +2 -2
  30. package/tests/liquidsoap/doc/content/install.md +13 -2
  31. package/tests/liquidsoap/doc/content/json.md +1 -1
  32. package/tests/liquidsoap/doc/content/language.md +4 -4
  33. package/tests/liquidsoap/doc/content/liq/beets-protocol.liq +1 -1
  34. package/tests/liquidsoap/doc/content/liq/crossfade.liq +1 -1
  35. package/tests/liquidsoap/doc/content/liq/harbor-simple.liq +1 -1
  36. package/tests/liquidsoap/doc/content/liq/radiopi.liq +10 -9
  37. package/tests/liquidsoap/doc/content/liq/request.dynamic.liq +1 -1
  38. package/tests/liquidsoap/doc/content/migrating.md +25 -3
  39. package/tests/liquidsoap/doc/content/playlist_parsers.md +46 -1
  40. package/tests/liquidsoap/doc/content/script_loading.md +3 -0
  41. package/tests/liquidsoap/doc/content/xml.md +160 -0
  42. package/tests/liquidsoap/doc/dune.inc +129 -0
  43. package/tests/liquidsoap/dune-project +29 -49
  44. package/tests/liquidsoap/liquidsoap +1 -1
  45. package/tests/liquidsoap/{liquidsoap-js.opam → opam/liquidsoap-js.opam} +3 -2
  46. package/tests/liquidsoap/{liquidsoap-lang.opam → opam/liquidsoap-lang.opam} +4 -3
  47. package/tests/liquidsoap/{liquidsoap-mode.opam → opam/liquidsoap-mode.opam} +3 -2
  48. package/tests/liquidsoap/{liquidsoap-core.opam → opam/liquidsoap.opam} +46 -17
  49. package/tests/liquidsoap/{prometheus-liquidsoap.opam → opam/prometheus-liquidsoap.opam} +2 -1
  50. package/tests/liquidsoap/{sdl-liquidsoap.opam → opam/sdl-liquidsoap.opam} +2 -1
  51. package/tests/liquidsoap/{tls-liquidsoap.opam → opam/tls-liquidsoap.opam} +2 -1
  52. package/tests/liquidsoap/src/bin/dune +1 -1
  53. package/tests/liquidsoap/src/config/xmlplaylist_option.disabled.ml +2 -0
  54. package/tests/liquidsoap/src/core/builtins/builtins_ffmpeg_decoder.ml +22 -22
  55. package/tests/liquidsoap/src/core/builtins/builtins_ffmpeg_encoder.ml +4 -4
  56. package/tests/liquidsoap/src/core/builtins/builtins_ffmpeg_filters.ml +37 -41
  57. package/tests/liquidsoap/src/core/builtins/builtins_files.ml +3 -1
  58. package/tests/liquidsoap/src/core/builtins/builtins_optionals.ml +0 -1
  59. package/tests/liquidsoap/src/core/builtins/builtins_process.ml +15 -7
  60. package/tests/liquidsoap/src/core/builtins/builtins_resolvers.ml +16 -0
  61. package/tests/liquidsoap/src/core/builtins/builtins_socket.ml +7 -5
  62. package/tests/liquidsoap/src/core/builtins/builtins_source.ml +3 -3
  63. package/tests/liquidsoap/src/core/builtins/builtins_srt.ml +84 -8
  64. package/tests/liquidsoap/src/core/builtins/builtins_string_extra.ml +13 -0
  65. package/tests/liquidsoap/src/core/builtins/builtins_sys.ml +6 -6
  66. package/tests/liquidsoap/src/core/builtins/builtins_thread.ml +2 -2
  67. package/tests/liquidsoap/src/core/builtins/builtins_time.ml +5 -3
  68. package/tests/liquidsoap/src/core/builtins/builtins_tls.ml +1 -1
  69. package/tests/liquidsoap/src/core/clock.ml +105 -38
  70. package/tests/liquidsoap/src/core/clock.mli +1 -0
  71. package/tests/liquidsoap/src/core/clock_base.ml +2 -2
  72. package/tests/liquidsoap/src/core/conversions/stereo.ml +6 -8
  73. package/tests/liquidsoap/src/core/converters/audio_converter.mli +5 -5
  74. package/tests/liquidsoap/src/core/converters/video_converter.ml +2 -2
  75. package/tests/liquidsoap/src/core/converters/video_converter.mli +3 -3
  76. package/tests/liquidsoap/src/core/decoder/decoder.ml +14 -17
  77. package/tests/liquidsoap/src/core/decoder/decoder.mli +11 -11
  78. package/tests/liquidsoap/src/core/decoder/decoder_utils.ml +12 -13
  79. package/tests/liquidsoap/src/core/decoder/decoder_utils.mli +2 -3
  80. package/tests/liquidsoap/src/core/decoder/external_decoder.ml +9 -13
  81. package/tests/liquidsoap/src/core/decoder/ffmpeg_decoder.ml +57 -53
  82. package/tests/liquidsoap/src/core/decoder/ffmpeg_raw_decoder.ml +28 -9
  83. package/tests/liquidsoap/src/core/decoder/flac_metadata_plug.ml +15 -2
  84. package/tests/liquidsoap/src/core/decoder/image_decoder.ml +33 -19
  85. package/tests/liquidsoap/src/core/decoder/liq_flac_decoder.ml +22 -23
  86. package/tests/liquidsoap/src/core/decoder/liq_ogg_decoder.ml +5 -5
  87. package/tests/liquidsoap/src/core/decoder/mad_decoder.ml +2 -2
  88. package/tests/liquidsoap/src/core/decoder/midi_decoder.ml +1 -2
  89. package/tests/liquidsoap/src/core/decoder/ogg_flac_duration.ml +3 -11
  90. package/tests/liquidsoap/src/core/decoder/ogg_metadata_plug.ml +15 -2
  91. package/tests/liquidsoap/src/core/decoder/raw_audio_decoder.ml +8 -7
  92. package/tests/liquidsoap/src/core/decoder/wav_aiff_decoder.ml +3 -3
  93. package/tests/liquidsoap/src/core/dune +2 -15
  94. package/tests/liquidsoap/src/core/encoder/encoder.ml +18 -23
  95. package/tests/liquidsoap/src/core/encoder/encoder.mli +12 -17
  96. package/tests/liquidsoap/src/core/encoder/encoders/ffmpeg_encoder.ml +13 -27
  97. package/tests/liquidsoap/src/core/encoder/encoders/ffmpeg_encoder_common.ml +1 -1
  98. package/tests/liquidsoap/src/core/encoder/encoders/flac_encoder.ml +3 -4
  99. package/tests/liquidsoap/src/core/encoder/encoders/ndi_encoder.ml +2 -1
  100. package/tests/liquidsoap/src/core/encoder/encoders/ogg_encoder.ml +1 -2
  101. package/tests/liquidsoap/src/core/encoder/lang/lang_external_encoder.ml +2 -2
  102. package/tests/liquidsoap/src/core/encoder/lang/lang_fdkaac.ml +1 -1
  103. package/tests/liquidsoap/src/core/encoder/lang/lang_ffmpeg.ml +46 -39
  104. package/tests/liquidsoap/src/core/encoder/lang/lang_flac.ml +1 -1
  105. package/tests/liquidsoap/src/core/encoder/lang/lang_shine.ml +2 -2
  106. package/tests/liquidsoap/src/core/encoder/lang/lang_vorbis.ml +1 -1
  107. package/tests/liquidsoap/src/core/encoder/lang/lang_wav.ml +1 -1
  108. package/tests/liquidsoap/src/core/file_watcher.inotify.ml +8 -13
  109. package/tests/liquidsoap/src/core/harbor/harbor.ml +22 -24
  110. package/tests/liquidsoap/src/core/io/ffmpeg_filter_io.ml +4 -3
  111. package/tests/liquidsoap/src/core/io/oss_io.ml +3 -4
  112. package/tests/liquidsoap/src/core/io/portaudio_io.ml +1 -1
  113. package/tests/liquidsoap/src/core/io/pulseaudio_io.ml +3 -4
  114. package/tests/liquidsoap/src/core/io/srt_io.ml +316 -120
  115. package/tests/liquidsoap/src/core/io/udp_io.ml +14 -12
  116. package/tests/liquidsoap/src/core/lang.mli +10 -12
  117. package/tests/liquidsoap/src/core/lang_source.ml +25 -39
  118. package/tests/liquidsoap/src/core/lang_string.ml +30 -0
  119. package/tests/liquidsoap/src/core/lang_string.mli +3 -0
  120. package/tests/liquidsoap/src/core/ogg_formats/ogg_flac_encoder.ml +6 -6
  121. package/tests/liquidsoap/src/core/ogg_formats/ogg_muxer.ml +17 -27
  122. package/tests/liquidsoap/src/core/ogg_formats/ogg_muxer.mli +44 -53
  123. package/tests/liquidsoap/src/core/ogg_formats/opus_encoder.ml +1 -1
  124. package/tests/liquidsoap/src/core/ogg_formats/vorbis_encoder.ml +1 -2
  125. package/tests/liquidsoap/src/core/operators/add.ml +2 -2
  126. package/tests/liquidsoap/src/core/operators/cross.ml +2 -2
  127. package/tests/liquidsoap/src/core/operators/delay.ml +23 -6
  128. package/tests/liquidsoap/src/core/operators/dtmf.ml +3 -2
  129. package/tests/liquidsoap/src/core/operators/dyn_op.ml +2 -2
  130. package/tests/liquidsoap/src/core/operators/fir_filter.ml +2 -1
  131. package/tests/liquidsoap/src/core/operators/iir_filter.ml +1 -1
  132. package/tests/liquidsoap/src/core/operators/insert_metadata.ml +1 -1
  133. package/tests/liquidsoap/src/core/operators/lilv_op.ml +1 -1
  134. package/tests/liquidsoap/src/core/operators/lufs.ml +136 -89
  135. package/tests/liquidsoap/src/core/operators/lufs_c.c +105 -0
  136. package/tests/liquidsoap/src/core/operators/map_metadata.ml +33 -9
  137. package/tests/liquidsoap/src/core/operators/max_duration.ml +3 -4
  138. package/tests/liquidsoap/src/core/operators/muxer.ml +2 -1
  139. package/tests/liquidsoap/src/core/operators/noblank.ml +6 -6
  140. package/tests/liquidsoap/src/core/operators/sequence.ml +5 -5
  141. package/tests/liquidsoap/src/core/operators/switch.ml +10 -11
  142. package/tests/liquidsoap/src/core/operators/time_warp.ml +14 -11
  143. package/tests/liquidsoap/src/core/operators/video_fade.ml +2 -3
  144. package/tests/liquidsoap/src/core/outputs/ao_out.ml +1 -1
  145. package/tests/liquidsoap/src/core/outputs/bjack_out.ml +1 -1
  146. package/tests/liquidsoap/src/core/outputs/graphics_out.ml +6 -2
  147. package/tests/liquidsoap/src/core/outputs/harbor_output.ml +12 -10
  148. package/tests/liquidsoap/src/core/outputs/hls_output.ml +19 -14
  149. package/tests/liquidsoap/src/core/outputs/icecast2.ml +85 -52
  150. package/tests/liquidsoap/src/core/outputs/ndi_out.ml +1 -1
  151. package/tests/liquidsoap/src/core/outputs/output.ml +8 -9
  152. package/tests/liquidsoap/src/core/outputs/output.mli +61 -61
  153. package/tests/liquidsoap/src/core/outputs/pipe_output.ml +8 -6
  154. package/tests/liquidsoap/src/core/outputs/sdl_out.ml +5 -2
  155. package/tests/liquidsoap/src/core/playlist_parser.ml +6 -7
  156. package/tests/liquidsoap/src/core/playlists/playlist_basic.ml +0 -180
  157. package/tests/liquidsoap/src/core/protocols/annotate.ml +3 -3
  158. package/tests/liquidsoap/src/core/request.ml +16 -17
  159. package/tests/liquidsoap/src/core/request.mli +27 -28
  160. package/tests/liquidsoap/src/core/shebang.ml +3 -2
  161. package/tests/liquidsoap/src/core/source.ml +104 -63
  162. package/tests/liquidsoap/src/core/source.mli +249 -247
  163. package/tests/liquidsoap/src/core/sources/generated.ml +2 -2
  164. package/tests/liquidsoap/src/core/sources/request_dynamic.ml +2 -2
  165. package/tests/liquidsoap/src/core/sources/synthesized.ml +2 -2
  166. package/tests/liquidsoap/src/core/stream/aFrame.mli +7 -9
  167. package/tests/liquidsoap/src/core/stream/content.mli +4 -13
  168. package/tests/liquidsoap/src/core/stream/content_base.ml +2 -19
  169. package/tests/liquidsoap/src/core/stream/content_video.ml +9 -10
  170. package/tests/liquidsoap/src/core/stream/ffmpeg_copy_content.ml +19 -15
  171. package/tests/liquidsoap/src/core/stream/ffmpeg_raw_content.ml +26 -9
  172. package/tests/liquidsoap/src/core/stream/frame.ml +4 -4
  173. package/tests/liquidsoap/src/core/stream/frame.mli +13 -15
  174. package/tests/liquidsoap/src/core/stream/frame_base.ml +1 -2
  175. package/tests/liquidsoap/src/core/stream/frame_settings.ml +14 -14
  176. package/tests/liquidsoap/src/core/stream/generator.mli +14 -17
  177. package/tests/liquidsoap/src/core/stream/mFrame.mli +2 -2
  178. package/tests/liquidsoap/src/core/tools/charset.ml +28 -18
  179. package/tests/liquidsoap/src/core/tools/charset_base.ml +5 -0
  180. package/tests/liquidsoap/src/core/tools/child_support.ml +2 -2
  181. package/tests/liquidsoap/src/core/tools/ffmpeg_avfilter_utils.ml +139 -0
  182. package/tests/liquidsoap/src/core/tools/ffmpeg_avfilter_utils.mli +22 -0
  183. package/tests/liquidsoap/src/core/tools/ffmpeg_utils.ml +2 -1
  184. package/tests/liquidsoap/src/core/tools/lifecycle.mli +4 -4
  185. package/tests/liquidsoap/src/core/tools/liq_http.ml +44 -19
  186. package/tests/liquidsoap/src/core/tools/liq_http.mli +1 -1
  187. package/tests/liquidsoap/src/core/tools/log.ml +3 -8
  188. package/tests/liquidsoap/src/core/tools/log.mli +1 -1
  189. package/tests/liquidsoap/src/core/tools/mutex_utils.ml +1 -1
  190. package/tests/liquidsoap/src/core/tools/pool.ml +2 -2
  191. package/tests/liquidsoap/src/core/tools/process_handler.mli +30 -27
  192. package/tests/liquidsoap/src/core/tools/producer_consumer.ml +10 -9
  193. package/tests/liquidsoap/src/{lang → core/tools}/queues.ml +58 -64
  194. package/tests/liquidsoap/src/{lang → core/tools}/queues.mli +10 -0
  195. package/tests/liquidsoap/src/core/tools/sdl_utils.ml +2 -0
  196. package/tests/liquidsoap/src/core/tools/server.mli +8 -8
  197. package/tests/liquidsoap/src/core/tools/sha1.ml +2 -1
  198. package/tests/liquidsoap/src/core/tools/start_stop.ml +2 -1
  199. package/tests/liquidsoap/src/core/tools/strings.mli +5 -4
  200. package/tests/liquidsoap/src/core/tools/tutils.ml +7 -7
  201. package/tests/liquidsoap/src/core/tools/tutils.mli +14 -18
  202. package/tests/liquidsoap/src/core/tools/unix_c.c +16 -5
  203. package/tests/liquidsoap/src/core/tools/utils.ml +83 -25
  204. package/tests/liquidsoap/src/core/tools/wav_aiff.ml +3 -3
  205. package/tests/liquidsoap/src/core/tools/wav_aiff.mli +7 -7
  206. package/tests/liquidsoap/src/core/types/format_type.ml +6 -6
  207. package/tests/liquidsoap/src/js/index.html +1 -154
  208. package/tests/liquidsoap/src/js/interactive_js.ml +7 -3
  209. package/tests/liquidsoap/src/js/stdlib_js.liq +6 -0
  210. package/tests/liquidsoap/src/lang/builtins_lang.ml +8 -0
  211. package/tests/liquidsoap/src/lang/builtins_null.ml +1 -1
  212. package/tests/liquidsoap/src/lang/builtins_string.ml +2 -11
  213. package/tests/liquidsoap/src/lang/builtins_xml.ml +204 -0
  214. package/tests/liquidsoap/src/lang/cache.ml +7 -2
  215. package/tests/liquidsoap/src/lang/dune +5 -2
  216. package/tests/liquidsoap/src/lang/flags.ml +2 -2
  217. package/tests/liquidsoap/src/lang/lang.mli +10 -12
  218. package/tests/liquidsoap/src/lang/lang_core.ml +24 -24
  219. package/tests/liquidsoap/src/lang/lang_eval.ml +1 -1
  220. package/tests/liquidsoap/src/lang/lang_string.ml +7 -13
  221. package/tests/liquidsoap/src/lang/lang_string.mli +0 -1
  222. package/tests/liquidsoap/src/lang/lexer.ml +3 -0
  223. package/tests/liquidsoap/src/lang/parser.mly +7 -4
  224. package/tests/liquidsoap/src/lang/parser_helper.ml +9 -77
  225. package/tests/liquidsoap/src/lang/parser_helper.mli +1 -1
  226. package/tests/liquidsoap/src/lang/pos.ml +4 -4
  227. package/tests/liquidsoap/src/lang/pos.mli +55 -0
  228. package/tests/liquidsoap/src/lang/preprocessor.ml +12 -5
  229. package/tests/liquidsoap/src/lang/repr.ml +6 -6
  230. package/tests/liquidsoap/src/lang/runtime.ml +55 -48
  231. package/tests/liquidsoap/src/lang/runtime.mli +8 -3
  232. package/tests/liquidsoap/src/lang/term/parsed_term.ml +33 -33
  233. package/tests/liquidsoap/src/lang/term/term_base.ml +14 -10
  234. package/tests/liquidsoap/src/lang/term/term_preprocessor.ml +28 -1
  235. package/tests/liquidsoap/src/lang/term/term_reducer.ml +244 -132
  236. package/tests/liquidsoap/src/lang/term/term_reducer.mli +10 -2
  237. package/tests/liquidsoap/src/lang/term/term_stdlib.ml +14 -13
  238. package/tests/liquidsoap/src/lang/term.mli +3 -1
  239. package/tests/liquidsoap/src/lang/typechecking.ml +16 -16
  240. package/tests/liquidsoap/src/lang/typechecking.mli +5 -1
  241. package/tests/liquidsoap/src/lang/types/type_base.ml +16 -17
  242. package/tests/liquidsoap/src/lang/typing.ml +13 -12
  243. package/tests/liquidsoap/src/lang/typing.mli +2 -1
  244. package/tests/liquidsoap/src/lang/value.ml +20 -14
  245. package/tests/liquidsoap/src/libs/audio.liq +53 -18
  246. package/tests/liquidsoap/src/libs/autocue.liq +8 -8
  247. package/tests/liquidsoap/src/libs/clock.liq +3 -3
  248. package/tests/liquidsoap/src/libs/dune +2 -2
  249. package/tests/liquidsoap/src/libs/extra/audio.liq +4 -4
  250. package/tests/liquidsoap/src/libs/extra/audioscrobbler.liq +487 -0
  251. package/tests/liquidsoap/src/libs/extra/deprecations.liq +11 -11
  252. package/tests/liquidsoap/src/libs/extra/externals.liq +9 -9
  253. package/tests/liquidsoap/src/libs/extra/fades.liq +2 -2
  254. package/tests/liquidsoap/src/libs/extra/file.liq +1 -1
  255. package/tests/liquidsoap/src/libs/extra/http.liq +4 -4
  256. package/tests/liquidsoap/src/libs/extra/interactive.liq +1 -1
  257. package/tests/liquidsoap/src/libs/extra/metadata.liq +3 -3
  258. package/tests/liquidsoap/src/libs/extra/native.liq +6 -6
  259. package/tests/liquidsoap/src/libs/extra/server.liq +2 -2
  260. package/tests/liquidsoap/src/libs/extra/source.liq +10 -10
  261. package/tests/liquidsoap/src/libs/extra/spinitron.liq +11 -11
  262. package/tests/liquidsoap/src/libs/extra/telnet.liq +51 -0
  263. package/tests/liquidsoap/src/libs/extra/video.liq +2 -2
  264. package/tests/liquidsoap/src/libs/fades.liq +70 -57
  265. package/tests/liquidsoap/src/libs/ffmpeg.liq +50 -33
  266. package/tests/liquidsoap/src/libs/file.liq +8 -8
  267. package/tests/liquidsoap/src/libs/hls.liq +5 -5
  268. package/tests/liquidsoap/src/libs/http.liq +64 -37
  269. package/tests/liquidsoap/src/libs/icecast.liq +1 -1
  270. package/tests/liquidsoap/src/libs/io.liq +6 -6
  271. package/tests/liquidsoap/src/libs/medialib.liq +46 -45
  272. package/tests/liquidsoap/src/libs/metadata.liq +4 -4
  273. package/tests/liquidsoap/src/libs/null.liq +3 -3
  274. package/tests/liquidsoap/src/libs/playlist.liq +547 -22
  275. package/tests/liquidsoap/src/libs/protocols.liq +14 -14
  276. package/tests/liquidsoap/src/libs/replaygain.liq +11 -11
  277. package/tests/liquidsoap/src/libs/request.liq +27 -29
  278. package/tests/liquidsoap/src/libs/runtime.liq +2 -0
  279. package/tests/liquidsoap/src/libs/source.liq +15 -15
  280. package/tests/liquidsoap/src/libs/sqlite.liq +1 -1
  281. package/tests/liquidsoap/src/libs/stdlib.liq +1 -1
  282. package/tests/liquidsoap/src/libs/string.liq +6 -6
  283. package/tests/liquidsoap/src/libs/switches.liq +3 -3
  284. package/tests/liquidsoap/src/libs/thread.liq +3 -9
  285. package/tests/liquidsoap/src/libs/tracks.liq +23 -9
  286. package/tests/liquidsoap/src/libs/video.liq +32 -32
  287. package/tests/liquidsoap/src/modules/dtools/README.md +58 -0
  288. package/tests/liquidsoap/src/modules/dtools/dtools.ml +19 -0
  289. package/tests/liquidsoap/src/modules/dtools/dtools.mli +284 -0
  290. package/tests/liquidsoap/src/modules/dtools/dtools_impl.ml +860 -0
  291. package/tests/liquidsoap/src/modules/dtools/dtools_syslog.impl.ml +45 -0
  292. package/tests/liquidsoap/src/modules/dtools/dtools_syslog.noop.ml +1 -0
  293. package/tests/liquidsoap/src/modules/dtools/dune +12 -0
  294. package/tests/liquidsoap/src/modules/duppy/.merlin +4 -0
  295. package/tests/liquidsoap/src/modules/duppy/README.md +47 -0
  296. package/tests/liquidsoap/src/modules/duppy/dune +7 -0
  297. package/tests/liquidsoap/src/modules/duppy/duppy.ml +1097 -0
  298. package/tests/liquidsoap/src/modules/duppy/duppy.mli +494 -0
  299. package/tests/liquidsoap/src/modules/duppy/duppy_stubs.c +176 -0
  300. package/tests/liquidsoap/src/modules/duppy/examples/dune +9 -0
  301. package/tests/liquidsoap/src/modules/duppy/examples/http.ml +560 -0
  302. package/tests/liquidsoap/src/modules/duppy/examples/index.html +1 -0
  303. package/tests/liquidsoap/src/modules/duppy/examples/telnet.ml +150 -0
  304. package/tests/liquidsoap/src/modules/xmlplaylist/dune +5 -0
  305. package/tests/liquidsoap/src/modules/xmlplaylist/xmlplaylist.ml +185 -0
  306. package/tests/liquidsoap/src/modules/xmlplaylist/xmlplaylist.mli +56 -0
  307. package/tests/liquidsoap/src/ndi/ndi.mli +2 -3
  308. package/tests/liquidsoap/src/runtime/build_config.ml +0 -1
  309. package/tests/liquidsoap/src/runtime/main.ml +4 -23
  310. package/tests/liquidsoap/src/stereotool/stereotool.mli +3 -3
  311. package/tests/liquidsoap/src/tooling/parsed_json.ml +6 -4
  312. package/tests/liquidsoap/tests/core/content_test.ml +2 -39
  313. package/tests/liquidsoap/tests/core/dune +13 -0
  314. package/tests/liquidsoap/tests/core/dune.inc +1 -1
  315. package/tests/liquidsoap/tests/core/gen_dune.ml +4 -1
  316. package/tests/liquidsoap/tests/core/json_test.ml +10 -0
  317. package/tests/liquidsoap/tests/core/more_types.ml +32 -28
  318. package/tests/liquidsoap/tests/core/output_encoded_test.ml +2 -0
  319. package/tests/liquidsoap/tests/core/string_test.ml +4 -0
  320. package/tests/liquidsoap/tests/core/types.ml +1 -1
  321. package/tests/liquidsoap/tests/harbor/http.liq +1 -1
  322. package/tests/liquidsoap/tests/harbor/http2.liq +1 -1
  323. package/tests/liquidsoap/tests/language/cue_test.liq +3993 -0
  324. package/tests/liquidsoap/tests/language/dune.inc +24 -0
  325. package/tests/liquidsoap/tests/language/error.liq +1 -1
  326. package/tests/liquidsoap/tests/language/json.liq +11 -11
  327. package/tests/liquidsoap/tests/language/list.liq +1 -1
  328. package/tests/liquidsoap/tests/language/metadata.liq +1 -1
  329. package/tests/liquidsoap/tests/language/null.liq +9 -9
  330. package/tests/liquidsoap/tests/language/record.liq +23 -23
  331. package/tests/liquidsoap/tests/language/replaygain.liq +8 -8
  332. package/tests/liquidsoap/tests/language/sqlite.liq +1 -1
  333. package/tests/liquidsoap/tests/language/string.liq +1 -1
  334. package/tests/liquidsoap/tests/language/type_errors.liq +2 -2
  335. package/tests/liquidsoap/tests/language/typing.liq +2 -2
  336. package/tests/liquidsoap/tests/language/various.liq +1 -0
  337. package/tests/liquidsoap/tests/language/xml_test.liq +132 -0
  338. package/tests/liquidsoap/tests/media/dune +74 -0
  339. package/tests/liquidsoap/tests/media/dune.inc +63 -0
  340. package/tests/liquidsoap/tests/media/ffmpeg_add_text.liq +42 -56
  341. package/tests/liquidsoap/tests/media/ffmpeg_copy_concat.liq +5 -2
  342. package/tests/liquidsoap/tests/media/ffmpeg_distributed_hls.liq +2 -4
  343. package/tests/liquidsoap/tests/media/ffmpeg_filter_changing_rate.liq +1 -1
  344. package/tests/liquidsoap/tests/media/ffmpeg_inline_encode_decode_audio.liq +1 -5
  345. package/tests/liquidsoap/tests/media/ffmpeg_inline_encode_decode_video.liq +1 -3
  346. package/tests/liquidsoap/tests/media/ffmpeg_raw_and_encode_decoder.liq +1 -3
  347. package/tests/liquidsoap/tests/media/ffmpeg_raw_hls.liq +2 -4
  348. package/tests/liquidsoap/tests/media/ffmpeg_raw_implicit_conversion.liq +63 -0
  349. package/tests/liquidsoap/tests/media/gen_dune.ml +1 -0
  350. package/tests/liquidsoap/tests/media/image_decoder_duration.liq +15 -0
  351. package/tests/liquidsoap/tests/media/lufs_integrated.liq +17 -0
  352. package/tests/liquidsoap/tests/regression/AC5109.liq +2 -2
  353. package/tests/liquidsoap/tests/regression/GH1129.liq +3 -3
  354. package/tests/liquidsoap/tests/regression/GH1279.liq +2 -2
  355. package/tests/liquidsoap/tests/regression/GH1327.liq +3 -3
  356. package/tests/liquidsoap/tests/regression/GH2585.liq +0 -2
  357. package/tests/liquidsoap/tests/regression/GH2756-2.liq +3 -3
  358. package/tests/liquidsoap/tests/regression/GH2756.liq +2 -2
  359. package/tests/liquidsoap/tests/regression/GH3134.liq +2 -2
  360. package/tests/liquidsoap/tests/regression/GH3303.liq +2 -2
  361. package/tests/liquidsoap/tests/regression/GH4163.liq +14 -3
  362. package/tests/liquidsoap/tests/regression/GH4281-2.liq +29 -0
  363. package/tests/liquidsoap/tests/regression/GH4281.liq +29 -0
  364. package/tests/liquidsoap/tests/regression/GH4395.liq +27 -0
  365. package/tests/liquidsoap/tests/regression/LS354-1.liq +1 -1
  366. package/tests/liquidsoap/tests/regression/LS354-2.liq +1 -1
  367. package/tests/liquidsoap/tests/regression/append-merge.liq +3 -1
  368. package/tests/liquidsoap/tests/regression/dune.inc +64 -0
  369. package/tests/liquidsoap/tests/regression/fallible_ogg.liq +9 -0
  370. package/tests/liquidsoap/tests/regression/init-error.liq +2 -0
  371. package/tests/liquidsoap/tests/regression/seek_track_map.liq +1 -1
  372. package/tests/liquidsoap/tests/regression/source_dynamic.liq +2 -2
  373. package/tests/liquidsoap/tests/run_test.ml +53 -60
  374. package/tests/liquidsoap/tests/streams/cross-override-end.liq +9 -2
  375. package/tests/liquidsoap/tests/streams/cross-override-start.liq +9 -2
  376. package/tests/liquidsoap/tests/streams/cross-override.liq +9 -2
  377. package/tests/liquidsoap/tests/streams/cross-persist-end-override.liq +9 -2
  378. package/tests/liquidsoap/tests/streams/cross-persist-override.liq +9 -2
  379. package/tests/liquidsoap/tests/streams/cross-persist-start-override.liq +9 -2
  380. package/tests/liquidsoap/tests/streams/cross.liq +8 -2
  381. package/tests/liquidsoap/tests/streams/crossfade-plot.liq +11 -8
  382. package/tests/liquidsoap/tests/streams/crossfade-plot.new.txt +148 -248
  383. package/tests/liquidsoap/tests/streams/crossfade-plot.old.txt +50 -150
  384. package/tests/liquidsoap/tests/streams/crossfade.liq +8 -2
  385. package/tests/liquidsoap/tests/streams/ctype2.liq +1 -1
  386. package/tests/liquidsoap/tests/streams/dune.inc +31 -0
  387. package/tests/liquidsoap/tests/streams/fades-overrides.liq +9 -2
  388. package/tests/liquidsoap/tests/streams/fades-persistent-override.liq +9 -2
  389. package/tests/liquidsoap/tests/streams/harbor_metadata_3.liq +1 -1
  390. package/tests/liquidsoap/tests/streams/hls_id3v2.liq +11 -7
  391. package/tests/liquidsoap/tests/streams/icecast_last_meta.liq +47 -0
  392. package/tests/liquidsoap/tests/streams/icecast_ssl.liq +3 -0
  393. package/tests/liquidsoap/tests/streams/icecast_ssl_tls.liq +3 -3
  394. package/tests/liquidsoap/tests/streams/icecast_tls.liq +1 -0
  395. package/tests/liquidsoap/tests/streams/icecast_tls_ssl.liq +5 -0
  396. package/tests/liquidsoap/tests/streams/no-cue-cut.liq +2 -2
  397. package/tests/liquidsoap/tests/streams/random.liq +2 -2
  398. package/tests/liquidsoap/tests/streams/replaygain.liq +10 -10
  399. package/tests/liquidsoap/tests/streams/rotate.liq +6 -1
  400. package/tests/liquidsoap/tests/streams/say.liq +2 -2
  401. package/tests/liquidsoap/tests/streams/srt_listen_callback.liq +1 -0
  402. package/tests/liquidsoap/tests/streams/srt_multiple_outputs.liq +1 -0
  403. package/tests/liquidsoap/tests/streams/srt_passphrase.liq +1 -0
  404. package/tests/liquidsoap/tests/streams/srt_raw_pcm.liq +1 -0
  405. package/tests/liquidsoap/tests/test.liq +4 -5
  406. package/tests/liquidsoap/.github/docker/Dockerfile.production +0 -37
  407. package/tests/liquidsoap/.github/docker/Dockerfile.production-alpine +0 -18
  408. package/tests/liquidsoap/.github/opam/packages/metadata/metadata.0.3.0/opam +0 -33
  409. package/tests/liquidsoap/.github/scripts/build-docker-alpine.sh +0 -31
  410. package/tests/liquidsoap/.github/scripts/build-docker.sh +0 -35
  411. package/tests/liquidsoap/liquidsoap-libs-extra.opam +0 -32
  412. package/tests/liquidsoap/liquidsoap-libs.opam +0 -31
  413. package/tests/liquidsoap/liquidsoap.opam +0 -63
  414. package/tests/liquidsoap/src/core/builtins/builtins_lastfm.ml +0 -110
  415. package/tests/liquidsoap/src/core/tools/liqfm.ml +0 -244
  416. package/tests/liquidsoap/src/libs/extra/lastfm.liq +0 -185
  417. /package/tests/liquidsoap/.github/docker/{Dockerfile.website → website.dockerfile} +0 -0
  418. /package/tests/liquidsoap/.github/opam/packages/ffmpeg-av-windows/{ffmpeg-av-windows.1.2.0 → ffmpeg-av-windows.1.2.5}/opam +0 -0
  419. /package/tests/liquidsoap/.github/opam/packages/ffmpeg-avcodec-windows/{ffmpeg-avcodec-windows.1.2.0 → ffmpeg-avcodec-windows.1.2.5}/opam +0 -0
  420. /package/tests/liquidsoap/.github/opam/packages/ffmpeg-avdevice-windows/{ffmpeg-avdevice-windows.1.2.0 → ffmpeg-avdevice-windows.1.2.5}/opam +0 -0
  421. /package/tests/liquidsoap/.github/opam/packages/ffmpeg-avfilter-windows/{ffmpeg-avfilter-windows.1.2.0 → ffmpeg-avfilter-windows.1.2.5}/opam +0 -0
  422. /package/tests/liquidsoap/.github/opam/packages/ffmpeg-avutil-windows/{ffmpeg-avutil-windows.1.2.0 → ffmpeg-avutil-windows.1.2.5}/opam +0 -0
  423. /package/tests/liquidsoap/.github/opam/packages/ffmpeg-swresample-windows/{ffmpeg-swresample-windows.1.2.0 → ffmpeg-swresample-windows.1.2.5}/opam +0 -0
  424. /package/tests/liquidsoap/.github/opam/packages/ffmpeg-swscale-windows/{ffmpeg-swscale-windows.1.2.0 → ffmpeg-swscale-windows.1.2.5}/opam +0 -0
  425. /package/tests/liquidsoap/.github/opam/packages/ffmpeg-windows/{ffmpeg-windows.1.2.0 → ffmpeg-windows.1.2.5}/opam +0 -0
  426. /package/tests/liquidsoap/{liquidsoap-mode.opam.template → opam/liquidsoap-mode.opam.template} +0 -0
  427. /package/tests/liquidsoap/{liquidsoap.opam.template → opam/liquidsoap.opam.template} +0 -0
@@ -0,0 +1,860 @@
1
+ (**************************************************************************)
2
+ (* ocaml-dtools *)
3
+ (* Copyright (C) 2003-2010 The Savonet Team *)
4
+ (**************************************************************************)
5
+ (* This program is free software; you can redistribute it and/or modify *)
6
+ (* it under the terms of the GNU General Public License as published by *)
7
+ (* the Free Software Foundation; either version 2 of the License, or *)
8
+ (* any later version. *)
9
+ (**************************************************************************)
10
+ (* Contact: savonet-devl@lists.sourceforge.net *)
11
+ (**************************************************************************)
12
+
13
+ (* $Id$ *)
14
+
15
+ (** ocaml-dtools
16
+ @author Stephane Gimenez *)
17
+
18
+ module Conf = struct
19
+ type link = string
20
+
21
+ type path = link list
22
+
23
+ and ut =
24
+ < kind : string option
25
+ ; descr : string
26
+ ; comments : string list
27
+ ; plug : string -> ut -> unit
28
+ ; subs : string list
29
+ ; path : string list -> ut
30
+ ; routes : ut -> path list
31
+ ; ut : ut >
32
+
33
+ type 'a t =
34
+ < kind : string option
35
+ ; alias : ?comments:string list -> ?descr:string -> (ut -> unit) -> 'a t
36
+ ; descr : string
37
+ ; comments : string list
38
+ ; plug : string -> ut -> unit
39
+ ; subs : string list
40
+ ; path : string list -> ut
41
+ ; routes : ut -> path list
42
+ ; ut : ut
43
+ ; set_d : 'a option -> unit
44
+ ; get_d : 'a option
45
+ ; set : 'a -> unit
46
+ ; get : 'a
47
+ ; validate : ('a -> bool) -> unit
48
+ ; on_change : ('a -> unit) -> unit >
49
+
50
+ type links = (string * ut) list
51
+
52
+ type 'a builder =
53
+ ?d:'a ->
54
+ ?p:(ut -> unit) ->
55
+ ?l:links ->
56
+ ?comments:string list ->
57
+ string ->
58
+ 'a t
59
+
60
+ exception Undefined of ut
61
+ exception Invalid of string
62
+ exception Unbound of ut * string
63
+ exception Bound of ut * string
64
+ exception Mismatch of ut
65
+ exception Wrong_Conf of string * string
66
+ exception File_Wrong_Conf of string * int * string
67
+ exception Cyclic of ut * ut
68
+ exception Invalid_Value of ut
69
+
70
+ let path_sep_regexp = Str.regexp "\\."
71
+ let list_sep_regexp = Str.regexp ":"
72
+
73
+ let line_regexp =
74
+ Str.regexp
75
+ "^[ \t]*\\([a-zA-Z]+\\)[ \t]+\\([a-zA-Z0-9._-]+\\)[ \t]*:\\(.*\\)$"
76
+
77
+ let comment_regexp = Str.regexp "^[ ]*\\(#.*\\)?$"
78
+ let check s = if Str.string_match path_sep_regexp s 0 then raise (Invalid s)
79
+
80
+ let make kind ?(d : 'a option) ?(p : ut -> unit = fun _ -> ())
81
+ ?(l : links = []) ?(comments : string list = []) descr : 'a t =
82
+ object (self)
83
+ val kind : string option = kind
84
+ val mutable descr : string = descr
85
+ val mutable comments : string list = comments
86
+ val mutable links : links = []
87
+ val value_d : 'a option ref = ref d
88
+ val value : 'a option ref = ref None
89
+ val mutable validators : ('a -> bool) list = []
90
+ val mutable listeners : ('a -> unit) list = []
91
+
92
+ initializer
93
+ p self#ut;
94
+ List.iter (fun (s, t) -> self#plug s t) l
95
+
96
+ method subs = List.sort compare (List.map fst links)
97
+
98
+ method private sub (s : string) : ut =
99
+ check s;
100
+ try List.assoc s links with Not_found -> raise (Unbound (self#ut, s))
101
+
102
+ method path (l : string list) : ut =
103
+ match l with [] -> self#ut | s :: q -> (self#sub s)#path q
104
+
105
+ method routes (st : ut) =
106
+ (* todo: cache already accessed nodes *)
107
+ let rec aux l t =
108
+ match t = st with
109
+ | true -> [List.rev l]
110
+ | false ->
111
+ List.concat
112
+ (List.map (fun s -> aux (s :: l) (t#path [s])) t#subs)
113
+ in
114
+ aux [] self#ut
115
+
116
+ method kind = kind
117
+ method descr = descr
118
+ method private set_descr new_descr = descr <- new_descr
119
+ method comments = comments
120
+ method private set_comments new_comments = comments <- new_comments
121
+
122
+ method plug s t =
123
+ if t#routes self#ut <> [] then raise (Cyclic (self#ut, t));
124
+ if List.mem_assoc s links then raise (Bound (self#ut, s));
125
+ links <- (s, t) :: links
126
+
127
+ (* Nice hack. heh! *)
128
+ method alias ?comments ?descr p =
129
+ let maybe f x = match x with Some x -> f x | None -> () in
130
+ let old_comments = self#comments in
131
+ let old_descr = self#descr in
132
+ maybe self#set_comments comments;
133
+ maybe self#set_descr descr;
134
+ let key = Oo.copy self in
135
+ p key#ut;
136
+ self#set_comments old_comments;
137
+ self#set_descr old_descr;
138
+ key
139
+
140
+ method ut = (self :> ut)
141
+ method get_d : 'a option = !value_d
142
+ method set_d (v : 'a option) : unit = value_d := v
143
+
144
+ method get : 'a =
145
+ match !value with
146
+ | None -> (
147
+ match !value_d with
148
+ | None -> raise (Undefined self#ut)
149
+ | Some v -> v)
150
+ | Some v -> v
151
+
152
+ method set (v : 'a) : unit =
153
+ List.iter
154
+ (fun fn -> if not (fn v) then raise (Invalid_Value self#ut))
155
+ validators;
156
+ value := Some v;
157
+ List.iter (fun fn -> fn v) listeners
158
+
159
+ method validate (fn : 'a -> bool) : unit = validators <- fn :: validators
160
+ method on_change (fn : 'a -> unit) : unit = listeners <- fn :: listeners
161
+ end
162
+
163
+ let void ?p ?l ?comments descr = (make None ?p ?l ~d:None ?comments descr)#ut
164
+ let unit ?d = make (Some "unit") ?d
165
+ let int ?d = make (Some "int") ?d
166
+ let float ?d = make (Some "float") ?d
167
+ let bool ?d = make (Some "bool") ?d
168
+ let string ?d = make (Some "string") ?d
169
+ let list ?d = make (Some "list") ?d
170
+
171
+ (* Harmful function, do not use *)
172
+ let force_type c (t : ut) : 'a t =
173
+ match t#kind with
174
+ | Some x when x = c -> (Obj.magic t : 'a t)
175
+ | _ -> raise (Mismatch t)
176
+
177
+ let as_unit t : unit t = force_type "unit" t
178
+ let as_int t : int t = force_type "int" t
179
+ let as_float t : float t = force_type "float" t
180
+ let as_bool t : bool t = force_type "bool" t
181
+ let as_string t : string t = force_type "string" t
182
+ let as_list t : string list t = force_type "list" t
183
+ let path_of_string p = Str.split path_sep_regexp p
184
+ let string_of_path p = String.concat "." p
185
+
186
+ let get_string (t : ut) =
187
+ try
188
+ match t#kind with
189
+ | None -> None
190
+ | Some "unit" -> Some ""
191
+ | Some "int" -> Some (string_of_int (as_int t)#get)
192
+ | Some "float" -> Some (string_of_float (as_float t)#get)
193
+ | Some "bool" -> Some (string_of_bool (as_bool t)#get)
194
+ | Some "string" -> Some (as_string t)#get
195
+ | Some "list" -> Some (String.concat ":" (as_list t)#get)
196
+ | _ -> assert false
197
+ with Undefined _ -> None
198
+
199
+ let get_d_string (t : ut) =
200
+ let mapopt f = function None -> None | Some x -> Some (f x) in
201
+ try
202
+ match t#kind with
203
+ | None -> None
204
+ | Some "unit" -> mapopt (fun () -> "") (as_unit t)#get_d
205
+ | Some "int" -> mapopt string_of_int (as_int t)#get_d
206
+ | Some "float" -> mapopt string_of_float (as_float t)#get_d
207
+ | Some "bool" -> mapopt string_of_bool (as_bool t)#get_d
208
+ | Some "string" -> (as_string t)#get_d
209
+ | Some "list" -> mapopt (String.concat ":") (as_list t)#get_d
210
+ | _ -> assert false
211
+ with Undefined _ -> None
212
+
213
+ let descr ?(prefix = []) (t : ut) =
214
+ let rec aux prefix t =
215
+ let p s = if prefix = "" then s else prefix ^ "." ^ s in
216
+ let subs = List.map (function s -> aux (p s) (t#path [s])) t#subs in
217
+ Printf.sprintf "## %s\n" t#descr
218
+ ^ begin
219
+ match get_d_string t with
220
+ | None -> ""
221
+ | Some d -> Printf.sprintf "# default :%s\n" d
222
+ end
223
+ ^ begin
224
+ match (t#kind, get_string t) with
225
+ | Some k, None -> Printf.sprintf "#%s\t%-30s\n" k prefix
226
+ | Some k, Some p -> Printf.sprintf "%s\t%-30s :%s\n" k prefix p
227
+ | _ -> ""
228
+ end
229
+ ^ begin
230
+ match t#comments with
231
+ | [] -> ""
232
+ | l ->
233
+ "# comments:\n"
234
+ ^ String.concat ""
235
+ (List.map (fun s -> Printf.sprintf "# %s\n" s) l)
236
+ end
237
+ ^ "\n" ^ String.concat "" subs
238
+ in
239
+ aux (string_of_path prefix) (t#path prefix)
240
+
241
+ let dump ?(prefix = []) (t : ut) =
242
+ let rec aux prefix t =
243
+ let p s = if prefix = "" then s else prefix ^ "." ^ s in
244
+ let subs = List.map (function s -> aux (p s) (t#path [s])) t#subs in
245
+ begin
246
+ match t#kind with
247
+ | Some k -> (
248
+ match (get_d_string t, get_string t) with
249
+ | None, None -> Printf.sprintf "#%s\t%-30s\n" k prefix
250
+ | Some p, None -> Printf.sprintf "#%s\t%-30s :%s\n" k prefix p
251
+ | Some p, Some p' when p' = p ->
252
+ Printf.sprintf "#%s\t%-30s :%s\n" k prefix p
253
+ | _, Some p -> Printf.sprintf "%s\t%-30s :%s\n" k prefix p)
254
+ | _ -> ""
255
+ end
256
+ ^ String.concat "" subs
257
+ in
258
+ aux (string_of_path prefix) (t#path prefix)
259
+
260
+ let conf_set (t : ut) s =
261
+ if Str.string_match line_regexp s 0 then (
262
+ let val0 = Str.matched_group 1 s in
263
+ let val1 = Str.matched_group 2 s in
264
+ let val2 = Str.matched_group 3 s in
265
+ let st = t#path (path_of_string val1) in
266
+ match val0 with
267
+ | "unit" -> (
268
+ match val2 = "" with
269
+ | false -> raise (Wrong_Conf (s, "unit expected"))
270
+ | true -> (as_unit st)#set ())
271
+ | "int" ->
272
+ let i =
273
+ try int_of_string val2
274
+ with Invalid_argument _ ->
275
+ raise (Wrong_Conf (s, "integer expected"))
276
+ in
277
+ (as_int st)#set i
278
+ | "float" ->
279
+ let f =
280
+ try float_of_string val2
281
+ with Invalid_argument _ ->
282
+ raise (Wrong_Conf (s, "float expected"))
283
+ in
284
+ (as_float st)#set f
285
+ | "bool" ->
286
+ let b =
287
+ try bool_of_string val2
288
+ with Invalid_argument _ ->
289
+ raise (Wrong_Conf (s, "boolean expected"))
290
+ in
291
+ (as_bool st)#set b
292
+ | "string" ->
293
+ let s = val2 in
294
+ (as_string st)#set s
295
+ | "list" ->
296
+ let l = Str.split list_sep_regexp val2 in
297
+ (as_list st)#set l
298
+ | _ -> raise (Wrong_Conf (s, "unknown type")))
299
+ else raise (Wrong_Conf (s, "syntax error"))
300
+
301
+ let conf_file t s =
302
+ let nb = ref 0 in
303
+ let f = open_in s in
304
+ try
305
+ while true do
306
+ nb := !nb + 1;
307
+ let l = input_line f in
308
+ if Str.string_match comment_regexp l 0 then ()
309
+ else begin
310
+ try conf_set t l
311
+ with Wrong_Conf (_, y) -> raise (File_Wrong_Conf (s, !nb, y))
312
+ end
313
+ done
314
+ with End_of_file -> ()
315
+
316
+ let args t =
317
+ [
318
+ ( ["--conf-file"; "-f"],
319
+ Arg.String (conf_file t),
320
+ "read the given configuration file" );
321
+ ( ["--conf-set"; "-s"],
322
+ Arg.String (conf_set t),
323
+ "apply the given configuration assignation" );
324
+ ( ["--conf-descr-key"],
325
+ Arg.String
326
+ (fun p ->
327
+ Printf.printf "%s" (descr ~prefix:(path_of_string p) t);
328
+ exit 0),
329
+ "describe a configuration key" );
330
+ ( ["--conf-descr"],
331
+ Arg.Unit
332
+ (fun () ->
333
+ Printf.printf "%s" (descr t);
334
+ exit 0),
335
+ "display a described table of the configuration keys" );
336
+ ( ["--conf-dump"],
337
+ Arg.Unit
338
+ (fun () ->
339
+ Printf.printf "%s" (dump t);
340
+ exit 0),
341
+ "dump the configuration state" );
342
+ ]
343
+ end
344
+
345
+ module Init = struct
346
+ let conf = Conf.void "initialization configuration"
347
+
348
+ (* Unix.fork is not implemented in Win32. *)
349
+ let daemon_conf =
350
+ if Sys.os_type <> "Win32" then conf else Conf.void "dummy conf"
351
+
352
+ let conf_daemon =
353
+ Conf.bool ~p:(daemon_conf#plug "daemon") ~d:false "run in daemon mode"
354
+
355
+ let conf_daemon_pidfile =
356
+ Conf.bool
357
+ ~p:(conf_daemon#plug "pidfile")
358
+ ~d:false "support for pidfile generation"
359
+
360
+ let conf_daemon_pidfile_path =
361
+ Conf.string ~p:(conf_daemon_pidfile#plug "path") "path to pidfile"
362
+
363
+ let conf_daemon_pidfile_perms =
364
+ Conf.int ~d:0o640
365
+ ~p:(conf_daemon_pidfile#plug "perms")
366
+ "Unix file permissions for pidfile. Default: `0o640`."
367
+
368
+ let conf_daemon_drop_user =
369
+ Conf.bool
370
+ ~p:(conf_daemon#plug "change_user")
371
+ ~d:false "Changes the effective user (drops privileges)."
372
+
373
+ let conf_daemon_user =
374
+ Conf.string
375
+ ~p:(conf_daemon_drop_user#plug "user")
376
+ ~d:"daemon" "User used to run the daemon."
377
+
378
+ let conf_daemon_group =
379
+ Conf.string
380
+ ~p:(conf_daemon_drop_user#plug "group")
381
+ ~d:"daemon" "Group used to run the daemon."
382
+
383
+ let conf_trace =
384
+ Conf.bool ~p:(conf#plug "trace") ~d:false "dump an initialization trace"
385
+
386
+ let conf_catch_exn =
387
+ Conf.bool ~p:(conf#plug "catch_exn") ~d:true
388
+ "catch exceptions, use false to backtrace exceptions"
389
+
390
+ type t = {
391
+ name : string;
392
+ mutable launched : bool;
393
+ mutable depends : t list;
394
+ mutable triggers : t list;
395
+ mutable mutex : Mutex.t;
396
+ f : unit -> unit;
397
+ }
398
+
399
+ let make ?(name = "") ?(depends = []) ?(triggers = []) ?(after = [])
400
+ ?(before = []) f =
401
+ let na =
402
+ { name; launched = false; depends; triggers; mutex = Mutex.create (); f }
403
+ in
404
+ List.iter (fun a -> a.triggers <- na :: a.triggers) after;
405
+ List.iter (fun a -> a.depends <- na :: a.depends) before;
406
+ na
407
+
408
+ let start = make ~name:"init-start" flush_all
409
+ let stop = make ~name:"init-stop" flush_all
410
+
411
+ let at_start ?name ?depends ?triggers ?after ?before f =
412
+ let a = make ?name ?depends ?triggers ?after ?before f in
413
+ start.triggers <- a :: start.triggers;
414
+ a
415
+
416
+ let at_stop ?name ?depends ?triggers ?after ?before f =
417
+ let a = make ?name ?depends ?triggers ?after ?before f in
418
+ stop.depends <- a :: stop.depends;
419
+ a
420
+
421
+ let rec exec a =
422
+ let log =
423
+ if conf_trace#get then fun s ->
424
+ let id = Thread.id (Thread.self ()) in
425
+ Printf.printf "init(%i):%-35s@%s\n%!" id a.name s
426
+ else fun _ -> ()
427
+ in
428
+ log "called";
429
+ Mutex.lock a.mutex;
430
+ try
431
+ if not a.launched then begin
432
+ a.launched <- true;
433
+ log "start";
434
+ log "start-depends";
435
+ List.iter exec a.depends;
436
+ log "stop-depends";
437
+ log "start-atom";
438
+ a.f ();
439
+ log "stop-atom";
440
+ log "start-triggers";
441
+ List.iter exec a.triggers;
442
+ log "stop-triggers";
443
+ log "stop"
444
+ end;
445
+ Mutex.unlock a.mutex;
446
+ log "return"
447
+ with e ->
448
+ Mutex.unlock a.mutex;
449
+ raise e
450
+
451
+ let rec wait_signal () =
452
+ try ignore (Thread.wait_signal [Sys.sigterm; Sys.sigint]) with
453
+ | Unix.Unix_error (Unix.EINTR, _, _) -> ()
454
+ | Sys_error s when s = "Thread.wait_signal: Interrupted system call" ->
455
+ wait_signal ()
456
+
457
+ exception StartError of exn
458
+ exception StopError of exn
459
+
460
+ (* Dummy functions in the case where
461
+ * Printexc does not have the required
462
+ * functions. *)
463
+ let get_backtrace () =
464
+ "ocaml-dtools not compiled with ocaml >= 3.11, cannot print stack backtrace"
465
+
466
+ (* For the compiler.. *)
467
+ let () = ignore (get_backtrace ())
468
+
469
+ open Printexc
470
+
471
+ let main f () =
472
+ begin
473
+ try exec start with e -> raise (StartError e)
474
+ end;
475
+ let quit pid = if Sys.os_type <> "Win32" then Unix.kill pid Sys.sigterm in
476
+ let thread pid =
477
+ try
478
+ f ();
479
+ quit pid
480
+ with e ->
481
+ let se = Printexc.to_string e in
482
+ Printf.eprintf
483
+ "init: exception encountered during main phase:\n %s\n%!" se;
484
+ Printf.eprintf "exception: %s\n%s%!" se (get_backtrace ());
485
+ if conf_catch_exn#get then quit pid else raise e
486
+ in
487
+ let th = Thread.create thread (Unix.getpid ()) in
488
+ if Sys.os_type <> "Win32" then wait_signal () else Thread.join th;
489
+ try exec stop with e -> raise (StopError e)
490
+
491
+ let catch f clean =
492
+ try
493
+ f ();
494
+ clean ()
495
+ with
496
+ | StartError e ->
497
+ Printf.eprintf
498
+ "init: exception encountered during start phase:\n %s\n%!"
499
+ (Printexc.to_string e);
500
+ clean ();
501
+ exit (-1)
502
+ | StopError e ->
503
+ Printf.eprintf
504
+ "init: exception encountered during stop phase:\n %s\n%!"
505
+ (Printexc.to_string e);
506
+ clean ();
507
+ exit (-1)
508
+
509
+ (** A function to reopen a file descriptor * Thanks to Xavier Leroy! * Ref:
510
+ http://caml.inria.fr/pub/ml-archives/caml-list/2000/01/ *
511
+ a7e3bbdfaab33603320d75dbdcd40c37.en.html *)
512
+ let reopen_out outchan filename =
513
+ flush outchan;
514
+ let fd1 = Unix.descr_of_out_channel outchan in
515
+ let fd2 = Unix.openfile filename [Unix.O_WRONLY] 0o666 in
516
+ Unix.dup2 fd2 fd1;
517
+ Unix.close fd2
518
+
519
+ (** The same for inchan *)
520
+ let reopen_in inchan filename =
521
+ let fd1 = Unix.descr_of_in_channel inchan in
522
+ let fd2 = Unix.openfile filename [Unix.O_RDONLY] 0o666 in
523
+ Unix.dup2 fd2 fd1;
524
+ Unix.close fd2
525
+
526
+ let daemonize () =
527
+ if Unix.fork () <> 0 then exit 0;
528
+ (* Detach from the console *)
529
+ if Unix.setsid () < 0 then exit 1;
530
+ (* Refork.. *)
531
+ if Unix.fork () <> 0 then exit 0;
532
+ (* Change umask to 0 *)
533
+ ignore (Unix.umask 0);
534
+ (* chdir to / *)
535
+ Unix.chdir "/";
536
+ if conf_daemon_pidfile#get then begin
537
+ (* Write PID to file *)
538
+ let filename = conf_daemon_pidfile_path#get in
539
+ let f =
540
+ open_out_gen
541
+ [Open_wronly; Open_creat; Open_trunc]
542
+ conf_daemon_pidfile_perms#get filename
543
+ in
544
+ let pid = Unix.getpid () in
545
+ output_string f (string_of_int pid);
546
+ output_char f '\n';
547
+ close_out f
548
+ end;
549
+ (* Reopen usual file descriptor *)
550
+ reopen_in stdin "/dev/null";
551
+ reopen_out stdout "/dev/null";
552
+ reopen_out stderr "/dev/null"
553
+
554
+ let cleanup_daemon () =
555
+ if conf_daemon_pidfile#get then (
556
+ try
557
+ let filename = conf_daemon_pidfile_path#get in
558
+ Sys.remove filename
559
+ with _ -> ())
560
+
561
+ exception Root_prohibited of [ `User | `Group | `Both ]
562
+
563
+ let exit_when_root () =
564
+ (* Change user.. *)
565
+ if conf_daemon_drop_user#get then begin
566
+ let grd = Unix.getgrnam conf_daemon_group#get in
567
+ let gid = grd.Unix.gr_gid in
568
+ if Unix.getegid () <> gid then Unix.setgid gid;
569
+ let pwd = Unix.getpwnam conf_daemon_user#get in
570
+ let uid = pwd.Unix.pw_uid in
571
+ if Unix.geteuid () <> uid then Unix.setuid uid
572
+ end;
573
+ match (Unix.geteuid (), Unix.getegid ()) with
574
+ | 0, 0 -> raise (Root_prohibited `Both)
575
+ | 0, _ -> raise (Root_prohibited `User)
576
+ | _, 0 -> raise (Root_prohibited `Group)
577
+ | _ -> ()
578
+
579
+ let init ?(prohibit_root = false) f =
580
+ if prohibit_root then exit_when_root ();
581
+ if conf_daemon#get && Sys.os_type <> "Win32" then daemonize ();
582
+ let signal_h _ = () in
583
+ Sys.set_signal Sys.sigterm (Sys.Signal_handle signal_h);
584
+ Sys.set_signal Sys.sigint (Sys.Signal_handle signal_h);
585
+ (* We block signals that would kill us,
586
+ * we'll wait for them and shutdown cleanly.
587
+ * On Windows this is impossible so the only way for the application
588
+ * to shutdown is to terminate the main function [f]. *)
589
+ if Sys.os_type <> "Win32" then
590
+ ignore (Unix.sigprocmask Unix.SIG_BLOCK [Sys.sigterm; Sys.sigint]);
591
+ let cleanup =
592
+ if conf_daemon#get && Sys.os_type <> "Win32" then cleanup_daemon
593
+ else fun () -> ()
594
+ in
595
+ catch (main f) cleanup
596
+
597
+ let args =
598
+ if Sys.os_type <> "Win32" then
599
+ [
600
+ ( ["-d"; "--daemon"],
601
+ Arg.Unit (fun () -> conf_daemon#set true),
602
+ "Run in daemon mode." );
603
+ ]
604
+ else []
605
+ end
606
+
607
+ module Log = struct
608
+ type entry = {
609
+ time : float;
610
+ label : string option;
611
+ level : int option;
612
+ log : string;
613
+ }
614
+
615
+ type pending_entry = { colorize : entry -> entry; entry : entry }
616
+
617
+ type t =
618
+ < active : int -> bool
619
+ ; level : int
620
+ ; set_level : int -> unit
621
+ ; path : Conf.path
622
+ ; f : 'a. int -> ('a, unit, string, unit) format4 -> 'a
623
+ ; g :
624
+ 'a.
625
+ ?colorize:(entry -> entry) ->
626
+ int ->
627
+ ('a, unit, string, unit) format4 ->
628
+ 'a >
629
+
630
+ type custom_log = { timestamp : bool; exec : string -> unit }
631
+
632
+ let log_ch = ref None
633
+
634
+ (* Custom logging methods. *)
635
+ let custom_log : (string, custom_log) Hashtbl.t = Hashtbl.create 0
636
+ let add_custom_log name f = Hashtbl.replace custom_log name f
637
+ let rm_custom_log name = Hashtbl.remove custom_log name
638
+ let conf = Conf.void "log configuration"
639
+ let conf_level = Conf.int ~p:(conf#plug "level") ~d:3 "general log level"
640
+
641
+ let conf_unix_timestamps =
642
+ Conf.bool
643
+ ~p:(conf#plug "unix_timestamps")
644
+ ~d:false
645
+ "display unix timestamps (subsecond accuracy, timezone independent)"
646
+
647
+ let conf_file = Conf.bool ~p:(conf#plug "file") ~d:true "log to file"
648
+ let conf_file_path = Conf.string ~p:(conf_file#plug "path") "path to log file"
649
+
650
+ let conf_file_append =
651
+ Conf.bool ~p:(conf_file#plug "append") ~d:true "append log to the file"
652
+
653
+ let conf_file_perms =
654
+ Conf.int ~p:(conf_file#plug "perms") ~d:0o600 "log file permissions"
655
+
656
+ let conf_stdout = Conf.bool ~p:(conf#plug "stdout") ~d:false "log to stdout"
657
+
658
+ let timestamp time =
659
+ match conf_unix_timestamps#get with
660
+ | true -> Printf.sprintf "%f" time
661
+ | false ->
662
+ let date = Unix.localtime time in
663
+ Printf.sprintf "%d/%02d/%02d %02d:%02d:%02d"
664
+ (date.Unix.tm_year + 1900) (date.Unix.tm_mon + 1) date.Unix.tm_mday
665
+ date.Unix.tm_hour date.Unix.tm_min date.Unix.tm_sec
666
+
667
+ let message ?(show_timestamp = true) { time; label; level; log } =
668
+ let label =
669
+ match (label, level) with
670
+ | None, None -> ""
671
+ | Some l, None -> Printf.sprintf "[%s] " l
672
+ | None, Some d -> Printf.sprintf "[%d] " d
673
+ | Some l, Some d -> Printf.sprintf "[%s:%d] " l d
674
+ in
675
+ let str = label ^ log in
676
+ let timestamp = if show_timestamp then timestamp time ^ " " else "" in
677
+ Printf.sprintf "%s%s" timestamp str
678
+
679
+ let print { colorize; entry } =
680
+ let to_stdout = conf_stdout#get in
681
+ let to_file = !log_ch <> None in
682
+ begin
683
+ match to_stdout || to_file with
684
+ | true ->
685
+ let do_stdout () =
686
+ Printf.printf "%s\n%!" (message (colorize entry))
687
+ in
688
+ let do_file () =
689
+ match !log_ch with
690
+ | None -> ()
691
+ | Some ch -> Printf.fprintf ch "%s\n%!" (message entry)
692
+ in
693
+ if to_stdout then do_stdout ();
694
+ if to_file then do_file ()
695
+ | false -> ()
696
+ end;
697
+ let f _ x = x.exec (message ~show_timestamp:x.timestamp entry) in
698
+ Hashtbl.iter f custom_log
699
+
700
+ (* Avoid interlacing logs *)
701
+ let log_mutex = Mutex.create ()
702
+ let log_condition = Condition.create ()
703
+ let log_queue = ref (Queue.create ())
704
+ let log_stop = ref false
705
+ let log_thread = ref None
706
+
707
+ let mutexify f x =
708
+ Mutex.lock log_mutex;
709
+ try
710
+ let ret = f x in
711
+ Mutex.unlock log_mutex;
712
+ ret
713
+ with e ->
714
+ Mutex.unlock log_mutex;
715
+ raise e
716
+
717
+ let rotate_queue () =
718
+ let new_q = Queue.create () in
719
+ mutexify
720
+ (fun () ->
721
+ let q = !log_queue in
722
+ log_queue := new_q;
723
+ q)
724
+ ()
725
+
726
+ let flush_queue () =
727
+ let rec flush q =
728
+ Queue.iter print q;
729
+ let q = rotate_queue () in
730
+ if not (Queue.is_empty q) then flush q
731
+ in
732
+ flush (rotate_queue ())
733
+
734
+ let log_thread_fn () =
735
+ let rec f () =
736
+ flush_queue ();
737
+ let log_stop =
738
+ mutexify
739
+ (fun () ->
740
+ if !log_stop then true
741
+ else begin
742
+ Condition.wait log_condition log_mutex;
743
+ !log_stop
744
+ end)
745
+ ()
746
+ in
747
+ if not log_stop then f ()
748
+ in
749
+ f ()
750
+
751
+ let proceed =
752
+ mutexify (fun entry ->
753
+ Queue.push entry !log_queue;
754
+ Condition.signal log_condition)
755
+
756
+ let make path : t =
757
+ let path_str = Conf.string_of_path path in
758
+ let conf_level = ref (fun () -> conf_level#get) in
759
+ object (self : t)
760
+ method path = path
761
+ method active level = level <= !conf_level ()
762
+ method level = !conf_level ()
763
+ method set_level level = conf_level := fun () -> level
764
+
765
+ method g ?(colorize = fun x -> x) level =
766
+ match self#active level with
767
+ | true ->
768
+ let time = Unix.gettimeofday () in
769
+ Printf.ksprintf (fun s ->
770
+ List.iter
771
+ (fun log ->
772
+ proceed
773
+ {
774
+ colorize;
775
+ entry =
776
+ {
777
+ time;
778
+ label = Some path_str;
779
+ level = Some level;
780
+ log;
781
+ };
782
+ })
783
+ (String.split_on_char '\n' s))
784
+ | false -> Printf.ksprintf (fun _ -> ())
785
+
786
+ method f level = self#g ?colorize:None level
787
+ end
788
+
789
+ let init () =
790
+ let time = Unix.gettimeofday () in
791
+ let reopen_log =
792
+ if conf_file#get then begin
793
+ let opts =
794
+ [Open_wronly; Open_creat; Open_nonblock]
795
+ @ if conf_file_append#get then [Open_append] else [Open_trunc]
796
+ in
797
+ let log_file_path = conf_file_path#get in
798
+ let log_file_perms = conf_file_perms#get in
799
+ log_ch := Some (open_out_gen opts log_file_perms log_file_path);
800
+ fun _ ->
801
+ begin
802
+ match !log_ch with
803
+ | None -> ()
804
+ | Some ch ->
805
+ log_ch := None;
806
+ close_out ch
807
+ end;
808
+ log_ch := Some (open_out_gen opts log_file_perms log_file_path)
809
+ end
810
+ else fun _ -> ()
811
+ in
812
+ (* Re-open log file on SIGUSR1 -- for logrotate *)
813
+ if Sys.os_type <> "Win32" then
814
+ Sys.set_signal Sys.sigusr1 (Sys.Signal_handle reopen_log);
815
+ print
816
+ {
817
+ colorize = (fun x -> x);
818
+ entry = { time; level = None; label = None; log = ">>> LOG START" };
819
+ };
820
+ log_thread := Some (Thread.create log_thread_fn ())
821
+
822
+ let start = Init.make ~name:"init-log-start" ~before:[Init.start] init
823
+
824
+ let close () =
825
+ let time = Unix.gettimeofday () in
826
+ mutexify (fun () -> log_stop := true) ();
827
+ proceed
828
+ {
829
+ colorize = (fun x -> x);
830
+ entry = { time; level = None; label = None; log = ">>> LOG END" };
831
+ };
832
+ begin
833
+ match !log_thread with
834
+ | None -> ()
835
+ | Some th ->
836
+ log_thread := None;
837
+ Condition.signal log_condition;
838
+ Thread.join th
839
+ end;
840
+ match !log_ch with
841
+ | None -> ()
842
+ | Some ch ->
843
+ log_ch := None;
844
+ close_out ch
845
+
846
+ let stop = Init.make ~name:"init-log-stop" ~after:[Init.stop] close
847
+
848
+ let args =
849
+ [
850
+ ( ["--log-stdout"],
851
+ Arg.Unit (fun () -> conf_stdout#set true),
852
+ "log also to stdout" );
853
+ ( ["--log-file"; "-l"],
854
+ Arg.String
855
+ (fun s ->
856
+ conf_file#set true;
857
+ conf_file_path#set s),
858
+ "log file" );
859
+ ]
860
+ end