Improve error reporting in getdns_query.

This commit is contained in:
Sara Dickinson 2015-06-23 17:01:43 +01:00
parent c425f96e0b
commit c9a0ffc7a5
1 changed files with 19 additions and 7 deletions

View File

@ -181,18 +181,20 @@ void callback(getdns_context *context, getdns_callback_type_t callback_type,
free(response_str); free(response_str);
} }
fprintf(stderr, fprintf(stderr,
"The callback with ID %llu was successfull.\n", "Result: The callback with ID %llu was successfull.\n",
(unsigned long long)trans_id); (unsigned long long)trans_id);
} else if (callback_type == GETDNS_CALLBACK_CANCEL) } else if (callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, fprintf(stderr,
"The callback with ID %llu was cancelled. Exiting.\n", "Result: The callback with ID %llu was cancelled. Exiting.\n",
(unsigned long long)trans_id); (unsigned long long)trans_id);
else else
fprintf(stderr, fprintf(stderr,
"The callback got a callback_type of %d. Exiting.\n", "Result: The callback got a callback_type of %d. Exiting.\n",
callback_type); callback_type);
fprintf(stderr,
"Error : '%s'\n",
getdns_get_errorstr_by_id(callback_type));
getdns_dict_destroy(response); getdns_dict_destroy(response);
response = NULL; response = NULL;
} }
@ -522,8 +524,10 @@ main(int argc, char **argv)
if (!fgets(line, 1024, stdin) || !*line) if (!fgets(line, 1024, stdin) || !*line)
break; break;
} else { } else {
if (!fgets(line, 1024, fp) || !*line) if (!fgets(line, 1024, fp) || !*line) {
fprintf(stdout,"End of file.");
break; break;
}
fprintf(stdout,"Found query: %s", line); fprintf(stdout,"Found query: %s", line);
} }
@ -531,6 +535,10 @@ main(int argc, char **argv)
linec = 1; linec = 1;
if ( ! (token = strtok(line, " \t\f\n\r"))) if ( ! (token = strtok(line, " \t\f\n\r")))
continue; continue;
if (*token == '#') {
fprintf(stdout,"Result: Skipping comment\n");
continue;
}
do linev[linec++] = token; do linev[linec++] = token;
while (linec < 256 && while (linec < 256 &&
(token = strtok(NULL, " \t\f\n\r"))); (token = strtok(NULL, " \t\f\n\r")));
@ -611,8 +619,12 @@ main(int argc, char **argv)
fprintf( stderr fprintf( stderr
, "Could not print response\n"); , "Could not print response\n");
} }
} else if (r == GETDNS_RETURN_GOOD) } else if (r == GETDNS_RETURN_GOOD) {
fprintf(stdout, "Response code was: GOOD\n"); uint32_t status;
getdns_dict_get_int(response, "status", &status);
fprintf(stdout, "Response code was: GOOD. Status was: %s\n",
getdns_get_errorstr_by_id(status));
}
else if (interactive) else if (interactive)
fprintf(stderr, "An error occurred: %d\n", r); fprintf(stderr, "An error occurred: %d\n", r);
} }