OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
xmpp_proto.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef __XMPP_STANZA_H__
6 #define __XMPP_STANZA_H__
7 
8 #include "xmpp/xmpp_str.h"
9 #include "xml/xml_base.h"
10 
11 class XmppConnection;
12 
13 class XmppStanza {
14 public:
16  INVALID = 0,
19  IQ_STANZA = 3,
22  };
23 
25  NONE = 0,
27  CONFLICT = 2,
29  FORBIDDEN = 4,
30  GONE = 5,
39  REDIRECT = 14,
49  };
50 
51  class XmppMessage {
52  public:
54  type(type), from(""), to("") {
55  }
56  virtual ~XmppMessage(){ }
59  std::string from;
60  std::string to;
61  std::string xmlns;
62  std::unique_ptr<XmlBase> dom;
63 
65  return (type > INVALID && type < RESERVED_STANZA);
66  };
67  private:
68  XmppMessage(const XmppMessage&) = delete;
69  XmppMessage(XmppMessage&&) = delete;
70  const XmppMessage& operator = (const XmppMessage&) = delete;
71  const XmppMessage& operator = (XmppMessage&&) = delete;
72  };
73 
76  }
77 
86  };
87 
89  };
90 
91 
94  TLS_START = 2,
96  };
97 
100  };
101 
105  };
106 
107 
108  struct XmppChatMessage : public XmppMessage {
110  XmppMessage(MESSAGE_STANZA), state(stype) {
111  };
113  NORMAL = 1,
114  CHAT = 2,
116  HEADLINE = 4,
117  ERROR = 5
118  };
119 
122  };
123 
127  PROBE = 2,
129  };
130 
132  CHAT = 1, AWAY = 2, XA = 3, DND = 4
133  };
134 
137  std::string timestamp;
138  std::string statusDescr;
139  int16_t priority;
140  };
141 
142  struct XmppMessageIq : public XmppMessage {
144  }
146  GET = 1,
147  SET = 2,
148  RESULT = 3,
149  ERROR = 4
150  };
151 
153  AUTH = 1, CANCEL = 2, CONTINUE = 3, MODIFY = 4, WAIT = 5
154  };
155 
157  std::string node;
158  std::string id;
159  std::string iq_type;
160  std::string action;
161  std::string as_node;
163  };
164 
165  XmppStanza();
166 
167  static XmlBase *AllocXmppXmlImpl(const char *doc = NULL) {
169  BOOST_ASSERT(tmp);
170  if (doc) tmp->LoadDoc(doc);
171  return tmp;
172  }
173 
174 private:
176 };
177 
178 class XmppProto : public XmppStanza {
179 public:
180 
181  static XmppStanza::XmppMessage *Decode(const XmppConnection *connection,
182  const std::string &ts);
183  static int EncodeStream(const XmppStreamMessage &str, std::string &to,
184  std::string &from, const std::string &xmlns,
185  uint8_t *data, size_t size);
186  static int EncodeStream(const XmppMessage &str, uint8_t *data, size_t size);
187  static int EncodeMessage(const XmppChatMessage *, uint8_t *data, size_t size);
188  static int EncodeMessage(XmlBase *, uint8_t *data, size_t size);
189  static int EncodePresence(uint8_t *data, size_t size);
190  static int EncodeIq(const XmppMessageIq *iq, XmlBase *doc,
191  uint8_t *data, size_t size);
192 
193 private:
194  static int EncodeOpen(uint8_t *data, std::string &to, std::string &from,
195  const std::string &xmlns, size_t size);
196  static int EncodeOpenResp(uint8_t *data, std::string &to, std::string &from,
197  size_t size);
198  static int EncodeFeatureTlsRequest(uint8_t *data);
199  static int EncodeFeatureTlsStart(uint8_t *data);
200  static int EncodeFeatureTlsProceed(uint8_t *data);
201  static int EncodeWhitespace(uint8_t *data);
202  static int SetTo(std::string &to, XmlBase *doc);
203  static int SetFrom(std::string &from, XmlBase *doc);
204  static int SetXmlns(const std::string &from, XmlBase *doc);
205 
206  static const char *GetId(XmlBase *doc);
207  static const char *GetType(XmlBase *doc);
208  static const char *GetTo(XmlBase *doc);
209  static const char *GetFrom(XmlBase *doc);
210  static const char *GetXmlns(XmlBase *doc);
211  static const char *GetAction(XmlBase *doc, const std::string &str);
212  static const char *GetNode(XmlBase *doc, const std::string &str);
213  static const char *GetAsNode(XmlBase *doc);
214  static const char *GetDsNode(XmlBase *doc);
215 
217  const XmppConnection *connection, const std::string &ts,
218  XmlBase *impl);
219 
220  static std::unique_ptr<XmlBase> open_doc_;
221 
222  XmppProto();
223  ~XmppProto();
224 
226 };
227 
228 #endif // __XMPP_STANZA_H__
static int EncodeOpen(uint8_t *data, std::string &to, std::string &from, const std::string &xmlns, size_t size)
Definition: xmpp_proto.cc:165
static const char * GetXmlns(XmlBase *doc)
Definition: xmpp_proto.cc:443
bool IsValidType(XmppMessageType type) const
Definition: xmpp_proto.h:64
XmppMessageStateType
Definition: xmpp_proto.h:102
XmppChatMessage(XmppMessageStateType stype)
Definition: xmpp_proto.h:109
static const char * GetId(XmlBase *doc)
Definition: xmpp_proto.cc:451
XmppMessageType type
Definition: xmpp_proto.h:57
virtual int LoadDoc(const std::string &doc)=0
XmppStreamTlsType strmtlstype
Definition: xmpp_proto.h:99
static XmlBase * AllocXmppXmlImpl(const char *doc=NULL)
Definition: xmpp_proto.h:167
DISALLOW_COPY_AND_ASSIGN(XmppProto)
XmppPresenceShowType show
Definition: xmpp_proto.h:136
static const char * GetType(XmlBase *doc)
Definition: xmpp_proto.cc:458
static int EncodeMessage(const XmppChatMessage *, uint8_t *data, size_t size)
static const char * GetDsNode(XmlBase *doc)
Definition: xmpp_proto.cc:498
XmppStreamMsgType strmtype
Definition: xmpp_proto.h:98
static int EncodePresence(uint8_t *data, size_t size)
Definition: xmpp_proto.cc:84
static const char * GetFrom(XmlBase *doc)
Definition: xmpp_proto.cc:436
XmlBase * GetXmlImpl()
Definition: xml_base.cc:10
static int SetFrom(std::string &from, XmlBase *doc)
Definition: xmpp_proto.cc:412
DISALLOW_COPY_AND_ASSIGN(XmppStanza)
std::unique_ptr< XmlBase > dom
Definition: xmpp_proto.h:62
static XmppStanza::XmppMessage * DecodeInternal(const XmppConnection *connection, const std::string &ts, XmlBase *impl)
Definition: xmpp_proto.cc:231
static std::unique_ptr< XmlBase > open_doc_
Definition: xmpp_proto.h:220
XmppMessage(XmppMessageType type)
Definition: xmpp_proto.h:53
XmppStanzaErrorType error
Definition: xmpp_proto.h:58
static int SetXmlns(const std::string &from, XmlBase *doc)
Definition: xmpp_proto.cc:420
static int EncodeIq(const XmppMessageIq *iq, XmlBase *doc, uint8_t *data, size_t size)
Definition: xmpp_proto.cc:88
static int EncodeFeatureTlsProceed(uint8_t *data)
Definition: xmpp_proto.cc:206
XmppMessageStateType state
Definition: xmpp_proto.h:120
static const char * GetAction(XmlBase *doc, const std::string &str)
Definition: xmpp_proto.cc:465
static XmppStanza::XmppMessage * Decode(const XmppConnection *connection, const std::string &ts)
Definition: xmpp_proto.cc:213
static const char * GetAsNode(XmlBase *doc)
Definition: xmpp_proto.cc:487
XmppMessageSubtype stype
Definition: xmpp_proto.h:121
static int SetTo(std::string &to, XmlBase *doc)
Definition: xmpp_proto.cc:402
static int EncodeWhitespace(uint8_t *data)
Definition: xmpp_proto.cc:127
XmppPresenceSubtype stype
Definition: xmpp_proto.h:135
XmppStanzaErrorType
Definition: xmpp_proto.h:24
const XmppMessage & operator=(const XmppMessage &)=delete
static int EncodeStream(const XmppStreamMessage &str, std::string &to, std::string &from, const std::string &xmlns, uint8_t *data, size_t size)
static int EncodeFeatureTlsStart(uint8_t *data)
Definition: xmpp_proto.cc:199
static XmppXmlImplFactory * Instance()
Definition: xml_base.cc:18
static int EncodeFeatureTlsRequest(uint8_t *data)
Definition: xmpp_proto.cc:192
static int EncodeOpenResp(uint8_t *data, std::string &to, std::string &from, size_t size)
Definition: xmpp_proto.cc:138
static const char * GetNode(XmlBase *doc, const std::string &str)
Definition: xmpp_proto.cc:477
static const char * GetTo(XmlBase *doc)
Definition: xmpp_proto.cc:429