mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-12 23:43:23 -05:00
fix up txt records to show password info, mtd-version, and itunes version
This commit is contained in:
parent
4b728b899d
commit
cf59f7dc33
46
src/main.c
46
src/main.c
@ -56,6 +56,7 @@
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -117,6 +118,31 @@ CONFIG config; /**< Main configuration structure, as read from configfile */
|
||||
* Forwards
|
||||
*/
|
||||
static void usage(char *program);
|
||||
static void txt_add(char *txtrecord, char *fmt, ...);
|
||||
|
||||
|
||||
/**
|
||||
* build a dns text string
|
||||
*
|
||||
* @param txtrecord buffer to append text record string to
|
||||
* @param fmt sprintf-style format
|
||||
*/
|
||||
void txt_add(char *txtrecord, char *fmt, ...) {
|
||||
va_list ap;
|
||||
char buff[256];
|
||||
int len;
|
||||
char *end;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buff, sizeof(buff), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
len = strlen(buff);
|
||||
end = txtrecord + strlen(txtrecord);
|
||||
*end = len;
|
||||
strcpy(end+1,buff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print usage information to stdout
|
||||
@ -169,7 +195,6 @@ int main(int argc, char *argv[]) {
|
||||
int old_song_count, song_count;
|
||||
int force_non_root=0;
|
||||
int skip_initial=0;
|
||||
|
||||
int size;
|
||||
char logfile[PATH_MAX];
|
||||
char db_type[40];
|
||||
@ -180,6 +205,8 @@ int main(int argc, char *argv[]) {
|
||||
char servername[PATH_MAX];
|
||||
char iface[20];
|
||||
|
||||
char txtrecord[255];
|
||||
|
||||
int err;
|
||||
char *perr;
|
||||
|
||||
@ -343,13 +370,24 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
#ifndef WITHOUT_MDNS
|
||||
if(config.use_mdns) { /* register services */
|
||||
DPRINTF(E_LOG,L_MAIN|L_REND,"Registering rendezvous names\n");
|
||||
size = sizeof(servername);
|
||||
conf_get_string("general","servername","mt-daapd",servername,&size);
|
||||
|
||||
memset(txtrecord,0,sizeof(txtrecord));
|
||||
txt_add(txtrecord,"txtvers=1");
|
||||
txt_add(txtrecord,"Database ID=beddab1edeadbea7");
|
||||
txt_add(txtrecord,"Machine ID=f00f00f00");
|
||||
txt_add(txtrecord,"Machine Name=%s",servername);
|
||||
txt_add(txtrecord,"mtd-version=" VERSION);
|
||||
txt_add(txtrecord,"iTSh Version=131073");
|
||||
txt_add(txtrecord,"Version=196610");
|
||||
txt_add(txtrecord,"Password=%s",conf_isset("general","password") ? "true" : "false");
|
||||
|
||||
DPRINTF(E_LOG,L_MAIN|L_REND,"Registering rendezvous names\n");
|
||||
size = sizeof(iface);
|
||||
conf_get_string("general","interface","",iface,&size);
|
||||
rend_register(servername,"_daap._tcp",ws_config.port,iface);
|
||||
rend_register(servername,"_http._tcp",ws_config.port,iface);
|
||||
rend_register(servername,"_daap._tcp",ws_config.port,iface,txtrecord);
|
||||
rend_register(servername,"_http._tcp",ws_config.port,iface,txtrecord);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -157,8 +157,8 @@ void rend_callback(void) {
|
||||
NULL, /* domain */
|
||||
NULL, /* host */
|
||||
msg.port,
|
||||
"\011txtvers=1\034Database ID=beddab1edeadbea7", /* text record */
|
||||
39, /* text record length */
|
||||
msg.txt,
|
||||
strlen(msg.txt),
|
||||
rend_howl_reply,
|
||||
NULL,
|
||||
&rend_oid)) != SW_OKAY) {
|
||||
|
@ -161,6 +161,8 @@ void rend_callback(void *info) {
|
||||
REND_MESSAGE msg;
|
||||
unsigned short usPort;
|
||||
dns_service_discovery_ref dns_ref=NULL;
|
||||
char *src,*dst;
|
||||
int len;
|
||||
|
||||
/* here, we've seen the message, now we have to process it */
|
||||
if(rend_read_message(&msg) != sizeof(msg)) {
|
||||
@ -168,12 +170,24 @@ void rend_callback(void *info) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
src=dst=msg.txt;
|
||||
while(src && (*src)) {
|
||||
len = (*src);
|
||||
memmove(dst,src+1,len);
|
||||
dst += len;
|
||||
src += len + 1;
|
||||
if(*src) {
|
||||
*dst++ = '\001';
|
||||
} else {
|
||||
*dst='\0';
|
||||
}
|
||||
}
|
||||
|
||||
switch(msg.cmd) {
|
||||
case REND_MSG_TYPE_REGISTER:
|
||||
DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.type,msg.name,msg.port);
|
||||
usPort=htons(msg.port);
|
||||
dns_ref=DNSServiceRegistrationCreate(msg.name,msg.type,"",usPort,
|
||||
"txtvers=1\001Database ID=bedabb1edeadbea7",rend_reply,nil);
|
||||
dns_ref=DNSServiceRegistrationCreate(msg.name,msg.type,"",usPort,msg.txt,rend_reply,nil);
|
||||
if(rend_addtorunloop(dns_ref)) {
|
||||
DPRINTF(E_WARN,L_REND,"Add to runloop failed\n");
|
||||
rend_send_response(-1);
|
||||
|
@ -89,6 +89,9 @@
|
||||
Change History (most recent first):
|
||||
|
||||
$Log$
|
||||
Revision 1.29 2006/03/05 08:09:27 rpedde
|
||||
fix up txt records to show password info, mtd-version, and itunes version
|
||||
|
||||
Revision 1.28 2006/02/26 08:46:24 rpedde
|
||||
Merged win32-branch
|
||||
|
||||
@ -480,7 +483,7 @@ void rend_callback(void) {
|
||||
case REND_MSG_TYPE_REGISTER:
|
||||
id=rend_get_interface_id(msg.iface);
|
||||
DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.name,msg.type,msg.port);
|
||||
RegisterOneService(msg.name,msg.type,"local.","\011txtvers=1\034Database ID=beddab1edeadbea7",39,
|
||||
RegisterOneService(msg.name,msg.type,"local.",msg.txt,strlen(msg.txt),
|
||||
msg.port,id);
|
||||
rend_send_response(0); /* success */
|
||||
break;
|
||||
|
@ -161,10 +161,11 @@ int rend_stop(void) {
|
||||
*
|
||||
* register a rendezvous name
|
||||
*/
|
||||
int rend_register(char *name, char *type, int port, char *iface) {
|
||||
int rend_register(char *name, char *type, int port, char *iface, char *txt) {
|
||||
REND_MESSAGE msg;
|
||||
|
||||
if((strlen(name)+1 > MAX_NAME_LEN) || (strlen(type)+1 > MAX_NAME_LEN)) {
|
||||
if((strlen(name)+1 > MAX_NAME_LEN) || (strlen(type)+1 > MAX_NAME_LEN) ||
|
||||
(strlen(txt)+1 > MAX_TEXT_LEN)) {
|
||||
DPRINTF(E_FATAL,L_REND,"Registration failed: name or type too long\n");
|
||||
return -1;
|
||||
}
|
||||
@ -175,7 +176,7 @@ int rend_register(char *name, char *type, int port, char *iface) {
|
||||
strncpy(msg.type,type,MAX_NAME_LEN-1);
|
||||
if(iface)
|
||||
strncpy(msg.iface,iface,MAX_IFACE_NAME_LEN-1);
|
||||
|
||||
strncpy(msg.txt,txt,MAX_NAME_LEN-1);
|
||||
msg.port=port;
|
||||
|
||||
return rend_send_message(&msg);
|
||||
|
@ -25,7 +25,7 @@
|
||||
#define MAX_NAME_LEN 200
|
||||
/* Is there a posixly correct constant for this? */
|
||||
#define MAX_IFACE_NAME_LEN 20
|
||||
|
||||
#define MAX_TEXT_LEN 255
|
||||
|
||||
typedef struct tag_rend_message {
|
||||
int cmd;
|
||||
@ -33,6 +33,7 @@ typedef struct tag_rend_message {
|
||||
char name[MAX_NAME_LEN];
|
||||
char type[MAX_NAME_LEN];
|
||||
char iface[MAX_IFACE_NAME_LEN];
|
||||
char txt[MAX_TEXT_LEN];
|
||||
} REND_MESSAGE;
|
||||
|
||||
#define REND_MSG_TYPE_REGISTER 0
|
||||
|
@ -136,7 +136,7 @@ int rend_stop(void) {
|
||||
* @param iface interface to register with (ignored)
|
||||
* @returns TRUE if registered, FALSE otherwise
|
||||
*/
|
||||
int rend_register(char *name, char *type, int port, char *iface) {
|
||||
int rend_register(char *name, char *type, int port, char *iface, char *txt) {
|
||||
int err;
|
||||
uint16_t port_netorder = htons((unsigned short)port);
|
||||
|
||||
@ -144,7 +144,7 @@ int rend_register(char *name, char *type, int port, char *iface) {
|
||||
name, type, port);
|
||||
|
||||
DNSServiceRegister(&rend_client,0,kDNSServiceInterfaceIndexAny,name,type,"local",NULL,
|
||||
htons((unsigned short)port),0,NULL,rend_reg_reply, NULL);
|
||||
htons((unsigned short)port),strlen(txt),txt,rend_reg_reply, NULL);
|
||||
|
||||
/* throw off a new thread work this */
|
||||
if(!rend_count) {
|
||||
|
@ -25,7 +25,7 @@
|
||||
extern int rend_init(char *user);
|
||||
extern int rend_running(void);
|
||||
extern int rend_stop(void);
|
||||
extern int rend_register(char *name, char *type, int port, char *iface);
|
||||
extern int rend_register(char *name, char *type, int port, char *iface, char *txt);
|
||||
extern int rend_unregister(char *name, char *type, int port);
|
||||
|
||||
#endif /* _REND_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user