Merge pull request #1826 from connortechnology/uri_decode_in_zms

Uri decode in zms
This commit is contained in:
Andrew Bauer 2017-04-03 20:13:30 -05:00 committed by GitHub
commit b609b9ad4c
3 changed files with 30 additions and 9 deletions

View File

@ -25,6 +25,10 @@
#include <stdio.h>
#include <stdarg.h>
#ifdef HAVE_CURL_CURL_H
#include <curl/curl.h>
#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
}

View File

@ -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

View File

@ -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() );
}
}
}