Commit 5355017a authored by Philipp Schafft's avatar Philipp Schafft 🦁

Update: Added client_protocol_from_string() and client_protocol_to_string()

parent 22513650
......@@ -687,17 +687,7 @@ static inline xmlNodePtr __add_listener(client_t *client,
xmlNewTextChild(node, NULL, XMLSTR("tls"), XMLSTR(client->con->tls ? "true" : "false"));
switch (client->protocol) {
case ICECAST_PROTOCOL_HTTP:
xmlNewTextChild(node, NULL, XMLSTR("protocol"), XMLSTR("http"));
break;
case ICECAST_PROTOCOL_SHOUTCAST:
xmlNewTextChild(node, NULL, XMLSTR("protocol"), XMLSTR("icy"));
break;
case ICECAST_PROTOCOL_GOPHER:
xmlNewTextChild(node, NULL, XMLSTR("protocol"), XMLSTR("gopher"));
break;
}
xmlNewTextChild(node, NULL, XMLSTR("protocol"), XMLSTR(client_protocol_to_string(client->protocol)));
return node;
}
......
......@@ -57,6 +57,45 @@
static inline void client_send_500(client_t *client, const char *message);
/* This returns the protocol ID based on the string.
* If the string is invalid for any reason we return ICECAST_PROTOCOL_HTTP.
*/
protocol_t client_protocol_from_string(const char *str)
{
if (!str) {
ICECAST_LOG_ERROR("No protocol string given. Returning ICECAST_PROTOCOL_HTTP.");
return ICECAST_PROTOCOL_HTTP;
}
if (strcasecmp(str, "http") == 0) {
return ICECAST_PROTOCOL_HTTP;
} else if (strcasecmp(str, "icy") == 0 || strcasecmp(str, "shoutcast") == 0) {
return ICECAST_PROTOCOL_SHOUTCAST;
} else if (strcasecmp(str, "gopher") == 0) {
return ICECAST_PROTOCOL_GOPHER;
} else {
ICECAST_LOG_ERROR("Unknown protocol \"%H\" string given. Returning ICECAST_PROTOCOL_HTTP.", str);
return ICECAST_PROTOCOL_HTTP;
}
}
const char * client_protocol_to_string(protocol_t protocol)
{
switch (protocol) {
case ICECAST_PROTOCOL_HTTP:
return "http";
break;
case ICECAST_PROTOCOL_SHOUTCAST:
return "icy";
break;
case ICECAST_PROTOCOL_GOPHER:
return "gopher";
break;
}
return NULL;
}
/* create a client_t with the provided connection and parser details. Return
* 0 on success, -1 if server limit has been reached. In either case a
* client_t is returned just in case a message needs to be returned. Should
......
......@@ -113,6 +113,9 @@ struct _client_tag {
int (*check_buffer)(source_t *source, client_t *client);
};
protocol_t client_protocol_from_string(const char *str);
const char * client_protocol_to_string(protocol_t protocol);
int client_create (client_t **c_ptr, connection_t *con, http_parser_t *parser);
void client_destroy(client_t *client);
void client_send_error_by_id(client_t *client, icecast_error_id_t id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment