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
|
|
|
|
2004-12-17 19:11:56 -05:00
|
|
|
#include "format_ogg.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"
|
2004-11-11 10:47:33 -05:00
|
|
|
#include "stats.h"
|
2002-12-29 03:10:10 -05:00
|
|
|
#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)
|
2004-12-07 16:06:26 -05:00
|
|
|
return FORMAT_TYPE_OGG; /* Backwards compatibility */
|
2003-02-11 07:18:22 -05:00
|
|
|
else if(strcmp(contenttype, "application/ogg") == 0)
|
2004-12-07 16:06:26 -05:00
|
|
|
return FORMAT_TYPE_OGG; /* Now blessed by IANA */
|
2005-05-30 22:48:40 -04:00
|
|
|
else
|
2004-11-18 18:49:59 -05:00
|
|
|
/* We default to the Generic format handler, which
|
|
|
|
can handle many more formats than just mp3 */
|
2005-05-30 22:48:40 -04:00
|
|
|
return FORMAT_TYPE_GENERIC;
|
2002-07-24 09:55:12 -04:00
|
|
|
}
|
|
|
|
|
2004-08-20 11:13:59 -04:00
|
|
|
int format_get_plugin(format_type_t type, source_t *source)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2004-08-20 11:13:59 -04:00
|
|
|
int ret = -1;
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
switch (type) {
|
2004-12-07 16:06:26 -05:00
|
|
|
case FORMAT_TYPE_OGG:
|
|
|
|
ret = format_ogg_get_plugin (source);
|
2003-03-14 21:10:19 -05:00
|
|
|
break;
|
2004-11-18 18:49:59 -05:00
|
|
|
case FORMAT_TYPE_GENERIC:
|
2004-11-11 10:47:33 -05:00
|
|
|
ret = format_mp3_get_plugin (source);
|
|
|
|
break;
|
2003-03-14 21:10:19 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-11-19 21:16:59 -05:00
|
|
|
if (ret < 0)
|
|
|
|
stats_event (source->mount, "content-type",
|
|
|
|
source->format->contenttype);
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2004-08-20 11:13:59 -04:00
|
|
|
return ret;
|
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
|
|
|
}
|
|
|
|
|