static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) { Config *config = userdata; client = c; switch (state) { case AVAHI_CLIENT_FAILURE: if (config->no_fail && avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) { int error; /* We have been disconnected, so let reconnect */ fprintf(stderr, "Disconnected, reconnecting ...\n"); avahi_client_free(client); client = NULL; entry_group = NULL; if (!(client = avahi_client_new(avahi_simple_poll_get(simple_poll), AVAHI_CLIENT_NO_FAIL, client_callback, config, &error))) { fprintf(stderr, "Failed to create client object: %s\n", avahi_strerror(error)); avahi_simple_poll_quit(simple_poll); } } else { fprintf(stderr, "Client failure, exiting: %s\n", avahi_strerror(avahi_client_errno(c))); avahi_simple_poll_quit(simple_poll); } break; case AVAHI_CLIENT_S_RUNNING: if (register_stuff(config) < 0) avahi_simple_poll_quit(simple_poll); break; case AVAHI_CLIENT_S_COLLISION: if (config->verbose) fprintf(stderr, "Host name conflict\n"); if (entry_group) { avahi_entry_group_free(entry_group); entry_group = NULL; } break; case AVAHI_CLIENT_CONNECTING: if (config->verbose) fprintf(stderr, "Waiting for daemon ...\n"); break; case AVAHI_CLIENT_S_REGISTERING: ; } }
static void client_callback(AvahiClient *client, AvahiClientState state, void *userdata) { ctx->client = client; switch (state) { case AVAHI_CLIENT_S_RUNNING: /* The server has startup successfully and registered its host * name on the network, so it's time to create our services */ if (!ctx->group) register_stuff(); break; case AVAHI_CLIENT_S_COLLISION: if (ctx->group) avahi_entry_group_reset(ctx->group); break; case AVAHI_CLIENT_FAILURE: { if (avahi_client_errno(client) == AVAHI_ERR_DISCONNECTED) { int error; avahi_client_free(ctx->client); ctx->client = NULL; ctx->group = NULL; /* Reconnect to the server */ if (!(ctx->client = avahi_client_new(avahi_threaded_poll_get(ctx->threaded_poll), AVAHI_CLIENT_NO_FAIL, client_callback, ctx, &error))) { LOG(log_error, logtype_afpd, "Failed to contact server: %s", avahi_strerror(error)); avahi_threaded_poll_quit(ctx->threaded_poll); } } else { LOG(log_error, logtype_afpd, "Client failure: %s", avahi_strerror(avahi_client_errno(client))); avahi_threaded_poll_quit(ctx->threaded_poll); } break; } case AVAHI_CLIENT_S_REGISTERING: break; case AVAHI_CLIENT_CONNECTING: break; } }
static void client_callback(AvahiClient *client, AvahiClientState state, void *userdata) { struct context *ctx = userdata; ctx->client = client; switch (state) { case AVAHI_CLIENT_S_RUNNING: register_stuff(ctx); break; case AVAHI_CLIENT_S_COLLISION: case AVAHI_CLIENT_S_REGISTERING: if (ctx->group) avahi_entry_group_reset(ctx->group); break; case AVAHI_CLIENT_FAILURE: if (avahi_client_errno(client) == AVAHI_ERR_DISCONNECTED) { int error; avahi_client_free(ctx->client); ctx->client = NULL; ctx->group = NULL; /* Reconnect to the server */ if (!(ctx->client = avahi_client_new( avahi_threaded_poll_get(ctx->threaded_poll), AVAHI_CLIENT_NO_FAIL, client_callback, ctx, &error))) { rs_log_crit("Failed to contact server: %s", avahi_strerror(error)); avahi_threaded_poll_quit(ctx->threaded_poll); } } else { rs_log_crit("Client failure: %s", avahi_strerror(avahi_client_errno(client))); avahi_threaded_poll_quit(ctx->threaded_poll); } break; case AVAHI_CLIENT_CONNECTING: ; } }
static void client_callback(AvahiClient *client, AvahiClientState state, void *userdata) { ctx.client = client; switch (state) { case AVAHI_CLIENT_S_RUNNING: /* The server has started up successfully and registered its host * name on the network, so it's time to create our services */ register_stuff(); break; case AVAHI_CLIENT_S_COLLISION: case AVAHI_CLIENT_S_REGISTERING: if (ctx.group) avahi_entry_group_reset(ctx.group); break; case AVAHI_CLIENT_FAILURE: if (avahi_client_errno(client) == AVAHI_ERR_DISCONNECTED) { int error; avahi_client_free(ctx.client); ctx.client = NULL; ctx.group = NULL; /* Reconnect to the server */ ctx.client = avahi_client_new( avahi_threaded_poll_get(ctx.threaded_poll), AVAHI_CLIENT_NO_FAIL, client_callback, &ctx, &error); if (!ctx.client) { DPRINTF(E_ERROR, L_SSDP, "Failed to contact server: %s\n", avahi_strerror(error)); avahi_threaded_poll_quit(ctx.threaded_poll); } } else { DPRINTF(E_ERROR, L_SSDP, "Client failure: %s\n", avahi_strerror(avahi_client_errno(client))); avahi_threaded_poll_quit(ctx.threaded_poll); } break; case AVAHI_CLIENT_CONNECTING: default: break; } }
int __init my_init(void) { int err = -ENOMEM; item1 = allocate_thing(arguments); item2 = allocate_thing2(arguments2); if (!item1 || !item2) goto fail; err = register_stuff(item1, item2); if (!err) stuff_ok = 1; else goto fail; return 0; /* success */ fail: my_cleanup(); return err; }
static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) { Config *config = userdata; assert(g); assert(config); switch (state) { case AVAHI_ENTRY_GROUP_ESTABLISHED: fprintf(stderr, "Established under name '%s'\n", config->name); break; case AVAHI_ENTRY_GROUP_FAILURE: fprintf(stderr, "Failed to register: %s\n", avahi_strerror(avahi_client_errno(client))); break; case AVAHI_ENTRY_GROUP_COLLISION: { char *n; if (config->command == COMMAND_PUBLISH_SERVICE) n = avahi_alternative_service_name(config->name); else { assert(config->command == COMMAND_PUBLISH_ADDRESS); n = avahi_alternative_host_name(config->name); } fprintf(stderr, "Name collision, picking new name '%s'.\n", n); avahi_free(config->name); config->name = n; register_stuff(config); break; } case AVAHI_ENTRY_GROUP_UNCOMMITED: case AVAHI_ENTRY_GROUP_REGISTERING: ; } }
/* Called when publishing of service data completes */ static void publish_reply(AvahiEntryGroup *UNUSED(g), AvahiEntryGroupState state, void *userdata) { struct context *ctx = userdata; switch (state) { case AVAHI_ENTRY_GROUP_COLLISION: { char *n; /* Pick a new name for our service */ n = avahi_alternative_service_name(ctx->name); assert(n); avahi_free(ctx->name); ctx->name = n; register_stuff(ctx); break; } case AVAHI_ENTRY_GROUP_FAILURE: rs_log_crit("Failed to register service: %s", avahi_strerror(avahi_client_errno(ctx->client))); avahi_threaded_poll_quit(ctx->threaded_poll); break; case AVAHI_ENTRY_GROUP_ESTABLISHED: rs_log_info("registered as \"%s.%s.%s\"", avahi_client_get_host_name(ctx->client), ctx->service_type, avahi_client_get_domain_name(ctx->client)); break; case AVAHI_ENTRY_GROUP_UNCOMMITED: case AVAHI_ENTRY_GROUP_REGISTERING: ; } }
/* * Tries to setup the Zeroconf thread and any * neccessary config setting. */ void md_zeroconf_register(const AFPObj *obj) { int error; register_stuff(obj); return; }