
#include <stdio.h>
#include <stdlib.h>

#include "http.h"

#include "mobilitytable.h"
#include "mobility.h"


int mobility_init (void);
int mobility_handler (httpTtrans *t, lstTset *opts);

int
mobility_init()
{
    return (STATUS_PROCEED);
}

int
mobility_handler (httpTtrans *t, lstTset *opts)
{
    const char *handler;
    const char *mimetype;
    Mobility *mob;

    mimetype = lstFset_get (opts, "mimetype");

    if (mimetype != NULL)
    {
        const char *this_mimetype = lstFset_get (t->res_hdrs, "Content-Type");

        if (this_mimetype == NULL || strcmp (mimetype, this_mimetype) != 0)
        {
            return (STATUS_PROCEED);
        }
    }

    handler = lstFset_get (opts, "handler");

    mob = mobilitytable_getMobilityEntry (mobilitytable_getTable(), handler);

    if (mob == NULL)
    {
        logFmsg (CONT_LOG_ERROR, "mobility: Couldn't get a mobility entry.");

        /* we couldn't function.. we'll just keep on going */
        return (STATUS_PROCEED);
    }
    else
    {
        return (mobility_sendRequest (mob, t));
    }
}
