* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * with this program; if not, write to the Free Software Foundation, Inc.,
*/
/* modified for FLAC support by Steven Richman (2003) */
+
+#include "plugin.h"
+
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h>
#include <pthread.h>
#include <xmms/util.h>
#include <xmms/plugin.h>
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "configure.h"
-#include "plugin_common/locale_hack.h"
#include "FLAC/format.h"
-#include "plugin.h"
+#include "configure.h"
+#include "locale_hack.h"
-#ifndef HAVE_SOCKLEN_T
+/* on FreeBSD we get socklen_t from <sys/socket.h> */
+#if (!defined HAVE_SOCKLEN_T) && !defined(__FreeBSD__)
typedef unsigned int socklen_t;
#endif
res = g_strdup_printf("%s: Basic %s\r\n", header, t2);
g_free(t2);
g_free(t1);
-
+
return res;
}
*port = 80;
}
*host = g_strdup(h);
-
+
if (f)
*filename = g_strdup(f + 1);
else
gchar line[1024], *user, *pass, *host, *filename,
*status, *url, *temp, *file;
gchar *chost;
- gint cnt, error, err_len, port, cport;
+ gint cnt, error, port, cport;
+ socklen_t err_len;
gboolean redirect;
int udp_sock = 0;
fd_set set;
do
{
redirect=FALSE;
-
+
g_strstrip(url);
parse_url(url, &user, &pass, &host, &port, &filename);
flac_ip.set_info_text(NULL);
eof = TRUE;
-
+
}
break;
}
if (flac_cfg.stream.use_udp_channel)
{
udp_port = udp_establish_listener (&udp_sock);
- if (udp_port > 0)
- sprintf (udpspace, "x-audiocast-udpport: %d\r\n", udp_port);
+ if (udp_port > 0)
+ flac_snprintf (udpspace, sizeof (udpspace), "x-audiocast-udpport: %d\r\n", udp_port);
else
udp_sock = 0;
}
-
+
if(user && pass)
auth = basic_authentication_encode(user, pass, "Authorization");
"Host: %s\r\n"
"User-Agent: %s/%s\r\n"
"%s%s%s%s",
- file, host, "Reference FLAC Player", FLAC__VERSION_STRING,
+ file, host, "Reference FLAC Player", FLAC__VERSION_STRING,
proxy_auth ? proxy_auth : "", auth ? auth : "",
flac_cfg.stream.cast_title_streaming ? "Icy-MetaData:1\r\n" : "",
flac_cfg.stream.use_udp_channel ? udpspace : "");
if (offset && !head) {
gchar *temp_dead = temp;
- temp = g_strconcat ("%sRange: %ll-\r\n", temp, offset);
- fprintf (stderr, "%s", temp);
+ temp = g_strdup_printf ("%sRange: %" PRIu64 "-\r\n", temp, offset);
+ fputs (temp, stderr);
g_free (temp_dead);
}
-
+
g_free(file);
if(proxy_auth)
g_free(proxy_auth);
break;
}
}
- }
+ }
redirect=TRUE;
break;
}
#endif
/*udp_serverport = atoi (line + 20);*/
}
-
+
}
else
{
}
}
}
-
+
if(redirect)
{
if (output_file)
url = (gchar *) arg;
sock = http_connect (url, false, offset);
-
+
if (sock >= 0 && flac_cfg.stream.save_http_stream) {
gchar *output_name;
file = flac_http_get_title(url);
g_free(buffer);
g_free(url);
-
+
pthread_exit(NULL);
return NULL; /* avoid compiler warning */
}
-int flac_http_open(gchar * _url, guint64 _offset)
+int flac_http_open(const gchar * _url, guint64 _offset)
{
gchar *url;
{
struct sockaddr_in sin;
socklen_t sinlen = sizeof (struct sockaddr_in);
-
+
#ifdef DEBUG_UDP
fprintf (stderr,"Establishing udp listener\n");
#endif
-
+
if ((*sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
g_log(NULL, G_LOG_LEVEL_CRITICAL,
memset(&sin, 0, sinlen);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = g_htonl(INADDR_ANY);
-
+
if (bind(*sock, (struct sockaddr *)&sin, sinlen) < 0)
{
g_log(NULL, G_LOG_LEVEL_CRITICAL,
#ifdef DEBUG_UDP
fprintf (stderr,"Listening on local %s:%d\n", inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port));
#endif
-
+
return g_ntohs(sin.sin_port);
}
socklen_t fromlen;
fromlen = sizeof(struct sockaddr_in);
-
+
if ((len = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen)) < 0)
{
if (errno != EAGAIN)
lines = g_strsplit(buf, "\n", 0);
if (!lines)
return 0;
-
+
for (i = 0; lines[i]; i++)
{
while ((lines[i][strlen(lines[i]) - 1] == '\n') ||
(lines[i][strlen(lines[i]) - 1] == '\r'))
lines[i][strlen(lines[i]) - 1] = '\0';
-
+
valptr = strchr(lines[i], ':');
-
+
if (!valptr)
continue;
else
valptr++;
-
+
g_strstrip(valptr);
if (!strlen(valptr))
continue;
-
+
if (strstr(lines[i], "x-audiocast-streamtitle") != NULL)
{
title = g_strdup_printf ("%s (%s)", valptr, icy_name);
set_track_info(NULL, atoi(valptr));
}
#endif
-
+
else if (strstr(lines[i], "x-audiocast-streammsg") != NULL)
{
/* set_track_info(title, -1); */
else if (strstr(lines[i], "x-audiocast-udpseqnr:") != NULL)
{
gchar obuf[60];
- sprintf(obuf, "x-audiocast-ack: %ld \r\n", atol(valptr));
+ flac_snprintf(obuf, sizeof (obuf), "x-audiocast-ack: %ld \r\n", atol(valptr));
if (sendto(sock, obuf, strlen(obuf), 0, (struct sockaddr *) &from, fromlen) < 0)
{
g_log(NULL, G_LOG_LEVEL_WARNING,