jcallback.c
来自「mediastreamer2是开源的网络传输媒体流的库」· C语言 代码 · 共 2,026 行 · 第 1/5 页
C
2,026 行
else if (jd != NULL && MSG_IS_RESPONSE_FOR (sip, "SUBSCRIBE")) { eXosip_event_t *je; je = eXosip_event_init_for_subscribe (EXOSIP_SUBSCRIPTION_PROCEEDING, js, jd, tr); report_event (je, sip); }#endif if (MSG_TEST_CODE (sip, 180) && jd != NULL) { jd->d_STATE = JD_RINGING; } else if (MSG_TEST_CODE (sip, 183) && jd != NULL) { jd->d_STATE = JD_QUEUED; } }}static voidcb_rcv2xx_4invite (osip_transaction_t * tr, osip_message_t * sip){ int i; eXosip_dialog_t *jd; eXosip_call_t *jc; jinfo_t *jinfo = (jinfo_t *) osip_transaction_get_your_instance (tr); if (jinfo == NULL) return; jd = jinfo->jd; jc = jinfo->jc; if (jd == NULL) /* This transaction initiate a dialog in the case of INVITE (else it would be attached to a "jd" element. */ { /* allocate a jd */ i = eXosip_dialog_init_as_uac (&jd, sip); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot establish a dialog\n")); return; } ADD_ELEMENT (jc->c_dialogs, jd); jinfo->jd = jd; eXosip_update (); osip_transaction_set_your_instance (tr, jinfo); } else { /* Here is a special case: We have initiated a dialog and we have received informationnal answers from 2 or more remote SIP UA. Those answer can be differentiated with the "To" header's tag. We have used the first informationnal answer to create a dialog, but we now want to be sure the 200ok received is for the dialog this dialog. We have to check the To tag and if it does not match, we just have to modify the existing dialog and replace it. */ osip_generic_param_t *tag; int i; i = osip_to_get_tag (sip->to, &tag); i = 1; /* default is the same dialog */ if (jd->d_dialog == NULL || jd->d_dialog->remote_tag == NULL) { /* There are real use-case where a BYE is received/processed before the 200ok of the previous INVITE. In this case, jd->d_dialog is empty and the transaction should be silently discarded. */ /* a ACK should still be sent... -but there is no dialog built- */ return; } if (jd->d_dialog->remote_tag == NULL && tag == NULL) { } /* non compliant remote UA -> assume it is the same dialog */ else if (jd->d_dialog->remote_tag != NULL && tag == NULL) { i = 0; } /* different dialog! */ else if (jd->d_dialog->remote_tag == NULL && tag != NULL) { i = 0; } /* different dialog! */ else if (jd->d_dialog->remote_tag != NULL && tag != NULL && tag->gvalue != NULL && 0 != strcmp (jd->d_dialog->remote_tag, tag->gvalue)) { i = 0; } /* different dialog! */ if (i == 1) /* just update the dialog */ { osip_dialog_update_route_set_as_uac (jd->d_dialog, sip); if (jd->d_dialog->remote_tag == NULL) osip_dialog_update_tag_as_uac (jd->d_dialog, sip); osip_dialog_set_state (jd->d_dialog, DIALOG_CONFIRMED); } else { /* the best thing is to replace the current dialog information... Much easier than creating a useless dialog! */ osip_dialog_free (jd->d_dialog); i = osip_dialog_init_as_uac (&(jd->d_dialog), sip); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Cannot replace the dialog.\r\n")); } else { jd->d_dialog->local_cseq = jd->d_dialog->local_cseq + jd->d_mincseq; jd->d_mincseq = 0; OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "The dialog has been replaced with the new one from 200ok.\r\n")); } } } jd->d_STATE = JD_ESTABLISHED; /* eXosip_dialog_set_200ok (jd, sip); */ report_call_event (EXOSIP_CALL_ANSWERED, jc, jd, tr); /* look for the SDP information and decide if this answer was for an initial INVITE, an HoldCall, or a RetreiveCall */ /* don't handle hold/unhold by now... */ /* eXosip_update_audio_session(tr); */}#ifndef MINISIZEstatic voidcb_rcv2xx_4subscribe (osip_transaction_t * tr, osip_message_t * sip){ int i; eXosip_dialog_t *jd; eXosip_subscribe_t *js; jinfo_t *jinfo = (jinfo_t *) osip_transaction_get_your_instance (tr); if (jinfo == NULL) return; jd = jinfo->jd; js = jinfo->js; _eXosip_subscribe_set_refresh_interval (js, sip); /* for SUBSCRIBE, test if the dialog has been already created with a previous NOTIFY */ if (jd == NULL && js != NULL && js->s_dialogs != NULL && MSG_IS_RESPONSE_FOR (sip, "SUBSCRIBE")) { /* find if existing dialog match the to tag */ osip_generic_param_t *tag; int i; i = osip_to_get_tag (sip->to, &tag); if (i == 0 && tag != NULL && tag->gvalue != NULL) { for (jd = js->s_dialogs; jd != NULL; jd = jd->next) { if (0 == strcmp (jd->d_dialog->remote_tag, tag->gvalue)) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "eXosip: found established early dialog for this subscribe\n")); jinfo->jd = jd; break; } } } } if (jd == NULL) /* This transaction initiate a dialog in the case of SUBSCRIBE (else it would be attached to a "jd" element. */ { /* allocate a jd */ i = eXosip_dialog_init_as_uac (&jd, sip); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot establish a dialog\n")); return; } ADD_ELEMENT (js->s_dialogs, jd); jinfo->jd = jd; eXosip_update (); osip_transaction_set_your_instance (tr, jinfo); } else { osip_dialog_update_route_set_as_uac (jd->d_dialog, sip); if (jd->d_dialog->remote_tag == NULL) osip_dialog_update_tag_as_uac (jd->d_dialog, sip); osip_dialog_set_state (jd->d_dialog, DIALOG_CONFIRMED); } jd->d_STATE = JD_ESTABLISHED; /* look for the body information */ { eXosip_event_t *je; je = eXosip_event_init_for_subscribe (EXOSIP_SUBSCRIPTION_ANSWERED, js, jd, tr); report_event (je, sip); }}#endifstatic int_eXosip_update_expires_according_to_contact (eXosip_reg_t * jreg, osip_transaction_t * tr, osip_message_t * sip){ osip_contact_t *co_register; int pos; if (jreg == NULL) return OSIP_BADPARAMETER; /* only update if only one Contact was in INVITE */ if (tr->orig_request == NULL) return OSIP_BADPARAMETER; if (osip_list_size (&tr->orig_request->contacts) != 1) return OSIP_SUCCESS; /* search for matching contact (line parameter must be equal) */ pos = 0; co_register = (osip_contact_t *) osip_list_get (&sip->contacts, pos); while (co_register != NULL) { osip_uri_param_t *line_param = NULL; if (co_register->url != NULL) osip_uri_uparam_get_byname (co_register->url, "line", &line_param); if (line_param != NULL && line_param->gvalue != NULL) { if (osip_strcasecmp (jreg->r_line, line_param->gvalue) == 0) { /* found contact */ int val; osip_generic_param_t *exp_param = NULL; osip_contact_param_get_byname (co_register, "expires", &exp_param); if (exp_param != NULL && exp_param->gvalue != NULL) { val = atoi (exp_param->gvalue); /* update only if expires value has REALLY be decreased (more than one minutes): In many cases value is decreased because a few seconds has elapsed when server send the 200ok. */ if (val < jreg->r_reg_period - 60) { jreg->r_reg_period = val + 60; return OSIP_SUCCESS; } } return OSIP_SUCCESS; } } pos++; co_register = (osip_contact_t *) osip_list_get (&sip->contacts, pos); } return OSIP_NOTFOUND;}static voidcb_rcv2xx (int type, osip_transaction_t * tr, osip_message_t * sip){ eXosip_dialog_t *jd; eXosip_call_t *jc;#ifndef MINISIZE eXosip_subscribe_t *js; eXosip_notify_t *jn;#endif jinfo_t *jinfo = (jinfo_t *) osip_transaction_get_your_instance (tr); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_rcv2xx (id=%i)\r\n", tr->transactionid)); udp_tl_learn_port_from_via (sip);#ifndef MINISIZE if (MSG_IS_RESPONSE_FOR (sip, "PUBLISH")) { eXosip_pub_t *pub = NULL; eXosip_event_t *je; int i; i = _eXosip_pub_update (&pub, tr, sip); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "cb_rcv2xx (id=%i) No publication to update\r\n", tr->transactionid)); } if (pub != NULL) { /* update registration interval */ osip_header_t *exp; osip_message_header_get_byname (sip, "expires", 0, &exp); if (exp != NULL && exp->hvalue != NULL) { int val = atoi (exp->hvalue); if (val > 0) { /* update only if expires value has REALLY be decreased (more than one minutes): In many cases value is decreased because a few seconds has elapsed when server send the 200ok. */ if (val < pub->p_period - 60) { pub->p_period = val + 60; } } } pub->p_retry = 0; /* reset value */ } je = eXosip_event_init_for_message (EXOSIP_MESSAGE_ANSWERED, tr); report_event (je, sip); return; } else#endif if (MSG_IS_RESPONSE_FOR (sip, "REGISTER")) { eXosip_event_t *je; eXosip_reg_t *jreg = NULL; /* find matching j_reg */ _eXosip_reg_find (&jreg, tr); if (jreg != NULL) { /* update registration interval */ osip_header_t *exp; osip_message_header_get_byname (sip, "expires", 0, &exp); if (exp != NULL && exp->hvalue != NULL) { int val = atoi (exp->hvalue); if (val > 0) { /* update only if expires value has REALLY be decreased (more than one minutes): In many cases value is decreased because a few seconds has elapsed when server send the 200ok. */ if (val < jreg->r_reg_period - 60) { jreg->r_reg_period = val + 60; } } } _eXosip_update_expires_according_to_contact (jreg, tr, sip); je = eXosip_event_init_for_reg (EXOSIP_REGISTRATION_SUCCESS, jreg, tr); report_event (je, sip); jreg->r_retry = 0; /* reset value */ } return; } if (jinfo == NULL) return; jd = jinfo->jd; jc = jinfo->jc;#ifndef MINISIZE jn = jinfo->jn; js = jinfo->js;#endif if (jd != NULL) jd->d_retry = 0; /* reset marker for authentication */ if (jc != NULL) jc->c_retry = 0; /* reset marker for authentication */#ifndef MINISIZE if (js != NULL) js->s_retry = 0; /* reset marker for authentication */#endif if (MSG_IS_RESPONSE_FOR (sip, "INVITE")) { cb_rcv2xx_4invite (tr, sip); } else if (MSG_IS_RESPONSE_FOR (sip, "BYE")) { if (jd != NULL) jd->d_STATE = JD_TERMINATED; report_call_event (EXOSIP_CALL_MESSAGE_ANSWERED, jc, jd, tr); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?