Compare commits
106 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
bf41d1ad2b | ||
![]() |
d27e534a85 | ||
![]() |
6d54928d7c | ||
![]() |
0dffe05bf7 | ||
![]() |
9ef1f10319 | ||
![]() |
23fcfdbd2a | ||
![]() |
3401d26d4c | ||
![]() |
256753ea46 | ||
![]() |
76cd5f8595 | ||
![]() |
5684025847 | ||
![]() |
744bd1eadc | ||
![]() |
2bc127bb43 | ||
![]() |
7770298a65 | ||
![]() |
fa50cdb39e | ||
![]() |
816ef12088 | ||
![]() |
5ff786e59c | ||
![]() |
80fe88e8f6 | ||
![]() |
a1afe9afc6 | ||
![]() |
fe598e7d30 | ||
![]() |
4475b8ca04 | ||
![]() |
a714bdb0ce | ||
![]() |
087874620f | ||
![]() |
f1116c9258 | ||
![]() |
d01fb6730a | ||
![]() |
7bfe6a3304 | ||
![]() |
9a577f8060 | ||
![]() |
d75a0d714e | ||
![]() |
9be3a1554e | ||
![]() |
7764719513 | ||
![]() |
dcbb9fe07c | ||
![]() |
e3b347820a | ||
![]() |
a84bf5a92e | ||
![]() |
732bdc800d | ||
![]() |
a8661b5931 | ||
![]() |
5680a3a4b7 | ||
![]() |
15ce8eb487 | ||
![]() |
b7744be208 | ||
![]() |
63c5d66016 | ||
![]() |
d09bd9178f | ||
![]() |
7d8b1860c3 | ||
![]() |
b06825829b | ||
![]() |
ba4cd47fd8 | ||
![]() |
bbe403f141 | ||
![]() |
5df2707d98 | ||
![]() |
4859ea468f | ||
![]() |
2a8830db70 | ||
![]() |
fed9b6fd74 | ||
![]() |
b02890eb8a | ||
![]() |
da882a6eb6 | ||
![]() |
aeb89aa9d6 | ||
![]() |
f885807ecc | ||
![]() |
b826fd71f0 | ||
![]() |
ae35df1126 | ||
![]() |
80e55f6bfc | ||
![]() |
e7411c0c4b | ||
![]() |
e9af692973 | ||
![]() |
0cf90ee8b6 | ||
![]() |
dc3c0c8866 | ||
![]() |
1c46bb1ba6 | ||
![]() |
2e8f42c6ad | ||
![]() |
2b301ffd2c | ||
![]() |
ef0765ca10 | ||
![]() |
9766ac6db3 | ||
![]() |
32799ff682 | ||
![]() |
ce093be12c | ||
![]() |
2c276770f0 | ||
![]() |
75a592f629 | ||
![]() |
13ce07d181 | ||
![]() |
d659c7df19 | ||
![]() |
f8403a1d29 | ||
![]() |
ebb952c4ad | ||
![]() |
bea3b954a5 | ||
![]() |
129d8e89b9 | ||
![]() |
65778a3774 | ||
![]() |
d9841668ff | ||
![]() |
85d27cbcb9 | ||
![]() |
9b95e65bd9 | ||
![]() |
12a86c4975 | ||
![]() |
0b9435858b | ||
![]() |
f0386459ee | ||
![]() |
e98d4670b8 | ||
![]() |
56cc42b752 | ||
![]() |
ead208987d | ||
![]() |
364acc8949 | ||
![]() |
a8f4d2b6fc | ||
![]() |
0eb113e7c6 | ||
![]() |
96a9670c69 | ||
![]() |
dcc5ce6792 | ||
![]() |
23d08820a2 | ||
![]() |
b9b906ab20 | ||
![]() |
964804a4c2 | ||
![]() |
92495d2b0b | ||
![]() |
9270829b5b | ||
![]() |
b6243a9945 | ||
![]() |
496f88653d | ||
![]() |
5ef645df97 | ||
![]() |
bf49c9e4e2 | ||
![]() |
0da9c91af2 | ||
![]() |
193e637dd9 | ||
![]() |
928bee933d | ||
![]() |
4d1720c886 | ||
![]() |
8f8ed87327 | ||
![]() |
28a441c977 | ||
![]() |
8cf50b08f2 | ||
![]() |
818b7e0641 | ||
![]() |
e70f40fac1 |
.travis.ymlNEWS
android
doc
meson.buildpython/build
src
LocateUri.cxxPlaylistDatabase.cxxReplayGainInfo.hxxSongPrint.cxxSongSave.cxxSongUpdate.cxxStats.cxxTimePrint.cxx
archive
plugins
command
db
decoder
event
input
lib
curl
Easy.hxxEscape.cxxEscape.hxxForm.cxxGlobal.cxxGlobal.hxxHandler.hxxInit.cxxMulti.hxxRequest.cxxRequest.hxxSlist.hxxString.hxxVersion.cxxVersion.hxxmeson.build
gcrypt
icu
nfs
sqlite
xiph
neighbor
net
output
pcm
player
queue
song
storage
plugins
system
tag
time
util
zeroconf
test
53
.travis.yml
53
.travis.yml
@@ -2,6 +2,28 @@ language: cpp
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# Ubuntu Bionic (18.04) with GCC 7
|
||||
- os: linux
|
||||
dist: bionic
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:deadsnakes/ppa' # for Python 3.7 (required by Meson)
|
||||
packages:
|
||||
- libgtest-dev
|
||||
- libboost-dev
|
||||
- python3.6
|
||||
- python3-urllib3
|
||||
- ninja-build
|
||||
before_install:
|
||||
- wget https://bootstrap.pypa.io/get-pip.py
|
||||
- /usr/bin/python3.6 get-pip.py --user
|
||||
install:
|
||||
- /usr/bin/python3.6 $HOME/.local/bin/pip install --user meson
|
||||
env:
|
||||
- MATRIX_EVAL="export PATH=\$HOME/.local/bin:\$PATH"
|
||||
|
||||
# Ubuntu Trusty (16.04) with GCC 6
|
||||
- os: linux
|
||||
dist: trusty
|
||||
addons:
|
||||
@@ -25,8 +47,9 @@ matrix:
|
||||
- /usr/bin/python3.6 $HOME/.local/bin/pip install --user meson
|
||||
env:
|
||||
# use gold as workaround for https://sourceware.org/bugzilla/show_bug.cgi?id=17068
|
||||
- MATRIX_EVAL="export CC=gcc-6 CXX=g++-6 LDFLAGS=-fuse-ld=gold PATH=$HOME/.local/bin:$PATH"
|
||||
- MATRIX_EVAL="export CC='ccache gcc-6' CXX='ccache g++-6' LDFLAGS=-fuse-ld=gold PATH=\$HOME/.local/bin:\$PATH"
|
||||
|
||||
# Ubuntu Trusty (16.04) with GCC 8
|
||||
- os: linux
|
||||
dist: trusty
|
||||
addons:
|
||||
@@ -50,25 +73,37 @@ matrix:
|
||||
- /usr/bin/python3.6 $HOME/.local/bin/pip install --user meson
|
||||
env:
|
||||
# use gold as workaround for https://sourceware.org/bugzilla/show_bug.cgi?id=17068
|
||||
- MATRIX_EVAL="export CC=gcc-8 CXX=g++-8 LDFLAGS=-fuse-ld=gold PATH=$HOME/.local/bin:$PATH"
|
||||
- MATRIX_EVAL="export CC='ccache gcc-8' CXX='ccache g++-8' LDFLAGS=-fuse-ld=gold PATH=\$HOME/.local/bin:\$PATH"
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode9.3beta
|
||||
osx_image: xcode9.4
|
||||
addons:
|
||||
homebrew:
|
||||
packages:
|
||||
- ccache
|
||||
- meson
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- MATRIX_EVAL="export PATH=/usr/local/opt/ccache/libexec:$PATH HOMEBREW_NO_ANALYTICS=1"
|
||||
|
||||
cache:
|
||||
- apt
|
||||
- ccache
|
||||
apt: true
|
||||
ccache: true
|
||||
directories:
|
||||
- $HOME/Library/Caches/Homebrew
|
||||
|
||||
before_cache:
|
||||
- test "$TRAVIS_OS_NAME" != "osx" || brew cleanup
|
||||
|
||||
before_install:
|
||||
- eval "${MATRIX_EVAL}"
|
||||
# C++14
|
||||
- test "$TRAVIS_OS_NAME" != "osx" || brew update
|
||||
|
||||
install:
|
||||
# C++14
|
||||
- test "$TRAVIS_OS_NAME" != "osx" || brew install ccache meson
|
||||
|
||||
# Work around "Target /usr/local/lib/libgtest.a is a symlink
|
||||
# belonging to nss. You can unlink it" during gtest install
|
||||
- test "$TRAVIS_OS_NAME" != "osx" || brew unlink nss
|
||||
|
||||
- test "$TRAVIS_OS_NAME" != "osx" || brew install --HEAD https://gist.githubusercontent.com/Kronuz/96ac10fbd8472eb1e7566d740c4034f8/raw/gtest.rb
|
||||
|
||||
before_script:
|
||||
|
39
NEWS
39
NEWS
@@ -1,3 +1,42 @@
|
||||
ver 0.21.18 (2019/12/24)
|
||||
* protocol
|
||||
- work around Mac OS X bug in the ISO 8601 parser
|
||||
* output
|
||||
- alsa: fix hang bug with ALSA "null" outputs
|
||||
* storage
|
||||
- curl: fix crash bug
|
||||
* drop support for CURL versions older than 7.32.0
|
||||
* reduce unnecessary CPU wakeups
|
||||
|
||||
ver 0.21.17 (2019/12/16)
|
||||
* protocol
|
||||
- relax the ISO 8601 parser: allow omitting field separators, the
|
||||
time of day and the "Z" suffix
|
||||
* archive
|
||||
- zzip: improve error reporting
|
||||
* outputs
|
||||
- jack: mark ports as terminal
|
||||
- shout: declare metadata as UTF-8
|
||||
* fix build failure with -Ddatabase=false
|
||||
|
||||
ver 0.21.16 (2019/10/16)
|
||||
* queue
|
||||
- fix relative destination offset when moving a range
|
||||
* storage
|
||||
- curl: request the "resourcetype" property to fix database update
|
||||
- curl: URL-encode more paths
|
||||
- curl: follow redirects for collections without trailing slash
|
||||
* update
|
||||
- fix crash when music_directory is not a directory
|
||||
* fix build with iconv() instead of ICU
|
||||
|
||||
ver 0.21.15 (2019/09/25)
|
||||
* decoder
|
||||
- dsdiff, dsf: fix displayed bit rate
|
||||
- mpcdec: fix bogus ReplayGain values
|
||||
* output
|
||||
- solaris: fix build with glibc 2.30
|
||||
|
||||
ver 0.21.14 (2019/08/21)
|
||||
* decoder
|
||||
- sidplay: show track durations in database
|
||||
|
@@ -2,8 +2,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.musicpd"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="37"
|
||||
android:versionName="0.21.14">
|
||||
android:versionCode="41"
|
||||
android:versionName="0.21.18">
|
||||
|
||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="26"/>
|
||||
|
||||
|
@@ -38,7 +38,7 @@ author = 'Max Kellermann'
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.21.14'
|
||||
version = '0.21.18'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = version
|
||||
|
||||
|
@@ -42,7 +42,7 @@ Provides access to the database of another :program:`MPD` instance using libmpdc
|
||||
* - **password**
|
||||
- The password used to log in to the "master" :program:`MPD` instance.
|
||||
* - **keepalive yes|no**
|
||||
- Send TCP keepalive packets to the "master" :program:`MPD` instance? This option can help avoid certain firewalls dropping inactive connections, at the expensive of a very small amount of additional network traffic. Disabled by default.
|
||||
- Send TCP keepalive packets to the "master" :program:`MPD` instance? This option can help avoid certain firewalls dropping inactive connections, at the expense of a very small amount of additional network traffic. Disabled by default.
|
||||
|
||||
upnp
|
||||
----
|
||||
@@ -1069,7 +1069,7 @@ Filter plugins
|
||||
normalize
|
||||
---------
|
||||
|
||||
Normalize the volume during playback (at the expensve of quality).
|
||||
Normalize the volume during playback (at the expense of quality).
|
||||
|
||||
|
||||
null
|
||||
|
12
doc/user.rst
12
doc/user.rst
@@ -62,16 +62,16 @@ In any case, you need:
|
||||
Each plugin usually needs a codec library, which you also need to
|
||||
install. Check the :doc:`plugins` for details about required libraries
|
||||
|
||||
For example, the following installs a fairly complete list of build dependencies on Debian Jessie:
|
||||
For example, the following installs a fairly complete list of build dependencies on Debian Buster:
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
apt install g++ \
|
||||
apt install meson g++ \
|
||||
libpcre3-dev \
|
||||
libmad0-dev libmpg123-dev libid3tag0-dev \
|
||||
libflac-dev libvorbis-dev libopus-dev \
|
||||
libflac-dev libvorbis-dev libopus-dev libogg-dev \
|
||||
libadplug-dev libaudiofile-dev libsndfile1-dev libfaad-dev \
|
||||
libfluidsynth-dev libgme-dev libmikmod2-dev libmodplug-dev \
|
||||
libfluidsynth-dev libgme-dev libmikmod-dev libmodplug-dev \
|
||||
libmpcdec-dev libwavpack-dev libwildmidi-dev \
|
||||
libsidplay2-dev libsidutils-dev libresid-builder-dev \
|
||||
libavcodec-dev libavformat-dev \
|
||||
@@ -91,7 +91,9 @@ For example, the following installs a fairly complete list of build dependencies
|
||||
libsystemd-dev \
|
||||
libgtest-dev \
|
||||
libboost-dev \
|
||||
libicu-dev
|
||||
libicu-dev \
|
||||
libchromaprint-dev \
|
||||
libgcrypt20-dev
|
||||
|
||||
|
||||
Now configure the source tree:
|
||||
|
@@ -1,7 +1,7 @@
|
||||
project(
|
||||
'mpd',
|
||||
['c', 'cpp'],
|
||||
version: '0.21.14',
|
||||
version: '0.21.18',
|
||||
meson_version: '>= 0.49.0',
|
||||
default_options: [
|
||||
'c_std=c99',
|
||||
@@ -304,6 +304,7 @@ if enable_database
|
||||
endif
|
||||
|
||||
subdir('src/util')
|
||||
subdir('src/time')
|
||||
subdir('src/system')
|
||||
subdir('src/thread')
|
||||
subdir('src/event')
|
||||
@@ -385,8 +386,11 @@ endif
|
||||
if archive_glue_dep.found()
|
||||
sources += [
|
||||
'src/TagArchive.cxx',
|
||||
'src/db/update/Archive.cxx',
|
||||
]
|
||||
|
||||
if enable_database
|
||||
sources += ['src/db/update/Archive.cxx']
|
||||
endif
|
||||
endif
|
||||
|
||||
if is_windows
|
||||
|
@@ -15,8 +15,8 @@ libmpdclient = MesonProject(
|
||||
)
|
||||
|
||||
libogg = AutotoolsProject(
|
||||
'http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.xz',
|
||||
'4f3fc6178a533d392064f14776b23c397ed4b9f48f5de297aba73b643f955c08',
|
||||
'http://downloads.xiph.org/releases/ogg/libogg-1.3.4.tar.xz',
|
||||
'c163bc12bc300c401b6aa35907ac682671ea376f13ae0969a220f7ddf71893fe',
|
||||
'lib/libogg.a',
|
||||
[
|
||||
'--disable-shared', '--enable-static',
|
||||
@@ -38,8 +38,8 @@ libvorbis = AutotoolsProject(
|
||||
)
|
||||
|
||||
opus = AutotoolsProject(
|
||||
'https://archive.mozilla.org/pub/opus/opus-1.3.tar.gz',
|
||||
'4f3d69aefdf2dbaf9825408e452a8a414ffc60494c70633560700398820dc550',
|
||||
'https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz',
|
||||
'65b58e1e25b2a114157014736a3d9dfeaad8d41be1c8179866f144a2fb44ff9d',
|
||||
'lib/libopus.a',
|
||||
[
|
||||
'--disable-shared', '--enable-static',
|
||||
@@ -112,8 +112,8 @@ liblame = AutotoolsProject(
|
||||
)
|
||||
|
||||
ffmpeg = FfmpegProject(
|
||||
'http://ffmpeg.org/releases/ffmpeg-4.1.3.tar.xz',
|
||||
'0c3020452880581a8face91595b239198078645e7d7184273b8bcc7758beb63d',
|
||||
'http://ffmpeg.org/releases/ffmpeg-4.2.1.tar.xz',
|
||||
'cec7c87e9b60d174509e263ac4011b522385fd0775292e1670ecc1180c9bb6d4',
|
||||
'lib/libavcodec.a',
|
||||
[
|
||||
'--disable-shared', '--enable-static',
|
||||
@@ -341,8 +341,8 @@ ffmpeg = FfmpegProject(
|
||||
)
|
||||
|
||||
curl = AutotoolsProject(
|
||||
'http://curl.haxx.se/download/curl-7.64.1.tar.xz',
|
||||
'9252332a7f871ce37bfa7f78bdd0a0e3924d8187cc27cb57c76c9474a7168fb3',
|
||||
'http://curl.haxx.se/download/curl-7.66.0.tar.xz',
|
||||
'dbb48088193016d079b97c5c3efde8efa56ada2ebf336e8a97d04eb8e2ed98c1',
|
||||
'lib/libcurl.a',
|
||||
[
|
||||
'--disable-shared', '--enable-static',
|
||||
@@ -365,8 +365,8 @@ curl = AutotoolsProject(
|
||||
)
|
||||
|
||||
libexpat = AutotoolsProject(
|
||||
'https://github.com/libexpat/libexpat/releases/download/R_2_2_6/expat-2.2.6.tar.bz2',
|
||||
'17b43c2716d521369f82fc2dc70f359860e90fa440bea65b3b85f0b246ea81f2',
|
||||
'https://github.com/libexpat/libexpat/releases/download/R_2_2_7/expat-2.2.7.tar.bz2',
|
||||
'cbc9102f4a31a8dafd42d642e9a3aa31e79a0aedaa1f6efd2795ebc83174ec18',
|
||||
'lib/libexpat.a',
|
||||
[
|
||||
'--disable-shared', '--enable-static',
|
||||
@@ -392,7 +392,7 @@ libnfs = AutotoolsProject(
|
||||
)
|
||||
|
||||
boost = BoostProject(
|
||||
'http://downloads.sourceforge.net/project/boost/boost/1.70.0/boost_1_70_0.tar.bz2',
|
||||
'430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778',
|
||||
'https://dl.bintray.com/boostorg/release/1.71.0/source/boost_1_71_0.tar.bz2',
|
||||
'd73a8da01e8bf8c7eda40b4c84915071a8c8a0df4a6734537ddde4a8580524ee',
|
||||
'include/boost/version.hpp',
|
||||
)
|
||||
|
@@ -29,6 +29,8 @@
|
||||
#include "storage/StorageInterface.hxx"
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
static LocatedUri
|
||||
LocateFileUri(const char *uri, const Client *client
|
||||
#ifdef ENABLE_DATABASE
|
||||
|
@@ -21,8 +21,8 @@
|
||||
#include "db/PlaylistVector.hxx"
|
||||
#include "fs/io/TextFile.hxx"
|
||||
#include "fs/io/BufferedOutputStream.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/StringStrip.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
#include <string.h>
|
||||
|
@@ -38,6 +38,10 @@ struct ReplayGainTuple {
|
||||
return gain > -100;
|
||||
}
|
||||
|
||||
static constexpr ReplayGainTuple Undefined() noexcept {
|
||||
return {-200.0f, 0.0f};
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
float CalculateScale(const ReplayGainConfig &config) const noexcept;
|
||||
};
|
||||
@@ -49,6 +53,13 @@ struct ReplayGainInfo {
|
||||
return track.IsDefined() || album.IsDefined();
|
||||
}
|
||||
|
||||
static constexpr ReplayGainInfo Undefined() noexcept {
|
||||
return {
|
||||
ReplayGainTuple::Undefined(),
|
||||
ReplayGainTuple::Undefined(),
|
||||
};
|
||||
}
|
||||
|
||||
const ReplayGainTuple &Get(ReplayGainMode mode) const noexcept {
|
||||
return mode == ReplayGainMode::ALBUM
|
||||
? (album.IsDefined() ? album : track)
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "TagPrint.hxx"
|
||||
#include "client/Response.hxx"
|
||||
#include "fs/Traits.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/UriUtil.hxx"
|
||||
|
||||
#define SONG_FILE "file: "
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "tag/ParseName.hxx"
|
||||
#include "tag/Tag.hxx"
|
||||
#include "tag/Builder.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/StringAPI.hxx"
|
||||
#include "util/StringBuffer.hxx"
|
||||
#include "util/StringStrip.hxx"
|
||||
|
@@ -98,8 +98,6 @@ Song::UpdateFile(Storage &storage) noexcept
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_ARCHIVE
|
||||
|
||||
Song *
|
||||
@@ -145,6 +143,8 @@ Song::UpdateFileInArchive(ArchiveFile &archive) noexcept
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* ENABLE_DATABASE */
|
||||
|
||||
bool
|
||||
DetachedSong::LoadFile(Path path) noexcept
|
||||
{
|
||||
|
@@ -28,7 +28,7 @@
|
||||
#include "db/Stats.hxx"
|
||||
#include "system/Clock.hxx"
|
||||
#include "Log.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
|
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "TimePrint.hxx"
|
||||
#include "client/Response.hxx"
|
||||
#include "util/TimeISO8601.hxx"
|
||||
#include "time/ISO8601.hxx"
|
||||
|
||||
void
|
||||
time_print(Response &r, const char *name,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2018 The Music Player Daemon Project
|
||||
* Copyright 2003-2019 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "../ArchiveVisitor.hxx"
|
||||
#include "input/InputStream.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "system/Error.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
#include <zzip/zzip.h>
|
||||
@@ -120,9 +121,19 @@ ZzipArchiveFile::OpenStream(const char *pathname,
|
||||
Mutex &mutex)
|
||||
{
|
||||
ZZIP_FILE *_file = zzip_file_open(dir->dir, pathname, 0);
|
||||
if (_file == nullptr)
|
||||
throw FormatRuntimeError("not found in the ZIP file: %s",
|
||||
pathname);
|
||||
if (_file == nullptr) {
|
||||
const auto error = (zzip_error_t)zzip_error(dir->dir);
|
||||
switch (error) {
|
||||
case ZZIP_ENOENT:
|
||||
throw FormatFileNotFound("Failed to open '%s' in ZIP file",
|
||||
pathname);
|
||||
|
||||
default:
|
||||
throw FormatRuntimeError("Failed to open '%s' in ZIP file: %s",
|
||||
pathname,
|
||||
zzip_strerror(error));
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_unique<ZzipInputStream>(dir, pathname,
|
||||
mutex,
|
||||
|
@@ -35,7 +35,7 @@
|
||||
#include "decoder/DecoderPrint.hxx"
|
||||
#include "ls.hxx"
|
||||
#include "mixer/Volume.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/UriUtil.hxx"
|
||||
#include "util/StringAPI.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
|
@@ -37,9 +37,9 @@
|
||||
#include "client/Response.hxx"
|
||||
#include "Mapper.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/UriUtil.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "LocateUri.hxx"
|
||||
|
||||
bool
|
||||
|
@@ -23,8 +23,8 @@
|
||||
#include "StorageCommands.hxx"
|
||||
#include "Request.hxx"
|
||||
#include "CommandError.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/UriUtil.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "fs/Traits.hxx"
|
||||
#include "client/Client.hxx"
|
||||
|
@@ -34,7 +34,7 @@
|
||||
#include "PlaylistInfo.hxx"
|
||||
#include "Interface.hxx"
|
||||
#include "fs/Traits.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/RecursiveMap.hxx"
|
||||
|
||||
#include <functional>
|
||||
|
@@ -25,7 +25,7 @@
|
||||
#include "PlaylistDatabase.hxx"
|
||||
#include "fs/io/TextFile.hxx"
|
||||
#include "fs/io/BufferedOutputStream.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/StringCompare.hxx"
|
||||
#include "util/NumberParser.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
@@ -493,6 +493,12 @@ UpdateWalk::Walk(Directory &root, const char *path, bool discard) noexcept
|
||||
if (!GetInfo(storage, "", info))
|
||||
return false;
|
||||
|
||||
if (!info.IsDirectory()) {
|
||||
FormatError(update_domain, "Not a directory: %s",
|
||||
storage.MapUTF8("").c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
ExcludeList exclude_list;
|
||||
|
||||
UpdateDirectory(root, exclude_list, info);
|
||||
|
@@ -362,6 +362,7 @@ dsdiff_decode_chunk(DecoderClient &client, InputStream &is,
|
||||
unsigned channels, unsigned sample_rate,
|
||||
const offset_type total_bytes)
|
||||
{
|
||||
const unsigned kbit_rate = channels * sample_rate / 1000;
|
||||
const offset_type start_offset = is.GetOffset();
|
||||
|
||||
uint8_t buffer[8192];
|
||||
@@ -408,7 +409,7 @@ dsdiff_decode_chunk(DecoderClient &client, InputStream &is,
|
||||
bit_reverse_buffer(buffer, buffer + nbytes);
|
||||
|
||||
cmd = client.SubmitData(is, buffer, nbytes,
|
||||
sample_rate / 1000);
|
||||
kbit_rate);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -256,6 +256,7 @@ dsf_decode_chunk(DecoderClient &client, InputStream &is,
|
||||
offset_type n_blocks,
|
||||
bool bitreverse)
|
||||
{
|
||||
const unsigned kbit_rate = channels * sample_rate / 1000;
|
||||
const size_t block_size = channels * DSF_BLOCK_SIZE;
|
||||
const offset_type start_offset = is.GetOffset();
|
||||
|
||||
@@ -291,7 +292,7 @@ dsf_decode_chunk(DecoderClient &client, InputStream &is,
|
||||
|
||||
cmd = client.SubmitData(is,
|
||||
interleaved_buffer, block_size,
|
||||
sample_rate / 1000);
|
||||
kbit_rate);
|
||||
++i;
|
||||
}
|
||||
|
||||
|
@@ -719,6 +719,11 @@ MadDecoder::DecodeFirstFrame(Tag *tag) noexcept
|
||||
{
|
||||
struct xing xing;
|
||||
|
||||
#if GCC_CHECK_VERSION(10,0)
|
||||
/* work around bogus -Wuninitialized in GCC 10 */
|
||||
xing.frames = 0;
|
||||
#endif
|
||||
|
||||
while (true) {
|
||||
MadDecoderAction ret;
|
||||
do {
|
||||
|
@@ -137,6 +137,28 @@ mpc_to_mpd_buffer(MpcdecSampleTraits::pointer_type dest,
|
||||
*dest++ = mpc_to_mpd_sample(*src++);
|
||||
}
|
||||
|
||||
static constexpr ReplayGainTuple
|
||||
ImportMpcdecReplayGain(mpc_uint16_t gain, mpc_uint16_t peak) noexcept
|
||||
{
|
||||
auto t = ReplayGainTuple::Undefined();
|
||||
|
||||
if (gain != 0 && peak != 0) {
|
||||
t.gain = MPC_OLD_GAIN_REF - (gain / 256.);
|
||||
t.peak = pow(10, peak / 256. / 20) / 32767;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static constexpr ReplayGainInfo
|
||||
ImportMpcdecReplayGain(const mpc_streaminfo &info) noexcept
|
||||
{
|
||||
auto rgi = ReplayGainInfo::Undefined();
|
||||
rgi.album = ImportMpcdecReplayGain(info.gain_album, info.peak_album);
|
||||
rgi.track = ImportMpcdecReplayGain(info.gain_title, info.peak_title);
|
||||
return rgi;
|
||||
}
|
||||
|
||||
static void
|
||||
mpcdec_decode(DecoderClient &client, InputStream &is)
|
||||
{
|
||||
@@ -167,14 +189,11 @@ mpcdec_decode(DecoderClient &client, InputStream &is)
|
||||
mpcdec_sample_format,
|
||||
info.channels);
|
||||
|
||||
ReplayGainInfo rgi;
|
||||
rgi.Clear();
|
||||
rgi.album.gain = MPC_OLD_GAIN_REF - (info.gain_album / 256.);
|
||||
rgi.album.peak = pow(10, info.peak_album / 256. / 20) / 32767;
|
||||
rgi.track.gain = MPC_OLD_GAIN_REF - (info.gain_title / 256.);
|
||||
rgi.track.peak = pow(10, info.peak_title / 256. / 20) / 32767;
|
||||
|
||||
client.SubmitReplayGain(&rgi);
|
||||
{
|
||||
const auto rgi = ImportMpcdecReplayGain(info);
|
||||
if (rgi.IsDefined())
|
||||
client.SubmitReplayGain(&rgi);
|
||||
}
|
||||
|
||||
client.Ready(audio_format, is.IsSeekable(),
|
||||
SongTime::FromS(mpc_streaminfo_get_length(&info)));
|
||||
|
@@ -137,7 +137,8 @@ static constexpr int
|
||||
ExportTimeoutMS(std::chrono::steady_clock::duration timeout)
|
||||
{
|
||||
return timeout >= timeout.zero()
|
||||
? int(std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count())
|
||||
/* round up (+1) to avoid unnecessary wakeups */
|
||||
? int(std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count()) + 1
|
||||
: -1;
|
||||
}
|
||||
|
||||
@@ -220,7 +221,6 @@ EventLoop::Run() noexcept
|
||||
} while (!quit);
|
||||
|
||||
#ifndef NDEBUG
|
||||
assert(busy);
|
||||
assert(thread.IsInside());
|
||||
#endif
|
||||
}
|
||||
|
@@ -22,6 +22,10 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef USE_EPOLL
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <poll.h>
|
||||
#endif
|
||||
@@ -37,17 +41,42 @@ MultiSocketMonitor::Reset() noexcept
|
||||
assert(GetEventLoop().IsInside());
|
||||
|
||||
fds.clear();
|
||||
#ifdef USE_EPOLL
|
||||
always_ready_fds.clear();
|
||||
#endif
|
||||
IdleMonitor::Cancel();
|
||||
timeout_event.Cancel();
|
||||
ready = refresh = false;
|
||||
}
|
||||
|
||||
bool
|
||||
MultiSocketMonitor::AddSocket(SocketDescriptor fd, unsigned events) noexcept
|
||||
{
|
||||
fds.emplace_front(*this, fd);
|
||||
bool success = fds.front().Schedule(events);
|
||||
if (!success) {
|
||||
fds.pop_front();
|
||||
|
||||
#ifdef USE_EPOLL
|
||||
if (errno == EPERM)
|
||||
/* not supported by epoll (e.g. "/dev/null"):
|
||||
add it to the "always ready" list */
|
||||
always_ready_fds.push_front({fd, events});
|
||||
#endif
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void
|
||||
MultiSocketMonitor::ClearSocketList() noexcept
|
||||
{
|
||||
assert(GetEventLoop().IsInside());
|
||||
|
||||
fds.clear();
|
||||
#ifdef USE_EPOLL
|
||||
always_ready_fds.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
@@ -55,6 +84,10 @@ MultiSocketMonitor::ClearSocketList() noexcept
|
||||
void
|
||||
MultiSocketMonitor::ReplaceSocketList(pollfd *pfds, unsigned n) noexcept
|
||||
{
|
||||
#ifdef USE_EPOLL
|
||||
always_ready_fds.clear();
|
||||
#endif
|
||||
|
||||
pollfd *const end = pfds + n;
|
||||
|
||||
UpdateSocketList([pfds, end](SocketDescriptor fd) -> unsigned {
|
||||
@@ -64,9 +97,7 @@ MultiSocketMonitor::ReplaceSocketList(pollfd *pfds, unsigned n) noexcept
|
||||
if (i == end)
|
||||
return 0;
|
||||
|
||||
auto events = i->events;
|
||||
i->events = 0;
|
||||
return events;
|
||||
return std::exchange(i->events, 0);
|
||||
});
|
||||
|
||||
for (auto i = pfds; i != end; ++i)
|
||||
@@ -79,7 +110,20 @@ MultiSocketMonitor::ReplaceSocketList(pollfd *pfds, unsigned n) noexcept
|
||||
void
|
||||
MultiSocketMonitor::Prepare() noexcept
|
||||
{
|
||||
const auto timeout = PrepareSockets();
|
||||
auto timeout = PrepareSockets();
|
||||
|
||||
#ifdef USE_EPOLL
|
||||
if (!always_ready_fds.empty()) {
|
||||
/* if there was at least one file descriptor not
|
||||
supported by epoll, install a very short timeout
|
||||
because we assume it's always ready */
|
||||
constexpr std::chrono::steady_clock::duration ready_timeout =
|
||||
std::chrono::milliseconds(1);
|
||||
if (timeout < timeout.zero() || timeout > ready_timeout)
|
||||
timeout = ready_timeout;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (timeout >= timeout.zero())
|
||||
timeout_event.Schedule(timeout);
|
||||
else
|
||||
|
@@ -50,12 +50,10 @@ class MultiSocketMonitor : IdleMonitor
|
||||
unsigned revents;
|
||||
|
||||
public:
|
||||
SingleFD(MultiSocketMonitor &_multi, SocketDescriptor _fd,
|
||||
unsigned events) noexcept
|
||||
SingleFD(MultiSocketMonitor &_multi,
|
||||
SocketDescriptor _fd) noexcept
|
||||
:SocketMonitor(_fd, _multi.GetEventLoop()),
|
||||
multi(_multi), revents(0) {
|
||||
Schedule(events);
|
||||
}
|
||||
multi(_multi), revents(0) {}
|
||||
|
||||
SocketDescriptor GetSocket() const noexcept {
|
||||
return SocketMonitor::GetSocket();
|
||||
@@ -86,8 +84,6 @@ class MultiSocketMonitor : IdleMonitor
|
||||
}
|
||||
};
|
||||
|
||||
friend class SingleFD;
|
||||
|
||||
TimerEvent timeout_event;
|
||||
|
||||
/**
|
||||
@@ -106,6 +102,21 @@ class MultiSocketMonitor : IdleMonitor
|
||||
|
||||
std::forward_list<SingleFD> fds;
|
||||
|
||||
#ifdef USE_EPOLL
|
||||
struct AlwaysReady {
|
||||
const SocketDescriptor fd;
|
||||
const unsigned revents;
|
||||
};
|
||||
|
||||
/**
|
||||
* A list of file descriptors which are always ready. This is
|
||||
* a kludge needed because the ALSA output plugin gives us a
|
||||
* file descriptor to /dev/null, which is incompatible with
|
||||
* epoll (epoll_ctl() returns -EPERM).
|
||||
*/
|
||||
std::forward_list<AlwaysReady> always_ready_fds;
|
||||
#endif
|
||||
|
||||
public:
|
||||
static constexpr unsigned READ = SocketMonitor::READ;
|
||||
static constexpr unsigned WRITE = SocketMonitor::WRITE;
|
||||
@@ -147,9 +158,7 @@ public:
|
||||
*
|
||||
* May only be called from PrepareSockets().
|
||||
*/
|
||||
void AddSocket(SocketDescriptor fd, unsigned events) noexcept {
|
||||
fds.emplace_front(*this, fd, events);
|
||||
}
|
||||
bool AddSocket(SocketDescriptor fd, unsigned events) noexcept;
|
||||
|
||||
/**
|
||||
* Remove all sockets.
|
||||
@@ -204,6 +213,11 @@ public:
|
||||
i.ClearReturnedEvents();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_EPOLL
|
||||
for (const auto &i : always_ready_fds)
|
||||
f(i.fd, i.revents);
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -232,7 +246,6 @@ private:
|
||||
|
||||
void OnTimeout() noexcept {
|
||||
SetReady();
|
||||
IdleMonitor::Schedule();
|
||||
}
|
||||
|
||||
virtual void OnIdle() noexcept final;
|
||||
|
@@ -68,20 +68,24 @@ SocketMonitor::Close() noexcept
|
||||
Steal().Close();
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
SocketMonitor::Schedule(unsigned flags) noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
if (flags == GetScheduledFlags())
|
||||
return;
|
||||
return true;
|
||||
|
||||
bool success;
|
||||
if (scheduled_flags == 0)
|
||||
loop.AddFD(fd.Get(), flags, *this);
|
||||
success = loop.AddFD(fd.Get(), flags, *this);
|
||||
else if (flags == 0)
|
||||
loop.RemoveFD(fd.Get(), *this);
|
||||
success = loop.RemoveFD(fd.Get(), *this);
|
||||
else
|
||||
loop.ModifyFD(fd.Get(), flags, *this);
|
||||
success = loop.ModifyFD(fd.Get(), flags, *this);
|
||||
|
||||
scheduled_flags = flags;
|
||||
if (success)
|
||||
scheduled_flags = flags;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
@@ -98,18 +98,22 @@ public:
|
||||
return scheduled_flags;
|
||||
}
|
||||
|
||||
void Schedule(unsigned flags) noexcept;
|
||||
/**
|
||||
* @return true on success, false on error (with errno set if
|
||||
* USE_EPOLL is defined)
|
||||
*/
|
||||
bool Schedule(unsigned flags) noexcept;
|
||||
|
||||
void Cancel() noexcept {
|
||||
Schedule(0);
|
||||
}
|
||||
|
||||
void ScheduleRead() noexcept {
|
||||
Schedule(GetScheduledFlags() | READ | HANGUP | ERROR);
|
||||
bool ScheduleRead() noexcept {
|
||||
return Schedule(GetScheduledFlags() | READ | HANGUP | ERROR);
|
||||
}
|
||||
|
||||
void ScheduleWrite() noexcept {
|
||||
Schedule(GetScheduledFlags() | WRITE);
|
||||
bool ScheduleWrite() noexcept {
|
||||
return Schedule(GetScheduledFlags() | WRITE);
|
||||
}
|
||||
|
||||
void CancelRead() noexcept {
|
||||
|
@@ -35,6 +35,9 @@ input_glue = static_library(
|
||||
'BufferedInputStream.cxx',
|
||||
'MaybeBufferedInputStream.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
boost_dep,
|
||||
],
|
||||
)
|
||||
|
||||
input_glue_dep = declare_dependency(
|
||||
|
@@ -180,7 +180,6 @@ CurlInputStream::FreeEasyIndirect() noexcept
|
||||
{
|
||||
BlockingCall(GetEventLoop(), [this](){
|
||||
FreeEasy();
|
||||
(*curl_init)->InvalidateSockets();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -30,6 +30,8 @@
|
||||
#ifndef CURL_EASY_HXX
|
||||
#define CURL_EASY_HXX
|
||||
|
||||
#include "String.hxx"
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <utility>
|
||||
@@ -88,8 +90,8 @@ public:
|
||||
throw std::runtime_error(curl_easy_strerror(code));
|
||||
}
|
||||
|
||||
char *Escape(const char *string, int length=0) const noexcept {
|
||||
return curl_easy_escape(handle, string, length);
|
||||
CurlString Escape(const char *string, int length=0) const noexcept {
|
||||
return CurlString(curl_easy_escape(handle, string, length));
|
||||
}
|
||||
};
|
||||
|
||||
|
71
src/lib/curl/Escape.cxx
Normal file
71
src/lib/curl/Escape.cxx
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "Escape.hxx"
|
||||
#include "Easy.hxx"
|
||||
#include "String.hxx"
|
||||
#include "util/IterableSplitString.hxx"
|
||||
|
||||
std::string
|
||||
CurlEscapeUriPath(CURL *curl, StringView src) noexcept
|
||||
{
|
||||
std::string dest;
|
||||
|
||||
for (const auto i : IterableSplitString(src, '/')) {
|
||||
CurlString escaped(curl_easy_escape(curl, i.data, i.size));
|
||||
if (!dest.empty())
|
||||
dest.push_back('/');
|
||||
dest += escaped.c_str();
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
std::string
|
||||
CurlEscapeUriPath(StringView src) noexcept
|
||||
{
|
||||
CurlEasy easy;
|
||||
return CurlEscapeUriPath(easy.Get(), src);
|
||||
}
|
||||
|
||||
std::string
|
||||
CurlUnescape(CURL *curl, StringView src) noexcept
|
||||
{
|
||||
int outlength;
|
||||
CurlString tmp(curl_easy_unescape(curl, src.data, src.size,
|
||||
&outlength));
|
||||
return std::string(tmp.c_str(), outlength);
|
||||
}
|
||||
|
||||
std::string
|
||||
CurlUnescape(StringView src) noexcept
|
||||
{
|
||||
CurlEasy easy;
|
||||
return CurlUnescape(easy.Get(), src);
|
||||
}
|
@@ -1,8 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2017 Content Management AG
|
||||
* All rights reserved.
|
||||
*
|
||||
* author: Max Kellermann <mk@cm4all.com>
|
||||
* Copyright (C) 2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -30,32 +27,25 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "TimeISO8601.hxx"
|
||||
#include "TimeConvert.hxx"
|
||||
#include "TimeParser.hxx"
|
||||
#ifndef CURL_ESCAPE_HXX
|
||||
#define CURL_ESCAPE_HXX
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
struct StringView;
|
||||
|
||||
std::string
|
||||
CurlEscapeUriPath(CURL *curl, StringView src) noexcept;
|
||||
|
||||
std::string
|
||||
CurlEscapeUriPath(StringView src) noexcept;
|
||||
|
||||
std::string
|
||||
CurlUnescape(CURL *curl, StringView src) noexcept;
|
||||
|
||||
std::string
|
||||
CurlUnescape(StringView src) noexcept;
|
||||
|
||||
StringBuffer<64>
|
||||
FormatISO8601(const struct tm &tm) noexcept
|
||||
{
|
||||
StringBuffer<64> buffer;
|
||||
strftime(buffer.data(), buffer.capacity(),
|
||||
#ifdef _WIN32
|
||||
"%Y-%m-%dT%H:%M:%SZ",
|
||||
#else
|
||||
"%FT%TZ",
|
||||
#endif
|
||||
&tm);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
StringBuffer<64>
|
||||
FormatISO8601(std::chrono::system_clock::time_point tp)
|
||||
{
|
||||
return FormatISO8601(GmTime(tp));
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point
|
||||
ParseISO8601(const char *s)
|
||||
{
|
||||
return ParseTimePoint(s, "%FT%TZ");
|
||||
}
|
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#include "Form.hxx"
|
||||
#include "String.hxx"
|
||||
|
||||
std::string
|
||||
EncodeForm(CURL *curl,
|
||||
@@ -43,12 +44,10 @@ EncodeForm(CURL *curl,
|
||||
result.push_back('=');
|
||||
|
||||
if (!i.second.empty()) {
|
||||
char *value = curl_easy_escape(curl, i.second.data(),
|
||||
i.second.length());
|
||||
if (value != nullptr) {
|
||||
CurlString value(curl_easy_escape(curl, i.second.data(),
|
||||
i.second.length()));
|
||||
if (value)
|
||||
result.append(value);
|
||||
curl_free(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2016 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2008-2016 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -181,8 +181,6 @@ CurlGlobal::Remove(CURL *easy) noexcept
|
||||
assert(easy != nullptr);
|
||||
|
||||
curl_multi_remove_handle(multi.Get(), easy);
|
||||
|
||||
InvalidateSockets();
|
||||
}
|
||||
|
||||
static CurlRequest *
|
||||
@@ -227,12 +225,12 @@ CurlGlobal::UpdateTimeout(long timeout_ms) noexcept
|
||||
return;
|
||||
}
|
||||
|
||||
if (timeout_ms < 10)
|
||||
/* CURL 7.21.1 likes to report "timeout=0", which
|
||||
if (timeout_ms < 1)
|
||||
/* CURL's threaded resolver sets a timeout of 0ms, which
|
||||
means we're running in a busy loop. Quite a bad
|
||||
idea to waste so much CPU. Let's use a lower limit
|
||||
of 10ms. */
|
||||
timeout_ms = 10;
|
||||
of 1ms. */
|
||||
timeout_ms = 1;
|
||||
|
||||
timeout_event.Schedule(std::chrono::milliseconds(timeout_ms));
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2016 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2008-2016 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -74,16 +74,6 @@ public:
|
||||
SocketAction(CURL_SOCKET_TIMEOUT, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a kludge to allow pausing/resuming a stream with
|
||||
* libcurl < 7.32.0. Read the curl_easy_pause manpage for
|
||||
* more information.
|
||||
*/
|
||||
void ResumeSockets() {
|
||||
int running_handles;
|
||||
curl_multi_socket_all(multi.Get(), &running_handles);
|
||||
}
|
||||
|
||||
private:
|
||||
void UpdateTimeout(long timeout_ms) noexcept;
|
||||
static int TimerFunction(CURLM *global, long timeout_ms,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2008-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2008-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2016-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2008-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "config.h"
|
||||
#include "Request.hxx"
|
||||
#include "Global.hxx"
|
||||
#include "Version.hxx"
|
||||
#include "Handler.hxx"
|
||||
#include "event/Call.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
@@ -124,12 +123,6 @@ CurlRequest::Resume() noexcept
|
||||
|
||||
curl_easy_pause(easy.Get(), CURLPAUSE_CONT);
|
||||
|
||||
if (IsCurlOlderThan(0x072000))
|
||||
/* libcurl older than 7.32.0 does not update
|
||||
its sockets after curl_easy_pause(); force
|
||||
libcurl to do it now */
|
||||
global.ResumeSockets();
|
||||
|
||||
global.InvalidateSockets();
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2008-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2008-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
/**
|
||||
* OO wrapper for "struct curl_slist *".
|
||||
|
77
src/lib/curl/String.hxx
Normal file
77
src/lib/curl/String.hxx
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2019 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CURL_STRING_HXX
|
||||
#define CURL_STRING_HXX
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
/**
|
||||
* An OO wrapper for an allocated string to be freed with curl_free().
|
||||
*/
|
||||
class CurlString {
|
||||
char *p = nullptr;
|
||||
|
||||
public:
|
||||
CurlString() noexcept = default;
|
||||
CurlString(std::nullptr_t) noexcept {}
|
||||
|
||||
explicit CurlString(char *_p) noexcept
|
||||
:p(_p) {}
|
||||
|
||||
CurlString(CurlString &&src) noexcept
|
||||
:p(std::exchange(src.p, nullptr)) {}
|
||||
|
||||
~CurlString() noexcept {
|
||||
if (p != nullptr)
|
||||
curl_free(p);
|
||||
}
|
||||
|
||||
CurlString &operator=(CurlString &&src) noexcept {
|
||||
using std::swap;
|
||||
swap(p, src.p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator bool() const noexcept {
|
||||
return p != nullptr;
|
||||
}
|
||||
|
||||
operator const char *() const noexcept {
|
||||
return p;
|
||||
}
|
||||
|
||||
const char *c_str() const noexcept {
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2017-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2017-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@@ -1,4 +1,4 @@
|
||||
curl_dep = dependency('libcurl', version: '>= 7.18', required: get_option('curl'))
|
||||
curl_dep = dependency('libcurl', version: '>= 7.32', required: get_option('curl'))
|
||||
conf.set('ENABLE_CURL', curl_dep.found())
|
||||
if not curl_dep.found()
|
||||
subdir_done()
|
||||
@@ -11,6 +11,7 @@ curl = static_library(
|
||||
'Init.cxx',
|
||||
'Global.cxx',
|
||||
'Request.cxx',
|
||||
'Escape.cxx',
|
||||
'Form.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
|
@@ -35,6 +35,8 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
template<typename T> struct ConstBuffer;
|
||||
|
||||
gcc_pure
|
||||
|
@@ -20,7 +20,7 @@ if icu_dep.found()
|
||||
elif not get_option('iconv').disabled()
|
||||
have_iconv = compiler.has_function('iconv')
|
||||
conf.set('HAVE_ICONV', have_iconv)
|
||||
if get_option('iconv').enabled()
|
||||
if not have_iconv and get_option('iconv').enabled()
|
||||
error('iconv() not available')
|
||||
endif
|
||||
endif
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include "util/ASCII.hxx"
|
||||
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
@@ -1,4 +1,9 @@
|
||||
sqlite_dep = dependency('sqlite3', version: '>= 3.7.3', required: get_option('sqlite'))
|
||||
if enable_database
|
||||
sqlite_dep = dependency('sqlite3', version: '>= 3.7.3', required: get_option('sqlite'))
|
||||
else
|
||||
sqlite_dep = dependency('', required: false)
|
||||
endif
|
||||
|
||||
conf.set('ENABLE_SQLITE', sqlite_dep.found())
|
||||
if not sqlite_dep.found()
|
||||
subdir_done()
|
||||
|
@@ -49,6 +49,9 @@ xiph = static_library(
|
||||
'VorbisComments.cxx',
|
||||
'XiphTags.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
libvorbis_dep,
|
||||
],
|
||||
)
|
||||
|
||||
xiph_dep = declare_dependency(
|
||||
|
@@ -1,4 +1,4 @@
|
||||
if not get_option('neighbor')
|
||||
if not get_option('neighbor') or not enable_database
|
||||
conf.set('ENABLE_NEIGHBOR_PLUGINS', false)
|
||||
neighbor_glue_dep = dependency('', required: false)
|
||||
subdir_done()
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#define STATIC_SOCKET_ADDRESS_HXX
|
||||
|
||||
#include "SocketAddress.hxx"
|
||||
#include "Features.hxx"
|
||||
#include "util/Compiler.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
@@ -403,10 +403,11 @@ JackOutput::Connect()
|
||||
jack_on_shutdown(client, mpd_jack_shutdown, this);
|
||||
|
||||
for (unsigned i = 0; i < num_source_ports; ++i) {
|
||||
unsigned long portflags = JackPortIsOutput | JackPortIsTerminal;
|
||||
ports[i] = jack_port_register(client,
|
||||
source_ports[i].c_str(),
|
||||
JACK_DEFAULT_AUDIO_TYPE,
|
||||
JackPortIsOutput, 0);
|
||||
portflags, 0);
|
||||
if (ports[i] == nullptr) {
|
||||
Disconnect();
|
||||
throw FormatRuntimeError("Cannot register output port \"%s\"",
|
||||
|
@@ -383,6 +383,7 @@ ShoutOutput::SendTag(const Tag &tag)
|
||||
shout_tag_to_metadata(tag, song, sizeof(song));
|
||||
|
||||
shout_metadata_add(meta, "song", song);
|
||||
shout_metadata_add(meta, "charset", "UTF-8");
|
||||
if (SHOUTERR_SUCCESS != shout_set_metadata(shout_conn, meta)) {
|
||||
LogWarning(shout_output_domain,
|
||||
"error setting shout metadata");
|
||||
|
@@ -22,7 +22,6 @@
|
||||
#include "system/FileDescriptor.hxx"
|
||||
#include "system/Error.hxx"
|
||||
|
||||
#include <sys/stropts.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
@@ -31,11 +30,18 @@
|
||||
|
||||
#ifdef __sun
|
||||
#include <sys/audio.h>
|
||||
#include <sys/stropts.h>
|
||||
#else
|
||||
|
||||
/* some fake declarations that allow build this plugin on systems
|
||||
other than Solaris, just to see if it compiles */
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#ifndef I_FLUSH
|
||||
#define I_FLUSH 0
|
||||
#endif
|
||||
|
||||
#define AUDIO_GETINFO 0
|
||||
#define AUDIO_SETINFO 0
|
||||
#define AUDIO_ENCODING_LINEAR 0
|
||||
|
@@ -21,6 +21,8 @@
|
||||
#include "ConfiguredResampler.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
void
|
||||
|
@@ -46,6 +46,7 @@
|
||||
#include "CrossFade.hxx"
|
||||
#include "tag/Tag.hxx"
|
||||
#include "Idle.hxx"
|
||||
#include "util/Compiler.h"
|
||||
#include "util/Domain.hxx"
|
||||
#include "thread/Name.hxx"
|
||||
#include "Log.hxx"
|
||||
@@ -1171,6 +1172,7 @@ try {
|
||||
}
|
||||
|
||||
/* fall through */
|
||||
gcc_fallthrough;
|
||||
|
||||
case PlayerCommand::PAUSE:
|
||||
next_song.reset();
|
||||
|
@@ -353,7 +353,7 @@ playlist::MoveRange(PlayerControl &pc, unsigned start, unsigned end, int to)
|
||||
return;
|
||||
to = (currentSong + abs(to)) % GetLength();
|
||||
if (start < (unsigned)to)
|
||||
to--;
|
||||
to -= end - start;
|
||||
}
|
||||
|
||||
queue.MoveRange(start, end, to);
|
||||
|
@@ -29,8 +29,9 @@
|
||||
#include "AudioParser.hxx"
|
||||
#include "tag/ParseName.hxx"
|
||||
#include "tag/Tag.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "time/ISO8601.hxx"
|
||||
#include "util/CharUtil.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/StringAPI.hxx"
|
||||
@@ -38,7 +39,6 @@
|
||||
#include "util/StringStrip.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "util/ASCII.hxx"
|
||||
#include "util/TimeISO8601.hxx"
|
||||
#include "util/UriUtil.hxx"
|
||||
#include "lib/icu/CaseFold.hxx"
|
||||
|
||||
@@ -113,14 +113,19 @@ ParseTimeStamp(const char *s)
|
||||
{
|
||||
assert(s != nullptr);
|
||||
|
||||
char *endptr;
|
||||
unsigned long long value = strtoull(s, &endptr, 10);
|
||||
if (*endptr == 0 && endptr > s)
|
||||
/* it's an integral UNIX time stamp */
|
||||
return std::chrono::system_clock::from_time_t((time_t)value);
|
||||
try {
|
||||
/* try ISO 8601 */
|
||||
return ParseISO8601(s).first;
|
||||
} catch (...) {
|
||||
char *endptr;
|
||||
unsigned long long value = strtoull(s, &endptr, 10);
|
||||
if (*endptr == 0 && endptr > s)
|
||||
/* it's an integral UNIX time stamp */
|
||||
return std::chrono::system_clock::from_time_t((time_t)value);
|
||||
|
||||
/* try ISO 8601 */
|
||||
return ParseISO8601(s);
|
||||
/* rethrow the ParseISO8601() error */
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr bool
|
||||
|
@@ -19,7 +19,8 @@
|
||||
|
||||
#include "ModifiedSinceSongFilter.hxx"
|
||||
#include "LightSong.hxx"
|
||||
#include "util/TimeISO8601.hxx"
|
||||
#include "time/ISO8601.hxx"
|
||||
#include "util/StringBuffer.hxx"
|
||||
|
||||
std::string
|
||||
ModifiedSinceSongFilter::ToExpression() const noexcept
|
||||
|
@@ -24,6 +24,7 @@ song_dep = declare_dependency(
|
||||
icu_dep,
|
||||
pcre_dep,
|
||||
tag_dep,
|
||||
time_dep,
|
||||
util_dep,
|
||||
],
|
||||
)
|
||||
|
@@ -25,21 +25,23 @@
|
||||
#include "lib/curl/Init.hxx"
|
||||
#include "lib/curl/Global.hxx"
|
||||
#include "lib/curl/Slist.hxx"
|
||||
#include "lib/curl/String.hxx"
|
||||
#include "lib/curl/Request.hxx"
|
||||
#include "lib/curl/Handler.hxx"
|
||||
#include "lib/curl/Escape.hxx"
|
||||
#include "lib/expat/ExpatParser.hxx"
|
||||
#include "fs/Traits.hxx"
|
||||
#include "event/Call.hxx"
|
||||
#include "event/DeferEvent.hxx"
|
||||
#include "thread/Mutex.hxx"
|
||||
#include "thread/Cond.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "time/Parser.hxx"
|
||||
#include "util/ASCII.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "util/IterableSplitString.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/StringCompare.hxx"
|
||||
#include "util/StringFormat.hxx"
|
||||
#include "util/TimeParser.hxx"
|
||||
#include "util/UriUtil.hxx"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -77,26 +79,15 @@ CurlStorage::MapUTF8(const char *uri_utf8) const noexcept
|
||||
if (StringIsEmpty(uri_utf8))
|
||||
return base;
|
||||
|
||||
CurlEasy easy;
|
||||
std::string path_esc;
|
||||
|
||||
for (auto elt: IterableSplitString(uri_utf8, '/')) {
|
||||
char *elt_esc = easy.Escape(elt.data, elt.size);
|
||||
if (!path_esc.empty())
|
||||
path_esc.push_back('/');
|
||||
path_esc += elt_esc;
|
||||
curl_free(elt_esc);
|
||||
}
|
||||
|
||||
std::string path_esc = CurlEscapeUriPath(uri_utf8);
|
||||
return PathTraitsUTF8::Build(base.c_str(), path_esc.c_str());
|
||||
}
|
||||
|
||||
const char *
|
||||
CurlStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept
|
||||
{
|
||||
// TODO: escape/unescape?
|
||||
|
||||
return PathTraitsUTF8::Relative(base.c_str(), uri_utf8);
|
||||
return PathTraitsUTF8::Relative(base.c_str(),
|
||||
CurlUnescape(uri_utf8).c_str());
|
||||
}
|
||||
|
||||
class BlockingHttpRequest : protected CurlResponseHandler {
|
||||
@@ -118,7 +109,9 @@ public:
|
||||
BIND_THIS_METHOD(OnDeferredStart)),
|
||||
request(curl, uri, *this) {
|
||||
// TODO: use CurlInputStream's configuration
|
||||
}
|
||||
|
||||
void DeferStart() noexcept {
|
||||
/* start the transfer inside the IOThread */
|
||||
defer_start.Schedule();
|
||||
}
|
||||
@@ -132,6 +125,10 @@ public:
|
||||
std::rethrow_exception(postponed_error);
|
||||
}
|
||||
|
||||
CURL *GetEasy() noexcept {
|
||||
return request.Get();
|
||||
}
|
||||
|
||||
protected:
|
||||
void SetDone() {
|
||||
assert(!done);
|
||||
@@ -269,6 +266,8 @@ public:
|
||||
CommonExpatParser(ExpatNamespaceSeparator{'|'})
|
||||
{
|
||||
request.SetOption(CURLOPT_CUSTOMREQUEST, "PROPFIND");
|
||||
request.SetOption(CURLOPT_FOLLOWLOCATION, 1l);
|
||||
request.SetOption(CURLOPT_MAXREDIRS, 1l);
|
||||
|
||||
request_headers.Append(StringFormat<40>("depth: %u", depth));
|
||||
|
||||
@@ -277,6 +276,7 @@ public:
|
||||
request.SetOption(CURLOPT_POSTFIELDS,
|
||||
"<?xml version=\"1.0\"?>\n"
|
||||
"<a:propfind xmlns:a=\"DAV:\">"
|
||||
"<a:prop><a:resourcetype/></a:prop>"
|
||||
"<a:prop><a:getcontenttype/></a:prop>"
|
||||
"<a:prop><a:getcontentlength/></a:prop>"
|
||||
"</a:propfind>");
|
||||
@@ -284,6 +284,8 @@ public:
|
||||
// TODO: send request body
|
||||
}
|
||||
|
||||
using BlockingHttpRequest::GetEasy;
|
||||
using BlockingHttpRequest::DeferStart;
|
||||
using BlockingHttpRequest::Wait;
|
||||
|
||||
protected:
|
||||
@@ -431,6 +433,7 @@ public:
|
||||
}
|
||||
|
||||
const StorageFileInfo &Perform() {
|
||||
DeferStart();
|
||||
Wait();
|
||||
return info;
|
||||
}
|
||||
@@ -454,9 +457,7 @@ CurlStorage::GetInfo(const char *uri_utf8, gcc_unused bool follow)
|
||||
{
|
||||
// TODO: escape the given URI
|
||||
|
||||
std::string uri = base;
|
||||
uri += uri_utf8;
|
||||
|
||||
const auto uri = MapUTF8(uri_utf8);
|
||||
return HttpGetInfoOperation(*curl, uri.c_str()).Perform();
|
||||
}
|
||||
|
||||
@@ -484,6 +485,7 @@ public:
|
||||
base_path(UriPathOrSlash(uri)) {}
|
||||
|
||||
std::unique_ptr<StorageDirectoryReader> Perform() {
|
||||
DeferStart();
|
||||
Wait();
|
||||
return ToReader();
|
||||
}
|
||||
@@ -503,7 +505,11 @@ private:
|
||||
if (path == nullptr)
|
||||
return nullptr;
|
||||
|
||||
path = StringAfterPrefix(path, base_path.c_str());
|
||||
/* kludge: ignoring case in this comparison to avoid
|
||||
false negatives if the web server uses a different
|
||||
case in hex digits in escaped characters; TODO:
|
||||
implement properly */
|
||||
path = StringAfterPrefixIgnoreCase(path, base_path.c_str());
|
||||
if (path == nullptr || *path == 0)
|
||||
return nullptr;
|
||||
|
||||
@@ -529,10 +535,7 @@ protected:
|
||||
if (escaped_name.IsNull())
|
||||
return;
|
||||
|
||||
// TODO: unescape
|
||||
const auto name = escaped_name;
|
||||
|
||||
entries.emplace_front(std::string(name.data, name.size));
|
||||
entries.emplace_front(CurlUnescape(GetEasy(), escaped_name));
|
||||
|
||||
auto &info = entries.front().info;
|
||||
info = StorageFileInfo(r.collection
|
||||
@@ -546,10 +549,7 @@ protected:
|
||||
std::unique_ptr<StorageDirectoryReader>
|
||||
CurlStorage::OpenDirectory(const char *uri_utf8)
|
||||
{
|
||||
// TODO: escape the given URI
|
||||
|
||||
std::string uri = base;
|
||||
uri += uri_utf8;
|
||||
std::string uri = MapUTF8(uri_utf8);
|
||||
|
||||
/* collection URIs must end with a slash */
|
||||
if (uri.back() != '/')
|
||||
|
@@ -57,5 +57,6 @@ storage_plugins_dep = declare_dependency(
|
||||
dependencies: [
|
||||
storage_api_dep,
|
||||
fs_dep,
|
||||
time_dep,
|
||||
],
|
||||
)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2013-2019 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2015 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2013-2015 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -147,6 +147,26 @@ FormatErrno(const char *fmt, Args&&... args) noexcept
|
||||
return FormatErrno(errno, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static inline std::system_error
|
||||
FormatFileNotFound(const char *fmt, Args&&... args) noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return FormatLastError(ERROR_FILE_NOT_FOUND, fmt,
|
||||
std::forward<Args>(args)...);
|
||||
#else
|
||||
return FormatErrno(ENOENT, fmt, std::forward<Args>(args)...);
|
||||
#endif
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
inline bool
|
||||
IsErrno(const std::system_error &e, int code) noexcept
|
||||
{
|
||||
return e.code().category() == ErrnoCategory() &&
|
||||
e.code().value() == code;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
static inline bool
|
||||
IsFileNotFound(const std::system_error &e) noexcept
|
||||
@@ -155,8 +175,7 @@ IsFileNotFound(const std::system_error &e) noexcept
|
||||
return e.code().category() == std::system_category() &&
|
||||
e.code().value() == ERROR_FILE_NOT_FOUND;
|
||||
#else
|
||||
return e.code().category() == ErrnoCategory() &&
|
||||
e.code().value() == ENOENT;
|
||||
return IsErrno(e, ENOENT);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -168,8 +187,7 @@ IsPathNotFound(const std::system_error &e) noexcept
|
||||
return e.code().category() == std::system_category() &&
|
||||
e.code().value() == ERROR_PATH_NOT_FOUND;
|
||||
#else
|
||||
return e.code().category() == ErrnoCategory() &&
|
||||
e.code().value() == ENOTDIR;
|
||||
return IsErrno(e, ENOTDIR);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -181,8 +199,7 @@ IsAccessDenied(const std::system_error &e) noexcept
|
||||
return e.code().category() == std::system_category() &&
|
||||
e.code().value() == ERROR_ACCESS_DENIED;
|
||||
#else
|
||||
return e.code().category() == ErrnoCategory() &&
|
||||
e.code().value() == EACCES;
|
||||
return IsErrno(e, EACCES);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -20,9 +20,9 @@
|
||||
#include "Format.hxx"
|
||||
#include "Tag.hxx"
|
||||
#include "ParseName.hxx"
|
||||
#include "time/Convert.hxx"
|
||||
#include "util/format.h"
|
||||
#include "util/TruncateString.hxx"
|
||||
#include "util/TimeConvert.hxx"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
@@ -48,6 +48,7 @@ tag = static_library(
|
||||
tag_dep = declare_dependency(
|
||||
link_with: tag,
|
||||
dependencies: [
|
||||
time_dep,
|
||||
util_dep,
|
||||
],
|
||||
)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2017 Content Management AG
|
||||
* Copyright 2007-2019 Content Management AG
|
||||
* All rights reserved.
|
||||
*
|
||||
* author: Max Kellermann <mk@cm4all.com>
|
||||
@@ -30,11 +30,12 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "TimeConvert.hxx"
|
||||
#include "Convert.hxx"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h> /* for struct timeval */
|
||||
|
||||
struct tm
|
||||
GmTime(std::chrono::system_clock::time_point tp)
|
||||
@@ -66,18 +67,52 @@ LocalTime(std::chrono::system_clock::time_point tp)
|
||||
return *tm;
|
||||
}
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#ifndef __GLIBC__
|
||||
|
||||
std::chrono::system_clock::time_point
|
||||
TimeGm(struct tm &tm)
|
||||
/**
|
||||
* Determine the time zone offset in a portable way.
|
||||
*/
|
||||
gcc_const
|
||||
static time_t
|
||||
GetTimeZoneOffset() noexcept
|
||||
{
|
||||
return std::chrono::system_clock::from_time_t(timegm(&tm));
|
||||
time_t t = 1234567890;
|
||||
struct tm tm;
|
||||
tm.tm_isdst = 0;
|
||||
#ifdef _WIN32
|
||||
struct tm *p = gmtime(&t);
|
||||
#else
|
||||
struct tm *p = &tm;
|
||||
gmtime_r(&t, p);
|
||||
#endif
|
||||
return t - mktime(&tm);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* !__GLIBC__ */
|
||||
|
||||
std::chrono::system_clock::time_point
|
||||
MakeTime(struct tm &tm)
|
||||
TimeGm(struct tm &tm) noexcept
|
||||
{
|
||||
#ifdef __GLIBC__
|
||||
/* timegm() is a GNU extension */
|
||||
const auto t = timegm(&tm);
|
||||
#else
|
||||
tm.tm_isdst = 0;
|
||||
const auto t = mktime(&tm) + GetTimeZoneOffset();
|
||||
#endif /* !__GLIBC__ */
|
||||
|
||||
return std::chrono::system_clock::from_time_t(t);
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point
|
||||
MakeTime(struct tm &tm) noexcept
|
||||
{
|
||||
return std::chrono::system_clock::from_time_t(mktime(&tm));
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::duration
|
||||
ToSteadyClockDuration(const struct timeval &tv) noexcept
|
||||
{
|
||||
return std::chrono::steady_clock::duration(std::chrono::seconds(tv.tv_sec)) +
|
||||
std::chrono::steady_clock::duration(std::chrono::microseconds(tv.tv_usec));
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2017 Content Management AG
|
||||
* Copyright 2007-2019 Content Management AG
|
||||
* All rights reserved.
|
||||
*
|
||||
* author: Max Kellermann <mk@cm4all.com>
|
||||
@@ -33,34 +33,42 @@
|
||||
#ifndef TIME_CONVERT_HXX
|
||||
#define TIME_CONVERT_HXX
|
||||
|
||||
#include "util/Compiler.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
/**
|
||||
* Convert a UTC-based time point to a UTC-based "struct tm".
|
||||
*
|
||||
* Throws on error.
|
||||
*/
|
||||
struct tm
|
||||
GmTime(std::chrono::system_clock::time_point tp);
|
||||
|
||||
/**
|
||||
* Convert a UTC-based time point to a local "struct tm".
|
||||
*
|
||||
* Throws on error.
|
||||
*/
|
||||
struct tm
|
||||
LocalTime(std::chrono::system_clock::time_point tp);
|
||||
|
||||
#ifdef __GLIBC__
|
||||
|
||||
/**
|
||||
* Convert a UTC-based "struct tm" to a UTC-based time point.
|
||||
*/
|
||||
gcc_pure
|
||||
std::chrono::system_clock::time_point
|
||||
TimeGm(struct tm &tm);
|
||||
|
||||
#endif
|
||||
TimeGm(struct tm &tm) noexcept;
|
||||
|
||||
/**
|
||||
* Convert a local "struct tm" to a UTC-based time point.
|
||||
*/
|
||||
gcc_pure
|
||||
std::chrono::system_clock::time_point
|
||||
MakeTime(struct tm &tm);
|
||||
MakeTime(struct tm &tm) noexcept;
|
||||
|
||||
gcc_pure
|
||||
std::chrono::steady_clock::duration
|
||||
ToSteadyClockDuration(const struct timeval &tv) noexcept;
|
||||
|
||||
#endif
|
222
src/time/ISO8601.cxx
Normal file
222
src/time/ISO8601.cxx
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright 2007-2019 Content Management AG
|
||||
* All rights reserved.
|
||||
*
|
||||
* author: Max Kellermann <mk@cm4all.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "ISO8601.hxx"
|
||||
#include "Convert.hxx"
|
||||
#include "util/StringBuffer.hxx"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
StringBuffer<64>
|
||||
FormatISO8601(const struct tm &tm) noexcept
|
||||
{
|
||||
StringBuffer<64> buffer;
|
||||
strftime(buffer.data(), buffer.capacity(),
|
||||
#ifdef _WIN32
|
||||
"%Y-%m-%dT%H:%M:%SZ",
|
||||
#else
|
||||
"%FT%TZ",
|
||||
#endif
|
||||
&tm);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
StringBuffer<64>
|
||||
FormatISO8601(std::chrono::system_clock::time_point tp)
|
||||
{
|
||||
return FormatISO8601(GmTime(tp));
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
static std::pair<unsigned, unsigned>
|
||||
ParseTimeZoneOffsetRaw(const char *&s)
|
||||
{
|
||||
char *endptr;
|
||||
unsigned long value = strtoul(s, &endptr, 10);
|
||||
if (endptr == s + 4) {
|
||||
s = endptr;
|
||||
return std::make_pair(value / 100, value % 100);
|
||||
} else if (endptr == s + 2) {
|
||||
s = endptr;
|
||||
|
||||
unsigned hours = value, minutes = 0;
|
||||
if (*s == ':') {
|
||||
++s;
|
||||
minutes = strtoul(s, &endptr, 10);
|
||||
if (endptr != s + 2)
|
||||
throw std::runtime_error("Failed to parse time zone offset");
|
||||
|
||||
s = endptr;
|
||||
}
|
||||
|
||||
return std::make_pair(hours, minutes);
|
||||
} else
|
||||
throw std::runtime_error("Failed to parse time zone offset");
|
||||
}
|
||||
|
||||
static std::chrono::system_clock::duration
|
||||
ParseTimeZoneOffset(const char *&s)
|
||||
{
|
||||
assert(*s == '+' || *s == '-');
|
||||
|
||||
bool negative = *s == '-';
|
||||
++s;
|
||||
|
||||
auto raw = ParseTimeZoneOffsetRaw(s);
|
||||
if (raw.first > 13)
|
||||
throw std::runtime_error("Time offset hours out of range");
|
||||
|
||||
if (raw.second >= 60)
|
||||
throw std::runtime_error("Time offset minutes out of range");
|
||||
|
||||
std::chrono::system_clock::duration d = std::chrono::hours(raw.first);
|
||||
d += std::chrono::minutes(raw.second);
|
||||
|
||||
if (negative)
|
||||
d = -d;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
static const char *
|
||||
ParseTimeOfDay(const char *s, struct tm &tm,
|
||||
std::chrono::system_clock::duration &precision) noexcept
|
||||
{
|
||||
/* this function always checks "end==s" to work around a
|
||||
strptime() bug on OS X: if nothing could be parsed,
|
||||
strptime() returns the input string (indicating success)
|
||||
instead of nullptr (indicating error) */
|
||||
|
||||
const char *end = strptime(s, "%H", &tm);
|
||||
if (end == nullptr || end == s)
|
||||
return end;
|
||||
|
||||
s = end;
|
||||
precision = std::chrono::hours(1);
|
||||
|
||||
if (*s == ':') {
|
||||
/* with field separators: now a minute must follow */
|
||||
|
||||
++s;
|
||||
|
||||
end = strptime(s, "%M", &tm);
|
||||
if (end == nullptr || end == s)
|
||||
return nullptr;
|
||||
|
||||
s = end;
|
||||
precision = std::chrono::minutes(1);
|
||||
|
||||
/* the "seconds" field is optional */
|
||||
if (*s != ':')
|
||||
return s;
|
||||
|
||||
++s;
|
||||
|
||||
end = strptime(s, "%S", &tm);
|
||||
if (end == nullptr || end == s)
|
||||
return nullptr;
|
||||
|
||||
precision = std::chrono::seconds(1);
|
||||
return end;
|
||||
}
|
||||
|
||||
/* without field separators */
|
||||
|
||||
end = strptime(s, "%M", &tm);
|
||||
if (end == nullptr || end == s)
|
||||
return s;
|
||||
|
||||
s = end;
|
||||
precision = std::chrono::minutes(1);
|
||||
|
||||
end = strptime(s, "%S", &tm);
|
||||
if (end == nullptr || end == s)
|
||||
return s;
|
||||
|
||||
precision = std::chrono::seconds(1);
|
||||
return end;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
std::pair<std::chrono::system_clock::time_point,
|
||||
std::chrono::system_clock::duration>
|
||||
ParseISO8601(const char *s)
|
||||
{
|
||||
assert(s != nullptr);
|
||||
|
||||
#ifdef _WIN32
|
||||
/* TODO: emulate strptime()? */
|
||||
(void)s;
|
||||
throw std::runtime_error("Time parsing not implemented on Windows");
|
||||
#else
|
||||
struct tm tm{};
|
||||
|
||||
/* parse the date */
|
||||
const char *end = strptime(s, "%F", &tm);
|
||||
if (end == nullptr) {
|
||||
/* try without field separators */
|
||||
end = strptime(s, "%Y%m%d", &tm);
|
||||
if (end == nullptr)
|
||||
throw std::runtime_error("Failed to parse date");
|
||||
}
|
||||
|
||||
s = end;
|
||||
|
||||
std::chrono::system_clock::duration precision = std::chrono::hours(24);
|
||||
|
||||
/* parse the time of day */
|
||||
if (*s == 'T') {
|
||||
++s;
|
||||
|
||||
s = ParseTimeOfDay(s, tm, precision);
|
||||
if (s == nullptr)
|
||||
throw std::runtime_error("Failed to parse time of day");
|
||||
}
|
||||
|
||||
auto tp = TimeGm(tm);
|
||||
|
||||
/* time zone */
|
||||
if (*s == 'Z')
|
||||
++s;
|
||||
else if (*s == '+' || *s == '-')
|
||||
tp -= ParseTimeZoneOffset(s);
|
||||
|
||||
if (*s != 0)
|
||||
throw std::runtime_error("Garbage at end of time stamp");
|
||||
|
||||
return std::make_pair(tp, precision);
|
||||
#endif /* !_WIN32 */
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2017 Content Management AG
|
||||
* Copyright 2007-2019 Content Management AG
|
||||
* All rights reserved.
|
||||
*
|
||||
* author: Max Kellermann <mk@cm4all.com>
|
||||
@@ -33,13 +33,15 @@
|
||||
#ifndef TIME_ISO8601_HXX
|
||||
#define TIME_ISO8601_HXX
|
||||
|
||||
#include "StringBuffer.hxx"
|
||||
#include "Compiler.h"
|
||||
#include "util/Compiler.h"
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <utility>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct tm;
|
||||
template<size_t CAPACITY> class StringBuffer;
|
||||
|
||||
gcc_pure
|
||||
StringBuffer<64>
|
||||
@@ -49,7 +51,16 @@ gcc_pure
|
||||
StringBuffer<64>
|
||||
FormatISO8601(std::chrono::system_clock::time_point tp);
|
||||
|
||||
std::chrono::system_clock::time_point
|
||||
/**
|
||||
* Parse a time stamp in ISO8601 format.
|
||||
*
|
||||
* Throws on error.
|
||||
*
|
||||
* @return a pair consisting of the time point and the specified
|
||||
* precision; e.g. for a date, the second value is "one day"
|
||||
*/
|
||||
std::pair<std::chrono::system_clock::time_point,
|
||||
std::chrono::system_clock::duration>
|
||||
ParseISO8601(const char *s);
|
||||
|
||||
#endif
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2014-2019 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -27,32 +27,14 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "TimeParser.hxx"
|
||||
#include "Compiler.h"
|
||||
#include "Parser.hxx"
|
||||
#include "Convert.hxx"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
#if !defined(__GLIBC__) && !defined(_WIN32)
|
||||
|
||||
/**
|
||||
* Determine the time zone offset in a portable way.
|
||||
*/
|
||||
gcc_const
|
||||
static time_t
|
||||
GetTimeZoneOffset() noexcept
|
||||
{
|
||||
time_t t = 1234567890;
|
||||
struct tm tm;
|
||||
tm.tm_isdst = 0;
|
||||
gmtime_r(&t, &tm);
|
||||
return t - mktime(&tm);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
std::chrono::system_clock::time_point
|
||||
ParseTimePoint(const char *s, const char *format)
|
||||
{
|
||||
@@ -65,20 +47,11 @@ ParseTimePoint(const char *s, const char *format)
|
||||
(void)format;
|
||||
throw std::runtime_error("Time parsing not implemented on Windows");
|
||||
#else
|
||||
struct tm tm;
|
||||
struct tm tm{};
|
||||
const char *end = strptime(s, format, &tm);
|
||||
if (end == nullptr || *end != 0)
|
||||
throw std::runtime_error("Failed to parse time stamp");
|
||||
|
||||
#ifdef __GLIBC__
|
||||
/* timegm() is a GNU extension */
|
||||
const auto t = timegm(&tm);
|
||||
#else
|
||||
tm.tm_isdst = 0;
|
||||
const auto t = mktime(&tm) + GetTimeZoneOffset();
|
||||
#endif /* !__GLIBC__ */
|
||||
|
||||
return std::chrono::system_clock::from_time_t(t);
|
||||
|
||||
return TimeGm(tm);
|
||||
#endif /* !_WIN32 */
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2014-2019 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
11
src/time/meson.build
Normal file
11
src/time/meson.build
Normal file
@@ -0,0 +1,11 @@
|
||||
time = static_library(
|
||||
'time',
|
||||
'Parser.cxx',
|
||||
'Convert.cxx',
|
||||
'ISO8601.cxx',
|
||||
include_directories: inc,
|
||||
)
|
||||
|
||||
time_dep = declare_dependency(
|
||||
link_with: time,
|
||||
)
|
@@ -143,6 +143,14 @@
|
||||
#define gcc_flatten
|
||||
#endif
|
||||
|
||||
#if GCC_CHECK_VERSION(7,0)
|
||||
#define gcc_fallthrough __attribute__((fallthrough))
|
||||
#elif CLANG_CHECK_VERSION(10,0)
|
||||
#define gcc_fallthrough [[fallthrough]]
|
||||
#else
|
||||
#define gcc_fallthrough
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
/* plain C99 has "restrict" */
|
||||
#define gcc_restrict restrict
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2017 Content Management AG
|
||||
* Copyright 2007-2019 Content Management AG
|
||||
* All rights reserved.
|
||||
*
|
||||
* author: Max Kellermann <mk@cm4all.com>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2017 Content Management AG
|
||||
* Copyright 2007-2019 Content Management AG
|
||||
* All rights reserved.
|
||||
*
|
||||
* author: Max Kellermann <mk@cm4all.com>
|
||||
|
@@ -35,14 +35,14 @@
|
||||
/**
|
||||
* A statically allocated string buffer.
|
||||
*/
|
||||
template<typename T, size_t CAPACITY>
|
||||
template<typename T, std::size_t CAPACITY>
|
||||
class BasicStringBuffer {
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef T &reference;
|
||||
typedef T *pointer;
|
||||
typedef const T *const_pointer;
|
||||
typedef size_t size_type;
|
||||
typedef std::size_t size_type;
|
||||
|
||||
static constexpr value_type SENTINEL = '\0';
|
||||
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t CAPACITY>
|
||||
template<std::size_t CAPACITY>
|
||||
class StringBuffer : public BasicStringBuffer<char, CAPACITY> {};
|
||||
|
||||
#endif
|
||||
|
@@ -36,13 +36,13 @@
|
||||
|
||||
template<typename... Args>
|
||||
static inline void
|
||||
StringFormat(char *buffer, size_t size,
|
||||
StringFormat(char *buffer, std::size_t size,
|
||||
const char *fmt, Args&&... args) noexcept
|
||||
{
|
||||
snprintf(buffer, size, fmt, args...);
|
||||
}
|
||||
|
||||
template<size_t CAPACITY, typename... Args>
|
||||
template<std::size_t CAPACITY, typename... Args>
|
||||
static inline void
|
||||
StringFormat(StringBuffer<CAPACITY> &buffer,
|
||||
const char *fmt, Args&&... args) noexcept
|
||||
@@ -50,7 +50,7 @@ StringFormat(StringBuffer<CAPACITY> &buffer,
|
||||
StringFormat(buffer.data(), buffer.capacity(), fmt, args...);
|
||||
}
|
||||
|
||||
template<size_t CAPACITY, typename... Args>
|
||||
template<std::size_t CAPACITY, typename... Args>
|
||||
static inline StringBuffer<CAPACITY>
|
||||
StringFormat(const char *fmt, Args&&... args) noexcept
|
||||
{
|
||||
|
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "format.h"
|
||||
#include "util/Compiler.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@@ -238,6 +239,7 @@ format_object2(const char *format, const char **last, const void *object,
|
||||
}
|
||||
|
||||
/* fall through */
|
||||
gcc_fallthrough;
|
||||
|
||||
default:
|
||||
/* pass-through non-escaped portions of the format string */
|
||||
|
@@ -16,9 +16,6 @@ util = static_library(
|
||||
'SplitString.cxx',
|
||||
'FormatString.cxx',
|
||||
'Tokenizer.cxx',
|
||||
'TimeParser.cxx',
|
||||
'TimeConvert.cxx',
|
||||
'TimeISO8601.cxx',
|
||||
'UriUtil.cxx',
|
||||
'LazyRandomEngine.cxx',
|
||||
'HugeAllocator.cxx',
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include "AvahiPoll.hxx"
|
||||
#include "event/SocketMonitor.hxx"
|
||||
#include "event/TimerEvent.hxx"
|
||||
#include "time/Convert.hxx"
|
||||
|
||||
static unsigned
|
||||
FromAvahiWatchEvent(AvahiWatchEvent e)
|
||||
@@ -78,12 +79,6 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr std::chrono::steady_clock::duration
|
||||
TimevalToChrono(const timeval &tv)
|
||||
{
|
||||
return std::chrono::seconds(tv.tv_sec) + std::chrono::microseconds(tv.tv_usec);
|
||||
}
|
||||
|
||||
struct AvahiTimeout final {
|
||||
TimerEvent timer;
|
||||
|
||||
@@ -97,12 +92,12 @@ public:
|
||||
:timer(_loop, BIND_THIS_METHOD(OnTimeout)),
|
||||
callback(_callback), userdata(_userdata) {
|
||||
if (tv != nullptr)
|
||||
timer.Schedule(TimevalToChrono(*tv));
|
||||
timer.Schedule(ToSteadyClockDuration(*tv));
|
||||
}
|
||||
|
||||
static void TimeoutUpdate(AvahiTimeout *t, const struct timeval *tv) {
|
||||
if (tv != nullptr)
|
||||
t->timer.Schedule(TimevalToChrono(*tv));
|
||||
t->timer.Schedule(ToSteadyClockDuration(*tv));
|
||||
else
|
||||
t->timer.Cancel();
|
||||
}
|
||||
|
@@ -67,6 +67,7 @@ else
|
||||
dependencies: [
|
||||
libavahi_client_dep,
|
||||
dbus_dep,
|
||||
time_dep,
|
||||
],
|
||||
)
|
||||
|
||||
|
93
test/RunCurl.cxx
Normal file
93
test/RunCurl.cxx
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2003-2019 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "ShutdownHandler.hxx"
|
||||
#include "lib/curl/Global.hxx"
|
||||
#include "lib/curl/Request.hxx"
|
||||
#include "lib/curl/Handler.hxx"
|
||||
#include "event/Loop.hxx"
|
||||
#include "util/PrintException.hxx"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
class MyHandler final : public CurlResponseHandler {
|
||||
EventLoop &event_loop;
|
||||
|
||||
std::exception_ptr error;
|
||||
|
||||
public:
|
||||
explicit MyHandler(EventLoop &_event_loop) noexcept
|
||||
:event_loop(_event_loop) {}
|
||||
|
||||
void Finish() {
|
||||
if (error)
|
||||
std::rethrow_exception(error);
|
||||
}
|
||||
|
||||
/* virtual methods from CurlResponseHandler */
|
||||
void OnHeaders(unsigned status,
|
||||
std::multimap<std::string, std::string> &&headers) override {
|
||||
fprintf(stderr, "status: %u\n", status);
|
||||
for (const auto &i : headers)
|
||||
fprintf(stderr, "%s: %s\n",
|
||||
i.first.c_str(), i.second.c_str());
|
||||
}
|
||||
|
||||
void OnData(ConstBuffer<void> data) override {
|
||||
if (fwrite(data.data, data.size, 1, stdout) != 1)
|
||||
throw std::runtime_error("Failed to write");
|
||||
}
|
||||
|
||||
void OnEnd() override {
|
||||
event_loop.Break();
|
||||
}
|
||||
|
||||
void OnError(std::exception_ptr e) noexcept override {
|
||||
error = std::move(e);
|
||||
event_loop.Break();
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char **argv) noexcept
|
||||
try {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: RunCurl URI\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
const char *const uri = argv[1];
|
||||
|
||||
EventLoop event_loop;
|
||||
const ShutdownHandler shutdown_handler(event_loop);
|
||||
CurlGlobal curl_global(event_loop);
|
||||
|
||||
MyHandler handler(event_loop);
|
||||
CurlRequest request(curl_global, uri, handler);
|
||||
request.Start();
|
||||
|
||||
event_loop.Run();
|
||||
|
||||
handler.Finish();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} catch (...) {
|
||||
PrintException(std::current_exception());
|
||||
return EXIT_FAILURE;
|
||||
}
|
92
test/TestISO8601.cxx
Normal file
92
test/TestISO8601.cxx
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2019 Content Management AG
|
||||
* All rights reserved.
|
||||
*
|
||||
* author: Max Kellermann <mk@cm4all.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "time/ISO8601.hxx"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static constexpr struct {
|
||||
const char *s;
|
||||
time_t t;
|
||||
std::chrono::system_clock::duration d;
|
||||
} parse_tests[] = {
|
||||
/* full ISO8601 */
|
||||
{ "1970-01-01T00:00:00Z", 0, std::chrono::seconds(1) },
|
||||
{ "1970-01-01T00:00:01Z", 1, std::chrono::seconds(1) },
|
||||
{ "2019-02-04T16:46:41Z", 1549298801, std::chrono::seconds(1) },
|
||||
{ "2018-12-31T23:59:59Z", 1546300799, std::chrono::seconds(1) },
|
||||
{ "2019-01-01T00:00:00Z", 1546300800, std::chrono::seconds(1) },
|
||||
|
||||
/* only date */
|
||||
{ "1970-01-01", 0, std::chrono::hours(24) },
|
||||
{ "2019-02-04", 1549238400, std::chrono::hours(24) },
|
||||
{ "2018-12-31", 1546214400, std::chrono::hours(24) },
|
||||
{ "2019-01-01", 1546300800, std::chrono::hours(24) },
|
||||
|
||||
/* date with time zone */
|
||||
{ "2019-02-04Z", 1549238400, std::chrono::hours(24) },
|
||||
|
||||
/* without time zone */
|
||||
{ "2019-02-04T16:46:41", 1549298801, std::chrono::seconds(1) },
|
||||
|
||||
/* without seconds */
|
||||
{ "2019-02-04T16:46", 1549298760, std::chrono::minutes(1) },
|
||||
{ "2019-02-04T16:46Z", 1549298760, std::chrono::minutes(1) },
|
||||
|
||||
/* without minutes */
|
||||
{ "2019-02-04T16", 1549296000, std::chrono::hours(1) },
|
||||
{ "2019-02-04T16Z", 1549296000, std::chrono::hours(1) },
|
||||
|
||||
/* with time zone */
|
||||
{ "2019-02-04T16:46:41+02", 1549291601, std::chrono::seconds(1) },
|
||||
{ "2019-02-04T16:46:41+0200", 1549291601, std::chrono::seconds(1) },
|
||||
{ "2019-02-04T16:46:41+02:00", 1549291601, std::chrono::seconds(1) },
|
||||
{ "2019-02-04T16:46:41-0200", 1549306001, std::chrono::seconds(1) },
|
||||
|
||||
/* without field separators */
|
||||
{ "19700101T000000Z", 0, std::chrono::seconds(1) },
|
||||
{ "19700101T000001Z", 1, std::chrono::seconds(1) },
|
||||
{ "20190204T164641Z", 1549298801, std::chrono::seconds(1) },
|
||||
{ "19700101", 0, std::chrono::hours(24) },
|
||||
{ "20190204", 1549238400, std::chrono::hours(24) },
|
||||
{ "20190204T1646", 1549298760, std::chrono::minutes(1) },
|
||||
{ "20190204T16", 1549296000, std::chrono::hours(1) },
|
||||
};
|
||||
|
||||
TEST(ISO8601, Parse)
|
||||
{
|
||||
for (const auto &i : parse_tests) {
|
||||
const auto result = ParseISO8601(i.s);
|
||||
EXPECT_EQ(std::chrono::system_clock::to_time_t(result.first), i.t);
|
||||
EXPECT_EQ(result.second, i.d);
|
||||
}
|
||||
}
|
@@ -46,6 +46,19 @@ test('TestUtil', executable(
|
||||
],
|
||||
))
|
||||
|
||||
test(
|
||||
'TestTime',
|
||||
executable(
|
||||
'TestTime',
|
||||
'TestISO8601.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
time_dep,
|
||||
gtest_dep,
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
test('TestRewindInputStream', executable(
|
||||
'TestRewindInputStream',
|
||||
'TestRewindInputStream.cxx',
|
||||
@@ -321,6 +334,18 @@ executable(
|
||||
)
|
||||
|
||||
if curl_dep.found()
|
||||
executable(
|
||||
'RunCurl',
|
||||
'RunCurl.cxx',
|
||||
'ShutdownHandler.cxx',
|
||||
'../src/Log.cxx',
|
||||
'../src/LogBackend.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
curl_dep,
|
||||
],
|
||||
)
|
||||
|
||||
test('test_icy_parser', executable(
|
||||
'test_icy_parser',
|
||||
'test_icy_parser.cxx',
|
||||
|
@@ -22,7 +22,7 @@
|
||||
#include "storage/StorageInterface.hxx"
|
||||
#include "storage/FileInfo.hxx"
|
||||
#include "net/Init.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
#include "util/PrintException.hxx"
|
||||
|
||||
#include <memory>
|
||||
@@ -90,6 +90,29 @@ Ls(Storage &storage, const char *path)
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
Stat(Storage &storage, const char *path)
|
||||
{
|
||||
const auto info = storage.GetInfo(path, false);
|
||||
switch (info.type) {
|
||||
case StorageFileInfo::Type::OTHER:
|
||||
printf("other\n");
|
||||
break;
|
||||
|
||||
case StorageFileInfo::Type::REGULAR:
|
||||
printf("regular\n");
|
||||
break;
|
||||
|
||||
case StorageFileInfo::Type::DIRECTORY:
|
||||
printf("directory\n");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("size: %llu\n", (unsigned long long)info.size);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
try {
|
||||
@@ -117,6 +140,18 @@ try {
|
||||
storage_uri);
|
||||
|
||||
return Ls(*storage, path);
|
||||
} else if (strcmp(command, "stat") == 0) {
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "Usage: run_storage stat URI PATH\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
const char *const path = argv[3];
|
||||
|
||||
auto storage = MakeStorage(io_thread.GetEventLoop(),
|
||||
storage_uri);
|
||||
|
||||
return Stat(*storage, path);
|
||||
} else {
|
||||
fprintf(stderr, "Unknown command\n");
|
||||
return EXIT_FAILURE;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
#include "storage/StorageInterface.hxx"
|
||||
#include "storage/plugins/LocalStorage.hxx"
|
||||
#include "Mapper.hxx"
|
||||
#include "util/ChronoUtil.hxx"
|
||||
#include "time/ChronoUtil.hxx"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
Reference in New Issue
Block a user