Example #1
0
/* 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);
		}
	}
}
Example #2
0
static int		sip_get_address(osip_message_t *msg, u_int *host, u_short *port)
{
  osip_content_type_t	*ctt;
  sdp_message_t		*sdp;
  char			*tmp;
  int			i;
  int			j;

  if (NULL == (ctt = osip_message_get_content_type(msg)))
    return 0;
  if ((NULL == ctt->type) || (NULL == ctt->subtype))
    return 0;
  if (osip_strcasecmp(ctt->type, "application"))
    return 0;
  if (osip_strcasecmp(ctt->subtype, "sdp"))
    return 0;
  for (i = 0; !osip_list_eol(msg->bodies, i); ++i) {
    sdp = NULL;
    sdp_message_init(&sdp);
    tmp = ((osip_body_t *)osip_list_get(msg->bodies, i))->body;
    if (sdp_message_parse(sdp, tmp)) {
      sdp_message_free(sdp);
      continue;
    }
    for (j = 0; NULL != sdp_message_m_media_get(sdp, j); ++j) {
      if (NULL == (tmp = sdp_message_m_port_get(sdp, j)))
	continue;
      *port = atoi(tmp);
      if (NULL == (tmp = sdp_message_c_addr_get(sdp, -1, 0)))
	if (NULL == (tmp = sdp_message_c_addr_get(sdp, j, 0)))
	  continue;
      *host = (u_int)inet_addr(tmp);
      sdp_message_free(sdp);
      return 1;
    }
    sdp_message_free(sdp);
  }
  return 0;
}
Example #3
0
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;
}
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;
}
Example #5
0
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;
}
Example #7
0
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);
				}
			}
		}
	}
}
Example #8
0
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;
	}
}
Example #9
0
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;
}