char * sdp_message_a_att_value_get (sdp_message_t * sdp, int pos_media, int pos) { sdp_attribute_t *attr = sdp_message_attribute_get (sdp, pos_media, pos); if (attr == NULL) return NULL; return attr->a_att_value; }
/* return the value of attr "field" */ static const char *sdp_message_a_attr_value_get(sdp_message_t *sdp,int pos,const char *field) { int i; sdp_attribute_t *attr; for (i=0;(attr=sdp_message_attribute_get(sdp,pos,i))!=NULL;i++){ if (keywordcmp(field,attr->a_att_field)==0 && attr->a_att_value!=NULL){ return attr->a_att_value; } } return NULL; }
static int _sdp_message_get_a_ptime(sdp_message_t *sdp, int mline){ int i,ret; sdp_attribute_t *attr; for (i=0;(attr=sdp_message_attribute_get(sdp,mline,i))!=NULL;i++){ if (keywordcmp("ptime",attr->a_att_field)==0){ int nb = sscanf(attr->a_att_value,"%i",&ret); /* the return value may depend on how %n is interpreted by the libc: see manpage*/ if (nb == 1){ return ret; }else ms_warning("sdp has a strange a=ptime line (%s) ",attr->a_att_value); } } return 0; }
static int _sdp_message_get_mline_dir(sdp_message_t *sdp, int mline){ int i; sdp_attribute_t *attr; for (i=0;(attr=sdp_message_attribute_get(sdp,mline,i))!=NULL;i++){ if (keywordcmp("sendrecv",attr->a_att_field)==0){ return SalStreamSendRecv; }else if (keywordcmp("sendonly",attr->a_att_field)==0){ return SalStreamSendOnly; }else if (keywordcmp("recvonly",attr->a_att_field)==0){ return SalStreamSendOnly; }else if (keywordcmp("inactive",attr->a_att_field)==0){ return SalStreamInactive; } } return SalStreamSendRecv; }
/* return the value of attr "field" for payload pt at line pos (field=rtpmap,fmtp...)*/ static const char *sdp_message_a_attr_value_get_with_pt(sdp_message_t *sdp,int pos,int pt,const char *field) { int i,tmppt=0,scanned=0; char *tmp; sdp_attribute_t *attr; for (i=0;(attr=sdp_message_attribute_get(sdp,pos,i))!=NULL;i++){ if (keywordcmp(field,attr->a_att_field)==0 && attr->a_att_value!=NULL){ int nb = sscanf(attr->a_att_value,"%i %n",&tmppt,&scanned); /* the return value may depend on how %n is interpreted by the libc: see manpage*/ if (nb == 1 || nb==2 ){ if (pt==tmppt){ tmp=attr->a_att_value+scanned; if (strlen(tmp)>0) return tmp; } }else ms_warning("sdp has a strange a= line (%s) nb=%i",attr->a_att_value,nb); } } return NULL; }
/*--------------------------------------------------------------------*/ 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; }