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; }
int osip_via_clone (const osip_via_t * via, osip_via_t ** dest) { int i; osip_via_t *vi; *dest = NULL; if (via == NULL) return -1; if (via->version == NULL) return -1; if (via->protocol == NULL) return -1; if (via->host == NULL) return -1; i = osip_via_init (&vi); if (i != 0) return -1; vi->version = osip_strdup (via->version); vi->protocol = osip_strdup (via->protocol); vi->host = osip_strdup (via->host); if (via->port != NULL) vi->port = osip_strdup (via->port); if (via->comment != NULL) vi->comment = osip_strdup (via->comment); { int pos = 0; osip_generic_param_t *u_param; osip_generic_param_t *dest_param; while (!osip_list_eol (via->via_params, pos)) { u_param = (osip_generic_param_t *) osip_list_get (via->via_params, pos); i = osip_generic_param_clone (u_param, &dest_param); if (i != 0) { osip_via_free (vi); return -1; } osip_list_add (vi->via_params, dest_param, -1); pos++; } } *dest = vi; 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_DEL_MYVIA * * RETURNS * STS_SUCCESS on success * STS_FAILURE on error */ int sip_del_myvia (sip_ticket_t *ticket, struct in_addr *local_ip) { osip_via_t *via; int sts; DEBUGC(DBCLASS_PROXY,"deleting topmost VIA"); via = osip_list_get (ticket->sipmsg->vias, 0); if ( via == NULL ) { ERROR("Got empty VIA list - is your UA configured properly?"); return STS_FAILURE; } if ( is_via_local(via, local_ip) == STS_FALSE ) { ERROR("I'm trying to delete a VIA but it's not mine! host=%s",via->host); return STS_FAILURE; } sts = osip_list_remove(ticket->sipmsg->vias, 0); osip_via_free (via); 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; }
void osip_message_free (osip_message_t * sip) { int pos = 0; if (sip == NULL) return; osip_free (sip->sip_method); osip_free (sip->sip_version); if (sip->req_uri != NULL) { osip_uri_free (sip->req_uri); } osip_free (sip->reason_phrase); { osip_accept_t *accept; while (!osip_list_eol (&sip->accepts, pos)) { accept = (osip_accept_t *) osip_list_get (&sip->accepts, pos); osip_list_remove (&sip->accepts, pos); osip_accept_free (accept); } } { osip_accept_encoding_t *accept_encoding; while (!osip_list_eol (&sip->accept_encodings, pos)) { accept_encoding = (osip_accept_encoding_t *) osip_list_get (&sip->accept_encodings, pos); osip_list_remove (&sip->accept_encodings, pos); osip_accept_encoding_free (accept_encoding); } } { osip_accept_language_t *accept_language; while (!osip_list_eol (&sip->accept_languages, pos)) { accept_language = (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos); osip_list_remove (&sip->accept_languages, pos); osip_accept_language_free (accept_language); } } { osip_alert_info_t *alert_info; while (!osip_list_eol (&sip->alert_infos, pos)) { alert_info = (osip_alert_info_t *) osip_list_get (&sip->alert_infos, pos); osip_list_remove (&sip->alert_infos, pos); osip_alert_info_free (alert_info); } } { osip_allow_t *al; while (!osip_list_eol (&sip->allows, pos)) { al = (osip_allow_t *) osip_list_get (&sip->allows, pos); osip_list_remove (&sip->allows, pos); osip_allow_free (al); } } { osip_authentication_info_t *al; while (!osip_list_eol (&sip->authentication_infos, pos)) { al = (osip_authentication_info_t *) osip_list_get (&sip-> authentication_infos, pos); osip_list_remove (&sip->authentication_infos, pos); osip_authentication_info_free (al); } } { osip_authorization_t *al; while (!osip_list_eol (&sip->authorizations, pos)) { al = (osip_authorization_t *) osip_list_get (&sip->authorizations, pos); osip_list_remove (&sip->authorizations, pos); osip_authorization_free (al); } } if (sip->call_id != NULL) { osip_call_id_free (sip->call_id); } { osip_call_info_t *call_info; while (!osip_list_eol (&sip->call_infos, pos)) { call_info = (osip_call_info_t *) osip_list_get (&sip->call_infos, pos); osip_list_remove (&sip->call_infos, pos); osip_call_info_free (call_info); } } { osip_contact_t *contact; while (!osip_list_eol (&sip->contacts, pos)) { contact = (osip_contact_t *) osip_list_get (&sip->contacts, pos); osip_list_remove (&sip->contacts, pos); osip_contact_free (contact); } } { osip_content_encoding_t *ce; while (!osip_list_eol (&sip->content_encodings, pos)) { ce = (osip_content_encoding_t *) osip_list_get (&sip->content_encodings, pos); osip_list_remove (&sip->content_encodings, pos); osip_content_encoding_free (ce); } } if (sip->content_length != NULL) { osip_content_length_free (sip->content_length); } if (sip->content_type != NULL) { osip_content_type_free (sip->content_type); } if (sip->cseq != NULL) { osip_cseq_free (sip->cseq); } { osip_error_info_t *error_info; while (!osip_list_eol (&sip->error_infos, pos)) { error_info = (osip_error_info_t *) osip_list_get (&sip->error_infos, pos); osip_list_remove (&sip->error_infos, pos); osip_error_info_free (error_info); } } if (sip->from != NULL) { osip_from_free (sip->from); } if (sip->mime_version != NULL) { osip_mime_version_free (sip->mime_version); } { osip_proxy_authenticate_t *al; while (!osip_list_eol (&sip->proxy_authenticates, pos)) { al = (osip_proxy_authenticate_t *) osip_list_get (&sip-> proxy_authenticates, pos); osip_list_remove (&sip->proxy_authenticates, pos); osip_proxy_authenticate_free (al); } } { osip_proxy_authentication_info_t *al; while (!osip_list_eol (&sip->proxy_authentication_infos, pos)) { al = (osip_proxy_authentication_info_t *) osip_list_get (&sip-> proxy_authentication_infos, pos); osip_list_remove (&sip->proxy_authentication_infos, pos); osip_proxy_authentication_info_free (al); } } { osip_proxy_authorization_t *proxy_authorization; while (!osip_list_eol (&sip->proxy_authorizations, pos)) { proxy_authorization = (osip_proxy_authorization_t *) osip_list_get (&sip-> proxy_authorizations, pos); osip_list_remove (&sip->proxy_authorizations, pos); osip_proxy_authorization_free (proxy_authorization); } } { osip_record_route_t *record_route; while (!osip_list_eol (&sip->record_routes, pos)) { record_route = (osip_record_route_t *) osip_list_get (&sip->record_routes, pos); osip_list_remove (&sip->record_routes, pos); osip_record_route_free (record_route); } } { osip_route_t *route; while (!osip_list_eol (&sip->routes, pos)) { route = (osip_route_t *) osip_list_get (&sip->routes, pos); osip_list_remove (&sip->routes, pos); osip_route_free (route); } } if (sip->to != NULL) { osip_to_free (sip->to); } { osip_via_t *via; while (!osip_list_eol (&sip->vias, pos)) { via = (osip_via_t *) osip_list_get (&sip->vias, pos); osip_list_remove (&sip->vias, pos); osip_via_free (via); } } { osip_www_authenticate_t *al; while (!osip_list_eol (&sip->www_authenticates, pos)) { al = (osip_www_authenticate_t *) osip_list_get (&sip->www_authenticates, pos); osip_list_remove (&sip->www_authenticates, pos); osip_www_authenticate_free (al); } } { osip_header_t *header; while (!osip_list_eol (&sip->headers, pos)) { header = (osip_header_t *) osip_list_get (&sip->headers, pos); osip_list_remove (&sip->headers, pos); osip_header_free (header); } } { osip_body_t *body; while (!osip_list_eol (&sip->bodies, pos)) { body = (osip_body_t *) osip_list_get (&sip->bodies, pos); osip_list_remove (&sip->bodies, pos); osip_body_free (body); } } osip_free (sip->message); osip_free (sip); }