int eXosip_register_send_register (int rid, osip_message_t * reg) { osip_transaction_t *transaction; osip_event_t *sipevent; eXosip_reg_t *jr; int i; jr = eXosip_reg_find (rid); if (jr == NULL) { osip_message_free (reg); return -1; } if (jr->r_last_tr != NULL) { if (jr->r_last_tr->state != NICT_TERMINATED && jr->r_last_tr->state != NICT_COMPLETED) { osip_message_free (reg); return -1; } } if (reg == NULL) { i = _eXosip_register_build_register (jr, ®); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot build REGISTER!")); return i; } } i = _eXosip_transaction_init (&transaction, NICT, eXosip.j_osip, reg); if (i != 0) { /* TODO: release the j_call.. */ osip_message_free (reg); return -2; } jr->r_last_tr = transaction; /* send REGISTER */ sipevent = osip_new_outgoing_sipmessage (reg); sipevent->transactionid = transaction->transactionid; osip_message_force_update (reg); osip_transaction_add_event (transaction, sipevent); __eXosip_wakeup (); return 0; }
int eXosip_message_send_answer (int tid, int status, osip_message_t * answer) { osip_transaction_t *tr = NULL; osip_event_t *evt_answer; int i = -1; if (tid <= 0) return OSIP_BADPARAMETER; if (status <= 100 || status > 699) return OSIP_BADPARAMETER; if (answer == NULL && status > 100 && status < 200) return OSIP_BADPARAMETER; if (tid > 0) { eXosip_transaction_find (tid, &tr); } if (tr == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No MESSAGE transaction found\n")); osip_message_free (answer); return OSIP_NOTFOUND; } /* is the transaction already answered? */ if (tr->state == NIST_COMPLETED || tr->state == NIST_TERMINATED) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: transaction already answered\n")); osip_message_free (answer); return OSIP_WRONG_STATE; } if (answer == NULL) { i = -1; if (status > 199 && status < 300) i = _eXosip_build_response_default (&answer, NULL, status, tr->orig_request); else if (status > 300 && status <= 699) i = _eXosip_build_response_default (&answer, NULL, status, tr->orig_request); if (i != 0) return i; } evt_answer = osip_new_outgoing_sipmessage (answer); evt_answer->transactionid = tr->transactionid; osip_transaction_add_event (tr, evt_answer); __eXosip_wakeup (); return OSIP_SUCCESS; }
// 发送响应消息 int GB_Send_Response(GB_CONNECT_STATE *gb_cons, void *cmd_struct, gb_CommandType_enum cmdType, osip_call_id_t **call_id) { osip_message_t *reg = NULL; PRM_GB_SIPD_CFG gb_cfg; char to[GB_URI_MAX_LEN] = {0}; char from[GB_URI_MAX_LEN] = {0}; char proxy[GB_URI_MAX_LEN] = {0}; int ret; char *result = NULL; size_t length; char localip[20]; char sipserver_ip[20] = {0}; SN_MEMSET(&gb_cfg, 0, sizeof(gb_cfg)); GB_Get_GBCfg(&gb_cfg); SN_MEMSET(localip,0,sizeof(localip)); SN_STRCPY(localip,sizeof(localip),GB_Get_LocalIP()); SN_SPRINTF(sipserver_ip,sizeof(sipserver_ip),"%d.%d.%d.%d", gb_cfg.sipserver_ip[0],gb_cfg.sipserver_ip[1],gb_cfg.sipserver_ip[2],gb_cfg.sipserver_ip[3]); SN_SPRINTF(from, GB_URI_MAX_LEN, "sip:%s@%s", gb_cfg.deviceID, localip); SN_SPRINTF(to, GB_URI_MAX_LEN, "sip:%s@%s", gb_cfg.sipserver_ID, sipserver_ip); SN_SPRINTF(proxy, GB_URI_MAX_LEN, "sip:%s@%s:%d", gb_cfg.sipserver_ID,sipserver_ip, gb_cfg.sipserver_port); ret = gb_generating_MESSAGE(®, Transport_Str[gb_cons->transfer_protocol], from, to, proxy, localip,gb_cfg.local_port, gb_cons->local_cseq, (void *)cmd_struct, cmdType); if (ret < 0) { osip_message_free (reg); printf("%s line=%d\n",__FUNCTION__,__LINE__); return -1; } if(call_id != NULL) { osip_call_id_clone(reg->call_id,call_id); } ret = osip_message_to_str(reg, &result, &length); if (ret == -1) { printf("ERROR: failed while printing message!\n"); osip_message_free (reg); return -1; } gb_cons->local_cseq++; GB_SocketSendData(gb_cons->connfd,inet_ntoa(gb_cons->remoteAddr.sin_addr), ntohs(gb_cons->remoteAddr.sin_port), result, length, 0); SN_FREE(result); osip_message_free(reg); return 0; }
int eXosip_subscribe_send_refresh_request (struct eXosip_t *excontext, int did, osip_message_t * sub) { eXosip_dialog_t *jd = NULL; eXosip_subscribe_t *js = NULL; osip_transaction_t *transaction; osip_event_t *sipevent; int i; if (did <= 0) return OSIP_BADPARAMETER; if (did > 0) { _eXosip_subscribe_dialog_find (excontext, did, &js, &jd); } if (jd == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No subscribe here?\n")); osip_message_free (sub); return OSIP_NOTFOUND; } transaction = NULL; transaction = _eXosip_find_last_out_subscribe (js, jd); if (transaction != NULL) { if (transaction->state != NICT_TERMINATED && transaction->state != NIST_TERMINATED && transaction->state != NICT_COMPLETED && transaction->state != NIST_COMPLETED) { osip_message_free (sub); return OSIP_WRONG_STATE; } transaction = NULL; } transaction = NULL; i = _eXosip_transaction_init (excontext, &transaction, NICT, excontext->j_osip, sub); if (i != 0) { osip_message_free (sub); return i; } js->s_reg_period = 3600; _eXosip_subscribe_set_refresh_interval (js, sub); osip_list_add (jd->d_out_trs, transaction, 0); sipevent = osip_new_outgoing_sipmessage (sub); sipevent->transactionid = transaction->transactionid; osip_transaction_set_reserved5 (transaction, js); osip_transaction_set_reserved3 (transaction, jd); osip_transaction_add_event (transaction, sipevent); _eXosip_wakeup (excontext); return OSIP_SUCCESS; }
int GB_sipd_register(GB_CONNECT_STATE *gb_cons, int flag) { osip_message_t *reg = NULL; PRM_GB_SIPD_CFG gb_cfg; char from[GB_URI_MAX_LEN] = {0}; char proxy[GB_URI_MAX_LEN] = {0}; int ret; char *result = NULL; size_t length; char localip[20]; char sipserver_ip[20] = {0}; SN_MEMSET(&gb_cfg, 0, sizeof(gb_cfg)); GB_Get_GBCfg(&gb_cfg); SN_MEMSET(localip,0,sizeof(localip)); SN_STRCPY(localip,sizeof(localip),GB_Get_LocalIP()); SN_SPRINTF(sipserver_ip,sizeof(sipserver_ip),"%d.%d.%d.%d", gb_cfg.sipserver_ip[0],gb_cfg.sipserver_ip[1],gb_cfg.sipserver_ip[2],gb_cfg.sipserver_ip[3]); SN_SPRINTF(from, GB_URI_MAX_LEN, "sip:%s@%s", gb_cfg.deviceID, localip); SN_SPRINTF(proxy, GB_URI_MAX_LEN, "sip:%s@%s:%d", gb_cfg.sipserver_ID,sipserver_ip, gb_cfg.sipserver_port); if(flag == 0) // 注册 { ret = gb_generating_register(®, Transport_Str[gb_cons->transfer_protocol], from, proxy, NULL, gb_cfg.register_period, localip,gb_cfg.local_port, gb_cons->local_cseq); } else // 注销 { ret = gb_generating_register(®, Transport_Str[gb_cons->transfer_protocol], from, proxy, NULL, 0, localip,gb_cfg.local_port, gb_cons->local_cseq); } if (ret < 0) { osip_message_free (reg); return -1; } //printf("gb_cons->callID:%s\n", gb_cons->callID); ret = osip_message_to_str(reg, &result, &length); if (ret == -1) { printf("ERROR: failed while printing message!\n"); osip_message_free (reg); return -1; } gb_cons->local_cseq++; GB_SocketSendData(gb_cons->connfd,inet_ntoa(gb_cons->remoteAddr.sin_addr), ntohs(gb_cons->remoteAddr.sin_port), result, length, 0); SN_FREE(result); osip_message_free(reg); return 0; }
void eXosip_event_free (eXosip_event_t * je) { if (je == NULL) return; if (je->request != NULL) osip_message_free (je->request); if (je->response != NULL) osip_message_free (je->response); if (je->ack != NULL) osip_message_free (je->ack); osip_free (je); }
int eXosip_call_send_initial_invite (osip_message_t * invite) { eXosip_call_t *jc; osip_transaction_t *transaction; osip_event_t *sipevent; int i; if (invite == NULL) { osip_message_free (invite); return OSIP_BADPARAMETER; } i = eXosip_call_init (&jc); if (i != 0) { osip_message_free (invite); return i; } i = _eXosip_transaction_init (&transaction, ICT, eXosip.j_osip, invite); if (i != 0) { eXosip_call_free (jc); osip_message_free (invite); return i; } jc->c_out_tr = transaction; sipevent = osip_new_outgoing_sipmessage (invite); sipevent->transactionid = transaction->transactionid; #ifndef MINISIZE osip_transaction_set_your_instance (transaction, __eXosip_new_jinfo (jc, NULL, NULL, NULL)); #else osip_transaction_set_your_instance (transaction, __eXosip_new_jinfo (jc, NULL)); #endif osip_transaction_add_event (transaction, sipevent); jc->external_reference = NULL; ADD_ELEMENT (eXosip.j_calls, jc); eXosip_update (); /* fixed? */ __eXosip_wakeup (); return jc->c_id; }
/*presence Subscribe/notify*/ int sal_subscribe_presence(SalOp *op, const char *from, const char *to){ osip_message_t *msg=NULL; if (from) sal_op_set_from(op,from); if (to) sal_op_set_to(op,to); sal_exosip_fix_route(op); eXosip_lock(); eXosip_subscribe_build_initial_request(&msg,sal_op_get_to(op),sal_op_get_from(op), sal_op_get_route(op),"presence",600); if (msg==NULL){ ms_error("Could not build subscribe request to %s",to); eXosip_unlock(); return -1; } if (op->base.contact){ _osip_list_set_empty(&msg->contacts,(void (*)(void*))osip_contact_free); osip_message_set_contact(msg,op->base.contact); } op->sid=eXosip_subscribe_send_initial_request(msg); eXosip_unlock(); if (op->sid==-1){ osip_message_free(msg); return -1; } sal_add_out_subscribe(op->base.root,op); return 0; }
void nict_rcv_23456xx (osip_transaction_t * nict, osip_event_t * evt) { /* leave this answer to the core application */ if (nict->last_response != NULL) { osip_message_free (nict->last_response); } nict->last_response = evt->sip; if (EVT_IS_RCV_STATUS_2XX (evt)) __osip_message_callback (OSIP_NICT_STATUS_2XX_RECEIVED, nict, nict->last_response); else if (MSG_IS_STATUS_3XX (nict->last_response)) __osip_message_callback (OSIP_NICT_STATUS_3XX_RECEIVED, nict, nict->last_response); else if (MSG_IS_STATUS_4XX (nict->last_response)) __osip_message_callback (OSIP_NICT_STATUS_4XX_RECEIVED, nict, nict->last_response); else if (MSG_IS_STATUS_5XX (nict->last_response)) __osip_message_callback (OSIP_NICT_STATUS_5XX_RECEIVED, nict, nict->last_response); else __osip_message_callback (OSIP_NICT_STATUS_6XX_RECEIVED, nict, nict->last_response); if (nict->state != NICT_COMPLETED) /* reset timer K */ { osip_gettimeofday (&nict->nict_context->timer_k_start, NULL); add_gettimeofday (&nict->nict_context->timer_k_start, nict->nict_context->timer_k_length); } __osip_transaction_set_state (nict, NICT_COMPLETED); }
static int eXosip_create_transaction (eXosip_call_t * jc, eXosip_dialog_t * jd, osip_message_t * request) { osip_event_t *sipevent; osip_transaction_t *tr; int i; i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, request); if (i != 0) { /* TODO: release the j_call.. */ osip_message_free (request); return i; } if (jd != NULL) osip_list_add (jd->d_out_trs, tr, 0); sipevent = osip_new_outgoing_sipmessage (request); sipevent->transactionid = tr->transactionid; #ifndef MINISIZE osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (jc, jd, NULL, NULL)); #else osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (jc, jd)); #endif osip_transaction_add_event (tr, sipevent); __eXosip_wakeup (); return OSIP_SUCCESS; }
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; }
static int eXosip_create_cancel_transaction (eXosip_call_t * jc, eXosip_dialog_t * jd, osip_message_t * request) { osip_event_t *sipevent; osip_transaction_t *tr; int i; i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, request); if (i != 0) { /* TODO: release the j_call.. */ osip_message_free (request); return i; } osip_list_add (&eXosip.j_transactions, tr, 0); sipevent = osip_new_outgoing_sipmessage (request); sipevent->transactionid = tr->transactionid; osip_transaction_add_event (tr, sipevent); __eXosip_wakeup (); return OSIP_SUCCESS; }
int eXosip_message_send_request (osip_message_t * message) { osip_transaction_t *transaction; osip_event_t *sipevent; int i; i = _eXosip_transaction_init (&transaction, NICT, eXosip.j_osip, message); if (i != 0) { osip_message_free (message); return -1; } osip_list_add (eXosip.j_transactions, transaction, 0); sipevent = osip_new_outgoing_sipmessage (message); sipevent->transactionid = transaction->transactionid; #ifndef MINISIZE osip_transaction_set_your_instance (transaction, __eXosip_new_jinfo (NULL, NULL, NULL, NULL)); #else osip_transaction_set_your_instance (transaction, __eXosip_new_jinfo (NULL, NULL)); #endif osip_transaction_add_event (transaction, sipevent); __eXosip_wakeup (); return 0; }
void ist_snd_3456xx (osip_transaction_t * ist, osip_event_t * evt) { int i; if (ist->last_response != NULL) { osip_message_free (ist->last_response); } ist->last_response = evt->sip; i = __osip_transaction_snd_xxx (ist, evt->sip); if (i != 0) { ist_handle_transport_error (ist, i); return; } else { if (MSG_IS_STATUS_3XX (ist->last_response)) __osip_message_callback (OSIP_IST_STATUS_3XX_SENT, ist, ist->last_response); else if (MSG_IS_STATUS_4XX (ist->last_response)) __osip_message_callback (OSIP_IST_STATUS_4XX_SENT, ist, ist->last_response); else if (MSG_IS_STATUS_5XX (ist->last_response)) __osip_message_callback (OSIP_IST_STATUS_5XX_SENT, ist, ist->last_response); else __osip_message_callback (OSIP_IST_STATUS_6XX_SENT, ist, ist->last_response); } if (ist->ist_context->timer_g_length != -1) { osip_gettimeofday (&ist->ist_context->timer_g_start, NULL); add_gettimeofday (&ist->ist_context->timer_g_start, ist->ist_context->timer_g_length); } osip_gettimeofday (&ist->ist_context->timer_h_start, NULL); add_gettimeofday (&ist->ist_context->timer_h_start, ist->ist_context->timer_h_length); __osip_transaction_set_state (ist, IST_COMPLETED); return; }
/* * SIP_GEN_RESPONSE * * send an proxy generated response back to the client. * Only errors are reported from the proxy itself. * code = SIP result code to deliver * * RETURNS * STS_SUCCESS on success * STS_FAILURE on error */ int sip_gen_response(sip_ticket_t *ticket, int code) { osip_message_t *response; int sts; osip_via_t *via; int port; char *buffer; size_t buflen; struct in_addr addr; /* create the response template */ if ((response=msg_make_template_reply(ticket, code))==NULL) { ERROR("sip_gen_response: error in msg_make_template_reply"); return STS_FAILURE; } /* we must check if first via has x.x.x.x address. If not, we must resolve it */ osip_message_get_via (response, 0, &via); if (via == NULL) { ERROR("sip_gen_response: Cannot send response - no via field"); return STS_FAILURE; } /* name resolution */ if (utils_inet_aton(via->host, &addr) == 0) { /* need name resolution */ DEBUGC(DBCLASS_DNS,"resolving name:%s",via->host); sts = get_ip_by_host(via->host, &addr); if (sts == STS_FAILURE) { DEBUGC(DBCLASS_PROXY, "sip_gen_response: cannot resolve via [%s]", via->host); return STS_FAILURE; } } sts = sip_message_to_str(response, &buffer, &buflen); if (sts != 0) { ERROR("sip_gen_response: msg_2char failed"); return STS_FAILURE; } if (via->port) { port=atoi(via->port); } else { port=SIP_PORT; } /* send to destination */ sipsock_send(addr, port, ticket->protocol, buffer, buflen); /* free the resources */ osip_message_free(response); osip_free(buffer); return STS_SUCCESS; }
int _eXosip2_answer_invite_2xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code, osip_message_t **answer) { int i; osip_transaction_t *tr; tr = eXosip_find_last_inc_invite(jc, jd); if (tr==NULL || tr->orig_request==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot find transaction to answer\n")); return -1; } if (jd!=NULL && jd->d_dialog==NULL) { /* element previously removed */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot answer this closed transaction\n")); return -1; } /* is the transaction already answered? */ if (tr->state==IST_COMPLETED || tr->state==IST_CONFIRMED || tr->state==IST_TERMINATED) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: transaction already answered\n")); return -1; } if (jd==NULL) i = _eXosip_build_response_default(answer, NULL, code, tr->orig_request); else i = _eXosip_build_response_default(answer, jd->d_dialog, code, tr->orig_request); if (i!=0) { OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for invite\n")); return -1; } /* request that estabish a dialog: */ /* 12.1.1 UAS Behavior */ i = complete_answer_that_establish_a_dialog(*answer, tr->orig_request); if (i!=0) goto g2atii_error_1;; /* ?? */ return 0; g2atii_error_1: osip_message_free(*answer); return -1; }
void ict_rcv_1xx(osip_transaction_t * ict, osip_event_t * evt) { /* leave this answer to the core application */ if (ict->last_response != NULL) { osip_message_free(ict->last_response); } ict->last_response = evt->sip; __osip_message_callback(OSIP_ICT_STATUS_1XX_RECEIVED, ict, evt->sip); __osip_transaction_set_state(ict, ICT_PROCEEDING); }
void ict_rcv_2xx(osip_transaction_t * ict, osip_event_t * evt) { /* leave this answer to the core application */ if (ict->last_response != NULL) { osip_message_free(ict->last_response); } ict->last_response = evt->sip; __osip_message_callback(OSIP_ICT_STATUS_2XX_RECEIVED, ict, evt->sip); __osip_transaction_set_state(ict, ICT_TERMINATED); __osip_kill_transaction_callback(OSIP_ICT_KILL_TRANSACTION, ict); }
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; }
int eXosip_subscribe_send_initial_request (struct eXosip_t *excontext, osip_message_t * subscribe) { eXosip_subscribe_t *js = NULL; osip_transaction_t *transaction; osip_event_t *sipevent; int i; i = _eXosip_subscribe_init (&js); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot subscribe.")); osip_message_free (subscribe); return i; } i = _eXosip_transaction_init (excontext, &transaction, NICT, excontext->j_osip, subscribe); if (i != 0) { _eXosip_subscribe_free (excontext, js); osip_message_free (subscribe); return i; } js->s_reg_period = 3600; _eXosip_subscribe_set_refresh_interval (js, subscribe); js->s_out_tr = transaction; sipevent = osip_new_outgoing_sipmessage (subscribe); sipevent->transactionid = transaction->transactionid; osip_transaction_set_reserved5 (transaction, js); osip_transaction_add_event (transaction, sipevent); ADD_ELEMENT (excontext->j_subscribes, js); _eXosip_update (excontext); /* fixed? */ _eXosip_wakeup (excontext); return js->s_id; }
int _eXosip_dialog_set_200ok (eXosip_dialog_t * jd, osip_message_t * _200Ok) { int i; if (jd == NULL) return OSIP_BADPARAMETER; if (jd->d_200Ok != NULL) osip_message_free (jd->d_200Ok); jd->d_timer = osip_getsystemtime (NULL) + 1; jd->d_count = 0; i = osip_message_clone (_200Ok, &(jd->d_200Ok)); if (i != 0) return i; return OSIP_SUCCESS; }
int eXosip_dialog_set_200ok (eXosip_dialog_t * jd, osip_message_t * _200Ok) { int i; if (jd == NULL) return -1; if (jd->d_200Ok!=NULL) osip_message_free(jd->d_200Ok); i = osip_message_clone (_200Ok, &(jd->d_200Ok)); if (i != 0) { return -1; } return 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; }
void ist_rcv_ack (osip_transaction_t * ist, osip_event_t * evt) { if (ist->ack != NULL) { osip_message_free (ist->ack); } ist->ack = evt->sip; if (ist->state == IST_COMPLETED) __osip_message_callback (OSIP_IST_ACK_RECEIVED, ist, ist->ack); else /* IST_CONFIRMED */ __osip_message_callback (OSIP_IST_ACK_RECEIVED_AGAIN, ist, ist->ack); /* set the timer to 0 for reliable, and T4 for unreliable (already set) */ osip_gettimeofday (&ist->ist_context->timer_i_start, NULL); add_gettimeofday (&ist->ist_context->timer_i_start, ist->ist_context->timer_i_length); __osip_transaction_set_state (ist, IST_CONFIRMED); }
/* Get SIP message of the call leg */ osip_message_t *eXosipua_extract_message(eXosipua_t *jua, eXosip_event_t *je) { osip_message_t *message; if(osip_message_init(&message) != 0) { jua_debug(("eXosipua_extract_message: init sip body error\n")); return NULL; } if(osip_message_parse(message, je->sdp_body, strlen(je->sdp_body)) != 0) { osip_message_free(message); return NULL; } return message; }
void nist_snd_23456xx (osip_transaction_t * nist, osip_event_t * evt) { int i; if (nist->last_response != NULL) { osip_message_free (nist->last_response); } nist->last_response = evt->sip; i = __osip_transaction_snd_xxx(nist, nist->last_response); if (i != 0) { nist_handle_transport_error (nist, i); return; } else { if (EVT_IS_SND_STATUS_2XX (evt)) __osip_message_callback (OSIP_NIST_STATUS_2XX_SENT, nist, nist->last_response); else if (MSG_IS_STATUS_3XX (nist->last_response)) __osip_message_callback (OSIP_NIST_STATUS_3XX_SENT, nist, nist->last_response); else if (MSG_IS_STATUS_4XX (nist->last_response)) __osip_message_callback (OSIP_NIST_STATUS_4XX_SENT, nist, nist->last_response); else if (MSG_IS_STATUS_5XX (nist->last_response)) __osip_message_callback (OSIP_NIST_STATUS_5XX_SENT, nist, nist->last_response); else __osip_message_callback (OSIP_NIST_STATUS_6XX_SENT, nist, nist->last_response); } if (nist->state != NIST_COMPLETED) /* start J timer */ { osip_gettimeofday (&nist->nist_context->timer_j_start, NULL); add_gettimeofday (&nist->nist_context->timer_j_start, nist->nist_context->timer_j_length); } __osip_transaction_set_state (nist, NIST_COMPLETED); }
int BuildResponse(const osip_message_t *request, osip_message_t **response) { osip_message_t *msg = NULL; char port[6]; char* pContact = osip_malloc(strlen(SERV_IP_ADDR) + strlen(USER_NAME) + sizeof(port) + 7 + 10 ); // 7 is "sip:...@..:. \0" 10 - zapas osip_message_init(&msg); osip_from_clone(request->from, &msg->from); osip_to_clone(request->to, &msg->to); osip_cseq_clone(request->cseq, &msg->cseq); osip_call_id_clone(request->call_id, &msg->call_id); int pos = 0;//copy vias from request to response while (!osip_list_eol(&request->vias, pos)) { osip_via_t *via; osip_via_t *via2; via = (osip_via_t *) osip_list_get(&request->vias, pos); int i = osip_via_clone(via, &via2); if (i != 0) { osip_message_free(msg); return i; } osip_list_add(&(msg->vias), via2, -1); pos++; } osip_message_set_max_forwards(msg, osip_strdup("70")); osip_to_set_tag(msg->to, osip_strdup("4893693")); // set to tag in response. todo: randomize osip_message_set_version(msg, osip_strdup("SIP/2.0")); // create contact strcat(pContact, osip_strdup("sip:")); strcat(pContact, osip_strdup(USER_NAME)); strcat(pContact, osip_strdup("@")); strcat(pContact, osip_strdup(SERV_IP_ADDR)); osip_message_set_contact(msg, osip_strdup(pContact)); osip_free(pContact); osip_message_set_user_agent(msg, osip_strdup("SipMore/0.1")); *response = msg; return 0; }
void eXosip_retransmit_lost200ok() { eXosip_call_t *jc; eXosip_dialog_t *jd; time_t now; now = time (NULL); for (jc = eXosip.j_calls; jc != NULL; jc = jc->next) { if (jc->c_id >= 1 && jc->c_dialogs != NULL) { for (jd = jc->c_dialogs; jd != NULL; jd = jd->next) { if (jd->d_id >=1 && jd->d_dialog != NULL && jd->d_200Ok!=NULL) { if (jd->d_count==5) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: no ACK received during 20s: dropping call\n")); /* hard for users to detect than I sent this BYE... */ jd->d_count=0; osip_message_free(jd->d_200Ok); jd->d_200Ok=NULL; eXosip_call_terminate(jc->c_id, jd->d_id); } else if (jd->d_timer<now) { /* a dialog exist: retransmit lost 200ok */ jd->d_timer = time (NULL) + 4; jd->d_count++; jd = jc->c_dialogs; /* TU retransmission */ cb_snd_message (NULL, jd->d_200Ok, NULL,0, -1); } } } } } return; }
void nist_snd_1xx(osip_transaction_t * nist, osip_event_t * evt) { int i; if (nist->last_response != NULL) { osip_message_free(nist->last_response); } nist->last_response = evt->sip; i = __osip_transaction_snd_xxx(nist, nist->last_response); if (i != 0) { nist_handle_transport_error(nist, i); return; } else __osip_message_callback(OSIP_NIST_STATUS_1XX_SENT, nist, nist->last_response); __osip_transaction_set_state(nist, NIST_PROCEEDING); }
void nict_rcv_1xx (osip_transaction_t * nict, osip_event_t * evt) { /* leave this answer to the core application */ if (nict->last_response != NULL) { osip_message_free (nict->last_response); } nict->last_response = evt->sip; /* for unreliable transport increase the retransmission timeout */ if (nict->nict_context->timer_e_length > 0) { nict->nict_context->timer_e_length = DEFAULT_T2; osip_gettimeofday (&nict->nict_context->timer_e_start, NULL); add_gettimeofday (&nict->nict_context->timer_e_start, nict->nict_context->timer_e_length); } __osip_message_callback (OSIP_NICT_STATUS_1XX_RECEIVED, nict, evt->sip); __osip_transaction_set_state (nict, NICT_PROCEEDING); }