| 1 | /* |
| 2 | * res_pjsip_private.h |
| 3 | * |
| 4 | * Created on: Jan 25, 2013 |
| 5 | * Author: mjordan |
| 6 | */ |
| 7 | |
| 8 | #ifndef RES_PJSIP_PRIVATE_H_ |
| 9 | #define RES_PJSIP_PRIVATE_H_ |
| 10 | |
| 11 | /*! |
| 12 | * \todo XXX Functions prototyped in this file that begin with "ast_sip_" |
| 13 | * need to be renamed so res_pjsip.so does not export the names outside |
| 14 | * of the module. |
| 15 | */ |
| 16 | |
| 17 | #include "asterisk/module.h" |
| 18 | #include "asterisk/compat.h" |
| 19 | |
| 20 | struct ao2_container; |
| 21 | struct ast_taskpool_options; |
| 22 | struct ast_sip_cli_context; |
| 23 | |
| 24 | /*! |
| 25 | * \internal |
| 26 | * \brief Initialize the configuration for res_pjsip |
| 27 | */ |
| 28 | int ast_res_pjsip_initialize_configuration(void); |
| 29 | |
| 30 | /*! |
| 31 | * \internal |
| 32 | * \brief Annihilate the configuration objects |
| 33 | */ |
| 34 | void ast_res_pjsip_destroy_configuration(void); |
| 35 | |
| 36 | /*! |
| 37 | * \internal |
| 38 | * \brief Reload the configuration |
| 39 | */ |
| 40 | int ast_res_pjsip_reload_configuration(void); |
| 41 | |
| 42 | /*! |
| 43 | * \internal |
| 44 | * \brief Initialize transport support on a sorcery instance |
| 45 | * |
| 46 | * \retval -1 failure |
| 47 | * \retval 0 success |
| 48 | */ |
| 49 | int ast_sip_initialize_sorcery_transport(void); |
| 50 | |
| 51 | /*! |
| 52 | * \internal |
| 53 | * \brief Destroy transport support on a sorcery instance |
| 54 | * |
| 55 | * \retval -1 failure |
| 56 | * \retval 0 success |
| 57 | */ |
| 58 | int ast_sip_destroy_sorcery_transport(void); |
| 59 | |
| 60 | /*! |
| 61 | * \internal |
| 62 | * \brief Initialize qualify support on a sorcery instance |
| 63 | * |
| 64 | * \retval -1 failure |
| 65 | * \retval 0 success |
| 66 | */ |
| 67 | int ast_sip_initialize_sorcery_qualify(void); |
| 68 | |
| 69 | /*! |
| 70 | * \internal |
| 71 | * \brief Initialize location support on a sorcery instance |
| 72 | * |
| 73 | * \retval -1 failure |
| 74 | * \retval 0 success |
| 75 | */ |
| 76 | int ast_sip_initialize_sorcery_location(void); |
| 77 | |
| 78 | /*! |
| 79 | * \internal |
| 80 | * \brief Destroy location support on a sorcery instance |
| 81 | * |
| 82 | * \retval -1 failure |
| 83 | * \retval 0 success |
| 84 | */ |
| 85 | int ast_sip_destroy_sorcery_location(void); |
| 86 | |
| 87 | /*! |
| 88 | * \internal |
| 89 | * \brief Initialize domain aliases support on a sorcery instance |
| 90 | * |
| 91 | * \retval -1 failure |
| 92 | * \retval 0 success |
| 93 | */ |
| 94 | int ast_sip_initialize_sorcery_domain_alias(void); |
| 95 | |
| 96 | /*! |
| 97 | * \internal |
| 98 | * \brief Initialize authentication support on a sorcery instance |
| 99 | * |
| 100 | * \retval -1 failure |
| 101 | * \retval 0 success |
| 102 | */ |
| 103 | int ast_sip_initialize_sorcery_auth(void); |
| 104 | |
| 105 | /*! |
| 106 | * \internal |
| 107 | * \brief Destroy authentication support on a sorcery instance |
| 108 | * |
| 109 | * \retval -1 failure |
| 110 | * \retval 0 success |
| 111 | */ |
| 112 | int ast_sip_destroy_sorcery_auth(void); |
| 113 | |
| 114 | /*! |
| 115 | * \internal |
| 116 | * \brief Initialize the distributor module |
| 117 | * |
| 118 | * The distributor module is responsible for taking an incoming |
| 119 | * SIP message and placing it into the taskpool. Once in the taskpool, |
| 120 | * the distributor will perform endpoint lookups and authentication, and |
| 121 | * then distribute the message up the stack to any further modules. |
| 122 | * |
| 123 | * \retval -1 Failure |
| 124 | * \retval 0 Success |
| 125 | */ |
| 126 | int ast_sip_initialize_distributor(void); |
| 127 | |
| 128 | /*! |
| 129 | * \internal |
| 130 | * \brief Destruct the distributor module. |
| 131 | * |
| 132 | * Unregisters pjsip modules and cleans up any allocated resources. |
| 133 | */ |
| 134 | void ast_sip_destroy_distributor(void); |
| 135 | |
| 136 | /*! |
| 137 | * \internal |
| 138 | * \brief Initialize the transport events notify module |
| 139 | * \since 13.18.0 |
| 140 | * |
| 141 | * The transport events notify module is responsible for monitoring |
| 142 | * when transports die and calling any registered callbacks when that |
| 143 | * happens. It also manages any PJPROJECT transport state callbacks |
| 144 | * registered to it so the callbacks be more dynamic allowing module |
| 145 | * loading/unloading. |
| 146 | * |
| 147 | * \retval -1 Failure |
| 148 | * \retval 0 Success |
| 149 | */ |
| 150 | int ast_sip_initialize_transport_events(void); |
| 151 | |
| 152 | /*! |
| 153 | * \internal |
| 154 | * \brief Destruct the transport events notify module. |
| 155 | * \since 13.18.0 |
| 156 | */ |
| 157 | void ast_sip_destroy_transport_events(void); |
| 158 | |
| 159 | /*! |
| 160 | * \internal |
| 161 | * \brief Initialize global type on a sorcery instance |
| 162 | * |
| 163 | * \retval -1 failure |
| 164 | * \retval 0 success |
| 165 | */ |
| 166 | int ast_sip_initialize_sorcery_global(void); |
| 167 | |
| 168 | /*! |
| 169 | * \internal |
| 170 | * \brief Destroy global type on a sorcery instance |
| 171 | * \since 13.3.0 |
| 172 | * |
| 173 | * \retval -1 failure |
| 174 | * \retval 0 success |
| 175 | */ |
| 176 | int ast_sip_destroy_sorcery_global(void); |
| 177 | |
| 178 | /*! |
| 179 | * \internal |
| 180 | * \brief Initialize global headers support |
| 181 | */ |
| 182 | void ast_sip_initialize_global_headers(void); |
| 183 | |
| 184 | /*! |
| 185 | * \internal |
| 186 | * \brief Destroy global headers support |
| 187 | */ |
| 188 | void ast_sip_destroy_global_headers(void); |
| 189 | |
| 190 | /*! |
| 191 | * \internal |
| 192 | * \brief Pre-initialize OPTIONS request handling. |
| 193 | * |
| 194 | * \retval 0 on success |
| 195 | * \retval other on failure |
| 196 | */ |
| 197 | int ast_res_pjsip_preinit_options_handling(void); |
| 198 | |
| 199 | /*! |
| 200 | * \internal |
| 201 | * \brief Initialize OPTIONS request handling. |
| 202 | * |
| 203 | * XXX This currently includes qualifying peers. It shouldn't. |
| 204 | * That should go into a registrar. When that occurs, we won't |
| 205 | * need the reload stuff. |
| 206 | * |
| 207 | * \param reload Reload options handling |
| 208 | * |
| 209 | * \retval 0 on success |
| 210 | * \retval other on failure |
| 211 | */ |
| 212 | int ast_res_pjsip_init_options_handling(int reload); |
| 213 | |
| 214 | /*! |
| 215 | * \internal Initialize message IP updating handling. |
| 216 | * |
| 217 | * \retval 0 on success |
| 218 | * \retval other on failure |
| 219 | */ |
| 220 | int ast_res_pjsip_init_message_filter(void); |
| 221 | |
| 222 | /*! |
| 223 | * \internal |
| 224 | * \brief Initialize transport storage for contacts. |
| 225 | * |
| 226 | * \retval 0 on success |
| 227 | * \retval other on failure |
| 228 | */ |
| 229 | int ast_res_pjsip_init_contact_transports(void); |
| 230 | |
| 231 | /*! |
| 232 | * \internal |
| 233 | * \brief Initialize system configuration |
| 234 | * |
| 235 | * \retval 0 Success |
| 236 | * \retval non-zero Failure |
| 237 | */ |
| 238 | int ast_sip_initialize_system(void); |
| 239 | |
| 240 | /*! |
| 241 | * \internal |
| 242 | * \brief Destroy system configuration |
| 243 | */ |
| 244 | void ast_sip_destroy_system(void); |
| 245 | |
| 246 | /*! |
| 247 | * \internal |
| 248 | * \brief Initialize nameserver configuration |
| 249 | */ |
| 250 | void ast_sip_initialize_dns(void); |
| 251 | |
| 252 | /*! |
| 253 | * \internal |
| 254 | * \brief Initialize our own resolver support |
| 255 | */ |
| 256 | void ast_sip_initialize_resolver(void); |
| 257 | |
| 258 | /*! |
| 259 | * \internal |
| 260 | * \brief Initialize global configuration |
| 261 | * |
| 262 | * \retval 0 Success |
| 263 | * \retval non-zero Failure |
| 264 | */ |
| 265 | int ast_sip_initialize_global(void); |
| 266 | |
| 267 | /*! |
| 268 | * \internal |
| 269 | * \brief Clean up res_pjsip options handling |
| 270 | */ |
| 271 | void ast_res_pjsip_cleanup_options_handling(void); |
| 272 | |
| 273 | /*! |
| 274 | * \internal |
| 275 | * \brief Clean up res_pjsip message ip updating handling |
| 276 | */ |
| 277 | void ast_res_pjsip_cleanup_message_filter(void); |
| 278 | |
| 279 | /*! |
| 280 | * \internal |
| 281 | * \brief Get taskpool options |
| 282 | */ |
| 283 | void sip_get_taskpool_options(struct ast_taskpool_options *taskpool_options); |
| 284 | |
| 285 | /*! |
| 286 | * \internal |
| 287 | * \brief Retrieve the name of the default outbound endpoint. |
| 288 | * |
| 289 | * \note This returns a memory allocated copy of the name that |
| 290 | * needs to be freed by the caller. |
| 291 | * |
| 292 | * \retval The name of the default outbound endpoint. |
| 293 | * \retval NULL if configuration not found. |
| 294 | */ |
| 295 | char *ast_sip_global_default_outbound_endpoint(void); |
| 296 | |
| 297 | /*! |
| 298 | * \internal |
| 299 | * \brief Functions for initializing and destroying the CLI. |
| 300 | */ |
| 301 | int ast_sip_initialize_cli(void); |
| 302 | void ast_sip_destroy_cli(void); |
| 303 | |
| 304 | /*! |
| 305 | * \internal |
| 306 | * \brief Add res_pjsip global configuration options to the cli context. |
| 307 | * |
| 308 | * \param context context to add options to |
| 309 | * \retval 0 Success, -1 on failure |
| 310 | */ |
| 311 | int sip_cli_print_global(struct ast_sip_cli_context *context); |
| 312 | |
| 313 | /*! |
| 314 | * \internal |
| 315 | * \brief Add res_pjsip system configuration options to the cli context. |
| 316 | * |
| 317 | * \param context context to add options to |
| 318 | * \retval 0 Success, -1 on failure |
| 319 | */ |
| 320 | int sip_cli_print_system(struct ast_sip_cli_context *context); |
| 321 | |
| 322 | struct ast_sip_session_supplement; |
| 323 | |
| 324 | /*! |
| 325 | * \internal |
| 326 | * \brief Finds or creates contact_status for a contact |
| 327 | */ |
| 328 | struct ast_sip_contact_status *ast_res_pjsip_find_or_create_contact_status(const struct ast_sip_contact *contact); |
| 329 | |
| 330 | /*! |
| 331 | * \internal |
| 332 | * \brief Validate that the uri meets pjproject length restrictions |
| 333 | */ |
| 334 | int ast_sip_validate_uri_length(const char *uri); |
| 335 | |
| 336 | /*! |
| 337 | * \brief Initialize scheduler |
| 338 | * \since 13.9.0 |
| 339 | * |
| 340 | * \retval -1 failure |
| 341 | * \retval 0 success |
| 342 | */ |
| 343 | int ast_sip_initialize_scheduler(void); |
| 344 | |
| 345 | /*! |
| 346 | * \internal |
| 347 | * \brief Destroy scheduler |
| 348 | * \since 13.9.0 |
| 349 | * |
| 350 | * \retval -1 failure |
| 351 | * \retval 0 success |
| 352 | */ |
| 353 | int ast_sip_destroy_scheduler(void); |
| 354 | |
| 355 | /*! |
| 356 | * \internal |
| 357 | * \brief Determines if a uri will still be valid after an asterisk restart |
| 358 | * \since 13.20.0 |
| 359 | * |
| 360 | * \param uri uri to test |
| 361 | * \param endpoint The associated endpoint |
| 362 | * \param rdata The rdata to get transport information from |
| 363 | * |
| 364 | * \retval 1 Yes, 0 No |
| 365 | */ |
| 366 | int ast_sip_will_uri_survive_restart(pjsip_sip_uri *uri, struct ast_sip_endpoint *endpoint, |
| 367 | pjsip_rx_data *rdata); |
| 368 | |
| 369 | /*! |
| 370 | * \internal |
| 371 | * \brief Initialize the transport management module |
| 372 | * \since 13.20.0 |
| 373 | * |
| 374 | * The transport management module is responsible for 3 things... |
| 375 | * 1. It automatically destroys any reliable transport that does not |
| 376 | * receive a valid request within system/timer_b milliseconds of the |
| 377 | * connection being opened. (Attack mitigation) |
| 378 | * 2. Since it increments the reliable transport's reference count |
| 379 | * for that period of time, it also prevents issues if the transport |
| 380 | * disconnects while we're still trying to process a response. |
| 381 | * (Attack mitigation) |
| 382 | * 3. If enabled by global/keep_alive_interval, it sends '\\r\\n' |
| 383 | * keepalives on reliable transports at the interval specified. |
| 384 | * |
| 385 | * \retval -1 Failure |
| 386 | * \retval 0 Success |
| 387 | */ |
| 388 | int ast_sip_initialize_transport_management(void); |
| 389 | |
| 390 | /*! |
| 391 | * \internal |
| 392 | * \brief Destruct the transport management module. |
| 393 | * \since 13.20.0 |
| 394 | */ |
| 395 | void ast_sip_destroy_transport_management(void); |
| 396 | |
| 397 | /*! |
| 398 | * \internal |
| 399 | * \brief Add online persistent endpoints to the given regcontext |
| 400 | * |
| 401 | * \param regcontext The context to add endpoints to |
| 402 | * |
| 403 | * \retval -1 on error, 0 on success |
| 404 | */ |
| 405 | int ast_sip_persistent_endpoint_add_to_regcontext(const char *regcontext); |
| 406 | |
| 407 | enum ast_sip_taskprocessor_overload_trigger { |
| 408 | TASKPROCESSOR_OVERLOAD_TRIGGER_NONE = 0, |
| 409 | TASKPROCESSOR_OVERLOAD_TRIGGER_GLOBAL, |
| 410 | TASKPROCESSOR_OVERLOAD_TRIGGER_PJSIP_ONLY |
| 411 | }; |
| 412 | |
| 413 | enum ast_sip_taskprocessor_overload_trigger ast_sip_get_taskprocessor_overload_trigger(void); |
| 414 | |
| 415 | const char *ast_sip_overload_trigger_to_str(enum ast_sip_taskprocessor_overload_trigger trigger); |
| 416 | |
| 417 | #endif /* RES_PJSIP_PRIVATE_H_ */ |