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