Logo Search packages:      
Sourcecode: jabberd14 version File versions  Download package

udata js_user ( jsmi  si,
jid  id,
xht  ht 
)

get the udata record for a user

js_user attempts to locate the user data record for the specifed id. First it looks in current list, if that fails, it looks in xdb and creates new list entry. If THAT fails, it returns NULL (not a user).

Parameters:
si the session manager instance data
id which user to load (some memory is allocated from this jid's pool)
ht the hash table for the host the user belongs to (may be NULL)
Returns:
the udata record for the user, NULL if no such user

Definition at line 248 of file users.cc.

References udata_struct::aux_data, jsmi_struct::hosts, udata_struct::id, udata_struct::p, pmalloco(), pool_cleanup(), udata_struct::si, jsmi_struct::xc, xdb_get(), xhash_get(), xhash_new(), xhash_put(), and xmlnode_free().

Referenced by _js_authreg_auth(), _js_authreg_register(), _js_routed_packet(), _jsm_deserialize_session(), js_deliver(), js_deliver_local(), js_sc_session_new(), js_server_main(), js_session_new(), js_user_create(), and js_user_delete().

                                       {
    pool p;
    udata cur, newu;
    char *ustr;
    xmlnode x, y;
    jid uid;

    if (si == NULL || id == NULL || id->user == NULL)
      return NULL;

    /* get the host hash table if it wasn't provided */
    if (ht == NULL)
        ht = static_cast<xht>(xhash_get(si->hosts,id->server));

    /* hrm, like, this isn't our user! */
    if (ht == NULL)
      return NULL;

    /* copy the id and convert user to lower case (if not done by libidn) */
    uid = jid_new(id->p, jid_full(jid_user(id)));
#ifndef LIBIDN
    for (ustr = uid->user; *ustr != '\0'; ustr++)
        *ustr = tolower(*ustr);
#endif

    /* debug message */
    log_debug2(ZONE, LOGT_SESSION, "js_user(%s,%X)",jid_full(uid),ht);

    /* try to get the user data from the hash table */
    if ((cur = static_cast<udata>(xhash_get(ht,uid->user))) != NULL)
        return cur;

    /* debug message */
    log_debug2(ZONE, LOGT_SESSION, "## js_user not current ##");

    /* try to get the user auth data from xdb */
    x = xdb_get(si->xc, uid, NS_AUTH);

    /* try to get hashed user auth data from xdb, if there was no plain data */
    y = (x == NULL) ? xdb_get(si->xc, uid, NS_AUTH_CRYPT) : NULL;

    /* does the user exist? */
    if (x == NULL && y == NULL)
      return NULL;

    /* create a udata struct */
    p = pool_heap(64);
    newu = static_cast<udata>(pmalloco(p, sizeof(_udata)));
    newu->p = p;
    newu->si = si;
    newu->aux_data = xhash_new(17);
    pool_cleanup(p, js_user_free_aux_data, newu->aux_data);
    newu->id = jid_new(p,jid_full(uid));
    if (x)
      xmlnode_free(x);
    if (y)
      xmlnode_free(y);


    /* got the user, add it to the user list */
    xhash_put(ht, newu->id->user, newu);
    log_debug2(ZONE, LOGT_SESSION, "js_user debug %X %X", xhash_get(ht, newu->id->user), newu);

    return newu;
}


Generated by  Doxygen 1.6.0   Back to index