bool foundzone = false;
bool foundrecord = false;
bool foundclient = false;
+ char *free_me = NULL;
char *temp_str = NULL;
- char *right_str = NULL;
query_list_t *tql;
query_segment_t *tseg = NULL;
- char *last;
+ char *last = NULL;
REQUIRE(querylist != NULL && *querylist == NULL);
REQUIRE(mctx != NULL);
ISC_LIST_INIT(*tql);
/* make a copy of query_str so we can chop it up */
- temp_str = right_str = isc_mem_strdup(mctx, query_str);
+ free_me = temp_str = isc_mem_strdup(mctx, query_str);
/* couldn't make a copy, problem!! */
- if (right_str == NULL) {
+ if (temp_str == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
/* loop through the string and chop it up */
- while (right_str != NULL) {
+ for (;;) {
+ /*
+ * Split string into tokens at '$'.
+ */
+ const char *sql = strtok_r(temp_str, "$", &last);
+ if (sql == NULL) {
+ break;
+ }
+ temp_str = NULL;
+
/* allocate memory for tseg */
tseg = isc_mem_get(mctx, sizeof(query_segment_t));
if (tseg == NULL) { /* no memory, clean everything up. */
/* append the query segment to the list */
ISC_LIST_APPEND(*tql, tseg, link);
- /*
- * split string at the first "$". set query segment to
- * left portion
- */
- last = NULL;
- tseg->sql = isc_mem_strdup(mctx,
- strtok_r(right_str, "$", &last));
+ tseg->sql = isc_mem_strdup(mctx, sql);
if (tseg->sql == NULL) {
/* no memory, clean everything up. */
result = ISC_R_NOMEMORY;
*/
isc_mem_free(mctx, tseg->sql);
/* set tseg->sql to in-direct zone string */
- tseg->sql = (char**) zone;
+ tseg->sql = zone;
tseg->strlen = 0;
/* tseg->sql points in-directly to a string */
tseg->direct = false;
*/
isc_mem_free(mctx, tseg->sql);
/* set tseg->sql to in-direct record string */
- tseg->sql = (char**) record;
+ tseg->sql = record;
tseg->strlen = 0;
- /* tseg->sql points in-directly poinsts to a string */
+ /* tseg->sql points in-directly points to a string */
tseg->direct = false;
foundrecord = true;
/* check if we encountered "$client$" token */
*/
isc_mem_free(mctx, tseg->sql);
/* set tseg->sql to in-direct record string */
- tseg->sql = (char**) client;
+ tseg->sql = client;
tseg->strlen = 0;
- /* tseg->sql points in-directly poinsts to a string */
+ /* tseg->sql points in-directly points to a string */
tseg->direct = false;
foundclient = true;
}
}
/* we don't need temp_str any more */
- isc_mem_free(mctx, temp_str);
+ isc_mem_free(mctx, free_me);
/*
* add checks later to verify zone and record are found if
* necessary.
return (ISC_R_SUCCESS);
cleanup:
- /* get rid of temp_str */
- if (temp_str != NULL)
- isc_mem_free(mctx, temp_str);
+ /* get rid of free_me */
+ if (free_me != NULL)
+ isc_mem_free(mctx, free_me);
flag_fail:
/* get rid of what was build of the query list */