libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Typedefs | Functions
exportlocal.c File Reference
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <pwd.h>
#include <onion/shortcuts.h>
#include <onion/handler.h>
#include <onion/response.h>
#include <onion/codecs.h>
#include <onion/log.h>
#include <onion/low.h>
#include "exportlocal.h"

Data Structures

struct  onion_handler_export_local_data_t

Typedefs

typedef struct
onion_handler_export_local_data_t 
onion_handler_export_local_data

Functions

int onion_handler_export_local_directory (onion_handler_export_local_data *data, const char *realp, const char *showpath, onion_request *req, onion_response *res)
 Returns the directory listing.
int onion_handler_export_local_file (const char *realp, struct stat *reals, onion_request *request, onion_response *response)
int onion_handler_export_local_handler (onion_handler_export_local_data *d, onion_request *request, onion_response *response)
void onion_handler_export_local_header_default (onion_response *res, const char *dirname)
 Default directory handler: The style + dirname on a h1.
void onion_handler_export_local_footer_default (onion_response *res, const char *dirname)
void onion_handler_export_local_delete (void *data)
 Frees local data from the directory handler.
void onion_handler_export_local_set_header (onion_handler *handler, void(*renderer)(onion_response *res, const char *dirname))
 Sets the header renderer.
void onion_handler_export_local_set_footer (onion_handler *handler, void(*renderer)(onion_response *res, const char *dirname))
 Sets the footer renderer.
onion_handleronion_handler_export_local_new (const char *localpath)
 Creates an local filesystem handler.

Typedef Documentation

Function Documentation

void onion_handler_export_local_delete ( void *  data)

Frees local data from the directory handler.

References onion_handler_export_local_data_t::localpath, and onion_low_free().

Referenced by onion_handler_export_local_new().

int onion_handler_export_local_directory ( onion_handler_export_local_data data,
const char *  realp,
const char *  showpath,
onion_request req,
onion_response res 
)
int onion_handler_export_local_file ( const char *  realp,
struct stat *  reals,
onion_request request,
onion_response response 
)
void onion_handler_export_local_footer_default ( onion_response res,
const char *  dirname 
)
int onion_handler_export_local_handler ( onion_handler_export_local_data d,
onion_request request,
onion_response response 
)
void onion_handler_export_local_header_default ( onion_response res,
const char *  dirname 
)

Default directory handler: The style + dirname on a h1.

References onion_response_t::onion_response_printf(), and onion_response_write0().

Referenced by onion_handler_export_local_new().

onion_handler* onion_handler_export_local_new ( const char *  localpath)

Creates an local filesystem handler.

Creates an export local handler. When path matches, it returns a file from localpath (final localpath + path). No dir listing.

Exports the given localpath and any file inside this localpath is returned.

It performs security checks, so that the returned data is saftly known to be inside that localpath. Normal permissions apply.

References onion_handler_export_local_data_t::is_file, onion_handler_export_local_data_t::localpath, ONION_ERROR, onion_handler_export_local_delete(), onion_handler_export_local_footer_default(), onion_handler_export_local_handler(), onion_handler_export_local_header_default(), onion_handler_t::onion_handler_new(), onion_low_free(), onion_low_malloc(), onion_handler_export_local_data_t::renderer_footer, and onion_handler_export_local_data_t::renderer_header.

void onion_handler_export_local_set_footer ( onion_handler handler,
void(*)(onion_response *res, const char *dirname)  renderer 
)

Sets the footer renderer.

Calls to render a footers before end.

References onion_handler_t::onion_handler_get_private_data(), and onion_handler_export_local_data_t::renderer_footer.

void onion_handler_export_local_set_header ( onion_handler handler,
void(*)(onion_response *res, const char *dirname)  renderer 
)

Sets the header renderer.

Calls to render a header after the "Listing of directory...".

References onion_handler_t::onion_handler_get_private_data(), and onion_handler_export_local_data_t::renderer_header.