File: job.h

package info (click to toggle)
apt-cacher-ng 0.7.27-1~bpo70+1
  • links: PTS
  • area: main
  • in suites: wheezy-backports
  • size: 1,740 kB
  • sloc: cpp: 13,987; sh: 519; perl: 442; ansic: 414; makefile: 77
file content (93 lines) | stat: -rw-r--r-- 2,140 bytes parent folder | download
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

#ifndef _JOB_H
#define _JOB_H

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

/*
class fileitem_base;
typedef SHARED_PTR<fileitem_base> tFileItemPtr;
*/

class con;

class job {


   public:

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

	   typedef enum {
	   	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();

      /*
       * Start or continue returning the file.
       */
      eJobResult SendData(int confd, int nAllJobCount);
  
   private:
      
	  int m_filefd;
	  con *m_pParentCon;
      
      bool m_bChunkMode;
      bool m_bClientWants2Close;
      bool m_bIsHttp11;
      bool m_bNoDownloadStarted;
      
      eJobState m_state, m_backstate;
      
      //mstring m_sErrorMsgBuffer;
      tSS m_sendbuf;
      mstring m_sFileLoc; // local_relative_path_to_file
      mstring m_sMaintCmd;
      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;
      rechecks::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(const mstring &fileLoc);
      void SetErrorResponse(const char * errorLine, const char *szLocation=NULL, const char *bodytext=NULL);
      void HandleLocalDownload(const mstring &visPath,
    			const mstring &fsBase, const mstring &fsSubpath);

      bool ParseRange();

      off_t m_nReqRangeFrom, m_nReqRangeTo;
};

#endif