2004-01-28 20:02:12 -05:00
|
|
|
/* Icecast
|
|
|
|
*
|
|
|
|
* This program is distributed under the GNU General Public License, version 2.
|
|
|
|
* A copy of this license is included with this source.
|
|
|
|
*
|
|
|
|
* Copyright 2000-2004, Jack Moffitt <jack@xiph.org,
|
|
|
|
* Michael Smith <msmith@xiph.org>,
|
|
|
|
* oddsock <oddsock@xiph.org>,
|
|
|
|
* Karl Heyes <karl@xiph.org>
|
|
|
|
* and others (see AUTHORS for details).
|
|
|
|
*/
|
|
|
|
|
2003-07-02 21:39:59 -04:00
|
|
|
/* -*- c-basic-offset: 4; -*- */
|
2001-09-09 22:21:46 -04:00
|
|
|
/* format.c
|
|
|
|
**
|
|
|
|
** format plugin implementation
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2003-07-20 21:58:54 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-09-09 22:21:46 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2003-07-22 20:27:10 -04:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-10-20 02:43:04 -04:00
|
|
|
#include <time.h>
|
2001-09-09 22:21:46 -04:00
|
|
|
|
|
|
|
#include "connection.h"
|
|
|
|
#include "refbuf.h"
|
|
|
|
|
2002-12-30 02:55:56 -05:00
|
|
|
#include "source.h"
|
2001-09-09 22:21:46 -04:00
|
|
|
#include "format.h"
|
2003-02-11 09:23:34 -05:00
|
|
|
#include "global.h"
|
2003-07-16 15:41:59 -04:00
|
|
|
#include "httpp/httpp.h"
|
2001-09-09 22:21:46 -04:00
|
|
|
|
|
|
|
#include "format_vorbis.h"
|
2002-07-23 11:15:11 -04:00
|
|
|
#include "format_mp3.h"
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2002-12-29 03:10:10 -05:00
|
|
|
#include "logging.h"
|
|
|
|
#define CATMODULE "format"
|
2002-12-31 15:15:03 -05:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#define strcasecmp stricmp
|
|
|
|
#define strncasecmp strnicmp
|
|
|
|
#endif
|
2002-12-29 03:10:10 -05:00
|
|
|
|
2002-02-11 04:11:18 -05:00
|
|
|
format_type_t format_get_type(char *contenttype)
|
|
|
|
{
|
|
|
|
if(strcmp(contenttype, "application/x-ogg") == 0)
|
2003-02-11 07:18:22 -05:00
|
|
|
return FORMAT_TYPE_VORBIS; /* Backwards compatibility */
|
|
|
|
else if(strcmp(contenttype, "application/ogg") == 0)
|
|
|
|
return FORMAT_TYPE_VORBIS; /* Now blessed by IANA */
|
2002-07-23 11:15:11 -04:00
|
|
|
else if(strcmp(contenttype, "audio/mpeg") == 0)
|
|
|
|
return FORMAT_TYPE_MP3;
|
2004-05-10 22:24:18 -04:00
|
|
|
else if(strcmp(contenttype, "audio/x-mpeg") == 0)
|
|
|
|
return FORMAT_TYPE_MP3; /* Relay-compatibility for some servers */
|
2002-02-11 04:11:18 -05:00
|
|
|
else
|
2003-02-14 05:31:21 -05:00
|
|
|
return FORMAT_ERROR;
|
2002-02-11 04:11:18 -05:00
|
|
|
}
|
|
|
|
|
2002-07-24 09:55:12 -04:00
|
|
|
char *format_get_mimetype(format_type_t type)
|
|
|
|
{
|
|
|
|
switch(type) {
|
|
|
|
case FORMAT_TYPE_VORBIS:
|
2003-02-11 07:18:22 -05:00
|
|
|
return "application/ogg";
|
2002-07-24 09:55:12 -04:00
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_MP3:
|
|
|
|
return "audio/mpeg";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-17 07:05:45 -05:00
|
|
|
format_plugin_t *format_get_plugin(format_type_t type, char *mount,
|
|
|
|
http_parser_t *parser)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
format_plugin_t *plugin;
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
switch (type) {
|
|
|
|
case FORMAT_TYPE_VORBIS:
|
|
|
|
plugin = format_vorbis_get_plugin();
|
|
|
|
if (plugin) plugin->mount = mount;
|
|
|
|
break;
|
2002-07-23 11:15:11 -04:00
|
|
|
case FORMAT_TYPE_MP3:
|
2003-02-17 07:05:45 -05:00
|
|
|
plugin = format_mp3_get_plugin(parser);
|
2002-07-23 11:15:11 -04:00
|
|
|
if (plugin) plugin->mount = mount;
|
|
|
|
break;
|
2003-03-14 21:10:19 -05:00
|
|
|
default:
|
|
|
|
plugin = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
return plugin;
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
2002-12-29 03:10:10 -05:00
|
|
|
|
|
|
|
int format_generic_write_buf_to_client(format_plugin_t *format,
|
|
|
|
client_t *client, unsigned char *buf, int len)
|
|
|
|
{
|
2004-07-16 11:47:12 -04:00
|
|
|
return client_send_bytes (client, buf, len);
|
2002-12-29 03:10:10 -05:00
|
|
|
}
|
|
|
|
|
2002-12-30 02:55:56 -05:00
|
|
|
void format_send_general_headers(format_plugin_t *format,
|
|
|
|
source_t *source, client_t *client)
|
|
|
|
{
|
|
|
|
http_var_t *var;
|
|
|
|
avl_node *node;
|
|
|
|
int bytes;
|
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
/* iterate through source http headers and send to client */
|
|
|
|
avl_tree_rlock(source->parser->vars);
|
|
|
|
node = avl_get_first(source->parser->vars);
|
2004-02-02 19:29:36 -05:00
|
|
|
while (node)
|
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
var = (http_var_t *)node->key;
|
2004-02-02 19:29:36 -05:00
|
|
|
if (!strcasecmp(var->name, "ice-audio-info")) {
|
|
|
|
/* convert ice-audio-info to icy-br */
|
|
|
|
char *brfield;
|
|
|
|
unsigned int bitrate;
|
|
|
|
|
|
|
|
brfield = strstr(var->value, "bitrate=");
|
|
|
|
if (brfield && sscanf(var->value, "bitrate=%u", &bitrate)) {
|
|
|
|
bytes = sock_write(client->con->sock, "icy-br:%u\r\n", bitrate);
|
|
|
|
if (bytes > 0)
|
|
|
|
client->con->sent_bytes += bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strcasecmp(var->name, "ice-password") &&
|
|
|
|
strcasecmp(var->name, "icy-metaint"))
|
|
|
|
{
|
|
|
|
bytes = 0;
|
|
|
|
if (!strncasecmp("ice-", var->name, 4))
|
|
|
|
{
|
|
|
|
if (!strcasecmp("ice-bitrate", var->name))
|
|
|
|
bytes += sock_write(client->con->sock, "icy-br:%s\r\n", var->value);
|
|
|
|
else
|
2004-05-03 10:55:44 -04:00
|
|
|
if (!strcasecmp("ice-public", var->name))
|
|
|
|
bytes += sock_write(client->con->sock,
|
|
|
|
"icy-pub:%s\r\n", var->value);
|
|
|
|
else
|
|
|
|
bytes = sock_write(client->con->sock, "icy%s:%s\r\n",
|
|
|
|
var->name + 3, var->value);
|
2004-02-02 19:29:36 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
if (!strncasecmp("icy-", var->name, 4))
|
|
|
|
{
|
|
|
|
bytes = sock_write(client->con->sock, "icy%s:%s\r\n",
|
|
|
|
var->name + 3, var->value);
|
|
|
|
}
|
|
|
|
if (bytes > 0)
|
|
|
|
client->con->sent_bytes += bytes;
|
|
|
|
}
|
2003-03-14 21:10:19 -05:00
|
|
|
}
|
|
|
|
node = avl_get_next(node);
|
|
|
|
}
|
|
|
|
avl_tree_unlock(source->parser->vars);
|
2003-02-14 08:17:38 -05:00
|
|
|
bytes = sock_write(client->con->sock,
|
|
|
|
"Server: %s\r\n", ICECAST_VERSION_STRING);
|
|
|
|
if(bytes > 0) client->con->sent_bytes += bytes;
|
2002-12-30 02:55:56 -05:00
|
|
|
}
|
|
|
|
|