summaryrefslogtreecommitdiff
path: root/src/xmpp/jid.hpp
blob: 85e835cad84c55878aa7aad4f0a204b5bffeae4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once


#include <string>

/**
 * Parse a JID into its different subart
 */
class Jid
{
public:
  explicit Jid(const std::string& jid);

  Jid(const Jid&) = delete;
  Jid(Jid&&) = delete;
  Jid& operator=(const Jid&) = delete;
  Jid& operator=(Jid&&) = delete;

  std::string domain;
  std::string local;
  std::string resource;

  std::string bare() const
  {
    return this->local + "@" + this->domain;
  }
  std::string full() const
  {
    std::string res = this->domain;
    if (!this->local.empty())
      res = this->local + "@" + this->domain;
    if (!this->resource.empty())
      res += "/" + this->resource;
    return res;
  }
};

/**
 * Prepare the given UTF-8 string according to the XMPP node stringprep
 * identifier profile.  This is used to send properly-formed JID to the XMPP
 * server.
 *
 * If the stringprep library is not found, we return an empty string.  When
 * this function is used, the result must always be checked for an empty
 * value, and if this is the case it must not be used as a JID.
 */
std::string jidprep(const std::string& original);