Yate: yatemime.h Source File

Yate

- Main Page
- Namespaces
- Classes
- Files

- File List

yatemime.h
1
22 #ifndef __YATEMIME_H
23 #define __YATEMIME_H
24
25 #ifndef __cplusplus
26 #error C++ is required
27 #endif
28
29 #include <yateclass.h>
30
34 namespace TelEngine {
35
41 class YATE_API MimeHeaderLine : public NamedString
42 {
43 public:
52 MimeHeaderLine(const char* name, const String& value, char sep = 0);
53
60 MimeHeaderLine(const MimeHeaderLine& original, const char* newName = 0);
61
65 virtual ~MimeHeaderLine();
66
72 virtual void* getObject(const String& name) const;
73
79 virtual MimeHeaderLine* clone(const char* newName = 0) const;
80
86 virtual void buildLine(String& line, bool header = true) const;
87
92 inline MimeHeaderLine& operator=(const char* value)
93 { NamedString::operator=(value); return *this; }
94
99 inline const ObjList& params() const
100 { return m_params; }
101
106 inline char separator() const
107 { return m_separator; }
108
114 void setParam(const char* name, const char* value = 0);
115
120 void delParam(const char* name);
121
127 const NamedString* getParam(const char* name) const;
128
134 static void addQuotes(String& str, bool force = false);
135
141 static void delQuotes(String& str, bool force = false);
142
149 static String quote(const String& str, bool force = false);
150
157 static String unquote(const String& str, bool force = false);
158
166 static int findSep(const char* str, char sep, int offs = 0);
167
174 static void buildHeaders(String& buf, const ObjList& headers);
175
176 protected:
177 ObjList m_params; // Header list of parameters
178 char m_separator; // Parameter separator
179 private:
180 void operator=(const MimeHeaderLine&); // no assignment
181 };
182
187 class YATE_API MimeAuthLine : public MimeHeaderLine
188 {
189 public:
197 MimeAuthLine(const char* name, const String& value);
198
205 MimeAuthLine(const MimeAuthLine& original, const char* newName = 0);
206
212 virtual void* getObject(const String& name) const;
213
219 virtual MimeHeaderLine* clone(const char* newName = 0) const;
220
226 virtual void buildLine(String& line, bool header = true) const;
227
228 private:
229 void operator=(const MimeAuthLine&); // no assignment
230 };
231
239 class YATE_API MimeBody : public GenObject
240 {
241 YNOCOPY(MimeBody); // no automatic copies please
242 public:
246 virtual ~MimeBody();
247
253 virtual void* getObject(const String& name) const;
254
259 inline const MimeHeaderLine& getType() const
260 { return m_type; }
261
267 MimeBody* getFirst(const String& type) const;
268
273 inline const ObjList& headers() const
274 { return m_headers; }
275
280 inline void appendHdr(MimeHeaderLine* hdr)
281 { if (hdr) m_headers.append(hdr); }
282
288 inline void removeHdr(MimeHeaderLine* hdr, bool delobj = true)
289 { if (hdr) m_headers.remove(hdr,delobj); }
290
297 MimeHeaderLine* findHdr(const String& name, const MimeHeaderLine* start = 0) const;
298
303 inline void buildHeaders(String& buf) {
304 m_type.buildLine(buf);
305 buf << "\r\n";
306 MimeHeaderLine::buildHeaders(buf,m_headers);
307 }
308
317 bool setParam(const char* name, const char* value = 0, const char* header = 0);
318
326 bool delParam(const char* name, const char* header = 0);
327
335 const NamedString* getParam(const char* name, const char* header = 0) const;
336
342 const DataBlock& getBody() const;
343
348 inline const DataBlock& body() const
349 { return m_body; }
350
355 virtual bool isSDP() const
356 { return false; }
357
362 virtual bool isMultipart() const
363 { return false; }
364
369 virtual MimeBody* clone() const = 0;
370
381 static MimeBody* build(const char* buf, int len, const MimeHeaderLine& type);
382
389 static String* getUnfoldedLine(const char*& buf, int& len);
390
391 protected:
397 MimeBody(const String& type);
398
405 MimeBody(const MimeHeaderLine& type);
406
410 virtual void buildBody() const = 0;
411
415 mutable DataBlock m_body;
416
420 ObjList m_headers;
421
422 private:
423 MimeHeaderLine m_type; // Content type header line
424 };
425
430 class YATE_API MimeMultipartBody : public MimeBody
431 {
432 public:
440 explicit MimeMultipartBody(const char* subtype = "mixed", const char* boundary = 0);
441
448 MimeMultipartBody(const String& type, const char* buf, int len);
449
456 MimeMultipartBody(const MimeHeaderLine& type, const char* buf, int len);
457
461 virtual ~MimeMultipartBody();
462
467 inline const ObjList& bodies() const
468 { return m_bodies; }
469
474 inline void appendBody(MimeBody* body)
475 { if (body) m_bodies.append(body); }
476
482 inline void removeBody(MimeBody* body, bool delobj = true)
483 { if (body) m_bodies.remove(body,delobj); }
484
493 MimeBody* findBody(const String& content, MimeBody** start = 0) const;
494
500 virtual void* getObject(const String& name) const;
501
506 virtual bool isMultipart() const
507 { return true; }
508
513 virtual MimeBody* clone() const;
514
515 protected:
519 MimeMultipartBody(const MimeMultipartBody& original);
520
524 virtual void buildBody() const;
525
532 void parse(const char* buf, int len);
533
534 private:
535 // Parse input buffer for first body boundary or data end
536 // Advance buffer pass the boundary line and decrease the buffer length
537 // Set endBody to true if the last boundary was found
538 // Return the length of data before the found boundary
539 int findBoundary(const char*& buf, int& len,
540 const char* boundary, unsigned int bLen, bool& endBody);
541 // Build a boundary string to be used when parsing or building body
542 // Remove quotes if present. Trim blanks
543 // Insert CRLF and boundary marks ('--') before parameter
544 // @param boundary Destination string
545 // @return False if the parameter is missing or the boundary is empty
546 bool getBoundary(String& boundary) const;
547
548
549 ObjList m_bodies; // The list of bodies contained in this multipart
550 };
551
556 class YATE_API MimeSdpBody : public MimeBody
557 {
558 public:
563 MimeSdpBody(bool hashing = false);
564
571 MimeSdpBody(const String& type, const char* buf, int len);
572
579 MimeSdpBody(const MimeHeaderLine& type, const char* buf, int len);
580
584 virtual ~MimeSdpBody();
585
591 virtual void* getObject(const String& name) const;
592
597 virtual bool isSDP() const
598 { return true; }
599
604 virtual MimeBody* clone() const;
605
610 inline const ObjList& lines() const
611 { return m_lines; }
612
617 inline unsigned int hash() const
618 { return m_hash; }
619
626 NamedString* addLine(const char* name, const char* value = 0);
627
633 const NamedString* getLine(const char* name) const;
634
640 const NamedString* getNextLine(const NamedString* line) const;
641
642 protected:
646 MimeSdpBody(const MimeSdpBody& original);
647
651 virtual void buildBody() const;
652
653 private:
654 // Build the lines from a data buffer
655 void buildLines(const char* buf, int len);
656
657 ObjList m_lines;
658 ObjList* m_lineAppend;
659 unsigned int m_hash;
660 bool m_hashing;
661 };
662
667 class YATE_API MimeBinaryBody : public MimeBody
668 {
669 public:
676 MimeBinaryBody(const String& type, const char* buf, int len);
677
684 MimeBinaryBody(const MimeHeaderLine& type, const char* buf, int len);
685
689 virtual ~MimeBinaryBody();
690
696 virtual void* getObject(const String& name) const;
697
702 virtual MimeBody* clone() const;
703
704 protected:
708 MimeBinaryBody(const MimeBinaryBody& original);
709
713 virtual void buildBody() const;
714 };
715
720 class YATE_API MimeStringBody : public MimeBody
721 {
722 public:
729 MimeStringBody(const String& type, const char* buf, int len = -1);
730
737 MimeStringBody(const MimeHeaderLine& type, const char* buf, int len = -1);
738
742 virtual ~MimeStringBody();
743
749 virtual void* getObject(const String& name) const;
750
755 virtual MimeBody* clone() const;
756
761 inline const String& text() const
762 { return m_text; }
763
764 protected:
768 MimeStringBody(const MimeStringBody& original);
769
773 virtual void buildBody() const;
774
775 private:
776 String m_text;
777 };
778
783 class YATE_API MimeLinesBody : public MimeBody
784 {
785 public:
792 MimeLinesBody(const String& type, const char* buf, int len);
793
800 MimeLinesBody(const MimeHeaderLine& type, const char* buf, int len);
801
805 virtual ~MimeLinesBody();
806
812 virtual void* getObject(const String& name) const;
813
818 virtual MimeBody* clone() const;
819
824 inline const ObjList& lines() const
825 { return m_lines; }
826
831 inline void addLine(const char* line)
832 { m_lines.append(new String(line)); }
833
834 protected:
838 MimeLinesBody(const MimeLinesBody& original);
839
843 virtual void buildBody() const;
844
845 private:
846 ObjList m_lines;
847 };
848
849 }; // namespace TelEngine
850
851 #endif /* __YATEMIME_H */
852
853 /* vi: set ts=8 sw=4 sts=4 noet: */
TelEngine::MimeLinesBody::addLine
void addLine(const char *line)
Definition: yatemime.h:831
TelEngine::MimeLinesBody::lines
const ObjList & lines() const
Definition: yatemime.h:824
TelEngine::DataBlock
A class that holds just a block of raw data.
Definition: yateclass.h:3994
TelEngine::MimeHeaderLine::params
const ObjList & params() const
Definition: yatemime.h:99
TelEngine::MimeBody::headers
const ObjList & headers() const
Definition: yatemime.h:273
TelEngine::MimeMultipartBody::bodies
const ObjList & bodies() const
Definition: yatemime.h:467
TelEngine::MimeMultipartBody::isMultipart
virtual bool isMultipart() const
Definition: yatemime.h:506
TelEngine::MimeBody::appendHdr
void appendHdr(MimeHeaderLine *hdr)
Definition: yatemime.h:280
TelEngine::MimeHeaderLine::buildHeaders
static void buildHeaders(String &buf, const ObjList &headers)
TelEngine::MimeLinesBody
MIME for multiple text lines.
Definition: yatemime.h:783
TelEngine::MimeBody::removeHdr
void removeHdr(MimeHeaderLine *hdr, bool delobj=true)
Definition: yatemime.h:288
TelEngine::MimeStringBody::text
const String & text() const
Definition: yatemime.h:761
TelEngine::MimeMultipartBody
MIME multipart container.
Definition: yatemime.h:430
TelEngine::MimeSdpBody
MIME for application/sdp.
Definition: yatemime.h:556
TelEngine::MimeMultipartBody::removeBody
void removeBody(MimeBody *body, bool delobj=true)
Definition: yatemime.h:482
TelEngine::MimeSdpBody::hash
unsigned int hash() const
Definition: yatemime.h:617
TelEngine::MimeBody::body
const DataBlock & body() const
Definition: yatemime.h:348
TelEngine::MimeBody::m_headers
ObjList m_headers
Definition: yatemime.h:420
TelEngine::MimeHeaderLine::separator
char separator() const
Definition: yatemime.h:106
TelEngine::MimeHeaderLine
MIME header line.
Definition: yatemime.h:41
TelEngine::MimeBody
Abstract MIME data holder.
Definition: yatemime.h:239
TelEngine::MimeBody::isMultipart
virtual bool isMultipart() const
Definition: yatemime.h:362
TelEngine::MimeBody::isSDP
virtual bool isSDP() const
Definition: yatemime.h:355
TelEngine::NamedString
A named string class.
Definition: yateclass.h:3260
TelEngine::MimeBody::m_body
DataBlock m_body
Definition: yatemime.h:415
TelEngine::MimeBody::buildHeaders
void buildHeaders(String &buf)
Definition: yatemime.h:303
TelEngine::MimeSdpBody::isSDP
virtual bool isSDP() const
Definition: yatemime.h:597
TelEngine::MimeHeaderLine::operator=
MimeHeaderLine & operator=(const char *value)
Definition: yatemime.h:92
TelEngine::MimeBody::getType
const MimeHeaderLine & getType() const
Definition: yatemime.h:259
TelEngine::MimeAuthLine
MIME authentication line.
Definition: yatemime.h:187
TelEngine::MimeMultipartBody::appendBody
void appendBody(MimeBody *body)
Definition: yatemime.h:474
TelEngine
Definition: yateclass.h:217
TelEngine::NamedString::operator=
NamedString & operator=(const char *value)
Definition: yateclass.h:3294
TelEngine::String
A C-style string handling class.
Definition: yateclass.h:1924
TelEngine::ObjList
An object list class.
Definition: yateclass.h:1247
TelEngine::YNOCOPY
void YNOCOPY(class type)
TelEngine::MimeSdpBody::lines
const ObjList & lines() const
Definition: yatemime.h:610
TelEngine::MimeBinaryBody
MIME for obscure binary data.
Definition: yatemime.h:667
TelEngine::GenObject
Definition: yateclass.h:848
TelEngine::MimeStringBody
MIME for one text string.
Definition: yatemime.h:720