mirror of
https://github.com/lammertb/libhttp.git
synced 2026-01-27 08:02:47 +03:00
Moved skip_quoted to own file
This commit is contained in:
1
Makefile
1
Makefile
@@ -183,6 +183,7 @@ LIB_SOURCES = src/libhttp.c \
|
||||
src/httplib_set_uid_option.c \
|
||||
src/httplib_set_user_connection_data.c \
|
||||
src/httplib_set_websocket_handler.c \
|
||||
src/httplib_skip_quoted.c \
|
||||
src/httplib_snprintf.c \
|
||||
src/httplib_sockaddr_to_string.c \
|
||||
src/httplib_spawn_process.c \
|
||||
|
||||
79
src/httplib_skip_quoted.c
Normal file
79
src/httplib_skip_quoted.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lammert Bies
|
||||
* Copyright (c) 2013-2016 the Civetweb developers
|
||||
* Copyright (c) 2004-2013 Sergey Lyubka
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "libhttp-private.h"
|
||||
|
||||
|
||||
|
||||
/* Skip the characters until one of the delimiters characters found.
|
||||
* 0-terminate resulting word. Skip the delimiter and following whitespaces.
|
||||
* Advance pointer to buffer to the next word. Return found 0-terminated word.
|
||||
* Delimiters can be quoted with quotechar. */
|
||||
char * XX_httplib_skip_quoted( char **buf, const char *delimiters, const char *whitespace, char quotechar ) {
|
||||
|
||||
char *p;
|
||||
char *begin_word;
|
||||
char *end_word;
|
||||
char *end_whitespace;
|
||||
|
||||
begin_word = *buf;
|
||||
end_word = begin_word + strcspn(begin_word, delimiters);
|
||||
|
||||
/* Check for quotechar */
|
||||
if (end_word > begin_word) {
|
||||
p = end_word - 1;
|
||||
while (*p == quotechar) {
|
||||
/* While the delimiter is quoted, look for the next delimiter. */
|
||||
/* This happens, e.g., in calls from XX_httplib_parse_auth_header,
|
||||
* if the user name contains a " character. */
|
||||
|
||||
/* If there is anything beyond end_word, copy it. */
|
||||
if (*end_word != '\0') {
|
||||
size_t end_off = strcspn(end_word + 1, delimiters);
|
||||
memmove(p, end_word, end_off + 1);
|
||||
p += end_off; /* p must correspond to end_word - 1 */
|
||||
end_word += end_off + 1;
|
||||
} else {
|
||||
*p = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (p++; p < end_word; p++) *p = '\0';
|
||||
}
|
||||
|
||||
if (*end_word == '\0') {
|
||||
*buf = end_word;
|
||||
} else {
|
||||
end_whitespace = end_word + 1 + strspn(end_word + 1, whitespace);
|
||||
|
||||
for (p = end_word; p < end_whitespace; p++) *p = '\0';
|
||||
|
||||
*buf = end_whitespace;
|
||||
}
|
||||
|
||||
return begin_word;
|
||||
|
||||
} /* XX_httplib_skip_quoted */
|
||||
@@ -828,57 +828,6 @@ void XX_httplib_set_thread_name(const char *threadName) {
|
||||
|
||||
|
||||
|
||||
/* Skip the characters until one of the delimiters characters found.
|
||||
* 0-terminate resulting word. Skip the delimiter and following whitespaces.
|
||||
* Advance pointer to buffer to the next word. Return found 0-terminated word.
|
||||
* Delimiters can be quoted with quotechar. */
|
||||
char * XX_httplib_skip_quoted( char **buf, const char *delimiters, const char *whitespace, char quotechar ) {
|
||||
|
||||
char *p;
|
||||
char *begin_word;
|
||||
char *end_word;
|
||||
char *end_whitespace;
|
||||
|
||||
begin_word = *buf;
|
||||
end_word = begin_word + strcspn(begin_word, delimiters);
|
||||
|
||||
/* Check for quotechar */
|
||||
if (end_word > begin_word) {
|
||||
p = end_word - 1;
|
||||
while (*p == quotechar) {
|
||||
/* While the delimiter is quoted, look for the next delimiter. */
|
||||
/* This happens, e.g., in calls from XX_httplib_parse_auth_header,
|
||||
* if the user name contains a " character. */
|
||||
|
||||
/* If there is anything beyond end_word, copy it. */
|
||||
if (*end_word != '\0') {
|
||||
size_t end_off = strcspn(end_word + 1, delimiters);
|
||||
memmove(p, end_word, end_off + 1);
|
||||
p += end_off; /* p must correspond to end_word - 1 */
|
||||
end_word += end_off + 1;
|
||||
} else {
|
||||
*p = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (p++; p < end_word; p++) *p = '\0';
|
||||
}
|
||||
|
||||
if (*end_word == '\0') {
|
||||
*buf = end_word;
|
||||
} else {
|
||||
end_whitespace = end_word + 1 + strspn(end_word + 1, whitespace);
|
||||
|
||||
for (p = end_word; p < end_whitespace; p++) *p = '\0';
|
||||
|
||||
*buf = end_whitespace;
|
||||
}
|
||||
|
||||
return begin_word;
|
||||
|
||||
} /* XX_httplib_skip_quoted */
|
||||
|
||||
|
||||
/* Simplified version of XX_httplib_skip_quoted without quote char
|
||||
* and whitespace == delimiters */
|
||||
char *XX_httplib_skip( char **buf, const char *delimiters ) {
|
||||
|
||||
Reference in New Issue
Block a user