<commit_before>/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*  Monkey HTTP Daemon
 *  ------------------
 *  Copyright (C) 2001-2010, <NAME>. <<EMAIL>>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "monkey.h"
#include "memory.h"
#include "http.h"
#include "http_status.h"
#include "file.h"
#include "utils.h"
#include "config.h"
#include "str.h"
#include "method.h"
#include "socket.h"
#include "mimetype.h"
#include "logfile.h"
#include "header.h"
#include "plugin.h"

int mk_http_method_check(mk_pointer method)
{
    if (strncasecmp(method.data, HTTP_METHOD_GET_STR, method.len) == 0) {
        return HTTP_METHOD_GET;
    }

    if (strncasecmp(method.data, HTTP_METHOD_POST_STR, method.len) == 0) {
        return HTTP_METHOD_POST;
    }

    if (strncasecmp(method.data, HTTP_METHOD_HEAD_STR, method.len) == 0) {
        return HTTP_METHOD_HEAD;
    }

    return METHOD_NOT_FOUND;
}

mk_pointer mk_http_method_check_str(int method)
{
    switch (method) {
    case HTTP_METHOD_GET:
        return mk_http_method_get_p;

    case HTTP_METHOD_POST:
        return mk_http_method_post_p;

    case HTTP_METHOD_HEAD:
        return mk_http_method_head_p;
    }
    return mk_http_method_null_p;
}

int mk_http_method_get(char *body)
{
    int int_method, pos = 0;
    int max_len_method = 5;
    mk_pointer method;

    /* Max method length is 4 (POST/HEAD) */
    pos = mk_string_char_search(body, ' ', 5);
    if (pos <= 2 || pos >= max_len_method) {
        return METHOD_NOT_FOUND;
    }

    method.data = body;
    method.len = (unsigned long) pos;

    int_method = mk_http_method_check(method);

    return int_method;
}

int mk_http_protocol_check(char *protocol, int len)
{
    if (strncasecmp(protocol, HTTP_PROTOCOL_11_STR, len) == 0) {
        return HTTP_PROTOCOL_11;
    }
    if (strncasecmp(protocol, HTTP_PROTOCOL_10_STR, len) == 0) {
        return HTTP_PROTOCOL_10;
    }
    if (strncasecmp(protocol, HTTP_PROTOCOL_09_STR, len) == 0) {
        return HTTP_PROTOCOL_09;
    }

    return HTTP_PROTOCOL_UNKNOWN;
}

mk_pointer mk_http_protocol_check_str(int protocol)
{
    if (protocol == HTTP_PROTOCOL_11) {
        return mk_http_protocol_11_p;
    }
    if (protocol == HTTP_PROTOCOL_10) {<commit_msg>Just allow HTTP method and protocol request in uppercase<commit_after>/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*  Monkey HTTP Daemon
 *  ------------------
 *  Copyright (C) 2001-2010, <NAME>. <<EMAIL>>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "monkey.h"
#include "memory.h"
#include "http.h"
#include "http_status.h"
#include "file.h"
#include "utils.h"
#include "config.h"
#include "str.h"
#include "method.h"
#include "socket.h"
#include "mimetype.h"
#include "logfile.h"
#include "header.h"
#include "plugin.h"

int mk_http_method_check(mk_pointer method)
{
    if (strncmp(method.data, HTTP_METHOD_GET_STR, method.len) == 0) {
        return HTTP_METHOD_GET;
    }

    if (strncmp(method.data, HTTP_METHOD_POST_STR, method.len) == 0) {
        return HTTP_METHOD_POST;
    }

    if (strncmp(method.data, HTTP_METHOD_HEAD_STR, method.len) == 0) {
        return HTTP_METHOD_HEAD;
    }

    return METHOD_NOT_FOUND;
}

mk_pointer mk_http_method_check_str(int method)
{
    switch (method) {
    case HTTP_METHOD_GET:
        return mk_http_method_get_p;

    case HTTP_METHOD_POST:
        return mk_http_method_post_p;

    case HTTP_METHOD_HEAD:
        return mk_http_method_head_p;
    }
    return mk_http_method_null_p;
}

int mk_http_method_get(char *body)
{
    int int_method, pos = 0;
    int max_len_method = 5;
    mk_pointer method;

    /* Max method length is 4 (POST/HEAD) */
    pos = mk_string_char_search(body, ' ', 5);
    if (pos <= 2 || pos >= max_len_method) {
        return METHOD_NOT_FOUND;
    }

    method.data = body;
    method.len = (unsigned long) pos;

    int_method = mk_http_method_check(method);

    return int_method;
}

int mk_http_protocol_check(char *protocol, int len)
{
    if (strncmp(protocol, HTTP_PROTOCOL_11_STR, len) == 0) {
        return HTTP_PROTOCOL_11;
    }
    if (strncmp(protocol, HTTP_PROTOCOL_10_STR, len) == 0) {
        return HTTP_PROTOCOL_10;
    }
    if (strncmp(protocol, HTTP_PROTOCOL_09_STR, len) == 0) {
        return HTTP_PROTOCOL_09;
    }

    return HTTP_PROTOCOL_UNKNOWN;
}

mk_pointer mk_http_protocol_check_str(int protocol)
{
    if (protocol == HTTP_PROTOCOL_11) {
        return mk_http_protocol_11_p;
    }
    if (protocol == HTTP_PROTOCOL_10) {
{'fraction_non_alphanumeric': 0.11019816336394393, 'fraction_numerical': 0.016433059449009184, 'mean_word_length': 3.3382250174703003, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6143463', 'n_tokens_mistral': 2220, 'n_tokens_neox': 2131, 'n_words': 594}