int osip_message_clone (const osip_message_t * sip, osip_message_t ** dest) { osip_message_t *copy; int pos = 0; int i; *dest = NULL; if (sip == NULL) return OSIP_BADPARAMETER; i = osip_message_init (©); if (i != 0) return i; copy->sip_method = osip_strdup (sip->sip_method); if (sip->sip_method != NULL && copy->sip_method == NULL) { osip_message_free (copy); return OSIP_NOMEM; } copy->sip_version = osip_strdup (sip->sip_version); if (sip->sip_version != NULL && copy->sip_version == NULL) { osip_message_free (copy); return OSIP_NOMEM; } copy->status_code = sip->status_code; copy->reason_phrase = osip_strdup (sip->reason_phrase); if (sip->reason_phrase != NULL && copy->reason_phrase == NULL) { osip_message_free (copy); return OSIP_NOMEM; } if (sip->req_uri != NULL) { i = osip_uri_clone (sip->req_uri, &(copy->req_uri)); if (i != 0) { osip_message_free (copy); return i; } } #ifndef MINISIZE { osip_accept_t *accept; osip_accept_t *accept2; pos = 0; while (!osip_list_eol (&sip->accepts, pos)) { accept = (osip_accept_t *) osip_list_get (&sip->accepts, pos); i = osip_accept_clone (accept, &accept2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->accepts, accept2, -1); /* insert as last element */ pos++; } } { osip_accept_encoding_t *accept_encoding; osip_accept_encoding_t *accept_encoding2; pos = 0; while (!osip_list_eol (&sip->accept_encodings, pos)) { accept_encoding = (osip_accept_encoding_t *) osip_list_get (&sip->accept_encodings, pos); i = osip_accept_encoding_clone (accept_encoding, &accept_encoding2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->accept_encodings, accept_encoding2, -1); pos++; } } { osip_accept_language_t *accept_language; osip_accept_language_t *accept_language2; pos = 0; while (!osip_list_eol (&sip->accept_languages, pos)) { accept_language = (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos); i = osip_accept_language_clone (accept_language, &accept_language2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->accept_languages, accept_language2, -1); pos++; } } { osip_alert_info_t *alert_info; osip_alert_info_t *alert_info2; pos = 0; while (!osip_list_eol (&sip->alert_infos, pos)) { alert_info = (osip_alert_info_t *) osip_list_get (&sip->alert_infos, pos); i = osip_alert_info_clone (alert_info, &alert_info2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->alert_infos, alert_info2, -1); pos++; } } { osip_allow_t *allow; osip_allow_t *allow2; pos = 0; while (!osip_list_eol (&sip->allows, pos)) { allow = (osip_allow_t *) osip_list_get (&sip->allows, pos); i = osip_allow_clone (allow, &allow2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->allows, allow2, -1); pos++; } } { osip_authentication_info_t *authentication_info; osip_authentication_info_t *authentication_info2; pos = 0; while (!osip_list_eol (&sip->authentication_infos, pos)) { authentication_info = (osip_authentication_info_t *) osip_list_get (&sip->authentication_infos, pos); i = osip_authentication_info_clone (authentication_info, &authentication_info2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->authentication_infos, authentication_info2, -1); pos++; } } { osip_call_info_t *call_info; osip_call_info_t *call_info2; pos = 0; while (!osip_list_eol (&sip->call_infos, pos)) { call_info = (osip_call_info_t *) osip_list_get (&sip->call_infos, pos); i = osip_call_info_clone (call_info, &call_info2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->call_infos, call_info2, -1); pos++; } } { osip_content_encoding_t *content_encoding; osip_content_encoding_t *content_encoding2; pos = 0; while (!osip_list_eol (&sip->content_encodings, pos)) { content_encoding = (osip_content_encoding_t *) osip_list_get (&sip->content_encodings, pos); i = osip_content_encoding_clone (content_encoding, &content_encoding2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->content_encodings, content_encoding2, -1); pos++; } } { osip_error_info_t *error_info; osip_error_info_t *error_info2; pos = 0; while (!osip_list_eol (&sip->error_infos, pos)) { error_info = (osip_error_info_t *) osip_list_get (&sip->error_infos, pos); i = osip_error_info_clone (error_info, &error_info2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->error_infos, error_info2, -1); pos++; } } { osip_proxy_authentication_info_t *proxy_authentication_info; osip_proxy_authentication_info_t *proxy_authentication_info2; pos = 0; while (!osip_list_eol (&sip->proxy_authentication_infos, pos)) { proxy_authentication_info = (osip_proxy_authentication_info_t *) osip_list_get (&sip->proxy_authentication_infos, pos); i = osip_proxy_authentication_info_clone (proxy_authentication_info, &proxy_authentication_info2); if (i != 0) { osip_message_free (copy); return i; } osip_list_add (©->proxy_authentication_infos, proxy_authentication_info2, -1); pos++; } } #endif i = osip_list_clone (&sip->authorizations, ©->authorizations, (int (*)(void *, void **)) &osip_authorization_clone); if (i != 0) { osip_message_free (copy); return i; } if (sip->call_id != NULL) { i = osip_call_id_clone (sip->call_id, &(copy->call_id)); if (i != 0) { osip_message_free (copy); return i; } } i = osip_list_clone (&sip->contacts, ©->contacts, (int (*)(void *, void **)) &osip_contact_clone); if (i != 0) { osip_message_free (copy); return i; } if (sip->content_length != NULL) { i = osip_content_length_clone (sip->content_length, &(copy->content_length)); if (i != 0) { osip_message_free (copy); return i; } } if (sip->content_type != NULL) { i = osip_content_type_clone (sip->content_type, &(copy->content_type)); if (i != 0) { osip_message_free (copy); return i; } } if (sip->cseq != NULL) { i = osip_cseq_clone (sip->cseq, &(copy->cseq)); if (i != 0) { osip_message_free (copy); return i; } } if (sip->from != NULL) { i = osip_from_clone (sip->from, &(copy->from)); if (i != 0) { osip_message_free (copy); return i; } } if (sip->mime_version != NULL) { i = osip_mime_version_clone (sip->mime_version, &(copy->mime_version)); if (i != 0) { osip_message_free (copy); return i; } } i = osip_list_clone (&sip->proxy_authenticates, ©->proxy_authenticates, (int (*)(void *, void **)) &osip_proxy_authenticate_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone (&sip->proxy_authorizations, ©->proxy_authorizations, (int (*)(void *, void **)) &osip_proxy_authorization_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone (&sip->record_routes, ©->record_routes, (int (*)(void *, void **)) &osip_record_route_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone (&sip->routes, ©->routes, (int (*)(void *, void **)) &osip_route_clone); if (i != 0) { osip_message_free (copy); return i; } if (sip->to != NULL) { i = osip_to_clone (sip->to, &(copy->to)); if (i != 0) { osip_message_free (copy); return i; } } i = osip_list_clone (&sip->vias, ©->vias, (int (*)(void *, void **)) &osip_via_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone (&sip->www_authenticates, ©->www_authenticates, (int (*)(void *, void **)) &osip_www_authenticate_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone (&sip->headers, ©->headers, (int (*)(void *, void **)) &osip_header_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone (&sip->bodies, ©->bodies, (int (*)(void *, void **)) &osip_body_clone); if (i != 0) { osip_message_free (copy); return i; } copy->message_length = sip->message_length; copy->message = osip_strdup (sip->message); if (copy->message == NULL && sip->message != NULL) { osip_message_free (copy); return OSIP_NOMEM; } copy->message_property = sip->message_property; copy->application_data = sip->application_data; *dest = copy; return OSIP_SUCCESS; }
int eXosip_subscribe_build_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; char *transport; int i; *sub = NULL; 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")); 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) return OSIP_WRONG_STATE; } transport = NULL; if (transaction != NULL && transaction->orig_request != NULL) transport = _eXosip_transport_protocol (transaction->orig_request); if (transport == NULL) i = _eXosip_build_request_within_dialog (excontext, sub, "SUBSCRIBE", jd->d_dialog, "UDP"); else i = _eXosip_build_request_within_dialog (excontext, sub, "SUBSCRIBE", jd->d_dialog, transport); if (i != 0) return i; if (transaction != NULL && transaction->orig_request != NULL) { int pos = 0; osip_header_t *_header = NULL; osip_call_info_t *_call_info_header = NULL; pos = osip_message_get_supported (transaction->orig_request, pos, &_header); while (pos >= 0 && _header != NULL) { osip_header_t *_header2; i = osip_header_clone (_header, &_header2); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Error in Supported header\n")); break; } osip_list_add (&(*sub)->headers, _header2, -1); _header = NULL; pos++; pos = osip_message_get_supported (transaction->orig_request, pos, &_header); } pos = 0; pos = osip_message_get_call_info (transaction->orig_request, pos, &_call_info_header); while (pos >= 0 && _call_info_header != NULL) { osip_call_info_t *_header2; i = osip_call_info_clone (_call_info_header, &_header2); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Error in Call-Info header\n")); break; } osip_list_add (&(*sub)->call_infos, _header2, -1); _call_info_header = NULL; pos++; pos = osip_message_get_call_info (transaction->orig_request, pos, &_call_info_header); } } _eXosip_add_authentication_information (excontext, *sub, NULL); return OSIP_SUCCESS; }
int osip_message_clone (const osip_message_t * sip, osip_message_t ** dest) { osip_message_t *copy; int pos = 0; int i; if (sip == NULL) return -1; *dest = NULL; i = osip_message_init (©); if (i != 0) return -1; copy->sip_method = osip_strdup (sip->sip_method); copy->sip_version = osip_strdup (sip->sip_version); copy->status_code = sip->status_code; copy->reason_phrase = osip_strdup (sip->reason_phrase); if (sip->req_uri != NULL) { i = osip_uri_clone (sip->req_uri, &(copy->req_uri)); if (i != 0) goto mc_error1; } { osip_accept_t *accept; osip_accept_t *accept2; pos = 0; while (!osip_list_eol (&sip->accepts, pos)) { accept = (osip_accept_t *) osip_list_get (&sip->accepts, pos); i = osip_accept_clone (accept, &accept2); if (i != 0) goto mc_error1; osip_list_add (©->accepts, accept2, -1); /* insert as last element */ pos++; } } { osip_accept_encoding_t *accept_encoding; osip_accept_encoding_t *accept_encoding2; pos = 0; while (!osip_list_eol (&sip->accept_encodings, pos)) { accept_encoding = (osip_accept_encoding_t *) osip_list_get (&sip->accept_encodings, pos); i = osip_accept_encoding_clone (accept_encoding, &accept_encoding2); if (i != 0) goto mc_error1; osip_list_add (©->accept_encodings, accept_encoding2, -1); pos++; } } { osip_accept_language_t *accept_language; osip_accept_language_t *accept_language2; pos = 0; while (!osip_list_eol (&sip->accept_languages, pos)) { accept_language = (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos); i = osip_accept_language_clone (accept_language, &accept_language2); if (i != 0) goto mc_error1; osip_list_add (©->accept_languages, accept_language2, -1); pos++; } } { osip_alert_info_t *alert_info; osip_alert_info_t *alert_info2; pos = 0; while (!osip_list_eol (&sip->alert_infos, pos)) { alert_info = (osip_alert_info_t *) osip_list_get (&sip->alert_infos, pos); i = osip_alert_info_clone (alert_info, &alert_info2); if (i != 0) goto mc_error1; osip_list_add (©->alert_infos, alert_info2, -1); pos++; } } { osip_allow_t *allow; osip_allow_t *allow2; pos = 0; while (!osip_list_eol (&sip->allows, pos)) { allow = (osip_allow_t *) osip_list_get (&sip->allows, pos); i = osip_allow_clone (allow, &allow2); if (i != 0) goto mc_error1; osip_list_add (©->allows, allow2, -1); pos++; } } { osip_authentication_info_t *authentication_info; osip_authentication_info_t *authentication_info2; pos = 0; while (!osip_list_eol (&sip->authentication_infos, pos)) { authentication_info = (osip_authentication_info_t *) osip_list_get (&sip-> authentication_infos, pos); i = osip_authentication_info_clone (authentication_info, &authentication_info2); if (i != 0) goto mc_error1; osip_list_add (©->authentication_infos, authentication_info2, -1); pos++; } } { osip_authorization_t *authorization; osip_authorization_t *authorization2; pos = 0; while (!osip_list_eol (&sip->authorizations, pos)) { authorization = (osip_authorization_t *) osip_list_get (&sip->authorizations, pos); i = osip_authorization_clone (authorization, &authorization2); if (i != 0) goto mc_error1; osip_list_add (©->authorizations, authorization2, -1); pos++; } } if (sip->call_id != NULL) { i = osip_call_id_clone (sip->call_id, &(copy->call_id)); if (i != 0) goto mc_error1; } { osip_call_info_t *call_info; osip_call_info_t *call_info2; pos = 0; while (!osip_list_eol (&sip->call_infos, pos)) { call_info = (osip_call_info_t *) osip_list_get (&sip->call_infos, pos); i = osip_call_info_clone (call_info, &call_info2); if (i != 0) goto mc_error1; osip_list_add (©->call_infos, call_info2, -1); pos++; } } { osip_contact_t *contact; osip_contact_t *contact2; pos = 0; while (!osip_list_eol (&sip->contacts, pos)) { contact = (osip_contact_t *) osip_list_get (&sip->contacts, pos); i = osip_contact_clone (contact, &contact2); if (i != 0) goto mc_error1; osip_list_add (©->contacts, contact2, -1); pos++; } } { osip_content_encoding_t *content_encoding; osip_content_encoding_t *content_encoding2; pos = 0; while (!osip_list_eol (&sip->content_encodings, pos)) { content_encoding = (osip_content_encoding_t *) osip_list_get (&sip->content_encodings, pos); i = osip_content_encoding_clone (content_encoding, &content_encoding2); if (i != 0) goto mc_error1; osip_list_add (©->content_encodings, content_encoding2, -1); pos++; } } if (sip->content_length != NULL) { i = osip_content_length_clone (sip->content_length, &(copy->content_length)); if (i != 0) goto mc_error1; } if (sip->content_type != NULL) { i = osip_content_type_clone (sip->content_type, &(copy->content_type)); if (i != 0) goto mc_error1; } if (sip->cseq != NULL) { i = osip_cseq_clone (sip->cseq, &(copy->cseq)); if (i != 0) goto mc_error1; } { osip_error_info_t *error_info; osip_error_info_t *error_info2; pos = 0; while (!osip_list_eol (&sip->error_infos, pos)) { error_info = (osip_error_info_t *) osip_list_get (&sip->error_infos, pos); i = osip_error_info_clone (error_info, &error_info2); if (i != 0) goto mc_error1; osip_list_add (©->error_infos, error_info2, -1); pos++; } } if (sip->from != NULL) { i = osip_from_clone (sip->from, &(copy->from)); if (i != 0) goto mc_error1; } if (sip->mime_version != NULL) { i = osip_mime_version_clone (sip->mime_version, &(copy->mime_version)); if (i != 0) goto mc_error1; } { osip_proxy_authenticate_t *proxy_authenticate; osip_proxy_authenticate_t *proxy_authenticate2; pos = 0; while (!osip_list_eol (&sip->proxy_authenticates, pos)) { proxy_authenticate = (osip_proxy_authenticate_t *) osip_list_get (&sip-> proxy_authenticates, pos); i = osip_proxy_authenticate_clone (proxy_authenticate, &proxy_authenticate2); if (i != 0) goto mc_error1; osip_list_add (©->proxy_authenticates, proxy_authenticate2, -1); pos++; } } { osip_proxy_authentication_info_t *proxy_authentication_info; osip_proxy_authentication_info_t *proxy_authentication_info2; pos = 0; while (!osip_list_eol (&sip->proxy_authentication_infos, pos)) { proxy_authentication_info = (osip_proxy_authentication_info_t *) osip_list_get (&sip-> proxy_authentication_infos, pos); i = osip_proxy_authentication_info_clone (proxy_authentication_info, &proxy_authentication_info2); if (i != 0) goto mc_error1; osip_list_add (©->proxy_authentication_infos, proxy_authentication_info2, -1); pos++; } } { osip_proxy_authorization_t *proxy_authorization; osip_proxy_authorization_t *proxy_authorization2; pos = 0; while (!osip_list_eol (&sip->proxy_authorizations, pos)) { proxy_authorization = (osip_proxy_authorization_t *) osip_list_get (&sip-> proxy_authorizations, pos); i = osip_proxy_authorization_clone (proxy_authorization, &proxy_authorization2); if (i != 0) goto mc_error1; osip_list_add (©->proxy_authorizations, proxy_authorization2, -1); pos++; } } { osip_record_route_t *record_route; osip_record_route_t *record_route2; pos = 0; while (!osip_list_eol (&sip->record_routes, pos)) { record_route = (osip_record_route_t *) osip_list_get (&sip->record_routes, pos); i = osip_record_route_clone (record_route, &record_route2); if (i != 0) goto mc_error1; osip_list_add (©->record_routes, record_route2, -1); pos++; } } { osip_route_t *route; osip_route_t *route2; pos = 0; while (!osip_list_eol (&sip->routes, pos)) { route = (osip_route_t *) osip_list_get (&sip->routes, pos); i = osip_route_clone (route, &route2); if (i != 0) goto mc_error1; osip_list_add (©->routes, route2, -1); pos++; } } if (sip->to != NULL) { i = osip_to_clone (sip->to, &(copy->to)); if (i != 0) goto mc_error1; } { osip_via_t *via; osip_via_t *via2; pos = 0; while (!osip_list_eol (&sip->vias, pos)) { via = (osip_via_t *) osip_list_get (&sip->vias, pos); i = osip_via_clone (via, &via2); if (i != 0) goto mc_error1; osip_list_add (©->vias, via2, -1); pos++; } } { osip_www_authenticate_t *www_authenticate; osip_www_authenticate_t *www_authenticate2; pos = 0; while (!osip_list_eol (&sip->www_authenticates, pos)) { www_authenticate = (osip_www_authenticate_t *) osip_list_get (&sip->www_authenticates, pos); i = osip_www_authenticate_clone (www_authenticate, &www_authenticate2); if (i != 0) goto mc_error1; osip_list_add (©->www_authenticates, www_authenticate2, -1); pos++; } } { osip_header_t *header; osip_header_t *header2; pos = 0; while (!osip_list_eol (&sip->headers, pos)) { header = (osip_header_t *) osip_list_get (&sip->headers, pos); i = osip_header_clone (header, &header2); if (i != 0) goto mc_error1; osip_list_add (©->headers, header2, -1); pos++; } } { osip_body_t *body; osip_body_t *body2; pos = 0; while (!osip_list_eol (&sip->bodies, pos)) { body = (osip_body_t *) osip_list_get (&sip->bodies, pos); i = osip_body_clone (body, &body2); if (i != 0) goto mc_error1; osip_list_add (©->bodies, body2, -1); pos++; } } copy->message_length = sip->message_length; copy->message = osip_strdup (sip->message); copy->message_property = sip->message_property; *dest = copy; return 0; mc_error1: osip_message_free (copy); return -1; }