diff --git a/src/zm_utils.cpp b/src/zm_utils.cpp index e777a9266..b84cead1c 100644 --- a/src/zm_utils.cpp +++ b/src/zm_utils.cpp @@ -25,6 +25,10 @@ #include #include +#ifdef HAVE_CURL_CURL_H +#include +#endif + unsigned int sseversion = 0; std::string trimSet(std::string str, std::string trimset) { @@ -345,3 +349,18 @@ void timespec_diff(struct timespec *start, struct timespec *end, struct timespec } } +std::string UriDecode( const std::string &encoded ) { +#ifdef HAVE_LIBCURL + CURL *curl = curl_easy_init(); + int outlength; + char *cres = curl_easy_unescape(curl, encoded.c_str(), encoded.length(), &outlength); + std::string res(cres, cres + outlength); + curl_free(cres); + curl_easy_cleanup(curl); + return res; +#else +Warning("ZM Compiled without LIBCURL. UriDecoding not implemented."); + return encoded; +#endif +} + diff --git a/src/zm_utils.h b/src/zm_utils.h index 6dbf76a4d..b8345c356 100644 --- a/src/zm_utils.h +++ b/src/zm_utils.h @@ -60,4 +60,6 @@ void timespec_diff(struct timespec *start, struct timespec *end, struct timespec extern unsigned int sseversion; +std::string UriDecode( const std::string &encoded ); + #endif // ZM_UTILS_H diff --git a/src/zms.cpp b/src/zms.cpp index 87eaf3202..c32b9affd 100644 --- a/src/zms.cpp +++ b/src/zms.cpp @@ -69,8 +69,8 @@ int main( int argc, const char *argv[] ) unsigned int bitrate = 100000; unsigned int ttl = 0; EventStream::StreamMode replay = EventStream::MODE_SINGLE; - char username[64] = ""; - char password[64] = ""; + std::string username; + std::string password; char auth[64] = ""; unsigned int connkey = 0; unsigned int playback_buffer = 0; @@ -164,7 +164,7 @@ int main( int argc, const char *argv[] ) { if ( !strcmp( name, "user" ) ) { - strncpy( username, value, sizeof(username) ); + username = value; } } else @@ -180,11 +180,11 @@ int main( int argc, const char *argv[] ) { if ( !strcmp( name, "user" ) ) { - strncpy( username, value, sizeof(username) ); + username = UriDecode(value); } if ( !strcmp( name, "pass" ) ) { - strncpy( password, value, sizeof(password) ); + password = UriDecode( password ); } } } @@ -198,9 +198,9 @@ int main( int argc, const char *argv[] ) if ( strcmp( config.auth_relay, "none" ) == 0 ) { - if ( *username ) + if ( username.length() ) { - user = zmLoadUser( username ); + user = zmLoadUser( username.c_str() ); } } else @@ -214,9 +214,9 @@ int main( int argc, const char *argv[] ) } //else if ( strcmp( config.auth_relay, "plain" ) == 0 ) { - if ( *username && *password ) + if ( username.length() && password.length() ) { - user = zmLoadUser( username, password ); + user = zmLoadUser( username.c_str(), password.c_str() ); } } }