mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-09 20:58:10 -05:00
Add hostname (%h) and version (%v) templates for the servername parameter
This commit is contained in:
parent
2f0dafba61
commit
325c86073b
74
src/conf.c
74
src/conf.c
@ -1635,19 +1635,79 @@ char *conf_get_filename(void) {
|
|||||||
*/
|
*/
|
||||||
char *conf_get_servername(void) {
|
char *conf_get_servername(void) {
|
||||||
char *retval;
|
char *retval;
|
||||||
char newname[HOST_NAME_MAX + 1 + 16]; /* " Firefly Server" */
|
char *default_name = "firefly %v on %h";
|
||||||
|
char hostname[HOST_NAME_MAX + 1]; /* " Firefly Server" */
|
||||||
|
char *template, *src, *dst;
|
||||||
|
int len;
|
||||||
|
|
||||||
gethostname(newname,HOST_NAME_MAX);
|
gethostname(hostname,HOST_NAME_MAX);
|
||||||
retval = strchr(newname,'.');
|
retval = strchr(hostname,'.');
|
||||||
if(retval) *retval = '\0';
|
if(retval) *retval = '\0';
|
||||||
|
|
||||||
retval = newname;
|
retval = hostname;
|
||||||
while(*retval) {
|
while(*retval) {
|
||||||
*retval = tolower(*retval);
|
*retval = tolower(*retval);
|
||||||
retval++;
|
retval++;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat(newname," Firefly Server");
|
template = conf_alloc_string("general","servername",default_name);
|
||||||
|
src = template;
|
||||||
return conf_alloc_string("general","servername",newname);
|
len = 0;
|
||||||
|
while(*src) {
|
||||||
|
if(*src == '%') {
|
||||||
|
src++;
|
||||||
|
switch(*src) {
|
||||||
|
case 'h':
|
||||||
|
len += strlen(hostname);
|
||||||
|
src++;
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
len += strlen(VERSION);
|
||||||
|
src++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
len += 2;
|
||||||
|
src++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
len++;
|
||||||
|
src++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char*)malloc(len+1);
|
||||||
|
if(!retval) DPRINTF(E_FATAL,L_MISC,"malloc");
|
||||||
|
|
||||||
|
memset(retval,0,len+1);
|
||||||
|
|
||||||
|
dst = retval;
|
||||||
|
src = template;
|
||||||
|
|
||||||
|
while(*src) {
|
||||||
|
if(*src == '%') {
|
||||||
|
src++;
|
||||||
|
switch(*src) {
|
||||||
|
case 'h':
|
||||||
|
strcat(dst,hostname);
|
||||||
|
dst += strlen(hostname);
|
||||||
|
src ++;
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
strcat(dst,VERSION);
|
||||||
|
dst += strlen(VERSION);
|
||||||
|
src++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*dst++ = '%';
|
||||||
|
*dst++ = *src++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*dst++ = *src++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,11 @@ void txt_add(char *txtrecord, char *fmt, ...) {
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
len = (int)strlen(buff);
|
len = (int)strlen(buff);
|
||||||
|
if(len + strlen(txtrecord) > 255) {
|
||||||
|
DPRINTF(E_FATAL,L_MAIN,"dns-sd text string too long. Try a shorter "
|
||||||
|
"share name.\n");
|
||||||
|
}
|
||||||
|
|
||||||
end = txtrecord + strlen(txtrecord);
|
end = txtrecord + strlen(txtrecord);
|
||||||
*end = len;
|
*end = len;
|
||||||
strcpy(end+1,buff);
|
strcpy(end+1,buff);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user