From cf59f7dc338848f603ebeb5c1f394275a685175e Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sun, 5 Mar 2006 08:09:27 +0000 Subject: [PATCH] fix up txt records to show password info, mtd-version, and itunes version --- src/main.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- src/rend-howl.c | 4 ++-- src/rend-osx.c | 18 ++++++++++++++++-- src/rend-posix.c | 5 ++++- src/rend-unix.c | 7 ++++--- src/rend-unix.h | 3 ++- src/rend-win32.c | 4 ++-- src/rend.h | 2 +- 8 files changed, 73 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 6a9ef9ed..4aad816d 100644 --- a/src/main.c +++ b/src/main.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -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 diff --git a/src/rend-howl.c b/src/rend-howl.c index 72dc752a..e6c18407 100644 --- a/src/rend-howl.c +++ b/src/rend-howl.c @@ -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) { diff --git a/src/rend-osx.c b/src/rend-osx.c index 556f2ab5..bcc51ebb 100644 --- a/src/rend-osx.c +++ b/src/rend-osx.c @@ -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); diff --git a/src/rend-posix.c b/src/rend-posix.c index 752f6e90..c6816cb7 100644 --- a/src/rend-posix.c +++ b/src/rend-posix.c @@ -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; diff --git a/src/rend-unix.c b/src/rend-unix.c index bf212ecd..0b16e45b 100644 --- a/src/rend-unix.c +++ b/src/rend-unix.c @@ -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); diff --git a/src/rend-unix.h b/src/rend-unix.h index 3da91503..f84081ec 100644 --- a/src/rend-unix.h +++ b/src/rend-unix.h @@ -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 diff --git a/src/rend-win32.c b/src/rend-win32.c index f2f27aab..e6b1dde7 100644 --- a/src/rend-win32.c +++ b/src/rend-win32.c @@ -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) { diff --git a/src/rend.h b/src/rend.h index 7d76fcfd..acbd8ddd 100644 --- a/src/rend.h +++ b/src/rend.h @@ -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_ */