1 /* -*- c-basic-offset: 8; -*- */
2 /* proto_icy.c: Implementation of protocol ICY.
3  *
4  *  Copyright (C) 2002-2004 the Icecast team <team@icecast.org>,
5  *  Copyright (C) 2012-2019 Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
6  *
7  *  This library is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU Library General Public
9  *  License as published by the Free Software Foundation; either
10  *  version 2 of the License, or (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Library General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Library General Public
18  *  License along with this library; if not, write to the Free
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  * $Id$
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #   include <config.h>
26 #endif
27 
28 #include <shout/shout.h>
29 #include "shout_private.h"
30 
shout_create_icy_request_poke(shout_t * self,shout_connection_t * connection)31 static int shout_create_icy_request_poke(shout_t *self, shout_connection_t *connection)
32 {
33     if (shout_queue_printf(connection, "!POKE\nicy-name:libshout server poke request\n\n")) {
34         return SHOUTERR_MALLOC;
35     } else {
36         return SHOUTERR_SUCCESS;
37     }
38 }
39 
shout_create_icy_request_real(shout_t * self,shout_connection_t * connection)40 static int shout_create_icy_request_real(shout_t *self, shout_connection_t *connection)
41 {
42     const char *bitrate;
43     const char *val;
44     int         ret;
45 
46     bitrate = shout_get_audio_info(self, SHOUT_AI_BITRATE);
47 	if (!bitrate)
48         bitrate = "0";
49 
50     ret = SHOUTERR_MALLOC;
51     do {
52 		if (shout_queue_printf(connection, "%s\n", self->password))
53             break;
54 		if (shout_queue_printf(connection, "icy-name:%s\n", shout_get_meta(self, "name")))
55             break;
56         val = shout_get_meta(self, "url");
57 		if (shout_queue_printf(connection, "icy-url:%s\n", val ? val : "http://www.icecast.org/"))
58             break;
59         val = shout_get_meta(self, "irc");
60 		if (shout_queue_printf(connection, "icy-irc:%s\n", val ? val : ""))
61             break;
62         val = shout_get_meta(self, "aim");
63 		if (shout_queue_printf(connection, "icy-aim:%s\n", val ? val : ""))
64             break;
65         val = shout_get_meta(self, "icq");
66 		if (shout_queue_printf(connection, "icy-icq:%s\n", val ? val : ""))
67             break;
68 		if (shout_queue_printf(connection, "icy-pub:%i\n", self->public))
69             break;
70         val = shout_get_meta(self, "genre");
71 		if (shout_queue_printf(connection, "icy-genre:%s\n", val ? val : "icecast"))
72             break;
73 		if (shout_queue_printf(connection, "icy-br:%s\n\n", bitrate))
74             break;
75 
76         ret = SHOUTERR_SUCCESS;
77     } while (0);
78 
79     return ret;
80 }
81 
shout_create_icy_request(shout_t * self,shout_connection_t * connection)82 shout_connection_return_state_t shout_create_icy_request(shout_t *self, shout_connection_t *connection)
83 {
84     int ret;
85 
86     if (connection->server_caps & LIBSHOUT_CAP_GOTCAPS) {
87         ret = shout_create_icy_request_real(self, connection);
88     } else {
89         ret = shout_create_icy_request_poke(self, connection);
90     }
91 
92     shout_connection_set_error(connection, ret);
93     return ret == SHOUTERR_SUCCESS ? SHOUT_RS_DONE : SHOUT_RS_ERROR;
94 }
95 
96 static const shout_protocol_impl_t shout_icy_impl_real = {
97     .msg_create = shout_create_icy_request,
98     .msg_get = shout_get_xaudiocast_response,
99     .msg_parse = shout_parse_xaudiocast_response
100 };
101 const shout_protocol_impl_t *shout_icy_impl = &shout_icy_impl_real;
102