ensure errors msg are followed by \n, specify in a define the number of matches we need, remove bad structure init
This commit is contained in:
parent
be0f86df8d
commit
5063f3e95b
22
vger.c
22
vger.c
|
@ -43,6 +43,7 @@ stop(const int r, const char *fmt, ...)
|
||||||
va_start(ap2, fmt);
|
va_start(ap2, fmt);
|
||||||
vfprintf(stderr, fmt, ap2);
|
vfprintf(stderr, fmt, ap2);
|
||||||
va_end(ap2);
|
va_end(ap2);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(r);
|
exit(r);
|
||||||
|
@ -344,8 +345,8 @@ check_request(char *request)
|
||||||
*/
|
*/
|
||||||
char *pos = NULL;
|
char *pos = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* read 1024 +1 chars from stdin to get the request (1024 + \0) */
|
/* read 1024 +1 chars from stdin to get the request (1024 + \0) */
|
||||||
|
|
||||||
if (fgets(request, GEMINI_REQUEST_MAX, stdin) == NULL) {
|
if (fgets(request, GEMINI_REQUEST_MAX, stdin) == NULL) {
|
||||||
/* EOF reached before reading anything */
|
/* EOF reached before reading anything */
|
||||||
if (feof(stdin)) {
|
if (feof(stdin)) {
|
||||||
|
@ -368,22 +369,9 @@ check_request(char *request)
|
||||||
/* remove \r\n at the end of string */
|
/* remove \r\n at the end of string */
|
||||||
request[strcspn(request, "\r\n")] = '\0';
|
request[strcspn(request, "\r\n")] = '\0';
|
||||||
|
|
||||||
/*
|
|
||||||
* check if the beginning of the request starts with
|
|
||||||
* gemini://
|
|
||||||
*/
|
|
||||||
if (strncmp(request, "gemini://", GEMINI_PART) != 0) {
|
|
||||||
/* error code url malformed */
|
|
||||||
status(59, "request «%s» doesn't match gemini://", request);
|
|
||||||
stop(EXIT_FAILURE, "request «%s» doesn't match gemini://", request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* save request for logs */
|
/* save request for logs */
|
||||||
estrlcpy(_request, request, sizeof(_request));
|
estrlcpy(_request, request, sizeof(_request));
|
||||||
|
|
||||||
/* remove the gemini:// part */
|
|
||||||
memmove(request, request + GEMINI_PART, strlen(request) + 1 - GEMINI_PART);
|
|
||||||
|
|
||||||
/* remove all "/.." for safety reasons */
|
/* remove all "/.." for safety reasons */
|
||||||
while ((pos = strstr(request, "/..")) != NULL)
|
while ((pos = strstr(request, "/..")) != NULL)
|
||||||
memmove(request, pos + 3, strlen(pos) + 1 - 3); /* "/.." = 3 */
|
memmove(request, pos + 3, strlen(pos) + 1 - 3); /* "/.." = 3 */
|
||||||
|
@ -508,11 +496,11 @@ get_query(char *path, char *query, size_t querysiz)
|
||||||
void
|
void
|
||||||
split_request(const char *request, char *hostname, char *path, char *query)
|
split_request(const char *request, char *hostname, char *path, char *query)
|
||||||
{
|
{
|
||||||
regex_t greg = {0}; /* compiled gemini regex */
|
size_t nmatch = SE_MAX; /* 3 "()" + 1 for whole match */
|
||||||
regmatch_t *match = {0}; /* matches founds */
|
|
||||||
size_t nmatch = 4; /* number of substrings to look for */
|
|
||||||
char buf[BUFSIZ] = {'\0'}; /* to handle error messages */
|
char buf[BUFSIZ] = {'\0'}; /* to handle error messages */
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
regex_t greg; /* compiled gemini regex */
|
||||||
|
regmatch_t match[SE_MAX]; /* matches founds */
|
||||||
|
|
||||||
ret = regcomp(&greg, _gemini_regex, REG_EXTENDED);
|
ret = regcomp(&greg, _gemini_regex, REG_EXTENDED);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
|
3
vger.h
3
vger.h
|
@ -11,6 +11,9 @@
|
||||||
*/
|
*/
|
||||||
#define GEMINI_REQUEST_MAX 1025
|
#define GEMINI_REQUEST_MAX 1025
|
||||||
|
|
||||||
|
/* max subexpression in regex : 3 + 1 */
|
||||||
|
#define SE_MAX 4
|
||||||
|
|
||||||
/* gemini_regex:
|
/* gemini_regex:
|
||||||
* =============
|
* =============
|
||||||
* ^gemini://+ : in case of gemini:///
|
* ^gemini://+ : in case of gemini:///
|
||||||
|
|
Loading…
Reference in New Issue