2001-09-09 22:21:46 -04:00
|
|
|
/* format.c
|
|
|
|
**
|
|
|
|
** format plugin implementation
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
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"
|
|
|
|
|
|
|
|
#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 10:46:32 -05:00
|
|
|
#include "log.h"
|
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
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-04 02:08:52 -05:00
|
|
|
format_plugin_t *format_get_plugin(format_type_t type, char *mount)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
|
|
|
format_plugin_t *plugin;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case FORMAT_TYPE_VORBIS:
|
|
|
|
plugin = format_vorbis_get_plugin();
|
2002-02-04 02:08:52 -05:00
|
|
|
if (plugin) plugin->mount = mount;
|
2001-09-09 22:21:46 -04:00
|
|
|
break;
|
2002-07-23 11:15:11 -04:00
|
|
|
case FORMAT_TYPE_MP3:
|
|
|
|
plugin = format_mp3_get_plugin();
|
|
|
|
if (plugin) plugin->mount = mount;
|
|
|
|
break;
|
2001-09-09 22:21:46 -04:00
|
|
|
default:
|
|
|
|
plugin = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return plugin;
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
if (strcasecmp(var->name, "ice-password") &&
|
|
|
|
(!strncasecmp("ice-", var->name, 4) ||
|
|
|
|
!strncasecmp("icy-", 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;
|
|
|
|
}
|
|
|
|
node = avl_get_next(node);
|
|
|
|
}
|
|
|
|
avl_tree_unlock(source->parser->vars);
|
|
|
|
}
|
|
|
|
|