pacemaker  2.0.2-debe490
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
nvpair.c File Reference
#include <crm_internal.h>
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <ctype.h>
#include <glib.h>
#include <libxml/tree.h>
#include <crm/crm.h>
#include <crm/msg_xml.h>
#include <crm/common/xml.h>
#include "crmcommon_private.h"
Include dependency graph for nvpair.c:

Go to the source code of this file.

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...
 
GSList * pcmk_sort_nvpairs (GSList *list)
 Sort a list of name/value pairs. More...
 
GSList * pcmk_xml_attrs2nvpairs (xmlNode *xml)
 Create a list of name/value pairs from an XML node's attributes. More...
 
void pcmk_nvpairs2xml_attrs (GSList *list, xmlNode *xml)
 Add XML attributes based on a list of name/value pairs. More...
 
int pcmk_scan_nvpair (const char *input, char **name, char **value)
 Extract the name and value from an input string formatted as "name=value". If unable to extract them, they are returned as NULL. More...
 
const char * crm_xml_add (xmlNode *node, const char *name, const char *value)
 Create an XML attribute with specified name and value. More...
 
const char * crm_xml_replace (xmlNode *node, const char *name, const char *value)
 Replace an XML attribute with specified name and (possibly NULL) value. More...
 
const char * crm_xml_add_int (xmlNode *node, const char *name, int value)
 Create an XML attribute with specified name and integer value. More...
 
const char * crm_xml_add_ms (xmlNode *node, const char *name, guint ms)
 Create an XML attribute with specified name and unsigned value. More...
 
const char * crm_element_value (const xmlNode *data, const char *name)
 Retrieve the value of an XML attribute. More...
 
int crm_element_value_int (const xmlNode *data, const char *name, int *dest)
 Retrieve the integer value of an XML attribute. More...
 
int crm_element_value_ms (const xmlNode *data, const char *name, guint *dest)
 Retrieve the millisecond value of an XML attribute. More...
 
int crm_element_value_timeval (const xmlNode *xml, const char *name_sec, const char *name_usec, struct timeval *dest)
 Retrieve the value of XML second/microsecond attributes as time. More...
 
char * crm_element_value_copy (const xmlNode *data, const char *name)
 Retrieve a copy of the value of an XML attribute. More...
 
void hash2smartfield (gpointer key, gpointer value, gpointer user_data)
 Add hash table entry to XML as (possibly legacy) name/value. 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...
 
xmlNode * crm_create_nvpair_xml (xmlNode *parent, const char *id, const char *name, const char *value)
 Create an XML name/value pair. More...
 
void hash2nvpair (gpointer key, gpointer value, gpointer user_data)
 Add XML nvpair element based on hash table entry. More...
 
GHashTable * xml2list (xmlNode *parent)
 Retrieve XML attributes as a hash table. More...
 

Function Documentation

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

Create an XML name/value pair.

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

Definition at line 678 of file nvpair.c.

const char* crm_element_value ( const xmlNode *  data,
const char *  name 
)

Retrieve the value of an XML attribute.

Parameters
[in]dataXML node to check
[in]nameAttribute name to check
Returns
Value of specified attribute (may be NULL)

Definition at line 423 of file nvpair.c.

char* crm_element_value_copy ( const xmlNode *  data,
const char *  name 
)

Retrieve a copy of the value of an XML attribute.

This is like crm_element_value() but allocating new memory for the result.

Parameters
[in]dataXML node to check
[in]nameAttribute name to check
Returns
Value of specified attribute (may be NULL)
Note
The caller is responsible for freeing the result.

Definition at line 556 of file nvpair.c.

int crm_element_value_int ( const xmlNode *  data,
const char *  name,
int *  dest 
)

Retrieve the integer value of an XML attribute.

This is like crm_element_value() but getting the value as an integer.

Parameters
[in]dataXML node to check
[in]nameAttribute name to check
[in]destWhere to store element value
Returns
0 on success, -1 otherwise

Definition at line 459 of file nvpair.c.

int crm_element_value_ms ( const xmlNode *  data,
const char *  name,
guint *  dest 
)

Retrieve the millisecond value of an XML attribute.

This is like crm_element_value() but returning the value as a guint.

Parameters
[in]dataXML node to check
[in]nameAttribute name to check
[out]destWhere to store attribute value
Returns
pcmk_ok on success, -1 otherwise

Definition at line 484 of file nvpair.c.

int crm_element_value_timeval ( const xmlNode *  xml,
const char *  name_sec,
const char *  name_usec,
struct timeval *  dest 
)

Retrieve the value of XML second/microsecond attributes as time.

This is like crm_element_value() but returning value as a struct timeval.

Parameters
[in]xmlXML to parse
[in]name_secName of XML attribute for seconds
[in]name_usecName of XML attribute for microseconds
[out]destWhere to store result
Returns
pcmk_ok on success, -errno on error
Note
Values default to 0 if XML or XML attribute does not exist

Definition at line 508 of file nvpair.c.

const char* crm_xml_add ( xmlNode *  node,
const char *  name,
const char *  value 
)

Create an XML attribute with specified name and value.

Parameters
[in,out]nodeXML node to modify
[in]nameAttribute name to set
[in]valueAttribute value to set
Returns
New value on success, NULL otherwise
Note
This does nothing if node, name, or value are NULL or empty.

Definition at line 275 of file nvpair.c.

const char* crm_xml_add_int ( xmlNode *  node,
const char *  name,
int  value 
)

Create an XML attribute with specified name and integer value.

This is like crm_xml_add() but taking an integer value.

Parameters
[in,out]nodeXML node to modify
[in]nameAttribute name to set
[in]valueAttribute value to set
Returns
New value as string on success, NULL otherwise
Note
This does nothing if node or name are NULL or empty.

Definition at line 383 of file nvpair.c.

const char* crm_xml_add_ms ( xmlNode *  node,
const char *  name,
guint  ms 
)

Create an XML attribute with specified name and unsigned value.

This is like crm_xml_add() but taking a guint value.

Parameters
[in,out]nodeXML node to modify
[in]nameAttribute name to set
[in]msAttribute value to set
Returns
New value as string on success, NULL otherwise
Note
This does nothing if node or name are NULL or empty.

Definition at line 405 of file nvpair.c.

const char* crm_xml_replace ( xmlNode *  node,
const char *  name,
const char *  value 
)

Replace an XML attribute with specified name and (possibly NULL) value.

Parameters
[in,out]nodeXML node to modify
[in]nameAttribute name to set
[in]valueAttribute value to set
Returns
New value on success, NULL otherwise
Note
This does nothing if node or name is NULL or empty.

Definition at line 332 of file nvpair.c.

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]user_dataXML node

Definition at line 615 of file nvpair.c.

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]user_dataXML node

Definition at line 643 of file nvpair.c.

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

Add XML nvpair element 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 the user data, and adds an nvpair XML element with the specified name and value.

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

Definition at line 716 of file nvpair.c.

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

Add hash table entry to XML as (possibly legacy) name/value.

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, this will instead add a <param name=NAME value=VALUE/> child to the XML (for legacy compatibility with heartbeat).

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

Definition at line 581 of file nvpair.c.

void pcmk_free_nvpairs ( GSList *  nvpairs)

Free a list of name/value pairs.

Parameters
[in]listList to free

Definition at line 99 of file nvpair.c.

void pcmk_nvpairs2xml_attrs ( GSList *  list,
xmlNode *  xml 
)

Add XML attributes based on a list of name/value pairs.

Parameters
[in]listList of name/value pairs
[in,out]xmlXML node to add attributes to

Definition at line 198 of file nvpair.c.

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 88 of file nvpair.c.

int pcmk_scan_nvpair ( const char *  input,
char **  name,
char **  value 
)

Extract the name and value from an input string formatted as "name=value". If unable to extract them, they are returned as NULL.

Parameters
[in]inputThe input string, likely from the command line
[out]nameEverything before the first '=' in the input string
[out]valueEverything after the first '=' in the input string
Returns
2 if both name and value could be extracted, 1 if only one could, and and error code otherwise

Definition at line 217 of file nvpair.c.

GSList* pcmk_sort_nvpairs ( GSList *  list)

Sort a list of name/value pairs.

Parameters
[in,out]listList to sort
Returns
New head of list

Definition at line 143 of file nvpair.c.

GSList* pcmk_xml_attrs2nvpairs ( xmlNode *  xml)

Create a list of name/value pairs from an XML node's attributes.

Parameters
[in]XMLto parse
Returns
New list of name/value pairs
Note
It is the caller's responsibility to free the list with pcmk_free_nvpairs().

Definition at line 158 of file nvpair.c.

GHashTable* xml2list ( 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 741 of file nvpair.c.