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;
|
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)
|
|
|
|
{
|
|
|
|
int ret;
|
2003-02-24 08:37:15 -05:00
|
|
|
|
2002-12-29 03:10:10 -05:00
|
|
|
ret = sock_write_bytes(client->con->sock, buf, len);
|
|
|
|
|
|
|
|
if(ret < 0) {
|
2003-01-18 07:30:29 -05:00
|
|
|
if(sock_recoverable(sock_error())) {
|
2002-12-29 03:10:10 -05:00
|
|
|
DEBUG1("Client had recoverable error %ld", ret);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
client->con->sent_bytes += ret;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
while (node) {
|
|
|
|
var = (http_var_t *)node->key;
|
2003-07-02 21:39:59 -04:00
|
|
|
if (strcasecmp(var->name, "ice-password") &&
|
2003-07-06 11:27:50 -04:00
|
|
|
(!strncasecmp("ice-", var->name, 4))) {
|
|
|
|
bytes = sock_write(client->con->sock,
|
|
|
|
"%s: %s\r\n", var->name, 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
|
|
|
}
|
|
|
|
|