1 2 #ifndef _JOB_H 3 #define _JOB_H 4 5 #include "config.h" 6 #include "header.h" 7 #include "acbuf.h" 8 #include <sys/types.h> 9 #include "fileitem.h" 10 #include "maintenance.h" 11 12 namespace acng 13 { 14 15 class conn; 16 17 class job { 18 19 20 public: 21 22 typedef enum : char 23 { 24 R_DONE = 0, R_AGAIN = 1, R_DISCON = 2, R_NOTFORUS = 3 25 } eJobResult; 26 27 typedef enum : char { 28 STATE_SEND_MAIN_HEAD, 29 STATE_HEADER_SENT, 30 STATE_SEND_PLAIN_DATA, 31 STATE_SEND_CHUNK_HEADER, 32 STATE_SEND_CHUNK_DATA, 33 STATE_TODISCON, 34 STATE_ALLDONE, 35 STATE_SEND_BUFFER, 36 STATE_ERRORCONT, 37 STATE_FINISHJOB 38 } eJobState; 39 40 job(header *h, conn *pParent); 41 ~job(); 42 // __attribute__((externally_visible)) 43 44 void PrepareDownload(LPCSTR headBuf); 45 46 /* 47 * Start or continue returning the file. 48 */ 49 eJobResult SendData(int confd); 50 51 private: 52 53 int m_filefd; 54 conn *m_pParentCon; 55 56 bool m_bChunkMode; 57 bool m_bClientWants2Close; 58 bool m_bIsHttp11; 59 bool m_bNoDownloadStarted; 60 61 eJobState m_state, m_backstate; 62 63 tSS m_sendbuf; 64 mstring m_sFileLoc; // local_relative_path_to_file 65 tSpecialRequest::eMaintWorkType m_eMaintWorkType = tSpecialRequest::workNotSpecial; 66 mstring m_sOrigUrl; // local SAFE copy of the originating source 67 68 header *m_pReqHead; // copy of users requests header 69 70 fileItemMgmt m_pItem; 71 off_t m_nSendPos, m_nCurrentRangeLast; 72 off_t m_nAllDataCount; 73 74 unsigned long m_nChunkRemainingBytes; 75 rex::eMatchType m_type; 76 77 job(const job&); 78 job & operator=(const job&); 79 80 const char * BuildAndEnqueHeader(const fileitem::FiStatus &fistate, const off_t &nGooddataSize, header& respHead); 81 fileitem::FiStatus _SwitchToPtItem(); 82 void SetErrorResponse(const char * errorLine, const char *szLocation=nullptr, const char *bodytext=nullptr); 83 void PrepareLocalDownload(const mstring &visPath, 84 const mstring &fsBase, const mstring &fsSubpath); 85 86 bool ParseRange(); 87 88 off_t m_nReqRangeFrom, m_nReqRangeTo; 89 }; 90 91 92 class tTraceData: public tStrSet, public base_with_mutex { 93 public: 94 static tTraceData& getInstance(); 95 }; 96 97 } 98 99 #endif 100