rpm  5.4.15
Macros | Functions | Variables
rpmaug.c File Reference
#include "system.h"
#include <rpmiotypes.h>
#include <rpmio.h>
#include <rpmlog.h>
#include <argv.h>
#include <rpmaug.h>
#include "debug.h"
Include dependency graph for rpmaug.c:

Go to the source code of this file.

Macros

#define _RPMIOB_INTERNAL
 
#define _RPMAUG_INTERNAL
 
#define SEP   '/'
 
#define DATADIR   "/usr/share"
 
#define AUGEAS_LENS_DIR   DATADIR "/augeas/lenses"
 
#define AUGEAS_LENS_DIST_DIR   DATADIR "/augeas/lenses/dist"
 
#define PATH_SEP_CHAR   ':'
 
#define ARGMINMAX(_min, _max)   (int)(((_min) << 8) | ((_max) & 0xff))
 

Functions

static void rpmaugFini (void *_aug)
 
static rpmaug rpmaugGetPool (rpmioPool pool)
 
rpmaug rpmaugNew (const char *root, const char *loadpath, unsigned int flags)
 Create and load a augeas wrapper. More...
 
int rpmaugDefvar (rpmaug aug, const char *name, const char *expr)
 Define an augeas variable. More...
 
int rpmaugDefnode (rpmaug aug, const char *name, const char *expr, const char *value, int *created)
 Define an augeas node. More...
 
int rpmaugGet (rpmaug aug, const char *path, const char **value)
 Get the value associated with a path. More...
 
int rpmaugSet (rpmaug aug, const char *path, const char *value)
 Set the value associated with a path. More...
 
int rpmaugInsert (rpmaug aug, const char *path, const char *label, int before)
 Insert new sibling node before/after a given node. More...
 
int rpmaugRm (rpmaug aug, const char *path)
 Remove node and associated sub-tree. More...
 
int rpmaugMv (rpmaug aug, const char *src, const char *dst)
 Move src node to dst node. More...
 
int rpmaugMatch (rpmaug aug, const char *path, char ***matches)
 Return path(s) in tree that match an expression. More...
 
int rpmaugSave (rpmaug aug)
 Save changed files to disk, appending .augnew or .augsave as requested. More...
 
int rpmaugLoad (rpmaug aug)
 Load files/lenses from disk. More...
 
int rpmaugPrint (rpmaug aug, FILE *out, const char *path)
 Print node paths that match an expression. More...
 
void rpmaugFprintf (rpmaug aug, const char *fmt,...)
 Append augeas output to an iob. More...
 
static char * cleanstr (char *path, const char sep)
 
static char * cleanpath (char *path)
 
static void err_check (void)
 
static char * ls_pattern (const char *path)
 
static int child_count (const char *path)
 
static int cmd_quit (int ac, char *av[])
 
static int cmd_ls (int ac, char *av[])
 
static int cmd_match (int ac, char *av[])
 
static int cmd_rm (int ac, char *av[])
 
static int cmd_mv (int ac, char *av[])
 
static int cmd_set (int ac, char *av[])
 
static int cmd_defvar (int ac, char *av[])
 
static int cmd_defnode (int ac, char *av[])
 
static int cmd_clear (int ac, char *av[])
 
static int cmd_get (int ac, char *av[])
 
static int cmd_print (int ac, char *av[])
 
static int cmd_save (int ac, char *av[])
 
static int cmd_load (int ac, char *av[])
 
static int cmd_ins (int ac, char *av[])
 
static int cmd_help (int ac, char *av[])
 
rpmRC rpmaugRun (rpmaug aug, const char *str, const char **resultp)
 Run augeas commands from a buffer. More...
 

Variables

int _rpmaug_debug = 0
 
rpmaug _rpmaugI = NULL
 
rpmioPool _rpmaugPool = NULL
 
static const char _root [] = "/"
 
const char * _rpmaugRoot = _root
 
static const char _loadpath [] = ""
 
const char * _rpmaugLoadpath = _loadpath
 
unsigned int _rpmaugFlags = 0
 
const char ** _rpmaugLoadargv
 
struct poptOption rpmaugPoptTable []
 Popt option table for options to configure Augeas augtool. More...
 
const struct poptOption _rpmaugCommandTable []
 

Macro Definition Documentation

#define _RPMAUG_INTERNAL

Definition at line 23 of file rpmaug.c.

#define _RPMIOB_INTERNAL

Definition at line 17 of file rpmaug.c.

#define ARGMINMAX (   _min,
  _max 
)    (int)(((_min) << 8) | ((_max) & 0xff))

Definition at line 681 of file rpmaug.c.

#define AUGEAS_LENS_DIR   DATADIR "/augeas/lenses"

Definition at line 358 of file rpmaug.c.

Referenced by cmd_help().

#define AUGEAS_LENS_DIST_DIR   DATADIR "/augeas/lenses/dist"

Definition at line 361 of file rpmaug.c.

#define DATADIR   "/usr/share"

Definition at line 354 of file rpmaug.c.

#define PATH_SEP_CHAR   ':'

Definition at line 366 of file rpmaug.c.

#define SEP   '/'

Definition at line 351 of file rpmaug.c.

Referenced by cleanpath(), cmd_ls(), and ls_pattern().

Function Documentation

static int child_count ( const char *  path)
static

Definition at line 418 of file rpmaug.c.

References err_check(), ls_pattern(), and rpmaugMatch().

Referenced by cmd_ls().

static char* cleanpath ( char *  path)
static

Definition at line 380 of file rpmaug.c.

References cleanstr(), and SEP.

Referenced by cmd_clear(), cmd_defnode(), cmd_defvar(), cmd_get(), cmd_ins(), cmd_ls(), cmd_match(), cmd_mv(), cmd_print(), cmd_rm(), and cmd_set().

static char* cleanstr ( char *  path,
const char  sep 
)
static

Definition at line 370 of file rpmaug.c.

References xisspace().

Referenced by cleanpath().

static int cmd_clear ( int  ac,
char *  av[] 
)
static

Definition at line 574 of file rpmaug.c.

References cleanpath(), err_check(), rpmaugFprintf(), and rpmaugSet().

static int cmd_defnode ( int  ac,
char *  av[] 
)
static

Definition at line 555 of file rpmaug.c.

References cleanpath(), err_check(), name, rpmaugDefnode(), and rpmaugFprintf().

static int cmd_defvar ( int  ac,
char *  av[] 
)
static

Definition at line 543 of file rpmaug.c.

References cleanpath(), err_check(), name, rpmaugDefvar(), and rpmaugFprintf().

static int cmd_get ( int  ac,
char *  av[] 
)
static

Definition at line 585 of file rpmaug.c.

References cleanpath(), err_check(), rpmaugFprintf(), and rpmaugGet().

static int cmd_help ( int  ac,
char *  av[] 
)
static

Definition at line 665 of file rpmaug.c.

References _rpmaugCommandTable, AUGEAS_LENS_DIR, and rpmaugFprintf().

static int cmd_ins ( int  ac,
char *  av[] 
)
static

Definition at line 641 of file rpmaug.c.

References cleanpath(), err_check(), rpmaugFprintf(), and rpmaugInsert().

static int cmd_load ( int  ac,
char *  av[] 
)
static

Definition at line 625 of file rpmaug.c.

References err_check(), rpmaugFprintf(), rpmaugLoad(), and rpmaugMatch().

static int cmd_ls ( int  ac,
char *  av[] 
)
static
static int cmd_match ( int  ac,
char *  av[] 
)
static

Definition at line 466 of file rpmaug.c.

References _free(), cleanpath(), err_check(), i, pattern, rpmaugFprintf(), rpmaugGet(), and rpmaugMatch().

static int cmd_mv ( int  ac,
char *  av[] 
)
static

Definition at line 519 of file rpmaug.c.

References cleanpath(), err_check(), rpmaugFprintf(), and rpmaugMv().

static int cmd_print ( int  ac,
char *  av[] 
)
static

Definition at line 601 of file rpmaug.c.

References cleanpath(), err_check(), and rpmaugPrint().

static int cmd_quit ( int  ac,
char *  av[] 
)
static

Definition at line 431 of file rpmaug.c.

static int cmd_rm ( int  ac,
char *  av[] 
)
static

Definition at line 507 of file rpmaug.c.

References cleanpath(), err_check(), rpmaugFprintf(), and rpmaugRm().

static int cmd_save ( int  ac,
char *  av[] 
)
static

Definition at line 608 of file rpmaug.c.

References err_check(), rpmaugFprintf(), rpmaugMatch(), and rpmaugSave().

static int cmd_set ( int  ac,
char *  av[] 
)
static

Definition at line 531 of file rpmaug.c.

References cleanpath(), err_check(), rpmaugFprintf(), and rpmaugSet().

static void err_check ( void  )
static
static char* ls_pattern ( const char *  path)
static

Definition at line 404 of file rpmaug.c.

References SEP.

Referenced by child_count(), and cmd_ls().

int rpmaugDefnode ( rpmaug  aug,
const char *  name,
const char *  expr,
const char *  value,
int *  created 
)

Define an augeas node.

Parameters
augaugeas wrapper (NULL uses global interpreter)
namevariable name
exprexpression to be evaluated (must eval to a nodeset)
valueinitial node value (if creating)
Return values
*created1 if node was created
Returns
-1 on error, or no. nodes in set

Definition at line 179 of file rpmaug.c.

Referenced by cmd_defnode().

int rpmaugDefvar ( rpmaug  aug,
const char *  name,
const char *  expr 
)

Define an augeas variable.

Parameters
augaugeas wrapper (NULL uses global interpreter)
namevariable name
exprexpression to be evaluated
Returns
-1 on error, or no. nodes in nodeset

Definition at line 165 of file rpmaug.c.

Referenced by cmd_defvar().

static void rpmaugFini ( void *  _aug)
static

Definition at line 39 of file rpmaug.c.

References _free(), and rpmiobFree().

Referenced by rpmaugGetPool().

void rpmaugFprintf ( rpmaug  aug,
const char *  fmt,
  ... 
)

Append augeas output to an iob.

Parameters
augaugeas wrapper (NULL uses global interpreter)
fmtformat to use

Definition at line 322 of file rpmaug.c.

References _free(), b, rpmiobAppend(), vsnprintf(), xmalloc, and xrealloc.

Referenced by cmd_clear(), cmd_defnode(), cmd_defvar(), cmd_get(), cmd_help(), cmd_ins(), cmd_load(), cmd_ls(), cmd_match(), cmd_mv(), cmd_rm(), cmd_save(), cmd_set(), and rpmaugRun().

int rpmaugGet ( rpmaug  aug,
const char *  path,
const char **  value 
)

Get the value associated with a path.

Parameters
augaugeas wrapper (NULL uses global interpreter)
pathpath to lookup
Return values
*valuereturned value (malloc'd)
Returns
-1 if multiple paths, 0 if none, 1 on success

Definition at line 194 of file rpmaug.c.

Referenced by cmd_get(), cmd_ls(), and cmd_match().

static rpmaug rpmaugGetPool ( rpmioPool  pool)
static

Definition at line 60 of file rpmaug.c.

References _rpmaugPool, rpmaugFini(), rpmioGetPool(), and rpmioNewPool().

Referenced by rpmaugNew().

int rpmaugInsert ( rpmaug  aug,
const char *  path,
const char *  label,
int  before 
)

Insert new sibling node before/after a given node.

Parameters
augaugeas wrapper (NULL uses global interpreter)
pathpath to node in tree
labellabel to insert
beforeinsert label into tree before path? (else after)
Returns
-1 on failure, 0 on success

Definition at line 222 of file rpmaug.c.

Referenced by cmd_ins().

int rpmaugLoad ( rpmaug  aug)

Load files/lenses from disk.

Parameters
augaugeas wrapper (NULL uses global interpreter)
Returns
-1 on error, 0 on success

Definition at line 292 of file rpmaug.c.

Referenced by cmd_load().

int rpmaugMatch ( rpmaug  aug,
const char *  path,
char ***  matches 
)

Return path(s) in tree that match an expression.

Parameters
augaugeas wrapper (NULL uses global interpreter)
pathpath expression to match
Return values
*matchespaths that match
Returns
no. of matches

Definition at line 264 of file rpmaug.c.

Referenced by child_count(), cmd_load(), cmd_ls(), cmd_match(), and cmd_save().

int rpmaugMv ( rpmaug  aug,
const char *  src,
const char *  dst 
)

Move src node to dst node.

Parameters
augaugeas wrapper (NULL uses global interpreter)
srcsrc path to node in tree
dstdst path to node in tree
Returns
-1 on failure, 0 on success

Definition at line 250 of file rpmaug.c.

Referenced by cmd_mv().

rpmaug rpmaugNew ( const char *  root,
const char *  loadpath,
unsigned int  flags 
)

Create and load a augeas wrapper.

Todo:
Change to common RPM embedded interpreter API.
Parameters
rootaugeas filesystem root
loadpathaugeas load path (colon separated)
flagsaugeas flags
Returns
new augeas wrapper

Definition at line 132 of file rpmaug.c.

References _rpmaugLoadpath, _rpmaugRoot, flags, rpmaugGetPool(), rpmaugLink(), rpmiobNew(), and xstrdup().

Referenced by expandMacro().

int rpmaugPrint ( rpmaug  aug,
FILE *  out,
const char *  path 
)

Print node paths that match an expression.

Parameters
augaugeas wrapper (NULL uses global interpreter)
outouput file (NULL uses stdout)
pathnode path expression
Returns
0 on success, <0 on error

Definition at line 306 of file rpmaug.c.

Referenced by cmd_print().

int rpmaugRm ( rpmaug  aug,
const char *  path 
)

Remove node and associated sub-tree.

Parameters
augaugeas wrapper (NULL uses global interpreter)
pathpath to node in tree to remove
Returns
-1 on failure, 0 on success

Definition at line 236 of file rpmaug.c.

Referenced by cmd_rm().

rpmRC rpmaugRun ( rpmaug  aug,
const char *  str,
const char **  resultp 
)

Run augeas commands from a buffer.

Parameters
augaugeas wrapper (NULL uses global interpreter)
straugeas commands to run
Return values
*resultpoutput running augeas commands
Returns
RPMRC_OK on success

Definition at line 763 of file rpmaug.c.

References _free(), rpmioP_s::ac, argvFree(), rpmioP_s::av, rpmaugFprintf(), rpmiobStr(), rpmioParse(), RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, and rpmioP_s::str.

Referenced by expandMacro().

int rpmaugSave ( rpmaug  aug)

Save changed files to disk, appending .augnew or .augsave as requested.

Parameters
augaugeas wrapper (NULL uses global interpreter)
Returns
-1 on error, 0 on success

Definition at line 278 of file rpmaug.c.

Referenced by cmd_save().

int rpmaugSet ( rpmaug  aug,
const char *  path,
const char *  value 
)

Set the value associated with a path.

Parameters
augaugeas wrapper (NULL uses global interpreter)
pathpath to lookup
valuevalue
Returns
-1 if multiple paths, 0 if none, 1 on success

Definition at line 208 of file rpmaug.c.

Referenced by cmd_clear(), and cmd_set().

Variable Documentation

const char _loadpath[] = ""
static

Definition at line 78 of file rpmaug.c.

const char _root[] = "/"
static

Definition at line 75 of file rpmaug.c.

int _rpmaug_debug = 0

Definition at line 33 of file rpmaug.c.

const struct poptOption _rpmaugCommandTable[]

Definition at line 683 of file rpmaug.c.

Referenced by cmd_help().

unsigned int _rpmaugFlags = 0

Definition at line 80 of file rpmaug.c.

Referenced by expandMacro().

rpmaug _rpmaugI = NULL

Definition at line 36 of file rpmaug.c.

Referenced by rpmioClean().

const char** _rpmaugLoadargv

Definition at line 107 of file rpmaug.c.

const char* _rpmaugLoadpath = _loadpath

Definition at line 79 of file rpmaug.c.

Referenced by expandMacro(), and rpmaugNew().

rpmioPool _rpmaugPool = NULL

Definition at line 58 of file rpmaug.c.

Referenced by rpmaugGetPool(), and rpmioClean().

const char* _rpmaugRoot = _root

Definition at line 76 of file rpmaug.c.

Referenced by expandMacro(), and rpmaugNew().

struct poptOption rpmaugPoptTable[]
Initial value:
= {
POPT_TABLEEND
}

Popt option table for options to configure Augeas augtool.

Definition at line 109 of file rpmaug.c.