00001
00002 #ifndef PARSER_IMPLEMENTATIONS_H
00003 #define PARSER_IMPLEMENTATIONS_H
00004
00005 #include <string>
00006
00007 #include <mime/field.h>
00008 #include <mime/object.h>
00009 #include <mime/client.h>
00010 #include <mime/parser.h>
00011
00012 namespace mime {
00013
00014 class base64_parser : public object_body_parser {
00015 std::string encoding;
00016 uint32_t buffer;
00017 int buflen;
00018 int pad;
00019 public:
00020 base64_parser(client_interface* client, object *obj) :
00021 object_body_parser(client, obj) {
00022
00023 client->data_start(obj);
00024
00025 buflen = 0;
00026 buffer = 0;
00027 pad = 0;
00028 encoding =
00029 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00030 "abcdefghijklmnopqrstuvwxyz"
00031 "0123456789+/";
00032 }
00033 virtual void parse(unsigned char c);
00034 void close() {
00035 client->data_end(obj);
00036 }
00037 };
00038
00042 class quotedprintable_parser : public object_body_parser {
00043 private:
00044 uint32_t buffer;
00045 int buflen;
00046 enum { NORMAL, SPECIAL } state;
00047 public:
00048 quotedprintable_parser(client_interface* client, object *obj) :
00049 object_body_parser(client, obj) {
00050
00051 client->data_start(obj);
00052
00053 buflen = 0;
00054 buffer = 0;
00055 state = NORMAL;
00056 }
00057 virtual void parse(unsigned char c);
00058 void close() {
00059 client->data_end(obj);
00060 }
00061 };
00062
00063 class multipart_parser : public object_body_parser {
00064 private:
00065 parser* sub_parser;
00066 object* sub_obj;
00067
00068
00069
00070
00071
00072
00073 enum { PRE, ATBOUND, FOLLBOUND, INSIDE, DONE, STARTOBJECT } state;
00074 std::string boundary;
00075 std::string buffer;
00076 int posn;
00077 public:
00078 multipart_parser(client_interface* client, object* obj);
00079 virtual void parse(unsigned char c);
00080 void close();
00081 };
00082
00083 class simple_parser : public object_body_parser {
00084 public:
00085 simple_parser(client_interface* client, object *obj) :
00086 object_body_parser(client, obj) {
00087 client->data_start(obj);
00088 }
00089 virtual void parse(unsigned char c);
00090 void close() {
00091 client->data_end(obj);
00092 }
00093 };
00094
00099 class header_parser : public parser {
00100 private:
00101 object *obj;
00102
00103 std::string key;
00104 std::string value;
00105 std::string attrkey;
00106 std::string attrval;
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 enum {
00120 KEY, VAL, ATTRKEY, ATTRVAL, PREKEY, PREVAL, POSTVAL, EOL,
00121 QTVAL, CR
00122 } state;
00123 std::map<std::string,std::string> attributes;
00124 void add_header(const std::string& key, const std::string& value);
00125 void parse_attrs(field& fld);
00126 void split(std::string& x, std::string& y, std::string& z,
00127 unsigned char spl);
00128 public:
00129 header_parser(object* obj) {
00130 this->obj = obj;
00131 state = PREKEY;
00132 }
00133 virtual void parse(unsigned char c);
00134 };
00135
00136 class any_object_parser : public object_parser {
00137 private:
00138 parser* p;
00139 enum { HEADER, HEADER_COMPLETE, BODY } state;
00140 public:
00141 any_object_parser(client_interface* client, object* obj) :
00142 object_parser(client, obj) {
00143 p = new header_parser(obj);
00144 state = HEADER;
00145 }
00146 virtual void parse(unsigned char c);
00147 void close() {
00148 if (p) {
00149 p->close();
00150 delete p;
00151 }
00152 }
00153 };
00154
00155 class parser_factory {
00156 public:
00157 static parser* generic(client_interface* client, object* obj);
00158 static parser* create(client_interface* client, object* obj);
00159 };
00160
00161 }
00162
00163 #endif
00164