| 1 | /* |
| 2 | * Copyright (C) 2024 Teluu Inc. (http://www.teluu.com) |
| 3 | * Copyright (C) 2013 Maxim Kondratenko <[email protected]> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #ifndef __PJSIP_SIMPLE_DLG_EVENT_H__ |
| 20 | #define __PJSIP_SIMPLE_DLG_EVENT_H__ |
| 21 | |
| 22 | /** |
| 23 | * @file dlg_event.h |
| 24 | * @brief SIP Extension for INVITE-Initiated Dialog Event (RFC 4235) |
| 25 | */ |
| 26 | #include <pjsip-simple/evsub.h> |
| 27 | #include <pjsip-simple/dialog_info.h> |
| 28 | |
| 29 | PJ_BEGIN_DECL |
| 30 | |
| 31 | |
| 32 | /** |
| 33 | * @defgroup PJSIP_SIMPLE_DLG_EVENT SIP Extension for Dialog Event (RFC 4235) |
| 34 | * @ingroup PJSIP_SIMPLE |
| 35 | * @brief Support for SIP Extension for Dialog Event (RFC 4235) |
| 36 | * @{ |
| 37 | * |
| 38 | * This module contains the implementation of INVITE-Initiated Dialog Event |
| 39 | * Package as described in RFC 4235. It uses the SIP Event Notification |
| 40 | * framework (evsub.h) and extends the framework by implementing |
| 41 | * "dialog-info+xml" event package. This could be useful for features such as |
| 42 | * Busy Lamp Field (BLF). |
| 43 | */ |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | * Initialize the dialog event module and register it as endpoint module and |
| 48 | * package to the event subscription module. |
| 49 | * |
| 50 | * @param endpt The endpoint instance. |
| 51 | * @param mod_evsub The event subscription module instance. |
| 52 | * |
| 53 | * @return PJ_SUCCESS if the module is successfully |
| 54 | * initialized and registered to both endpoint |
| 55 | * and the event subscription module. |
| 56 | */ |
| 57 | PJ_DECL(pj_status_t) pjsip_dlg_event_init_module(pjsip_endpoint *endpt, |
| 58 | pjsip_module *mod_evsub); |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * Get the dialog event module instance. |
| 63 | * |
| 64 | * @return The dialog event module instance. |
| 65 | */ |
| 66 | PJ_DECL(pjsip_module*) pjsip_bdlg_event_instance(void); |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * Maximum dialog event status info items which can handled by application. |
| 71 | * |
| 72 | */ |
| 73 | #define PJSIP_DLG_EVENT_STATUS_MAX_INFO 1 |
| 74 | |
| 75 | |
| 76 | /** |
| 77 | * This structure describes dialog event status of an entity. |
| 78 | */ |
| 79 | struct pjsip_dlg_event_status |
| 80 | { |
| 81 | unsigned info_cnt; /**< Number of info in the status */ |
| 82 | struct { |
| 83 | |
| 84 | pj_str_t dialog_info_state; /**< Dialog-Info state */ |
| 85 | pj_str_t dialog_info_entity; /**< Dialog-Info entity */ |
| 86 | pj_str_t dialog_call_id; /**< Dialog's call_id */ |
| 87 | pj_str_t dialog_remote_tag; /**< Dialog's remote-tag */ |
| 88 | pj_str_t dialog_local_tag; /**< Dialog's local-tag */ |
| 89 | pj_str_t dialog_direction; /**< Dialog's direction */ |
| 90 | pj_str_t dialog_id; /**< Dialog's id */ |
| 91 | pj_str_t dialog_state; /**< Dialog state */ |
| 92 | pj_str_t dialog_duration; /**< Dialog duration */ |
| 93 | |
| 94 | pj_xml_node *dialog_node; /**< Pointer to tuple XML node of |
| 95 | parsed dialog-info body received |
| 96 | from remote agent. Only valid |
| 97 | for client subscription. If the |
| 98 | last received NOTIFY request |
| 99 | does not contain any dialog-info |
| 100 | body, this will be set to NULL*/ |
| 101 | pj_str_t local_identity; |
| 102 | pj_str_t local_identity_display; |
| 103 | pj_str_t local_target_uri; |
| 104 | |
| 105 | pj_str_t remote_identity; |
| 106 | pj_str_t remote_identity_display; |
| 107 | pj_str_t remote_target_uri; |
| 108 | |
| 109 | } info[PJSIP_DLG_EVENT_STATUS_MAX_INFO]; /**< Array of info. */ |
| 110 | }; |
| 111 | |
| 112 | |
| 113 | /** |
| 114 | * @see pjsip_dlg_event_status |
| 115 | */ |
| 116 | typedef struct pjsip_dlg_event_status pjsip_dlg_event_status; |
| 117 | |
| 118 | |
| 119 | /** |
| 120 | * Create dialog event client subscription session. |
| 121 | * |
| 122 | * @param dlg The underlying dialog to use. |
| 123 | * @param user_cb Pointer to callbacks to receive dialog events. |
| 124 | * @param options Option flags. Currently only PJSIP_EVSUB_NO_EVENT_ID |
| 125 | * is recognized. |
| 126 | * @param p_evsub Pointer to receive the dialog event subscription |
| 127 | * session. |
| 128 | * |
| 129 | * @return PJ_SUCCESS on success. |
| 130 | */ |
| 131 | PJ_DECL(pj_status_t) |
| 132 | pjsip_dlg_event_create_uac(pjsip_dialog *dlg, |
| 133 | const pjsip_evsub_user *user_cb, |
| 134 | unsigned options, |
| 135 | pjsip_evsub **p_evsub ); |
| 136 | |
| 137 | |
| 138 | /** |
| 139 | * Forcefully destroy the dialog event subscription. This function should only |
| 140 | * be called on special condition, such as when the subscription |
| 141 | * initialization has failed. For other conditions, application MUST terminate |
| 142 | * the subscription by sending the appropriate un(SUBSCRIBE) or NOTIFY. |
| 143 | * |
| 144 | * @param sub The dialog event subscription. |
| 145 | * @param notify Specify whether the state notification callback |
| 146 | * should be called. |
| 147 | * |
| 148 | * @return PJ_SUCCESS if subscription session has been destroyed. |
| 149 | */ |
| 150 | PJ_DECL(pj_status_t) pjsip_dlg_event_terminate(pjsip_evsub *sub, |
| 151 | pj_bool_t notify ); |
| 152 | |
| 153 | |
| 154 | |
| 155 | /** |
| 156 | * Call this function to create request to initiate dialog event subscription, |
| 157 | * to refresh subcription, or to request subscription termination. |
| 158 | * |
| 159 | * @param sub Client subscription instance. |
| 160 | * @param expires Subscription expiration. If the value is set to zero, |
| 161 | * this will request unsubscription. |
| 162 | * @param p_tdata Pointer to receive the request. |
| 163 | * |
| 164 | * @return PJ_SUCCESS on success. |
| 165 | */ |
| 166 | PJ_DECL(pj_status_t) pjsip_dlg_event_initiate(pjsip_evsub *sub, |
| 167 | pj_int32_t expires, |
| 168 | pjsip_tx_data **p_tdata); |
| 169 | |
| 170 | |
| 171 | /** |
| 172 | * Add a list of headers to the subscription instance. The list of headers |
| 173 | * will be added to outgoing dialog event subscription requests. |
| 174 | * |
| 175 | * @param sub Subscription instance. |
| 176 | * @param hdr_list List of headers to be added. |
| 177 | * |
| 178 | * @return PJ_SUCCESS on success. |
| 179 | */ |
| 180 | PJ_DECL(pj_status_t) pjsip_dlg_event_add_header(pjsip_evsub *sub, |
| 181 | const pjsip_hdr *hdr_list); |
| 182 | |
| 183 | |
| 184 | /** |
| 185 | * Accept the incoming subscription request by sending 2xx response to |
| 186 | * incoming SUBSCRIBE request. |
| 187 | * |
| 188 | * @param sub Server subscription instance. |
| 189 | * @param rdata The incoming subscription request message. |
| 190 | * @param st_code Status code, which MUST be final response. |
| 191 | * @param hdr_list Optional list of headers to be added in the response. |
| 192 | * |
| 193 | * @return PJ_SUCCESS on success. |
| 194 | */ |
| 195 | PJ_DECL(pj_status_t) pjsip_dlg_event_accept(pjsip_evsub *sub, |
| 196 | pjsip_rx_data *rdata, |
| 197 | int st_code, |
| 198 | const pjsip_hdr *hdr_list ); |
| 199 | |
| 200 | /** |
| 201 | * Send request message. Application may also send request created with other |
| 202 | * functions, e.g. authentication. But the request MUST be either request |
| 203 | * that creates/refresh subscription or NOTIFY request. |
| 204 | * |
| 205 | * @param sub The subscription object. |
| 206 | * @param tdata Request message to be sent. |
| 207 | * |
| 208 | * @return PJ_SUCCESS on success. |
| 209 | */ |
| 210 | PJ_DECL(pj_status_t) pjsip_dlg_event_send_request(pjsip_evsub *sub, |
| 211 | pjsip_tx_data *tdata); |
| 212 | |
| 213 | |
| 214 | /** |
| 215 | * Get the dialog event status. Client normally would call this function |
| 216 | * after receiving NOTIFY request from server. |
| 217 | * |
| 218 | * @param sub The client or server subscription. |
| 219 | * @param status The structure to receive dialog event status. |
| 220 | * |
| 221 | * @return PJ_SUCCESS on success. |
| 222 | */ |
| 223 | PJ_DECL(pj_status_t) |
| 224 | pjsip_dlg_event_get_status(pjsip_evsub *sub, pjsip_dlg_event_status *status); |
| 225 | |
| 226 | |
| 227 | /** |
| 228 | * This is a utility function to parse XML body into PJSIP dialog event status. |
| 229 | * |
| 230 | * @param rdata The incoming SIP message containing the XML body. |
| 231 | * @param pool Pool to allocate memory to copy the strings into |
| 232 | * the dialog event status structure. |
| 233 | * @param status The dialog event status to be initialized. |
| 234 | * |
| 235 | * @return PJ_SUCCESS on success. |
| 236 | * |
| 237 | * @see pjsip_dlg_event_parse_dialog_info() |
| 238 | */ |
| 239 | PJ_DECL(pj_status_t) |
| 240 | pjsip_dlg_event_parse_dialog_info(pjsip_rx_data *rdata, |
| 241 | pj_pool_t *pool, |
| 242 | pjsip_dlg_event_status *dlg_status); |
| 243 | |
| 244 | |
| 245 | /** |
| 246 | * This is a utility function to parse XML body into PJSIP dialog event status. |
| 247 | * |
| 248 | * @param body Text body, with one extra space at the end to place |
| 249 | * NULL character temporarily during parsing. |
| 250 | * @param body_len Length of the body, not including the NULL termination |
| 251 | * character. |
| 252 | * @param pool Pool to allocate memory to copy the strings into |
| 253 | * the dialog event status structure. |
| 254 | * @param status The dialog event status to be initialized. |
| 255 | * |
| 256 | * @return PJ_SUCCESS on success. |
| 257 | * |
| 258 | * @see pjsip_dlg_event_parse_dialog_info2() |
| 259 | */ |
| 260 | PJ_DECL(pj_status_t) |
| 261 | pjsip_dlg_event_parse_dialog_info2(char *body, unsigned body_len, |
| 262 | pj_pool_t *pool, |
| 263 | pjsip_dlg_event_status *dlg_status); |
| 264 | |
| 265 | |
| 266 | /** |
| 267 | * @} |
| 268 | */ |
| 269 | |
| 270 | PJ_END_DECL |
| 271 | |
| 272 | |
| 273 | #endif /* __PJSIP_SIMPLE_DLG_EVENT_H__ */ |