dpm-ctrl_http.c File Reference

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

#include <dirent.h>
#include <pthread.h>
#include <mihl.h>
#include "dpm-ctrl_main.h"
#include "dpm-ctrl_config.h"
#include "dpm-ctrl_http.h"

Go to the source code of this file.

Defines

#define DPM_HTTP_PORT   80
#define DPM_HTTP_MAX_CONNECTIONS   400
#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"

Enumerations

enum  status_e { LOGGED_OUT = 1, LOGGED_IN, BAD_PASSWORD, LOGIN_SUCCESSFUL }

Functions

static void write_page (mihl_cnx_t *cnx, status_e status)
static int logout (mihl_cnx_t *cnx, char const *tag, char const *host, int num_vars __unused, char **var_names __unused, char **var_values __unused, void *param __unused)
static int login (mihl_cnx_t *cnx, char const *tag, char const *host, int num_vars, char **var_names, char **var_values, void *param __unused)
static int check_access (mihl_cnx_t *cnx, char const *tag, char const *host, void *param __unused)
static void * run_http_server (void *params __unused)
void init_http_server (void)
void suspend_http_server (void)
void resume_http_server (void)
void shutdown_http_server (void)

Variables

static volatile uint8_t shutdown_server = 1
static pthread_t http_thread
 thread of the HTTP server
static pthread_mutex_t suspend_lock
 lock for running server
int http_cpu_num
 CPU setup for use of HTTP server.


Detailed Description

Relating to the DPM's HTTP server.

The DPM runs an HTTP server in the dpm-ctrl_http module on a separate thread. The public functions provide a way to start and stop the HTTP server.

Definition in file dpm-ctrl_http.c.


Define Documentation

#define DPM_HTTP_MAX_CONNECTIONS   400

The maximum number of concurrently accepted connections to the HTTP server

Definition at line 41 of file dpm-ctrl_http.c.

Referenced by run_http_server().

#define DPM_HTTP_PORT   80

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

Definition at line 36 of file dpm-ctrl_http.c.

Referenced by run_http_server().

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

HTML content type header

Definition at line 52 of file dpm-ctrl_http.c.

Referenced by check_access(), login(), and logout().

#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 46 of file dpm-ctrl_http.c.

Referenced by run_http_server().


Enumeration Type Documentation

enum status_e

Used to control output on the standard webpage

Enumerator:
LOGGED_OUT  display login page
LOGGED_IN  display logout page
BAD_PASSWORD  display login page, with error msg
LOGIN_SUCCESSFUL  display logout page, with success msg

Definition at line 68 of file dpm-ctrl_http.c.


Function Documentation

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

Send a page with a script to redirect to the DPM'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 310 of file dpm-ctrl_http.c.

References HTML_CONTENT, LOG, LOGGED_IN, LOGGED_OUT, user_logged_in(), 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 401 of file dpm-ctrl_http.c.

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

Referenced by dpm_init(), retry_attach_fdb(), and wait_for_dfw().

static int login ( mihl_cnx_t *  cnx,
char const *  tag,
char const *  host,
int  num_vars,
char **  var_names,
char **  var_values,
void *param  __unused 
) [static]

Send a page with a script to redirect to the DPM'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 240 of file dpm-ctrl_http.c.

References apply_policy(), BAD_PASSWORD, HTML_CONTENT, LOG, LOGIN_SUCCESSFUL, validate_credentials(), and write_page().

Referenced by run_http_server().

static int logout ( mihl_cnx_t *  cnx,
char const *  tag,
char const *  host,
int num_vars  __unused,
char **var_names  __unused,
char **var_values  __unused,
void *param  __unused 
) [static]

Send a page with a script to redirect to the DPM'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 184 of file dpm-ctrl_http.c.

References HTML_CONTENT, LOG, LOGGED_OUT, remove_policy(), user_logged_in(), and write_page().

Referenced by run_http_server().

void resume_http_server ( void   ) 

Resume the HTTP server after reconfiguration. Can only be called if suspended with suspend_http_server.

Definition at line 453 of file dpm-ctrl_http.c.

References LOG, and suspend_lock.

Referenced by configuration_complete().

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 342 of file dpm-ctrl_http.c.

References check_access(), DPM_HTTP_MAX_CONNECTIONS, DPM_HTTP_PORT, HTTP_SERVER_LOG_LEVEL, INSIST_ERR, LOG, login(), logout(), shutdown_server, and suspend_lock.

Referenced by init_http_server().

void shutdown_http_server ( void   ) 

Stop and shutdown the HTTP server. It supports being restarted. Server cannot be suspended before calling this.

Definition at line 470 of file dpm-ctrl_http.c.

References http_thread, LOG, shutdown_server, and suspend_lock.

Referenced by dpm_quit(), and init_http_server().

void suspend_http_server ( void   ) 

Suspend the HTTP server. May block.

Definition at line 436 of file dpm-ctrl_http.c.

References LOG, and suspend_lock.

Referenced by reset_configuration().

static void write_page ( mihl_cnx_t *  cnx,
status_e  status 
) [static]

Display 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()
is_logged_in True if the user is logged in (will display log out page), and False if the user is not logged in (will display login page)

Definition at line 90 of file dpm-ctrl_http.c.

References BAD_PASSWORD, LOGGED_IN, and LOGIN_SUCCESSFUL.

Referenced by check_access(), login(), and logout().


Variable Documentation

volatile uint8_t shutdown_server = 1 [static]

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

Definition at line 60 of file dpm-ctrl_http.c.

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


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:54 2010 for SDK Your Net Corporation Dynamic Policy Manager Example: dpm-ctrl 1.0 by Doxygen 1.5.1