示例#1
0
void
Ekiga::PresenceCore::on_presence_received (const std::string uri,
					   const std::string presence)
{
  uri_infos[uri].presence = presence;
  presence_received (uri, presence);
}
示例#2
0
void
Ekiga::PresenceCore::fetch_presence (const std::string uri)
{
  uri_infos[uri].count++;

  if (uri_infos[uri].count == 1) {

    for (std::list<boost::shared_ptr<PresenceFetcher> >::iterator iter
	   = presence_fetchers.begin ();
	 iter != presence_fetchers.end ();
	 ++iter)
      (*iter)->fetch (uri);
  }

  presence_received (uri, uri_infos[uri].presence);
  status_received (uri, uri_infos[uri].status);
}
示例#3
0
void
Avahi::Heap::ResolverCallback (AvahiServiceResolver * /*resolver*/,
			       AvahiIfIndex /*interface*/,
			       AvahiProtocol /*protocol*/,
			       AvahiResolverEvent event,
			       const char * name_,
			       const char * typ,
			       const char * /*domain*/,
			       const char* host_name,
			       const AvahiAddress */*address*/,
			       uint16_t port,
			       AvahiStringList *txt,
			       AvahiLookupResultFlags flags)
{
  std::string name;
  std::string software;
  std::string presence;
  std::string note;
  gchar *url = NULL;
  AvahiStringList *txt_tmp = NULL;

  // filter out seeing ourselves
  // FIXME: doesn't it hide other people on the same box too?
  if (flags & AVAHI_LOOKUP_RESULT_LOCAL) {

    avahi_service_resolver_free (resolver);
    resolver = NULL;
#if DEBUG
    std::cout << __PRETTY_FUNCTION__ << " LOCAL RESULT" << std::endl;
#endif
    return;
  }

  switch (event) {

  case AVAHI_RESOLVER_FOUND:
  {
#if DEBUG
    std::cout << __PRETTY_FUNCTION__ << " AVAHI_RESOLVER_FOUND" << std::endl;
#endif

    name = name_;
    for (txt_tmp = txt;  txt_tmp != NULL; txt_tmp = txt_tmp->next) {

      char *ckey = NULL;
      char *cvalue = NULL;
      size_t valsize;
      if (avahi_string_list_get_pair (txt_tmp, &ckey, &cvalue, &valsize) >= 0) {

	if (ckey != NULL && cvalue != NULL) {

	  std::string key (ckey);
	  std::string value (cvalue);
	  if (key == "presence")
	    presence = value;
	  else if (key == "status")  // interoperability with older versions
	    note = value;
	  else if (key == "note")
	    note = value;
	  else if (key == "software")
	    software = value;
	}
	if (ckey != NULL) free (ckey);
	if (cvalue != NULL) free (cvalue);
      }
    }

    resolver_callback_helper helper(name);
    visit_presentities (boost::ref (helper));
    if (helper.found_presentity ()) {

      /* known contact has been updated */
      presence_received (helper.found_presentity ()->get_uri (), presence);
      note_received (helper.found_presentity ()->get_uri (), note);
    }
    else {

      /* ok, this is a new contact */
      gchar** broken = NULL;
      broken = g_strsplit_set (typ, "._", 0);
      boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
      if (broken != NULL && broken[0] != NULL && broken[1] != NULL) {

	std::list<std::string> groups;

	groups.push_back (_("Neighbours"));
	url = g_strdup_printf ("%s:neighbour@%s:%d", broken[1], host_name, port);
	boost::shared_ptr<Avahi::Presentity> presentity = Avahi::Presentity::create (presence_core, name, url, groups);
	note_received (url, note);
	presence_received (url, presence);
	add_presentity (presentity);
	g_free (url);
      }
      g_strfreev (broken);
    }
  }
    break;
  case AVAHI_RESOLVER_FAILURE:

#if DEBUG
    std::cout << __PRETTY_FUNCTION__ << " AVAHI_RESOLVER_FAILURE" << std::endl;
#endif
    avahi_service_resolver_free (resolver);
    resolver = NULL;
    break;
  default:
    /* shouldn't happen */
#if DEBUG
    std::cout << __PRETTY_FUNCTION__ << " SHOULDN'T HAPPEN" << std::endl;
#endif
    break;
  }
}