00001 #ifndef _GMIME_H_
00002 #define _GMIME_H_
00003
00004 #include "LgiNetInc.h"
00005 #include "GStream.h"
00006 #include "INetTools.h"
00007
00008 class GMime;
00009
00010 class GMimeAction
00011 {
00012 friend class GMime;
00013
00014 protected:
00015
00016 GMime *Mime;
00017
00018 public:
00019 GMimeAction()
00020 {
00021 Mime = 0;
00022 }
00023
00024 virtual void Empty() {}
00025 };
00026
00027 class GMimeBuf : public GStringPipe
00028 {
00029 int Total;
00030 GStreamI *Src;
00031 GStreamEnd *End;
00032
00033 public:
00034 GMimeBuf(GStreamI *src, GStreamEnd *end);
00035 int Pop(char *Str, int BufSize);
00036 };
00037
00038 class GMime
00039 {
00040
00041 char *Headers;
00042
00043
00044 int DataPos;
00045 int DataSize;
00046 GSemaphore *DataLock;
00047 GStreamI *DataStore;
00048 bool OwnDataStore;
00049
00050
00051 char *TmpPath;
00052 GMime *Parent;
00053 GArray<GMime*> Children;
00054
00055
00056 bool Lock();
00057 void Unlock();
00058 bool CreateTempData();
00059 char *NewValue(char *&s, bool Alloc = true);
00060 char *StartOfField(char *s, const char *Feild);
00061 char *NextField(char *s);
00062 char *GetTmpPath();
00063
00064 public:
00065 static char *DefaultCharset;
00066
00067 GMime(char *TmpFileRoot = 0);
00068 virtual ~GMime();
00069
00070
00071 bool Insert(GMime *m, int pos = -1);
00072 void Remove();
00073 int Length() { return Children.Length(); }
00074 GMime *operator[](int i);
00075 void DeleteChildren() { Children.DeleteObjects(); }
00076
00077 void Empty();
00078 bool SetHeaders(char *h);
00079 char *GetHeaders() { return Headers; }
00080 int GetLength() { return DataSize; }
00081 GStreamI *GetData(bool Detach = false);
00082 bool SetData(GStreamI *d, int p = 0, int s = -1, GSemaphore *l = 0);
00083 bool SetData(char *Str, int Len);
00084
00085
00086 char *Get(const char *Field, bool Short = true, const char *Default = 0);
00087 bool Set(const char *Field, const char *Value);
00088 char *GetSub(const char *Field, const char *Sub);
00089 bool SetSub(const char *Field, const char *Sub, const char *Value, const char *DefaultValue = 0);
00090
00091
00092 char *GetMimeType() { return Get("Content-Type", true, "text/plain"); }
00093 bool SetMimeType(const char *s) { return Set("Content-Type", s); }
00094 char *GetEncoding() { return Get("Content-Transfer-Encoding"); }
00095 bool SetEncoding(const char *s) { return Set("Content-Transfer-Encoding", s); }
00096 char *GetCharset() { return GetSub("Content-Type", "Charset"); }
00097 bool SetCharset(const char *s) { return SetSub("Content-Type", "Charset", s, DefaultCharset); }
00098 char *GetBoundary() { return GetSub("Content-Type", "Boundary"); }
00099 bool SetBoundary(const char *s) { return SetSub("Content-Type", "Boundary", s, DefaultCharset); }
00100 char *GetFileName();
00101 bool SetFileName(const char *s) { return SetSub("Content-Type", "Name", s, DefaultCharset); }
00102
00103
00104 class GMimeText
00105 {
00106 public:
00107 class GMimeDecode : public GPullStreamer, public GMimeAction
00108 {
00109 public:
00110 int Pull(GStreamI *Source, GStreamEnd *End = 0);
00111 int Parse(GStringPipe *Source, class ParentState *State = 0);
00112 void Empty();
00113 } Decode;
00114
00115 class GMimeEncode : public GPushStreamer, public GMimeAction
00116 {
00117 public:
00118 int Push(GStreamI *Dest, GStreamEnd *End = 0);
00119 void Empty();
00120 } Encode;
00121
00122 } Text;
00123
00124 friend class GMime::GMimeText::GMimeDecode;
00125 friend class GMime::GMimeText::GMimeEncode;
00126
00127 class GMimeBinary
00128 {
00129 public:
00130 class GMimeRead : public GPullStreamer, public GMimeAction
00131 {
00132 public:
00133 int Pull(GStreamI *Source, GStreamEnd *End = 0);
00134 void Empty();
00135 } Read;
00136
00137 class GMimeWrite : public GPushStreamer, public GMimeAction
00138 {
00139 public:
00140 int64 GetSize();
00141 int Push(GStreamI *Dest, GStreamEnd *End = 0);
00142 void Empty();
00143 } Write;
00144
00145 } Binary;
00146
00147 friend class GMime::GMimeBinary::GMimeRead;
00148 friend class GMime::GMimeBinary::GMimeWrite;
00149 };
00150
00151 #endif