예제 #1
0
int
eXosip_options_send_request (osip_message_t * options)
{
  osip_transaction_t *transaction;
  osip_event_t *sipevent;
  int i;

  i = osip_transaction_init (&transaction, NICT, eXosip.j_osip, options);
  if (i != 0)
    {
      osip_message_free (options);
      return -1;
    }

  osip_list_add (eXosip.j_transactions, transaction, 0);

  sipevent = osip_new_outgoing_sipmessage (options);
  sipevent->transactionid = transaction->transactionid;

  osip_transaction_set_your_instance (transaction,
                                      __eXosip_new_jinfo (NULL, NULL, NULL, NULL));
  osip_transaction_add_event (transaction, sipevent);

  __eXosip_wakeup ();
  return 0;
}
예제 #2
0
int
_eXosip_transaction_init (osip_transaction_t ** transaction,
                       osip_fsm_type_t ctx_type, osip_t * osip,
                       osip_message_t * message)
{
#ifdef SRV_RECORD
	osip_srv_record_t record;
#endif
	int i;
    i = osip_transaction_init (transaction, ctx_type, osip, message);
	if (i != 0)
	{
		return i;
	}
#ifdef SRV_RECORD
	memset(&record, 0, sizeof(osip_srv_record_t));
	i = _eXosip_srv_lookup(*transaction, message, &record);
	if (i<0)
	{
		return 0;
	}
	osip_transaction_set_srv_record(*transaction, &record);
#endif
	return 0;
}
예제 #3
0
int
eXosip_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 = osip_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;
}
예제 #4
0
파일: sip.c 프로젝트: maxgrind/sipmore
void ProcessNewReqNist(osip_t* osip, osip_event_t *evt, int sock)
{
	osip_transaction_t *tran;
	osip_transaction_init(&tran, NIST, osip, evt->sip);
	osip_transaction_set_out_socket(tran, sock);
	osip_transaction_set_your_instance(tran, osip);
	osip_transaction_add_event(tran, evt);
}
예제 #5
0
파일: sip.c 프로젝트: maxgrind/sipmore
void ProcessNewReqIst(osip_t* osip, osip_event_t *evt, int sock)
{
	osip_transaction_t *tran;
	osip_transaction_init(&tran, IST, osip, evt->sip);
	//osip_transaction_set_in_socket (tran, socket);
	osip_transaction_set_out_socket(tran, sock);
	osip_transaction_set_your_instance(tran, osip);// store osip in transaction for later usage
	osip_transaction_add_event(tran, evt);
}
예제 #6
0
int eXosip_subscribe_send_subscribe(eXosip_subscribe_t *js,
				     eXosip_dialog_t *jd, const char *expires)
{
  osip_transaction_t *transaction;
  osip_message_t *subscribe;
  osip_event_t *sipevent;
  int i;
  transaction = eXosip_find_last_out_subscribe(js, jd);
  if (transaction!=NULL)
    {
      if (transaction->state!=NICT_TERMINATED &&
	  transaction->state!=NIST_TERMINATED)
	return -1;
    }

  i = _eXosip_build_request_within_dialog(&subscribe, "SUBSCRIBE",
					  jd->d_dialog, "UDP");
  if (i!=0)
    return -2;

  osip_message_set_expires(subscribe, expires);

  i = osip_transaction_init(&transaction,
			    NICT,
			    eXosip.j_osip,
			    subscribe);
  if (i!=0)
    {
      /* TODO: release the j_call.. */
      osip_message_free(subscribe);
      return -1;
    }
  
  _eXosip_subscribe_set_refresh_interval(js, subscribe);
  osip_list_add(jd->d_out_trs, transaction, 0);
  
  sipevent = osip_new_outgoing_sipmessage(subscribe);
  sipevent->transactionid =  transaction->transactionid;
  
  osip_transaction_add_event(transaction, sipevent);

  osip_transaction_set_your_instance(transaction, __eXosip_new_jinfo(NULL, jd, js, NULL));
  __eXosip_wakeup();
  return 0;
}
예제 #7
0
int bSipSend(
						 osip_message_t    *msgPtr,
						 osip_fsm_type_t   transactionType)
{
	int status;
	osip_transaction_t *transactionPtr;
	osip_event_t       *sipeventPtr;

	if ( (status = osip_transaction_init(&transactionPtr,transactionType,osip,msgPtr)) != 0 ){
		printf("Failed to init transaction %d",status);
		return -1;
	}

	if((sipeventPtr = osip_new_outgoing_sipmessage(msgPtr)) == NULL){
		printf("Can't allocate message");
		osip_message_free(msgPtr);
		return -1;
	}

	sipeventPtr->transactionid =  transactionPtr->transactionid;


	if((status = osip_message_force_update(msgPtr)) != 0){
		printf("Failed force update",status);
		osip_message_free(msgPtr);
		return -1;
	}

	if((status = osip_transaction_add_event(transactionPtr, sipeventPtr)) != 0){
		printf("Can't add event");
		osip_message_free(msgPtr);
		return -1;
	}

	return 0;

}
예제 #8
0
파일: Node.cpp 프로젝트: inuyasha1027/SI2P
int Node::SndRegister(REG_TYPE type , 
					  ChordId req_uri ,  
					  ChordId to , 
					  ChordId contact , 
					  BOOL IncludeSuccList) 
{
	char *message1;
	unsigned int len = 0;



	osip_transaction_t *transaction;
	osip_event_t *sipevent;
	osip_message_t *request;

	/* temp uri */
	char * tmp_uri;
	
	int i;

	i = osip_message_init(&request);
	if (i!=0) 
		goto si2perror1;
	/* prepare the request-line */
	osip_message_set_method(request, osip_strdup("REGISTER"));
	osip_message_set_version(request, osip_strdup("SIP/2.0"));
	osip_message_set_status_code(request, 0);
	osip_message_set_reason_phrase(request, NULL);

	//requset uri
	if(type == MULTICAST)
	{
		tmp_uri = osip_strdup("sip:224.0.1.75") ;
	}
	else
		tmp_uri = ChordId2Uri(req_uri,false) ;

	osip_uri_t *uri;

	i=osip_uri_init(&uri);
	if (i!=0) 
		goto si2perror2;
	i=osip_uri_parse(uri, tmp_uri );
	if(tmp_uri)	osip_free(tmp_uri) ;
	if (i!=0)
		goto si2perror2;

	osip_message_set_uri(request , uri) ;

	if(type == JOIN)
	{
		tmp_uri = ChordId2Uri(to,false) ;

		/* when JOIN , to and from are same */
		osip_message_set_to(request, tmp_uri );
		osip_message_set_from(request, tmp_uri);
		if (tmp_uri) osip_free(tmp_uri) ;
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("join"));
	}

	else if(type == FINDSUCC)
	{
		tmp_uri = ChordId2Uri(to,true) ;
		osip_message_set_to(request, tmp_uri );
		if (tmp_uri) osip_free(tmp_uri) ;

		tmp_uri = ChordId2Uri(chordId,false);
		osip_message_set_from(request, tmp_uri  );
		if (tmp_uri) osip_free(tmp_uri) ;
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("findsucc"));
		
		//has no contact
	}

	else if(type == STABILIZE)
	{
		tmp_uri = ChordId2Uri(to,false);
		osip_message_set_to(request, tmp_uri);
		if (tmp_uri) osip_free(tmp_uri) ;

		tmp_uri = ChordId2Uri(chordId,false)  ;
		osip_message_set_from(request, tmp_uri );
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("stabilize"));	
		if (tmp_uri) osip_free(tmp_uri) ;
		
		//contact
		tmp_uri = ChordId2Uri(chordId,false);
		char * pre_uri = ChordId2Uri(getFingerTable()->getPredecessor(),false) ;

		char *ctt = (char *) osip_malloc(strlen(tmp_uri) + strlen(";predecessor=") + strlen(pre_uri) +1) ;
		if (ctt == NULL)
			return NULL;
		sprintf (ctt, "%s;predecessor=%s", tmp_uri,pre_uri);
		osip_free(tmp_uri) ;	osip_free(pre_uri) ;

		osip_message_set_contact(request, ctt );
		osip_free(ctt) ;
	}

	else if(type == LEAVE)
	{
		tmp_uri = ChordId2Uri(to,false) ;
		osip_message_set_to(request, tmp_uri );
		if (tmp_uri) osip_free(tmp_uri) ;

		tmp_uri = ChordId2Uri(chordId,false) ;
		osip_message_set_from(request, tmp_uri );
		if (tmp_uri) osip_free(tmp_uri) ;
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("leave"));
		
		//contact
		tmp_uri = ChordId2Uri(chordId,false);
		char * pre_uri = ChordId2Uri(getFingerTable()->getPredecessor(),false) ;

		char *ctt = (char *) osip_malloc(strlen(tmp_uri) + strlen(";predecessor=") + strlen(pre_uri) +1) ;
		if (ctt == NULL)
			return NULL;
		sprintf (ctt, "%s;predecessor=%s", tmp_uri,pre_uri);
		osip_free(tmp_uri) ;	osip_free(pre_uri) ;

		osip_message_set_contact(request, ctt );
		osip_free(ctt) ;
		
		//succlist
		if(IncludeSuccList)
		{
			for(i = 0  ; i < getFingerTable()->getSuccNum() ; i++)
			{
				tmp_uri = ChordId2Uri(getFingerTable()->getSuccessor(i),false) ;
				osip_message_set_contact(request, tmp_uri );
				osip_free(tmp_uri) ;
			}
		}
	}//type == LEAVE
	
	if(type == MULTICAST)
	{
		
		tmp_uri = ChordId2Uri(chordId,false);
		/* when JOIN , to and from are same */
		osip_message_set_to(request, tmp_uri );
		osip_message_set_from(request, tmp_uri);
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("multicast"));
		osip_free(tmp_uri) ;
		//no contact
	}//type == MULTIPL


	//---set call_id and cseq
	osip_call_id_t *callid;
	osip_cseq_t *cseq;
	char *num;
	char  *cidrand;
	char *register_callid_number ;

	/* call-id is always the same for REGISTRATIONS */
	i = osip_call_id_init(&callid);
	if (i!=0) 
		goto si2perror2;
	cidrand = osip_strdup("BF9598C48B184EBBAFADFE527EED8186") ;
	osip_call_id_set_number(callid, cidrand);
	register_callid_number = cidrand;

	osip_call_id_set_host(callid, osip_strdup("SI2P.COM"));
	request->call_id = callid;

	//cseq
	i = osip_cseq_init(&cseq);
	if (i!=0) 
		goto si2perror2 ;
	num = osip_strdup("1");
	osip_cseq_set_number(cseq, num);
	osip_cseq_set_method(cseq, osip_strdup("REGISTER"));
	request->cseq = cseq;
	 
	/*the Max-Forward header */
	osip_message_set_max_forwards(request, "5"); /* a UA should start a request with 70 */

	/* the via header */
	char tmp[200];
	unsigned int branch;
	branch=osip_build_random_number();
    snprintf(tmp, 200, "SIP/2.0/%s %s:%s;rport;branch=z9hG4bK%u", "UDP",
	      localip,
	      localport,
	      branch );

    osip_message_set_via(request, tmp);

	/* the UA header */
	osip_message_set_user_agent(request, user_agent);

	/*  the expires header */
	char exp[10]; /* MUST never be ouside 1 and 3600 */
	snprintf(exp, 9, "%i", expires);
	osip_message_set_expires(request, exp);
	osip_message_set_content_length(request, "0");


	/*** then must wake up osip ***/
	i = osip_transaction_init(&transaction,
		       NICT,
		       adosip->j_osip,
		       request);
	if (i!=0)
		goto si2perror2 ;

	//jr->r_last_tr = transaction;

	/* send REGISTER */
	
	i = osip_message_to_str(request, &message1, &len);
	LogStream("SEND======================================>>\n") ;
	LogStream(message1) ;
	if(message1)	osip_free(message1) ;
//	printf("SEND======================================>>\n") ;
//	printf(message1) ;

	sipevent = osip_new_outgoing_sipmessage(request);
	sipevent->transactionid =  transaction->transactionid;
	osip_message_force_update(request);
  
	osip_transaction_add_event(transaction, sipevent);

	adosip->ThreadWakeUp();
	return 0;

si2perror1:
	if(request != NULL)osip_message_free(request);
	return -1 ;
si2perror2:
	if(request != NULL)osip_message_free(request);
	return -1;
}
예제 #9
0
파일: Node.cpp 프로젝트: inuyasha1027/SI2P
int Node::SndUserRegisterRequest(char *aor ,const char *requri)
{
	char *message1;
	unsigned int len = 0;



	osip_transaction_t *transaction;
	osip_event_t *sipevent;
	osip_message_t *request;


	int i;

	i = osip_message_init(&request);
	if (i!=0) 
		goto si2perror1;
	/* prepare the request-line */
	osip_message_set_method(request, osip_strdup("REGISTER"));
	osip_message_set_version(request, osip_strdup("SIP/2.0"));
	osip_message_set_status_code(request, 0);
	osip_message_set_reason_phrase(request, NULL);

	//requset uri


	osip_uri_t *uri;

	i=osip_uri_init(&uri);
	if (i!=0) 
		goto si2perror2;
	i=osip_uri_parse(uri, requri);
	if (i!=0)
		goto si2perror2;

	osip_message_set_uri(request , uri) ;


	//to from ,no contact
	osip_message_set_to(request,aor);
	osip_message_set_from(request,aor);

	osip_from_param_add(request->from,osip_strdup("user"),osip_strdup("user_query"));

	//---set call_id and cseq
	osip_call_id_t *callid;
	osip_cseq_t *cseq;
	char *num;
	char  *cidrand;
	char *register_callid_number ;

	/* call-id is always the same for REGISTRATIONS */
	i = osip_call_id_init(&callid);
	if (i!=0) 
		goto si2perror2;
	cidrand = osip_strdup("BF9598C48B184EBBAFADFE527EED8186") ;
	osip_call_id_set_number(callid, cidrand);
	register_callid_number = cidrand;

	osip_call_id_set_host(callid, osip_strdup("SI2P.COM"));
	request->call_id = callid;

	//cseq
	i = osip_cseq_init(&cseq);
	if (i!=0) 
		goto si2perror2 ;
	num = osip_strdup("1");
	osip_cseq_set_number(cseq, num);
	osip_cseq_set_method(cseq, osip_strdup("REGISTER"));
	request->cseq = cseq;
	 
	/*the Max-Forward header */
	osip_message_set_max_forwards(request, "5"); /* a UA should start a request with 70 */

	/* the via header */
	char tmp[200];
	unsigned int branch;
	branch=osip_build_random_number();
    snprintf(tmp, 200, "SIP/2.0/%s %s:%s;rport;branch=z9hG4bK%u", "UDP",
	      localip,
	      localport,
	      branch );

    osip_message_set_via(request, tmp);

	/* the UA header */
	osip_message_set_user_agent(request, user_agent);

	/*  the expires header */
	char exp[10]; /* MUST never be ouside 1 and 3600 */
	snprintf(exp, 9, "%i", expires);
	osip_message_set_expires(request, exp);
	osip_message_set_content_length(request, "0");


	/*** then must wake up osip ***/
	i = osip_transaction_init(&transaction,
		       NICT,
		       adosip->j_osip,
		       request);
	if (i!=0)
		goto si2perror2 ;

	/* send REGISTER */
	i = osip_message_to_str(request, &message1, &len);
	LogStream("SEND======================================>>\n") ;
	LogStream(message1) ;
	if(message1) osip_free(message1) ;

	sipevent = osip_new_outgoing_sipmessage(request);
	sipevent->transactionid =  transaction->transactionid;
	osip_message_force_update(request);
  
	osip_transaction_add_event(transaction, sipevent);

	adosip->ThreadWakeUp();
	return 0;

si2perror1:
	if(request != NULL)osip_message_free(request);
	return -1 ;
si2perror2:
	if(request != NULL)osip_message_free(request);
	return -1;
	return 0;
}
예제 #10
0
파일: Node.cpp 프로젝트: inuyasha1027/SI2P
int
Node::SndUserRegisterRequest(REG_TYPE type,
				uinfo_t *user_info,
				const char *registrar,
				int expires)
{
	char *message1;
	unsigned int len = 0;

	osip_message_t *request;
	osip_event_t *sipevent;
	osip_transaction_t *transaction;
	osip_uri_t *uri;
	
	char *tmp_uri;
	int i;

	i=osip_message_init(&request);
	if(i!=0)
		goto si2perror1;
	osip_message_set_method(request,strdup("REGISTER"));
	osip_message_set_version(request,strdup("SIP/2.0"));
	osip_message_set_status_code(request,0);
	osip_message_set_reason_phrase(request,NULL);

	i=osip_uri_init(&uri);
	if(i!=0)
		goto si2perror2;
	i=osip_uri_parse(uri,osip_strdup(registrar));
	osip_message_set_uri(request,uri);

	//*set to,from and header
	if(type==USER_REGISTRATION)
	{	
		char *dest1;
		char *dest2;
		
		osip_uri_to_str(user_info->aor->uri,&dest1);
		i=osip_message_set_to(request,dest1);
		i=osip_message_set_from(request,dest1);
		if(dest1)	osip_free(dest1) ;
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("user_registration"));

		osip_contact_to_str(user_info->bindings->contact,&dest2);
		i=osip_message_set_contact(request,osip_strdup(dest2));
		if(dest2)	osip_free(dest2) ;
	}

	if(type == RED_REGISTER)
	{
		char *dest1;
		char *dest2;
		osip_uri_to_str(user_info->aor->uri,&dest1);
		i=osip_message_set_to(request,dest1);
		i=osip_message_set_from(request,dest1);
		if(dest1)	osip_free(dest1) ;
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("red_register"));

		osip_contact_to_str(user_info->bindings->contact,&dest2);
		i=osip_message_set_contact(request,osip_strdup(dest2));
		if(dest2)	osip_free(dest2) ;
	}

	if(type==TRANSFER_REGISTRATION)
	{
		char *dest1;
		char *dest2;
		//string tmp_uri;
		osip_uri_to_str(user_info->aor->uri,&dest1);
		osip_message_set_to(request,dest1);
		if(dest1)	osip_free(dest1) ;

		tmp_uri = ChordId2Uri(chordId,false);
		osip_message_set_from(request,tmp_uri);
		osip_from_param_add (request->from, osip_strdup ("user"), osip_strdup("transfer_registration"));
		if(tmp_uri)	osip_free(tmp_uri) ;

		osip_contact_to_str(user_info->bindings->contact,&dest2);
		osip_message_set_contact(request,dest2);
		if(dest2)	osip_free(dest2) ;
	}
	if(type==THIRD_PARTY)
	{
		//todo
	}
		//---set call_id and cseq
	osip_call_id_t *callid;
	osip_cseq_t *cseq;
	char *num;
	char  *cidrand;
	char *register_callid_number ;

	//* call-id is always the same for REGISTRATIONS 
	i = osip_call_id_init(&callid);
	if (i!=0) 
		goto si2perror2;
	cidrand = osip_strdup("BF9598C48B184EBBAFADFE527EED8186") ;
	osip_call_id_set_number(callid, cidrand);
	register_callid_number = cidrand;

	osip_call_id_set_host(callid, osip_strdup("SI2P.COM"));
	request->call_id = callid;

	//cseq
	i = osip_cseq_init(&cseq);
	if (i!=0) 
		goto si2perror2 ;
	num = osip_strdup("1");
	osip_cseq_set_number(cseq, num);
	osip_cseq_set_method(cseq, osip_strdup("REGISTER"));
	request->cseq = cseq;
	 
	//*the Max-Forward header 
	osip_message_set_max_forwards(request, "5"); //* a UA should start a request with 70 

	//* the via header 
	char tmp[200];
    snprintf(tmp, 200, "SIP/2.0/%s %s:%s;rport;branch=z9hG4bK%u", "UDP",
	      localip,
	      localport,
	      via_branch_new_random() );

    osip_message_set_via(request, tmp);

	//* the UA header 
	osip_message_set_user_agent(request, user_agent);

	//*  the expires header 
	char exp[10]; //* MUST never be ouside 1 and 3600 
	snprintf(exp, 9, "%i", expires);
	osip_message_set_expires(request, exp);
	osip_message_set_content_length(request, "0");


	//*** then must wake up osip 
	i = osip_transaction_init(&transaction,
		       NICT,
		       adosip->j_osip,
		       request);
	if (i!=0)
		goto si2perror3 ;

	//* send REGISTER 
	i = osip_message_to_str(request, &message1, &len);
	LogStream("SEND======================================>>\n") ;
	LogStream(message1) ;
	if(message1) osip_free(message1) ;
//	printf("SEND======================================>>\n") ;
//	printf(message1) ;
	sipevent = osip_new_outgoing_sipmessage(request);
	sipevent->transactionid =  transaction->transactionid;
	osip_message_force_update(request);
  
	osip_transaction_add_event(transaction, sipevent);

	adosip->ThreadWakeUp();
	return 0;

si2perror1:
	
	return -1;

si2perror2:
	if(request!=NULL)
		osip_message_free(request);
	return -1;

si2perror3:
	if(transaction!=NULL)
		osip_message_free(request);
	return -1;


}
예제 #11
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;

    char locip[256];
    int cseq;
    char tmp[256];
    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++;
    }

    osip_list_remove (msg->vias, 0);
    osip_via_free (via);

    i = _eXosip_find_protocol (out_tr->orig_request);
    if (i == IPPROTO_UDP)
    {
        eXosip_guess_ip_for_via (eXosip.net_interfaces[0].net_ip_family, locip,
                                 sizeof (locip));
        if (eXosip.net_interfaces[0].net_ip_family == AF_INET6)
            snprintf (tmp, 256, "SIP/2.0/UDP [%s]:%s;branch=z9hG4bK%u",
                      locip, eXosip.net_interfaces[0].net_port,
                      via_branch_new_random ());
        else
            snprintf (tmp, 256, "SIP/2.0/UDP %s:%s;rport;branch=z9hG4bK%u",
                      locip, eXosip.net_interfaces[0].net_port,
                      via_branch_new_random ());
    } else if (i == IPPROTO_TCP)
    {
        eXosip_guess_ip_for_via (eXosip.net_interfaces[1].net_ip_family, locip,
                                 sizeof (locip));
        if (eXosip.net_interfaces[1].net_ip_family == AF_INET6)
            snprintf (tmp, 256, "SIP/2.0/TCP [%s]:%s;branch=z9hG4bK%u",
                      locip, eXosip.net_interfaces[1].net_port,
                      via_branch_new_random ());
        else
            snprintf (tmp, 256, "SIP/2.0/TCP %s:%s;rport;branch=z9hG4bK%u",
                      locip, eXosip.net_interfaces[1].net_port,
                      via_branch_new_random ());
    } else
    {
        /* tls? */
        osip_message_free (msg);
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_ERROR, NULL,
                     "eXosip: unsupported protocol\n"));
        return -1;
    }

    osip_via_init (&via);
    osip_via_parse (via, tmp);
    osip_list_add (msg->vias, via, 0);

    eXosip_add_authentication_information (msg, out_tr->last_response);
    osip_message_force_update (msg);

    i = osip_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;
}
예제 #12
0
int eXosip_reinvite_with_authentication (struct eXosip_call_t *jc)
{
    struct eXosip_call_t *jcc;
#ifdef SM

    char *locip;
#else
    char locip[50];
#endif
	osip_message_t * cloneinvite;
  	osip_event_t *sipevent;
  	osip_transaction_t *transaction;
	int osip_cseq_num,length;
    osip_via_t *via;
    char *tmp;
    int i;

	osip_message_clone (jc->c_out_tr->orig_request, &cloneinvite);

	osip_cseq_num = osip_atoi(jc->c_out_tr->orig_request->cseq->number);
	length   = strlen(jc->c_out_tr->orig_request->cseq->number);
	tmp    = (char *)osip_malloc(90*sizeof(char));
	via   = (osip_via_t *) osip_list_get (cloneinvite->vias, 0);

	osip_list_remove(cloneinvite->vias, 0);
	osip_via_free(via);

#ifdef SM
	eXosip_get_localip_for(cloneinvite->req_uri->host,&locip);
#else
	eXosip_guess_ip_for_via(eXosip.ip_family, locip, 49);
#endif

	if (eXosip.ip_family==AF_INET6) {
		sprintf(tmp, "SIP/2.0/UDP [%s]:%s;branch=z9hG4bK%u", locip,
		      eXosip.localport, via_branch_new_random());
	} else {
		sprintf(tmp, "SIP/2.0/UDP %s:%s;branch=z9hG4bK%u", locip,
		      eXosip.localport, via_branch_new_random());
	}
#ifdef SM
	osip_free(locip);
#endif
	osip_via_init(&via);
	osip_via_parse(via, tmp);
	osip_list_add(cloneinvite->vias, via, 0);
	osip_free(tmp);

	osip_cseq_num++;
	osip_free(cloneinvite->cseq->number);
	cloneinvite->cseq->number = (char*)osip_malloc(length + 2);
	sprintf(cloneinvite->cseq->number, "%i", osip_cseq_num);

	eXosip_add_authentication_information(cloneinvite, jc->c_out_tr->last_response);
    cloneinvite->message_property = 0;

    eXosip_call_init(&jcc);
    i = osip_transaction_init(&transaction,
		       ICT,
		       eXosip.j_osip,
		       cloneinvite);
    if (i!=0)
    {
      eXosip_call_free(jc);
      osip_message_free(cloneinvite);
      return -1;
    }
    jcc->c_out_tr = transaction;
    sipevent = osip_new_outgoing_sipmessage(cloneinvite);
    sipevent->transactionid =  transaction->transactionid;
    osip_transaction_set_your_instance(transaction, __eXosip_new_jinfo(jcc,
NULL, NULL, NULL));
    osip_transaction_add_event(transaction, sipevent);

    jcc->external_reference = 0;
    ADD_ELEMENT(eXosip.j_calls, jcc);

    eXosip_update(); /* fixed? */
    __eXosip_wakeup();
	return 0;
}
예제 #13
0
int eXosip_subscribe_send_subscribe(eXosip_subscribe_t *js,
				     eXosip_dialog_t *jd, const char *expires)
{
  osip_transaction_t *transaction;
  osip_message_t *subscribe;
  osip_event_t *sipevent;
  int i;
  
	if (!jd || !jd->d_dialog)
	{
		// JULIEN : Maybe the first SUBSCRIBE didn't work 
		// that's why there's no more dialog
		return -1;
	}

  transaction = eXosip_find_last_out_subscribe(js, jd);

  if (transaction!=NULL)
    {
      if (transaction->state!=NICT_TERMINATED && transaction->state!=NIST_TERMINATED)
	return -1;
      //<MINHPQ>		
      // Remove the transaction from dialog structure
      if (jd)
	owsip_list_remove_element (jd->d_out_trs, transaction); // Remove the transaction from jd->d_out_trs list
      if (js && (js->s_out_tr == transaction)) 
	{
	  js->s_out_tr = NULL; // Remove the transaction from js->s_out_tr
	}

      eXosip_transaction_free(transaction);
      transaction = NULL;
      //</MINHPQ>
    }		

  i = _eXosip_build_request_within_dialog(&subscribe, "SUBSCRIBE", jd->d_dialog);
  if (i!=0)
    return -2;
  //<MINHPQ>
  if (js->winfo) 
    {
      owsip_message_set_header(subscribe, "Event", "presence.winfo");
      owsip_message_set_header(subscribe, "Accept", "application/watcherinfo+xml");
    }
  //</MINHPQ>
  
  owsip_message_set_expires(subscribe, expires);

  i = osip_transaction_init(&transaction,
			    NICT,
			    eXosip.j_osip,
			    subscribe);
  if (i!=0)
    {
      /* TODO: release the j_call.. */
      osip_message_free(subscribe);
      return -1;
    }
  
  _eXosip_subscribe_set_refresh_interval(js, subscribe);
  osip_list_add(jd->d_out_trs, transaction, 0);
  
  sipevent = osip_new_outgoing_sipmessage(subscribe);
  sipevent->transactionid =  transaction->transactionid;
  
  osip_transaction_add_event(transaction, sipevent);

  osip_transaction_set_your_instance(transaction, __eXosip_new_jinfo(owsip_dialog_account_get (jd), NULL, jd, js, NULL));
  __eXosip_wakeup();
  return 0;
}