Пример #1
0
 */

#define _GNU_SOURCE
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stddef.h>

#include "lwan.h"
#include "lwan-config.h"
#include "lwan-http-authorize.h"

enum {
    HTTP_STR_GET  = MULTICHAR_CONSTANT('G','E','T',' '),
    HTTP_STR_HEAD = MULTICHAR_CONSTANT('H','E','A','D'),
    HTTP_STR_POST = MULTICHAR_CONSTANT('P','O','S','T')
} lwan_http_method_str_t;

typedef enum {
    FINALIZER_DONE,
    FINALIZER_TRY_AGAIN,
    FINALIZER_YIELD_TRY_AGAIN,
    FINALIZER_ERROR_TOO_LARGE
} lwan_read_finalizer_t;

enum {
    HTTP_HDR_CONNECTION        = MULTICHAR_CONSTANT_L('C','o','n','n'),
    HTTP_HDR_RANGE             = MULTICHAR_CONSTANT_L('R','a','n','g'),
    HTTP_HDR_IF_MODIFIED_SINCE = MULTICHAR_CONSTANT_L('I','f','-','M'),
Пример #2
0
    val = (*str - '0') * 10;
    val += *(str + 1) - '0';

    if (UNLIKELY(val < min || val > max))
        return -EINVAL;

    return val;
}

int lwan_parse_rfc_time(const char in[static 30], time_t *out)
{
    /* This function is used instead of strptime() because locale
     * information can affect the parsing.  Instead of defining
     * the locale to "C", use hardcoded constants. */
    enum {
        WEEKDAY_SUN = MULTICHAR_CONSTANT('S','u','n',','),
        WEEKDAY_MON = MULTICHAR_CONSTANT('M','o','n',','),
        WEEKDAY_TUE = MULTICHAR_CONSTANT('T','u','e',','),
        WEEKDAY_WED = MULTICHAR_CONSTANT('W','e','d',','),
        WEEKDAY_THU = MULTICHAR_CONSTANT('T','h','u',','),
        WEEKDAY_FRI = MULTICHAR_CONSTANT('F','r','i',','),
        WEEKDAY_SAT = MULTICHAR_CONSTANT('S','a','t',','),
        MONTH_JAN = MULTICHAR_CONSTANT('J','a','n',' '),
        MONTH_FEB = MULTICHAR_CONSTANT('F','e','b',' '),
        MONTH_MAR = MULTICHAR_CONSTANT('M','a','r',' '),
        MONTH_APR = MULTICHAR_CONSTANT('A','p','r',' '),
        MONTH_MAY = MULTICHAR_CONSTANT('M','a','y',' '),
        MONTH_JUN = MULTICHAR_CONSTANT('J','u','n',' '),
        MONTH_JUL = MULTICHAR_CONSTANT('J','u','l',' '),
        MONTH_AUG = MULTICHAR_CONSTANT('A','u','g',' '),
        MONTH_SEP = MULTICHAR_CONSTANT('S','e','p',' '),