yatemime.h

00001 /*
00002  * yatemime.h
00003  * This file is part of the YATE Project http://YATE.null.ro
00004  *
00005  * MIME types, body codecs and related functions
00006  *
00007  * Yet Another Telephony Engine - a fully featured software PBX and IVR
00008  * Copyright (C) 2004-2006 Null Team
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
00023  */
00024 
00025 #ifndef __YATEMIME_H
00026 #define __YATEMIME_H
00027 
00028 #ifndef __cplusplus
00029 #error C++ is required
00030 #endif
00031 
00032 #include <yateclass.h>
00033 
00037 namespace TelEngine {
00038 
00043 class YATE_API MimeBody : public GenObject
00044 {
00045 public:
00049     virtual ~MimeBody();
00050 
00056     virtual void* getObject(const String& name) const;
00057 
00062     inline const String& getType() const
00063         { return m_type; }
00064 
00069     const DataBlock& getBody() const;
00070 
00075     virtual bool isSDP() const
00076         { return false; }
00077 
00082     virtual bool isMultipart() const
00083         { return false; }
00084 
00089     virtual MimeBody* clone() const = 0;
00090 
00098     static MimeBody* build(const char* buf, int len, const String& type);
00099 
00106     static String* getUnfoldedLine(const char*& buf, int& len);
00107 
00108 protected:
00113     MimeBody(const String& type);
00114 
00118     virtual void buildBody() const = 0;
00119 
00123     mutable DataBlock m_body;
00124 
00125 private:
00126     String m_type;
00127 };
00128 
00133 class YATE_API MimeSdpBody : public MimeBody
00134 {
00135 public:
00139     MimeSdpBody();
00140 
00147     MimeSdpBody(const String& type, const char* buf, int len);
00148 
00152     virtual ~MimeSdpBody();
00153 
00159     virtual void* getObject(const String& name) const;
00160 
00165     virtual bool isSDP() const
00166         { return true; }
00167 
00172     virtual MimeBody* clone() const;
00173 
00178     inline const ObjList& lines() const
00179         { return m_lines; }
00180 
00186     inline void addLine(const char* name, const char* value = 0)
00187         { m_lines.append(new NamedString(name,value)); }
00188 
00194     const NamedString* getLine(const char* name) const;
00195 
00201     const NamedString* getNextLine(const NamedString* line) const;
00202 
00203 protected:
00207     MimeSdpBody(const MimeSdpBody& original);
00208 
00212     virtual void buildBody() const;
00213 
00214 private:
00215     ObjList m_lines;
00216 };
00217 
00222 class YATE_API MimeBinaryBody : public MimeBody
00223 {
00224 public:
00231     MimeBinaryBody(const String& type, const char* buf, int len);
00232 
00236     virtual ~MimeBinaryBody();
00237 
00243     virtual void* getObject(const String& name) const;
00244 
00249     virtual MimeBody* clone() const;
00250 
00251 protected:
00255     MimeBinaryBody(const MimeBinaryBody& original);
00256 
00260     virtual void buildBody() const;
00261 };
00262 
00267 class YATE_API MimeStringBody : public MimeBody
00268 {
00269 public:
00276     MimeStringBody(const String& type, const char* buf, int len = -1);
00277 
00281     virtual ~MimeStringBody();
00282 
00288     virtual void* getObject(const String& name) const;
00289 
00294     virtual MimeBody* clone() const;
00295 
00300     inline const String& text() const
00301         { return m_text; }
00302 
00303 protected:
00307     MimeStringBody(const MimeStringBody& original);
00308 
00312     virtual void buildBody() const;
00313 
00314 private:
00315     String m_text;
00316 };
00317 
00322 class YATE_API MimeLinesBody : public MimeBody
00323 {
00324 public:
00331     MimeLinesBody(const String& type, const char* buf, int len);
00332 
00336     virtual ~MimeLinesBody();
00337 
00343     virtual void* getObject(const String& name) const;
00344 
00349     virtual MimeBody* clone() const;
00350 
00355     inline const ObjList& lines() const
00356         { return m_lines; }
00357 
00362     inline void addLine(const char* line)
00363         { m_lines.append(new String(line)); }
00364 
00365 protected:
00369     MimeLinesBody(const MimeLinesBody& original);
00370 
00374     virtual void buildBody() const;
00375 
00376 private:
00377     ObjList m_lines;
00378 };
00379 
00380 }; // namespace TelEngine
00381 
00382 #endif /* __YATEMIME_H */
00383 
00384 /* vi: set ts=8 sw=4 sts=4 noet: */

Generated on Mon Oct 22 07:43:07 2007 for Yate by  doxygen 1.5.2