<commit_before>/*
 * Copyright (c) 2005, <NAME> and IFS Institute for Software at HSR Rapperswil, Switzerland
 * All rights reserved.
 *
 * This library/application is free software; you can redistribute and/or modify it under the terms of
 * the license that is included with this library/application in the file license.txt.
 */

//--- interface include --------------------------------------------------------
#include "LDAPConnection.h"

//--- project modules used -----------------------------------------------------
#include "LDAPMessageEntry.h"
#include "LDAPConnectionManager.h"
#include "ldap-extension.h"

//--- standard modules used ----------------------------------------------------
#include "Dbg.h"
#include "Threads.h"
#include "StringStream.h"
#include "TimeStamp.h"

//--- c-modules used -----------------------------------------------------------

//int LDAP_CALL LDAP_CALLBACK LDAPConnection::RebindProc( LDAP *ld, char **dnp, char **passwdp, int *authmethodp, int freeit, void *arg )
//{
//  cerr << "Rebindproc called" << endl;
//  switch ( freeit ) {
//  /* Your client calls the rebind function with freeit==1 when it needs
//    to free any memory you've allocated. */
//  case 1:
//    cerr << "Freeing memory" << endl;
//    if ( dnp && *dnp ) {
//      free( *dnp );
//    }
//    if ( passwdp && *passwdp ) {
//      free( *passwdp );
//    }
//    break;
//  /* Your client calls the rebind function with freeit==0 when it needs
//  to get the DN, credentials, and authentication method. */
//  case 0:
//    cerr << "Getting DN and credentials." << endl;
//    *dnp = strdup( "cn=Directory Manager" );
//    *passwdp = strdup( "<PASSWORD>" );
//    *authmethodp = LDAP_AUTH_SIMPLE;
//    break;
//  default:
//    cerr << "Unknown value of freeit argument: " <<  freeit  << endl;
//    break;
//  }
//  /* If you successfully set the DN and credentials, you should return
//    LDAP_SUCCESS. (Any other return code will stop the client from
//    automatically following the referral. */
//  return LDAP_SUCCESS;
//}

LDAPConnection::LDAPConnection(ROAnything connectionParams)
{
	StartTrace(LDAPConnection.LDAPConnection);
	fServer = connectionParams["Server"].AsString("localhost");
	fPort = connectionParams["Port"].AsLong(389L);
	fSearchTimeout  = (int) connectionParams["Timeout"].AsLong(60L);
	// A reasonable connection timeout default
	fConnectionTimeout = connectionParams["ConnectionTimeout"].AsLong(10);
	fConnectionTimeout *= 1000;
	fMapUTF8 = connectionParams["MapUTF8"].AsBool(true);
	fUseLdapConnectionManager = ( bool ) connectionParams["PooledConnections"].AsLong(0L);
	fRebindTimeout = connectionParams["RebindTimeout"].AsLong(0L);
	TraceAny(connectionParams, "ConnectionParams");
}

LDAPConnection::~LDAPConnection()
{
	if ( !fUseLdapConnectionManager ) {
		Disconnect();<commit_msg>corrected boolean test<commit_after>/*
 * Copyright (c) 2005, <NAME> and IFS Institute for Software at HSR Rapperswil, Switzerland
 * All rights reserved.
 *
 * This library/application is free software; you can redistribute and/or modify it under the terms of
 * the license that is included with this library/application in the file license.txt.
 */

//--- interface include --------------------------------------------------------
#include "LDAPConnection.h"

//--- project modules used -----------------------------------------------------
#include "LDAPMessageEntry.h"
#include "LDAPConnectionManager.h"
#include "ldap-extension.h"

//--- standard modules used ----------------------------------------------------
#include "Dbg.h"
#include "Threads.h"
#include "StringStream.h"
#include "TimeStamp.h"

//--- c-modules used -----------------------------------------------------------

//int LDAP_CALL LDAP_CALLBACK LDAPConnection::RebindProc( LDAP *ld, char **dnp, char **passwdp, int *authmethodp, int freeit, void *arg )
//{
//  cerr << "Rebindproc called" << endl;
//  switch ( freeit ) {
//  /* Your client calls the rebind function with freeit==1 when it needs
//    to free any memory you've allocated. */
//  case 1:
//    cerr << "Freeing memory" << endl;
//    if ( dnp && *dnp ) {
//      free( *dnp );
//    }
//    if ( passwdp && *passwdp ) {
//      free( *passwdp );
//    }
//    break;
//  /* Your client calls the rebind function with freeit==0 when it needs
//  to get the DN, credentials, and authentication method. */
//  case 0:
//    cerr << "Getting DN and credentials." << endl;
//    *dnp = strdup( "cn=Directory Manager" );
//    *passwdp = strdup( "<PASSWORD>" );
//    *authmethodp = LDAP_AUTH_SIMPLE;
//    break;
//  default:
//    cerr << "Unknown value of freeit argument: " <<  freeit  << endl;
//    break;
//  }
//  /* If you successfully set the DN and credentials, you should return
//    LDAP_SUCCESS. (Any other return code will stop the client from
//    automatically following the referral. */
//  return LDAP_SUCCESS;
//}

LDAPConnection::LDAPConnection(ROAnything connectionParams)
{
	StartTrace(LDAPConnection.LDAPConnection);
	fServer = connectionParams["Server"].AsString("localhost");
	fPort = connectionParams["Port"].AsLong(389L);
	fSearchTimeout  = (int) connectionParams["Timeout"].AsLong(60L);
	// A reasonable connection timeout default
	fConnectionTimeout = connectionParams["ConnectionTimeout"].AsLong(10);
	fConnectionTimeout *= 1000;
	fMapUTF8 = connectionParams["MapUTF8"].AsBool(true);
	fUseLdapConnectionManager = ( connectionParams["PooledConnections"].AsLong(0L) > 0L );
	fRebindTimeout = connectionParams["RebindTimeout"].AsLong(0L);
	TraceAny(connectionParams, "ConnectionParams");
}

LDAPConnection::~LDAPConnection()
{
	if ( !fUseLdapConnectionManager ) {
		Disconnect();
{'fraction_non_alphanumeric': 0.20944160648229698, 'fraction_numerical': 0.008279020609476837, 'mean_word_length': 2.6632258064516128, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2748479', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1636, 'n_words': 465}