Changeset 167 for pjproject/trunk/pjsip/src/pjsua/pjsua_core.c
- Timestamp:
- Feb 9, 2006 9:30:09 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua/pjsua_core.c
r163 r167 19 19 #include "pjsua.h" 20 20 21 22 #define THIS_FILE "pjsua.c" 23 21 /* 22 * pjsua_core.c 23 * 24 * Core application functionalities. 25 */ 26 27 #define THIS_FILE "pjsua_core.c" 28 29 30 /* 31 * Global variable. 32 */ 24 33 struct pjsua pjsua; 25 34 35 26 36 /* 27 * Default local URI, if no tspecified in cmd-line37 * Default local URI, if none is specified in cmd-line 28 38 */ 29 39 #define PJSUA_LOCAL_URI "<sip:user@127.0.0.1>" … … 93 103 static pj_bool_t mod_pjsua_on_rx_request(pjsip_rx_data *rdata) 94 104 { 95 pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata); 96 pjsip_transaction *tsx = pjsip_rdata_get_tsx(rdata); 97 pjsip_msg *msg = rdata->msg_info.msg; 98 99 /* 100 * Handle incoming INVITE outside dialog. 101 */ 102 if (dlg == NULL && tsx == NULL && 103 msg->line.req.method.id == PJSIP_INVITE_METHOD) 104 { 105 pj_status_t status; 106 pjsip_tx_data *response = NULL; 107 unsigned options = 0; 108 109 /* Verify that we can handle the request. */ 110 status = pjsip_inv_verify_request(rdata, &options, NULL, NULL, 111 pjsua.endpt, &response); 112 if (status != PJ_SUCCESS) { 113 114 /* 115 * No we can't handle the incoming INVITE request. 116 */ 117 118 if (response) { 119 pjsip_response_addr res_addr; 120 121 pjsip_get_response_addr(response->pool, rdata, &res_addr); 122 pjsip_endpt_send_response(pjsua.endpt, &res_addr, response, 123 NULL, NULL); 124 125 } else { 126 127 /* Respond with 500 (Internal Server Error) */ 128 pjsip_endpt_respond_stateless(pjsua.endpt, rdata, 500, NULL, 129 NULL, NULL); 130 } 131 132 } else { 133 /* 134 * Yes we can handle the incoming INVITE request. 135 */ 136 pjsip_inv_session *inv; 137 struct pjsua_inv_data *inv_data; 138 pjmedia_sdp_session *answer; 139 140 141 /* Get media capability from media endpoint: */ 142 143 status = pjmedia_endpt_create_sdp( pjsua.med_endpt, rdata->tp_info.pool, 144 1, &pjsua.med_skinfo, &answer ); 145 if (status != PJ_SUCCESS) { 146 147 pjsip_endpt_respond_stateless(pjsua.endpt, rdata, 500, NULL, 148 NULL, NULL); 149 return PJ_TRUE; 150 } 151 152 /* Create dialog: */ 153 154 status = pjsip_dlg_create_uas( pjsip_ua_instance(), rdata, 155 &pjsua.contact_uri, &dlg); 156 if (status != PJ_SUCCESS) 157 return PJ_TRUE; 158 159 160 /* Create invite session: */ 161 162 status = pjsip_inv_create_uas( dlg, rdata, answer, 0, &inv); 163 if (status != PJ_SUCCESS) { 164 165 status = pjsip_dlg_create_response( dlg, rdata, 500, NULL, 166 &response); 167 if (status == PJ_SUCCESS) 168 status = pjsip_dlg_send_response(dlg, 169 pjsip_rdata_get_tsx(rdata), 170 response); 171 return PJ_TRUE; 172 173 } 174 175 176 /* Create and attach pjsua data to the dialog: */ 177 178 inv_data = pj_pool_zalloc(dlg->pool, sizeof(struct pjsua_inv_data)); 179 dlg->mod_data[pjsua.mod.id] = inv_data; 180 181 182 /* Answer with 100 (using the dialog, not invite): */ 183 184 status = pjsip_dlg_create_response(dlg, rdata, 100, NULL, &response); 185 if (status == PJ_SUCCESS) 186 status = pjsip_dlg_send_response(dlg, pjsip_rdata_get_tsx(rdata), response); 187 } 188 189 /* This INVITE request has been handled. */ 190 return PJ_TRUE; 191 } 192 193 105 106 if (rdata->msg_info.msg->line.req.method.id == PJSIP_INVITE_METHOD) { 107 108 return pjsua_inv_on_incoming(rdata); 109 110 } 194 111 195 112 return PJ_FALSE; … … 214 131 } 215 132 216 217 /*218 * This callback receives notification from invite session when the219 * session state has changed.220 */221 static void pjsua_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e)222 {223 224 /* Destroy media session when invite session is disconnected. */225 if (inv->state == PJSIP_INV_STATE_DISCONNECTED) {226 struct pjsua_inv_data *inv_data;227 228 inv_data = inv->dlg->mod_data[pjsua.mod.id];229 if (inv_data && inv_data->session) {230 pjmedia_session_destroy(inv_data->session);231 inv_data->session = NULL;232 233 PJ_LOG(3,(THIS_FILE,"Media session is destroyed"));234 }235 236 }237 238 pjsua_ui_inv_on_state_changed(inv, e);239 }240 241 242 /*243 * This callback is called by invite session framework when UAC session244 * has forked.245 */246 static void pjsua_inv_on_new_session(pjsip_inv_session *inv, pjsip_event *e)247 {248 PJ_UNUSED_ARG(inv);249 PJ_UNUSED_ARG(e);250 251 PJ_TODO(HANDLE_FORKED_DIALOG);252 }253 254 /*255 *256 */257 static void pjsua_inv_on_media_update(pjsip_inv_session *inv,258 pj_status_t status)259 {260 struct pjsua_inv_data *inv_data;261 const pjmedia_sdp_session *local_sdp;262 const pjmedia_sdp_session *remote_sdp;263 264 if (status != PJ_SUCCESS) {265 266 pjsua_perror("SDP negotiation has failed", status);267 return;268 269 }270 271 /* Destroy existing media session, if any. */272 273 inv_data = inv->dlg->mod_data[pjsua.mod.id];274 if (inv_data && inv_data->session) {275 pjmedia_session_destroy(inv_data->session);276 inv_data->session = NULL;277 }278 279 /* Get local and remote SDP */280 281 status = pjmedia_sdp_neg_get_active_local(inv->neg, &local_sdp);282 if (status != PJ_SUCCESS) {283 pjsua_perror("Unable to retrieve currently active local SDP", status);284 return;285 }286 287 288 status = pjmedia_sdp_neg_get_active_remote(inv->neg, &remote_sdp);289 if (status != PJ_SUCCESS) {290 pjsua_perror("Unable to retrieve currently active remote SDP", status);291 return;292 }293 294 295 /* Create new media session.296 * The media session is active immediately.297 */298 299 status = pjmedia_session_create( pjsua.med_endpt, 1, &pjsua.med_skinfo,300 local_sdp, remote_sdp, &inv_data->session );301 if (status != PJ_SUCCESS) {302 pjsua_perror("Unable to create media session", status);303 return;304 }305 306 PJ_LOG(3,(THIS_FILE,"Media has been started successfully"));307 }308 133 309 134 /* … … 846 671 847 672 /* Destroy endpoint. */ 673 848 674 pjsip_endpt_destroy(pjsua.endpt); 849 675 pjsua.endpt = NULL; 850 676 851 677 /* Destroy caching pool. */ 678 852 679 pj_caching_pool_destroy(&pjsua.cp); 853 680 … … 858 685 } 859 686 860 861 /**862 * Make outgoing call.863 */864 pj_status_t pjsua_invite(const char *cstr_dest_uri,865 pjsip_inv_session **p_inv)866 {867 pj_str_t dest_uri;868 pjsip_dialog *dlg;869 pjmedia_sdp_session *offer;870 pjsip_inv_session *inv;871 struct pjsua_inv_data *inv_data;872 pjsip_tx_data *tdata;873 pj_status_t status;874 875 /* Convert cstr_dest_uri to dest_uri */876 877 dest_uri = pj_str((char*)cstr_dest_uri);878 879 /* Create outgoing dialog: */880 881 status = pjsip_dlg_create_uac( pjsip_ua_instance(), &pjsua.local_uri,882 &pjsua.contact_uri, &dest_uri, &dest_uri,883 &dlg);884 if (status != PJ_SUCCESS) {885 pjsua_perror("Dialog creation failed", status);886 return status;887 }888 889 /* Get media capability from media endpoint: */890 891 status = pjmedia_endpt_create_sdp( pjsua.med_endpt, dlg->pool,892 1, &pjsua.med_skinfo, &offer);893 if (status != PJ_SUCCESS) {894 pjsua_perror("pjmedia unable to create SDP", status);895 goto on_error;896 }897 898 /* Create the INVITE session: */899 900 status = pjsip_inv_create_uac( dlg, offer, 0, &inv);901 if (status != PJ_SUCCESS) {902 pjsua_perror("Invite session creation failed", status);903 goto on_error;904 }905 906 907 /* Create and associate our data in the session. */908 909 inv_data = pj_pool_zalloc( dlg->pool, sizeof(struct pjsua_inv_data));910 dlg->mod_data[pjsua.mod.id] = inv_data;911 912 913 /* Set dialog Route-Set: */914 915 if (!pj_list_empty(&pjsua.route_set))916 pjsip_dlg_set_route_set(dlg, &pjsua.route_set);917 918 919 /* Set credentials: */920 921 pjsip_auth_clt_set_credentials( &dlg->auth_sess, pjsua.cred_count,922 pjsua.cred_info);923 924 925 /* Create initial INVITE: */926 927 status = pjsip_inv_invite(inv, &tdata);928 if (status != PJ_SUCCESS) {929 pjsua_perror("Unable to create initial INVITE request", status);930 goto on_error;931 }932 933 934 /* Send initial INVITE: */935 936 status = pjsip_inv_send_msg(inv, tdata, NULL);937 if (status != PJ_SUCCESS) {938 pjsua_perror("Unable to send initial INVITE request", status);939 goto on_error;940 }941 942 943 /* Done. */944 945 *p_inv = inv;946 947 return PJ_SUCCESS;948 949 950 on_error:951 952 PJ_TODO(DESTROY_DIALOG_ON_FAIL);953 return status;954 }955
Note: See TracChangeset
for help on using the changeset viewer.