OPAL  Version 3.18.8
im.h
Go to the documentation of this file.
1 /*
2  * im.h
3  *
4  * Instant Messaging classes
5  *
6  * Open Phone Abstraction Library (OPAL)
7  *
8  * Copyright (c) 2008 Post Increment
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open Phone Abstraction Library.
21  *
22  * The Initial Developer of the Original Code is Post Increment
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef OPAL_IM_IM_H
28 #define OPAL_IM_IM_H
29 
30 #include <ptlib.h>
31 #include <opal_config.h>
32 
33 #if OPAL_HAS_IM
34 
35 #include <ptclib/url.h>
36 #include <opal//transports.h>
37 
38 
39 class OpalCall;
40 class OpalMediaFormat;
41 class OpalIMEndPoint;
42 
43 
45 
46 #if OPAL_HAS_SIPIM
47  #define OPAL_SIPIM "SIP-IM"
48  #define OpalSIPIM GetOpalSIPIM()
49  extern const OpalMediaFormat & GetOpalSIPIM();
50 #endif
51 
52 #if OPAL_HAS_RFC4103
53  #define OPAL_T140 "T.140"
54  #define OpalT140 GetOpalT140()
55  extern const OpalMediaFormat & GetOpalT140();
56 #endif
57 
58 #if OPAL_HAS_MSRP
59  #define OPAL_MSRP "MSRP"
60  #define OpalMSRP GetOpalMSRP()
61  extern const OpalMediaFormat & GetOpalMSRP();
62 #endif
63 
64 #define OPAL_IM_MEDIA_TYPE_PREFIX "im-"
65 
66 
68 
75 class OpalIM : public PObject
76 {
77  PCLASSINFO_WITH_CLONE(OpalIM, PObject);
78  public:
79  OpalIM();
80 
81  PString m_conversationId;
82 
83  PURL m_to;
85  PURL m_from;
87  PString m_fromName;
88  PStringToString m_bodies;
89  PMultiPartList m_bodyParts;
90 
91  typedef uint32_t MessageID;
95  static MessageID GetNextMessageId();
96 };
97 
98 
100 
107 class OpalIMContext : public PSafeObject
108 {
109  PCLASSINFO(OpalIMContext, PSafeObject);
110 
113  protected:
115  OpalIMContext();
116 
117  public:
119  ~OpalIMContext();
120 
124  {
126  const PString & id,
127  bool opening,
128  bool byRemote,
129  const PSafePtr<OpalIMContext> & context
130  ) : m_conversationId(id)
131  , m_opening(opening)
132  , m_byRemote(byRemote)
133  , m_context(context)
134  { }
135 
137  bool m_opening;
138  bool m_byRemote;
139  PSafePtr<OpalIMContext> m_context;
140  };
141 
145  virtual bool Open(
146  bool byRemote
147  );
148 
152  virtual void Close();
154 
155 
163  P_DECLARE_STREAMABLE_ENUM(MessageDisposition,
164  DispositionPending,
165  DispositionAccepted,
166  DeliveryOK,
167  DisplayConfirmed,
168  ProcessedNotification,
169  StorageNotification,
170 
172  DispositionErrors,
173  GenericError,
174  UnacceptableContent,
175  InvalidContent,
176  DestinationUnknown,
177  DestinationUnavailable,
178  TransmissionTimeout,
179  TransportFailure,
180  ConversationClosed,
181  UnsupportedFeature,
182  DeliveryFailed
183  );
184 
195  virtual MessageDisposition Send(
196  OpalIM * message
197  );
198 
204  MessageDisposition m_disposition;
205  };
206 
210  virtual void OnMessageDisposition(
211  const DispositionInfo & info
212  );
213 
215  typedef PNotifierTemplate<DispositionInfo> MessageDispositionNotifier;
216 
218  #define PDECLARE_MessageDispositionNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::DispositionInfo)
219 
221  #define PDECLARE_ASYNC_MessageDispositionNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::DispositionInfo)
222 
224  #define PCREATE_MessageDispositionNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIMContext::DispositionInfo)
225 
228  const MessageDispositionNotifier & notifier
229  );
231 
232 
240  virtual MessageDisposition OnMessageReceived(
241  const OpalIM & message
242  );
243 
245  typedef PNotifierTemplate<OpalIM> MessageReceivedNotifier;
246 
248  #define PDECLARE_MessageReceivedNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIM)
249 
251  #define PDECLARE_ASYNC_MessageReceivedNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalIMContext, cls, fn, OpalIM)
252 
254  #define PCREATE_MessageReceivedNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIM)
255 
258  const MessageReceivedNotifier & notifier
259  );
261 
262 
265  static const PCaselessString & CompositionIndicationActive();
266  static const PCaselessString & CompositionIndicationIdle();
267 
271  {
273  PString m_state;
274  PString m_contentType;
275 
277  const PString & id,
278  const PString & state,
279  const PString & contentType = PString::Empty()
280  ) : m_conversationId(id)
281  , m_state(state)
282  , m_contentType(contentType)
283  { }
284  };
285 
290  virtual bool SendCompositionIndication(
291  const CompositionInfo & info
292  );
293 
297  virtual void OnCompositionIndication(
298  const CompositionInfo & info
299  );
300 
302  typedef PNotifierTemplate<CompositionInfo> CompositionIndicationNotifier;
303 
305  #define PDECLARE_CompositionIndicationNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::CompositionInfo)
306 
308  #define PDECLARE_ASYNC_CompositionIndicationNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::CompositionInfo)
309 
311  #define PCREATE_CompositionIndicationNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIMContext::CompositionInfo)
312 
315  const CompositionIndicationNotifier & notifier
316  );
318 
319 
322  virtual bool CheckContentType(
324  const PString & contentType
325  ) const;
326 
328  virtual PStringArray GetContentTypes() const;
329 
331  static PString CreateKey(const PURL & from, const PURL & to);
333 
334 
337  const PString & GetID() const { return m_conversationId; }
339 
341  const PString & GetKey() const { return m_key; }
342 
344  const PURL & GetRemoteURL() const { return m_remoteURL; }
345 
347  const PString & GetRemoteName() const { return m_remoteName; }
348 
350  const PURL & GetLocalURL() const { return m_localURL; }
351 
353  const PString & GetLocalName() const { return m_localName; }
354 
356  void SetLocalName(const PString & name) { m_localName = name; }
357 
359  PStringOptions & GetAttributes() { return m_attributes; }
360  const PStringOptions & GetAttributes() const { return m_attributes; }
362 
363  protected:
364  void ResetLastUsed();
365 
366  virtual MessageDisposition InternalSend();
367  virtual MessageDisposition InternalSendOutsideCall(OpalIM & message);
368  virtual MessageDisposition InternalSendInsideCall(OpalIM & message);
369  virtual void InternalOnMessageSent(const DispositionInfo & info);
370 
372  PStringOptions m_attributes;
373 
374  PSafePtr<OpalCall> m_call;
376 
377  PDECLARE_MUTEX( m_notificationMutex);
381 
382  PDECLARE_MUTEX(m_outgoingMessagesMutex);
384  PQueue<OpalIM> m_outgoingMessages;
385 
386  PDECLARE_MUTEX(m_lastUsedMutex);
387  PTime m_lastUsed;
388 
391  PString m_localName;
393  PString m_remoteName;
394  PString m_key;
395 
396  friend class OpalIMEndPoint;
397  friend class OpalIMConnection;
398 };
399 
400 
401 #endif // OPAL_HAS_IM
402 
403 #endif // OPAL_IM_IM_H
PMultiPartList m_bodyParts
More detailed information on the body data.
Definition: im.h:89
PQueue< OpalIM > m_outgoingMessages
Definition: im.h:384
bool m_opening
Opening or closing conversation.
Definition: im.h:137
virtual PStringArray GetContentTypes() const
Return array of all valid content types.
PSafePtr< OpalIMContext > m_context
Context opening/closing.
Definition: im.h:139
virtual void InternalOnMessageSent(const DispositionInfo &info)
void SetMessageReceivedNotifier(const MessageReceivedNotifier &notifier)
Set the notifier for the OnMessageReceived() function.
PSafePtr< OpalCall > m_call
Definition: im.h:374
uint32_t MessageID
Definition: im.h:91
virtual MessageDisposition Send(OpalIM *message)
static MessageID GetNextMessageId()
virtual void OnMessageDisposition(const DispositionInfo &info)
PString m_contentType
MIME type of composed message.
Definition: im.h:274
PURL m_to
URL for destination of message.
Definition: im.h:83
Definition: im_ep.h:40
virtual MessageDisposition OnMessageReceived(const OpalIM &message)
PString m_conversationId
Conversation ID to get OpalIMContext.
Definition: im.h:202
virtual MessageDisposition InternalSend()
PURL m_remoteURL
Definition: im.h:392
CompositionIndicationNotifier m_compositionIndicationNotifier
Definition: im.h:380
PNotifierTemplate< CompositionInfo > CompositionIndicationNotifier
Type for composition indication notifiers.
Definition: im.h:302
const PString & GetRemoteName() const
Get remote display name for conversation.
Definition: im.h:347
virtual MessageDisposition InternalSendOutsideCall(OpalIM &message)
ConversationInfo(const PString &id, bool opening, bool byRemote, const PSafePtr< OpalIMContext > &context)
Definition: im.h:125
Definition: im.h:75
MessageDispositionNotifier m_messageDispositionNotifier
Definition: im.h:378
PStringOptions m_attributes
Definition: im.h:372
virtual bool SendCompositionIndication(const CompositionInfo &info)
bool m_byRemote
Operation is initiated by remote user or local user.
Definition: im.h:138
const PStringOptions & GetAttributes() const
Definition: im.h:360
PString m_conversationId
Definition: im.h:389
PString m_state
New state, usually CompositionIndicationActive() or CompositionIndicationIdle()
Definition: im.h:273
static PString CreateKey(const PURL &from, const PURL &to)
Calculate a key based on the from an to addresses.
void SetCompositionIndicationNotifier(const CompositionIndicationNotifier &notifier)
Set the notifier for the OnCompositionIndication() function.
virtual void OnCompositionIndication(const CompositionInfo &info)
MessageDisposition m_disposition
Disposition status.
Definition: im.h:204
MessageReceivedNotifier m_messageReceivedNotifier
Definition: im.h:379
PURL m_from
URL for source of message.
Definition: im.h:85
OpalIM * m_currentOutgoingMessage
Definition: im.h:383
Definition: mediafmt.h:806
Definition: call.h:62
virtual MessageDisposition InternalSendInsideCall(OpalIM &message)
const OpalMediaFormat & GetOpalSIPIM()
virtual bool Open(bool byRemote)
PDECLARE_MUTEX(m_notificationMutex)
virtual void Close()
const PURL & GetLocalURL() const
Get local URL for conversation.
Definition: im.h:350
PString m_localName
Definition: im.h:391
MessageID m_messageId
Definition: im.h:92
static const PCaselessString & CompositionIndicationIdle()
CompositionIndication idle status.
const PURL & GetRemoteURL() const
Get remote URL for conversation.
Definition: im.h:344
OpalTransportAddress m_toAddr
Physical address for destination of message.
Definition: im.h:84
CompositionInfo(const PString &id, const PString &state, const PString &contentType=PString::Empty())
Definition: im.h:276
const PString & GetKey() const
Get key for context based on to/from addresses.
Definition: im.h:341
PString m_conversationId
Conversation ID.
Definition: im.h:136
const OpalMediaFormat & GetOpalMSRP()
PTime m_lastUsed
Definition: im.h:387
PString m_conversationId
Conversation ID to get OpalIMContext.
Definition: im.h:272
PURL m_localURL
Definition: im.h:390
PString m_fromName
Alias (human readable) name for source of message.
Definition: im.h:87
void SetLocalName(const PString &name)
Set local display for conversation.
Definition: im.h:356
PString m_key
Definition: im.h:394
virtual bool CheckContentType(const PString &contentType) const
Check that the context type is valid for protocol.
bool m_weStartedCall
Definition: im.h:375
const PString & GetLocalName() const
Get local display for conversation.
Definition: im.h:353
Definition: im.h:107
Definition: im.h:201
Definition: im.h:270
void SetMessageDispositionNotifier(const MessageDispositionNotifier &notifier)
Set the notifier for the OnMessageDisposition() function.
void ResetLastUsed()
const PString & GetID() const
Get conversation ID.
Definition: im.h:338
OpalIMEndPoint * m_endpoint
Definition: im.h:371
OpalTransportAddress m_fromAddr
Physical address for source of message.
Definition: im.h:86
Definition: transports.h:151
PNotifierTemplate< OpalIM > MessageReceivedNotifier
Type for message received notifiers.
Definition: im.h:245
PStringToString m_bodies
Map of MIME types to body text, e.g. &quot;text/plain&quot;, &quot;Hello Bob!&quot;.
Definition: im.h:88
Definition: im_ep.h:217
PString m_remoteName
Definition: im.h:393
OpalIMContext()
Construct base for context.
static const PCaselessString & CompositionIndicationActive()
CompositionIndication active status.
PNotifierTemplate< DispositionInfo > MessageDispositionNotifier
Type for disposition notifiers.
Definition: im.h:215
~OpalIMContext()
Destroy context.
PString m_conversationId
Identifier for the conversation of messages.
Definition: im.h:81
P_DECLARE_STREAMABLE_ENUM(MessageDisposition, DispositionPending, DispositionAccepted, DeliveryOK, DisplayConfirmed, ProcessedNotification, StorageNotification, DispositionErrors, GenericError, UnacceptableContent, InvalidContent, DestinationUnknown, DestinationUnavailable, TransmissionTimeout, TransportFailure, ConversationClosed, UnsupportedFeature, DeliveryFailed)
const OpalMediaFormat & GetOpalT140()
OpalIM::MessageID m_messageId
Id of message disposition is of.
Definition: im.h:203
PStringOptions & GetAttributes()
Get the attributes for this presentity.
Definition: im.h:359