📄 sdp_rfc2327.c
字号:
crlf = equal + 1; while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0')) crlf++; if (*crlf == '\0') return ERR_ERROR; if (crlf == equal + 1) return ERR_ERROR; /* e=\r ?? bad header */ /* e=email */ /* we assume this is an EMAIL-ADDRESS */ e_email = smalloc (crlf - (equal + 1) + 1); sstrncpy (e_email, equal + 1, crlf - (equal + 1)); list_add (sdp->e_emails, e_email, -1); if (crlf[1] == '\n') *next = crlf + 2; else *next = crlf + 1; return WF;}intsdp_parse_p (sdp_t * sdp, char *buf, char **next){ char *equal; char *crlf; char *p_phone; *next = buf; equal = buf; while ((*equal != '=') && (*equal != '\0')) equal++; if (*equal == '\0') return ERR_ERROR; /* check if header is "p" */ if (equal[-1] != 'p') 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; /* p=\r ?? bad header */ /* e=email */ /* we assume this is an EMAIL-ADDRESS */ p_phone = smalloc (crlf - (equal + 1) + 1); sstrncpy (p_phone, equal + 1, crlf - (equal + 1)); list_add (sdp->p_phones, p_phone, -1); if (crlf[1] == '\n') *next = crlf + 2; else *next = crlf + 1; return WF;}intsdp_parse_c (sdp_t * sdp, char *buf, char **next){ char *equal; char *crlf; char *tmp; char *tmp_next; sdp_connection_t *c_header; int i; *next = buf; equal = buf; while ((*equal != '=') && (*equal != '\0')) equal++; if (*equal == '\0') return ERR_ERROR; /* check if header is "c" */ if (equal[-1] != 'c') 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; /* c=\r ?? bad header */ tmp = equal + 1; i = sdp_connection_init (&c_header); if (i != 0) return ERR_ERROR; /* c=nettype addrtype (multicastaddr | addr) */ /* nettype is "IN" and will be extended */ i = set_next_token (&(c_header->c_nettype), tmp, ' ', &tmp_next); if (i != 0) return -1; tmp = tmp_next; /* nettype is "IP4" or "IP6" and will be extended */ i = set_next_token (&(c_header->c_addrtype), tmp, ' ', &tmp_next); if (i != 0) return -1; tmp = tmp_next; /* there we have a multicast or unicast address */ /* multicast can be ip/ttl [/integer] */ /* unicast is FQDN or ip (no ttl, no integer) */ /* is MULTICAST? */ { char *slash = strchr (tmp, '/'); if (slash != NULL && slash < crlf) /* it's a multicast address! */ { i = set_next_token (&(c_header->c_addr), tmp, '/', &tmp_next); if (i != 0) return -1; tmp = tmp_next; slash = strchr (slash + 1, '/'); if (slash != NULL && slash < crlf) /* optionnal integer is there! */ { i = set_next_token (&(c_header->c_addr_multicast_ttl), tmp, '/', &tmp_next); if (i != 0) return -1; tmp = tmp_next; i = set_next_token (&(c_header->c_addr_multicast_int), tmp, '\r', &tmp_next); if (i != 0) { i = set_next_token (&(c_header->c_addr_multicast_int), tmp, '\n', &tmp_next); if (i != 0) { sdp_connection_free (c_header); sfree (c_header); return -1; } } } else { i = set_next_token (&(c_header->c_addr_multicast_ttl), tmp, '\r', &tmp_next); if (i != 0) { i = set_next_token (&(c_header->c_addr_multicast_ttl), tmp, '\n', &tmp_next); if (i != 0) { sdp_connection_free (c_header); sfree (c_header); return -1; } } } } else { /* in this case, we have a unicast address */ i = set_next_token (&(c_header->c_addr), tmp, '\r', &tmp_next); if (i != 0) { i = set_next_token (&(c_header->c_addr), tmp, '\n', &tmp_next); if (i != 0) { sdp_connection_free (c_header); sfree (c_header); return -1; } } } } /* add the connection at the correct place: if there is no media line yet, then the "c=" is the global one. */ i = list_size (sdp->m_medias); if (i == 0) sdp->c_connection = c_header; else { sdp_media_t *last_sdp_media = (sdp_media_t *) list_get (sdp->m_medias, i - 1); list_add (last_sdp_media->c_connections, c_header, -1); } if (crlf[1] == '\n') *next = crlf + 2; else *next = crlf + 1; return WF;}intsdp_parse_b (sdp_t * sdp, char *buf, char **next){ char *equal; char *crlf; char *tmp; char *tmp_next; int i; sdp_bandwidth_t *b_header; *next = buf; equal = buf; while ((*equal != '=') && (*equal != '\0')) equal++; if (*equal == '\0') return ERR_ERROR; /* check if header is "b" */ if (equal[-1] != 'b') 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; /* b=\r ?? bad header */ tmp = equal + 1; /* b = bwtype: bandwidth */ i = sdp_bandwidth_init (&b_header); if (i != 0) return ERR_ERROR; /* bwtype is alpha-numeric */ i = set_next_token (&(b_header->b_bwtype), tmp, ':', &tmp_next); if (i != 0) return -1; tmp = tmp_next; i = set_next_token (&(b_header->b_bandwidth), tmp, '\r', &tmp_next); if (i != 0) { i = set_next_token (&(b_header->b_bandwidth), tmp, '\n', &tmp_next); if (i != 0) { sdp_bandwidth_free (b_header); sfree (b_header); return -1; } } /* add the bandwidth at the correct place: if there is no media line yet, then the "b=" is the global one. */ i = list_size (sdp->m_medias); if (i == 0) list_add (sdp->b_bandwidths, b_header, -1); else { sdp_media_t *last_sdp_media = (sdp_media_t *) list_get (sdp->m_medias, i - 1); list_add (last_sdp_media->b_bandwidths, b_header, -1); } if (crlf[1] == '\n') *next = crlf + 2; else *next = crlf + 1; return WF;}intsdp_parse_t (sdp_t * sdp, char *buf, char **next){ char *equal; char *crlf; char *tmp; char *tmp_next; int i; sdp_time_descr_t *t_header; *next = buf; equal = buf; while ((*equal != '=') && (*equal != '\0')) equal++; if (*equal == '\0') return ERR_ERROR; /* check if header is "t" */ if (equal[-1] != 't') 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; /* t=\r ?? bad header */ tmp = equal + 1; /* t = start_time stop_time */ i = sdp_time_descr_init (&t_header); if (i != 0) return ERR_ERROR; i = set_next_token (&(t_header->t_start_time), tmp, ' ', &tmp_next); if (i != 0) { sdp_time_descr_free (t_header); sfree (t_header); return -1; } tmp = tmp_next; i = set_next_token (&(t_header->t_stop_time), tmp, '\r', &tmp_next); if (i != 0) { i = set_next_token (&(t_header->t_stop_time), tmp, '\n', &tmp_next); if (i != 0) { sdp_time_descr_free (t_header); sfree (t_header); return -1; } } /* add the new time_description header */ list_add (sdp->t_descrs, t_header, -1); if (crlf[1] == '\n') *next = crlf + 2; else *next = crlf + 1; return WF;}intsdp_parse_r (sdp_t * sdp, char *buf, char **next){ char *equal; char *crlf; int index; char *r_header; sdp_time_descr_t *t_descr; *next = buf; equal = buf; while ((*equal != '=') && (*equal != '\0')) equal++; if (*equal == '\0') return ERR_ERROR; /* check if header is "r" */ if (equal[-1] != 'r') return ERR_DISCARD; index = list_size (sdp->t_descrs); if (index == 0) return ERR_ERROR; /* r field can't come alone! */ crlf = equal + 1; while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0')) crlf++; if (*crlf == '\0') return ERR_ERROR; if (crlf == equal + 1) return ERR_ERROR; /* r=\r ?? bad header */ /* r=far too complexe and somewhat useless... I don't parse it! */ r_header = smalloc (crlf - (equal + 1) + 1); sstrncpy (r_header, equal + 1, crlf - (equal + 1)); /* r field carry information for the last "t" field */ t_descr = (sdp_time_descr_t *) list_get (sdp->t_descrs, index - 1); list_add (t_descr->r_repeats, r_header, -1); if (crlf[1] == '\n') *next = crlf + 2; else *next = crlf + 1; return WF;}intsdp_parse_z (sdp_t * sdp, char *buf, char **next){ char *equal; char *crlf; char *z_header; *next = buf; equal = buf; while ((*equal != '=') && (*equal != '\0')) equal++; if (*equal == '\0') return ERR_ERROR; /* check if header is "z" */ if (equal[-1] != 'z') 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; /* z=\r ?? bad header */ /* z=somewhat useless... I don't parse it! */ z_header = smalloc (crlf - (equal + 1) + 1); sstrncpy (z_header, equal + 1, crlf - (equal + 1)); sdp->z_adjustments = z_header; if (crlf[1] == '\n') *next = crlf + 2; else *next = crlf + 1; return WF;}intsdp_parse_k (sdp_t * sdp, char *buf, char **next){ char *equal; char *crlf; int i; char *colon; sdp_key_t *k_header; char *tmp; char *tmp_next; *next = buf; equal = buf; while ((*equal != '=') && (*equal != '\0')) equal++; if (*equal == '\0') return ERR_ERROR; /* check if header is "k" */ if (equal[-1] != 'k') 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; /* k=\r ?? bad header */ tmp = equal + 1; i = sdp_key_init (&k_header); if (i != 0) return ERR_ERROR; /* k=key-type[:key-data] */ /* is there any key-data? */ colon = strchr (equal + 1, ':'); if ((colon != NULL) && (colon < crlf)) { /* att-field is alpha-numeric */ i = set_next_token (&(k_header->k_keytype), tmp, ':', &tmp_next); if (i != 0) { sdp_key_free (k_header); sfree (k_header); return -1; } tmp = tmp_next; i = set_next_token (&(k_header->k_keydata), tmp, '\r', &tmp_next); if (i != 0) { i = set_next_token (&(k_header->k_keydata), tmp, '\n', &tmp_next); if (i != 0) { sdp_key_free (k_header); sfree (k_header); return -1; } } } else { i = set_next_token (&(k_header->k_keytype), tmp, '\r', &tmp_next); if (i != 0) { i = set_next_token (&(k_header->k_keytype), tmp, '\n', &tmp_next);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -