mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-12 22:28:09 -05:00
Make default server name based on hostname, fixing #111
This commit is contained in:
parent
510fbde5b8
commit
80f7c87567
35
src/conf.c
35
src/conf.c
@ -37,6 +37,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
@ -51,6 +55,11 @@
|
||||
#include "webserver.h"
|
||||
#include "xml-rpc.h"
|
||||
|
||||
|
||||
#ifndef HOST_NAME_MAX
|
||||
# define HOST_NAME_MAX 255
|
||||
#endif
|
||||
|
||||
/** Globals */
|
||||
//static int ecode;
|
||||
static LL_HANDLE conf_main=NULL;
|
||||
@ -99,7 +108,7 @@ static CONF_ELEMENTS conf_elements[] = {
|
||||
{ 0, 0, CONF_T_STRING,"general","db_type" },
|
||||
{ 0, 0, CONF_T_EXISTPATH,"general","db_parms" }, /* this isn't right */
|
||||
{ 0, 0, CONF_T_INT,"general","debuglevel" },
|
||||
{ 1, 0, CONF_T_STRING,"general","servername" },
|
||||
{ 0, 0, CONF_T_STRING,"general","servername" },
|
||||
{ 0, 0, CONF_T_INT,"general","rescan_interval" },
|
||||
{ 0, 0, CONF_T_INT,"general","always_scan" },
|
||||
{ 0, 1, CONF_T_INT,"general","latin1_tags" },
|
||||
@ -1445,3 +1454,27 @@ int _conf_xml_dump(XMLSTRUCT *pxml, LL *pll, int sublevel, char *parent) {
|
||||
char *conf_get_filename(void) {
|
||||
return conf_main_file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this is an ugly block of crap to carry around every
|
||||
* time one wants the servername.
|
||||
*/
|
||||
char *conf_get_servername(void) {
|
||||
char *retval;
|
||||
char newname[HOST_NAME_MAX + 1 + 16]; /* " Firefly Server" */
|
||||
|
||||
gethostname(newname,HOST_NAME_MAX);
|
||||
retval = strchr(newname,'.');
|
||||
if(retval) *retval = '\0';
|
||||
|
||||
retval = newname;
|
||||
while(*retval) {
|
||||
*retval = tolower(*retval);
|
||||
retval++;
|
||||
}
|
||||
|
||||
strcat(newname," Firefly Server");
|
||||
|
||||
return conf_alloc_string("general","servername",newname);
|
||||
}
|
||||
|
@ -59,4 +59,8 @@ extern char *conf_get_filename(void);
|
||||
#include "webserver.h"
|
||||
extern int conf_xml_dump(WS_CONNINFO *pwsc);
|
||||
|
||||
/* FIXME: well used config reading stuff... */
|
||||
extern char *conf_get_servername(void);
|
||||
|
||||
|
||||
#endif /* _CONF_H_ */
|
||||
|
@ -1480,7 +1480,7 @@ void dispatch_dbinfo(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
int count;
|
||||
char *servername;
|
||||
|
||||
servername = conf_alloc_string("general","servername","mt-daapd");
|
||||
servername = conf_get_servername();
|
||||
namelen=(int) strlen(servername);
|
||||
|
||||
current += db_dmap_add_container(current,"avdb",105 + namelen);
|
||||
@ -1574,7 +1574,7 @@ void dispatch_server_info(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
int actual_length;
|
||||
int supports_update;
|
||||
|
||||
servername = conf_alloc_string("general","servername","mt-daapd");
|
||||
servername = conf_get_servername();
|
||||
supports_update = conf_get_int("daap","supports_update",1);
|
||||
|
||||
actual_length=130 + (int) strlen(servername);
|
||||
|
@ -429,8 +429,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
#ifndef WITHOUT_MDNS
|
||||
if(config.use_mdns) { /* register services */
|
||||
/* FIXME: get default name from hostname (os_hostname()?) */
|
||||
servername = conf_alloc_string("general","servername","mt-daapd");
|
||||
servername = conf_get_servername();
|
||||
|
||||
memset(txtrecord,0,sizeof(txtrecord));
|
||||
txt_add(txtrecord,"txtvers=1");
|
||||
|
13
src/plugin.c
13
src/plugin.c
@ -556,7 +556,18 @@ char *pi_server_ver(void) {
|
||||
}
|
||||
|
||||
int pi_server_name(char *name, int *len) {
|
||||
return conf_get_string("general","servername","unknown",name, len);
|
||||
char *servername;
|
||||
|
||||
servername = conf_get_servername();
|
||||
if((servername) && (strlen(servername) < (size_t)len)) {
|
||||
strcpy(name,servername);
|
||||
} else {
|
||||
if((size_t)len > strlen("Firefly Media Server"))
|
||||
strcpy(name,"Firefly Media Server");
|
||||
}
|
||||
|
||||
free(servername);
|
||||
return CONF_E_SUCCESS;
|
||||
}
|
||||
|
||||
int pi_db_count(void) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user