This file is indexed.

/usr/include/openh323/h323filetransfer.h is in libh323plus-dev 1.24.0~dfsg2-1ubuntu1.

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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
/*
 * h323filetransfer.h
 *
 * H323 File Transfer class.
 *
 * h323plus library
 *
 * Copyright (c) 2008 ISVO (Asia) Pte. Ltd.
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (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/
 *
 * Alternatively, the contents of this file may be used under the terms
 * of the General Public License (the  "GNU License"), in which case the
 * provisions of GNU License are applicable instead of those
 * above. If you wish to allow use of your version of this file only
 * under the terms of the GNU License and not to allow others to use
 * your version of this file under the MPL, indicate your decision by
 * deleting the provisions above and replace them with the notice and
 * other provisions required by the GNU License. If you do not delete
 * the provisions above, a recipient may use your version of this file
 * under either the MPL or the GNU License."
 *
 * 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 Initial Developer of the Original Code is ISVO (Asia) Pte. Ltd.
 *
 * Contributor(s): ______________________________________.
 *
 * $Log: h323filetransfer.h,v $
 * Revision 1.4  2011/10/18 13:32:30  shorne
 * Rearranged Default Session ids so FECC is Session 3 for better interoperability.
 *
 * Revision 1.3  2009/02/21 14:06:02  shorne
 * Major FileTransfer code review and improvement
 *
 * Revision 1.2  2008/05/23 11:19:38  willamowius
 * switch BOOL to PBoolean to be able to compile with Ptlib 2.2.x
 *
 * Revision 1.1  2008/01/01 00:16:12  shorne
 * Added GnuGknat and FileTransfer support
 *
 *
 *
 */


#ifdef H323_FILE

#include <ptclib/delaychan.h>
#include <list>

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

class H323File
{
  public:
	PString    m_Filename;
	PString    m_Directory;
	long       m_Filesize;
};

class H323FileTransferList : public list<H323File>
{ 
  public:
    H323FileTransferList();
	PINDEX GetSize();
	H323File * GetAt(PINDEX i);
    void Add(const PString & filename, const PDirectory & directory, long filesize);
    void SetSaveDirectory(const PString directory);
	const PDirectory & GetSaveDirectory();
 
	void SetDirection(H323Channel::Directions _direction);
	H323Channel::Directions GetDirection();

	void SetMaster(PBoolean state);
	PBoolean IsMaster();

  protected:
	H323Channel::Directions direction;
	PDirectory saveDirectory;
	PBoolean master;
};


//////////////////////////////////////////////////////////////////////////////////
/**This class describes the File Transfer logical channel.
 */
class H323FileTransferHandler;
class H323FileTransferChannel : public H323Channel
{
    PCLASSINFO(H323FileTransferChannel, H323Channel);
  public:
  /**@name Construction */
  //@{
    /**Create a new channel.
     */
    H323FileTransferChannel(
      H323Connection & connection,          ///<  Connection to endpoint for channel
      const H323Capability & capability,    ///<  Capability channel is using
      Directions theDirection,              ///<  Direction of channel
	  RTP_UDP & rtp,                        ///<  RTP Session for channel
      unsigned theSessionID,                ///<  Session ID for channel
	  const H323FileTransferList & list		///<  List of files to Request/Send
    );

    ~H323FileTransferChannel();
  //@}

  /**@name Overrides from class H323Channel */
  //@{

   /**Indicate the direction of the channel.
       Return if the channel is bidirectional, or unidirectional, and which
       direction for the latter case.
     */
    virtual H323Channel::Directions GetDirection() const;

    /**Set the initial bandwidth for the channel.
       This calculates the initial bandwidth required by the channel and
       returns TRUE if the connection can support this bandwidth.

       The default behaviour does nothing.
     */
    virtual PBoolean SetInitialBandwidth();

    /**Fill out the OpenLogicalChannel PDU for the particular channel type.
     */
    virtual PBoolean OnSendingPDU(
      H245_OpenLogicalChannel & openPDU  ///<  Open PDU to send. 
    ) const;

    virtual PBoolean OnSendingPDU(H245_H2250LogicalChannelParameters & param) const;

    virtual void OnSendOpenAck(const H245_OpenLogicalChannel & openPDU, 
							 H245_OpenLogicalChannelAck & ack) const;

    virtual void OnSendOpenAck(H245_H2250LogicalChannelAckParameters & param) const;


    /**This is called after a request to create a channel occurs from the
       local machine via the H245LogicalChannelDict::Open() function, and
       the request has been acknowledged by the remote endpoint.

       The default makes sure the parameters are compatible and passes on
       the PDU to the rtp session.
     */
    virtual PBoolean OnReceivedPDU(
      const H245_OpenLogicalChannel & pdu,    ///<  Open PDU
      unsigned & errorCode                    ///<  Error code on failure
    );

    virtual PBoolean OnReceivedPDU(const H245_H2250LogicalChannelParameters & param,
							 unsigned & errorCode);

    virtual PBoolean OnReceivedAckPDU(const H245_OpenLogicalChannelAck & pdu);

    virtual PBoolean OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param);


    /**Handle channel data reception.

       This is called by the thread started by the Start() function and is
       a loop reading from the transport and calling HandlePacket() for each
       PDU read.
      */
    virtual void Receive();

    /**Handle channel data transmission.

       This is called by the thread started by the Start() function and is
       typically a loop reading from the codec and writing to the transport
       (eg an RTP_session).
      */
    virtual void Transmit();


    virtual PBoolean Open();

    virtual PBoolean Start();

    virtual void Close();

    virtual PBoolean SetDynamicRTPPayloadType(int newType);
    RTP_DataFrame::PayloadTypes GetDynamicRTPPayloadType() const { return rtpPayloadType; }
	
    H323FileTransferHandler * GetHandler() const { return fileHandler; }

  //@}

  protected:
    PBoolean ExtractTransport(const H245_TransportAddress & pdu,
			     PBoolean isDataPort,
			     unsigned & errorCode
						 );

    PBoolean RetreiveFileInfo(const H245_GenericInformation & info, 
			     H323FileTransferList & filelist
						 );

    void SetFileList(H245_OpenLogicalChannel & open, H323FileTransferList flist) const;
    PBoolean GetFileList(const H245_OpenLogicalChannel & open);

    unsigned sessionID;
    Directions direction;
    RTP_UDP & rtpSession;
    H323_RTP_Session & rtpCallbacks;
    H323FileTransferHandler *fileHandler;
	H323FileTransferList filelist;
    RTP_DataFrame::PayloadTypes rtpPayloadType;

};

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

class H323FileTransferCapability : public H323DataCapability
{
  PCLASSINFO(H323FileTransferCapability, H323DataCapability);

  public:
  /**@name Construction */
  //@{
    /**Create a new File Transfer capability with default values.
      */
    H323FileTransferCapability();

    /**Create a new File Transfer capability with defined value.
      */
    H323FileTransferCapability(unsigned maxBitRate, unsigned maxBlockSize);
  //@}

  /**@name Overrides from class PObject */
  //@{
    /**Compare two capability instances. This compares the main and sub-types
       of the capability.
     */
    Comparison Compare(const PObject & obj) const;


	/**Clone the File Transfer Capability
	  */
	PObject * Clone() const;
  //@}

  /**@name Identification functions */
  //@{

    virtual PString GetFormatName() const
    { return "TFTP over RTP"; }

    /**Get the sub-type of the capability. This is a code dependent on the
       main type of the capability.

       This returns one of the four possible combinations of mode and speed
       using the enum values of the protocol ASN H245_AudioCapability class.
     */
	virtual unsigned GetSubType() const;

    /**Get the default RTP session.
       This function gets the default RTP session ID for the capability
       type. 
       The default behaviour returns zero, indicating it is not an RTP
       based capability.
      */
    virtual unsigned GetDefaultSessionID() const;
  //@}
    
  /**@name Protocol manipulation */
  //@{
    /**This function is called whenever and outgoing TerminalCapabilitySet
       or OpenLogicalChannel PDU is being constructed for the control channel.
       It allows the capability to set the PDU fields from information in
       members specific to the class.

       The default behaviour sets the pdu and calls OnSendingPDU with a
       H245_DataProtocolCapability parameter.
     */
    virtual PBoolean OnSendingPDU(
      H245_DataApplicationCapability & pdu
    ) const;

    /**This function is called whenever and incoming TerminalCapabilitySet
       or OpenLogicalChannel PDU has been used to construct the control
       channel. It allows the capability to set from the PDU fields,
       information in members specific to the class.

       The default behaviour does nothing.
     */

    virtual PBoolean OnReceivedPDU(
      const H245_DataApplicationCapability & cap  ///< PDU to get information from
    );

    /**This function is called whenever and outgoing RequestMode
       PDU is being constructed for the control channel. It allows the
       capability to set the PDU fields from information in members specific
       to the class.

       The default behaviour sets the PDUs tag according to the GetSubType()
       function (translated to different enum).
     */
    virtual PBoolean OnSendingPDU(
      H245_DataMode & pdu  ///< PDU to set information on
    ) const;

    /**This function is called whenever and incoming TerminalCapabilitySet
       or OpenLogicalChannel PDU has been used to construct the control
       channel. It allows the capability to set from the PDU fields,
       information in members specific to the class.

       The default behaviour does nothing.
     */
    PBoolean OnReceivedPDU(const H245_GenericCapability & pdu);

    /**This function is called whenever and outgoing TerminalCapabilitySet
       PDU is being constructed for the control channel. It allows the
       capability to set the PDU fields from information in members specific
       to the class.

       The default behaviour calls the OnSendingPDU() function with a more
       specific PDU type.
     */
    PBoolean OnSendingPDU(H245_GenericCapability & pdu) const;

	//@}

	enum blockSizes {
		e_RFC1350   = 512,
		e_1024      = 1024,
		e_1428      = 1428,
		e_2048      = 2048,
		e_4096      = 4096,
		e_8192      = 8192
	};

  /**@name Operations */
  //@{
    /**Create the channel instance, allocating resources as required.
     */
    virtual H323Channel * CreateChannel(
      H323Connection & connection,          ///< Owner connection for channel
      H323Channel::Directions direction,    ///< Direction of channel
      unsigned sessionID,                   ///< Session ID for RTP channel
      const H245_H2250LogicalChannelParameters * param
                                            ///< Parameters for channel
    ) const;
  //@}

  /**@name Utilities */
  //@{
    /**Get the BlockSize of data to be sent.
     */
	unsigned GetBlockSize() const  { return m_blockSize; }

    /**Get the BlockSize of data to be sent (as Capability Parameter).
     */
	unsigned GetBlockRate() const  { return maxBitRate / m_blockOctets; }

    /**Get the BlockSize of data to be sent (as Octets size).
     */
	unsigned GetOctetSize() const  { return m_blockOctets; }

    /**Get the Transfer Mode.
     */
	unsigned GetTransferMode() const  { return m_transferMode; }

	/**Set the List of files to send
	 */
	void SetFileTransferList(const H323FileTransferList & list);
  //@}

  protected:
    unsigned				m_blockSize;          ///< Size indicator in capability negotiation
	unsigned				m_blockOctets;        ///< Block Octet size
	unsigned				m_transferMode;       ///< Mode of transfer Raw Tftp or RTP encaptulated
	H323FileTransferList	m_filelist;           ///< File list to Request/Send

};

class H323FilePacket : public PBYTEArray
{
  PCLASSINFO(H323FilePacket, PBYTEArray);

public:
  enum opcodes {
	  e_PROB,
	  e_RRQ,
	  e_WRQ,
	  e_DATA,
	  e_ACK,
	  e_ERROR
  };

  enum errCodes {
      ErrNotDefined,
	  ErrFileNotFound,
	  ErrAccessViolation,
	  ErrDiskFull,
	  ErrIllegalOperation,
	  ErrUnknownID,
	  ErrFileExists,
	  ErrNoSuchUser
  }; 

  void BuildPROB();
  void BuildRequest(opcodes code, const PString & filename, int filesize, int blocksize);
  void BuildData(int blockid, int size);
  void BuildACK(int blockid,int filesize = 0);
  void BuildError(int errorcode,PString errmsg);

  H323FilePacket::opcodes GetPacketType() const;

  // for RRQ/WRQ Only
  PString GetFileName() const;
  unsigned GetFileSize() const;
  unsigned GetBlockSize() const;

  // for DATA only
  unsigned GetDataSize() const;
  BYTE * GetDataPtr();
  int GetBlockNo() const;

  // For ACK
  int GetACKBlockNo() const;

  // for ERROR messages
  void GetErrorInformation(int & ErrCode, PString & ErrStr) const;

  protected:
	void attach(PString & data);

};

class H323FileIOChannel : public PIndirectChannel
{
  public:

	  enum fileError {
		  e_OK,
		  e_NotFound,
		  e_AccessDenied,
		  e_FileExists = 6
	  };

    H323FileIOChannel(PFilePath _file, PBoolean read);
	~H323FileIOChannel();

	PBoolean IsError(fileError & err);

	PBoolean Open();
	PBoolean Close();

    PBoolean Read(void * buffer, PINDEX & amount);
    PBoolean Write(const void * buf, PINDEX amount);

	unsigned GetFileSize();

  protected:
	PBoolean CheckFile(PFilePath _file, PBoolean read, fileError & errCode);

    PMutex chanMutex;
	PBoolean fileopen;
	unsigned filesize;
	fileError IOError;
};


//////////////////////////////////////////////////////////////////////////////
// FileTransferHandler
// Derive you class from this to set and collect events associated with
// the file transfer
//
class H323FileTransferHandler : public PObject
{
  PCLASSINFO(H323FileTransferHandler, PObject);
	
public:
	
  H323FileTransferHandler(H323Connection & connection, 
	                    unsigned sessionID,
			    H323Channel::Directions dir,
			    H323FileTransferList & filelist
			  );

  ~H323FileTransferHandler();

  enum transferState {
	  e_probing,         ///< Probing for connectivity
	  e_connect,         ///< Received a probe packet and confirm
	  e_waiting,         ///< Waiting for RRQ/WRQ command
	  e_sending,         ///< Sending Data
	  e_receiving,       ///< Receiving Data
	  e_completed,       ///< Transfer Completed
	  e_error            ///< Error Received
  };

  enum receiveStates {
	  recOK,             ///< received block OK
	  recPartial,        ///< Only partial block received
	  recComplete,       ///< File was fully received
	  recIncomplete,     ///< Incomplete receival of File.
	  recTimeOut,        ///< TimeOut waiting for packet.
	  recReady           ///< Ready to receive files
  };

//////////////////////////
// User override to custom set blocksize and transmission rate

  virtual void SetBlockSize(H323FileTransferCapability::blockSizes size);
  virtual void SetMaxBlockRate(unsigned rate);

// User override to get events

  virtual void OnStateChange(transferState newState) {};
  virtual void OnFileStart(const PString & filename, unsigned filesize, PBoolean transmit) {};
  virtual void OnFileOpenError(const PString & filename, H323FileIOChannel::fileError _err) {};
  virtual void OnError(const PString ErrMsg) {};
  virtual void OnFileComplete(const PString & filename) {};
  virtual void OnFileProgress(const PString & filename, int Blockno, unsigned OctetsSent, PBoolean transmit) {};
  virtual void OnFileError(const PString & filename, int Blockno, PBoolean transmit) {};
  virtual void OnTransferComplete() {};

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


  H323FileTransferCapability::blockSizes GetBlockSize()  
        { return (H323FileTransferCapability::blockSizes)blockSize; }
  unsigned GetBlockRate()  
        { return blockRate; }

  PBoolean Start(H323Channel::Directions direction);
  PBoolean Stop(H323Channel::Directions direction);

  void SetPayloadType(RTP_DataFrame::PayloadTypes _type);

  void SetMaster(PBoolean newVal) 
	        { master = newVal; }

protected:

  PBoolean TransmitFrame(H323FilePacket & buffer, PBoolean final);
  PBoolean ReceiveFrame(H323FilePacket & buffer, PBoolean & final);

  void ChangeState(transferState newState);
  void SetBlockState(receiveStates state);

  H323FileTransferList filelist;

  PThread * TransmitThread;
  PThread * ReceiveThread;

  PDECLARE_NOTIFIER(PThread, H323FileTransferHandler, Transmit);
  PDECLARE_NOTIFIER(PThread, H323FileTransferHandler, Receive);

  PBoolean transmitRunning;
  PBoolean receiveRunning;
  PSyncPointAck        exitTransmit;
  PSyncPointAck        exitReceive;
  PTimer               shutdownTimer;

  RTP_DataFrame transmitFrame;   ///< Template RTP Frame for sending/receiving

  RTP_Session * session;         ///< RTP Session

  PSyncPoint probMutex;    ///< probing Mutex
  PMutex transferMutex;     ///< Mutex for read/write operation
  PMutex stateMutex;        ///< Mutex for state change
  PSyncPoint nextFrame;     ///< Wait for confirmation before sending the next block
  PINDEX responseTimeOut;   ///< Time to wait for a response (set at 1.5 sec)

  PTime *StartTime;
  PBoolean master;          ///< Was Initiator of the channel

private:
  RTP_DataFrame::PayloadTypes rtpPayloadType;  ///< Payload Type should be dynamically allocated
  int msBetweenBlocks;                         ///< milliseconds between sending next block of data
  PAdaptiveDelay sendwait;                     ///< Wait before sending the next block of data
  unsigned timestamp;                          ///< TimeStamp of last packet received
  unsigned blockSize;                          ///< Size of the Blocks to transmit
  unsigned blockRate;                          ///< Rate of Transmission in bits/sec
  
  // Transfer states
  H323FileIOChannel * curFile;                 ///< Current File being sent
  H323FileIOChannel::fileError ioerr;          ///< Last IO error
  transferState currentState;                  ///< Current state of Transmission
  receiveStates blockState;                    ///< State of Received block          
  int lastBlockNo;                             ///< Last Block No sent
  unsigned lastBlockSize;                      ///< Last Block Size sent
  PString curFileName;						   ///< Current FileName being sent/received
  unsigned curFileSize;                        ///< Current File being Transmitted size
  unsigned curBlockSize;                       ///< Block size of current transmittion
  unsigned curProgSize;						   ///< Current amount of data sent/received
};

#endif