/* * SIP_ADD_MYVIA * * interface == IF_OUTBOUND, IF_INBOUND * * RETURNS * STS_SUCCESS on success * STS_FAILURE on error */ int sip_add_myvia (sip_ticket_t *ticket, int interface) { struct in_addr addr; char tmp[URL_STRING_SIZE]; osip_via_t *via; int sts; char branch_id[VIA_BRANCH_SIZE]; char *myaddr; if (get_interface_ip(interface, &addr) != STS_SUCCESS) { return STS_FAILURE; } sts = sip_calculate_branch_id(ticket, branch_id); myaddr=utils_inet_ntoa(addr); sprintf(tmp, "SIP/2.0/UDP %s:%i;branch=%s", myaddr, configuration.sip_listen_port, branch_id); DEBUGC(DBCLASS_BABBLE,"adding VIA:%s",tmp); sts = osip_via_init(&via); if (sts!=0) return STS_FAILURE; /* allocation failed */ sts = osip_via_parse(via, tmp); if (sts!=0) return STS_FAILURE; osip_list_add(ticket->sipmsg->vias,via,0); return STS_SUCCESS; }
int main (int argc, char **argv) { FILE *vias_file; osip_via_t *via; char *a_via; char *dest; char *res; vias_file = fopen (argv[1], "r"); if (vias_file == NULL) { fprintf (stdout, "Failed to open %s file.\nUsage: tvia vias.txt\n", argv[1]); exit (0); } a_via = (char *) osip_malloc (200); res = fgets (a_via, 200, vias_file); /* lines are under 200 */ while (res != NULL) { int errcode; /* remove the last '\n' before parsing */ osip_strncpy (a_via + strlen (a_via) - 1, "\0", 1); if (0 != strncmp (a_via, "#", 1)) { /* allocate & init via */ osip_via_init (&via); printf ("=================================================\n"); printf ("VIA TO PARSE: |%s|\n", a_via); errcode = osip_via_parse (via, a_via); if (errcode != -1) { if (osip_via_to_str (via, &dest) != -1) { printf ("result: |%s|\n", dest); osip_free (dest); } } else printf ("Bad via format: %s\n", a_via); osip_via_free (via); printf ("=================================================\n"); } res = fgets (a_via, 200, vias_file); /* lines are under 200 */ } osip_free (a_via); return 0; }
/* returns -1 on error. */ int osip_message_append_via (osip_message_t * sip, const char *hvalue) { osip_via_t *via; int i; i = osip_via_init (&via); if (i != 0) return -1; i = osip_via_parse (via, hvalue); if (i != 0) { osip_via_free (via); return -1; } sip->message_property = 2; osip_list_add (sip->vias, via, 0); return 0; }
/* * SIP_ADD_MYVIA * * interface == IF_OUTBOUND, IF_INBOUND * * RETURNS * STS_SUCCESS on success * STS_FAILURE on error */ int sip_add_myvia (sip_ticket_t *ticket, int interface, struct in_addr *local_ip) { struct in_addr addr; char tmp[URL_STRING_SIZE] = {0}; osip_via_t *via; int sts; char branch_id[VIA_BRANCH_SIZE]; if (local_ip == NULL) { if (interface == IF_OUTBOUND) { if (get_ip_by_ifname(configuration.outbound_if, &addr) != STS_SUCCESS) { ERROR("can't find interface %s - configuration error?", configuration.outbound_if); return STS_FAILURE; } } else { if (get_ip_by_ifname(configuration.inbound_if, &addr) != STS_SUCCESS) { ERROR("can't find inbound interface %s - configuration error?", configuration.inbound_if); return STS_FAILURE; } } } else { addr = *local_ip; } sts = sip_calculate_branch_id(ticket, branch_id); snprintf(tmp,URL_STRING_SIZE, "SIP/2.0/UDP %s:%i;branch=%s;", utils_inet_ntoa(addr), configuration.sip_listen_port, branch_id); DEBUGC(DBCLASS_BABBLE,"adding VIA:%s",tmp); sts = osip_via_init(&via); if (sts!=0) return STS_FAILURE; /* allocation failed */ sts = osip_via_parse(via, tmp); if (sts!=0) return STS_FAILURE; osip_list_add(ticket->sipmsg->vias,via,0); return STS_SUCCESS; }
/* returns -1 on error. */ int osip_message_set_via (osip_message_t * sip, const char *hvalue) { osip_via_t *via; int i; if (hvalue == NULL || hvalue[0] == '\0') return 0; i = osip_via_init (&via); if (i != 0) return -1; i = osip_via_parse (via, hvalue); if (i != 0) { osip_via_free (via); return -1; } sip->message_property = 2; osip_list_add (sip->vias, via, -1); 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; 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; }
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; }