sdp_decode.c
资源名称:NETVIDEO.rar [点击查看]
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:48k
源码类别:
流媒体/Mpeg4/MP4
开发平台:
Visual C++
- /*
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- *
- * The Original Code is MPEG4IP.
- *
- * The Initial Developer of the Original Code is Cisco Systems Inc.
- * Portions created by Cisco Systems Inc. are
- * Copyright (C) Cisco Systems Inc. 2000, 2001. All Rights Reserved.
- *
- * Contributor(s):
- * Bill May wmay@cisco.com
- */
- /*
- * sdp_decode.c
- *
- * decode SDP format from file into session description structures
- * defined in sdp.h
- *
- * October, 2000
- * Bill May (wmay@cisco.com)
- * Cisco Systems, Inc.
- */
- #include "sdp.h"
- #include "sdp_decode_private.h"
- #define ADV_SPACE(a) {while (isspace(*(a)) && (*(a) != ' '))(a)++;}
- static const char *SPACES=" t";
- #define FREE_CHECK(a,b) if (a->b != NULL) { free(a->b); a->b = NULL;}
- /*****************************************************************************
- * Memory free routines - frees memory associated with various structures
- *****************************************************************************/
- static void free_bandwidth_desc (bandwidth_t *bptr)
- {
- bandwidth_t *q;
- while (bptr != NULL) {
- q = bptr;
- bptr = q->next;
- FREE_CHECK(q, user_band);
- free(q);
- }
- }
- static void free_category_list (category_list_t **cptr)
- {
- category_list_t *p;
- if (*cptr == NULL) return;
- while (*cptr != NULL) {
- p = *cptr;
- *cptr = p->next;
- free(p);
- }
- }
- static void free_connect_desc (connect_desc_t *cptr)
- {
- FREE_CHECK(cptr, conn_type);
- FREE_CHECK(cptr, conn_addr);
- }
- /*
- * free_media_desc()
- * Frees all memory associated with a media descriptor(mptr)
- */
- static void free_media_desc (media_desc_t *mptr)
- {
- free_bandwidth_desc(mptr->media_bandwidth);
- mptr->media_bandwidth = NULL;
- free_connect_desc(&mptr->media_connect);
- sdp_free_format_list(&mptr->fmt);
- sdp_free_string_list(&mptr->unparsed_a_lines);
- FREE_CHECK(mptr, media);
- FREE_CHECK(mptr, media_desc);
- FREE_CHECK(mptr, proto);
- FREE_CHECK(mptr, sdplang);
- FREE_CHECK(mptr, lang);
- FREE_CHECK(mptr, orient_user_type);
- FREE_CHECK(mptr, control_string);
- FREE_CHECK(mptr, key.key);
- mptr->parent = NULL;
- free(mptr);
- }
- static void free_time_desc (session_time_desc_t *time)
- {
- time_repeat_desc_t *rptr;
- if (time->next != NULL) {
- free_time_desc(time->next);
- time->next = NULL;
- }
- while (time->repeat != NULL) {
- rptr = time->repeat;
- time->repeat = rptr->next;
- free (rptr);
- }
- free(time);
- }
- /*
- * sdp_free_session_desc()
- * Inputs - sptr - pointer to session_description list to free
- */
- void sdp_free_session_desc (session_desc_t *sptr)
- {
- session_desc_t *p;
- media_desc_t *mptr, *q;
- p = sptr;
- while (p != NULL) {
- sptr = p;
- p = p->next;
- sptr->next = NULL;
- mptr = sptr->media;
- sptr->media = NULL;
- while (mptr != NULL) {
- q = mptr;
- mptr = q->next;
- free_media_desc(q);
- }
- FREE_CHECK(sptr, etag);
- FREE_CHECK(sptr, orig_username);
- FREE_CHECK(sptr, control_string);
- FREE_CHECK(sptr, create_addr_type);
- FREE_CHECK(sptr, create_addr);
- FREE_CHECK(sptr, session_name);
- FREE_CHECK(sptr, session_desc);
- FREE_CHECK(sptr, uri);
- FREE_CHECK(sptr, key.key);
- FREE_CHECK(sptr, keywds);
- FREE_CHECK(sptr, lang);
- FREE_CHECK(sptr, tool);
- FREE_CHECK(sptr, charset);
- FREE_CHECK(sptr, sdplang);
- FREE_CHECK(sptr, conf_type_user);
- if (sptr->time_desc != NULL) {
- free_time_desc(sptr->time_desc);
- sptr->time_desc = NULL;
- }
- free_bandwidth_desc(sptr->session_bandwidth);
- sptr->session_bandwidth = NULL;
- free_category_list(&sptr->category_list);
- free_connect_desc(&sptr->session_connect);
- sdp_free_string_list(&sptr->admin_phone);
- sdp_free_string_list(&sptr->admin_email);
- sdp_free_string_list(&sptr->unparsed_a_lines);
- while (sptr->time_adj_desc != NULL) {
- time_adj_desc_t *aptr;
- aptr = sptr->time_adj_desc;
- sptr->time_adj_desc = aptr->next;
- free(aptr);
- }
- free(sptr);
- }
- }
- /*****************************************************************************
- * Utility routines - string manipulation, etc
- *****************************************************************************/
- /*
- * get_next_line will get the next line to process, and stick it in
- * lptr.
- *
- * Inputs:
- * lptr - buffer to store into
- * decode - pointer to where to get next line
- * buflen - max length of buffer
- *
- * Outputs:
- * TRUE - have a new line.
- * FALSE - all done.
- */
- static int get_next_line (char **polptr,
- sdp_decode_info_t *decode,
- uint32_t *buflen)
- {
- char *fret;
- uint32_t len;
- uint32_t buflen_left;
- const char *cptr;
- if (decode->isMem) {
- cptr = decode->memptr;
- if (*cptr == ' ') return FALSE;
- while (*cptr != ' ' && *cptr != 'n' && *cptr != 'r') cptr++;
- len = cptr - decode->memptr;
- if (*buflen <= len + 1) {
- if (len > 65535) {
- sdp_debug(LOG_CRIT, "Max line length of 65535 exceeded %u",
- len);
- return (FALSE);
- }
- *polptr = realloc(*polptr, len + 1);
- *buflen = len + 1;
- }
- memcpy(*polptr, decode->memptr, len);
- (*polptr)[len] = ' ';
- decode->memptr += len;
- while (*decode->memptr == 'n' || *decode->memptr == 'r')
- decode->memptr++;
- } else {
- char *ptr;
- // File reads...
- if (decode->ifile == NULL)
- return FALSE;
- if (*buflen == 0) {
- *polptr = (char *)malloc(1024);
- *buflen = 1024;
- }
- // Read file until we hit the end, or a non-blank line read
- ptr = *polptr;
- buflen_left = *buflen;
- len = 0;
- while (1) {
- fret = fgets(ptr, buflen_left, decode->ifile);
- if (fret == NULL) {
- if (len > 0) {
- sdp_debug(LOG_WARNING, "Unterminated last line");
- (*polptr)[len] = ' '; // make sure
- return (TRUE);
- }
- return (FALSE);
- }
- len = strlen(ptr);
- if (ptr[len - 1] == 'n' || ptr[len - 1] == 'r') {
- // we have an end of line
- len--;
- while (len >= 0 &&
- (ptr[len] == 'n' || ptr[len] == 'r')) {
- ptr[len] = ' ';
- len--;
- }
- return (TRUE);
- }
- // too long...
- buflen_left -= len;
- if (*buflen + 1024 > 65535) {
- sdp_debug(LOG_CRIT, "Max line length of 65535 exceeded %u",
- *buflen);
- return (FALSE);
- }
- *buflen += 1024;
- buflen_left += 1024;
- *polptr = realloc(*polptr, *buflen);
- ptr = *polptr + *buflen - buflen_left;
- }
- }
- return TRUE;
- }
- /*
- * strtou64()
- * Converts string to uint64_t number up to next space, with error checking.
- * Inputs:
- * lptr - pointer to pointer to string. *lptr will be modified
- * num - return value
- * Outputs - TRUE - sucess, FALSE, failure
- */
- static int strtou64 (char **lptr, uint64_t *num)
- {
- char *sep;
- *num = 0;
- ADV_SPACE((*lptr));
- sep = strsep(lptr, SPACES);
- if (sep == NULL || *lptr == NULL) {
- return (FALSE);
- }
- *num = 0;
- while (*sep != ' ') {
- if (isdigit(*sep)) {
- *num *= 10;
- *num += *sep - '0';
- sep++;
- } else {
- return (FALSE);
- }
- }
- return (TRUE);
- }
- /*
- * str_to_time_offset()
- * converts typed-time field (number or [#d][#h][#m][#s])
- *
- * Inputs -
- * str -