summaryrefslogtreecommitdiff
path: root/muggle-plugin
diff options
context:
space:
mode:
authorwr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b>2005-03-09 18:51:21 +0000
committerwr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b>2005-03-09 18:51:21 +0000
commita09d656b90c2355ebf2a38bfaf036a3e1defa1ee (patch)
tree75e31c0d2ec4f71bffe77593679ff595182702b6 /muggle-plugin
parent806a02f87d720494b1b23781f23107ca1f45991e (diff)
downloadvdr-plugin-muggle-a09d656b90c2355ebf2a38bfaf036a3e1defa1ee.tar.gz
vdr-plugin-muggle-a09d656b90c2355ebf2a38bfaf036a3e1defa1ee.tar.bz2
rename HAVE_SERVER to HAVE_ONLY_SERVER, simplify connect, replace USE SQL by sql_select_db
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/branches/0.1.4-wr@560 e10066b5-e1e2-0310-b819-94efdf66514b
Diffstat (limited to 'muggle-plugin')
-rw-r--r--muggle-plugin/Makefile12
-rw-r--r--muggle-plugin/mg_mysql.c73
-rw-r--r--muggle-plugin/mg_mysql.h1
-rw-r--r--muggle-plugin/muggle.c27
-rwxr-xr-xmuggle-plugin/mugglei.c15
5 files changed, 57 insertions, 71 deletions
diff --git a/muggle-plugin/Makefile b/muggle-plugin/Makefile
index 394060e..59e5d56 100644
--- a/muggle-plugin/Makefile
+++ b/muggle-plugin/Makefile
@@ -14,10 +14,10 @@ PLUGIN = muggle
# HAVE_VORBISFILE=1
# HAVE_FLAC=1
-#if you want to use a dedicated Mysql server instead of the embedded code,
+#if you do not want to compile in code for embedded sql,
#define this in $VDRDIR/Make.config:
-# HAVE_SERVER=1
-#
+# HAVE_ONLY_SERVER=1
+
### The version number of this plugin (taken from the main source file):
VERSION = $(shell grep 'static const char \*VERSION *=' $(PLUGIN).c | awk '{ print $$6 }' | sed -e 's/[";]//g')
@@ -53,7 +53,7 @@ PACKAGE = vdr-$(ARCHIVE)
INCLUDES += -I$(VDRDIR) -I$(VDRDIR)/include -I$(DVBDIR)/include \
`mysql_config --cflags` `taglib-config --cflags`
-DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
+DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -DMYSQLCLIENTVERSION=`mysql_config --version`
### The object files (add further files here):
@@ -64,9 +64,9 @@ OBJS = $(PLUGIN).o i18n.o mg_valmap.o mg_mysql.o mg_sync.o mg_order.o mg_content
LIBS = -lmad `taglib-config --libs`
MILIBS = `taglib-config --libs`
-ifdef HAVE_SERVER
+ifdef HAVE_ONLY_SERVER
SQLLIBS = `mysql_config --libs`
-DEFINES += -DHAVE_SERVER
+DEFINES += -DHAVE_ONLY_SERVER
else
SQLLIBS = `mysql_config --libmysqld-libs` -L/lib
endif
diff --git a/muggle-plugin/mg_mysql.c b/muggle-plugin/mg_mysql.c
index b63c35d..5c3170a 100644
--- a/muggle-plugin/mg_mysql.c
+++ b/muggle-plugin/mg_mysql.c
@@ -29,7 +29,7 @@ class mysqlhandle_t {
~mysqlhandle_t();
};
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
static char *datadir;
static char *server_args[] =
@@ -64,7 +64,7 @@ set_datadir(char *dir)
mysqlhandle_t::mysqlhandle_t()
{
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
mgDebug(1,"calling mysql_server_init");
if (mysql_server_init(sizeof(server_args) / sizeof(char *),
server_args, server_groups))
@@ -74,7 +74,7 @@ mysqlhandle_t::mysqlhandle_t()
mysqlhandle_t::~mysqlhandle_t()
{
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
mgDebug(3,"calling mysql_server_end");
mysql_server_end();
#endif
@@ -388,12 +388,13 @@ void mgmySql::Create()
mgWarning("Cannot create database:%s",mysql_error (m_db));
return;
}
-#ifdef HAVE_SERVER
+#ifdef HAVE_ONLY_SERVER
mysql_query(m_db,"grant all privileges on GiantDisc.* to vdr@localhost;");
// ignore error. If we can create the data base, we can do everything
// with it anyway.
#endif
- mysql_query(m_db,"use GiantDisc;");
+ if (mysql_select_db(m_db,the_setup.DbName))
+ mgError("mysql_select_db(%s) failed with %s",mysql_error(m_db));
int len = sizeof( db_cmds ) / sizeof( char* );
for( int i=0; i < len; i ++ )
{
@@ -405,7 +406,6 @@ void mgmySql::Create()
}
}
m_database_found=true;
- Use();
FillTables();
}
@@ -465,42 +465,34 @@ void
mgmySql::Connect ()
{
assert(!m_db);
-#ifdef HAVE_SERVER
+#ifdef HAVE_ONLY_SERVER
if (the_setup.DbHost == "") return;
#endif
m_db = mysql_init (0);
if (!m_db)
return;
-#ifdef HAVE_SERVER
+#ifdef HAVE_ONLY_SERVER
bool success;
- if (the_setup.DbSocket != NULL)
+ if (!the_setup.DbHost || !strcmp(the_setup.DbHost,"localhost"))
{
- mgDebug(1,"Using socket %s for connecting to server as user %s.",
+ mgDebug(1,"Using socket %s for connecting to local system as user %s.",
the_setup.DbSocket,
the_setup.DbUser);
- mgDebug(3,"DbPassword is: '%s'",the_setup.DbPass);
- success = (mysql_real_connect( m_db,
- "",
- the_setup.DbUser,
- the_setup.DbPass,
- 0,
- 0,
- the_setup.DbSocket, 0 ) != 0 );
}
else
{
mgDebug(1,"Using TCP for connecting to server %s as user %s.",
the_setup.DbHost,
the_setup.DbUser);
- mgDebug(3,"DbPassword is: '%s'",the_setup.DbPass);
- success = ( mysql_real_connect( m_db,
- the_setup.DbHost,
- the_setup.DbUser,
- the_setup.DbPass,
- 0,
- the_setup.DbPort,
- 0, 0 ) != 0 );
}
+ mgDebug(3,"DbPassword is: '%s'",the_setup.DbPass);
+ success = ( mysql_real_connect( m_db,
+ the_setup.DbHost,
+ the_setup.DbUser,
+ the_setup.DbPass,
+ 0,
+ the_setup.DbPort,
+ the_setup.DbSocket, 0 ) != 0 );
if (!success)
{
mgWarning("Failed to connect to server '%s' as User '%s', Password '%s': %s",
@@ -516,24 +508,13 @@ mgmySql::Connect ()
#endif
if (m_db)
{
- mysql_query(m_db,"SHOW DATABASES");
- MYSQL_RES * rows = mysql_store_result(m_db);
- if (rows)
+ m_database_found = mysql_select_db(m_db,the_setup.DbName)==0;
{
- MYSQL_ROW row;
- while ((row = mysql_fetch_row (rows)) != 0)
- if (!strcmp(row[0],the_setup.DbName))
- {
- m_database_found=true;
- break;
- }
- mysql_free_result(rows);
+ if (!Connected())
+ if (!createtime)
+ mgWarning("Database %s not found:%s",
+ the_setup.DbName,mysql_error(m_db));
}
- if (m_database_found)
- Use();
- else
- if (!createtime)
- mgWarning("Database %s does not exist",the_setup.DbName);
}
if (!needGenre2_set && Connected())
{
@@ -543,14 +524,6 @@ mgmySql::Connect ()
return;
}
-void
-mgmySql::Use()
-{
- char b[100];
- sprintf(b,"USE %s;",the_setup.DbName);
- mysql_query(m_db,b);
- mgDebug(1,"found database %s",the_setup.DbName);
-}
void
mgmySql::CreateFolderFields()
diff --git a/muggle-plugin/mg_mysql.h b/muggle-plugin/mg_mysql.h
index eddc34e..636862f 100644
--- a/muggle-plugin/mg_mysql.h
+++ b/muggle-plugin/mg_mysql.h
@@ -62,7 +62,6 @@ class mgmySql
bool Connected() const;
bool HasFolderFields() const { return m_hasfolderfields;}
void Connect();
- void Use();
//! \brief create database and tables
void Create();
void FillTables();
diff --git a/muggle-plugin/muggle.c b/muggle-plugin/muggle.c
index 7259078..d6bbcc7 100644
--- a/muggle-plugin/muggle.c
+++ b/muggle-plugin/muggle.c
@@ -50,14 +50,14 @@ mgMuggle::mgMuggle (void)
main = NULL;
// defaults for database arguments
the_setup.DbHost = strdup ("localhost");
- the_setup.DbSocket = NULL;
+ the_setup.DbSocket = 0;
the_setup.DbPort = 0;
the_setup.DbName = strdup ("GiantDisc");
- the_setup.DbUser = strdup ("");
- the_setup.DbPass = strdup ("");
+ the_setup.DbUser = 0;
+ the_setup.DbPass = 0;
the_setup.GdCompatibility = false;
the_setup.ToplevelDir = strdup ("/mnt/music/");
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
char *buf;
asprintf(&buf,"%s/.muggle",getenv("HOME"));
set_datadir(buf);
@@ -85,18 +85,25 @@ mgMuggle::CommandLineHelp (void)
{
// Return a string that describes all known command line options.
return
+#ifdef HAVE_ONLY_SERVER
" -h HHHH, --host=HHHH specify database host (default is localhost)\n"
- " -s SSSS --socket=PATH specify database socket (default is TCP connection)\n"
+#else
+ " -h HHHH, --host=HHHH specify database host (default is mysql embedded)\n"
+#endif
+ " -s SSSS --socket=PATH specify database socket\n"
" -n NNNN, --name=NNNN specify database name (overridden by -g)\n"
" -p PPPP, --port=PPPP specify port of database server (default is )\n"
" -u UUUU, --user=UUUU specify database user (default is )\n"
" -w WWWW, --password=WWWW specify database password (default is empty)\n"
" -t TTTT, --toplevel=TTTT specify toplevel directory for music (default is /mnt/music)\n"
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
" -d DIRN, --datadir=DIRN specify directory for embedded sql data (default is $HOME/.muggle)\n"
#endif
" -g, --giantdisc enable full Giantdisc compatibility mode\n"
- " -v, --verbose specify debug level. The higher the more. Default is 1\n";
+ " -v, --verbose specify debug level. The higher the more. Default is 1\n"
+ "\n"
+ "if the specified host is localhost, sockets will be used if possible.\n"
+ "Otherwise the -s parameter will be ignored";
}
@@ -115,7 +122,7 @@ bool mgMuggle::ProcessArgs (int argc, char *argv[])
{"port", required_argument, NULL, 'p'},
{"user", required_argument, NULL, 'u'},
{"password", required_argument, NULL, 'w'},
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
{"datadir", required_argument, NULL, 'd'},
#endif
{"toplevel", required_argument, NULL, 't'},
@@ -127,7 +134,7 @@ bool mgMuggle::ProcessArgs (int argc, char *argv[])
c,
option_index = 0;
while ((c =
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
getopt_long (argc, argv, "gh:s:n:p:t:u:w:d:v:", long_options,
#else
getopt_long (argc, argv, "gh:s:n:p:t:u:w:v:", long_options,
@@ -166,7 +173,7 @@ bool mgMuggle::ProcessArgs (int argc, char *argv[])
the_setup.DbPass = strcpyrealloc (the_setup.DbPass, optarg);
}
break;
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
case 'd':
{
set_datadir(optarg);
diff --git a/muggle-plugin/mugglei.c b/muggle-plugin/mugglei.c
index 1e2f7ae..e5e7c21 100755
--- a/muggle-plugin/mugglei.c
+++ b/muggle-plugin/mugglei.c
@@ -71,7 +71,11 @@ int main( int argc, char *argv[] )
std::cout << "Only files ending in .flac, .mp3, .ogg (ignoring case) will be imported" << std::endl;
std::cout << "" << std::endl;
std::cout << "Options:" << std::endl;
+#ifdef HAVE_ONLY_SERVER
std::cout << " -h <hostname> - specify host of mySql database server (default is 'localhost')" << std::endl;
+#else
+ std::cout << " -h <hostname> - specify host of mySql database server (default is mysql embedded')" << std::endl;
+#endif
std::cout << " -s <socket> - specify a socket for mySQL communication (default is TCP)" << std::endl;
std::cout << " -n <database> - specify database name (default is 'GiantDisc')" << std::endl;
std::cout << " -u <username> - specify user of mySql database (default is empty)" << std::endl;
@@ -80,10 +84,13 @@ int main( int argc, char *argv[] )
std::cout << " -z - scan all database entries and delete entries for files not found" << std::endl;
std::cout << " -z is not yet implemented" << std::endl;
std::cout << " -c - delete the entire database and recreate a new empty one" << std::endl;
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
std::cout << " -d <datadir> - the data directory for the embedded mysql server. Defaults to ./.muggle" << std::endl;
#endif
std::cout << " -v - the wanted log level, the higher the more. Default is 1" << std::endl;
+ std::cout << std::endl << std::endl;
+ std::cout << "if the specified host is localhost, sockets will be used if possible." << std::endl;
+ std::cout << "Otherwise the -s parameter will be ignored" << std::endl;
exit( 1 );
}
@@ -92,7 +99,7 @@ int main( int argc, char *argv[] )
import_assorted = false;
delete_mode = false;
create_mode = false;
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
char *buf;
asprintf(&buf,"%s/.muggle",getenv("HOME"));
set_datadir(buf);
@@ -102,7 +109,7 @@ int main( int argc, char *argv[] )
// parse command line options
while( 1 )
{
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
int c = getopt(argc, argv, "h:s:n:u:p:t:zcv:d:");
#else
int c = getopt(argc, argv, "h:s:n:u:p:t:zcv:");
@@ -153,7 +160,7 @@ int main( int argc, char *argv[] )
{
mgSetDebugLevel(atol(optarg));
} break;
-#ifndef HAVE_SERVER
+#ifndef HAVE_ONLY_SERVER
case 'd':
{
set_datadir(optarg);