pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
Data Structures | Typedefs | Functions
nvpair.h File Reference

Functionality for manipulating name/value pairs. More...

#include <sys/time.h>
#include <glib.h>
#include <libxml/tree.h>
#include <crm/crm.h>
#include <crm/common/nvpair_compat.h>
Include dependency graph for nvpair.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pcmk_nvpair_s
 

Typedefs

typedef struct pcmk_nvpair_s pcmk_nvpair_t
 

Functions

GSList * pcmk_prepend_nvpair (GSList *nvpairs, const char *name, const char *value)
 Prepend a name/value pair to a list. More...
 
void pcmk_free_nvpairs (GSList *nvpairs)
 Free a list of name/value pairs. More...
 
xmlNode * crm_create_nvpair_xml (xmlNode *parent, const char *id, const char *name, const char *value)
 Create an XML name/value pair. More...
 
void hash2field (gpointer key, gpointer value, gpointer user_data)
 Set XML attribute based on hash table entry. More...
 
void hash2metafield (gpointer key, gpointer value, gpointer user_data)
 Set XML attribute based on hash table entry, as meta-attribute name. More...
 
void hash2smartfield (gpointer key, gpointer value, gpointer user_data)
 Safely add hash table entry to XML as attribute or name-value pair. More...
 
GHashTable * xml2list (const xmlNode *parent)
 Retrieve XML attributes as a hash table. More...
 
char * crm_meta_name (const char *field)
 Get the environment variable equivalent of a meta-attribute name. More...
 
const char * crm_meta_value (GHashTable *hash, const char *field)
 Get the value of a meta-attribute. More...
 

Detailed Description

Functionality for manipulating name/value pairs.

Definition in file nvpair.h.

Typedef Documentation

◆ pcmk_nvpair_t

typedef struct pcmk_nvpair_s pcmk_nvpair_t

Function Documentation

◆ crm_create_nvpair_xml()

xmlNode* crm_create_nvpair_xml ( xmlNode *  parent,
const char *  id,
const char *  name,
const char *  value 
)

Create an XML name/value pair.

Parameters
[in,out]parentIf not NULL, make new XML node a child of this one
[in]idSet this as XML ID (or NULL to auto-generate)
[in]nameName to use
[in]valueValue to use
Returns
New XML object on success, NULL otherwise

Definition at line 312 of file nvpair.c.

◆ crm_meta_name()

char* crm_meta_name ( const char *  attr_name)

Get the environment variable equivalent of a meta-attribute name.

Parameters
[in]attr_nameName of meta-attribute
Returns
Newly allocated string for attr_name with "CRM_meta_" prefix and underbars instead of dashes
Note
This asserts on an invalid argument or memory allocation error, so callers can assume the result is non-NULL. The caller is responsible for freeing the result using free().

Definition at line 407 of file nvpair.c.

◆ crm_meta_value()

const char* crm_meta_value ( GHashTable *  meta,
const char *  attr_name 
)

Get the value of a meta-attribute.

Get the value of a meta-attribute from a hash table whose keys are meta-attribute environment variable names (as crm_meta_name() would create, like pcmk__graph_action_t:params, not pcmk_resource_t:meta).

Parameters
[in]metaHash table of meta-attributes
[in]attr_nameName of meta-attribute to get
Returns
Value of given meta-attribute

Definition at line 435 of file nvpair.c.

◆ hash2field()

void hash2field ( gpointer  key,
gpointer  value,
gpointer  user_data 
)

Set XML attribute based on hash table entry.

Suitable for g_hash_table_foreach(), this function takes a hash table key and value, with an XML node passed as user data, and adds an XML attribute with the specified name and value if it does not already exist.

Parameters
[in]keyKey of hash table entry
[in]valueValue of hash table entry
[in,out]user_dataXML node

Definition at line 249 of file nvpair.c.

◆ hash2metafield()

void hash2metafield ( gpointer  key,
gpointer  value,
gpointer  user_data 
)

Set XML attribute based on hash table entry, as meta-attribute name.

Suitable for g_hash_table_foreach(), this function takes a hash table key and value, with an XML node passed as user data, and adds an XML attribute with the meta-attribute version of the specified name and value if it does not already exist and if the name does not appear to be cluster-internal.

Parameters
[in]keyKey of hash table entry
[in]valueValue of hash table entry
[in,out]user_dataXML node

Definition at line 277 of file nvpair.c.

◆ hash2smartfield()

void hash2smartfield ( gpointer  key,
gpointer  value,
gpointer  user_data 
)

Safely add hash table entry to XML as attribute or name-value pair.

Suitable for g_hash_table_foreach(), this function takes a hash table key and value, with an XML node passed as user data, and adds an XML attribute with the specified name and value if it does not already exist. If the key name starts with a digit, then it's not a valid XML attribute name. In that case, this will instead add a

Parameters
NAMEchild to the XML.
[in]keyKey of hash table entry
[in]valueValue of hash table entry
[in,out]user_dataXML node

Definition at line 207 of file nvpair.c.

◆ pcmk_free_nvpairs()

void pcmk_free_nvpairs ( GSList *  nvpairs)

Free a list of name/value pairs.

Parameters
[in,out]listList to free

Definition at line 103 of file nvpair.c.

◆ pcmk_prepend_nvpair()

GSList* pcmk_prepend_nvpair ( GSList *  nvpairs,
const char *  name,
const char *  value 
)

Prepend a name/value pair to a list.

Parameters
[in,out]nvpairsList to modify
[in]nameNew entry's name
[in]valueNew entry's value
Returns
New head of list
Note
The caller is responsible for freeing the list with pcmk_free_nvpairs().

Definition at line 92 of file nvpair.c.

◆ xml2list()

GHashTable* xml2list ( const xmlNode *  parent)

Retrieve XML attributes as a hash table.

Given an XML element, this will look for any <attributes> element child, creating a hash table of (newly allocated string) name/value pairs taken first from the attributes element's NAME=VALUE XML attributes, and then from any <param name=NAME value=VALUE> children of attributes.

Parameters
[in]XMLnode to parse
Returns
Hash table with name/value pairs
Note
It is the caller's responsibility to free the result using g_hash_table_destroy().

Definition at line 350 of file nvpair.c.