/*% * Loops through the list of DB instances, attempting to lock * on the mutex. If successful, the DBI is reserved for use * and the thread can perform queries against the database. * If the lock fails, the next one in the list is tried. * looping continues until a lock is obtained, or until * the list has been searched dbc_search_limit times. * This function is only used when the module is compiled for * multithreaded operation. */ static dbinstance_t * mysql_find_avail_conn(mysql_instance_t *mysql) { dbinstance_t *dbi = NULL, *head; int count = 0; /* get top of list */ head = dbi = DLZ_LIST_HEAD(*(mysql->db)); /* loop through list */ while (count < dbc_search_limit) { /* try to lock on the mutex */ if (dlz_mutex_trylock(&dbi->lock) == 0) return (dbi); /* success, return the DBI for use. */ /* not successful, keep trying */ dbi = DLZ_LIST_NEXT(dbi, link); /* check to see if we have gone to the top of the list. */ if (dbi == NULL) { count++; dbi = head; } } mysql->log(ISC_LOG_INFO, "MySQL module unable to find available connection " "after searching %d times", count); return (NULL); }
void destroy_querylist(query_list_t **querylist) { query_segment_t *tseg = NULL; query_segment_t *nseg = NULL; /* if query list is null, nothing to do */ if (*querylist == NULL) return; /* start at the top of the list */ nseg = DLZ_LIST_HEAD(**querylist); while (nseg != NULL) { /* loop, until end of list */ tseg = nseg; /* * free the query segment's text string but only if it * was really a query segment, and not a pointer to * %zone%, or %record%, or %client% */ if (tseg->cmd != NULL && tseg->direct == ISC_TRUE) free(tseg->cmd); /* get the next query segment, before we destroy this one. */ nseg = DLZ_LIST_NEXT(nseg, link); /* deallocate this query segment. */ free(tseg); } /* deallocate the query segment list */ free(*querylist); }
/*% * build a query string from query segments, and dynamic segments * dynamic segments replace where the tokens %zone%, %record%, %client% * used to be in our queries from named.conf */ char * build_querystring(query_list_t *querylist) { query_segment_t *tseg = NULL; unsigned int length = 0; char *qs = NULL; /* start at the top of the list */ tseg = DLZ_LIST_HEAD(*querylist); while (tseg != NULL) { /* * if this is a query segment, use the * precalculated string length */ if (tseg->direct == ISC_TRUE) length += tseg->strlen; else /* calculate string length for dynamic segments. */ length += strlen(* (char**) tseg->cmd); /* get the next segment */ tseg = DLZ_LIST_NEXT(tseg, link); } /* allocate memory for the string */ qs = malloc(length + 1); /* couldn't allocate memory, We need more ram! */ if (qs == NULL) return (NULL); *qs = 0; /* start at the top of the list again */ tseg = DLZ_LIST_HEAD(*querylist); while (tseg != NULL) { if (tseg->direct == ISC_TRUE) /* query segments */ strcat(qs, tseg->cmd); else /* dynamic segments */ strcat(qs, * (char**) tseg->cmd); /* get the next segment */ tseg = DLZ_LIST_NEXT(tseg, link); } return (qs); }
/*% * Properly cleans up a list of database instances. * This function is only used when the module is compiled for * multithreaded operation. */ static void mysql_destroy_dblist(db_list_t *dblist) { dbinstance_t *ndbi = NULL; dbinstance_t *dbi = NULL; ndbi = DLZ_LIST_HEAD(*dblist); while (ndbi != NULL) { dbi = ndbi; ndbi = DLZ_LIST_NEXT(dbi, link); mysql_destroy(dbi); } /* release memory for the list structure */ free(dblist); }
/*% * Properly cleans up a list of database instances. * This function is only used when the driver is compiled for * multithreaded operation. */ static void ldap_destroy_dblist(db_list_t *dblist) { dbinstance_t *ndbi = NULL; dbinstance_t *dbi = NULL; /* get the first DBI in the list */ ndbi = DLZ_LIST_HEAD(*dblist); /* loop through the list */ while (ndbi != NULL) { dbi = ndbi; /* get the next DBI in the list */ ndbi = DLZ_LIST_NEXT(dbi, link); /* release DB connection */ if (dbi->dbconn != NULL) ldap_unbind_s((LDAP *) dbi->dbconn); /* release all memory that comprised a DBI */ destroy_dbinstance(dbi); } /* release memory for the list structure */ free(dblist); }