File: job.h

package info (click to toggle)
apt-cacher-ng 2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,032 kB
  • ctags: 1,705
  • sloc: cpp: 16,869; sh: 536; ansic: 404; perl: 377; makefile: 124
file content (99 lines) | stat: -rw-r--r-- 2,235 bytes parent folder | download | duplicates (2)
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

#ifndef _JOB_H
#define _JOB_H

#include "config.h"
#include "header.h"
#include "acbuf.h"
#include <sys/types.h>
#include "fileitem.h"
#include "maintenance.h"

namespace acng
{

class con;

class job {


   public:

	   typedef enum : char
	{
		R_DONE = 0, R_AGAIN = 1, R_DISCON = 2, R_NOTFORUS = 3
	} eJobResult;

	   typedef enum : char {
	   	STATE_SEND_MAIN_HEAD,
	   	STATE_HEADER_SENT,
	   	STATE_SEND_PLAIN_DATA,
	   	STATE_SEND_CHUNK_HEADER,
	   	STATE_SEND_CHUNK_DATA,
	   	STATE_TODISCON,
	   	STATE_ALLDONE,
	   	STATE_SEND_BUFFER,
	   	STATE_ERRORCONT,
	   	STATE_FINISHJOB
	   } eJobState;

      job(header *h, con *pParent);
      ~job();
      //  __attribute__((externally_visible))  
      
      void PrepareDownload(LPCSTR headBuf);

      /*
       * Start or continue returning the file.
       */
      eJobResult SendData(int confd);
  
   private:
      
	  int m_filefd;
	  con *m_pParentCon;
      
      bool m_bChunkMode;
      bool m_bClientWants2Close;
      bool m_bIsHttp11;
      bool m_bNoDownloadStarted;
      
      eJobState m_state, m_backstate;
      
      tSS m_sendbuf;
      mstring m_sFileLoc; // local_relative_path_to_file
      tSpecialRequest::eMaintWorkType m_eMaintWorkType = tSpecialRequest::workNotSpecial;
      mstring m_sOrigUrl; // local SAFE copy of the originating source
      
      header *m_pReqHead; // copy of users requests header

      fileItemMgmt m_pItem;
      off_t m_nSendPos, m_nCurrentRangeLast;
      off_t m_nAllDataCount;
      
      unsigned long m_nChunkRemainingBytes;
      rex::eMatchType m_type;
      
      job(const job&);
      job & operator=(const job&);

      const char * BuildAndEnqueHeader(const fileitem::FiStatus &fistate, const off_t &nGooddataSize, header& respHead);
      fileitem::FiStatus _SwitchToPtItem();
      void SetErrorResponse(const char * errorLine, const char *szLocation=nullptr, const char *bodytext=nullptr);
      void PrepareLocalDownload(const mstring &visPath,
    			const mstring &fsBase, const mstring &fsSubpath);

      bool ParseRange();

      off_t m_nReqRangeFrom, m_nReqRangeTo;
};


class tTraceData: public tStrSet, public base_with_mutex {
public:
	static tTraceData& getInstance();
};

}

#endif