Skip to content

Commit c02b6a4

Browse files
authored
Merge pull request #936 from rvbc1/auth-hotfix
auth hotfix
2 parents 33dcd4c + 17010eb commit c02b6a4

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/Audio.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
515515
uint32_t timestamp = 0; // timeout surveillance
516516
uint16_t hostwoext_begin = 0;
517517

518-
char* authorization = NULL; // authorization
518+
// char* authorization = NULL; // authorization
519519
char* rqh = NULL; // request header
520520
char* toEncode = NULL; // temporary memory for base64 encoding
521521
char* h_host = NULL;
@@ -527,6 +527,18 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
527527

528528
xSemaphoreTakeRecursive(mutex_playAudioData, 0.3 * configTICK_RATE_HZ);
529529

530+
// optional basic authorization
531+
authLen = strlen(user) + strlen(pwd);
532+
char authorization[base64_encode_expected_len(authLen + 1) + 1];
533+
authorization[0] = '\0';
534+
if(authLen > 0) {
535+
char toEncode[authLen + 4];
536+
strcpy(toEncode, user);
537+
strcat(toEncode, ":");
538+
strcat(toEncode, pwd);
539+
b64encode((const char*)toEncode, strlen(toEncode), authorization);
540+
}
541+
530542
if (host == NULL) { AUDIO_INFO("Hostaddress is empty"); stopSong(); goto exit;}
531543
if (strlen(host) > 2048) { AUDIO_INFO("Hostaddress is too long"); stopSong(); goto exit;} // max length in Chrome DevTools
532544

@@ -551,21 +563,21 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
551563
h_host[pos_colon] = '\0';
552564
}
553565

554-
// optional basic authorization
555-
if(strlen(user) > 0 && strlen(pwd) > 0) {
556-
authLen = strlen(user) + strlen(pwd);
557-
authorization = x_ps_calloc(base64_encode_expected_len(authLen + 1), 1);
558-
if(!authorization) {AUDIO_INFO("out of memory"); stopSong(); goto exit;}
559-
toEncode = x_ps_calloc(authLen + 4, 1);
560-
if(!toEncode) {AUDIO_INFO("out of memory"); stopSong(); goto exit;}
561-
strcpy(toEncode, user);
562-
strcat(toEncode, ":");
563-
strcat(toEncode, pwd);
564-
b64encode((const char*)toEncode, strlen(toEncode), authorization);
565-
}
566-
else{
567-
authorization = strdup("");
568-
}
566+
// // optional basic authorization
567+
// if(strlen(user) > 0 && strlen(pwd) > 0) {
568+
// authLen = strlen(user) + strlen(pwd);
569+
// authorization = x_ps_calloc(base64_encode_expected_len(authLen + 1), 1);
570+
// if(!authorization) {AUDIO_INFO("out of memory"); stopSong(); goto exit;}
571+
// toEncode = x_ps_calloc(authLen + 4, 1);
572+
// if(!toEncode) {AUDIO_INFO("out of memory"); stopSong(); goto exit;}
573+
// strcpy(toEncode, user);
574+
// strcat(toEncode, ":");
575+
// strcat(toEncode, pwd);
576+
// b64encode((const char*)toEncode, strlen(toEncode), authorization);
577+
// }
578+
// else{
579+
// authorization = strdup("");
580+
// }
569581

570582
setDefaults();
571583
rqh = x_ps_calloc(lenHost + strlen(authorization) + 300, 1); // http request header
@@ -641,7 +653,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
641653
xSemaphoreGiveRecursive(mutex_playAudioData);
642654
x_ps_free(h_host);
643655
x_ps_free(rqh);
644-
x_ps_free(authorization);
656+
// x_ps_free(authorization);
645657
x_ps_free(toEncode);
646658
return res;
647659
}

0 commit comments

Comments
 (0)