15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef REMOTING_PROTOCOL_JINGLE_MESSAGES_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define REMOTING_PROTOCOL_JINGLE_MESSAGES_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <list>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/libjingle/source/talk/p2p/base/candidate.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace protocol {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentDescription;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern const char kJabberNamespace[];
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern const char kJingleNamespace[];
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern const char kP2PTransportNamespace[];
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct JingleMessage {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum ActionType {
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UNKNOWN_ACTION,
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SESSION_INITIATE,
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SESSION_ACCEPT,
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SESSION_TERMINATE,
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SESSION_INFO,
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TRANSPORT_INFO,
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Reason {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UNKNOWN_REASON,
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SUCCESS,
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DECLINE,
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CANCEL,
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GENERAL_ERROR,
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    INCOMPATIBLE_PARAMETERS,
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct NamedCandidate {
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NamedCandidate();
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NamedCandidate(const std::string& name,
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   const cricket::Candidate& candidate);
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::string name;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cricket::Candidate candidate;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JingleMessage();
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JingleMessage(const std::string& to_value,
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                ActionType action_value,
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                const std::string& sid_value);
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~JingleMessage();
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Caller keeps ownership of |stanza|.
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool IsJingleMessage(const buzz::XmlElement* stanza);
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static std::string GetActionName(ActionType action);
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Caller keeps ownership of |stanza|. |error| is set to debug error
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // message when parsing fails.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ParseXml(const buzz::XmlElement* stanza, std::string* error);
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<buzz::XmlElement> ToXml() const;
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string from;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string to;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ActionType action;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string sid;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  std::string initiator;
75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<ContentDescription> description;
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::list<NamedCandidate> candidates;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Content of session-info messages.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<buzz::XmlElement> info;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Value from the <reason> tag if it is present in the
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // message. Useful mainly for session-terminate messages, but Jingle
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // spec allows it in any message.
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Reason reason;
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct JingleMessageReply {
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum ReplyType {
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    REPLY_RESULT,
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    REPLY_ERROR,
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum ErrorType {
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NONE,
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    BAD_REQUEST,
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NOT_IMPLEMENTED,
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    INVALID_SID,
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UNEXPECTED_REQUEST,
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UNSUPPORTED_INFO,
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JingleMessageReply();
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JingleMessageReply(ErrorType error);
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JingleMessageReply(ErrorType error, const std::string& text);
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~JingleMessageReply();
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Formats reply stanza for the specified |request_stanza|. Id and
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // recepient as well as other information needed to generate a valid
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // reply are taken from |request_stanza|.
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<buzz::XmlElement> ToXml(
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const buzz::XmlElement* request_stanza) const;
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ReplyType type;
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ErrorType error_type;
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string text;
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // protocol
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // remoting
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // REMOTING_PROTOCOL_JINGLE_MESSAGES_H_
122