History::Contact::Contact (boost::shared_ptr<Ekiga::ContactCore> _contact_core, boost::shared_ptr<xmlDoc> _doc, const std::string _name, const std::string _uri, time_t _call_start, const std::string _call_duration, call_type c_t): contact_core(_contact_core), doc(_doc), name(_name), uri(_uri), call_start(_call_start), call_duration(_call_duration), m_type(c_t) { gchar* tmp = NULL; std::string callp; node = xmlNewNode (NULL, BAD_CAST "entry"); xmlSetProp (node, BAD_CAST "uri", BAD_CAST uri.c_str ()); xmlNewChild (node, NULL, BAD_CAST "name", BAD_CAST robust_xmlEscape (node->doc, name).c_str ()); tmp = g_strdup_printf ("%lu", call_start); xmlNewChild (node, NULL, BAD_CAST "call_start", BAD_CAST tmp); g_free (tmp); xmlNewChild (node, NULL, BAD_CAST "call_duration", BAD_CAST call_duration.c_str ()); /* FIXME: I don't like the way it's done */ tmp = g_strdup_printf ("%d", m_type); xmlSetProp (node, BAD_CAST "type", BAD_CAST tmp); g_free (tmp); }
void Local::Presentity::rename_group (const std::string old_name, const std::string new_name) { bool old_name_present = false; bool already_in_new_name = false; std::set<xmlNodePtr> nodes_to_remove; /* remove the old name's node * and check if we aren't already in the new name's group */ for (xmlNodePtr child = node->children ; child != NULL ; child = child->next) { if (child->type == XML_ELEMENT_NODE && child->name != NULL) { if (xmlStrEqual (BAD_CAST ("group"), child->name)) { xmlChar* xml_str = xmlNodeGetContent (child); if (xml_str != NULL) { if (!xmlStrcasecmp ((const xmlChar*)old_name.c_str (), xml_str)) { nodes_to_remove.insert (child); // don't free what we loop on! old_name_present = true; } if (!xmlStrcasecmp ((const xmlChar*)new_name.c_str (), xml_str)) { already_in_new_name = true; } xmlFree (xml_str); } } } } // ok, now we can clean up! for (std::set<xmlNodePtr>::iterator iter = nodes_to_remove.begin (); iter != nodes_to_remove.end (); ++iter) { xmlUnlinkNode (*iter); xmlFreeNode (*iter); } if (old_name_present && !already_in_new_name) { xmlNewChild (node, NULL, BAD_CAST "group", BAD_CAST robust_xmlEscape (node->doc, new_name).c_str ()); } updated (); trigger_saving (); }
History::Contact::Contact (Ekiga::ServiceCore &_core, const std::string _name, const std::string _uri, time_t _call_start, const std::string _call_duration, call_type c_t): core(_core), name(_name), uri(_uri), call_start(_call_start), call_duration(_call_duration), m_type(c_t) { gchar *tmp = NULL; std::string callp; contact_core = dynamic_cast<Ekiga::ContactCore*>(core.get ("contact-core")); node = xmlNewNode (NULL, BAD_CAST "entry"); xmlSetProp (node, BAD_CAST "uri", BAD_CAST uri.c_str ()); xmlNewChild (node, NULL, BAD_CAST "name", BAD_CAST robust_xmlEscape (node->doc, name).c_str ()); tmp = g_strdup_printf ("%lu", call_start); xmlNewChild (node, NULL, BAD_CAST "call_start", BAD_CAST tmp); g_free (tmp); xmlNewChild (node, NULL, BAD_CAST "call_duration", BAD_CAST call_duration.c_str ()); /* FIXME: I don't like the way it's done */ tmp = g_strdup_printf ("%d", m_type); xmlSetProp (node, BAD_CAST "type", BAD_CAST tmp); g_free (tmp); }
void robust_xmlNodeSetContent (xmlNodePtr parent, xmlNodePtr* child, const std::string& name, const std::string& value) { if (*child == NULL) { *child = xmlNewChild (parent, NULL, BAD_CAST name.c_str (), BAD_CAST robust_xmlEscape (parent->doc, value).c_str ()); } else { xmlNodeSetContent (*child, BAD_CAST robust_xmlEscape (parent->doc, value).c_str ()); } }
void RL::Presentity::edit_presentity_form_submitted (bool submitted, Ekiga::Form &result) { if (!submitted) return; const std::string new_name = result.text ("name"); const std::string new_uri = result.text ("uri"); const std::set<std::string> new_groups = result.editable_set ("groups"); std::map<std::string, xmlNodePtr> future_group_nodes; xmlNsPtr ns = xmlSearchNsByHref (node->doc, node, BAD_CAST "http://www.ekiga.org"); bool reload = false; robust_xmlNodeSetContent (node, &name_node, "name", new_name); if (uri != new_uri) { xmlSetProp (node, (const xmlChar*)"uri", (const xmlChar*)uri.c_str ()); boost::shared_ptr<Ekiga::PresenceCore> presence_core(services.get<Ekiga::PresenceCore> ("presence-core")); presence_core->unfetch_presence (uri); reload = true; } for (std::map<std::string, xmlNodePtr>::const_iterator iter = group_nodes.begin (); iter != group_nodes.end () ; iter++) { if (new_groups.find (iter->first) == new_groups.end ()) { xmlUnlinkNode (iter->second); xmlFreeNode (iter->second); } else { future_group_nodes[iter->first] = iter->second; } } for (std::set<std::string>::const_iterator iter = new_groups.begin (); iter != new_groups.end (); iter++) { if (std::find (groups.begin (), groups.end (), *iter) == groups.end ()) future_group_nodes[*iter] = xmlNewChild (node, ns, BAD_CAST "group", BAD_CAST robust_xmlEscape (node->doc, *iter).c_str ()); } group_nodes = future_group_nodes; groups = new_groups; save (reload); }
xmlNodePtr Opal::Presentity::build_node (const std::string name, const std::string uri, const std::list<std::string> groups) { xmlNodePtr node = xmlNewNode (NULL, BAD_CAST "entry"); xmlSetProp (node, BAD_CAST "uri", BAD_CAST uri.c_str ()); xmlNewChild (node, NULL, BAD_CAST "name", BAD_CAST robust_xmlEscape (node->doc, name).c_str ()); for (std::list<std::string>::const_iterator iter = groups.begin (); iter != groups.end (); ++iter) xmlNewChild (node, NULL, BAD_CAST "group", BAD_CAST robust_xmlEscape (node->doc, *iter).c_str ()); return node; }
Local::Presentity::Presentity (boost::weak_ptr<Local::Cluster> _local_cluster, boost::weak_ptr<Ekiga::PresenceCore> _presence_core, boost::shared_ptr<xmlDoc> _doc, const std::string name, const std::string uri, const std::set<std::string> groups) : local_cluster(_local_cluster), presence_core(_presence_core), doc(_doc), presence("unknown") { node = xmlNewNode (NULL, BAD_CAST "entry"); xmlSetProp (node, BAD_CAST "uri", BAD_CAST uri.c_str ()); xmlSetProp (node, BAD_CAST "preferred", BAD_CAST "false"); xmlNewChild (node, NULL, BAD_CAST "name", BAD_CAST robust_xmlEscape (node->doc, name).c_str ()); for (std::set<std::string>::const_iterator iter = groups.begin (); iter != groups.end (); iter++) xmlNewChild (node, NULL, BAD_CAST "group", BAD_CAST robust_xmlEscape (node->doc, *iter).c_str ()); }
OPENLDAP::Book::Book (Ekiga::ServiceCore &_core, boost::shared_ptr<xmlDoc> _doc, OPENLDAP::BookInfo _bookinfo): saslform(NULL), core(_core), doc(_doc), name_node(NULL), uri_node(NULL), authcID_node(NULL), password_node(NULL), ldap_context(NULL), patience(0) { node = xmlNewNode (NULL, BAD_CAST "server"); bookinfo = _bookinfo; name_node = xmlNewChild (node, NULL, BAD_CAST "name", BAD_CAST robust_xmlEscape (node->doc, bookinfo.name).c_str ()); uri_node = xmlNewChild (node, NULL, BAD_CAST "uri", BAD_CAST robust_xmlEscape (node->doc, bookinfo.uri).c_str ()); authcID_node = xmlNewChild (node, NULL, BAD_CAST "authcID", BAD_CAST robust_xmlEscape (node->doc, bookinfo.authcID).c_str ()); password_node = xmlNewChild (node, NULL, BAD_CAST "password", BAD_CAST robust_xmlEscape (node->doc, bookinfo.password).c_str ()); OPENLDAP::BookInfoParse (bookinfo); if (bookinfo.uri_host == EKIGA_NET_URI) I_am_an_ekiga_net_book = true; else I_am_an_ekiga_net_book = false; }
RL::Heap::Heap (Ekiga::ServiceCore& services_, std::tr1::shared_ptr<xmlDoc> doc_, const std::string name_, const std::string root_, const std::string user_, const std::string username_, const std::string password_, bool writable_): services(services_), node(NULL), name(NULL), root(NULL), user(NULL), username(NULL), password(NULL), doc(doc_), list_node(NULL) { node = xmlNewNode (NULL, BAD_CAST "entry"); if (writable_) xmlSetProp (node, BAD_CAST "writable", BAD_CAST "1"); else xmlSetProp (node, BAD_CAST "writable", BAD_CAST "0"); if ( !name_.empty ()) name = xmlNewChild (node, NULL, BAD_CAST "name", BAD_CAST robust_xmlEscape (node->doc, name_).c_str ()); else name = xmlNewChild (node, NULL, BAD_CAST "name", BAD_CAST robust_xmlEscape (node->doc, _("Unnamed")).c_str ()); root = xmlNewChild (node, NULL, BAD_CAST "root", BAD_CAST robust_xmlEscape (node->doc, root_).c_str ()); user = xmlNewChild (node, NULL, BAD_CAST "user", BAD_CAST robust_xmlEscape (node->doc, user_).c_str ()); username = xmlNewChild (node, NULL, BAD_CAST "username", BAD_CAST robust_xmlEscape (node->doc, username_).c_str ()); password = xmlNewChild (node, NULL, BAD_CAST "password", BAD_CAST robust_xmlEscape (node->doc, password_).c_str ()); refresh (); }
void RL::Heap::on_new_entry_form_submitted (bool submitted, Ekiga::Form& result) { if (!submitted) return; std::string entry_name = result.text ("name"); std::string entry_uri = result.text ("uri"); std::set<std::string> entry_groups = result.editable_set ("groups"); xmlNodePtr entry_node = xmlNewChild (list_node, NULL, BAD_CAST "entry", NULL); xmlSetProp (entry_node, BAD_CAST "uri", BAD_CAST robust_xmlEscape (doc.get (), entry_uri).c_str ()); xmlNewChild (entry_node, NULL, BAD_CAST "display-name", BAD_CAST robust_xmlEscape (doc.get (), entry_name).c_str ()); xmlNsPtr ns = xmlSearchNsByHref (doc.get (), entry_node, BAD_CAST "http://www.ekiga.org"); if (ns == NULL) { // FIXME: we should handle the case, even if it shouldn't happen } for (std::set<std::string>::const_iterator iter = entry_groups.begin (); iter != entry_groups.end (); ++iter) { xmlNewChild (entry_node, ns, BAD_CAST "group", BAD_CAST robust_xmlEscape (doc.get (), *iter).c_str ()); } xmlBufferPtr buffer = xmlBufferCreate (); int res = xmlNodeDump (buffer, doc.get (), entry_node, 0, 0); if (res >= 0) { std::string root_str; std::string username_str; std::string password_str; std::string user_str; { 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; } 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"); path = path->build_child_with_attribute ("entry", "uri", entry_uri); gmref_ptr<XCAP::Core> xcap(services.get ("xcap-core")); xcap->write (path, "application/xcap-el+xml", (const char*)xmlBufferContent (buffer), sigc::mem_fun (this, &RL::Heap::new_entry_result)); } xmlBufferFree (buffer); }
RL::Heap::Heap (Ekiga::ServiceCore& services_, std::tr1::shared_ptr<xmlDoc> doc_, xmlNodePtr node_): services(services_), node(node_), name(NULL), root(NULL), user(NULL), username(NULL), password(NULL), doc(doc_), list_node(NULL) { { xmlChar* xml_str = NULL; xml_str = xmlGetProp (node, BAD_CAST "writable"); if (xml_str != NULL) xmlFree (xml_str); else { xmlSetProp (node, BAD_CAST "writable", BAD_CAST "0"); } } for (xmlNodePtr child = node->children; child != NULL; child = child->next) { if (child->type == XML_ELEMENT_NODE && child->name != NULL) { if (xmlStrEqual (BAD_CAST ("name"), child->name)) { name = child; continue; } if (xmlStrEqual (BAD_CAST ("root"), child->name)) { root = child; continue; } if (xmlStrEqual (BAD_CAST ("user"), child->name)) { user = child; continue; } if (xmlStrEqual (BAD_CAST ("username"), child->name)) { username = child; continue; } if (xmlStrEqual (BAD_CAST ("password"), child->name)) { password = child; continue; } } } if (name == NULL) name = xmlNewChild (node, NULL, BAD_CAST "name", BAD_CAST robust_xmlEscape(doc.get (), _("Unnamed")).c_str ()); if (root == NULL) root = xmlNewChild (node, NULL, BAD_CAST "root", BAD_CAST ""); if (user == NULL) user = xmlNewChild (node, NULL, BAD_CAST "user", BAD_CAST ""); if (username == NULL) username = xmlNewChild (node, NULL, BAD_CAST "username", BAD_CAST ""); if (password == NULL) password = xmlNewChild (node, NULL, BAD_CAST "password", BAD_CAST ""); refresh (); }
void Local::Presentity::edit_presentity_form_submitted (bool submitted, Ekiga::Form &result) { if (!submitted) return; const std::string new_name = result.text ("name"); const std::set<std::string> groups = get_groups (); const std::set<std::string> new_groups = result.editable_set ("groups"); std::string new_uri = result.text ("uri"); const std::string uri = get_uri (); bool preferred = result.boolean ("preferred"); std::set<xmlNodePtr> nodes_to_remove; new_uri = canonize_uri (new_uri); for (xmlNodePtr child = node->children ; child != NULL ; child = child->next) { if (child->type == XML_ELEMENT_NODE && child->name != NULL) { if (xmlStrEqual (BAD_CAST ("name"), child->name)) { robust_xmlNodeSetContent (node, &child, "name", new_name); } } } if (uri != new_uri) { boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock (); if (pcore) { pcore->unfetch_presence (uri); pcore->fetch_presence (new_uri); } presence = "unknown"; xmlSetProp (node, (const xmlChar*)"uri", (const xmlChar*)new_uri.c_str ()); } // the first loop looks at groups we were in : are we still in ? for (xmlNodePtr child = node->children ; child != NULL ; child = child->next) { if (child->type == XML_ELEMENT_NODE && child->name != NULL) { if (xmlStrEqual (BAD_CAST ("group"), child->name)) { xmlChar* xml_str = xmlNodeGetContent (child); if (xml_str != NULL) { if (new_groups.find ((const char*) xml_str) == new_groups.end ()) { nodes_to_remove.insert (child); // don't free what we loop on! } xmlFree (xml_str); } } } } // ok, now we can clean up! for (std::set<xmlNodePtr>::iterator iter = nodes_to_remove.begin (); iter != nodes_to_remove.end (); ++iter) { xmlUnlinkNode (*iter); xmlFreeNode (*iter); } // the second loop looking for groups we weren't in but are now for (std::set<std::string>::const_iterator iter = new_groups.begin (); iter != new_groups.end (); iter++) { if (std::find (groups.begin (), groups.end (), *iter) == groups.end ()) { xmlNewChild (node, NULL, BAD_CAST "group", BAD_CAST robust_xmlEscape (node->doc, *iter).c_str ()); } } if (preferred) { xmlSetProp (node, BAD_CAST "preferred", BAD_CAST "true"); } else { xmlSetProp (node, BAD_CAST "preferred", BAD_CAST "false"); } updated (); trigger_saving (); }
bool Opal::Presentity::edit_presentity_form_submitted (bool submitted, Ekiga::Form &result, std::string &error) { if (!submitted) return false; const std::string new_name = result.text ("name"); const std::list<std::string> groups = get_groups (); const std::list<std::string> new_groups = result.editable_list ("groups"); std::string new_uri = result.text ("uri"); const std::string uri = get_uri (); std::set<xmlNodePtr> nodes_to_remove; if (new_name.empty ()) { error = _("You did not provide a valid name"); return false; } else if (new_uri.empty ()) { error = _("You did not provide a valid address"); return false; } new_uri = canonize_uri (new_uri); for (xmlNodePtr child = node->children ; child != NULL ; child = child->next) { if (child->type == XML_ELEMENT_NODE && child->name != NULL) if (xmlStrEqual (BAD_CAST ("name"), child->name)) robust_xmlNodeSetContent (node, &child, "name", new_name); } if (uri != new_uri) { xmlSetProp (node, (const xmlChar*)"uri", (const xmlChar*)new_uri.c_str ()); account.unfetch (uri); account.fetch (new_uri); Ekiga::Runtime::run_in_main (boost::bind (&Opal::Account::presence_status_in_main, &account, new_uri, "unknown", "")); } // the first loop looks at groups we were in: are we still in? for (xmlNodePtr child = node->children ; child != NULL ; child = child->next) { if (child->type == XML_ELEMENT_NODE && child->name != NULL) { if (xmlStrEqual (BAD_CAST ("group"), child->name)) { xmlChar* xml_str = xmlNodeGetContent (child); if (xml_str != NULL) { if (std::find (new_groups.begin (), new_groups.end (), (const char*) xml_str) == new_groups.end ()) nodes_to_remove.insert (child); // don't free what we loop on! xmlFree (xml_str); } } } } // ok, now we can clean up! for (std::set<xmlNodePtr>::iterator iter = nodes_to_remove.begin (); iter != nodes_to_remove.end (); ++iter) { xmlUnlinkNode (*iter); xmlFreeNode (*iter); } // the second loop looks for groups we weren't in but are now for (std::list<std::string>::const_iterator iter = new_groups.begin (); iter != new_groups.end (); iter++) { if (std::find (groups.begin (), groups.end (), *iter) == groups.end ()) xmlNewChild (node, NULL, BAD_CAST "group", BAD_CAST robust_xmlEscape (node->doc, *iter).c_str ()); } updated (this->shared_from_this ()); trigger_saving (); return true; }