+ va_start(va, name);
+ flx_server_add_text_va(s, id, interface, protocol, flags, name, va);
+ va_end(va);
+}
+
+static void escape_service_name(gchar *d, guint size, const gchar *s) {
+ g_assert(d);
+ g_assert(size);
+ g_assert(s);
+
+ while (*s && size >= 2) {
+ if (*s == '.' || *s == '\\') {
+ if (size < 3)
+ break;
+
+ *(d++) = '\\';
+ size--;
+ }
+
+ *(d++) = *(s++);
+ size--;
+ }
+
+ g_assert(size > 0);
+ *(d++) = 0;
+}
+
+
+void flx_server_add_service_va(
+ flxServer *s,
+ gint id,
+ gint interface,
+ guchar protocol,
+ const gchar *type,
+ const gchar *name,
+ const gchar *domain,
+ const gchar *host,
+ guint16 port,
+ va_list va) {
+
+ gchar ptr_name[256], svc_name[256], ename[64], enum_ptr[256];
+ flxRecord *r;
+
+ g_assert(s);
+ g_assert(type);
+ g_assert(name);
+
+ escape_service_name(ename, sizeof(ename), name);
+
+ if (domain) {
+ while (domain[0] == '.')
+ domain++;
+ } else
+ domain = "local";
+
+ if (!host)
+ host = s->hostname;
+
+ snprintf(ptr_name, sizeof(ptr_name), "%s.%s", type, domain);
+ snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, type, domain);
+
+ flx_server_add_ptr(s, id, interface, protocol, FALSE, ptr_name, svc_name);
+
+ r = flx_record_new_full(svc_name, FLX_DNS_CLASS_IN, FLX_DNS_TYPE_SRV);
+ r->data.srv.priority = 0;
+ r->data.srv.weight = 0;
+ r->data.srv.port = port;
+ r->data.srv.name = flx_normalize_name(host);
+ flx_server_add(s, id, interface, protocol, TRUE, r);
+ flx_record_unref(r);
+
+ flx_server_add_text_va(s, id, interface, protocol, FALSE, svc_name, va);
+
+ snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", domain);
+ flx_server_add_ptr(s, id, interface, protocol, FALSE, enum_ptr, ptr_name);