[xiph-commits] r8359 - in trunk/icecast2yp: . sql src
oddsock at motherfish-iii.xiph.org
oddsock at motherfish-iii.xiph.org
Thu Dec 9 11:03:20 PST 2004
Author: oddsock
Date: 2004-12-09 11:03:20 -0800 (Thu, 09 Dec 2004)
New Revision: 8359
Modified:
trunk/icecast2yp/Makefile.am
trunk/icecast2yp/configure.in
trunk/icecast2yp/sql/reset_db.sql
trunk/icecast2yp/src/Makefile.am
trunk/icecast2yp/src/log.h
trunk/icecast2yp/src/yp_cgi.c
trunk/icecast2yp/src/yp_clean.c
trunk/icecast2yp/src/yp_routines.c
Log:
update the YP cgi to support clustering of relays
Modified: trunk/icecast2yp/Makefile.am
===================================================================
--- trunk/icecast2yp/Makefile.am 2004-12-09 17:08:52 UTC (rev 8358)
+++ trunk/icecast2yp/Makefile.am 2004-12-09 19:03:20 UTC (rev 8359)
@@ -10,3 +10,6 @@
profile:
$(MAKE) all CFLAGS="@PROFILE@"
+static:
+ $(MAKE) all LDFLAGS="${LDFLAGS} -all-static"
+
Modified: trunk/icecast2yp/configure.in
===================================================================
--- trunk/icecast2yp/configure.in 2004-12-09 17:08:52 UTC (rev 8358)
+++ trunk/icecast2yp/configure.in 2004-12-09 19:03:20 UTC (rev 8359)
@@ -1,4 +1,4 @@
-AC_INIT([icecast2_yp], [0.1.0], [icecast at xiph.org])
+AC_INIT([icecast2_yp], [0.2.0], [icecast at xiph.org])
AC_CANONICAL_HOST
AC_PREREQ(2.54)
Modified: trunk/icecast2yp/sql/reset_db.sql
===================================================================
--- trunk/icecast2yp/sql/reset_db.sql 2004-12-09 17:08:52 UTC (rev 8358)
+++ trunk/icecast2yp/sql/reset_db.sql 2004-12-09 19:03:20 UTC (rev 8359)
@@ -1,8 +1,10 @@
-use oddsock;
-drop table listens;
-drop table server_details;
-drop table servers;
-drop table servers_touch;
+use icecast2_yp;
+DROP TABLE if exists server_details;
+DROP TABLE if exists servers_touch;
+DROP TABLE if exists servers;
+DROP TABLE if exists clusters;
+DROP TABLE if exists playlists;
+DROP TABLE if exists listens;
-- MySQL dump 9.08
--
@@ -14,7 +16,7 @@
-- Table structure for table 'listens'
--
-CREATE TABLE listens (
+CREATE TABLE if not exists listens (
listen_ip varchar(25) default NULL,
server_name varchar(100) default NULL,
listen_time timestamp(14) NOT NULL
@@ -24,7 +26,7 @@
-- Table structure for table 'server_details'
--
-CREATE TABLE server_details (
+CREATE TABLE if not exists server_details (
id mediumint(9) NOT NULL auto_increment,
parent_id mediumint(9) default NULL,
server_name varchar(100) default NULL,
@@ -36,6 +38,7 @@
url varchar(255) default NULL,
current_song varchar(255) default NULL,
listen_url varchar(200) default NULL,
+ playlist_id mediumint(9) default NULL,
server_type varchar(25) default NULL,
bitrate varchar(25) default NULL,
listeners int(11) default NULL,
@@ -44,11 +47,23 @@
PRIMARY KEY (id)
) TYPE=MyISAM;
+create table if not exists playlists (
+ id mediumint(9) NOT NULL,
+ listen_url varchar(200) default NULL
+) TYPE=MyISAM;
+
+create table if not exists clusters (
+ id mediumint(9) NOT NULL auto_increment,
+ server_name varchar(255) default NULL,
+ cluster_password varchar(50) default NULL,
+ PRIMARY KEY (id)
+) TYPE=MyISAM;
+
--
-- Table structure for table 'servers'
--
-CREATE TABLE servers (
+CREATE TABLE if not exists servers (
id mediumint(9) NOT NULL auto_increment,
server_name varchar(100) default NULL,
listing_ip varchar(25) default NULL,
@@ -61,7 +76,7 @@
-- Table structure for table 'servers_touch'
--
-CREATE TABLE servers_touch (
+CREATE TABLE if not exists servers_touch (
id varchar(200) NOT NULL default '',
server_name varchar(100) default NULL,
listing_ip varchar(25) default NULL,
Modified: trunk/icecast2yp/src/Makefile.am
===================================================================
--- trunk/icecast2yp/src/Makefile.am 2004-12-09 17:08:52 UTC (rev 8358)
+++ trunk/icecast2yp/src/Makefile.am 2004-12-09 19:03:20 UTC (rev 8359)
@@ -2,7 +2,7 @@
AUTOMAKE_OPTIONS = foreign
-EXTRA_DIST= iconv_string.h log.h yp_db.h yp_routines.h run_cachegen.sh
+EXTRA_DIST= log.h yp_db.h yp_routines.h run_cachegen.sh
bin_PROGRAMS = yp_cgi yp_cachegen yp_clean yp_random
@@ -12,11 +12,13 @@
yp_clean_SOURCES = yp_clean.c log.c yp_routines.c
yp_random_SOURCES = yp_random.c log.c yp_routines.c
-CFLAGS = @CFLAGS@ @MYSQL_CFLAGS@ @XML_CPPFLAGS@ -I${prefix}/include
-CPPFLAGS = @CPPFLAGS@ @MYSQL_CFLAGS@ @XML_CPPFLAGS@ -I${prefix}/include
+CFLAGS = @CFLAGS@ @MYSQL_CFLAGS@ @XML_CFLAGS@ -I${prefix}/include
LIBS = @LIBS@ @MYSQL_LIBS@ @XML_LIBS@ -L${prefix}/lib
+static:
+ $(MAKE) all LDFLAGS="${LDFLAGS} -all-static"
+
debug:
$(MAKE) all CFLAGS="@DEBUG@"
Modified: trunk/icecast2yp/src/log.h
===================================================================
--- trunk/icecast2yp/src/log.h 2004-12-09 17:08:52 UTC (rev 8358)
+++ trunk/icecast2yp/src/log.h 2004-12-09 19:03:20 UTC (rev 8359)
@@ -23,6 +23,6 @@
#define LOG_DEBUG LM_DEBUG, __FILE__, __LINE__
#define Log LogMessage
-#define YP_LOGDIR "./"
+#define YP_LOGDIR "/tmp/"
#endif
Modified: trunk/icecast2yp/src/yp_cgi.c
===================================================================
--- trunk/icecast2yp/src/yp_cgi.c 2004-12-09 17:08:52 UTC (rev 8358)
+++ trunk/icecast2yp/src/yp_cgi.c 2004-12-09 19:03:20 UTC (rev 8359)
@@ -32,7 +32,7 @@
int use_listingIP = 0;
- setErrorType(LM_INFO);
+ setErrorType(LM_ERROR);
setLogFile(YP_LOGDIR"yp_cgi.log");
memset(error, '\000', sizeof(error));
memset(listing_ip, '\000', sizeof(listing_ip));
Modified: trunk/icecast2yp/src/yp_clean.c
===================================================================
--- trunk/icecast2yp/src/yp_clean.c 2004-12-09 17:08:52 UTC (rev 8358)
+++ trunk/icecast2yp/src/yp_clean.c 2004-12-09 19:03:20 UTC (rev 8359)
@@ -16,6 +16,7 @@
#define YP_ERROR 0
#define YP_SUCCESS 1
+#define YP_EXCEPTION 2
int cleanServers2(char *error)
@@ -250,7 +251,179 @@
return(YP_SUCCESS);
}
+int cleanServers5(char *error)
+{
+ char sql[8096];
+ char sid[2046];
+ int i;
+ MYSQL_ROW row;
+ MYSQL_ROW row2;
+ int existing = 0;
+ int nrows = 0;
+ int nrows2 = 0;
+ char detail_id[255] = "";
+ char parent_id[255] = "";
+ char id[255] = "";
+ char *p1 = NULL;
+ int ret = YP_SUCCESS;
+ memset(sql, '\000', sizeof(sql));
+
+ sprintf(sql,"SELECT id FROM playlists");
+ if(mysql_real_query(&dbase,sql,strlen(sql))) {
+ strcpy(error, mysql_error(&dbase));
+ return(YP_ERROR);
+ }
+ result = mysql_store_result(&dbase);
+ nrows = mysql_num_rows(result);
+ if(nrows == 0) {
+ return(YP_SUCCESS);
+ }
+ else {
+ for (i=0;i<nrows;i++) {
+ row = mysql_fetch_row(result);
+ if (row[0]) {
+ sprintf(id, "%s", row[0]);
+ sprintf(sql,"SELECT count(*) FROM clusters where id = '%s'", id);
+ if(mysql_real_query(&dbase,sql,strlen(sql))) {
+ strcpy(error, mysql_error(&dbase));
+ return(YP_ERROR);
+ }
+ result2 = mysql_store_result(&dbase);
+ nrows2 = mysql_num_rows(result2);
+ if(nrows2 != 0) {
+ row2 = mysql_fetch_row(result2);
+ if (row2[0]) {
+ if (atoi(row2[0]) == 0) {
+ sprintf(sql,"delete from clusters where id = '%s'", row[0]);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "clusters: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ mysql_free_result(result);
+ mysql_free_result(result2);
+ return(YP_ERROR);
+ }
+ sprintf(sql,"delete from playlists where id = '%s'", row[0]);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "playlists: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ mysql_free_result(result);
+ mysql_free_result(result2);
+ return(YP_ERROR);
+ }
+ sprintf(sql,"delete from server_details where playlist_id = '%s'", row[0]);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "server_details: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ mysql_free_result(result);
+ mysql_free_result(result2);
+ return(YP_ERROR);
+ }
+ LogMessage(LOG_INFO, "Deleted Cluster ID (%s) because it didn't have a record in clusters", id);
+ ret = YP_EXCEPTION;
+ }
+ }
+ }
+ mysql_free_result(result2);
+ }
+ }
+ mysql_free_result(result);
+ sprintf(sql,"COMMIT");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ }
+ return(ret);
+
+}
+int cleanServers6(char *error)
+{
+ char sql[8096];
+ char sid[2046];
+ int i;
+ MYSQL_ROW row;
+ MYSQL_ROW row2;
+ int existing = 0;
+ int nrows = 0;
+ int nrows2 = 0;
+ char detail_id[255] = "";
+ char parent_id[255] = "";
+ char id[255] = "";
+ char *p1 = NULL;
+ int ret = YP_SUCCESS;
+
+ memset(sql, '\000', sizeof(sql));
+
+ sprintf(sql,"SELECT id FROM clusters");
+ if(mysql_real_query(&dbase,sql,strlen(sql))) {
+ strcpy(error, mysql_error(&dbase));
+ return(YP_ERROR);
+ }
+ result = mysql_store_result(&dbase);
+ nrows = mysql_num_rows(result);
+ if(nrows == 0) {
+ return(YP_SUCCESS);
+ }
+ else {
+ for (i=0;i<nrows;i++) {
+ row = mysql_fetch_row(result);
+ if (row[0]) {
+ sprintf(id, "%s", row[0]);
+ sprintf(sql,"SELECT count(*) FROM server_details where playlist_id = '%s'", id);
+ if(mysql_real_query(&dbase,sql,strlen(sql))) {
+ strcpy(error, mysql_error(&dbase));
+ return(YP_ERROR);
+ }
+ result2 = mysql_store_result(&dbase);
+ nrows2 = mysql_num_rows(result2);
+ if(nrows2 != 0) {
+ row2 = mysql_fetch_row(result2);
+ if (row2[0]) {
+ if (atoi(row2[0]) == 0) {
+ sprintf(sql,"delete from clusters where id = '%s'", row[0]);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "clusters: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ mysql_free_result(result);
+ mysql_free_result(result2);
+ return(YP_ERROR);
+ }
+ sprintf(sql,"delete from playlists where id = '%s'", row[0]);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "playlists: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ mysql_free_result(result);
+ mysql_free_result(result2);
+ return(YP_ERROR);
+ }
+ sprintf(sql,"delete from server_details where playlist_id = '%s'", row[0]);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "server_details: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ mysql_free_result(result);
+ mysql_free_result(result2);
+ return(YP_ERROR);
+ }
+ LogMessage(LOG_INFO, "Deleted Cluster ID (%s) because it didn't have a record in clusters", id);
+ ret = YP_EXCEPTION;
+ }
+ }
+ }
+ mysql_free_result(result2);
+ }
+ }
+ mysql_free_result(result);
+ sprintf(sql,"COMMIT");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ }
+ return(ret);
+
+}
+
int cleanServers(char *error)
{
char sql[8096];
@@ -368,6 +541,26 @@
LogMessage(LOG_ERROR, "Error: %s", error);
}
LogMessage(LOG_INFO, "Ran clean servers 4 OK");
+ ret = cleanServers5(error);
+ if (ret == YP_ERROR) {
+ LogMessage(LOG_ERROR, "Error: %s", error);
+ }
+ if (ret == YP_EXCEPTION) {
+ cleanServers2(error);
+ cleanServers3(error);
+ cleanServers4(error);
+ }
+ LogMessage(LOG_INFO, "Ran clean servers 5 OK");
+ ret = cleanServers6(error);
+ if (ret == YP_ERROR) {
+ LogMessage(LOG_ERROR, "Error: %s", error);
+ }
+ if (ret == YP_EXCEPTION) {
+ cleanServers2(error);
+ cleanServers3(error);
+ cleanServers4(error);
+ }
+ LogMessage(LOG_INFO, "Ran clean servers 6 OK");
}
return(0);
}
Modified: trunk/icecast2yp/src/yp_routines.c
===================================================================
--- trunk/icecast2yp/src/yp_routines.c 2004-12-09 17:08:52 UTC (rev 8358)
+++ trunk/icecast2yp/src/yp_routines.c 2004-12-09 19:03:20 UTC (rev 8359)
@@ -121,6 +121,50 @@
return(YP_SUCCESS);
}
+int genClusterPassword(char *sid, char *error)
+{
+ char key[1024];
+ int i = 0;
+ char sql[8096];
+ MYSQL_ROW row;
+ int existing = 0;
+ int nrows = 0;
+
+
+ Log(LOG_DEBUG, "Generating Cluster Password");
+ for (i=0;i<10;i++) {
+ memset(key, '\000', sizeof(key));
+ sprintf(key, "%f", GetCurrentTime());
+ Log(LOG_DEBUG, "Key %d = %s", i, key);
+
+ memset(sql, '\000', sizeof(sql));
+
+ sprintf(sql,"select count(*) from clusters where cluster_password = \'%s\'",key);
+ if(mysql_real_query(&dbase,sql,strlen(sql))) {
+ strcpy(error, mysql_error(&dbase));
+ return(YP_ERROR);
+ }
+ result = mysql_store_result(&dbase);
+ nrows = mysql_num_rows(result);
+ if(nrows == 0) {
+ return(YP_ERROR);
+ }
+ else {
+ row = mysql_fetch_row(result);
+ mysql_free_result(result);
+ existing = 0;
+ if (row[0]) {
+ existing = atoi(row[0]);
+ }
+ if (!existing) {
+ strcpy(sid, key);
+ break;
+ }
+ }
+ }
+ return(YP_SUCCESS);
+
+}
void disconnectFromDB() {
mysql_close(&dbase);
}
@@ -195,6 +239,120 @@
}
return existing;
}
+int getPlaylistId(char *parent_id, char *detail_id, char *error, char *playlist_id, char *listen_url)
+{
+ char sql[8096];
+ MYSQL_ROW row;
+ int existing = 0;
+ int nrows = 0;
+
+ memset(sql, '\000', sizeof(sql));
+
+ snprintf(sql, sizeof(sql)-1, "select playlist_id, listen_url from server_details where id = %s and parent_id = %s",detail_id, parent_id);
+ Log(LOG_DEBUG, "getPlaylistId: Going to execute %s", sql);
+ if(mysql_real_query(&dbase,sql,strlen(sql))) {
+ strcpy(error, mysql_error(&dbase));
+ return(YP_ERROR);
+ }
+
+ result = mysql_store_result(&dbase);
+ nrows = mysql_num_rows(result);
+
+ if(nrows == 0) {
+ existing = 0;
+ }
+ else {
+ row = mysql_fetch_row(result);
+ mysql_free_result(result);
+ if (row[0]) {
+ existing = 1;
+ strcpy(playlist_id, row[0]);
+ strcpy(listen_url, row[1]);
+ }
+ }
+ return existing;
+}
+int checkForClusterId(char *server_name, char *cluster_password, char *error, char *existing_id)
+{
+ char sql[8096];
+ MYSQL_ROW row;
+ int existing = 0;
+ int nrows = 0;
+ char *server_name_esc = NULL;
+ char *cluster_password_esc = NULL;
+
+ memset(sql, '\000', sizeof(sql));
+
+ server_name_esc = malloc(strlen(server_name)*2 + 1);
+ memset(server_name_esc, '\000', strlen(server_name)*2 + 1);
+ cluster_password_esc = malloc(strlen(cluster_password)*2 + 1);
+ memset(cluster_password_esc, '\000', strlen(cluster_password)*2 + 1);
+ mysql_real_escape_string(&dbase, server_name_esc, server_name, strlen(server_name));
+ mysql_real_escape_string(&dbase, cluster_password_esc, cluster_password, strlen(cluster_password));
+
+ snprintf(sql, sizeof(sql)-1, "select id from clusters where server_name = \'%s\' and cluster_password = \'%s\'",server_name_esc, cluster_password_esc);
+ if(mysql_real_query(&dbase,sql,strlen(sql))) {
+ strcpy(error, mysql_error(&dbase));
+ free(server_name_esc);
+ return(YP_ERROR);
+ }
+
+ free(server_name_esc);
+ server_name_esc = NULL;
+ free(cluster_password_esc);
+ cluster_password_esc = NULL;
+
+ result = mysql_store_result(&dbase);
+ nrows = mysql_num_rows(result);
+
+ if(nrows == 0) {
+ existing = 0;
+ }
+ else {
+ row = mysql_fetch_row(result);
+ mysql_free_result(result);
+ if (row[0]) {
+ existing = 1;
+ strcpy(existing_id, row[0]);
+ }
+ }
+ return existing;
+}
+int anyMorePlaylists(char *sid, char *error)
+{
+ char sql[8096];
+ MYSQL_ROW row;
+ int existing = 0;
+ int nrows = 0;
+
+ memset(sql, '\000', sizeof(sql));
+
+ snprintf(sql, sizeof(sql)-1, "select count(*) from playlists where id = %s",sid);
+ if(mysql_real_query(&dbase,sql,strlen(sql))) {
+ strcpy(error, mysql_error(&dbase));
+ return(YP_ERROR);
+ }
+
+ result = mysql_store_result(&dbase);
+ nrows = mysql_num_rows(result);
+
+ if(nrows == 0) {
+ return(0);
+ }
+ else {
+ row = mysql_fetch_row(result);
+ mysql_free_result(result);
+ if (row[0]) {
+ if (atoi(row[0]) > 0) {
+ return(1);
+ }
+ }
+ else {
+ return(0);
+ }
+ }
+ return(0);
+}
int anyMoreServerDetails(char *sid, char *error, char *parent_id)
{
char sql[8096];
@@ -355,7 +513,7 @@
int addServer(char *server_name, char *genre, char *cluster_password, char *desc, char *url, char *listenurl, char *server_type, char *bitrate, char *listing_ip, char *sid, char *samplerate, char *channels, char *error)
{
- char sql[8096];
+ char sql[2*8096];
int i;
MYSQL_ROW row;
int existing = 0;
@@ -370,10 +528,14 @@
char *listeners_esc = NULL;
char *samplerate_esc = NULL;
char *channels_esc = NULL;
+ char *cluster_password_esc = NULL;
int cluster_flag = 0;
+ int clusterid_flag = 0;
int have_cluster_id = 0;
char table_name[255] = "";
char parent_id[255] = "";
+ char cluster_id[255] = "";
+ char generated_cluster_password[255] = "";
char detail_id[255] = "";
int ret = 0;
@@ -444,6 +606,12 @@
goto Error;
}
+ if (strlen(cluster_password) == 0) {
+ if (genClusterPassword(cluster_password, error) != YP_SUCCESS) {
+ goto Error;
+ }
+ }
+
server_name_esc = malloc(strlen(server_name)*2 + 1);
memset(server_name_esc, '\000', strlen(server_name)*2 + 1);
genre_esc = malloc(strlen(genre)*2 + 1);
@@ -462,6 +630,8 @@
memset(samplerate_esc, '\000', strlen(samplerate)*2 + 1);
channels_esc = malloc(strlen(channels)*2 + 1);
memset(channels_esc, '\000', strlen(channels)*2 + 1);
+ cluster_password_esc = malloc(strlen(cluster_password)*2 + 1);
+ memset(cluster_password_esc, '\000', strlen(cluster_password)*2 + 1);
mysql_real_escape_string(&dbase, server_name_esc, server_name, strlen(server_name));
mysql_real_escape_string(&dbase, genre_esc, genre, strlen(genre));
@@ -472,6 +642,7 @@
mysql_real_escape_string(&dbase, listenurl_esc, listenurl, strlen(listenurl));
mysql_real_escape_string(&dbase, samplerate_esc, samplerate, strlen(samplerate));
mysql_real_escape_string(&dbase, channels_esc, channels, strlen(channels));
+ mysql_real_escape_string(&dbase, cluster_password_esc, cluster_password, strlen(cluster_password));
if (!cluster_flag) {
@@ -488,6 +659,35 @@
Log(LOG_DEBUG, sql);
+ Log(LOG_DEBUG, "Checking for a cluster ID");
+ existing = checkForClusterId(server_name, cluster_password, error, cluster_id);
+ if (existing == YP_ERROR) {
+ Log(LOG_DEBUG, "check for cluster ID returned error");
+ goto Error;
+ }
+ if (existing) {
+ clusterid_flag = 1;
+ }
+ Log(LOG_DEBUG, "Done Checking for a cluster ID");
+ if (!clusterid_flag) {
+ snprintf(sql, sizeof(sql)-1, "insert into clusters (server_name, cluster_password) values ('%s', '%s')", server_name_esc, cluster_password_esc);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "clusters: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ goto Error;
+ }
+ sprintf(cluster_id, "%d", mysql_insert_id(&dbase));
+ }
+
+ snprintf(sql, sizeof(sql)-1, "insert into playlists (id, listen_url) values (%s, '%s')", cluster_id, listenurl_esc);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "playlists: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ goto Error;
+ }
+
snprintf(sql, sizeof(sql)-1, "insert into \
server_details (parent_id, \
server_name, \
@@ -499,6 +699,7 @@
url, \
current_song, \
listen_url, \
+ playlist_id, \
server_type, \
bitrate, \
listeners, \
@@ -514,11 +715,13 @@
'%s', \
'%s', \
'%s', \
+ %s, \
'%s', \
'%s', \
0, \
'%s', \
- '%s')", parent_id, server_name_esc, listing_ip, desc_esc, genre_esc, sid, cluster_password, url_esc, "", listenurl_esc, server_type_esc, bitrate_esc, samplerate_esc, channels_esc);
+ '%s')", parent_id, server_name_esc, listing_ip, desc_esc, genre_esc, sid, cluster_password_esc, url_esc, "", listenurl_esc, cluster_id, server_type_esc, bitrate_esc, samplerate_esc, channels_esc);
+ Log(LOG_DEBUG, sql);
if (mysql_real_query(&dbase,sql,strlen(sql))) {
sprintf(error, "servers: %s", mysql_error(&dbase));
sprintf(sql,"ROLLBACK");
@@ -793,7 +996,9 @@
int nrows = 0;
int cluster_flag = 0;
char detail_id[255] = "";
+ char playlist_id[255] = "";
char parent_id[255] = "";
+ char listenurl[1024] = "";
char *p1;
memset(sql, '\000', sizeof(sql));
@@ -829,6 +1034,19 @@
}
mysql_free_result(result);
+ existing = getPlaylistId(parent_id, detail_id, error, playlist_id, listenurl);
+ if (existing == YP_ERROR) {
+ Log(LOG_DEBUG, "check for playlist id returned error");
+ }
+
+ sprintf(sql,"delete from playlists where id = %s and listen_url = \'%s\'", playlist_id, listenurl);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "playlists: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ return(YP_ERROR);
+ }
+
sprintf(sql,"delete from server_details where id = %s", detail_id);
if (mysql_real_query(&dbase,sql,strlen(sql))) {
sprintf(error, "clustered_servers: %s", mysql_error(&dbase));
@@ -836,6 +1054,22 @@
mysql_real_query(&dbase,sql,strlen(sql));
return(YP_ERROR);
}
+
+ Log(LOG_DEBUG, "Checking to see if there are any more playlist ids");
+ if (!anyMorePlaylists(playlist_id, error)) {
+ Log(LOG_DEBUG, "Nope, so lets delete the parent in clusters...");
+ // Now delete the parent
+ sprintf(sql,"delete from clusters where id = %s", playlist_id);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "clusters: %s", mysql_error(&dbase));
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
+ return(YP_ERROR);
+ }
+ }
+ else {
+ Log(LOG_DEBUG, "Yep, so lets NOT delete the clusters parent...");
+ }
// At this point, we need to check to see if there are any server_details left for this
// parent, if not, then delete the parent, if so, then leave the parent, because
More information about the commits
mailing list