Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / remoting / protocol / jingle_messages.h
blob47f9afc9431363bd7422d8a724255e30080730e6
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.
5 #ifndef REMOTING_PROTOCOL_JINGLE_MESSAGES_H_
6 #define REMOTING_PROTOCOL_JINGLE_MESSAGES_H_
8 #include <list>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
13 #include "third_party/webrtc/p2p/base/candidate.h"
15 namespace remoting {
16 namespace protocol {
18 class ContentDescription;
20 struct JingleMessage {
21 enum ActionType {
22 UNKNOWN_ACTION,
23 SESSION_INITIATE,
24 SESSION_ACCEPT,
25 SESSION_TERMINATE,
26 SESSION_INFO,
27 TRANSPORT_INFO,
30 enum Reason {
31 UNKNOWN_REASON,
32 SUCCESS,
33 DECLINE,
34 CANCEL,
35 GENERAL_ERROR,
36 INCOMPATIBLE_PARAMETERS,
39 struct NamedCandidate {
40 NamedCandidate() = default;
41 NamedCandidate(const std::string& name,
42 const cricket::Candidate& candidate);
44 std::string name;
45 cricket::Candidate candidate;
48 struct IceCredentials {
49 IceCredentials() = default;
50 IceCredentials(std::string channel,
51 std::string ufrag,
52 std::string password);
54 std::string channel;
55 std::string ufrag;
56 std::string password;
59 JingleMessage();
60 JingleMessage(const std::string& to_value,
61 ActionType action_value,
62 const std::string& sid_value);
63 ~JingleMessage();
65 // Caller keeps ownership of |stanza|.
66 static bool IsJingleMessage(const buzz::XmlElement* stanza);
67 static std::string GetActionName(ActionType action);
69 // Caller keeps ownership of |stanza|. |error| is set to debug error
70 // message when parsing fails.
71 bool ParseXml(const buzz::XmlElement* stanza, std::string* error);
73 scoped_ptr<buzz::XmlElement> ToXml() const;
75 std::string from;
76 std::string to;
77 ActionType action = UNKNOWN_ACTION;
78 std::string sid;
80 std::string initiator;
82 scoped_ptr<ContentDescription> description;
84 std::list<IceCredentials> ice_credentials;
85 std::list<NamedCandidate> candidates;
87 // Content of session-info messages.
88 scoped_ptr<buzz::XmlElement> info;
90 // Value from the <reason> tag if it is present in the
91 // message. Useful mainly for session-terminate messages, but Jingle
92 // spec allows it in any message.
93 Reason reason = UNKNOWN_REASON;
96 struct JingleMessageReply {
97 enum ReplyType {
98 REPLY_RESULT,
99 REPLY_ERROR,
101 enum ErrorType {
102 NONE,
103 BAD_REQUEST,
104 NOT_IMPLEMENTED,
105 INVALID_SID,
106 UNEXPECTED_REQUEST,
107 UNSUPPORTED_INFO,
110 JingleMessageReply();
111 JingleMessageReply(ErrorType error);
112 JingleMessageReply(ErrorType error, const std::string& text);
113 ~JingleMessageReply();
115 // Formats reply stanza for the specified |request_stanza|. Id and
116 // recepient as well as other information needed to generate a valid
117 // reply are taken from |request_stanza|.
118 scoped_ptr<buzz::XmlElement> ToXml(
119 const buzz::XmlElement* request_stanza) const;
121 ReplyType type;
122 ErrorType error_type;
123 std::string text;
126 } // protocol
127 } // remoting
129 #endif // REMOTING_PROTOCOL_JINGLE_MESSAGES_H_