wsp_headers.c
来自「mms client」· C语言 代码 · 共 2,167 行 · 第 1/5 页
C
2,167 行
{ unsigned long timeval; int length; length = parse_get_char(context); if (length > 30) { warning(0, "WSP headers: bad date-value."); return NULL; } timeval = unpack_multi_octet_integer(context, length); if (timeval < 0) { warning(0, "WSP headers: cannot unpack date-value."); return NULL; } return date_format_http(timeval);}/* Accept-general-form is defined in 8.4.2.7 */Octstr *unpack_accept_general_form(ParseContext *context){ Octstr *decoded = NULL; int ret; long val; /* The definition for Accept-general-form looks quite complicated, * but the "Q-token Q-value" part fits the normal expansion of * Parameter, so it simplifies to: * Value-length Media-range *(Parameter) * and we've already parsed Value-length. */ /* We use this function to parse content-general-form too, * because its definition of Media-type is identical to Media-range. */ ret = secondary_field_value(context, &val); if (parse_error(context) || ret == WSP_FIELD_VALUE_NONE) { warning(0, "bad media-range or media-type"); return NULL; } if (ret == WSP_FIELD_VALUE_ENCODED) { decoded = wsp_content_type_to_string(val); if (!decoded) { warning(0, "Unknown content type 0x%02lx.", val); return NULL; } } else if (ret == WSP_FIELD_VALUE_NUL_STRING) { decoded = parse_get_nul_string(context); if (!decoded) { warning(0, "Format error in content type"); return NULL; } } else { panic(0, "Unknown secondary field value type %d.", ret); } unpack_all_parameters(context, decoded); return decoded;}/* Accept-charset-general-form is defined in 8.4.2.8 */Octstr *unpack_accept_charset_general_form(ParseContext *context){ Octstr *decoded = NULL; int ret; long val; ret = secondary_field_value(context, &val); if (parse_error(context) || ret == WSP_FIELD_VALUE_NONE) { warning(0, "Bad accept-charset-general-form"); return NULL; } if (ret == WSP_FIELD_VALUE_ENCODED) { decoded = wsp_charset_to_string(val); if (!decoded) { warning(0, "Unknown character set %04lx.", val); return NULL; } } else if (ret == WSP_FIELD_VALUE_NUL_STRING) { decoded = parse_get_nul_string(context); if (!decoded) { warning(0, "Format error in accept-charset"); return NULL; } } else { panic(0, "Unknown secondary field value type %d.", ret); } unpack_optional_q_value(context, decoded); return decoded;}/* Accept-language-general-form is defined in 8.4.2.10 */Octstr *unpack_accept_language_general_form(ParseContext *context){ Octstr *decoded = NULL; int ret; long val; ret = secondary_field_value(context, &val); if (parse_error(context) || ret == WSP_FIELD_VALUE_NONE) { warning(0, "Bad accept-language-general-form"); return NULL; } if (ret == WSP_FIELD_VALUE_ENCODED) { /* Any-language is handled by a special entry in the * language table. */ decoded = wsp_language_to_string(val); if (!decoded) { warning(0, "Unknown language %02lx.", val); return NULL; } } else if (ret == WSP_FIELD_VALUE_NUL_STRING) { decoded = parse_get_nul_string(context); if (!decoded) { warning(0, "Format error in accept-language"); return NULL; } } else { panic(0, "Unknown secondary field value type %d.", ret); } unpack_optional_q_value(context, decoded); return decoded;}/* Credentials is defined in 8.4.2.5 */Octstr *unpack_credentials(ParseContext *context){ Octstr *decoded = NULL; int val; val = parse_peek_char(context); if (val == BASIC_AUTHENTICATION) { Octstr *userid, *password; parse_skip(context, 1); userid = parse_get_nul_string(context); password = parse_get_nul_string(context); if (parse_error(context)) { octstr_destroy(userid); octstr_destroy(password); } else { /* Create the user-pass cookie */ decoded = octstr_duplicate(userid); octstr_append_char(decoded, ':'); octstr_append(decoded, password); /* XXX Deal with cookies that overflow the 76-per-line * limit of base64. Either go through and zap all * CR LF sequences, or give the conversion function * a flag or something to leave them out. */ octstr_binary_to_base64(decoded); /* Zap the CR LF at the end */ octstr_delete(decoded, octstr_len(decoded) - 2, 2); octstr_insert_data(decoded, 0, "Basic ", 6); octstr_destroy(userid); octstr_destroy(password); } } else if (val >= 32 && val < 128) { /* Generic authentication scheme */ decoded = parse_get_nul_string(context); if (decoded) unpack_broken_parameters(context, decoded); } if (!decoded) warning(0, "Cannot parse credentials."); return decoded;}/* Challenge is defined in 8.4.2.5 */Octstr *unpack_challenge(ParseContext *context){ Octstr *decoded = NULL; Octstr *realm_value = NULL; int val; val = parse_peek_char(context); if (val == BASIC_AUTHENTICATION) { parse_skip(context, 1); realm_value = parse_get_nul_string(context); if (realm_value) { decoded = octstr_create("Basic realm=\""); octstr_append(decoded, realm_value); octstr_append_char(decoded, '"'); } } else if (val >= 32 && val < 128) { /* Generic authentication scheme */ decoded = parse_get_nul_string(context); realm_value = parse_get_nul_string(context); if (decoded && realm_value) { octstr_append(decoded, octstr_imm(" realm=\"")); octstr_append(decoded, realm_value); octstr_append_char(decoded, '"'); if (parse_octets_left(context) > 0) { /* Prepare for following parameter list */ octstr_append_char(decoded, ','); } unpack_broken_parameters(context, decoded); } } if (!decoded) warning(0, "Cannot parse challenge."); octstr_destroy(realm_value); return decoded;}/* Content-range is defined in 8.4.2.23 */Octstr *unpack_content_range(ParseContext *context){ /* We'd have to figure out how to access the content range * length (i.e. user_data size) from here to parse this, * and I don't see why the _client_ would send this in any case. */ warning(0, "Decoding of content-range not supported"); return NULL; /* Octstr *decoded = NULL; unsigned long first_byte_pos, entity_length; unsigned long last_byte_pos; first_byte_pos = parse_get_uintvar(context); entity_length = parse_get_uintvar(context); if (parse_error(context)) { warning(0, "Cannot parse content-range header"); return NULL; } decoded = octstr_create("bytes "); octstr_append_decimal(decoded, first_byte_pos); octstr_append_char(decoded, '-'); octstr_append_decimal(decoded, last_byte_pos); octstr_append_char(decoded, '/'); octstr_append_decimal(decoded, entity_length); return decoded; */}/* Field-name is defined in 8.4.2.6 */Octstr *unpack_field_name(ParseContext *context){ Octstr *decoded = NULL; int ret; int val; ret = field_value(context, &val); if (parse_error(context) || ret == WSP_FIELD_VALUE_DATA) { warning(0, "Bad field-name encoding"); return NULL; } if (ret == WSP_FIELD_VALUE_ENCODED) { decoded = wsp_header_to_string(val); if (!decoded) { warning(0, "Unknown field-name 0x%02x.", val); return NULL; } } else if (ret == WSP_FIELD_VALUE_NUL_STRING) { decoded = parse_get_nul_string(context); if (!decoded) { warning(0, "Bad field-name encoding"); return NULL; } } else { panic(0, "Unknown field value type %d.", ret); } return decoded;}/* Cache-directive is defined in 8.4.2.15 */Octstr *unpack_cache_directive(ParseContext *context){ Octstr *decoded = NULL; int ret; int val; ret = field_value(context, &val); if (parse_error(context) || ret == WSP_FIELD_VALUE_DATA) { warning(0, "Bad cache-directive"); goto error; } if (ret == WSP_FIELD_VALUE_ENCODED) { decoded = wsp_cache_control_to_string(val); if (!decoded) { warning(0, "Bad cache-directive 0x%02x.", val); goto error; } octstr_append_char(decoded, '='); switch (val) { case WSP_CACHE_CONTROL_NO_CACHE: case WSP_CACHE_CONTROL_PRIVATE: if (parse_octets_left(context) == 0) { warning(0, "Too short cache-directive"); goto error; } octstr_append_char(decoded, '"'); do { Octstr *fieldname = unpack_field_name(context); if (!fieldname) { warning(0, "Bad field name in cache directive"); goto error; } octstr_append(decoded, fieldname); octstr_destroy(fieldname); if (parse_octets_left(context) > 0) { octstr_append_char(decoded, ','); octstr_append_char(decoded, ' '); } } while (parse_octets_left(context) > 0 && !parse_error(context)); octstr_append_char(decoded, '"'); break; case WSP_CACHE_CONTROL_MAX_AGE: case WSP_CACHE_CONTROL_MAX_STALE: case WSP_CACHE_CONTROL_MIN_FRESH: { Octstr *seconds; seconds = unpack_integer_value(context); if (!seconds) { warning(0, "Bad integer value in cache directive"); goto error; } octstr_append(decoded, seconds); octstr_destroy(seconds); } break; default: warning(0, "Unexpected value 0x%02x in cache directive.", val); break; } } else if (ret == WSP_FIELD_VALUE_NUL_STRING) { /* XXX: WSP grammar seems wrong here. It works out * to Token-text followed by Parameter. But the * grammar in RFC2616 works out to a key = value * pair, i.e. only a Parameter. */ decoded = parse_get_nul_string(context); if (!decoded) { warning(0, "Format error in cache-control."); return NULL; } /* Yes, the grammar allows only one */ unpack_parameter(context, decoded); } else { panic(0, "Unknown field value type %d.", ret); } return decoded;error: octstr_destroy(decoded); return NULL;}/* Retry-after is defined in 8.4.2.44 */Octstr *unpack_retry_after(ParseContext *context){ int selector; selector = parse_get_char(context); if (selector == ABSOLUTE_TIME) { return unpack_date_value(context); } else if (selector == RELATIVE_TIME) { return unpack_integer_value(context); } else { warning(0, "Cannot parse retry-after value."); return NULL; }}/* Disposition is defined in 8.4.2.53 */Octstr *unpack_disposition(ParseContext *context){ Octstr *decoded = NULL; int selector; selector = parse_get_char(context) - 128; decoded = wsp_disposition_to_string(selector); if (!decoded) { warning(0, "Cannot parse content-disposition value."); return NULL; } unpack_all_parameters(context, decoded); return decoded;}/* Range-value is defined in 8.4.2.42 */Octstr *unpack_range_value(ParseContext *context){ Octstr *decoded = NULL; int selector; unsigned long first_byte_pos, last_byte_pos, suffix_length; selector = parse_get_char(context); if (selector == BYTE_RANGE) { first_byte_pos = parse_get_uintvar(context); if (parse_error(context)) goto error; decoded = octstr_create("bytes = "); octstr_append_decimal(decoded, first_byte_pos); octstr_append_char(decoded, '-'); last_byte_pos = parse_get_uintvar(context); if (parse_error(context)) { /* last_byte_pos is optional */ parse_clear_error(context); } else { octstr_append_decimal(decoded, last_byte_pos); } } else if (selector == SUFFIX_BYTE_RANGE) { suffix_length = parse_get_uintvar(context); if (parse_error(context)) goto error;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?