[pulseaudio-commits] r1674 - /branches/lennart/src/modules/module-zeroconf-publish.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu Aug 16 06:47:20 PDT 2007


Author: lennart
Date: Thu Aug 16 15:47:18 2007
New Revision: 1674

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1674&root=3Dpulseaudio&vi=
ew=3Drev
Log:
truncate service names if necessary, include user name in service string

Modified:
    branches/lennart/src/modules/module-zeroconf-publish.c

Modified: branches/lennart/src/modules/module-zeroconf-publish.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/mo=
dule-zeroconf-publish.c?rev=3D1674&root=3Dpulseaudio&r1=3D1673&r2=3D1674&vi=
ew=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/modules/module-zeroconf-publish.c (original)
+++ branches/lennart/src/modules/module-zeroconf-publish.c Thu Aug 16 15:47=
:18 2007
@@ -35,6 +35,7 @@
 #include <avahi-client/publish.h>
 #include <avahi-common/alternative.h>
 #include <avahi-common/error.h>
+#include <avahi-common/domain.h>
 =

 #include <pulse/xmalloc.h>
 #include <pulse/util.h>
@@ -102,25 +103,31 @@
 };
 =

 static void get_service_data(struct userdata *u, struct service *s, pa_sam=
ple_spec *ret_ss, char **ret_description) {
-    pa_assert(u && s && s->loaded.valid && ret_ss && ret_description);
+    pa_assert(u);
+    pa_assert(s);
+    pa_assert(s->loaded.valid);
+    pa_assert(ret_ss);
+    pa_assert(ret_description);
 =

     if (s->loaded.type =3D=3D PA_NAMEREG_SINK) {
-        pa_sink *sink =3D pa_idxset_get_by_index(u->core->sinks, s->loaded=
.index);
-        pa_assert(sink);
+        pa_sink *sink =3D PA_SINK(pa_idxset_get_by_index(u->core->sinks, s=
->loaded.index));
+        pa_sink_assert_ref(sink);
         *ret_ss =3D sink->sample_spec;
         *ret_description =3D sink->description;
+        =

     } else if (s->loaded.type =3D=3D PA_NAMEREG_SOURCE) {
-        pa_source *source =3D pa_idxset_get_by_index(u->core->sources, s->=
loaded.index);
-        pa_assert(source);
+        pa_source *source =3D PA_SOURCE(pa_idxset_get_by_index(u->core->so=
urces, s->loaded.index));
+        pa_source_assert_ref(source);
         *ret_ss =3D source->sample_spec;
         *ret_description =3D source->description;
     } else
-        pa_assert(0);
+        pa_assert_not_reached();
 }
 =

 static AvahiStringList* txt_record_server_data(pa_core *c, AvahiStringList=
 *l) {
     char s[128];
-    pa_assert(c);
+    =

+    pa_core_assert_ref(c);
 =

     l =3D avahi_string_list_add_pair(l, "server-version", PACKAGE_NAME" "P=
ACKAGE_VERSION);
     l =3D avahi_string_list_add_pair(l, "user-name", pa_get_user_name(s, s=
izeof(s)));
@@ -134,6 +141,8 @@
 =

 static void service_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGro=
upState state, void *userdata) {
     struct service *s =3D userdata;
+
+    pa_assert(s);
 =

     if (state =3D=3D AVAHI_ENTRY_GROUP_COLLISION) {
         char *t;
@@ -244,7 +253,7 @@
 =

 static struct service *get_service(struct userdata *u, const char *name, c=
onst char *description) {
     struct service *s;
-    char hn[64];
+    char hn[64], un[64];
 =

     if ((s =3D pa_hashmap_get(u->services, name)))
         return s;
@@ -255,7 +264,7 @@
     s->published =3D UNPUBLISHED;
     s->name =3D pa_xstrdup(name);
     s->loaded.valid =3D s->autoload.valid =3D 0;
-    s->service_name =3D pa_sprintf_malloc("%s on %s", description ? descri=
ption : s->name, pa_get_host_name(hn, sizeof(hn)));
+    s->service_name =3D pa_truncate_utf8(pa_sprintf_malloc("%s@%s: %s", pa=
_get_user_name(un, sizeof(un)), pa_get_host_name(hn, sizeof(hn)), descripti=
on ? description : s->name), AVAHI_LABEL_MAX-1);
 =

     pa_hashmap_put(u->services, s->name, s);
 =

@@ -265,7 +274,9 @@
 static int publish_sink(struct userdata *u, pa_sink *s) {
     struct service *svc;
     int ret;
-    pa_assert(u && s);
+
+    pa_assert(u);
+    pa_sink_assert_ref(s);
 =

     svc =3D get_service(u, s->name, s->description);
     if (svc->loaded.valid)
@@ -286,7 +297,8 @@
     struct service *svc;
     int ret;
 =

-    pa_assert(u && s);
+    pa_assert(u);
+    pa_source_assert_ref(s);
 =

     svc =3D get_service(u, s->name, s->description);
     if (svc->loaded.valid)
@@ -309,7 +321,8 @@
     struct service *svc;
     int ret;
 =

-    pa_assert(u && s);
+    pa_assert(u);
+    pa_assert(s);
 =

     svc =3D get_service(u, s->name, NULL);
     if (svc->autoload.valid)
@@ -328,7 +341,9 @@
 =

 static int remove_sink(struct userdata *u, uint32_t idx) {
     struct service *svc;
-    pa_assert(u && idx !=3D PA_INVALID_INDEX);
+    =

+    pa_assert(u);
+    pa_assert(idx !=3D PA_INVALID_INDEX);
 =

     if (!(svc =3D pa_dynarray_get(u->sink_dynarray, idx)))
         return 0;
@@ -344,7 +359,9 @@
 =

 static int remove_source(struct userdata *u, uint32_t idx) {
     struct service *svc;
-    pa_assert(u && idx !=3D PA_INVALID_INDEX);
+    =

+    pa_assert(u);
+    pa_assert(idx !=3D PA_INVALID_INDEX);
 =

     if (!(svc =3D pa_dynarray_get(u->source_dynarray, idx)))
         return 0;
@@ -360,7 +377,9 @@
 =

 static int remove_autoload(struct userdata *u, uint32_t idx) {
     struct service *svc;
-    pa_assert(u && idx !=3D PA_INVALID_INDEX);
+    =

+    pa_assert(u);
+    pa_assert(idx !=3D PA_INVALID_INDEX);
 =

     if (!(svc =3D pa_dynarray_get(u->autoload_dynarray, idx)))
         return 0;
@@ -376,14 +395,17 @@
 =

 static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t,=
 uint32_t idx, void *userdata) {
     struct userdata *u =3D userdata;
-    pa_assert(u && c);
+    =

+    pa_assert(u);
+    pa_core_assert_ref(c);
 =

     switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK)
+        =

         case PA_SUBSCRIPTION_EVENT_SINK: {
             if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) =3D=3D PA_SUBSCRIPTI=
ON_EVENT_NEW) {
                 pa_sink *sink;
 =

-                if ((sink =3D pa_idxset_get_by_index(c->sinks, idx))) {
+                if ((sink =3D PA_SINK(pa_idxset_get_by_index(c->sinks, idx=
)))) {
                     if (publish_sink(u, sink) < 0)
                         goto fail;
                 }
@@ -399,7 +421,7 @@
             if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) =3D=3D PA_SUBSCRIPTI=
ON_EVENT_NEW) {
                 pa_source *source;
 =

-                if ((source =3D pa_idxset_get_by_index(c->sources, idx))) {
+                if ((source =3D PA_SOURCE(pa_idxset_get_by_index(c->source=
s, idx)))) {
                     if (publish_source(u, source) < 0)
                         goto fail;
                 }
@@ -456,6 +478,8 @@
     AvahiStringList *txt =3D NULL;
     int r =3D -1;
 =

+    pa_assert(u);
+    =

     if (!u->main_entry_group) {
         if (!(u->main_entry_group =3D avahi_entry_group_new(u->client, mai=
n_entry_group_callback, u))) {
             pa_log("avahi_entry_group_new() failed: %s", avahi_strerror(av=
ahi_client_errno(u->client)));
@@ -505,11 +529,11 @@
 =

     pa_log_debug("Publishing services in Zeroconf");
 =

-    for (sink =3D pa_idxset_first(u->core->sinks, &idx); sink; sink =3D pa=
_idxset_next(u->core->sinks, &idx))
+    for (sink =3D PA_SINK(pa_idxset_first(u->core->sinks, &idx)); sink; si=
nk =3D PA_SINK(pa_idxset_next(u->core->sinks, &idx)))
         if (publish_sink(u, sink) < 0)
             goto fail;
 =

-    for (source =3D pa_idxset_first(u->core->sources, &idx); source; sourc=
e =3D pa_idxset_next(u->core->sources, &idx))
+    for (source =3D PA_SOURCE(pa_idxset_first(u->core->sources, &idx)); so=
urce; source =3D PA_SOURCE(pa_idxset_next(u->core->sources, &idx)))
         if (publish_source(u, source) < 0)
             goto fail;
 =

@@ -558,7 +582,9 @@
 =

 static void client_callback(AvahiClient *c, AvahiClientState state, void *=
userdata) {
     struct userdata *u =3D userdata;
+    =

     pa_assert(c);
+    pa_assert(u);
 =

     u->client =3D c;
 =

@@ -592,7 +618,7 @@
     struct userdata *u;
     uint32_t port =3D PA_NATIVE_DEFAULT_PORT;
     pa_modargs *ma =3D NULL;
-    char hn[256];
+    char hn[256], un[256];
     int error;
 =

     if (!(ma =3D pa_modargs_new(m->argument, valid_modargs))) {
@@ -623,7 +649,7 @@
 =

     u->main_entry_group =3D NULL;
 =

-    u->service_name =3D pa_xstrdup(pa_get_host_name(hn, sizeof(hn)));
+    u->service_name =3D pa_truncate_utf8(pa_sprintf_malloc("%s@%s", pa_get=
_user_name(un, sizeof(un)), pa_get_host_name(hn, sizeof(hn))), AVAHI_LABEL_=
MAX);
 =

     if (!(u->client =3D avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FA=
IL, client_callback, u, &error))) {
         pa_log("pa_avahi_client_new() failed: %s", avahi_strerror(error));
@@ -678,7 +704,6 @@
     if (u->autoload_dynarray)
         pa_dynarray_free(u->autoload_dynarray, NULL, NULL);
 =

-
     if (u->main_entry_group)
         avahi_entry_group_free(u->main_entry_group);
 =





More information about the pulseaudio-commits mailing list