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 GStream *DataStore;
00037 bool OwnDataStore;
00038
00039
00040 bool Lock();
00041 void Unlock();
00042 bool CreateTempData();
00043 char *NewValue(char *&s, bool Alloc = true);
00044 char *StartOfField(char *s, char *Feild);
00045 char *NextField(char *s);
00046
00047 public:
00048 List<GMime> Children;
00049
00050 GMime();
00051 virtual ~GMime();
00052
00053
00054 void Empty();
00055 char *GetHeaders() { return Headers; }
00056 int GetLength() { return DataSize; }
00057 GStream *GetData();
00058 bool SetData(GStream *d, int p = 0, int s = -1, GSemaphore *l = 0);
00059 bool SetData(char *Str, int Len);
00060
00061
00062 char *Get(char *Field, bool Short = true, char *Default = 0);
00063 bool Set(char *Field, char *Value);
00064 char *GetSub(char *Field, char *Sub);
00065 bool SetSub(char *Field, char *Sub, char *Value, char *DefaultValue = 0);
00066
00067
00068 char *GetMimeType() { return Get("Content-Type", true, "text/plain"); }
00069 bool SetMimeType(char *s) { return Set("Content-Type", s); }
00070 char *GetEncoding() { return Get("Content-Transfer-Encoding"); }
00071 bool SetEncoding(char *s) { return Set("Content-Transfer-Encoding", s); }
00072 char *GetCharSet() { return GetSub("Content-Type", "Charset"); }
00073 bool SetCharSet(char *s) { return SetSub("Content-Type", "Charset", s, "text/plain"); }
00074 char *GetBoundary() { return GetSub("Content-Type", "Boundary"); }
00075 bool SetBoundary(char *s) { return SetSub("Content-Type", "Boundary", s, "text/plain"); }
00076
00077
00078 class GMimeText
00079 {
00080 public:
00081 class GMimeDecode : public GPullStreamer, public GMimeAction
00082 {
00083 int Parse(GStringPipe *Source, class ParentState *State = 0);
00084 public:
00085 int Pull(GStream *Source, GStreamEnd *End = 0);
00086 void Empty();
00087 } Decode;
00088
00089 class GMimeEncode : public GPushStreamer, public GMimeAction
00090 {
00091 public:
00092 int Push(GStream *Dest, GStreamEnd *End = 0);
00093 void Empty();
00094 } Encode;
00095
00096 } Text;
00097
00098 friend class GMime::GMimeText::GMimeDecode;
00099 friend class GMime::GMimeText::GMimeEncode;
00100
00101 class GMimeBinary
00102 {
00103 public:
00104 class GMimeRead : public GPullStreamer, public GMimeAction
00105 {
00106 public:
00107 int Pull(GStream *Source, GStreamEnd *End = 0);
00108 void Empty();
00109 } Read;
00110
00111 class GMimeWrite : public GPushStreamer, public GMimeAction
00112 {
00113 public:
00114 int64 GetSize();
00115 int Push(GStream *Dest, GStreamEnd *End = 0);
00116 void Empty();
00117 } Write;
00118
00119 } Binary;
00120
00121 friend class GMime::GMimeBinary::GMimeRead;
00122 friend class GMime::GMimeBinary::GMimeWrite;
00123 };
00124
00125 #endif