resolve.h 3.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

15 16
#ifndef ISC_RESOLVE_H
#define ISC_RESOLVE_H 1
17

18 19 20
/// This file includes all other libresolve headers, and provides
/// several helper functions used in resolving.

21 22
#include <resolve/resolver_interface.h>
#include <resolve/resolver_callback.h>
23
#include <resolve/response_classifier.h>
24

25 26
#include <dns/rcode.h>

27 28 29 30 31 32 33 34 35 36 37 38 39 40
namespace isc {
namespace resolve {

/// \brief Create an error response
///
/// Clears the answer, authority, and additional section of the
/// given MessagePtr and sets the given error code
///
/// Notes: Assuming you have already done initial preparations
/// on the given answer message (copy the opcode, qid and question
/// section), you can simply use this to create an error response.
///
/// \param answer_message The message to clear and place the error in
/// \param error_code The error Rcode
41
void makeErrorMessage(isc::dns::MessagePtr answer_message,
42
                      const isc::dns::Rcode& error_code);
43

44 45 46 47 48 49 50 51

/// \brief Initialize a response message
///
/// Based on the given query message, this fills in the very
/// first details of the response (i.e. the Question section and
/// the Opcode). This allows for direct usage of makeErrorMessage(),
/// as well as ResolveCache.lookup().
///
Jelte Jansen's avatar
Jelte Jansen committed
52 53 54
/// Raises an isc::dns::InvalidMessageOperation if reponse_message is
/// not in RENDER mode.
///
55 56 57
/// \param query_message The query message to take the Question, Qid,
///                      and Opcode from.
/// \param response_message The fresh response message to initialize
58
///                         (must be in RENDER mode)
59 60 61 62 63 64 65 66 67 68 69
void initResponseMessage(const isc::dns::Message& query_message,
                         isc::dns::Message& response_message);


/// \brief Initialize a response message
///
/// Based on the given question, this fills in the very
/// first details of the response (i.e. the Question section and the
/// Opcode Query). This allows for direct usage of makeErrorMessage(),
/// as well as ResolveCache.lookup().
///
Jelte Jansen's avatar
Jelte Jansen committed
70 71 72
/// Raises an isc::dns::InvalidMessageOperation if reponse_message is
/// not in RENDER mode.
///
73 74
/// \param question The question to place in the Question section
/// \param response_message The fresh response message to initialize
75
///                         (must be in RENDER mode)
76 77 78 79
void initResponseMessage(const isc::dns::Question& question,
                         isc::dns::Message& response_message);


Jeremy C. Reed's avatar
Jeremy C. Reed committed
80
/// \brief Copies the parts relevant for a DNS response to the
81 82 83 84 85
/// target message
///
/// This adds all the RRsets in the answer, authority and
/// additional sections to the target, as well as the response
/// code
86 87 88 89
/// \param source The Message to copy the data from
/// \param target The Message to copy the data to
void copyResponseMessage(const isc::dns::Message& source,
                         isc::dns::MessagePtr target);
90

91 92 93 94

} // namespace resolve
} // namespace isc

95
#endif // ISC_RESOLVE_H_