Unverified Commit e68ece5c authored by Wolle's avatar Wolle Committed by GitHub

allow ssl port != 443

if http status code 301 "Moved Permanently" wait for Location: and redirect to new url
correct connection time
parent 7754fed6
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
* *
* Created on: Oct 26.2018 * Created on: Oct 26.2018
* *
* Version 2.0.4b * Version 2.0.4c
* Updated on: Jul 08.2022 * Updated on: Jul 09.2022
* Author: Wolle (schreibfaul1) * Author: Wolle (schreibfaul1)
* *
*/ */
...@@ -407,7 +407,8 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) { ...@@ -407,7 +407,8 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
// In the URL there may be an extension, like noisefm.ru:8000/play.m3u&t=.m3u // In the URL there may be an extension, like noisefm.ru:8000/play.m3u&t=.m3u
pos_slash = indexOf(h_host, "/", 0); pos_slash = indexOf(h_host, "/", 0);
pos_colon = indexOf(h_host, ":", 0); if(isalpha(h_host[pos_colon + 1])) pos_colon = -1; // no portnumber follows pos_colon = indexOf(h_host, ":", 0);
if(isalpha(h_host[pos_colon + 1])) pos_colon = -1; // no portnumber follows
pos_ampersand = indexOf(h_host, "&", 0); pos_ampersand = indexOf(h_host, "&", 0);
char *hostwoext = NULL; // "skonto.ls.lv:8002" in "skonto.ls.lv:8002/mp3" char *hostwoext = NULL; // "skonto.ls.lv:8002" in "skonto.ls.lv:8002/mp3"
...@@ -450,7 +451,6 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) { ...@@ -450,7 +451,6 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
strcat(rqh, "Accept-Encoding: gzip;q=0\r\n"); strcat(rqh, "Accept-Encoding: gzip;q=0\r\n");
strcat(rqh, "User-Agent: Mozilla/5.0\r\n"); strcat(rqh, "User-Agent: Mozilla/5.0\r\n");
strcat(rqh, "Connection: keep-alive\r\n\r\n"); strcat(rqh, "Connection: keep-alive\r\n\r\n");
uint32_t t = millis();
if(ESP_ARDUINO_VERSION_MAJOR == 2 && ESP_ARDUINO_VERSION_MINOR == 0 && ESP_ARDUINO_VERSION_PATCH == 3){ if(ESP_ARDUINO_VERSION_MAJOR == 2 && ESP_ARDUINO_VERSION_MINOR == 0 && ESP_ARDUINO_VERSION_PATCH == 3){
m_timeout_ms_ssl = UINT16_MAX; // bug in v2.0.3 if hostwoext is a IPaddr not a name m_timeout_ms_ssl = UINT16_MAX; // bug in v2.0.3 if hostwoext is a IPaddr not a name
...@@ -458,14 +458,15 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) { ...@@ -458,14 +458,15 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
} }
bool res = true; // no need to reconnect if connection exists bool res = true; // no need to reconnect if connection exists
if(m_f_ssl){ _client = static_cast<WiFiClient*>(&clientsecure); port = 443;} if(m_f_ssl){ _client = static_cast<WiFiClient*>(&clientsecure); if(port == 80) port = 443;}
else { _client = static_cast<WiFiClient*>(&client);} else { _client = static_cast<WiFiClient*>(&client);}
if(!_client->connected()) { if(!_client->connected()) {
uint32_t dt = millis() - t; uint32_t t = millis();
if(m_f_Log) AUDIO_INFO("connect to %s on port %d path %s", hostwoext, port, extension);
res = _client->connect(hostwoext, port, m_f_ssl ? m_timeout_ms_ssl : m_timeout_ms); res = _client->connect(hostwoext, port, m_f_ssl ? m_timeout_ms_ssl : m_timeout_ms);
if(res){ if(res){
uint32_t dt = millis() - t;
strcpy(m_lastHost, l_host); strcpy(m_lastHost, l_host);
AUDIO_INFO("%s has been established in %u ms, free Heap: %u bytes", AUDIO_INFO("%s has been established in %u ms, free Heap: %u bytes",
m_f_ssl?"SSL":"Connection", dt, ESP.getFreeHeap()); m_f_ssl?"SSL":"Connection", dt, ESP.getFreeHeap());
...@@ -2287,7 +2288,7 @@ bool Audio::readPlayListData() { ...@@ -2287,7 +2288,7 @@ bool Audio::readPlayListData() {
} }
if(startsWith(pl, "<!DOCTYPE")) {AUDIO_INFO("url is a webpage!"); goto exit;} if(startsWith(pl, "<!DOCTYPE")) {AUDIO_INFO("url is a webpage!"); goto exit;}
m_playlistContent.push_back(strdup((const char*)pl)); if(strlen(pl) > 0) m_playlistContent.push_back(strdup((const char*)pl));
if(m_playlistContent.size() == 100){ if(m_playlistContent.size() == 100){
ESP_LOGD("", "the maximum number of lines in the playlist has been reached"); ESP_LOGD("", "the maximum number of lines in the playlist has been reached");
break; break;
...@@ -3067,7 +3068,7 @@ bool Audio::parseHttpResponseHeader() { // this is the response to a GET / reque ...@@ -3067,7 +3068,7 @@ bool Audio::parseHttpResponseHeader() { // this is the response to a GET / reque
char rhl[512]; // responseHeaderline char rhl[512]; // responseHeaderline
bool ct_seen = false; bool ct_seen = false;
uint32_t ctime = millis(); uint32_t ctime = millis();
uint32_t timeout = 2000; // ms uint32_t timeout = 5000; // ms
while(true){ // outer while while(true){ // outer while
uint16_t pos = 0; uint16_t pos = 0;
...@@ -3117,7 +3118,7 @@ bool Audio::parseHttpResponseHeader() { // this is the response to a GET / reque ...@@ -3117,7 +3118,7 @@ bool Audio::parseHttpResponseHeader() { // this is the response to a GET / reque
if(sc > 310 || sc == 301){ // e.g. HTTP/1.1 301 Moved Permanently if(sc > 310 || sc == 301){ // e.g. HTTP/1.1 301 Moved Permanently
AUDIO_INFO(rhl); AUDIO_INFO(rhl);
if(audio_showstreamtitle) audio_showstreamtitle(rhl); if(audio_showstreamtitle) audio_showstreamtitle(rhl);
goto exit; // goto exit;
} }
} }
...@@ -3369,7 +3370,8 @@ bool Audio::readMetadata(uint8_t b, bool first) { ...@@ -3369,7 +3370,8 @@ bool Audio::readMetadata(uint8_t b, bool first) {
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool Audio::parseContentType(char* ct) { bool Audio::parseContentType(char* ct) {
enum : int {CT_NONE, CT_MP3, CT_AAC, CT_M4A, CT_WAV, CT_OGG, CT_FLAC, CT_PLS, CT_M3U, CT_ASX, CT_M3U8, CT_TXT}; enum : int {CT_NONE, CT_MP3, CT_AAC, CT_M4A, CT_WAV, CT_OGG, CT_FLAC, CT_PLS, CT_M3U, CT_ASX,
CT_M3U8, CT_TXT, CT_AACP};
strlwr(ct); strlwr(ct);
trim(ct); trim(ct);
...@@ -3385,7 +3387,7 @@ bool Audio::parseContentType(char* ct) { ...@@ -3385,7 +3387,7 @@ bool Audio::parseContentType(char* ct) {
if(!strcmp(ct, "audio/aac")) ct_val = CT_AAC; if(!strcmp(ct, "audio/aac")) ct_val = CT_AAC;
if(!strcmp(ct, "audio/x-aac")) ct_val = CT_AAC; if(!strcmp(ct, "audio/x-aac")) ct_val = CT_AAC;
if(!strcmp(ct, "audio/aacp")) ct_val = CT_AAC; if(!strcmp(ct, "audio/aacp")) ct_val = CT_AACP;
if(!strcmp(ct, "audio/mp4")) ct_val = CT_M4A; if(!strcmp(ct, "audio/mp4")) ct_val = CT_M4A;
if(!strcmp(ct, "audio/m4a")) ct_val = CT_M4A; if(!strcmp(ct, "audio/m4a")) ct_val = CT_M4A;
...@@ -3409,7 +3411,7 @@ bool Audio::parseContentType(char* ct) { ...@@ -3409,7 +3411,7 @@ bool Audio::parseContentType(char* ct) {
if(!strcmp(ct, "text/html")) ct_val = CT_TXT; if(!strcmp(ct, "text/html")) ct_val = CT_TXT;
if(!strcmp(ct, "text/plain")) ct_val = CT_TXT; if(!strcmp(ct, "text/plain")) ct_val = CT_TXT;
if(ct_val == CT_NONE){ if(ct_val == CT_NONE || ct_val == CT_AACP){
AUDIO_INFO("ContentType %s not supported", ct); AUDIO_INFO("ContentType %s not supported", ct);
return false; // nothing valid had been seen return false; // nothing valid had been seen
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment