nsDirIndexParser.h (1522B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef __NSDIRINDEX_H_ 7 #define __NSDIRINDEX_H_ 8 9 #include "nsString.h" 10 #include "nsCOMPtr.h" 11 #include "nsIDirIndexListener.h" 12 #include "mozilla/RefPtr.h" 13 14 class nsIDirIndex; 15 class nsITextToSubURI; 16 17 /* CID: {a0d6ad32-1dd1-11b2-aa55-a40187b54036} */ 18 19 class nsDirIndexParser : public nsIDirIndexParser { 20 private: 21 virtual ~nsDirIndexParser() = default; 22 23 nsDirIndexParser() = default; 24 void Init(); 25 26 public: 27 NS_DECL_ISUPPORTS 28 NS_DECL_NSISTREAMLISTENER 29 NS_DECL_NSIREQUESTOBSERVER 30 NS_DECL_NSIDIRINDEXPARSER 31 32 static already_AddRefed<nsIDirIndexParser> CreateInstance() { 33 RefPtr<nsDirIndexParser> parser = new nsDirIndexParser(); 34 parser->Init(); 35 return parser.forget(); 36 } 37 38 enum fieldType { 39 FIELD_UNKNOWN = 0, // MUST be 0 40 FIELD_FILENAME, 41 FIELD_CONTENTLENGTH, 42 FIELD_LASTMODIFIED, 43 FIELD_FILETYPE 44 }; 45 46 protected: 47 nsCOMPtr<nsIDirIndexListener> mListener; 48 49 nsCString mBuf; 50 int32_t mLineStart{0}; 51 int mFormat[8]{-1}; 52 53 nsresult ProcessData(nsIRequest* aRequest); 54 void ParseFormat(const char* aFormatStr); 55 void ParseData(nsIDirIndex* aIdx, char* aDataStr, int32_t lineLen); 56 57 struct Field { 58 const char* mName; 59 fieldType mType; 60 }; 61 62 static Field gFieldTable[]; 63 }; 64 65 #endif