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

void it_presence ( session  s,
jpacket  jp 
)

Process presence from Jabber

Definition at line 16 of file presence.c.

References session_st::connected, session_st::exit_flag, session_st::id, it_contact_get(), it_contact_send_presence(), it_sms_get(), it_unknown_contact_add(), session_st::p_db, iti::sms_id, session_st::status, session_st::status_text, and session_st::ti.

Referenced by it_session_jpacket().

{
    log_debug(ZONE,"Session[%s], handling presence",jid_full(s->id));

    switch (jpacket_subtype(jp))
    {
    case JPACKET__PROBE:
      if (jp->to->user) {
        UIN_t uin;
        contact c;
        uin = it_jid2uin(jp->to);
      
            if (j_strcmp(jp->to->server,s->ti->sms_id)==0) {
              uin = SMS_CONTACT;
            }

        if (uin == SMS_CONTACT)
          c = it_sms_get(s,jp->to->user);
        else
          c = it_contact_get(s,uin);

        if (c != NULL)
          it_contact_send_presence(c,NULL);
            else {
              c = it_unknown_contact_add(s,jp->to->user,uin);
              if (c != NULL)
                  it_contact_send_presence(c,NULL);
            }
      }
      break;

    case JPACKET__INVISIBLE:
      {
      icqstatus status;
      char *text;

      if (jp->to->user) /* presence to groupchat here */
        break;

      /* update users presence */
      s->p_db = ppdb_insert(s->p_db,jp->from,jp->x);

      text = xmlnode_get_tag_data(jp->x,"status");
      
      if (text != NULL)
        strncpy(s->status_text,text,MAX_STATUS_TEXT);
      else
        s->status_text[0] = '\0';
      
      status = ICQ_STATUS_INVISIBLE;
      if (status != s->status) {
        s->status = status;
        /* propagate to C++ backend */
        SendStatus(s);
      }
      
      /* echo.... */
      /* only when connected */
      if (!s->connected) {
        xmlnode_free(jp->x);
        return;
      }
      
      xmlnode_put_attrib(jp->x,"from",jid_full(jp->to));
      xmlnode_put_attrib(jp->x,"to",jid_full(jid_user(jp->from)));
      it_deliver(s->ti,jp->x);
      return;
      }

    case JPACKET__AVAILABLE:
      {
        icqstatus status;
        char *text;

        if (jp->to->user) /* presence to groupchat here */
            break;

        log_debug(ZONE,"presence");

        /* update user's presence */
        s->p_db = ppdb_insert(s->p_db,jp->from,jp->x);

        text = xmlnode_get_tag_data(jp->x,"status");

        if (text != NULL) {
          strncpy(s->status_text,text,MAX_STATUS_TEXT);
        }
        else
          s->status_text[0] = '\0';
    
        status = jit_show2status(xmlnode_get_tag_data(jp->x,"show"));
        if (status != s->status) {
          s->status = status;
          /* Always set status regardless of being connected or not */
          /* Client class will set this status */
          /* after connecting */
          SendStatus(s);
        }

        /* echo.... */
        /* only when connected */
        if (!s->connected) {
          xmlnode_free(jp->x);
          return;
        }
    
        xmlnode_put_attrib(jp->x,"from",jid_full(jp->to));
        xmlnode_put_attrib(jp->x,"to",jid_full(jid_user(jp->from)));
        it_deliver(s->ti,jp->x);
        return;
    }

    case JPACKET__UNAVAILABLE:
        if (jp->to->user == NULL)
        { /* kill the session if there are no available resources left */
          s->p_db = ppdb_insert(s->p_db,jp->from,jp->x);
          if (ppdb_primary(s->p_db,s->id) == NULL){
            if (!s->exit_flag)
              EndClient(s); // will call it_session_end
          }
        }

    default:
        break;
    }

    xmlnode_free(jp->x);
}


Generated by  Doxygen 1.6.0   Back to index