Permalink
Browse files

committed wrong avahi example

  • Loading branch information...
1 parent 5f796d7 commit e8936172660f2c4e7527002fa3a4767a27a1e7be @ers35 ers35 committed Jul 29, 2012
Showing with 48 additions and 83 deletions.
  1. +48 −83 0.0.0.0_8080/#0.0.0.0/handlers/avahi-publish.c
View
131 0.0.0.0_8080/#0.0.0.0/handlers/avahi-publish.c
@@ -1,8 +1,12 @@
-#ifdef HAVE_CONFIG_H
- #include <config.h>
-#endif
+/*
+
+Installation: rename to main.c and place in handlers directory
+Usage: make sure avahi-daemon is running, then start G-WAN
+
+*/
+
+#include "gwan.h"
-#include <time.h>
#include <stdio.h>
#include <stdlib.h>
@@ -16,105 +20,66 @@
#pragma link "avahi-client"
-static AvahiEntryGroup *group = NULL;
-static AvahiSimplePoll *simple_poll = NULL;
static char *name = "G-WAN (Global-WAN)";
-static void create_services(AvahiClient *c);
-
-static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void *userdata)
+static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata)
{
- group = g;
+ *(AvahiEntryGroup **)userdata = g;
switch (state)
{
- case AVAHI_ENTRY_GROUP_ESTABLISHED: {
- fprintf(stderr, "Service '%s' successfully established.\n", name);
- break;
- }
-
- case AVAHI_ENTRY_GROUP_COLLISION: {
- char *n;
-
- n = avahi_alternative_service_name(name);
- avahi_free(name);
- name = n;
-
- fprintf(stderr, "Service name collision, renaming service to '%s'\n", name);
-
- create_services(avahi_entry_group_get_client(g));
- break;
- }
-
- case AVAHI_ENTRY_GROUP_FAILURE: {
- fprintf(stderr, "Entry group failure: %s\n", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))));
+ case AVAHI_ENTRY_GROUP_ESTABLISHED: {
+ printf("Service '%s' successfully established.\n", name);
+ break;
+ }
- avahi_simple_poll_quit(simple_poll);
- break;
- }
- case AVAHI_ENTRY_GROUP_UNCOMMITED: {}
- case AVAHI_ENTRY_GROUP_REGISTERING: {}
+ case AVAHI_ENTRY_GROUP_COLLISION: { break; }
+ case AVAHI_ENTRY_GROUP_FAILURE: { break; }
+ case AVAHI_ENTRY_GROUP_UNCOMMITED: { break; }
+ case AVAHI_ENTRY_GROUP_REGISTERING: { break; }
}
}
-static void create_services(AvahiClient *c)
+static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata)
{
- if (!group) {
- group = avahi_entry_group_new(c, entry_group_callback, NULL);
- }
-
- if (avahi_entry_group_is_empty(group)) {
- fprintf(stderr, "Adding service '%s'\n", name);
-
- avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_http._tcp", NULL, NULL, 8080, NULL);
-
- /* Tell the server to register the service */
- avahi_entry_group_commit(group);
- }
-}
-
-static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) {
-
- /* Called whenever the client or server state changes */
-
- 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 */
- create_services(c);
- break;
- }
-
- case AVAHI_CLIENT_FAILURE: {
- fprintf(stderr, "Client failure: %s\n", avahi_strerror(avahi_client_errno(c)));
- avahi_simple_poll_quit(simple_poll);
-
- break;
- }
+ switch (state)
+ {
+ case AVAHI_CLIENT_S_RUNNING: {
+ static AvahiEntryGroup *group = NULL;
+
+ if (!group) {
+ avahi_entry_group_new(c, entry_group_callback, &group);
+ }
- case AVAHI_CLIENT_S_COLLISION: {}
- case AVAHI_CLIENT_S_REGISTERING: {
- /* The server records are now being established. This
- * might be caused by a host name change. We need to wait
- * for our own records to register until the host name is
- * properly esatblished. */
+ if (avahi_entry_group_is_empty(group)) {
+ printf("Adding service '%s'\n", name);
- if (group)
- avahi_entry_group_reset(group);
- }
- break;
+ avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_http._tcp", NULL, NULL, 8080, NULL);
- case AVAHI_CLIENT_CONNECTING: {}
+ avahi_entry_group_commit(group);
+ }
+
+ break;
}
+
+ case AVAHI_CLIENT_FAILURE: { break; }
+ case AVAHI_CLIENT_S_COLLISION: { break; }
+ case AVAHI_CLIENT_S_REGISTERING: { break; }
+ case AVAHI_CLIENT_CONNECTING: { break; }
+ }
}
+static AvahiSimplePoll *simple_poll = NULL;
int init(int argc, char *argv[])
{
+ puts("Avahi zero-conf handler init.");
+
simple_poll = avahi_simple_poll_new();
-
- avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, NULL);
-
+
+ int error = 0;
+ avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error);
+ printf("Avahi status: %s\n", avahi_strerror(error));
+
avahi_simple_poll_loop(simple_poll);
return 255;

0 comments on commit e893617

Please sign in to comment.