#include "addritem.h"
#include "addrcache.h"
+#include "common/utils.h"
/*
* Key for thread specific data.
void ldapqry_set_search_value( LdapQuery *qry, const gchar *value ) {
ADDRQUERY_SEARCHVALUE(qry) = mgu_replace_string( ADDRQUERY_SEARCHVALUE(qry), value );
g_strstrip( ADDRQUERY_SEARCHVALUE(qry) );
+ debug_print("search value: %s\n", ADDRQUERY_SEARCHVALUE(qry));
}
/**
if( ( vals = ldap_get_values_len( ld, entry, attr ) ) != NULL ) {
for( i = 0; vals[i] != NULL; i++ ) {
- /* printf( "lv\t%s: %s\n", attr, vals[i] ); */
+ /*debug_print("lv\t%s: %s\n", attr, vals[i]->bv_val);*/
list = g_slist_append( list, g_strndup( vals[i]->bv_val, vals[i]->bv_len) );
}
}
if( ( vals = ldap_get_values_len( ld, entry, attr ) ) != NULL ) {
if( vals[0] != NULL ) {
- /* printf( "sv\t%s: %s\n", attr, vals[0] ); */
+ debug_print("sv\t%s: %s\n", attr, vals[0]->bv_val);
list = g_slist_append( list, g_strndup( vals[0]->bv_val, vals[0]->bv_len ));
}
}
addrcache_id_email( cache, email );
addrcache_person_add_email( cache, person, email );
addritem_person_add_email( person, email );
- /*addritem_print_item_email(email, stdout);*/
+ /*if (debug_get_mode()) {
+ addritem_print_item_email(email, stdout);
+ }*/
listReturn = g_list_append( listReturn, email );
nodeAddress = g_slist_next( nodeAddress );
}
listReturn = NULL;
ctl = qry->control;
dnEntry = ldap_get_dn( ld, e );
- /* printf( "DN: %s\n", dnEntry ); */
+ debug_print( "DN: %s\n", dnEntry );
/* Process all attributes */
for( attribute = ldap_first_attribute( ld, e, &ber ); attribute != NULL;
gchar *uri = NULL;
/* Initialize connection */
- /* printf( "===ldapqry_connect===\n" ); */
- /* ldapqry_print( qry, stdout ); */
+ if (debug_get_mode()) {
+ debug_print("===ldapqry_connect===\n");
+ /*ldapqry_print(qry, stdout);*/
+ }
ctl = qry->control;
- /* ldapctl_print( ctl, stdout ); */
- /* printf( "======\n" ); */
+ /*if (debug_get_mode()) {
+ ldapctl_print(ctl, stdout);
+ debug_print("======\n");
+ }*/
ldapqry_touch( qry );
qry->startTime = qry->touchTime;
qry->elapsedTime = -1;
}
ldapqry_touch( qry );
- /*
- printf( "connected to LDAP host %s on port %d\n", ctl->hostName, ctl->port );
- */
+ debug_print("connected to LDAP host %s on port %d\n", ctl->hostName, ctl->port);
#ifdef USE_LDAP_TLS
/* Handle TLS */
ADDRQUERY_RETVAL(qry) = LDAPRC_TLS;
rc = ldap_start_tls_s( ld, NULL, NULL );
- /* printf( "rc=%d\n", rc );
- printf( "LDAP Status: set_option: %s\n", ldap_err2string( rc ) ); */
+ debug_print("rc=%d\n", rc);
+ debug_print("LDAP Status: set_option: %s\n", ldap_err2string( rc ) );
if( rc != LDAP_SUCCESS ) {
return ADDRQUERY_RETVAL(qry);
ADDRQUERY_RETVAL(qry) = LDAPRC_BIND;
if( ctl->bindDN ) {
if( * ctl->bindDN != '\0' ) {
- /* printf( "binding...\n" ); */
+ debug_print("binding...\n");
rc = claws_ldap_simple_bind_s( ld, ctl->bindDN, ctl->bindPass );
- /* printf( "rc=%d\n", rc ); */
+ debug_print("rc=%d\n", rc);
if( rc != LDAP_SUCCESS ) {
- /*
- printf( "LDAP Error: ldap_simple_bind_s: %s\n",
- ldap_err2string( rc ) );
- */
+ debug_print("LDAP Error: ldap_simple_bind_s: %s\n", ldap_err2string(rc));
return ADDRQUERY_RETVAL(qry);
}
}
/* Create LDAP search string */
criteria = ldapctl_format_criteria( ctl, ADDRQUERY_SEARCHVALUE(qry) );
- /* printf( "Search criteria ::%s::\n", criteria ); */
+ debug_print("Search criteria ::%s::\n", criteria);
/*
* Execute the search - this step may take some time to complete
ADDRQUERY_RETVAL(qry) = LDAPRC_TIMEOUT;
rc = ldap_search_ext_s( ld, ctl->baseDN, LDAP_SCOPE_SUBTREE, criteria,
attribs, 0, NULL, NULL, &timeout, 0, &result );
+ debug_print("LDAP Error: ldap_search_st: %d\n", rc);
+ debug_print("LDAP Error: ldap_search_st: %s\n", ldap_err2string(rc));
ldapctl_free_attribute_array( attribs );
g_free( criteria );
criteria = NULL;
searchFlag = TRUE;
}
else {
- /*
- printf( "LDAP Error: ldap_search_st: %d\n", rc );
- printf( "LDAP Error: ldap_search_st: %s\n", ldap_err2string( rc ) );
- */
+ debug_print("LDAP Error: ldap_search_st: %d\n", rc);
+ debug_print("LDAP Error: ldap_search_st: %s\n", ldap_err2string(rc));
return ADDRQUERY_RETVAL(qry);
}
ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG;
- /*
- printf( "Total results are: %d\n", ldap_count_entries( ld, result ) );
- */
+ debug_print("Total results are: %d\n", ldap_count_entries(ld, result));
/* Process results */
first = TRUE;
qry->callBackEntry( qry, ADDRQUERY_ID(qry), listEMail, qry->data );
}
else {
- /*GList *node = listEMail;
- while (node) {
- addritem_print_item_email(node->data, stdout);
- node = g_list_next(node);
+ /*if (debug_get_mode()) {
+ GList *node = listEMail;
+ while (node) {
+ addritem_print_item_email(node->data, stdout);
+ node = g_list_next(node);
+ }
}*/
g_list_free( listEMail );
}
qry->server->addressCache->dataRead = TRUE;
qry->server->addressCache->accessFlag = FALSE;
if( ldapqry_get_stop_flag( qry ) ) {
- /*
- printf( "Search was terminated prematurely\n" );
- */
+ debug_print("Search was terminated prematurely\n");
}
else {
ldapqry_touch( qry );
qry->completed = TRUE;
- /*
- printf( "Search ran to completion\n" );
- */
+ debug_print("Search ran to completion\n");
}
}
ldapqry_set_stop_flag( qry, TRUE );
ldapqry_touch( qry );
if( ldapqry_check_search( qry ) ) {
if( ADDRQUERY_RETVAL(qry) == LDAPRC_SUCCESS ) {
- /*
- printf( "Starting LDAP search thread\n");
- */
+ debug_print("Starting LDAP search thread\n");
ldapqry_set_busy_flag( qry, TRUE );
qry->thread = g_malloc0( sizeof( pthread_t ) );
LdapQuery *qry;
qry = ( LdapQuery * ) ptr;
- /*
- printf( "ldapqry_destroyer::%d::%s\n", (int) pthread_self(), ADDRQUERY_NAME(qry) );
- */
+ debug_print("ldapqry_destroyer::%d::%s\n", (int) pthread_self(), ADDRQUERY_NAME(qry));
/* Perform any destruction here */
if( qry->control != NULL ) {
void ldapqry_cancel( LdapQuery *qry ) {
g_return_if_fail( qry != NULL );
- /*
- printf( "cancelling::%d::%s\n", (int) pthread_self(), ADDRQUERY_NAME(qry) );
- */
+ debug_print("cancelling::%d::%s\n", (int) pthread_self(), ADDRQUERY_NAME(qry));
if( ldapqry_get_busy_flag( qry ) ) {
if( qry->thread ) {
- /* printf( "calling pthread_cancel\n" ); */
+ debug_print("calling pthread_cancel\n");
pthread_cancel( * qry->thread );
}
}
* any LDAP queries to initialize thread specific data.
*/
void ldapqry_initialize( void ) {
- /* printf( "ldapqry_initialize...\n" ); */
+ debug_print("ldapqry_initialize...\n");
if( ! _queryThreadInit_ ) {
- /*
- printf( "ldapqry_initialize::creating thread specific area\n" );
- */
+ debug_print("ldapqry_initialize::creating thread specific area\n");
pthread_key_create( &_queryThreadKey_, ldapqry_destroyer );
_queryThreadInit_ = TRUE;
}
- /* printf( "ldapqry_initialize... done!\n" ); */
+ debug_print("ldapqry_initialize... done!\n");
}
/**
}
ADDRQUERY_RETVAL(qry) = LDAPRC_SEARCH;
if( rc != LDAP_SUCCESS ) {
- /*
- printf( "LDAP Error: ldap_search_st: %s\n", ldap_err2string( rc ) );
- */
+ debug_print("LDAP Error: ldap_search_st: %s\n", ldap_err2string(rc));
return ADDRQUERY_RETVAL(qry);
}
- /*
- printf( "Total results are: %d\n", ldap_count_entries( ld, result ) );
- */
+ debug_print("Total results are: %d\n", ldap_count_entries(ld, result));
/* Process results */
ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG;
return retVal;
}
+void ldapqry_print(LdapQuery *qry, FILE *stream) {
+ ldapsvr_print_data(qry->server, stream);
+ ldapctl_print(qry->control, stream);
+ fprintf(stream, "entriesRead: %d\n", qry->entriesRead);
+ fprintf(stream, "elapsedTime: %d\n", qry->elapsedTime);
+ fprintf(stream, "stopFlag: %d\n", qry->stopFlag);
+ fprintf(stream, "busyFlag: %d\n", qry->busyFlag);
+ fprintf(stream, "agedFlag: %d\n", qry->agedFlag);
+ fprintf(stream, "completed: %d\n", qry->completed);
+ fprintf(stream, "startTime: %d\n", (int) qry->startTime);
+ fprintf(stream, "touchTime: %d\n", (int) qry->touchTime);
+ fprintf(stream, "data: %s\n", (gchar *) qry->data);
+}
+
#endif /* USE_LDAP */
/*