diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-13 20:36:30 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-13 20:36:30 +0200 |
commit | 5565cb954c8a4303b697271fa8620230baa64eaa (patch) | |
tree | 1784e764548e69efe63ae56afa32294cc5cf6502 | |
parent | b84ae2b67f1cdfebd24585335125423f5f27517d (diff) | |
download | libmicrohttpd-5565cb954c8a4303b697271fa8620230baa64eaa.tar.gz libmicrohttpd-5565cb954c8a4303b697271fa8620230baa64eaa.zip |
indentation
-rw-r--r-- | src/microhttpd/test_md5.c | 406 | ||||
-rw-r--r-- | src/microhttpd/test_upgrade.c | 626 |
2 files changed, 553 insertions, 479 deletions
diff --git a/src/microhttpd/test_md5.c b/src/microhttpd/test_md5.c index d9517206..2825c09f 100644 --- a/src/microhttpd/test_md5.c +++ b/src/microhttpd/test_md5.c | |||
@@ -33,7 +33,7 @@ static int verbose = 0; /* verbose level (0-1)*/ | |||
33 | 33 | ||
34 | struct str_with_len | 34 | struct str_with_len |
35 | { | 35 | { |
36 | const char * const str; | 36 | const char *const str; |
37 | const size_t len; | 37 | const size_t len; |
38 | }; | 38 | }; |
39 | 39 | ||
@@ -46,17 +46,22 @@ struct data_unit1 | |||
46 | }; | 46 | }; |
47 | 47 | ||
48 | static const struct data_unit1 data_units1[] = { | 48 | static const struct data_unit1 data_units1[] = { |
49 | {D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`."), | 49 | {D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`."), |
50 | {0x1c, 0x68, 0xc2, 0xe5, 0x1f, 0x63, 0xc9, 0x5f, 0x17, 0xab, 0x1f, 0x20, 0x8b, 0x86, 0x39, 0x57}}, | 50 | {0x1c, 0x68, 0xc2, 0xe5, 0x1f, 0x63, 0xc9, 0x5f, 0x17, 0xab, 0x1f, 0x20, |
51 | {D_STR_W_LEN("Simple string."), | 51 | 0x8b, 0x86, 0x39, 0x57}}, |
52 | {0xf1, 0x2b, 0x7c, 0xad, 0xa0, 0x41, 0xfe, 0xde, 0x4e, 0x68, 0x16, 0x63, 0xb4, 0x60, 0x5d, 0x78}}, | 52 | {D_STR_W_LEN ("Simple string."), |
53 | {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz"), | 53 | {0xf1, 0x2b, 0x7c, 0xad, 0xa0, 0x41, 0xfe, 0xde, 0x4e, 0x68, 0x16, 0x63, |
54 | {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b}}, | 54 | 0xb4, 0x60, 0x5d, 0x78}}, |
55 | {D_STR_W_LEN("zyxwvutsrqponMLKJIHGFEDCBA"), | 55 | {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz"), |
56 | {0x05, 0x61, 0x3a, 0x6b, 0xde, 0x75, 0x3a, 0x45, 0x91, 0xa8, 0x81, 0xb0, 0xa7, 0xe2, 0xe2, 0x0e}}, | 56 | {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, |
57 | {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA" | 57 | 0xca, 0x67, 0xe1, 0x3b}}, |
58 | "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA"), | 58 | {D_STR_W_LEN ("zyxwvutsrqponMLKJIHGFEDCBA"), |
59 | {0xaf, 0xab, 0xc7, 0xe9, 0xe7, 0x17, 0xbe, 0xd6, 0xc0, 0x0f, 0x78, 0x8c, 0xde, 0xdd, 0x11, 0xd1}}, | 59 | {0x05, 0x61, 0x3a, 0x6b, 0xde, 0x75, 0x3a, 0x45, 0x91, 0xa8, 0x81, 0xb0, |
60 | 0xa7, 0xe2, 0xe2, 0x0e}}, | ||
61 | {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA" | ||
62 | "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA"), | ||
63 | {0xaf, 0xab, 0xc7, 0xe9, 0xe7, 0x17, 0xbe, 0xd6, 0xc0, 0x0f, 0x78, 0x8c, | ||
64 | 0xde, 0xdd, 0x11, 0xd1}}, | ||
60 | }; | 65 | }; |
61 | 66 | ||
62 | static const size_t units1_num = sizeof(data_units1) / sizeof(data_units1[0]); | 67 | static const size_t units1_num = sizeof(data_units1) / sizeof(data_units1[0]); |
@@ -74,85 +79,134 @@ struct data_unit2 | |||
74 | }; | 79 | }; |
75 | 80 | ||
76 | static const struct data_unit2 data_units2[] = { | 81 | static const struct data_unit2 data_units2[] = { |
77 | { { {97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, | 82 | { { {97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, |
78 | 117, 118, 119, 120, 121, 122}, 26},/* a..z ASCII sequence */ | 83 | 112, 113, 114, 115, 116, |
79 | {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b} | 84 | 117, 118, 119, 120, 121, 122}, 26}, /* a..z ASCII sequence */ |
80 | }, | 85 | {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, |
81 | { { {65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 86 | 0xca, 0x67, 0xe1, 0x3b}}, |
82 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 87 | { { {65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, |
83 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65 | 88 | 65, 65, 65, 65, 65, 65, |
84 | }, 72 },/* 'A' x 72 times */ | 89 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, |
85 | {0x24, 0xa5, 0xef, 0x36, 0x82, 0x80, 0x3a, 0x06, 0x2f, 0xea, 0xad, 0xad, 0x76, 0xda, 0xbd, 0xa8} | 90 | 65, 65, 65, 65, 65, 65, |
86 | }, | 91 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, |
87 | { { {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, | 92 | 65, 65, 65, 65, 65, 65}, 72 },/* 'A' x 72 times */ |
88 | 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, | 93 | {0x24, 0xa5, 0xef, 0x36, 0x82, 0x80, 0x3a, 0x06, 0x2f, 0xea, 0xad, 0xad, |
89 | 68, 69, 70, 71, 72, 73}, 55},/* 19..73 sequence */ | 94 | 0x76, 0xda, 0xbd, 0xa8}}, |
90 | {0x6d, 0x2e, 0x6e, 0xde, 0x5d, 0x64, 0x6a, 0x17, 0xf1, 0x09, 0x2c, 0xac, 0x19, 0x10, 0xe3, 0xd6} | 95 | { { {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, |
91 | }, | 96 | 37, 38, 39, 40, 41, 42, |
92 | { { {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, | 97 | 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, |
93 | 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, | 98 | 61, 62, 63, 64, 65, 66, 67, |
94 | 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69}, 63},/* 7..69 sequence */ | 99 | 68, 69, 70, 71, 72, 73}, 55}, /* 19..73 sequence */ |
95 | {0x88, 0x13, 0x48, 0x47, 0x73, 0xaa, 0x92, 0xf2, 0xc9, 0xdd, 0x69, 0xb3, 0xac, 0xf4, 0xba, 0x6e} | 100 | {0x6d, 0x2e, 0x6e, 0xde, 0x5d, 0x64, 0x6a, 0x17, 0xf1, 0x09, 0x2c, 0xac, |
96 | }, | 101 | 0x19, 0x10, 0xe3, 0xd6}}, |
97 | { { {38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, | 102 | { { {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, |
98 | 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, | 103 | 26, 27, 28, 29, 30, 31, |
99 | 87, 88, 89, 90, 91, 92}, 55},/* 38..92 sequence */ | 104 | 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, |
100 | {0x80, 0xf0, 0x05, 0x7e, 0xa2, 0xf7, 0xc8, 0x43, 0x12, 0xd3, 0xb1, 0x61, 0xab, 0x52, 0x3b, 0xaf} | 105 | 50, 51, 52, 53, 54, 55, 56, |
101 | }, | 106 | 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69}, 63}, /* 7..69 sequence */ |
102 | { { {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, | 107 | {0x88, 0x13, 0x48, 0x47, 0x73, 0xaa, 0x92, 0xf2, 0xc9, 0xdd, 0x69, 0xb3, |
103 | 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, | 108 | 0xac, 0xf4, 0xba, 0x6e}}, |
104 | 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72}, | 109 | { { {38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, |
110 | 56, 57, 58, 59, 60, 61, | ||
111 | 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, | ||
112 | 80, 81, 82, 83, 84, 85, 86, | ||
113 | 87, 88, 89, 90, 91, 92}, 55}, /* 38..92 sequence */ | ||
114 | {0x80, 0xf0, 0x05, 0x7e, 0xa2, 0xf7, 0xc8, 0x43, 0x12, 0xd3, 0xb1, 0x61, | ||
115 | 0xab, 0x52, 0x3b, 0xaf}}, | ||
116 | { { {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, | ||
117 | 21, 22, 23, 24, 25, 26, 27, | ||
118 | 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, | ||
119 | 46, 47, 48, 49, 50, 51, 52, | ||
120 | 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, | ||
121 | 71, 72}, | ||
105 | 72},/* 1..72 sequence */ | 122 | 72},/* 1..72 sequence */ |
106 | {0xc3, 0x28, 0xc5, 0xad, 0xc9, 0x26, 0xa9, 0x99, 0x95, 0x4a, 0x5e, 0x25, 0x50, 0x34, 0x51, 0x73} | 123 | {0xc3, 0x28, 0xc5, 0xad, 0xc9, 0x26, 0xa9, 0x99, 0x95, 0x4a, 0x5e, 0x25, |
107 | }, | 124 | 0x50, 0x34, 0x51, 0x73}}, |
108 | { { {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, | 125 | { { {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
109 | 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, | 126 | 21, 22, 23, 24, 25, 26, |
110 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, | 127 | 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, |
111 | 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, | 128 | 45, 46, 47, 48, 49, 50, 51, |
112 | 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, | 129 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, |
113 | 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, | 130 | 70, 71, 72, 73, 74, 75, 76, |
114 | 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, | 131 | 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, |
115 | 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, | 132 | 95, 96, 97, 98, 99, 100, |
116 | 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, | 133 | 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, |
117 | 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, | 134 | 115, 116, 117, 118, 119, 120, |
118 | 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, | 135 | 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, |
119 | 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}, 256}, /* 0..255 sequence */ | 136 | 135, 136, 137, 138, 139, 140, |
120 | {0xe2, 0xc8, 0x65, 0xdb, 0x41, 0x62, 0xbe, 0xd9, 0x63, 0xbf, 0xaa, 0x9e, 0xf6, 0xac, 0x18, 0xf0} | 137 | 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, |
121 | }, | 138 | 155, 156, 157, 158, 159, 160, |
122 | { { {199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, | 139 | 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, |
123 | 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, | 140 | 175, 176, 177, 178, 179, 180, |
124 | 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, | 141 | 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, |
125 | 139}, 61}, /* 199..139 sequence */ | 142 | 195, 196, 197, 198, 199, 200, |
126 | {0xbb, 0x3f, 0xdb, 0x4a, 0x96, 0x03, 0x36, 0x37, 0x38, 0x78, 0x5e, 0x44, 0xbf, 0x3a, 0x85, 0x51} | 143 | 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, |
127 | }, | 144 | 215, 216, 217, 218, 219, 220, |
128 | { { {255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 237, 236, | 145 | 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, |
129 | 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, | 146 | 235, 236, 237, 238, 239, 240, |
130 | 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200, 199, 198, 197, 196, | 147 | 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, |
131 | 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, | 148 | 255}, 256}, /* 0..255 sequence */ |
132 | 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, 156, | 149 | {0xe2, 0xc8, 0x65, 0xdb, 0x41, 0x62, 0xbe, 0xd9, 0x63, 0xbf, 0xaa, 0x9e, |
133 | 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, | 150 | 0xf6, 0xac, 0x18, 0xf0}}, |
134 | 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, | 151 | { { {199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, |
135 | 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, | 152 | 185, 184, 183, 182, 181, 180, |
136 | 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, | 153 | 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, |
137 | 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, | 154 | 165, 164, 163, 162, 161, 160, |
138 | 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, | 155 | 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, |
139 | 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 255}, /* 255..1 sequence */ | 156 | 145, 144, 143, 142, 141, 140, |
140 | {0x52, 0x21, 0xa5, 0x83, 0x4f, 0x38, 0x7c, 0x73, 0xba, 0x18, 0x22, 0xb1, 0xf9, 0x7e, 0xae, 0x8b} | 157 | 139}, 61}, /* 199..139 sequence */ |
141 | }, | 158 | {0xbb, 0x3f, 0xdb, 0x4a, 0x96, 0x03, 0x36, 0x37, 0x38, 0x78, 0x5e, 0x44, |
142 | { { {41, 35, 190, 132, 225, 108, 214, 174, 82, 144, 73, 241, 241, 187, 233, 235, 179, 166, 219, 60, 135, | 159 | 0xbf, 0x3a, 0x85, 0x51}}, |
143 | 12, 62, 153, 36, 94, 13, 28, 6, 183, 71, 222, 179, 18, 77, 200, 67, 187, 139, 166, 31, 3, 90, 125, 9, | 160 | { { {255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, |
144 | 56, 37, 31, 93, 212, 203, 252, 150, 245, 69, 59, 19, 13, 137, 10, 28, 219, 174, 50, 32, 154, 80, 238, | 161 | 241, 240, 239, 238, 237, 236, |
145 | 64, 120, 54, 253, 18, 73, 50, 246, 158, 125, 73, 220, 173, 79, 20, 242, 68, 64, 102, 208, 107, 196, | 162 | 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, |
146 | 48, 183, 50, 59, 161, 34, 246, 34, 145, 157, 225, 139, 31, 218, 176, 202, 153, 2, 185, 114, 157, 73, | 163 | 221, 220, 219, 218, 217, 216, |
147 | 44, 128, 126, 197, 153, 213, 233, 128, 178, 234, 201, 204, 83, 191, 103, 214, 191, 20, 214, 126, 45, | 164 | 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, |
148 | 220, 142, 102, 131, 239, 87, 73, 97, 255, 105, 143, 97, 205, 209, 30, 157, 156, 22, 114, 114, 230, | 165 | 201, 200, 199, 198, 197, 196, |
149 | 29, 240, 132, 79, 74, 119, 2, 215, 232, 57, 44, 83, 203, 201, 18, 30, 51, 116, 158, 12, 244, 213, | 166 | 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, |
150 | 212, 159, 212, 164, 89, 126, 53, 207, 50, 34, 244, 204, 207, 211, 144, 45, 72, 211, 143, 117, 230, | 167 | 181, 180, 179, 178, 177, 176, |
151 | 217, 29, 42, 229, 192, 247, 43, 120, 129, 135, 68, 14, 95, 80, 0, 212, 97, 141, 190, 123, 5, 21, 7, | 168 | 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, |
152 | 59, 51, 130, 31, 24, 112, 146, 218, 100, 84, 206, 177, 133, 62, 105, 21, 248, 70, 106, 4, 150, 115, | 169 | 161, 160, 159, 158, 157, 156, |
153 | 14, 217, 22, 47, 103, 104, 212, 247, 74, 74, 208, 87, 104}, 255}, /* pseudo-random data */ | 170 | 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, |
154 | {0x55, 0x61, 0x2c, 0xeb, 0x29, 0xee, 0xa8, 0xb2, 0xf6, 0x10, 0x7b, 0xc1, 0x5b, 0x0f, 0x01, 0x95} | 171 | 141, 140, 139, 138, 137, 136, |
155 | } | 172 | 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, |
173 | 121, 120, 119, 118, 117, 116, | ||
174 | 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, | ||
175 | 101, 100, 99, 98, 97, 96, 95, | ||
176 | 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, | ||
177 | 76, 75, 74, 73, 72, 71, 70, | ||
178 | 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, | ||
179 | 51, 50, 49, 48, 47, 46, 45, | ||
180 | 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, | ||
181 | 26, 25, 24, 23, 22, 21, 20, | ||
182 | 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 255}, /* 255..1 sequence */ | ||
183 | {0x52, 0x21, 0xa5, 0x83, 0x4f, 0x38, 0x7c, 0x73, 0xba, 0x18, 0x22, 0xb1, | ||
184 | 0xf9, 0x7e, 0xae, 0x8b}}, | ||
185 | { { {41, 35, 190, 132, 225, 108, 214, 174, 82, 144, 73, 241, 241, 187, 233, | ||
186 | 235, 179, 166, 219, 60, 135, | ||
187 | 12, 62, 153, 36, 94, 13, 28, 6, 183, 71, 222, 179, 18, 77, 200, 67, 187, | ||
188 | 139, 166, 31, 3, 90, 125, 9, | ||
189 | 56, 37, 31, 93, 212, 203, 252, 150, 245, 69, 59, 19, 13, 137, 10, 28, | ||
190 | 219, 174, 50, 32, 154, 80, 238, | ||
191 | 64, 120, 54, 253, 18, 73, 50, 246, 158, 125, 73, 220, 173, 79, 20, 242, | ||
192 | 68, 64, 102, 208, 107, 196, | ||
193 | 48, 183, 50, 59, 161, 34, 246, 34, 145, 157, 225, 139, 31, 218, 176, 202, | ||
194 | 153, 2, 185, 114, 157, 73, | ||
195 | 44, 128, 126, 197, 153, 213, 233, 128, 178, 234, 201, 204, 83, 191, 103, | ||
196 | 214, 191, 20, 214, 126, 45, | ||
197 | 220, 142, 102, 131, 239, 87, 73, 97, 255, 105, 143, 97, 205, 209, 30, | ||
198 | 157, 156, 22, 114, 114, 230, | ||
199 | 29, 240, 132, 79, 74, 119, 2, 215, 232, 57, 44, 83, 203, 201, 18, 30, 51, | ||
200 | 116, 158, 12, 244, 213, | ||
201 | 212, 159, 212, 164, 89, 126, 53, 207, 50, 34, 244, 204, 207, 211, 144, | ||
202 | 45, 72, 211, 143, 117, 230, | ||
203 | 217, 29, 42, 229, 192, 247, 43, 120, 129, 135, 68, 14, 95, 80, 0, 212, | ||
204 | 97, 141, 190, 123, 5, 21, 7, | ||
205 | 59, 51, 130, 31, 24, 112, 146, 218, 100, 84, 206, 177, 133, 62, 105, 21, | ||
206 | 248, 70, 106, 4, 150, 115, | ||
207 | 14, 217, 22, 47, 103, 104, 212, 247, 74, 74, 208, 87, 104}, 255}, /* pseudo-random data */ | ||
208 | {0x55, 0x61, 0x2c, 0xeb, 0x29, 0xee, 0xa8, 0xb2, 0xf6, 0x10, 0x7b, 0xc1, | ||
209 | 0x5b, 0x0f, 0x01, 0x95}} | ||
156 | }; | 210 | }; |
157 | 211 | ||
158 | static const size_t units2_num = sizeof(data_units2) / sizeof(data_units2[0]); | 212 | static const size_t units2_num = sizeof(data_units2) / sizeof(data_units2[0]); |
@@ -171,17 +225,17 @@ static const size_t units2_num = sizeof(data_units2) / sizeof(data_units2[0]); | |||
171 | */ | 225 | */ |
172 | static void | 226 | static void |
173 | bin2hex (const uint8_t *bin, | 227 | bin2hex (const uint8_t *bin, |
174 | size_t len, | 228 | size_t len, |
175 | char *hex) | 229 | char *hex) |
176 | { | 230 | { |
177 | while (len-- > 0) | 231 | while (len-- > 0) |
178 | { | 232 | { |
179 | unsigned int b1, b2; | 233 | unsigned int b1, b2; |
180 | b1 = (*bin >> 4) & 0xf; | 234 | b1 = (*bin >> 4) & 0xf; |
181 | *hex++ = (char)((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0')); | 235 | *hex++ = (char) ((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0')); |
182 | b2 = *bin++ & 0xf; | 236 | b2 = *bin++ & 0xf; |
183 | *hex++ = (char)((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0')); | 237 | *hex++ = (char) ((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0')); |
184 | } | 238 | } |
185 | *hex = 0; | 239 | *hex = 0; |
186 | } | 240 | } |
187 | 241 | ||
@@ -192,26 +246,28 @@ check_result (const char *test_name, | |||
192 | const uint8_t calcualted[MD5_DIGEST_SIZE], | 246 | const uint8_t calcualted[MD5_DIGEST_SIZE], |
193 | const uint8_t expected[MD5_DIGEST_SIZE]) | 247 | const uint8_t expected[MD5_DIGEST_SIZE]) |
194 | { | 248 | { |
195 | int failed = memcmp(calcualted, expected, MD5_DIGEST_SIZE); | 249 | int failed = memcmp (calcualted, expected, MD5_DIGEST_SIZE); |
196 | check_num++; /* Print 1-based numbers */ | 250 | check_num++; /* Print 1-based numbers */ |
197 | if (failed) | 251 | if (failed) |
198 | { | 252 | { |
199 | char calc_str[MD5_DIGEST_STRING_LENGTH]; | 253 | char calc_str[MD5_DIGEST_STRING_LENGTH]; |
200 | char expc_str[MD5_DIGEST_STRING_LENGTH]; | 254 | char expc_str[MD5_DIGEST_STRING_LENGTH]; |
201 | bin2hex(calcualted, MD5_DIGEST_SIZE, calc_str); | 255 | bin2hex (calcualted, MD5_DIGEST_SIZE, calc_str); |
202 | bin2hex(expected, MD5_DIGEST_SIZE, expc_str); | 256 | bin2hex (expected, MD5_DIGEST_SIZE, expc_str); |
203 | fprintf (stderr, "FAILED: %s check %u: calculated digest %s, expected digest %s.\n", | 257 | fprintf (stderr, |
204 | test_name, check_num, calc_str, expc_str); | 258 | "FAILED: %s check %u: calculated digest %s, expected digest %s.\n", |
205 | fflush (stderr); | 259 | test_name, check_num, calc_str, expc_str); |
206 | } | 260 | fflush (stderr); |
261 | } | ||
207 | else if (verbose) | 262 | else if (verbose) |
208 | { | 263 | { |
209 | char calc_str[MD5_DIGEST_STRING_LENGTH]; | 264 | char calc_str[MD5_DIGEST_STRING_LENGTH]; |
210 | bin2hex(calcualted, MD5_DIGEST_SIZE, calc_str); | 265 | bin2hex (calcualted, MD5_DIGEST_SIZE, calc_str); |
211 | printf ("PASSED: %s check %u: calculated digest %s match expected digest.\n", | 266 | printf ( |
212 | test_name, check_num, calc_str); | 267 | "PASSED: %s check %u: calculated digest %s match expected digest.\n", |
213 | fflush (stdout); | 268 | test_name, check_num, calc_str); |
214 | } | 269 | fflush (stdout); |
270 | } | ||
215 | return failed ? 1 : 0; | 271 | return failed ? 1 : 0; |
216 | } | 272 | } |
217 | 273 | ||
@@ -222,106 +278,110 @@ check_result (const char *test_name, | |||
222 | 278 | ||
223 | /* Calculated MD5 as one pass for whole data */ | 279 | /* Calculated MD5 as one pass for whole data */ |
224 | static int | 280 | static int |
225 | test1_str(void) | 281 | test1_str (void) |
226 | { | 282 | { |
227 | unsigned int i; | 283 | unsigned int i; |
228 | int num_failed = 0; | 284 | int num_failed = 0; |
285 | |||
229 | for (i = 0; i < units1_num; i++) | 286 | for (i = 0; i < units1_num; i++) |
230 | { | 287 | { |
231 | struct MD5Context ctx; | 288 | struct MD5Context ctx; |
232 | uint8_t digest[MD5_DIGEST_SIZE]; | 289 | uint8_t digest[MD5_DIGEST_SIZE]; |
233 | 290 | ||
234 | MHD_MD5Init (&ctx); | 291 | MHD_MD5Init (&ctx); |
235 | MHD_MD5Update (&ctx, (const uint8_t*)data_units1[i].str_l.str, data_units1[i].str_l.len); | 292 | MHD_MD5Update (&ctx, (const uint8_t*) data_units1[i].str_l.str, |
236 | MHD_MD5Final (&ctx, digest); | 293 | data_units1[i].str_l.len); |
237 | num_failed += check_result (__FUNCTION__, i, digest, | 294 | MHD_MD5Final (&ctx, digest); |
238 | data_units1[i].digest); | 295 | num_failed += check_result (__FUNCTION__, i, digest, |
239 | } | 296 | data_units1[i].digest); |
297 | } | ||
240 | return num_failed; | 298 | return num_failed; |
241 | } | 299 | } |
242 | 300 | ||
243 | 301 | ||
244 | static int | 302 | static int |
245 | test1_bin(void) | 303 | test1_bin (void) |
246 | { | 304 | { |
247 | unsigned int i; | 305 | unsigned int i; |
248 | int num_failed = 0; | 306 | int num_failed = 0; |
249 | 307 | ||
250 | for (i = 0; i < units2_num; i++) | 308 | for (i = 0; i < units2_num; i++) |
251 | { | 309 | { |
252 | struct MD5Context ctx; | 310 | struct MD5Context ctx; |
253 | uint8_t digest[MD5_DIGEST_SIZE]; | 311 | uint8_t digest[MD5_DIGEST_SIZE]; |
254 | 312 | ||
255 | MHD_MD5Init (&ctx); | 313 | MHD_MD5Init (&ctx); |
256 | MHD_MD5Update (&ctx, data_units2[i].bin_l.bin, data_units2[i].bin_l.len); | 314 | MHD_MD5Update (&ctx, data_units2[i].bin_l.bin, data_units2[i].bin_l.len); |
257 | MHD_MD5Final (&ctx, digest); | 315 | MHD_MD5Final (&ctx, digest); |
258 | num_failed += check_result (__FUNCTION__, i, digest, | 316 | num_failed += check_result (__FUNCTION__, i, digest, |
259 | data_units2[i].digest); | 317 | data_units2[i].digest); |
260 | } | 318 | } |
261 | return num_failed; | 319 | return num_failed; |
262 | } | 320 | } |
263 | 321 | ||
264 | 322 | ||
265 | /* Calculated MD5 as two iterations for whole data */ | 323 | /* Calculated MD5 as two iterations for whole data */ |
266 | static int | 324 | static int |
267 | test2_str(void) | 325 | test2_str (void) |
268 | { | 326 | { |
269 | unsigned int i; | 327 | unsigned int i; |
270 | int num_failed = 0; | 328 | int num_failed = 0; |
271 | 329 | ||
272 | for (i = 0; i < units1_num; i++) | 330 | for (i = 0; i < units1_num; i++) |
273 | { | 331 | { |
274 | struct MD5Context ctx; | 332 | struct MD5Context ctx; |
275 | uint8_t digest[MD5_DIGEST_SIZE]; | 333 | uint8_t digest[MD5_DIGEST_SIZE]; |
276 | size_t part_s = data_units1[i].str_l.len / 4; | 334 | size_t part_s = data_units1[i].str_l.len / 4; |
277 | 335 | ||
278 | MHD_MD5Init (&ctx); | 336 | MHD_MD5Init (&ctx); |
279 | MHD_MD5Update (&ctx, (const uint8_t*)data_units1[i].str_l.str, part_s); | 337 | MHD_MD5Update (&ctx, (const uint8_t*) data_units1[i].str_l.str, part_s); |
280 | MHD_MD5Update (&ctx, (const uint8_t*)data_units1[i].str_l.str + part_s, data_units1[i].str_l.len - part_s); | 338 | MHD_MD5Update (&ctx, (const uint8_t*) data_units1[i].str_l.str + part_s, |
281 | MHD_MD5Final (&ctx, digest); | 339 | data_units1[i].str_l.len - part_s); |
282 | num_failed += check_result (__FUNCTION__, i, digest, | 340 | MHD_MD5Final (&ctx, digest); |
283 | data_units1[i].digest); | 341 | num_failed += check_result (__FUNCTION__, i, digest, |
284 | } | 342 | data_units1[i].digest); |
343 | } | ||
285 | return num_failed; | 344 | return num_failed; |
286 | } | 345 | } |
287 | 346 | ||
288 | 347 | ||
289 | static int | 348 | static int |
290 | test2_bin(void) | 349 | test2_bin (void) |
291 | { | 350 | { |
292 | unsigned int i; | 351 | unsigned int i; |
293 | int num_failed = 0; | 352 | int num_failed = 0; |
294 | 353 | ||
295 | for (i = 0; i < units2_num; i++) | 354 | for (i = 0; i < units2_num; i++) |
296 | { | 355 | { |
297 | struct MD5Context ctx; | 356 | struct MD5Context ctx; |
298 | uint8_t digest[MD5_DIGEST_SIZE]; | 357 | uint8_t digest[MD5_DIGEST_SIZE]; |
299 | size_t part_s = data_units2[i].bin_l.len * 2 / 3; | 358 | size_t part_s = data_units2[i].bin_l.len * 2 / 3; |
300 | 359 | ||
301 | MHD_MD5Init (&ctx); | 360 | MHD_MD5Init (&ctx); |
302 | MHD_MD5Update (&ctx, data_units2[i].bin_l.bin, part_s); | 361 | MHD_MD5Update (&ctx, data_units2[i].bin_l.bin, part_s); |
303 | MHD_MD5Update (&ctx, data_units2[i].bin_l.bin + part_s, data_units2[i].bin_l.len - part_s); | 362 | MHD_MD5Update (&ctx, data_units2[i].bin_l.bin + part_s, |
304 | MHD_MD5Final (&ctx, digest); | 363 | data_units2[i].bin_l.len - part_s); |
305 | num_failed += check_result (__FUNCTION__, i, digest, | 364 | MHD_MD5Final (&ctx, digest); |
306 | data_units2[i].digest); | 365 | num_failed += check_result (__FUNCTION__, i, digest, |
307 | } | 366 | data_units2[i].digest); |
367 | } | ||
308 | return num_failed; | 368 | return num_failed; |
309 | } | 369 | } |
310 | 370 | ||
311 | 371 | ||
312 | int | 372 | int |
313 | main(int argc, char * argv[]) | 373 | main (int argc, char *argv[]) |
314 | { | 374 | { |
315 | int num_failed = 0; | 375 | int num_failed = 0; |
316 | (void)has_in_name; /* Mute compiler warning. */ | 376 | (void) has_in_name; /* Mute compiler warning. */ |
317 | if (has_param(argc, argv, "-v") || has_param(argc, argv, "--verbose")) | 377 | if (has_param (argc, argv, "-v") || has_param (argc, argv, "--verbose")) |
318 | verbose = 1; | 378 | verbose = 1; |
319 | 379 | ||
320 | num_failed += test1_str(); | 380 | num_failed += test1_str (); |
321 | num_failed += test1_bin(); | 381 | num_failed += test1_bin (); |
322 | 382 | ||
323 | num_failed += test2_str(); | 383 | num_failed += test2_str (); |
324 | num_failed += test2_bin(); | 384 | num_failed += test2_bin (); |
325 | 385 | ||
326 | return num_failed ? 1 : 0; | 386 | return num_failed ? 1 : 0; |
327 | } | 387 | } |
diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c index 9135187c..dbfa847d 100644 --- a/src/microhttpd/test_upgrade.c +++ b/src/microhttpd/test_upgrade.c | |||
@@ -82,7 +82,7 @@ enum tls_tool use_tls_tool; | |||
82 | */ | 82 | */ |
83 | static pid_t | 83 | static pid_t |
84 | gnutlscli_connect (int *sock, | 84 | gnutlscli_connect (int *sock, |
85 | uint16_t port) | 85 | uint16_t port) |
86 | { | 86 | { |
87 | pid_t chld; | 87 | pid_t chld; |
88 | int sp[2]; | 88 | int sp[2]; |
@@ -95,11 +95,11 @@ gnutlscli_connect (int *sock, | |||
95 | return -1; | 95 | return -1; |
96 | chld = fork (); | 96 | chld = fork (); |
97 | if (0 != chld) | 97 | if (0 != chld) |
98 | { | 98 | { |
99 | *sock = sp[1]; | 99 | *sock = sp[1]; |
100 | MHD_socket_close_chk_ (sp[0]); | 100 | MHD_socket_close_chk_ (sp[0]); |
101 | return chld; | 101 | return chld; |
102 | } | 102 | } |
103 | MHD_socket_close_chk_ (sp[1]); | 103 | MHD_socket_close_chk_ (sp[1]); |
104 | (void) close (0); | 104 | (void) close (0); |
105 | (void) close (1); | 105 | (void) close (1); |
@@ -109,34 +109,34 @@ gnutlscli_connect (int *sock, | |||
109 | abort (); | 109 | abort (); |
110 | MHD_socket_close_chk_ (sp[0]); | 110 | MHD_socket_close_chk_ (sp[0]); |
111 | if (TLS_CLI_GNUTLS == use_tls_tool) | 111 | if (TLS_CLI_GNUTLS == use_tls_tool) |
112 | { | 112 | { |
113 | snprintf (destination, | 113 | snprintf (destination, |
114 | sizeof(destination), | 114 | sizeof(destination), |
115 | "%u", | 115 | "%u", |
116 | (unsigned int) port); | 116 | (unsigned int) port); |
117 | execlp ("gnutls-cli", | 117 | execlp ("gnutls-cli", |
118 | "gnutls-cli", | 118 | "gnutls-cli", |
119 | "--insecure", | 119 | "--insecure", |
120 | "-p", | 120 | "-p", |
121 | destination, | 121 | destination, |
122 | "127.0.0.1", | 122 | "127.0.0.1", |
123 | (char *) NULL); | 123 | (char *) NULL); |
124 | } | 124 | } |
125 | else if (TLS_CLI_OPENSSL == use_tls_tool) | 125 | else if (TLS_CLI_OPENSSL == use_tls_tool) |
126 | { | 126 | { |
127 | snprintf (destination, | 127 | snprintf (destination, |
128 | sizeof(destination), | 128 | sizeof(destination), |
129 | "127.0.0.1:%u", | 129 | "127.0.0.1:%u", |
130 | (unsigned int) port); | 130 | (unsigned int) port); |
131 | execlp ("openssl", | 131 | execlp ("openssl", |
132 | "openssl", | 132 | "openssl", |
133 | "s_client", | 133 | "s_client", |
134 | "-connect", | 134 | "-connect", |
135 | destination, | 135 | destination, |
136 | "-verify", | 136 | "-verify", |
137 | "1", | 137 | "1", |
138 | (char *) NULL); | 138 | (char *) NULL); |
139 | } | 139 | } |
140 | _exit (1); | 140 | _exit (1); |
141 | } | 141 | } |
142 | #endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ | 142 | #endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ |
@@ -192,16 +192,16 @@ struct wr_socket | |||
192 | * @return created socket on success, NULL otherwise | 192 | * @return created socket on success, NULL otherwise |
193 | */ | 193 | */ |
194 | static struct wr_socket * | 194 | static struct wr_socket * |
195 | wr_create_plain_sckt(void) | 195 | wr_create_plain_sckt (void) |
196 | { | 196 | { |
197 | struct wr_socket *s = malloc(sizeof(struct wr_socket)); | 197 | struct wr_socket *s = malloc (sizeof(struct wr_socket)); |
198 | if (NULL == s) | 198 | if (NULL == s) |
199 | return NULL; | 199 | return NULL; |
200 | s->t = wr_plain; | 200 | s->t = wr_plain; |
201 | s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); | 201 | s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); |
202 | if (MHD_INVALID_SOCKET != s->fd) | 202 | if (MHD_INVALID_SOCKET != s->fd) |
203 | return s; | 203 | return s; |
204 | free(s); | 204 | free (s); |
205 | return NULL; | 205 | return NULL; |
206 | } | 206 | } |
207 | 207 | ||
@@ -211,40 +211,44 @@ wr_create_plain_sckt(void) | |||
211 | * @return created socket on success, NULL otherwise | 211 | * @return created socket on success, NULL otherwise |
212 | */ | 212 | */ |
213 | static struct wr_socket * | 213 | static struct wr_socket * |
214 | wr_create_tls_sckt(void) | 214 | wr_create_tls_sckt (void) |
215 | { | 215 | { |
216 | #ifdef HTTPS_SUPPORT | 216 | #ifdef HTTPS_SUPPORT |
217 | struct wr_socket *s = malloc(sizeof(struct wr_socket)); | 217 | struct wr_socket *s = malloc (sizeof(struct wr_socket)); |
218 | if (NULL == s) | 218 | if (NULL == s) |
219 | return NULL; | 219 | return NULL; |
220 | s->t = wr_tls; | 220 | s->t = wr_tls; |
221 | s->tls_connected = 0; | 221 | s->tls_connected = 0; |
222 | s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); | 222 | s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); |
223 | if (MHD_INVALID_SOCKET != s->fd) | 223 | if (MHD_INVALID_SOCKET != s->fd) |
224 | { | ||
225 | if (GNUTLS_E_SUCCESS == gnutls_init (&(s->tls_s), GNUTLS_CLIENT)) | ||
224 | { | 226 | { |
225 | if (GNUTLS_E_SUCCESS == gnutls_init (&(s->tls_s), GNUTLS_CLIENT)) | 227 | if (GNUTLS_E_SUCCESS == gnutls_set_default_priority (s->tls_s)) |
228 | { | ||
229 | if (GNUTLS_E_SUCCESS == gnutls_certificate_allocate_credentials ( | ||
230 | &(s->tls_crd))) | ||
226 | { | 231 | { |
227 | if (GNUTLS_E_SUCCESS == gnutls_set_default_priority (s->tls_s)) | 232 | if (GNUTLS_E_SUCCESS == gnutls_credentials_set (s->tls_s, |
228 | { | 233 | GNUTLS_CRD_CERTIFICATE, |
229 | if (GNUTLS_E_SUCCESS == gnutls_certificate_allocate_credentials (&(s->tls_crd))) | 234 | s->tls_crd)) |
230 | { | 235 | { |
231 | if (GNUTLS_E_SUCCESS == gnutls_credentials_set (s->tls_s, GNUTLS_CRD_CERTIFICATE, s->tls_crd)) | 236 | #if GNUTLS_VERSION_NUMBER + 0 >= 0x030109 |
232 | { | 237 | gnutls_transport_set_int (s->tls_s, (int) (s->fd)); |
233 | #if GNUTLS_VERSION_NUMBER+0 >= 0x030109 | ||
234 | gnutls_transport_set_int (s->tls_s, (int)(s->fd)); | ||
235 | #else /* GnuTLS before 3.1.9 */ | 238 | #else /* GnuTLS before 3.1.9 */ |
236 | gnutls_transport_set_ptr (s->tls_s, (gnutls_transport_ptr_t)(intptr_t)(s->fd)); | 239 | gnutls_transport_set_ptr (s->tls_s, |
240 | (gnutls_transport_ptr_t) (intptr_t) (s->fd)); | ||
237 | #endif /* GnuTLS before 3.1.9 */ | 241 | #endif /* GnuTLS before 3.1.9 */ |
238 | return s; | 242 | return s; |
239 | } | 243 | } |
240 | gnutls_certificate_free_credentials (s->tls_crd); | 244 | gnutls_certificate_free_credentials (s->tls_crd); |
241 | } | ||
242 | } | ||
243 | gnutls_deinit (s->tls_s); | ||
244 | } | 245 | } |
245 | (void)MHD_socket_close_ (s->fd); | 246 | } |
247 | gnutls_deinit (s->tls_s); | ||
246 | } | 248 | } |
247 | free(s); | 249 | (void) MHD_socket_close_ (s->fd); |
250 | } | ||
251 | free (s); | ||
248 | #endif /* HTTPS_SUPPORT */ | 252 | #endif /* HTTPS_SUPPORT */ |
249 | return NULL; | 253 | return NULL; |
250 | } | 254 | } |
@@ -257,9 +261,9 @@ wr_create_tls_sckt(void) | |||
257 | * @return created socket on success, NULL otherwise | 261 | * @return created socket on success, NULL otherwise |
258 | */ | 262 | */ |
259 | static struct wr_socket * | 263 | static struct wr_socket * |
260 | wr_create_from_plain_sckt(MHD_socket plain_sk) | 264 | wr_create_from_plain_sckt (MHD_socket plain_sk) |
261 | { | 265 | { |
262 | struct wr_socket *s = malloc(sizeof(struct wr_socket)); | 266 | struct wr_socket *s = malloc (sizeof(struct wr_socket)); |
263 | 267 | ||
264 | if (NULL == s) | 268 | if (NULL == s) |
265 | return NULL; | 269 | return NULL; |
@@ -277,9 +281,9 @@ wr_create_from_plain_sckt(MHD_socket plain_sk) | |||
277 | * @return zero on success, -1 otherwise. | 281 | * @return zero on success, -1 otherwise. |
278 | */ | 282 | */ |
279 | static int | 283 | static int |
280 | wr_connect(struct wr_socket *s, | 284 | wr_connect (struct wr_socket *s, |
281 | const struct sockaddr *addr, | 285 | const struct sockaddr *addr, |
282 | int length) | 286 | int length) |
283 | { | 287 | { |
284 | if (0 != connect (s->fd, addr, length)) | 288 | if (0 != connect (s->fd, addr, length)) |
285 | return -1; | 289 | return -1; |
@@ -287,15 +291,15 @@ wr_connect(struct wr_socket *s, | |||
287 | return 0; | 291 | return 0; |
288 | #ifdef HTTPS_SUPPORT | 292 | #ifdef HTTPS_SUPPORT |
289 | if (wr_tls == s->t) | 293 | if (wr_tls == s->t) |
290 | { | 294 | { |
291 | /* Do not try handshake here as | 295 | /* Do not try handshake here as |
292 | * it require processing on MHD side and | 296 | * it require processing on MHD side and |
293 | * when testing with "external" polling, | 297 | * when testing with "external" polling, |
294 | * test will call MHD processing only | 298 | * test will call MHD processing only |
295 | * after return from wr_connect(). */ | 299 | * after return from wr_connect(). */ |
296 | s->tls_connected = 0; | 300 | s->tls_connected = 0; |
297 | return 0; | 301 | return 0; |
298 | } | 302 | } |
299 | #endif /* HTTPS_SUPPORT */ | 303 | #endif /* HTTPS_SUPPORT */ |
300 | return -1; | 304 | return -1; |
301 | } | 305 | } |
@@ -303,7 +307,7 @@ wr_connect(struct wr_socket *s, | |||
303 | #ifdef HTTPS_SUPPORT | 307 | #ifdef HTTPS_SUPPORT |
304 | /* Only to be called from wr_send() and wr_recv() ! */ | 308 | /* Only to be called from wr_send() and wr_recv() ! */ |
305 | static bool | 309 | static bool |
306 | wr_handshake(struct wr_socket *s) | 310 | wr_handshake (struct wr_socket *s) |
307 | { | 311 | { |
308 | int res = gnutls_handshake (s->tls_s); | 312 | int res = gnutls_handshake (s->tls_s); |
309 | if (GNUTLS_E_SUCCESS == res) | 313 | if (GNUTLS_E_SUCCESS == res) |
@@ -332,22 +336,22 @@ wr_send (struct wr_socket *s, | |||
332 | size_t len) | 336 | size_t len) |
333 | { | 337 | { |
334 | if (wr_plain == s->t) | 338 | if (wr_plain == s->t) |
335 | return MHD_send_(s->fd, buf, len); | 339 | return MHD_send_ (s->fd, buf, len); |
336 | #ifdef HTTPS_SUPPORT | 340 | #ifdef HTTPS_SUPPORT |
337 | if (wr_tls == s->t) | 341 | if (wr_tls == s->t) |
338 | { | 342 | { |
339 | ssize_t ret; | 343 | ssize_t ret; |
340 | if (!s->tls_connected && !wr_handshake (s)) | 344 | if (! s->tls_connected && ! wr_handshake (s)) |
341 | return -1; | 345 | return -1; |
342 | 346 | ||
343 | ret = gnutls_record_send (s->tls_s, buf, len); | 347 | ret = gnutls_record_send (s->tls_s, buf, len); |
344 | if (ret > 0) | 348 | if (ret > 0) |
345 | return ret; | 349 | return ret; |
346 | if (GNUTLS_E_AGAIN == ret) | 350 | if (GNUTLS_E_AGAIN == ret) |
347 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); | 351 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); |
348 | else | 352 | else |
349 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ | 353 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ |
350 | } | 354 | } |
351 | #endif /* HTTPS_SUPPORT */ | 355 | #endif /* HTTPS_SUPPORT */ |
352 | return -1; | 356 | return -1; |
353 | } | 357 | } |
@@ -371,19 +375,19 @@ wr_recv (struct wr_socket *s, | |||
371 | return MHD_recv_ (s->fd, buf, len); | 375 | return MHD_recv_ (s->fd, buf, len); |
372 | #ifdef HTTPS_SUPPORT | 376 | #ifdef HTTPS_SUPPORT |
373 | if (wr_tls == s->t) | 377 | if (wr_tls == s->t) |
374 | { | 378 | { |
375 | ssize_t ret; | 379 | ssize_t ret; |
376 | if (!s->tls_connected && !wr_handshake (s)) | 380 | if (! s->tls_connected && ! wr_handshake (s)) |
377 | return -1; | 381 | return -1; |
378 | 382 | ||
379 | ret = gnutls_record_recv (s->tls_s, buf, len); | 383 | ret = gnutls_record_recv (s->tls_s, buf, len); |
380 | if (ret > 0) | 384 | if (ret > 0) |
381 | return ret; | 385 | return ret; |
382 | if (GNUTLS_E_AGAIN == ret) | 386 | if (GNUTLS_E_AGAIN == ret) |
383 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); | 387 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); |
384 | else | 388 | else |
385 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ | 389 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ |
386 | } | 390 | } |
387 | #endif /* HTTPS_SUPPORT */ | 391 | #endif /* HTTPS_SUPPORT */ |
388 | return -1; | 392 | return -1; |
389 | } | 393 | } |
@@ -397,13 +401,13 @@ wr_recv (struct wr_socket *s, | |||
397 | static int | 401 | static int |
398 | wr_close (struct wr_socket *s) | 402 | wr_close (struct wr_socket *s) |
399 | { | 403 | { |
400 | int ret = (MHD_socket_close_(s->fd)) ? 0 : -1; | 404 | int ret = (MHD_socket_close_ (s->fd)) ? 0 : -1; |
401 | #ifdef HTTPS_SUPPORT | 405 | #ifdef HTTPS_SUPPORT |
402 | if (wr_tls == s->t) | 406 | if (wr_tls == s->t) |
403 | { | 407 | { |
404 | gnutls_deinit (s->tls_s); | 408 | gnutls_deinit (s->tls_s); |
405 | gnutls_certificate_free_credentials (s->tls_crd); | 409 | gnutls_certificate_free_credentials (s->tls_crd); |
406 | } | 410 | } |
407 | #endif /* HTTPS_SUPPORT */ | 411 | #endif /* HTTPS_SUPPORT */ |
408 | free (s); | 412 | free (s); |
409 | return ret; | 413 | return ret; |
@@ -447,7 +451,7 @@ notify_completed_cb (void *cls, | |||
447 | void **con_cls, | 451 | void **con_cls, |
448 | enum MHD_RequestTerminationCode toe) | 452 | enum MHD_RequestTerminationCode toe) |
449 | { | 453 | { |
450 | pthread_t* ppth = *con_cls; | 454 | pthread_t*ppth = *con_cls; |
451 | 455 | ||
452 | (void) cls; | 456 | (void) cls; |
453 | (void) connection; /* Unused. Silent compiler warning. */ | 457 | (void) connection; /* Unused. Silent compiler warning. */ |
@@ -455,7 +459,7 @@ notify_completed_cb (void *cls, | |||
455 | (toe != MHD_REQUEST_TERMINATED_CLIENT_ABORT) && | 459 | (toe != MHD_REQUEST_TERMINATED_CLIENT_ABORT) && |
456 | (toe != MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN) ) | 460 | (toe != MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN) ) |
457 | abort (); | 461 | abort (); |
458 | if (! pthread_equal (**((pthread_t**)con_cls), | 462 | if (! pthread_equal (**((pthread_t**) con_cls), |
459 | pthread_self ())) | 463 | pthread_self ())) |
460 | abort (); | 464 | abort (); |
461 | if (NULL != ppth) | 465 | if (NULL != ppth) |
@@ -486,7 +490,7 @@ log_cb (void *cls, | |||
486 | abort (); | 490 | abort (); |
487 | ppth = malloc (sizeof (pthread_t)); | 491 | ppth = malloc (sizeof (pthread_t)); |
488 | if (NULL == ppth) | 492 | if (NULL == ppth) |
489 | abort(); | 493 | abort (); |
490 | *ppth = pthread_self (); | 494 | *ppth = pthread_self (); |
491 | return (void *) ppth; | 495 | return (void *) ppth; |
492 | } | 496 | } |
@@ -578,20 +582,20 @@ send_all (struct wr_socket *sock, | |||
578 | 582 | ||
579 | make_blocking (wr_fd (sock)); | 583 | make_blocking (wr_fd (sock)); |
580 | for (off = 0; off < len; off += ret) | 584 | for (off = 0; off < len; off += ret) |
585 | { | ||
586 | ret = wr_send (sock, | ||
587 | &text[off], | ||
588 | len - off); | ||
589 | if (0 > ret) | ||
581 | { | 590 | { |
582 | ret = wr_send (sock, | 591 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) |
583 | &text[off], | 592 | { |
584 | len - off); | 593 | ret = 0; |
585 | if (0 > ret) | 594 | continue; |
586 | { | 595 | } |
587 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) | 596 | abort (); |
588 | { | ||
589 | ret = 0; | ||
590 | continue; | ||
591 | } | ||
592 | abort (); | ||
593 | } | ||
594 | } | 597 | } |
598 | } | ||
595 | } | 599 | } |
596 | 600 | ||
597 | 601 | ||
@@ -611,36 +615,36 @@ recv_hdr (struct wr_socket *sock) | |||
611 | next = '\r'; | 615 | next = '\r'; |
612 | i = 0; | 616 | i = 0; |
613 | while (i < 4) | 617 | while (i < 4) |
618 | { | ||
619 | ret = wr_recv (sock, | ||
620 | &c, | ||
621 | 1); | ||
622 | if (0 > ret) | ||
614 | { | 623 | { |
615 | ret = wr_recv (sock, | 624 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) |
616 | &c, | ||
617 | 1); | ||
618 | if (0 > ret) | ||
619 | { | ||
620 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) | ||
621 | continue; | ||
622 | abort (); | ||
623 | } | ||
624 | if (0 == ret) | ||
625 | continue; | 625 | continue; |
626 | if (c == next) | 626 | abort (); |
627 | { | ||
628 | i++; | ||
629 | if (next == '\r') | ||
630 | next = '\n'; | ||
631 | else | ||
632 | next = '\r'; | ||
633 | continue; | ||
634 | } | ||
635 | if (c == '\r') | ||
636 | { | ||
637 | i = 1; | ||
638 | next = '\n'; | ||
639 | continue; | ||
640 | } | ||
641 | i = 0; | ||
642 | next = '\r'; | ||
643 | } | 627 | } |
628 | if (0 == ret) | ||
629 | continue; | ||
630 | if (c == next) | ||
631 | { | ||
632 | i++; | ||
633 | if (next == '\r') | ||
634 | next = '\n'; | ||
635 | else | ||
636 | next = '\r'; | ||
637 | continue; | ||
638 | } | ||
639 | if (c == '\r') | ||
640 | { | ||
641 | i = 1; | ||
642 | next = '\n'; | ||
643 | continue; | ||
644 | } | ||
645 | i = 0; | ||
646 | next = '\r'; | ||
647 | } | ||
644 | } | 648 | } |
645 | 649 | ||
646 | 650 | ||
@@ -655,22 +659,22 @@ recv_all (struct wr_socket *sock, | |||
655 | 659 | ||
656 | make_blocking (wr_fd (sock)); | 660 | make_blocking (wr_fd (sock)); |
657 | for (off = 0; off < len; off += ret) | 661 | for (off = 0; off < len; off += ret) |
662 | { | ||
663 | ret = wr_recv (sock, | ||
664 | &buf[off], | ||
665 | len - off); | ||
666 | if (0 > ret) | ||
658 | { | 667 | { |
659 | ret = wr_recv (sock, | 668 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) |
660 | &buf[off], | 669 | { |
661 | len - off); | 670 | ret = 0; |
662 | if (0 > ret) | 671 | continue; |
663 | { | 672 | } |
664 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) | 673 | abort (); |
665 | { | ||
666 | ret = 0; | ||
667 | continue; | ||
668 | } | ||
669 | abort (); | ||
670 | } | ||
671 | } | 674 | } |
675 | } | ||
672 | if (0 != strncmp (text, buf, len)) | 676 | if (0 != strncmp (text, buf, len)) |
673 | abort(); | 677 | abort (); |
674 | } | 678 | } |
675 | 679 | ||
676 | 680 | ||
@@ -856,7 +860,7 @@ ahc_upgrade (void *cls, | |||
856 | 860 | ||
857 | if (NULL == *con_cls) | 861 | if (NULL == *con_cls) |
858 | abort (); | 862 | abort (); |
859 | if (! pthread_equal (**((pthread_t**)con_cls), pthread_self ())) | 863 | if (! pthread_equal (**((pthread_t**) con_cls), pthread_self ())) |
860 | abort (); | 864 | abort (); |
861 | resp = MHD_create_response_for_upgrade (&upgrade_cb, | 865 | resp = MHD_create_response_for_upgrade (&upgrade_cb, |
862 | NULL); | 866 | NULL); |
@@ -887,37 +891,37 @@ run_mhd_select_loop (struct MHD_Daemon *daemon) | |||
887 | struct timeval tv; | 891 | struct timeval tv; |
888 | 892 | ||
889 | while (! done) | 893 | while (! done) |
890 | { | 894 | { |
891 | FD_ZERO (&rs); | 895 | FD_ZERO (&rs); |
892 | FD_ZERO (&ws); | 896 | FD_ZERO (&ws); |
893 | FD_ZERO (&es); | 897 | FD_ZERO (&es); |
894 | max_fd = -1; | 898 | max_fd = -1; |
899 | to = 1000; | ||
900 | |||
901 | if (MHD_YES != | ||
902 | MHD_get_fdset (daemon, | ||
903 | &rs, | ||
904 | &ws, | ||
905 | &es, | ||
906 | &max_fd)) | ||
907 | abort (); | ||
908 | (void) MHD_get_timeout (daemon, | ||
909 | &to); | ||
910 | if (1000 < to) | ||
895 | to = 1000; | 911 | to = 1000; |
896 | 912 | tv.tv_sec = to / 1000; | |
897 | if (MHD_YES != | 913 | tv.tv_usec = 1000 * (to % 1000); |
898 | MHD_get_fdset (daemon, | 914 | if (0 > MHD_SYS_select_ (max_fd + 1, |
915 | &rs, | ||
916 | &ws, | ||
917 | &es, | ||
918 | &tv)) | ||
919 | abort (); | ||
920 | MHD_run_from_select (daemon, | ||
899 | &rs, | 921 | &rs, |
900 | &ws, | 922 | &ws, |
901 | &es, | 923 | &es); |
902 | &max_fd)) | 924 | } |
903 | abort (); | ||
904 | (void) MHD_get_timeout (daemon, | ||
905 | &to); | ||
906 | if (1000 < to) | ||
907 | to = 1000; | ||
908 | tv.tv_sec = to / 1000; | ||
909 | tv.tv_usec = 1000 * (to % 1000); | ||
910 | if (0 > MHD_SYS_select_ (max_fd + 1, | ||
911 | &rs, | ||
912 | &ws, | ||
913 | &es, | ||
914 | &tv)) | ||
915 | abort (); | ||
916 | MHD_run_from_select (daemon, | ||
917 | &rs, | ||
918 | &ws, | ||
919 | &es); | ||
920 | } | ||
921 | } | 925 | } |
922 | 926 | ||
923 | #ifdef HAVE_POLL | 927 | #ifdef HAVE_POLL |
@@ -930,7 +934,7 @@ run_mhd_select_loop (struct MHD_Daemon *daemon) | |||
930 | static void | 934 | static void |
931 | run_mhd_poll_loop (struct MHD_Daemon *daemon) | 935 | run_mhd_poll_loop (struct MHD_Daemon *daemon) |
932 | { | 936 | { |
933 | (void)daemon; /* Unused. Silent compiler warning. */ | 937 | (void) daemon; /* Unused. Silent compiler warning. */ |
934 | abort (); /* currently not implementable with existing MHD API */ | 938 | abort (); /* currently not implementable with existing MHD API */ |
935 | } | 939 | } |
936 | #endif /* HAVE_POLL */ | 940 | #endif /* HAVE_POLL */ |
@@ -956,28 +960,28 @@ run_mhd_epoll_loop (struct MHD_Daemon *daemon) | |||
956 | MHD_DAEMON_INFO_EPOLL_FD); | 960 | MHD_DAEMON_INFO_EPOLL_FD); |
957 | ep = di->listen_fd; | 961 | ep = di->listen_fd; |
958 | while (! done) | 962 | while (! done) |
959 | { | 963 | { |
960 | FD_ZERO (&rs); | 964 | FD_ZERO (&rs); |
961 | to = 1000; | 965 | to = 1000; |
962 | 966 | ||
963 | FD_SET (ep, &rs); | 967 | FD_SET (ep, &rs); |
964 | (void) MHD_get_timeout (daemon, | 968 | (void) MHD_get_timeout (daemon, |
965 | &to); | 969 | &to); |
966 | if (1000 < to) | 970 | if (1000 < to) |
967 | to = 1000; | 971 | to = 1000; |
968 | tv.tv_sec = to / 1000; | 972 | tv.tv_sec = to / 1000; |
969 | tv.tv_usec = 1000 * (to % 1000); | 973 | tv.tv_usec = 1000 * (to % 1000); |
970 | ret = select (ep + 1, | 974 | ret = select (ep + 1, |
971 | &rs, | 975 | &rs, |
972 | NULL, | 976 | NULL, |
973 | NULL, | 977 | NULL, |
974 | &tv); | 978 | &tv); |
975 | if ( (-1 == ret) && | 979 | if ( (-1 == ret) && |
976 | (EAGAIN != errno) && | 980 | (EAGAIN != errno) && |
977 | (EINTR != errno) ) | 981 | (EINTR != errno) ) |
978 | abort (); | 982 | abort (); |
979 | MHD_run (daemon); | 983 | MHD_run (daemon); |
980 | } | 984 | } |
981 | } | 985 | } |
982 | #endif /* EPOLL_SUPPORT */ | 986 | #endif /* EPOLL_SUPPORT */ |
983 | 987 | ||
@@ -1030,25 +1034,32 @@ test_upgrade (int flags, | |||
1030 | 1034 | ||
1031 | if (! test_tls) | 1035 | if (! test_tls) |
1032 | d = MHD_start_daemon (flags | MHD_USE_ERROR_LOG | MHD_ALLOW_UPGRADE, | 1036 | d = MHD_start_daemon (flags | MHD_USE_ERROR_LOG | MHD_ALLOW_UPGRADE, |
1033 | MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT) ? | 1037 | MHD_is_feature_supported ( |
1034 | 0 : 1090, | 1038 | MHD_FEATURE_AUTODETECT_BIND_PORT) ? |
1035 | NULL, NULL, | 1039 | 0 : 1090, |
1036 | &ahc_upgrade, NULL, | 1040 | NULL, NULL, |
1037 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | 1041 | &ahc_upgrade, NULL, |
1038 | MHD_OPTION_NOTIFY_COMPLETED, ¬ify_completed_cb, NULL, | 1042 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, |
1039 | MHD_OPTION_NOTIFY_CONNECTION, ¬ify_connection_cb, NULL, | 1043 | MHD_OPTION_NOTIFY_COMPLETED, ¬ify_completed_cb, |
1040 | MHD_OPTION_THREAD_POOL_SIZE, pool, | 1044 | NULL, |
1041 | MHD_OPTION_END); | 1045 | MHD_OPTION_NOTIFY_CONNECTION, ¬ify_connection_cb, |
1046 | NULL, | ||
1047 | MHD_OPTION_THREAD_POOL_SIZE, pool, | ||
1048 | MHD_OPTION_END); | ||
1042 | #ifdef HTTPS_SUPPORT | 1049 | #ifdef HTTPS_SUPPORT |
1043 | else | 1050 | else |
1044 | d = MHD_start_daemon (flags | MHD_USE_ERROR_LOG | MHD_ALLOW_UPGRADE | MHD_USE_TLS, | 1051 | d = MHD_start_daemon (flags | MHD_USE_ERROR_LOG | MHD_ALLOW_UPGRADE |
1045 | MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT) ? | 1052 | | MHD_USE_TLS, |
1046 | 0 : 1090, | 1053 | MHD_is_feature_supported ( |
1054 | MHD_FEATURE_AUTODETECT_BIND_PORT) ? | ||
1055 | 0 : 1090, | ||
1047 | NULL, NULL, | 1056 | NULL, NULL, |
1048 | &ahc_upgrade, NULL, | 1057 | &ahc_upgrade, NULL, |
1049 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | 1058 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, |
1050 | MHD_OPTION_NOTIFY_COMPLETED, ¬ify_completed_cb, NULL, | 1059 | MHD_OPTION_NOTIFY_COMPLETED, ¬ify_completed_cb, |
1051 | MHD_OPTION_NOTIFY_CONNECTION, ¬ify_connection_cb, NULL, | 1060 | NULL, |
1061 | MHD_OPTION_NOTIFY_CONNECTION, ¬ify_connection_cb, | ||
1062 | NULL, | ||
1052 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, | 1063 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, |
1053 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, | 1064 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, |
1054 | MHD_OPTION_THREAD_POOL_SIZE, pool, | 1065 | MHD_OPTION_THREAD_POOL_SIZE, pool, |
@@ -1065,43 +1076,43 @@ test_upgrade (int flags, | |||
1065 | if ( (NULL == dinfo) || | 1076 | if ( (NULL == dinfo) || |
1066 | (0 == dinfo->port) ) | 1077 | (0 == dinfo->port) ) |
1067 | abort (); | 1078 | abort (); |
1068 | if (!test_tls || TLS_LIB_GNUTLS == use_tls_tool) | 1079 | if (! test_tls ||(TLS_LIB_GNUTLS == use_tls_tool)) |
1069 | { | 1080 | { |
1070 | sock = test_tls ? wr_create_tls_sckt () : wr_create_plain_sckt (); | 1081 | sock = test_tls ? wr_create_tls_sckt () : wr_create_plain_sckt (); |
1071 | if (NULL == sock) | 1082 | if (NULL == sock) |
1072 | abort (); | 1083 | abort (); |
1073 | sa.sin_family = AF_INET; | 1084 | sa.sin_family = AF_INET; |
1074 | sa.sin_port = htons (dinfo->port); | 1085 | sa.sin_port = htons (dinfo->port); |
1075 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | 1086 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
1076 | if (0 != wr_connect (sock, | 1087 | if (0 != wr_connect (sock, |
1077 | (struct sockaddr *) &sa, | 1088 | (struct sockaddr *) &sa, |
1078 | sizeof (sa))) | 1089 | sizeof (sa))) |
1079 | abort (); | 1090 | abort (); |
1080 | } | 1091 | } |
1081 | else | 1092 | else |
1082 | { | 1093 | { |
1083 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) | 1094 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) |
1084 | MHD_socket tls_fork_sock; | 1095 | MHD_socket tls_fork_sock; |
1085 | uint16_t port; | 1096 | uint16_t port; |
1086 | 1097 | ||
1087 | /* make address sanitizer happy */ | 1098 | /* make address sanitizer happy */ |
1088 | memcpy (&port, | 1099 | memcpy (&port, |
1089 | dinfo /* ->port */, | 1100 | dinfo /* ->port */, |
1090 | sizeof (port)); | 1101 | sizeof (port)); |
1091 | if (-1 == (pid = gnutlscli_connect (&tls_fork_sock, | 1102 | if (-1 == (pid = gnutlscli_connect (&tls_fork_sock, |
1092 | port))) | 1103 | port))) |
1093 | { | 1104 | { |
1094 | MHD_stop_daemon (d); | 1105 | MHD_stop_daemon (d); |
1095 | return 4; | 1106 | return 4; |
1096 | } | 1107 | } |
1097 | 1108 | ||
1098 | sock = wr_create_from_plain_sckt (tls_fork_sock); | 1109 | sock = wr_create_from_plain_sckt (tls_fork_sock); |
1099 | if (NULL == sock) | 1110 | if (NULL == sock) |
1100 | abort (); | ||
1101 | #else /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */ | ||
1102 | abort (); | 1111 | abort (); |
1112 | #else /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */ | ||
1113 | abort (); | ||
1103 | #endif /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */ | 1114 | #endif /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */ |
1104 | } | 1115 | } |
1105 | 1116 | ||
1106 | if (0 != pthread_create (&pt_client, | 1117 | if (0 != pthread_create (&pt_client, |
1107 | NULL, | 1118 | NULL, |
@@ -1109,21 +1120,21 @@ test_upgrade (int flags, | |||
1109 | sock)) | 1120 | sock)) |
1110 | abort (); | 1121 | abort (); |
1111 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) | 1122 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) |
1112 | { | 1123 | { |
1113 | enum MHD_FLAG flags; | 1124 | enum MHD_FLAG flags; |
1114 | 1125 | ||
1115 | /* make address sanitizer happy */ | 1126 | /* make address sanitizer happy */ |
1116 | memcpy (&flags, | 1127 | memcpy (&flags, |
1117 | real_flags /* ->flags */, | 1128 | real_flags /* ->flags */, |
1118 | sizeof (flags)); | 1129 | sizeof (flags)); |
1119 | run_mhd_loop (d, flags); | 1130 | run_mhd_loop (d, flags); |
1120 | } | 1131 | } |
1121 | pthread_join (pt_client, | 1132 | pthread_join (pt_client, |
1122 | NULL); | 1133 | NULL); |
1123 | pthread_join (pt, | 1134 | pthread_join (pt, |
1124 | NULL); | 1135 | NULL); |
1125 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) | 1136 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) |
1126 | if (test_tls && TLS_LIB_GNUTLS != use_tls_tool) | 1137 | if (test_tls &&(TLS_LIB_GNUTLS != use_tls_tool)) |
1127 | waitpid (pid, NULL, 0); | 1138 | waitpid (pid, NULL, 0); |
1128 | #endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ | 1139 | #endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ |
1129 | MHD_stop_daemon (d); | 1140 | MHD_stop_daemon (d); |
@@ -1139,56 +1150,56 @@ main (int argc, | |||
1139 | int res; | 1150 | int res; |
1140 | 1151 | ||
1141 | use_tls_tool = TLS_CLI_NO_TOOL; | 1152 | use_tls_tool = TLS_CLI_NO_TOOL; |
1142 | test_tls = has_in_name(argv[0], "_tls"); | 1153 | test_tls = has_in_name (argv[0], "_tls"); |
1143 | 1154 | ||
1144 | verbose = 1; | 1155 | verbose = 1; |
1145 | if (has_param(argc, argv, "-q") || | 1156 | if (has_param (argc, argv, "-q") || |
1146 | has_param(argc, argv, "--quiet")) | 1157 | has_param (argc, argv, "--quiet")) |
1147 | verbose = 0; | 1158 | verbose = 0; |
1148 | 1159 | ||
1149 | if (test_tls) | 1160 | if (test_tls) |
1150 | { | 1161 | { |
1151 | #ifdef HTTPS_SUPPORT | 1162 | #ifdef HTTPS_SUPPORT |
1152 | if (has_param(argc, argv, "--use-gnutls-cli")) | 1163 | if (has_param (argc, argv, "--use-gnutls-cli")) |
1153 | use_tls_tool = TLS_CLI_GNUTLS; | 1164 | use_tls_tool = TLS_CLI_GNUTLS; |
1154 | else if (has_param(argc, argv, "--use-openssl")) | 1165 | else if (has_param (argc, argv, "--use-openssl")) |
1155 | use_tls_tool = TLS_CLI_OPENSSL; | 1166 | use_tls_tool = TLS_CLI_OPENSSL; |
1156 | else if (has_param(argc, argv, "--use-gnutls-lib")) | 1167 | else if (has_param (argc, argv, "--use-gnutls-lib")) |
1157 | use_tls_tool = TLS_LIB_GNUTLS; | 1168 | use_tls_tool = TLS_LIB_GNUTLS; |
1158 | #if defined(HAVE_FORK) && defined(HAVE_WAITPID) | 1169 | #if defined(HAVE_FORK) && defined(HAVE_WAITPID) |
1159 | else if (0 == system ("gnutls-cli --version 1> /dev/null 2> /dev/null")) | 1170 | else if (0 == system ("gnutls-cli --version 1> /dev/null 2> /dev/null")) |
1160 | use_tls_tool = TLS_CLI_GNUTLS; | 1171 | use_tls_tool = TLS_CLI_GNUTLS; |
1161 | else if (0 == system ("openssl version 1> /dev/null 2> /dev/null")) | 1172 | else if (0 == system ("openssl version 1> /dev/null 2> /dev/null")) |
1162 | use_tls_tool = TLS_CLI_OPENSSL; | 1173 | use_tls_tool = TLS_CLI_OPENSSL; |
1163 | #endif /* HAVE_FORK && HAVE_WAITPID */ | 1174 | #endif /* HAVE_FORK && HAVE_WAITPID */ |
1164 | else | 1175 | else |
1165 | use_tls_tool = TLS_LIB_GNUTLS; /* Should be available as MHD use it. */ | 1176 | use_tls_tool = TLS_LIB_GNUTLS; /* Should be available as MHD use it. */ |
1166 | if (verbose) | 1177 | if (verbose) |
1167 | { | 1178 | { |
1168 | switch (use_tls_tool) | 1179 | switch (use_tls_tool) |
1169 | { | 1180 | { |
1170 | case TLS_CLI_GNUTLS: | 1181 | case TLS_CLI_GNUTLS: |
1171 | printf ("GnuTLS-CLI will be used for testing.\n"); | 1182 | printf ("GnuTLS-CLI will be used for testing.\n"); |
1172 | break; | 1183 | break; |
1173 | case TLS_CLI_OPENSSL: | 1184 | case TLS_CLI_OPENSSL: |
1174 | printf ("Command line version of OpenSSL will be used for testing.\n"); | 1185 | printf ("Command line version of OpenSSL will be used for testing.\n"); |
1175 | break; | 1186 | break; |
1176 | case TLS_LIB_GNUTLS: | 1187 | case TLS_LIB_GNUTLS: |
1177 | printf ("GnuTLS library will be used for testing.\n"); | 1188 | printf ("GnuTLS library will be used for testing.\n"); |
1178 | break; | 1189 | break; |
1179 | default: | 1190 | default: |
1180 | abort (); | ||
1181 | } | ||
1182 | } | ||
1183 | if ( (TLS_LIB_GNUTLS == use_tls_tool) && | ||
1184 | (GNUTLS_E_SUCCESS != gnutls_global_init()) ) | ||
1185 | abort (); | 1191 | abort (); |
1192 | } | ||
1193 | } | ||
1194 | if ( (TLS_LIB_GNUTLS == use_tls_tool) && | ||
1195 | (GNUTLS_E_SUCCESS != gnutls_global_init ()) ) | ||
1196 | abort (); | ||
1186 | 1197 | ||
1187 | #else /* ! HTTPS_SUPPORT */ | 1198 | #else /* ! HTTPS_SUPPORT */ |
1188 | fprintf (stderr, "HTTPS support was disabled by configure.\n"); | 1199 | fprintf (stderr, "HTTPS support was disabled by configure.\n"); |
1189 | return 77; | 1200 | return 77; |
1190 | #endif /* ! HTTPS_SUPPORT */ | 1201 | #endif /* ! HTTPS_SUPPORT */ |
1191 | } | 1202 | } |
1192 | 1203 | ||
1193 | /* run tests */ | 1204 | /* run tests */ |
1194 | if (verbose) | 1205 | if (verbose) |
@@ -1229,7 +1240,8 @@ main (int argc, | |||
1229 | #endif | 1240 | #endif |
1230 | 1241 | ||
1231 | /* Test thread-per-connection */ | 1242 | /* Test thread-per-connection */ |
1232 | res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION, | 1243 | res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD |
1244 | | MHD_USE_THREAD_PER_CONNECTION, | ||
1233 | 0); | 1245 | 0); |
1234 | error_count += res; | 1246 | error_count += res; |
1235 | if (res) | 1247 | if (res) |
@@ -1239,7 +1251,8 @@ main (int argc, | |||
1239 | else if (verbose) | 1251 | else if (verbose) |
1240 | printf ("PASSED: Upgrade with thread per connection.\n"); | 1252 | printf ("PASSED: Upgrade with thread per connection.\n"); |
1241 | 1253 | ||
1242 | res = test_upgrade (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION, | 1254 | res = test_upgrade (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD |
1255 | | MHD_USE_THREAD_PER_CONNECTION, | ||
1243 | 0); | 1256 | 0); |
1244 | error_count += res; | 1257 | error_count += res; |
1245 | if (res) | 1258 | if (res) |
@@ -1249,7 +1262,8 @@ main (int argc, | |||
1249 | else if (verbose) | 1262 | else if (verbose) |
1250 | printf ("PASSED: Upgrade with thread per connection and 'auto'.\n"); | 1263 | printf ("PASSED: Upgrade with thread per connection and 'auto'.\n"); |
1251 | #ifdef HAVE_POLL | 1264 | #ifdef HAVE_POLL |
1252 | res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_POLL, | 1265 | res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD |
1266 | | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_POLL, | ||
1253 | 0); | 1267 | 0); |
1254 | error_count += res; | 1268 | error_count += res; |
1255 | if (res) | 1269 | if (res) |
@@ -1341,7 +1355,7 @@ main (int argc, | |||
1341 | error_count); | 1355 | error_count); |
1342 | #ifdef HTTPS_SUPPORT | 1356 | #ifdef HTTPS_SUPPORT |
1343 | if (test_tls && (TLS_LIB_GNUTLS == use_tls_tool)) | 1357 | if (test_tls && (TLS_LIB_GNUTLS == use_tls_tool)) |
1344 | gnutls_global_deinit(); | 1358 | gnutls_global_deinit (); |
1345 | #endif /* HTTPS_SUPPORT */ | 1359 | #endif /* HTTPS_SUPPORT */ |
1346 | return error_count != 0; /* 0 == pass */ | 1360 | return error_count != 0; /* 0 == pass */ |
1347 | } | 1361 | } |