Previous Topic: Language Client APINext Topic: Query: Entity Handling Operations


The CA ControlMinder Database

The LCA can update and query a CA ControlMinder local, remote, or PMDB. The Administration API can only query the database at the local station.

The following diagram shows the layout of a CA ControlMinder database:

Sample Program

The following sample program receives a command and, optionally, a list of property names as command line arguments. The program assumes that the command is a selang command, and that the property names should appear in the same format as displayed by the dbmgr -d -r p ClassName command (in older versions of CA ControlMinder, as displayed by the rdbdump p command).

The program invokes the lca_ParseLine function to execute the command. After execution, the results are analyzed.

If the command succeeds, the API routines that handle the query data are called, and the results of the queries are displayed. (No query information displays if the command was not a query.) If a list of properties was supplied, only data for those properties appear. If the command fails, the API routines that analyze the error are called.

#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <seostype.h>
#include <langapi.h>


static void scan_entities(void);
static void print_entity_info(LCA_QENT_H entity_handle);
static void scan_props(LCA_QENT_H entity_handle);
static void print_prop_info(LCA_QPROP_H prop_handle);
static void scan_values(LCA_QPROP_H prop_handle);
static void print_prop_value(LCA_QPROP_H prop_handle,void *prop_value);


static char  *Command = NULL;
static char **Properties = NULL;
static int    NProps = 0;

static void put_commands(int argc,char **argv);

int ShowUsage(void)
{
  fprintf( stderr, “Usage:\n
                    lca_examp Command [{List‑of‑property‑names}]\n”);
  return 1;
}

int main(int argc,char **argv) 
{
  char  *output = NULL;
  int   rv;
  int   n_ents;
  char  buff [1025];
     /****************** Initialization ***********************/
     /********************************************************/

    if ( argc < 2 )
        return ShowUsage();
    
    rv = lca_Init(“langapi”,&output);
    if ( rv )
    {
        printf( “Return value: 0x%08x\n”
              “Msg: '%s'\n”, rv, output );
        return 1;
    }

    put_commands(‑‑argc,++argv);

     /************** Execution of command **********************/
     /********************************************************/
  
    rv = lca_ParseLine(Command, &output);
    /* print the command output */
    printf(“Command's output\n%s\n”, output);

    if (rv == 0) 
    {

     /************ Success ‑ get the results *******************/
     /********************************************************/


     /** Get number of entities (objects) that were returned ***/
     /********************************************************/


        n_ents = lca_QEntsGetNum();
        printf(“number of entities returned: %d\n”,n_ents);


     /******* Get the names of the entities (objects) *********/
     /********************************************************/

        scan_entities();
    } 
    else 
    {


     /******************* The command failed ******************/
     /********************************************************/

        LCA_ERR_H error_handle = NULL;


     /*********************************************************
     * For further analysis of the error, review all errors 
     * (usually there is only one, but if there are warnings as
     * well as errors, there could be more than one in the list).
     *********************************************************/

        printf(“Numbers of errors: %d\n\n”,lca_ErrsGetNum());
        while ((error_handle = lca_ErrGetNext(error_handle))
                                                       != 0) 
        {
            printf(“Severity: %d, Stage:%d\n”,
                                lca_ErrSeverity(error_handle),
                                lca_ErrStage   (error_handle));

     rv = lca_Err2Str (error_handle, buff, sizeof (buff)‑1); 
            if ( rv ) 
                printf (“Error message: '%s'\n”, buff);
        }
      }
    
     /************** Terminate the use of lca_ API **************/
     /********************************************************/

  lca_Terminate();
  return 0; 
}

static void put_commands(int argc,char **argv)
{
  Command = argv[0];
  Properties = ++argv;
  NProps = ‑‑argc;
}

static void scan_entities(void)
{
  LCA_QENT_H entity_handle = NULL;

while ( (entity_handle = lca_QEntGetNext(entity_handle)) != 0 )
      print_entity_info(entity_handle);
}

/**************************************************************
Print the information for one entity, including its name, class name, and information about its properties.
If the entity is a class, the “name” will be empty, and the “class name” full. 
If the entity is an object, the “name” will be full, and the “class name” empty.
*************************************************************/


static void print_entity_info(LCA_QENT_H entity_handle)
{
  char    *name;

  if ( entity_handle == 0 )
    return;
  
  name = lca_QEntObjName(entity_handle);
  if ( name != 0 )
    printf(“\nName: %s\t”,name);
  name = lca_QEntClassName(entity_handle);
  if ( name != 0 )
    printf(“Class name: %s\n”,name);

  scan_props(entity_handle);

}

static void scan_props(LCA_QENT_H entity_handle)
{
  LCA_QPROP_H prop_handle = NULL;
  register int i;

    if ( NProps == 0 )
        while ( (prop_handle = lca_QPropGetNext(entity_handle,prop_handle)) != 0)
            print_prop_info(prop_handle);
    else
    for ( i = 0; i < NProps; i++ )
    {
        prop_handle = lca_QPropGetByName(entity_handle,Properties[i]);
        if ( prop_handle == 0 )
        {
            printf(“Property %s does not exist for this entity.\n”,
                           Properties[i]); 
            continue;
        }
        print_prop_info(prop_handle);
    } 
}

/*************************************************************
  This function gets a property handle, and:
  1. Gets its name and prints it.
  2. Gets its value, translates it to a string, and prints it.
*************************************************************/

static void print_prop_info(LCA_QPROP_H prop_handle)
{
  char *prop_name = NULL;
  char prop_type;
  unsigned short prop_size;
  unsigned int n_vals;

  if ( prop_handle == 0 )
    return;

  prop_name = lca_QPropName(prop_handle);
  if ( prop_name == 0 )
    printf(“Cannot get name of property. Handle: %d\n”,
                  prop_handle);
  
  printf(“\nPropname: %s.”,prop_name);

  prop_type = lca_QPropType(prop_handle);
  printf(“Property type: %d; “,prop_type);

  prop_size = lca_QPropSize(prop_handle);
  printf(“Property size: %d; “,prop_size);

  n_vals = lca_QPropValsNum(prop_handle);
  printf(“Number of values: %d.\n”,n_vals);


/* Loop over the property values, because there could be more
than one value for a property.
This happens if properties are of type list (ACLs, PACLs, User
list, Member list and so on).
*/

  scan_values(prop_handle);

}

static void scan_values(LCA_QPROP_H prop_handle)
{
  void *prop_value;
  int i;
  int n_vals;

    n_vals = lca_QPropValsNum(prop_handle);
    for ( i=0; i<n_vals; i++) 
    {
      prop_value = lca_QPropValGetByIdx(prop_handle,i);
      print_prop_value(prop_handle,prop_value);
    }
}

static void print_prop_value(LCA_QPROP_H prop_handle,void 
      *prop_value)
{
  char buff[1024];
  int n_vals;

  if ( prop_handle == 0 || prop_value ==0 )
    return;
  n_vals= lca_QPropVal2Str(prop_handle,prop_value,buff,sizeof(buff));
  if ( n_vals > 0 )
    printf(“Value: %s\n”,buff);
}

Functions

The LCA includes functions in the following categories:

The langapi.h file contains a basic description of each LCA function. The langapi.h file is located in the following directory:

Execution Operations

The following functions control LCA operations:

lca_Init

Initializes the LCA.

lca_InitWithType

Initializes the LCA with a specific communication type that triggers specific functionality.

lca_Terminate

Terminates the LCA.

lca_ParseLine

Performs selang commands.

lca_ParseMBLine

Performs selang commands and lets you input multibyte format strings.

lca_SetHosts

Connects to a list of one or more hosts.

Password Operations

The following functions control LCA passwords:

lca_CheckPasswordQuality

Checks new passwords for adherence to password rules.

Error Handling Operations

The following functions operate on errors. The errors are generated by execution operation functions:

lca_ErrsGetNum

Returns the number of error records for the last executed command.

lca_ErrGetByIdx

Returns an error handle of type LCA_ERR_H for the Nth error record.

lca_ErrGetFirst

Returns an error handle of type LCA_ERR_H for the first error in a command.

lca_ErrGetNext

Returns an error handle of type LCA_ERR_H for the next error in a command.

lca_ErrMajCode

Returns the major error code for an error.

lca_ErrMinCode

Returns the minor error code for an error.

lca_ErrMajStrs

Returns the information string for the major error code for an error.

lca_ErrMinStrs

Returns the information string for the minor error code for an error.

lca_ErrSeverity

Returns the severity level of an error.

lca_ErrStage

Returns information about when the error occurred.

lca_Err2Str

Converts an error record to string format and copies it to a buffer.