Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to compile against the new libnetapi.so, radio search functionality restored, crashes fixed #39

Merged
merged 3 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions HttpUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,31 +194,31 @@ HttpUtils::GetAll(BUrl url, BHttpHeaders* responseHeaders, bigtime_t timeOut,
return data;

HttpIOReader reader(data, responseHeaders, sizeLimit);
HttpRequest request(url, false, "HTTP", &reader);
BHttpRequest* request = dynamic_cast<BHttpRequest*>(BUrlProtocolRoster::MakeRequest(url.UrlString().String(), &reader, NULL));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing a "delete request;" at the end of the function to avoid a memory leak.


if (contentType && !contentType->IsEmpty()) {
BHttpHeaders* requestHeaders = new BHttpHeaders();
requestHeaders->AddHeader("accept", contentType->String());
request.AdoptHeaders(requestHeaders);
request->AdoptHeaders(requestHeaders);
}

request.SetAutoReferrer(true);
request.SetFollowLocation(true);
request.SetTimeout(timeOut);
request.SetUserAgent("StreamRadio/0.0.4");
request->SetAutoReferrer(true);
request->SetFollowLocation(true);
request->SetTimeout(timeOut);
request->SetUserAgent("StreamRadio/0.0.4");

thread_id threadId = request.Run();
thread_id threadId = request->Run();
status_t status;
wait_for_thread(threadId, &status);

int32 statusCode = request.Result().StatusCode();
int32 statusCode = ((BHttpResult&)request->Result()).StatusCode();
size_t bufferLen = data->BufferLength();
if (!(statusCode == 0 || request.IsSuccessStatusCode(statusCode))
if (!(statusCode == 0 || request->IsSuccessStatusCode(statusCode))
|| bufferLen == 0) {
delete data;
data = NULL;
} else if (contentType != NULL)
contentType->SetTo(request.Result().ContentType());
contentType->SetTo(request->Result().ContentType());

return data;
}
Expand All @@ -230,23 +230,23 @@ HttpUtils::GetStreamHeader(BUrl url, BHttpHeaders* responseHeaders)
status_t status;
HttpIOReader reader(NULL, responseHeaders, 0);

HttpRequest request(url, false, "HTTP", &reader);
request.SetMethod("GET");
request.SetAutoReferrer(true);
request.SetFollowLocation(true);
request.SetTimeout(10000);
request.SetDiscardData(true);
request.SetUserAgent("StreamRadio/0.0.4");
BHttpRequest* request = dynamic_cast<BHttpRequest*>(BUrlProtocolRoster::MakeRequest(url.UrlString().String(), NULL));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing a delete request; at the end of the function, otherwise this will leak memory.

request->SetMethod("GET");
request->SetAutoReferrer(true);
request->SetFollowLocation(true);
request->SetTimeout(10000);
request->SetDiscardData(true);
request->SetUserAgent("StreamRadio/0.0.4");

BHttpHeaders* requestHeaders = new BHttpHeaders();
requestHeaders->AddHeader("Icy-MetaData", 1);
request.AdoptHeaders(requestHeaders);
request->AdoptHeaders(requestHeaders);

thread_id threadId = request.Run();
thread_id threadId = request->Run();
wait_for_thread(threadId, &status);

if (status == B_OK) {
BHttpResult result = request.Result();
BHttpResult result = (BHttpResult&)request->Result();
if (result.StatusCode() == 200 || result.StatusCode() == B_OK)
*responseHeaders = result.Headers();
else
Expand Down
19 changes: 0 additions & 19 deletions HttpUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,6 @@
#include <StringList.h>
#include <Url.h>


class HttpRequest : public BHttpRequest {
public:
HttpRequest(const BUrl& url, bool ssl = false,
const char* protocolName = "HTTP",
BUrlProtocolListener* listener = NULL, BUrlContext* context = NULL)
:
BHttpRequest(url, ssl, protocolName, listener, context)
{};


virtual BHttpResult&
Result() const
{
return (BHttpResult&)BHttpRequest::Result();
}
};


class HttpUtils {
public:
static status_t CheckPort(BUrl url, BUrl* newUrl,
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ LIBPATHS =
# NOT auto-included here.
SYSTEM_INCLUDE_PATHS = /boot/system/develop/headers/private/media \
/boot/system/develop/headers/private/media/experimental \
/boot/system/develop/headers/private/shared
/boot/system/develop/headers/private/shared \
/boot/system/develop/headers/private/netservices

# Additional paths paths to look for local headers. These use the form
# #include "header". Directories that contain the files in SRCS are
Expand All @@ -114,7 +115,7 @@ LOCALES = ca de en_GB en es ro
# use. For example, setting DEFINES to "DEBUG=1" will cause the compiler
# option "-DDEBUG=1" to be used. Setting DEFINES to "DEBUG" would pass
# "-DDEBUG" on the compiler's command line.
DEFINES =
DEFINES = LIBNETAPI_DEPRECATED

# Specify the warning level. Either NONE (suppress all warnings),
# ALL (enable all warnings), or leave blank (enable default warnings).
Expand Down
22 changes: 11 additions & 11 deletions Station.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,18 +503,18 @@ Station::Load(BString name, BEntry* entry)
archive.Unflatten(archiveBuffer);
free(archiveBuffer);
station->fLogo = (BBitmap*) BBitmap::Instantiate(&archive);
} else
} else {
station->fLogo = new BBitmap(BRect(0, 0, 32, 32), B_RGB32);

status = stationInfo.GetIcon(station->fLogo, B_LARGE_ICON);
if (status != B_OK)
delete station->fLogo;

station->fLogo = new BBitmap(BRect(0, 0, 16, 16), B_RGB32);
status = stationInfo.GetIcon(station->fLogo, B_MINI_ICON);
if (status != B_OK) {
delete station->fLogo;
station->fLogo = NULL;
status = stationInfo.GetIcon(station->fLogo, B_LARGE_ICON);
if (status != B_OK) {
delete station->fLogo;
station->fLogo = new BBitmap(BRect(0, 0, 16, 16), B_RGB32);
status = stationInfo.GetIcon(station->fLogo, B_MINI_ICON);
if (status != B_OK) {
delete station->fLogo;
station->fLogo = NULL;
}
}
}

if (!station->fSource.IsValid()) {
Expand Down
8 changes: 5 additions & 3 deletions StationFinderRadioNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ StationFinderRadioNetwork::FindBy(int capabilityIndex, const char* searchFor,

station->SetUniqueIdentifier(stationMessage.GetString(
"stationuuid", B_EMPTY_STRING));

jsteinaker marked this conversation as resolved.
Show resolved Hide resolved
station->SetName(stationMessage.GetString("name", "unknown"));

station->SetSource(stationMessage.GetString("url",
Expand All @@ -180,8 +180,10 @@ StationFinderRadioNetwork::FindBy(int capabilityIndex, const char* searchFor,

BString iconUrl;
if (stationMessage.FindString("favicon", &iconUrl) == B_OK) {
fIconLookupList.AddItem(
new IconLookup(station, BUrl(iconUrl)));
if (!iconUrl.IsEmpty()) {
fIconLookupList.AddItem(
new IconLookup(station, BUrl(iconUrl)));
}
}

station->SetGenre(stationMessage.GetString("tags",
Expand Down
2 changes: 1 addition & 1 deletion StreamPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ StreamPlayer::StreamPlayer(Station* station, BLooper* notify)

StreamPlayer::~StreamPlayer()
{
_SetState(StreamPlayer::Stopped);
//_SetState(StreamPlayer::Stopped);
if (fInitStatus == B_OK && fPlayer != NULL)
fPlayer->Stop(true, false);

Expand Down