This file is indexed.

/usr/include/opal/im/im.h is in libopal-dev 3.10.2~dfsg-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*
 * im_mf.h
 *
 * Media formats for Instant Messaging
 *
 * Open Phone Abstraction Library (OPAL)
 *
 * Copyright (c) 2008 Post Increment
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is Open Phone Abstraction Library.
 *
 * The Initial Developer of the Original Code is Post Increment
 *
 * Contributor(s): ______________________________________.
 *
 * $Revision: 26270 $
 * $Author: rjongbloed $
 * $Date: 2011-08-03 03:29:01 -0500 (Wed, 03 Aug 2011) $
 */

#ifndef OPAL_IM_IM_H
#define OPAL_IM_IM_H

#include <ptlib.h>
#include <opal/buildopts.h>

#include <ptclib/url.h>
#include <ptclib/threadpool.h>

#include <opal/transports.h>

class OpalIM : public PObject
{
  public:
    OpalIM();

    enum Type {
      Text,
      CompositionIndication_Idle,   // aka RFC 3994
      CompositionIndication_Active, // aka RFC 3994
      Disposition                   // aka RFC 5438
    } m_type;

    PURL    m_to;
    PURL    m_from;
    PString m_fromName;
    PString m_mimeType;
    PString m_body;
    PString m_conversationId;

    OpalTransportAddress m_fromAddr;
    OpalTransportAddress m_toAddr;

    PAtomicInteger::IntegerType m_messageId;

    static PAtomicInteger::IntegerType GetNextMessageId();
};

#if OPAL_HAS_IM

#include <opal/mediastrm.h>
#include <im/rfc4103.h>

class OpalIMMediaType : public OpalMediaTypeDefinition 
{
  public:
    OpalIMMediaType(
      const char * mediaType, ///< name of the media type (audio, video etc)
      const char * sdpType    ///< name of the SDP type 
    )
      : OpalMediaTypeDefinition(mediaType, sdpType, 0, OpalMediaType::DontOffer)
    { }

    PString GetRTPEncoding() const { return PString::Empty(); }
    RTP_UDP * CreateRTPSession(OpalRTPConnection & , unsigned , bool ) { return NULL; }
    virtual bool UsesRTP() const { return false; }
};

/////////////////////////////////////////////////////////////////////

class OpalIMManager;
class OpalPresentity;

class OpalIMContext : public PSafeObject
{
  PCLASSINFO(OpalIMContext, PSafeObject);

  public:
    friend class OpalIMManager;

    OpalIMContext();
    ~OpalIMContext();

    static PSafePtr<OpalIMContext> Create(
      OpalManager & manager, 
      const PURL & localURL, 
      const PURL & remoteURL
    );

    static PSafePtr<OpalIMContext> Create(
      OpalManager & manager,
      PSafePtr<OpalConnection> conn
    );

    static PSafePtr<OpalIMContext> Create(
      OpalManager & manager,
      PSafePtr<OpalPresentity> presentity,
      const PURL & remoteURL
    );

    enum SentStatus {
      SentOK,
      SentPending,
      SentAccepted,
      SentUnacceptableContent,
      SentInvalidContent,
      SentConnectionClosed,
      SentNoTransport,
      SentNoAnswer,
      SentDestinationUnknown,
      SentFailedGeneric,
    };

    // send text message in this conversation
    virtual SentStatus Send(OpalIM * message);
    virtual SentStatus SendCompositionIndication(bool active = true);

    /// Called when an outgoing message has been delivered for this context
    /// Default implementation calls MessageSentNotifier, if set
    struct MessageSentInfo {
      PAtomicInteger::IntegerType messageId;
      OpalIMContext::SentStatus status;
    };
    virtual void OnMessageSent(const MessageSentInfo & info);

    typedef PNotifierTemplate<const MessageSentInfo &> MessageSentNotifier;
    #define PDECLARE_MessageSentNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, const MessageSentInfo &)
    #define PCREATE_MessageSentNotifier(fn) PCREATE_NOTIFIER2(fn, const MessageSentInfo &)

    /// Set the notifier for the OnMessageSent() function.
    void SetMessageSentNotifier(
      const MessageSentNotifier & notifier   ///< Notifier to be called by OnIncomingIM()
    );

    /// Called when an incoming message arrives for this context
    /// Default implementation calls IncomingIMNotifier, if set, else returns true
    virtual SentStatus OnIncomingIM(OpalIM & message);

    typedef PNotifierTemplate<const OpalIM &> IncomingIMNotifier;
    #define PDECLARE_IncomingIMNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, const OpalIM &)
    #define PCREATE_IncomingIMNotifier(fn) PCREATE_NOTIFIER2(fn, const OpalIM &)

    /// Set the notifier for the OnIncomingMessage() function.
    void SetIncomingIMNotifier(
      const IncomingIMNotifier & notifier   ///< Notifier to be called by OnIncomingIM()
    );

    /// Called when the remote composition indication changes state for this context
    /// Default implementation calls IncomingIMNotifier, if set, else returns true
    virtual void OnCompositionIndicationChanged(const PString & state);

    typedef PNotifierTemplate<const PString &> CompositionIndicationChangedNotifier;
    #define PDECLARE_CompositionIndicationChangedNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, const PString &)
    #define PCREATE_CompositionIndicationChangedNotifier(fn) PCREATE_NOTIFIER2(fn, const PString &)

    /// Set the notifier for the OnIncomingMessage() function.
    void SetCompositionIndicationChangedNotifier(
      const CompositionIndicationChangedNotifier & notifier   ///< Notifier to be called by OnIncomingIM()
    );

    virtual bool CheckContentType(const PString & contentType) const;
    virtual PStringArray GetContentTypes() const;

    // start of internal functions

    PString GetID() const          { return m_id; }
    void SetID(const PString & id) { m_id = id; }
    PString GetKey() const         { return m_key; }
    PString GetLocalURL() const    { return m_localURL; }
    PString GetRemoteURL() const   { return m_remoteURL; }

  /**@name Attributes */
  //@{
    ///< Get the attributes for this presentity.
    PStringOptions & GetAttributes() { return m_attributes; }
    const PStringOptions & GetAttributes() const { return m_attributes; }

    virtual bool OnNewIncomingIM();

    virtual bool AddIncomingIM(OpalIM * message);

    virtual void OnCompositionIndicationTimeout();

    OpalIM * GetIncomingMessage();

    virtual void InternalOnMessageSent(const MessageSentInfo & info);

    static PString CreateKey(const PString & from, const PString & to);

    void ResetLastUsed();

  protected:
    virtual SentStatus InternalSend();
    virtual SentStatus InternalSendOutsideCall(OpalIM * message);
    virtual SentStatus InternalSendInsideCall(OpalIM * message);

    PMutex m_notificationMutex;
    IncomingIMNotifier                   m_incomingMessageNotifier;
    MessageSentNotifier                  m_messageSentNotifier;
    CompositionIndicationChangedNotifier m_compositionIndicationChangedNotifier;

    OpalManager  * m_manager;
    PStringOptions m_attributes;

    PSafePtr<OpalConnection> m_connection;
    PSafePtr<OpalPresentity> m_presentity;

    PMutex m_incomingMessagesMutex;
    PQueue<OpalIM> m_incomingMessages;

    PMutex m_outgoingMessagesMutex;
    OpalIM * m_currentOutgoingMessage;
    PQueue<OpalIM> m_outgoingMessages;

    PMutex m_lastUsedMutex;
    PTime m_lastUsed;

  private:    
    PString m_id, m_localURL, m_remoteURL, m_key;

};

class OpalConnectionIMContext : public OpalIMContext
{
  public:
    OpalConnectionIMContext();
};

class OpalPresentityIMContext : public OpalIMContext
{
  public:
    OpalPresentityIMContext();
};

/////////////////////////////////////////////////////////////////////

class OpalIMManager : public PObject
{
  public:
    OpalIMManager(OpalManager & manager);
    ~OpalIMManager();

    class IM_Work;

    OpalIMContext::SentStatus OnIncomingMessage(OpalIM * im, PString & conversationId, PSafePtr<OpalConnection> conn = NULL);
    void OnCompositionIndicationTimeout(const PString & conversationId);

    void AddContext(PSafePtr<OpalIMContext> context);
    void RemoveContext(OpalIMContext * context);

    void GarbageCollection();

    PSafePtr<OpalIMContext> FindContextByIdWithLock(
      const PString & key,
      PSafetyMode mode = PSafeReadWrite
    );

    PSafePtr<OpalIMContext> FindContextByNamesWithLock(
      const PString & local, 
      const PString & remote, 
      PSafetyMode mode = PSafeReadWrite
    );

    PSafePtr<OpalIMContext> FindContextForMessageWithLock(OpalIM & im, OpalConnection * conn = NULL);

    typedef PNotifierTemplate<OpalIMContext &> NewConversationNotifier;
    #define PDECLARE_NewConversationNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMManager, cls, fn, OpalIMContext &)
    #define PCREATE_NewConversationNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIMContext &)

    class NewConversationCallBack : public PObject {
      public:
        NewConversationNotifier m_notifier;
        PString m_scheme;
    };

    void AddNotifier(const NewConversationNotifier & notifier, const PString & scheme);
    bool RemoveNotifier(const NewConversationNotifier & notifier, const PString & scheme);


    // thread pool declarations
    class IM_Work
    {
      public:
        IM_Work(OpalIMManager & mgr, const PString & conversationId);
        virtual ~IM_Work();

        virtual void Work() = 0;

        OpalIMManager & m_mgr;
        PString m_conversationId;
    };

    class NewIncomingIM_Work : public IM_Work 
    {
      public:
        NewIncomingIM_Work(OpalIMManager & mgr, const PString & conversationId)
          : IM_Work(mgr, conversationId)
        { }
        virtual void Work()
        { m_mgr.InternalOnNewIncomingIM(m_conversationId); }
    };

    class NewConversation_Work : public IM_Work 
    {
      public:
        NewConversation_Work(OpalIMManager & mgr, const PString & conversationId)
          : IM_Work(mgr, conversationId)
        { }
        virtual void Work()
        { m_mgr.InternalOnNewConversation(m_conversationId); }
    };

    class MessageSent_Work : public IM_Work 
    {
      public:
        MessageSent_Work(OpalIMManager & mgr, const PString & conversationId, const OpalIMContext::MessageSentInfo & info)
          : IM_Work(mgr, conversationId)
          , m_info(info)
        { }
        virtual void Work()
        { m_mgr.InternalOnMessageSent(m_conversationId, m_info); }

        OpalIMContext::MessageSentInfo m_info;
    };

    class CompositionIndicationTimeout_Work : public IM_Work 
    {
      public:
        CompositionIndicationTimeout_Work(OpalIMManager & mgr, const PString & conversationId)
          : IM_Work(mgr, conversationId)
        { }
        virtual void Work()
        { m_mgr.InternalOnCompositionIndicationTimeout(m_conversationId); }
    };


    void AddWork(IM_Work * work);
    virtual void InternalOnNewConversation(const PString & conversation);
    virtual void InternalOnNewIncomingIM(const PString & conversation);
    virtual void InternalOnMessageSent(const PString & conversation, const OpalIMContext::MessageSentInfo & info);
    virtual void InternalOnCompositionIndicationTimeout(const PString & conversationId);

  protected:
    PQueuedThreadPool<IM_Work> m_imThreadPool;

    PTime m_lastGarbageCollection;
    OpalManager & m_manager;
    bool m_deleting;
    typedef PSafeDictionary<PString, OpalIMContext> ContextsByConversationId;
    ContextsByConversationId m_contextsByConversationId;

    PMutex m_contextsByNamesMutex;
    typedef std::multimap<std::string, PString> ContextsByNames;
    ContextsByNames m_contextsByNames;

    PMutex m_notifierMutex;
    PList<NewConversationCallBack> m_callbacks;
};

/////////////////////////////////////////////////////////////////////

class RTP_IMFrame : public RTP_DataFrame
{
  public:
    RTP_IMFrame();
    RTP_IMFrame(const PString & contentType);
    RTP_IMFrame(const PString & contentType, const T140String & content);
    RTP_IMFrame(const BYTE * data, PINDEX len, PBoolean dynamic = true);

    void SetContentType(const PString & contentType);
    PString GetContentType() const;

    void SetContent(const T140String & text);
    bool GetContent(T140String & text) const;

    PString AsString() const { return PString((const char *)GetPayloadPtr(), GetPayloadSize()); }
};

class OpalIMMediaStream : public OpalMediaStream
{
  public:
    OpalIMMediaStream(
      OpalConnection & conn,
      const OpalMediaFormat & mediaFormat, ///<  Media format for stream
      unsigned sessionID,                  ///<  Session number for stream
      bool isSource                        ///<  Is a source stream
    );

    virtual PBoolean IsSynchronous() const         { return false; }
    virtual PBoolean RequiresPatchThread() const   { return false; }

    bool ReadPacket(RTP_DataFrame & packet);
    bool WritePacket(RTP_DataFrame & packet);
};

#endif // OPAL_HAS_IM

#endif // OPAL_IM_IM_H