cpd_http.c File Reference

Relating to the CPD's HTTP server. More...

#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <signal.h>
#include <pthread.h>
#include <mihl.h>
#include <jnx/aux_types.h>
#include "cpd_http.h"
#include "cpd_config.h"
#include "cpd_conn.h"
#include "cpd_logging.h"

Go to the source code of this file.

Defines

#define CPD_HTTP_PORT   80
#define CPD_HTTP_MAX_CONNECTIONS   100
#define HTTP_SERVER_LOG_LEVEL   (MIHL_LOG_ERROR | MIHL_LOG_WARNING | MIHL_LOG_INFO | MIHL_LOG_INFO_VERBOSE)
#define HTML_CONTENT   "Content-type: text/html\r\n"
#define CPD_CONTENT_DIRECTORY   "/var/cpd_content"
#define MEDIA_TYPES   9
#define DEFAULT_MEDIA_TYPE   "text/plain"

Functions

static void write_page (mihl_cnx_t *cnx, char const *message)
static int page_not_found (mihl_cnx_t *cnx, char const *tag, char const *host, void *param __unused)
static int repudiate_access (mihl_cnx_t *cnx, char const *tag, char const *host, void *param)
static int authorize_access (mihl_cnx_t *cnx, char const *tag, char const *host, void *param)
static int check_access (mihl_cnx_t *cnx, char const *tag, char const *host, void *param)
static void register_content (mihl_ctx_t *ctx)
static void * run_http_server (void *params __unused)
void init_http_server (void)
void shutdown_http_server (void)

Variables

const char * type_mappings [MEDIA_TYPES][2]
static boolean shutdown_server = TRUE
static pthread_t http_thread
static char * pfd_address = NULL
static char * cpd_address = NULL


Detailed Description

Relating to the CPD's HTTP server.

The CPD runs an HTTP server in the cpd_http module on a separate thread. The functions provide a way to start and stop the HTTP server.

Definition in file cpd_http.c.


Define Documentation

#define CPD_CONTENT_DIRECTORY   "/var/cpd_content"

The directory in which content to serve via HTTP is found

Definition at line 64 of file cpd_http.c.

Referenced by register_content().

#define CPD_HTTP_MAX_CONNECTIONS   100

The maximum number of concurrently accepted connections to the HTTP server

Definition at line 48 of file cpd_http.c.

Referenced by run_http_server().

#define CPD_HTTP_PORT   80

The port that the CPD's public HTTP server runs on

Definition at line 43 of file cpd_http.c.

Referenced by run_http_server().

#define DEFAULT_MEDIA_TYPE   "text/plain"

The of the type is undefined in type_mappings then use this type

Definition at line 74 of file cpd_http.c.

Referenced by register_content().

#define HTML_CONTENT   "Content-type: text/html\r\n"

HTML content type header

Definition at line 59 of file cpd_http.c.

Referenced by authorize_access(), check_access(), page_not_found(), and repudiate_access().

#define HTTP_SERVER_LOG_LEVEL   (MIHL_LOG_ERROR | MIHL_LOG_WARNING | MIHL_LOG_INFO | MIHL_LOG_INFO_VERBOSE)

The logging level to use with the HTTP server (library)

Definition at line 53 of file cpd_http.c.

Referenced by run_http_server().

#define MEDIA_TYPES   9

Number of media types in type_mappings

Definition at line 69 of file cpd_http.c.

Referenced by register_content().


Function Documentation

static int authorize_access ( mihl_cnx_t *  cnx,
char const *  tag,
char const *  host,
void *  param 
) [static]

Send a page with a script to redirect to the CPD's home page Alternatively, we could send an HTTP MOVED, but this library doesn't support that currently.

Parameters:
cnx Opaque context structure as returned by mihl_init()
tag URL
host The connecting host
param The user data registers for the callback
Returns:
the result of mihl_send

Definition at line 284 of file cpd_http.c.

References add_auth_user_addr(), HTML_CONTENT, is_auth_user(), LOG, page_not_found(), pfd_address, send_authorized_user(), and write_page().

Referenced by run_http_server().

static int check_access ( mihl_cnx_t *  cnx,
char const *  tag,
char const *  host,
void *  param 
) [static]

Send a page with a script to redirect to the CPD's home page Alternatively, we could send an HTTP MOVED, but this library doesn't support that currently.

Parameters:
cnx Opaque context structure as returned by mihl_init()
tag URL
host The connecting host
param The user data registers for the callback
Returns:
the result of mihl_send

Definition at line 338 of file cpd_http.c.

References HTML_CONTENT, is_auth_user(), LOG, page_not_found(), pfd_address, and write_page().

Referenced by run_http_server().

void init_http_server ( void   ) 

Initialize and start the HTTP server on a separate thread

Definition at line 535 of file cpd_http.c.

References http_thread, LOG, run_http_server(), shutdown_http_server(), and shutdown_server.

Referenced by ifa_async_handler().

static int page_not_found ( mihl_cnx_t *  cnx,
char const *  tag,
char const *  host,
void *param  __unused 
) [static]

Send a page with a script to redirect to the CPD's home page Alternatively, we could send an HTTP MOVED, but this library doesn't support that currently.

Parameters:
cnx Opaque context structure as returned by mihl_init()
tag URL (of the non existent page)
host The connecting host
param The user data registers for the callback (the server's IP)
Returns:
the result of mihl_send

Definition at line 191 of file cpd_http.c.

References cpd_address, HTML_CONTENT, and LOG.

Referenced by authorize_access(), check_access(), repudiate_access(), and run_http_server().

static void register_content ( mihl_ctx_t *  ctx  )  [static]

Register content with the HTTP server

Parameters:
[in] ctx The mihl HTTP library context/handle for the started server

Definition at line 376 of file cpd_http.c.

References CPD_CONTENT_DIRECTORY, DEFAULT_MEDIA_TYPE, LOG, MEDIA_TYPES, and type_mappings.

Referenced by run_http_server().

static int repudiate_access ( mihl_cnx_t *  cnx,
char const *  tag,
char const *  host,
void *  param 
) [static]

Send a page with a script to redirect to the CPD's home page Alternatively, we could send an HTTP MOVED, but this library doesn't support that currently.

Parameters:
cnx Opaque context structure as returned by mihl_init()
tag URL
host The connecting host
param The user data registers for the callback
Returns:
the result of mihl_send

Definition at line 230 of file cpd_http.c.

References delete_auth_user_addr(), HTML_CONTENT, is_auth_user(), LOG, page_not_found(), pfd_address, send_repudiated_user(), and write_page().

Referenced by run_http_server().

static void* run_http_server ( void *params  __unused  )  [static]

Run the HTTP server

Parameters:
[in] params parameters passed to pthread create
Returns:
NULL

Definition at line 460 of file cpd_http.c.

References authorize_access(), check_access(), cpd_address, CPD_HTTP_MAX_CONNECTIONS, CPD_HTTP_PORT, get_cpd_address(), get_pfd_address(), HTTP_SERVER_LOG_LEVEL, LOG, page_not_found(), pfd_address, register_content(), repudiate_access(), and shutdown_server.

Referenced by init_http_server().

void shutdown_http_server ( void   ) 

Stop and shutdown the HTTP server. It supports being restarted.

Definition at line 567 of file cpd_http.c.

References http_thread, LOG, and shutdown_server.

Referenced by cpd_ctrl_quit(), ifa_async_handler(), and init_http_server().

static void write_page ( mihl_cnx_t *  cnx,
char const *  message 
) [static]

Add a message to a standard HTML page and write it in the HTTP response using the mihl_add function

Parameters:
cnx Opaque context structure as returned by mihl_init()
message The message that will be bold and in red on the page

Definition at line 131 of file cpd_http.c.

Referenced by authorize_access(), check_access(), and repudiate_access().


Variable Documentation

char* cpd_address = NULL [static]

The readable formatted pfd address

Definition at line 114 of file cpd_http.c.

pthread_t http_thread [static]

The thread of the HTTP server

Definition at line 103 of file cpd_http.c.

Referenced by init_http_server(), and shutdown_http_server().

char* pfd_address = NULL [static]

The readable formatted pfd address

Definition at line 108 of file cpd_http.c.

boolean shutdown_server = TRUE [static]

Whether the server is shutdown or (for the server thread) needs shutting down

Definition at line 98 of file cpd_http.c.

Referenced by init_http_server(), run_http_server(), and shutdown_http_server().

const char* type_mappings[MEDIA_TYPES][2]

Initial value:

 {
    {".html", "text/html"},
    {".htm",  "text/html"},
    {".css",  "text/css"},
    {".xml",  "text/xml"},
    {".jpg",  "image/jpeg"},
    {".gif",  "image/gif"},
    {".png",  "image/png"},
    {".js",   "application/javascript"},
    {".swf",  "application/x-shockwave-flash"}
}
MIME type mapping mapping for (our) supported file extensions in the directory of content for the HTTP server.

Definition at line 80 of file cpd_http.c.

Referenced by register_content().


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:53 2010 for SDK Your Net Corporation Policy Manager Example: Captive Portal Daemon (cpd) 1.0 by Doxygen 1.5.1