Commit dc59abdf authored by Barnabás Pőcze's avatar Barnabás Pőcze
Browse files

pulse-server: module-zeroconf-publish: reorder functions

parent bf593ee3
Pipeline #441035 passed with stages
in 5 minutes and 42 seconds
......@@ -122,55 +122,7 @@ static const struct pw_core_events core_events = {
.error = on_core_error,
};
static void get_service_name(struct pw_manager_object *o, char *buf, size_t length)
{
const char *hn, *un, *n;
hn = pw_get_host_name();
un = pw_get_user_name();
n = pw_properties_get(o->props, PW_KEY_NODE_DESCRIPTION);
snprintf(buf, length, "%s@%s: %s", un, hn, n);
}
static void service_free(struct service *s)
{
if (s->entry_group) {
pw_log_debug("Removing entry group for %s.", s->service_name);
avahi_entry_group_free(s->entry_group);
}
if (s->name) {
pw_log_debug("Removing service for node: %s", s->name);
free(s->name);
}
pw_properties_free(s->props);
avahi_string_list_free(s->txt);
spa_list_remove(&s->link);
}
static void unpublish_service(struct service *s, bool free_entry_group)
{
if (s->entry_group && free_entry_group) {
avahi_entry_group_free(s->entry_group);
s->entry_group = NULL;
}
spa_list_remove(&s->link); /* remove from `published` list */
spa_list_append(&s->userdata->pending, &s->link);
}
static void unpublish_all_services(struct module_zeroconf_publish_data *d, bool free_entry_group)
{
struct service *s;
spa_list_consume(s, &d->published, link)
unpublish_service(s, free_entry_group);
}
static char* channel_map_snprint(char *s, size_t l, const struct channel_map *map)
static char *channel_map_snprint(char *s, size_t l, const struct channel_map *map)
{
unsigned channel;
bool first = true;
......@@ -262,6 +214,17 @@ static void fill_service_data(struct module_zeroconf_publish_data *d, struct ser
spa_assert_not_reached();
}
static void get_service_name(struct pw_manager_object *o, char *buf, size_t length)
{
const char *hn, *un, *n;
hn = pw_get_host_name();
un = pw_get_user_name();
n = pw_properties_get(o->props, PW_KEY_NODE_DESCRIPTION);
snprintf(buf, length, "%s@%s: %s", un, hn, n);
}
static struct service *create_service(struct module_zeroconf_publish_data *d, struct pw_manager_object *o)
{
struct service *s;
......@@ -279,6 +242,24 @@ static struct service *create_service(struct module_zeroconf_publish_data *d, st
return s;
}
static void service_free(struct service *s)
{
if (s->entry_group) {
pw_log_debug("Removing entry group for %s.", s->service_name);
avahi_entry_group_free(s->entry_group);
}
if (s->name) {
pw_log_debug("Removing service for node: %s", s->name);
free(s->name);
}
pw_properties_free(s->props);
avahi_string_list_free(s->txt);
spa_list_remove(&s->link);
}
static AvahiStringList* txt_record_server_data(struct pw_core_info *info, AvahiStringList *l)
{
const char *t;
......@@ -305,43 +286,6 @@ static AvahiStringList* txt_record_server_data(struct pw_core_info *info, AvahiS
return l;
}
static void publish_service(struct service *s);
static void service_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata)
{
struct service *s = userdata;
spa_assert(s);
switch (state) {
case AVAHI_ENTRY_GROUP_ESTABLISHED:
pw_log_info("Successfully established service %s.", s->service_name);
break;
case AVAHI_ENTRY_GROUP_COLLISION:
{
char *t;
t = avahi_alternative_service_name(s->service_name);
pw_log_info("Name collision, renaming %s to %s.", s->service_name, t);
snprintf(s->service_name, sizeof(s->service_name), "%s", t);
avahi_free(t);
publish_service(s);
break;
}
case AVAHI_ENTRY_GROUP_FAILURE:
pw_log_error("Failed to register service: %s",
avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))));
unpublish_service(s, true);
break;
case AVAHI_ENTRY_GROUP_UNCOMMITED:
case AVAHI_ENTRY_GROUP_REGISTERING:
break;
}
}
#define PA_CHANNEL_MAP_SNPRINT_MAX (CHANNELS_MAX * 32)
static AvahiStringList *get_service_txt(const struct service *s)
......@@ -385,6 +329,8 @@ static AvahiStringList *get_service_txt(const struct service *s)
return txt;
}
static void service_entry_group_callback(AvahiEntryGroup *, AvahiEntryGroupState, void *);
static void publish_service(struct service *s)
{
if (!s->userdata->client || avahi_client_get_state(s->userdata->client) != AVAHI_CLIENT_S_RUNNING)
......@@ -461,6 +407,17 @@ static void publish_service(struct service *s)
pw_log_info("Successfully created entry group for %s.", s->service_name);
}
static void unpublish_service(struct service *s, bool free_entry_group)
{
if (s->entry_group && free_entry_group) {
avahi_entry_group_free(s->entry_group);
s->entry_group = NULL;
}
spa_list_remove(&s->link); /* remove from `published` list */
spa_list_append(&s->userdata->pending, &s->link);
}
static void publish_pending(struct module_zeroconf_publish_data *data)
{
struct service *s, *next;
......@@ -469,6 +426,49 @@ static void publish_pending(struct module_zeroconf_publish_data *data)
publish_service(s);
}
static void unpublish_all_services(struct module_zeroconf_publish_data *d, bool free_entry_group)
{
struct service *s;
spa_list_consume(s, &d->published, link)
unpublish_service(s, free_entry_group);
}
static void service_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata)
{
struct service *s = userdata;
spa_assert(s);
switch (state) {
case AVAHI_ENTRY_GROUP_ESTABLISHED:
pw_log_info("Successfully established service %s.", s->service_name);
break;
case AVAHI_ENTRY_GROUP_COLLISION:
{
char *t;
t = avahi_alternative_service_name(s->service_name);
pw_log_info("Name collision, renaming %s to %s.", s->service_name, t);
snprintf(s->service_name, sizeof(s->service_name), "%s", t);
avahi_free(t);
publish_service(s);
break;
}
case AVAHI_ENTRY_GROUP_FAILURE:
pw_log_error("Failed to register service: %s",
avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))));
unpublish_service(s, true);
break;
case AVAHI_ENTRY_GROUP_UNCOMMITED:
case AVAHI_ENTRY_GROUP_REGISTERING:
break;
}
}
static void client_callback(AvahiClient *c, AvahiClientState state, void *d)
{
struct module_zeroconf_publish_data *data = d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment