Back to index

avfs  1.0.1
Classes | Functions | Variables
http_redirect.c File Reference
#include "config.h"
#include "http_request.h"
#include "ne_alloc.h"
#include "http_private.h"
#include "http_redirect.h"
#include "uri.h"
#include "neon_i18n.h"

Go to the source code of this file.

Classes

struct  redirect

Functions

static void * create (void *session, http_req *req, const char *method, const char *uri)
static int post_send (void *private, const http_status *status)
static void destroy (void *private)
static int auto_redirect (struct redirect *red)
void http_redirect_register (http_session *sess, http_redirect_confirm confirm, http_redirect_notify notify, void *userdata)

Variables

http_request_hooks redirect_hooks

Class Documentation

struct redirect

Definition at line 38 of file http_redirect.c.

Class Members
http_redirect_confirm confirm
char * location
http_redirect_notify notify
http_req * req
void * userdata

Function Documentation

static int auto_redirect ( struct redirect red) [static]

Definition at line 77 of file http_redirect.c.

{
    return (red->req->method_is_head ||
           strcasecmp(red->req->method, "GET") == 0 || 
           strcasecmp(red->req->method, "PROPFIND") == 0);
}

Here is the caller graph for this function:

static void * create ( void *  session,
http_req *  req,
const char *  method,
const char *  uri 
) [static]

Definition at line 61 of file http_redirect.c.

{
    struct redirect *red = session;
    
    /* for handling 3xx redirects */
    http_add_response_header_handler(req, "Location",
                                 http_duplicate_header, &red->location);

    red->req = req;

    return red;
}
static void destroy ( void *  private) [static]

Definition at line 143 of file http_redirect.c.

{
    struct redirect *red = private;
    HTTP_FREE(red->location);
}
void http_redirect_register ( http_session *  sess,
http_redirect_confirm  confirm,
http_redirect_notify  notify,
void *  userdata 
)

Definition at line 149 of file http_redirect.c.

{
    struct redirect *red = ne_calloc(sizeof *red);
    
    red->confirm = confirm;
    red->notify = notify;
    red->userdata = userdata;
    
    http_add_hooks(sess, &redirect_hooks, red);
}
static int post_send ( void *  private,
const http_status status 
) [static]

Definition at line 84 of file http_redirect.c.

{
    struct redirect *red = private;
    struct uri uri;

    if ((status->code != 302 && status->code != 301) ||
       red->location == NULL) {
       /* Nothing to do. */
       return HTTP_OK;
    }
    
    if (uri_parse(red->location, &uri, NULL)) {
       /* Couldn't parse the URI */
       http_set_error(red->req->session, 
                     _("Could not parse redirect location."));
       return HTTP_ERROR;
    }
    
    
    if (auto_redirect(red)) {
       if (red->notify != NULL) {
           (*red->notify)(red->userdata, red->req->abs_path, uri.path);
       }
    } else {
       /* Need user-confirmation to follow the redirect */
       if (red->confirm == NULL || 
           !(*red->confirm)(red->userdata, red->req->abs_path, uri.path)) {
           return HTTP_OK;
       }
    }
    
    red->req->abs_path = ne_strdup(uri.path);

    /* Set red->req->uri and new host/port for the session, if necessary */
    
    HTTP_FREE(red->req->uri);
    if (red->req->use_proxy)
       red->req->uri = ne_strdup(red->location);
    else
       red->req->uri = ne_strdup(red->req->abs_path);
    
    if (uri.host != NULL && 
       strcasecmp(uri.host, red->req->session->server.hostname) != 0) {
       /* Handle redirecting to another host. */
       
       if (uri.port <= 0)
           uri.port = HTTP_PORT;
       
       /* FIXME: shouldn't do this here.  Let the caller control
           this.  */
       http_session_server(red->req->session, uri.host, uri.port);
    }

    /* FIXME: need to uri_free here (the above http_session_server()
     * call prevents this at the moment). */
    
    return HTTP_RETRY;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
 {
    "http://www.webdav.org/neon/hooks/http-redirect",
    create,
    NULL,
    NULL,
    post_send,
    destroy
}

Definition at line 51 of file http_redirect.c.