⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exinsubscription_api.c

📁 libeXosip2-3.0.3.tar.gz
💻 C
📖 第 1 页 / 共 2 页
字号:
    {      eXosip_notify_dialog_find (did, &jn, &jd);    }  if (jd == NULL || jn == NULL)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: No incoming subscription here?\n"));      return -1;    }  transaction = NULL;  transaction = eXosip_find_last_out_notify (jn, jd);  if (transaction != NULL)    {      if (transaction->state != NICT_TERMINATED &&          transaction->state != NIST_TERMINATED &&          transaction->state != NICT_COMPLETED &&          transaction->state != NIST_COMPLETED)        return -1;    }  transport = NULL;  if (transaction == NULL)    transaction = jn->n_inc_tr;  if (transaction != NULL && transaction->orig_request != NULL)    transport = _eXosip_transport_protocol (transaction->orig_request);  transaction = NULL;  if (transport == NULL)    i = _eXosip_build_request_within_dialog (request, method, jd->d_dialog, "UDP");  else    i =      _eXosip_build_request_within_dialog (request, method, jd->d_dialog,                                           transport);  if (i != 0)    return -2;  return 0;}inteXosip_insubscription_send_request (int did, osip_message_t * request){  eXosip_dialog_t *jd = NULL;  eXosip_notify_t *jn = NULL;  osip_transaction_t *transaction;  osip_event_t *sipevent;  int i;  if (request == NULL)    return -1;  if (did > 0)    {      eXosip_notify_dialog_find (did, &jn, &jd);    }  if (jd == NULL || jn == NULL)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: No incoming subscription here?\n"));      osip_message_free (request);      return -1;    }  transaction = NULL;  transaction = eXosip_find_last_out_notify (jn, jd);  if (transaction != NULL)    {      if (transaction->state != NICT_TERMINATED &&          transaction->state != NIST_TERMINATED &&          transaction->state != NICT_COMPLETED &&          transaction->state != NIST_COMPLETED)        {          osip_message_free (request);          return -1;        }      transaction = NULL;    }  i = _eXosip_transaction_init (&transaction, NICT, eXosip.j_osip, request);  if (i != 0)    {      osip_message_free (request);      return -1;    }  osip_list_add (jd->d_out_trs, transaction, 0);  sipevent = osip_new_outgoing_sipmessage (request);  sipevent->transactionid = transaction->transactionid;  osip_transaction_set_your_instance (transaction,                                      __eXosip_new_jinfo (NULL, jd, NULL, jn));  osip_transaction_add_event (transaction, sipevent);  __eXosip_wakeup ();  return 0;}int_eXosip_insubscription_send_request_with_credential (eXosip_notify_t * jn,                                                     eXosip_dialog_t * jd,                                                     osip_transaction_t * out_tr){  osip_transaction_t *tr = NULL;  osip_message_t *msg = NULL;  osip_event_t *sipevent;  int cseq;  osip_via_t *via;  int i;  if (jn == NULL)    return -1;  if (jd != NULL)    {      if (jd->d_out_trs == NULL)        return -1;    }  if (out_tr == NULL)    {      out_tr = eXosip_find_last_out_notify (jn, jd);    }  if (out_tr == NULL      || out_tr->orig_request == NULL || out_tr->last_response == NULL)    return -1;  osip_message_clone (out_tr->orig_request, &msg);  if (msg == NULL)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: could not clone msg for authentication\n"));      return -1;    }  via = (osip_via_t *) osip_list_get (&msg->vias, 0);  if (via == NULL || msg->cseq == NULL || msg->cseq->number == NULL)    {      osip_message_free (msg);      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: missing via or cseq header\n"));      return -1;    }  /* increment cseq */  cseq = atoi (msg->cseq->number);  osip_free (msg->cseq->number);  msg->cseq->number = strdup_printf ("%i", cseq + 1);  if (jd != NULL && jd->d_dialog != NULL)    {      jd->d_dialog->local_cseq++;    }  i = eXosip_update_top_via(msg);  if (i!=0)    {      osip_message_free (msg);      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: unsupported protocol\n"));      return -1;    }  eXosip_add_authentication_information (msg, out_tr->last_response);  osip_message_force_update (msg);  i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg);  if (i != 0)    {      osip_message_free (msg);      return -1;    }  /* add the new tr for the current dialog */  osip_list_add (jd->d_out_trs, tr, 0);  sipevent = osip_new_outgoing_sipmessage (msg);  osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (NULL, jd, NULL, jn));  osip_transaction_add_event (tr, sipevent);  eXosip_update ();             /* fixed? */  __eXosip_wakeup ();  return 0;}int_eXosip_insubscription_auto_send_notify (int did,                          int subscription_status, int subscription_reason){	osip_message_t *notify;	int i;	char xml[4096];	char *entity;	eXosip_call_t *jc;	eXosip_dialog_t *jd;	i = eXosip_insubscription_build_notify (did, subscription_status,										  subscription_reason, &notify);	if (i != 0)	{		return -1;	}	/* build dialog xml state */	memset(xml, 0, sizeof(xml));	osip_uri_to_str(notify->from->url , &entity);	if (entity==NULL)		return -1;	snprintf(xml, sizeof(xml),
		   "<?xml version=\"1.0\"?>" "\r\n"
		   "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\"" "\r\n"
		   "	version=\"2\" state=\"full\"" "\r\n"
		   "	entity=\"%s\">" "\r\n",		   entity);	osip_free(entity);	/* loop over all jc/jd */	for (jc = eXosip.j_calls; jc != NULL; jc = jc->next)	{		for (jd = jc->c_dialogs; jd != NULL; jd = jd->next)		{			if (jd->d_dialog == NULL)     /* finished call */			{			}			else			{				char tmp_dialog[2048];				char direction[20];				char dlg_state[20];				char *remote_uri=NULL;				if (jd->d_dialog->type == CALLER)					strcpy(direction, "initiator");				else					strcpy(direction, "recipient");				if (jd->d_dialog->state == DIALOG_CONFIRMED)					strcpy(dlg_state, "confirmed");				else					strcpy(dlg_state, "early");				if (jd->d_dialog->remote_uri!=NULL					&&jd->d_dialog->remote_uri->url!=NULL)				{					osip_uri_to_str(jd->d_dialog->remote_uri->url, &remote_uri);				}				if (remote_uri!=NULL)				{					/* add dialog info */					snprintf(tmp_dialog, sizeof(tmp_dialog),						"	<dialog id=\"%s\" call-id=\"%s\"" "\r\n"						"		local-tag=\"%s\" remote-tag=\"%s\"" "\r\n"						"		direction=\"%s\">" "\r\n"						"		<state>%s</state>" "\r\n"						"		<remote>" "\r\n"
						"			<identity>%s</identity>" "\r\n"
						"		</remote>" "\r\n"						"	</dialog>" "\r\n",
						jd->d_dialog->call_id,						jd->d_dialog->call_id,						jd->d_dialog->local_tag,						jd->d_dialog->remote_tag,						direction,						dlg_state,						remote_uri);					strcat(xml, tmp_dialog);				}			}		}	}	strcat(xml, "</dialog-info>" "\r\n");	osip_message_set_content_type (notify, "application/dialog-info+xml");	osip_message_set_body (notify, xml, strlen(xml));	return eXosip_insubscription_send_request (did, notify);}inteXosip_insubscription_automatic(eXosip_event_t *evt){	eXosip_dialog_t *jd = NULL;	eXosip_notify_t *jn = NULL;	osip_header_t *event_header;	if (evt->did<=0 || evt->nid<=0)		return -1;	if (evt->request==NULL)		return -1;	eXosip_notify_dialog_find (evt->did, &jn, &jd);	if (jd == NULL || jn == NULL)	{		OSIP_TRACE (osip_trace				  (__FILE__, __LINE__, OSIP_ERROR, NULL,				   "eXosip: No incoming subscription here?\n"));		return -1;	}    osip_message_header_get_byname (evt->request , "event",                                    0, &event_header);    if (event_header == NULL || event_header->hvalue == NULL)	{		eXosip_insubscription_send_answer (evt->tid, 400, NULL);		return 0;	}	/* this event should be handled internally */	if (osip_strcasecmp(event_header->hvalue, "dialog") == 0)	{		/* send 200 ok to SUBSCRIBEs */		if (evt->type == EXOSIP_IN_SUBSCRIPTION_NEW)		{			osip_message_t *answer;			int i;			i = eXosip_insubscription_build_answer (evt->tid, 202, &answer);			if (i == 0)			{				i = eXosip_insubscription_send_answer (evt->tid, 202, answer);			}			if (i != 0)			{				i = eXosip_insubscription_send_answer (evt->tid, 400, NULL);				return 0;			}			/* send initial notify */			i = _eXosip_insubscription_auto_send_notify(evt->did , EXOSIP_SUBCRSTATE_ACTIVE, PROBATION);			if (i != 0)			{				/* delete subscription... */				return 0;			}		}	}	else	{		eXosip_insubscription_send_answer (evt->tid, 489, NULL);	}	return 0;}#endif

⌨️ 快捷键说明

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