⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.c

📁 SDP文件解析代码
💻 C
📖 第 1 页 / 共 4 页
字号:
fsdp_parse_b (const char **p, fsdp_bw_modifier_t ** bw_modifiers,	      unsigned int *bw_modifiers_count){  char fsdp_buf[MAXSHORTFIELDLEN];  unsigned long int wuint;  unsigned int i = 0;  const char *lp = *p;  /* count b= lines */  while (!strncmp (lp, "b=", 2))  {    NEXT_LINE (lp);    i++;  }  *bw_modifiers = calloc (i, sizeof (fsdp_bw_modifier_t));  *bw_modifiers_count = i;  while (i > 0)  {    unsigned int index = *bw_modifiers_count - i;    if (2 == sscanf (*p, "b=%20[^:\r\n]:%lu", fsdp_buf, &wuint))    {      if (!strncmp (fsdp_buf, "CT", 2))        (*bw_modifiers)[index].b_mod_type =          FSDP_BW_MOD_TYPE_CONFERENCE_TOTAL;      else if (!strncmp (fsdp_buf, "AS", 2))        (*bw_modifiers)[index].b_mod_type =          FSDP_BW_MOD_TYPE_APPLICATION_SPECIFIC;      else if (!strncmp (fsdp_buf, "RS", 2))        (*bw_modifiers)[index].b_mod_type = FSDP_BW_MOD_TYPE_RTCP_SENDERS;      else if (!strncmp (fsdp_buf, "RR", 2))        (*bw_modifiers)[index].b_mod_type =          FSDP_BW_MOD_TYPE_RTCP_RECEIVERS;      else      {        (*bw_modifiers)[index].b_mod_type = FSDP_BW_MOD_TYPE_UNKNOWN;        (*bw_modifiers)[index].b_unknown_bw_modt =          (char *) strdup (fsdp_buf);      }      (*bw_modifiers)[index].b_value = wuint;      NEXT_LINE (*p);    }    else    {      *bw_modifiers_count -= i;      return FSDPE_INVALID_BANDWIDTH;    }    i--;  }  return FSDPE_OK;}static fsdp_error_tfsdp_parse_k (const char **p, fsdp_encryption_method_t * method,	      char **content){  char fsdp_buf[MAXSHORTFIELDLEN];  char longfsdp_buf[MAXLONGFIELDLEN];  if (!strncmp (*p, "k=", 2))  {    if (sscanf (*p, "k=prompt"))    {      *method = FSDP_ENCRYPTION_METHOD_PROMPT;      *content = NULL;      NEXT_LINE (*p);    }    else    {      if (sscanf          (*p, "k=%6[^:\r\n]:%" MLFLENS "s", fsdp_buf, longfsdp_buf))      {        if (!strncmp (fsdp_buf, "clear", 5))          *method = FSDP_ENCRYPTION_METHOD_CLEAR;        else if (!strncmp (fsdp_buf, "base64", 6))          *method = FSDP_ENCRYPTION_METHOD_BASE64;        else if (!strncmp (fsdp_buf, "uri", 3))          *method = FSDP_ENCRYPTION_METHOD_URI;        else          return FSDPE_INVALID_ENCRYPTION_METHOD;        *content = strdup (longfsdp_buf);        NEXT_LINE (*p);      }    }  }  return FSDPE_OK;}static fsdp_error_tfsdp_parse_rtpmap (fsdp_rtpmap_t *** rtpmap, unsigned int *counter,		   const char *value){  fsdp_error_t result = FSDPE_OK;  if (0 == *counter)  {    *counter = 0;    *rtpmap = calloc (MEDIA_RTPMAPS_MAX_COUNT, sizeof (fsdp_rtpmap_t *));  }  if (*counter < MEDIA_RTPMAPS_MAX_COUNT)  {    unsigned int c = *counter;    fsdp_rtpmap_t **map = *rtpmap;    char fsdp_buf[MAXSHORTFIELDLEN];    char longfsdp_buf[MAXLONGFIELDLEN];    map[c] = calloc (1, sizeof (fsdp_rtpmap_t));    /* a=rtpmap:<payload type> <encoding name>/<clock rate>[/<encoding       parameters]> */    if (2 == sscanf (value, "%s %s", fsdp_buf, longfsdp_buf))    {      char *slash1;      map[c]->pt = strdup (fsdp_buf);      /* parse <encoding name>/<clock rate>[/<encoding parameters>] */      slash1 = strchr (longfsdp_buf, '/');      if (NULL == slash1)      {        result = FSDPE_INVALID_ATTRIBUTE_RTPMAP;      }      else      {        char *slash2;        *slash1 = '\0';        slash1++;        map[c]->encoding_name = strdup (longfsdp_buf);        slash2 = strchr (slash1, '/');        if (NULL != slash2)        {          *slash2 = '\0';          slash2++;          map[c]->parameters = strdup (slash2);        }        map[c]->clock_rate = strtol (slash1, NULL, 10);      }      (*counter)++;    }  }  return result;}static fsdp_error_tfsdp_repeat_time_to_uint (const char *time, unsigned long int *seconds){  const unsigned long SECONDS_PER_DAY = 86400;  const unsigned long SECONDS_PER_HOUR = 3600;  const unsigned long SECONDS_PER_MINUTE = 60;  char c;  unsigned long int wuint;  if (sscanf (time, "%lu%c", &wuint, &c) == 2)  {    /* time with unit specification character */    switch (c)    {    case 'd':      *seconds = wuint * SECONDS_PER_DAY;      break;    case 'h':      *seconds = wuint * SECONDS_PER_HOUR;      break;    case 'm':      *seconds = wuint * SECONDS_PER_MINUTE;      break;    case 's':      *seconds = wuint;      break;    default:      return FSDPE_INVALID_REPEAT;      break;    }  }  else if (sscanf (time, "%lu", &wuint) == 1)  {    /* time without unit specification character */    *seconds = wuint;  }  else  {    return FSDPE_INVALID_REPEAT;  }  return FSDPE_OK;}unsigned intfsdp_get_version (const fsdp_description_t * dsc){  if (!dsc)    return 0;  return dsc->version;}const char *fsdp_get_owner_username (const fsdp_description_t * dsc){  if (!dsc)    return NULL;  return dsc->o_username;}const char *fsdp_get_session_id (const fsdp_description_t * dsc){  if (!dsc)    return NULL;  return dsc->o_session_id;}const char *fsdp_get_announcement_version (const fsdp_description_t * dsc){  if (!dsc)    return NULL;  return dsc->o_announcement_version;}fsdp_network_type_tfsdp_get_owner_network_type (const fsdp_description_t * dsc){  if (!dsc)    return FSDP_NETWORK_TYPE_UNDEFINED;  return dsc->o_network_type;}fsdp_address_type_tfsdp_get_owner_address_type (const fsdp_description_t * dsc){  if (!dsc)    return FSDP_ADDRESS_TYPE_UNDEFINED;  return dsc->o_address_type;}const char *fsdp_get_owner_address (const fsdp_description_t * dsc){  if (!dsc)    return NULL;  return dsc->o_address;}const char *fsdp_get_name (const fsdp_description_t * dsc){  if (!dsc)    return NULL;  return dsc->s_name;}const char *fsdp_get_information (const fsdp_description_t * dsc){  if (!dsc)    return NULL;  return dsc->i_information;}const char *fsdp_get_uri (const fsdp_description_t * dsc){  if (!dsc)    return NULL;  return dsc->u_uri;}unsigned intfsdp_get_emails_count (const fsdp_description_t * dsc){  if (!dsc)    return 0;  return dsc->emails_count;}const char *fsdp_get_email (const fsdp_description_t * dsc, unsigned int index){  if ((!dsc) || (index >= dsc->emails_count))    return NULL;  return dsc->emails[index];}unsigned intfsdp_get_phones_count (const fsdp_description_t * dsc){  if (!dsc)    return 0;  return dsc->phones_count;}const char *fsdp_get_phone (const fsdp_description_t * dsc, unsigned int index){  if ((!dsc) || (index >= dsc->phones_count))    return NULL;  return dsc->phones[index];}fsdp_network_type_tfsdp_get_global_conn_network_type (const fsdp_description_t * dsc){  if (!dsc)    return FSDP_NETWORK_TYPE_UNDEFINED;  return dsc->c_network_type;}fsdp_address_type_tfsdp_get_global_conn_address_type (const fsdp_description_t * dsc){  if (!dsc)    return FSDP_ADDRESS_TYPE_UNDEFINED;  return dsc->c_address_type;}const char *fsdp_get_global_conn_address (const fsdp_description_t * dsc){  if (!dsc)    return NULL;  return dsc->c_address.address;}unsigned intfsdp_get_global_conn_address_ttl (const fsdp_description_t * dsc){  if (!dsc)    return 0;  return dsc->c_address.address_ttl;}unsigned intfsdp_get_global_conn_address_count (const fsdp_description_t * dsc){  if (!dsc)    return 0;  return dsc->c_address.address_count;}unsigned intfsdp_get_bw_modifier_count (const fsdp_description_t * dsc){  if (!dsc)    return 0;  return dsc->bw_modifiers_count;}fsdp_bw_modifier_type_tfsdp_get_bw_modifier_type (const fsdp_description_t * dsc, unsigned int index){  if ((!dsc) || (index >= dsc->bw_modifiers_count))    return FSDP_BW_MOD_TYPE_UNDEFINED;  return dsc->bw_modifiers[index].b_mod_type;}const char *fsdp_get_bw_modifier_type_unknown (const fsdp_description_t * dsc,				   unsigned int index){  if ((!dsc) || (index >= dsc->bw_modifiers_count) ||      (dsc->bw_modifiers[index].b_mod_type != FSDP_BW_MOD_TYPE_UNKNOWN))    return NULL;  return dsc->bw_modifiers[index].b_unknown_bw_modt;}unsigned long intfsdp_get_bw_value (const fsdp_description_t * dsc, unsigned int index){  if ((!dsc) || (index >= dsc->bw_modifiers_count))    return 0;  return dsc->bw_modifiers[index].b_value;}time_tfsdp_get_period_start (const fsdp_description_t * dsc, unsigned int index){  if ((!dsc) || (index >= dsc->time_periods_count))    return 0;  return dsc->time_periods[index]->start;}time_tfsdp_get_period_stop (const fsdp_description_t * dsc, unsigned int index){  if ((!dsc) || (index >= dsc->time_periods_count))    return 0;  return dsc->time_periods[index]->stop;}unsigned intfsdp_get_period_repeats_count (const fsdp_description_t * dsc,			       unsigned int index){  if ((!dsc) || (index >= dsc->time_periods_count))    return 0;  return dsc->time_periods[index]->repeats_count;}unsigned long intfsdp_get_period_repeat_interval (const fsdp_description_t * dsc,				 unsigned int index, unsigned int rindex){  if ((!dsc) || (index >= dsc->time_periods_count))    return 0;  return dsc->time_periods[index]->repeats[rindex]->interval;}unsigned long intfsdp_get_period_repeat_duration (const fsdp_description_t * dsc,				 unsigned int index, unsigned int rindex){  if ((!dsc) || (index >= dsc->time_periods_count))    return 0;  return dsc->time_periods[index]->repeats[rindex]->duration;}const unsigned long int *fsdp_get_period_repeat_offsets (const fsdp_description_t * dsc,				unsigned int index, unsigned int rindex){  if ((!dsc) || (index >= dsc->time_periods_count))    return NULL;  return dsc->time_periods[index]->repeats[rindex]->offsets;}const char *fsdp_get_timezone_adj (const fsdp_description_t * dsc){  if (!dsc)    return NULL;  return dsc->timezone_adj;}unsigned intfsdp_get_unidentified_attribute_count (const fsdp_description_t * dsc){  if (!dsc)    return 0;  return dsc->unidentified_attributes_count;}const char *fsdp_get_unidentified_attribute (const fsdp_description_t * dsc,				 unsigned int index){  if (!dsc || (index < dsc->unidentified_attributes_count))    return NULL;  return dsc->unidentified_attributes[index];}fsdp_encryption_method_tfsdp_get_encryption_method (const fsdp_description_t * dsc){  if (!dsc)    return FSDP_ENCRYPTION_METHOD_UNDEFINED;  return dsc->k_encryption_method;}const char *fsdp_get_encryption_content (const fsdp_description_t * dsc){  if (!dsc || (dsc->k_encryption_method == FSDP_ENCRYPTION_METHOD_UNDEFINED))    return NULL;  return dsc->k_encryption_content;}unsigned intfsdp_get_rtpmap_count (const fsdp_description_t * dsc){  if (!dsc)    return 0;  return dsc->a_rtpmaps_count;}const char *fsdp_get_rtpmap_payload_type (const fsdp_description_t * dsc,			      unsigned int index){  if ((!dsc) || (index >= dsc->a_rtpmaps_count))    return NULL;  return dsc->a_rtpmaps[index]->pt;}const char *fsdp_get_rtpmap_encoding_name (const fsdp_description_t * dsc,			       unsigned int index){  if ((!dsc) || (index >= dsc->a_rtpmaps_count))    return NULL;  return dsc->a_rtpmaps[index]->encoding_name;}unsigned intfsdp_get_rtpmap_clock_rate (const fsdp_description_t * dsc,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -