LDAP Directory Synchronizer
Online Documentation

HOME NEXT PREVIOUS

User Written Procedures

LDSU provides several ways to easily include User Written Procedures to help manipulate data if needed. These include Pre and Post Processors which the LDSU scripts call before or after LDSU runs, or Procedures which are called out by LDSU to determine field values or generate a unique field value.

Pre and Post Processors

Although the RDF files are very powerful and can manipulate data in many ways, sometimes the data must be further processed before an import or after an export. This calls for a user-written Pre or Post processor to be run to format the data.

The LDSU Scripts have a built in way to call optional user written pre and post processors before an import or after an export if needed. (See the LDSU scripts section for exact filenames. and the order of parameters which specify the name of the input file(s) and output file(s) to be converted.)

For Pre Processors, used in Import, Transaction, Export1, and Changes1 Modes on input files, the LDSU script files look for a specifically named file to run in the instance subdirectory before running LDSU to convert the input file.

For Post Processors, used in all Export and Changes Modes on output files, the LDSU script files look for a specifically named file to run in the instance subdirectory after running LDSU to convert the output file.

RDF $SYSTEM Function User Written Procedure

When specifying a $SYSTEM function in a RDF file, a user-specified procedure is called to return a string to be assigned to an RDF field (on import) or file location (on export).

The $SYSTEM function contains three arguments. The first argument is the name of the procedure to run in double quotes. The second and third arguments are optional arguments which are passed to the procedure specified in the first argument. These can be fields, constant strings, file locations, etc.

The way the RDF $SYSTEM function returns a value depends on the operating system that LDSU is being run on.

On Windows NT and Unix, the value is returned through the stdout pipe. On OpenVMS, the value is returned through the job logical name LDSU_RDF_VAL. Here are examples for each Operating System type:

Windows NT example of using an RDF $SYSTEM function

import.rdf

    Extension-Attribute-1 = $SYSTEM("program1", 1-1, 1-2)

program1.bat

    @ECHO OFF
    REM
    REM return the value of the first two fields
    REM
    echo %1 %2

Digital UNIX example of using an RDF $SYSTEM function

import.rdf

    Extension-Attribute-1 = $SYSTEM("program1", 1-1, 1-2)

program1 (must be executable)

    #!/usr/bin/ksh
    #
    # program1
    #
    # $1 - field 1
    # $2 - field 2
    #
     echo "$2 $3"

OpenVMS example of using an RDF $SYSTEM function

import.rdf

    Extension-Attribute-1 = $SYSTEM("@program1", 1-1, 1-2)

PROGRAM1.COM

    $!
    $! PROGRAM1.COM
    $!
    $!    p1 - field 1
    $!    p2 - field 2
    $!
    $ val = P1 + " " + P2
    $ define/job LDSU_RDF_VALUE "''val'"
    $ exit

MAKE_UNIQUE_PROGRAM User Written Procedure

When specifying a make_unique_field, a make_unique_program may be specified in ldsu_config.dat to determine the unique value.

This causes LDSU to call the make_unique_program whenever the initial value for make_unique_field is not unique to determine a unique value, and continue calling it until a unique value is found.

The make_unique_program can specify a command procedure or executable with the fields listed in make_unique_params as the parameters. The attempt number will also be passed to the user program as a parameter. The user program will then return another unique field value to try. This will be repeated until a successful unique value is generated.

The way the make_unique_program returns a unique value depends on the operating system that LDSU is being run on.

On Windows NT and Unix, the value is returned through the stdout pipe. On OpenVMS, the value is returned through the job logical name LDSU_UNIQUE_FIELD_VALUE. Here are examples for each Operating System type:

Windows NT example of using make_unique_program

ldsu_config.dat parameters:

    make_unique_field    = emailUSE3
    make_unique_program  = make_unique
    make_unique_params   = surname,givenname

import.rdf

    emailUSE3 = surname

make_unique.c (compiled into make_unique.exe)

    /*
     * make_unique.c
     *
     * arg1 - attempt number (0-N)
     * arg2 - surname
     * arg3 - givenName
     */
    #include 
    #include 
    #include 
    #include 

    main(int argc, char *argv[])
    {
	if (argc < 3) printf("");	/* return null to terminate checking */
	else {
	    if (strcmp(argv[1], "0") == 0) {
		printf("%s%.1s", argv[2], argv[3])  /* last + first one */
	    } else if (strcmp(argv[1], "1") == 0) {
		printf("%s%.2s", argv[2], argv[3])  /* last + first two */
	    } else {
		printf("%s%.2s%s", argv[2], argv[3], argv[1])  /* last + first two + N */
	    }
	}
    }

Digital UNIX example of using make_unique_program

ldsu_config.dat parameters:

    make_unique_field    = emailUSE3
    make_unique_program  = ./make_unique
    make_unique_params   = surname,givenname

import.rdf

    emailUSE3 = surname

make_unique  (must be executable)

    #!/usr/bin/ksh
    #
    # make_unqiue
    #
    # $1 - attempt number (0-N)
    # $2 - surname
    # $3 - givenName
    #
    if [[ $1 -eq 0 ]]
    then
      typeset -L1 s=$3
      echo "$2$s"        # last + first one
    elif [[ $1 -eq 1 ]]
    then
      typeset -L2 s=$3
      echo "$2$s"        # last + first two
    else
      typeset -L2 s=$3
      echo "$2$s$1"      # last + first two + N
    fi

OpenVMS example of using make_unique_program

LDSU_CONFIG.DAT parameters:

    make_unique_field    = emailUSE3
    make_unique_program  = @MAKE_UNIQUE.COM
    make_unique_params   = surname,givenname

IMPORT.RDF

    emailUSE3 = surname

MAKE_UNIQUE.COM

    $!
    $! MAKE_UNIQUE.COM
    $!
    $!    p1 - Attempt Number (0 to N)
    $!    p2 - Last Name
    $!    p3 - First Name
    $!
    $ if P1 .eqs. "0"
    $ then
    $    val = P2 + f$extract(0,1,P3)    ! LAST + FIRST ONE
    $ else
    $ if P1 .eqs. "1"
    $ then
    $    val = P2 + f$extract(0,2,P3)    ! LAST + FIRST TWO
    $ else
    $    val = P2 + f$extract(0,2,P3) + P1 ! LAST + FIRST TWO + N
    $ endif
    $ endif
    $!
    $ define/job LDSU_UNIQUE_FIELD_VALUE "''val'"
    $ exit



HOME NEXT PREVIOUS

Digital Copyright © Digital Equipment Corporation 1998