You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

754 lines
24 KiB

  1. --- a/ChangeLog
  2. +++ b/ChangeLog
  3. @@ -1,3 +1,14 @@
  4. +Thu Jun 4 13:37:05 CEST 2015
  5. + Fixing memory leak in digest authentication. -AW
  6. +
  7. +Wed Jun 03 21:23:47 CEST 2015
  8. + Add deprecation compiler messages for deprecated functions
  9. + and macros. -EG
  10. +
  11. +Fri May 29 12:23:01 CEST 2015
  12. + Fixing digest authentication when used in combination
  13. + with escaped characters in URLs. -CG/AW
  14. +
  15. Wed May 13 11:49:09 CEST 2015
  16. Releasing libmicrohttpd 0.9.42. -CG
  17. --- a/src/microhttpd/response.c
  18. +++ b/src/microhttpd/response.c
  19. @@ -24,6 +24,8 @@
  20. * @author Christian Grothoff
  21. */
  22. +#define MHD_NO_DEPRECATION 1
  23. +
  24. #include "internal.h"
  25. #include "response.h"
  26. --- a/src/microhttpd/digestauth.c
  27. +++ b/src/microhttpd/digestauth.c
  28. @@ -1,6 +1,6 @@
  29. /*
  30. This file is part of libmicrohttpd
  31. - Copyright (C) 2010, 2011, 2012 Daniel Pittman and Christian Grothoff
  32. + Copyright (C) 2010, 2011, 2012, 2015 Daniel Pittman and Christian Grothoff
  33. This library is free software; you can redistribute it and/or
  34. modify it under the terms of the GNU Lesser General Public
  35. @@ -472,8 +472,8 @@ test_header (struct MHD_Connection *conn
  36. *
  37. * @param connection connections with headers to compare against
  38. * @param args argument URI string (after "?" in URI)
  39. - * @return MHD_YES if the arguments match,
  40. - * MHD_NO if not
  41. + * @return #MHD_YES if the arguments match,
  42. + * #MHD_NO if not
  43. */
  44. static int
  45. check_argument_match (struct MHD_Connection *connection,
  46. @@ -508,7 +508,10 @@ check_argument_match (struct MHD_Connect
  47. connection,
  48. argp);
  49. if (MHD_YES != test_header (connection, argp, NULL))
  50. - return MHD_NO;
  51. + {
  52. + free(argb);
  53. + return MHD_NO;
  54. + }
  55. num_headers++;
  56. break;
  57. }
  58. @@ -527,10 +530,16 @@ check_argument_match (struct MHD_Connect
  59. connection,
  60. equals);
  61. if (! test_header (connection, argp, equals))
  62. - return MHD_NO;
  63. + {
  64. + free(argb);
  65. + return MHD_NO;
  66. + }
  67. +
  68. num_headers++;
  69. argp = amper;
  70. }
  71. +
  72. + free(argb);
  73. /* also check that the number of headers matches */
  74. for (pos = connection->headers_received; NULL != pos; pos = pos->next)
  75. @@ -632,10 +641,83 @@ MHD_digest_auth_check (struct MHD_Connec
  76. header value. */
  77. return MHD_NO;
  78. }
  79. + /* 8 = 4 hexadecimal numbers for the timestamp */
  80. + nonce_time = strtoul (nonce + len - 8, (char **)NULL, 16);
  81. + t = (uint32_t) MHD_monotonic_time();
  82. + /*
  83. + * First level vetting for the nonce validity: if the timestamp
  84. + * attached to the nonce exceeds `nonce_timeout', then the nonce is
  85. + * invalid.
  86. + */
  87. + if ( (t > nonce_time + nonce_timeout) ||
  88. + (nonce_time + nonce_timeout < nonce_time) )
  89. + {
  90. + /* too old */
  91. + return MHD_INVALID_NONCE;
  92. + }
  93. +
  94. + calculate_nonce (nonce_time,
  95. + connection->method,
  96. + connection->daemon->digest_auth_random,
  97. + connection->daemon->digest_auth_rand_size,
  98. + connection->url,
  99. + realm,
  100. + noncehashexp);
  101. + /*
  102. + * Second level vetting for the nonce validity
  103. + * if the timestamp attached to the nonce is valid
  104. + * and possibly fabricated (in case of an attack)
  105. + * the attacker must also know the random seed to be
  106. + * able to generate a "sane" nonce, which if he does
  107. + * not, the nonce fabrication process going to be
  108. + * very hard to achieve.
  109. + */
  110. +
  111. + if (0 != strcmp (nonce, noncehashexp))
  112. + {
  113. + return MHD_INVALID_NONCE;
  114. + }
  115. + if ( (0 == lookup_sub_value (cnonce,
  116. + sizeof (cnonce),
  117. + header, "cnonce")) ||
  118. + (0 == lookup_sub_value (qop, sizeof (qop), header, "qop")) ||
  119. + ( (0 != strcmp (qop, "auth")) &&
  120. + (0 != strcmp (qop, "")) ) ||
  121. + (0 == lookup_sub_value (nc, sizeof (nc), header, "nc")) ||
  122. + (0 == lookup_sub_value (response, sizeof (response), header, "response")) )
  123. + {
  124. +#if HAVE_MESSAGES
  125. + MHD_DLOG (connection->daemon,
  126. + "Authentication failed, invalid format.\n");
  127. +#endif
  128. + return MHD_NO;
  129. + }
  130. + nci = strtoul (nc, &end, 16);
  131. + if ( ('\0' != *end) ||
  132. + ( (LONG_MAX == nci) &&
  133. + (ERANGE == errno) ) )
  134. + {
  135. +#if HAVE_MESSAGES
  136. + MHD_DLOG (connection->daemon,
  137. + "Authentication failed, invalid format.\n");
  138. +#endif
  139. + return MHD_NO; /* invalid nonce format */
  140. + }
  141. + /*
  142. + * Checking if that combination of nonce and nc is sound
  143. + * and not a replay attack attempt. Also adds the nonce
  144. + * to the nonce-nc map if it does not exist there.
  145. + */
  146. +
  147. + if (MHD_YES != check_nonce_nc (connection, nonce, nci))
  148. + {
  149. + return MHD_NO;
  150. + }
  151. +
  152. {
  153. char *uri;
  154. -
  155. - uri = malloc(left + 1);
  156. +
  157. + uri = malloc (left + 1);
  158. if (NULL == uri)
  159. {
  160. #if HAVE_MESSAGES
  161. @@ -648,24 +730,31 @@ MHD_digest_auth_check (struct MHD_Connec
  162. left + 1,
  163. header, "uri"))
  164. {
  165. - free(uri);
  166. + free (uri);
  167. return MHD_NO;
  168. }
  169. - /* 8 = 4 hexadecimal numbers for the timestamp */
  170. - nonce_time = strtoul (nonce + len - 8, (char **)NULL, 16);
  171. - t = (uint32_t) MHD_monotonic_time();
  172. - /*
  173. - * First level vetting for the nonce validity: if the timestamp
  174. - * attached to the nonce exceeds `nonce_timeout', then the nonce is
  175. - * invalid.
  176. - */
  177. - if ( (t > nonce_time + nonce_timeout) ||
  178. - (nonce_time + nonce_timeout < nonce_time) )
  179. - {
  180. - free(uri);
  181. - return MHD_INVALID_NONCE;
  182. - }
  183. + digest_calc_ha1("md5",
  184. + username,
  185. + realm,
  186. + password,
  187. + nonce,
  188. + cnonce,
  189. + ha1);
  190. + digest_calc_response (ha1,
  191. + nonce,
  192. + nc,
  193. + cnonce,
  194. + qop,
  195. + connection->method,
  196. + uri,
  197. + hentity,
  198. + respexp);
  199. +
  200. + /* Need to unescape URI before comparing with connection->url */
  201. + connection->daemon->unescape_callback (connection->daemon->unescape_callback_cls,
  202. + connection,
  203. + uri);
  204. if (0 != strncmp (uri,
  205. connection->url,
  206. strlen (connection->url)))
  207. @@ -674,9 +763,10 @@ MHD_digest_auth_check (struct MHD_Connec
  208. MHD_DLOG (connection->daemon,
  209. "Authentication failed, URI does not match.\n");
  210. #endif
  211. - free(uri);
  212. + free (uri);
  213. return MHD_NO;
  214. }
  215. +
  216. {
  217. const char *args = strchr (uri, '?');
  218. @@ -692,89 +782,11 @@ MHD_digest_auth_check (struct MHD_Connec
  219. MHD_DLOG (connection->daemon,
  220. "Authentication failed, arguments do not match.\n");
  221. #endif
  222. - free(uri);
  223. + free (uri);
  224. return MHD_NO;
  225. }
  226. }
  227. - calculate_nonce (nonce_time,
  228. - connection->method,
  229. - connection->daemon->digest_auth_random,
  230. - connection->daemon->digest_auth_rand_size,
  231. - connection->url,
  232. - realm,
  233. - noncehashexp);
  234. - /*
  235. - * Second level vetting for the nonce validity
  236. - * if the timestamp attached to the nonce is valid
  237. - * and possibly fabricated (in case of an attack)
  238. - * the attacker must also know the random seed to be
  239. - * able to generate a "sane" nonce, which if he does
  240. - * not, the nonce fabrication process going to be
  241. - * very hard to achieve.
  242. - */
  243. -
  244. - if (0 != strcmp (nonce, noncehashexp))
  245. - {
  246. - free(uri);
  247. - return MHD_INVALID_NONCE;
  248. - }
  249. - if ( (0 == lookup_sub_value (cnonce,
  250. - sizeof (cnonce),
  251. - header, "cnonce")) ||
  252. - (0 == lookup_sub_value (qop, sizeof (qop), header, "qop")) ||
  253. - ( (0 != strcmp (qop, "auth")) &&
  254. - (0 != strcmp (qop, "")) ) ||
  255. - (0 == lookup_sub_value (nc, sizeof (nc), header, "nc")) ||
  256. - (0 == lookup_sub_value (response, sizeof (response), header, "response")) )
  257. - {
  258. -#if HAVE_MESSAGES
  259. - MHD_DLOG (connection->daemon,
  260. - "Authentication failed, invalid format.\n");
  261. -#endif
  262. - free(uri);
  263. - return MHD_NO;
  264. - }
  265. - nci = strtoul (nc, &end, 16);
  266. - if ( ('\0' != *end) ||
  267. - ( (LONG_MAX == nci) &&
  268. - (ERANGE == errno) ) )
  269. - {
  270. -#if HAVE_MESSAGES
  271. - MHD_DLOG (connection->daemon,
  272. - "Authentication failed, invalid format.\n");
  273. -#endif
  274. - free(uri);
  275. - return MHD_NO; /* invalid nonce format */
  276. - }
  277. - /*
  278. - * Checking if that combination of nonce and nc is sound
  279. - * and not a replay attack attempt. Also adds the nonce
  280. - * to the nonce-nc map if it does not exist there.
  281. - */
  282. -
  283. - if (MHD_YES != check_nonce_nc (connection, nonce, nci))
  284. - {
  285. - free(uri);
  286. - return MHD_NO;
  287. - }
  288. -
  289. - digest_calc_ha1("md5",
  290. - username,
  291. - realm,
  292. - password,
  293. - nonce,
  294. - cnonce,
  295. - ha1);
  296. - digest_calc_response (ha1,
  297. - nonce,
  298. - nc,
  299. - cnonce,
  300. - qop,
  301. - connection->method,
  302. - uri,
  303. - hentity,
  304. - respexp);
  305. - free(uri);
  306. + free (uri);
  307. return (0 == strcmp(response, respexp))
  308. ? MHD_YES
  309. : MHD_NO;
  310. @@ -835,7 +847,7 @@ MHD_queue_auth_fail_response (struct MHD
  311. : "");
  312. {
  313. char *header;
  314. -
  315. +
  316. header = malloc(hlen + 1);
  317. if (NULL == header)
  318. {
  319. --- a/src/microhttpd/daemon.c
  320. +++ b/src/microhttpd/daemon.c
  321. @@ -73,7 +73,7 @@
  322. /**
  323. * Default connection limit.
  324. */
  325. -#ifndef WINDOWS
  326. +#ifndef MHD_WINSOCK_SOCKETS
  327. #define MHD_MAX_CONNECTIONS_DEFAULT FD_SETSIZE - 4
  328. #else
  329. #define MHD_MAX_CONNECTIONS_DEFAULT FD_SETSIZE
  330. @@ -1271,7 +1271,7 @@ internal_add_connection (struct MHD_Daem
  331. return MHD_NO;
  332. }
  333. -#ifndef WINDOWS
  334. +#ifndef MHD_WINSOCK_SOCKETS
  335. if ( (client_socket >= FD_SETSIZE) &&
  336. (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) )
  337. {
  338. @@ -1418,7 +1418,7 @@ internal_add_connection (struct MHD_Daem
  339. #endif
  340. {
  341. /* make socket non-blocking */
  342. -#if !defined(WINDOWS) || defined(CYGWIN)
  343. +#if !defined(MHD_WINSOCK_SOCKETS)
  344. int flags = fcntl (connection->socket_fd, F_GETFL);
  345. if ( (-1 == flags) ||
  346. (0 != fcntl (connection->socket_fd, F_SETFL, flags | O_NONBLOCK)) )
  347. @@ -1797,7 +1797,7 @@ static void
  348. make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
  349. MHD_socket sock)
  350. {
  351. -#ifdef WINDOWS
  352. +#ifdef MHD_WINSOCK_SOCKETS
  353. DWORD dwFlags;
  354. unsigned long flags = 1;
  355. @@ -3611,7 +3611,7 @@ MHD_start_daemon_va (unsigned int flags,
  356. daemon->socket_fd = MHD_INVALID_SOCKET;
  357. daemon->listening_address_reuse = 0;
  358. daemon->options = flags;
  359. -#if WINDOWS
  360. +#if defined(MHD_WINSOCK_SOCKETS) || defined(CYGWIN)
  361. /* Winsock is broken with respect to 'shutdown';
  362. this disables us calling 'shutdown' on W32. */
  363. daemon->options |= MHD_USE_EPOLL_TURBO;
  364. @@ -3650,7 +3650,7 @@ MHD_start_daemon_va (unsigned int flags,
  365. free (daemon);
  366. return NULL;
  367. }
  368. -#ifndef WINDOWS
  369. +#ifndef MHD_WINSOCK_SOCKETS
  370. if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) &&
  371. (1 == use_pipe) &&
  372. (daemon->wpipe[0] >= FD_SETSIZE) )
  373. @@ -3934,7 +3934,7 @@ MHD_start_daemon_va (unsigned int flags,
  374. (http://msdn.microsoft.com/en-us/library/ms738574%28v=VS.85%29.aspx);
  375. and may also be missing on older POSIX systems; good luck if you have any of those,
  376. your IPv6 socket may then also bind against IPv4 anyway... */
  377. -#ifndef WINDOWS
  378. +#ifndef MHD_WINSOCK_SOCKETS
  379. const int
  380. #else
  381. const char
  382. @@ -4016,7 +4016,7 @@ MHD_start_daemon_va (unsigned int flags,
  383. {
  384. socket_fd = daemon->socket_fd;
  385. }
  386. -#ifndef WINDOWS
  387. +#ifndef MHD_WINSOCK_SOCKETS
  388. if ( (socket_fd >= FD_SETSIZE) &&
  389. (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY)) ) )
  390. {
  391. @@ -4121,7 +4121,7 @@ MHD_start_daemon_va (unsigned int flags,
  392. if ( (daemon->worker_pool_size > 0) &&
  393. (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) )
  394. {
  395. -#if !defined(WINDOWS) || defined(CYGWIN)
  396. +#if !defined(MHD_WINSOCK_SOCKETS)
  397. int sk_flags;
  398. #else
  399. unsigned long sk_flags;
  400. @@ -4140,7 +4140,7 @@ MHD_start_daemon_va (unsigned int flags,
  401. /* Accept must be non-blocking. Multiple children may wake up
  402. * to handle a new connection, but only one will win the race.
  403. * The others must immediately return. */
  404. -#if !defined(WINDOWS) || defined(CYGWIN)
  405. +#if !defined(MHD_WINSOCK_SOCKETS)
  406. sk_flags = fcntl (socket_fd, F_GETFL);
  407. if (sk_flags < 0)
  408. goto thread_failed;
  409. @@ -4150,7 +4150,7 @@ MHD_start_daemon_va (unsigned int flags,
  410. sk_flags = 1;
  411. if (SOCKET_ERROR == ioctlsocket (socket_fd, FIONBIO, &sk_flags))
  412. goto thread_failed;
  413. -#endif /* WINDOWS && !CYGWIN */
  414. +#endif /* MHD_WINSOCK_SOCKETS */
  415. /* Allocate memory for pooled objects */
  416. daemon->worker_pool = malloc (sizeof (struct MHD_Daemon)
  417. @@ -4182,7 +4182,7 @@ MHD_start_daemon_va (unsigned int flags,
  418. #endif
  419. goto thread_failed;
  420. }
  421. -#ifndef WINDOWS
  422. +#ifndef MHD_WINSOCK_SOCKETS
  423. if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) &&
  424. (MHD_USE_SUSPEND_RESUME == (flags & MHD_USE_SUSPEND_RESUME)) &&
  425. (d->wpipe[0] >= FD_SETSIZE) )
  426. @@ -4343,7 +4343,7 @@ close_all_connections (struct MHD_Daemon
  427. {
  428. shutdown (pos->socket_fd,
  429. (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR);
  430. -#if WINDOWS
  431. +#if MHD_WINSOCK_SOCKETS
  432. if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
  433. (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&
  434. (1 != MHD_pipe_write_ (daemon->wpipe[1], "e", 1)) )
  435. --- a/src/include/microhttpd.h
  436. +++ b/src/include/microhttpd.h
  437. @@ -130,7 +130,7 @@ typedef intptr_t ssize_t;
  438. * Current version of the library.
  439. * 0x01093001 = 1.9.30-1.
  440. */
  441. -#define MHD_VERSION 0x00094200
  442. +#define MHD_VERSION 0x00094202
  443. /**
  444. * MHD-internal return code for "YES".
  445. @@ -194,6 +194,53 @@ typedef SOCKET MHD_socket;
  446. #endif /* MHD_SOCKET_DEFINED */
  447. /**
  448. + * Define MHD_NO_DEPRECATION before including "microhttpd.h" to disable deprecation messages
  449. + */
  450. +#ifdef MHD_NO_DEPRECATION
  451. +#define _MHD_DEPR_MACRO(msg)
  452. +#define _MHD_DEPR_FUNC(msg)
  453. +#endif /* MHD_NO_DEPRECATION */
  454. +
  455. +#ifndef _MHD_DEPR_MACRO
  456. +#if defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1500
  457. +/* Stringify macros */
  458. +#define _MHD_INSTRMACRO(a) #a
  459. +#define _MHD_STRMACRO(a) _MHD_INSTRMACRO(a)
  460. +#define _MHD_DEPR_MACRO(msg) __pragma(message(__FILE__ "(" _MHD_STRMACRO(__LINE__)"): warning: " msg))
  461. +#elif defined(__clang__) || defined (__GNUC_PATCHLEVEL__)
  462. +#define _MHD_GCC_PRAG(x) _Pragma (#x)
  463. +#if __clang_major__+0 >= 5 || \
  464. + (!defined(__apple_build_version__) && (__clang_major__+0 > 3 || (__clang_major__+0 == 3 && __clang_minor__ >= 3))) || \
  465. + __GNUC__+0 > 4 || (__GNUC__+0 == 4 && __GNUC_MINOR__+0 >= 8)
  466. +#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG(GCC warning msg)
  467. +#else /* older clang or GCC */
  468. +#define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG(message msg)
  469. +#endif
  470. +/* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
  471. +#else /* other compilers */
  472. +#define _MHD_DEPR_MACRO(msg)
  473. +#endif
  474. +#endif /* _MHD_DEPR_MACRO */
  475. +
  476. +#ifndef _MHD_DEPR_FUNC
  477. +#if defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1400
  478. +#define _MHD_DEPR_FUNC(msg) __declspec(deprecated(msg))
  479. +#elif defined(_MSC_FULL_VER) && _MSC_VER+0 >= 1310
  480. +/* VS .NET 2003 deprecation do not support custom messages */
  481. +#define _MHD_DEPR_FUNC(msg) __declspec(deprecated)
  482. +#elif defined (__clang__) && \
  483. + (__clang_major__+0 >= 4 || (!defined(__apple_build_version__) && __clang_major__+0 >= 3))
  484. +#define _MHD_DEPR_FUNC(msg) __attribute__((deprecated(msg)))
  485. +#elif defined (__clang__) || __GNUC__+0 > 3 || (__GNUC__+0 == 3 && __GNUC_MINOR__+0 >= 1)
  486. +/* GCC-style deprecation do not support custom messages */
  487. +#define _MHD_DEPR_FUNC(msg) __attribute__((__deprecated__))
  488. +/* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
  489. +#else /* other compilers */
  490. +#define _MHD_DEPR_FUNC(msg)
  491. +#endif
  492. +#endif /* _MHD_DEPR_FUNC */
  493. +
  494. +/**
  495. * Not all architectures and `printf()`'s support the `long long` type.
  496. * This gives the ability to replace `long long` with just a `long`,
  497. * standard `int` or a `short`.
  498. @@ -204,6 +251,8 @@ typedef SOCKET MHD_socket;
  499. */
  500. #define MHD_LONG_LONG long long
  501. #define MHD_UNSIGNED_LONG_LONG unsigned long long
  502. +#else /* MHD_LONG_LONG */
  503. +_MHD_DEPR_MACRO("Macro MHD_LONG_LONG is deprecated, use MHD_UNSIGNED_LONG_LONG")
  504. #endif
  505. /**
  506. * Format string for printing a variable of type #MHD_LONG_LONG.
  507. @@ -215,6 +264,8 @@ typedef SOCKET MHD_socket;
  508. */
  509. #define MHD_LONG_LONG_PRINTF "ll"
  510. #define MHD_UNSIGNED_LONG_LONG_PRINTF "%llu"
  511. +#else /* MHD_LONG_LONG_PRINTF */
  512. +_MHD_DEPR_MACRO("Macro MHD_LONG_LONG_PRINTF is deprecated, use MHD_UNSIGNED_LONG_LONG_PRINTF")
  513. #endif
  514. @@ -253,7 +304,8 @@ typedef SOCKET MHD_socket;
  515. #define MHD_HTTP_METHOD_NOT_ALLOWED 405
  516. #define MHD_HTTP_NOT_ACCEPTABLE 406
  517. /** @deprecated */
  518. -#define MHD_HTTP_METHOD_NOT_ACCEPTABLE 406
  519. +#define MHD_HTTP_METHOD_NOT_ACCEPTABLE \
  520. + _MHD_DEPR_MACRO("Value MHD_HTTP_METHOD_NOT_ACCEPTABLE is deprecated, use MHD_HTTP_NOT_ACCEPTABLE") 406
  521. #define MHD_HTTP_PROXY_AUTHENTICATION_REQUIRED 407
  522. #define MHD_HTTP_REQUEST_TIMEOUT 408
  523. #define MHD_HTTP_CONFLICT 409
  524. @@ -1953,6 +2005,7 @@ MHD_create_response_from_callback (uint6
  525. * @deprecated use #MHD_create_response_from_buffer instead
  526. * @ingroup response
  527. */
  528. +_MHD_DEPR_FUNC("MHD_create_response_from_data() is deprecated, use MHD_create_response_from_buffer()") \
  529. _MHD_EXTERN struct MHD_Response *
  530. MHD_create_response_from_data (size_t size,
  531. void *data,
  532. @@ -2023,6 +2076,8 @@ MHD_create_response_from_buffer (size_t
  533. * @return NULL on error (i.e. invalid arguments, out of memory)
  534. * @ingroup response
  535. */
  536. +/* NOTE: this should be 'uint64_t' instead of 'size_t', but changing
  537. + this would break API compatibility. */
  538. _MHD_EXTERN struct MHD_Response *
  539. MHD_create_response_from_fd (size_t size,
  540. int fd);
  541. @@ -2044,6 +2099,8 @@ MHD_create_response_from_fd (size_t size
  542. * @return NULL on error (i.e. invalid arguments, out of memory)
  543. * @ingroup response
  544. */
  545. +/* NOTE: this should be 'uint64_t' instead of 'size_t', but changing
  546. + this would break API compatibility. */
  547. _MHD_EXTERN struct MHD_Response *
  548. MHD_create_response_from_fd_at_offset (size_t size,
  549. int fd,
  550. --- a/src/include/platform_interface.h
  551. +++ b/src/include/platform_interface.h
  552. @@ -82,14 +82,14 @@
  553. /* MHD_socket_close_(fd) close any FDs (non-W32) / close only socket FDs (W32) */
  554. -#if !defined(_WIN32) || defined(__CYGWIN__)
  555. +#if !defined(MHD_WINSOCK_SOCKETS)
  556. #define MHD_socket_close_(fd) close((fd))
  557. #else
  558. #define MHD_socket_close_(fd) closesocket((fd))
  559. #endif
  560. /* MHD_socket_errno_ is errno of last function (non-W32) / errno of last socket function (W32) */
  561. -#if !defined(_WIN32) || defined(__CYGWIN__)
  562. +#if !defined(MHD_WINSOCK_SOCKETS)
  563. #define MHD_socket_errno_ errno
  564. #else
  565. #define MHD_socket_errno_ MHD_W32_errno_from_winsock_()
  566. @@ -97,21 +97,21 @@
  567. /* MHD_socket_last_strerr_ is description string of last errno (non-W32) /
  568. * description string of last socket error (W32) */
  569. -#if !defined(_WIN32) || defined(__CYGWIN__)
  570. +#if !defined(MHD_WINSOCK_SOCKETS)
  571. #define MHD_socket_last_strerr_() strerror(errno)
  572. #else
  573. #define MHD_socket_last_strerr_() MHD_W32_strerror_last_winsock_()
  574. #endif
  575. /* MHD_strerror_ is strerror (both non-W32/W32) */
  576. -#if !defined(_WIN32) || defined(__CYGWIN__)
  577. +#if !defined(MHD_WINSOCK_SOCKETS)
  578. #define MHD_strerror_(errnum) strerror((errnum))
  579. #else
  580. #define MHD_strerror_(errnum) MHD_W32_strerror_((errnum))
  581. #endif
  582. /* MHD_set_socket_errno_ set errno to errnum (non-W32) / set socket last error to errnum (W32) */
  583. -#if !defined(_WIN32) || defined(__CYGWIN__)
  584. +#if !defined(MHD_WINSOCK_SOCKETS)
  585. #define MHD_set_socket_errno_(errnum) errno=(errnum)
  586. #else
  587. #define MHD_set_socket_errno_(errnum) MHD_W32_set_last_winsock_error_((errnum))
  588. --- a/src/testcurl/test_digestauth.c
  589. +++ b/src/testcurl/test_digestauth.c
  590. @@ -73,7 +73,8 @@ ahc_echo (void *cls,
  591. const char *url,
  592. const char *method,
  593. const char *version,
  594. - const char *upload_data, size_t *upload_data_size,
  595. + const char *upload_data,
  596. + size_t *upload_data_size,
  597. void **unused)
  598. {
  599. struct MHD_Response *response;
  600. @@ -82,44 +83,47 @@ ahc_echo (void *cls,
  601. const char *realm = "test@example.com";
  602. int ret;
  603. - username = MHD_digest_auth_get_username(connection);
  604. + username = MHD_digest_auth_get_username (connection);
  605. if ( (username == NULL) ||
  606. (0 != strcmp (username, "testuser")) )
  607. {
  608. - response = MHD_create_response_from_buffer(strlen (DENIED),
  609. - DENIED,
  610. - MHD_RESPMEM_PERSISTENT);
  611. + response = MHD_create_response_from_buffer (strlen (DENIED),
  612. + DENIED,
  613. + MHD_RESPMEM_PERSISTENT);
  614. ret = MHD_queue_auth_fail_response(connection, realm,
  615. MY_OPAQUE,
  616. response,
  617. - MHD_NO);
  618. - MHD_destroy_response(response);
  619. + MHD_NO);
  620. + MHD_destroy_response(response);
  621. return ret;
  622. }
  623. ret = MHD_digest_auth_check(connection, realm,
  624. - username,
  625. - password,
  626. + username,
  627. + password,
  628. 300);
  629. free(username);
  630. if ( (ret == MHD_INVALID_NONCE) ||
  631. (ret == MHD_NO) )
  632. {
  633. - response = MHD_create_response_from_buffer(strlen (DENIED),
  634. + response = MHD_create_response_from_buffer(strlen (DENIED),
  635. DENIED,
  636. - MHD_RESPMEM_PERSISTENT);
  637. - if (NULL == response)
  638. + MHD_RESPMEM_PERSISTENT);
  639. + if (NULL == response)
  640. return MHD_NO;
  641. ret = MHD_queue_auth_fail_response(connection, realm,
  642. MY_OPAQUE,
  643. response,
  644. - (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
  645. - MHD_destroy_response(response);
  646. + (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
  647. + MHD_destroy_response(response);
  648. return ret;
  649. }
  650. - response = MHD_create_response_from_buffer(strlen(PAGE), PAGE,
  651. - MHD_RESPMEM_PERSISTENT);
  652. - ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
  653. - MHD_destroy_response(response);
  654. + response = MHD_create_response_from_buffer (strlen(PAGE),
  655. + PAGE,
  656. + MHD_RESPMEM_PERSISTENT);
  657. + ret = MHD_queue_response (connection,
  658. + MHD_HTTP_OK,
  659. + response);
  660. + MHD_destroy_response (response);
  661. return ret;
  662. }
  663. @@ -144,24 +148,24 @@ testDigestAuth ()
  664. fd = open("/dev/urandom", O_RDONLY);
  665. if (-1 == fd)
  666. {
  667. - fprintf(stderr, "Failed to open `%s': %s\n",
  668. - "/dev/urandom",
  669. - strerror(errno));
  670. - return 1;
  671. - }
  672. + fprintf(stderr, "Failed to open `%s': %s\n",
  673. + "/dev/urandom",
  674. + strerror(errno));
  675. + return 1;
  676. + }
  677. while (off < 8)
  678. - {
  679. - len = read(fd, rnd, 8);
  680. - if (len == -1)
  681. - {
  682. - fprintf(stderr, "Failed to read `%s': %s\n",
  683. - "/dev/urandom",
  684. - strerror(errno));
  685. - (void) close(fd);
  686. - return 1;
  687. - }
  688. - off += len;
  689. - }
  690. + {
  691. + len = read(fd, rnd, 8);
  692. + if (len == -1)
  693. + {
  694. + fprintf(stderr, "Failed to read `%s': %s\n",
  695. + "/dev/urandom",
  696. + strerror(errno));
  697. + (void) close(fd);
  698. + return 1;
  699. + }
  700. + off += len;
  701. + }
  702. (void) close(fd);
  703. #else
  704. {
  705. @@ -193,7 +197,7 @@ testDigestAuth ()
  706. if (d == NULL)
  707. return 1;
  708. c = curl_easy_init ();
  709. - curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1337/");
  710. + curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1337/bar%20 foo?a=bü%20");
  711. curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
  712. curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
  713. curl_easy_setopt (c, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
  714. @@ -225,7 +229,6 @@ testDigestAuth ()
  715. }
  716. -
  717. int
  718. main (int argc, char *const *argv)
  719. {
  720. --- a/src/testcurl/https/test_https_time_out.c
  721. +++ b/src/testcurl/https/test_https_time_out.c
  722. @@ -64,7 +64,7 @@ test_tls_session_time_out (gnutls_sessio
  723. gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) (intptr_t) sd);
  724. - ret = connect (sd, &sa, sizeof (struct sockaddr_in));
  725. + ret = connect (sd, (struct sockaddr *) &sa, sizeof (struct sockaddr_in));
  726. if (ret < 0)
  727. {