int osip_cseq_clone (const osip_cseq_t * cseq, osip_cseq_t ** dest) { int i; osip_cseq_t *cs; *dest = NULL; if (cseq == NULL) return OSIP_BADPARAMETER; if (cseq->method == NULL) return OSIP_BADPARAMETER; if (cseq->number == NULL) return OSIP_BADPARAMETER; i = osip_cseq_init (&cs); if (i != 0) { osip_cseq_free (cs); return i; } cs->method = osip_strdup (cseq->method); cs->number = osip_strdup (cseq->number); *dest = cs; return OSIP_SUCCESS; }
int osip_authentication_info_clone (const osip_authentication_info_t * ainfo, osip_authentication_info_t ** dest) { int i; osip_authentication_info_t *wa; *dest = NULL; if (ainfo == NULL) return -1; i = osip_authentication_info_init (&wa); if (i == -1) /* allocation failed */ return -1; if (ainfo->nextnonce != NULL) wa->nextnonce = osip_strdup (ainfo->nextnonce); if (ainfo->cnonce != NULL) wa->cnonce = osip_strdup (ainfo->cnonce); if (ainfo->rspauth != NULL) wa->rspauth = osip_strdup (ainfo->rspauth); if (ainfo->nonce_count != NULL) wa->nonce_count = osip_strdup (ainfo->nonce_count); if (ainfo->qop_options != NULL) wa->qop_options = osip_strdup (ainfo->qop_options); *dest = wa; return 0; }
int osip_cseq_clone (const osip_cseq_t * cseq, osip_cseq_t ** dest) { int i; osip_cseq_t *cs; *dest = NULL; if (cseq == NULL) return -1; if (cseq->method == NULL) return -1; if (cseq->number == NULL) return -1; i = osip_cseq_init (&cs); if (i != 0) { osip_cseq_free (cs); return -1; } cs->method = osip_strdup (cseq->method); cs->number = osip_strdup (cseq->number); *dest = cs; return 0; }
static void add_relay_info(sdp_message_t *sdp, int mline, const char *relay, const char *relay_session_id){ if (relay) sdp_message_a_attribute_add(sdp, mline, osip_strdup ("relay-addr"),osip_strdup(relay)); if (relay_session_id) sdp_message_a_attribute_add(sdp, mline, osip_strdup ("relay-session-id"), osip_strdup(relay_session_id)); }
void linphone_proxy_config_register_again_with_updated_contact(LinphoneProxyConfig *obj, osip_message_t *orig_request, osip_message_t *last_answer){ osip_message_t *msg; const char *rport,*received; osip_via_t *via=NULL; osip_generic_param_t *param=NULL; osip_contact_t *ctt=NULL; osip_message_get_via(last_answer,0,&via); if (!via) return; osip_via_param_get_byname(via,"rport",¶m); if (param) rport=param->gvalue; else return; param=NULL; osip_via_param_get_byname(via,"received",¶m); if (param) received=param->gvalue; else return; osip_message_get_contact(orig_request,0,&ctt); if (strcmp(ctt->url->host,received)==0 && (ctt->url->port!=0 && strcmp(ctt->url->port,rport)==0)){ ms_message("Register has up to date contact, doing nothing."); return; } eXosip_lock(); eXosip_register_build_register(obj->rid,obj->expires,&msg); osip_message_get_contact(msg,0,&ctt); if (ctt->url->host!=NULL){ osip_free(ctt->url->host); } ctt->url->host=osip_strdup(received); if (ctt->url->port!=NULL){ osip_free(ctt->url->port); } ctt->url->port=osip_strdup(rport); eXosip_register_send_register(obj->rid,msg); eXosip_unlock(); ms_message("Resending new register with updated contact %s:%i",received,rport); }
static int eXtl_update_local_target(osip_message_t *req) { int pos = 0; if (dtls_firewall_ip!='\0') { while (!osip_list_eol (&req->contacts, pos)) { osip_contact_t *co; co = (osip_contact_t *) osip_list_get (&req->contacts, pos); pos++; if (co != NULL && co->url != NULL && co->url->host != NULL && 0 == osip_strcasecmp (co->url->host, dtls_firewall_ip)) { if (co->url->port == NULL && 0 != osip_strcasecmp (dtls_firewall_port, "5061")) { co->url->port = osip_strdup (dtls_firewall_port); } else if (co->url->port != NULL && 0 != osip_strcasecmp (dtls_firewall_port, co->url->port)) { osip_free (co->url->port); co->url->port = osip_strdup (dtls_firewall_port); } } } } return 0; }
int osip_content_type_clone (const osip_content_type_t * ctt, osip_content_type_t ** dest) { int i; osip_content_type_t *ct; *dest = NULL; if (ctt == NULL) return OSIP_BADPARAMETER; i = osip_content_type_init (&ct); if (i != 0) /* allocation failed */ return i; if (ctt->type != NULL) ct->type = osip_strdup (ctt->type); if (ctt->subtype != NULL) ct->subtype = osip_strdup (ctt->subtype); { osip_generic_param_t *dest_param; osip_list_iterator_t it; osip_generic_param_t *u_param = (osip_generic_param_t*) osip_list_get_first(&ctt->gen_params, &it); while (u_param != OSIP_SUCCESS) { i = osip_generic_param_clone (u_param, &dest_param); if (i != 0) { osip_content_type_free (ct); return i; } osip_list_add (&ct->gen_params, dest_param, -1); u_param = (osip_generic_param_t *) osip_list_get_next(&it); } } *dest = ct; return OSIP_SUCCESS; }
int osip_header_clone (const osip_header_t * header, osip_header_t ** dest) { int i; osip_header_t *he; *dest = NULL; if (header == NULL) return OSIP_BADPARAMETER; if (header->hname == NULL) return OSIP_BADPARAMETER; i = osip_header_init (&he); if (i != 0) return i; he->hname = osip_strdup (header->hname); if (he->hname==NULL) { osip_header_free (he); return OSIP_NOMEM; } if (header->hvalue != NULL) { he->hvalue = osip_strdup (header->hvalue); if (he->hvalue==NULL) { osip_header_free (he); return OSIP_NOMEM; } } *dest = he; return OSIP_SUCCESS; }
static void sip_rewrite_osip_uri(osip_uri_t* uri, char* host, char* username) { if (NULL != uri->host) osip_free(uri->host); if (NULL != uri->username) osip_free(uri->username); uri->host = osip_strdup(host); uri->username = osip_strdup(username); }
/* refuse the line */ static void refuse_mline(sdp_message_t *answer,char *mtype,char *proto, int mline) { sdp_message_m_media_add (answer, osip_strdup (mtype), int_2char (0), NULL, osip_strdup (proto)); /* add a payload just to comply with sdp RFC.*/ sdp_message_m_payload_add(answer,mline,int_2char(0)); }
int eXosip_call_get_referto (int did, char *refer_to, size_t refer_to_len) { eXosip_dialog_t *jd = NULL; eXosip_call_t *jc = NULL; osip_transaction_t *tr = NULL; osip_uri_t *referto_uri; char atmp[256]; char *referto_tmp = NULL; int i; if (did <= 0) return OSIP_BADPARAMETER; eXosip_call_dialog_find (did, &jc, &jd); if (jc == NULL || jd == NULL || jd->d_dialog == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No call here?\n")); return OSIP_NOTFOUND; } tr = eXosip_find_last_invite (jc, jd); if (tr == NULL || tr->orig_request == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No transaction for call?\n")); return OSIP_NOTFOUND; } i = osip_uri_clone (jd->d_dialog->remote_uri->url, &referto_uri); if (i != 0) return i; snprintf (atmp, sizeof (atmp), "%s;to-tag=%s;from-tag=%s", jd->d_dialog->call_id, jd->d_dialog->remote_tag, jd->d_dialog->local_tag); osip_uri_uheader_add (referto_uri, osip_strdup ("Replaces"), osip_strdup (atmp)); i = osip_uri_to_str (referto_uri, &referto_tmp); if (i != 0) { osip_uri_free (referto_uri); return i; } snprintf (refer_to, refer_to_len, "%s", referto_tmp); osip_uri_free (referto_uri); return OSIP_SUCCESS; }
sdp_context_t *sdp_handler_create_context(sdp_handler_t *handler, const char *localip, const char *username, const char *relay){ sdp_context_t *ctx=osip_malloc(sizeof(sdp_context_t)); memset(ctx,0,sizeof(sdp_context_t)); if (localip!=NULL) ctx->localip=osip_strdup(localip); ctx->username=osip_strdup(username); ctx->handler=handler; if (relay){ ctx->relay=osip_strdup(relay); ctx->relay_session_id=make_relay_session_id(username,relay); } return ctx; }
void init_gateway_map(void) { gw_count = 0; gateway_map[gw_count].dp = NULL; gateway_map[gw_count].host = osip_strdup("sip.sipgate.com"); gateway_map[gw_count].username = osip_strdup("user"); gateway_map[gw_count].password = osip_strdup("password"); gateway_map[gw_count].port = 5060; gw_count++; }
/* * 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; }
/* to add payloads to the offer, must be called inside the write_offer callback */ void sdp_context_add_payload (sdp_context_t * ctx, sdp_payload_t * payload, char *media) { sdp_message_t *offer = ctx->offer; char *attr_field; if (!ctx->incb) { eXosip_trace (OSIP_ERROR, ("You must not call sdp_context_add_*_payload outside the write_offer callback\n")); abort (); } if (payload->proto == NULL) payload->proto = "RTP/AVP"; /*printf("payload->line=%i payload->pt=%i\n",payload->line, payload->pt);*/ if (sdp_message_m_media_get (offer, payload->line) == NULL) { /*printf("Adding new mline %s \n",media);*/ /* need a new line */ sdp_message_m_media_add (offer, osip_strdup (media), int_2char (payload->localport), NULL, osip_strdup (payload->proto)); if (ctx->relay){ add_relay_info(offer,payload->line,ctx->relay,ctx->relay_session_id); } } sdp_message_m_payload_add (offer, payload->line, int_2char (payload->pt)); if (payload->a_rtpmap != NULL) { attr_field = sstrdup_sprintf ("%i %s", payload->pt, payload->a_rtpmap); sdp_message_a_attribute_add (offer, payload->line, osip_strdup ("rtpmap"), attr_field); } if (payload->a_fmtp != NULL) { attr_field = sstrdup_sprintf ("%i %s", payload->pt, payload->a_fmtp); sdp_message_a_attribute_add (offer, payload->line, osip_strdup ("fmtp"), attr_field); } if (payload->b_as_bandwidth != 0) { if (sdp_message_bandwidth_get(offer,payload->line,0)==NULL){ attr_field = sstrdup_sprintf ("%i", payload->b_as_bandwidth); sdp_message_b_bandwidth_add (offer, payload->line, osip_strdup ("AS"), attr_field); } } }
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; }
int osip_from_clone (const osip_from_t * from, osip_from_t ** dest) { int i; osip_from_t *fr; *dest = NULL; if (from == NULL) return -1; i = osip_from_init (&fr); if (i != 0) /* allocation failed */ return -1; if (from->displayname != NULL) fr->displayname = osip_strdup (from->displayname); if (from->url != NULL) { i = osip_uri_clone (from->url, &(fr->url)); if (i != 0) { osip_from_free (fr); return -1; } } i = osip_list_clone(&from->gen_params, &fr->gen_params, (int *(*)(void *, void *)) &osip_generic_param_clone); if (i != 0) { osip_from_free (fr); return -1; } *dest = fr; return 0; }
int osip_call_info_clone (const osip_call_info_t * ctt, osip_call_info_t ** dest) { int i; osip_call_info_t *ct; *dest = NULL; if (ctt == NULL) return OSIP_BADPARAMETER; if (ctt->element == NULL) return OSIP_BADPARAMETER; i = osip_call_info_init (&ct); if (i != 0) /* allocation failed */ return i; ct->element = osip_strdup (ctt->element); if (ct->element==NULL) { osip_call_info_free (ct); return OSIP_NOMEM; } i = osip_list_clone(&ctt->gen_params, &ct->gen_params, &osip_generic_param_clone); if (i != 0) { osip_call_info_free (ct); return i; } *dest = ct; return OSIP_SUCCESS; }
int osip_content_length_clone (const osip_content_length_t * ctl, osip_content_length_t ** dest) { int i; osip_content_length_t *cl; *dest = NULL; if (ctl == NULL) return OSIP_BADPARAMETER; /* empty headers are allowed: if (ctl->value==NULL) return -1; */ i = osip_content_length_init (&cl); if (i != 0) /* allocation failed */ return i; if (ctl->value != NULL) { cl->value = osip_strdup (ctl->value); if (cl->value == NULL) { osip_content_length_free (cl); return OSIP_NOMEM; } } *dest = cl; return OSIP_SUCCESS; }
int eXosip_update_top_via (osip_message_t * sip) { unsigned int number; char tmp[40]; osip_generic_param_t *br=NULL; osip_via_t *via = (osip_via_t *) osip_list_get (&sip->vias, 0); if (via==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "missing via in SIP message\n")); return -1; } /* browse parameter and replace "branch" */ osip_via_param_get_byname (via, "branch", &br); if (br==NULL || br->gvalue==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "missing branch parameter via in SIP message\n")); return -1; } osip_free(br->gvalue); number = osip_build_random_number (); sprintf (tmp, "z9hG4bK%u", number); br->gvalue = osip_strdup(tmp); return 0; }
void linphone_proxy_config_set_route(LinphoneProxyConfig *obj, const char *route) { int err; osip_uri_param_t *lr_param=NULL; osip_route_t *rt=NULL; char *tmproute=NULL; if (route!=NULL && strlen(route)>0){ osip_route_init(&rt); err=osip_route_parse(rt,route); if (err<0){ ms_warning("Could not parse %s",route); osip_route_free(rt); return ; } if (obj->reg_route!=NULL) { ms_free(obj->reg_route); obj->reg_route=NULL; } /* check if the lr parameter is set , if not add it */ osip_uri_uparam_get_byname(rt->url, "lr", &lr_param); if (lr_param==NULL){ osip_uri_uparam_add(rt->url,osip_strdup("lr"),NULL); osip_route_to_str(rt,&tmproute); obj->reg_route=ms_strdup(tmproute); osip_free(tmproute); }else obj->reg_route=ms_strdup(route); }else{ if (obj->reg_route!=NULL) ms_free(obj->reg_route); obj->reg_route=NULL; } }
int osip_dialog_update_tag_as_uac (osip_dialog_t * dialog, osip_message_t * response) { osip_generic_param_t *tag; int i; if (dialog == NULL) return OSIP_BADPARAMETER; if (response == NULL || response->to == NULL) return OSIP_BADPARAMETER; if (dialog->remote_tag != NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "This dialog already have a remote tag: it can't be changed!\n")); return OSIP_WRONG_STATE; } i = osip_to_get_tag (response->to, &tag); if (i != 0 || tag == NULL || tag->gvalue == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Remote UA is not compliant: missing a tag in response!\n")); dialog->remote_tag = NULL; } else dialog->remote_tag = osip_strdup (tag->gvalue); return OSIP_SUCCESS; }
/* returns null on error. */ int osip_content_length_to_str (const osip_content_length_t * cl, char **dest) { if (cl == NULL) return -1; *dest = osip_strdup (cl->value); return 0; }
int osip_negotiation_sdp_message_put_on_hold (sdp_message_t * sdp) { int pos; int pos_media = -1; char *rcvsnd; int recv_send = -1; pos = 0; rcvsnd = sdp_message_a_att_field_get (sdp, pos_media, pos); while (rcvsnd != NULL) { if (rcvsnd != NULL && 0 == strcmp (rcvsnd, "sendonly")) { recv_send = 0; } else if (rcvsnd != NULL && (0 == strcmp (rcvsnd, "recvonly") || 0 == strcmp (rcvsnd, "sendrecv"))) { recv_send = 0; sprintf (rcvsnd, "sendonly"); } pos++; rcvsnd = sdp_message_a_att_field_get (sdp, pos_media, pos); } pos_media = 0; while (!sdp_message_endof_media (sdp, pos_media)) { pos = 0; rcvsnd = sdp_message_a_att_field_get (sdp, pos_media, pos); while (rcvsnd != NULL) { if (rcvsnd != NULL && 0 == strcmp (rcvsnd, "sendonly")) { recv_send = 0; } else if (rcvsnd != NULL && (0 == strcmp (rcvsnd, "recvonly") || 0 == strcmp (rcvsnd, "sendrecv"))) { recv_send = 0; sprintf (rcvsnd, "sendonly"); } pos++; rcvsnd = sdp_message_a_att_field_get (sdp, pos_media, pos); } pos_media++; } if (recv_send == -1) { /* we need to add a global attribute with a field set to "sendonly" */ sdp_message_a_attribute_add (sdp, -1, osip_strdup ("sendonly"), NULL); } return 0; }
int osip_content_type_clone (const osip_content_type_t * ctt, osip_content_type_t ** dest) { int i; osip_content_type_t *ct; *dest = NULL; if (ctt == NULL) return -1; if (ctt->type == NULL) return -1; if (ctt->subtype == NULL) return -1; i = osip_content_type_init (&ct); if (i != 0) /* allocation failed */ return -1; ct->type = osip_strdup (ctt->type); ct->subtype = osip_strdup (ctt->subtype); { int pos = 0; osip_generic_param_t *u_param; osip_generic_param_t *dest_param; while (!osip_list_eol (ctt->gen_params, pos)) { u_param = (osip_generic_param_t *) osip_list_get (ctt->gen_params, pos); i = osip_generic_param_clone (u_param, &dest_param); if (i != 0) { osip_content_type_free (ct); osip_free (ct); return -1; } osip_list_add (ct->gen_params, dest_param, -1); pos++; } } *dest = ct; return 0; }
static char *make_relay_session_id(const char *username, const char *relay){ /*ideally this should be a hash of the parameters with a random part*/ char tmp[128]; int s1=(int)random(); int s2=(int)random(); long long int res=((long long int)s1)<<32 | (long long int) s2; void *src=&res; b64_encode(src, sizeof(long long int), tmp, sizeof(tmp)); return osip_strdup(tmp); }
/* returns null on error. */ int osip_content_length_to_str (const osip_content_length_t * cl, char **dest) { if (cl == NULL) return OSIP_BADPARAMETER; *dest = osip_strdup (cl->value); if (*dest == NULL) return OSIP_NOMEM; return OSIP_SUCCESS; }
static char * ua_sdp_get_video_port (osip_negotiation_ctx_t * context, int pos_media) { ua_context_t *ua_con; ua_con = (ua_context_t *) context->mycontext; return osip_strdup (ua_con->m_video_port); /* this port should not be static ... */ /* also, this method should be called more than once... */ /* If there is more than one audio line, this may fail :( */ }
char * jidentity_get_identity(int fid) { jidentity_t *fr; for (fr = eXosip.j_identitys; fr!=NULL ; fr=fr->next) { if (fid==0) return osip_strdup(fr->i_identity); fid--; } return NULL; }
static int jidentity_init(jidentity_t **fr, char *ch) { char *next; int i; *fr = (jidentity_t *)osip_malloc(sizeof(jidentity_t)); if (*fr==NULL) return -1; i = jidentity_get_and_set_next_token(&((*fr)->i_identity), ch, &next); if (i != 0) goto ji_error1; osip_clrspace ((*fr)->i_identity); ch = next; i = jidentity_get_and_set_next_token(&((*fr)->i_registrar), next, &next); if (i != 0) goto ji_error2; osip_clrspace ((*fr)->i_registrar); ch = next; i = jidentity_get_and_set_next_token(&((*fr)->i_realm), ch, &next); if (i != 0) goto ji_error3; osip_clrspace ((*fr)->i_realm); ch = next; i = jidentity_get_and_set_next_token(&((*fr)->i_userid), ch, &next); if (i != 0) goto ji_error4; osip_clrspace ((*fr)->i_userid); (*fr)->i_pwd = osip_strdup(next); osip_clrspace ((*fr)->i_pwd); if ((*fr)->i_pwd!=NULL && (*fr)->i_pwd[0]!='\0') { eXosip_add_authentication_info((*fr)->i_userid, (*fr)->i_userid, (*fr)->i_pwd, NULL, (*fr)->i_realm); } return 0; ji_error4: osip_free((*fr)->i_realm); ji_error3: osip_free((*fr)->i_registrar); ji_error2: osip_free((*fr)->i_identity); ji_error1: osip_free(*fr); *fr = NULL; return -1; }