APPWEB API

Extensions

MaState Current configuration parse state.

Functions

voidmaAddDirective(cchar *directive, MaDirective proc)
 Define a new appweb configuration file directive.
intmaConfigureServer(cchar *configFile, cchar *home, cchar *documents, cchar *ip, int port)
 Configure a web server.
char *maGetNextArg(char *s, char **tok)
 Get the argument in a directive.
intmaLoadModule(cchar *name, cchar *libname)
 Load an appweb module.
intmaLoadModules(void)
 Load default modules.
intmaParseConfig(cchar *path)
 Parse an Appweb configuration file.
intmaParseFile(MaState *state, cchar *path)
 Parse a configuration file.
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.
boolmaTokenize(MaState *state, cchar *str, cchar *fmt, ...)
 Tokenize a string based on route data.

Typedefs

MaDirectiveAppweb configuration file directive parsing callback function.

Defines

#defineMA_PARSE_NON_SERVER   0x1
 Command file being parsed by a utility program.
#defineMA_UNLOAD_TIMEOUT   "5mins"
 Default module inactivity timeout.

MaState

MaState

Current configuration parse state.

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

Define a new appweb configuration file 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:
directiveDirective name.
procDirective callback procedure of the type MaDirective
API Stability:
Evolving.
See Also:
MaDirective, MaState, maPopState, maPushState, maTokenize
int maConfigureServer (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:
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.
API Stability:
Evolving.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maPushState, maTokenize
char * * maGetNextArg (char *s, char **tok)

Get the argument in a directive.

Description:
Break into arguments. Args may be quoted. An outer quoting of the entire arg is removed.
Parameters:
sString to examine.
tokNext token reference.
Returns:
Reference to the next token. (Not allocate.
API Stability:
Evolving.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maPushState, maTokenize
int maLoadModule (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:
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.
API Stability:
Evolving.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maPushState, maTokenize
int maLoadModules (void )

Load default modules.

Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
API Stability:
Prototype.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maPushState, maTokenize
int maParseConfig (cchar *path)

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:
pathConfiguration file pathname.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
API Stability:
Evolving.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maPushState, maTokenize
int maParseFile (MaState *state, cchar *path)

Parse a configuration file.

Parameters:
stateCurrent state level object.
pathFilename to parse.
Returns:
Zero if successful, otherwise a negative Mpr error code. See the Appweb log for diagnostics.
API Stability:
Prototype.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maPushState, maTokenize
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.
API Stability:
Evolving.
See Also:
MaDirective, MaState, maAddDirective, maPushState, maTokenize
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.
API Stability:
Evolving.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maTokenize
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.
API Stability:
Evolving.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maPushState, maTokenize
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.
API Stability:
Evolving.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maPushState, maTokenize
bool maTokenize (MaState *state, cchar *str, cchar *fmt, ...)

Tokenize a string based on route data.

Description:
This is a utility routine to parse a string into tokens given a format specifier. Mandatory tokens can be specified with "%" format specifier. Optional tokens are specified with "?" format. Values wrapped in quotes will have the outermost quotes trimmed.
Parameters:
stateCurrent config parsing state.
strString to expand.
fmtFormat string specifier Supported tokens:
  • B - Boolean. Parses: on/off, true/false, yes/no.
  • N - Number. Parses numbers in base 10.
  • S - String. Removes quotes.
  • P - Path string. Removes quotes and expands ${PathVars}. Resolved relative to host->dir (ServerRoot).
  • W - Parse words into a list
  • %! - Optional negate. Set value to HTTP_ROUTE_NOT present, otherwise zero.
Returns:
True if the string can be successfully parsed.
API Stability:
Evolving.
See Also:
MaDirective, MaState, maAddDirective, maPopState, maPushState

Functions

Typedefs

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

Appweb configuration file directive parsing 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.
API Stability:
Evolving.
See Also:
MaState, maAddDirective, maPopState, maPushState, maTokenize

© Embedthis Software. All rights reserved.