summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/msn/msninvitation.cpp
blob: 8a64aa9320f76fe5f3a11163070733faaccb3ee6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
    msninvitation.cpp

    Copyright (c) 2003 by Olivier Goffart        <ogoffart @ kde.org>

    Kopete    (c) 2003 by the Kopete developers  <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * 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.                                   *
    *                                                                       *
    *************************************************************************
*/
#include "msninvitation.h"
#include <stdlib.h>
#include <tqregexp.h>

MSNInvitation::MSNInvitation(bool incoming, const TQString &applicationID , const TQString &applicationName)
{
	m_incoming=incoming;
	m_applicationId=applicationID;
	m_applicationName=applicationName;
	m_cookie= (rand()%(999999))+1;
	m_state = Nothing;
}


MSNInvitation::~MSNInvitation()
{
}

TQCString MSNInvitation::unimplemented(long unsigned int cookie)
{
	return TQString( "MIME-Version: 1.0\r\n"
					"Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n"
					"\r\n"
					"Invitation-Command: CANCEL\r\n"
					"Cancel-Code: REJECT_NOT_INSTALLED\r\n"
					"Invitation-Cookie: " + TQString::number(cookie) + "\r\n"
					"Session-ID: {120019D9-C3F5-4F94-978D-CB33534C3309}\r\n\r\n").utf8();
		//FIXME: i don't know at all what Seession-ID is
}

TQString MSNInvitation::invitationHead()
{
	setState(Invited);
	return TQString( "MIME-Version: 1.0\r\n"
					"Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n"
					"\r\n"
					"Application-Name: " + m_applicationName + "\r\n"
					"Application-GUID: {" + m_applicationId + "}\r\n"
					"Invitation-Command: INVITE\r\n"
					"Invitation-Cookie: " +TQString::number(m_cookie) +"\r\n");
}

TQCString MSNInvitation::rejectMessage(const TQString & rejectcode)
{
	return TQString( "MIME-Version: 1.0\r\n"
					"Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n"
					"\r\n"
					"Invitation-Command: CANCEL\r\n"
					"Invitation-Cookie: " + TQString::number(cookie()) + "\r\n"
					"Cancel-Code: "+ rejectcode +"\r\n").utf8();
}

void MSNInvitation::parseInvitation(const TQString& msg)
{
	TQRegExp rx("Invitation-Command: ([A-Z]*)");
	rx.search(msg);
	TQString command=rx.cap(1);

	if(command=="INVITE")
	{
		rx=TQRegExp("Invitation-Cookie: ([0-9]*)");
		rx.search(msg);
		m_cookie=rx.cap(1).toUInt();
	}
	else if(command=="CANCEL")
	{
		/*rx=TQRegExp("Cancel-Code: ([0-9]*)");
		rx.search(msg);
		TQString code=rx.cap(1).toUInt();
		//TODO: parse the code*/
	}
//	else if(command=="ACCEPT")
}

MSNInvitation::State MSNInvitation::state()
{
	return m_state;
}

void MSNInvitation::setState(MSNInvitation::State s)
{
	m_state=s;
}