Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
3d12f8d2
Commit
3d12f8d2
authored
Oct 23, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UriUtil: uri_remove_auth() returns std::string
parent
c3e72027
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
38 deletions
+25
-38
Makefile.am
Makefile.am
+0
-1
DecoderThread.cxx
src/DecoderThread.cxx
+3
-6
SongPrint.cxx
src/SongPrint.cxx
+4
-10
UriUtil.cxx
src/util/UriUtil.cxx
+6
-11
UriUtil.hxx
src/util/UriUtil.hxx
+6
-4
test_util.cxx
test/test_util.cxx
+6
-6
No files found.
Makefile.am
View file @
3d12f8d2
...
@@ -1473,7 +1473,6 @@ test_test_util_CPPFLAGS = $(AM_CPPFLAGS) $(CPPUNIT_CFLAGS) -DCPPUNIT_HAVE_RTTI=0
...
@@ -1473,7 +1473,6 @@ test_test_util_CPPFLAGS = $(AM_CPPFLAGS) $(CPPUNIT_CFLAGS) -DCPPUNIT_HAVE_RTTI=0
test_test_util_CXXFLAGS
=
$(AM_CXXFLAGS)
-Wno-error
=
deprecated-declarations
test_test_util_CXXFLAGS
=
$(AM_CXXFLAGS)
-Wno-error
=
deprecated-declarations
test_test_util_LDADD
=
\
test_test_util_LDADD
=
\
libutil.a
\
libutil.a
\
$(GLIB_LIBS)
\
$(CPPUNIT_LIBS)
$(CPPUNIT_LIBS)
test_test_byte_reverse_SOURCES
=
\
test_test_byte_reverse_SOURCES
=
\
...
...
src/DecoderThread.cxx
View file @
3d12f8d2
...
@@ -38,8 +38,6 @@
...
@@ -38,8 +38,6 @@
#include "tag/ApeReplayGain.hxx"
#include "tag/ApeReplayGain.hxx"
#include "Log.hxx"
#include "Log.hxx"
#include <glib.h>
static
constexpr
Domain
decoder_thread_domain
(
"decoder_thread"
);
static
constexpr
Domain
decoder_thread_domain
(
"decoder_thread"
);
/**
/**
...
@@ -367,13 +365,12 @@ decoder_run_song(decoder_control &dc,
...
@@ -367,13 +365,12 @@ decoder_run_song(decoder_control &dc,
dc
.
state
=
DecoderState
::
ERROR
;
dc
.
state
=
DecoderState
::
ERROR
;
const
char
*
error_uri
=
song
->
uri
;
const
char
*
error_uri
=
song
->
uri
;
c
har
*
allocated
=
uri_remove_auth
(
error_uri
);
c
onst
std
::
string
allocated
=
uri_remove_auth
(
error_uri
);
if
(
allocated
!=
nullptr
)
if
(
!
allocated
.
empty
()
)
error_uri
=
allocated
;
error_uri
=
allocated
.
c_str
()
;
dc
.
error
.
Format
(
decoder_domain
,
dc
.
error
.
Format
(
decoder_domain
,
"Failed to decode %s"
,
error_uri
);
"Failed to decode %s"
,
error_uri
);
g_free
(
allocated
);
}
}
dc
.
client_cond
.
signal
();
dc
.
client_cond
.
signal
();
...
...
src/SongPrint.cxx
View file @
3d12f8d2
...
@@ -27,8 +27,6 @@
...
@@ -27,8 +27,6 @@
#include "Client.hxx"
#include "Client.hxx"
#include "util/UriUtil.hxx"
#include "util/UriUtil.hxx"
#include <glib.h>
void
void
song_print_uri
(
Client
&
client
,
const
Song
&
song
)
song_print_uri
(
Client
&
client
,
const
Song
&
song
)
{
{
...
@@ -36,17 +34,13 @@ song_print_uri(Client &client, const Song &song)
...
@@ -36,17 +34,13 @@ song_print_uri(Client &client, const Song &song)
client_printf
(
client
,
"%s%s/%s
\n
"
,
SONG_FILE
,
client_printf
(
client
,
"%s%s/%s
\n
"
,
SONG_FILE
,
song
.
parent
->
GetPath
(),
song
.
uri
);
song
.
parent
->
GetPath
(),
song
.
uri
);
}
else
{
}
else
{
char
*
allocated
;
const
char
*
uri
=
song
.
uri
;
const
char
*
uri
;
const
std
::
string
allocated
=
uri_remove_auth
(
uri
);
if
(
!
allocated
.
empty
())
uri
=
allocated
=
uri_remove_auth
(
song
.
uri
);
uri
=
allocated
.
c_str
();
if
(
uri
==
NULL
)
uri
=
song
.
uri
;
client_printf
(
client
,
"%s%s
\n
"
,
SONG_FILE
,
client_printf
(
client
,
"%s%s
\n
"
,
SONG_FILE
,
map_to_relative_path
(
uri
));
map_to_relative_path
(
uri
));
g_free
(
allocated
);
}
}
}
}
...
...
src/util/UriUtil.cxx
View file @
3d12f8d2
...
@@ -19,8 +19,6 @@
...
@@ -19,8 +19,6 @@
#include "UriUtil.hxx"
#include "UriUtil.hxx"
#include <glib.h>
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
...
@@ -80,11 +78,10 @@ uri_safe_local(const char *uri)
...
@@ -80,11 +78,10 @@ uri_safe_local(const char *uri)
}
}
}
}
char
*
std
::
string
uri_remove_auth
(
const
char
*
uri
)
uri_remove_auth
(
const
char
*
uri
)
{
{
const
char
*
auth
,
*
slash
,
*
at
;
const
char
*
auth
,
*
slash
,
*
at
;
char
*
p
;
if
(
memcmp
(
uri
,
"http://"
,
7
)
==
0
)
if
(
memcmp
(
uri
,
"http://"
,
7
)
==
0
)
auth
=
uri
+
7
;
auth
=
uri
+
7
;
...
@@ -92,7 +89,7 @@ uri_remove_auth(const char *uri)
...
@@ -92,7 +89,7 @@ uri_remove_auth(const char *uri)
auth
=
uri
+
8
;
auth
=
uri
+
8
;
else
else
/* unrecognized URI */
/* unrecognized URI */
return
nullptr
;
return
std
::
string
()
;
slash
=
strchr
(
auth
,
'/'
);
slash
=
strchr
(
auth
,
'/'
);
if
(
slash
==
nullptr
)
if
(
slash
==
nullptr
)
...
@@ -101,13 +98,11 @@ uri_remove_auth(const char *uri)
...
@@ -101,13 +98,11 @@ uri_remove_auth(const char *uri)
at
=
(
const
char
*
)
memchr
(
auth
,
'@'
,
slash
-
auth
);
at
=
(
const
char
*
)
memchr
(
auth
,
'@'
,
slash
-
auth
);
if
(
at
==
nullptr
)
if
(
at
==
nullptr
)
/* no auth info present, do nothing */
/* no auth info present, do nothing */
return
nullptr
;
return
std
::
string
()
;
/* duplicate the full URI and then delete the auth
/* duplicate the full URI and then delete the auth
information */
information */
p
=
g_strdup
(
uri
);
std
::
string
result
(
uri
);
memmove
(
p
+
(
auth
-
uri
),
p
+
(
at
+
1
-
uri
),
result
.
erase
(
auth
-
uri
,
at
+
1
-
auth
);
strlen
(
at
));
return
result
;
return
p
;
}
}
src/util/UriUtil.hxx
View file @
3d12f8d2
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
#include "Compiler.h"
#include "Compiler.h"
#include <string>
/**
/**
* Checks whether the specified URI has a scheme in the form
* Checks whether the specified URI has a scheme in the form
* "scheme://".
* "scheme://".
...
@@ -48,11 +50,11 @@ uri_safe_local(const char *uri);
...
@@ -48,11 +50,11 @@ uri_safe_local(const char *uri);
/**
/**
* Removes HTTP username and password from the URI. This may be
* Removes HTTP username and password from the URI. This may be
* useful for displaying an URI without disclosing secrets. Returns
* useful for displaying an URI without disclosing secrets. Returns
*
NULL if nothing needs to be removed, or if the URI is not
*
an empty string if nothing needs to be removed, or if the URI is
* recognized.
*
not
recognized.
*/
*/
gcc_
malloc
gcc_
pure
char
*
std
::
string
uri_remove_auth
(
const
char
*
uri
);
uri_remove_auth
(
const
char
*
uri
);
#endif
#endif
test/test_util.cxx
View file @
3d12f8d2
...
@@ -31,13 +31,13 @@ public:
...
@@ -31,13 +31,13 @@ public:
}
}
void
TestRemoveAuth
()
{
void
TestRemoveAuth
()
{
CPPUNIT_ASSERT_EQUAL
(
(
char
*
)
nullptr
,
CPPUNIT_ASSERT_EQUAL
(
std
::
string
()
,
uri_remove_auth
(
"http://www.example.com/"
));
uri_remove_auth
(
"http://www.example.com/"
));
CPPUNIT_ASSERT_EQUAL
(
0
,
strcmp
(
uri_remove_auth
(
"http://foo:bar@
www.example.com/"
),
CPPUNIT_ASSERT_EQUAL
(
std
::
string
(
"http://
www.example.com/"
),
"http://
www.example.com/"
));
uri_remove_auth
(
"http://foo:bar@
www.example.com/"
));
CPPUNIT_ASSERT_EQUAL
(
0
,
strcmp
(
uri_remove_auth
(
"http://foo@
www.example.com/"
),
CPPUNIT_ASSERT_EQUAL
(
std
::
string
(
"http://
www.example.com/"
),
"http://
www.example.com/"
));
uri_remove_auth
(
"http://foo@
www.example.com/"
));
CPPUNIT_ASSERT_EQUAL
(
(
char
*
)
nullptr
,
CPPUNIT_ASSERT_EQUAL
(
std
::
string
()
,
uri_remove_auth
(
"http://www.example.com/f:oo@bar"
));
uri_remove_auth
(
"http://www.example.com/f:oo@bar"
));
}
}
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment