TinyMUSH 3.3
TinyMUSH Server
Loading...
Searching...
No Matches
Functions | Variables
conf.c File Reference

Configuration functions and defaults. More...

#include "config.h"
#include "constants.h"
#include "typedefs.h"
#include "macros.h"
#include "externs.h"
#include "prototypes.h"
#include <stdbool.h>
#include <ctype.h>
#include <fcntl.h>
#include <string.h>
#include <dlfcn.h>
#include <arpa/inet.h>
#include <sys/param.h>
#include <libgen.h>
#include <unistd.h>
Include dependency graph for conf.c:

Functions

void cf_init (void)
 Initialize mushconf to default values. More...
 
void cf_log (dbref player, const char *primary, const char *secondary, char *cmd, const char *format,...)
 Log a configuration error. More...
 
CF_Result cf_status_from_succfail (dbref player, char *cmd, int success, int failure)
 Return command status from succ and fail info. More...
 
CF_Result cf_const (int *vp __attribute__((unused)), char *str __attribute__((unused)), long extra __attribute__((unused)), dbref player, char *cmd)
 Read-only integer or boolean parameter. More...
 
CF_Result cf_int (int *vp, char *str, long extra, dbref player, char *cmd)
 Set integer parameter. More...
 
CF_Result cf_int_factor (int *vp, char *str, long extra, dbref player, char *cmd)
 Set integer parameter that will be used as a factor (ie. cannot be set to 0) More...
 
CF_Result cf_dbref (int *vp, char *str, long extra, dbref player, char *cmd)
 Set dbref parameter. More...
 
CF_Result cf_module (int *vp __attribute__((unused)), char *modname, long extra __attribute__((unused)), dbref player __attribute__((unused)), char *cmd __attribute__((unused)))
 Open a loadable module. Modules are initialized later in the startup. More...
 
CF_Result cf_bool (int *vp, char *str, long extra __attribute__((unused)), dbref player __attribute__((unused)), char *cmd __attribute__((unused)))
 Set boolean parameter. More...
 
CF_Result cf_option (int *vp, char *str, long extra, dbref player, char *cmd)
 Select one option from many choices. More...
 
CF_Result cf_string (int *vp, char *str, long extra, dbref player, char *cmd)
 Set string parameter. More...
 
CF_Result cf_alias (int *vp, char *str, long extra, dbref player, char *cmd)
 define a generic hash table alias. More...
 
CF_Result cf_infotext (int *vp __attribute__((unused)), char *str, long extra __attribute__((unused)), dbref player __attribute__((unused)), char *cmd __attribute__((unused)))
 Add an arbitrary field to INFO output. More...
 
CF_Result cf_divert_log (int *vp, char *str, long extra, dbref player, char *cmd)
 Redirect a log type. More...
 
CF_Result cf_modify_bits (int *vp, char *str, long extra, dbref player, char *cmd)
 set or clear bits in a flag word from a namelist. More...
 
bool modify_xfuncs (char *fn_name, int(*fn_ptr)(dbref), EXTFUNCS **xfuncs, bool negate)
 Helper function to change xfuncs. More...
 
CF_Result parse_ext_access (int *perms, EXTFUNCS **xperms, char *str, NAMETAB *ntab, dbref player, char *cmd)
 Parse an extended access list with module callouts. More...
 
CF_Result cf_set_flags (int *vp, char *str, long extra __attribute__((unused)), dbref player, char *cmd)
 Clear flag word and then set from a flags htab. More...
 
CF_Result cf_badname (int *vp __attribute__((unused)), char *str, long extra, dbref player __attribute__((unused)), char *cmd __attribute__((unused)))
 Disallow use of player name/alias. More...
 
in_addr_t sane_inet_addr (char *str)
 Replacement for inet_addr() More...
 
CF_Result cf_site (long **vp, char *str, long extra, dbref player, char *cmd)
 Update site information. More...
 
CF_Result helper_cf_cf_access (CONF *tp, dbref player, int *vp, char *ap, char *cmd, long extra)
 Set write or read access on config directives kludge. More...
 
CF_Result cf_cf_access (int *vp, char *str, long extra, dbref player, char *cmd)
 Set configuration parameter access. More...
 
CF_Result add_helpfile (dbref player, char *confcmd, char *str, bool is_raw)
 Add a help/news-style file. Only valid during startup. More...
 
CF_Result cf_helpfile (int *vp __attribute__((unused)), char *str, long extra __attribute__((unused)), dbref player, char *cmd)
 Add an helpfile. More...
 
CF_Result cf_raw_helpfile (int *vp __attribute__((unused)), char *str, long extra __attribute__((unused)), dbref player, char *cmd)
 Add a raw helpfile. More...
 
CF_Result cf_include (int *vp __attribute__((unused)), char *str, long extra __attribute__((unused)), dbref player, char *cmd)
 Read another config file. Only valid during startup. More...
 
CF_Result helper_cf_set (char *cp, char *ap, dbref player, CONF *tp)
 Set config parameter. More...
 
CF_Result cf_set (char *cp, char *ap, dbref player)
 Set a config directive. More...
 
void do_admin (dbref player, dbref cause __attribute__((unused)), int extra __attribute__((unused)), char *kw, char *value)
 Command handler to set config params at runtime. More...
 
CF_Result cf_read (char *fn)
 Read in config parameters from named file. More...
 
void list_cf_access (dbref player)
 List write or read access to config directives. More...
 
void list_cf_read_access (dbref player)
 List read access to config directives. More...
 
void cf_verify (void)
 Walk all configuration tables and validate any dbref values. More...
 
void helper_cf_display (dbref player, char *buff, char **bufc, CONF *tp)
 Helper function for cf_display. More...
 
void cf_display (dbref player, char *param_name, char *buff, char **bufc)
 Given a config parameter by name, return its value in some sane fashion. More...
 
void list_options (dbref player)
 List options to player. More...
 
void * dlopen_format (const char *filename,...)
 Wrapper around lt_dlopen that can format filename. More...
 
void * dlsym_format (void *place, const char *symbol,...)
 Wrapper for lt_dlsym that format symbol string. More...
 

Variables

CONFDATA mushconf
 
STATEDATA mushstate
 
int(* cf_interpreter )(int *, char *, long, dbref, char *)
 

Detailed Description

Configuration functions and defaults.

Author
TinyMUSH development team (https://github.com/TinyMUSH)
Version
3.3
Date
2020-12-25

Function Documentation

◆ add_helpfile()

CF_Result add_helpfile ( dbref  player,
char *  confcmd,
char *  str,
bool  is_raw 
)

Add a help/news-style file. Only valid during startup.

Parameters
playerDbref of player
confcmdCommand
strFilename
is_rawRaw textfile?
Returns
CF_Result

Make a new string so we won't SEGV if given a constant string

Check if file exists in given and standard path

Rebuild Index

We may need to grow the helpfiles table, or create it.

Add or replace the path to the file.

Initialize the associated hashtable.

◆ cf_alias()

CF_Result cf_alias ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

define a generic hash table alias.

Parameters
vp
str
extra
player
cmd
Returns
CF_Result

hashadd won't copy it, so we do that here

◆ cf_badname()

CF_Result cf_badname ( int *vp   __attribute__(unused),
char *  str,
long  extra,
dbref player   __attribute__(unused),
char *cmd   __attribute__(unused) 
)

Disallow use of player name/alias.

Parameters
vpVariable buffer
strString Buffer
extraName Table
playerDBref of player
cmdCommand
Returns
CF_Result

◆ cf_bool()

CF_Result cf_bool ( int *  vp,
char *  str,
long extra   __attribute__(unused),
dbref player   __attribute__(unused),
char *cmd   __attribute__(unused) 
)

Set boolean parameter.

Parameters
vpBoolean value
strString buffer
extraNot used
playerDBref of the player
cmdCommand
Returns
CF_Result

◆ cf_cf_access()

CF_Result cf_cf_access ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

Set configuration parameter access.

Parameters
vpVariable buffer
strString Buffer
extraName Table
playerDBref of player
cmdCommand
Returns
CF_Result

◆ cf_const()

CF_Result cf_const ( int *vp   __attribute__(unused),
char *str   __attribute__(unused),
long extra   __attribute__(unused),
dbref  player,
char *  cmd 
)

Read-only integer or boolean parameter.

Parameters
vpNot used
strNot used
extraNot used
playerDbref of the player
cmdCommand
Returns
CF_Result

Fail on any attempt to change the value

◆ cf_dbref()

CF_Result cf_dbref ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

Set dbref parameter.

Parameters
vpNumeric value
strString buffer
extraMaximum limit
playerDBref of the player
cmdCommand
Returns
CF_Result

No consistency check on initialization.

Otherwise we have to validate this. If 'extra' is non-zero, the dbref is allowed to be NOTHING.

◆ cf_display()

void cf_display ( dbref  player,
char *  param_name,
char *  buff,
char **  bufc 
)

Given a config parameter by name, return its value in some sane fashion.

Parameters
playerDBref of player
param_nameParameter name
buffOutput buffer
bufcOutput buffer tracker

◆ cf_divert_log()

CF_Result cf_divert_log ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

Redirect a log type.

Parameters
vpVariable buffer
strString Buffer
extraName Table
playerDBref of player
cmdCommand
Returns
CF_Result

Two args, two args only

Find the log.

This should never happen!

We shouldn't have a file open already.

Check to make sure that we don't have this filename open already.

We don't have this filename yet. Open the logfile.

Indicate that this is being diverted.

◆ cf_helpfile()

CF_Result cf_helpfile ( int *vp   __attribute__(unused),
char *  str,
long extra   __attribute__(unused),
dbref  player,
char *  cmd 
)

Add an helpfile.

Parameters
playerDbref of player
confcmdCommand
strFilename
is_rawRaw textfile?
Returns
CF_Result

◆ cf_include()

CF_Result cf_include ( int *vp   __attribute__(unused),
char *  str,
long extra   __attribute__(unused),
dbref  player,
char *  cmd 
)

Read another config file. Only valid during startup.

Parameters
vpVariable buffer
strString buffer
extraExtra data
playerDBref of player
cmdCommand
Returns
CF_Result
Todo:
TODO Add stuff to fill

**cfiletab; // Array of config files cfiletab_size; // Size of the table storing config pointers

Not a comment line. Strip off the NL and any characters following it. Then, split the line into the command and argument portions (separated by a space). Also, trim off the trailing comment, if any (delimited by #)

strip

strip spaces

skip over command

trim command

skip spaces

find comment

zap comment, but only if it's not sitting between whitespace and a digit, which traps a case like 'master_room #2'

zap trailing spaces

◆ cf_infotext()

CF_Result cf_infotext ( int *vp   __attribute__(unused),
char *  str,
long extra   __attribute__(unused),
dbref player   __attribute__(unused),
char *cmd   __attribute__(unused) 
)

Add an arbitrary field to INFO output.

Parameters
vpVariable buffer
strString Buffer
extraNot used
playerDBref of player
cmdCommand
Returns
CF_Result

Empty loop

Otherwise we're setting. Replace if we had a previous value.

No previous value. Add a node.

◆ cf_init()

void cf_init ( void  )

Initialize mushconf to default values.

We can make theses NULL because we are going to define default values later if they are still NULL.

< ??? Running SC on a non-SC DB may cause problems

◆ cf_int()

CF_Result cf_int ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

Set integer parameter.

Parameters
vpNumeric value
strString buffer
extraMaximum limit
playerDBref of the player
cmdCommand
Returns
CF_Result

Copy the numeric value to the parameter

◆ cf_int_factor()

CF_Result cf_int_factor ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

Set integer parameter that will be used as a factor (ie. cannot be set to 0)

Parameters
vpNumeric value
strString buffer
extraMaximum limit
playerDBref of the player
cmdCommand
Returns
CF_Result

◆ cf_log()

void cf_log ( dbref  player,
const char *  primary,
const char *  secondary,
char *  cmd,
const char *  format,
  ... 
)

Log a configuration error.

Parameters
playerDBref of player
primaryPrimary error type
secondarySecondary error type
cmdCommand
formatFormat string
...Variable parameter for format

◆ cf_modify_bits()

CF_Result cf_modify_bits ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

set or clear bits in a flag word from a namelist.

Parameters
vpVariable buffer
strString Buffer
extraName Table
playerDBref of player
cmdCommand
Returns
CF_Result

Walk through the tokens

Check for negation

Set or clear the appropriate bit

Get the next token

◆ cf_module()

CF_Result cf_module ( int *vp   __attribute__(unused),
char *  modname,
long extra   __attribute__(unused),
dbref player   __attribute__(unused),
char *cmd   __attribute__(unused) 
)

Open a loadable module. Modules are initialized later in the startup.

Parameters
vp
modname
extra
player
cmd
Returns
int

Look up our symbols now, and cache the pointers. They're not going to change from here on out.

◆ cf_option()

CF_Result cf_option ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

Select one option from many choices.

Parameters
vpIndex of the option
strString buffer
extraName Table
playerDBref of the player
cmdCommand
Returns
int -1 on Failure, 0 on Success

◆ cf_raw_helpfile()

CF_Result cf_raw_helpfile ( int *vp   __attribute__(unused),
char *  str,
long extra   __attribute__(unused),
dbref  player,
char *  cmd 
)

Add a raw helpfile.

Parameters
playerDbref of player
confcmdCommand
strFilename
is_rawRaw textfile?
Returns
CF_Result

◆ cf_read()

CF_Result cf_read ( char *  fn)

Read in config parameters from named file.

Parameters
fnFilename
Returns
int

◆ cf_set()

CF_Result cf_set ( char *  cp,
char *  ap,
dbref  player 
)

Set a config directive.

Parameters
cp
ap
player
Returns
CF_Result

Search the config parameter table for the command. If we find it, call the handler to parse the argument. Make sure that if we're standalone, the paramaters we need to load module flatfiles are loaded

Config directive not found. Complain about it.

◆ cf_set_flags()

CF_Result cf_set_flags ( int *  vp,
char *  str,
long extra   __attribute__(unused),
dbref  player,
char *  cmd 
)

Clear flag word and then set from a flags htab.

Parameters
vpVariable buffer
strString Buffer
extraName Table
playerDBref of player
cmdCommand
Returns
CF_Result

Walk through the tokens

Set the appropriate bit

Get the next token

◆ cf_site()

CF_Result cf_site ( long **  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

Update site information.

Parameters
vpVariable buffer
strString Buffer
extraName Table
playerDBref of player
cmdCommand
Returns
CF_Result

Standard IP range and netmask notation.

RFC 1517, 1518, 1519, 1520: CIDR IP prefix notation

can't shift by 32

Parse the access entry and allocate space for it

Initialize the site entry

Link in the entry. Link it at the start if not initializing, at the end if initializing. This is so that entries in the config file are processed as you would think they would be, while entries made while running are processed first.

◆ cf_status_from_succfail()

CF_Result cf_status_from_succfail ( dbref  player,
char *  cmd,
int  success,
int  failure 
)

Return command status from succ and fail info.

Parameters
playerDBref of player
cmdCommand
successDit it success?
failureDid it fail?
Returns
CF_Result

If any successes, return SUCCESS(0) if no failures or PARTIAL_SUCCESS(1) if any failures.

No successes. If no failures indicate nothing done. Always return FAILURE(-1)

◆ cf_string()

CF_Result cf_string ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

Set string parameter.

Parameters
vpVariable type
strString buffer
extraMaximum string length
playerDBref of player
cmdCommand
Returns
CF_Result

Make a copy of the string if it is not too big

◆ cf_verify()

void cf_verify ( void  )

Walk all configuration tables and validate any dbref values.

◆ dlopen_format()

void * dlopen_format ( const char *  filename,
  ... 
)

Wrapper around lt_dlopen that can format filename.

Parameters
filenamefilename to load (or construct if a format string is given)
...arguments for the format string
Returns
void* Handler for the module.

◆ dlsym_format()

void * dlsym_format ( void *  place,
const char *  symbol,
  ... 
)

Wrapper for lt_dlsym that format symbol string.

Parameters
placeModule handler
symbolSymbol to load (or construct if a format string is given)
...arguments for the format string
Returns
void* Return the address in the module handle, where the symbol is loaded

◆ do_admin()

void do_admin ( dbref  player,
dbref cause   __attribute__(unused),
int extra   __attribute__(unused),
char *  kw,
char *  value 
)

Command handler to set config params at runtime.

Parameters
playerDBref of player
causeDBref of cause
extraExtra data
kwKeyword
valueValue

◆ helper_cf_cf_access()

CF_Result helper_cf_cf_access ( CONF tp,
dbref  player,
int *  vp,
char *  ap,
char *  cmd,
long  extra 
)

Set write or read access on config directives kludge.

this cf handler uses vp as an extra extra field since the first extra field is taken up with the access nametab.

Parameters
tpConfig Parameter
playerDBrief of player
vpExtra field
apString buffer
cmdCommand
extraExtra field
Returns
CF_Result

Cannot modify parameters set STATIC

◆ helper_cf_display()

void helper_cf_display ( dbref  player,
char *  buff,
char **  bufc,
CONF tp 
)

Helper function for cf_display.

Parameters
playerDBref of player
buffOutput buffer
bufcOutput buffer tracker
tpConfig parameter

◆ helper_cf_set()

CF_Result helper_cf_set ( char *  cp,
char *  ap,
dbref  player,
CONF tp 
)

Set config parameter.

Parameters
cp
ap
player
tp
Returns
int

◆ list_cf_access()

void list_cf_access ( dbref  player)

List write or read access to config directives.

Parameters
playerDBref of player

◆ list_cf_read_access()

void list_cf_read_access ( dbref  player)

List read access to config directives.

Parameters
playerDBref of player

◆ list_options()

void list_options ( dbref  player)

List options to player.

Parameters
playerDBref of player

◆ modify_xfuncs()

bool modify_xfuncs ( char *  fn_name,
int(*)(dbref)  fn_ptr,
EXTFUNCS **  xfuncs,
bool  negate 
)

Helper function to change xfuncs.

Parameters
fn_nameFunction name
fn_ptrFunction pointer
xfuncsExternal functions
negatetrue: remove, false add:
Returns
bool

If we're negating, just remove it from the list of functions.

Have we encountered this function before?

If not, we need to allocate it.

Add it to the ones we know about.

Do we have an existing list of functions? If not, this is easy.

See if we have an empty slot to insert into.

Guess not. Tack it onto the end.

◆ parse_ext_access()

CF_Result parse_ext_access ( int *  perms,
EXTFUNCS **  xperms,
char *  str,
NAMETAB ntab,
dbref  player,
char *  cmd 
)

Parse an extended access list with module callouts.

Parameters
permsPermissions
xpermsExtendes permissions
strString buffer
ntabName Table
playerDBref of player
cmdCommand
Returns
CF_Result

Walk through the tokens

Check for negation

Set or clear the appropriate bit

Is this a module callout?

Split it apart, see if we have anything.

Get the next token

◆ sane_inet_addr()

in_addr_t sane_inet_addr ( char *  str)

Replacement for inet_addr()

inet_addr() does not necessarily do reasonable checking for sane syntax. On certain operating systems, if passed less than four octets, it will cause a segmentation violation. This is unfriendly. We take steps here to deal with it.

Parameters
strIP Address
Returns
in_addr_t