instant_messaging.h 5.3 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
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
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
 *
 *  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 3 of the License, or
 *  (at your option) any later version.
 *
 *  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
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
 */

32
33
#ifndef __INSTANT_MESSAGING_H__
#define __INSTANT_MESSAGING_H__
34
35
36

#include <string>
#include <iostream>
37
#include <vector>
38
#include <fstream>
39
40
41
42
43
#include <pjsip.h>
#include <pjlib.h>
#include <pjsip_ua.h>
#include <pjlib-util.h>

44
#include <map>
45
#include <list>
46
#include <stdexcept>
47

48
49
#include <iax-client.h>

50
51
#include "config.h"

52
#define EMPTY_MESSAGE   pj_str((char*)"")
53
#define MAXIMUM_MESSAGE_LENGTH		1560			/* PJSIP's sip message limit */
54

55
56
57
#define MODE_APPEND			std::ios::out || std::ios::app
#define MODE_TEST			std::ios::out

58
namespace sfl {
59

60
61
const std::string IM_XML_URI("uri");
const std::string BOUNDARY("--boundary");
62

63
class InstantMessageException : public std::runtime_error {
64
    public:
65
        InstantMessageException(const std::string& str="") :
66
            std::runtime_error("InstantMessageException occured: " + str) {}
67
68
};

69
70
71
namespace InstantMessaging {
        typedef std::map<std::string, std::string> UriEntry;
        typedef std::list<UriEntry> UriList;
72

73
74
75
76
77
78
79
80
        /*
         * Write the text message to the right file
         * The call ID is associated to a file descriptor, so it is easy then to retrieve the right file
         *
         * @param message	The text message
         * @param id	The current call
         * @return True if the message could have been successfully saved, False otherwise
         */
81
        bool saveMessage(const std::string& message, const std::string& author, const std::string& id, int mode = MODE_APPEND);
82
83
84
85
86
87
88

        /*
         * Send a SIP string message inside a call
         *
         * @param id	The call ID we will retrieve the invite session from
         * @param message	The string message, as sent by the client
         */
89
        void sip_send(pjsip_inv_session*, const std::string& id, const std::string&);
90

91
        void send_sip_message(pjsip_inv_session*, const std::string& id, const std::string&);
92
#if HAVE_IAX
93
        void send_iax_message(iax_session *session, const std::string& id, const std::string&);
94
#endif
95

Rafaël Carré's avatar
Rafaël Carré committed
96
        std::vector<std::string> split_message(std::string);
97

98
99
100
        /**
         * Generate Xml participant list for multi recipient based on RFC Draft 5365
         *
101
102
103
104
105
        * @param A UriList of UriEntry
        *
        * @return A string containing the full XML formated information to be included in the
        *         sip instant message.
        */
106
        std::string generateXmlUriList(UriList &list);
107
108
109
110
111
112
113
114

        /**
         * Parse the Urilist from a SIP Instant Message provided by a UriList service.
         *
         * @param A XML formated string as obtained from a SIP instant message.
         *
         * @return An UriList of UriEntry containing parsed XML information as a map.
         */
115
        UriList parseXmlUriList(const std::string &urilist);
116

117
118
119
120
121
122
123
124
        /**
         * Format text message according to RFC 5365, append recipient-list to the message
         *
         * @param text to be displayed
         * @param list containing the recipients
         *
         * @return formated text stored into a string to be included in sip MESSAGE
         */
125
        std::string appendUriList(const std::string &text, UriList &list);
126

127
128
129
130
131
132
133
        /**
             * Retreive the xml formated uri list in formated text data according to RFC 5365
             *
         * @param text The formated text message as retreived in the SIP message
         *
         * @return A string containing the XML content
         */
134
        std::string findTextUriList(const std::string &text);
135

136
137
138
139
        /**
             * Retrive the plain text message in formated text data according to RFC 5365
             *
         * @param text The formated text message as retreived in the SIP message
140
         *
141
142
         * @return A string containing the actual message
         */
143
144
        std::string findTextMessage(const std::string &text);
} // end namespace InstantMessaging
145
}
146
#endif // __INSTANT_MESSAGING_H_