| 1 |
/* |
| 2 |
net123: network (HTTP(S)) streaming for mpg123 using external code |
| 3 |
|
| 4 |
copyright 2022 by the mpg123 project -- |
| 5 |
free software under the terms of the LGPL 2.1, |
| 6 |
see COPYING and AUTHORS files in distribution or http://mpg123.org |
| 7 |
initially written by Thomas Orgis |
| 8 |
|
| 9 |
This is supposed to be a binding to some system facilty to |
| 10 |
get HTTP/HTTPS streaming going. The goal is to not be responsible |
| 11 |
for HTTP protocol handling or even TLS in mpg123 code. |
| 12 |
Maybe this could also stream via other protocols ... maybe even |
| 13 |
SSH, whatever. |
| 14 |
|
| 15 |
For POSIX platforms, this shall refer to external binaries that |
| 16 |
do all the network stuff. For others, some system library or |
| 17 |
other facility shall provide the minimal required functionality. |
| 18 |
|
| 19 |
We could support seeking using HTTP ranges. But the first step is |
| 20 |
to be able to just make a request to a certain URL and get the |
| 21 |
server response headers followed by the data (be it a playlist file |
| 22 |
or the MPEG stream itself). |
| 23 |
|
| 24 |
We need to support: |
| 25 |
- client headers (ICY yes or no, client name) |
| 26 |
- HTTP auth parameters |
| 27 |
|
| 28 |
The idea is that this just handles the network and protocol part |
| 29 |
of fetching data from an URL, returning |
| 30 |
|
| 31 |
<server response headers> |
| 32 |
<empty line> |
| 33 |
<stream data> |
| 34 |
|
| 35 |
via net123_read(). Header part is with <cr><lf>, just passing through |
| 36 |
what the server gives should be OK. The only HTTP thing mpg123 shall do |
| 37 |
is to parse headers. |
| 38 |
*/ |
| 39 |
#ifndef _MPG123_NET123_H_ |
| 40 |
#define _MPG123_NET123_H_ |
| 41 |
|
| 42 |
#include "config.h" |
| 43 |
#include <sys/types.h> |
| 44 |
|
| 45 |
// stream handle for differing implementations, build-time plugins |
| 46 |
struct net123_handle_struct |
| 47 |
{ |
| 48 |
void *parts; // custom internal data |
| 49 |
// callbacks |
| 50 |
size_t (*read)(struct net123_handle_struct *nh, void *buf, size_t bufsize); |
| 51 |
void (*close)(struct net123_handle_struct *nh); |
| 52 |
}; |
| 53 |
typedef struct net123_handle_struct net123_handle; |
| 54 |
|
| 55 |
extern const char *net123_backends[]; |
| 56 |
|
| 57 |
// Open stream from URL, preparing output such that net123_read() |
| 58 |
// later on gets the response header lines followed by one empty line |
| 59 |
// and then the raw data. |
| 60 |
// client_head contains header lines to send with the request, without |
| 61 |
// line ending |
| 62 |
|
| 63 |
// Variant for the external binding. |
| 64 |
#ifdef NET123_EXEC |
| 65 |
net123_handle *net123_open_exec(const char *url, const char * const *client_head); |
| 66 |
#endif |
| 67 |
#ifdef NET123_WININET |
| 68 |
net123_handle *net123_open_wininet(const char *url, const char * const *client_head); |
| 69 |
#endif |
| 70 |
#ifdef NET123_WINHTTP |
| 71 |
net123_handle *net123_open_winhttp(const char *url, const char * const *client_head); |
| 72 |
#endif |
| 73 |
|
| 74 |
#endif |