Name.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Name.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include <WString.h>
14 
15 namespace mDNS
16 {
17 class Message;
18 struct Packet;
19 
37 class Name
38 {
39 public:
40  // The mDNS spec says this should never be more than 256 (including trailing '\0').
41  static constexpr size_t maxLength{256};
42 
43  Name(Message& message, uint16_t ptr) : message(message), ptr(ptr)
44  {
45  }
46 
48  {
49  return message;
50  }
51 
56  uint16_t getDataLength() const;
57 
58  String toString() const;
59 
60  operator String() const
61  {
62  return toString();
63  }
64 
74  Name getDomain() const;
75 
84  Name getProtocol() const;
85 
94  Name getService() const;
95 
96  bool equalsIgnoreCase(const char* str, size_t length) const;
97 
98  bool equalsIgnoreCase(const String& value) const
99  {
100  return equalsIgnoreCase(value.c_str(), value.length());
101  }
102 
103  bool operator==(const String& value) const
104  {
105  return equalsIgnoreCase(value);
106  }
107 
108  bool operator!=(const String& value) const
109  {
110  return !operator==(value);
111  }
112 
113  uint16_t getPtr() const
114  {
115  return ptr;
116  }
117 
121  uint16_t makePointer() const;
122 
128  bool fixup(const Name& other);
129 
130 private:
131  uint16_t read(char* buffer, uint16_t bufSize) const;
132 
133  struct ElementPointers {
134  uint16_t service;
135  uint16_t protocol;
136  uint16_t domain;
137  };
138 
139  ElementPointers parseElements() const;
140 
141  Message& message;
142  uint16_t ptr;
143 };
144 
145 } // namespace mDNS
The String class.
Definition: WString.h:137
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:617
size_t length(void) const
Obtain the String length in characters, excluding NUL terminator.
Definition: WString.h:244
Encapsulates a message packet for flexible introspection.
Definition: MDNS/src/include/Network/Mdns/Message.h:29
Encoded DNS name.
Definition: Name.h:38
String toString() const
Name getService() const
Get the service name.
bool fixup(const Name &other)
Fixup pointer at end of name to point to another name.
static constexpr size_t maxLength
Definition: Name.h:41
bool equalsIgnoreCase(const char *str, size_t length) const
uint16_t makePointer() const
Ensure a pointer refers to actual content, not another pointer.
bool operator==(const String &value) const
Definition: Name.h:103
uint16_t getPtr() const
Definition: Name.h:113
Name getProtocol() const
Get the service name.
Name(Message &message, uint16_t ptr)
Definition: Name.h:43
uint16_t getDataLength() const
Get number of bytes occupied by the name Not the same as the string length because content is encoded...
Message & getMessage() const
Definition: Name.h:47
bool operator!=(const String &value) const
Definition: Name.h:108
bool equalsIgnoreCase(const String &value) const
Definition: Name.h:98
Name getDomain() const
Get the last element of the name, which must be the domain.
Definition: Answer.h:18
Helper class for reading/writing packet content.
Definition: Packet.h:18
#define str(s)
Definition: testrunner.h:124