Bug 798873 - Signaling SDP construction uses flex_string r=jesup

This commit is contained in:
Ethan Hugg 2012-10-08 16:43:33 -07:00
parent c4f39bb7ab
commit 94d4df0c19
10 changed files with 779 additions and 1211 deletions

View File

@ -53,8 +53,6 @@
#define SDP_CHOOSE_PARAM (-1)
#define SDP_SESSION_LEVEL 0xFFFF
#define SDP_MAX_LEN 4096
#define UNKNOWN_CRYPTO_SUITE "UNKNOWN_CRYPTO_SUITE"
#define AES_CM_128_HMAC_SHA1_32 "AES_CM_128_HMAC_SHA1_32"
#define AES_CM_128_HMAC_SHA1_80 "AES_CM_128_HMAC_SHA1_80"
@ -575,7 +573,7 @@ extern void *sdp_init_description(void *config_p);
extern void sdp_debug(void *sdp_ptr, sdp_debug_e debug_type, tinybool debug_flag);
extern void sdp_set_string_debug(void *sdp_ptr, char *debug_str);
extern sdp_result_e sdp_parse(void *sdp_ptr, char **bufp, u16 len);
extern sdp_result_e sdp_build(void *sdp_ptr, char **bufp, u16 len);
extern sdp_result_e sdp_build(void *sdp_ptr, flex_string *fs);
extern void *sdp_copy(void *sdp_ptr);
extern sdp_result_e sdp_free_description(void *sdp_ptr);

File diff suppressed because it is too large Load Diff

View File

@ -1141,18 +1141,14 @@ sdp_result_e sdp_parse (void *sdp_ptr, char **bufp, u16 len)
* Description: Build an SDP description in the specified buffer based
* on the information in the given SDP structure.
* Parameters: sdp_ptr The SDP handle returned by sdp_init_description
* bufp Pointer to the buffer where the SDP description
* should be built.
* len The maximum length of the SDP/length of the buffer.
* fs A flex_string where the SDP description should be built.
* Returns: A result value indicating if the build was successful and
* if not, what type of error was encountered - e.g.,
* description was too long for the given buffer.
*/
sdp_result_e sdp_build (void *sdp_ptr, char **bufp, u16 len)
sdp_result_e sdp_build (void *sdp_ptr, flex_string *fs)
{
int i, j;
char *ptr = NULL;
char *endbuf_p;
sdp_t *sdp_p = (sdp_t *)sdp_ptr;
sdp_result_e result = SDP_SUCCESS;
@ -1160,7 +1156,7 @@ sdp_result_e sdp_build (void *sdp_ptr, char **bufp, u16 len)
return (SDP_INVALID_SDP_PTR);
}
if ((bufp == NULL) || (*bufp == NULL)) {
if (!fs) {
return (SDP_NULL_BUF_PTR);
}
@ -1168,26 +1164,22 @@ sdp_result_e sdp_build (void *sdp_ptr, char **bufp, u16 len)
SDP_PRINT("%s Trace SDP Build:", sdp_p->debug_str);
}
ptr = *bufp;
sdp_p->conf_p->num_builds++;
/* Find ptr to the end of the buf for recalculating len remaining. */
endbuf_p = ptr + len;
for (i=0; ((i < SDP_TOKEN_M) &&
(result == SDP_SUCCESS) && (endbuf_p - ptr > 0)); i++) {
result = sdp_token[i].build_func(sdp_p, SDP_SESSION_LEVEL, &ptr, (u16)(endbuf_p - ptr));
(result == SDP_SUCCESS)); i++) {
result = sdp_token[i].build_func(sdp_p, SDP_SESSION_LEVEL, fs);
/* ok not to check buffer space (yet) as the if() checks it */
}
/* If the session level was ok, build the media lines. */
if ((result == SDP_SUCCESS) && (endbuf_p - ptr > 0)) {
if (result == SDP_SUCCESS) {
for (i=1; ((i <= sdp_p->mca_count) &&
(result == SDP_SUCCESS) && (endbuf_p - ptr > 0)); i++) {
result = sdp_token[SDP_TOKEN_M].build_func(sdp_p, (u16)i, &ptr, (u16)(endbuf_p - ptr));
(result == SDP_SUCCESS)); i++) {
result = sdp_token[SDP_TOKEN_M].build_func(sdp_p, (u16)i, fs);
/* ok not to check buffer space (yet) as the for() checks it */
for (j=SDP_TOKEN_I;
((j < SDP_TOKEN_M) && (result == SDP_SUCCESS) && (endbuf_p - ptr > 0));
((j < SDP_TOKEN_M) && (result == SDP_SUCCESS));
j++) {
if ((j == SDP_TOKEN_U) || (j == SDP_TOKEN_E) ||
(j == SDP_TOKEN_P) || (j == SDP_TOKEN_T) ||
@ -1195,25 +1187,12 @@ sdp_result_e sdp_build (void *sdp_ptr, char **bufp, u16 len)
/* These tokens not valid at media level. */
continue;
}
result = sdp_token[j].build_func(sdp_p, (u16)i, &ptr, (u16)(endbuf_p - ptr));
result = sdp_token[j].build_func(sdp_p, (u16)i, fs);
/* ok not to check buffer space (yet) as the for() checks it */
}
}
}
/* Return the pointer where we left off. */
*bufp = ptr;
if (result == SDP_SUCCESS) {
if ((endbuf_p - ptr) <= 1) {
/*
* The buffer was too small, or just big enough, to hold
* the sdp. Some of the sdp may have gotten dropped.
*/
result = SDP_POTENTIAL_SDP_OVERFLOW;
}
}
return (result);
}

View File

@ -46,7 +46,6 @@
/* SDP Defines */
#define SDP_MAX_STRING_LEN 256 /* Max len for SDP string */
#define SDP_MAX_CANDIDATE_LEN 256 /* Max len for SDP string */
#define SDP_MAX_SHORT_STRING_LEN 12 /* Max len for a short SDP string */
#define SDP_MAX_PAYLOAD_TYPES 23 /* Max payload types in m= line */
#define SDP_TOKEN_LEN 2 /* Len of <token>= */
@ -453,7 +452,7 @@ typedef struct sdp_attr {
tinybool boolean_val;
u32 u32_val;
char string_val[SDP_MAX_STRING_LEN+1];
char ice_attr[SDP_MAX_CANDIDATE_LEN];
char ice_attr[SDP_MAX_STRING_LEN+1];
sdp_fmtp_t fmtp;
sdp_qos_t qos;
sdp_curr_t curr;
@ -552,7 +551,7 @@ typedef struct {
typedef struct {
char *name;
sdp_result_e (*parse_func)(sdp_t *sdp_p, u16 level, const char *ptr);
sdp_result_e (*build_func)(sdp_t *sdp_p, u16 level, char **ptr, u16 len);
sdp_result_e (*build_func)(sdp_t *sdp_p, u16 level, flex_string *fs);
} sdp_tokenarray_t;
@ -563,7 +562,7 @@ typedef struct {
sdp_result_e (*parse_func)(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
sdp_result_e (*build_func)(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
} sdp_attrarray_t;
@ -608,139 +607,139 @@ extern sdp_result_e sdp_parse_attribute(sdp_t *sdp_p, u16 level,
extern sdp_result_e sdp_parse_attr_simple_string(sdp_t *sdp_p,
sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_simple_string(sdp_t *sdp_p,
sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_simple_u32(sdp_t *sdp_p,
sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_simple_u32(sdp_t *sdp_p,
sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_simple_bool(sdp_t *sdp_p,
sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_simple_bool(sdp_t *sdp_p,
sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_maxprate(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_parse_attr_fmtp(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_fmtp(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_direction(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_direction(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_qos(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_qos(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_curr(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_curr (sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_des(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_des (sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_conf(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_conf (sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_transport_map(sdp_t *sdp_p,
sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_transport_map(sdp_t *sdp_p,
sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_subnet(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_subnet(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_t38_ratemgmt(sdp_t *sdp_p,
sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_t38_ratemgmt(sdp_t *sdp_p,
sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_t38_udpec(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_t38_udpec(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_cap(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_cap(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_cpar(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_cpar(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_pc_codec(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_pc_codec(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_xcap(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_xcap(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_xcpar(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_xcpar(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_rtr(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_rtr(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_comediadir(sdp_t *sdp_p, sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_comediadir(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_silencesupp(sdp_t *sdp_p,
sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_silencesupp(sdp_t *sdp_p,
sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_srtpcontext(sdp_t *sdp_p,
sdp_attr_t *attr_p,
const char *ptr);
extern sdp_result_e sdp_build_attr_srtpcontext(sdp_t *sdp_p,
sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
extern sdp_result_e sdp_parse_attr_mptime(
sdp_t *sdp_p, sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_mptime(
sdp_t *sdp_p, sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_t *sdp_p, sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_x_sidin(
sdp_t *sdp_p, sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_x_sidin(
sdp_t *sdp_p, sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_t *sdp_p, sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_x_sidout(
sdp_t *sdp_p, sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_x_sidout(
sdp_t *sdp_p, sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_t *sdp_p, sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_x_confid(
sdp_t *sdp_p, sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_x_confid(
sdp_t *sdp_p, sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_t *sdp_p, sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_group(
sdp_t *sdp_p, sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_group(
sdp_t *sdp_p, sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_t *sdp_p, sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_source_filter(
sdp_t *sdp_p, sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_source_filter(
sdp_t *sdp_p, sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_t *sdp_p, sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_rtcp_unicast(
sdp_t *sdp_p, sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_rtcp_unicast(
sdp_t *sdp_p, sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_t *sdp_p, sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_build_attr_ice_attr (
sdp_t *sdp_p, sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_t *sdp_p, sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_ice_attr (
sdp_t *sdp_p, sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_build_attr_rtcp_mux_attr (
sdp_t *sdp_p, sdp_attr_t *attr_p, char **ptr, u16 len);
sdp_t *sdp_p, sdp_attr_t *attr_p, flex_string *fs);
extern sdp_result_e sdp_parse_attr_rtcp_mux_attr (
sdp_t *sdp_p, sdp_attr_t *attr_p, const char *ptr);
extern sdp_result_e sdp_parse_attr_fingerprint_attr (
@ -789,61 +788,46 @@ extern tinybool sdp_verify_sdp_ptr(sdp_t *sdp_p);
/* sdp_tokens.c */
extern sdp_result_e sdp_parse_version(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_version(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_version(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_owner(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_owner(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_owner(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_sessname(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_sessname(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_sessname(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_sessinfo(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_sessinfo(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_sessinfo(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_uri(sdp_t *sdp_p, u16 token, const char *ptr);
extern sdp_result_e sdp_build_uri(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_uri(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_email(sdp_t *sdp_p, u16 token, const char *ptr);
extern sdp_result_e sdp_build_email(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_email(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_phonenum(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_phonenum(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_phonenum(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_connection(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_connection(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_connection(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_bandwidth(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_bandwidth(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_bandwidth(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_timespec(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_timespec(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_timespec(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_repeat_time(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_repeat_time(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_repeat_time(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_timezone_adj(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_timezone_adj(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_timezone_adj(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_encryption(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_encryption(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_encryption(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_media(sdp_t *sdp_p, u16 token, const char *ptr);
extern sdp_result_e sdp_build_media(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_media(sdp_t *sdp_p, u16 token, flex_string *fs);
extern sdp_result_e sdp_parse_attribute(sdp_t *sdp_p, u16 token,
const char *ptr);
extern sdp_result_e sdp_build_attribute(sdp_t *sdp_p, u16 token, char **ptr,
u16 len);
extern sdp_result_e sdp_build_attribute(sdp_t *sdp_p, u16 token, flex_string *fs);
extern void sdp_parse_payload_types(sdp_t *sdp_p, sdp_mca_t *mca_p,
const char *ptr);
@ -856,7 +840,7 @@ sdp_parse_attr_sdescriptions(sdp_t *sdp_p, sdp_attr_t *attr_p,
extern sdp_result_e
sdp_build_attr_sdescriptions(sdp_t *sdp_p, sdp_attr_t *attr_p,
char **ptr, u16 len);
flex_string *fs);
/* sdp_utils.c */

View File

@ -70,10 +70,8 @@ sdp_result_e sdp_parse_version (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_version (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_version (sdp_t *sdp_p, u16 level, flex_string *fs)
{
char *endbuf_p = *ptr + len;
if (sdp_p->version == SDP_INVALID_VALUE) {
if (sdp_p->conf_p->version_reqd == TRUE) {
if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
@ -87,7 +85,8 @@ sdp_result_e sdp_build_version (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
return (SDP_SUCCESS);
}
}
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "v=%u\r\n", (u16)sdp_p->version);
flex_string_sprintf(fs, "v=%u\r\n", (u16)sdp_p->version);
if (sdp_p->debug_flag[SDP_DEBUG_TRACE]) {
SDP_PRINT("%s Built v= version line", sdp_p->debug_str);
@ -239,10 +238,8 @@ sdp_result_e sdp_parse_owner (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_owner (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_owner (sdp_t *sdp_p, u16 level, flex_string *fs)
{
char *endbuf_p = *ptr + len;
if ((sdp_p->owner_name[0] == '\0') ||
(sdp_p->owner_network_type >= SDP_MAX_NETWORK_TYPES) ||
(sdp_p->owner_addr_type >= SDP_MAX_ADDR_TYPES) ||
@ -250,7 +247,7 @@ sdp_result_e sdp_build_owner (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
if((sdp_p->owner_network_type == SDP_NT_ATM) &&
(sdp_p->owner_addr_type == SDP_AT_INVALID)) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "o=%s %s %s %s - -\r\n",
flex_string_sprintf(fs, "o=%s %s %s %s - -\r\n",
sdp_p->owner_name, sdp_p->owner_sessid,
sdp_p->owner_version,
sdp_get_network_name(sdp_p->owner_network_type));
@ -269,7 +266,7 @@ sdp_result_e sdp_build_owner (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
}
}
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "o=%s %s %s %s %s %s\r\n",
flex_string_sprintf(fs, "o=%s %s %s %s %s %s\r\n",
sdp_p->owner_name, sdp_p->owner_sessid,
sdp_p->owner_version,
sdp_get_network_name(sdp_p->owner_network_type),
@ -312,10 +309,8 @@ sdp_result_e sdp_parse_sessname (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_sessname (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_sessname (sdp_t *sdp_p, u16 level, flex_string *fs)
{
char *endbuf_p = *ptr + len;
if (sdp_p->sessname[0] == '\0') {
if (sdp_p->conf_p->session_name_reqd == TRUE) {
if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) {
@ -330,7 +325,7 @@ sdp_result_e sdp_build_sessname (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
}
}
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "s=%s\r\n", sdp_p->sessname);
flex_string_sprintf(fs, "s=%s\r\n", sdp_p->sessname);
if (sdp_p->debug_flag[SDP_DEBUG_TRACE]) {
SDP_PRINT("%s Built s= session name line", sdp_p->debug_str);
@ -385,7 +380,7 @@ sdp_result_e sdp_parse_sessinfo (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_sessinfo (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_sessinfo (sdp_t *sdp_p, u16 level, flex_string *fs)
{
/* Build session info line not supported. */
return (SDP_SUCCESS);
@ -417,7 +412,7 @@ sdp_result_e sdp_parse_uri (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_uri (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_uri (sdp_t *sdp_p, u16 level, flex_string *fs)
{
/* Build URI line not supported. */
return (SDP_SUCCESS);
@ -440,7 +435,7 @@ sdp_result_e sdp_parse_email (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_email (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_email (sdp_t *sdp_p, u16 level, flex_string *fs)
{
/* Build email line not supported. */
return (SDP_SUCCESS);
@ -464,7 +459,7 @@ sdp_result_e sdp_parse_phonenum (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_phonenum (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_phonenum (sdp_t *sdp_p, u16 level, flex_string *fs)
{
/* Build phone number line not supported. */
return (SDP_SUCCESS);
@ -692,12 +687,10 @@ sdp_result_e sdp_parse_connection (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_connection (sdp_t *sdp_p, u16 level, char **ptr,
u16 len)
sdp_result_e sdp_build_connection (sdp_t *sdp_p, u16 level, flex_string *fs)
{
sdp_mca_t *mca_p;
sdp_conn_t *conn_p;
char *endbuf_p = *ptr + len;
if (level == SDP_SESSION_LEVEL) {
conn_p = &(sdp_p->default_conn);
@ -713,7 +706,7 @@ sdp_result_e sdp_build_connection (sdp_t *sdp_p, u16 level, char **ptr,
(conn_p->addrtype == SDP_AT_INVALID)) {
/*allow c= line to be built without address type and address fields
* This is a special case for ATM PVC*/
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "c=%s\r\n",
flex_string_sprintf(fs, "c=%s\r\n",
sdp_get_network_name(conn_p->nettype));
return SDP_SUCCESS;
}
@ -726,20 +719,20 @@ sdp_result_e sdp_build_connection (sdp_t *sdp_p, u16 level, char **ptr,
if (conn_p->is_multicast) {
if (conn_p->num_of_addresses > 1) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "c=%s %s %s/%d/%d\r\n",
flex_string_sprintf(fs, "c=%s %s %s/%d/%d\r\n",
sdp_get_network_name(conn_p->nettype),
sdp_get_address_name(conn_p->addrtype),
conn_p->conn_addr, conn_p->ttl,
conn_p->num_of_addresses);
} else {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "c=%s %s %s/%d\r\n",
flex_string_sprintf(fs, "c=%s %s %s/%d\r\n",
sdp_get_network_name(conn_p->nettype),
sdp_get_address_name(conn_p->addrtype),
conn_p->conn_addr, conn_p->ttl);
}
} else {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "c=%s %s %s\r\n",
flex_string_sprintf(fs, "c=%s %s %s\r\n",
sdp_get_network_name(conn_p->nettype),
sdp_get_address_name(conn_p->addrtype),
conn_p->conn_addr);
@ -877,12 +870,11 @@ sdp_result_e sdp_parse_bandwidth (sdp_t *sdp_p, u16 level, const char *ptr)
*
* Builds *all* the bandwith lines for the specified level.
*/
sdp_result_e sdp_build_bandwidth (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_bandwidth (sdp_t *sdp_p, u16 level, flex_string *fs)
{
sdp_bw_t *bw_p;
sdp_bw_data_t *bw_data_p;
sdp_mca_t *mca_p;
char *endbuf_p;
if (level == SDP_SESSION_LEVEL) {
bw_p = &(sdp_p->bw);
@ -894,12 +886,9 @@ sdp_result_e sdp_build_bandwidth (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
bw_p = &(mca_p->bw);
}
/* Find ptr to the end of the buf for recalculating len remaining. */
endbuf_p = *ptr + len;
bw_data_p = bw_p->bw_data_list;
while (bw_data_p) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "b=%s:%d\r\n",
flex_string_sprintf(fs, "b=%s:%d\r\n",
sdp_get_bw_modifier_name(bw_data_p->bw_modifier),
bw_data_p->bw_val);
@ -982,10 +971,8 @@ sdp_result_e sdp_parse_timespec (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_timespec (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_timespec (sdp_t *sdp_p, u16 level, flex_string *fs)
{
char *endbuf_p = *ptr + len;
if ((sdp_p->timespec_p == NULL) ||
(sdp_p->timespec_p->start_time == '\0') ||
(sdp_p->timespec_p->stop_time == '\0')) {
@ -1003,7 +990,7 @@ sdp_result_e sdp_build_timespec (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
}
/* Note: We only support one t= line currently. */
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "t=%s %s\r\n", sdp_p->timespec_p->start_time,
flex_string_sprintf(fs, "t=%s %s\r\n", sdp_p->timespec_p->start_time,
sdp_p->timespec_p->stop_time);
if (sdp_p->debug_flag[SDP_DEBUG_TRACE]) {
@ -1030,7 +1017,7 @@ sdp_result_e sdp_parse_repeat_time (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_repeat_time (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_repeat_time (sdp_t *sdp_p, u16 level, flex_string *fs)
{
/* Build repeat time line not supported. */
return (SDP_SUCCESS);
@ -1054,8 +1041,7 @@ sdp_result_e sdp_parse_timezone_adj (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_timezone_adj (sdp_t *sdp_p, u16 level, char **ptr,
u16 len)
sdp_result_e sdp_build_timezone_adj (sdp_t *sdp_p, u16 level, flex_string *fs)
{
/* Build timezone adjustment line not supported. */
return (SDP_SUCCESS);
@ -1136,15 +1122,10 @@ sdp_result_e sdp_parse_encryption (sdp_t *sdp_p, u16 level, const char *ptr)
}
/* If the encryption info is valid, we build it. Else skip it. */
sdp_result_e sdp_build_encryption (sdp_t *sdp_p, u16 level, char **ptr,
u16 len)
sdp_result_e sdp_build_encryption (sdp_t *sdp_p, u16 level, flex_string *fs)
{
sdp_encryptspec_t *encrypt_p;
sdp_mca_t *mca_p;
char *endbuf_p;
/* Find ptr to the end of the buf for recalculating len remaining. */
endbuf_p = *ptr + len;
if (level == SDP_SESSION_LEVEL) {
encrypt_p = &(sdp_p->encrypt);
@ -1163,14 +1144,14 @@ sdp_result_e sdp_build_encryption (sdp_t *sdp_p, u16 level, char **ptr,
return (SDP_SUCCESS);
}
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "k=%s",
flex_string_sprintf(fs, "k=%s",
sdp_get_encrypt_name(encrypt_p->encrypt_type));
if (encrypt_p->encrypt_type == SDP_ENCRYPT_PROMPT) {
/* There is no key to print. */
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "\r\n");
flex_string_sprintf(fs, "\r\n");
} else {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), ":%s\r\n", encrypt_p->encrypt_key);
flex_string_sprintf(fs, ":%s\r\n", encrypt_p->encrypt_key);
}
if (sdp_p->debug_flag[SDP_DEBUG_TRACE]) {
@ -1539,16 +1520,12 @@ sdp_result_e sdp_parse_media (sdp_t *sdp_p, u16 level, const char *ptr)
return (SDP_SUCCESS);
}
sdp_result_e sdp_build_media (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_result_e sdp_build_media (sdp_t *sdp_p, u16 level, flex_string *fs)
{
int i, j;
sdp_mca_t *mca_p;
tinybool invalid_params=FALSE;
sdp_media_profiles_t *profile_p;
char *endbuf_p;
/* Find ptr to the end of the buf for recalculating len remaining. */
endbuf_p = *ptr + len;
/* Find the right media line */
mca_p = sdp_find_media_level(sdp_p, level);
@ -1573,30 +1550,30 @@ sdp_result_e sdp_build_media (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
}
/* Build the media type */
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "m=%s ", sdp_get_media_name(mca_p->media));
flex_string_sprintf(fs, "m=%s ", sdp_get_media_name(mca_p->media));
/* Build the port based on the specified port format */
if (mca_p->port_format == SDP_PORT_NUM_ONLY) {
if (mca_p->port == SDP_CHOOSE_PARAM) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "$ ");
flex_string_sprintf(fs, "$ ");
} else {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%u ", (u16)mca_p->port);
flex_string_sprintf(fs, "%u ", (u16)mca_p->port);
}
} else if (mca_p->port_format == SDP_PORT_NUM_COUNT) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%u/%u ", (u16)mca_p->port,
flex_string_sprintf(fs, "%u/%u ", (u16)mca_p->port,
(u16)mca_p->num_ports);
} else if (mca_p->port_format == SDP_PORT_VPI_VCI) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%u/%u ",
flex_string_sprintf(fs, "%u/%u ",
(u16)mca_p->vpi, (u16)mca_p->vci);
} else if (mca_p->port_format == SDP_PORT_VCCI) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%u ", (u16)mca_p->vcci);
flex_string_sprintf(fs, "%u ", (u16)mca_p->vcci);
} else if (mca_p->port_format == SDP_PORT_NUM_VPI_VCI) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%u/%u/%u ", (u16)mca_p->port,
flex_string_sprintf(fs, "%u/%u/%u ", (u16)mca_p->port,
(u16)mca_p->vpi, (u16)mca_p->vci);
} else if (mca_p->port_format == SDP_PORT_VCCI_CID) {
if ((mca_p->vcci == SDP_CHOOSE_PARAM) &&
(mca_p->cid == SDP_CHOOSE_PARAM)) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "$/$ ");
flex_string_sprintf(fs, "$/$ ");
} else if ((mca_p->vcci == SDP_CHOOSE_PARAM) ||
(mca_p->cid == SDP_CHOOSE_PARAM)) {
/* If one is set but not the other, this is an error. */
@ -1607,11 +1584,11 @@ sdp_result_e sdp_build_media (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
sdp_p->conf_p->num_invalid_param++;
return (SDP_INVALID_PARAMETER);
} else {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%u/%u ",
flex_string_sprintf(fs, "%u/%u ",
(u16)mca_p->vcci, (u16)mca_p->cid);
}
} else if (mca_p->port_format == SDP_PORT_NUM_VPI_VCI_CID) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%u/%u/%u/%u ", (u16)mca_p->port,
flex_string_sprintf(fs, "%u/%u/%u/%u ", (u16)mca_p->port,
(u16)mca_p->vpi, (u16)mca_p->vci, (u16)mca_p->cid);
}
@ -1621,16 +1598,16 @@ sdp_result_e sdp_build_media (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
(mca_p->transport == SDP_TRANSPORT_AAL2_CUSTOM)) {
profile_p = mca_p->media_profiles_p;
for (i=0; i < profile_p->num_profiles; i++) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%s",
flex_string_sprintf(fs, "%s",
sdp_get_transport_name(profile_p->profile[i]));
for (j=0; j < profile_p->num_payloads[i]; j++) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), " %u",
flex_string_sprintf(fs, " %u",
profile_p->payload_type[i][j]);
}
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), " ");
flex_string_sprintf(fs, " ");
}
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "\n");
flex_string_sprintf(fs, "\n");
if (sdp_p->debug_flag[SDP_DEBUG_TRACE]) {
SDP_PRINT("%s Built m= media line", sdp_p->debug_str);
}
@ -1638,7 +1615,7 @@ sdp_result_e sdp_build_media (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
}
/* Build the transport name */
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%s",
flex_string_sprintf(fs, "%s",
sdp_get_transport_name(mca_p->transport));
if(mca_p->transport != SDP_TRANSPORT_SCTPDTLS) {
@ -1646,18 +1623,18 @@ sdp_result_e sdp_build_media (sdp_t *sdp_p, u16 level, char **ptr, u16 len)
/* Build the format lists */
for (i=0; i < mca_p->num_payloads; i++) {
if (mca_p->payload_indicator[i] == SDP_PAYLOAD_ENUM) {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), " %s",
flex_string_sprintf(fs, " %s",
sdp_get_payload_name((sdp_payload_e)mca_p->payload_type[i]));
} else {
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), " %u", mca_p->payload_type[i]);
flex_string_sprintf(fs, " %u", mca_p->payload_type[i]);
}
}
} else {
/* Add port to SDP if transport is SCTP/DTLS */
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), " %u ", (u32)mca_p->sctpport);
flex_string_sprintf(fs, " %u ", (u32)mca_p->sctpport);
}
*ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "\r\n");
flex_string_sprintf(fs, "\r\n");
if (sdp_p->debug_flag[SDP_DEBUG_TRACE]) {
SDP_PRINT("%s Built m= media line", sdp_p->debug_str);

View File

@ -404,69 +404,31 @@ sipsdp_create_from_buf (char *buf, uint32_t nbytes, cc_sdp_t *sdp)
char *
sipsdp_write_to_buf (cc_sdp_t *sdp_info, uint32_t *retbytes)
{
const char *fname = "sipsdp_write_to_buf";
char *buf, *new_buf;
char *sdp_buf;
flex_string fs;
uint32_t sdp_len;
sdp_result_e rc;
flex_string_init(&fs);
if (!sdp_info || !sdp_info->src_sdp) {
CCSIP_DEBUG_ERROR(SIP_F_PREFIX"NULL sdp_info or src_sdp\n", fname);
CCSIP_DEBUG_ERROR(SIP_F_PREFIX"NULL sdp_info or src_sdp\n", __FUNCTION__);
return (NULL);
}
/*
* Allocate storage for the SDP text
*/
buf = (char *) cpr_malloc(CCSIP_SDP_BUF_SIZE);
if (!buf) {
CCSIP_DEBUG_ERROR(SIP_F_PREFIX"malloc failure\n", fname);
return (NULL);
}
sdp_buf = buf;
if ((rc = sdp_build(sdp_info->src_sdp, &sdp_buf, CCSIP_SDP_BUF_SIZE))
if ((rc = sdp_build(sdp_info->src_sdp, &fs))
!= SDP_SUCCESS) {
CCSIP_DEBUG_TASK(DEB_F_PREFIX"sdp_build rc=%s\n", DEB_F_PREFIX_ARGS(SIP_SDP, fname),
CCSIP_DEBUG_TASK(DEB_F_PREFIX"sdp_build rc=%s\n", DEB_F_PREFIX_ARGS(SIP_SDP, __FUNCTION__),
sdp_get_result_name(rc));
if (rc == SDP_POTENTIAL_SDP_OVERFLOW) {
/* SDP may have been truncated. Issue an extra warning and abort */
CCSIP_DEBUG_ERROR(SIP_F_PREFIX"Build SDP buffer overflow\n", fname);
}
cpr_free(buf);
flex_string_free(&fs);
*retbytes = 0;
return (NULL);
}
/*
* Compute length of SDP
*/
sdp_len = sdp_buf - buf;
/*
* Minimize the memory impact on the SDP buffer by reallocating buffer
* with a smaller size that fits the actual SDP body for the size.
*/
if ((CCSIP_SDP_BUF_SIZE - sdp_len) > 64) {
/*
* Allocate space with NULL string character, the
* output buffer content contains the NULL char but the
* the length represents an actual length of SDP
* without NULL char. The NULL char is added just in case,
* there is code that uses strlen() on the SDP then
* it will terminate properly.
*/
new_buf = (char *) cpr_malloc(sdp_len + 1);
if (new_buf != NULL) {
memcpy(new_buf, buf, sdp_len);
new_buf[sdp_len] = '\0';
cpr_free(buf);
buf = new_buf;
}
}
*retbytes = sdp_len;
*retbytes = fs.string_length;
return (buf);
/* We are not calling flex_string_free on this, instead returning the buffer
* caller's responsibility to free
*/
return fs.buffer;
}

View File

@ -46,8 +46,6 @@
#include "sdp.h"
#include "ccapi.h"
// RAMC-start
#define CCSIP_SDP_BUF_SIZE SDP_MAX_LEN
/* SDP bitmask values */
#define CCSIP_SRC_SDP_BIT 0x1
@ -92,7 +90,7 @@ PMH_EXTERN cc_sdp_t *sipsdp_create_from_buf(char *buf, uint32_t nbytes,
*/
#define SIPSDP_VERSION 0
// RAMC_DEBUG #define SIPSDP_ORIGIN_USERNAME "CiscoSystemsSIP-GW-UserAgent"
#define SIPSDP_ORIGIN_USERNAME "Cisco-SIPUA"
#define SIPSDP_ORIGIN_USERNAME "Mozilla-SIPUA"
#define SIPSDP_SESSION_NAME "SIP Call"
/* Possible encoding names fo static payload types*/

View File

@ -37,7 +37,10 @@
*
* ***** END LICENSE BLOCK ***** */
#include <stdio.h>
#include <stdarg.h>
#include "mozilla/Assertions.h"
#include "cpr_types.h"
#include "cpr_stdlib.h"
#include "cpr_string.h"
@ -129,3 +132,101 @@ sstrncat (char *s1, const char *s2, unsigned long max)
return s1;
}
/*
* flex_string
*/
/*
* flex_string_init
*
* Not thread-safe
*/
void flex_string_init(flex_string *fs) {
fs->buffer_length = FLEX_STRING_CHUNK_SIZE;
fs->string_length = 0;
fs->buffer = cpr_malloc(fs->buffer_length);
fs->buffer[0] = '\0';
}
/*
* flex_string_free
*
* Not thread-safe
*/
void flex_string_free(flex_string *fs) {
fs->buffer_length = 0;
fs->string_length = 0;
cpr_free(fs->buffer);
fs->buffer = NULL;
}
/* For sanity check before alloc */
#define FLEX_STRING_MAX_SIZE (10 * 1024 * 1024) /* 10MB */
/*
* flex_string_check_alloc
*
* Allocate enough chunks to hold the new minimum size.
*
* Not thread-safe
*/
void flex_string_check_alloc(flex_string *fs, size_t new_min_length) {
if (new_min_length > fs->buffer_length) {
/* Oversize, allocate more */
/* Sanity check on allocation size */
if (new_min_length > FLEX_STRING_MAX_SIZE) {
MOZ_CRASH();
}
/* Alloc to nearest chunk */
fs->buffer_length = (((new_min_length - 1) / FLEX_STRING_CHUNK_SIZE) + 1) * FLEX_STRING_CHUNK_SIZE;
fs->buffer = cpr_realloc(fs->buffer, fs->buffer_length);
}
}
/*
* flex_string_append
*
* Not thread-safe
*/
void flex_string_append(flex_string *fs, const char *more) {
fs->string_length += strlen(more);
flex_string_check_alloc(fs, fs->string_length + 1);
sstrncat(fs->buffer, more, fs->buffer_length - strlen(fs->buffer));
}
/*
* flex_string_sprintf
*
* Not thread-safe
*/
void flex_string_sprintf(flex_string *fs, const char *format, ...) {
va_list ap;
int vsnprintf_result;
va_start(ap, format);
vsnprintf_result = vsnprintf(fs->buffer + fs->string_length, fs->buffer_length - fs->string_length, format, ap);
va_end(ap);
if (fs->string_length + vsnprintf_result >= fs->buffer_length) {
/* Buffer overflow, resize */
flex_string_check_alloc(fs, fs->string_length + vsnprintf_result + 1);
/* Try again with new buffer */
va_start(ap, format);
vsnprintf_result = vsnprintf(fs->buffer + fs->string_length, fs->buffer_length - fs->string_length, format, ap);
MOZ_ASSERT(vsnprintf_result > 0 && vsnprintf_result < (fs->buffer_length - fs->string_length));
va_end(ap);
}
if (vsnprintf_result > 0) {
fs->string_length += vsnprintf_result;
}
}

View File

@ -98,6 +98,54 @@ sstrncpy(char *dst, const char *src, unsigned long max);
char *
sstrncat(char *s1, const char *s2, unsigned long max);
/*
* flex_string
*/
#define FLEX_STRING_CHUNK_SIZE 256
typedef struct {
char *buffer;
size_t buffer_length;
size_t string_length;
} flex_string;
/*
* flex_string_init
*
* Not thread-safe
*/
void flex_string_init(flex_string *fs);
/*
* flex_string_free
*
* Not thread-safe
*/
void flex_string_free(flex_string *fs);
/*
* flex_string_check_alloc
*
* Allocate enough chunks to hold the new minimum size.
*
* Not thread-safe
*/
void flex_string_check_alloc(flex_string *fs, size_t new_min_length);
/*
* flex_string_append
*
* Not thread-safe
*/
void flex_string_append(flex_string *fs, const char *more);
/*
* flex_string_sprintf
*
* Not thread-safe
*/
void flex_string_sprintf(flex_string *fs, const char *format, ...);
__END_DECLS
#endif

View File

@ -38,7 +38,7 @@ namespace test {
static const std::string strSampleSdpAudioVideoNoIce =
"v=0\r\n"
"o=Cisco-SIPUA 4949 0 IN IP4 10.86.255.143\r\n"
"o=Mozilla-SIPUA 4949 0 IN IP4 10.86.255.143\r\n"
"s=SIP Call\r\n"
"t=0 0\r\n"
"a=ice-ufrag:qkEP\r\n"