res_pjsip_refer.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2013, Digium, Inc.
00005  *
00006  * Joshua Colp <jcolp@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*** MODULEINFO
00020    <depend>pjproject</depend>
00021    <depend>res_pjsip</depend>
00022    <depend>res_pjsip_session</depend>
00023    <support_level>core</support_level>
00024  ***/
00025 
00026 #include "asterisk.h"
00027 
00028 #include <pjsip.h>
00029 #include <pjsip_ua.h>
00030 
00031 #include "asterisk/res_pjsip.h"
00032 #include "asterisk/res_pjsip_session.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/taskprocessor.h"
00036 #include "asterisk/bridge.h"
00037 #include "asterisk/framehook.h"
00038 #include "asterisk/stasis_bridges.h"
00039 #include "asterisk/stasis_channels.h"
00040 #include "asterisk/causes.h"
00041 
00042 /*! \brief REFER Progress structure */
00043 struct refer_progress {
00044    /*! \brief Subscription to provide updates on */
00045    pjsip_evsub *sub;
00046    /*! \brief Dialog for subscription */
00047    pjsip_dialog *dlg;
00048    /*! \brief Received packet, used to construct final response in case no subscription exists */
00049    pjsip_rx_data *rdata;
00050    /*! \brief Frame hook for monitoring REFER progress */
00051    int framehook;
00052    /*! \brief Last received subclass in frame hook */
00053    int subclass;
00054    /*! \brief Serializer for notifications */
00055    struct ast_taskprocessor *serializer;
00056    /*! \brief Stasis subscription for bridge events */
00057    struct stasis_subscription *bridge_sub;
00058    /*! \brief Reference to transfer_channel_data related to the refer */
00059    struct transfer_channel_data *transfer_data;
00060    /*! \brief Uniqueid of transferee channel */
00061    char *transferee;
00062 };
00063 
00064 /*! \brief REFER Progress notification structure */
00065 struct refer_progress_notification {
00066    /*! \brief Refer progress structure to send notification on */
00067    struct refer_progress *progress;
00068    /*! \brief SIP response code to send */
00069    int response;
00070    /*! \brief Subscription state */
00071    pjsip_evsub_state state;
00072 };
00073 
00074 /*! \brief REFER Progress module, used to attach REFER progress structure to subscriptions */
00075 static pjsip_module refer_progress_module = {
00076    .name = { "REFER Progress", 14 },
00077    .id = -1,
00078 };
00079 
00080 /*! \brief Destructor for REFER Progress notification structure */
00081 static void refer_progress_notification_destroy(void *obj)
00082 {
00083    struct refer_progress_notification *notification = obj;
00084 
00085    ao2_cleanup(notification->progress);
00086 }
00087 
00088 /*! \brief Allocator for REFER Progress notification structure */
00089 static struct refer_progress_notification *refer_progress_notification_alloc(struct refer_progress *progress, int response,
00090    pjsip_evsub_state state)
00091 {
00092    struct refer_progress_notification *notification = ao2_alloc(sizeof(*notification), refer_progress_notification_destroy);
00093 
00094    if (!notification) {
00095       return NULL;
00096    }
00097 
00098    ao2_ref(progress, +1);
00099    notification->progress = progress;
00100    notification->response = response;
00101    notification->state = state;
00102 
00103    return notification;
00104 }
00105 
00106 /*! \brief Serialized callback for subscription notification */
00107 static int refer_progress_notify(void *data)
00108 {
00109    RAII_VAR(struct refer_progress_notification *, notification, data, ao2_cleanup);
00110    pjsip_evsub *sub;
00111    pjsip_tx_data *tdata;
00112 
00113    /* If the subscription has already been terminated we can't send a notification */
00114    if (!(sub = notification->progress->sub)) {
00115       ast_debug(3, "Not sending NOTIFY of response '%d' and state '%u' on progress monitor '%p' as subscription has been terminated\n",
00116          notification->response, notification->state, notification->progress);
00117       return 0;
00118    }
00119 
00120    /* If the subscription is being terminated we want to actually remove the progress structure here to
00121     * stop a deadlock from occurring - basically terminated changes the state which queues a synchronous task
00122     * but we are already running a task... thus it would deadlock */
00123    if (notification->state == PJSIP_EVSUB_STATE_TERMINATED) {
00124       ast_debug(3, "Subscription '%p' is being terminated as a result of a NOTIFY, removing REFER progress structure early on progress monitor '%p'\n",
00125          notification->progress->sub, notification->progress);
00126       pjsip_dlg_inc_lock(notification->progress->dlg);
00127       pjsip_evsub_set_mod_data(notification->progress->sub, refer_progress_module.id, NULL);
00128       pjsip_dlg_dec_lock(notification->progress->dlg);
00129 
00130       /* This is for dropping the reference on the subscription */
00131       ao2_cleanup(notification->progress);
00132 
00133       notification->progress->sub = NULL;
00134    }
00135 
00136    ast_debug(3, "Sending NOTIFY with response '%d' and state '%u' on subscription '%p' and progress monitor '%p'\n",
00137       notification->response, notification->state, sub, notification->progress);
00138 
00139    /* Actually send the notification */
00140    if (pjsip_xfer_notify(sub, notification->state, notification->response, NULL, &tdata) == PJ_SUCCESS) {
00141       pjsip_xfer_send_request(sub, tdata);
00142    }
00143 
00144    return 0;
00145 }
00146 
00147 static void refer_progress_bridge(void *data, struct stasis_subscription *sub,
00148       struct stasis_message *message)
00149 {
00150    struct refer_progress *progress = data;
00151    struct ast_bridge_blob *enter_blob;
00152    struct refer_progress_notification *notification;
00153    struct ast_channel *chan;
00154 
00155    if (stasis_subscription_final_message(sub, message)) {
00156       ao2_ref(progress, -1);
00157       return;
00158    }
00159 
00160    if (ast_channel_entered_bridge_type() != stasis_message_type(message)) {
00161       /* Don't care */
00162       return;
00163    }
00164 
00165    enter_blob = stasis_message_data(message);
00166    if (strcmp(enter_blob->channel->uniqueid, progress->transferee)) {
00167       /* Don't care */
00168       return;
00169    }
00170 
00171    if (!progress->transfer_data->completed) {
00172       /* We can't act on this message because the transfer_channel_data doesn't show that
00173        * the transfer is ready to progress */
00174       return;
00175    }
00176 
00177    /* OMG the transferee is joining a bridge. His call got answered! */
00178    notification = refer_progress_notification_alloc(progress, 200, PJSIP_EVSUB_STATE_TERMINATED);
00179    if (notification) {
00180       if (ast_sip_push_task(progress->serializer, refer_progress_notify, notification)) {
00181          ao2_cleanup(notification);
00182       }
00183       progress->bridge_sub = stasis_unsubscribe(progress->bridge_sub);
00184    }
00185 
00186    chan = ast_channel_get_by_name(progress->transferee);
00187    if (!chan) {
00188       /* The channel is already gone */
00189       return;
00190    }
00191 
00192    ast_channel_lock(chan);
00193    ast_debug(3, "Detaching REFER progress monitoring hook from '%s' as it has joined a bridge\n",
00194       ast_channel_name(chan));
00195    ast_framehook_detach(chan, progress->framehook);
00196    ast_channel_unlock(chan);
00197 
00198    ast_channel_unref(chan);
00199 }
00200 
00201 /*! \brief Progress monitoring frame hook - examines frames to determine state of transfer */
00202 static struct ast_frame *refer_progress_framehook(struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data)
00203 {
00204    struct refer_progress *progress = data;
00205    struct refer_progress_notification *notification = NULL;
00206 
00207    /* We only care about frames *to* the channel */
00208    if (!f || (event != AST_FRAMEHOOK_EVENT_WRITE)) {
00209       return f;
00210    }
00211 
00212    /* If the completed flag hasn't been raised, skip this pass. */
00213    if (!progress->transfer_data->completed) {
00214       return f;
00215    }
00216 
00217    /* Determine the state of the REFER based on the control frames (or voice frames) passing */
00218    if (f->frametype == AST_FRAME_VOICE && !progress->subclass) {
00219       /* Media is passing without progress, this means the call has been answered */
00220       notification = refer_progress_notification_alloc(progress, 200, PJSIP_EVSUB_STATE_TERMINATED);
00221    } else if (f->frametype == AST_FRAME_CONTROL) {
00222       /* Based on the control frame being written we can send a NOTIFY advising of the progress */
00223       if ((f->subclass.integer == AST_CONTROL_RING) || (f->subclass.integer == AST_CONTROL_RINGING)) {
00224          progress->subclass = f->subclass.integer;
00225          notification = refer_progress_notification_alloc(progress, 180, PJSIP_EVSUB_STATE_ACTIVE);
00226       } else if (f->subclass.integer == AST_CONTROL_BUSY) {
00227          progress->subclass = f->subclass.integer;
00228          notification = refer_progress_notification_alloc(progress, 486, PJSIP_EVSUB_STATE_TERMINATED);
00229       } else if (f->subclass.integer == AST_CONTROL_CONGESTION) {
00230          progress->subclass = f->subclass.integer;
00231          notification = refer_progress_notification_alloc(progress, 503, PJSIP_EVSUB_STATE_TERMINATED);
00232       } else if (f->subclass.integer == AST_CONTROL_PROGRESS) {
00233          progress->subclass = f->subclass.integer;
00234          notification = refer_progress_notification_alloc(progress, 183, PJSIP_EVSUB_STATE_ACTIVE);
00235       } else if (f->subclass.integer == AST_CONTROL_PROCEEDING) {
00236          progress->subclass = f->subclass.integer;
00237          notification = refer_progress_notification_alloc(progress, 100, PJSIP_EVSUB_STATE_ACTIVE);
00238       } else if (f->subclass.integer == AST_CONTROL_ANSWER) {
00239          progress->subclass = f->subclass.integer;
00240          notification = refer_progress_notification_alloc(progress, 200, PJSIP_EVSUB_STATE_TERMINATED);
00241       }
00242    }
00243 
00244    /* If a notification is due to be sent push it to the thread pool */
00245    if (notification) {
00246       /* If the subscription is being terminated we don't need the frame hook any longer */
00247       if (notification->state == PJSIP_EVSUB_STATE_TERMINATED) {
00248          ast_debug(3, "Detaching REFER progress monitoring hook from '%s' as subscription is being terminated\n",
00249             ast_channel_name(chan));
00250          ast_framehook_detach(chan, progress->framehook);
00251       }
00252 
00253       if (ast_sip_push_task(progress->serializer, refer_progress_notify, notification)) {
00254          ao2_cleanup(notification);
00255       }
00256    }
00257 
00258    return f;
00259 }
00260 
00261 /*! \brief Destroy callback for monitoring framehook */
00262 static void refer_progress_framehook_destroy(void *data)
00263 {
00264    struct refer_progress *progress = data;
00265    struct refer_progress_notification *notification = refer_progress_notification_alloc(progress, 503, PJSIP_EVSUB_STATE_TERMINATED);
00266 
00267    if (notification && ast_sip_push_task(progress->serializer, refer_progress_notify, notification)) {
00268       ao2_cleanup(notification);
00269    }
00270 
00271    if (progress->bridge_sub) {
00272       progress->bridge_sub = stasis_unsubscribe(progress->bridge_sub);
00273    }
00274 
00275    ao2_cleanup(progress);
00276 }
00277 
00278 /*! \brief Serialized callback for subscription termination */
00279 static int refer_progress_terminate(void *data)
00280 {
00281    struct refer_progress *progress = data;
00282 
00283    /* The subscription is no longer valid */
00284    progress->sub = NULL;
00285 
00286    return 0;
00287 }
00288 
00289 /*! \brief Callback for REFER subscription state changes */
00290 static void refer_progress_on_evsub_state(pjsip_evsub *sub, pjsip_event *event)
00291 {
00292    struct refer_progress *progress = pjsip_evsub_get_mod_data(sub, refer_progress_module.id);
00293 
00294    /* If being destroyed queue it up to the serializer */
00295    if (progress && (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_TERMINATED)) {
00296       /* To prevent a deadlock race condition we unlock the dialog so other serialized tasks can execute */
00297       ast_debug(3, "Subscription '%p' has been remotely terminated, waiting for other tasks to complete on progress monitor '%p'\n",
00298          sub, progress);
00299 
00300       /* It's possible that a task is waiting to remove us already, so bump the refcount of progress so it doesn't get destroyed */
00301       ao2_ref(progress, +1);
00302       pjsip_dlg_dec_lock(progress->dlg);
00303       ast_sip_push_task_synchronous(progress->serializer, refer_progress_terminate, progress);
00304       pjsip_dlg_inc_lock(progress->dlg);
00305       ao2_ref(progress, -1);
00306 
00307       ast_debug(3, "Subscription '%p' removed from progress monitor '%p'\n", sub, progress);
00308 
00309       /* Since it was unlocked it is possible for this to have been removed already, so check again */
00310       if (pjsip_evsub_get_mod_data(sub, refer_progress_module.id)) {
00311          pjsip_evsub_set_mod_data(sub, refer_progress_module.id, NULL);
00312          ao2_cleanup(progress);
00313       }
00314    }
00315 }
00316 
00317 /*! \brief Callback structure for subscription */
00318 static pjsip_evsub_user refer_progress_evsub_cb = {
00319    .on_evsub_state = refer_progress_on_evsub_state,
00320 };
00321 
00322 /*! \brief Destructor for REFER progress sutrcture */
00323 static void refer_progress_destroy(void *obj)
00324 {
00325    struct refer_progress *progress = obj;
00326 
00327    if (progress->bridge_sub) {
00328       progress->bridge_sub = stasis_unsubscribe(progress->bridge_sub);
00329    }
00330 
00331    ao2_cleanup(progress->transfer_data);
00332 
00333    ast_free(progress->transferee);
00334    ast_taskprocessor_unreference(progress->serializer);
00335 }
00336 
00337 /*! \brief Internal helper function which sets up a refer progress structure if needed */
00338 static int refer_progress_alloc(struct ast_sip_session *session, pjsip_rx_data *rdata, struct refer_progress **progress)
00339 {
00340    const pj_str_t str_refer_sub = { "Refer-Sub", 9 };
00341    pjsip_generic_string_hdr *refer_sub = NULL;
00342    const pj_str_t str_true = { "true", 4 };
00343    pjsip_tx_data *tdata;
00344    pjsip_hdr hdr_list;
00345 
00346    *progress = NULL;
00347 
00348    /* Grab the optional Refer-Sub header, it can be used to suppress the implicit subscription */
00349    refer_sub = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_sub, NULL);
00350    if ((refer_sub && pj_strnicmp(&refer_sub->hvalue, &str_true, 4))) {
00351       return 0;
00352    }
00353 
00354    if (!(*progress = ao2_alloc(sizeof(struct refer_progress), refer_progress_destroy))) {
00355       return -1;
00356    }
00357 
00358    ast_debug(3, "Created progress monitor '%p' for transfer occurring from channel '%s' and endpoint '%s'\n",
00359       progress, ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
00360 
00361    (*progress)->framehook = -1;
00362 
00363    /* To prevent a potential deadlock we need the dialog so we can lock/unlock */
00364    (*progress)->dlg = session->inv_session->dlg;
00365 
00366    if (!((*progress)->serializer = ast_sip_create_serializer())) {
00367       goto error;
00368    }
00369 
00370    /* Create the implicit subscription for monitoring of this transfer */
00371    if (pjsip_xfer_create_uas(session->inv_session->dlg, &refer_progress_evsub_cb, rdata, &(*progress)->sub) != PJ_SUCCESS) {
00372       goto error;
00373    }
00374 
00375    /* Associate the REFER progress structure with the subscription */
00376    ao2_ref(*progress, +1);
00377    pjsip_evsub_set_mod_data((*progress)->sub, refer_progress_module.id, *progress);
00378 
00379    pj_list_init(&hdr_list);
00380    if (refer_sub) {
00381       pjsip_hdr *hdr = (pjsip_hdr*)pjsip_generic_string_hdr_create(session->inv_session->dlg->pool, &str_refer_sub, &str_true);
00382 
00383       pj_list_push_back(&hdr_list, hdr);
00384    }
00385 
00386    /* Accept the REFER request */
00387    ast_debug(3, "Accepting REFER request for progress monitor '%p'\n", *progress);
00388    pjsip_xfer_accept((*progress)->sub, rdata, 202, &hdr_list);
00389 
00390    /* Send initial NOTIFY Request */
00391    ast_debug(3, "Sending initial 100 Trying NOTIFY for progress monitor '%p'\n", *progress);
00392    if (pjsip_xfer_notify((*progress)->sub, PJSIP_EVSUB_STATE_ACTIVE, 100, NULL, &tdata) == PJ_SUCCESS) {
00393       pjsip_xfer_send_request((*progress)->sub, tdata);
00394    }
00395 
00396    return 0;
00397 
00398 error:
00399    ao2_cleanup(*progress);
00400    *progress = NULL;
00401    return -1;
00402 }
00403 
00404 /*! \brief Structure for attended transfer task */
00405 struct refer_attended {
00406    /*! \brief Transferer session */
00407    struct ast_sip_session *transferer;
00408    /*! \brief Transferer channel */
00409    struct ast_channel *transferer_chan;
00410    /*! \brief Second transferer session */
00411    struct ast_sip_session *transferer_second;
00412    /*! \brief Optional refer progress structure */
00413    struct refer_progress *progress;
00414 };
00415 
00416 /*! \brief Destructor for attended transfer task */
00417 static void refer_attended_destroy(void *obj)
00418 {
00419    struct refer_attended *attended = obj;
00420 
00421    ao2_cleanup(attended->transferer);
00422    ast_channel_cleanup(attended->transferer_chan);
00423    ao2_cleanup(attended->transferer_second);
00424    ao2_cleanup(attended->progress);
00425 }
00426 
00427 /*! \brief Allocator for attended transfer task */
00428 static struct refer_attended *refer_attended_alloc(struct ast_sip_session *transferer,
00429    struct ast_sip_session *transferer_second,
00430    struct refer_progress *progress)
00431 {
00432    struct refer_attended *attended;
00433 
00434    attended = ao2_alloc_options(sizeof(*attended), refer_attended_destroy,
00435       AO2_ALLOC_OPT_LOCK_NOLOCK);
00436    if (!attended) {
00437       return NULL;
00438    }
00439 
00440    ao2_ref(transferer, +1);
00441    attended->transferer = transferer;
00442    ast_channel_ref(transferer->channel);
00443    attended->transferer_chan = transferer->channel;
00444    ao2_ref(transferer_second, +1);
00445    attended->transferer_second = transferer_second;
00446 
00447    if (progress) {
00448       ao2_ref(progress, +1);
00449       attended->progress = progress;
00450    }
00451 
00452    return attended;
00453 }
00454 
00455 static int defer_termination_cancel(void *data)
00456 {
00457    struct ast_sip_session *session = data;
00458 
00459    ast_sip_session_defer_termination_cancel(session);
00460    ao2_ref(session, -1);
00461    return 0;
00462 }
00463 
00464 /*!
00465  * \internal
00466  * \brief Convert transfer enum to SIP response code.
00467  * \since 13.3.0
00468  *
00469  * \param xfer_code Core transfer function enum result.
00470  *
00471  * \return SIP response code
00472  */
00473 static int xfer_response_code2sip(enum ast_transfer_result xfer_code)
00474 {
00475    int response;
00476 
00477    response = 503;
00478    switch (xfer_code) {
00479    case AST_BRIDGE_TRANSFER_INVALID:
00480       response = 400;
00481       break;
00482    case AST_BRIDGE_TRANSFER_NOT_PERMITTED:
00483       response = 403;
00484       break;
00485    case AST_BRIDGE_TRANSFER_FAIL:
00486       response = 500;
00487       break;
00488    case AST_BRIDGE_TRANSFER_SUCCESS:
00489       response = 200;
00490       break;
00491    }
00492    return response;
00493 }
00494 
00495 /*! \brief Task for attended transfer executed by attended->transferer_second serializer */
00496 static int refer_attended_task(void *data)
00497 {
00498    struct refer_attended *attended = data;
00499    int response;
00500 
00501    if (attended->transferer_second->channel) {
00502       ast_debug(3, "Performing a REFER attended transfer - Transferer #1: %s Transferer #2: %s\n",
00503          ast_channel_name(attended->transferer_chan),
00504          ast_channel_name(attended->transferer_second->channel));
00505 
00506       response = xfer_response_code2sip(ast_bridge_transfer_attended(
00507          attended->transferer_chan,
00508          attended->transferer_second->channel));
00509 
00510       ast_debug(3, "Final response for REFER attended transfer - Transferer #1: %s Transferer #2: %s is '%d'\n",
00511          ast_channel_name(attended->transferer_chan),
00512          ast_channel_name(attended->transferer_second->channel),
00513          response);
00514    } else {
00515       ast_debug(3, "Received REFER request on channel '%s' but other channel has gone.\n",
00516          ast_channel_name(attended->transferer_chan));
00517       response = 603;
00518    }
00519 
00520    if (attended->progress) {
00521       struct refer_progress_notification *notification;
00522 
00523       notification = refer_progress_notification_alloc(attended->progress, response,
00524          PJSIP_EVSUB_STATE_TERMINATED);
00525       if (notification) {
00526          refer_progress_notify(notification);
00527       }
00528    }
00529 
00530    if (response != 200) {
00531       if (!ast_sip_push_task(attended->transferer->serializer,
00532          defer_termination_cancel, attended->transferer)) {
00533          /* Gave the ref to the pushed task. */
00534          attended->transferer = NULL;
00535       }
00536    }
00537 
00538    ao2_ref(attended, -1);
00539    return 0;
00540 }
00541 
00542 /*! \brief Structure for blind transfer callback details */
00543 struct refer_blind {
00544    /*! \brief Context being used for transfer */
00545    const char *context;
00546    /*! \brief Optional progress structure */
00547    struct refer_progress *progress;
00548    /*! \brief REFER message */
00549    pjsip_rx_data *rdata;
00550    /*! \brief Optional Replaces header */
00551    pjsip_replaces_hdr *replaces;
00552    /*! \brief Optional Refer-To header */
00553    pjsip_sip_uri *refer_to;
00554 };
00555 
00556 /*! \brief Blind transfer callback function */
00557 static void refer_blind_callback(struct ast_channel *chan, struct transfer_channel_data *user_data_wrapper,
00558    enum ast_transfer_type transfer_type)
00559 {
00560    struct refer_blind *refer = user_data_wrapper->data;
00561    pjsip_generic_string_hdr *referred_by;
00562 
00563    static const pj_str_t str_referred_by = { "Referred-By", 11 };
00564 
00565    pbx_builtin_setvar_helper(chan, "SIPTRANSFER", "yes");
00566 
00567    /* If progress monitoring is being done attach a frame hook so we can monitor it */
00568    if (refer->progress) {
00569       struct ast_framehook_interface hook = {
00570          .version = AST_FRAMEHOOK_INTERFACE_VERSION,
00571          .event_cb = refer_progress_framehook,
00572          .destroy_cb = refer_progress_framehook_destroy,
00573          .data = refer->progress,
00574          .disable_inheritance = 1,
00575       };
00576 
00577       refer->progress->transferee = ast_strdup(ast_channel_uniqueid(chan));
00578       if (!refer->progress->transferee) {
00579          struct refer_progress_notification *notification = refer_progress_notification_alloc(refer->progress, 200,
00580             PJSIP_EVSUB_STATE_TERMINATED);
00581 
00582          ast_log(LOG_WARNING, "Could not copy channel name '%s' during transfer - assuming success\n",
00583             ast_channel_name(chan));
00584 
00585          if (notification) {
00586             refer_progress_notify(notification);
00587          }
00588       }
00589 
00590       /* Progress needs a reference to the transfer_channel_data so that it can track the completed status of the transfer */
00591       ao2_ref(user_data_wrapper, +1);
00592       refer->progress->transfer_data = user_data_wrapper;
00593 
00594       /* We need to bump the reference count up on the progress structure since it is in the frame hook now */
00595       ao2_ref(refer->progress, +1);
00596 
00597       /* If we can't attach a frame hook for whatever reason send a notification of success immediately */
00598       if ((refer->progress->framehook = ast_framehook_attach(chan, &hook)) < 0) {
00599          struct refer_progress_notification *notification = refer_progress_notification_alloc(refer->progress, 200,
00600             PJSIP_EVSUB_STATE_TERMINATED);
00601 
00602          ast_log(LOG_WARNING, "Could not attach REFER transfer progress monitoring hook to channel '%s' - assuming success\n",
00603             ast_channel_name(chan));
00604 
00605          if (notification) {
00606             refer_progress_notify(notification);
00607          }
00608 
00609          ao2_cleanup(refer->progress);
00610       }
00611 
00612       /* We need to bump the reference count for the stasis subscription */
00613       ao2_ref(refer->progress, +1);
00614       /* We also will need to detect if the transferee enters a bridge. This is currently the only reliable way to
00615        * detect if the transfer target has answered the call
00616        */
00617       refer->progress->bridge_sub = stasis_subscribe_pool(ast_bridge_topic_all(), refer_progress_bridge, refer->progress);
00618       if (!refer->progress->bridge_sub) {
00619          struct refer_progress_notification *notification = refer_progress_notification_alloc(refer->progress, 200,
00620             PJSIP_EVSUB_STATE_TERMINATED);
00621 
00622          ast_log(LOG_WARNING, "Could not create bridge stasis subscription for monitoring progress on transfer of channel '%s' - assuming success\n",
00623                ast_channel_name(chan));
00624 
00625          if (notification) {
00626             refer_progress_notify(notification);
00627          }
00628 
00629          ast_framehook_detach(chan, refer->progress->framehook);
00630 
00631          ao2_cleanup(refer->progress);
00632       }
00633    }
00634 
00635    pbx_builtin_setvar_helper(chan, "SIPREFERRINGCONTEXT", S_OR(refer->context, NULL));
00636 
00637    referred_by = pjsip_msg_find_hdr_by_name(refer->rdata->msg_info.msg,
00638       &str_referred_by, NULL);
00639    if (referred_by) {
00640       size_t uri_size = pj_strlen(&referred_by->hvalue) + 1;
00641       char *uri = ast_alloca(uri_size);
00642 
00643       ast_copy_pj_str(uri, &referred_by->hvalue, uri_size);
00644       pbx_builtin_setvar_helper(chan, "__SIPREFERREDBYHDR", S_OR(uri, NULL));
00645    } else {
00646       pbx_builtin_setvar_helper(chan, "SIPREFERREDBYHDR", NULL);
00647    }
00648 
00649    if (refer->replaces) {
00650       char replaces[512];
00651       char *replaces_val = NULL;
00652       int len;
00653 
00654       len = pjsip_hdr_print_on(refer->replaces, replaces, sizeof(replaces) - 1);
00655       if (len != -1) {
00656          /* pjsip_hdr_print_on does not NULL terminate the buffer */
00657          replaces[len] = '\0';
00658          replaces_val = replaces + sizeof("Replaces:");
00659       }
00660       pbx_builtin_setvar_helper(chan, "__SIPREPLACESHDR", replaces_val);
00661    } else {
00662       pbx_builtin_setvar_helper(chan, "SIPREPLACESHDR", NULL);
00663    }
00664 
00665    if (refer->refer_to) {
00666       char refer_to[PJSIP_MAX_URL_SIZE];
00667 
00668       pjsip_uri_print(PJSIP_URI_IN_REQ_URI, refer->refer_to, refer_to, sizeof(refer_to));
00669       pbx_builtin_setvar_helper(chan, "SIPREFERTOHDR", S_OR(refer_to, NULL));
00670    } else {
00671       pbx_builtin_setvar_helper(chan, "SIPREFERTOHDR", NULL);
00672    }
00673 }
00674 
00675 /*!
00676  * \internal
00677  * \brief Set the passed in context variable to the determined transfer context.
00678  * \since 13.3.0
00679  *
00680  * \param context Set to the determined transfer context.
00681  * \param session INVITE dialog SIP session.
00682  */
00683 #define DETERMINE_TRANSFER_CONTEXT(context, session)                          \
00684    do {                                                           \
00685       ast_channel_lock((session)->channel);                                \
00686       context = pbx_builtin_getvar_helper((session)->channel, "TRANSFER_CONTEXT");  \
00687       if (ast_strlen_zero(context)) {                                      \
00688          context = (session)->endpoint->context;                              \
00689       } else {                                                    \
00690          context = ast_strdupa(context);                                   \
00691       }                                                           \
00692       ast_channel_unlock((session)->channel);                                 \
00693    } while (0)                                                       \
00694 
00695 static int refer_incoming_attended_request(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_sip_uri *target_uri,
00696    pjsip_param *replaces_param, struct refer_progress *progress)
00697 {
00698    const pj_str_t str_replaces = { "Replaces", 8 };
00699    pj_str_t replaces_content;
00700    pjsip_replaces_hdr *replaces;
00701    int parsed_len;
00702    pjsip_dialog *dlg;
00703 
00704    pj_strdup_with_null(rdata->tp_info.pool, &replaces_content, &replaces_param->value);
00705 
00706    /* Parsing the parameter as a Replaces header easily grabs the needed information */
00707    if (!(replaces = pjsip_parse_hdr(rdata->tp_info.pool, &str_replaces, replaces_content.ptr,
00708       pj_strlen(&replaces_content), &parsed_len))) {
00709       ast_log(LOG_ERROR, "Received REFER request on channel '%s' from endpoint '%s' with invalid Replaces header, rejecting\n",
00710          ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
00711       return 400;
00712    }
00713 
00714    /* See if the dialog is local, or remote */
00715    if ((dlg = pjsip_ua_find_dialog(&replaces->call_id, &replaces->to_tag, &replaces->from_tag, PJ_TRUE))) {
00716       RAII_VAR(struct ast_sip_session *, other_session, ast_sip_dialog_get_session(dlg), ao2_cleanup);
00717       struct refer_attended *attended;
00718 
00719       pjsip_dlg_dec_lock(dlg);
00720 
00721       if (!other_session) {
00722          ast_debug(3, "Received REFER request on channel '%s' from endpoint '%s' for local dialog but no session exists on it\n",
00723             ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
00724          return 603;
00725       }
00726 
00727       /* We defer actually doing the attended transfer to the other session so no deadlock can occur */
00728       if (!(attended = refer_attended_alloc(session, other_session, progress))) {
00729          ast_log(LOG_ERROR, "Received REFER request on channel '%s' from endpoint '%s' for local dialog but could not allocate structure to complete, rejecting\n",
00730             ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
00731          return 500;
00732       }
00733 
00734       if (ast_sip_session_defer_termination(session)) {
00735          ast_log(LOG_ERROR, "Received REFER request on channel '%s' from endpoint '%s' for local dialog but could not defer termination, rejecting\n",
00736             ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
00737          ao2_cleanup(attended);
00738          return 500;
00739       }
00740 
00741       /* Push it to the other session, which will have both channels with minimal locking */
00742       if (ast_sip_push_task(other_session->serializer, refer_attended_task, attended)) {
00743          ast_sip_session_defer_termination_cancel(session);
00744          ao2_cleanup(attended);
00745          return 500;
00746       }
00747 
00748       ast_debug(3, "Attended transfer from '%s' pushed to second channel serializer\n",
00749          ast_channel_name(session->channel));
00750 
00751       return 200;
00752    } else {
00753       const char *context;
00754       struct refer_blind refer = { 0, };
00755       int response;
00756 
00757       DETERMINE_TRANSFER_CONTEXT(context, session);
00758 
00759       if (!ast_exists_extension(NULL, context, "external_replaces", 1, NULL)) {
00760          ast_log(LOG_ERROR, "Received REFER for remote session on channel '%s' from endpoint '%s' but 'external_replaces' extension not found in context %s\n",
00761             ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint), context);
00762          return 404;
00763       }
00764 
00765       refer.context = context;
00766       refer.progress = progress;
00767       refer.rdata = rdata;
00768       refer.replaces = replaces;
00769       refer.refer_to = target_uri;
00770 
00771       if (ast_sip_session_defer_termination(session)) {
00772          ast_log(LOG_ERROR, "Received REFER for remote session on channel '%s' from endpoint '%s' but could not defer termination, rejecting\n",
00773             ast_channel_name(session->channel),
00774             ast_sorcery_object_get_id(session->endpoint));
00775          return 500;
00776       }
00777 
00778       response = xfer_response_code2sip(ast_bridge_transfer_blind(1, session->channel,
00779          "external_replaces", context, refer_blind_callback, &refer));
00780       if (response != 200) {
00781          ast_sip_session_defer_termination_cancel(session);
00782       }
00783       return response;
00784    }
00785 }
00786 
00787 static int refer_incoming_blind_request(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_sip_uri *target,
00788    struct refer_progress *progress)
00789 {
00790    const char *context;
00791    char exten[AST_MAX_EXTENSION];
00792    struct refer_blind refer = { 0, };
00793    int response;
00794 
00795    /* If no explicit transfer context has been provided use their configured context */
00796    DETERMINE_TRANSFER_CONTEXT(context, session);
00797 
00798    /* Using the user portion of the target URI see if it exists as a valid extension in their context */
00799    ast_copy_pj_str(exten, &target->user, sizeof(exten));
00800    if (!ast_exists_extension(NULL, context, exten, 1, NULL)) {
00801       ast_log(LOG_ERROR, "Channel '%s' from endpoint '%s' attempted blind transfer to '%s@%s' but target does not exist\n",
00802          ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint), exten, context);
00803       return 404;
00804    }
00805 
00806    refer.context = context;
00807    refer.progress = progress;
00808    refer.rdata = rdata;
00809    refer.refer_to = target;
00810 
00811    if (ast_sip_session_defer_termination(session)) {
00812       ast_log(LOG_ERROR, "Channel '%s' from endpoint '%s' attempted blind transfer but could not defer termination, rejecting\n",
00813          ast_channel_name(session->channel),
00814          ast_sorcery_object_get_id(session->endpoint));
00815       return 500;
00816    }
00817 
00818    response = xfer_response_code2sip(ast_bridge_transfer_blind(1, session->channel,
00819       exten, context, refer_blind_callback, &refer));
00820    if (response != 200) {
00821       ast_sip_session_defer_termination_cancel(session);
00822    }
00823    return response;
00824 }
00825 
00826 /*! \brief Structure used to retrieve channel from another session */
00827 struct invite_replaces {
00828    /*! \brief Session we want the channel from */
00829    struct ast_sip_session *session;
00830    /*! \brief Channel from the session (with reference) */
00831    struct ast_channel *channel;
00832    /*! \brief Bridge the channel is in */
00833    struct ast_bridge *bridge;
00834 };
00835 
00836 /*! \brief Task for invite replaces */
00837 static int invite_replaces(void *data)
00838 {
00839    struct invite_replaces *invite = data;
00840 
00841    if (!invite->session->channel) {
00842       return -1;
00843    }
00844 
00845    ast_channel_ref(invite->session->channel);
00846    invite->channel = invite->session->channel;
00847 
00848    ast_channel_lock(invite->channel);
00849    invite->bridge = ast_channel_get_bridge(invite->channel);
00850    ast_channel_unlock(invite->channel);
00851 
00852    return 0;
00853 }
00854 
00855 static int refer_incoming_invite_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
00856 {
00857    pjsip_dialog *other_dlg = NULL;
00858    pjsip_tx_data *packet;
00859    int response = 0;
00860    RAII_VAR(struct ast_sip_session *, other_session, NULL, ao2_cleanup);
00861    struct invite_replaces invite;
00862 
00863    /* If a Replaces header is present make sure it is valid */
00864    if (pjsip_replaces_verify_request(rdata, &other_dlg, PJ_TRUE, &packet) != PJ_SUCCESS) {
00865       response = packet->msg->line.status.code;
00866       ast_assert(response != 0);
00867       pjsip_tx_data_dec_ref(packet);
00868       goto inv_replace_failed;
00869    }
00870 
00871    /* If no other dialog exists then this INVITE request does not have a Replaces header */
00872    if (!other_dlg) {
00873       return 0;
00874    }
00875 
00876    other_session = ast_sip_dialog_get_session(other_dlg);
00877    pjsip_dlg_dec_lock(other_dlg);
00878 
00879    /* Don't accept an in-dialog INVITE with Replaces as it does not make much sense */
00880    if (session->inv_session->dlg->state == PJSIP_DIALOG_STATE_ESTABLISHED) {
00881       response = 488;
00882       goto inv_replace_failed;
00883    }
00884 
00885    if (!other_session) {
00886       ast_debug(3, "INVITE with Replaces received on channel '%s' from endpoint '%s', but requested session does not exist\n",
00887          ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
00888       response = 481;
00889       goto inv_replace_failed;
00890    }
00891 
00892    invite.session = other_session;
00893 
00894    if (ast_sip_push_task_synchronous(other_session->serializer, invite_replaces, &invite)) {
00895       response = 481;
00896       goto inv_replace_failed;
00897    }
00898 
00899    ast_channel_lock(session->channel);
00900    ast_setstate(session->channel, AST_STATE_RING);
00901    ast_channel_unlock(session->channel);
00902    ast_raw_answer(session->channel);
00903 
00904    ast_debug(3, "INVITE with Replaces being attempted.  '%s' --> '%s'\n",
00905       ast_channel_name(session->channel), ast_channel_name(invite.channel));
00906 
00907    if (!invite.bridge) {
00908       struct ast_channel *chan = session->channel;
00909 
00910       /*
00911        * This will use a synchronous task but we aren't operating in
00912        * the serializer at this point in time, so it won't deadlock.
00913        */
00914       if (!ast_channel_move(invite.channel, chan)) {
00915          /*
00916           * We can't directly use session->channel because ast_channel_move()
00917           * does a masquerade which changes session->channel to a different
00918           * channel.  To ensure we work on the right channel we store a
00919           * pointer locally before we begin so it remains valid.
00920           */
00921          ast_hangup(chan);
00922       } else {
00923          response = AST_CAUSE_FAILURE;
00924       }
00925    } else {
00926       if (ast_bridge_impart(invite.bridge, session->channel, invite.channel, NULL,
00927          AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
00928          response = AST_CAUSE_FAILURE;
00929       }
00930    }
00931 
00932    ast_channel_unref(invite.channel);
00933    ao2_cleanup(invite.bridge);
00934 
00935    if (!response) {
00936       /*
00937        * On success we cannot use session->channel in the debug message.
00938        * This thread either no longer has a ref to session->channel or
00939        * session->channel is no longer the original channel.
00940        */
00941       ast_debug(3, "INVITE with Replaces successfully completed.\n");
00942    } else {
00943       ast_debug(3, "INVITE with Replaces failed on channel '%s', hanging up with cause '%d'\n",
00944          ast_channel_name(session->channel), response);
00945       ast_channel_lock(session->channel);
00946       ast_channel_hangupcause_set(session->channel, response);
00947       ast_channel_unlock(session->channel);
00948       ast_hangup(session->channel);
00949    }
00950 
00951    return 1;
00952 
00953 inv_replace_failed:
00954    if (session->inv_session->dlg->state != PJSIP_DIALOG_STATE_ESTABLISHED) {
00955       ast_debug(3, "INVITE with Replaces failed on channel '%s', sending response of '%d'\n",
00956          ast_channel_name(session->channel), response);
00957       session->defer_terminate = 1;
00958       ast_hangup(session->channel);
00959 
00960       if (pjsip_inv_end_session(session->inv_session, response, NULL, &packet) == PJ_SUCCESS) {
00961          ast_sip_session_send_response(session, packet);
00962       }
00963    } else {
00964       ast_debug(3, "INVITE with Replaces in-dialog on channel '%s', hanging up\n",
00965          ast_channel_name(session->channel));
00966       ast_queue_hangup(session->channel);
00967    }
00968 
00969    return 1;
00970 }
00971 
00972 static int refer_incoming_refer_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
00973 {
00974    pjsip_generic_string_hdr *refer_to;
00975    char *uri;
00976    pjsip_uri *target;
00977    pjsip_sip_uri *target_uri;
00978    RAII_VAR(struct refer_progress *, progress, NULL, ao2_cleanup);
00979    pjsip_param *replaces;
00980    int response;
00981 
00982    static const pj_str_t str_refer_to = { "Refer-To", 8 };
00983    static const pj_str_t str_replaces = { "Replaces", 8 };
00984 
00985    if (!session->channel) {
00986       /* No channel to refer.  Likely because the call was just hung up. */
00987       pjsip_dlg_respond(session->inv_session->dlg, rdata, 404, NULL, NULL, NULL);
00988       ast_debug(3, "Received a REFER on a session with no channel from endpoint '%s'.\n",
00989          ast_sorcery_object_get_id(session->endpoint));
00990       return 0;
00991    }
00992 
00993    if (!session->endpoint->allowtransfer) {
00994       pjsip_dlg_respond(session->inv_session->dlg, rdata, 603, NULL, NULL, NULL);
00995       ast_log(LOG_WARNING, "Endpoint %s transfer attempt blocked due to configuration\n",
00996             ast_sorcery_object_get_id(session->endpoint));
00997       return 0;
00998    }
00999 
01000    /* A Refer-To header is required */
01001    refer_to = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_to, NULL);
01002    if (!refer_to) {
01003       pjsip_dlg_respond(session->inv_session->dlg, rdata, 400, NULL, NULL, NULL);
01004       ast_debug(3, "Received a REFER without Refer-To on channel '%s' from endpoint '%s'\n",
01005          ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
01006       return 0;
01007    }
01008 
01009    /* This is done on purpose (and is safe) - it's done so that the value passed to
01010     * pjsip_parse_uri is NULL terminated as required
01011     */
01012    uri = refer_to->hvalue.ptr;
01013    uri[refer_to->hvalue.slen] = '\0';
01014 
01015    target = pjsip_parse_uri(rdata->tp_info.pool, refer_to->hvalue.ptr, refer_to->hvalue.slen, 0);
01016    if (!target
01017       || (!PJSIP_URI_SCHEME_IS_SIP(target)
01018          && !PJSIP_URI_SCHEME_IS_SIPS(target))) {
01019       size_t uri_size = pj_strlen(&refer_to->hvalue) + 1;
01020       char *uri = ast_alloca(uri_size);
01021 
01022       ast_copy_pj_str(uri, &refer_to->hvalue, uri_size);
01023 
01024       pjsip_dlg_respond(session->inv_session->dlg, rdata, 400, NULL, NULL, NULL);
01025       ast_debug(3, "Received a REFER without a parseable Refer-To ('%s') on channel '%s' from endpoint '%s'\n",
01026          uri, ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
01027       return 0;
01028    }
01029    target_uri = pjsip_uri_get_uri(target);
01030 
01031    /* Set up REFER progress subscription if requested/possible */
01032    if (refer_progress_alloc(session, rdata, &progress)) {
01033       pjsip_dlg_respond(session->inv_session->dlg, rdata, 500, NULL, NULL, NULL);
01034       ast_debug(3, "Could not set up subscription for REFER on channel '%s' from endpoint '%s'\n",
01035          ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
01036       return 0;
01037    }
01038 
01039    /* Determine if this is an attended or blind transfer */
01040    if ((replaces = pjsip_param_find(&target_uri->header_param, &str_replaces)) ||
01041       (replaces = pjsip_param_find(&target_uri->other_param, &str_replaces))) {
01042       response = refer_incoming_attended_request(session, rdata, target_uri, replaces, progress);
01043    } else {
01044       response = refer_incoming_blind_request(session, rdata, target_uri, progress);
01045    }
01046 
01047    if (!progress) {
01048       /* The transferer has requested no subscription, so send a final response immediately */
01049       pjsip_tx_data *tdata;
01050       const pj_str_t str_refer_sub = { "Refer-Sub", 9 };
01051       const pj_str_t str_false = { "false", 5 };
01052       pjsip_hdr *hdr;
01053 
01054       ast_debug(3, "Progress monitoring not requested for REFER on channel '%s' from endpoint '%s', sending immediate response of '%d'\n",
01055          ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint), response);
01056 
01057       if (pjsip_dlg_create_response(session->inv_session->dlg, rdata, response, NULL, &tdata) != PJ_SUCCESS) {
01058          pjsip_dlg_respond(session->inv_session->dlg, rdata, response, NULL, NULL, NULL);
01059          return 0;
01060       }
01061 
01062       hdr = (pjsip_hdr*)pjsip_generic_string_hdr_create(tdata->pool, &str_refer_sub, &str_false);
01063       pjsip_msg_add_hdr(tdata->msg, hdr);
01064 
01065       pjsip_dlg_send_response(session->inv_session->dlg, pjsip_rdata_get_tsx(rdata), tdata);
01066    } else if (response != 200) {
01067       /* Since this failed we can send a final NOTIFY now and terminate the subscription */
01068       struct refer_progress_notification *notification = refer_progress_notification_alloc(progress, response, PJSIP_EVSUB_STATE_TERMINATED);
01069 
01070       if (notification) {
01071          /* The refer_progress_notify function will call ao2_cleanup on this for us */
01072          refer_progress_notify(notification);
01073       }
01074    }
01075 
01076    return 0;
01077 }
01078 
01079 static int refer_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
01080 {
01081    if (!pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, pjsip_get_refer_method())) {
01082       return refer_incoming_refer_request(session, rdata);
01083    } else if (!pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_invite_method)) {
01084       return refer_incoming_invite_request(session, rdata);
01085    } else {
01086       return 0;
01087    }
01088 }
01089 
01090 static void refer_outgoing_request(struct ast_sip_session *session, struct pjsip_tx_data *tdata)
01091 {
01092    const char *hdr;
01093 
01094    if (pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_invite_method)
01095       || !session->channel
01096       || session->inv_session->state != PJSIP_INV_STATE_NULL) {
01097       return;
01098    }
01099 
01100    ast_channel_lock(session->channel);
01101    hdr = pbx_builtin_getvar_helper(session->channel, "SIPREPLACESHDR");
01102    if (!ast_strlen_zero(hdr)) {
01103       ast_sip_add_header(tdata, "Replaces", hdr);
01104    }
01105 
01106    hdr = pbx_builtin_getvar_helper(session->channel, "SIPREFERREDBYHDR");
01107    if (!ast_strlen_zero(hdr)) {
01108       ast_sip_add_header(tdata, "Referred-By", hdr);
01109    }
01110    ast_channel_unlock(session->channel);
01111 }
01112 
01113 static struct ast_sip_session_supplement refer_supplement = {
01114    .priority = AST_SIP_SUPPLEMENT_PRIORITY_CHANNEL + 1,
01115    .incoming_request = refer_incoming_request,
01116    .outgoing_request = refer_outgoing_request,
01117 };
01118 
01119 static int load_module(void)
01120 {
01121    const pj_str_t str_norefersub = { "norefersub", 10 };
01122 
01123    CHECK_PJSIP_SESSION_MODULE_LOADED();
01124 
01125    pjsip_replaces_init_module(ast_sip_get_pjsip_endpoint());
01126    pjsip_xfer_init_module(ast_sip_get_pjsip_endpoint());
01127    pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), NULL, PJSIP_H_SUPPORTED, NULL, 1, &str_norefersub);
01128 
01129    ast_sip_register_service(&refer_progress_module);
01130    ast_sip_session_register_supplement(&refer_supplement);
01131 
01132    return AST_MODULE_LOAD_SUCCESS;
01133 }
01134 
01135 static int unload_module(void)
01136 {
01137    ast_sip_session_unregister_supplement(&refer_supplement);
01138    ast_sip_unregister_service(&refer_progress_module);
01139 
01140    return 0;
01141 }
01142 
01143 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Blind and Attended Transfer Support",
01144       .support_level = AST_MODULE_SUPPORT_CORE,
01145       .load = load_module,
01146       .unload = unload_module,
01147       .load_pri = AST_MODPRI_APP_DEPEND,
01148          );

Generated on Thu Apr 16 06:27:50 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6