Skip to content

nxplayer: add more error messages #3116

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

Closed
wants to merge 1 commit into from
Closed
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
59 changes: 46 additions & 13 deletions system/nxplayer/nxplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
n = netlib_parsehttpurl(fullurl, &port,
hostname, sizeof(hostname) - 1,
relurl, sizeof(relurl) - 1);

if (OK != n)
{
printf("netlib_parsehttpurl() returned %d\n", n);
Expand All @@ -221,18 +220,30 @@

FAR struct hostent *he;
he = gethostbyname(hostname);
if (!he)
{
close(s);

// DNS resolution failed

Check failure on line 227 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

C++ style comment

Check failure on line 227 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

C++ style comment
return -ENETUNREACH;
}

memcpy(&server.sin_addr.s_addr,
he->h_addr, sizeof(in_addr_t));

n = connect(s,
(struct sockaddr *)&server,
sizeof(struct sockaddr_in));

if (-1 == n)
{
int err = errno;
close(s);
return -1;
switch (err)
{
case ETIMEDOUT: return -ETIMEDOUT;

Check failure on line 242 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line

Check failure on line 242 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line
case ECONNREFUSED: return -ECONNREFUSED;

Check failure on line 243 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line

Check failure on line 243 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line
case ENETUNREACH: return -ENETUNREACH;

Check failure on line 244 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line

Check failure on line 244 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line
default: return -1;

Check failure on line 245 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line

Check failure on line 245 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line
}
}

/* Send GET request */
Expand All @@ -250,8 +261,24 @@

if (200 != n)
{
int err = errno;
close(s);
return -1;
switch (err)
{
// Unauthorized

Check failure on line 268 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found

Check failure on line 268 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

C++ style comment

Check failure on line 268 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found

Check failure on line 268 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

C++ style comment
case 401: return -EACCES;

Check failure on line 269 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line

Check failure on line 269 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Case statement should be on a new line

// No access

Check failure on line 271 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found

Check failure on line 271 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

C++ style comment

Check failure on line 271 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

Mixed case identifier found

Check failure on line 271 in system/nxplayer/nxplayer.c

View workflow job for this annotation

GitHub Actions / check

C++ style comment
case 403: return -EACCES;

case 404: return -ENOENT;

// Server internal error
case 500: return -EREMOTEIO;

// Other protocol errors
default: return -EPROTO;
}
}

/* Skip response header */
Expand Down Expand Up @@ -1809,11 +1836,15 @@
/* Test that the specified file exists */

#ifdef CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT
if ((pplayer->fd = _open_with_http(pfilename)) == -1)
pplayer->fd = _open_with_http(pfilename);
if (pplayer->fd < 0)
#else
if ((pplayer->fd = open(pfilename, O_RDONLY)) == -1)
pplayer->fd = open(pfilename, O_RDONLY);
if (pplayer->fd == -1)
#endif
{
int err = errno;

/* File not found. Test if its in the mediadir */

#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
Expand All @@ -1827,19 +1858,21 @@
if (nxplayer_mediasearch(pplayer, pfilename, path,
sizeof(path)) != OK)
{
auderr("ERROR: Could not find file\n");
return -ENOENT;
auderr("ERROR: Media search failed for %s: %s\n",
pfilename, strerror(err));
return -err;
}
#else
auderr("ERROR: Could not open %s or %s\n", pfilename, path);
return -ENOENT;
auderr("ERROR: Could not open %s or %s: %s\n",
pfilename, path, strerror(err));
return -err;
#endif /* CONFIG_NXPLAYER_MEDIA_SEARCH */
}

#else /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */

auderr("ERROR: Could not open %s\n", pfilename);
return -ENOENT;
auderr("ERROR: Could not open %s: %s\n", pfilename, strerror(err));
return -err;
#endif /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
}

Expand Down
16 changes: 16 additions & 0 deletions system/nxplayer/nxplayer_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,22 @@ static int nxplayer_cmd_play(FAR struct nxplayer_s *pplayer, char *parg)
printf("File %s not found\n", parg);
break;

case ENETUNREACH:
printf("DNS resolution failed\n");
break;

case ETIMEDOUT:
printf("Timeout\n");
break;

case EACCES:
printf("No access\n");
break;

case ECONNREFUSED:
printf("Connect refused\n");
break;

case ENOSYS:
printf("Unknown audio format\n");
break;
Expand Down
Loading