summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_string.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2022-11-16Added nxt_usts2str() to make C strings from nxt_str_t.Alejandro Colomar1-0/+2
This function is identical to nxt_ustr2str(), except that it takes a nxt_str_t structure as input, instead of a 'u_char *' and a size. The documentation of the function: /* * SYNOPSIS * void nxt_usts2str(char dst[restrict .src->length+1], * const nxt_str_t *restrict src); * * ARGUMENTS * dst Pointer to the first byte of the destination buffer. * src Pointer to the source Unterminated STring Structure. * * DESCRIPTION * Copy a string from the source nxt_str_t, which may be * not-NUL-terminated, into a NUL-terminated string in the * destination buffer. * * CAVEATS * If the destination buffer is not wider than the source buffer * at least by 1 byte, the behavior is undefined. * * EXAMPLES * nxt_str_t src = nxt_string("0123456789"); * char dst[src.length + 1]; * * nxt_usts2str(dst, &src); * * SEE ALSO * ustr2str(3), strlcpy(3), strscpy(9) */ Suggested-by: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
2022-11-16Added nxt_ustr2str() to make C strings from fixed-width buffers.Alejandro Colomar1-0/+4
This function makes it easy to transform a fixed-width buffer (which is how we represent strings in Unit most of the time) into a proper C string (NUL-terminated). We need to do this when interfacing libraries or the kernel, where most APIs expect NUL-terminated strings. The implementation is similar to strncpy_s(3), but avoids the unnecessary runtime checks. It's better to wrap the function in a macro and do as many static_assert(3)s as one considers necessary; in fact, if in the future C allows backwards VLA syntax, static analysis could be better than those static_assert(3)s. We use char for NUL-terminated strings, and u_char for the *u*nterminated strings. The documentation for the function: /* * SYNOPSIS * void ustr2str(char dst[restrict .n+1], * const u_char src[restrict .n], * size_t n); * * ARGUMENTS * dst Pointer to the first byte of the destination buffer. * src Pointer to the first byte of the source string. * n Size of 'src'. * * DESCRIPTION * Copy a string from the fixed-width source string, which may be * not-NUL-terminated, into a NUL-terminated string in the * destination buffer. * * CAVEATS * If the destination buffer is not wider than the source buffer * at least by 1 byte, the behavior is undefined. * * Use of this function normally indicates a problem in the design * of the strings, since normally it's better to guarantee that all * strings are properly terminated. The main use for this function * is to interface with some standard buffers, such as those * defined in utmp(7), which for historical reasons are not * guaranteed to be terminated. * * EXAMPLES * u_char src[10] = "0123456789"; // not NUL-terminated * char dst[sizeof(src) + 1]; * * static_assert(lengthof(src) < lengthof(dst)) * ustr2str(dst, src, lengthof(src)); * * SEE ALSO * nxt_sts2str(3), strlcpy(3), strscpy(9) */ Cc: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
2022-11-04Removed the unsafe nxt_memcmp() wrapper for memcmp(3).Alejandro Colomar1-2/+2
The casts are unnecessary, since memcmp(3)'s arguments are 'void *'. It might have been necessary in the times of K&R, where 'void *' didn't exist. Nowadays, it's unnecessary, and _very_ unsafe, since casts can hide all classes of bugs by silencing most compiler warnings. The changes from nxt_memcmp() to memcmp(3) were scripted: $ find src/ -type f \ | grep '\.[ch]$' \ | xargs sed -i 's/nxt_memcmp/memcmp/' Reviewed-by: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
2022-06-22Constified numerous function parameters.Andrew Clayton1-1/+1
As was pointed out by the cppcheck[0] static code analysis utility we can mark numerous function parameters as 'const'. This acts as a hint to the compiler about our intentions and the compiler will tell us when we deviate from them. [0]: https://cppcheck.sourceforge.io/
2021-10-26Custom implementation of Base64 decoding function.Valentin Bartenev1-0/+97
Compared to the previous implementation based on OpenSSL, the new implementation has these advantages: 1. Strict and reliable detection of invalid strings, including strings with less than 4 bytes of garbage at the end; 2. Allows to use Base64 strings without '=' padding.
2020-05-14Router: decode uri and args.Axel Duch1-1/+42
2020-03-30Configuration: support for rational numbers.Valentin Bartenev1-0/+18
2020-03-27Added nxt_is_complex_uri_encoded()/nxt_encode_complex_uri().Valentin Bartenev1-44/+155
2020-03-27Updated URI escaping table for better conformity with RFC 3986.Valentin Bartenev1-6/+4
Now '>', '<', '"', '^', '\', '}', '|', '{', and '`' are also escaped.
2019-10-10Changed nxt_memcasecmp() interface to avoid casts.Igor Sysoev1-3/+7
2019-09-19Basic support for serving static files.Valentin Bartenev1-0/+66
2019-09-16Configuration: added ability to access object members with slashes.Valentin Bartenev1-0/+56
Now URI encoding can be used to escape "/" in the request path: GET /config/listeners/unix:%2Fpath%2Fto%2Fsocket/
2019-02-26Introduced nxt_memcpy_upcase().Igor Sysoev1-0/+13
2018-06-25Removed '\r' and '\n' artifact macros.Igor Sysoev1-1/+1
2017-10-19Fixed matching of empty version.Valentin Bartenev1-0/+4
2017-10-05Fixed building with old GCC after the previous change.Valentin Bartenev1-2/+1
2017-10-05Improved applications versions handling.Valentin Bartenev1-0/+120
2017-08-17The new module configuration interface.Igor Sysoev1-3/+2
Configuration and building example: ./configure ./configure python ./configure php ./configure go make all or ./configure make nginext ./configure python make python ./configure php make php ./configure go make go Modules configuration options and building examples: ./configure python --module=python2 --config=python2.7-config make python2 ./configure php --module=php7 --config=php7.0-config --lib-path=/usr/local/php7.0 make php7 ./configure go --go=go1.6 --go-path=${HOME}/go1.6 make go1.6
2017-08-16Renamed nxt_str_copy() to nxt_str_cstrz().Valentin Bartenev1-2/+2
2017-06-27Applied nxt_pointer_to() and nxt_value_at() where possible.Valentin Bartenev1-1/+1
2017-06-20Using new memory pool implementation.Igor Sysoev1-7/+7
2017-02-01nxt_str_t changes.Igor Sysoev1-39/+40
2017-01-17Initial version.Igor Sysoev1-0/+317