00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __NAME_H
00018 #define __NAME_H 1
00019
00020 #include <string>
00021 #include <vector>
00022
00023 #include "exceptions.h"
00024
00025 namespace isc {
00026 namespace dns {
00027 class InputBuffer;
00028 class OutputBuffer;
00029 class MessageRenderer;
00030
00035 class EmptyLabel : public Exception {
00036 public:
00037 EmptyLabel(const char* file, size_t line, const char* what) :
00038 isc::dns::Exception(file, line, what) {}
00039 };
00040
00045 class TooLongName : public Exception {
00046 public:
00047 TooLongName(const char* file, size_t line, const char* what) :
00048 isc::dns::Exception(file, line, what) {}
00049 };
00050
00055 class TooLongLabel : public Exception {
00056 public:
00057 TooLongLabel(const char* file, size_t line, const char* what) :
00058 isc::dns::Exception(file, line, what) {}
00059 };
00060
00067 class BadLabelType : public Exception {
00068 public:
00069 BadLabelType(const char* file, size_t line, const char* what) :
00070 isc::dns::Exception(file, line, what) {}
00071 };
00072
00077 class BadEscape : public Exception {
00078 public:
00079 BadEscape(const char* file, size_t line, const char* what) :
00080 isc::dns::Exception(file, line, what) {}
00081 };
00082
00087 class BadPointer : public Exception {
00088 public:
00089 BadPointer(const char* file, size_t line, const char* what) :
00090 isc::dns::Exception(file, line, what) {}
00091 };
00092
00100 class IncompleteName : public Exception {
00101 public:
00102 IncompleteName(const char* file, size_t line, const char* what) :
00103 isc::dns::Exception(file, line, what) {}
00104 };
00105
00115 class NameComparisonResult {
00116 public:
00132 enum NameRelation {
00133 SUPERDOMAIN = 0,
00134 SUBDOMAIN = 1,
00135 EQUAL = 2,
00136 COMMONANCESTOR = 3
00137 };
00138
00142
00143
00144
00145
00146
00147 explicit NameComparisonResult(int order, unsigned int nlabels,
00148 NameRelation relation) :
00149 order_(order), nlabels_(nlabels), relation_(relation) {}
00151
00155
00156
00157 int getOrder() const { return (order_); }
00159 unsigned int getCommonLabels() const { return (nlabels_); }
00161 NameRelation getRelation() const { return (relation_); }
00163 private:
00164 int order_;
00165 unsigned int nlabels_;
00166 NameRelation relation_;
00167 };
00168
00212 class Name {
00216
00217 private:
00224 Name() : length_(0), labels_(0) {}
00225 public:
00236 explicit Name(const std::string& namestr, bool downcase = false);
00254 explicit Name(InputBuffer& buffer, bool downcase = false);
00256
00260
00261
00262
00263
00264
00265
00266 size_t getLength() const { return (length_); }
00267
00276 unsigned int getLabels() const { return (labels_); }
00278
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00299 std::string toText(bool omit_final_dot = false) const;
00300
00312 void toWire(MessageRenderer& renderer) const;
00313
00323 void toWire(OutputBuffer& buffer) const;
00325
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 NameComparisonResult compare(const Name& other) const;
00344
00358 bool equals(const Name& other) const;
00359
00361 bool operator==(const Name& other) const { return (this->equals(other)); }
00362
00368 bool nequals(const Name& other) const { return !(this->equals(other)); }
00369
00371 bool operator!=(const Name& other) const { return (this->nequals(other)); }
00372
00382 bool leq(const Name& other) const;
00383
00385 bool operator<=(const Name& other) const { return (leq(other)); }
00386
00397 bool geq(const Name& other) const;
00398
00400 bool operator>=(const Name& other) const { return (geq(other)); }
00401
00411 bool lthan(const Name& other) const;
00412
00414 bool operator<(const Name& other) const { return (lthan(other)); }
00415
00425 bool gthan(const Name& other) const;
00426
00428 bool operator>(const Name& other) const { return (gthan(other)); }
00430
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 Name split(unsigned int first, unsigned int n) const;
00463
00477 Name concatenate(const Name& suffix) const;
00478
00500 Name& downcase();
00502
00506
00507
00508
00509
00510
00511 bool isWildcard() const;
00513
00517
00518
00519 static const size_t MAX_WIRE = 255;
00520
00525 static const size_t MAX_LABELS = 128;
00526
00528 static const size_t MAX_LABELLEN = 63;
00529
00535 static const uint16_t MAX_COMPRESS_POINTER = 0x3fff;
00537 static const uint16_t COMPRESS_POINTER_MARK8 = 0xc0;
00539 static const uint16_t COMPRESS_POINTER_MARK16 = 0xc000;
00541
00542 private:
00543 std::string ndata_;
00544 std::vector<unsigned char> offsets_;
00545 unsigned int length_;
00546 unsigned int labels_;
00547 };
00548
00563 std::ostream&
00564 operator<<(std::ostream& os, const Name& name);
00565 }
00566 }
00567 #endif // __NAME_H
00568
00569
00570
00571