1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef REMOTING_PROTOCOL_JINGLE_MESSAGES_H_
6#define REMOTING_PROTOCOL_JINGLE_MESSAGES_H_
7
8#include <list>
9#include <string>
10
11#include "base/memory/scoped_ptr.h"
12#include "third_party/libjingle/source/talk/p2p/base/candidate.h"
13#include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
14
15
16namespace remoting {
17namespace protocol {
18
19class ContentDescription;
20
21extern const char kJabberNamespace[];
22extern const char kJingleNamespace[];
23extern const char kP2PTransportNamespace[];
24
25struct JingleMessage {
26  enum ActionType {
27    UNKNOWN_ACTION,
28    SESSION_INITIATE,
29    SESSION_ACCEPT,
30    SESSION_TERMINATE,
31    SESSION_INFO,
32    TRANSPORT_INFO,
33  };
34
35  enum Reason {
36    UNKNOWN_REASON,
37    SUCCESS,
38    DECLINE,
39    CANCEL,
40    GENERAL_ERROR,
41    INCOMPATIBLE_PARAMETERS,
42  };
43
44  struct NamedCandidate {
45    NamedCandidate();
46    NamedCandidate(const std::string& name,
47                   const cricket::Candidate& candidate);
48
49    std::string name;
50    cricket::Candidate candidate;
51  };
52
53  JingleMessage();
54  JingleMessage(const std::string& to_value,
55                ActionType action_value,
56                const std::string& sid_value);
57  ~JingleMessage();
58
59  // Caller keeps ownership of |stanza|.
60  static bool IsJingleMessage(const buzz::XmlElement* stanza);
61  static std::string GetActionName(ActionType action);
62
63  // Caller keeps ownership of |stanza|. |error| is set to debug error
64  // message when parsing fails.
65  bool ParseXml(const buzz::XmlElement* stanza, std::string* error);
66
67  scoped_ptr<buzz::XmlElement> ToXml() const;
68
69  std::string from;
70  std::string to;
71  ActionType action;
72  std::string sid;
73
74  std::string initiator;
75
76  scoped_ptr<ContentDescription> description;
77  std::list<NamedCandidate> candidates;
78
79  // Content of session-info messages.
80  scoped_ptr<buzz::XmlElement> info;
81
82  // Value from the <reason> tag if it is present in the
83  // message. Useful mainly for session-terminate messages, but Jingle
84  // spec allows it in any message.
85  Reason reason;
86};
87
88struct JingleMessageReply {
89  enum ReplyType {
90    REPLY_RESULT,
91    REPLY_ERROR,
92  };
93  enum ErrorType {
94    NONE,
95    BAD_REQUEST,
96    NOT_IMPLEMENTED,
97    INVALID_SID,
98    UNEXPECTED_REQUEST,
99    UNSUPPORTED_INFO,
100  };
101
102  JingleMessageReply();
103  JingleMessageReply(ErrorType error);
104  JingleMessageReply(ErrorType error, const std::string& text);
105  ~JingleMessageReply();
106
107  // Formats reply stanza for the specified |request_stanza|. Id and
108  // recepient as well as other information needed to generate a valid
109  // reply are taken from |request_stanza|.
110  scoped_ptr<buzz::XmlElement> ToXml(
111      const buzz::XmlElement* request_stanza) const;
112
113  ReplyType type;
114  ErrorType error_type;
115  std::string text;
116};
117
118}  // protocol
119}  // remoting
120
121#endif  // REMOTING_PROTOCOL_JINGLE_MESSAGES_H_
122