diff --git a/lib/nghttp2_frame.c b/lib/nghttp2_frame.c index 3efebadd..737eb371 100644 --- a/lib/nghttp2_frame.c +++ b/lib/nghttp2_frame.c @@ -32,21 +32,6 @@ #include "nghttp2_helper.h" #include "nghttp2_net.h" -/* This is SPDY stuff, and will be removed after header compression is - implemented */ -static size_t nghttp2_frame_get_len_size(void) -{ - return 2; -} - -static uint8_t* nghttp2_pack_str(uint8_t *buf, const char *str, size_t len) -{ - nghttp2_frame_put_nv_len(buf, len); - buf += nghttp2_frame_get_len_size(); - memcpy(buf, str, len); - return buf+len; -} - int nghttp2_frame_is_data_frame(uint8_t *head) { return head[2] == 0; @@ -68,122 +53,6 @@ void nghttp2_frame_unpack_frame_hd(nghttp2_frame_hd *hd, const uint8_t* buf) hd->stream_id = nghttp2_get_uint32(&buf[4]) & NGHTTP2_STREAM_ID_MASK; } -ssize_t nghttp2_frame_pack_nv(uint8_t *buf, char **nv, size_t len_size) -{ - int i; - uint8_t *bufp = buf+len_size; - uint32_t num_nv = 0; - const char *prev = ""; - uint8_t *cur_vallen_buf = NULL; - uint32_t cur_vallen = 0; - size_t prevkeylen = 0; - size_t prevvallen = 0; - for(i = 0; nv[i]; i += 2) { - const char *key = nv[i]; - const char *val = nv[i+1]; - size_t keylen = strlen(key); - size_t vallen = strlen(val); - if(prevkeylen == keylen && memcmp(prev, key, keylen) == 0) { - if(vallen) { - if(prevvallen) { - /* Join previous value, with NULL character */ - cur_vallen += vallen+1; - nghttp2_frame_put_nv_len(cur_vallen_buf, cur_vallen); - *bufp = '\0'; - ++bufp; - memcpy(bufp, val, vallen); - bufp += vallen; - } else { - /* Previous value is empty. In this case, drop the - previous. */ - cur_vallen += vallen; - nghttp2_frame_put_nv_len(cur_vallen_buf, cur_vallen); - memcpy(bufp, val, vallen); - bufp += vallen; - } - } - } else { - ++num_nv; - bufp = nghttp2_pack_str(bufp, key, keylen); - prev = key; - cur_vallen_buf = bufp; - cur_vallen = vallen; - prevkeylen = keylen; - prevvallen = vallen; - bufp = nghttp2_pack_str(bufp, val, vallen); - } - } - nghttp2_frame_put_nv_len(buf, num_nv); - return bufp-buf; -} - -void nghttp2_frame_nv_del(char **nv) -{ - free(nv); -} - -char** nghttp2_frame_nv_copy(const char **nv) -{ - int i; - char *buf; - char **idx, *data; - size_t buflen = 0; - for(i = 0; nv[i]; ++i) { - buflen += strlen(nv[i])+1; - } - buflen += (i+1)*sizeof(char*); - buf = malloc(buflen); - if(buf == NULL) { - return NULL; - } - idx = (char**)buf; - data = buf+(i+1)*sizeof(char*); - - for(i = 0; nv[i]; ++i) { - size_t len = strlen(nv[i])+1; - memcpy(data, nv[i], len); - *idx++ = data; - data += len; - } - *idx = NULL; - return (char**)buf; -} - -static int nghttp2_string_compar(const void *lhs, const void *rhs) -{ - return strcmp(*(char **)lhs, *(char **)rhs); -} - -void nghttp2_frame_nv_sort(char **nv) -{ - int n; - for(n = 0; nv[n]; ++n); - qsort(nv, n/2, 2*sizeof(char*), nghttp2_string_compar); -} - -void nghttp2_frame_nv_downcase(char **nv) -{ - int i, j; - for(i = 0; nv[i]; i += 2) { - for(j = 0; nv[i][j] != '\0'; ++j) { - if('A' <= nv[i][j] && nv[i][j] <= 'Z') { - nv[i][j] += 'a'-'A'; - } - } - } -} - -char** nghttp2_frame_nv_norm_copy(const char **nv) -{ - char **nv_copy; - nv_copy = nghttp2_frame_nv_copy(nv); - if(nv_copy != NULL) { - nghttp2_frame_nv_downcase(nv_copy); - nghttp2_frame_nv_sort(nv_copy); - } - return nv_copy; -} - static void nghttp2_frame_set_hd(nghttp2_frame_hd *hd, uint16_t length, uint8_t type, uint8_t flags, int32_t stream_id) @@ -326,6 +195,10 @@ void nghttp2_frame_data_init(nghttp2_data *frame, uint8_t flags, void nghttp2_frame_data_free(nghttp2_data *frame) {} +/* + * Returns the offset of the name/header block in the HEADERS frame, + * including frame header length. + */ static size_t headers_nv_offset(nghttp2_headers *frame) { if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY) { @@ -711,22 +584,6 @@ nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv, return iv_copy; } -ssize_t nghttp2_frame_nv_offset(const uint8_t *head) -{ - switch(head[2]) { - case NGHTTP2_HEADERS: - if(head[3] & NGHTTP2_FLAG_PRIORITY) { - return NGHTTP2_FRAME_HEAD_LENGTH + 4; - } else { - return NGHTTP2_FRAME_HEAD_LENGTH; - } - case NGHTTP2_PUSH_PROMISE: - return NGHTTP2_FRAME_HEAD_LENGTH + 4; - default: - return -1; - } -} - int nghttp2_frame_nv_check_null(const char **nv) { size_t i; diff --git a/lib/nghttp2_frame.h b/lib/nghttp2_frame.h index d9d5f29e..79a35a8c 100644 --- a/lib/nghttp2_frame.h +++ b/lib/nghttp2_frame.h @@ -64,9 +64,6 @@ typedef enum { NGHTTP2_CAT_DATA } nghttp2_frame_category; -#define nghttp2_frame_get_nv_len(RED) nghttp2_buffer_reader_uint16(RED) -#define nghttp2_frame_put_nv_len(OUT, VAL) nghttp2_put_uint16be(OUT, VAL) - /** * @struct * The DATA frame. It has the following members: @@ -434,24 +431,6 @@ int nghttp2_frame_unpack_window_update(nghttp2_window_update *frame, const uint8_t *payload, size_t payloadlen); -/* - * Returns number of bytes to pack name/value pairs |nv|. This - * function expects |nv| is sorted in ascending order of key. - * |len_size| is the number of bytes in length of name/value pair and - * it must be 2 or 4. - * - * This function can handles duplicate keys and concatenation of thier - * values with '\0'. - */ -size_t nghttp2_frame_count_nv_space(char **nv, size_t len_size); - -/* - * Packs name/value pairs in |nv| in |buf|. |buf| must have at least - * nghttp2_frame_count_nv_space(nv) bytes. |len_size| is the number - * of bytes in length of name/value pair and it must be 2 or 4. - */ -ssize_t nghttp2_frame_pack_nv(uint8_t *buf, char **nv, size_t len_size); - /* * Initializes HEADERS frame |frame| with given values. |frame| takes * ownership of |nva|, so caller must not free it. If |stream_id| is @@ -531,39 +510,6 @@ void nghttp2_frame_data_init(nghttp2_data *frame, uint8_t flags, void nghttp2_frame_data_free(nghttp2_data *frame); -/* - * Deallocates memory of name/value pair |nv|. - */ -void nghttp2_frame_nv_del(char **nv); - -/* - * Makes a deep copy of |nv| and returns the copy. This function - * returns the pointer to the copy if it succeeds, or NULL. To free - * allocated memory, use nghttp2_frame_nv_del(). - */ -char** nghttp2_frame_nv_copy(const char **nv); - -/* - * Sorts |nv| in the ascending order of name. - */ -void nghttp2_frame_nv_sort(char **nv); - -/* - * Makes names in |nv| lower cased. - */ -void nghttp2_frame_nv_downcase(char **nv); - -/* - * This function first makes a copy of |nv| using - * nghttp2_frame_nv_copy(). If it succeeds, then call - * nghttp2_frame_nv_downcase() and nghttp2_frame_nv_sort() with the - * copied name/value pairs. - * - * This function returns the copied name/value pairs if it succeeds, - * or NULL. - */ -char** nghttp2_frame_nv_norm_copy(const char **nv); - /* * Makes copy of |iv| and return the copy. The |niv| is the number of * entries in |iv|. This function returns the pointer to the copy if @@ -572,13 +518,6 @@ char** nghttp2_frame_nv_norm_copy(const char **nv); nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv, size_t niv); -/* - * Returns the offset of the name/header block in the frame, including - * frame header. The |head| is frame header. If the indicated frame - * type does not have header block, this function returns -1. - */ -ssize_t nghttp2_frame_nv_offset(const uint8_t *head); - /* * Checks names are not empty string and do not contain control * characters and values are not NULL. diff --git a/tests/main.c b/tests/main.c index 1d2748a0..c3668b6f 100644 --- a/tests/main.c +++ b/tests/main.c @@ -196,9 +196,6 @@ int main(int argc, char* argv[]) test_nghttp2_session_data_backoff_by_high_pri_frame) || !CU_add_test(pSuite, "pack_settings_payload", test_nghttp2_pack_settings_payload) || - !CU_add_test(pSuite, "frame_nv_sort", test_nghttp2_frame_nv_sort) || - !CU_add_test(pSuite, "frame_nv_downcase", - test_nghttp2_frame_nv_downcase) || !CU_add_test(pSuite, "frame_nv_check_null", test_nghttp2_frame_nv_check_null) || !CU_add_test(pSuite, "frame_pack_headers", diff --git a/tests/nghttp2_frame_test.c b/tests/nghttp2_frame_test.c index aabd2b15..3c620e37 100644 --- a/tests/nghttp2_frame_test.c +++ b/tests/nghttp2_frame_test.c @@ -44,42 +44,6 @@ static const char *headers[] = { NULL }; -void test_nghttp2_frame_nv_sort(void) -{ - char *nv[7]; - nv[0] = (char*)"version"; - nv[1] = (char*)"HTTP/1.1"; - nv[2] = (char*)"method"; - nv[3] = (char*)"GET"; - nv[4] = (char*)"scheme"; - nv[5] = (char*)"https"; - nv[6] = NULL; - nghttp2_frame_nv_sort(nv); - CU_ASSERT(strcmp("method", nv[0]) == 0); - CU_ASSERT(strcmp("GET", nv[1]) == 0); - CU_ASSERT(strcmp("scheme", nv[2]) == 0); - CU_ASSERT(strcmp("https", nv[3]) == 0); - CU_ASSERT(strcmp("version", nv[4]) == 0); - CU_ASSERT(strcmp("HTTP/1.1", nv[5]) == 0); -} - -void test_nghttp2_frame_nv_downcase(void) -{ - const char *nv_src[] = { - "VERSION", "HTTP/1.1", - "Content-Length", "1000000007", - NULL - }; - char **nv; - nv = nghttp2_frame_nv_copy(nv_src); - nghttp2_frame_nv_downcase(nv); - CU_ASSERT(0 == strcmp("version", nv[0])); - CU_ASSERT(0 == strcmp("HTTP/1.1", nv[1])); - CU_ASSERT(0 == strcmp("content-length", nv[2])); - CU_ASSERT(0 == strcmp("1000000007", nv[3])); - nghttp2_frame_nv_del(nv); -} - void test_nghttp2_frame_nv_check_null(void) { const char *headers1[] = { "path", "/", "host", "a", NULL }; diff --git a/tests/nghttp2_frame_test.h b/tests/nghttp2_frame_test.h index 7eb52e62..742038e2 100644 --- a/tests/nghttp2_frame_test.h +++ b/tests/nghttp2_frame_test.h @@ -25,8 +25,6 @@ #ifndef NGHTTP2_FRAME_TEST_H #define NGHTTP2_FRAME_TEST_H -void test_nghttp2_frame_nv_sort(void); -void test_nghttp2_frame_nv_downcase(void); void test_nghttp2_frame_nv_check_null(void); void test_nghttp2_frame_pack_headers(void); void test_nghttp2_frame_pack_headers_frame_too_large(void);