static int add_string_to_encode (sdp_encode_t *sptr, const char *buf, int line) { uint32_t len; char *temp; if (buf == NULL) { sdp_debug(LOG_CRIT, "Can't add NULL string to SDP - line %d", line); return (EINVAL); } len = strlen(buf); if (len == 0) return (0); if (len + 1 + sptr->used > sptr->buflen) { /// 2005.03.11 Sky modify : not accumuate 1024 one time, accumulate next 1024 degree (fix bug) uint32_t degree = (len + sptr->used - sptr->buflen) / 1024; temp = (char *)realloc(sptr->buffer, sptr->buflen + (degree+1)*1024); if (temp == NULL) return (ENOMEM); sptr->buffer = temp; sptr->buflen += ((degree+1)*1024); /// 2005.03.11 End of modification } strcpy(sptr->buffer + sptr->used, buf); sptr->used += len; return (0); }
/* * sip_sdp_create() * * Allocate a standard SDP with SIP config and set debug options * based on ccsip debug settings */ void * sipsdp_create (void) { const char *fname = "sipsdp_create :"; void *sdp; // char debug_str[80]; sdp = sdp_init_description(ccsip_sdp_config); if (!sdp) { CCSIP_DEBUG_ERROR(SIP_F_PREFIX"SDP allocation failure\n", fname); return (NULL); } /* * Map "ccsip debug events (or info)" to SDP warnings * "ccsip debug errors to SDP errors */ CCSIP_INFO_DEBUG { sdp_debug(sdp, SDP_DEBUG_WARNINGS, TRUE); } CCSIP_ERR_DEBUG { sdp_debug(sdp, SDP_DEBUG_ERRORS, TRUE); } #ifdef DEBUG_SDP_LIB /* * Enabling this is redundant to the existing message printing * available for the entire SIP text messages, so it is not * enabled here. It is useful for debugging the SDP parser, * however. */ CCSIP_MESSAGES_DEBUG { sdp_debug(sdp, SDP_DEBUG_TRACE, TRUE); } #endif return (sdp); }
int sdp_encode_one_to_file (session_desc_t *sptr, const char *filename, int append) { FILE *ofile; sdp_encode_t sdp; CHECK_RETURN(prepare_sdp_encode(&sdp)); CHECK_RETURN(sdp_encode(sptr, &sdp)); ofile = fopen(filename, append ? "a" : "w"); if (ofile == NULL) { sdp_debug(LOG_CRIT, "Cannot open file %s", filename); free(sdp.buffer); return (-1); } fputs(sdp.buffer, ofile); fclose(ofile); free(sdp.buffer); return (0); }