Line data Source code
1 : /*
2 : * Copyright (C) 2004-2026 Savoir-faire Linux Inc.
3 : *
4 : * This program is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 3 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * This program is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 : */
17 : #pragma once
18 :
19 : #include <string>
20 : #include <map>
21 : #include <stdexcept>
22 :
23 : #ifdef HAVE_CONFIG_H
24 : #include "config.h"
25 : #endif
26 :
27 : extern "C" {
28 : struct pjsip_inv_session;
29 : struct pjsip_rx_data;
30 : struct pjsip_msg;
31 : struct pjsip_tx_data;
32 : }
33 :
34 : namespace jami {
35 : namespace im {
36 :
37 : struct InstantMessageException : std::runtime_error
38 : {
39 0 : InstantMessageException(const std::string& str = "")
40 0 : : std::runtime_error("InstantMessageException occurred: " + str)
41 0 : {}
42 : };
43 :
44 : /**
45 : * Constructs and sends a SIP message.
46 : *
47 : * The expected format of the map key is:
48 : * type/subtype[; *[; arg=value]]
49 : * eg: "text/plain; id=1234;part=2;of=1001"
50 : * note: all whitespace is optional
51 : *
52 : * If the map contains more than one pair, then a multipart/mixed message type will be created
53 : * containing multiple message parts. Note that all of the message parts must be able to fit into
54 : * one message... they will not be split into multiple messages.
55 : *
56 : * @param session SIP session
57 : * @param payloads a map where the mime type and optional parameters are the key
58 : * and the message payload is the value
59 : *
60 : * Exception: throw InstantMessageException if no message sent
61 : */
62 : void sendSipMessage(pjsip_inv_session* session, const std::map<std::string, std::string>& payloads);
63 :
64 : /**
65 : * Parses given SIP message into a map where the key is the contents of the Content-Type header
66 : * (along with any parameters) and the value is the message payload.
67 : *
68 : * @param msg received SIP message
69 : *
70 : * @return map of content types and message payloads
71 : */
72 : std::map<std::string, std::string> parseSipMessage(const pjsip_msg* msg);
73 :
74 : void fillPJSIPMessageBody(pjsip_tx_data& tdata, const std::map<std::string, std::string>& payloads);
75 :
76 : } // namespace im
77 : } // namespace jami
|