Stop the TXT record encoding madness

Use a proper string array to pass the TXT record fields, get rid of the
encoding stuff.

Changes the plugin API.
This commit is contained in:
Julien BLACHE
2009-04-08 16:35:59 +02:00
parent 2e2dbc6964
commit 3ec2cc0f00
6 changed files with 43 additions and 83 deletions

View File

@@ -505,14 +505,11 @@ mdns_deinit(void)
}
int
mdns_register(char *name, char *type, int port, char *txt)
mdns_register(char *name, char *type, int port, char **txt)
{
struct mdns_group_entry *ge;
AvahiStringList *txt_sl;
unsigned char count;
unsigned char *key;
unsigned char *nextkey;
unsigned char *newtxt;
int i;
DPRINTF(E_DBG, L_REND, "Adding mDNS service %s/%s\n", name, type);
@@ -524,41 +521,14 @@ mdns_register(char *name, char *type, int port, char *txt)
ge->type = strdup(type);
ge->port = port;
/* Build a string list from the "encoded" txt record
* "<len1><record1><len2><record2>...<recordN>\0"
* Length is 1 byte
*/
count = 0;
txt_sl = NULL;
newtxt = (unsigned char *)strdup(txt);
if (!newtxt)
for (i = 0; txt[i]; i++)
{
DPRINTF(E_FATAL, L_REND, "Out of memory\n");
txt_sl = avahi_string_list_add(txt_sl, txt[i]);
return -1;
DPRINTF(E_DBG, L_REND, "Added key %s\n", txt[i]);
}
key = nextkey = newtxt;
if (*nextkey)
count = *nextkey;
DPRINTF(E_DBG, L_REND, "Found key of size %d\n", count);
while ((*nextkey) && (nextkey < (newtxt + strlen(txt))))
{
key = nextkey + 1;
nextkey += (count + 1);
count = *nextkey;
*nextkey = '\0';
txt_sl = avahi_string_list_add(txt_sl, (char *)key);
DPRINTF(E_DBG, L_REND, "Added key %s\n", key);
*nextkey = count;
}
free(newtxt);
ge->txt = txt_sl;
ge->next = group_entries;