APPWEB - Appweb API Native API

Components

Appweb Appweb Service.
MaServer The MaServer object.
MaState Current configuration parse state.

Functions

voidmaAddDirective(MaAppweb *appweb, cchar *directive, MaDirective proc)
 Define a new config directive.
voidmaAddEndpoint(MaServer *server, HttpEndpoint *endpoint)
 Add a listening endpoint.
voidmaAddServer(MaAppweb *appweb, struct MaServer *server)
 Add a server.
intmaApplyChangedGroup(MaAppweb *appweb)
 Apply the changed group.
intmaApplyChangedUser(MaAppweb *appweb)
 Apply the changed user.
intmaArchiveLog(cchar *path, int count, int maxSize)
 Archive a log file.
intmaConfigureServer(MaServer *server, cchar *configFile, cchar *home, cchar *documents, cchar *ip, int port)
 Configure a web server.
MaAppweb*maCreateAppweb()
 Create the Appweb object.
MaServer*maCreateServer(MaAppweb *appweb, cchar *name)
 Create a MaServer object.
voidmaGetUserGroup(MaAppweb *appweb)
 Get the user group.
intmaLoadModule(MaAppweb *appweb, cchar *name, cchar *libname)
 Load an appweb module.
struct MaServer*maLookupServer(MaAppweb *appweb, cchar *name)
 Lookup a server.
intmaMatchDir(HttpConn *conn, HttpRoute *route, int direction)
 Match routine for the dirHandler.
intmaParseConfig(MaServer *server, cchar *path, int flags)
 Parse an Appweb configuration file.
intmaParseInit(MaAppweb *appweb)
 Initialize the config file parser.
MaState*maPopState(MaState *state)
 Pop the state.
MaState*maPushState(MaState *state)
 Push the state.
intmaRunSimpleWebServer(cchar *ip, int port, cchar *home, cchar *documents)
 Create and run a simple web server listening on a single IP address.
intmaRunWebServer(cchar *configFile)
 Create and run a web server based on a configuration file.
voidmaSetAccessLog(HttpRoute *route, cchar *path, cchar *format)
 Define the access log.
voidmaSetDefaultServer(MaAppweb *appweb, struct MaServer *server)
 Set the default server.
intmaSetHttpGroup(MaAppweb *appweb, cchar *group)
 Set the Http Group.
intmaSetHttpUser(MaAppweb *appweb, cchar *user)
 Set the Http User.
voidmaSetServerAddress(MaServer *server, cchar *ip, int port)
 Set the server listen address.
voidmaSetServerHome(MaServer *server, cchar *path)
 Set the server home directory.
intmaStartAccessLogging(HttpRoute *route)
 Start access logging.
intmaStartAppweb(MaAppweb *appweb)
 Start Appweb services.
intmaStartServer(MaServer *server)
 Start a server.
voidmaStopAccessLogging(HttpRoute *route)
 Stop access logging.
intmaStopAppweb(MaAppweb *appweb)
 Stop Appweb services.
voidmaStopServer(MaServer *server)
 Stop a server.
boolmaValidateServer(MaServer *server)
 Validate the configuration of a server.

Typedefs

MaDirectiveDirective callback function.

Defines

#defineHTTP_NAME   MA_SERVER_NAME
 Default web server software identification.
#defineMA_MAX_ACCESS_LOG   20971520
 Access file size (20 MB).
#defineMA_MAX_CONFIG_DEPTH   16
 Max nest of directives in config file.
#defineMA_MAX_REWRITE   10
 Maximum recursive URI rewrites.
#defineMA_PARSE_NON_SERVER   0x1
 Command file being parsed by a utility program.
#defineMA_SDB_MEMORY   (20 * 1024 * 1024)
 SDB heap memory.
#defineMA_SDB_TIMEOUT   (20 * 1000)
 SDB busy timeout.
#defineMA_UNLOAD_TIMEOUT   "5mins"
 Default module inactivity unload timeout.

Appweb

Appweb

Appweb Service.

Description:
There is one instance of MaAppweb per application. It manages a list of HTTP servers running in the application.
API Stability:
Evolving.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
Fields:
void maAddDirective (MaAppweb *appweb, cchar *directive, MaDirective proc)

Define a new config directive.

Description:
The appweb configuration file parse is extensible. New directives can be registered by this call. When encountered in the config file, the given callback proc will be invoked to parse.
Parameters:
appwebAppweb object created via maCreateAppweb
directiveDirective name.
procDirective callback procedure of the type MaDirective
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
void maAddEndpoint (MaServer *server, HttpEndpoint *endpoint)

Add a listening endpoint.

Parameters:
serverServer object to modify.
endpointListening endpoint to add to the server.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
void maAddServer (MaAppweb *appweb, struct MaServer *server)

Add a server.

Description:
Add a server to the list of appweb managed web servers.
Parameters:
appwebAppweb object created via maCreateAppweb
serverMaServer object.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maApplyChangedGroup (MaAppweb *appweb)

Apply the changed group.

Description:
Apply configuration changes and actually change the Appweb group id.
Parameters:
appwebAppweb object created via maCreateAppweb
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maApplyChangedUser (MaAppweb *appweb)

Apply the changed user.

Description:
Apply configuration changes and actually change the Appweb user id.
Parameters:
appwebAppweb object created via maCreateAppweb
See Also:
Http, maAddServer, maApplyChangedGroup, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
MaAppweb * maCreateAppweb ()

Create the Appweb object.

Description:
Appweb uses a singleton Appweb object to manage multiple web servers instances.
Returns:
A Http object. Use mprFree to close and release.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
void maGetUserGroup (MaAppweb *appweb)

Get the user group.

Description:
Get the user name and ID for appweb.
Parameters:
appwebAppweb object created via maCreateAppweb
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maLoadModule (MaAppweb *appweb, cchar *name, cchar *libname)

Load an appweb module.

Description:
Load an appweb module. If the module is already loaded, this call will return successfully without reloading. Modules can be dynamically loaded or may also be pre-loaded using static linking.
Parameters:
appwebAppweb object created via maCreateAppweb
nameUser name. Must be defined in the system password file.
libnameLibrary path name.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
struct MaServer * MaServer* maLookupServer (MaAppweb *appweb, cchar *name)

Lookup a server.

Description:
Lookup a server by name and return the MaServer object.
Parameters:
appwebAppweb object created via maCreateAppweb
nameServer name.
Returns:
MaServer object.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maMatchDir (HttpConn *conn, HttpRoute *route, int direction)

Match routine for the dirHandler.

Parameters:
connConnection object.
routeMatching route object.
directionSet to HTTP_STAGE_TX or HTTP_STAGE_RX.
Returns:
HTTP_ROUTE_OK if the request matches.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maParseConfig (MaServer *server, cchar *path, int flags)

Parse an Appweb configuration file.

Description:
Parse the configuration file and configure the server. This creates a default host and route and then configures the server based on config file directives.
Parameters:
serverMaServer object created via maCreateServer
pathConfiguration file pathname.
flagsParse control flags. Reserved. Set to zero.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maParseInit (MaAppweb *appweb)

Initialize the config file parser.

Parameters:
appwebAppweb object created via maCreateAppweb
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
MaState * maPopState (MaState *state)

Pop the state.

Description:
This is used when parsing config files to handle nested include files and block level directives.
Parameters:
stateCurrent state.
Returns:
The next lower level state object.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
MaState * maPushState (MaState *state)

Push the state.

Description:
This is used when parsing config files to handle nested include files and block level directives.
Parameters:
stateCurrent state.
Returns:
The state passed as a parameter which becomes the new top level state.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
void maSetAccessLog (HttpRoute *route, cchar *path, cchar *format)

Define the access log.

Description:
The access log is used to log details about requests to the web server. Errors are logged in the error log.
Parameters:
routeHttpRoute object for which to define the logging characteristics.
pathPathname for the log file.
formatLog file format. The format string argument defines how Appweb will record HTTP accesses to the access log. The following log format specifiers are supported:
  • %% - Percent sign
  • a - Remote IP address
  • b - Response bytes written to the client include headers. If zero, "-" is written.
  • B - Response bytes written excluding headers
  • h - Remote hostname
  • O - Bytes written include headers. If zero bytes, "0" is written.
  • r - First line of the request
  • s - HTTP response status code
  • t - Time the request was completed
  • u - Authenticated username
  • %{header}i -
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
void maSetDefaultServer (MaAppweb *appweb, struct MaServer *server)

Set the default server.

Parameters:
appwebAppweb object created via maCreateAppweb
serverMaServer object.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maSetHttpGroup (MaAppweb *appweb, cchar *group)

Set the Http Group.

Description:
Define the group name under which to run the Appweb service.
Parameters:
appwebAppweb object created via maCreateAppweb
groupGroup name. Must be defined in the system group file.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpUser, maStartAppweb, maStopAppweb
int maSetHttpUser (MaAppweb *appweb, cchar *user)

Set the Http User.

Description:
Define the user name under which to run the Appweb service.
Parameters:
appwebAppweb object created via maCreateAppweb
userUser name. Must be defined in the system password file.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maStartAppweb, maStopAppweb
void maSetServerAddress (MaServer *server, cchar *ip, int port)

Set the server listen address.

Description:
Set the internet addresses for all endpoints managed by the server.
Parameters:
serverMaServer object created via maCreateServer
ipIP address to set for the server.
portPort number to use for the server.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
void maSetServerHome (MaServer *server, cchar *path)

Set the server home directory.

Parameters:
serverMaServer object created via maCreateServer
pathPath to the directory for the server configuration.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maStartAccessLogging (HttpRoute *route)

Start access logging.

Description:
Start access logging for a host.
Parameters:
routeHttpRoute object.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maStartAppweb (MaAppweb *appweb)

Start Appweb services.

Description:
This starts listening for requests on all configured servers.
Parameters:
appwebAppweb object created via maCreateAppweb
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStopAppweb
void maStopAccessLogging (HttpRoute *route)

Stop access logging.

Parameters:
routeHttpRoute object.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb
int maStopAppweb (MaAppweb *appweb)

Stop Appweb services.

Description:
This stops listening for requests on all configured servers. Shutdown is somewhat graceful.
Parameters:
appwebAppweb object created via maCreateAppweb
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb
bool maValidateServer (MaServer *server)

Validate the configuration of a server.

Parameters:
serverServer object to validate.
Returns:
True if the configuration is valid.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb

MaServer

MaServer

The MaServer object.

Description:
An application may have any number of HTTP servers, each managed by a MaServer instance.
API Stability:
Evolving.
See Also:
maAddEndpoint, maConfigureServer, maCreateServer, maParseConfig, maRunSimpleWebServer, maRunWebServer, maSetServerAddress, maSetServerHome, maValidateServer
Fields:
MaAppweb *appweb Appweb control object.
MprList *endpoints List of HttpEndpoints.
char *home Server root.
Http *http Http service object (copy of appweb->http).
HttpLimits *limits Limits for this server.
char *name Unique name for this server.
int maConfigureServer (MaServer *server, cchar *configFile, cchar *home, cchar *documents, cchar *ip, int port)

Configure a web server.

Description:
This will configure a web server based on either a configuration file or using the supplied IP address and port.
Parameters:
serverMaServer object created via maCreateServer
configFileFile name of the Appweb configuration file (appweb.conf) that defines the web server configuration.
homeAdmin directory for the server. This overrides the value in the config file.
documentsDefault directory for web documents to serve. This overrides the value in the config file.
ipIP address to listen on. This overrides the value specified in the config file.
portPort address to listen on. This overrides the value specified in the config file.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
MaServer, maAddEndpoint, maCreateServer, maParseConfig, maRunSimpleWebServer, maRunWebServer, maSetServerAddress, maSetServerHome, maValidateServer
MaServer * maCreateServer (MaAppweb *appweb, cchar *name)

Create a MaServer object.

Description:
Create new MaServer object. This routine creates a bare MaServer object, loads any required static modules and performs minimal configuration. To use the server object created, more configuration will be required before starting Http services. If you want a one-line embedding of Appweb, use maRunWebServer or maRunSimpleWebServer
Parameters:
appwebHttp object returned from maCreateAppweb
nameName of the web server. This name is used as the initial server name.
Returns:
MaServer A newly created MaServer object. Use mprFree to free and release.
See Also:
MaServer, maAddEndpoint, maConfigureServer, maParseConfig, maRunSimpleWebServer, maRunWebServer, maSetServerAddress, maSetServerHome, maValidateServer
int maRunSimpleWebServer (cchar *ip, int port, cchar *home, cchar *documents)

Create and run a simple web server listening on a single IP address.

Description:
Create a simple web server without using a configuration file. The server is created to listen on the specified IP address and port. This routine provides a one-line embedding of Appweb. If you want to use a config file, try the maRunWebServer instead.
Parameters:
ipIP address on which to listen. Set to "0.0.0.0" to listen on all interfaces.
portPort number to listen to.
homeHome directory for the web server.
documentsDirectory containing the documents to serve.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
MaServer, maAddEndpoint, maConfigureServer, maCreateServer, maParseConfig, maRunWebServer, maSetServerAddress, maSetServerHome, maValidateServer
int maRunWebServer (cchar *configFile)

Create and run a web server based on a configuration file.

Description:
Create a web server configuration based on the supplied config file. This routine provides a one-line embedding of Appweb. If you don't want to use a config file, try the maRunSimpleWebServer instead.
Parameters:
configFileFile name of the Appweb configuration file (appweb.conf) that defines the web server configuration.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
MaServer, maAddEndpoint, maConfigureServer, maCreateServer, maParseConfig, maRunSimpleWebServer, maSetServerAddress, maSetServerHome, maValidateServer

MaState

MaState

Current configuration parse state.

API Stability:
Evolving.
See Also:
MaDirective, maAddDirective, maPopState, maPushState, maSetAccessLog, maStartAccessLogging, maStopAccessLogging
Fields:
HttpAuth *auth Quick alias for route->auth.
char *configDir Directory containing config file.
struct MaState *current Current state.
intenabled True if the current block is enabled.
MprFile *file Config file handle.
char *filename Config file name.
intflags Parsing flags.
HttpHost *host Current host.
char *key Current directive being parsed.
HttpLimits *limits Current limits (host->limits).
intlineNumber Current line number.
struct MaState *prev Previous (inherited) state.
HttpRoute *route Current route.
MaServer *server Current server.
struct MaState *top Top level state.

Functions

int maArchiveLog (cchar *path, int count, int maxSize)

Archive a log file.

Description:
The current log file is archived by appending ".1" to the log path name. If a "path.1" exists, it will be renamed first to "path.2" and so on up to "path.count".
Parameters:
pathCurrent log file name.
countNumber of archived log files to preserve.
maxSizeReserved.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
int maStartServer (MaServer *server)

Start a server.

Parameters:
serverObject created via maCreateServer
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
void maStopServer (MaServer *server)

Stop a server.

Parameters:
serverObject created via maCreateServer

Typedefs

typedef int( MaDirective)(MaState *state, cchar *key, cchar *value).

Directive callback function.

Description:
Directive callbacks are invoked to parse a directive. Directive callbacks are registered using maAddDirective
Parameters:
stateCurrent config parse state.
keyDirective key name.
valueDirective key value.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
See Also:
Http, maAddServer, maApplyChangedGroup, maApplyChangedUser, maCreateAppweb, maGetUserGroup, maLoadModule, maLookupServer, maMatchDir, maParseInit, maSetDefaultServer, maSetHttpGroup, maSetHttpUser, maStartAppweb, maStopAppweb