Mercurial > pidgin.yaz
diff libpurple/protocols/bonjour/mdns_win32.c @ 17739:c96b085ddf5c
Clean up Bonjour service publishing and improve XEP-0174 compliance.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 05 Jun 2007 22:13:10 +0000 |
parents | d7b50cac1c7a |
children | c921f901c7ea |
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/mdns_win32.c Tue Jun 05 21:32:28 2007 +0000 +++ b/libpurple/protocols/bonjour/mdns_win32.c Tue Jun 05 22:13:10 2007 +0000 @@ -235,46 +235,56 @@ TXTRecordRef dns_data; char portstring[6]; int ret = 0; - + const char *jid, *aim, *email; + DNSServiceErrorType set_ret; + TXTRecordCreate(&dns_data, 256, NULL); /* Convert the port to a string */ snprintf(portstring, sizeof(portstring), "%d", data->port_p2pj); - - /* Publish standard records */ + + jid = purple_account_get_string(data->account, "jid", NULL); + aim = purple_account_get_string(data->account, "AIM", NULL); + email = purple_account_get_string(data->account, "email", NULL); + + /* We should try to follow XEP-0174, but some clients have "issues", so we humor them. + * See http://telepathy.freedesktop.org/wiki/SalutInteroperability + */ - if (kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "txtvers", strlen(data->txtvers), data->txtvers) || - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "version", strlen(data->version), data->version) || - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "1st", strlen(data->first), data->first) || - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "last", strlen(data->last), data->last) || - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "port", strlen(portstring), portstring) || - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "phsh", strlen(data->phsh), data->phsh) || - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "status", strlen(data->status), data->status) || - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "vc", strlen(data->vc), data->vc)) - { - purple_debug_error("bonjour", "Unable to allocate memory for text record.\n"); - ret = -1; - } - else if ((data->email != NULL) && (*data->email != '\0') && - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "email", strlen(data->email), data->email)) - { - purple_debug_error("bonjour", "Unable to allocate memory for text record.\n"); - ret = -1; - } - else if ((data->jid != NULL) && (*data->jid != '\0') && - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "email", strlen(data->jid), data->jid)) - { - purple_debug_error("bonjour", "Unable to allocate memory for text record.\n"); - ret = -1; - } - else if ((data->AIM != NULL) && (*data->AIM != '\0') && - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "AIM", strlen(data->AIM), data->AIM)) - { - purple_debug_error("bonjour", "Unable to allocate memory for text record.\n"); - ret = -1; - } - else if ((data->msg != NULL) && (*data->msg != '\0') && - kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "msg", strlen(data->msg), data->msg)) + /* Needed by iChat */ + set_ret = TXTRecordSetValue(&dns_data, "txtvers", 1, "1"); + /* Needed by Gaim/Pidgin <= 2.0.1 (remove at some point) */ + if (set_ret == kDNSServiceErr_NoError) + set_ret = TXTRecordSetValue(&dns_data, "1st", strlen(data->first), data->first); + /* Needed by Gaim/Pidgin <= 2.0.1 (remove at some point) */ + if (set_ret == kDNSServiceErr_NoError) + set_ret = TXTRecordSetValue(&dns_data, "last", strlen(data->last), data->last); + /* Needed by Adium */ + if (set_ret == kDNSServiceErr_NoError) + set_ret = TXTRecordSetValue(&dns_data, "port.p2pj", strlen(portstring), portstring); + /* Needed by iChat, Gaim/Pidgin <= 2.0.1 */ + if (set_ret == kDNSServiceErr_NoError) + set_ret = TXTRecordSetValue(&dns_data, "status", strlen(data->status), data->status); + if (set_ret == kDNSServiceErr_NoError) + set_ret = TXTRecordSetValue(&dns_data, "ver", strlen(VERSION), VERSION); + /* Currently always set to "!" since we don't support AV and wont ever be in a conference */ + if (set_ret == kDNSServiceErr_NoError) + set_ret = TXTRecordSetValue(&dns_data, "vc", strlen(data->vc), data->vc); + if (set_ret == kDNSServiceErr_NoError && email != NULL && *email != '\0') + set_ret = TXTRecordSetValue(&dns_data, "email", strlen(email), email); + if (set_ret == kDNSServiceErr_NoError && jid != NULL && *jid != '\0') + set_ret = TXTRecordSetValue(&dns_data, "jid", strlen(jid), jid); + /* Nonstandard, but used by iChat */ + if (set_ret == kDNSServiceErr_NoError && aim != NULL && *aim != '\0') + set_ret = TXTRecordSetValue(&dns_data, "AIM", strlen(aim), aim); + if (set_ret == kDNSServiceErr_NoError && data->msg != NULL && *data->msg != '\0') + set_ret = TXTRecordSetValue(&dns_data, "msg", strlen(data->msg), data->msg); + if (set_ret == kDNSServiceErr_NoError && data->phsh != NULL && *data->phsh != '\0') + set_ret = TXTRecordSetValue(&dns_data, "phsh", strlen(data->phsh), data->phsh); + + /* TODO: ext, nick, node */ + + if (set_ret != kDNSServiceErr_NoError) { purple_debug_error("bonjour", "Unable to allocate memory for text record.\n"); ret = -1; @@ -288,7 +298,7 @@ switch (type) { case PUBLISH_START: - err = DNSServiceRegister(&data->advertisement, 0, 0, data->name, ICHAT_SERVICE, + err = DNSServiceRegister(&data->advertisement, 0, 0, purple_account_get_username(data->account), ICHAT_SERVICE, NULL, NULL, data->port_p2pj, TXTRecordGetLength(&dns_data), TXTRecordGetBytesPtr(&dns_data), _mdns_service_register_callback, NULL); break;