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; }
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; }
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_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_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 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; }
int eXosip_options_send_request(struct eXosip_t *excontext, osip_message_t * options) { osip_transaction_t *transaction; osip_event_t *sipevent; int i; i = _eXosip_transaction_init(excontext, &transaction, NICT, excontext->j_osip, options); if (i != 0) { osip_message_free(options); return i; } osip_list_add(&excontext->j_transactions, transaction, 0); sipevent = osip_new_outgoing_sipmessage(options); sipevent->transactionid = transaction->transactionid; osip_transaction_add_event(transaction, sipevent); _eXosip_wakeup(excontext); return OSIP_SUCCESS; }
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_call_send_request (int jid, osip_message_t * request) { eXosip_dialog_t *jd = NULL; eXosip_call_t *jc = NULL; osip_transaction_t *transaction; osip_event_t *sipevent; int i; if (request == NULL) return OSIP_BADPARAMETER; if (jid <= 0) { osip_message_free (request); return OSIP_BADPARAMETER; } if (request->sip_method == NULL) { osip_message_free (request); return OSIP_BADPARAMETER; } if (jid > 0) { eXosip_call_dialog_find (jid, &jc, &jd); } if (jd == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No call here?\n")); osip_message_free (request); return OSIP_NOTFOUND; } transaction = NULL; if (0 == osip_strcasecmp (request->sip_method, "INVITE")) { transaction = eXosip_find_last_invite (jc, jd); } else /* OPTIONS, UPDATE, INFO, REFER, ?... */ { transaction = eXosip_find_last_transaction (jc, jd, request->sip_method); } if (transaction != NULL) { if (0 != osip_strcasecmp (request->sip_method, "INVITE")) { if (transaction->state != NICT_TERMINATED && transaction->state != NIST_TERMINATED && transaction->state != NICT_COMPLETED && transaction->state != NIST_COMPLETED) { osip_message_free (request); return OSIP_WRONG_STATE; } } else { if (transaction->state != ICT_TERMINATED && transaction->state != IST_TERMINATED && transaction->state != IST_CONFIRMED && transaction->state != ICT_COMPLETED) { osip_message_free (request); return OSIP_WRONG_STATE; } } } transaction = NULL; if (0 != osip_strcasecmp (request->sip_method, "INVITE")) { i = _eXosip_transaction_init (&transaction, NICT, eXosip.j_osip, request); } else { i = _eXosip_transaction_init (&transaction, ICT, eXosip.j_osip, request); } if (i != 0) { osip_message_free (request); return i; } osip_list_add (jd->d_out_trs, transaction, 0); sipevent = osip_new_outgoing_sipmessage (request); sipevent->transactionid = transaction->transactionid; #ifndef MINISIZE osip_transaction_set_your_instance (transaction, __eXosip_new_jinfo (jc, jd, NULL, NULL)); #else osip_transaction_set_your_instance (transaction, __eXosip_new_jinfo (jc, jd)); #endif osip_transaction_add_event (transaction, sipevent); __eXosip_wakeup (); return OSIP_SUCCESS; }
int _eXosip_call_retry_request (eXosip_call_t * jc, 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; osip_contact_t *co; int pos; int i; int protocol = IPPROTO_UDP; if (jc == NULL) return OSIP_BADPARAMETER; if (jd != NULL) { if (jd->d_out_trs == NULL) return OSIP_BADPARAMETER; } if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL) return OSIP_BADPARAMETER; i = osip_message_clone (out_tr->orig_request, &msg); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone msg for authentication\n")); return i; } 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 OSIP_SYNTAXERROR; } if (MSG_IS_STATUS_3XX (out_tr->last_response)) { co = NULL; pos = 0; while (!osip_list_eol (&out_tr->last_response->contacts, pos)) { co = (osip_contact_t *) osip_list_get (&out_tr->last_response->contacts, pos); if (co != NULL && co->url != NULL) { /* check tranport? Only allow UDP, right now */ osip_uri_param_t *u_param; int pos2; u_param = NULL; pos2 = 0; while (!osip_list_eol (&co->url->url_params, pos2)) { u_param = (osip_uri_param_t *) osip_list_get (&co->url->url_params, pos2); if (u_param == NULL || u_param->gname == NULL || u_param->gvalue == NULL) { u_param = NULL; /* skip */ } else if (0 == osip_strcasecmp (u_param->gname, "transport")) { if (0 == osip_strcasecmp (u_param->gvalue, "udp")) { u_param = NULL; protocol = IPPROTO_UDP; break; /* ok */ } else if (0 == osip_strcasecmp (u_param->gvalue, "tcp")) { protocol = IPPROTO_TCP; u_param = NULL; } break; } pos2++; } if (u_param == NULL || u_param->gname == NULL || u_param->gvalue == NULL) { break; /* default is udp! */ } } pos++; co = NULL; } if (co == NULL || co->url == NULL) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: contact header\n")); return OSIP_SYNTAXERROR; } /* TODO: remove extra parameter from new request-uri check usual parameter like "transport" */ if (msg->req_uri != NULL && msg->req_uri->host != NULL && co->url->host != NULL && 0 == osip_strcasecmp (co->url->host, msg->req_uri->host)) { osip_uri_param_t *maddr_param = NULL; osip_uri_uparam_get_byname (co->url, "maddr", &maddr_param); if (maddr_param != NULL && maddr_param->gvalue != NULL) { /* This is a redirect server, the route should probably be removed? */ osip_route_t *route = NULL; osip_generic_param_t *tag = NULL; osip_message_get_route (msg, 0, &route); if (route != NULL) { osip_to_get_tag (msg->to, &tag); if (tag == NULL && route != NULL && route->url != NULL) { osip_list_remove (&msg->routes, 0); osip_route_free (route); } } } } /* replace request-uri with NEW contact address */ osip_uri_free (msg->req_uri); msg->req_uri = NULL; osip_uri_clone (co->url, &msg->req_uri); /* support for diversions headers/draft! */ { int count = 0; pos = 0; while (!osip_list_eol (&out_tr->last_response->headers, pos)) { osip_header_t *copy = NULL; osip_header_t *head = osip_list_get (&out_tr->last_response->headers, pos); if (head != NULL && 0 == osip_strcasecmp (head->hname, "diversion")) { i = osip_header_clone (head, ©); if (i == 0) { osip_list_add (&msg->headers, copy, count); count++; } } pos++; } } } /* remove all previous authentication headers */ osip_list_special_free (&msg->authorizations, (void *(*)(void *)) &osip_authorization_free); osip_list_special_free (&msg->proxy_authorizations, (void *(*)(void *)) &osip_proxy_authorization_free); /* 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); return i; } if (out_tr->last_response->status_code == 401 || out_tr->last_response->status_code == 407) eXosip_add_authentication_information (msg, out_tr->last_response); else eXosip_add_authentication_information (msg, NULL); osip_message_force_update (msg); if (0 != osip_strcasecmp (msg->sip_method, "INVITE")) { i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg); } else { i = _eXosip_transaction_init (&tr, ICT, eXosip.j_osip, msg); } if (i != 0) { osip_message_free (msg); return i; } if (out_tr == jc->c_out_tr) { /* replace with the new tr */ osip_list_add (&eXosip.j_transactions, jc->c_out_tr, 0); jc->c_out_tr = tr; /* fix dialog issue */ if (jd != NULL) { REMOVE_ELEMENT (jc->c_dialogs, jd); eXosip_dialog_free (jd); jd = NULL; } } else { /* add the new tr for the current dialog */ osip_list_add (jd->d_out_trs, tr, 0); } sipevent = osip_new_outgoing_sipmessage (msg); #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_update (); /* fixed? */ __eXosip_wakeup (); return OSIP_SUCCESS; }
int eXosip_call_send_prack (int tid, osip_message_t * prack) { eXosip_dialog_t *jd = NULL; eXosip_call_t *jc = NULL; osip_transaction_t *tr = NULL; osip_event_t *sipevent; int i; if (tid < 0) return OSIP_BADPARAMETER; if (prack == NULL) return OSIP_BADPARAMETER; if (tid > 0) { _eXosip_call_transaction_find (tid, &jc, &jd, &tr); } if (jc == NULL || jd == NULL || jd->d_dialog == NULL || tr == NULL || tr->orig_request == NULL || tr->orig_request->sip_method == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No call here or no transaction for call\n")); osip_message_free (prack); return OSIP_NOTFOUND; } if (0 != osip_strcasecmp (tr->orig_request->sip_method, "INVITE")) { osip_message_free (prack); return OSIP_BADPARAMETER; } /* PRACK are only send in the PROCEEDING state */ if (tr->state != ICT_PROCEEDING) { osip_message_free (prack); return OSIP_WRONG_STATE; } tr = NULL; i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, prack); if (i != 0) { osip_message_free (prack); return i; } jd->d_mincseq++; osip_list_add (jd->d_out_trs, tr, 0); sipevent = osip_new_outgoing_sipmessage (prack); 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_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 OSIP_BADPARAMETER; if (did <= 0) { osip_message_free (request); return OSIP_BADPARAMETER; } 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 OSIP_NOTFOUND; } 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 OSIP_WRONG_STATE; } transaction = NULL; } i = _eXosip_transaction_init (&transaction, NICT, eXosip.j_osip, request); if (i != 0) { osip_message_free (request); return i; } 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 OSIP_SUCCESS; }
int _eXosip_subscribe_send_request_with_credential (struct eXosip_t *excontext, eXosip_subscribe_t * js, 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 (js == NULL) return OSIP_BADPARAMETER; if (jd != NULL) { if (jd->d_out_trs == NULL) return OSIP_BADPARAMETER; } if (out_tr == NULL) { out_tr = _eXosip_find_last_out_subscribe (js, jd); } if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL) return OSIP_NOTFOUND; i = osip_message_clone (out_tr->orig_request, &msg); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone msg for authentication\n")); return i; } { osip_generic_param_t *tag = NULL; osip_to_get_tag (msg->to, &tag); if (NULL == tag && jd != NULL && jd->d_dialog != NULL && jd->d_dialog->remote_tag != NULL) { osip_to_set_tag (msg->to, osip_strdup (jd->d_dialog->remote_tag)); } } 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 OSIP_SYNTAXERROR; } /* increment cseq */ cseq = atoi (msg->cseq->number); osip_free (msg->cseq->number); msg->cseq->number = _eXosip_strdup_printf ("%i", cseq + 1); if (msg->cseq->number == NULL) { osip_message_free (msg); return OSIP_NOMEM; } 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); return i; } osip_list_special_free (&msg->authorizations, (void (*)(void *)) &osip_authorization_free); osip_list_special_free (&msg->proxy_authorizations, (void (*)(void *)) &osip_proxy_authorization_free); if (out_tr->last_response->status_code == 401 || out_tr->last_response->status_code == 407) { _eXosip_add_authentication_information (excontext, msg, out_tr->last_response); } else _eXosip_add_authentication_information (excontext, msg, NULL); if (out_tr != NULL && out_tr->last_response != NULL && out_tr->last_response->status_code == 423) { /* increase expires value to "min-expires" value */ osip_header_t *exp; osip_header_t *min_exp; osip_message_header_get_byname (msg, "expires", 0, &exp); osip_message_header_get_byname (out_tr->last_response, "min-expires", 0, &min_exp); if (exp != NULL && exp->hvalue != NULL && min_exp != NULL && min_exp->hvalue != NULL) { osip_free (exp->hvalue); exp->hvalue = osip_strdup (min_exp->hvalue); } else { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing Min-Expires or Expires in PUBLISH\n")); return OSIP_SYNTAXERROR; } } osip_message_force_update (msg); i = _eXosip_transaction_init (excontext, &tr, NICT, excontext->j_osip, msg); if (i != 0) { osip_message_free (msg); return i; } if (out_tr == js->s_out_tr) { /* replace with the new tr */ osip_list_add (&excontext->j_transactions, js->s_out_tr, 0); js->s_out_tr = tr; } else { /* 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_reserved5 (tr, js); osip_transaction_set_reserved3 (tr, jd); osip_transaction_add_event (tr, sipevent); _eXosip_update (excontext); /* fixed? */ _eXosip_wakeup (excontext); return OSIP_SUCCESS; }
static int eXosip_create_cancel_transaction(eXosip_call_t * jc, eXosip_dialog_t * jd, osip_message_t * request MARGS); static int _eXosip_call_reuse_contact(osip_message_t * invite, osip_message_t * msg MARGS); static int eXosip_create_transaction(eXosip_call_t * jc, eXosip_dialog_t * jd, osip_message_t * request MARGS) { osip_event_t *sipevent; osip_transaction_t *tr; int i; i = _eXosip_transaction_init(&tr, NICT, eXosip.j_osip, request MPARAMS); 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 MPARAMS));
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 OSIP_BADPARAMETER; if (jd != NULL) { if (jd->d_out_trs == NULL) return OSIP_BADPARAMETER; } 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 OSIP_NOTFOUND; i = osip_message_clone (out_tr->orig_request, &msg); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone msg for authentication\n")); return i; } 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 OSIP_SYNTAXERROR; } /* increment cseq */ cseq = atoi (msg->cseq->number); osip_free (msg->cseq->number); msg->cseq->number = strdup_printf ("%i", cseq + 1); if (msg->cseq->number == NULL) { osip_message_free (msg); return OSIP_NOMEM; } 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 i; } if (out_tr->last_response->status_code == 401 || out_tr->last_response->status_code == 407) eXosip_add_authentication_information (msg, out_tr->last_response); else eXosip_add_authentication_information (msg, NULL); osip_message_force_update (msg); i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg); if (i != 0) { osip_message_free (msg); return i; } /* 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 OSIP_SUCCESS; }
static int _eXosip_retry_with_auth (eXosip_dialog_t * jd, osip_transaction_t ** ptr, int *retry) { osip_transaction_t *out_tr = NULL; osip_transaction_t *tr = NULL; osip_message_t *msg = NULL; osip_event_t *sipevent; jinfo_t *ji = NULL; int cseq; osip_via_t *via; int i; if (!ptr) return -1; if (jd != NULL) { if (jd->d_out_trs == NULL) return -1; } out_tr = *ptr; if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL) return -1; if (retry && (*retry >= 3)) 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; } if (eXosip_add_authentication_information (msg, out_tr->last_response) < 0) { osip_message_free (msg); return -1; } osip_message_force_update (msg); if (MSG_IS_INVITE (msg)) i = _eXosip_transaction_init (&tr, ICT, eXosip.j_osip, msg); else i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg); if (i != 0) { osip_message_free (msg); return -1; } /* replace with the new tr */ if (MSG_IS_PUBLISH(msg)) { /* old transaction is put in the garbage list */ osip_list_add (eXosip.j_transactions, out_tr, 0); /* new transaction is put in the publish context */ *ptr = tr; } else osip_list_add (eXosip.j_transactions, tr, 0); sipevent = osip_new_outgoing_sipmessage (msg); ji = osip_transaction_get_your_instance (out_tr); osip_transaction_set_your_instance (out_tr, NULL); osip_transaction_set_your_instance (tr, ji); osip_transaction_add_event (tr, sipevent); if (retry) (*retry)++; eXosip_update (); /* fixed? */ __eXosip_wakeup (); return 0; }
int eXosip_publish (struct eXosip_t *excontext, osip_message_t * message, const char *to) { osip_transaction_t *transaction; osip_event_t *sipevent; int i; eXosip_pub_t *pub = NULL; if (message == NULL) return OSIP_BADPARAMETER; if (message->cseq == NULL || message->cseq->number == NULL) { osip_message_free (message); return OSIP_SYNTAXERROR; } if (to == NULL) { osip_message_free (message); return OSIP_BADPARAMETER; } i = _eXosip_pub_find_by_aor (excontext, &pub, to); if (i != 0 || pub == NULL) { osip_header_t *expires; osip_message_get_expires (message, 0, &expires); if (expires == NULL || expires->hvalue == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing expires header in PUBLISH!")); osip_message_free (message); return OSIP_SYNTAXERROR; } else { /* start a new publication context */ i = _eXosip_pub_init (&pub, to, expires->hvalue); if (i != 0) { osip_message_free (message); return i; } ADD_ELEMENT (excontext->j_pub, pub); } } else { if (pub->p_sip_etag[0] != '\0') { /* increase cseq */ osip_message_set_header (message, "SIP-If-Match", pub->p_sip_etag); } { osip_header_t *expires; osip_message_get_expires (message, 0, &expires); if (expires == NULL || expires->hvalue == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing expires header in PUBLISH!")); osip_message_free (message); return OSIP_SYNTAXERROR; } pub->p_period = atoi (expires->hvalue); } if (pub->p_last_tr != NULL && pub->p_last_tr->cseq != NULL && pub->p_last_tr->cseq->number != NULL) { int osip_cseq_num = osip_atoi (pub->p_last_tr->cseq->number); int length = (int) strlen (pub->p_last_tr->cseq->number); osip_cseq_num++; osip_free (message->cseq->number); message->cseq->number = (char *) osip_malloc (length + 2); /* +2 like for 9 to 10 */ if (message->cseq->number == NULL) { osip_message_free (message); return OSIP_NOMEM; } snprintf (message->cseq->number, length + 2, "%i", osip_cseq_num); } } i = _eXosip_transaction_init (excontext, &transaction, NICT, excontext->j_osip, message); if (i != 0) { osip_message_free (message); return i; } if (pub->p_last_tr != NULL) osip_list_add (&excontext->j_transactions, pub->p_last_tr, 0); pub->p_last_tr = transaction; sipevent = osip_new_outgoing_sipmessage (message); sipevent->transactionid = transaction->transactionid; osip_transaction_add_event (transaction, sipevent); _eXosip_wakeup (excontext); return transaction->transactionid; }