Пример #1
0
static void
dnssdDeregisterInstance(
    cupsd_srv_t     *srv,		/* I - Service */
    int             from_callback)	/* I - Called from callback? */
{
  if (!srv || !*srv)
    return;

#  ifdef HAVE_DNSSD
  (void)from_callback;

  DNSServiceRefDeallocate(*srv);

#  else /* HAVE_AVAHI */
  if (!from_callback)
    avahi_threaded_poll_lock(DNSSDMaster);

  avahi_entry_group_free(*srv);

  if (!from_callback)
    avahi_threaded_poll_unlock(DNSSDMaster);
#  endif /* HAVE_DNSSD */

  *srv = NULL;
}
Пример #2
0
void AvahiBrowseQuery::stopBrowsing() {
    std::cout << "Stop browsing" << std::endl;
    avahi_threaded_poll_lock(querier->getThreadedPoll());
    avahi_service_browser_free(browser);
    browser = NULL;
    avahi_threaded_poll_unlock(querier->getThreadedPoll());
}
Пример #3
0
void avahi_cleanup(void) {
if (db) fprintf(stderr, "in  avahi_cleanup\n");
	if (!_client) {
if (db) fprintf(stderr, "    avahi_cleanup client null\n");
		return;
	}
if (db) fprintf(stderr, "    avahi_cleanup poll_lock\n");
	avahi_threaded_poll_lock(_poll);
if (db) fprintf(stderr, "    avahi_cleanup poll_stop\n");

	signal(SIGALRM, avahi_timeout);
	alarm(3);
	avahi_threaded_poll_stop(_poll);
	alarm(0);
	signal(SIGALRM, SIG_DFL);

if (db) fprintf(stderr, "    avahi_cleanup client_free\n");
	avahi_client_free(_client);
	_client = NULL;

if (db) fprintf(stderr, "    avahi_cleanup poll_free\n");
	avahi_threaded_poll_free(_poll);
	_poll = NULL;
if (db) fprintf(stderr, "out avahi_cleanup\n");
}
/**
 * Adds a new service to the Avahi Daemon
 *
 * @param _service The service to add
 *
 * @return void
 */
int avahi_core_create_service(Service *_service)
{
    int rc;

    avahi_threaded_poll_lock(threaded_poll);
    rc = static_create_services (_service);
    avahi_threaded_poll_unlock(threaded_poll);

    return rc;
}
/**
 * Adds a new service to the Avahi Daemon
 *
 * @param service_to_create The service to add
 *
 * @return void
 */ 
int 
avahi_client_create_service ( Service *service_to_create )
{
	int rc;

	avahi_threaded_poll_lock( threaded_poll );
	rc = static_create_services ( service_to_create );
	avahi_threaded_poll_unlock( threaded_poll );

	return rc;
}
Пример #6
0
void AvahiBrowseQuery::startBrowsing() {
    std::cout << "Start browsing" << std::endl;
    assert(!browser);
    avahi_threaded_poll_lock(querier->getThreadedPoll());
    browser = avahi_service_browser_new(querier->getClient(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_presence._tcp", NULL, static_cast<AvahiLookupFlags>(0), &handleServiceDiscoveredStatic, this);
    if (!browser) {
        std::cout << "Error" << std::endl;
        eventLoop->postEvent(boost::bind(boost::ref(onError)), shared_from_this());
    }
    avahi_threaded_poll_unlock(querier->getThreadedPoll());
}
Пример #7
0
void avahi_advertise(char *name, char *host, uint16_t port) {
	int i;
	char *t;
	t = getenv("X11VNC_AVAHI_NAME"); if (t) name = t;
	t = getenv("X11VNC_AVAHI_HOST"); if (t) host = t;
	t = getenv("X11VNC_AVAHI_PORT"); if (t) port = atoi(t);

if (db) fprintf(stderr, "in  avahi_advertise: '%s' '%s' %d\n", name, host, port);
	if (!_client) {
if (db) fprintf(stderr, "    avahi_advertise client null\n");
		return;
	}
	if (_poll == NULL) {
		rfbLog("Avahi poll not initialized.\n");
		return;
	}
	/* well, we just track it ourselves... */
	for (i=0; i<NREG; i++) {
		if (!registered[i].name) {
			continue;
		}
		if (strcmp(registered[i].name, name)) {
			continue;
		}
		if (strcmp(registered[i].host, host)) {
			continue;
		}
		if (registered[i].port != port) {
			continue;
		}
if (db) fprintf(stderr, "    avahi_advertise already did this one\n");
		return;
	}
	for (i=0; i<NREG; i++) {
		if (!registered[i].name) {
			registered[i].name = strdup(name);
			registered[i].host = strdup(host);
			registered[i].port = port;
			break;
		}
	}

	avahi_threaded_poll_lock(_poll);
	_avahi_create_services(name, host, port >= 5900 ? port : 5900+port);
	avahi_threaded_poll_unlock(_poll);
if (db) fprintf(stderr, "out avahi_advertise\n");
}
Пример #8
0
void AvahiSession::PublishPort(SCRendezvousProtocol proto, short port)
{
	if (!mClient) return;

	AvahiEntry* entry = new AvahiEntry;
	entry->mProto = proto;
	entry->mPort = port;
	entry->mRegistered = false;

	mMutex.lock();
	entry->mNext = mEntries;
	mEntries = entry;
	mMutex.unlock();

	avahi_threaded_poll_lock(mPoll);
	struct timeval tv;
	avahi_threaded_poll_get(mPoll)->timeout_new(
		avahi_threaded_poll_get(mPoll),
		avahi_elapse_time(&tv, 0, 0),
		modify_cb,
		this);
	avahi_threaded_poll_unlock(mPoll);
}
Пример #9
0
 ScopedEventLoopBlock(AvahiThreadedPoll* fp_poll):mp_poll(fp_poll)
 {
   avahi_threaded_poll_lock(mp_poll);
 }
Пример #10
0
static int				/* O - 1 on success, 0 on failure */
dnssdRegisterInstance(
    cupsd_srv_t     *srv,		/* O - Service */
    cupsd_printer_t *p,			/* I - Printer */
    char            *name,		/* I - DNS-SD service name */
    const char      *type,		/* I - DNS-SD service type */
    const char      *subtypes,		/* I - Subtypes to register or NULL */
    int             port,		/* I - Port number or 0 */
    cupsd_txt_t     *txt,		/* I - TXT record */
    int             commit,		/* I - Commit registration? */
    int             from_callback)	/* I - Called from callback? */
{
  char	temp[256],			/* Temporary string */
	*ptr;				/* Pointer into string */
  int	error;				/* Any error */


#  ifdef HAVE_DNSSD
  (void)from_callback;
#  endif /* HAVE_DNSSD */

  cupsdLogMessage(CUPSD_LOG_DEBUG, "Registering \"%s\" with DNS-SD type \"%s\".", name, type);

  if (p && !srv)
  {
   /*
    * Assign the correct pointer for "srv"...
    */

#  ifdef HAVE_DNSSD
    if (!strcmp(type, "_printer._tcp"))
      srv = &p->printer_srv;		/* Target LPD service */
#    ifdef HAVE_SSL
    else if (!strcmp(type, "_ipps._tcp"))
      srv = &p->ipps_srv;		/* Target IPPS service */
#    endif /* HAVE_SSL */
    else
      srv = &p->ipp_srv;		/* Target IPP service */

#  else /* HAVE_AVAHI */
    srv = &p->ipp_srv;			/* Target service group */
#  endif /* HAVE_DNSSD */
  }

#  ifdef HAVE_DNSSD
  (void)commit;

#  else /* HAVE_AVAHI */
  if (!from_callback)
    avahi_threaded_poll_lock(DNSSDMaster);

  if (!*srv)
    *srv = avahi_entry_group_new(DNSSDClient, dnssdRegisterCallback, NULL);
  if (!*srv)
  {
    if (!from_callback)
      avahi_threaded_poll_unlock(DNSSDMaster);

    cupsdLogMessage(CUPSD_LOG_WARN, "DNS-SD registration of \"%s\" failed: %s",
                    name, dnssdErrorString(avahi_client_errno(DNSSDClient)));
    return (0);
  }
#  endif /* HAVE_DNSSD */

 /*
  * Make sure the name is <= 63 octets, and when we truncate be sure to
  * properly truncate any UTF-8 characters...
  */

  ptr = name + strlen(name);
  while ((ptr - name) > 63)
  {
    do
    {
      ptr --;
    }
    while (ptr > name && (*ptr & 0xc0) == 0x80);

    if (ptr > name)
      *ptr = '\0';
  }

 /*
  * Register the service...
  */

#  ifdef HAVE_DNSSD
  if (subtypes)
    snprintf(temp, sizeof(temp), "%s,%s", type, subtypes);
  else
    strlcpy(temp, type, sizeof(temp));

  *srv  = DNSSDMaster;
  error = DNSServiceRegister(srv, kDNSServiceFlagsShareConnection,
			     0, name, temp, NULL, NULL, htons(port),
			     txt ? TXTRecordGetLength(txt) : 0,
			     txt ? TXTRecordGetBytesPtr(txt) : NULL,
			     dnssdRegisterCallback, p);

#  else /* HAVE_AVAHI */
  if (txt)
  {
    AvahiStringList *temptxt;
    for (temptxt = *txt; temptxt; temptxt = temptxt->next)
      cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS_SD \"%s\" %s", name, temptxt->text);
  }

  error = avahi_entry_group_add_service_strlst(*srv, AVAHI_IF_UNSPEC,
                                               AVAHI_PROTO_UNSPEC, 0, name,
                                               type, NULL, NULL, port,
                                               txt ? *txt : NULL);
  if (error)
    cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD service add for \"%s\" failed.",
                    name);

  if (!error && subtypes)
  {
   /*
    * Register all of the subtypes...
    */

    char	*start,			/* Start of subtype */
		subtype[256];		/* Subtype string */

    strlcpy(temp, subtypes, sizeof(temp));

    for (start = temp; *start; start = ptr)
    {
     /*
      * Skip leading whitespace...
      */

      while (*start && isspace(*start & 255))
        start ++;

     /*
      * Grab everything up to the next comma or the end of the string...
      */

      for (ptr = start; *ptr && *ptr != ','; ptr ++);

      if (*ptr)
        *ptr++ = '\0';

      if (!*start)
        break;

     /*
      * Register the subtype...
      */

      snprintf(subtype, sizeof(subtype), "%s._sub.%s", start, type);

      error = avahi_entry_group_add_service_subtype(*srv, AVAHI_IF_UNSPEC,
                                                    AVAHI_PROTO_UNSPEC, 0,
                                                    name, type, NULL, subtype);
      if (error)
      {
        cupsdLogMessage(CUPSD_LOG_DEBUG,
                        "DNS-SD subtype %s registration for \"%s\" failed." ,
                        subtype, name);
        break;
      }
    }
  }

  if (!error && commit)
  {
    if ((error = avahi_entry_group_commit(*srv)) != 0)
      cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD commit of \"%s\" failed.",
                      name);
  }

  if (!from_callback)
    avahi_threaded_poll_unlock(DNSSDMaster);
#  endif /* HAVE_DNSSD */

  if (error)
  {
    cupsdLogMessage(CUPSD_LOG_WARN, "DNS-SD registration of \"%s\" failed: %s",
                    name, dnssdErrorString(error));
    cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD type: %s", type);
    if (subtypes)
      cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD sub-types: %s", subtypes);
  }

  return (!error);
}
Пример #11
0
void Client::lock() {
        avahi_threaded_poll_lock(msPoll);
}
Пример #12
0
void wxAvahiThreadPool::Lock(){
    avahi_threaded_poll_lock(m_pool);
}