settings.c File Reference

Configuration settings. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <byteswap.h>
#include <errno.h>
#include <assert.h>
#include <gpxe/in.h>
#include <gpxe/vsprintf.h>
#include <gpxe/dhcp.h>
#include <gpxe/uuid.h>
#include <gpxe/uri.h>
#include <gpxe/settings.h>

Go to the source code of this file.

Data Structures

struct  generic_setting
 A generic setting. More...

Defines

#define settings_root   generic_settings_root.settings
 Root settings block.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static void * generic_setting_name (struct generic_setting *generic)
 Get generic setting name.
static void * generic_setting_data (struct generic_setting *generic)
 Get generic setting data.
static struct generic_settingfind_generic_setting (struct generic_settings *generics, struct setting *setting)
 Find generic setting.
int generic_settings_store (struct settings *settings, struct setting *setting, const void *data, size_t len)
 Store value of generic setting.
int generic_settings_fetch (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of generic setting.
void generic_settings_clear (struct settings *settings)
 Clear generic settings block.
static struct settingsfind_child_settings (struct settings *parent, const char *name)
 Find child named settings block.
static struct settingsautovivify_child_settings (struct settings *parent, const char *name)
 Find or create child named settings block.
static const char * settings_name (struct settings *settings)
 Return settings block name (for debug only).
static struct settingsparse_settings_name (const char *name, struct settings *(*get_child)(struct settings *, const char *))
 Parse settings block name.
struct settingsfind_settings (const char *name)
 Find named settings block.
static int apply_settings (void)
 Apply all settings.
static void reprioritise_settings (struct settings *settings)
 Reprioritise settings.
int register_settings (struct settings *settings, struct settings *parent)
 Register settings block.
void unregister_settings (struct settings *settings)
 Unregister settings block.
int store_setting (struct settings *settings, struct setting *setting, const void *data, size_t len)
 Store value of setting.
int fetch_setting (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of setting.
int fetch_setting_len (struct settings *settings, struct setting *setting)
 Fetch length of setting.
int fetch_string_setting (struct settings *settings, struct setting *setting, char *data, size_t len)
 Fetch value of string setting.
int fetch_string_setting_copy (struct settings *settings, struct setting *setting, char **data)
 Fetch value of string setting.
int fetch_ipv4_setting (struct settings *settings, struct setting *setting, struct in_addr *inp)
 Fetch value of IPv4 address setting.
int fetch_int_setting (struct settings *settings, struct setting *setting, long *value)
 Fetch value of signed integer setting.
int fetch_uint_setting (struct settings *settings, struct setting *setting, unsigned long *value)
 Fetch value of unsigned integer setting.
long fetch_intz_setting (struct settings *settings, struct setting *setting)
 Fetch value of signed integer setting, or zero.
unsigned long fetch_uintz_setting (struct settings *settings, struct setting *setting)
 Fetch value of unsigned integer setting, or zero.
int fetch_uuid_setting (struct settings *settings, struct setting *setting, union uuid *uuid)
 Fetch value of UUID setting.
void clear_settings (struct settings *settings)
 Clear settings block.
int setting_cmp (struct setting *a, struct setting *b)
 Compare two settings.
int storef_setting (struct settings *settings, struct setting *setting, const char *value)
 Store value of typed setting.
static struct settingfind_setting (const char *name)
 Find named setting.
static unsigned int parse_setting_tag (const char *name)
 Parse setting name as tag number.
static struct setting_typefind_setting_type (const char *name)
 Find setting type.
static int parse_setting_name (const char *name, struct settings *(*get_child)(struct settings *, const char *), struct settings **settings, struct setting *setting, char *tmp_name)
 Parse setting name.
int storef_named_setting (const char *name, const char *value)
 Parse and store value of named setting.
int fetchf_named_setting (const char *name, char *buf, size_t len)
 Fetch and format value of named setting.
static int storef_string (struct settings *settings, struct setting *setting, const char *value)
 Parse and store value of string setting.
static int fetchf_string (struct settings *settings, struct setting *setting, char *buf, size_t len)
 Fetch and format value of string setting.
static int storef_uristring (struct settings *settings, struct setting *setting, const char *value)
 Parse and store value of URI-encoded string setting.
static int fetchf_uristring (struct settings *settings, struct setting *setting, char *buf, size_t len)
 Fetch and format value of URI-encoded string setting.
static int storef_ipv4 (struct settings *settings, struct setting *setting, const char *value)
 Parse and store value of IPv4 address setting.
static int fetchf_ipv4 (struct settings *settings, struct setting *setting, char *buf, size_t len)
 Fetch and format value of IPv4 address setting.
static int storef_int (struct settings *settings, struct setting *setting, const char *value, unsigned int size)
 Parse and store value of integer setting.
static int storef_int8 (struct settings *settings, struct setting *setting, const char *value)
 Parse and store value of 8-bit integer setting.
static int storef_int16 (struct settings *settings, struct setting *setting, const char *value)
 Parse and store value of 16-bit integer setting.
static int storef_int32 (struct settings *settings, struct setting *setting, const char *value)
 Parse and store value of 32-bit integer setting.
static int fetchf_int (struct settings *settings, struct setting *setting, char *buf, size_t len)
 Fetch and format value of signed integer setting.
static int fetchf_uint (struct settings *settings, struct setting *setting, char *buf, size_t len)
 Fetch and format value of unsigned integer setting.
static int storef_hex (struct settings *settings, struct setting *setting, const char *value)
 Parse and store value of hex string setting.
static int fetchf_hex (struct settings *settings, struct setting *setting, char *buf, size_t len)
 Fetch and format value of hex string setting.
static int storef_uuid (struct settings *settings __unused, struct setting *setting __unused, const char *value __unused)
 Parse and store value of UUID setting.
static int fetchf_uuid (struct settings *settings, struct setting *setting, char *buf, size_t len)
 Fetch and format value of UUID setting.

Variables

struct settings_operations generic_settings_operations
 Generic settings operations.
struct generic_settings generic_settings_root
 Root generic settings block.
struct setting_type
setting_type_string 
__setting_type
 A string setting type.
struct setting hostname_setting __setting
 Hostname setting.


Detailed Description

Configuration settings.

Definition in file settings.c.


Define Documentation

#define settings_root   generic_settings_root.settings


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static void* generic_setting_name ( struct generic_setting generic  )  [inline, static]

Get generic setting name.

Parameters:
generic Generic setting
Return values:
name Generic setting name

Definition at line 70 of file settings.c.

Referenced by generic_settings_store().

00070                                                                               {
00071         return ( ( ( void * ) generic ) + sizeof ( *generic ) );
00072 }

static void* generic_setting_data ( struct generic_setting generic  )  [inline, static]

Get generic setting data.

Parameters:
generic Generic setting
Return values:
data Generic setting data

Definition at line 80 of file settings.c.

Referenced by generic_settings_fetch(), and generic_settings_store().

00080                                                                               {
00081         return ( ( ( void * ) generic ) + sizeof ( *generic ) +
00082                  generic->name_len );
00083 }

static struct generic_setting* find_generic_setting ( struct generic_settings generics,
struct setting setting 
) [static, read]

Find generic setting.

Parameters:
generics Generic settings block
setting Setting to find
Return values:
generic Generic setting, or NULL

Definition at line 93 of file settings.c.

References generic_setting::list, generic_settings::list, list_for_each_entry, NULL, and setting_cmp().

Referenced by generic_settings_fetch(), and generic_settings_store().

00094                                                  {
00095         struct generic_setting *generic;
00096 
00097         list_for_each_entry ( generic, &generics->list, list ) {
00098                 if ( setting_cmp ( &generic->setting, setting ) == 0 )
00099                         return generic;
00100         }
00101         return NULL;
00102 }

int generic_settings_store ( struct settings settings,
struct setting setting,
const void *  data,
size_t  len 
)

Store value of generic setting.

Parameters:
settings Settings block
setting Setting to store
data Setting data, or NULL to clear setting
len Length of setting data
Return values:
rc Return status code

Definition at line 113 of file settings.c.

References container_of, ENOMEM, find_generic_setting(), free(), generic_setting_data(), generic_setting_name(), generic_settings::list, generic_setting::list, list_add, list_del, memcpy, setting::name, generic_setting::name_len, NULL, strlen(), and zalloc().

Referenced by netdev_store().

00115                                                             {
00116         struct generic_settings *generics =
00117                 container_of ( settings, struct generic_settings, settings );
00118         struct generic_setting *old;
00119         struct generic_setting *new = NULL;
00120         size_t name_len;
00121 
00122         /* Identify existing generic setting, if any */
00123         old = find_generic_setting ( generics, setting );
00124 
00125         /* Create new generic setting, if required */
00126         if ( len ) {
00127                 /* Allocate new generic setting */
00128                 name_len = ( strlen ( setting->name ) + 1 );
00129                 new = zalloc ( sizeof ( *new ) + name_len + len );
00130                 if ( ! new )
00131                         return -ENOMEM;
00132 
00133                 /* Populate new generic setting */
00134                 new->name_len = name_len;
00135                 new->data_len = len;
00136                 memcpy ( &new->setting, setting, sizeof ( new->setting ) );
00137                 new->setting.name = generic_setting_name ( new );
00138                 memcpy ( generic_setting_name ( new ),
00139                          setting->name, name_len );
00140                 memcpy ( generic_setting_data ( new ), data, len );
00141         }
00142 
00143         /* Delete existing generic setting, if any */
00144         if ( old ) {
00145                 list_del ( &old->list );
00146                 free ( old );
00147         }
00148 
00149         /* Add new setting to list, if any */
00150         if ( new )
00151                 list_add ( &new->list, &generics->list );
00152 
00153         return 0;
00154 }

int generic_settings_fetch ( struct settings settings,
struct setting setting,
void *  data,
size_t  len 
)

Fetch value of generic setting.

Parameters:
settings Settings block
setting Setting to fetch
data Buffer to fill with setting data
len Length of buffer
Return values:
len Length of setting data, or negative error

Definition at line 165 of file settings.c.

References container_of, ENOENT, find_generic_setting(), generic_setting_data(), and memcpy.

Referenced by netdev_fetch().

00167                                                       {
00168         struct generic_settings *generics =
00169                 container_of ( settings, struct generic_settings, settings );
00170         struct generic_setting *generic;
00171 
00172         /* Find generic setting */
00173         generic = find_generic_setting ( generics, setting );
00174         if ( ! generic )
00175                 return -ENOENT;
00176 
00177         /* Copy out generic setting data */
00178         if ( len > generic->data_len )
00179                 len = generic->data_len;
00180         memcpy ( data, generic_setting_data ( generic ), len );
00181         return generic->data_len;
00182 }

void generic_settings_clear ( struct settings settings  ) 

Clear generic settings block.

Parameters:
settings Settings block

Definition at line 189 of file settings.c.

References assert, container_of, free(), generic_setting::list, generic_settings::list, list_del, list_empty(), and list_for_each_entry_safe.

Referenced by netdev_clear().

00189                                                           {
00190         struct generic_settings *generics =
00191                 container_of ( settings, struct generic_settings, settings );
00192         struct generic_setting *generic;
00193         struct generic_setting *tmp;
00194 
00195         list_for_each_entry_safe ( generic, tmp, &generics->list, list ) {
00196                 list_del ( &generic->list );
00197                 free ( generic );
00198         }
00199         assert ( list_empty ( &generics->list ) );
00200 }

static struct settings* find_child_settings ( struct settings parent,
const char *  name 
) [static, read]

Find child named settings block.

Parameters:
parent Parent settings block
name Name within this parent
Return values:
settings Settings block, or NULL

Definition at line 240 of file settings.c.

References settings::children, list_for_each_entry, settings::name, NULL, and strcmp().

Referenced by autovivify_child_settings(), fetchf_named_setting(), find_settings(), and register_settings().

00241                                                                   {
00242         struct settings *settings;
00243 
00244         /* Treat empty name as meaning "this block" */
00245         if ( ! *name )
00246                 return parent;
00247 
00248         /* Look for child with matching name */
00249         list_for_each_entry ( settings, &parent->children, siblings ) {
00250                 if ( strcmp ( settings->name, name ) == 0 )
00251                         return settings;
00252         }
00253 
00254         return NULL;
00255 }

static struct settings* autovivify_child_settings ( struct settings parent,
const char *  name 
) [static, read]

Find or create child named settings block.

Parameters:
parent Parent settings block
name Name within this parent
Return values:
settings Settings block, or NULL

Definition at line 264 of file settings.c.

References DBGC, find_child_settings(), generic_settings_init(), memcpy, NULL, register_settings(), strlen(), and zalloc().

Referenced by storef_named_setting().

00265                                                                         {
00266         struct {
00267                 struct generic_settings generic;
00268                 char name[ strlen ( name ) + 1 /* NUL */ ];
00269         } *new_child;
00270         struct settings *settings;
00271 
00272         /* Return existing settings, if existent */
00273         if ( ( settings = find_child_settings ( parent, name ) ) != NULL )
00274                 return settings;
00275 
00276         /* Create new generic settings block */
00277         new_child = zalloc ( sizeof ( *new_child ) );
00278         if ( ! new_child ) {
00279                 DBGC ( parent, "Settings %p could not create child %s\n",
00280                        parent, name );
00281                 return NULL;
00282         }
00283         memcpy ( new_child->name, name, sizeof ( new_child->name ) );
00284         generic_settings_init ( &new_child->generic, NULL, new_child->name );
00285         settings = &new_child->generic.settings;
00286         register_settings ( settings, parent );
00287         return settings;
00288 }

static const char* settings_name ( struct settings settings  )  [static]

Return settings block name (for debug only).

Parameters:
settings Settings block
Return values:
name Settings block name

Definition at line 296 of file settings.c.

References memcpy, settings::name, settings::parent, and snprintf().

Referenced by config_exec(), parse_setting_name(), register_settings(), and unregister_settings().

00296                                                                 {
00297         static char buf[64];
00298         char tmp[ sizeof ( buf ) ];
00299         int count;
00300 
00301         for ( count = 0 ; settings ; settings = settings->parent ) {
00302                 memcpy ( tmp, buf, sizeof ( tmp ) );
00303                 snprintf ( buf, sizeof ( buf ), "%s%c%s", settings->name,
00304                            ( count++ ? '.' : '\0' ), tmp );
00305         }
00306         return ( buf + 1 );
00307 }

static struct settings* parse_settings_name ( const char *  name,
struct settings *(*)(struct settings *, const char *)  get_child 
) [static, read]

Parse settings block name.

Parameters:
name Name
get_child Function to find or create child settings block
Return values:
settings Settings block, or NULL

Definition at line 317 of file settings.c.

References last_opened_netdev(), memcpy, net_device::name, netdev, NULL, settings_root, strchr(), strcmp(), and strlen().

Referenced by find_settings(), and parse_setting_name().

00319                                                                            {
00320         struct settings *settings = &settings_root;
00321         char name_copy[ strlen ( name ) + 1 ];
00322         char *subname;
00323         char *remainder;
00324 
00325         /* Create modifiable copy of name */
00326         memcpy ( name_copy, name, sizeof ( name_copy ) );
00327         remainder = name_copy;
00328 
00329         /* Parse each name component in turn */
00330         while ( remainder ) {
00331                 struct net_device *netdev;
00332 
00333                 subname = remainder;
00334                 remainder = strchr ( subname, '.' );
00335                 if ( remainder )
00336                         *(remainder++) = '\0';
00337 
00338                 /* Special case "netX" root settings block */
00339                 if ( ( subname == name_copy ) && ! strcmp ( subname, "netX" ) &&
00340                      ( ( netdev = last_opened_netdev() ) != NULL ) )
00341                         settings = get_child ( settings, netdev->name );
00342                 else
00343                         settings = get_child ( settings, subname );
00344 
00345                 if ( ! settings )
00346                         break;
00347         }
00348 
00349         return settings;
00350 }

struct settings* find_settings ( const char *  name  )  [read]

Find named settings block.

Parameters:
name Name
Return values:
settings Settings block, or NULL

Definition at line 358 of file settings.c.

References find_child_settings(), and parse_settings_name().

Referenced by config_exec(), create_fakepxebsack(), and pxe_menu_boot().

00358                                                      {
00359 
00360         return parse_settings_name ( name, find_child_settings );
00361 }

static int apply_settings ( void   )  [static]

Apply all settings.

Return values:
rc Return status code

Definition at line 368 of file settings.c.

References settings_applicator::apply, DBG, for_each_table_entry, SETTINGS_APPLICATORS, and strerror().

Referenced by register_settings(), store_setting(), and unregister_settings().

00368                                    {
00369         struct settings_applicator *applicator;
00370         int rc;
00371 
00372         /* Call all settings applicators */
00373         for_each_table_entry ( applicator, SETTINGS_APPLICATORS ) {
00374                 if ( ( rc = applicator->apply() ) != 0 ) {
00375                         DBG ( "Could not apply settings using applicator "
00376                               "%p: %s\n", applicator, strerror ( rc ) );
00377                         return rc;
00378                 }
00379         }
00380 
00381         return 0;
00382 }

static void reprioritise_settings ( struct settings settings  )  [static]

Reprioritise settings.

Parameters:
settings Settings block
Reorders the settings block amongst its siblings according to its priority.

Definition at line 392 of file settings.c.

References settings::children, fetch_intz_setting(), list_add_tail, list_del, list_for_each_entry, settings::parent, and settings::siblings.

Referenced by register_settings(), and store_setting().

00392                                                                 {
00393         struct settings *parent = settings->parent;
00394         long priority;
00395         struct settings *tmp;
00396         long tmp_priority;
00397 
00398         /* Stop when we reach the top of the tree */
00399         if ( ! parent )
00400                 return;
00401 
00402         /* Read priority, if present */
00403         priority = fetch_intz_setting ( settings, &priority_setting );
00404 
00405         /* Remove from siblings list */
00406         list_del ( &settings->siblings );
00407 
00408         /* Reinsert after any existing blocks which have a higher priority */
00409         list_for_each_entry ( tmp, &parent->children, siblings ) {
00410                 tmp_priority = fetch_intz_setting ( tmp, &priority_setting );
00411                 if ( priority > tmp_priority )
00412                         break;
00413         }
00414         list_add_tail ( &settings->siblings, &tmp->siblings );
00415 
00416         /* Recurse up the tree */
00417         reprioritise_settings ( parent );
00418 }

int register_settings ( struct settings settings,
struct settings parent 
)

Register settings block.

Parameters:
settings Settings block
parent Parent settings block, or NULL
Return values:
rc Return status code

Definition at line 427 of file settings.c.

References apply_settings(), assert, settings::children, DBGC, find_child_settings(), list_add_tail, settings::name, NULL, settings::parent, ref_get(), settings::refcnt, reprioritise_settings(), settings_name(), settings_root, settings::siblings, and unregister_settings().

Referenced by autovivify_child_settings(), dhcp_proxy_rx(), dhcp_pxebs_rx(), dhcp_request_rx(), phantom_probe(), register_netdev(), register_nvo(), smbios_init(), and store_cached_dhcpack().

00427                                                                              {
00428         struct settings *old_settings;
00429 
00430         /* NULL parent => add to settings root */
00431         assert ( settings != NULL );
00432         if ( parent == NULL )
00433                 parent = &settings_root;
00434 
00435         /* Remove any existing settings with the same name */
00436         if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
00437                 unregister_settings ( old_settings );
00438 
00439         /* Add to list of settings */
00440         ref_get ( settings->refcnt );
00441         ref_get ( parent->refcnt );
00442         settings->parent = parent;
00443         list_add_tail ( &settings->siblings, &parent->children );
00444         DBGC ( settings, "Settings %p (\"%s\") registered\n",
00445                settings, settings_name ( settings ) );
00446 
00447         /* Fix up settings priority */
00448         reprioritise_settings ( settings );
00449 
00450         /* Apply potentially-updated settings */
00451         apply_settings();
00452 
00453         return 0;
00454 }

void unregister_settings ( struct settings settings  ) 

Unregister settings block.

Parameters:
settings Settings block

Definition at line 461 of file settings.c.

References apply_settings(), DBGC, list_del, NULL, settings::parent, ref_put(), settings::refcnt, settings_name(), and settings::siblings.

Referenced by phantom_probe(), phantom_remove(), register_settings(), unregister_netdev(), and unregister_nvo().

00461                                                        {
00462 
00463         DBGC ( settings, "Settings %p (\"%s\") unregistered\n",
00464                settings, settings_name ( settings ) );
00465 
00466         /* Remove from list of settings */
00467         ref_put ( settings->refcnt );
00468         ref_put ( settings->parent->refcnt );
00469         settings->parent = NULL;
00470         list_del ( &settings->siblings );
00471 
00472         /* Apply potentially-updated settings */
00473         apply_settings();
00474 }

int store_setting ( struct settings settings,
struct setting setting,
const void *  data,
size_t  len 
)

Store value of setting.

Parameters:
settings Settings block, or NULL
setting Setting to store
data Setting data, or NULL to clear setting
len Length of setting data
Return values:
rc Return status code

Definition at line 492 of file settings.c.

References apply_settings(), ENOTSUP, settings::op, settings::parent, reprioritise_settings(), setting_cmp(), settings_root, and settings_operations::store.

Referenced by delete_setting(), login_ui(), storef_hex(), storef_int(), storef_ipv4(), storef_string(), and storef_uristring().

00493                                                    {
00494         int rc;
00495 
00496         /* NULL settings implies storing into the global settings root */
00497         if ( ! settings )
00498                 settings = &settings_root;
00499 
00500         /* Sanity check */
00501         if ( ! settings->op->store )
00502                 return -ENOTSUP;
00503 
00504         /* Store setting */
00505         if ( ( rc = settings->op->store ( settings, setting,
00506                                           data, len ) ) != 0 )
00507                 return rc;
00508 
00509         /* Reprioritise settings if necessary */
00510         if ( setting_cmp ( setting, &priority_setting ) == 0 )
00511                 reprioritise_settings ( settings );
00512 
00513         /* If these settings are registered, apply potentially-updated
00514          * settings
00515          */
00516         for ( ; settings ; settings = settings->parent ) {
00517                 if ( settings == &settings_root ) {
00518                         if ( ( rc = apply_settings() ) != 0 )
00519                                 return rc;
00520                         break;
00521                 }
00522         }
00523 
00524         return 0;
00525 }

int fetch_setting ( struct settings settings,
struct setting setting,
void *  data,
size_t  len 
)

Fetch value of setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
data Buffer to fill with setting data
len Length of buffer
Return values:
len Length of setting data, or negative error
The actual length of the setting will be returned even if the buffer was too small.

Definition at line 539 of file settings.c.

References settings::children, ENOENT, ENOTSUP, settings_operations::fetch, fetch_setting(), list_for_each_entry, memset(), settings::op, and settings_root.

Referenced by copy_encap_settings(), dhcp_create_request(), fetch_int_setting(), fetch_ipv4_setting(), fetch_setting(), fetch_setting_len(), fetch_string_setting(), fetch_uuid_setting(), fetchf_hex(), fetchf_uristring(), pxe_menu_parse(), start_pxebs(), trivial_change_key(), and trivial_init().

00540                                              {
00541         struct settings *child;
00542         int ret;
00543 
00544         /* Avoid returning uninitialised data on error */
00545         memset ( data, 0, len );
00546 
00547         /* NULL settings implies starting at the global settings root */
00548         if ( ! settings )
00549                 settings = &settings_root;
00550 
00551         /* Sanity check */
00552         if ( ! settings->op->fetch )
00553                 return -ENOTSUP;
00554 
00555         /* Try this block first */
00556         if ( ( ret = settings->op->fetch ( settings, setting,
00557                                            data, len ) ) >= 0 )
00558                 return ret;
00559 
00560         /* Recurse into each child block in turn */
00561         list_for_each_entry ( child, &settings->children, siblings ) {
00562                 if ( ( ret = fetch_setting ( child, setting,
00563                                              data, len ) ) >= 0 )
00564                         return ret;
00565         }
00566 
00567         return -ENOENT;
00568 }

int fetch_setting_len ( struct settings settings,
struct setting setting 
)

Fetch length of setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
Return values:
len Length of setting data, or negative error
This function can also be used as an existence check for the setting.

Definition at line 580 of file settings.c.

References fetch_setting(), and NULL.

Referenced by apply_iscsi_string_setting(), copy_encap_settings(), dhcp_create_request(), fetch_string_setting_copy(), fetchf_hex(), ibft_set_string_option(), pxe_menu_parse(), setting_exists(), and start_pxebs().

00580                                                                              {
00581         return fetch_setting ( settings, setting, NULL, 0 );
00582 }

int fetch_string_setting ( struct settings settings,
struct setting setting,
char *  data,
size_t  len 
)

Fetch value of string setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
data Buffer to fill with setting string data
len Length of buffer
Return values:
len Length of string setting, or negative error
The resulting string is guaranteed to be correctly NUL-terminated. The returned length will be the length of the underlying setting data.

Definition at line 597 of file settings.c.

References fetch_setting(), and memset().

Referenced by apply_iscsi_string_setting(), fetch_string_setting_copy(), fetchf_string(), fetchf_uristring(), ib_sma_node_desc(), ibft_set_string_option(), login_ui(), net80211_autoassociate(), net80211_check_settings_update(), netboot(), pxe_menu_boot(), and wpa_psk_start().

00598                                                     {
00599         memset ( data, 0, len );
00600         return fetch_setting ( settings, setting, data,
00601                                ( ( len > 0 ) ? ( len - 1 ) : 0 ) );
00602 }

int fetch_string_setting_copy ( struct settings settings,
struct setting setting,
char **  data 
)

Fetch value of string setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
data Buffer to allocate and fill with setting string data
Return values:
len Length of string setting, or negative error
The resulting string is guaranteed to be correctly NUL-terminated. The returned length will be the length of the underlying setting data. The caller is responsible for eventually freeing the allocated buffer.

Definition at line 617 of file settings.c.

References assert, ENOMEM, fetch_setting_len(), fetch_string_setting(), and malloc().

Referenced by apply_dns_settings().

00619                                               {
00620         int len;
00621         int check_len = 0;
00622 
00623         len = fetch_setting_len ( settings, setting );
00624         if ( len < 0 )
00625                 return len;
00626 
00627         *data = malloc ( len + 1 );
00628         if ( ! *data )
00629                 return -ENOMEM;
00630 
00631         check_len = fetch_string_setting ( settings, setting, *data,
00632                                            ( len + 1 ) );
00633         assert ( check_len == len );
00634         return len;
00635 }

int fetch_ipv4_setting ( struct settings settings,
struct setting setting,
struct in_addr inp 
)

Fetch value of IPv4 address setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
inp IPv4 address to fill in
Return values:
len Length of setting, or negative error

Definition at line 645 of file settings.c.

References ERANGE, and fetch_setting().

Referenced by apply_dns_settings(), fetchf_ipv4(), gdbudp_configure(), ibft_fill_nic(), ibft_set_ipaddr_option(), ipv4_create_routes(), netboot(), pxe_menu_boot(), start_pxebs(), and tftp_apply_settings().

00646                                                {
00647         int len;
00648 
00649         len = fetch_setting ( settings, setting, inp, sizeof ( *inp ) );
00650         if ( len < 0 )
00651                 return len;
00652         if ( len < ( int ) sizeof ( *inp ) )
00653                 return -ERANGE;
00654         return len;
00655 }

int fetch_int_setting ( struct settings settings,
struct setting setting,
long *  value 
)

Fetch value of signed integer setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
value Integer value to fill in
Return values:
len Length of setting, or negative error

Definition at line 665 of file settings.c.

References ERANGE, fetch_setting(), and u8.

Referenced by fetch_intz_setting(), fetch_uint_setting(), and fetchf_int().

00666                                       {
00667         union {
00668                 uint8_t u8[ sizeof ( long ) ];
00669                 int8_t s8[ sizeof ( long ) ];
00670         } buf;
00671         int len;
00672         int i;
00673 
00674         /* Avoid returning uninitialised data on error */
00675         *value = 0;
00676 
00677         /* Fetch raw (network-ordered, variable-length) setting */
00678         len = fetch_setting ( settings, setting, &buf, sizeof ( buf ) );
00679         if ( len < 0 )
00680                 return len;
00681         if ( len > ( int ) sizeof ( buf ) )
00682                 return -ERANGE;
00683 
00684         /* Convert to host-ordered signed long */
00685         *value = ( ( buf.s8[0] >= 0 ) ? 0 : -1L );
00686         for ( i = 0 ; i < len ; i++ ) {
00687                 *value = ( ( *value << 8 ) | buf.u8[i] );
00688         }
00689 
00690         return len;
00691 }

int fetch_uint_setting ( struct settings settings,
struct setting setting,
unsigned long *  value 
)

Fetch value of unsigned integer setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
value Integer value to fill in
Return values:
len Length of setting, or negative error

Definition at line 701 of file settings.c.

References assert, and fetch_int_setting().

Referenced by fetch_uintz_setting(), and fetchf_uint().

00702                                                 {
00703         long svalue;
00704         int len;
00705 
00706         /* Avoid returning uninitialised data on error */
00707         *value = 0;
00708 
00709         /* Fetch as a signed long */
00710         len = fetch_int_setting ( settings, setting, &svalue );
00711         if ( len < 0 )
00712                 return len;
00713 
00714         /* Mask off sign-extended bits */
00715         assert ( len <= ( int ) sizeof ( long ) );
00716         *value = ( svalue & ( -1UL >> ( 8 * ( sizeof ( long ) - len ) ) ) );
00717 
00718         return len;
00719 }

long fetch_intz_setting ( struct settings settings,
struct setting setting 
)

Fetch value of signed integer setting, or zero.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
Return values:
value Setting value, or zero

Definition at line 728 of file settings.c.

References fetch_int_setting().

Referenced by keep_san(), net80211_step_associate(), and reprioritise_settings().

00728                                                                               {
00729         long value;
00730 
00731         fetch_int_setting ( settings, setting, &value );
00732         return value;
00733 }

unsigned long fetch_uintz_setting ( struct settings settings,
struct setting setting 
)

Fetch value of unsigned integer setting, or zero.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
Return values:
value Setting value, or zero

Definition at line 742 of file settings.c.

References fetch_uint_setting().

Referenced by netboot(), start_dhcp(), and start_pxebs().

00743                                                               {
00744         unsigned long value;
00745 
00746         fetch_uint_setting ( settings, setting, &value );
00747         return value;
00748 }

int fetch_uuid_setting ( struct settings settings,
struct setting setting,
union uuid uuid 
)

Fetch value of UUID setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
uuid UUID to fill in
Return values:
len Length of setting, or negative error

Definition at line 758 of file settings.c.

References ERANGE, and fetch_setting().

Referenced by dhcp_create_request(), and fetchf_uuid().

00759                                             {
00760         int len;
00761 
00762         len = fetch_setting ( settings, setting, uuid, sizeof ( *uuid ) );
00763         if ( len < 0 )
00764                 return len;
00765         if ( len != sizeof ( *uuid ) )
00766                 return -ERANGE;
00767         return len;
00768 }

void clear_settings ( struct settings settings  ) 

Clear settings block.

Parameters:
settings Settings block

Definition at line 775 of file settings.c.

References settings_operations::clear, and settings::op.

Referenced by free_netdev().

00775                                                   {
00776         if ( settings->op->clear )
00777                 settings->op->clear ( settings );
00778 }

int setting_cmp ( struct setting a,
struct setting b 
)

Compare two settings.

Parameters:
a Setting to compare
b Setting to compare
Return values:
0 Settings are the same
non-zero Settings are not the same

Definition at line 788 of file settings.c.

References setting::name, strcmp(), and setting::tag.

Referenced by find_generic_setting(), netdev_fetch(), netdev_store(), phantom_clp_setting(), and store_setting().

00788                                                          {
00789 
00790         /* If the settings have tags, compare them */
00791         if ( a->tag && ( a->tag == b->tag ) )
00792                 return 0;
00793 
00794         /* Otherwise, if the settings have names, compare them */
00795         if ( a->name && b->name && a->name[0] )
00796                 return strcmp ( a->name, b->name );
00797 
00798         /* Otherwise, return a non-match */
00799         return ( ! 0 );
00800 }

int storef_setting ( struct settings settings,
struct setting setting,
const char *  value 
)

Store value of typed setting.

Parameters:
settings Settings block
setting Setting to store
type Settings type
value Formatted setting data, or NULL
Return values:
rc Return status code

Definition at line 818 of file settings.c.

References delete_setting(), setting_type::storef, and setting::type.

Referenced by save_setting(), and storef_named_setting().

00819                                          {
00820 
00821         /* NULL value implies deletion.  Avoid imposing the burden of
00822          * checking for NULL values on each typed setting's storef()
00823          * method.
00824          */
00825         if ( ! value )
00826                 return delete_setting ( settings, setting );
00827                 
00828         return setting->type->storef ( settings, setting, value );
00829 }

static struct setting* find_setting ( const char *  name  )  [static, read]

Find named setting.

Parameters:
name Name
Return values:
setting Named setting, or NULL

Definition at line 837 of file settings.c.

References for_each_table_entry, setting::name, NULL, SETTINGS, and strcmp().

Referenced by parse_setting_name().

00837                                                           {
00838         struct setting *setting;
00839 
00840         for_each_table_entry ( setting, SETTINGS ) {
00841                 if ( strcmp ( name, setting->name ) == 0 )
00842                         return setting;
00843         }
00844         return NULL;
00845 }

static unsigned int parse_setting_tag ( const char *  name  )  [static]

Parse setting name as tag number.

Parameters:
name Name
Return values:
tag Tag number, or 0 if not a valid number

Definition at line 853 of file settings.c.

References strtoul(), and setting::tag.

Referenced by parse_setting_name().

00853                                                            {
00854         char *tmp = ( ( char * ) name );
00855         unsigned int tag = 0;
00856 
00857         while ( 1 ) {
00858                 tag = ( ( tag << 8 ) | strtoul ( tmp, &tmp, 0 ) );
00859                 if ( *tmp == 0 )
00860                         return tag;
00861                 if ( *tmp != '.' )
00862                         return 0;
00863                 tmp++;
00864         }
00865 }

static struct setting_type* find_setting_type ( const char *  name  )  [static, read]

Find setting type.

Parameters:
name Name
Return values:
type Setting type, or NULL

Definition at line 873 of file settings.c.

References for_each_table_entry, setting_type::name, NULL, SETTING_TYPES, and strcmp().

Referenced by parse_setting_name().

00873                                                                     {
00874         struct setting_type *type;
00875 
00876         for_each_table_entry ( type, SETTING_TYPES ) {
00877                 if ( strcmp ( name, type->name ) == 0 )
00878                         return type;
00879         }
00880         return NULL;
00881 }

static int parse_setting_name ( const char *  name,
struct settings *(*)(struct settings *, const char *)  get_child,
struct settings **  settings,
struct setting setting,
char *  tmp_name 
) [static]

Parse setting name.

Parameters:
name Name of setting
get_child Function to find or create child settings block
settings Settings block to fill in
setting Setting to fill in
tmp_name Buffer for copy of setting name
Return values:
rc Return status code
Interprets a name of the form "[settings_name/]tag_name[:type_name]" and fills in the appropriate fields.

The tmp_name buffer must be large enough to hold a copy of the setting name.

Definition at line 901 of file settings.c.

References DBG, ENODEV, ENOTSUP, find_setting(), find_setting_type(), memcpy, memset(), setting::name, NULL, parse_setting_tag(), parse_settings_name(), settings_name(), settings_root, strchr(), strcpy(), setting::tag, and setting::type.

Referenced by fetchf_named_setting(), and storef_named_setting().

00905                                       {
00906         char *settings_name;
00907         char *setting_name;
00908         char *type_name;
00909         struct setting *named_setting;
00910 
00911         /* Set defaults */
00912         *settings = &settings_root;
00913         memset ( setting, 0, sizeof ( *setting ) );
00914         setting->name = "";
00915         setting->type = &setting_type_string;
00916 
00917         /* Split name into "[settings_name/]setting_name[:type_name]" */
00918         strcpy ( tmp_name, name );
00919         if ( ( setting_name = strchr ( tmp_name, '/' ) ) != NULL ) {
00920                 *(setting_name++) = 0;
00921                 settings_name = tmp_name;
00922         } else {
00923                 setting_name = tmp_name;
00924                 settings_name = NULL;
00925         }
00926         if ( ( type_name = strchr ( setting_name, ':' ) ) != NULL )
00927                 *(type_name++) = 0;
00928 
00929         /* Identify settings block, if specified */
00930         if ( settings_name ) {
00931                 *settings = parse_settings_name ( settings_name, get_child );
00932                 if ( *settings == NULL ) {
00933                         DBG ( "Unrecognised settings block \"%s\" in \"%s\"\n",
00934                               settings_name, name );
00935                         return -ENODEV;
00936                 }
00937         }
00938 
00939         /* Identify setting */
00940         if ( ( named_setting = find_setting ( setting_name ) ) != NULL ) {
00941                 /* Matches a defined named setting; use that setting */
00942                 memcpy ( setting, named_setting, sizeof ( *setting ) );
00943         } else if ( ( setting->tag = parse_setting_tag ( setting_name ) ) !=0){
00944                 /* Is a valid numeric tag; use the tag */
00945                 setting->tag |= (*settings)->tag_magic;
00946         } else {
00947                 /* Use the arbitrary name */
00948                 setting->name = setting_name;
00949         }
00950 
00951         /* Identify setting type, if specified */
00952         if ( type_name ) {
00953                 setting->type = find_setting_type ( type_name );
00954                 if ( setting->type == NULL ) {
00955                         DBG ( "Invalid setting type \"%s\" in \"%s\"\n",
00956                               type_name, name );
00957                         return -ENOTSUP;
00958                 }
00959         }
00960 
00961         return 0;
00962 }

int storef_named_setting ( const char *  name,
const char *  value 
)

Parse and store value of named setting.

Parameters:
name Name of setting
value Formatted setting data, or NULL
Return values:
rc Return status code

Definition at line 971 of file settings.c.

References autovivify_child_settings(), parse_setting_name(), storef_setting(), and strlen().

Referenced by delete_named_setting(), and set_exec().

00971                                                                  {
00972         struct settings *settings;
00973         struct setting setting;
00974         char tmp_name[ strlen ( name ) + 1 ];
00975         int rc;
00976 
00977         if ( ( rc = parse_setting_name ( name, autovivify_child_settings,
00978                                          &settings, &setting, tmp_name )) != 0)
00979                 return rc;
00980         return storef_setting ( settings, &setting, value );
00981 }

int fetchf_named_setting ( const char *  name,
char *  buf,
size_t  len 
)

Fetch and format value of named setting.

Parameters:
name Name of setting
buf Buffer to contain formatted value
len Length of buffer
Return values:
len Length of formatted value, or negative error

Definition at line 991 of file settings.c.

References fetchf_setting(), find_child_settings(), parse_setting_name(), and strlen().

Referenced by expand_command(), and show_exec().

00991                                                                      {
00992         struct settings *settings;
00993         struct setting setting;
00994         char tmp_name[ strlen ( name ) + 1 ];
00995         int rc;
00996 
00997         if ( ( rc = parse_setting_name ( name, find_child_settings,
00998                                          &settings, &setting, tmp_name )) != 0)
00999                 return rc;
01000         return fetchf_setting ( settings, &setting, buf, len );
01001 }

static int storef_string ( struct settings settings,
struct setting setting,
const char *  value 
) [static]

Parse and store value of string setting.

Parameters:
settings Settings block
setting Setting to store
value Formatted setting data
Return values:
rc Return status code

Definition at line 1018 of file settings.c.

References store_setting(), and strlen().

01019                                                {
01020         return store_setting ( settings, setting, value, strlen ( value ) );
01021 }

static int fetchf_string ( struct settings settings,
struct setting setting,
char *  buf,
size_t  len 
) [static]

Fetch and format value of string setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
buf Buffer to contain formatted value
len Length of buffer
Return values:
len Length of formatted value, or negative error

Definition at line 1032 of file settings.c.

References fetch_string_setting().

01033                                                    {
01034         return fetch_string_setting ( settings, setting, buf, len );
01035 }

static int storef_uristring ( struct settings settings,
struct setting setting,
const char *  value 
) [static]

Parse and store value of URI-encoded string setting.

Parameters:
settings Settings block
setting Setting to store
value Formatted setting data
Return values:
rc Return status code

Definition at line 1052 of file settings.c.

References store_setting(), strlen(), and uri_decode().

01054                                                   {
01055         char buf[ strlen ( value ) + 1 ]; /* Decoding never expands string */
01056         size_t len;
01057 
01058         len = uri_decode ( value, buf, sizeof ( buf ) );
01059         return store_setting ( settings, setting, buf, len );
01060 }

static int fetchf_uristring ( struct settings settings,
struct setting setting,
char *  buf,
size_t  len 
) [static]

Fetch and format value of URI-encoded string setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
buf Buffer to contain formatted value
len Length of buffer
Return values:
len Length of formatted value, or negative error

Definition at line 1071 of file settings.c.

References fetch_setting(), fetch_string_setting(), NULL, uri_encode(), and URI_FRAGMENT.

01073                                                       {
01074         ssize_t raw_len;
01075 
01076         /* We need to always retrieve the full raw string to know the
01077          * length of the encoded string.
01078          */
01079         raw_len = fetch_setting ( settings, setting, NULL, 0 );
01080         if ( raw_len < 0 )
01081                 return raw_len;
01082 
01083         {
01084                 char raw_buf[ raw_len + 1 ];
01085        
01086                 fetch_string_setting ( settings, setting, raw_buf,
01087                                        sizeof ( raw_buf ) );
01088                 return uri_encode ( raw_buf, buf, len, URI_FRAGMENT );
01089         }
01090 }

static int storef_ipv4 ( struct settings settings,
struct setting setting,
const char *  value 
) [static]

Parse and store value of IPv4 address setting.

Parameters:
settings Settings block
setting Setting to store
value Formatted setting data
Return values:
rc Return status code

Definition at line 1107 of file settings.c.

References EINVAL, inet_aton(), and store_setting().

01108                                              {
01109         struct in_addr ipv4;
01110 
01111         if ( inet_aton ( value, &ipv4 ) == 0 )
01112                 return -EINVAL;
01113         return store_setting ( settings, setting, &ipv4, sizeof ( ipv4 ) );
01114 }

static int fetchf_ipv4 ( struct settings settings,
struct setting setting,
char *  buf,
size_t  len 
) [static]

Fetch and format value of IPv4 address setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
buf Buffer to contain formatted value
len Length of buffer
Return values:
len Length of formatted value, or negative error

Definition at line 1125 of file settings.c.

References fetch_ipv4_setting(), inet_ntoa(), and snprintf().

01126                                                  {
01127         struct in_addr ipv4;
01128         int raw_len;
01129 
01130         if ( ( raw_len = fetch_ipv4_setting ( settings, setting, &ipv4 ) ) < 0)
01131                 return raw_len;
01132         return snprintf ( buf, len, "%s", inet_ntoa ( ipv4 ) );
01133 }

static int storef_int ( struct settings settings,
struct setting setting,
const char *  value,
unsigned int  size 
) [static]

Parse and store value of integer setting.

Parameters:
settings Settings block
setting Setting to store
value Formatted setting data
size Integer size, in bytes
Return values:
rc Return status code

Definition at line 1151 of file settings.c.

References EINVAL, htonl, store_setting(), and strtoul().

Referenced by storef_int16(), storef_int32(), and storef_int8().

01152                                                                {
01153         union {
01154                 uint32_t num;
01155                 uint8_t bytes[4];
01156         } u;
01157         char *endp;
01158 
01159         u.num = htonl ( strtoul ( value, &endp, 0 ) );
01160         if ( *endp )
01161                 return -EINVAL;
01162         return store_setting ( settings, setting, 
01163                                &u.bytes[ sizeof ( u ) - size ], size );
01164 }

static int storef_int8 ( struct settings settings,
struct setting setting,
const char *  value 
) [static]

Parse and store value of 8-bit integer setting.

Parameters:
settings Settings block
setting Setting to store
value Formatted setting data
size Integer size, in bytes
Return values:
rc Return status code

Definition at line 1175 of file settings.c.

References storef_int().

01176                                              {
01177         return storef_int ( settings, setting, value, 1 );
01178 }

static int storef_int16 ( struct settings settings,
struct setting setting,
const char *  value 
) [static]

Parse and store value of 16-bit integer setting.

Parameters:
settings Settings block
setting Setting to store
value Formatted setting data
size Integer size, in bytes
Return values:
rc Return status code

Definition at line 1189 of file settings.c.

References storef_int().

01190                                               {
01191         return storef_int ( settings, setting, value, 2 );
01192 }

static int storef_int32 ( struct settings settings,
struct setting setting,
const char *  value 
) [static]

Parse and store value of 32-bit integer setting.

Parameters:
settings Settings block
setting Setting to store
value Formatted setting data
size Integer size, in bytes
Return values:
rc Return status code

Definition at line 1203 of file settings.c.

References storef_int().

01204                                               {
01205         return storef_int ( settings, setting, value, 4 );
01206 }

static int fetchf_int ( struct settings settings,
struct setting setting,
char *  buf,
size_t  len 
) [static]

Fetch and format value of signed integer setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
buf Buffer to contain formatted value
len Length of buffer
Return values:
len Length of formatted value, or negative error

Definition at line 1217 of file settings.c.

References fetch_int_setting(), and snprintf().

01218                                                 {
01219         long value;
01220         int rc;
01221 
01222         if ( ( rc = fetch_int_setting ( settings, setting, &value ) ) < 0 )
01223                 return rc;
01224         return snprintf ( buf, len, "%ld", value );
01225 }

static int fetchf_uint ( struct settings settings,
struct setting setting,
char *  buf,
size_t  len 
) [static]

Fetch and format value of unsigned integer setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
buf Buffer to contain formatted value
len Length of buffer
Return values:
len Length of formatted value, or negative error

Definition at line 1236 of file settings.c.

References fetch_uint_setting(), and snprintf().

01237                                                  {
01238         unsigned long value;
01239         int rc;
01240 
01241         if ( ( rc = fetch_uint_setting ( settings, setting, &value ) ) < 0 )
01242                 return rc;
01243         return snprintf ( buf, len, "%#lx", value );
01244 }

static int storef_hex ( struct settings settings,
struct setting setting,
const char *  value 
) [static]

Parse and store value of hex string setting.

Parameters:
settings Settings block
setting Setting to store
value Formatted setting data
Return values:
rc Return status code

Definition at line 1296 of file settings.c.

References EINVAL, store_setting(), strlen(), and strtoul().

01297                                             {
01298         char *ptr = ( char * ) value;
01299         uint8_t bytes[ strlen ( value ) ]; /* cannot exceed strlen(value) */
01300         unsigned int len = 0;
01301 
01302         while ( 1 ) {
01303                 bytes[len++] = strtoul ( ptr, &ptr, 16 );
01304                 switch ( *ptr ) {
01305                 case '\0' :
01306                         return store_setting ( settings, setting, bytes, len );
01307                 case ':' :
01308                         ptr++;
01309                         break;
01310                 default :
01311                         return -EINVAL;
01312                 }
01313         }
01314 }

static int fetchf_hex ( struct settings settings,
struct setting setting,
char *  buf,
size_t  len 
) [static]

Fetch and format value of hex string setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
buf Buffer to contain formatted value
len Length of buffer
Return values:
len Length of formatted value, or negative error

Definition at line 1325 of file settings.c.

References assert, fetch_setting(), fetch_setting_len(), raw(), and ssnprintf().

01326                                                 {
01327         int raw_len;
01328         int check_len;
01329         int used = 0;
01330         int i;
01331 
01332         raw_len = fetch_setting_len ( settings, setting );
01333         if ( raw_len < 0 )
01334                 return raw_len;
01335 
01336         {
01337                 uint8_t raw[raw_len];
01338 
01339                 check_len = fetch_setting ( settings, setting, raw,
01340                                             sizeof ( raw ) );
01341                 if ( check_len < 0 )
01342                         return check_len;
01343                 assert ( check_len == raw_len );
01344                 
01345                 if ( len )
01346                         buf[0] = 0; /* Ensure that a terminating NUL exists */
01347                 for ( i = 0 ; i < raw_len ; i++ ) {
01348                         used += ssnprintf ( ( buf + used ), ( len - used ),
01349                                             "%s%02x", ( used ? ":" : "" ),
01350                                             raw[i] );
01351                 }
01352                 return used;
01353         }
01354 }

static int storef_uuid ( struct settings *settings  __unused,
struct setting *setting  __unused,
const char *value  __unused 
) [static]

Parse and store value of UUID setting.

Parameters:
settings Settings block
setting Setting to store
value Formatted setting data
Return values:
rc Return status code

Definition at line 1371 of file settings.c.

References ENOTSUP.

01373                                                       {
01374         return -ENOTSUP;
01375 }

static int fetchf_uuid ( struct settings settings,
struct setting setting,
char *  buf,
size_t  len 
) [static]

Fetch and format value of UUID setting.

Parameters:
settings Settings block, or NULL to search all blocks
setting Setting to fetch
buf Buffer to contain formatted value
len Length of buffer
Return values:
len Length of formatted value, or negative error

Definition at line 1386 of file settings.c.

References fetch_uuid_setting(), snprintf(), and uuid_ntoa().

01387                                                  {
01388         union uuid uuid;
01389         int raw_len;
01390 
01391         if ( ( raw_len = fetch_uuid_setting ( settings, setting, &uuid ) ) < 0)
01392                 return raw_len;
01393         return snprintf ( buf, len, "%s", uuid_ntoa ( &uuid ) );
01394 }


Variable Documentation

Initial value:

Generic settings operations.

Definition at line 203 of file settings.c.

Referenced by generic_settings_init().

Initial value:

Root generic settings block.

Definition at line 217 of file settings.c.

struct setting_type setting_type_uuid __setting_type [read]

Initial value:

 {
        .name = "string",
        .storef = storef_string,
        .fetchf = fetchf_string,
}
A string setting type.

UUID setting type.

A hex-string setting.

An unsigned 32-bit integer setting type.

An unsigned 16-bit integer setting type.

An unsigned 8-bit integer setting type.

A signed 32-bit integer setting type.

A signed 16-bit integer setting type.

A signed 8-bit integer setting type.

An IPv4 address setting type.

A URI-encoded string setting type.

Definition at line 1038 of file settings.c.

struct setting priority_setting __setting [read]

Initial value:

 {
        .name = "hostname",
        .description = "Host name",
        .tag = DHCP_HOST_NAME,
        .type = &setting_type_string,
}
Hostname setting.

802.11 encryption key setting

Priority setting.

Password setting.

Username setting.

Root path setting.

Filename setting.

Definition at line 1411 of file settings.c.


Generated on Tue Apr 6 20:01:15 2010 for gPXE by  doxygen 1.5.7.1