int sdp_message_a_attribute_add (sdp_message_t * sdp, int pos_media, char *att_field, char *att_value) { int i; sdp_media_t *med; sdp_attribute_t *attr; if (sdp == NULL) return -1; if ((pos_media != -1) && (osip_list_size (&sdp->m_medias) < pos_media + 1)) return -1; i = sdp_attribute_init (&attr); if (i != 0) return -1; attr->a_att_field = att_field; attr->a_att_value = att_value; if (pos_media == -1) { osip_list_add (&sdp->a_attributes, attr, -1); return 0; } med = (sdp_media_t *) osip_list_get (&sdp->m_medias, pos_media); osip_list_add (&med->a_attributes, attr, -1); return 0; }
int test_add_codec(struct osip_rfc3264 *cnf, int codec_type, int payload, char *attribute) { sdp_media_t *med; sdp_attribute_t *attr; char *tmp; int i; if (payload>127) return -1; if (attribute==NULL || strlen(attribute)==0) return -1; i = sdp_media_init(&med); if (i!=0) goto error; tmp = malloc(4); snprintf(tmp, 3, "%i", payload); med->m_proto = strdup("RTP/AVP"); osip_list_add(med->m_payloads, tmp, -1); i = sdp_attribute_init (&attr); if (i != 0) return -1; attr->a_att_field = strdup("rtpmap"); attr->a_att_value = strdup(attribute); osip_list_add (med->a_attributes, attr, -1); switch(codec_type) { case AUDIO_CODEC: med->m_media = strdup("audio"); osip_rfc3264_add_audio_media(cnf, med, -1); break; case VIDEO_CODEC: med->m_media = strdup("video"); osip_rfc3264_add_video_media(cnf, med, -1); break; } return 0; error: return -1; }
static int sdp_message_parse_a (sdp_message_t * sdp, char *buf, char **next) { char *equal; char *crlf; char *tmp; char *tmp_next; int i; sdp_attribute_t *a_attribute; char *colon; *next = buf; equal = buf; while ((*equal != '=') && (*equal != '\0')) equal++; if (*equal == '\0') return ERR_ERROR; /* check if header is "a" */ if (equal[-1] != 'a') return ERR_DISCARD; crlf = equal + 1; while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0')) crlf++; if (*crlf == '\0') return ERR_ERROR; if (crlf == equal + 1) return ERR_ERROR; /* a=\r ?? bad header */ tmp = equal + 1; i = sdp_attribute_init (&a_attribute); if (i != 0) return ERR_ERROR; /* a=att-field[:att-value] */ /* is there any att-value? */ colon = strchr (equal + 1, ':'); if ((colon != NULL) && (colon < crlf)) { /* att-field is alpha-numeric */ i = __osip_set_next_token (&(a_attribute->a_att_field), tmp, ':', &tmp_next); if (i != 0) { sdp_attribute_free (a_attribute); return -1; } tmp = tmp_next; i = __osip_set_next_token (&(a_attribute->a_att_value), tmp, '\r', &tmp_next); if (i != 0) { i = __osip_set_next_token (&(a_attribute->a_att_value), tmp, '\n', &tmp_next); if (i != 0) { sdp_attribute_free (a_attribute); return -1; } } } else { i = __osip_set_next_token (&(a_attribute->a_att_field), tmp, '\r', &tmp_next); if (i != 0) { i = __osip_set_next_token (&(a_attribute->a_att_field), tmp, '\n', &tmp_next); if (i != 0) { sdp_attribute_free (a_attribute); return -1; } } } /* add the attribute at the correct place: if there is no media line yet, then the "a=" is the global one. */ i = osip_list_size (sdp->m_medias); if (i == 0) osip_list_add (sdp->a_attributes, a_attribute, -1); else { sdp_media_t *last_sdp_media = (sdp_media_t *) osip_list_get (sdp->m_medias, i - 1); osip_list_add (last_sdp_media->a_attributes, a_attribute, -1); } if (crlf[1] == '\n') *next = crlf + 2; else *next = crlf + 1; return WF; }