aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_str.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_str.c')
-rw-r--r--src/microhttpd/mhd_str.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index 5829daa5..f8e1965f 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -1474,3 +1474,44 @@ MHD_str_unquote (const char *quoted,
1474 1474
1475 1475
1476#endif /* DAUTH_SUPPORT */ 1476#endif /* DAUTH_SUPPORT */
1477
1478#if defined(DAUTH_SUPPORT) || defined(BAUTH_SUPPORT)
1479
1480size_t
1481MHD_str_quote (const char *unquoted,
1482 size_t unquoted_len,
1483 char *result,
1484 size_t buf_size)
1485{
1486 size_t r;
1487 size_t w;
1488
1489 r = 0;
1490 w = 0;
1491
1492 if (unquoted_len > buf_size)
1493 return 0; /* The output buffer is too small */
1494
1495 while (unquoted_len > r)
1496 {
1497 if (buf_size <= w)
1498 return 0; /* The output buffer is too small */
1499 else
1500 {
1501 const char chr = unquoted[r++];
1502 if (('\\' == chr) || ('\"' == chr))
1503 {
1504 result[w++] = '\\'; /* Escape current char */
1505 if (buf_size <= w)
1506 return 0; /* The output buffer is too small */
1507 }
1508 result[w++] = chr;
1509 }
1510 }
1511 mhd_assert (w >= r);
1512 mhd_assert (w <= r * 2);
1513 return w;
1514}
1515
1516
1517#endif /* DAUTH_SUPPORT || BAUTH_SUPPORT */