void LM::HeapRoster::parse_roster (LmMessageNode* query) { for (LmMessageNode* node = query->children; node != NULL; node = node->next) { if (g_strcmp0 (node->name, "item") != 0) { continue; } const gchar* jid = lm_message_node_get_attribute (node, "jid"); bool found = false; for (iterator iter = begin (); !found && iter != end (); ++iter) { if ((*iter)->get_jid () == jid) { found = true; const gchar* subscription = lm_message_node_get_attribute (node, "subscription"); if (subscription != NULL && g_strcmp0 (subscription, "remove") == 0) { (*iter)->removed (); } else { (*iter)->update (node); } } } if ( !found) { PresentityPtr presentity(new Presentity (connection, node)); presentity->chat_requested.connect (boost::bind (&LM::HeapRoster::on_chat_requested, this, presentity)); add_presentity (presentity); const gchar* subscription = lm_message_node_get_attribute (node, "subscription"); if (subscription != NULL && g_strcmp0 (subscription, "none") == 0) { const gchar* ask = lm_message_node_get_attribute (node, "ask"); if (ask == NULL || (ask != NULL && g_strcmp0 (ask, "subscribe") != 0)) { std::set<std::string>::iterator iter = items_added_by_me.find (presentity->get_jid ()); if (iter != items_added_by_me.end ()) { /* if we're here then this is a new contact, we are not subscribed to it, * and we did not ask to be subscribed to it and we added it recently: * let's ask for subscription! * * Beware that the first three actions could have been done from another client, * so that last condition is important so we don't start doing things * in the back of the user! */ items_added_by_me.erase (iter); LmMessage* subscribe = lm_message_new (NULL, LM_MESSAGE_TYPE_PRESENCE); lm_message_node_set_attributes (lm_message_get_node (subscribe), "to", presentity->get_jid ().c_str (), "type", "subscribe", NULL); lm_connection_send (connection, subscribe, NULL); lm_message_unref (subscribe); } } } } } }
void RL::Heap::parse_list (xmlNodePtr list) { std::string root_str; std::string user_str; std::string username_str; std::string password_str; bool writable = false; list_node = list; { xmlChar* str = xmlNodeGetContent (root); if (str != NULL) root_str = (const char*)str; } { xmlChar* str = xmlNodeGetContent (user); if (str != NULL) user_str = (const char*)str; } { xmlChar* str = xmlNodeGetContent (username); if (str != NULL) username_str = (const char*)str; } { xmlChar* str = xmlNodeGetContent (password); if (str != NULL) password_str = (const char*)str; } { xmlChar* str = xmlGetProp (node, BAD_CAST "writable"); if (str != NULL) { if (xmlStrEqual (str, BAD_CAST "1")) writable = true; xmlFree (str); } } gmref_ptr<XCAP::Path> path(new XCAP::Path (root_str, "resource-lists", user_str)); path->set_credentials (username_str, password_str); path = path->build_child ("resource-lists"); path = path->build_child ("list"); for (xmlNodePtr child = list->children; child != NULL; child = child->next) if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST ("entry"), child->name)) { PresentityPtr presentity(new Presentity (services, path, doc, child, writable)); std::list<sigc::connection> conns; conns.push_back (presentity->updated.connect (sigc::bind (presentity_updated.make_slot (),presentity))); conns.push_back (presentity->removed.connect (sigc::bind(presentity_removed.make_slot (),presentity))); conns.push_back (presentity->trigger_reload.connect (sigc::mem_fun (this, &RL::Heap::refresh))); conns.push_back (presentity->questions.connect (questions.make_slot())); presentities[presentity]=conns; presentity_added.emit (presentity); continue; } }
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 status; 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); #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") status = 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); status_received (helper.found_presentity ()->get_uri (), status); } else { /* ok, this is a new contact */ gchar** broken = NULL; broken = g_strsplit_set (typ, "._", 0); boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock (); if (broken != NULL && broken[0] != NULL && broken[1] != NULL && pcore) { std::set<std::string> groups; groups.insert (_("Neighbours")); url = g_strdup_printf ("%s:neighbour@%s:%d", broken[1], host_name, port); boost::shared_ptr<Ekiga::URIPresentity> presentity (new Ekiga::URIPresentity (pcore, name, url, groups)); status_received (url, status); presence_received (url, presence); add_presentity (presentity); g_free (url); } g_strfreev (broken); } avahi_service_resolver_free (resolver); break;} case AVAHI_RESOLVER_FAILURE: #if DEBUG std::cout << __PRETTY_FUNCTION__ << " AVAHI_RESOLVER_FAILURE" << std::endl; #endif avahi_service_resolver_free (resolver); break; default: /* shouldn't happen */ #if DEBUG std::cout << __PRETTY_FUNCTION__ << " SHOULDN'T HAPPEN" << std::endl; #endif break; } }