/* * create a reply template from an given SIP request * * RETURNS a pointer to osip_message_t */ osip_message_t *msg_make_template_reply (sip_ticket_t *ticket, int code) { osip_message_t *request=ticket->sipmsg; osip_message_t *response; int pos; osip_message_init (&response); response->message=NULL; osip_message_set_version (response, osip_strdup ("SIP/2.0")); osip_message_set_status_code (response, code); osip_message_set_reason_phrase (response, osip_strdup(osip_message_get_reason (code))); if (request->to==NULL) { ERROR("msg_make_template_reply: empty To in request header"); return NULL; } if (request->from==NULL) { ERROR("msg_make_template_reply: empty From in request header"); return NULL; } osip_to_clone (request->to, &response->to); osip_from_clone (request->from, &response->from); /* if 3xx, also include 1st contact header */ if ((code==200) || ((code>=300) && (code<400))) { osip_contact_t *req_contact = NULL; osip_contact_t *res_contact = NULL; osip_message_get_contact(request, 0, &req_contact); if (req_contact) osip_contact_clone (req_contact, &res_contact); if (res_contact) osip_list_add(response->contacts,res_contact,0); } /* via headers */ pos = 0; while (!osip_list_eol (request->vias, pos)) { char *tmp; osip_via_t *via; via = (osip_via_t *) osip_list_get (request->vias, pos); osip_via_to_str (via, &tmp); osip_message_set_via (response, tmp); osip_free (tmp); pos++; } osip_call_id_clone(request->call_id,&response->call_id); osip_cseq_clone(request->cseq,&response->cseq); return response; }
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; }
osip_message_t* init_sip_msg_from_src (const osip_message_t *sipmsg, const int code) { __tri(init_sip_msg_from_src); if (sipmsg->to && sipmsg->from) { osip_message_t* sipgen; osip_message_init (&sipgen); if (sipgen) { sipgen->message = NULL; osip_message_set_version (sipgen, osip_strdup ("SIP/2.0")); osip_message_set_status_code (sipgen, code); osip_message_set_reason_phrase (sipgen, osip_strdup(osip_message_get_reason (code))); if (code == SIP_MOVED_TEMPORARILY) { char contact[100]; snprintf (contact, sizeof(contact), "<sip:%s@%s:%s>", sipmsg->to->url->username, "sip.voipcheap.com", "5060"); osip_message_set_contact(sipgen, contact); osip_to_clone (sipmsg->to, &sipgen->from); osip_from_clone (sipmsg->from, &sipgen->to); } else { /*include 1st contact header if 3xx*/ if (code < SIP_BAD_REQUEST && (SIP_OK == code || code >= SIP_MULTIPLE_CHOICES) ) { osip_contact_t* src_contact = NULL; osip_message_get_contact(sipmsg, 0, &src_contact); if (src_contact) { osip_contact_t* res_contact = NULL; osip_contact_clone (src_contact, &res_contact); if (res_contact) { osip_list_add(&(sipgen->contacts),res_contact,0); } } } osip_to_clone (sipmsg->to, &sipgen->to); osip_from_clone (sipmsg->from, &sipgen->from); } /* via headers */ int pos = 0; while (!osip_list_eol (&sipmsg->vias, pos)) { osip_via_t*via = (osip_via_t*)osip_list_get (&sipmsg->vias, pos); char *tmp; osip_via_to_str (via, &tmp); osip_message_set_via (sipgen, tmp); osip_free (tmp); pos++; } osip_call_id_clone (sipmsg->call_id, &sipgen->call_id); osip_cseq_clone (sipmsg->cseq, &sipgen->cseq); __tre(return) sipgen; } }
//--------------------------------------------------------------------- int Node::SndResponse4Query(int status, const char *contact, osip_transaction_t *tr, osip_message_t *request) { char *message1; size_t length = 0; // osip_generic_param_t *tag; osip_message_t *response; osip_event_t *evt ; char *tmp; int pos; int i; i = osip_message_init (&response); if (i != 0) return -1; osip_message_set_version (response, osip_strdup ("SIP/2.0")); osip_message_set_status_code (response, status); tmp = osip_strdup(osip_message_get_reason (status)); if (tmp == NULL) osip_message_set_reason_phrase (response, osip_strdup ("Unknown status code")); else osip_message_set_reason_phrase (response, tmp); osip_message_set_method (response, NULL); osip_message_set_uri (response, NULL); i = osip_to_clone (request->to, &(response->to)); if (i != 0) goto si2perror1; i = osip_to_get_tag (response->to, &tag); if (i != 0) { /* we only add a tag if it does not already contains one! */ if (status == 200 && MSG_IS_REGISTER (request)) { osip_to_set_tag (response->to, osip_to_tag_new_random ()); } else if (status >= 200) { osip_to_set_tag (response->to, osip_to_tag_new_random ()); } } i = osip_from_clone (request->from, &(response->from)); if (i != 0) goto si2perror1; pos = 0; 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); i = osip_via_clone (via, &via2); if (i != -0) goto si2perror1; osip_list_add (response->vias, via2, -1); pos++; } i = osip_call_id_clone (request->call_id, &(response->call_id)); if (i != 0) goto si2perror1; i = osip_cseq_clone (request->cseq, &(response->cseq)); if (i != 0) goto si2perror1; //set server osip_message_set_server (response, osip_strdup ("SI2P")); /*add contact*/ if(contact !=NULL) osip_message_set_contact(response,contact); i = osip_message_to_str(response, &message1, &length); LogStream("SEND======================================>>\n") ; LogStream(message1) ; if(message1) osip_free(message1) ; evt = osip_new_outgoing_sipmessage (response); evt->transactionid = tr->transactionid; osip_transaction_add_event(tr, evt); adosip->ThreadWakeUp(); return 0; si2perror1: osip_message_free (response); return -1; }
int Node::SndResponse(int status , osip_message_t *request , osip_transaction_t *tr, REG_TYPE type , ChordId contact, BOOL IncludeSuccList) { char *message1; size_t length = 0; // osip_generic_param_t *tag; osip_message_t *response; osip_event_t *evt ; char *tmp; char * tmp_uri; int pos; int i; i = osip_message_init (&response); if (i != 0) return -1; osip_message_set_version (response, osip_strdup ("SIP/2.0")); osip_message_set_status_code (response, status); tmp = osip_strdup(osip_message_get_reason (status)); if (tmp == NULL) osip_message_set_reason_phrase (response, osip_strdup ("Unknown status code")); else osip_message_set_reason_phrase (response, tmp); osip_message_set_method (response, NULL); osip_message_set_uri (response, NULL); i = osip_to_clone (request->to, &(response->to)); if (i != 0) goto si2perror1; i = osip_to_get_tag (response->to, &tag); if (i != 0) { /* we only add a tag if it does not already contains one! */ if (status == 200 && MSG_IS_REGISTER (request)) { osip_to_set_tag (response->to, osip_to_tag_new_random ()); } else if (status >= 200) { osip_to_set_tag (response->to, osip_to_tag_new_random ()); } } i = osip_from_clone (request->from, &(response->from)); if (i != 0) goto si2perror1; pos = 0; 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); i = osip_via_clone (via, &via2); if (i != -0) goto si2perror1; osip_list_add (response->vias, via2, -1); pos++; } i = osip_call_id_clone (request->call_id, &(response->call_id)); if (i != 0) goto si2perror1; i = osip_cseq_clone (request->cseq, &(response->cseq)); if (i != 0) goto si2perror1; //set server osip_message_set_server (response, osip_strdup ("SI2P")); /*add contact*/ //predecessor if(status == 200) { if(type == USER_REGISTRATION || type == TRANSFER_REGISTRATION || type == THIRD_PARTY) { osip_contact_t *tmp; char *dest; int pos=0; while(pos<osip_list_size(request->contacts)) { pos=osip_message_get_contact(request,0,&tmp); osip_contact_to_str(tmp,&dest); osip_message_set_contact(response,dest); if(dest) osip_free(dest) ; pos++; } } else { tmp_uri = ChordId2Uri(chordId,false); char * pre_uri = ChordId2Uri(getFingerTable()->getPredecessor(),false) ; char *ctt = (char *) osip_malloc(strlen(tmp_uri) + strlen(";predecessor=") + strlen(pre_uri) +1) ; if (ctt == NULL) return NULL; sprintf (ctt, "%s;predecessor=%s", tmp_uri,pre_uri); osip_free(tmp_uri) ; osip_free(pre_uri) ; osip_message_set_contact(response, ctt ); osip_free(ctt) ; } } else//302 { if(type == USER_REGISTRATION || type == TRANSFER_REGISTRATION || type == THIRD_PARTY) { tmp_uri = ChordId2Uri(contact,false); osip_message_set_contact(response,tmp_uri ); osip_free(tmp_uri) ; } else { tmp_uri = ChordId2Uri(contact,false) ; char *ctt = (char *) osip_malloc(strlen(tmp_uri) + strlen(";predecessor=notprovided") +1) ; if (ctt == NULL) return NULL; sprintf (ctt, "%s;predecessor=notprovided", tmp_uri); if(tmp_uri) osip_free(tmp_uri) ; osip_message_set_contact(response, ctt ); if(tmp_uri) osip_free(ctt) ; } } if(IncludeSuccList) { for(i = 0 ; i < getFingerTable()->getSuccNum() ; i++) { tmp_uri = ChordId2Uri(getFingerTable()->getSuccessor(i),false) ; osip_message_set_contact(response, tmp_uri ); osip_free(tmp_uri) ; } } i = osip_message_to_str(response, &message1, &length); LogStream("SEND======================================>>\n") ; LogStream(message1) ; if(message1) osip_free(message1) ; // printf("SEND======================================>>\n") ; // printf(message1) ; evt = osip_new_outgoing_sipmessage (response); evt->transactionid = tr->transactionid; osip_transaction_add_event(tr, evt); adosip->ThreadWakeUp(); return 0; si2perror1: osip_message_free (response); return -1; }
/* It is RECOMMENDED to only cancel INVITE request */ int generating_cancel (osip_message_t ** dest, osip_message_t * request_cancelled) { int i; osip_message_t *request; i = osip_message_init (&request); if (i != 0) return i; /* prepare the request-line */ osip_message_set_method (request, osip_strdup ("CANCEL")); osip_message_set_version (request, osip_strdup ("SIP/2.0")); osip_message_set_status_code (request, 0); osip_message_set_reason_phrase (request, NULL); i = osip_uri_clone (request_cancelled->req_uri, &(request->req_uri)); if (i != 0) { osip_message_free (request); *dest = NULL; return i; } i = osip_to_clone (request_cancelled->to, &(request->to)); if (i != 0) { osip_message_free (request); *dest = NULL; return i; } i = osip_from_clone (request_cancelled->from, &(request->from)); if (i != 0) { osip_message_free (request); *dest = NULL; return i; } /* set the cseq and call_id header */ i = osip_call_id_clone (request_cancelled->call_id, &(request->call_id)); if (i != 0) { osip_message_free (request); *dest = NULL; return i; } i = osip_cseq_clone (request_cancelled->cseq, &(request->cseq)); if (i != 0) { osip_message_free (request); *dest = NULL; return i; } osip_free (request->cseq->method); request->cseq->method = osip_strdup ("CANCEL"); if (request->cseq->method == NULL) { osip_message_free (request); *dest = NULL; return OSIP_NOMEM; } /* copy ONLY the top most Via Field (this method is also used by proxy) */ { osip_via_t *via; osip_via_t *via2; i = osip_message_get_via (request_cancelled, 0, &via); if (i < 0) { osip_message_free (request); *dest = NULL; return i; } i = osip_via_clone (via, &via2); if (i != 0) { osip_message_free (request); *dest = NULL; return i; } osip_list_add (&request->vias, via2, -1); } /* add the same route-set than in the previous request */ { int pos = 0; osip_route_t *route; osip_route_t *route2; while (!osip_list_eol (&request_cancelled->routes, pos)) { route = (osip_route_t *) osip_list_get (&request_cancelled->routes, pos); i = osip_route_clone (route, &route2); if (i != 0) { osip_message_free (request); *dest = NULL; return i; } osip_list_add (&request->routes, route2, -1); pos++; } } osip_message_set_max_forwards (request, "70"); /* a UA should start a request with 70 */ osip_message_set_user_agent (request, eXosip.user_agent); *dest = request; return OSIP_SUCCESS; }
int _eXosip_build_response_default (osip_message_t ** dest, osip_dialog_t * dialog, int status, osip_message_t * request) { osip_generic_param_t *tag; osip_message_t *response; int pos; int i; *dest = NULL; if (request == NULL) return -1; i = osip_message_init (&response); if (i != 0) return -1; /* initialise osip_message_t structure */ /* yet done... */ response->sip_version = (char *) osip_malloc (8 * sizeof (char)); sprintf (response->sip_version, "SIP/2.0"); osip_message_set_status_code (response, status); /* handle some internal reason definitions. */ if (MSG_IS_NOTIFY (request) && status == 481) { response->reason_phrase = osip_strdup ("Subcription Does Not Exist"); } else if (MSG_IS_SUBSCRIBE (request) && status == 202) { response->reason_phrase = osip_strdup ("Accepted subscription"); } else { response->reason_phrase = osip_strdup (osip_message_get_reason (status)); if (response->reason_phrase == NULL) { if (response->status_code == 101) response->reason_phrase = osip_strdup ("Dialog Establishement"); else response->reason_phrase = osip_strdup ("Unknown code"); } response->req_uri = NULL; response->sip_method = NULL; } i = osip_to_clone (request->to, &(response->to)); if (i != 0) goto grd_error_1; i = osip_to_get_tag (response->to, &tag); if (i != 0) { /* we only add a tag if it does not already contains one! */ if ((dialog != NULL) && (dialog->local_tag != NULL)) /* it should contain the local TAG we created */ { osip_to_set_tag (response->to, osip_strdup (dialog->local_tag)); } else { if (status != 100) osip_to_set_tag (response->to, osip_to_tag_new_random ()); } } i = osip_from_clone (request->from, &(response->from)); if (i != 0) goto grd_error_1; pos = 0; 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); i = osip_via_clone (via, &via2); if (i != -0) goto grd_error_1; osip_list_add (response->vias, via2, -1); pos++; } i = osip_call_id_clone (request->call_id, &(response->call_id)); if (i != 0) goto grd_error_1; i = osip_cseq_clone (request->cseq, &(response->cseq)); if (i != 0) goto grd_error_1; if (MSG_IS_SUBSCRIBE (request)) { osip_header_t *exp; osip_header_t *evt_hdr; osip_message_header_get_byname (request, "event", 0, &evt_hdr); if (evt_hdr != NULL && evt_hdr->hvalue != NULL) osip_message_set_header (response, "Event", evt_hdr->hvalue); else osip_message_set_header (response, "Event", "presence"); i = osip_message_get_expires (request, 0, &exp); if (exp == NULL) { osip_header_t *cp; i = osip_header_clone (exp, &cp); if (cp != NULL) osip_list_add (response->headers, cp, 0); } } osip_message_set_allow (response, "INVITE"); osip_message_set_allow (response, "ACK"); osip_message_set_allow (response, "OPTIONS"); osip_message_set_allow (response, "CANCEL"); osip_message_set_allow (response, "BYE"); osip_message_set_allow (response, "SUBSCRIBE"); osip_message_set_allow (response, "NOTIFY"); osip_message_set_allow (response, "MESSAGE"); osip_message_set_allow (response, "INFO"); osip_message_set_allow (response, "REFER"); osip_message_set_allow (response, "UPDATE"); *dest = response; return 0; grd_error_1: osip_message_free (response); return -1; }
osip_message_t *ict_create_ack(osip_transaction_t * ict, osip_message_t * response) { int i; osip_message_t *ack; i = osip_message_init(&ack); if (i != 0) return NULL; /* Section 17.1.1.3: Construction of the ACK request: */ i = osip_from_clone(response->from, &(ack->from)); if (i != 0) { osip_message_free(ack); return NULL; } i = osip_to_clone(response->to, &(ack->to)); /* include the tag! */ if (i != 0) { osip_message_free(ack); return NULL; } i = osip_call_id_clone(response->call_id, &(ack->call_id)); if (i != 0) { osip_message_free(ack); return NULL; } i = osip_cseq_clone(response->cseq, &(ack->cseq)); if (i != 0) { osip_message_free(ack); return NULL; } osip_free(ack->cseq->method); ack->cseq->method = osip_strdup("ACK"); if (ack->cseq->method == NULL) { osip_message_free(ack); return NULL; } ack->sip_method = (char *) osip_malloc(5); if (ack->sip_method == NULL) { osip_message_free(ack); return NULL; } sprintf(ack->sip_method, "ACK"); ack->sip_version = osip_strdup(ict->orig_request->sip_version); if (ack->sip_version == NULL) { osip_message_free(ack); return NULL; } ack->status_code = 0; ack->reason_phrase = NULL; /* MUST copy REQUEST-URI from Contact header! */ i = osip_uri_clone(ict->orig_request->req_uri, &(ack->req_uri)); if (i != 0) { osip_message_free(ack); return NULL; } /* ACK MUST contain only the TOP Via field from original request */ { osip_via_t *via; osip_via_t *orig_via; osip_message_get_via(ict->orig_request, 0, &orig_via); if (orig_via == NULL) { osip_message_free(ack); return NULL; } i = osip_via_clone(orig_via, &via); if (i != 0) { osip_message_free(ack); return NULL; } osip_list_add(&ack->vias, via, -1); } /* ack MUST contains the ROUTE headers field from the original request */ /* IS IT TRUE??? */ /* if the answers contains a set of route (or record route), then it */ /* should be used instead?? ......May be not..... */ { int pos = 0; osip_route_t *route; osip_route_t *orig_route; while (!osip_list_eol(&ict->orig_request->routes, pos)) { orig_route = (osip_route_t *) osip_list_get(&ict->orig_request->routes, pos); i = osip_route_clone(orig_route, &route); if (i != 0) { osip_message_free(ack); return NULL; } osip_list_add(&ack->routes, route, -1); pos++; } } /* may be we could add some other headers: */ /* For example "Max-Forward" */ return ack; }
int _eXosip_build_response_default (struct eXosip_t *excontext, osip_message_t ** dest, osip_dialog_t * dialog, int status, osip_message_t * request) { osip_generic_param_t *tag; osip_message_t *response; int i; *dest = NULL; if (request == NULL) return OSIP_BADPARAMETER; i = osip_message_init (&response); if (i != 0) return i; /* initialise osip_message_t structure */ /* yet done... */ response->sip_version = (char *) osip_malloc (8 * sizeof (char)); if (response->sip_version == NULL) { osip_message_free (response); return OSIP_NOMEM; } sprintf (response->sip_version, "SIP/2.0"); osip_message_set_status_code (response, status); #ifndef MINISIZE /* handle some internal reason definitions. */ if (MSG_IS_NOTIFY (request) && status == 481) { response->reason_phrase = osip_strdup ("Subscription Does Not Exist"); } else if (MSG_IS_SUBSCRIBE (request) && status == 202) { response->reason_phrase = osip_strdup ("Accepted subscription"); } else { response->reason_phrase = osip_strdup (osip_message_get_reason (status)); if (response->reason_phrase == NULL) { if (response->status_code == 101) response->reason_phrase = osip_strdup ("Dialog Establishement"); else response->reason_phrase = osip_strdup ("Unknown code"); } response->req_uri = NULL; response->sip_method = NULL; } #else response->reason_phrase = osip_strdup (osip_message_get_reason (status)); if (response->reason_phrase == NULL) { if (response->status_code == 101) response->reason_phrase = osip_strdup ("Dialog Establishement"); else response->reason_phrase = osip_strdup ("Unknown code"); } response->req_uri = NULL; response->sip_method = NULL; #endif if (response->reason_phrase == NULL) { osip_message_free (response); return OSIP_NOMEM; } i = osip_to_clone (request->to, &(response->to)); if (i != 0) { osip_message_free (response); return i; } i = osip_to_get_tag (response->to, &tag); if (i != 0) { /* we only add a tag if it does not already contains one! */ if ((dialog != NULL) && (dialog->local_tag != NULL)) /* it should contain the local TAG we created */ { osip_to_set_tag (response->to, osip_strdup (dialog->local_tag)); } else { if (status != 100) osip_to_set_tag (response->to, _eXosip_malloc_new_random ()); } } i = osip_from_clone (request->from, &(response->from)); if (i != 0) { osip_message_free (response); return i; } { osip_list_iterator_t it; osip_via_t *via = (osip_via_t*)osip_list_get_first(&request->vias, &it); while (via != NULL) { osip_via_t *via2; i = osip_via_clone (via, &via2); if (i != 0) { osip_message_free (response); return i; } osip_list_add (&response->vias, via2, -1); via = (osip_via_t *)osip_list_get_next(&it); } } i = osip_call_id_clone (request->call_id, &(response->call_id)); if (i != 0) { osip_message_free (response); return i; } i = osip_cseq_clone (request->cseq, &(response->cseq)); if (i != 0) { osip_message_free (response); return i; } #ifndef MINISIZE if (MSG_IS_SUBSCRIBE (request)) { osip_header_t *exp; osip_header_t *evt_hdr; osip_message_header_get_byname (request, "event", 0, &evt_hdr); if (evt_hdr != NULL && evt_hdr->hvalue != NULL) osip_message_set_header (response, "Event", evt_hdr->hvalue); else osip_message_set_header (response, "Event", "presence"); i = osip_message_get_expires (request, 0, &exp); if (exp == NULL) { osip_header_t *cp; i = osip_header_clone (exp, &cp); if (cp != NULL) osip_list_add (&response->headers, cp, 0); } } #endif osip_message_set_user_agent (response, excontext->user_agent); *dest = response; return OSIP_SUCCESS; }
int osip_message_clone (const osip_message_t * sip, osip_message_t ** dest) { osip_message_t *copy; 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 i = osip_list_clone(&sip->accepts, ©->accepts, (int (*)(void *, void **)) &osip_accept_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone(&sip->accept_encodings, ©->accept_encodings, (int (*)(void *, void **)) &osip_accept_encoding_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone(&sip->accept_languages, ©->accept_languages, (int (*)(void *, void **)) &osip_accept_language_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone(&sip->alert_infos, ©->alert_infos, (int (*)(void *, void **)) &osip_alert_info_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone(&sip->allows, ©->allows, (int (*)(void *, void **)) &osip_allow_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone(&sip->authentication_infos, ©->authentication_infos, (int (*)(void *, void **)) &osip_authentication_info_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone(&sip->content_encodings, ©->content_encodings, (int (*)(void *, void **)) &osip_content_encoding_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone(&sip->error_infos, ©->error_infos, (int (*)(void *, void **)) &osip_error_info_clone); if (i != 0) { osip_message_free (copy); return i; } i = osip_list_clone(&sip->proxy_authentication_infos, ©->proxy_authentication_infos, (int (*)(void *, void **)) &osip_proxy_authentication_info_clone); if (i != 0) { osip_message_free (copy); return i; } #endif i = osip_list_clone(&sip->call_infos, ©->call_infos, (int (*)(void *, void **)) &osip_call_info_clone); if (i != 0) { osip_message_free (copy); return i; } 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 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 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; }