jcallback.c

来自「libosip2-3版本的osip源代码」· C语言 代码 · 共 2,180 行 · 第 1/5 页

C
2,180
字号
cb_sndunkrequest (int type, osip_transaction_t * tr, osip_message_t * sip){  OSIP_TRACE (osip_trace              (__FILE__, __LINE__, OSIP_INFO3, NULL,               "cb_sndunkrequest (id=%i)\r\n", tr->transactionid));}void__eXosip_delete_jinfo (osip_transaction_t * transaction){  jinfo_t *ji;  if (transaction == NULL)    return;  ji = osip_transaction_get_your_instance (transaction);  osip_free (ji);  osip_transaction_set_your_instance (transaction, NULL);}jinfo_t *__eXosip_new_jinfo (eXosip_call_t * jc, eXosip_dialog_t * jd,                    eXosip_subscribe_t * js, eXosip_notify_t * jn){  jinfo_t *ji = (jinfo_t *) osip_malloc (sizeof (jinfo_t));  if (ji == NULL)    return NULL;  ji->jd = jd;  ji->jc = jc;  ji->js = js;  ji->jn = jn;  return ji;}static void_eXosip_learn_port_from_via(osip_transaction_t * tr, osip_message_t * sip);static void_eXosip_learn_port_from_via(osip_transaction_t * tr, osip_message_t * sip){    /* EXOSIP_OPT_UDP_LEARN_PORT option set */     if (eXosip.learn_port > 0)    {        struct eXosip_net *net;        osip_via_t *via = NULL;        osip_generic_param_t *br;        net = &eXosip.net_interfaces[0];        osip_message_get_via (sip, 0, &via);        if (via != NULL && via->protocol != NULL            && osip_strcasecmp (via->protocol, "udp") == 0)        {            osip_via_param_get_byname (via, "rport", &br);            if (br != NULL && br->gvalue != NULL)            {                snprintf (net->net_port, 20, "%s", br->gvalue);                OSIP_TRACE (osip_trace                            (__FILE__, __LINE__, OSIP_INFO1, NULL,                            "_eXosip_learn_port_from_via (id=%i) SIP port modified from rport in SIP answer\r\n",                            tr->transactionid));            }        }    }    return;}static voidcb_rcv1xx (int type, osip_transaction_t * tr, osip_message_t * sip){  eXosip_dialog_t *jd;  eXosip_call_t *jc;  eXosip_subscribe_t *js;  eXosip_notify_t *jn;  jinfo_t *jinfo = (jinfo_t *) osip_transaction_get_your_instance (tr);  OSIP_TRACE (osip_trace              (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_rcv1xx (id=%i)\r\n",               tr->transactionid));  _eXosip_learn_port_from_via(tr, sip);  if (jinfo == NULL)    return;  jd = jinfo->jd;  jc = jinfo->jc;  jn = jinfo->jn;  js = jinfo->js;  if (MSG_IS_RESPONSE_FOR (sip, "OPTIONS"))    {      if (jc == NULL)        {          eXosip_event_t *je;          OSIP_TRACE (osip_trace                      (__FILE__, __LINE__, OSIP_INFO3, NULL,                       "cb_rcv1xx (id=%i) OPTIONS outside of any call\r\n",                       tr->transactionid));          je = eXosip_event_init_for_message (EXOSIP_MESSAGE_PROCEEDING, tr);          eXosip_event_add (je);          return;        }      report_call_event (EXOSIP_CALL_MESSAGE_PROCEEDING, jc, jd, tr);      return;    }  if (MSG_IS_RESPONSE_FOR (sip, "INVITE") && MSG_TEST_CODE (sip, 100))    {      report_call_event (EXOSIP_CALL_PROCEEDING, jc, jd, tr);    }  if ((MSG_IS_RESPONSE_FOR (sip, "INVITE")       || MSG_IS_RESPONSE_FOR (sip, "SUBSCRIBE")) && !MSG_TEST_CODE (sip, 100))    {      int i;      /* 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                                   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;            }          if (jc != NULL)            {              ADD_ELEMENT (jc->c_dialogs, jd);              jinfo->jd = jd;              eXosip_update ();          } else if (js != NULL)            {              ADD_ELEMENT (js->s_dialogs, jd);              jinfo->jd = jd;              eXosip_update ();          } else if (jn != NULL)            {              ADD_ELEMENT (jn->n_dialogs, jd);              jinfo->jd = jd;              eXosip_update ();          } else            {#ifndef WIN32              assert (0 == 0);#else              exit (0);#endif            }          osip_transaction_set_your_instance (tr, jinfo);      } else        {			if (jd->d_dialog==NULL)			{			}			else if (jd->d_dialog->remote_tag==NULL)			{				osip_dialog_update_route_set_as_uac (jd->d_dialog, sip);				osip_dialog_update_tag_as_uac (jd->d_dialog, sip);			}			else			{				osip_generic_param_t *tag;				int i;				i = osip_to_get_tag (sip->to, &tag);				if (tag != NULL && tag->gvalue != NULL					&& 0 == strcmp (jd->d_dialog->remote_tag, tag->gvalue))				{					/* Update only if it is the same dialog */					osip_dialog_update_route_set_as_uac (jd->d_dialog, sip);				}			}        }      if (jd != NULL)        jd->d_STATE = JD_TRYING;      if (jd != NULL && MSG_IS_RESPONSE_FOR (sip, "INVITE")          && sip->status_code < 180)        {          report_call_event (EXOSIP_CALL_PROCEEDING, jc, jd, tr);      } else if (jd != NULL && MSG_IS_RESPONSE_FOR (sip, "INVITE")                 && sip->status_code >= 180)        {          report_call_event (EXOSIP_CALL_RINGING, jc, jd, tr);      } 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);        }      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            {              OSIP_TRACE (osip_trace                          (__FILE__, __LINE__, OSIP_WARNING, NULL,                           "The dialog has been replaced with the new one fro 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); */}static 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);  }}static voidcb_rcv2xx (int type, osip_transaction_t * tr, osip_message_t * sip){  eXosip_dialog_t *jd;  eXosip_call_t *jc;  eXosip_subscribe_t *js;  eXosip_notify_t *jn;  jinfo_t *jinfo = (jinfo_t *) osip_transaction_get_your_instance (tr);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?