void Local::Heap::common_add (PresentityPtr presentity) { gmref_ptr<Ekiga::PresenceCore> presence_core = core.get ("presence-core"); // Add the presentity to this Heap add_presentity (presentity); // Fetch presence presence_core->fetch_presence (presentity->get_uri ()); // Connect the Local::Presentity signals. add_connection (presentity, presentity->trigger_saving.connect (sigc::mem_fun (this, &Local::Heap::save))); }
void Local::Heap::common_add (PresentityPtr presentity) { boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock (); // Add the presentity to this Heap add_presentity (presentity); // Fetch presence if (pcore) pcore->fetch_presence (presentity->get_uri ()); // Connect the Local::Presentity signals. add_connection (presentity, presentity->trigger_saving.connect (boost::bind (&Local::Heap::save, this))); }
int fifo_pa_location_contact(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char p_contact_s[MAX_P_URI]; char location_s[MAX_LOCATION]; char priority_s[MAX_LOCATION]; char expires_s[MAX_LOCATION]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; presence_tuple_t *tuple = NULL; str pdomain_name, p_uri, p_contact, location, priority_str, expires_str; time_t expires; double priority; int changed = 0; char *msg = "no error"; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_location_contact: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 pa_location_contact: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(p_contact_s, MAX_P_URI, fifo, &p_contact.len) || p_contact.len == 0) { fifo_reply(response_file, "400 pa_location_contact: p_contact expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: p_contact expected\n"); return 1; } p_contact.s = p_contact_s; if (!read_line(location_s, MAX_LOCATION, fifo, &location.len) || location.len == 0) { fifo_reply(response_file, "400 pa_location_contact: location expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: location expected\n"); return 1; } location.s = location_s; if (!read_line(priority_s, MAX_LOCATION, fifo, &priority_str.len) || priority_str.len == 0) { fifo_reply(response_file, "400 pa_location_contact: priority expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: priority expected\n"); return 1; } priority = strtod(priority_s, NULL); if (!read_line(expires_s, MAX_LOCATION, fifo, &expires_str.len) || expires_str.len == 0) { fifo_reply(response_file, "400 pa_location_contact: expires expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: expires expected\n"); return 1; } expires = strtoul(expires_s, NULL, 0); register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location_contact: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } lock_pdomain(pdomain); find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); changed = 1; } if (!presentity) { msg = "400 could not find presentity\n"; LOG(L_ERR, "ERROR: pa_location_contact: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } find_presence_tuple(&p_contact, presentity, &tuple); if (!tuple && new_tuple_on_publish) { new_presence_tuple(&p_contact, expires, presentity, &tuple); add_presence_tuple(presentity, tuple); tuple->state = PS_ONLINE; changed = 1; } if (!tuple) { LOG(L_ERR, "publish_presentity: no tuple for %.*s\n", presentity->uri.len, presentity->uri.s); msg = "400 could not find presence tuple\n"; goto error; } changed = 1; if (1 || (tuple->location.loc.len && str_strcasecmp(&tuple->location.room, &location) != 0)) { changed = 1; LOG(L_ERR, "Setting room of contact=%.*s to %.*s\n", tuple->contact.len, tuple->contact.s, tuple->location.room.len, tuple->location.room.s); strncpy(tuple->location.room.s, location.s, location.len); tuple->location.room.len = location.len; strncpy(tuple->location.loc.s, location.s, location.len); tuple->location.loc.len = location.len; } if (tuple->priority != priority) { tuple->priority = priority; changed = 1; } if (expires < 7*24*3600) { /* must be seconds */ get_act_time(); expires = act_time + expires; } if (tuple->expires != expires) { tuple->expires = expires; changed = 1; } if (changed) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); unlock_pdomain(pdomain); fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), location.len, ZSW(location.s)); return 1; error: unlock_pdomain(pdomain); fifo_reply(response_file, msg); return 1; }
int fifo_pa_location(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char location_s[MAX_LOCATION]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; presence_tuple_t *tuple = NULL; str pdomain_name, p_uri, location; int changed = 0; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_location: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_location: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 pa_location: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_location: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(location_s, MAX_LOCATION, fifo, &location.len) || location.len == 0) { fifo_reply(response_file, "400 pa_location: location expected\n"); LOG(L_ERR, "ERROR: pa_location: location expected\n"); return 1; } location.s = location_s; register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } lock_pdomain(pdomain); find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); changed = 1; } if (!presentity) { unlock_pdomain(pdomain); fifo_reply(response_file, "400 could not find presentity\n"); LOG(L_ERR, "ERROR: pa_location: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } changed = 1; for (tuple = presentity->tuples; tuple; tuple = tuple->next) { if (tuple->location.loc.len && str_strcasecmp(&tuple->location.room, &location) != 0) changed = 1; LOG(L_ERR, "Setting room of contact=%.*s to %.*s\n", tuple->contact.len, tuple->contact.s, tuple->location.room.len, tuple->location.room.s); strncpy(tuple->location.room.s, location.s, location.len); tuple->location.room.len = location.len; strncpy(tuple->location.loc.s, location.s, location.len); tuple->location.loc.len = location.len; } if (changed) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); unlock_pdomain(pdomain); fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), location.len, ZSW(location.s)); return 1; }
int fifo_pa_presence(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char presence_s[MAX_PRESENCE]; // pdomain_t *pdomain = NULL; // presentity_t *presentity = NULL; str pdomain_name, p_uri, presence; // int origstate, newstate; // int allocated_presentity = 0; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 ul_add: pdomain expected\n"); LOG(L_ERR, "ERROR: ul_add: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 ul_add: p_uri expected\n"); LOG(L_ERR, "ERROR: ul_add: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(presence_s, MAX_PRESENCE, fifo, &presence.len) || presence.len == 0) { fifo_reply(response_file, "400 ul_add: presence expected\n"); LOG(L_ERR, "ERROR: ul_add: presence expected\n"); return 1; } presence.s = presence_s; #if 0 register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); allocated_presentity = 1; } if (!presentity) { fifo_reply(response_file, "400 could not find presentity %s\n", p_uri_s); LOG(L_ERR, "ERROR: pa_location: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } origstate = presentity->state; presentity->state = newstate = (strcasecmp(presence_s, "online") == 0) ? PS_ONLINE : PS_OFFLINE; if (origstate != newstate || allocated_presentity) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); #endif fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), presence.len, ZSW(presence.s)); return 1; }
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; } }
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); } } } } } }
/* Create a new presentity but do not update database. * If pres_id not set it generates new one, but only if db_mode set. */ static inline int new_presentity_no_wb(struct pdomain *pdomain, str* _uri, str *uid, xcap_query_params_t *xcap_params, str *pres_id, presentity_t** _p) { presentity_t* presentity; int size = 0; dbid_t id; int id_len = 0; char *xcap_param_buffer; if ((!_uri) || (!_p) || (!uid)) { paerrno = PA_INTERNAL_ERROR; ERR("Invalid parameter value\n"); return -1; } if (pres_id) size += pres_id->len; else { if (use_db) { /* do not generate IDs if not using DB */ generate_dbid(id); id_len = dbid_strlen(id); size += id_len; } else id_len = 0; } if (xcap_params) size += get_inline_xcap_buf_len(xcap_params); size += sizeof(presentity_t) + _uri->len + uid->len; presentity = (presentity_t*)mem_alloc(size); /* TRACE("allocating presentity: %d\n", size); */ if (!presentity) { paerrno = PA_NO_MEMORY; LOG(L_ERR, "No memory left: size=%d\n", size); *_p = NULL; return -1; } /* fill whole structure with zeros */ memset(presentity, 0, sizeof(presentity_t)); msg_queue_init(&presentity->mq); presentity->data.uri.s = ((char*)presentity) + sizeof(presentity_t); str_cpy(&presentity->data.uri, _uri); presentity->uuid.s = presentity->data.uri.s + presentity->data.uri.len; str_cpy(&presentity->uuid, uid); presentity->pres_id.s = presentity->uuid.s + presentity->uuid.len; if (pres_id) str_cpy(&presentity->pres_id, pres_id); else { if (use_db) dbid_strcpy(&presentity->pres_id, id, id_len); else presentity->pres_id.len = 0; } xcap_param_buffer = after_str_ptr(&presentity->pres_id); presentity->pdomain = pdomain; if (pa_auth_params.type == auth_xcap) { /* store XCAP parameters for async XCAP queries and refreshing * (FIXME: rewrite - use table of a few of existing XCAP parameter * sets instead of always duplicating because it will be mostly * the same!) */ if (dup_xcap_params_inline(&presentity->xcap_params, xcap_params, xcap_param_buffer) < 0) { ERR("can't duplicate XCAP parameters\n"); shm_free(presentity); *_p = NULL; return -1; } } if (ask_auth_rules(presentity) < 0) { /* try it from timer again if fails here */ presentity->auth_rules_refresh_time = act_time; } else presentity->auth_rules_refresh_time = act_time + auth_rules_refresh_time; *_p = presentity; /* add presentity into domain */ add_presentity(pdomain, *_p); return 0; }
/* * Create a new presentity and corresponding watcher list */ int create_presentity(struct sip_msg* _m, struct pdomain* _d, str* _puri, struct presentity** _p, struct watcher** _w) { time_t e; dlg_t* dialog; str watch_uri; str watch_dn; event_t *event = NULL; int et = 0; if (_m->event) { event = (event_t*)(_m->event->parsed); et = event->parsed; } else { et = EVENT_PRESENCE; } if (_m->expires) { e = ((exp_body_t*)_m->expires->parsed)->val; } else { e = default_expires; } if (e == 0) { *_p = 0; *_w = 0; DBG("create_presentity(): expires = 0\n"); return 0; } /* Convert to absolute time */ e += act_time; if (get_watch_uri(_m, &watch_uri, &watch_dn) < 0) { LOG(L_ERR, "create_presentity(): Error while extracting watcher URI\n"); return -1; } if (new_presentity(_d, _puri, _p) < 0) { LOG(L_ERR, "create_presentity(): Error while creating presentity\n"); return -2; } if (tmb.new_dlg_uas(_m, 200, &dialog) < 0) { paerrno = PA_DIALOG_ERR; LOG(L_ERR, "create_presentity(): Error while creating dialog state\n"); free_presentity(*_p); return -3; } if (et != EVENT_PRESENCE_WINFO) { if (add_watcher(*_p, &watch_uri, e, et, acc, dialog, &watch_dn, _w) < 0) { LOG(L_ERR, "create_presentity(): Error while adding a watcher\n"); tmb.free_dlg(dialog); free_presentity(*_p); return -4; } } else if (et == EVENT_PRESENCE_WINFO) { if (add_winfo_watcher(*_p, &watch_uri, e, et, acc, dialog, &watch_dn, _w) < 0) { LOG(L_ERR, "create_presentity(): Error while adding a winfo watcher\n"); tmb.free_dlg(dialog); free_presentity(*_p); return -5; } } add_presentity(_d, *_p); _d->reg(&watch_uri, _puri, (void*)callback, *_p); return 0; }