Logo Search packages:      
Sourcecode: jabber-jit version File versions  Download package

void it_contact_load_roster ( session  s  ) 

Load contact roster. Read the Jabber user's main Jabber roster and insert all contacts on this transport to our session's contact list. This will fail if the user connects from a different server than this transport is running on.

Definition at line 20 of file contact.c.

References session_st::contact_count, session_st::exit_flag, session_st::from, session_st::id, it_contact_add(), it_contact_get(), it_sms_add(), it_sms_get(), iti::no_jabber_roster, iti::own_roster, session_st::p, session_st::roster_changed, iti::sms_id, contact_st::status, session_st::ti, session_st::uin, and iti::xc.

{
  xmlnode roster, item;
  UIN_t uin;
  contact c;

  s->roster_changed = 0;

  if (s->exit_flag)
    return;

  /* get own roster */
  if (s->ti->own_roster) {
    roster = xdb_get(s->ti->xc,
                               it_xdb_id(s->p,s->id,s->from->server)
                               ,NS_ROSTER);
      if (roster != NULL) {

        /* loop roster */
        for (item = xmlnode_get_firstchild(roster); item != NULL; item = xmlnode_get_nextsibling(item))   {
            UIN_t uin;

            if (xmlnode_get_type(item) != NTYPE_TAG) continue;
            if (xmlnode_get_attrib(item,"jid") == NULL)  continue;

            uin = it_strtouin(xmlnode_get_attrib(item,"jid"));

        if (uin == SMS_CONTACT)
          c = it_sms_get(s,xmlnode_get_attrib(item,"jid"));
        else
          c = it_contact_get(s,uin);

            if (!c) {
              if (uin == SMS_CONTACT) {
                  log_debug("SMS","ADD %s",xmlnode_get_attrib(item,"jid"));
                  c = it_sms_add(s,xmlnode_get_attrib(item,"jid"));
                  c->status = ICQ_STATUS_OFFLINE;
                  s->contact_count++;
              }
              else 
                  if (uin && uin != s->uin)  {
                    c = it_contact_add(s,uin);
                    log_debug(ZONE,"Contact ADD %d",uin);
                    // propagate contact to C++ backend
                    AddICQContact(c);
                    
                    c->status = ICQ_STATUS_OFFLINE;
                    s->contact_count++;               
                  }
            }
            
        }
      }
      xmlnode_free(roster);
  }

  s->roster_changed = 0;
  
  if (s->ti->no_jabber_roster) 
      return;

  roster = xdb_get(s->ti->xc,s->id,NS_ROSTER); 
  if (roster == NULL)
    return;

  for (item = xmlnode_get_firstchild(roster); item != NULL; item = xmlnode_get_nextsibling(item))   {
      jid tmpjid;

    if (xmlnode_get_type(item) != NTYPE_TAG) continue;
    if (xmlnode_get_attrib(item,"jid") == NULL)  continue;
    if (xmlnode_get_attrib(item,"subscribe") != NULL) continue;

      tmpjid = jid_new(xmlnode_pool(roster),xmlnode_get_attrib(item,"jid"));
        
    log_debug(ZONE,"contact %s",tmpjid->server);

    /* SMS contact */
    if (j_strcmp(s->ti->sms_id,tmpjid->server)==0) {
      log_debug(ZONE,"SMS contact ADD %s",tmpjid->user);
      c = it_sms_add(s,tmpjid->user);
      c->status = ICQ_STATUS_OFFLINE;
      s->contact_count++;
      continue;
    }
    
    /* ignore transport itself */
    if (jid_cmpx(s->from,tmpjid,JID_SERVER)) continue;
    
    uin = it_strtouin(tmpjid->user);
    if (uin && uin != s->uin && it_contact_get(s,uin) == NULL)  {
        c = it_contact_add(s,uin);
      log_debug(ZONE,"Contact ADD %d",uin);
      // propagate contact to C++ backend
      AddICQContact(c);
        
      c->status = ICQ_STATUS_OFFLINE;
      s->contact_count++;
      
      //      if (xmlnode_get_attrib(item,"ask")) 
      //        c->asking = 1; 
    }
  }

  s->roster_changed = 0;
  
  xmlnode_free(roster);
}


Generated by  Doxygen 1.6.0   Back to index