cpim-parser.cpp 18.9 KB
Newer Older
Ronan's avatar
Ronan committed
1 2
/*
 * cpim-parser.cpp
Ronan's avatar
Ronan committed
3
 * Copyright (C) 2010-2018 Belledonne Communications SARL
Ronan's avatar
Ronan committed
4
 *
Ghislain MARY's avatar
Ghislain MARY committed
5 6 7 8
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
Ronan's avatar
Ronan committed
9 10 11 12 13 14 15
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
Ghislain MARY's avatar
Ghislain MARY committed
16 17
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Ronan's avatar
Ronan committed
18 19
 */

20
#include <set>
Sylvain Berfini's avatar
Sylvain Berfini committed
21

Ronan's avatar
Ronan committed
22 23 24
#include <belr/abnf.h>
#include <belr/grammarbuilder.h>

25 26
#include "linphone/utils/utils.h"

27
#include "content/content-type.h"
Ronan's avatar
Ronan committed
28
#include "logger/logger.h"
29
#include "object/object-p.h"
Ronan's avatar
Ronan committed
30 31 32 33 34

#include "cpim-parser.h"

// =============================================================================

35
using namespace std;
Ronan's avatar
Ronan committed
36

37
LINPHONE_BEGIN_NAMESPACE
Ronan's avatar
Ronan committed
38

39 40 41 42
namespace {
	string CpimGrammar("cpim_grammar");
}

43 44 45 46 47
namespace Cpim {
	class Node {
	public:
		virtual ~Node () = default;
	};
Ronan's avatar
Ronan committed
48

49 50 51
	class HeaderNode : public Node {
	public:
		HeaderNode () = default;
Ronan's avatar
Ronan committed
52

Ronan's avatar
Ronan committed
53
		explicit HeaderNode (const Header &header) : mName(header.getName()), mValue(header.getValue()) {
54 55 56 57
			const GenericHeader *genericHeader = dynamic_cast<const GenericHeader *>(&header);
			if (genericHeader) {
				for (const auto &parameter : *genericHeader->getParameters())
					mParameters += ";" + parameter.first + "=" + parameter.second;
Ronan's avatar
Ronan committed
58
			}
59
		}
Ronan's avatar
Ronan committed
60

61 62 63
		string getName () const {
			return mName;
		}
Ronan's avatar
Ronan committed
64

65
		void setName (const string &name) {
66 67 68 69 70 71
			static const set<string> reserved = {
				"From", "To", "cc", "DateTime", "Subject", "NS", "Require"
			};

			if (reserved.find(name) == reserved.end())
				mName = name;
72
		}
Ronan's avatar
Ronan committed
73

74 75 76
		string getParameters () const {
			return mParameters;
		}
Ronan's avatar
Ronan committed
77

78 79 80
		void setParameters (const string &parameters) {
			mParameters = parameters;
		}
Ronan's avatar
Ronan committed
81

82 83 84 85 86 87 88
		string getValue () const {
			return mValue;
		}

		void setValue (const string &value) {
			mValue = value;
		}
Ronan's avatar
Ronan committed
89

90 91 92
		virtual shared_ptr<Header> createHeader () const;

		virtual bool isValid () const;
Ronan's avatar
Ronan committed
93

94
	private:
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
		string mName;
		string mValue;
		string mParameters;
	};

	bool HeaderNode::isValid () const {
		return !mName.empty() && !mValue.empty();
	}

	shared_ptr<Header> HeaderNode::createHeader () const {
		if (!isValid())
			return nullptr;

		shared_ptr<GenericHeader> genericHeader = make_shared<GenericHeader>();
		genericHeader->setName(mName);

		for (const auto &parameter : Utils::split(mParameters, ';')) {
			size_t equalIndex = parameter.find('=');
			if (equalIndex != string::npos)
				genericHeader->addParameter(parameter.substr(0, equalIndex), parameter.substr(equalIndex + 1));
		}

		genericHeader->setValue(mValue);
		return genericHeader;
	}

	// -------------------------------------------------------------------------

	class ContactHeaderNode : public HeaderNode {
	public:
		ContactHeaderNode () = default;

		string getFormalName () const {
			return mFormalName;
		}

		void setFormalName (const string &formalName) {
			mFormalName = formalName;
		}

		string getUri () const {
			return mUri;
		}

		void setUri (const string &uri) {
			mUri = uri;
		}

		bool isValid () const override;

	private:
		string mFormalName;
		string mUri;
	};

	bool ContactHeaderNode::isValid () const {
		return !mUri.empty();
	}

	// -------------------------------------------------------------------------

	class FromHeaderNode : public ContactHeaderNode {
	public:
		FromHeaderNode () = default;

		explicit FromHeaderNode (const Header &header) {
			const FromHeader *fromHeader = dynamic_cast<const FromHeader *>(&header);
			if (fromHeader) {
				setFormalName(fromHeader->getFormalName());
				setUri(fromHeader->getUri());
Ronan's avatar
Ronan committed
165
			}
166 167 168 169 170 171 172 173 174 175 176
		}

		shared_ptr<Header> createHeader () const override;
	};

	shared_ptr<Header> FromHeaderNode::createHeader () const {
		if (!isValid())
			return nullptr;

		return make_shared<FromHeader>(getUri(), getFormalName());
	}
Ronan's avatar
Ronan committed
177

178 179 180 181 182 183 184 185 186 187 188 189
	// -------------------------------------------------------------------------

	class ToHeaderNode : public ContactHeaderNode {
	public:
		ToHeaderNode () = default;

		explicit ToHeaderNode (const Header &header) {
			const ToHeader *toHeader = dynamic_cast<const ToHeader *>(&header);
			if (toHeader) {
				setFormalName(toHeader->getFormalName());
				setUri(toHeader->getUri());
			}
Ronan's avatar
Ronan committed
190 191
		}

192
		shared_ptr<Header> createHeader () const override;
193 194
	};

195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
	shared_ptr<Header> ToHeaderNode::createHeader () const {
		if (!isValid())
			return nullptr;

		return make_shared<ToHeader>(getUri(), getFormalName());
	}

	// -------------------------------------------------------------------------

	class CcHeaderNode : public ContactHeaderNode {
	public:
		CcHeaderNode () = default;

		explicit CcHeaderNode (const Header &header) {
			const CcHeader *ccHeader = dynamic_cast<const CcHeader *>(&header);
			if (ccHeader) {
				setFormalName(ccHeader->getFormalName());
				setUri(ccHeader->getUri());
			}
		}

		shared_ptr<Header> createHeader () const override;
	};
218

219 220
	shared_ptr<Header> CcHeaderNode::createHeader () const {
		if (!isValid())
221
			return nullptr;
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295

		return make_shared<CcHeader>(getUri(), getFormalName());
	}

	// -------------------------------------------------------------------------

	class DateTimeOffsetNode : public Node {
		friend class DateTimeHeaderNode;

	public:
		DateTimeOffsetNode () {
			mSign = "Z";
		}

		void setHour (const string &value) {
			mHour = Utils::stoi(value);
		}

		void setMinute (const string &value) {
			mMinute = Utils::stoi(value);
		}

		void setSign (const string &value) {
			mSign = value;
		}

	private:
		string mSign;
		int mHour;
		int mMinute;
	};

	class DateTimeHeaderNode : public HeaderNode {
	public:
		DateTimeHeaderNode () = default;

		explicit DateTimeHeaderNode (const Header &header) {
			const DateTimeHeader *dateTimeHeader = dynamic_cast<const DateTimeHeader *>(&header);
			if (dateTimeHeader) {
				setTime(dateTimeHeader->getTimeStruct());
				setTimeOffset(dateTimeHeader->getTimeOffset());
				setSignOffset(dateTimeHeader->getSignOffset());
			}
		}

		struct tm getTime () const {
			return mTime;
		}

		void setTime (const struct tm &time) {
			mTime = time;
		}

		struct tm getTimeOffset () const {
			return mTimeOffset;
		}

		void setTimeOffset (const struct tm &timeOffset) {
			mTimeOffset = timeOffset;
		}

		string getSignOffset () const {
			return mSignOffset;
		}

		void setSignOffset (const string &signOffset) {
			mSignOffset = signOffset;
		}

		void setYear (const string &value) {
			mTime.tm_year = Utils::stoi(value);
		}

		void setMonth (const string &value) {
Mickaël Turnel's avatar
Mickaël Turnel committed
296
			mTime.tm_mon = Utils::stoi(value) - 1;
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
		}

		void setMonthDay (const string &value) {
			mTime.tm_mday = Utils::stoi(value);
		}

		void setHour (const string &value) {
			mTime.tm_hour = Utils::stoi(value);
		}

		void setMinute (const string &value) {
			mTime.tm_min = Utils::stoi(value);
		}

		void setSecond (const string &value) {
			mTime.tm_sec = Utils::stoi(value);
		}

		void setOffset (const shared_ptr<DateTimeOffsetNode> &offset) {
			mTimeOffset.tm_hour = offset->mHour;
			mTimeOffset.tm_min = offset->mMinute;
			mSignOffset = offset->mSign;
		}

		bool isValid () const override;

		shared_ptr<Header> createHeader() const override;

	private:
		tm mTime;
		tm mTimeOffset;
		string mSignOffset;
	};

	bool DateTimeHeaderNode::isValid () const {
		static const int daysInMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

		// Check date.
		const bool isLeapYear = (mTime.tm_year % 4 == 0 && mTime.tm_year % 100 != 0) || mTime.tm_year % 400 == 0;

		if (mTime.tm_mon < 1 || mTime.tm_mon > 12)
			return false;

340
		if (mTime.tm_mday < 1 || (mTime.tm_mon == 2 && isLeapYear ? mTime.tm_mday > 29 : mTime.tm_mday > daysInMonth[mTime.tm_mon]))
341 342 343 344 345 346 347 348 349 350
			return false;

		// Check time.
		if (mTime.tm_hour > 24 || mTime.tm_min > 59 || mTime.tm_sec > 60)
			return false;

		// Check num offset.
		if (mSignOffset != "Z") {
			if (mTimeOffset.tm_hour > 24 || mTime.tm_min > 59)
				return false;
Ronan's avatar
Ronan committed
351 352
		}

353
		return true;
354 355
	}

356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
	shared_ptr<Header> DateTimeHeaderNode::createHeader () const {
		if (!isValid())
			return nullptr;

		return make_shared<DateTimeHeader>(getTime(), getTimeOffset(), getSignOffset());
	}

	// -------------------------------------------------------------------------

	class SubjectHeaderNode : public HeaderNode {
	public:
		SubjectHeaderNode () = default;

		explicit SubjectHeaderNode (const Header &header) {
			const SubjectHeader *subjectHeader = dynamic_cast<const SubjectHeader *>(&header);
			if (subjectHeader) {
				setLanguage(subjectHeader->getLanguage());
				setSubject(subjectHeader->getSubject());
			}
		}

		string getLanguage () const {
			return mLanguage;
		}

		void setLanguage (const string &language) {
			mLanguage = language;
		}

		string getSubject () const {
			return mSubject;
		}

		void setSubject (const string &subject) {
			mSubject = subject;
		}

		bool isValid () const override;

		shared_ptr<Header> createHeader () const override;

	private:
		string mLanguage;
		string mSubject;
	};

	bool SubjectHeaderNode::isValid () const {
		return !mSubject.empty();
	}

	shared_ptr<Header> SubjectHeaderNode::createHeader () const {
		if (!isValid())
			return nullptr;

		return make_shared<SubjectHeader>(getSubject(), getLanguage());
	}

	// -------------------------------------------------------------------------

	class NsHeaderNode : public HeaderNode {
	public:
		NsHeaderNode () = default;

		explicit NsHeaderNode (const Header &header) {
			const NsHeader *nsHeader = dynamic_cast<const NsHeader *>(&header);
			if (nsHeader) {
				setPrefixName(nsHeader->getPrefixName());
				setUri(nsHeader->getUri());
			}
		}

		string getPrefixName () const {
			return mPrefixName;
		}

		void setPrefixName (const string &prefixName) {
			mPrefixName = prefixName;
		}

		string getUri () const {
			return mUri;
		}

		void setUri (const string &uri) {
			mUri = uri;
		}

		bool isValid () const override;

		shared_ptr<Header> createHeader () const override;

	private:
		string mPrefixName;
		string mUri;
	};

	bool NsHeaderNode::isValid () const {
		return !mUri.empty();
	}

	shared_ptr<Header> NsHeaderNode::createHeader () const {
		if (!isValid())
			return nullptr;

		return make_shared<NsHeader>(getUri(), getPrefixName());
	}

	// -------------------------------------------------------------------------

	class RequireHeaderNode : public HeaderNode {
	public:
		RequireHeaderNode () = default;

		explicit RequireHeaderNode (const Header &header) {
			const RequireHeader *requireHeader = dynamic_cast<const RequireHeader *>(&header);
			if (requireHeader) {
				for (const auto &header : requireHeader->getHeaderNames()) {
					if (header != requireHeader->getHeaderNames().front())
						mHeaderNames += ",";
					mHeaderNames += header;
				}
			}
		}

		string getHeaderNames () const {
			return mHeaderNames;
		}

		void setHeaderNames (const string &headerNames) {
			mHeaderNames = headerNames;
		}

		bool isValid () const override;

		shared_ptr<Header> createHeader () const override;

	private:
		string mHeaderNames;
	};

	bool RequireHeaderNode::isValid () const {
		return !mHeaderNames.empty();
	}

	shared_ptr<Header> RequireHeaderNode::createHeader () const  {
		if (!isValid())
			return nullptr;

		return make_shared<RequireHeader>(mHeaderNames);
505
	}
Ronan's avatar
Ronan committed
506

507
	// -------------------------------------------------------------------------
Ronan's avatar
Ronan committed
508

509 510 511
	class ListHeaderNode :
		public Node,
		public list<shared_ptr<HeaderNode> > {};
Ronan's avatar
Ronan committed
512

513 514 515 516
	// -------------------------------------------------------------------------

	class MessageNode : public Node {
	public:
517 518 519 520 521 522 523 524 525 526
		void addMessageHeaders (const shared_ptr<ListHeaderNode> &headers) {
			for (const auto &headerNode : *headers) {
				mMessageHeaders.push_back(headerNode);
			}
		}

		void addContentHeaders (const shared_ptr<ListHeaderNode> &headers) {
			for (const auto &headerNode : *headers) {
				mContentHeaders.push_back(headerNode);
			}
527 528 529 530
		}

		// Warning: Call this function one time!
		shared_ptr<Message> createMessage () const {
531
			if (mContentHeaders.empty() || mMessageHeaders.empty()) {
532 533
				lWarning() << "Bad headers lists size.";
				return nullptr;
Ronan's avatar
Ronan committed
534 535
			}

536 537
			//TODO: Verify all headers from other namespaces

538
			const shared_ptr<Message> message = make_shared<Message>();
Ronan's avatar
Ronan committed
539

540 541
			// Add message headers.
			for (const auto &headerNode : mMessageHeaders) {
542 543 544 545 546 547 548 549
				string ns = "";

				string::size_type n = headerNode->getName().find(".");
				if (n != string::npos) {
					ns = headerNode->getName().substr(0, n);
					headerNode->setName(headerNode->getName().substr(n + 1));
				}

550
				const shared_ptr<const Header> header = headerNode->createHeader();
551
				if (!header)
Ronan's avatar
Ronan committed
552
					return nullptr;
553

554
				message->addMessageHeader(*header, ns);
555
			}
556

557
			// Add content headers.
558
			for (const auto &headerNode : mContentHeaders) {
559
				const shared_ptr<const Header> header = headerNode->createHeader();
560
				if (!header)
561
					return nullptr;
562 563

				message->addContentHeader(*header);
564 565 566 567 568 569
			}

			return message;
		}

	private:
570 571
		list<shared_ptr<HeaderNode>> mContentHeaders;
		list<shared_ptr<HeaderNode>> mMessageHeaders;
572
	};
Ronan's avatar
Ronan committed
573 574 575 576 577 578 579 580 581 582
}

// -----------------------------------------------------------------------------

class Cpim::ParserPrivate : public ObjectPrivate {
public:
	shared_ptr<belr::Grammar> grammar;
};

Cpim::Parser::Parser () : Singleton(*new ParserPrivate) {
583
	L_D();
584
	d->grammar = belr::GrammarLoader::get().load(CpimGrammar);
Ronan's avatar
Ronan committed
585
	if (!d->grammar)
586
		lFatal() << "Unable to load CPIM grammar.";
Ronan's avatar
Ronan committed
587 588 589 590 591
}

// -----------------------------------------------------------------------------

shared_ptr<Cpim::Message> Cpim::Parser::parseMessage (const string &input) {
592
	L_D();
Ronan's avatar
Ronan committed
593 594 595 596

	typedef void (list<shared_ptr<HeaderNode> >::*pushPtr)(const shared_ptr<HeaderNode> &value);

	belr::Parser<shared_ptr<Node> > parser(d->grammar);
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
	parser.setHandler("Message", belr::make_fn(make_shared<MessageNode>))
		->setCollector("Message-headers", belr::make_sfn(&MessageNode::addMessageHeaders))
		->setCollector("Content-headers", belr::make_sfn(&MessageNode::addContentHeaders));

	parser.setHandler("Message-headers", belr::make_fn(make_shared<ListHeaderNode>))
		->setCollector("Header", belr::make_sfn(static_cast<pushPtr>(&ListHeaderNode::push_back)))
		->setCollector("From-header", belr::make_sfn(static_cast<pushPtr>(&ListHeaderNode::push_back)))
		->setCollector("To-header", belr::make_sfn(static_cast<pushPtr>(&ListHeaderNode::push_back)))
		->setCollector("DateTime-header", belr::make_sfn(static_cast<pushPtr>(&ListHeaderNode::push_back)))
		->setCollector("cc-header", belr::make_sfn(static_cast<pushPtr>(&ListHeaderNode::push_back)))
		->setCollector("Subject-header", belr::make_sfn(static_cast<pushPtr>(&ListHeaderNode::push_back)))
		->setCollector("NS-header", belr::make_sfn(static_cast<pushPtr>(&ListHeaderNode::push_back)))
		->setCollector("Require-header", belr::make_sfn(static_cast<pushPtr>(&ListHeaderNode::push_back)));

	parser.setHandler("Content-headers", belr::make_fn(make_shared<ListHeaderNode>))
		->setCollector("Header", belr::make_sfn(static_cast<pushPtr>(&ListHeaderNode::push_back)));

	parser.setHandler("Header", belr::make_fn(make_shared<HeaderNode>))
		->setCollector("Header-name", belr::make_sfn(&HeaderNode::setName))
		->setCollector("Header-value", belr::make_sfn(&HeaderNode::setValue))
		->setCollector("Header-parameters", belr::make_sfn(&HeaderNode::setParameters));

	parser.setHandler("From-header", belr::make_fn(make_shared<FromHeaderNode>))
		->setCollector("Formal-name", belr::make_sfn(&FromHeaderNode::setFormalName))
		->setCollector("URI", belr::make_sfn(&FromHeaderNode::setUri));

	parser.setHandler("To-header", belr::make_fn(make_shared<ToHeaderNode>))
		->setCollector("Formal-name", belr::make_sfn(&ToHeaderNode::setFormalName))
		->setCollector("URI", belr::make_sfn(&ToHeaderNode::setUri));

	parser.setHandler("cc-header", belr::make_fn(make_shared<CcHeaderNode>))
		->setCollector("Formal-name", belr::make_sfn(&CcHeaderNode::setFormalName))
		->setCollector("URI", belr::make_sfn(&CcHeaderNode::setUri));

	parser.setHandler("DateTime-header", belr::make_fn(make_shared<DateTimeHeaderNode>))
		->setCollector("date-fullyear", belr::make_sfn(&DateTimeHeaderNode::setYear))
		->setCollector("date-month", belr::make_sfn(&DateTimeHeaderNode::setMonth))
		->setCollector("date-mday", belr::make_sfn(&DateTimeHeaderNode::setMonthDay))
		->setCollector("time-hour", belr::make_sfn(&DateTimeHeaderNode::setHour))
		->setCollector("time-minute", belr::make_sfn(&DateTimeHeaderNode::setMinute))
		->setCollector("time-second", belr::make_sfn(&DateTimeHeaderNode::setSecond))
		->setCollector("time-offset", belr::make_sfn(&DateTimeHeaderNode::setOffset));

	parser.setHandler("time-offset", belr::make_fn(make_shared<DateTimeOffsetNode>))
		->setCollector("time-sign", belr::make_sfn(&DateTimeOffsetNode::setSign))
		->setCollector("time-hour", belr::make_sfn(&DateTimeOffsetNode::setHour))
		->setCollector("time-minute", belr::make_sfn(&DateTimeOffsetNode::setMinute));

	parser.setHandler("Subject-header", belr::make_fn(make_shared<SubjectHeaderNode>))
		->setCollector("Language-tag", belr::make_sfn(&SubjectHeaderNode::setLanguage))
		->setCollector("Header-value", belr::make_sfn(&SubjectHeaderNode::setSubject));

	parser.setHandler("Ns-header", belr::make_fn(make_shared<NsHeaderNode>))
		->setCollector("Name-prefix", belr::make_sfn(&NsHeaderNode::setPrefixName))
		->setCollector("URI", belr::make_sfn(&NsHeaderNode::setUri));

	parser.setHandler("Require-header", belr::make_fn(make_shared<RequireHeaderNode>))
		->setCollector("Require-header-value", belr::make_sfn(&RequireHeaderNode::setHeaderNames));
Ronan's avatar
Ronan committed
655 656 657 658

	size_t parsedSize;
	shared_ptr<Node> node = parser.parseInput("Message", input, &parsedSize);
	if (!node) {
Ronan's avatar
Ronan committed
659
		lWarning() << "Unable to parse message.";
Ronan's avatar
Ronan committed
660 661 662 663 664
		return nullptr;
	}

	shared_ptr<MessageNode> messageNode = dynamic_pointer_cast<MessageNode>(node);
	if (!messageNode) {
Ronan's avatar
Ronan committed
665
		lWarning() << "Unable to cast belr result to message node.";
Ronan's avatar
Ronan committed
666 667 668 669
		return nullptr;
	}

	shared_ptr<Message> message = messageNode->createMessage();
670
	if (message) {
Ronan's avatar
Ronan committed
671
		message->setContent(input.substr(parsedSize));
672
	}
Ronan's avatar
Ronan committed
673 674 675 676 677 678
	return message;
}

// -----------------------------------------------------------------------------

shared_ptr<Cpim::Header> Cpim::Parser::cloneHeader (const Header &header) {
679 680
	if (header.getName() == "From")
		return FromHeaderNode(header).createHeader();
Ronan's avatar
Ronan committed
681

682 683
	if (header.getName() == "To")
		return ToHeaderNode(header).createHeader();
Ronan's avatar
Ronan committed
684

685 686
	if (header.getName() == "cc")
		return CcHeaderNode(header).createHeader();
Ronan's avatar
Ronan committed
687

688 689
	if (header.getName() == "DateTime")
		return DateTimeHeaderNode(header).createHeader();
Ronan's avatar
Ronan committed
690

691 692
	if (header.getName() == "Subject")
		return SubjectHeaderNode(header).createHeader();
Ronan's avatar
Ronan committed
693

694 695
	if (header.getName() == "NS")
		return NsHeaderNode(header).createHeader();
Ronan's avatar
Ronan committed
696

697 698
	if (header.getName() == "Require")
		return RequireHeaderNode(header).createHeader();
Ronan's avatar
Ronan committed
699

700
	return HeaderNode(header).createHeader();
Ronan's avatar
Ronan committed
701
}
702 703

LINPHONE_END_NAMESPACE