EpcTools
An event based multi-threaded C++ development framework.
efqdn.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2020 T-Mobile
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #ifndef __EFQDN_H
18 #define __EFQDN_H
19 
20 #include "estring.h"
21 #include "eostring.h"
22 
23 class EFqdn
24 {
25 public:
26  EFqdn() {}
27  EFqdn(cpStr val)
28  {
29  *this = val;
30  }
31 
32  EFqdn &operator=(const EFqdn &val)
33  {
34  fqdn_ = val.fqdn_;
35  return *this;
36  }
37 
38  EFqdn &operator=(cpStr val)
39  {
40  cpStr ptr = val;
41  UChar idx = 1;
42  UChar label[256];
43  fqdn_.clear();
44  while (*ptr)
45  {
46  if (*ptr == '.')
47  {
48  label[0] = idx - 1;
49  fqdn_.append(label, idx);
50  idx = 1;
51  }
52  else
53  {
54  label[idx++] = *ptr;
55  }
56  ptr++;
57  }
58 
59  if (idx > 0)
60  {
61  label[0] = idx - 1;
62  fqdn_.append(label, idx);
63  }
64 
65  return *this;
66  }
67 
68  operator EOctetString() const
69  {
70  return fqdn_;
71  }
72 
73  cpUChar data() const
74  {
75  return fqdn_.data();
76  }
77 
78  size_t length() const
79  {
80  return fqdn_.length();
81  }
82 
83  EString toString() const
84  {
85  EString str;
86  Char label[256];
87  pChar lblptr = label;
88 
89  for (EOctetString::size_type i = 0; i < fqdn_.size(); )
90  {
91  UChar len = fqdn_[i++];
92  UChar j = 0;
93  if (!str.empty())
94  label[j++] = '.';
95  lblptr = &label[j];
96  while (len--)
97  {
98  *lblptr = static_cast<Char>(fqdn_[i++]);
99  lblptr++;
100  }
101  str.append(label, lblptr - label);
102  }
103 
104  return str;
105  }
106 
107 private:
108  EOctetString fqdn_;
109 };
110 
111 #endif // #ifndef __EFQDN_H
cpUChar data() const
Definition: efqdn.h:73
Encapsulates and extends a std::string object.
Represents an OctetString as defined in RFC 6733.
Definition: eostring.h:33
Void clear()
Sets the internal buffer to all NULL&#39;s and sets the length to zero.
Definition: eostring.h:372
EFqdn(cpStr val)
Definition: efqdn.h:27
size_type length() const
Returns the length of the assigned value of this object.
Definition: eostring.h:558
EString toString() const
Definition: efqdn.h:83
EFqdn & operator=(cpStr val)
Definition: efqdn.h:38
size_t length() const
Definition: efqdn.h:78
size_type size() const
Definition: eostring.h:559
EFqdn()
Definition: efqdn.h:26
Defines the EOctetString and ETbcdString classes.
EOctetString & append(const EOctetString &ostr)
Appends to this object.
Definition: eostring.h:182
cpUChar data() const
Returns a pointer to the internal data buffer.
Definition: eostring.h:516
EFqdn & operator=(const EFqdn &val)
Definition: efqdn.h:32
String class.
Definition: estring.h:31
size_t size_type
Definition: eostring.h:36
Definition: efqdn.h:23