int sdp_to_media_description(sdp_message_t *msg, SalMediaDescription *desc){ int i,j; const char *mtype,*proto,*port,*addr,*number; sdp_bandwidth_t *sbw=NULL; addr=sdp_message_c_addr_get (msg, -1, 0); if (addr) strncpy(desc->addr,addr,sizeof(desc->addr)); for(j=0;(sbw=sdp_message_bandwidth_get(msg,-1,j))!=NULL;++j){ if (strcasecmp(sbw->b_bwtype,"AS")==0) desc->bandwidth=atoi(sbw->b_bandwidth); } /* for each m= line */ for (i=0; !sdp_message_endof_media (msg, i) && i<SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++) { SalStreamDescription *stream=&desc->streams[i]; memset(stream,0,sizeof(*stream)); mtype = sdp_message_m_media_get(msg, i); proto = sdp_message_m_proto_get (msg, i); port = sdp_message_m_port_get(msg, i); stream->proto=SalProtoUnknown; if (proto){ if (strcasecmp(proto,"RTP/AVP")==0) stream->proto=SalProtoRtpAvp; else if (strcasecmp(proto,"RTP/SAVP")==0){ stream->proto=SalProtoRtpSavp; } } addr = sdp_message_c_addr_get (msg, i, 0); if (addr != NULL) strncpy(stream->addr,addr,sizeof(stream->addr)); if (port) stream->port=atoi(port); stream->ptime=_sdp_message_get_a_ptime(msg,i); if (strcasecmp("audio", mtype) == 0){ stream->type=SalAudio; }else if (strcasecmp("video", mtype) == 0){ stream->type=SalVideo; }else { stream->type=SalOther; strncpy(stream->typeother,mtype,sizeof(stream->typeother)-1); } for(j=0;(sbw=sdp_message_bandwidth_get(msg,i,j))!=NULL;++j){ if (strcasecmp(sbw->b_bwtype,"AS")==0) stream->bandwidth=atoi(sbw->b_bandwidth); } stream->dir=_sdp_message_get_mline_dir(msg,i); /* for each payload type */ for (j=0;((number=sdp_message_m_payload_get (msg, i,j)) != NULL); j++){ const char *rtpmap,*fmtp; int ptn=atoi(number); PayloadType *pt=payload_type_new(); payload_type_set_number(pt,ptn); /* get the rtpmap associated to this codec, if any */ rtpmap=sdp_message_a_attr_value_get_with_pt(msg, i,ptn,"rtpmap"); if (payload_type_fill_from_rtpmap(pt,rtpmap)==0){ /* get the fmtp, if any */ fmtp=sdp_message_a_attr_value_get_with_pt(msg, i, ptn,"fmtp"); payload_type_set_send_fmtp(pt,fmtp); stream->payloads=ms_list_append(stream->payloads,pt); ms_message("Found payload %s/%i fmtp=%s",pt->mime_type,pt->clock_rate, pt->send_fmtp ? pt->send_fmtp : ""); } } } desc->nstreams=i; return 0; }
int parse_sdp_file(arguments_t *a, char addrs[MAX_CHANNELS_IN_SESSION][INET6_ADDRSTRLEN], char ports[MAX_CHANNELS_IN_SESSION][MAX_PORT_LENGTH], char *sdp_buf) { int i; int m_lines = 0; int j = 0; int number_of_port; int number_of_address; int nb_of_accepted_ch = 0; int nb_of_defined_ch = 0; struct sockaddr_in ipv4; struct sockaddr_in6 ipv6; int position = 0; #ifdef _MSC_VER int addr_size; #else char *ep; #endif int m_line_att_pos; char *att_name; char *att_value; BOOL supported_fec = FALSE; BOOL fec_inst_exists = FALSE; char *addr_type = NULL; char *source_filter = NULL; char *tsi = NULL; char *flute_ch = NULL; int flute_ch_number; char *start_time = NULL; char *stop_time = NULL; fec_dec_t *fec_dec; fec_dec_t *current_fec_dec; sdp_message_init(&a->sdp); if(sdp_message_parse(a->sdp, sdp_buf) != 0) { printf("Error: sdp_parse()\n"); fflush(stdout); return -1; } if((source_filter = sdp_attr_get(a->sdp, "source-filter")) == NULL) { printf("Error: Invalid SDP, source-filter not present.\n"); fflush(stdout); return -1; } else { a->src_filt = sf_char2struct(source_filter); a->alc_a.src_addr = a->src_filt->src_addr; } if((tsi = sdp_attr_get(a->sdp, "flute-tsi")) == NULL) { printf("Error: Invalid SDP, TSI not present.\n"); fflush(stdout); return -1; } else { a->alc_a.tsi = (unsigned int)atoi(tsi); } /* Default channel number is one and it is overwrited if there is 'a:flute-ch' in the SDP file. */ flute_ch_number = 1; flute_ch = sdp_attr_get(a->sdp, "flute-ch"); if(flute_ch != NULL) { flute_ch_number = (unsigned int)atoi(flute_ch); } if((addr_type = sdp_message_c_addrtype_get(a->sdp, 0, 0)) == NULL) { printf("Error: Invalid SDP, no valid 'c' field.\n"); fflush(stdout); return -1; } else { if(strcmp(addr_type, "IP4") == 0) { a->alc_a.addr_family = PF_INET; } else if(strcmp(addr_type, "IP6") == 0) { a->alc_a.addr_family = PF_INET6; } else { printf("Error: Invalid SDP, address type invalid.\n"); fflush(stdout); return -1; } } /* fetch session starttime */ start_time = sdp_message_t_start_time_get (a->sdp, 0); if(start_time != NULL) { #ifdef _MSC_VER a->alc_a.start_time = _atoi64(start_time); if(a->alc_a.start_time > (unsigned long long)0xFFFFFFFFFFFFFFFF) { printf("Error: Invalid SDP, start time too big.\n"); fflush(stdout); return -1; } #else a->alc_a.start_time = strtoull(start_time, &ep, 10); if(errno == ERANGE && a->alc_a.start_time == 0xFFFFFFFFFFFFFFFFULL) { printf("Error: Invalid SDP, start time too big.\n"); fflush(stdout); return -1; } #endif } /* fetch session stoptime */ stop_time = sdp_message_t_stop_time_get (a->sdp, 0); if(stop_time != NULL) { #ifdef _MSC_VER a->alc_a.stop_time = _atoi64(stop_time); if(a->alc_a.stop_time > (unsigned long long)0xFFFFFFFFFFFFFFFF) { printf("Error: Invalid SDP, stop time too big.\n"); fflush(stdout); return -1; } #else a->alc_a.stop_time = strtoull(stop_time, &ep, 10); if(errno == ERANGE && a->alc_a.stop_time == 0xFFFFFFFFFFFFFFFFULL) { printf("Error: Invalid SDP, stop time too big.\n"); fflush(stdout); return -1; } #endif if(a->alc_a.stop_time == 0) { a->cont = TRUE; } } /* Session level FEC declaration */ fec_dec = sdp_fec_dec_get(a->sdp); /* Search how many m-lines is defined in SDP */ while(1) { if(sdp_message_endof_media(a->sdp, position) == 0) { /* check that 'proto' field is FLUTE/UDP */ if(strcmp(sdp_message_m_proto_get(a->sdp, position), "FLUTE/UDP") == 0) { /* check that payload number exists */ if(sdp_message_m_payload_get(a->sdp, position, 0) != NULL) { m_lines++; } } position++; } else { break; } } if(m_lines == 0) { printf("Error: Invalid SDP, no valid 'm' field.\n"); fflush(stdout); fec_dec_free(fec_dec); return -1; } for(i = 0; i < m_lines; i++) { m_line_att_pos = 0; while((att_name = sdp_message_a_att_field_get(a->sdp, i, m_line_att_pos)) != NULL) { if(strcmp(att_name, "FEC") == 0) { fec_inst_exists = TRUE; att_value = sdp_message_a_att_value_get(a->sdp, i, m_line_att_pos); if(fec_dec == NULL) { printf("Error: Invalid SDP, FEC-declaration does not exists.\n"); fflush(stdout); return -1; } current_fec_dec = fec_dec; while(current_fec_dec != NULL) { if(current_fec_dec->index == (unsigned int)atoi(att_value)) { if(current_fec_dec->fec_enc_id == COM_NO_C_FEC_ENC_ID) { a->alc_a.fec_enc_id = COM_NO_C_FEC_ENC_ID; a->alc_a.fec_inst_id = 0; supported_fec = TRUE; } else if(current_fec_dec->fec_enc_id == SIMPLE_XOR_FEC_ENC_ID) { a->alc_a.fec_enc_id = SIMPLE_XOR_FEC_ENC_ID; a->alc_a.fec_inst_id = 0; supported_fec = TRUE; } else if(current_fec_dec->fec_enc_id == RS_FEC_ENC_ID) { a->alc_a.fec_enc_id = RS_FEC_ENC_ID; a->alc_a.fec_inst_id = 0; supported_fec = TRUE; } else if(current_fec_dec->fec_enc_id == SB_SYS_FEC_ENC_ID && current_fec_dec->fec_inst_id == REED_SOL_FEC_INST_ID) { a->alc_a.fec_enc_id = SB_SYS_FEC_ENC_ID; a->alc_a.fec_inst_id = REED_SOL_FEC_INST_ID; supported_fec = TRUE; } } current_fec_dec = current_fec_dec->next; } } else if(strcmp(att_name, "FEC-declaration") == 0) { fec_inst_exists = TRUE; att_value = sdp_message_a_att_value_get(a->sdp, i, m_line_att_pos); current_fec_dec = fec_dec_char2struct(att_value); if(current_fec_dec->fec_enc_id == COM_NO_C_FEC_ENC_ID) { a->alc_a.fec_enc_id = COM_NO_C_FEC_ENC_ID; a->alc_a.fec_inst_id = 0; supported_fec = TRUE; } else if(current_fec_dec->fec_enc_id == SIMPLE_XOR_FEC_ENC_ID) { a->alc_a.fec_enc_id = SIMPLE_XOR_FEC_ENC_ID; a->alc_a.fec_inst_id = 0; supported_fec = TRUE; } else if(current_fec_dec->fec_enc_id == RS_FEC_ENC_ID) { a->alc_a.fec_enc_id = RS_FEC_ENC_ID; a->alc_a.fec_inst_id = 0; supported_fec = TRUE; } else if(current_fec_dec->fec_enc_id == SB_SYS_FEC_ENC_ID && current_fec_dec->fec_inst_id == REED_SOL_FEC_INST_ID) { a->alc_a.fec_enc_id = SB_SYS_FEC_ENC_ID; a->alc_a.fec_inst_id = REED_SOL_FEC_INST_ID; supported_fec = TRUE; } fec_dec_free(current_fec_dec); } m_line_att_pos++; } if(fec_inst_exists == FALSE) { supported_fec = TRUE; a->alc_a.fec_enc_id = COM_NO_C_FEC_ENC_ID; a->alc_a.fec_inst_id = 0; } /* how many ports in m-line */ if(sdp_message_m_number_of_port_get(a->sdp, i) == NULL) { number_of_port = 1; } else { number_of_port = atoi(sdp_message_m_number_of_port_get(a->sdp, i)); } /* how many addresses in c-line */ if(sdp_message_c_addr_multicast_int_get(a->sdp, i, 0) == NULL) { number_of_address = 1; } else { number_of_address = atoi(sdp_message_c_addr_multicast_int_get(a->sdp, i, 0)); } if(((number_of_port != 1) && (number_of_address != 1))) { printf("Error: Invalid SDP, confusing number of ports and addresses.\n"); fflush(stdout); fec_dec_free(fec_dec); return -1; } if(number_of_address == 1) { for(j = 0; j < number_of_port; j++) { if(supported_fec == TRUE) { memset(ports[nb_of_accepted_ch], 0, MAX_PORT_LENGTH); memset(addrs[nb_of_accepted_ch], 0, INET6_ADDRSTRLEN); sprintf(ports[nb_of_accepted_ch], "%i", (atoi(sdp_message_m_port_get(a->sdp, i)) + j)); strcpy(addrs[nb_of_accepted_ch], sdp_message_c_addr_get(a->sdp, i, 0)); nb_of_accepted_ch++; } nb_of_defined_ch++; } } else if(number_of_port == 1) { for(j = 0; j < number_of_address; j++) { if(supported_fec == TRUE) { if(a->alc_a.addr_family == PF_INET) { memset(addrs[nb_of_accepted_ch], 0, INET6_ADDRSTRLEN); ipv4.sin_addr.s_addr = htonl(ntohl(inet_addr(a->alc_a.addr)) + j); sprintf(addrs[j], "%s", inet_ntoa(ipv4.sin_addr)); memset(ports[nb_of_accepted_ch], 0, MAX_PORT_LENGTH); sprintf(ports[nb_of_accepted_ch], "%i", atoi(sdp_message_m_port_get(a->sdp, i))); } else if(a->alc_a.addr_family == PF_INET6) { #ifdef _MSC_VER addr_size = sizeof(struct sockaddr_in6); WSAStringToAddress((char*)a->alc_a.addr, AF_INET6, NULL, (struct sockaddr*)&ipv6, &addr_size); #else inet_pton(AF_INET6, a->alc_a.addr, &ipv6.sin6_addr); #endif memset(addrs[nb_of_accepted_ch], 0, INET6_ADDRSTRLEN); #ifdef _MSC_VER addr_size = sizeof(addrs[nb_of_accepted_ch]); WSAAddressToString((struct sockaddr*)&ipv6, sizeof(struct sockaddr_in6), NULL, addrs[nb_of_accepted_ch], &addr_size); #else inet_ntop(AF_INET6, &ipv6.sin6_addr, addrs[nb_of_accepted_ch], sizeof(addrs[nb_of_accepted_ch])); #endif memset(ports[nb_of_accepted_ch], 0, MAX_PORT_LENGTH); sprintf(ports[nb_of_accepted_ch], "%i", atoi(sdp_message_m_port_get(a->sdp, i))); if(j < (a->alc_a.nb_channel - 1)) { if(increase_ipv6_address(&ipv6.sin6_addr) == -1) { printf("Increasing IPv6 address %s is not possible\n", addrs[j]); fec_dec_free(fec_dec); return -1; } } } nb_of_accepted_ch++; } nb_of_defined_ch++; } } } if(flute_ch_number != nb_of_defined_ch) { printf("Error: Invalid SDP, channel number not correct.\n"); fflush(stdout); fec_dec_free(fec_dec); return -1; } a->alc_a.nb_channel = nb_of_accepted_ch; fec_dec_free(fec_dec); return 0; }
static int sdp_confirm_media (osip_negotiation_t * config, osip_negotiation_ctx_t * context, sdp_message_t * remote, sdp_message_t ** dest) { char *payload; char *tmp, *tmp2, *tmp3, *tmp4; int ret; int i; int k; int audio_qty = 0; /* accepted audio line: do not accept more than one */ int video_qty = 0; i = 0; while (!sdp_message_endof_media (remote, i)) { tmp = sdp_message_m_media_get (remote, i); tmp2 = sdp_message_m_port_get (remote, i); tmp3 = sdp_message_m_number_of_port_get (remote, i); tmp4 = sdp_message_m_proto_get (remote, i); if (tmp == NULL) return -1; sdp_message_m_media_add (*dest, osip_strdup (tmp), osip_strdup ("0"), NULL, osip_strdup (tmp4)); k = 0; if (0 == strncmp (tmp, "audio", 5)) { do { payload = sdp_message_m_payload_get (remote, i, k); if (payload != NULL) { __payload_t *my_payload = osip_negotiation_find_audio_payload (config, payload); if (my_payload != NULL) /* payload is supported */ { ret = -1; /* somtimes, codec can be refused even if supported */ if (config->fcn_accept_audio_codec != NULL) ret = config->fcn_accept_audio_codec (context, tmp2, tmp3, audio_qty, payload); if (0 == ret) { sdp_message_m_payload_add (*dest, i, osip_strdup (payload)); if (my_payload->a_rtpmap != NULL) sdp_message_a_attribute_add (*dest, i, osip_strdup ("rtpmap"), osip_strdup (my_payload-> a_rtpmap)); if (my_payload->c_nettype != NULL) { sdp_media_t *med = osip_list_get ((*dest)->m_medias, i); if (osip_list_eol (med->c_connections, 0)) sdp_message_c_connection_add (*dest, i, osip_strdup (my_payload-> c_nettype), osip_strdup (my_payload-> c_addrtype), osip_strdup (my_payload-> c_addr), osip_strdup (my_payload-> c_addr_multicast_ttl), osip_strdup (my_payload-> c_addr_multicast_int)); } } } } k++; } while (payload != NULL); if (NULL != sdp_message_m_payload_get (*dest, i, 0)) audio_qty = 1; } else if (0 == strncmp (tmp, "video", 5)) { do { payload = sdp_message_m_payload_get (remote, i, k); if (payload != NULL) { __payload_t *my_payload = osip_negotiation_find_video_payload (config, payload); if (my_payload != NULL) /* payload is supported */ { ret = -1; if (config->fcn_accept_video_codec != NULL) ret = config->fcn_accept_video_codec (context, tmp2, tmp3, video_qty, payload); if (0 == ret) { sdp_message_m_payload_add (*dest, i, osip_strdup (payload)); /* TODO set the attribute list (rtpmap..) */ if (my_payload->a_rtpmap != NULL) sdp_message_a_attribute_add (*dest, i, osip_strdup ("rtpmap"), osip_strdup (my_payload-> a_rtpmap)); if (my_payload->c_nettype != NULL) { sdp_media_t *med = osip_list_get ((*dest)->m_medias, i); if (osip_list_eol (med->c_connections, 0)) sdp_message_c_connection_add (*dest, i, osip_strdup (my_payload-> c_nettype), osip_strdup (my_payload-> c_addrtype), osip_strdup (my_payload-> c_addr), osip_strdup (my_payload-> c_addr_multicast_ttl), osip_strdup (my_payload-> c_addr_multicast_int)); } } } } k++; } while (payload != NULL); if (NULL != sdp_message_m_payload_get (*dest, i, 0)) video_qty = 1; } else { do { payload = sdp_message_m_payload_get (remote, i, k); if (payload != NULL) { __payload_t *my_payload = osip_negotiation_find_other_payload (config, payload); if (my_payload != NULL) /* payload is supported */ { ret = -1; if (config->fcn_accept_other_codec != NULL) ret = config->fcn_accept_other_codec (context, tmp, tmp2, tmp3, payload); if (0 == ret) { sdp_message_m_payload_add (*dest, i, osip_strdup (payload)); /* rtpmap has no meaning here! */ if (my_payload->c_nettype != NULL) { sdp_media_t *med = osip_list_get ((*dest)->m_medias, i); if (osip_list_eol (med->c_connections, 0)) sdp_message_c_connection_add (*dest, i, osip_strdup (my_payload-> c_nettype), osip_strdup (my_payload-> c_addrtype), osip_strdup (my_payload-> c_addr), osip_strdup (my_payload-> c_addr_multicast_ttl), osip_strdup (my_payload-> c_addr_multicast_int)); } } } } k++; } while (payload != NULL); } i++; } return 0; }
int osip_negotiation_ctx_execute_negotiation (osip_negotiation_t * config, osip_negotiation_ctx_t * context) { int m_lines_that_match = 0; sdp_message_t *remote; sdp_message_t *local; int i; if (context == NULL) return -1; remote = context->remote; if (remote == NULL) return -1; i = sdp_message_init (&local); if (i != 0) return -1; if (0 != strncmp (remote->v_version, "0", 1)) { sdp_message_free (local); /* sdp_context->fcn_wrong_version(context); */ return 406; /* Not Acceptable */ } i = sdp_partial_clone (config, context, remote, &local); if (i != 0) { sdp_message_free (local); return -1; } i = sdp_confirm_media (config, context, remote, &local); if (i != 0) { sdp_message_free (local); return i; } i = 0; while (!sdp_message_endof_media (local, i)) { /* this is to refuse each line with no codec that matches! */ if (NULL == sdp_message_m_payload_get (local, i, 0)) { sdp_media_t *med = osip_list_get ((local)->m_medias, i); char *str = sdp_message_m_payload_get (remote, i, 0); sdp_message_m_payload_add (local, i, osip_strdup (str)); osip_free (med->m_port); med->m_port = osip_strdup ("0"); /* refuse this line */ } else { /* number of "m" lines that match */ sdp_media_t *med = osip_list_get (local->m_medias, i); m_lines_that_match++; osip_free (med->m_port); /* AMD: use the correct fcn_get_xxx_port method: */ if (0 == strcmp (med->m_media, "audio")) { if (config->fcn_get_audio_port != NULL) med->m_port = config->fcn_get_audio_port (context, i); else med->m_port = osip_strdup ("0"); /* should never happen */ } else if (0 == strcmp (med->m_media, "video")) { if (config->fcn_get_video_port != NULL) med->m_port = config->fcn_get_video_port (context, i); else med->m_port = osip_strdup ("0"); /* should never happen */ } else { if (config->fcn_get_other_port != NULL) med->m_port = config->fcn_get_other_port (context, i); else med->m_port = osip_strdup ("0"); /* should never happen */ } } i++; } if (m_lines_that_match > 0) { context->local = local; return 200; } else { sdp_message_free (local); return 415; } }
static char * generating_no_sdp_answer(eXosip_call_t *jc, eXosip_dialog_t *jd, osip_message_t *orig_request, char *local_sdp_port, char *local_video_port) { sdp_message_t *local_sdp = NULL; char *local_body = NULL; char *size; int i; jc->c_ack_sdp = 1; if(osip_negotiation_sdp_build_offer(eXosip.osip_negotiation, NULL, &local_sdp, local_sdp_port, local_video_port) != 0) return NULL; if (local_sdp!=NULL) { int pos=0; while (!sdp_message_endof_media (local_sdp, pos)) { int k = 0; char *tmp = sdp_message_m_media_get (local_sdp, pos); if (0 == strncmp (tmp, "audio", 5)) { char *payload = NULL; do { payload = sdp_message_m_payload_get (local_sdp, pos, k); if (payload == NULL) { } else if (0==strncmp("110",payload,3)) { sdp_message_a_attribute_add (local_sdp, pos, osip_strdup ("AS"), osip_strdup ("110 20")); } else if (0==strncmp("111",payload,3)) { sdp_message_a_attribute_add (local_sdp, pos, osip_strdup ("AS"), osip_strdup ("111 20")); } k++; } while (payload != NULL); } pos++; } } i = sdp_message_to_str(local_sdp, &local_body); if (local_body!=NULL) { size= (char *)osip_malloc(7*sizeof(char)); #ifdef __APPLE_CC__ sprintf(size,"%li",strlen(local_body)); #else sprintf(size,"%i",strlen(local_body)); #endif osip_message_set_content_length(orig_request, size); osip_free(size); osip_message_set_body(orig_request, local_body, strlen(local_body)); osip_message_set_content_type(orig_request, "application/sdp"); } else osip_message_set_content_length(orig_request, "0"); osip_negotiation_ctx_set_local_sdp(jc->c_ctx, local_sdp); OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO3,NULL,"200 OK w/ SDP (RESPONSE TO INVITE w/ NO SDP)=\n%s\n", local_body)); return local_body; }
/*--------------------------------------------------------------------*/ static int sdp_filter_codec(sdp_message_t *sdp) { int sts; int i; char *sdp_media; int media_stream_no; // SDP payload list processing char *payload; int payload_mediatype; int payload_no; // SDP attribute list processing sdp_attribute_t *sdp_attr; int attr_mediatype; int media_attr_no; int skip_media_attr_inc=0; // // loop through all media descriptions (normal phone call has 1 stream, a video call // may have multiple streams) // media_stream_no=0; while ((sdp_media=sdp_message_m_media_get(sdp, media_stream_no))) { // // loop through all media attributes of this media stream // media_attr_no=0; while ((sdp_attr=sdp_message_attribute_get(sdp, media_stream_no, media_attr_no))) { DEBUGC(DBCLASS_PLUGIN, " +--Attr m:%i, a=%i", media_stream_no, media_attr_no); // check if attribute field and value exist if (sdp_attr->a_att_field && sdp_attr->a_att_value) { // fetch the media type value (first number field in value) attr_mediatype=0; sts=sscanf(sdp_attr->a_att_value, "%i", &attr_mediatype); DEBUGC(DBCLASS_PLUGIN, " +--Attr field=%s, val=%s [MT=%i]", sdp_attr->a_att_field, sdp_attr->a_att_value, attr_mediatype); // // loop through all configured "blacklisted" media strings // and look for a match // for (i=0; i<plugin_cfg.codec_blacklist.used; i++) { // do an *case-insensitive* *substring* match if (strcasestr(sdp_attr->a_att_value, plugin_cfg.codec_blacklist.string[i])) { // match, need to remove this codec DEBUGC(DBCLASS_PLUGIN, "%s: blacklisted - removing media attr [%s] at attrpos=%i", name, sdp_attr->a_att_value, media_attr_no); // // remove media attribute (a) // // libosip bug?? -> the following coda causes an infinite loop inside libosip2. //if (sdp_message_a_attribute_del_at_index(sdp, media_stream_no, sdp_attr->a_att_field, media_attr_no) != OSIP_SUCCESS) { // ERROR("%s: sdp_message_a_attribute_del() failed", name); //} // #&%+!@ -> So it manually... { sdp_media_t *med; sdp_attribute_t *attr; med = (sdp_media_t *) osip_list_get(&sdp->m_medias, media_stream_no); if ((attr = osip_list_get(&med->a_attributes, media_attr_no)) != NULL) { osip_list_remove(&med->a_attributes, media_attr_no); sdp_attribute_free(attr); attr=NULL; // as I have removed the current attribute, all other // attributes are shifted one down, so for the next iteration // I must not increment the index or I will skip one attribute skip_media_attr_inc=1; } } // // find corresponding (m) payload and remove it as well$ // // loop through all payloads of the current media description payload_no=0; while ((payload=sdp_message_m_payload_get(sdp, media_stream_no, payload_no))) { // extract the media type from the payload payload_mediatype=0; sts=sscanf(payload, "%i", &payload_mediatype); DEBUGC(DBCLASS_PLUGIN, " +-- payload:%s MT=%i", payload, payload_mediatype); // medfia type matches? if (payload_mediatype == attr_mediatype) { DEBUGC(DBCLASS_PLUGIN, "%s: blacklisted - removing media format %i at stream=%i, pos=%i", name, payload_mediatype, media_stream_no, payload_no); // remove (m) playload in media description if (sdp_message_m_payload_del(sdp, media_stream_no, payload_no) != OSIP_SUCCESS) { ERROR("%s: sdp_message_a_attribute_del() failed", name); } } else { // increment index only if the current payload has not been removed // as all other medias would have shifted down. payload_no++; } } /* while playload */ } /* if match with config blacklist */ } /* for codec_blacklist */ } /* if attribute field and value exist */ // increment index only of the current media attribute has not been deleted if (skip_media_attr_inc == 0) { media_attr_no++; } else { skip_media_attr_inc=0; } } /* while sdp_message_attribute_get */ media_stream_no++; } /* while sdp_message_m_media_get */ return STS_SUCCESS; }
void sdp_context_read_answer (sdp_context_t *ctx, sdp_message_t *remote) { char *mtype; char *proto, *port, *pt; int i, j,err; char *relay; sdp_payload_t payload,arg_payload; sdp_handler_t *sdph=ctx->handler; sdp_bandwidth_t *sbw=NULL; /* for each m= line */ for (i = 0; !sdp_message_endof_media (remote, i); i++) { sdp_payload_init(&payload); mtype = sdp_message_m_media_get (remote, i); proto = sdp_message_m_proto_get (remote, i); port = sdp_message_m_port_get (remote, i); payload.remoteport = osip_atoi (port); payload.localport = osip_atoi (sdp_message_m_port_get (ctx->offer, i)); payload.proto = proto; payload.line = i; payload.c_addr = sdp_message_c_addr_get (remote, i, 0); if (payload.c_addr == NULL) payload.c_addr = sdp_message_c_addr_get (remote, -1, 0); /*parse relay address if given*/ relay=sdp_message_a_attr_value_get(remote,i,"relay-addr"); if (relay){ payload.relay_host=parse_relay_addr(relay,&payload.relay_port); } payload.relay_session_id=sdp_message_a_attr_value_get(remote,i,"relay-session-id"); for(j=0;(sbw=sdp_message_bandwidth_get(remote,i,j))!=NULL;++j){ if (strcasecmp(sbw->b_bwtype,"AS")==0) payload.b_as_bandwidth=atoi(sbw->b_bandwidth); } payload.a_ptime=_sdp_message_get_a_ptime(remote,i); if (keywordcmp ("audio", mtype) == 0) { if (sdph->get_audio_codecs != NULL) { /* for each payload type */ for (j = 0; ((pt = sdp_message_m_payload_get (remote, i, j)) != NULL); j++) { payload.pt = osip_atoi (pt); /* get the rtpmap associated to this codec, if any */ payload.a_rtpmap = sdp_message_a_attr_value_get_with_pt (remote, i, payload.pt, "rtpmap"); /* get the fmtp, if any */ payload.a_fmtp = sdp_message_a_attr_value_get_with_pt (remote, i, payload.pt, "fmtp"); /* ask the application if this codec is supported */ memcpy(&arg_payload,&payload,sizeof(payload)); err = sdph->get_audio_codecs (ctx, &arg_payload); } } } else if (keywordcmp ("video", mtype) == 0) { if (sdph->get_video_codecs != NULL) { /* for each payload type */ for (j = 0; ((pt = sdp_message_m_payload_get (remote, i, j)) != NULL); j++) { payload.pt = osip_atoi (pt); /* get the rtpmap associated to this codec, if any */ payload.a_rtpmap = sdp_message_a_attr_value_get_with_pt (remote, i, payload.pt, "rtpmap"); /* get the fmtp, if any */ payload.a_fmtp = sdp_message_a_attr_value_get_with_pt (remote, i, payload.pt, "fmtp"); /* ask the application if this codec is supported */ memcpy(&arg_payload,&payload,sizeof(payload)); err = sdph->get_video_codecs (ctx, &arg_payload); } } } } }
char * sdp_context_get_answer ( sdp_context_t *ctx,sdp_message_t *remote) { sdp_message_t *answer=NULL; char *mtype=NULL, *tmp=NULL; char *proto=NULL, *port=NULL, *pt=NULL; int i, j, ncodec, m_lines_accepted = 0; int err; sdp_payload_t payload; sdp_handler_t *sdph=ctx->handler; sdp_bandwidth_t *sbw=NULL; char *relay; tmp = sdp_message_c_addr_get (remote, 0, 0); if (tmp == NULL) tmp = sdp_message_c_addr_get (remote, -1, 0); if (ctx->localip==NULL) { /* NULL means guess, otherwise we use the address given as localip */ ctx->localip=osip_malloc(128); eXosip_guess_localip(strchr(tmp,':') ? AF_INET6 : AF_INET,ctx->localip,128); } else eXosip_trace(OSIP_INFO1,("Using firewall address in sdp.")); answer = sdp_context_generate_template (ctx); /* for each m= line */ for (i = 0; !sdp_message_endof_media (remote, i); i++) { sdp_payload_init(&payload); mtype = sdp_message_m_media_get (remote, i); proto = sdp_message_m_proto_get (remote, i); port = sdp_message_m_port_get (remote, i); payload.remoteport = osip_atoi (port); payload.proto = proto; payload.line = i; payload.c_addr = sdp_message_c_addr_get (remote, i, 0); if (payload.c_addr == NULL) payload.c_addr = sdp_message_c_addr_get (remote, -1, 0); /*parse relay address if given*/ relay=sdp_message_a_attr_value_get(remote,i,"relay-addr"); if (relay){ payload.relay_host=parse_relay_addr(relay,&payload.relay_port); } payload.relay_session_id=sdp_message_a_attr_value_get(remote,i,"relay-session-id"); /* get application specific bandwidth, if any */ for(j=0;(sbw=sdp_message_bandwidth_get(remote,i,j))!=NULL;j++){ if (strcasecmp(sbw->b_bwtype,"AS")==0) payload.b_as_bandwidth=atoi(sbw->b_bandwidth); } payload.a_ptime=_sdp_message_get_a_ptime(remote,i); if (keywordcmp ("audio", mtype) == 0) { if (sdph->accept_audio_codecs != NULL) { ncodec = 0; /* for each payload type */ for (j = 0; ((pt = sdp_message_m_payload_get (remote, i, j)) != NULL); j++) { payload.pt = osip_atoi (pt); /* get the rtpmap associated to this codec, if any */ payload.a_rtpmap = sdp_message_a_attr_value_get_with_pt (remote, i, payload.pt, "rtpmap"); /* get the fmtp, if any */ payload.a_fmtp = sdp_message_a_attr_value_get_with_pt (remote, i, payload.pt, "fmtp"); /* ask the application if this codec is supported */ err = sdph->accept_audio_codecs (ctx, &payload); if (err == 0 && payload.localport > 0) { ncodec++; /* codec accepted */ if (ncodec == 1) { /* first codec accepted, setup the line */ sdp_message_m_media_add (answer, osip_strdup (mtype), int_2char (payload. localport), NULL, osip_strdup (proto)); /* and accept the remote relay addr if we planned to use our own */ if (ctx->relay!=NULL && relay){ add_relay_info(answer,i,relay,payload.relay_session_id); } } /* add the payload, rtpmap, fmtp */ sdp_message_m_payload_add (answer, i, int_2char (payload. pt)); if (payload.a_rtpmap != NULL) { sdp_message_a_attribute_add (answer, i, osip_strdup ("rtpmap"), sstrdup_sprintf ("%i %s", payload.pt, payload. a_rtpmap)); } if (payload.a_fmtp != NULL) { sdp_message_a_attribute_add (answer, i, osip_strdup ("fmtp"), sstrdup_sprintf ("%i %s", payload.pt, payload. a_fmtp)); } if (payload.b_as_bandwidth != 0) { if (sdp_message_bandwidth_get(answer,i,0)==NULL) sdp_message_b_bandwidth_add (answer, i, osip_strdup ("AS"), sstrdup_sprintf ("%i", payload. b_as_bandwidth)); } } } if (ncodec == 0) { /* refuse the line */ refuse_mline(answer,mtype,proto,i); } else m_lines_accepted++; } else { /* refuse this line (leave port to 0) */ refuse_mline(answer,mtype,proto,i); } } else if (keywordcmp ("video", mtype) == 0) { if (sdph->accept_video_codecs != NULL) { ncodec = 0; /* for each payload type */ for (j = 0; ((pt = sdp_message_m_payload_get (remote, i, j)) != NULL); j++) { payload.pt = osip_atoi (pt); /* get the rtpmap associated to this codec, if any */ payload.a_rtpmap = sdp_message_a_attr_value_get_with_pt (remote, i, payload.pt, "rtpmap"); /* get the fmtp, if any */ payload.a_fmtp = sdp_message_a_attr_value_get_with_pt (remote, i, payload.pt, "fmtp"); /* ask the application if this codec is supported */ err = sdph->accept_video_codecs (ctx, &payload); if (err == 0 && payload.localport > 0) { ncodec++; /* codec accepted */ if (ncodec == 1) { /* first codec accepted, setup the line */ sdp_message_m_media_add (answer, osip_strdup (mtype), int_2char (payload.localport), NULL, osip_strdup (proto)); /* and accept the remote relay addr if we planned to use our own */ if (ctx->relay!=NULL && relay){ add_relay_info(answer,i,relay,payload.relay_session_id); } } /* add the payload, rtpmap, fmtp */ sdp_message_m_payload_add (answer, i, int_2char (payload. pt)); if (payload.a_rtpmap != NULL) { sdp_message_a_attribute_add (answer, i, osip_strdup ("rtpmap"), sstrdup_sprintf ("%i %s", payload.pt, payload. a_rtpmap)); } if (payload.a_fmtp != NULL) { sdp_message_a_attribute_add (answer, i, osip_strdup ("fmtp"), sstrdup_sprintf ("%i %s", payload.pt, payload. a_fmtp)); } if (payload.b_as_bandwidth !=0) { if (sdp_message_bandwidth_get(answer,i,0)==NULL) sdp_message_b_bandwidth_add (answer, i, osip_strdup ("AS"), sstrdup_sprintf ("%i", payload. b_as_bandwidth)); } } } if (ncodec == 0) { /* refuse the line */ refuse_mline(answer,mtype,proto,i); } else m_lines_accepted++; } else { /* refuse the line */ refuse_mline(answer,mtype,proto,i); } } } if (ctx->answer!=NULL) sdp_message_free(ctx->answer); ctx->answer = answer; if (m_lines_accepted > 0){ ctx->negoc_status = 200; sdp_message_to_str(answer,&tmp); if (ctx->answerstr!=NULL) osip_free(ctx->answerstr); ctx->answerstr=tmp; return tmp; }else{ ctx->negoc_status = 415; return NULL; } }
int test_accessor_get_api (sdp_message_t * sdp) { char *tmp; char *tmp2; char *tmp3; char *tmp4; char *tmp5; int i; int k; if (sdp_message_v_version_get (sdp)) printf ("v_version: |%s|\n", sdp_message_v_version_get (sdp)); if (sdp_message_o_username_get (sdp)) printf ("o_originator: |%s|", sdp_message_o_username_get (sdp)); if (sdp_message_o_sess_id_get (sdp)) printf (" |%s|", sdp_message_o_sess_id_get (sdp)); if (sdp_message_o_sess_version_get (sdp) != NULL) printf (" |%s|", sdp_message_o_sess_version_get (sdp)); if (sdp_message_o_nettype_get (sdp)) printf (" |%s|", sdp_message_o_nettype_get (sdp)); if (sdp_message_o_addrtype_get (sdp)) printf (" |%s|", sdp_message_o_addrtype_get (sdp)); if (sdp_message_o_addr_get (sdp)) printf (" |%s|\n", sdp_message_o_addr_get (sdp)); if (sdp_message_s_name_get (sdp)) printf ("s_name: |%s|\n", sdp_message_s_name_get (sdp)); if (sdp_message_i_info_get (sdp, -1)) printf ("i_info: |%s|\n", sdp_message_i_info_get (sdp, -1)); if (sdp_message_u_uri_get (sdp)) printf ("u_uri: |%s|\n", sdp_message_u_uri_get (sdp)); i = 0; do { tmp = sdp_e_email_get (sdp, i); if (tmp != NULL) printf ("e_email: |%s|\n", tmp); i++; } while (tmp != NULL); i = 0; do { tmp = sdp_message_p_phone_get (sdp, i); if (tmp != NULL) printf ("p_phone: |%s|\n", tmp); i++; } while (tmp != NULL); k = 0; tmp = sdp_message_c_nettype_get (sdp, -1, k); tmp2 = sdp_message_c_addrtype_get (sdp, -1, k); tmp3 = sdp_message_c_addr_get (sdp, -1, k); tmp4 = sdp_message_c_addr_multicast_ttl_get (sdp, -1, k); tmp5 = sdp_message_c_addr_multicast_int_get (sdp, -1, k); if (tmp != NULL && tmp4 != NULL && tmp5 != NULL) printf ("c_connection: |%s| |%s| |%s| |%s| |%s|\n", tmp, tmp2, tmp3, tmp4, tmp5); else if (tmp != NULL && tmp4 != NULL) printf ("c_connection: |%s| |%s| |%s| |%s| |%s|\n", tmp, tmp2, tmp3, tmp4, "(null)"); else if (tmp != NULL && tmp5 != NULL) printf ("c_connection: |%s| |%s| |%s| |%s| |%s|\n", tmp, tmp2, tmp3, "(null)", tmp5); k = 0; do { tmp = sdp_message_b_bwtype_get (sdp, -1, k); tmp2 = sdp_message_b_bandwidth_get (sdp, -1, k); if (tmp != NULL && tmp2 != NULL) printf ("b_bandwidth: |%s|:|%s|\n", tmp, tmp2); else if (tmp != NULL) printf ("b_bandwidth: |%s|:|%s|\n", tmp, "(null)"); k++; } while (tmp != NULL); k = 0; do { tmp = sdp_message_t_start_time_get (sdp, k); tmp2 = sdp_message_t_stop_time_get (sdp, k); if (tmp != NULL && tmp2 != NULL) printf ("t_descr_time: |%s| |%s|\n", tmp, tmp2); else if (tmp != NULL) printf ("t_descr_time: |%s| |%s|\n", tmp, "(null)"); i = 0; do { tmp2 = sdp_message_r_repeat_get (sdp, k, i); i++; if (tmp2 != NULL) printf ("r_repeat: |%s|\n", tmp2); } while (tmp2 != NULL); k++; } while (tmp != NULL); /* TODO r */ if (sdp_message_z_adjustments_get (sdp) != NULL) printf ("z_adjustments: |%s|\n", sdp_message_z_adjustments_get (sdp)); tmp = sdp_message_k_keytype_get (sdp, -1); tmp2 = sdp_message_k_keydata_get (sdp, -1); if (tmp != NULL && tmp2 != NULL) printf ("k_key: |%s|:|%s|\n", tmp, tmp2); else if (tmp != NULL) printf ("k_key: |%s|:|%s|\n", tmp, "(null)"); k = 0; do { tmp = sdp_message_a_att_field_get (sdp, -1, k); tmp2 = sdp_message_a_att_value_get (sdp, -1, k); if (tmp != NULL && tmp2 != NULL) printf ("a_attribute: |%s|:|%s|\n", tmp, tmp2); if (tmp != NULL) printf ("a_attribute: |%s|:|%s|\n", tmp, "(null)"); k++; } while (tmp != NULL); i = 0; while (!sdp_message_endof_media (sdp, i)) { tmp = sdp_message_m_media_get (sdp, i); tmp2 = sdp_message_m_port_get (sdp, i); tmp3 = sdp_message_m_number_of_port_get (sdp, i); tmp4 = sdp_message_m_proto_get (sdp, i); if (tmp != NULL) printf ("m_media: |%s|", tmp); else printf ("m_media: |%s|", "(null)"); if (tmp2 != NULL) printf (" |%s|", tmp2); else printf (" |%s|", "(null)"); if (tmp3 != NULL) printf (" |%s|", tmp3); else printf (" |%s|", "(null)"); if (tmp4 != NULL) printf (" |%s|", tmp4); else printf (" |%s|", "(null)"); k = 0; do { tmp = sdp_message_m_payload_get (sdp, i, k); if (tmp != NULL) printf (" |%s|", tmp); k++; } while (tmp != NULL); printf ("\n"); k = 0; do { tmp = sdp_message_c_nettype_get (sdp, i, k); tmp2 = sdp_message_c_addrtype_get (sdp, i, k); tmp3 = sdp_message_c_addr_get (sdp, i, k); tmp4 = sdp_message_c_addr_multicast_ttl_get (sdp, i, k); tmp5 = sdp_message_c_addr_multicast_int_get (sdp, i, k); if (tmp != NULL) printf ("c_connection: |%s| |%s| |%s| |%s| |%s|\n", tmp, tmp2, tmp3, tmp4, tmp5); else printf ("c_connection: |%s|", "(null)"); if (tmp2 != NULL) printf (" |%s|", tmp2); else printf (" |%s|", "(null)"); if (tmp3 != NULL) printf (" |%s|", tmp3); else printf (" |%s|", "(null)"); if (tmp4 != NULL) printf (" |%s|", tmp4); else printf (" |%s|", "(null)"); if (tmp5 != NULL) printf (" |%s|", tmp5); else printf (" |%s|", "(null)"); printf ("\n"); if (tmp != NULL) k++; } while (tmp != NULL); k = 0; do { tmp = sdp_message_b_bwtype_get (sdp, i, k); tmp2 = sdp_message_b_bandwidth_get (sdp, i, k); if (tmp != NULL) printf ("b_bandwidth: |%s|", tmp); else printf ("b_bandwidth: |%s|", "(null)"); if (tmp2 != NULL) printf (":|%s|\n", tmp2); else printf (":|%s|", "(null)"); printf ("\n"); k++; } while (tmp != NULL); tmp = sdp_message_k_keytype_get (sdp, i); tmp2 = sdp_message_k_keydata_get (sdp, i); if (tmp != NULL) printf ("k_key: |%s|", tmp); else printf ("k_key: |%s|", "(null)"); if (tmp2 != NULL) printf (":|%s|", tmp2); else printf (":|%s|", "(null)"); printf ("\n"); k = 0; do { tmp = sdp_message_a_att_field_get (sdp, i, k); tmp2 = sdp_message_a_att_value_get (sdp, i, k); if (tmp != NULL) printf ("a_attribute: |%s|", tmp); else printf ("a_attribute: |%s|", "(null)"); if (tmp2 != NULL) printf (":|%s|", tmp2); else printf (":|%s|", "(null)"); printf ("\n"); k++; } while (tmp != NULL); i++; } return 0; }