Back to index

openldap  2.4.31
Classes | Functions | Variables
dnreverse.cpp File Reference
#include <stdlib.h>
#include <TTConnectionPool.h>
#include <TTConnection.h>
#include <TTCmd.h>
#include <TTXla.h>
#include <signal.h>

Go to the source code of this file.

Classes

class  LDAPEntriesHandler

Functions

void onintr (int sig)
int main (int argc, char *argv[])

Variables

TTConnectionPool pool
TTXlaConnection conn
TTConnection conn2
TTCmd assignDn_ru
TTCmd getNullDNs
int pleaseStop = 0

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 216 of file dnreverse.cpp.

{

  char* ownerP;

  TTXlaTableList list(&conn);      // List of tables to monitor

  // Handlers, one for each table we want to monitor

  LDAPEntriesHandler* sampP = NULL;

  // Misc stuff

  TTStatus stat;

  ttXlaUpdateDesc_t ** arry;

  int records;

  SQLUBIGINT  oldsize;
  int j;

  if (argc < 2) {
    cerr << "syntax: " << argv[0] << " <username>" << endl;
    exit(3);
  }

  ownerP = argv[1];

  signal(SIGINT, onintr);    /* signal for CTRL-C */
#ifdef _WIN32
  signal(SIGBREAK, onintr);  /* signal for CTRL-BREAK */
#endif

  // Before we do anything related to XLA, first we connect
  // to the database.  This is the connection we will use
  // to perform non-XLA operations on the tables.

  try {
    cerr << "Connecting..." << endl;

    conn2.Connect("DSN=ldap_tt", stat);
  }
  catch (TTStatus stat) {
    cerr << "Error connecting to TimesTen: " << stat;
    exit(1);
  }

  try {
    assignDn_ru.Prepare(&conn2,
                     "update ldap_entries set dn_ru=? where id=?", 
                     "", stat);
    getNullDNs.Prepare(&conn2,
                     "select dn, id from ldap_entries "
                     "where dn_ru is null "
                     "for update", 
                     "", stat);
    conn2.Commit(stat);
  }
  catch (TTStatus stat) {
    cerr << "Error preparing update: " << stat;
    exit(1);
  }

  // If there are any entries with a NULL reversed/upper cased DN, 
  // fix them now.

  try {
    cerr << "Fixing NULL reversed DNs" << endl;
    getNullDNs.Execute(stat);
    for (int k = 0;; k++) {
      getNullDNs.FetchNext(stat);
      if (stat.rc == SQL_NO_DATA_FOUND) break;
      char* dnP;
      int   id;
      getNullDNs.getColumn(1, &dnP);
      getNullDNs.getColumn(2, &id);
      // cerr << "Id " << id << ", Dn '" << dnP << "'" << endl;
      LDAPEntriesHandler::ReverseAndUpper(dnP, id, false);
      if (k % 1000 == 0) 
        cerr << ".";
    }
    getNullDNs.Close(stat);
    conn2.Commit(stat);
  }
  catch (TTStatus stat) {
    cerr << "Error updating NULL rows: " << stat;
    exit(1);
  }


  // Go ahead and start up the change monitoring application

  cerr << "Starting change monitoring..." << endl;
  try {
    conn.Connect("DSN=ldap_tt", stat);
  }
  catch (TTStatus stat) {
    cerr << "Error connecting to TimesTen: " << stat;
    exit(1);
  }

  /* set and configure size of buffer */
  conn.setXlaBufferSize((SQLUBIGINT) 1000000, &oldsize, stat);
  if (stat.rc) {
    cerr << "Error setting buffer size " << stat << endl;
    exit(1);
  }

  // Make a handler to process changes to the MYDATA table and
  // add the handler to the list of all handlers

  sampP = new LDAPEntriesHandler(conn, ownerP, "ldap_entries");
  if (!sampP) {
    cerr << "Could not create LDAPEntriesHandler" << endl;
    exit(3);
  }
  list.add(sampP);

  // Enable transaction logging for the table we're interested in 

  sampP->EnableTracking(stat);

  // Get updates.  Dispatch them to the appropriate handler.
  // This loop will handle updates to all the tables.

  while (pleaseStop == 0) {
    conn.fetchUpdates(&arry, 1000, &records, stat);
    if (stat.rc) {
      cerr << "Error fetching updates" << stat << endl;
      exit(1);
    }

    // Interpret the updates

    for(j=0;j < records;j++){
      ttXlaUpdateDesc_t *p;

      p = arry[j];

      list.HandleChange(p, stat);

    } // end for each record fetched
    
    if (records) {
      cerr << "Processed " << records << " records\n";
    }

    if (records == 0) {
#ifdef _WIN32
      Sleep(250);
#else
      struct timeval t;
      t.tv_sec = 0;
      t.tv_usec = 250000; // .25 seconds
      select(0, NULL, NULL, NULL, &t);
#endif
    }
  } // end while pleasestop == 0
  

  // When we get to here, the program is exiting.

  list.del(sampP);          // Take the table out of the list 
  delete sampP;

  conn.setXlaBufferSize(oldsize, NULL, stat);

  return 0;

}

Here is the call graph for this function:

void onintr ( int  sig)

Definition at line 206 of file dnreverse.cpp.

  {
    pleaseStop = 1;
    cerr << "Stopping...\n";
  }

Here is the caller graph for this function:


Variable Documentation

TTCmd assignDn_ru

Definition at line 22 of file dnreverse.cpp.

TTXlaConnection conn

Definition at line 20 of file dnreverse.cpp.

TTConnection conn2

Definition at line 21 of file dnreverse.cpp.

TTCmd getNullDNs

Definition at line 23 of file dnreverse.cpp.

Definition at line 202 of file dnreverse.cpp.

TTConnectionPool pool

Definition at line 19 of file dnreverse.cpp.