diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-06-22 20:57:50 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-06-22 20:58:43 +0300 |
commit | 6ccaa5da57dbfb74e6131ce0ff0165522ef501d6 (patch) | |
tree | fec3641b6b1bca65d4d91d1a4fe42ec11885ef0b /src/microhttpd/digestauth.c | |
parent | 5ba4b7709fc13ee3bbcb65083afa456be6fe3c7e (diff) | |
download | libmicrohttpd-6ccaa5da57dbfb74e6131ce0ff0165522ef501d6.tar.gz libmicrohttpd-6ccaa5da57dbfb74e6131ce0ff0165522ef501d6.zip |
MHD_parse_arguments_(): refactored, allow cls for the callback
Diffstat (limited to 'src/microhttpd/digestauth.c')
-rw-r--r-- | src/microhttpd/digestauth.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c index 890fc129..114f72b8 100644 --- a/src/microhttpd/digestauth.c +++ b/src/microhttpd/digestauth.c | |||
@@ -1185,11 +1185,17 @@ calculate_add_nonce_with_retry (struct MHD_Connection *const connection, | |||
1185 | } | 1185 | } |
1186 | 1186 | ||
1187 | 1187 | ||
1188 | struct test_header_param | ||
1189 | { | ||
1190 | struct MHD_Connection *connection; | ||
1191 | unsigned int num_headers; | ||
1192 | }; | ||
1193 | |||
1188 | /** | 1194 | /** |
1189 | * Test if the given key-value pair is in the headers for the | 1195 | * Test if the given key-value pair is in the headers for the |
1190 | * given connection. | 1196 | * given connection. |
1191 | * | 1197 | * |
1192 | * @param connection the connection | 1198 | * @param cls the test context |
1193 | * @param key the key | 1199 | * @param key the key |
1194 | * @param key_size number of bytes in @a key | 1200 | * @param key_size number of bytes in @a key |
1195 | * @param value the value, can be NULL | 1201 | * @param value the value, can be NULL |
@@ -1199,15 +1205,18 @@ calculate_add_nonce_with_retry (struct MHD_Connection *const connection, | |||
1199 | * #MHD_NO if not | 1205 | * #MHD_NO if not |
1200 | */ | 1206 | */ |
1201 | static enum MHD_Result | 1207 | static enum MHD_Result |
1202 | test_header (struct MHD_Connection *connection, | 1208 | test_header (void *cls, |
1203 | const char *key, | 1209 | const char *key, |
1204 | size_t key_size, | 1210 | size_t key_size, |
1205 | const char *value, | 1211 | const char *value, |
1206 | size_t value_size, | 1212 | size_t value_size, |
1207 | enum MHD_ValueKind kind) | 1213 | enum MHD_ValueKind kind) |
1208 | { | 1214 | { |
1215 | struct test_header_param *const param = (struct test_header_param *) cls; | ||
1216 | struct MHD_Connection *connection = param->connection; | ||
1209 | struct MHD_HTTP_Req_Header *pos; | 1217 | struct MHD_HTTP_Req_Header *pos; |
1210 | 1218 | ||
1219 | param->num_headers++; | ||
1211 | for (pos = connection->headers_received; NULL != pos; pos = pos->next) | 1220 | for (pos = connection->headers_received; NULL != pos; pos = pos->next) |
1212 | { | 1221 | { |
1213 | if (kind != pos->kind) | 1222 | if (kind != pos->kind) |
@@ -1251,8 +1260,8 @@ check_argument_match (struct MHD_Connection *connection, | |||
1251 | { | 1260 | { |
1252 | struct MHD_HTTP_Req_Header *pos; | 1261 | struct MHD_HTTP_Req_Header *pos; |
1253 | char *argb; | 1262 | char *argb; |
1254 | unsigned int num_headers; | ||
1255 | enum MHD_Result ret; | 1263 | enum MHD_Result ret; |
1264 | struct test_header_param param; | ||
1256 | 1265 | ||
1257 | argb = strdup (args); | 1266 | argb = strdup (args); |
1258 | if (NULL == argb) | 1267 | if (NULL == argb) |
@@ -1263,11 +1272,13 @@ check_argument_match (struct MHD_Connection *connection, | |||
1263 | #endif /* HAVE_MESSAGES */ | 1272 | #endif /* HAVE_MESSAGES */ |
1264 | return MHD_NO; | 1273 | return MHD_NO; |
1265 | } | 1274 | } |
1275 | param.connection = connection; | ||
1276 | param.num_headers = 0; | ||
1266 | ret = MHD_parse_arguments_ (connection, | 1277 | ret = MHD_parse_arguments_ (connection, |
1267 | MHD_GET_ARGUMENT_KIND, | 1278 | MHD_GET_ARGUMENT_KIND, |
1268 | argb, | 1279 | argb, |
1269 | &test_header, | 1280 | &test_header, |
1270 | &num_headers); | 1281 | ¶m); |
1271 | free (argb); | 1282 | free (argb); |
1272 | if (MHD_NO == ret) | 1283 | if (MHD_NO == ret) |
1273 | { | 1284 | { |
@@ -1278,9 +1289,9 @@ check_argument_match (struct MHD_Connection *connection, | |||
1278 | { | 1289 | { |
1279 | if (MHD_GET_ARGUMENT_KIND != pos->kind) | 1290 | if (MHD_GET_ARGUMENT_KIND != pos->kind) |
1280 | continue; | 1291 | continue; |
1281 | num_headers--; | 1292 | param.num_headers--; |
1282 | } | 1293 | } |
1283 | if (0 != num_headers) | 1294 | if (0 != param.num_headers) |
1284 | { | 1295 | { |
1285 | /* argument count mismatch */ | 1296 | /* argument count mismatch */ |
1286 | return MHD_NO; | 1297 | return MHD_NO; |