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

void dispatch ( sm_t  sm,
pkt_t  pkt 
)

main packet dispatcher

Definition at line 31 of file dispatch.c.

References pkt_st::from, sm_st::mm, mm_in_router(), mm_pkt_router(), mm_pkt_sm(), mm_pkt_user(), mod_HANDLED, mod_PASS, pkt_IQ_RESULT, route_BROADCAST, route_ERROR, route_UNICAST, pkt_st::rtype, user_st::sessions, pkt_st::sm, pkt_st::to, pkt_st::type, and user_load().

Referenced by sm_sx_callback().

                                  {
    user_t user;
    mod_ret_t ret;

    /* handle broadcasts */
    if(pkt->rtype == route_BROADCAST) {
        log_debug(ZONE, "can't handle broadcast routes (yet), dropping");
        pkt_free(pkt);
        return;
    }

    /* routing errors, add a im error */
    if(pkt->rtype & route_ERROR)
        pkt_error(pkt, stanza_err_REMOTE_SERVER_NOT_FOUND);

    /*
     * - if its from the router (non-route) it goes straight to pkt_router
     * - hand it to in_router chain
     * - if its for the sm itself (no user), hand it to the pkt_sm chain
     * - find the user
     * - hand to pkt_user
     */

    /* non route packets are special-purpose things from the router */
    if(!(pkt->rtype & route_UNICAST)) {
        ret = mm_pkt_router(pkt->sm->mm, pkt);
        switch(ret) {
            case mod_HANDLED:
                break;

            case mod_PASS:
            default:
                /* don't ever bounce these */
                pkt_free(pkt);

                break;
        }

        return;
    }

    /* preprocessing */
    ret = mm_in_router(pkt->sm->mm, pkt);
    switch(ret) {
        case mod_HANDLED:
            return;

        case mod_PASS:
            break;

        default:
            pkt_router(pkt_error(pkt, -ret));
            return;
    }

    /* has to come from someone */
    if(pkt->from == NULL) {
        pkt_router(pkt_error(pkt, stanza_err_BAD_REQUEST));
        return;
    }

    /* packet is for the sm itself */
    if(pkt->to != NULL && *pkt->to->node == '\0') {
        ret = mm_pkt_sm(pkt->sm->mm, pkt);
        switch(ret) {
            case mod_HANDLED:
                break;

            case mod_PASS:
                /* ignore IQ result packets that haven't been handled - XMPP 9.2.3.4 */
                if(pkt->type == pkt_IQ_RESULT)
                    break;
                 else
                    ret = -stanza_err_FEATURE_NOT_IMPLEMENTED;

            default:
                pkt_router(pkt_error(pkt, -ret));
    
                break;
        }

        return;
    }

    /* get the user */
    user = user_load(sm, pkt->to);
    if(user == NULL) {
        pkt_router(pkt_error(pkt, stanza_err_ITEM_NOT_FOUND));
        return;
    }
    
    ret = mm_pkt_user(pkt->sm->mm, user, pkt);
    switch(ret) {
        case mod_HANDLED:
            break;
    
        case mod_PASS:
            /* ignore IQ result packets that haven't been handled - XMPP 9.2.3.4 */
            if(pkt->type == pkt_IQ_RESULT)
                break;
             else
                ret = -stanza_err_FEATURE_NOT_IMPLEMENTED;

        default:
            pkt_router(pkt_error(pkt, -ret));

            break;
    }

    /* if they have no sessions, they were only loaded to do delivery, so free them */
    if(user->sessions == NULL)
        user_free(user);
}


Generated by  Doxygen 1.6.0   Back to index